Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0.x] Remove $di being passed in as second parameter into Volt service #11926

Closed
dschissler opened this issue Jun 26, 2016 · 17 comments
Closed
Milestone

Comments

@dschissler
Copy link
Contributor

dschissler commented Jun 26, 2016

Phalcon 2.1 is binding the service functions to the dependency injector and so the second parameter being passed into the Volt definition is unnecessary.

This would turn the following:

$di->set('voltService', function($view, $di) {
    ...
    $volt = new Volt($view, $di);

into this:

$di->set('voltService', function($view) {
    ...
    $volt = new Volt($view, $this);

This would add consistency to the services but would have the downside of breaking existing service definitions.

@sergeyklay
Copy link
Contributor

It seems to me this is mainly phalcon/docs issue

@Jurigag
Copy link
Contributor

Jurigag commented Jun 28, 2016

We just need to implemt both behaviours and that's it.

@dschissler

This comment was marked as abuse.

@sergeyklay
Copy link
Contributor

Could you please explain guys what kind of problem you are discussing

@dschissler

This comment was marked as abuse.

@Jurigag
Copy link
Contributor

Jurigag commented Jun 28, 2016

For me old syntax shouldn't be removed on version 2.x. We could do it on 3.x for me. Further 2.x shouldn't have any code breaking previous 2.x versions. There should be as little as possible changes in api to update to new minor version. We should just deprecate old syntax(just trigger E_DEPRECATED if it's used) but it should work in my opinion as it is.

@dschissler

This comment was marked as abuse.

@Jurigag
Copy link
Contributor

Jurigag commented Jun 28, 2016

Where there is - we just need to use reflection, but should we ? Just if function accept two arguments - trigger deprecated and inform in which version it will be removed. We could in 2.2 maybe beacause we don't follow semver. But i think we always should inform about something before remove it, not everyone will check changelog, github or blog. Some of people will just upgrade and that's it. At least in logs they could see something.

@dschissler

This comment was marked as abuse.

@dschissler dschissler reopened this Jun 28, 2016
@dschissler

This comment was marked as abuse.

@dschissler dschissler changed the title [2.1.x] Remove $di being passed in as second parameter into Volt service [3.0.x] Remove $di being passed in as second parameter into Volt service Nov 5, 2016
@dschissler

This comment was marked as abuse.

@sergeyklay
Copy link
Contributor

sergeyklay commented Nov 5, 2016

$di->setShared(
    'volt',
    function (\Phalcon\Mvc\ViewBaseInterface $view, \Phalcon\DiInterface $di = null) {
        /** @var \Phalcon\DiInterface $this */
        $config = $this->getShared('config');

        $volt = new Volt($view, $di ?: $this);

        $volt->setOptions(
            [
                'compiledPath'      => $config->application->view->compiledPath,
                'compiledSeparator' => $config->application->view->compiledSeparator,
                'compiledExtension' => $config->application->view->compiledExtension,
                'compileAlways'     => (bool) $config->application->debug,
            ]
        );

        return $volt;
    }
);


$di->setShared(
    'view',
    function () use () {
        /** @var \Phalcon\DiInterface $this */
        $config = $this->getShared('config');

        $view = new \Phalcon\Mvc\View();

        $engines = [
          '.volt' => $this->getShared('volt', [$view, $this]),
        ];

        $view->registerEngines($engines);
        $view->setViewsDir($config->application->view->viewsDir);

        return $view;
    }
);

@dschissler

This comment was marked as abuse.

@Jurigag
Copy link
Contributor

Jurigag commented Nov 6, 2016

It can be done in 3.* with keeping BC using reflection but there is no point in this imho.

@dschissler

This comment was marked as abuse.

@dschissler

This comment was marked as abuse.

@niden
Copy link
Member

niden commented Feb 23, 2019

Closing in favor of #13855. Will revisit if the community votes for it, or in later versions.

@niden niden closed this as completed Feb 23, 2019
niden pushed a commit that referenced this issue Feb 24, 2019
#13839)

* [#11926] Changed view engine service closures to no longer receive the dependency injector as the second parameter.

* Attempt to fix Volt engine integration test.

* Bind view service closures to the DI, fix more tests.

* Update CHANGELOG-4.0.md
@niden niden added the 4.0 label Jun 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants