Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface

Simon Hohl
Hi!

This may well be more a Zend- than a VuFind related question: In our
code we have a custom Controller which implements VuFind's
"AjaxController" class. After upgrading to VuFind 3.1 from 2.x recently,
I now get the following error when making an ajax call:

> [:error] [pid 3028] [client 134.95.92.121:53700] PHP Catchable fatal
> error:  Argument 1 passed to
> Zenon\\Controller\\ThesaurusController::__construct() must implement
> interface Zend\\ServiceManager\\ServiceLocatorInterface, none given,
> called in
> /usr/local/vufind/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php
> on line 252 and defined in
> /usr/local/vufind/module/Zenon/src/Zenon/Controller/ThesaurusController.php
> on line 50, ...
Looking at VuFinds commit history, commit "Eliminate controllers'
dependency on ServiceLocatorAwareInterface." [1] extended the
AjaxController's __construct() -method by adding ServiceLocatorInterface
as a Parameter. So it seems the injection is missing in our code, and I
am not quite sure how it is realized in for AjaxController. Can somebody
point me in the right direction? ;)

Kind regards,

Simon Hohl

[1]
https://github.com/dainst/vufind/commit/07dbedbebb67354c5bc6da274f3de0ff53ebbfd6



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
VuFind-General mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface

Demian Katz

Simon,


How is your controller currently configured in your module.config.php file? If it's set as an invokable, you will have to change it to be constructed by a factory.


You might find it helpful to look at VuFind's standard controller factory:


https://github.com/vufind-org/vufind/blob/master/module/VuFind/src/VuFind/Controller/Factory.php


If you copy the getGenericController and __callStatic methods from this class to a Factory.php class in the same namespace as the controller you are building, that may be enough to do what you need. Then you just change the 'invokables' setting of 'My\Namespace\MyController' to a 'factories' setting of 'My\Namespace\Factory::getMyController'.


Does that help? Please let me know if you still have problems or if you would like to know more about the reasons for this change. (Short version: the Zend Framework developers decided that using the ServiceLocatorAwareInterface to trigger injection of the service locator was an anti-pattern that encouraged bad habits, so it was necessary to switch to explicit dependency injection).


- Demian




From: Simon Hohl <[hidden email]>
Sent: Friday, July 14, 2017 10:21 AM
To: [hidden email]
Subject: [VuFind-General] Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface
 
Hi!

This may well be more a Zend- than a VuFind related question: In our
code we have a custom Controller which implements VuFind's
"AjaxController" class. After upgrading to VuFind 3.1 from 2.x recently,
I now get the following error when making an ajax call:

> [:error] [pid 3028] [client 134.95.92.121:53700] PHP Catchable fatal
> error:  Argument 1 passed to
> Zenon\\Controller\\ThesaurusController::__construct() must implement
> interface Zend\\ServiceManager\\ServiceLocatorInterface, none given,
> called in
> /usr/local/vufind/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php
> on line 252 and defined in
> /usr/local/vufind/module/Zenon/src/Zenon/Controller/ThesaurusController.php
> on line 50, ...
Looking at VuFinds commit history, commit "Eliminate controllers'
dependency on ServiceLocatorAwareInterface." [1] extended the
AjaxController's __construct() -method by adding ServiceLocatorInterface
as a Parameter. So it seems the injection is missing in our code, and I
am not quite sure how it is realized in for AjaxController. Can somebody
point me in the right direction? ;)

Kind regards,

Simon Hohl

[1]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdainst%2Fvufind%2Fcommit%2F07dbedbebb67354c5bc6da274f3de0ff53ebbfd6&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=958c8XE2PUlCfmUhM0SxpCsQPuQVN92l5bQzC%2FS3j2Q%3D&reserved=0



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsdm.link%2Fslashdot&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=%2FpC6gxMBfD6IrSOW8%2F0Iyi2qE2E7r%2F6AI3hJ7CuXqWg%3D&reserved=0
_______________________________________________
VuFind-General mailing list
[hidden email]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fvufind-general&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=m73JFYVJxNbIdN0y7tob5BhcSp%2FzGrTB0LJWmJcrzXM%3D&reserved=0

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
VuFind-General mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface

