Cleaning a Symfony project and installing a new bundle - php

Im very new to Symfony, yet Im already familiar to the MCV model, after a while reading the documentation I have now the standard edition of Symfony 2 running on my server.
Fresh start
As you know Symfony comes with a hello world app and some welcome scripts, how can I clean all of that?, even better, is there a way to install a Symfony project without the examples bundles?
Data base structure restore
In the past, every time I developed an app with database, I created the structure of the tables using phpmyadmin and then an initial php script that restore that database if I need to install my app on other server. Working with Symfony is quite different, I read that it use doctrine and the Symfony core restore the database format using some internal files. I have a bundle that I need to install, I know that this bundle/app use MySQL, I set the config file with all my MySQL information but I dont know how I can run a sript that will restore a clean database needed for that particular app. I know it has something to do with php app/console schema:update but not so sure.
Thanks for any orientation.

how can I clean all of that?, even better, is there a way to install a Symfony project without the examples bundles?
There is no way to do that in Symfony2 and it looks like it never become a part of the Symfony2 project:
"I think that we need clear instructions on how to remove the Acme demo code by hand. I'm -1 on added a CLI command to do that automatically."
-- fabpot on github
The things you should do:
Remove the src/Acme directory
Remove $bundles[] = new Acme\DemoBundle\AcmeDemoBundle(); (line 25) in app/AppKernel.php
Remove the related routes from app/config/routing_dev.yml (_welcome, _demo_secured and _demo)
You can remove everything in the security: key in app/config/security.yml and place enabled: false in it. However, this isn't needed and it works like a nice boilerplate for your own security
Your other question: Symfony2 don't have a 'view' layer. You can choose to use whatever you want. But Symfony2 included 2 ORMs in their framework by default, Doctrine and Propel. You can read more on how to work with these libraries in the documentation: Doctrine and Propel.

Related

Created new Symfony 3.4 project using Flex - Is this really Symfony 3.4?

The question:
Is a Symfony 3.4 project created with the Flex installer really Symfony 3.4? Or more a "Symfony 4 project with 3.4 core files?
The complete story:
I am working on migrating an existing Symfony 2.8 project to Symfony 3.4. At first I created a new Symfony 3.4 project using the Symfony installer:
symfony new MyProject 3.4
The file and folder structure is a bit different to Symfony 2.8 but overall everything is quite similar. It was not too difficult to migrate the config, files, etc. from the existing 2.8 project.
However, after some more research I thought it might be a good idea to start the new 3.4 project using the recommended Flex installer instead. This would give me the new folder structure which is also used in Symfony 4, which might make a future migration to this version easier.
composer create-project symfony/skeleton:3.4.* MyProject
Of course the directory structure is different in this project. But not only the folders are different but almost everything. The way the complete config is organized, how the routes are defined and managed, how bundles are organized (none at all), how parameters are defined and used, etc.
There is almost nothing left that looks like Symfony 3.4. This seems to be a Symfony 4 setup where only the files in vendor/symfony/... are from version 3.4
Migrating the 2.8 project to this setup would be way more complex.
Of course I know that a lot has changed in Symfony 4 while Symfony 3.4 is still quite similar to Symfony 2.8. But how is it possible that two Symfony 3.4 installations are so dramatically different?
I understood that Flex is a new workflow to manage projects but shouldn't be the end result - a new Symfony 3.4 project - be more or less the same no matter which workflow / install was used to create it?
Flex is more powerful when setting up and managing different project. However I want to setup the project once and run it for several years. Is there any advantage (in the near future) in proceeding with the Flex approach?
To answer your first question: Yes, a Symfony 3.4 project created using Flex is indeed a 3.4 project. "bin/console --version" will verify this.
As far as the directory structure goes, Symfony tries to strike a balance between maintaining backwards compatibility but at the same time keep moving forward and refining their design. For information on why things were done, it is useful to keep an eye in the Symfony blog and perhaps visit the slack channel. Especially the posts when Flex was introduced as well as the new directory structure.
One goal for Symfony is to make it as easy as possible to migrate from a long term support version to a newer version. Hence 2.8 is pretty much identical to 3.0 except that a bunch of depreciated functionality was removed. If you were following things at the time you would have noticed that there was quite a big jump between 2.7 and 2.8.
Same for 3.4 to 4.0 being easy but a few possible bumps going from 3.0 to 3.4.
Kind of meandered a bit. Sorry.
To address your second question of the value of using Flex, like all opinion based questions the only correct answer is: it depends.
In my case the choice to use the new directory structure was easy. I have a number of apps and use Symfony on a daily basis. Keeping up with the latest and greatest makes sense for me. Spending the time to port apps (some of them dating back to 2.3) to 4.0 makes my overall maintenance burden easier. The time spent experimenting how to port helped me understand the new functionality. Once I got comfortable with the process it was really just copy/paste/rename exercise for the most part. The hardest was making sure some of the 3rd party dependencies were properly updated.
In your case, it seem like you only have one app and you just want to get it updated and then forget about it for a few years. In that case, keep the old structure and move on. At some point you might need to move to the new structure but waiting a few years won't hurt anything. And hey, I suspect 5.0 will introduce more changes.
The choice is yours.
Symfony Flex is the new way to install and manage Symfony applications. Flex is not a new Symfony version, but a tool that replaces and improves the Symfony Installer and the Symfony Standard Edition.
Symfony Flex automates the most common tasks of Symfony applications, like installing and removing bundles and other Composer dependencies. Symfony Flex works for Symfony 3.3 and higher. Starting from Symfony 4.0, Flex should be used by default, but it is still optional.
Source : https://symfony.com/doc/3.4/setup/flex.html

