function output() { //set all template variables foreach ($this->vars as $var => $val) { ${$var} = $val; } if ($this->parent_view) { foreach ($this->parent_view->vars as $var => $val) { ${$var} = $val; } } // TODO: Check extract() for an alternative method $path = Kennel::cascade("{$this->view}", 'views'); if (!$path) { return debug::error("View <strong>{$this->view}</strong> not found."); } //begin intercepting the output buffer ob_start(); if ($path) { require $path; } //return the output and close the buffer return ob_get_clean(); //unset all template variables foreach ($this->vars as $var => $val) { unset(${$var}); } }
function __autoload($class_name) { // Controllers if (substr($class_name, -11) == '_controller') { $controller_name = strtolower(substr($class_name, 0, strlen($class_name) - 11)); $path = Kennel::cascade($controller_name, 'controllers'); if ($path) { return require_once $path; } } // Helpers if ($class_name == strtolower($class_name)) { $path = Kennel::cascade($class_name, 'helpers'); if ($path) { return require_once $path; } } // Models if (substr($class_name, -6) == '_model') { $model_name = strtolower(substr($class_name, 0, strlen($class_name) - 6)); $path = Kennel::cascade($model_name, 'models'); if ($path) { return require_once $path; } } // Libraries (allow use of namespaces, files must be organized in folders with the same structure) $path = Kennel::cascade(str_replace('\\', '/', $class_name), 'libraries'); if ($path) { return require_once $path; } // Nothing! debug::error("<strong>__autoload:</strong> class '{$class_name}' not found."); }
static function file($uri) { # Absolute paths if (substr($uri, 0, 7) === 'http://') { return $uri; } # Cascading Resource $path = Kennel::cascade($uri, 'file', true); if ($path) { return $path; } else { debug::error("assets helper: File <b>{$uri}</b> not found.", 1); } }
function __construct($model_name) { if (!$model_name) { debug::error("Schema::__construct - undefined model name."); } $path = Kennel::cascade($model_name, 'schemas'); if (!$path) { debug::error("Schema::__construct - model schema for \"{$model_name}\" not found."); } $doc = new DOMDocument(); $doc->load(realpath($path)); $root = $doc->getElementsByTagName('model')->item(0); if (Kennel::getSetting('database', 'prefix')) { $this->table = Kennel::getSetting('database', 'prefix') . '_' . $root->getAttribute('table'); } else { $this->table = $root->getAttribute('table'); } $fields = $doc->getElementsByTagName('field'); foreach ($fields as $field) { $this->fields[] = new Field($this->table, $field); } }
/** * Static methods */ static function getInstance($model_name) { $path = Kennel::cascade($model_name, 'models'); if ($path) { $class = ucfirst($model_name) . '_model'; $instance = new $class(); } else { $class = 'Model'; $instance = new $class($model_name); } return $instance; }