Академический Документы
Профессиональный Документы
Культура Документы
Serial entrepreneur
Developer by passion
Founder of Sensio
Creator and lead developer of Symfony
On Twitter @fabpot
On github http://www.github.com/fabpot
http://fabien.potencier.org/
The Symfony Components – Fabien Potencier
Standalone components for PHP 5.3
Routing Beta
Console Stable
Dependency Injection Container Stable Written from scratch
for Symfony 2
Request Handler Stable
Templating Stable
Main repository
Git Mirror
Synchronized
every 15 minutes
curl -O http://github.com/symfony/symfony/zipball/master
unzip symfony-symfony-XXXXXXX.zip
Nightly build
Vendor name
Vendor name
http://groups.google.com/group/php-standards/web/psr-0-final-proposal
use Symfony\Foundation\UniversalClassLoader;
PEAR style
use Symfony\Foundation\UniversalClassLoader;
// ...
// ...
$ ./foo …
$name = $argv[1];
echo 'Hello '.$name;
Array
(
[0] => ./life
[1] => foo
[2] => foo bar
[3] => --foo
[4] => foobar
[5] => -b
)
$attrs = $weather->getCurrentConditions();
$attrs = $weather->getForecast();
$application->addCommand($command);
The Output
$output->writeln("<comment>Conditions</comment>");
Getting help
The Input
$this->setDefinition($definition);
$output->writeln("<comment>Conditions</comment>");
}
$output->writeln("<comment>Conditions</comment>");
return 120;
}
$input->setArgument('place', $city);
}
formatter
formatSection()
formatBlock()
Testing
$application->run($input, $output);
rewind($output->getStream());
echo stream_get_contents($output->getStream());
// for testing
$application->setCatchExceptions(false);
$application->setAutoExit(false);
// Stubs
$phar['_cli_stub.php'] = $this->getCliStub();
$phar['_web_stub.php'] = $this->getWebStub();
$phar->setDefaultStub('_cli_stub.php', '_web_stub.php');
$phar->stopBuffering();
$phar->compressFiles(\Phar::GZ);
unset($phar);
http://example.com/article/confoo-2010
Matching URLs
$params['to']();
$params['to']($params);
$params['to']($params);
Generating URLs
/?foo=bar
http://www.example.com/myapp/
base_url
host
is_secure
method
blog_post:
pattern: /:year/:month/:day/:slug
defaults:
controller: blog
action: show
requirements:
year: \d{4}
$routes = $loader->load('routes.yml');
<routes xmlns="http://www.symfony-project.org/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.symfony-project.org/schema/routing
http://www.symfony-project.org/schema/routing/routing-1.0.xsd">
$routes = $loader->load('routes.xml');
<routes>
<route id="home" pattern="/">
<default key="controller">home</default>
<default key="action">index</default>
</route>
import:
- { resource: blog.yml, prefix: /blog }
- { resource: forum.xml, prefix: /forum }
$routes->addCollection(
$yamlLoader->load('blog.yml'), '/blog');
$routes->addCollection(
$xmlLoader->load('forum.xml'), '/forum');
The Symfony Components – Fabien Potencier
/blog/2010/03/10/confoo
prefix pattern
return $routes;
};
$context = array(
'base_url' => '/myapp',
'host' => 'www.example.com',
'is_secure' => false,
);
$options = array(
'cache_dir' => '/tmp/routing',
'debug' => true,
);
The Symfony Components – Fabien Potencier
$router = new Router($loader, $options, $context);
return false;
}
}
$loader = function ()
{
$routes = new RouteCollection();
// ...
$routes->addResource(new FileResource(__FILE__));
return $routes;
};
echo $dumper->dump();
$article = array(
'title' => 'Foo <br />',
'author' => array(
'name' => 'Fabien <br/>',
)
);
echo $article['title']."\n";
echo $article['author']['name']."\n";
echo $article->getTitle()."\n";
echo $article->getAuthor()->getName()."\n";
echo $article->full_title."\n";
echo $article->title."\n";
echo $article->title()."\n";
echo $article->getHtmlContent('raw');
echo $article->getTitle('js');
change the default
escaping strategy
$response->setHeader('Content-Type', 'text/plain');
$response->setCookie('foo', 'bar');
$response->setContent('Hello World');
$response->setStatusCode(200);
return true;
});
A small Framework
$parameters = $matcher->match($request->getPathInfo());
if (false === $parameters)
{
return false;
}
$request->setPathParameters($parameters);
$event->setReturnValue(array($parameters['to'], array($request)));
return true;
}
The Symfony Components – Fabien Potencier
$framework = new Framework(array(
'/' => function ($request)
{
$content = 'Hello '.
$request->getParameter('name');
Contact
Fabien Potencier
fabien.potencier at sensio.com
http://www.sensiolabs.com/
http://www.symfony-project.org/
http://fabien.potencier.org/