コード例 #1
0
ファイル: controller.php プロジェクト: cepharum/txf
 /**
  * Prepares action to perform (unless prepared before).
  *
  * @param string $explicit some explicit action to use instead of automatically extracted one
  * @return string
  */
 public function getAction($explicit = null)
 {
     if (is_null($this->action)) {
         if (is_string($explicit) && trim($explicit) !== '') {
             $this->action = $explicit;
         } else {
             $idSize = $this->getModel()->getMethod('idSize')->invoke(null);
             $selectors = application::current()->selectors;
             if (count($selectors) > $idSize) {
                 $this->action = $selectors[$idSize];
             } else {
                 if (count($selectors) === 1) {
                     // tricky case: single selector might be ID of item or
                     // action on list of items or action for creating new item
                     // -> provide 0-ID to handle this case
                     // TODO Revise approaching this tricky case.
                     $this->action = 'index';
                 } else {
                     $this->action = 'index';
                 }
             }
         }
         $this->action = strtolower(trim($this->action));
         if (preg_match('/^(.+)\\.([a-z]+)$/', $this->action, $matches)) {
             $this->format = strtolower($matches[2]);
             $this->action = trim($matches[1]);
         }
     }
     return $this->action;
 }
コード例 #2
0
ファイル: manager.php プロジェクト: cepharum/txf
 /**
  * Detects mode of widget in current request by checking some implicit
  * parameters unless caller has provided parameters explicitly.
  *
  * @return array tuple consisting of requested action and userID
  */
 protected function detectMode()
 {
     $selectors = application::current()->selectors;
     if (is_null($this->selectedUserId)) {
         // need to implicitly detect a user's ID
         if (ctype_digit(trim($selectors[0]))) {
             $userId = intval(array_shift($selectors));
         } else {
             $userId = false;
         }
     } else {
         $userId = intval($this->selectedUserId);
     }
     if (is_null($this->selectedAction)) {
         try {
             $action = $this->isValidAction(trim($selectors[0]));
             array_shift($selectors);
         } catch (\InvalidArgumentException $e) {
             $action = $userId ? 'view' : is_integer($userId) ? 'add' : null;
         }
     } else {
         $action = $this->selectedAction;
     }
     return array($action, $userId);
 }
コード例 #3
0
ファイル: manager.php プロジェクト: cepharum/txf
 /**
  * Retrieves URLs of assets matching requested type.
  *
  * @param enum $type one of the view::ASSET_TYPE_* constants
  * @return array set of matching assets' URLs
  */
 public static function getAssetsOfType($type)
 {
     return array_map(function ($asset) {
         return application::current()->normalizeUrl(data::qualifyString($asset['url']));
     }, array_filter(static::current()->assets, function ($asset) use($type) {
         return $type == @$asset['type'];
     }));
 }