I'm using Symfony's ClassMapGenerator to get an array of all classes inside a directory:
ClassMapGenerator::createMap(__DIR__ . '/Generators')
This works just fine - but the ClassMapGenerator class was deprecated in Symfony 3.3, and completely removed in symfony 4.
Since we've just performed an upgrade to Symfony 4, this code no longer works.
I've read this article that explains why it was removed, but doesn't offer any alternatives.
Any ideas?
I figured out how to solve this by replacing the Symfony import with Composer's ClassMapGenerator.
use Composer\Autoload\ClassMapGenerator;
The syntax is exactly the same
Related
I'm starting to migrate my application to symfony4 but I have the following deprecation notice in one of my third-party bundle ( tbbcmoneybundle . And I would like to know what to change in order to propose a PR
Currently the build is failing because of these errors (complete report here )
The "doctrine.database_create_command" service is private, getting it from the container is deprecated since Symfony 3.2 and will fail in 4.0. You should either make the service public, or stop using the container directly and use dependency injection instead: 25x
12x in ConfigTest::setUp from Tbbc\MoneyBundle\Tests\Config
6x in ConsoleTest::setUp from Tbbc\MoneyBundle\Tests\Console
3x in ConsoleTest::testRunRatioList from Tbbc\MoneyBundle\Tests\Console
2x in ConsoleTest::testRunRatioFetch from Tbbc\MoneyBundle\Tests\Console
1x in ConfigTest::testHistoryOfFetchedRatio from Tbbc\MoneyBundle\Tests\Config
1x in ConsoleTest::testRunSaveRatio from Tbbc\MoneyBundle\Tests\Console
I guess it's related to this code
$this->runCommand($this->client,'doctrine:database:create');
$this->runCommand($this->client,'doctrine:schema:update --force');
However I don't see see how to fix this and google seems unhelpful on this one.
The problem looks like it comes from the loss of container awareness (if that's a valid phrase) in Symfony 4, which started in Symfony 3.4. This blog talks about restricting container injection in 3.4 and how it will go away in 4.0.
It looks as though someone has opened a PR to upgrade to Symfony 4, but that is failing. (Looks like you're trying to help that along as well.)
According to this Travis integration test that is failing, the commands which extend "ContainerAwareCommand" are the source of the fail.
Which makes sense. The ContainerAwareCommand attempts to inject the Container, which is set to private in Symfony 4 (and deprecated since 3.4) as outlined in the blog post above. A fix, and I think you want to fix this in a PR to TBBC if I read your question correctly, seems to be to remove the extension of ContainerAwareCommand from those command classes and just inject the services necessary. See the new Symfony 4 doc on commands (and note that ContainerAware is no longer an option as it was in 2.8-ish.)
In short, get rid of the extension to ContainerAwareCommand and inject the services used by those commands. (Might need to do some extra configuration to ensure that the services are public.)
I have a project containing, amongst others, the following composer.json dependencies:
"propel/propel1": "dev-master"`,
"halleck45/phpmetrics": "dev-master"
I recently did a composer update and found that a new version of a library required by PhpMetrics, called Hoa, introduces a new class \EngineException to emulate a new PHP7 class. Unfortunately Propel 1 also defines \EngineException, and so a conflict results.
The correct fix for this would be to upgrade to Propel 2, which uses namespaces. However this is still in alpha and is subject to BC breaks, so is not really workable for me.
My present fix is to lock Hoa to a specific version that does not have the new class:
"hoa/core": "2.15.04.*"
That's not a bad solution, but it isn't entirely satisfying to lock a library to an old version.
In the Hoa code, the only way for the new class not to be loaded is to be running PHP 7, which is again not feasible. However, it also occurs to me that Hoa only needs to be required when PhpMetrics runs. This is a stand-alone code analysis tool and only sits in the root of the project for convenience; the rest of the project does not use this library.
Thus, it would be great if I could call something in Composer to ask that this class is not (auto)loaded, or perhaps something to do the same in the composer.json. It is being needlessly loaded at present - I don't know whether it is being autoloaded incorrectly or whether it is being required manually by Composer.
It may help to know that Hoa classes have been added by Composer to the auto-generated autoload_psr4.php script. As far as I can understand the docs, this means it is autoloaded, and there is nothing in my project that would require any of the Hoa classes.
Fixed by https://github.com/hoaproject/Core/commit/8ed00fe9345c4f8b2679a256926d6d24994ea842.
The new exception architecture introduced in PHP7 [1] has been totally
redesigned [2]. This patch updates the retro-compatibility classes
according to this new architecture. Consequently, the BaseException
class has been removed, along with EngineException and
ParseException. While these latters could be implemented (not as
is), we prefer to, so far, only implement the Throwable interface.
Let see if we can implement (still for the retro-compatibility) the
Error, TypeError and ParseError class.
[1]: https://wiki.php.net/rfc/engine_exceptions_for_php7
[2]: rfc/throwable-interface
I was curious, so I looked it up. Hoa indeed has a broken approach, having the file Core.php always included, by a "file" autoload in composer which in turn includes Consistency.php. The latter defines your class.
You could raise an issue with the developers at Hoa, to use class_exists to check for the method rather than the currection version check they are using. This could cause the propel autoloader to load its own. Another way would be to define their autoloading correctly, but they prefer to load manually as it seems.
After updating to Symfony 2.7 I've got deprecated notification in my profiler. Here it is:
It looks like an internal Symfony stuff. Any ideas about how to fix it or it will be fixed in next Symfony patches?
It seems that the issue is located at the "AllowedMethodsRouterLoader" class. This might be an external bundle, so you might be able to update this bundle. If it's your own class, it's as easy as just changing it to using ->getPath() instead of using the ConfigCache instance as a string.
Hi i am trying to use Sign me up Plugin for my application. But unable to get it running. There are so many issues and errors.
Plugin i have downloaded is:-
sign_me_up-2.0
But there are so many errors i am getting
Ex:- Declaration of SignMeUpComponent::initialize() should be compatible with Component::initialize(Controller $controller)
I have tried for tutorials and serached for solutions online. But no luck...
Can anyone help me out on how to use this plugin ???
What i reffered :-
http://www.jotlab.com/2011/sign-me-up-a-cakephp-registration-plugin
Thanks in advance
Make sure your version of CakePHP is compatible with the plugin. I understand between version 1.3 and 2, they took advantage of the newer features of PHP which included strongly-typed method parameters. The error you're receiving is that the SignMeUpComponent inherits from the Component class which is in framework core. If the component wants to override the initialize method, it must follow the same method/function signature.
If the plugin is on Git and you feel comfortable in doing so, clone it and update all the components methods, and then put in a pull request so you're changes can be merged in.
Alternatively use an earlier version of CakePHP.
After inheriting some Zend Framework code it didn't work, after lots of fiddling I've managed to create the schema and rebuild the models, although now I'm getting the following error:
Call to undefined method Criteria::hasSelectClause() in home/richard/library/om/BaseDomainPeer.php on line 329
Why would propel generate files that call unknown methods?
I would think that you have a name collision and you load some other class called Criteria and you don't realize it because of autoloading. Try dumping the methods using get_class_methods()
Turns out the code was built on a system using the beta version of propel, when i forced my system to use the beta version, it worked.
to use the beta version, go here