Doctrine ORM CLI Tool Not working - php

I had doctrine version 2.3.2 , whose CLI tool was working perfectly. Now, just trying to update to ORM v2.4.4, which is having the following error just by running "./vendor/bin/doctrine" command:
PHP Catchable fatal error: Argument 1 passed to
Doctrine\ORM\Tools\Console\ConsoleRunner::run() must be an instance of
Symfony\Component\Console\Helper\HelperSet, integer given, called in
/vagrant/vendor/doctrine/orm/bin/doctrine.php on line 59 and defined in
/vagrant/vendor/doctrine/orm/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php on line 57
Can anybody please explain what might be wrong? Thanks.

OK, I found the solution. This requires little change in cli-config as below:
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));
return $helperSet;
In previous versions, only including the cli-config.php file would be OK(it expected a variable named '$helperSet' ). But, in new version, it requires to return the variable and get it assigned to its internal variable.

Related

"Trying to get property of non-object" error when running a Codeception test

I have a Cest with a _before() that has the following code in it to authenticate (API testing):
// Log a user in
$I->haveHttpHeader('Accept', 'application/json');
$I->sendPOST('/authentication/login', ['username' => $this->username, 'password' => $this->password]);
$this->api_token = json_decode($I->grabResponse())->token;
When I run the test I get the following error:
[PHPUnit_Framework_Exception] Trying to get property of non-object
Scenario Steps:
3. $I->grabResponse() at tests/api/ApiBase.php:19
2. $I->sendPOST("/authentication/login",{"username":"user#examplecom","password":"abc123"}) at tests/api/ApiBase.php:17
1. $I->haveHttpHeader("Accept","application/json") at tests/api/ApiBase.php:16
tests/api/ApiBase.php:19 is $this->api_token = json_decode($I->grabResponse())->token;
It appears as if $I is no longer an object, but I have confirmed that it is still an instance of ApiTester. So the only thing I can think of is the call to the property of a non-object is somewhere deeper down.
How can I tell where? I'm running this with the --debug switch enabled.
[EDIT] This isn't a problem with the json_decode. If I move $I->grabResponse() up then the error will be on that line.
Validate response before using it.
seeResponseJsonMatchesJsonPath checks if the element is present in json response.
$I->seeResponseJsonMatchesJsonPath('$.token');
Also it could be useful to use grabDataFromResponseByJsonPath method instead of parsing it yourself.
$this->api_token = $I->grabDataFromResponseByJsonPath('$.token')[0];
[0] is necessary because grabDataFromResponseByJsonPath returns a list of matching items.
You may need to install flow/jsonpath library to get JsonPath methods working if it isn't installed yet.

Call to undefined method Illuminate\Foundation\Application::share() when use breadcrumbs package

