function u($short_url) { $args = func_get_args(); $route_info = Nimble::getInstance()->get_route_info_by_short_name($short_url); $args = array_merge(array($route_info->controller, $route_info->method), array_slice($args, 1)); return call_user_func_array('UrlBuilder::url_for', $args); }
function Run($test_mode = false) { if (defined('NIMBLE_IS_TESTING')) { $test_mode = NIMBLE_IS_TESTING; } Nimble::getInstance()->dispatch($test_mode); // exceptions handled by my_exception_handler. }
/** * Bind the Route object to Nimble's router. * @throws NimbleException if the requested HTTP method is invalid. */ function bind() { if (in_array($this->http_method, self::$allowed_methods)) { $router = Nimble::getInstance()->add_url($this->pattern, $this->controller, $this->action, $this->http_method); } else { throw new NimbleException('Invalid Request'); } }
function __construct() { $this->nimble = Nimble::getInstance(); $this->view_path = $this->nimble->config['view_path']; if (defined('NIMBLE_IS_TESTING') && NIMBLE_IS_TESTING && defined('FAKEMAIL_PORT')) { $this->mailmethod = 'smtp'; $this->mailparams['port'] = FAKEMAIL_PORT; } }
public function setUp() { $_SESSION = array(); $_SESSION['flashes'] = array(); $this->Nimble = Nimble::getInstance(); $this->Nimble->routes = array(); $this->url = ''; Nimble::set_config('plugins_path', dirname(__FILE__) . '/test_plugins/'); }
public function setUp() { $_SESSION = array(); $_SESSION['flashes'] = array(); $this->Nimble = Nimble::getInstance(); $this->Nimble->test_mode = true; $this->Nimble->routes = array(); $this->url = ''; }
/** * This class has 3 required variables that need to be set * $from (string), $subject (string), $recipient | $recipients (string || array) * Options Variables * $time (time), $headers (string) */ public function __construct() { $this->nimble = Nimble::getInstance(); $this->view_path = $this->nimble->config['view_path']; $this->class = get_called_class(); $this->time = time(); $this->_divider = '------=_' . rand(10000000, 99999999999) * 2; $this->_content = array(); }
public function setUp() { $_SESSION = array(); $_POST['_method'] = 'GET'; $_SERVER['REQUEST_METHOD'] = ''; $_SESSION['flashes'] = array(); $this->Nimble = Nimble::getInstance(); $this->Nimble->routes = array(); $this->Nimble->url = ''; }
public function setUp() { $_SESSION = array(); $_SESSION['flashes'] = array(); $_SERVER['REQUEST_METHOD'] = 'GET'; $this->Nimble = Nimble::getInstance(); $this->Nimble->routes = array(); $this->url = ''; $this->Nimble->test_mode = true; Nimble::set_config('plugins_path', join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'test_plugins'))); Nimble::set_config('view_path', join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'views'))); }
function Run($test_mode = false) { try { Nimble::getInstance()->dispatch($test_mode); } catch (Exception $e) { if (NIMBLE_ENV == 'development' && !$test_mode) { ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Error!</title> </head> <body> <h1>Caught exception: <?php echo $e->getMessage(); ?> </h1> <h2>File: <?php echo $e->getFile(); ?> </h2> <h2>Line: <?php echo $e->getLine(); ?> </h2> <h3>Trace</h3> <pre> <?php echo $e->getTraceAsString(); ?> </pre> <h3>Exception Object</h3> <pre> <?php var_dump($e); ?> </pre> <h3>Var Dump</h3> <pre> <?php debug_print_backtrace(); ?> </pre> </body> </html> <?php } } }
function rebind() { if (isset($this->bind_id)) { Nimble::getInstance()->remove_url_by_id($this->bind_id); $this->bind(); } }
public function setUp() { $this->nimble = Nimble::getInstance(); $this->nimble->config['view_path'] = join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'views')); }
/** * Dump out application routes to a human readable format. * @param boolean $cli True if being called from the command line. * @return string The application's routes in a human readable format. */ public static function dumpRoutes($cli = false) { $klass = Nimble::getInstance(); $out = array(); foreach ($klass->routes as $route) { $pattern = self::clean_route($route[0]); $pattern = empty($pattern) ? 'root path' : $pattern; array_push($out, "Controller: {$route[1]} Action: {$route[2]} Method: {$route[3]} Pattern: " . $pattern); } $return = "\n"; $return .= join("\n", $out); $return .= "\n"; return $cli ? $return : htmlspecialchars($return); }
/** * Include a PHP file, inject the controller's properties into that file, and return the output. * @param string $file The view file to render, relative to the base of the application. * @return string The rendered view file. */ public function render_partial($file) { NimbleLogger::log("RENDERING PARTIAL: {$file}"); $this->rendered_partials[] = $file; return $this->open_template(FileUtils::join(Nimble::getInstance()->config['view_path'], $file)); }
/** * Include a PHP file, inject the controller's properties into that file, and return the output. * @param string $file The view file to render, relative to the base of the application. * @return string The rendered view file. */ public function render_partial($file) { $this->rendered_partials[] = $file; return $this->open_template(FileUtils::join(Nimble::getInstance()->config['view_path'], $file)); }
{ if (is_dir($dir)) { foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir)) as $file) { if (preg_match('/\\.php$/', $file)) { require_once $file; } } } } /** load nimble */ require_once 'nimblize/nimblize.php'; /** Set the path to the view templates */ Nimble::set_config('view_path', FileUtils::join(dirname(__FILE__), '..', 'app', 'view')); /** set the default plugin path */ Nimble::set_config('plugins_path', FileUtils::join(dirname(__FILE__), '..', 'plugin')); Nimble::set_config('default_layout', FileUtils::join(Nimble::getInstance()->config['view_path'], 'layout', 'application.php')); /** set asset path change this in your config.php to override */ Nimble::set_config('stylesheet_folder', FileUtils::join(dirname(__FILE__), '..', 'public', 'style')); Nimble::set_config('stylesheet_folder_url', '/public/style'); Nimble::set_config('javascript_folder', FileUtils::join(dirname(__FILE__), '..', 'public', 'javascript')); Nimble::set_config('javascript_folder_url', '/public/javascript'); Nimble::set_config('image_url', 'public/image'); Nimble::set_config('image_path', FileUtils::join(dirname(__FILE__), '..', 'public', 'image')); Nimble::set_config('uri', '/'); //define the root define('NIMBLE_ROOT', FileUtils::join(dirname(__FILE__), '..')); // load any custom global config options require_once FileUtils::join(dirname(__FILE__), 'config.php'); require_once FileUtils::join(dirname(__FILE__), 'routes.php'); require_once FileUtils::join(dirname(__FILE__), 'r404.php'); // load any custom enviroment config options
/** * @param string $action action you wish to call * @param array $action_params array of arguments to pass to the action method */ private function load_action($action, $action_params) { global $_SESSION, $_POST, $_GET; $nimble = Nimble::getInstance(); ob_start(); $controller = new $this->controller_name(); $controller->format = !empty($action_params['format']) ? $action_params['format'] : $controller->default_format; call_user_func(array($controller, "run_before_filters"), $action); call_user_func_array(array($controller, $action), array($action_params)); $path = strtolower(Inflector::underscore(str_replace('Controller', '', $this->controller_name))); $template = FileUtils::join($path, $action); if ($controller->has_rendered === false) { if (empty($controller->layout_template) && $controller->layout) { $controller->set_layout_template(); } $controller->render($template); } call_user_func(array($controller, "run_after_filters"), $action); $this->response = ob_get_clean(); $this->controller = $controller; }
/** * Dump out application routes to a human readable format. * @param boolean $cli True if being called from the command line. * @return string The application's routes in a human readable format. */ public static function dumpRoutes($cli = false) { $klass = Nimble::getInstance(); $out = array(); foreach ($klass->routes as $route) { $pattern = self::clean_route($route->rule); $pattern = empty($pattern) ? 'root path' : $pattern; $string = ''; if (!empty($route->short_url)) { $string .= ' ' . CommandLineColor::underline('Short Url:') . ' ' . CommandLineColor::yellow($route->short_url) . ' '; } $string .= CommandLineColor::underline("Controller:") . ' ' . CommandLineColor::yellow($route->controller) . ' ' . CommandLineColor::underline('Action:') . ' ' . CommandLineColor::magenta($route->method) . ' ' . CommandLineColor::underline('Method:') . ' ' . CommandLineColor::green($route->http_method) . ' ' . CommandLineColor::underline('Pattern:') . ' ' . CommandLineColor::bold_red($pattern); array_push($out, $string); } $return = "\n"; $return .= join("\n", $out); $return .= "\n"; return $cli ? $return : htmlspecialchars($return); }