Simon Hohl

Hi Demian,


ok, it seems I was not completely off. The only difference in my code was the fact that I did not copy the generic/callStatic methods, but implemented an explicit "getThesaurusController"-function in my Factory class.


I updated my classes following your suggestions, but the error persists:


https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/config/module.config.php

https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/src/Zenon/Controller/Factory.php

https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/src/Zenon/Controller/ThesaurusController.php


Cheers,

Simon


Am 14.07.2017 um 16:57 schrieb Demian Katz:

Simon,


How is your controller currently configured in your module.config.php file? If it's set as an invokable, you will have to change it to be constructed by a factory.


You might find it helpful to look at VuFind's standard controller factory:


https://github.com/vufind-org/vufind/blob/master/module/VuFind/src/VuFind/Controller/Factory.php


If you copy the getGenericController and __callStatic methods from this class to a Factory.php class in the same namespace as the controller you are building, that may be enough to do what you need. Then you just change the 'invokables' setting of 'My\Namespace\MyController' to a 'factories' setting of 'My\Namespace\Factory::getMyController'.


Does that help? Please let me know if you still have problems or if you would like to know more about the reasons for this change. (Short version: the Zend Framework developers decided that using the ServiceLocatorAwareInterface to trigger injection of the service locator was an anti-pattern that encouraged bad habits, so it was necessary to switch to explicit dependency injection).


- Demian




From: Simon Hohl [hidden email]
Sent: Friday, July 14, 2017 10:21 AM
To: [hidden email]
Subject: [VuFind-General] Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface
 
Hi!

This may well be more a Zend- than a VuFind related question: In our
code we have a custom Controller which implements VuFind's
"AjaxController" class. After upgrading to VuFind 3.1 from 2.x recently,
I now get the following error when making an ajax call:

> [:error] [pid 3028] [client 134.95.92.121:53700] PHP Catchable fatal
> error:  Argument 1 passed to
> Zenon\\Controller\\ThesaurusController::__construct() must implement
> interface Zend\\ServiceManager\\ServiceLocatorInterface, none given,
> called in
> /usr/local/vufind/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php
> on line 252 and defined in
> /usr/local/vufind/module/Zenon/src/Zenon/Controller/ThesaurusController.php
> on line 50, ...
Looking at VuFinds commit history, commit "Eliminate controllers'
dependency on ServiceLocatorAwareInterface." [1] extended the
AjaxController's __construct() -method by adding ServiceLocatorInterface
as a Parameter. So it seems the injection is missing in our code, and I
am not quite sure how it is realized in for AjaxController. Can somebody
point me in the right direction? ;)

Kind regards,

Simon Hohl

[1]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdainst%2Fvufind%2Fcommit%2F07dbedbebb67354c5bc6da274f3de0ff53ebbfd6&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=958c8XE2PUlCfmUhM0SxpCsQPuQVN92l5bQzC%2FS3j2Q%3D&reserved=0



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsdm.link%2Fslashdot&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=%2FpC6gxMBfD6IrSOW8%2F0Iyi2qE2E7r%2F6AI3hJ7CuXqWg%3D&reserved=0
_______________________________________________
VuFind-General mailing list
[hidden email]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fvufind-general&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=m73JFYVJxNbIdN0y7tob5BhcSp%2FzGrTB0LJWmJcrzXM%3D&reserved=0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
VuFind-General mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface

Demian Katz

Have you cleared your $VUFIND_LOCAL_DIR/cache/configs directory? If not, it's possible that your original solution was already correct, but the configuration wasn't loading due to the cached version. Having an explicit getThesaurusController is perfectly fine -- but the "magic" __callStatic approach can be convenient if you need to construct a lot of different controllers and don't want to have to write the same basic factory method over and over


- Demian




