Skip to content

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

Merged
Naktibalda merged 2 commits into
Codeception:masterfrom
hyprr-social:master
Jan 6, 2020
Merged

Naktibalda merged 2 commits into
Codeception:masterfrom
hyprr-social:master

Conversation

@debugger84

Copy link
Copy Markdown
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
Copy Markdown
Member

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

@sergeyklay sergeyklay left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread src/Codeception/Module/Phalcon.php Resolved

@sergeyklay sergeyklay left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Member

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

@sergeyklay

Copy link
Copy Markdown
Contributor

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.

3 participants