protected function _pass($controller, $action, $parameters = array()) { $name = ucfirst($controller); $this->_controller = $controller; $this->_action = $action; try { $instance = new $name(array("parameters" => $parameters)); Registry::set("controller", $instance); } catch (\Framework\Database\Exception $e) { throw new \Framework\Database\Exception($e->getMessage()); } catch (\Exception $e) { throw new Exception\Controller("Controller {$name} not found " . $name); } if (!method_exists($instance, $action)) { $instance->willRenderLayoutView = false; $instance->willRenderActionView = false; throw new Exception\Action("Action {$action} not found"); } $inspector = new Inspector($instance); $methodMeta = $inspector->getMethodMeta($action); if (!empty($methodMeta["@protected"]) || !empty($methodMeta["@private"])) { throw new Exception\Action("Action {$action} not found"); } $hooks = function ($meta, $type) use($inspector, $instance) { if (isset($meta[$type])) { $run = array(); foreach ($meta[$type] as $method) { $hookMeta = $inspector->getMethodMeta($method); if (in_array($method, $run) && !empty($hookMeta["@once"])) { continue; } $instance->{$method}(); $run[] = $method; } } }; $hooks($methodMeta, "@before"); call_user_func_array(array($instance, $action), is_array($parameters) ? $parameters : array()); $hooks($methodMeta, "@after"); // unset controller to fire the __destruct magic method Registry::erase("controller"); }
public function getColumns() { if (empty($_columns)) { $primaries = 0; $columns = array(); $class = StringMethods::classNameWithoutNamespace(get_class($this)); $types = $this->types; $inspector = new Inspector($this); $properties = $inspector->getClassProperties(); $first = function ($array, $key) { if (!empty($array[$key]) && sizeof($array[$key]) == 1) { return $array[$key][0]; } return null; }; foreach ($properties as $property) { $propertyMeta = $inspector->getPropertyMeta($property); if (!empty($propertyMeta["@column"])) { $name = preg_replace("#^_#", "", $property); $primary = !empty($propertyMeta["@primary"]); $type = $first($propertyMeta, "@type"); $length = $first($propertyMeta, "@length"); $index = !empty($propertyMeta["@index"]); $readwrite = !empty($propertyMeta["@readwrite"]); $read = !empty($propertyMeta["@read"]) || $readwrite; $write = !empty($propertyMeta["@write"]) || $readwrite; $validate = !empty($propertyMeta["@validate"]) ? $propertyMeta["@validate"] : false; $label = $first($propertyMeta, "@label"); if (!in_array($type, $types)) { throw new Exception\Type("{$type} is not a valid type"); } if ($primary) { $primaries++; } $columns[$name] = array("raw" => $property, "name" => $name, "primary" => $primary, "type" => $type, "length" => $length, "index" => $index, "read" => $read, "write" => $write, "validate" => $validate, "label" => $label); } } if ($primaries !== 1) { throw new Exception\Primary("{$class} must have exactly one @primary column"); } $this->_columns = $columns; } return $this->_columns; }