From: Simon Hohl <[hidden email]>
Sent: Friday, July 14, 2017 11:22 AM
To: [hidden email]; Demian Katz
Subject: Re: [VuFind-General] Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface
 

Hi Demian,


ok, it seems I was not completely off. The only difference in my code was the fact that I did not copy the generic/callStatic methods, but implemented an explicit "getThesaurusController"-function in my Factory class.


I updated my classes following your suggestions, but the error persists:


https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/config/module.config.php

https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/src/Zenon/Controller/Factory.php

https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/src/Zenon/Controller/ThesaurusController.php


Cheers,

Simon


Am 14.07.2017 um 16:57 schrieb Demian Katz:

Simon,


How is your controller currently configured in your module.config.php file? If it's set as an invokable, you will have to change it to be constructed by a factory.


You might find it helpful to look at VuFind's standard controller factory:


https://github.com/vufind-org/vufind/blob/master/module/VuFind/src/VuFind/Controller/Factory.php


If you copy the getGenericController and __callStatic methods from this class to a Factory.php class in the same namespace as the controller you are building, that may be enough to do what you need. Then you just change the 'invokables' setting of 'My\Namespace\MyController' to a 'factories' setting of 'My\Namespace\Factory::getMyController'.


Does that help? Please let me know if you still have problems or if you would like to know more about the reasons for this change. (Short version: the Zend Framework developers decided that using the ServiceLocatorAwareInterface to trigger injection of the service locator was an anti-pattern that encouraged bad habits, so it was necessary to switch to explicit dependency injection).


- Demian




From: Simon Hohl [hidden email]
Sent: Friday, July 14, 2017 10:21 AM
To: [hidden email]
Subject: [VuFind-General] Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface
 
Hi!

This may well be more a Zend- than a VuFind related question: In our
code we have a custom Controller which implements VuFind's
"AjaxController" class. After upgrading to VuFind 3.1 from 2.x recently,
I now get the following error when making an ajax call:

> [:error] [pid 3028] [client 134.95.92.121:53700] PHP Catchable fatal
> error:  Argument 1 passed to
> Zenon\\Controller\\ThesaurusController::__construct() must implement
> interface Zend\\ServiceManager\\ServiceLocatorInterface, none given,
> called in
> /usr/local/vufind/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php
> on line 252 and defined in
> /usr/local/vufind/module/Zenon/src/Zenon/Controller/ThesaurusController.php
> on line 50, ...
Looking at VuFinds commit history, commit "Eliminate controllers'
dependency on ServiceLocatorAwareInterface." [1] extended the
AjaxController's __construct() -method by adding ServiceLocatorInterface
as a Parameter. So it seems the injection is missing in our code, and I
am not quite sure how it is realized in for AjaxController. Can somebody
point me in the right direction? ;)

Kind regards,

Simon Hohl

[1]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdainst%2Fvufind%2Fcommit%2F07dbedbebb67354c5bc6da274f3de0ff53ebbfd6&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=958c8XE2PUlCfmUhM0SxpCsQPuQVN92l5bQzC%2FS3j2Q%3D&reserved=0



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsdm.link%2Fslashdot&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=%2FpC6gxMBfD6IrSOW8%2F0Iyi2qE2E7r%2F6AI3hJ7CuXqWg%3D&reserved=0
_______________________________________________
VuFind-General mailing list
[hidden email]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fvufind-general&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=m73JFYVJxNbIdN0y7tob5BhcSp%2FzGrTB0LJWmJcrzXM%3D&reserved=0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
VuFind-General mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface

Simon Hohl

Hi Demian,


it seems the solution for every problem I have is "delete cache". ;) Now everything is working as expected.


Thanks!

Simon


Am 14.07.2017 um 17:37 schrieb Demian Katz:

Have you cleared your $VUFIND_LOCAL_DIR/cache/configs directory? If not, it's possible that your original solution was already correct, but the configuration wasn't loading due to the cached version. Having an explicit getThesaurusController is perfectly fine -- but the "magic" __callStatic approach can be convenient if you need to construct a lot of different controllers and don't want to have to write the same basic factory method over and over


