Op aanraden van Wouter heb ik een aparte klasse gemaakt voor het parsen van Controller strings als "Application::HelloController::index".
Ik heb nu volgende code:
<?php
namespace Symply\Mvc\Controller;
class ControllerResolver
{
public function resolve($name)
{
$parts = explode('::', $name);
if(count($parts) != 3)
{
throw new Exception\InvalidControllerException(sprintf(
'Controller string %s is invalid',
$name
));
}
$class = '\\' . ucfirst($parts[0]) . '\\Controller\\' . ucfirst($parts[1]);
return array(
'controller' => new $class,
'action' => lcfirst($parts[2]) . 'Action',
);
}
}
?>
Maar ik had graag gehad dat ControllerResolver de Resolvable class implements waardoor de resolve() method verplicht gesteld word.
Zo zou het dan eruit zien:
<?php
interface Resolvable
{
public function resolve($name);
}
class ControllerResolver implements Resolvable
{
public function resolve($name)
{
$parts = explode('::', $name);
if(count($parts) != 3)
{
throw new Exception\InvalidControllerException(sprintf(
'Controller string %s is invalid',
$name
));
}
$class = '\\' . ucfirst($parts[0]) . '\\Controller\\' . ucfirst($parts[1]);
return array(
'controller' => new $class,
'action' => lcfirst($parts[2]) . 'Action',
);
}
}
?>
Nu mijn vraag: waar gaat zo'n resolvable class? Ik wil er geen nieuw component voor maken. En die class in de \Symply\Mvc\Controller namespace zetten heb ik liever ook niet want ik wil zo'n Resolvable ook voor andere dingen gebruiken ipv enkel controllers parsen.
Iemand een idee?
Raoul