protected function decamelize($string) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return (string) self::parameters(['string' => DT::STRING])->call(__FUNCTION__)->with($string)->returning(DT::STRING); } else { return (string) decamelize($string); } }
function humanize($value) { $value = ucfirst(str_replace('_', ' ', $value)); $value = strip_extension($value); if (str_contains(' ', $value)) { return $value; } else { return decamelize($value); } }
public function setInformation(array $info) { parent::setInformation($info); $this->cm->attribute = isset($info['key_from']) ? $info['key_from'] : 'id'; $this->cm->column = (array) $this->cm->t->columnRealName($this->cm->attribute); $this->lm->attribute = isset($info['key_to']) ? $info['key_to'] : 'id'; $this->lm->column = (array) $this->lm->t->columnRealName($this->lm->attribute); $this->jm = new \StdClass(); if (isset($info['join_model'])) { $this->jm->class = $s = $info['join_model'] . Cfg::get('modelClassSuffix'); $this->jm->t = $s::table(); $this->jm->table = $this->jm->t->name; $this->jm->from = (array) $this->jm->t->columnRealName(isset($info['join_from']) ? $info['join_from'] : call_user_func(Cfg::get('buildForeignKey'), $this->cm->t->modelBaseName)); $this->jm->to = (array) $this->jm->t->columnRealName(isset($info['join_to']) ? $info['join_to'] : call_user_func(Cfg::get('buildForeignKey'), $this->lm->t->modelBaseName)); } else { $this->jm->class = null; $this->jm->table = isset($info['join_table']) ? $info['join_table'] : $this->cm->table . '_' . $this->lm->table; $this->jm->from = (array) (isset($info['join_from']) ? $info['join_from'] : decamelize($this->cm->t->modelBaseName) . '_id'); $this->jm->to = (array) (isset($info['join_to']) ? $info['join_to'] : decamelize($this->lm->t->modelBaseName) . '_id'); } }
/** * Helper function to prefix ids with the pack name as namespace. * ie. for a pack named 'MyFooPack', the id 'bar' becomes 'MyFoo.bar' or 'my_foo.bar' (with decamelize). * * @param string $id an id to namespace * @param boolean $decamelize * @param string $separator * @return string the pack namespaced id */ protected function _ns($id = null, $decamelize = true, $separator = '.') { static $decamelizeds = []; $me = get_class($this); if ($decamelize && empty($decamelizeds[$me])) { $decamelizeds[$me] = \decamelize($this->getName()); } $ns = $decamelize ? $decamelizeds[$me] : $this->getName(); return $ns . ($id ? $separator . $id : ''); }
<?php function decamelize($class_name) { return ltrim(strtolower(preg_replace('/[A-Z]/', '-$0', $class_name)), '-'); } spl_autoload_register(function ($class) { $this_dir = dirname(__FILE__); if (strlen($class) > 10 && "Controller" == substr($class, -10)) { $file = decamelize(substr($class, 0, -10)) . ".ctrl.php"; } elseif (strlen($class) > 5 && "Model" == substr($class, -5)) { $file = decamelize(substr($class, 0, -5)) . ".mdl.php"; } elseif (strlen($class) > 4 && "View" == substr($class, -4)) { $file = decamelize(substr($class, 0, -4)) . ".view.php"; } else { $file = decamelize($class) . ".php"; } if (defined("__CONTROLLER_PATH__") && file_exists("{$this_dir}/../app/" . __CONTROLLER_PATH__ . "/{$file}")) { require "{$this_dir}/../app/" . __CONTROLLER_PATH__ . "/{$file}"; } elseif (file_exists("{$this_dir}/../app/{$file}")) { require "{$this_dir}/../app/{$file}"; } elseif (file_exists("{$this_dir}/{$file}")) { require "{$this_dir}/{$file}"; } else { error_log("Unable to autoload class {$class}: \"{$file}\" not found"); header("HTTP/1.0 404 Not Found"); die("Error 404: Page not found."); } });