public function dispatch() { # check the route $this->parseURL(); if (is_readable($this->__file) == false) { # show the 404 error page $this->error404(); } # include the controller include $this->__file; $this->__class = $this->__controller . "_controller"; if (class_exists($this->__class)) { if (method_exists($this->__class, 'index')) { $__controller = new $this->__class(); } else { exit("Required method <strong>index</strong> not found for the class: <strong>{$this->__class}</strong>"); } } else { exit("<strong>Class could not be found: {$this->__class}</strong>"); return false; } # check if the action is callable if (is_callable(array($__controller, $this->__action)) === false) { # default action $__action = 'index'; } else { $__action = $this->__action; } ##### # set the argumentss for later retrieval ezphp::ez_set('arguments', $this->__args); # make an array of arguments foreach ($this->__args as $value) { # make an associative array ezphp::ez_set($value, $value); } // set vars for the uri library $lib_uri = ezphp::ez_get('uri'); $lib_uri->arguments = $this->__args; $lib_uri->method = $this->__action; $lib_uri->controller = $this->__controller; $lib_uri->controller_path = $this->__file; ///////////////////////////////// # call the action now call_user_func_array(array($__controller, $__action), $this->getArgs()); }
public function __set($index, $value) { ezphp::ez_set($index, $value); }
<?php // include the core startup file require './core/startup.php'; // load the loader ezphp::ez_set('load', new load()); // load the router ezphp::ez_set('router', new router()); // load the model ezphp::ez_set('model', new model()); // load the view ezphp::ez_set('view', new view()); // dispatch the controller ezphp::ez_get('router')->dispatch(); ?>
function model($model, $object_name = '') { if (!strlen($model)) { return false; } if (ezphp::ez_get('mod_' . $model)) { return ezphp::ez_get('mod_' . $model); } elseif (isset(self::$mod_objects['mod_' . $model])) { return self::$mod_objects['mod_' . $model]; } /* // get the respective controller's path for the model if (strpos($model, '/') !== false) { global $router; $controller_path = $router->controllerPath(); $controller_path = substr(strrchr($controller_path, 'controllers'), 11); $model_path = str_ireplace(end(explode('/', $router->controllerPath())), '', $controller_path); $path = __SITE_PATH . '/content/models' . $model_path . $model . '.php'; } else { $path = __SITE_PATH . '/content/models/' . $model . '.php'; } */ $path = __SITE_PATH . '/content/models/' . $model . '.php'; $model_class = $model; // get class name from subdir-x if specified one if (strpos($model, '/') !== false) { $model_class = end(explode('/', $model)); $model = str_replace('/', '_', $model); $model = str_replace('\\', '_', $model); } $class = $model_class . '_model'; if (file_exists($path) === false) { throw new Exception('Model Not Found: ' . $path); return false; } // include the model class include $path; if (class_exists($class)) { $class_instance = new $class(); // make it global for use in Cs, Vs $ref_name = $model; if (strlen($object_name)) { $ref_name = $object_name; ezphp::ez_set($object_name, $class_instance); } else { ezphp::ez_set($model, $class_instance); } // for instance returning self::$mod_objects['mod_' . $ref_name] = $class_instance; ezphp::ez_set('mod_' . $ref_name, $class_instance); if (is_object($class_instance)) { return $class_instance; } else { exit('Could not instantiate the class: ' . __SITE_PATH . '/content/models/' . $model . '.php'); } } else { exit("<strong>Class could not be found: {$class}</strong>"); return false; } }
function render($view_name) { $path = __SITE_PATH . '/content/views/' . $view_name . '.php'; if (file_exists($path) === false || is_readable($path) === false) { throw new Exception('View Not Found In ' . $path); return false; } // set view path ezphp::ez_set('ez_view_path', dirname($path) . '/'); $this->view_path = dirname($path) . '/'; $this->vars['ez_view_path'] = dirname($path) . '/'; # load variables to views from controller extract($this->vars); // for cache $qstring = $_SERVER['QUERY_STRING']; $qstring = preg_replace("/[^a-zA-Z0-9_]+/", '_', $qstring); # cache the current file //if (__ENABLE_CACHE == '1' && !$this->cache->isCached($view_name . $qstring)) if (__ENABLE_CACHE == '1') { $cache_data = $this->getContent($path); $this->cache->set($view_name . $qstring, $cache_data); $file = glob(__SITE_PATH . '/cache/' . 'cache.' . $view_name . $qstring . '.*'); } if ($this->no_template == true || ezphp::ez_get('use_template') == '0') { $ez_layout_content = ''; if (__ENABLE_CACHE == '1') { if ($file[0]) { $handle = fopen($file[0], 'r') or die('Could not open the file: ' . $file[0]); $cache = fread($handle, filesize($file[0])); fclose($handle); print unserialize($cache); } } else { include $path; } if (!file_exists($file[0]) || !is_readable($file[0]) || empty($cache)) { include $path; } } else { if (__ENABLE_CACHE == '1') { $ez_layout_content = $this->cache->get($view_name . $qstring); } else { $ez_layout_content = $this->getContent($path); } if (empty($ez_layout_content)) { $ez_layout_content = $this->getContent($path); } // load the template file include_once __SITE_PATH . '/template/' . ezphp::get_template() . '/template.php'; } }
function include_autoloads($autoloads) { foreach ($autoloads as $autoload) { if (is_array($autoload)) { $class_name = $autoload[0]; $args = $autoload; array_shift($args); // shift the first value eg class name $args = $args[0]; } else { $class_name = $autoload; } $file = __SITE_PATH . '/classes/' . $class_name . '.php'; if (file_exists($file) === true) { include $file; if (count($args) === 0) { ezphp::ez_set($class_name, new $class_name()); } elseif (count($args) === 1) { if (is_array($args)) { ezphp::ez_set($class_name, new $class_name($args[0])); } else { ezphp::ez_set($class_name, new $class_name($args)); } } elseif (count($args) > 1) { if (method_exists($class_name, '__construct') === false) { exit("Constructor for the class <strong>{$class_name}</strong> does not exist, you should not pass arguments to this class or provide a constructor for it!"); } $refMethod = new ReflectionMethod($class_name, '__construct'); $params = $refMethod->getParameters(); $re_args = array(); foreach ($params as $key => $param) { if ($param->isPassedByReference()) { $re_args[$key] =& $args[$key]; } else { $re_args[$key] = $args[$key]; } } $refClass = new ReflectionClass($class_name); ezphp::ez_set($class_name, $refClass->newInstanceArgs((array) $re_args)); } } } }
protected function __set($index, $value) { ezphp::ez_set($index, $value); }