How to include Symfony2 components within a symfony 1.4 application - php

I have an application written in symfony 1.4, and I'd like to use the Symfony2 Serializer component. Is it possible to begin with ? And what should I do to be able to do this ?

Symfony2 is composed of two main features: component and bundle. You are mixing this two concept in your question. Components are stand-alone and thus independent of each others, but can optionally make use of other components to enhance their possibilities. On the opposite, bundles usually use components to achieve their tasks. They can be dependent of each others and they all depend on the FrameworkBundle. The FrameworkBundle ties together multiple components, it's a kind of glue between components. The FrameworkBundle with other bundles like DoctrineBundle and the components form Symfony2.
Since Symfony2 components are stand-alone they can be used with any projects. There is no reason why it would not be possible to use the Serializer component within symfony 1.4.
There is not much documentation on using components of Symfony2 independently. I know they have a PEAR channel so it is simply a matter of getting the library via PEAR and add entry to the autoloader and use classes defined in the component.
I didn't see any README for the serializer component, you may need to look at the code to check how you can use it. Here some links to documentation related to the subject, not specially on serializer.
Symfony2 components page: here
Symfony2 PEAR channels: here
Serializer component github: here
Fabien Potencier's blog on what is Symfony2: here

Related

How to make a microframework version of Laravel?

I'm thinking about making a stripped-down version of Laravel that can be used as a micro-framework, kinda like the Silex of Symfony world.
I guess i need to use the Illuminate\Routing component of Laravel (available via Packagist) and make a new Router instance and then call ->dispatch on the router with a Request object but i'm not quite sure if that's the right way to do it.
I'd appreciate your suggestions/solution.
This Mohammad Gufran's blog post entitled "DRIVE YOUR APPLICATION WITH ILLUMINATE ROUTER" could give you a preview of what could be done.
To sum up:
Initialize your project using Composer.
Define the dependencies, namely: "illuminate/routing": "4.1.*" and "illuminate/events": "4.1.*".
Create the "index.php" and "routes.php" files as suggested.
Et voilĂ !
Excerpt from routes.php:
$app['router']->get('/', function() {
// Because 'Hello, World!' is too mainstream
return 'Are you looking for me ?';
});
Lumen "The stunningly fast micro-framework by Laravel" came to light.
Excerpt:
<?php
/**
* Reimagine what you expect...
*/
$app->get('/', function() {
return view('lumen');
});
/**
* From your micro-framework...
*/
$app->post('framework/{id}', function($framework) {
$this->dispatch(new Energy($framework));
});
Well, in order to make "stripped" version of Laravel you will have to dig deeper. Laravel is made of couple of proven architectural and design patterns.
Inside we can find:
Service oriented architecture in the form of Service Providers
Of course client/server implementation in the form of extending
Symfony HTTP components
Clever usage of Event driven design
Communication with app through CLI commands
MVC specific implementation with Blade templating and Eloquent ORM in
the DB layer.
Router as standalone unit.
Levereging Composer package capabilities.
And finally, in Laravel,everything is connected together with custom Application layer. I am fascinated with Laravel design. There is no framework that taught me more. So, to answer you question - it is possible to create your version of Laravel, but better solution is to accept what is Laravel offering, join community and improve it with you own ideas.
Laravel released Lumen, the official micro-framework for Laravel. It uses nikic/fast-route for routing instead of Symfony's Routing component for better performance.
Actually Laravel uses Symfony components (along with others) and the HTTP Foundation is built on Symfony HTTP Foundation and router is also from Symfony.
So, instead of digging into Laravel, check the Symfony components and you may easily build a micro framework using Symfony components (utilizing the composer).
For building the Foundation you may need these components:
HttpFoundation
Routing
HttpKernel
Read the manual, it's easy and you can make it easily and also follow the framework's source that used Symfony components to get an idea how to use these components.
Have a look Micro Version of Laravel Framework here.

Why are there two Cookie classes in Symfony 2?

