Use Symfony 2 component in non-Symfony project?
Manage your dependencies with composer.
First create a composer.json
file in your project folder :
{ "require": { "symfony/translation": "2.4.*" }}
Then download composer and run it :
wget http://getcomposer.org/composer.pharphp composer.phar install
You can now use your component by importing the composer autoloader :
<?php require_once('vendor/autoload.php'); use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\MessageSelector; use Symfony\Component\Translation\Loader\ArrayLoader; $translator = new Translator('fr_FR', new MessageSelector()); $translator->setFallbackLocales(array('fr')); $translator->addLoader('array', new ArrayLoader()); $translator->addResource('array', array( 'Hello World!' => 'Bonjour', ), 'fr'); echo $translator->trans('Hello World!')."\n";
What about using Composer to manage your dependencies.
The point here is that it also manages autoloading,
From the documentation,
Autoloading#
Besides downloading the library, Composer also prepares an autoloadfile that's capable of autoloading all of the classes in any of thelibraries that it downloads. To use it, just add the following line toyour code's bootstrap process:
require 'vendor/autoload.php';