Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Â
A Practical Introduction to Symfony2
1. A Practical Introduction
to Symfony2
Kris Wallsmith
PHP Matsuri ⢠October 2, 2010
Saturday, October 2, 2010
2. @kriswallsmith
⢠Release Manager for symfony 1.3 & 1.4
⢠Doctrine contributor
⢠Senior Software Engineer at
⢠10 years experience in web development
⢠Open source evangelist and international speaker
Saturday, October 2, 2010
3. the evolution of symfony
⢠Mojavi 3
⢠symfony (2007)
⢠Symfony2 (2011)
Saturday, October 2, 2010
4. a quick note for the
case-sensitive among us
Saturday, October 2, 2010
52. anatomy of a Symfony2 request
Saturday, October 2, 2010
53. anatomy of a Symfony2 request
⢠Kernel
Saturday, October 2, 2010
54. anatomy of a Symfony2 request
⢠Kernel
⢠Request
Saturday, October 2, 2010
55. anatomy of a Symfony2 request
⢠Kernel
⢠Request
⢠Controller
Saturday, October 2, 2010
56. anatomy of a Symfony2 request
⢠Kernel
⢠Request
⢠Controller
⢠Response
Saturday, October 2, 2010
57. anatomy of a Symfony2 request
Saturday, October 2, 2010
58. anatomy of a Symfony2 request
⢠index.php creates a Kernel
Saturday, October 2, 2010
59. anatomy of a Symfony2 request
⢠index.php creates a Kernel
⢠the kernel creates a Request
Saturday, October 2, 2010
60. anatomy of a Symfony2 request
⢠index.php creates a Kernel
⢠the kernel creates a Request
⢠the kernel passes the Request to the ControllerResolver
Saturday, October 2, 2010
61. anatomy of a Symfony2 request
⢠index.php creates a Kernel
⢠the kernel creates a Request
⢠the kernel passes the Request to the ControllerResolver
⢠the ControllerResolver returns a callable
Saturday, October 2, 2010
62. anatomy of a Symfony2 request
⢠index.php creates a Kernel
⢠the kernel creates a Request
⢠the kernel passes the Request to the ControllerResolver
⢠the ControllerResolver returns a callable
⢠the kernel calls the callable
Saturday, October 2, 2010
63. anatomy of a Symfony2 request
⢠index.php creates a Kernel
⢠the kernel creates a Request
⢠the kernel passes the Request to the ControllerResolver
⢠the ControllerResolver returns a callable
⢠the kernel calls the callable
⢠the callable returns a Response
Saturday, October 2, 2010
64. Silex
http://github.com/fabpot/Silex
Saturday, October 2, 2010
129. â if you want me to foo
you better give me the foo-er
Saturday, October 2, 2010
â
130. class User
{
protected $session;
public function __construct(Session $session)
{
$this->session = $session;
}
}
Saturday, October 2, 2010
131. class User
{
protected $session;
public function __construct()
{
$this->session = Session::factory();
}
}
Saturday, October 2, 2010
132. class User
{
protected $session;
public function __construct()
{
$this->session = Session::factory();
}
}
Saturday, October 2, 2010
133. $session = $this->getMock('Session')
->expects($this->any())
->method('get')
->with('foo')
->will($this->returnValue('bar'))
;
// inject the mock object!
$user = new User($session);
$this->assertEquals('bar',
$user->getSessionVar('foo'));
Saturday, October 2, 2010
134. dependency injection container
⢠a conďŹguration layer
⢠creates a "container" that manages the
creation of objects
⢠âteachâ the container
⢠using xml, yaml, php, ini
(or some combination)
Saturday, October 2, 2010
135. services:
session:
class: Session
user:
class: User
arguments:
- @session
Saturday, October 2, 2010
136. public function getUserService()
{
if (isset($this->shared['user']))
return $this->shared['user'];
$user = new User(
$this->getSessionService()
);
$this->shared['user'] = $user;
return $user;
}
Saturday, October 2, 2010
137. // get one service by name
$container->get('user');
Saturday, October 2, 2010
138. // find many services by "tag"
$c->findTaggedServiceIds('my_tag');
Saturday, October 2, 2010