コード例 #1
0
 protected function getAction($controller, $impliedActions)
 {
     if (is_string($impliedActions)) {
         $impliedActions = array($impliedActions);
     }
     if (array_key_exists("action", $this->model->routed)) {
         $impliedActions[] = $this->model->routed['action'];
     }
     $impliedActions[] = "show";
     $impliedActions[] = "noActionMatch";
     foreach ($impliedActions as $method) {
         $method = lcfirst(Inflector::camelize(str_replace("-", "_", $method)));
         if (method_exists($controller, $method)) {
             return $method;
         }
     }
     return "";
 }
コード例 #2
0
 /**
  * Analyzes the configuration and the class name to generate
  * both plural and singular human readable forms of this class name.
  * @return null
  */
 public function parse()
 {
     // Fetch the basic values from possible user defined values.
     if ($this->entity->hasConfig("labels")) {
         if ($this->entity->hasConfig("labels.singular_name")) {
             $this->singular = $this->entity->getConfig("labels.singular_name");
         } elseif ($this->entity->hasConfig("labels.name")) {
             $this->plural = $this->entity->getConfig("labels.name");
         }
     }
     if (!empty($this->singular) && empty($this->plural)) {
         $this->plural = Inflector::pluralize($this->singular);
     }
     if (!empty($this->plural) && empty($this->singular)) {
         $this->singular = Inflector::singularize($this->plural);
     }
     // If nothing is sent in, guess the name from the object name.
     if (empty($this->plural) && empty($this->singular)) {
         $this->singular = ucfirst(Inflector::singularize($this->entity->getShortName()));
         $this->plural = ucfirst(Inflector::pluralize($this->entity->getShortName()));
     }
 }
コード例 #3
0
ファイル: UrlRoute.php プロジェクト: francoisfaubert/strata
 /**
  * Formats the action based on the router's match
  * @param  string $action
  * @return string
  */
 private function getActionFromParam($action)
 {
     $action = str_replace("-", "_", $action);
     if (substr($action, -1) === "/") {
         $action = substr($action, 0, -1);
     }
     return lcfirst(Inflector::camelize($action));
 }
コード例 #4
0
 /**
  * Generates a valid class name from the $name value.
  * @param  string $name A possible class name.
  * @return string a Valid class name.
  */
 public static function generateClassName($name)
 {
     $name = str_replace("-", "_", $name);
     if (strstr($name, "\\")) {
         $composedName = "";
         foreach (explode("\\", $name) as $namespace) {
             $namespace = Inflector::underscore($namespace);
             $namespace = Inflector::classify($namespace);
             $composedName .= $namespace . "\\";
         }
     } else {
         $name = Inflector::underscore($name);
         $name = Inflector::classify($name);
     }
     $suffix = self::getClassNameSuffix();
     if (!preg_match("/{$suffix}\$/", $name)) {
         $name .= $suffix;
     }
     if (!preg_match('/^[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/', $name)) {
         throw new Exception(sprintf("We could not generate a valid PHP classname from %s", $name));
     }
     return $name;
 }
コード例 #5
0
 /**
  * Returns the internal custom post type slug
  * @return string
  */
 public function getWordpressKey()
 {
     $name = $this->getShortName();
     $name = Inflector::underscore($name);
     return $this->wpPrefix . $name;
 }
コード例 #6
0
 /**
  * Per Wordpress' configuration, shortcodes must be
  * formatted roughly as underscored function names.
  * @param  string $shortcode
  * @return string Shortcode with enforced formatting
  */
 private function formatCode($shortcode)
 {
     return Inflector::underscore($shortcode);
 }