Go beyond the documentation and explore some of what's possible if you stretch symfony to its limits. We will look at a number of aspects of symfony 1.4 and Doctrine 1.2 and tease out some powerful functionality you may not have expected to find, but will doubtless be able to use. Topics covered will include routing, forms, the config cache and record listeners. If you're comfortable in symfony and wondering what's next, this session is for you.
2. @kriswallsmith
• Release Manager for symfony 1.3 & 1.4
• On Symfony and Doctrine teams
• Senior Software Engineer at
• 10 years experience with PHP and web development
• Open source evangelist and international speaker
• Hopeless plugin developer…
15. class sfRoute
• ->matchesUrl(...)
Does the supplied URL match this route?
GET / HTTP/1.0
Host: foobar.domain.com
16. class sfRoute
Ver y slow
• ->matchesUrl(...)
url_for('main/dashboard?username=foobar')
Does the supplied URL match this route?
• ->matchesParameters(...)
Do the supplied parameters match this route?
17. class sfRoute
• ->matchesUrl(...)
Does the supplied URL match this route?
• ->matchesParameters(...)
url_for('@dashboard?username=foobar')
Do the supplied parameters match this route?
• ->generate(...)
Generate a URL using this route and these parameters.
18. ->matchesUrl(...)
• $url
The current URI
• $context
An array of contextual information, including the current host
• Returns false or an array of parameters extracted from the URI
19. ->matchesParameters(...)
• $params
An associative array of parameter names and values
• $context
An array of contextual information, including the current host
• Returns true or false
20. ->generate(...)
• $params
An associative array of parameter names and values
• $context
An array of contextual information, including the current host
• $absolute
Whether to generate an absolute URL
• Returns the generated URL
22. public function __construct(...)
{
list($host, $pattern) = explode('/', $pattern, 2);
$hostRoute = $this->createHostRoute($host, ...);
parent::__construct(...);
}
23. public function matchesUrl($url, $c)
{
// check parent::matchesUrl() first
$hp = $hostRoute->matchesUrl('/'.$c['host'], $c);
// include host parameters in return
}
24. public function matchesParameters($p, $c)
{
$hp = $this->extractHostParams($p);
return
parent::matchesParameters($p, $c)
&&
$hostRoute->matchesParameters($hp, $c);
}
27. Hard
co d
homepage: e
d F
TL
url: domain.com/ :(
class: sfHostAwareRoute
param: { module: main, action: index }
dashboard:
url: :username.domain.com/
class: sfHostAwareRoute
param: { module: main, action: dashboard }
99. // called when a form is configured
public function embedDynamicRelation($name)
{
$rel = $table->getRelation($name);
$this->rels[] = $rel;
$this->doEmbed($name, $obj->get($rel->getAlias()));
}
100. // called when a form is bound
public function filterValues(sfEvent $event, $values)
{
foreach ($this->rels as $rel)
{
$name = $rel->getName();
$this->doEmbed($name, $values[$name]);
}
$obj->addListener(new DeleteListener($form));
}
101. $parent = new BaseForm();
foreach ($values as $i => $value) {
if (is_object($value)) {
// create form with object
} elseif ($value['id']) {
// find previously embedded form
} else {
// create a new form
}
$parent->embedForm($i, $child);
}
$form->embedForm($rel->getName(), $parent);
102. // extract existing objects from embedded forms
// and compare to the current object collection
public function preSave(Doctrine_Event $event)
{
foreach ($coll as $i => $obj)
{
$pos = array_search($obj, $existing, true);
if (false === $pos) $coll->remove($i);
if ($column['notnull']) $obj->delete();
}
}