Skip to content

Instantly share code, notes, and snippets.

@Ultimater
Created September 15, 2017 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ultimater/32dd93694e28fb18316c5756d12ca292 to your computer and use it in GitHub Desktop.
Save Ultimater/32dd93694e28fb18316c5756d12ca292 to your computer and use it in GitHub Desktop.
micro-router.php
class MicroCollectionHandler
{
public $collection,$handlerIndex;
public function __construct($collection,$handlerIndex)
{
$this->collection = $collection;
$this->handlerIndex = $handlerIndex;
}
public function via($methods)
{
$this->collection->updateHandlerVia($this->handlerIndex , $methods);
return $this;
}
public function setName($name)
{
$this->collection->updateHandlerName($this->handlerIndex , $name);
return $this;
}
}
class MicroCollection extends \Phalcon\Mvc\Micro\Collection
{
public function updateHandlerName($handlerIndex, $name)
{
$this->_handlers[$handlerIndex][3] = $name;
}
public function updateHandlerVia($handlerIndex, $methods)
{
$this->_handlers[$handlerIndex][0] = $methods;
}
public function map($routePattern, $handler, $name = NULL)
{
parent::map($routePattern, $handler);
$handlerIndex = count($this->_handlers)-1;
$handler = $this->_handlers[$handlerIndex];
return new MicroCollectionHandler($this,$handlerIndex);
}
public function get($routePattern, $handler, $name = NULL)
{
parent::get($routePattern, $handler);
$handlerIndex = count($this->_handlers)-1;
return new MicroCollectionHandler($this,$handlerIndex);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment