static function field($field, $mapping) { if (isset($mapping[$field])) { return $mapping[$field]; } return InflectionComponent::humanize($field); }
public static function humanize($string) { $string = InflectionComponent::unCamelCase($string); $string = preg_replace('/_|-/', ' ', $string); $string = preg_replace('/ {2,}/', ' ', $string); $string = cfirst($string); return $string; }
private function doUpload() { if (!empty($_FILES)) { $file = $_FILES['uploaded']; $file_name = clean_filename($file['name']); // TODO: mettre le dosser d'upload dans des configs $path = '/uploads/' . date('Y') . '/' . date('m'); $full_path = $path . '/' . duplicate_filename(ROOT . '/www/' . $path, $file_name); $to_path = ROOT . '/www/' . $full_path; @mkdir(dirname($to_path), 0755, true); move_uploaded_file($file['tmp_name'], $to_path); if (isset($_POST['name']) && $_POST['name']) { $name = $_POST['name']; } else { $name = InflectionComponent::humanize(preg_replace('~\\.(.*?)$~', '', $file['name'])); } $info = getimagesize($to_path); $File = new Library(); $File['name'] = $name; $File['path'] = $full_path; $File['width'] = $info[0]; $File['height'] = $info[1]; $File['type'] = $info['mime']; $File->save(); return $File['id']; } }
public function addComponent($name, $options = array()) { $class = InflectionComponent::camelCase($name) . 'Component'; $this->Components[$name] = new $class($this, $options); }
public function dispatch() { $class = InflectionComponent::camelCase($this->controller) . 'Controller'; $action = InflectionComponent::camelCase($this->action, false); if (!class_exists($class)) { throw new Except("Le Controlleur '" . $class . "' n'existe pas", 404); } if (!method_exists($class, $action)) { throw new Except("L'Action '" . $action . "' n'existe pas dans " . $class, 404); } $get = Request::getInstance()->get(); $post = Request::getInstance()->post(); $Controller = new $class($action); $Controller->app = $this->app; foreach ($this->params as $key => $value) { $Controller->setParam($key, $value); } foreach ($get as $key => $value) { $Controller->setParam($key, $value); } foreach ($post as $key => $value) { $Controller->setParam($key, $value); } $Controller->preExecute(); call_user_func_array(array($Controller, $action), $this->rawParams); $Controller->postExecute(); $Controller->spit(); }