Today, I want to use Laravel Breadcrumbs package with laravel 5.4. I used that with laravel 5.3 without any problem and all things worked fine.
But when run the application I got this error :
FatalErrorException in ServiceProvider.php line 34:
Call to undefined method Illuminate\Foundation\Application::share()
I searched for that and I found that As of laravel 5.4 share has been removed. and I must to use the singleton instead.
But when I did that changes In the ServiceProvider.php like this :
public function register()
{
$this->app['breadcrumbs'] = $this->app->singleton(function($app)
{
$breadcrumbs = $this->app->make('DaveJamesMiller\Breadcrumbs\Manager');
$viewPath = __DIR__ . '/../views/';
$this->loadViewsFrom($viewPath, 'breadcrumbs');
$this->loadViewsFrom($viewPath, 'laravel-breadcrumbs'); // Backwards-compatibility with 2.x
$breadcrumbs->setView($app['config']['breadcrumbs.view']);
return $breadcrumbs;
});
}
I got another error. like this :
ErrorException in Container.php line 1057:
Illegal offset type in unset
I do not know what is problem. can anyone help me ?
Update :
I found the solution Here.
The first problem is that the singleton instance expects a class to bind to as the first argument, which in this case is 'breadcrumbs'.
The second problem is that you don't need to explicitly declare the array key for the singleton instance. So this is how it should look:
$this->app->singleton('breadcrumbs', function($app)
The next problem is that the package you're using has been abandoned. The developer will no longer maintain it.
The final problem is that you're using a version < 3.0.2. So change the version in your composer.json to 3.0.2 and then install that, then you shouldn't need to be modifying any files.

Configuring third party service in my CompilerPass

I'm using Symfony 2.7 and I want to configure some service by adding configurator to it. I follow instructions on http://symfony.com/doc/current/components/dependency_injection/configurators.html, but I want to add my configurator to that service in my CompilerPass.
I wrote the following code:
$container->getDefinition('exercise_html_purifier.config.default')
->setConfigurator([
$container->getDefinition('application.exercise_html_purifier.config_configurator')->getClass(),
'configure'
]);
where application.exercise_html_purifier.config_configurator is id of my configurator service. This code works as expected, but of course it is also triggers php's warning:
DEPRECATED - Non-static method Application\Service\ExerciseHTMLPurifier\Configurator\ConfigConfigurator::configure() should not be called statically, assuming $this from incompatible context
because the configure method is not static in my case. I can't figure out, how to tell symfony to set non-static configurator callback.
I tried to set it like this:
$container->getDefinition('exercise_html_purifier.config.default')
->setConfigurator([
$container->get('application.exercise_html_purifier.config_configurator'),
'configure'
]);
but got this error:
ContextErrorException in XmlDumper.php line 201:
Warning: DOMElement::setAttribute() expects parameter 2 to be string, object given
I even tried to use the following syntax:
$container->getDefinition('exercise_html_purifier.config.default')
->setConfigurator([
'#application.exercise_html_purifier.config_configurator',
'configure'
]);
but also got error
FatalErrorException in appDevDebugProjectContainer.php line 2992:
Parse Error: syntax error, unexpected '#', expecting identifier (T_STRING)
What I'm doing wrong?
Thanks.
OK, I've read the source of \Symfony\Component\DependencyInjection\Dumper\XmlDumper::addService() and found that one of the solutions is to pass Definition instead of instance:
$container->getDefinition('exercise_html_purifier.config.default')
->setConfigurator([
$container->getDefinition('application.exercise_html_purifier.config_configurator'),
'configure'
]);

Laravel 3 - PHP Warning: in_array() expects parameter 2 to be array

I am working with a code that was not written by me. It is a Laravel 3 application, it is giving me the following error:
PHP Warning: in_array() expects parameter 2 to be array, null given in /Users/use/Documents/project/laravel/error.php on line 87
Can you give me pointers on how to debug it? It is giving error in the file which was included in the framework. Also I using the php's inbuilt server to run the application. Does that cause problems? Any pointers are helpful.
PS: I am on a mac.
After looking at the source code it appears that you are getting the error from this file:
// laravel/error.php
// line 86
if (in_array($code, Config::get('error.ignore')))
{
return static::log($exception);
}
The method appears to be looking for the error.ignore config variable:
// application/config/error.php
// line 16
'ignore' => array(),
Check the application/config/error.php file, make sure that 'ignore' is set to an array. If it already is, then you likely have an error in one of the other config files which is corrupting the array.
Hopefully this helps and shows the steps you can take in tracking down the source of an error.
You can get this also if you're using composer and the required files have not been installed after a fresh checkout of the project. To resolve:
$ composer install
Or similar. To actually get a head on this information I had to throw $exception in the error.php file around line 87, then I saw the reason in the Apache error logs.
Most of this errors is about of parameters definition bug.
for example sometimes coder write
protected $guarded = 'title';
instead of
protected $guarded = ['title'];
That makes the paroblem

Symfony2 - How to delete/move an entity?

I am learning symfony2 and atfer creating some Doctrine Entities in a bundle, I wanted to move them.
However, after moving, and changing any instances of them being referenced, I was getting errors when trying to run my application.
I moved them back, and everything was fine.
Now I am just tyring to remove them completly, but again, I get errors when doing so.
Any help on removing Entities entirely?
I did exactly the same thing that Mr Pablo did, but for a bundle : I moved a bundle (renamed) and modified all calls to it.
I have the same error :
ErrorException: Catchable Fatal Error: Object of class __PHP_Incomplete_Class could not be converted to string in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php line 70
in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/HttpKernel/Debug/ErrorHandler.php line 65
at ErrorHandler->handle() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php line 70
at AbstractToken->getUsername() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Bundle/SecurityBundle/DataCollector/SecurityDataCollector.php line 56
at SecurityDataCollector->collect() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/HttpKernel/Profiler/Profiler.php line 174
at Profiler->collect() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php line 90
at ProfilerListener->onKernelResponse()
at call_user_func() in /Volumes/Data/home/timi/Sites/symfony2/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Debug/TraceableEventDispatcher.php line 82
at TraceableEventDispatcher->doDispatch() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3678
at EventDispatcher->dispatch() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 4754
at ContainerAwareEventDispatcher->dispatch() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3904
at HttpKernel->filterResponse() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3896
at HttpKernel->handleRaw() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 3846
at HttpKernel->handle() in /Volumes/Data/home/timi/Sites/symfony2/app/cache/dev/classes.php line 4791
at HttpKernel->handle() in /Volumes/Data/home/timi/Sites/symfony2/app/bootstrap.php.cache line 547
at Kernel->handle() in /Volumes/Data/home/timi/Sites/symfony2/web/app_dev.php line 20
Some help will be very welcomed :)
EDIT:
Well I solved the problem, Adam Stacey had heard it well :)
Before changing anything, I was logged in the website, by using FOSUserBundle firewall.
By changing the name of the bundle, it fooled the firewall and it was stuck at line 70 of ./vendor/symfony/src/Symfony/Component/Security/Core/Authentication/Token/AbstractToken.php
Here is the function :
public function getUsername()
{
if ($this->user instanceof UserInterface) {
return $this->user->getUsername();
}
return (string) $this->user;
}
So I commented out the line return (string) $this->user;, reloaded the webpage, logged out, than reverted the comment. And voilĂ  !
What kind of errors were you getting?
Make sure you:
Clear cache
Rebuild database
Don't have any entity relationships with it
Don't have any code based on the entities
Like Inori mentioned have you tried rebuilding your entities?
If not try this from the CLI:
php app/console doctrine:generate:entities Acme
php app/console doctrine:schema:update --force
Replace "Acme" with your name, company name or whatever you have used in your bundles.
The other thing you may have to do is remove any instances where you have used the entities.
For example, you may have some entities in the controllers that look like this:
use Acme\BundleName\Entity\SomeEntity;
use Acme\BundleName\Entity\AnotherEntity;
They will need to be removed.
If you have the details of the particular errors that are coming up let me know what they are and I will try and help you further.
I have heard that this can also sometimes be to do with sessions. Are you using any bundles for authentication or anything like that?
In your php.ini file do you have your set to:
session.auto_start = Off
This may be way off, but worth a go. Let me know.
On a separate note. Did your server setup pass the checks in the app/check.php file that you can run via CLI?

Categories