/**
  * Initialize demanded controller.
  * 
  * @param Registry $registry Registry object.
  * @return Controller | void
  * @author anza
  */
 public static function create($registry)
 {
     $parser = new URLParser();
     $controller = $parser->getController();
     $actions = $parser->getActions();
     if ($controller == null) {
         $controller = self::$inSession[0];
     }
     if ($controller == 'logout') {
         $registry->session->destroy();
         $controller = self::$inSession[0];
     }
     $controllerName = $controller . 'Controller';
     $modelName = $controller . 'Model';
     $allowedControllers = $registry->session->isStarted() ? self::$inSession : self::$noSession;
     $target = $registry->session->isStarted() ? self::$inSession[0] : self::$noSession[0];
     if (in_array($controller, $allowedControllers)) {
         $registry->controllerName = $controller;
         $controller = new $controllerName($actions, $registry);
         $controller->model = new $modelName($registry);
         return $controller;
     } else {
         Navigator::redirectTo($target);
     }
 }
 /**
  * @Invocable
  */
 protected function find()
 {
     if ($this->request->hasKey('friend')) {
         $name = Regex::replace('/[^A-Za-z0-9]/', '', $this->request->valueOf('friend'));
         Navigator::redirectTo($this->url->getParametersPath($name));
     }
     $name = $this->url->getParameter(0);
     if ($name == null) {
         return;
     }
     $this->getUsers($name);
 }
 /**
  * @Invocable
  */
 protected function add()
 {
     try {
         $fo = FOFactory::build('newvideo');
         if (!$fo->isSent()) {
             return;
         }
         $this->model->add($fo);
         Navigator::redirectTo('video');
     } catch (FormValidationException $e) {
         $e->getTraceAsString();
         $this->request->error = Bundle::get('form.validation.invalid.value', $e->getMessage());
     } catch (VideoNotExistsException $e) {
         $e->getTraceAsString();
         $this->request->error = Bundle::get('form.validation.video.url.incorrect', $e->getMessage());
     }
 }
 /**
  * Logout and destroy session.
  * Redirect to app starting point.
  * @Invocable
  */
 protected function logout()
 {
     Session::getInstance()->destroy();
     Navigator::redirectTo();
 }
 /**
  * Activate existing User.
  * @Invocable
  */
 public function activate()
 {
     try {
         $activeHash = $this->validateActiveHash();
         $this->model->activate($activeHash);
         $this->request->success = Bundle::get('form.validation.field.register.activated');
     } catch (NoResultException $e) {
         $e->getTraceAsString();
         Navigator::redirectTo($this);
     }
 }