Guzzle annotations not working with Doctrine2 annotation parser in Symfony2 project - php

I've got a Symfony2 project and am trying to integrate the GuzzleBundle to build a web service client. I'm using the #guzzle annotations for the client commands (which extend Guzzle\Service\Command\AbstractCommand).
It seems to work correctly in the dev environment but when I try to load pages using the prod environment I get a Doctrine AnnotationException:
PHP Fatal error: Uncaught exception 'Doctrine\Common\Annotations\AnnotationException' with message '[Semantical Error] The annotation "#guzzle" in class Admin\FindAnExpertBundle\Entity\SymplecticClient\Rest\Command\UserById was never imported. Did you maybe forget to add a "use" statement for this annotation?'
I also get an error about a missing Proxy class file:
PHP Warning: require(/home/httpd/sites/experts.admin/app/cache/prod/doctrine/orm/Proxies/AdminFindAnExpertBundleEntityRelationshipTypeProxy.php) [<a href='function.require'>function.require</a>]: failed to open stream: No such file or directory in /home/httpd/sites/experts.admin/vendor/doctrine/lib/Doctrine/ORM/Proxy/ProxyFactory.php
I assume this is because the fatal error is stopping all the proxy classes from being created.
Guzzle appears not to use the Doctrine annotation parser so I'm wondering if there's a way to make it ignore #guzzle annotations or register them somehow?

You have to import the annotation-Parser of Guzzle, which handles the "#guzzle" annotation, e.g.:
use Guzzle\Service\Inspector as guzzle;
But i don't know which class it is.
Maybe this gist file helps you.

I ended up moving the classes relating to the web service client out of the Entity folder, which stopped the Doctrine annotation parser from reading them. In retrospect, the classes shouldn't have been in that folder anyway.

Related

Symfony 3.4 Where to Put Auto-Generating Proxy Class Config Mode?

Symfony is complaining about renaming proxy classes during my multiple instance command execution. Basically, I am running a Symfony command mutliple times at the same time, and it is throwing an error for generated proxy classes not being able to be renamed...
In ProxyGenerator.php line 293:
Warning: rename(/Users/jlroberts/Projects/Shred/Symfony/var/cache/dev/doctrine/orm/Proxies/__CG__AppBundleEntityNslocaleCountryNames.php.5ee27c106fc5f0.51071995,/Users/jlroberts/Projects/Shred/Symfony/var/cache/dev/doctrine/orm/Proxies/__CG__AppBundleEntityNslocaleCountryNames.php): No such file or directory
I found this issue on github
https://github.com/doctrine/common/issues/327
And I think it says to set the AutoGeneratedProxyClasses to AUTOGENERATE_FILE_NOT_EXISTS, which I found on
https://www.doctrine-project.org/projects/doctrine-orm/en/latest/reference/advanced-configuration.html
Which says I use this following line to set that mode
$mode = AUTOGENERATE_FILE_NOT_EXISTS;
$config->setAutoGenerateProxyClasses($mode);
but where do I put that line?

PHP7 Type error with interface

In my symfony project I got an error with a vendor.
Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to eZ\Publish\Core\MVC\Legacy\Kernel\Loader::setCLIHandler() must implement interface ezpKernelHandler, instance of eZ\Publish\Core\MVC\Legacy\Kernel\CLIHandler given, called in /Users/steve/Projects/Web/BuildSuccess/www/vendor/ezsystems/legacy-bridge/mvc/Kernel/Loader.php on line 237 in /Users/steve/Projects/Web/BuildSuccess/www/vendor/ezsystems/legacy-bridge/mvc/Kernel/Loader.php:255
But this error is strange because I checked and eZ\Publish\Core\MVC\Legacy\Kernel\CLIHandler implements the interface ezpKernelHandler !
namespace eZ\Publish\Core\MVC\Legacy\Kernel;
use ezpKernelHandler;
class CLIHandler implements ezpKernelHandler
{
...
}
I tried to debug, with get_class method and I get
"eZ\Publish\Core\MVC\Legacy\Kernel\CLIHandler"
I also used class_implements method and I get
array(0) {
}
Any idea what append ?
Thanks
I see that it is not your code, but rather eZ Publish itself. Because of this it is unlikely that you will be able to update sources, but there is still some things that you can do:
Check your Composer autoloader configuration to see that ezpKernelHandler class is properly resolved. You may need to register custom autoloader for it.
You're most likely receiving this error because you're using Symfony 3.3+ and its recently added services auto-configuration features. You can avoid this error to be thrown by disabling service auto-configuration for affected service, take a look at example here
Since this error is fatal but catchable - if nothing else will help you can create your own service factory for this particular service and catch error inside it.
Fixed : https://github.com/ezsystems/LegacyBridge/issues/132
It is easilly fixed by creating app/autoload.php file which requires both vendor/autoload.php and ezpublish_legacy/autoload.php and changing bin/console to require that file instead of vendor/autoload.php

Zend Framework 2 error

After a composer update my application don't run anymore.
The error is:
PHP Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\InvalidArgumentException' with message 'Provided abstract factory must be the class name of an abstract factory or an instance of an AbstractFactoryInterface.' in /path_to_app/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php:302
I googled the error and seems that in may 2013 happened something similar that could be solved just commenting two lines in the module.config.php
Naturally, I've tried that but it doesn't seem to work.
Any ideas?
You have a factory service configuration issue in your module.config.php, like the error says one of your configured factory services is not a "class name of an abstract factory or an instance of an AbstractFactoryInterface.".
For debugging purpose, try to temporarily disable your application registered modules one by one to detect in which module this is configured (if you have no idea), until the error disappear.
Then check the services configs.

PHP Fatal error: Class 'sfConfig' not found in while run PHP Excel Symfony1.4

i am trying to run basic example of phpExcel in symfony1.4 and i am getting this error
C:\wamp\www\orangehrm-3.01\symfony>php plugins/sfPhpExcelPlugin/examples_1_2/01s
imple.php
10:39:01 Create new PHPExcel object
PHP Fatal error: Class 'sfConfig' not found in C:\wamp\www\orangehrm-3.01\symfo
ny\plugins\sfPhpExcelPlugin\lib\sfPhpExcel.class.php on line 9
any idea will be approciate.
The code for this plugin's examples is a bit strange. It uses the sfConfig class to read Symfony config variables but doesn't initialize nor include any Symfony code (hence the error).
In fact when you look at the code of this plugin you'll see that all it does is set some configuration when instantiating PHPExcel object. I would skip the plugin altogether and just use the PHPExcel directly in your project (you can either include it in the controller where you use it or in the ProjectConfiguration.class.php to make it available for the whole project (not recommended though).

sfYaml echoln() error in Zend Framework project PHPUnit tests

I'm starting a Zend Framework project and I decided to use Doctrine 1.2.3 instead of the Zend_Db classes. I configured my project and doctrine command line script works just fine, my index controller can query my database without problems, but Unit Tests with PHPUnit throws an error:
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
I'm using Zend Server with PHP 5.3. PHPUnit requires the PEAR SymfonyComponents' YAML package. This happens everytime my unit test bootstrap tries to re-create and load the whole testing database, specially when loading the fixtures files. This is the full command and output:
D:\Zend\Apache2\vhost\myproject\tests>phpunit
build-all-reload - Successfully dropped database for connection named 'doctrine'
build-all-reload - Successfully created database for connection named 'doctrine'
build-all-reload - Created tables successfully
build-all-reload - Data was successfully loaded
PHPUnit 3.5.10 by Sebastian Bergmann.
Fatal error: Cannot redeclare echoln() (previously declared in D:\Zend\Apache2\vhost\myproject\library\Doctrine\Parser\sfYaml\sfYaml.php:132) in D:\Zend\ZendServer\bin\PEAR\SymfonyComponents\YAML\sfYaml.php on line 135
D:\Zend\Apache2\vhost\myproject\tests>
As result, my database is completely created and data fixtures are loaded successfully. But this error stops the Unit Testing process. I only have one test class for Doctrine models but this error happens even if I comment its testing code.
It is strange, because if I execute the doctrine script by hand, It runs without problems, and no error happens when the system runs via web. This just happens for Unit Testing.
How can I avoid this libraries collition, if both, Doctrine and PHPUnit include the same sfYaml class from PEAR and from inside Doctrine, without breaking the working system?
You can see in the error message that sfYaml.php is being loaded from two different locations. You must clean up your include path so it has only one copy of each library you need. Use var_dump(get_include_path()) in your bootstrap.php to diagnose the issue.

Categories