Example #1
0
 public function dispatch($component = null, $controller = null, $action = null)
 {
     $eventManager = Registry::get('Velox.EventManager');
     $eventManager->broadcast(new Event('Velox.Dispatcher.beforeDispatch', $this));
     if (!is_null($component)) {
         $this->setComponent($component);
     }
     if (!is_null($controller)) {
         $this->setController($controller);
     }
     if (!is_null($action)) {
         $this->setAction($action);
     }
     $controllerFqn = sprintf('\\%s\\Controller\\%sController', $this->getComponent(), $this->getController());
     if (!class_exists($controllerFqn)) {
         throw new Exception\ControllerNotFoundException(sprintf('Controller "%s" doesn\'t exists.', $controllerFqn));
     }
     $controllerInstance = new $controllerFqn();
     $action = $this->action . 'Action';
     if (!method_exists($controllerInstance, $action)) {
         throw new Exception\ActionNotFoundException(sprintf('Action "%s" of controller %s doesn\'t exists.', $action, $controllerFqn));
     }
     $content = call_user_func(array($controllerInstance, $action));
     $eventManager->broadcast(new Event('Velox.Dispatcher.afterDispatch', $this));
     return $content;
 }
Example #2
0
 public function getEventListeners()
 {
     return array(new EventListener(array('Velox.Kernel.Launch'), function (Event $event) {
         //Registry::get('Velox.Security.AuthenticationManager')->init();
         $security = Registry::get('Velox.Security');
         $security->execute();
     }));
 }
Example #3
0
 public function generateUrl($name, $params = array(), array $ignoreConstraintsFor = array())
 {
     if (!isset($this->routes[$name])) {
         throw new RouteNotFoundException(sprintf('Named route "%s" doesn\'t exists', $name));
     }
     $request = Registry::get('Velox.Http.Request');
     return $this->routes[$name]->generateUrl($request, $params, $ignoreConstraintsFor);
 }
Example #4
0
 public static function halt()
 {
     chdir(self::$cwd);
     if (self::$isHalted) {
         return;
     }
     self::$isHalted = true;
     Registry::get('Velox.EventManager')->broadcast(new Event('Velox.Kernel.Halt'));
     exit;
 }
Example #5
0
 public function getEventListeners()
 {
     return array(new EventListener(array('Velox.Kernel.Launch'), function (Event $event) {
         //echo 'Fired!';
     }), new EventListener(array('Velox.Kernel.Halt'), function (Event $event) {
         Registry::get('Velox.Http.Response')->send();
         //echo 'Fired2!';
         //\Velox\Framework\Kernel\Kernel::halt();
     }));
 }
Example #6
0
 public function addBreadcrumb($title, $route, $routeParams = array(), $useForBack = true)
 {
     $href = $this->generateUrl($route, $routeParams);
     Registry::get('Velox.Extra.Breadcrumbs')->addItem($title, $href, $useForBack);
 }
Example #7
0
 public function request()
 {
     return Registry::get('Velox.Http.Request');
 }
Example #8
0
 public function update($entity, $broadcastEvents = true)
 {
     $pk = $this->getPk();
     if (is_null($pk)) {
         throw new \LogicException(sprintf('Trying to update entity "%s" with no Primary Key defined', $this->getEntityClass()));
     }
     if (method_exists($entity, 'ormBeforeUpdate')) {
         $entity->ormBeforeUpdate();
     }
     $eventManager = null;
     $eventName = '';
     if ($broadcastEvents) {
         $eventName = str_replace('\\', '.', $this->getEntityClass());
         $eventManager = Registry::get('Velox.EventManager');
         $eventManager->broadcast(new Event($eventName . '.BeforeUpdate', $entity));
     }
     $a = $this->castToDbArray($entity);
     // broadcast event
     $assignments = array();
     foreach ($this->fields as $f) {
         if ($f->isNoUpdate()) {
             continue;
         }
         $propName = $f->getPropName();
         if (is_null($a[$propName]) && !$f->getIsNullable()) {
             throw new Exception\NullValueException(sprintf('Updating not nullable "%s" property of "%s" with null.', $propName, $this->getEntityClass()));
         }
         if (is_null($a[$propName])) {
             $assignments[] = $f->getSql($this->getTableName()) . '=NULL';
         } else {
             $assignments[] = $f->getSql($this->getTableName()) . '=' . $this->dbDriver->escape($a[$propName]);
         }
     }
     $q = sprintf('UPDATE `%s` SET %s WHERE %s', $this->getTableName(), implode(', ', $assignments), $pk->getSql($this->getTableName()) . '=' . $this->dbDriver->escape($a[$pk->getPropName()]));
     $q = $this->prepare($q);
     if ($this->dumpQueryOnce) {
         $this->dumpQueryOnce = false;
         _dump($q);
     }
     $toReturn = $this->dbDriver->update($q);
     if (method_exists($entity, 'ormAfterUpdate')) {
         $entity->ormAfterUpdate();
     }
     if ($broadcastEvents) {
         $eventManager->broadcast(new Event($eventName . '.AfterUpdate', $entity));
     }
     return $toReturn;
 }
 public function removeRememberCookie($user)
 {
     Registry::get('Velox.Http.Response')->setCookie(new Cookie($this->rememberTokenName, '', time() - 9999));
 }