- Demian




From: Simon Hohl [hidden email]
Sent: Friday, July 14, 2017 11:22 AM
To: [hidden email]; Demian Katz
Subject: Re: [VuFind-General] Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface
 

Hi Demian,


ok, it seems I was not completely off. The only difference in my code was the fact that I did not copy the generic/callStatic methods, but implemented an explicit "getThesaurusController"-function in my Factory class.


I updated my classes following your suggestions, but the error persists:


https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/config/module.config.php

https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/src/Zenon/Controller/Factory.php

https://github.com/dainst/vufind/blob/acd19f50a95a604facac29abcdea110c0d0df927/module/Zenon/src/Zenon/Controller/ThesaurusController.php


Cheers,

Simon


Am 14.07.2017 um 16:57 schrieb Demian Katz:

Simon,


How is your controller currently configured in your module.config.php file? If it's set as an invokable, you will have to change it to be constructed by a factory.


You might find it helpful to look at VuFind's standard controller factory:


https://github.com/vufind-org/vufind/blob/master/module/VuFind/src/VuFind/Controller/Factory.php


If you copy the getGenericController and __callStatic methods from this class to a Factory.php class in the same namespace as the controller you are building, that may be enough to do what you need. Then you just change the 'invokables' setting of 'My\Namespace\MyController' to a 'factories' setting of 'My\Namespace\Factory::getMyController'.


Does that help? Please let me know if you still have problems or if you would like to know more about the reasons for this change. (Short version: the Zend Framework developers decided that using the ServiceLocatorAwareInterface to trigger injection of the service locator was an anti-pattern that encouraged bad habits, so it was necessary to switch to explicit dependency injection).


- Demian




From: Simon Hohl [hidden email]
Sent: Friday, July 14, 2017 10:21 AM
To: [hidden email]
Subject: [VuFind-General] Extending VuFind's "AjaxController"/Injecting the ServiceLocatorInterface
 
Hi!

This may well be more a Zend- than a VuFind related question: In our
code we have a custom Controller which implements VuFind's
"AjaxController" class. After upgrading to VuFind 3.1 from 2.x recently,
I now get the following error when making an ajax call:

> [:error] [pid 3028] [client 134.95.92.121:53700] PHP Catchable fatal
> error:  Argument 1 passed to
> Zenon\\Controller\\ThesaurusController::__construct() must implement
> interface Zend\\ServiceManager\\ServiceLocatorInterface, none given,
> called in
> /usr/local/vufind/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php
> on line 252 and defined in
> /usr/local/vufind/module/Zenon/src/Zenon/Controller/ThesaurusController.php
> on line 50, ...
Looking at VuFinds commit history, commit "Eliminate controllers'
dependency on ServiceLocatorAwareInterface." [1] extended the
AjaxController's __construct() -method by adding ServiceLocatorInterface
as a Parameter. So it seems the injection is missing in our code, and I
am not quite sure how it is realized in for AjaxController. Can somebody
point me in the right direction? ;)

Kind regards,

Simon Hohl

[1]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fdainst%2Fvufind%2Fcommit%2F07dbedbebb67354c5bc6da274f3de0ff53ebbfd6&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=958c8XE2PUlCfmUhM0SxpCsQPuQVN92l5bQzC%2FS3j2Q%3D&reserved=0



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fsdm.link%2Fslashdot&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=%2FpC6gxMBfD6IrSOW8%2F0Iyi2qE2E7r%2F6AI3hJ7CuXqWg%3D&reserved=0
_______________________________________________
VuFind-General mailing list
[hidden email]
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fvufind-general&data=02%7C01%7Cdemian.katz%40villanova.edu%7Ccd8941ce82e94686067908d4cac3c596%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636356389563247858&sdata=m73JFYVJxNbIdN0y7tob5BhcSp%2FzGrTB0LJWmJcrzXM%3D&reserved=0



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
VuFind-General mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/vufind-general
Loading...