Bug #59357

Using the PackageManager directly instead of the Interface results in unexpected behavior

Added by Marc Neuhaus about 1 year ago. Updated about 1 year ago.

Status:New Start date:2014-06-05
Priority:Should have Due date:
Assigned To:- % Done:

0%

Category:-
Target version:-
PHP Version: Complexity:
Has patch:No Affected Flow version:Git master

Description

If you try to inject the PackageManager into your class using the Inject Annotation
the "getAvailablePackages" returns no Packages because the PackageManager doesn't
seem to be initialized. Using the alternative injection method through an injectPackageManager
method works without a Problem.


Related issues

duplicated by TYPO3 Flow Base Distribution - Bug #59358: PackageManager does not work when being injected via Anno... Closed 2014-06-05

History

#1 Updated by Bastian Waidelich about 1 year ago

  • Status changed from New to Needs Feedback
  • Assigned To set to Bastian Waidelich

Marc, I can't reproduce this. Can you please add an example?
For me it doesn't make a difference which injection method is used (that would be a weird bug) but whether it's referring to the PackageManager or its interface (which is registered as "earlyInstance" in the bootstrap):

 1use TYPO3\Flow\Annotations as Flow;
 2use TYPO3\Flow\Cli\CommandController;
 3use TYPO3\Flow\Package\PackageManager;
 4use TYPO3\Flow\Package\PackageManagerInterface;
 5
 6/**
 7 * @Flow\Scope("singleton")
 8 */
 9class TestCommandController extends CommandController {
10
11    /**
12     * @var PackageManager
13     */
14    protected $packageManager1;
15
16    /**
17     * @Flow\Inject
18     * @var PackageManager
19     */
20    protected $packageManager2;
21
22    /**
23     * @var PackageManagerInterface
24     */
25    protected $packageManager3;
26
27    /**
28     * @Flow\Inject
29     * @var PackageManagerInterface
30     */
31    protected $packageManager4;
32
33    /**
34     * @param PackageManager $packageManager1
35     * @return void
36     */
37    public function injectPackageManager1(PackageManager $packageManager1) {
38        $this->packageManager1 = $packageManager1;
39    }
40
41    /**
42     * @param PackageManagerInterface $packageManager3
43     * @return void
44     */
45    public function injectPackageManager(PackageManagerInterface $packageManager3) {
46        $this->packageManager3 = $packageManager3;
47    }
48
49    /**
50     * @return void
51     */
52    public function testCommand() {
53        $this->outputLine('1: %d packages', array(count($this->packageManager1->getAvailablePackages())));
54        $this->outputLine('2: %d packages', array(count($this->packageManager2->getAvailablePackages())));
55        $this->outputLine('3: %d packages', array(count($this->packageManager3->getAvailablePackages())));
56        $this->outputLine('4: %d packages', array(count($this->packageManager4->getAvailablePackages())));
57    }
58
59}

Output:

1: 0 packages
2: 0 packages
3: 60 packages
4: 60 packages

#2 Updated by Christian Loock about 1 year ago

Bastian Waidelich wrote:

Marc, I can't reproduce this. Can you please add an example?
For me it doesn't make a difference which injection method is used (that would be a weird bug) but whether it's referring to the PackageManager or its interface (which is registered as "earlyInstance" in the bootstrap):

[...]

Output:
[...]

For my case (which i stated in the other Ticket) I used the PackageManager directly.

I do now know what to do, but I think it is very confusing. There should be some sort of notification or error when you try to use it directly instead of the interface. It is just not the behaviour you would epect at all. Or it should be fixed so that you can use both. (I dint see the point of an interface face here anyways, but that might just be me)

Cheers,

Christian

#3 Updated by Marc Neuhaus about 1 year ago

lol, just realized, that i tried to inject the PackageManager itself through
Annotation, which didn't work and then added an injectMethod with the
PackageManagerInterface in the method which then works of course ;D

still, i would either expect a helpful exception that you should use the
Interface instead, or it should work that way as well, imho

#4 Updated by Bastian Waidelich about 1 year ago

  • Status changed from Needs Feedback to New
  • Assigned To deleted (Bastian Waidelich)

I do now know what to do, but I think it is very confusing [...]

still, i would either expect a helpful exception that you should use the
Interface instead, or it should work that way as well, imho [...]

I agree, it's just a different issue. Would you update the subject accordingly?

#5 Updated by Marc Neuhaus about 1 year ago

  • Subject changed from PackageManager isnt initiliazed when injected through annotation to Using the PackageManager directly instead of the Interface results in unexpected behavior

Also available in: Atom PDF