tweaked the README files
This commit is contained in:
parent
0f2caf1106
commit
997f354d53
@ -1,7 +1,8 @@
|
||||
Doctrine Bridge
|
||||
===============
|
||||
|
||||
Provides integration for Doctrine with various Symfony2 components.
|
||||
Provides integration for [Doctrine](http://www.doctrine-project.org/) with
|
||||
various Symfony2 components.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,7 +1,8 @@
|
||||
Twig Bridge
|
||||
===========
|
||||
|
||||
Provides integration for Twig with various Symfony2 components.
|
||||
Provides integration for [Twig](http://twig.sensiolabs.org/) with various
|
||||
Symfony2 components.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,11 +1,17 @@
|
||||
BrowserKit Component
|
||||
====================
|
||||
|
||||
This component provides classes to simulate a browser for testing.
|
||||
BrowserKit simulates the behavior of a web browser.
|
||||
|
||||
The component only provide an abstract client and does not provide any
|
||||
"default" backend for the HTTP layer.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
Unit tests:
|
||||
For a simple implementation of a browser based on an HTTP layer, have a look
|
||||
at [Goutte](https://github.com/fabpot/Goutte).
|
||||
|
||||
https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/BrowserKit
|
||||
For an implementation based on HttpKernelInterface, have a look at the
|
||||
[Client](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Client.php)
|
||||
provided by the HttpKernel component.
|
||||
|
@ -1,41 +1,60 @@
|
||||
ClassLoader Component
|
||||
=====================
|
||||
|
||||
The ClassLoader component provides an autoloader that implements the PSR-0 standard
|
||||
(which is a standard way to autoload namespaced classes as available in PHP 5.3).
|
||||
It is also able to load classes that use the PEAR naming convention. It is really
|
||||
flexible as it can look for classes in different directories based on a sub-namespace.
|
||||
You can even give more than one directory for one namespace:
|
||||
ClassLoader loads your project classes automatically if they follow some
|
||||
standard PHP conventions.
|
||||
|
||||
```
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
The Universal ClassLoader is able to autoload classes that implement the PSR-0
|
||||
standard or the PEAR naming convention.
|
||||
|
||||
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||
First, register the autoloader:
|
||||
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->registerNamespaces(array(
|
||||
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
|
||||
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
|
||||
'Doctrine\\DBAL' => __DIR__.'/vendor/doctrine-dbal/lib',
|
||||
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
|
||||
'Monolog' => __DIR__.'/vendor/monolog/src',
|
||||
));
|
||||
$loader->registerPrefixes(array(
|
||||
'Twig_' => __DIR__.'/vendor/twig/lib',
|
||||
));
|
||||
$loader->register();
|
||||
```
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
|
||||
Most of the time, the Symfony2 ClassLoader is all you need to autoload all your project classes.
|
||||
And for better performance, you can use an APC cached version of the universal class loader or
|
||||
the map class loader.
|
||||
use Symfony\Component\ClassLoader\UniversalClassLoader;
|
||||
|
||||
Furthermore it provides tools to aggregate classes into a single file, which is especially
|
||||
useful to improve performance on servers that do not provide byte caches.
|
||||
$loader = new UniversalClassLoader();
|
||||
$loader->register();
|
||||
|
||||
Resources
|
||||
---------
|
||||
Then, register some namespaces with the `registerNamespace()` method:
|
||||
|
||||
Unit tests:
|
||||
$loader->registerNamespace('Symfony', __DIR__.'/src');
|
||||
$loader->registerNamespace('Monolog', __DIR__.'/vendor/monolog/src');
|
||||
|
||||
https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/ClassLoader
|
||||
The `registerNamespace()` method takes a namespace prefix and a path where to
|
||||
look for the classes as arguments.
|
||||
|
||||
You can also register a sub-namespaces:
|
||||
|
||||
$loader->registerNamespace('Doctrine\\Common', __DIR__.'/vendor/doctrine-common/lib');
|
||||
|
||||
The order of registration is significant and the first registered namespace
|
||||
takes precedence over later registered one.
|
||||
|
||||
You can also register more than one path for a given namespace:
|
||||
|
||||
$loader->registerNamespace('Symfony', array(__DIR__.'/src', __DIR__.'/symfony/src'));
|
||||
|
||||
Alternatively, you can use the `registerNamespaces()` method to register more
|
||||
than one namespace at once:
|
||||
|
||||
$loader->registerNamespaces(array(
|
||||
'Symfony' => array(__DIR__.'/src', __DIR__.'/symfony/src'),
|
||||
'Doctrine\\Common' => __DIR__.'/vendor/doctrine-common/lib',
|
||||
'Doctrine' => __DIR__.'/vendor/doctrine/lib',
|
||||
'Monolog' => __DIR__.'/vendor/monolog/src',
|
||||
));
|
||||
|
||||
For better performance, you can use the APC based version of the universal
|
||||
class loader:
|
||||
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
|
||||
require_once __DIR__.'/src/Symfony/Component/ClassLoader/ApcUniversalClassLoader.php';
|
||||
|
||||
use Symfony\Component\ClassLoader\ApcUniversalClassLoader;
|
||||
|
||||
$loader = new ApcUniversalClassLoader('apc.prefix.');
|
||||
|
||||
Furthermore, the component provides tools to aggregate classes into a single
|
||||
file, which is especially useful to improve performance on servers that do not
|
||||
provide byte caches.
|
||||
|
@ -1,10 +1,10 @@
|
||||
Config Component
|
||||
================
|
||||
|
||||
This component provides infrastructure from loading configurations from different
|
||||
data sources and optionally monitoring these data sources for changes. There are
|
||||
additional tools for validating, normalizing and handling of defaults that can
|
||||
optionally be used to convert from different formats to arrays.
|
||||
Config provides the infrastructure for loading configurations from different
|
||||
data sources and optionally monitoring these data sources for changes. There
|
||||
are additional tools for validating, normalizing and handling of defaults that
|
||||
can optionally be used to convert from different formats to arrays.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,40 +1,44 @@
|
||||
Console Component
|
||||
=================
|
||||
|
||||
Even if we are talking about a web framework, having some tools to manage
|
||||
your project from the command line is nice. In Symfony2, we use the console
|
||||
to generate CRUDs, update the database schema, etc. It's not required, but
|
||||
it is really convenient and it can boost your productivity a lot.
|
||||
Console eases the creation of beautiful and testable command line interfaces.
|
||||
|
||||
This example shows how to create a command line tool very easily:
|
||||
The Application object manages the CLI application:
|
||||
|
||||
```
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Symfony\Component\Console\Application;
|
||||
|
||||
$console = new Application();
|
||||
$console
|
||||
->register('ls')
|
||||
->setDefinition(array(
|
||||
new InputArgument('dir', InputArgument::REQUIRED, 'Directory name'),
|
||||
))
|
||||
->setDescription('Displays the files in the given directory')
|
||||
->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
$dir = $input->getArgument('dir');
|
||||
$console = new Application();
|
||||
$console->run();
|
||||
|
||||
$output->writeln(sprintf('Dir listing for <info>%s</info>', $dir));
|
||||
})
|
||||
;
|
||||
The ``run()`` method parses the arguments and options passed on the command
|
||||
line and executes the right command.
|
||||
|
||||
$console->run();
|
||||
```
|
||||
Registering a new command can easily be done via the ``register()`` method,
|
||||
which returns a ``Command`` instance:
|
||||
|
||||
With only 10 lines of code or so, you have access to a lot of features like output
|
||||
coloring, input and output abstractions (so that you can easily unit-test your
|
||||
commands), validation, automatic help messages, and a lot more. It's really powerful.
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
$console
|
||||
->register('ls')
|
||||
->setDefinition(array(
|
||||
new InputArgument('dir', InputArgument::REQUIRED, 'Directory name'),
|
||||
))
|
||||
->setDescription('Displays the files in the given directory')
|
||||
->setCode(function (InputInterface $input, OutputInterface $output) {
|
||||
$dir = $input->getArgument('dir');
|
||||
|
||||
$output->writeln(sprintf('Dir listing for <info>%s</info>', $dir));
|
||||
})
|
||||
;
|
||||
|
||||
You can also register new commands via classes.
|
||||
|
||||
The component provides a lot of features like output coloring, input and
|
||||
output abstractions (so that you can easily unit-test your commands),
|
||||
validation, automatic help messages, ...
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,34 +1,14 @@
|
||||
CssSelector Component
|
||||
=====================
|
||||
|
||||
This component is a port of the Python lxml library, which is copyright Infrae
|
||||
and distributed under the BSD license.
|
||||
CssSelector converts CSS selectors to XPath expressions.
|
||||
|
||||
Current code is a port of http://codespeak.net/svn/lxml/trunk/src/lxml/cssselect.py@71545
|
||||
The component only goal is to convert CSS selectors to their XPath
|
||||
equivalents:
|
||||
|
||||
Using CSS selectors is far easier than using XPath.
|
||||
use Symfony\Component\CssSelector\CssSelector;
|
||||
|
||||
Its only goal is to convert a CSS selector to its XPath equivalent:
|
||||
|
||||
```
|
||||
use Symfony\Component\CssSelector\CssSelector;
|
||||
|
||||
print CssSelector::toXPath('div.item > h4 > a');
|
||||
```
|
||||
|
||||
That way, you can just use CSS Selectors with the DomCrawler instead of XPath:
|
||||
|
||||
```
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
$crawler = new Crawler();
|
||||
$crawler->addContent('<html><body><p>Hello World!</p></body></html>');
|
||||
|
||||
print $crawler->filter('body > p')->text();
|
||||
```
|
||||
|
||||
By the way, that's one example of a component (DomCrawler) that relies
|
||||
on another one (CssSelector) for some optional features.
|
||||
print CssSelector::toXPath('div.item > h4 > a');
|
||||
|
||||
Resources
|
||||
---------
|
||||
@ -36,3 +16,8 @@ Resources
|
||||
Unit tests:
|
||||
|
||||
https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/CssSelector
|
||||
|
||||
This component is a port of the Python lxml library, which is copyright Infrae
|
||||
and distributed under the BSD license.
|
||||
|
||||
Current code is a port of http://codespeak.net/svn/lxml/trunk/src/lxml/cssselect.py@71545
|
||||
|
@ -1,22 +1,22 @@
|
||||
DependencyInjection Component
|
||||
=============================
|
||||
|
||||
Even the DependencyInjection component is really easy. It has many features, but its core
|
||||
is simple to use. See how easy it is to configure a service that relies on another service:
|
||||
DependencyInjection manages your services via a robust and flexible Dependency
|
||||
Injection Container.
|
||||
|
||||
```
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
Here is a simple example that shows how to register services and parameters:
|
||||
|
||||
$sc = new ContainerBuilder();
|
||||
$sc
|
||||
->register('foo', '%foo.class%')
|
||||
->addArgument(new Reference('bar'))
|
||||
;
|
||||
$sc->setParameter('foo.class', 'Foo');
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
$sc->get('foo');
|
||||
```
|
||||
$sc = new ContainerBuilder();
|
||||
$sc
|
||||
->register('foo', '%foo.class%')
|
||||
->addArgument(new Reference('bar'))
|
||||
;
|
||||
$sc->setParameter('foo.class', 'Foo');
|
||||
|
||||
$sc->get('foo');
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,17 +1,26 @@
|
||||
DomCrawler Component
|
||||
====================
|
||||
|
||||
If you are familiar with jQuery, DomCrawler is a PHP equivalent.
|
||||
It allows you to navigate the DOM of an HTML or XML document:
|
||||
DomCrawler eases DOM navigation for HTML and XML documents.
|
||||
|
||||
```
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
If you are familiar with jQuery, DomCrawler is a PHP equivalent:
|
||||
|
||||
$crawler = new Crawler();
|
||||
$crawler->addContent('<html><body><p>Hello World!</p></body></html>');
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
print $crawler->filterXPath('descendant-or-self::body/p')->text();
|
||||
```
|
||||
$crawler = new Crawler();
|
||||
$crawler->addContent('<html><body><p>Hello World!</p></body></html>');
|
||||
|
||||
print $crawler->filterXPath('descendant-or-self::body/p')->text();
|
||||
|
||||
If you are also using the CssSelector component, you can use CSS Selectors
|
||||
instead of XPath expressions:
|
||||
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
$crawler = new Crawler();
|
||||
$crawler->addContent('<html><body><p>Hello World!</p></body></html>');
|
||||
|
||||
print $crawler->filter('body > p')->text();
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,18 +1,19 @@
|
||||
EventDispatcher Component
|
||||
=========================
|
||||
|
||||
```
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
EventDispatcher implements a lightweight version of the Observer design
|
||||
pattern.
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
$dispatcher->addListener('event_name', function (Event $event) {
|
||||
// ...
|
||||
});
|
||||
$dispatcher = new EventDispatcher();
|
||||
|
||||
$dispatcher->dispatch('event_name');
|
||||
```
|
||||
$dispatcher->addListener('event_name', function (Event $event) {
|
||||
// ...
|
||||
});
|
||||
|
||||
$dispatcher->dispatch('event_name');
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,39 +1,34 @@
|
||||
Finder Component
|
||||
================
|
||||
|
||||
The Finder provides a very convenient and nice fluent interface to find files
|
||||
and directories on the filesystem:
|
||||
Finder finds files and directories via an intuitive fluent interface.
|
||||
|
||||
```
|
||||
use Symfony\Component\Finder\Finder;
|
||||
use Symfony\Component\Finder\Finder;
|
||||
|
||||
$finder = new Finder();
|
||||
$finder = new Finder();
|
||||
|
||||
$iterator = $finder
|
||||
->files()
|
||||
->name('*.php')
|
||||
->depth(0)
|
||||
->size('>= 1K')
|
||||
->in(__DIR__);
|
||||
$iterator = $finder
|
||||
->files()
|
||||
->name('*.php')
|
||||
->depth(0)
|
||||
->size('>= 1K')
|
||||
->in(__DIR__);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
print $file->getRealpath()."\n";
|
||||
}
|
||||
```
|
||||
foreach ($iterator as $file) {
|
||||
print $file->getRealpath()."\n";
|
||||
}
|
||||
|
||||
But you can also use it to find files stored remotely like in this example where
|
||||
we are looking for files on Amazon S3:
|
||||
|
||||
```
|
||||
$s3 = new \Zend_Service_Amazon_S3($key, $secret);
|
||||
$s3->registerStreamWrapper("s3");
|
||||
$s3 = new \Zend_Service_Amazon_S3($key, $secret);
|
||||
$s3->registerStreamWrapper("s3");
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->name('photos*')->size('< 100K')->date('since 1 hour ago');
|
||||
foreach ($finder->in('s3://bucket-name') as $file) {
|
||||
print $file->getFilename()."\n";
|
||||
}
|
||||
```
|
||||
$finder = new Finder();
|
||||
$finder->name('photos*')->size('< 100K')->date('since 1 hour ago');
|
||||
foreach ($finder->in('s3://bucket-name') as $file) {
|
||||
print $file->getFilename()."\n";
|
||||
}
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,13 +1,17 @@
|
||||
Form Component
|
||||
==============
|
||||
|
||||
The Symfony2 Form component provides tools for defining forms, rendering and
|
||||
binding request data to related models. Furthermore it provides integration
|
||||
with the Validation component.
|
||||
Form provides tools for defining forms, rendering and binding request data to
|
||||
related models. Furthermore it provides integration with the Validation
|
||||
component.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
Silex integration:
|
||||
|
||||
https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/FormServiceProvider.php
|
||||
|
||||
Unit tests:
|
||||
|
||||
https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/Form
|
||||
|
@ -1,34 +1,32 @@
|
||||
HttpFoundation Component
|
||||
========================
|
||||
|
||||
The Symfony2 HttpFoundation component adds an object-oriented layer on top of PHP for
|
||||
everything related to the Web: Requests, Responses, Uploaded files, Cookies, Sessions, ...
|
||||
HttpFoundation defines an object-oriented layer for the HTTP specification.
|
||||
|
||||
In this example, we get a Request object from the current PHP global variables:
|
||||
It provides an abstraction for requests, responses, uploaded files, cookies,
|
||||
sessions, ...
|
||||
|
||||
```
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
In this example, we get a Request object from the current PHP global
|
||||
variables:
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
echo $request->getPathInfo();
|
||||
```
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
echo $request->getPathInfo();
|
||||
|
||||
You can also create a Request directly -- that's interesting for unit testing:
|
||||
|
||||
```
|
||||
$request = Request::create('/?foo=bar', 'GET');
|
||||
echo $request->getPathInfo();
|
||||
```
|
||||
$request = Request::create('/?foo=bar', 'GET');
|
||||
echo $request->getPathInfo();
|
||||
|
||||
And here is how to create and send a Response:
|
||||
|
||||
```
|
||||
$response = new Response('Not Found', 404, array('Content-Type' => 'text/plain'));
|
||||
$response->send();
|
||||
```
|
||||
$response = new Response('Not Found', 404, array('Content-Type' => 'text/plain'));
|
||||
$response->send();
|
||||
|
||||
The Request and the Response classes have many other methods that implement the HTTP specification.
|
||||
The Request and the Response classes have many other methods that implement
|
||||
the HTTP specification.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,89 +1,83 @@
|
||||
HttpKernel Component
|
||||
====================
|
||||
|
||||
The HttpKernel component provides the dynamic part of the HTTP specification.
|
||||
It provides the HttpKernelInterface, which is the core interface of the Symfony2
|
||||
full-stack framework:
|
||||
HttpKernel provides the building blocks to create flexible and fast HTTP-based
|
||||
frameworks.
|
||||
|
||||
```
|
||||
interface HttpKernelInterface
|
||||
{
|
||||
/**
|
||||
* Handles a Request to convert it to a Response.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*/
|
||||
function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
|
||||
}
|
||||
```
|
||||
``HttpKernelInterface`` is the core interface of the Symfony2 full-stack
|
||||
framework:
|
||||
|
||||
It takes a Request as an input and should return a Response as an output. Using this
|
||||
interface makes your code compatible with all frameworks using the Symfony2 components.
|
||||
And this will gives you many cool features for free.
|
||||
|
||||
Creating a framework based on the Symfony2 components is really easy. Here is a very
|
||||
simple, but fully-featured framework based on the Symfony2 components:
|
||||
|
||||
```
|
||||
$routes = new RouteCollection();
|
||||
$routes->add('hello', new Route('/hello', array('_controller' =>
|
||||
function (Request $request) {
|
||||
return new Response(sprintf("Hello %s", $request->get('name')));
|
||||
interface HttpKernelInterface
|
||||
{
|
||||
/**
|
||||
* Handles a Request to convert it to a Response.
|
||||
*
|
||||
* @param Request $request A Request instance
|
||||
*
|
||||
* @return Response A Response instance
|
||||
*/
|
||||
function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);
|
||||
}
|
||||
)));
|
||||
|
||||
$request = Request::createFromGlobals();
|
||||
It takes a ``Request`` as an input and should return a ``Response`` as an
|
||||
output. Using this interface makes your code compatible with all frameworks
|
||||
using the Symfony2 components. And this will gives you many cool features for
|
||||
free.
|
||||
|
||||
$context = new RequestContext();
|
||||
$context->fromRequest($request);
|
||||
Creating a framework based on the Symfony2 components is really easy. Here is
|
||||
a very simple, but fully-featured framework based on the Symfony2 components:
|
||||
|
||||
$matcher = new UrlMatcher($routes, $context);
|
||||
$routes = new RouteCollection();
|
||||
$routes->add('hello', new Route('/hello', array('_controller' =>
|
||||
function (Request $request) {
|
||||
return new Response(sprintf("Hello %s", $request->get('name')));
|
||||
}
|
||||
)));
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addSubscriber(new RouterListener($matcher));
|
||||
$request = Request::createFromGlobals();
|
||||
|
||||
$resolver = new ControllerResolver();
|
||||
$context = new RequestContext();
|
||||
$context->fromRequest($request);
|
||||
|
||||
$kernel = new HttpKernel($dispatcher, $resolver);
|
||||
$matcher = new UrlMatcher($routes, $context);
|
||||
|
||||
$kernel->handle($request)->send();
|
||||
```
|
||||
$dispatcher = new EventDispatcher();
|
||||
$dispatcher->addSubscriber(new RouterListener($matcher));
|
||||
|
||||
This is all you need to create a flexible framework with the Symfony2 components.
|
||||
$resolver = new ControllerResolver();
|
||||
|
||||
Want to add an HTTP reverse proxy and benefit from HTTP caching and Edge Side Includes?
|
||||
$kernel = new HttpKernel($dispatcher, $resolver);
|
||||
|
||||
```
|
||||
$kernel = new HttpKernel($dispatcher, $resolver);
|
||||
$kernel->handle($request)->send();
|
||||
|
||||
$kernel = new HttpCache($kernel, new Store(__DIR__.'/cache'));
|
||||
```
|
||||
This is all you need to create a flexible framework with the Symfony2
|
||||
components.
|
||||
|
||||
Want to add an HTTP reverse proxy and benefit from HTTP caching and Edge Side
|
||||
Includes?
|
||||
|
||||
$kernel = new HttpKernel($dispatcher, $resolver);
|
||||
|
||||
$kernel = new HttpCache($kernel, new Store(__DIR__.'/cache'));
|
||||
|
||||
Want to functional test this small framework?
|
||||
|
||||
```
|
||||
$client = new Client($kernel);
|
||||
$crawler = $client->request('GET', '/hello/Fabien');
|
||||
$client = new Client($kernel);
|
||||
$crawler = $client->request('GET', '/hello/Fabien');
|
||||
|
||||
$this->assertEquals('Fabien', $crawler->filter('p > span')->text());
|
||||
```
|
||||
$this->assertEquals('Fabien', $crawler->filter('p > span')->text());
|
||||
|
||||
Want nice error pages instead of ugly PHP exceptions?
|
||||
|
||||
```
|
||||
$dispatcher->addSubscriber(new ExceptionListener(function (Request $request) {
|
||||
$msg = 'Something went wrong! ('.$request->get('exception')->getMessage().')';
|
||||
$dispatcher->addSubscriber(new ExceptionListener(function (Request $request) {
|
||||
$msg = 'Something went wrong! ('.$request->get('exception')->getMessage().')';
|
||||
|
||||
return new Response($msg, 500);
|
||||
}));
|
||||
```
|
||||
return new Response($msg, 500);
|
||||
}));
|
||||
|
||||
I can continue on and on but I think you get the point.
|
||||
|
||||
And that's why the simple looking HttpKernelInterface is so powerful.
|
||||
It gives you access to a lot of cool features, ready to be used out of the box, with no efforts.
|
||||
And that's why the simple looking ``HttpKernelInterface`` is so powerful. It
|
||||
gives you access to a lot of cool features, ready to be used out of the box,
|
||||
with no efforts.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,19 +1,18 @@
|
||||
Locale Component
|
||||
================
|
||||
|
||||
Provides fallback code to handle cases when the intl extension is missing.
|
||||
Locale provides fallback code to handle cases when the ``intl`` extension is
|
||||
missing.
|
||||
|
||||
Loading the fallback classes for example using the ClassLoader component only
|
||||
requires adding the following lines to your autoloader.
|
||||
requires adding the following lines to your autoloader:
|
||||
|
||||
```
|
||||
// intl
|
||||
if (!function_exists('intl_get_error_code')) {
|
||||
require __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
|
||||
// intl
|
||||
if (!function_exists('intl_get_error_code')) {
|
||||
require __DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
|
||||
|
||||
$loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
|
||||
}
|
||||
```
|
||||
$loader->registerPrefixFallbacks(array(__DIR__.'/../vendor/symfony/src/Symfony/Component/Locale/Resources/stubs'));
|
||||
}
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,40 +1,38 @@
|
||||
Process Component
|
||||
=================
|
||||
|
||||
The Process component allows you to execute a command in a sub-process.
|
||||
In this example, I run a simple directory listing and get the result back:
|
||||
Process executes commands in sub-processes.
|
||||
|
||||
```
|
||||
use Symfony\Component\Process\Process;
|
||||
In this example, we run a simple directory listing and get the result back:
|
||||
|
||||
$process = new Process('ls -lsa');
|
||||
$process->setTimeout(3600);
|
||||
$process->run();
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new RuntimeException($process->getErrorOutput());
|
||||
}
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
print $process->getOutput();
|
||||
```
|
||||
$process = new Process('ls -lsa');
|
||||
$process->setTimeout(3600);
|
||||
$process->run();
|
||||
if (!$process->isSuccessful()) {
|
||||
throw new RuntimeException($process->getErrorOutput());
|
||||
}
|
||||
|
||||
print $process->getOutput();
|
||||
|
||||
You can think that this is easy to achieve with plain PHP but it's not especially
|
||||
if you want to take care of the subtle differences between the different platforms.
|
||||
|
||||
And if you want to be able to get some feedback in real-time, just pass an anonymous
|
||||
function to the run() method and you will get the output buffer as it becomes available:
|
||||
And if you want to be able to get some feedback in real-time, just pass an
|
||||
anonymous function to the ``run()`` method and you will get the output buffer
|
||||
as it becomes available:
|
||||
|
||||
```
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
$process = new Process('ls -lsa');
|
||||
$process->run(function ($type, $buffer) {
|
||||
if ('err' === $type) {
|
||||
echo 'ERR > '.$buffer;
|
||||
} else {
|
||||
echo 'OUT > '.$buffer;
|
||||
}
|
||||
});
|
||||
```
|
||||
$process = new Process('ls -lsa');
|
||||
$process->run(function ($type, $buffer) {
|
||||
if ('err' === $type) {
|
||||
echo 'ERR > '.$buffer;
|
||||
} else {
|
||||
echo 'OUT > '.$buffer;
|
||||
}
|
||||
});
|
||||
|
||||
That's great if you want to execute a long running command (like rsync-ing files to a
|
||||
remote server) and give feedback to the user in real-time.
|
||||
|
@ -1,29 +1,28 @@
|
||||
Routing Component
|
||||
=================
|
||||
|
||||
The Routing component is a way to associate a Request with the code that will
|
||||
convert it somehow to a Response. The example below demonstrates that with only
|
||||
10 lines of code, you can set up a fully working routing system:
|
||||
Routing associates a request with the code that will convert it to a response.
|
||||
|
||||
```
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
The example below demonstrates how you can set up a fully working routing
|
||||
system:
|
||||
|
||||
$routes = new RouteCollection();
|
||||
$routes->add('hello', new Route('/hello', array('controller' => 'foo')));
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Matcher\UrlMatcher;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
||||
$context = new RequestContext();
|
||||
$routes = new RouteCollection();
|
||||
$routes->add('hello', new Route('/hello', array('controller' => 'foo')));
|
||||
|
||||
// this is optional and can be done without a Request instance
|
||||
$context->fromRequest(Request::createFromGlobals());
|
||||
$context = new RequestContext();
|
||||
|
||||
$matcher = new UrlMatcher($routes, $context);
|
||||
// this is optional and can be done without a Request instance
|
||||
$context->fromRequest(Request::createFromGlobals());
|
||||
|
||||
$parameters = $matcher->match('/hello');
|
||||
```
|
||||
$matcher = new UrlMatcher($routes, $context);
|
||||
|
||||
$parameters = $matcher->match('/hello');
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,10 +1,10 @@
|
||||
Security Component
|
||||
==================
|
||||
|
||||
This component provides an infrastructure for sophisticated authorization systems,
|
||||
which makes it possible to easily separate the actual authorization logic from so
|
||||
called user providers that hold the users credentials. It is inspired by the
|
||||
Java Spring framework.
|
||||
Security provides an infrastructure for sophisticated authorization systems,
|
||||
which makes it possible to easily separate the actual authorization logic from
|
||||
so called user providers that hold the users credentials. It is inspired by
|
||||
the Java Spring framework.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,10 +1,12 @@
|
||||
Templating Component
|
||||
====================
|
||||
|
||||
This component provides an infrastructure to load template files and optionally
|
||||
monitor them for changes. It also provides a concrete template engine implementation
|
||||
using PHP with additional tools for escaping and separating templates into blocks
|
||||
and layouts.
|
||||
Templating provides all the tools needed to build any kind of template system.
|
||||
|
||||
It provides an infrastructure to load template files and optionally monitor
|
||||
them for changes. It also provides a concrete template engine implementation
|
||||
using PHP with additional tools for escaping and separating templates into
|
||||
blocks and layouts.
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
@ -1,12 +1,29 @@
|
||||
Translation Component
|
||||
=====================
|
||||
|
||||
This component provides tools for loading translation files and generating translated
|
||||
strings from these including support for pluralization.
|
||||
Translation provides tools for loading translation files and generating
|
||||
translated strings from these including support for pluralization.
|
||||
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Symfony\Component\Translation\MessageSelector;
|
||||
use Symfony\Component\Translation\Loader\ArrayLoader;
|
||||
|
||||
$translator = new Translator('fr_FR', new MessageSelector());
|
||||
$translator->setFallbackLocale('fr');
|
||||
$translator->addLoader('array', return new ArrayLoader());
|
||||
$translator->addResource('array', array(
|
||||
'Hello World!' => 'Bonjour',
|
||||
), 'fr');
|
||||
|
||||
$translator->trans('Hello World!');
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
Silex integration:
|
||||
|
||||
https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/TranslationServiceProvider.php
|
||||
|
||||
Unit tests:
|
||||
|
||||
https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/Translation
|
||||
|
@ -1,13 +1,41 @@
|
||||
Validator Component
|
||||
===================
|
||||
|
||||
This component is based on the JSR-303 Bean Validation specification and enables
|
||||
specifying validation rules for classes using XML, YAML or annotations, which can
|
||||
then be checked against instances of these classes.
|
||||
This component is based on the JSR-303 Bean Validation specification and
|
||||
enables specifying validation rules for classes using XML, YAML or
|
||||
annotations, which can then be checked against instances of these classes.
|
||||
|
||||
use Symfony\Component\Validator\Validator;
|
||||
use Symfony\Component\Validator\Mapping\ClassMetadataFactory;
|
||||
use Symfony\Component\Validator\Mapping\Loader\StaticMethodLoader;
|
||||
use Symfony\Component\Validator\ConstraintValidatorFactory;
|
||||
|
||||
$validator = new Validator(
|
||||
new ClassMetadataFactory(new StaticMethodLoader()),
|
||||
new ConstraintValidatorFactory()
|
||||
);
|
||||
|
||||
$constraint = new Assert\Collection(array(
|
||||
'name' => new Assert\Collection(array(
|
||||
'first_name' => new Assert\MinLength(101),
|
||||
'last_name' => new Assert\MinLength(1),
|
||||
)),
|
||||
'email' => new Assert\Email(),
|
||||
'simple' => new Assert\MinLength(102),
|
||||
'gender' => new Assert\Choice(array(3, 4)),
|
||||
'file' => new Assert\File(),
|
||||
'password' => new Assert\MinLength(60),
|
||||
));
|
||||
|
||||
$violations = $validator->validateValue($input, $constraint);
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
||||
Silex integration:
|
||||
|
||||
https://github.com/fabpot/Silex/blob/master/src/Silex/Provider/ValidatorServiceProvider.php
|
||||
|
||||
Unit tests:
|
||||
|
||||
https://github.com/symfony/symfony/tree/master/tests/Symfony/Tests/Component/Validator
|
||||
|
@ -1,17 +1,13 @@
|
||||
Yaml Component
|
||||
==============
|
||||
|
||||
YAML is a great configuration format. It's the most popular Symfony2 component
|
||||
right now, because this is probably the only plain-PHP library that implements
|
||||
most of the YAML 1.2 specification:
|
||||
YAML implements most of the YAML 1.2 specification.
|
||||
|
||||
```
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
$array = Yaml::parse($file);
|
||||
$array = Yaml::parse($file);
|
||||
|
||||
print Yaml::dump($array);
|
||||
```
|
||||
print Yaml::dump($array);
|
||||
|
||||
Resources
|
||||
---------
|
||||
|
Reference in New Issue
Block a user