Why are there two different, yet extremely similar classes in Symfony to represent a browser Cookie?
Symfony\Component\HttpFoundation\Cookie and Symfony\Component\BrowserKit\Cookie
First you need to understand what Symfony components are.
Symfony Components implement common features needed to develop websites. They are the foundation of the Symfony full-stack framework, but they can also be used standalone even if you don't use the framework as they don't have any mandatory dependencies.
They don't have any external dependencies, meaning that any dependency will be bundled with the component.
HttpFoundation\Cookie is a Cookie class used by the HttpFoundation component. And BrowserKit\Cookie is a class used by the BrowserKit component. They are small bundled dependencies of each of the components. You should use the component, not an individual class inside it.
The purpose of these two components are
BrowserKit Simulates the behavior of a web browser.
HttpFoundation Defines an object-oriented layer for the HTTP specification.
Decide which components to use according to your scenario.

Why should not a Symfony2 bundle embed third-party libraries

Bundle Structure and Best Practices:
A bundle should not embed third-party libraries written in JavaScript,
CSS, or any other language.
Why shouldn't i create for example a bootstrap, or jQuery bundle?
I think it would be easier to maintain if all third-party CSS and JavaScript libraries live in their own bundle.
Well, for one, It's counter-intuitive. Symfony Bundles are for packages of PHP functionality and you're talking about bundling up front-end libraries.
Secondly - why would it be easier? Things like bootstrap and jQuery are public resources to begin with - they don't need a distributable bundle to achieve high re-use. PHP resources are not public and therefore benefit from this type of system.
The chaos comes when two or more bundles uses the same 3rd party library but different versions. A user of your bundle won't be able to choose which library to include and therefore can't use both bundles at the time.
It's fine to store them in a bundle folder if your bundle is a standalone application, i.e. your application's main bundle. For example, SonataAdminBundle includes 3rd party libraries: bootstrap.css, qtip, famfamfam icons.
look at MopaBootstrapBundle https://github.com/phiamo/MopaBootstrapBundle it integrates TwitterBootstrap & jQuery lib for you, also HTML5BoilerPlate if you enable initializr addon.

Confused with symfony2 bundles

I am little bit confused with symfony2 bundles.
I want to know that does everything in symfony is bundle including main application.
I was thinking as Core of site is somewhere i can write code to use bundles like we use plugins from main application code.
Or there is no core thing in Symfony . The core itself will be bundle
you can define your website completely as a bundle, meaning
Mycompany/MywebsiteBundle
Or you can define the different, sections of your website as different bundle, which i personally preffer
`Mycompany/ForumBundle
Mycompany/BlogBundle
Mycompany/NewsletterBundle`
Symfony2 is bundle-based framework
=> So, everything, as well as the core itself is a bundle.
You can see which bundle is loaded by default in app/AppKernel.php.
But Symfony2 does also include a library, organized by "components (vendor/symfony/src/Symfony/Components). Code in bundle can use this library..
Indeed, everything is a bundle. As per Symfony2 docs:
http://symfony.com/doc/2.0/book/page_creation.html#page-creation-bundles

Symfony2 Bundle System

I'm just working through the Symfony2 Bible and I'm a little stuck on the bundle system. It is a great feature but I'm not quite sure how to split my flat PHP application into bundles. It's my first time splitting my PHP code into a full featured MVC framework.
I'm working on a few online games (based on PHP) but how would I define the bundles ? Is it like one single onlinegame1 bundle with all the controllers and functions - Or like a login bundle, a register bundle, a war bundle - summarized one bundle for every single PHP file I got ?
I want to start clean and correct but I'm not quite sure if I understand that feature.
You could think of bundle as an independent reusable component - in most of the cases at least.
Let's imagine a personal blog website. I'd split it into ArticleBundle, UserBundle, CommentBundle and finally MainBundle which would stick all these other bundles together, creating your website. The main point is that you can take for example ArticleBundle and reuse it easily on other project without it being tied to any other bundle.
From Symfony2 book:
A bundle is similar to a plugin in other software, but even better.
The key difference is that everything is a bundle in Symfony2,
including both the core framework functionality and the code written
for your application. Bundles are first-class citizens in Symfony2.
This gives you the flexibility to use pre-built features packaged in
third-party bundles or to distribute your own bundles. It makes it
easy to pick and choose which features to enable in your application
and to optimize them the way you want.

Categories