Add requirement to Symfony system - symfony

In my Symfony project I'm using OpenSSL to encrypt/decrypt data. I can check if the cipher method that I want to use is avilable using openssl_get_cipher_methods(), but I dont want to perform this check everytime I run my code.
On the other hand Symfony has a way to check the system requirementes needed to run the project: https://symfony.com/doc/3.4/reference/requirements.html.
Is there a way I can add a new system requiremente to be checked? This way I could check for the available cipher just once and not everytime.

Symfony requirements checker is part of Symfony distribution bundle and it is static.
However you can use Composer scripts to perform required tasks upon install update or you can implement Symfony cache warmer that will perform required tests during Symfony cache building process that is essential part of every Symfony application.

Related

How to user symfony-cmf/simple-cms-bundle in symfony3

I want to use symfony-cmf/simple-cms-bundle in symfony3.2 but It's support only symfony2. So I am looking to avoid check version at the time of development and will update on production.
Is it possible by pass validation through any configuration or command for temporary basis into composer or any other place.

MVC via Symfony

There is a project in Symfony, who want to remake using MVC. The project has controllers and twig patterns , it is only necessary to fasten model.In which Symfony project directory to properly create model files ? Is there anything in Symfony tool allows to do it , rather than just to create these files and to connect them to the controller ?
Use Symfony standard edition as your starting point. If you try to make something own without prior experience with code organization in Symfony you will make it only worse.
https://github.com/symfony/symfony-standard
Standard edition above 2.8 version is pretty slim and doesn't force you to use everything if you don't need to.
If you need only "Model" classes then create them in src/AppBundle/Model and if you need Entities that will be persisted in database put them in src/AppBundle/Entity. Read about generation here http://symfony.com/doc/current/doctrine.html I will help you started

How can I get the Doctrine entity metadata before compiling Symfony container?

In one Symfony bundle I define a compiler pass to preprocess some configuration. Part of that config is based on Doctrine entities, so I need to get the full metadata information for all application entities.
The compiler pass is executed very late (PassConfig::TYPE_BEFORE_REMOVING). I'm using $container->get('doctrine') like this to get the entity metadata:
$em = $container->get('doctrine')->getManagerForClass($entityClass);
$entityMetadata = $em->getMetadataFactory()->getMetadataFor($entityClass);
However, this is causing random failures for some users because of the use of the doctrine service during the Symfony container compilation.
I'd recommend to change your entities addressing. Mainly - create your models with interfaces and make entities implementing them.
Using resolve_target_entities Doctrine will "convert" them to the particular classes.
An example code is here: https://github.com/Sylius/SyliusResourceBundle/blob/master/DependencyInjection/Compiler/DoctrineTargetEntitiesResolverPass.php
Just make sure your bundle is registered before DoctrineBundle is registered.
Then - in your whole app - instead of AppBundle::Entity addressing, use FQDN of interface bound to an entity earlier.
I've experimented a bit with compilers and services and it's a very bad idea to base on cross-bundle services under compiling container process... Why? It's not reliable - sometimes it will work as you want, sometimes it will fail as you described.
Thank you all for your comments and ideas. I post an answer to explain how I solved this problem.
Trying to use the Doctrine service in a compiler pass was creating more and more problems for our users (and it was creating other minor issues with other services such as Twig). So this was definitely a bad solution for our needs.
So at the end I decided to change everything. We no longer use a compiler pass to process the configuration and instead we use a regular PHP class called during runtime.
In the dev environment, the configuration is processed for each request. It's a bit slower than before, but we prevent any caching issue. In the prod environment we use Doctrine Cache to process the configuration once. Besides, we've create a cache warmer to create the cached configuration before the first request hits the application.

Equivalent of Laravel Seeders on Symfony?

I'm developing a web site with Symfony. I'm new on this framework. Before i used Laravel 5.0 and I need to have a database with rows.
I create my db with command prompt but now I don't find how to seed it.
There is a equivalent of Laravel seeders on Symfony?
No. Seeding was a feature added by Laravel. You’ll need to use a third-party package to load seeds/fixtures into your application: http://www.sitepoint.com/data-fixtures-symfony2/
All the answers here are a bit outdated and this question is the first result on google so for future readers:
Since Symfony 3 there is an official bundle for this very purpose
Installation: composer require --dev doctrine/doctrine-fixtures-bundle
Then write your fixtures in src/DataFixtures and run php bin/console doctrine:fixtures:load
Try this package https://packagist.org/packages/evotodi/seed-bundle. Looks like it's what you need.
Their readme
Symfony/Doctrine Seed Bundle
Used to load/unload seed data from the database. Example would be to load a table with a list of states and abbreviations, or populate the users table with initial admin user(s). Unlike the DoctrineFixturesBundle which is mainly for development this bundle is for seeding the database before the initial push to production.

Installing sfGuard without changing db

I am to integrate sfGuard plugin with existing application. What I want to do is to keep as much code as possible untouched. Any guides? It'd be perfect if I can use actual database schema, or bind it somehow to be used by sfGuard. I know about setting userProfile class but I'm not sure how should I get to it, not to destroy my app.
Greetings
Just install plugin. And try make migrations. doctrine::generate-migrations-diff
php symfony doctrine:generate-migrations-diff
And migrate php symfony doctrine:migrate :
php symfony doctrine:migrate
Check out question: Rebuild model without loss data in MySQL for Symfony

Resources