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

Add ability to use parameters defined in the service container #3

Merged
merged 2 commits into from
Jan 6, 2020
Merged

Add ability to use parameters defined in the service container #3

merged 2 commits into from
Jan 6, 2020

Conversation

debugger84
Copy link
Contributor

The parameter $parameters of the method get of the Phalcon's DiInterface can be array or null.

/**
     * Resolves the service based on its configuration
     *
     * @param string $name
     * @param array $parameters
     * @return mixed
     */
    public function get($name, $parameters = null);

According to this parameter Di container tries to create service. If we have an array of dependencies in our definition, such as

'group' => [
         'className' => '\Acme\Group',
         'arguments' => [
             [
                 'type' => 'service',
                 'service' => 'myComponent',
             ],
         ],
     ],

than we can get \Acme\Group without parameters $group = $container->get('group', null);. In this case we get class Group with injected myComponete.
If we use $group = $container->get('group', []);, than we have got an error " [ArgumentCountError] Too few arguments to function Acme\Group::__construct(), 0 passed and exactly 1 expected ".

This pull request adds an ability to use parameters from the container's definition, to create a service.

@Naktibalda
Copy link
Member

This small change raises the lowest supported version of PHP to 7.1

Copy link
Member

@sergeyklay sergeyklay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't break BC with this small change. At least for a minor module version. Consider to use array $parameter = null instead

src/Codeception/Module/Phalcon.php Outdated Show resolved Hide resolved
Copy link
Member

@sergeyklay sergeyklay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Naktibalda Naktibalda merged commit 985d266 into Codeception:master Jan 6, 2020
@Naktibalda
Copy link
Member

I think that this change is a feature, so it must be released as 1.1.0, is that right?

@sergeyklay
Copy link
Member

Yes, I think so

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

Successfully merging this pull request may close these issues.

None yet

3 participants