phalcon / cphalcon

High performance, full-stack PHP framework delivered as a C extension.
https://phalcon.io
BSD 3-Clause "New" or "Revised" License
10.79k stars 1.96k forks source link

Bug: $this->getDI()->getShared('dispatcher') returned bool #12929

Closed TimurFlush closed 7 years ago

TimurFlush commented 7 years ago

Hello. I'm not very good know English language, Russian is better.

<?php

class TranslationPlugin extends \Phalcon\Mvc\User\Plugin
{
    public function __construct()
    {
        var_dump(
            $this->getDI()->getShared('dispatcher')
        );
        var_dump(
            $this->getDI()->getShared('request')
        );
    }

why is the first var_dump returns bool(true), and the second \Phalcon\Request? The idea is to return the object \Phalcon\Mvc\Dispatcher, but instead returns bool(true). Explain to me, can I something not so do?

Details

stamster commented 7 years ago

Здравствуйте,

https://docs.phalconphp.com/en/latest/api/Phalcon_Mvc_User_Plugin https://olddocs.phalconphp.com/en/latest/api/Phalcon_Mvc_User_Plugin

You should not use PHP's constructor if you extend this class which extends Abstract class Phalcon\Di\Injectable.

Tip: perhaps you want to use setEventsManager() within this class to set events you need?

I think your question is more for a forum, then issue for git repo.

andrew-demb commented 7 years ago

@stamster, about constructor: why don't use? He can do it without any danger.

@TimurFlush, please, provide a script to reproduce.

P.S.: I have no problem with it - https://gist.github.com/andrew-demb/8f1bfcd37561efe3ed09dc3627e13a41

TimurFlush commented 7 years ago

@andrew-demb, I, too, have with your code no problem. @stamster, You can use a constructor.

Don'T know how to describe it to you, it at least needs to see. https://youtu.be/eViIviXw4zA