/** * Constructor * * @return void **/ public function __construct() { $config = \Configure::instance(); $this->plugins = $config->plugins; $this->_view_vars = array(); $this->layout = isset($config->options['layout']) && !empty($config->options['layout']) ? $config->options['layout'] : "main"; }
public static function validate($request) { $config = \Configure::instance(); $data = $config->authentication; if (empty($data)) { return null; } foreach ($data as $url => $values) { $redirect = isset($values['on_fail']) ? $values['on_fail'] : "/"; if (preg_match('@' . $url . '/?@i', $request)) { // Match the requested url. if (!isset($values['allow'])) { throw new Exception('Invalid user type or user type not set for protected url ' . $request); } $valid_user = $values['allow']; if (is_array($valid_user)) { // Access list is an array of user types. $pass = false; foreach ($valid_user as $user) { if (self::get() == $user) { $pass = true; } } // Check list of users for match if ($pass == false) { if (!preg_match('@' . $request . '/?@i', $redirect)) { \Controller\Flash::instance()->error('You must be logged in to access this page.'); Application::redirect($redirect); break; } } } else { // Access list is a single user type. $valid_user = strtolower($valid_user); if (self::get() != $valid_user) { // If user isn't allowed, redirect. if (!preg_match('@' . $request . '/?@i', $redirect)) { \Controller\Flash::instance()->error('You must be logged in to access this page.'); header('HTTP/1.0 401 Unauthorized'); header("Location:" . $redirect); exit; } } } } } }
public static function find($namespace = null) { $namespace = strtolower($namespace); if (!self::$instance) { self::$instance = new self(); } if ($namespace) { if (!self::$instance->exists($namespace)) { self::$instance->write($namespace, null); } $configure = clone self::$instance; $configure->namespace = $namespace; $configure->data =& self::$instance->data; $namespace_parts = explode('.', $namespace); $len = sizeof($namespace_parts); for ($i = 0; $i < $len; $i++) { $configure->data =& $configure->data[$namespace_parts[$i]]; } return $configure; } else { return self::$instance; } }
<?php $config = Configure::instance(); $config->project = array('name' => 'Valet', 'description' => 'Valet framework sample site.'); $config->options = array('layout' => 'main', 'caching' => false); $config->authentication = array('admin/?(.*)?' => array('allow' => 'admin', 'on_fail' => '/')); $config->plugins = array();