Symfony bundle configuration

I've just started working with Symfony and have run into a problem that I'm having a hard time tracking down information about.
I'm trying to create a bundle which has its own configuration file, e.g. configuration for doctrine connections.
All documentation I've found have never mentioned of showed how this can be set. Is it possible?
What I want to solve:
I have a bundle which when installed should handle connection to a secondary database table without any configuration needed from the main application in which the bundle has been integrated. Ultimately the configuration in the bundle should be override-able from the main application.
The bundle should be in the lack for a better work "self contained".
I've found documenation about bundle configuration. But all I've seen mentioned there is if one would like to configure the bundle and not interaction with other components (might have missed something).
tl;dr I want to have a config (e.g. AppBundle/Resources/Config/config.yml) file inside a bundle which can configure things like doctrine.
What i've tried
I've tried placing the configuration inside a config.yml file located in Resources/Config/. But I guess the file is never read.
I think it is not good idea to put something related to configuration right inside your bundle and ruin it's reusability by doing such thing. As far as I understood your task what your really need is to configure second entity manager to manage entities from secondary database when you need them. Same problem and its solution are described in following question: Doctrine 2 - Multiple databases configuration and use
Hope that will help!

Upgrading Doctrine from 2.0.6 to 2.3

I am trying to upgrade the Doctrine library in my Zend application from version 2.0.6 to 2.3. I assumed this would just involve copying the over the newer library files over the existing library - provided there are no major changes which would require me to change my application code.
However, I downloaded a zip from their GitHub page and found that the directories in the 2.3 differ greatly to the Doctrine version I currently have installed (consists of Common, DBAL, ORM and Symfony folders whereas 2.3 is completely different). I can't find anything on the difference in these folders, maybe I'm just really slow.
In my existing set up, I am not using any third party libraries to integrate Doctrine, most of it is done through autoloading in Bootstrap.php.
After several unsuccessful attempts to upgrade the Doctrine library, I decided to follow this tutorial based on the assumption that it will handle the unfamiliar directory structure of the Doctrine I downloaded. However further down the page this tutorial also refers to the Doctrine library as having the four folders that I have in my existing set up, which doesn't match the newer version of Doctrine.
Would sincerely appreciate it if someone could point me in the right direction or tell me where I am going wrong.
ps I am using Zend 1.11
I see three ways:
Use composer.
You can use Doctrine as Git Submodule. You'll get only Doctrine\ORM. Other libraries you get through its Submodules.
Download all the libraries separately: Doctrine\ORM, Doctrine\Common, Doctrine\DBAL, Symfony\Component\Console, Symfony\Component\Yaml

How to create a generic way to load files?

I'm new to Symfony2, even though I knew symfony 1.4.
In my new project, I need a way to be able to load data from various text files (csv, xml, other), from various locations, in the most generic way possible, i.e. adding a new file to be checked should only require some configuration.
What's the symfon-iest way of doing that ?
Whilst I don't know of the implementation details for Symfony specifically; Gaufrette is a good PHP5 file system layer abstraction layer and they provide a Symfony bundle so it should be easy to get up and running. There are also details on getting it going on Symfony 2 in the read me documentation (scroll down).
You can easily add your own drivers for other file systems such as S3 (already implemented in base package).

What php frameworks have database migration support?

I'm looking for a good php framework with support for handling database migrations. Ideally I would like to be able to run a command that generates a migration script, one that updates the database with changes and can handle rolling back those changes. Is there anything out there that does this?
The Doctrine project supports migrations - http://www.doctrine-project.org/projects/migrations/2.0/docs/reference/introduction/en
Hmm, that documentation is a bit lacking, at least in the introduction. Hopefully it gets better as it goes on.
Whilst most popular in Symfony, this can easily be integrated into other frameworks or even used on its own.
Promising, but not yet have a stable version : https://github.com/fuel/fuel
There is a new php framework called Laravel and it has migrations the same way as ruby on rails. It seems so pretty!
You can find it at http://laravel.com/
Migrations Docs
In addition, the framework introduces the idea of bundles, what can give to your project a great modular view.
If you try it, tell us your experience! :)
symfony - http://www.symfony-project.org/
In symfony you can write database schema using ORM like Propel, it is independant from database driver. If you have a database already, you want to migrate to a different db, I think you can dump the db, change the db config, and re-import it to the new db. (though I have not tried it myself.)
There are much php framework over there that can use any database. For example Zend, Ci, Cake and many others. One thing you should do is change database type that's usually stored in configuration file. And then migrate your database manually. No framework that can generate migration script automatically. U can also use ESF for database migration

Categories