Files organization Symfony 3 - php

I am starting a migration project from cakephp 2 to Symfony 3. I am trying to find the best organization for the different functions for my code.
In cakephp I have very simple organization: I used model, view and controller. On this point no problem with Symfony (same organization). But I also have 5 php libraries with only one or two function in each, and 3 object classes not linked to database. In cakephp all this files are in the Lib folder.
Where can I create and use this libraries and classes in Symfony (not in a new bundle)?

Related

Symfony 4 include another project from different directory

So, I have an application that consists of 5 different projects.
Each of the projects is a new Symfony 4 project, since I need to host them on separate domains.
My structure is like this:
Admin project: /var/www/html/admin
Client project: /var/www/html/client
Owners project: /var/www/html/owners
Each of the project has its own symfony skelet (src,public,config,bundles,public, etc...)
I know this can be done through bundle, but, what I want to do is to create a new Symfony project (Common) and use it accross all the others. Since ill be having same entities and same common services through projects, I need to include it in each of them.
Is there a way to include this Common project into all others and use services/entities from there?

Components, Extension or Module in Yii 2?

I am new to yii and using version 2. I developed a project which uses a library (I coded) for parsing a CAD model file, extract vertexes, edges, faces etc, finally combine those entities to display the model and then extract features. It displays the model using the three.js library. A user has to be signed-in in order to upload the model file and do all this stuff. I would like to refactor the app into version 2 using the yii 2 framework. So I would like to know how I can merge the feature recognition library into the yii app, should I create a Components, Extension or Module or use other means?
The library is coded in plain OOP. I access it by requiring an init.php file which requires about 20 library class files. If I create a module for the library the view will draw the model but where do the parser and feature extractor go in the model or controller files?
Thanks in advance.
In Yii 2 basically everything is a component.
Extension is the term usually used for the vendored components (or modules) available at packagist.org (or similar) so if you are not planning to release it outside you don't have to worry about extension-ing it.
Now for the component-module debate - module is a component that allows you to use it's own controllers structure so if you need something like this - use module. In any other case simple component is just fine.

Multiple Laravel websites, central codebase

I want to create a single Laravel installation that comprises the core functionality of the websites - for example content CRUD functions.
Then on top of this in separate folder on the server for each website have the public folder, css, images etc as well as overriding controllers, models and routes that can be used for specific features per site.
I have achieved the same previously using FuelPHP but have not been able to see where this would be setup in Laravel.
The kind of server folder structure I was anticipating is as below:
/Laravel Core Installation
/app
/vendor
storage
etc
/The first website
public
app (in here would be controllers and models that extend the controllers and models from the Laravel Core Installation folder)
config
etc
/The second website
public
app (in here would be controllers and models that extend the controllers and models from the Laravel Core Installation folder)
config
etc
What you are referring to is called multi tenancy.
Multitenancy refers to a software architecture in which a single instance of a software runs on a server and serves multiple tenants.
http://en.wikipedia.org/wiki/Multitenancy
There are several packages that assist with multi tenancy for Laravel, based on your needs. Some work with seperate database table prefixing, others with completely seperated databases and files.
Some of those packages:
Tenanti
AuraEQ
Hyn *
* Disclaimer; I wrote the last package from this list.

Symfony2 manage multiple databases (from other framework)

I have a problem. My client wants to have a website in one symfony framework package and the CMS integrated in the other Symfony framework (Service Panel of the company).
So, we have Symfony A and B.
Now that there is a blog on the website (Symfony A) among a few other dynamic pages. All the Delete, add and update stuff needs to go into the service panel (Symfony B) with forms and such.
I know I can use multiple Entity Managers, but that'll only work if the website bundle is placed in the service panel framework (Symfony B), because of the mappings. I think it isn't possible, but they really want to have the CMS in their Service panel and the website in another symfony framework instance.
Is there a 'remote' solution, so that Symfony B (service panel) can change and manage the database of the website (Symfony A) without migrating the website bundle (Symfony A) into Symfony B? The website will run on the same machine as the service panel will. Only difference is they are completely separated of each other.
If I'm not clear enough, please tell me. I'm trying to be as clear as possible.
Hope somebody is able to help me with the issue.
So let's say we want to update a blog.
Symfony A would process these requests:
GET /blog/42 - Returns json rep of blog 42
PUT /blog/42 - Accepts and updates blog 42
Easy enough. FOSRestBundle and JMSSerializerBundle can help with some of the plumbing.
So Symfony B uses curl (probably) to GET /blog/42 and converts the json data to a php array.
At this point you have a major decision. If the entities are simple and stable the Symfony B could just use the array representation. Symfony forms accept arrays no problem. So this maybe all you need.
If however you want to convert the array data into a real Blog object that matches Symfony A then you need to make some more decisions. The Symfony A entities are really just plain objects. You could tweak Symfony B's autoload so it can see the Symfony A entities. So B can get the entities from A (and then map the array data to the entities) without having any direct links. Autoload just needs to know where the Symfony A entities live.
Or you could go one step further and make a BlogModelBundle in which the blog entities (without any doctrine stuff) are defined. You would then have both applications load this bundle. The A app would then extend the model and add the doctrine 2 stuff. The B app would just hydrate the models using json. This is probably the best approach for the long term.

Symfony 2 and projects

Let's consider I have different projects for my company. What is the best practice concerning symfony 2 ?
1. Add new bundle for each project in the same symfony 2 skeleton (there could be several bundles for one project: even shared bundles between differents project)
2. Add a new Symfony 2 skeleton for one project (there could be several bundles for one project)
if way number 1 is acceptable, is there a maximum number of bundles for one symfony 2 skeleton ?
A Bundle is a logical component in your website like a backend or a menue. You should build your bundles global that you can use it in new projects.
I would prefer to make more instances and build bundles that were included in your projects (vendor folder). Then you have single components and can use it in new projects.
The advantage is that you can have different versions in different projects. Perhaps you need another version of a bundle in Project A and Project B. Thats its a bit complicated with one instance.
When need to scale your website its better to have more instances to put it on different servers. When you have only one instance with all projects then you need everytime the complete sources.
You can build your own composer packages to update and deploy over composer.
https://packagist.org/
I think there are some more package builder.

Categories