public static function load($file, $group = null) { $lang = array(); // Use the current language, failing that use the fallback language foreach (array(\Config::get('language'), static::$fallback) as $language) { if ($path = \Fuel::find_file('lang/'.$language, $file, '.php', true)) { $lang = array(); foreach ($path as $p) { $lang = $lang + \Fuel::load($p); } break; } } if ($group === null) { static::$lines = static::$lines + $lang; } else { if ( ! isset(static::$lines[$group])) { static::$lines[$group] = array(); } static::$lines[$group] = static::$lines[$group] + $lang; } }
/** * Get or inject a ProcessWire API variable * * 1. As a getter (option 1): * ========================== * Usage: $this->wire('name'); // name is an API variable name * If 'name' does not exist, a WireException will be thrown. * Specify '*' or 'all' for name to retrieve all API vars (as a Fuel object) * * 2. As a getter (option 2): * ========================== * Usage: $this->wire()->name; // name is an API variable name * Null will be returned if API var does not exist (no Exception thrown). * * 3. As a setter: * =============== * $this->wire('name', $value); * $this->wire('name', $value, true); // lock the API variable so nothing else can overwrite it * $this->wire()->set('name', $value); * $this->wire()->set('name', $value, true); // lock the API variable so nothing else can overwrite it * * 4. As a dependency injector (PW 3.0 only) * ========================================= * $this->wire(new Page()); * When creating a new object, this makes it inject the current PW instance into that object. * * @param string|object $name Name of API variable to retrieve, set, or omit to retrieve the master ProcessWire object * @param null|mixed $value Value to set if using this as a setter, otherwise omit. * @param bool $lock When using as a setter, specify true if you want to lock the value from future changes (default=false) * @return ProcessWire|Wire|Session|Page|Pages|Modules|User|Users|Roles|Permissions|Templates|Fields|Fieldtypes|Sanitizer|Config|Notices|WireDatabasePDO|WireInput|string|mixed * @throws WireException * * */ public function wire($name = '', $value = null, $lock = false) { if (is_null(self::$fuel)) { self::$fuel = new Fuel(); } if ($value !== null) { // setting a fuel value return self::$fuel->set($name, $value, $lock); } if (empty($name)) { // return ProcessWire instance return self::$fuel->wire; } else { if ($name === '*' || $name === 'all') { // return Fuel instance return self::$fuel; } } /* TBA PW3 if(is_object($name)) { // injecting ProcessWire instance to object if($name instanceof Wire) return $name->setWire($this->_wire); // inject fuel, PW 3.0 throw new WireException("Expected Wire instance"); } */ // get API variable $value = self::$fuel->{$name}; return $value; }
/** * Quick and nice way to output a mixed variable to the browser * * @static * @access public * @return string */ public static function inspect() { $backtrace = debug_backtrace(); // If being called from within, show the file above in the backtrack if (strpos($backtrace[0]['file'], 'core/classes/debug.php') !== FALSE) { $callee = $backtrace[1]; $label = \Inflector::humanize($backtrace[1]['function']); } else { $callee = $backtrace[0]; $label = 'Debug'; } $arguments = func_get_args(); $total_arguments = count($arguments); $callee['file'] = \Fuel::clean_path($callee['file']); if (!static::$js_displayed) { echo <<<JS <script type="text/javascript">function fuel_debug_toggle(a){if(document.getElementById){if(document.getElementById(a).style.display=="none"){document.getElementById(a).style.display="block"}else{document.getElementById(a).style.display="none"}}else{if(document.layers){if(document.id.display=="none"){document.id.display="block"}else{document.id.display="none"}}else{if(document.all.id.style.display=="none"){document.all.id.style.display="block"}else{document.all.id.style.display="none"}}}};</script> JS; static::$js_displayed = true; } echo '<div style="font-size: 13px;background: #EEE !important; border:1px solid #666; color: #000 !important; padding:10px;">'; echo '<h1 style="border-bottom: 1px solid #CCC; padding: 0 0 5px 0; margin: 0 0 5px 0; font: bold 120% sans-serif;">' . $callee['file'] . ' @ line: ' . $callee['line'] . '</h1>'; echo '<pre style="overflow:auto;font-size:100%;">'; $i = 0; foreach ($arguments as $argument) { echo '<strong>' . $label . ' #' . ++$i . ' of ' . $total_arguments . '</strong>:<br />'; echo static::format('...', $argument); echo '<br />'; } echo "</pre>"; echo "</div>"; }
/** * Gets a dot-notated key from an array, with a default value if it does * not exist. * * @param array $array The search array * @param mixed $key The dot-notated key or array of keys * @param string $default The default value * @return mixed */ public static function get($array, $key, $default = null) { if (!is_array($array) and !$array instanceof \ArrayAccess) { throw new \InvalidArgumentException('First parameter must be an array or ArrayAccess object.'); } if (is_null($key)) { return $array; } if (is_array($key)) { $return = array(); foreach ($key as $k) { $return[$k] = static::get($array, $k, $default); } return $return; } foreach (explode('.', $key) as $key_part) { if (($array instanceof \ArrayAccess and isset($array[$key_part])) === false) { if (!is_array($array) or !array_key_exists($key_part, $array)) { return \Fuel::value($default); } } $array = $array[$key_part]; } return $array; }
public static function save($file, $config) { if (!is_array($config)) { if (!isset(static::$items[$config])) { return false; } $config = static::$items[$config]; } $content = <<<CONF <?php /** * Fuel * * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package\t\tFuel * @version\t\t1.0 * @author\t\tFuel Development Team * @license\t\tMIT License * @copyright\t2011 Fuel Development Team * @link\t\thttp://fuelphp.com */ CONF; $content .= 'return ' . str_replace(' ', "\t", var_export($config, true)) . ';'; $content .= <<<CONF /* End of file {$file}.php */ CONF; $path = \Fuel::find_file('config', $file, '.php') or $path[0] = APPPATH . 'config' . DS . $file . '.php'; $path = pathinfo($path[0]); return File::update($path['dirname'], $path['basename'], $content); }
public static function run($task, $args) { // Make sure something is set if ($task === null or $task === 'help') { static::help(); return; } // Just call and run() or did they have a specific method in mind? list($task, $method) = array_pad(explode(':', $task), 2, 'run'); $task = ucfirst(strtolower($task)); // Find the task if (!($file = \Fuel::find_file('tasks', $task))) { throw new Exception(sprintf('Task "%s" does not exist.', $task)); return; } require $file; $task = '\\Fuel\\Tasks\\' . $task; $new_task = new $task(); // The help option hs been called, so call help instead if (\Cli::option('help') && is_callable(array($new_task, 'help'))) { $method = 'help'; } if ($return = call_user_func_array(array($new_task, $method), $args)) { \Cli::write($return); } }
public static function config($args, $build = true) { $args = self::_clear_args($args); $file = strtolower(array_shift($args)); $config = array(); // load the config if ($paths = \Finder::search('config', $file, '.php', true)) { // Reverse the file list so that we load the core configs first and // the app can override anything. $paths = array_reverse($paths); foreach ($paths as $path) { $config = \Fuel::load($path) + $config; } } unset($path); // We always pass in fields to a config, so lets sort them out here. foreach ($args as $conf) { // Each paramater for a config is seperated by the : character $parts = explode(":", $conf); // We must have the 'name:value' if nothing else! if (count($parts) >= 2) { $config[$parts[0]] = $parts[1]; } } $overwrite = \Cli::option('o') or \Cli::option('overwrite'); $content = <<<CONF <?php /** * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package\t\tFuel * @version\t\t1.0 * @author\t\tFuel Development Team * @license\t\tMIT License * @copyright\t2011 Fuel Development Team * @link\t\thttp://fuelphp.com */ CONF; $content .= 'return ' . str_replace(' ', "\t", var_export($config, true)) . ';'; $content .= <<<CONF /* End of file {$file}.php */ CONF; $path = APPPATH . 'config' . DS . $file . '.php'; if (!$overwrite and is_file($path)) { throw new Exception("APPPATH/config/{$file}.php already exist, please use -overwrite option to force update"); } $path = pathinfo($path); try { \File::update($path['dirname'], $path['basename'], $content); \Cli::write("Created config: APPPATH/config/{$file}.php", 'green'); } catch (\InvalidPathException $e) { throw new Exception("Invalid basepath, cannot update at " . APPPATH . "config" . DS . "{$file}.php"); } catch (\FileAccessException $e) { throw new Exception(APPPATH . "config" . DS . $file . ".php could not be written."); } }
public static function init($args) { try { if (!isset($args[1])) { static::help(); return; } switch ($args[1]) { case 'g': case 'generate': switch ($args[2]) { case 'controller': case 'model': case 'view': case 'views': case 'migration': call_user_func('Oil\\Generate::' . $args[2], array_slice($args, 3)); break; case 'scaffold': call_user_func('Oil\\Scaffold::generate', array_slice($args, 3)); break; default: Generate::help(); } break; case 'c': case 'console': new Console(); case 'r': case 'refine': $task = isset($args[2]) ? $args[2] : null; call_user_func('Oil\\Refine::run', $task, array_slice($args, 3)); break; case 'p': case 'package': switch ($args[2]) { case 'install': case 'uninstall': call_user_func_array('Oil\\Package::' . $args[2], array_slice($args, 3)); break; default: Package::help(); } break; case '-v': case '--version': \Cli::write('Fuel: ' . \Fuel::VERSION); break; case 'test': \Fuel::add_package('octane'); call_user_func('\\Fuel\\Octane\\Tests::run_' . $args[2], array_slice($args, 3)); break; default: static::help(); } } catch (Exception $e) { \Cli::write(\Cli::color('Error: ' . $e->getMessage(), 'light_red')); \Cli::beep(); } }
/** * Returns the option with the given name. You can also give the option * number. * * Named options must be in the following formats: * php index.php user -v --v -name=John --name=John * * @param string|int $name the name of the option (int if unnamed) * @return string */ public static function option($name, $default = null) { if (!isset(static::$args[$name])) { return \Fuel::value($default); } return static::$args[$name]; }
/** * Get stencil data. * * @return mixed returns the array or string on success or false on failure */ public static function get($stencil_name, $key = null) { $stencil_path = STENCILSPATH . $stencil_name . DS . 'config.php'; if (!File::file_exists($stencil_path)) { return false; } if (!($stencil_data = \Fuel::load($stencil_path))) { return false; } // return value if key found if (isset($key)) { if (isset($stencil_data[$key])) { return $stencil_data[$key]; } else { return false; } } // build inflections replacement array $tbl_singular = Table::get('crud.TBL_SINGULAR'); $tbl_plural = Table::get('crud.TBL_PLURAL'); if ($tbl_prefix = Table::get('crud.TBL_PREFIX')) { $pfx_path = str_replace('_', DS, $tbl_prefix); $tbl_singular = str_replace($tbl_prefix, $pfx_path, $tbl_singular); $tbl_plural = str_replace($tbl_prefix, $pfx_path, $tbl_plural); } $inflections = array(':SINGULAR' => $tbl_singular, ':PLURAL' => $tbl_plural); // make the replacements foreach ($stencil_data['files'] as $key => $value) { $stencil_data['files'][$key]['output_path'] = str_replace(array_keys($inflections), array_values($inflections), $value['output_path']); } return $stencil_data; }
/** * Loads the given package. If a path is not given, then PKGPATH is used. * It also accepts an array of packages as the first parameter. * * @param string|array $package The package name or array of packages. * @param string|null $path The path to the package * @return bool True on success * @throws PackageNotFoundException */ public static function load($package, $path = null) { if (is_array($package)) { foreach ($package as $pkg) { $path = null; if (is_array($pkg)) { list($pkg, $path) = $pkg; } static::load($pkg, $path); } return false; } if (static::loaded($package)) { return; } // Load it from PKGPATH if no path was given. if ($path === null) { $path = PKGPATH . $package . DS; } if (!is_dir($path)) { throw new \PackageNotFoundException("Package '{$package}' could not be found at '" . \Fuel::clean_path($path) . "'"); } \Finder::instance()->add_path($path, 1); \Fuel::load($path . 'bootstrap.php'); static::$packages[$package] = $path; return true; }
public static function run($task, $args) { // Just call and run() or did they have a specific method in mind? list($task, $method)=array_pad(explode(':', $task), 2, 'run'); $task = ucfirst(strtolower($task)); if ( ! $file = \Fuel::find_file('tasks', $task)) { throw new \Exception('Well that didnt work...'); return; } require $file; $task = '\\Fuel\\Tasks\\'.$task; $new_task = new $task; // The help option hs been called, so call help instead if (\Cli::option('help') && is_callable(array($new_task, 'help'))) { $method = 'help'; } if ($return = call_user_func_array(array($new_task, $method), $args)) { \Cli::write($return); } }
/** * Loads the given package. * If a path is not given, if will search through * the defined package_paths. If not defined, then PKGPATH is used. * It also accepts an array of packages as the first parameter. * * @param string|array $package * The package name or array of packages. * @param string|null $path * The path to the package * @return bool True on success * @throws PackageNotFoundException */ public static function load($package, $path = null) { if (is_array($package)) { foreach ($package as $pkg => $path) { if (is_numeric($pkg)) { $pkg = $path; $path = null; } static::load($pkg, $path); } return false; } if (static::loaded($package)) { return; } // if no path is given, try to locate the package if ($path === null) { $paths = \Config::get('package_paths', array()); empty($paths) and $paths = array(PKGPATH); if (!empty($paths)) { foreach ($paths as $modpath) { if (is_dir($path = $modpath . strtolower($package) . DS)) { break; } } } } if (!is_dir($path)) { throw new \PackageNotFoundException("Package '{$package}' could not be found at '" . \Fuel::clean_path($path) . "'"); } \Finder::instance()->add_path($path, 1); \Fuel::load($path . 'bootstrap.php'); static::$packages[$package] = $path; return true; }
/** * {@inheritdoc} */ public static function forge($instance = 'default', array $handlers = array()) { $logger = new Monolog\Logger($instance); $handlers = \Arr::merge(\Config::get('logger.' . $instance, array()), $handlers); foreach ($handlers as $handler) { $handler = \Fuel::value($handler); $logger->pushHandler($handler); } return static::newInstance($instance, $logger); }
/** * passes the data to the template and returns the result * * @param string $template_file the template file used to structure the data * @return array the restructured data */ public function to($template) { $template_folder = \Config::get('structure.templates_folder'); $template_path = \Fuel::find_file($template_folder, $template); if (!$template_path) { throw new \Fuel_Exception('The requested template could not be found: ' . \Fuel::clean_path($file)); } $data = static::capture($template_path, $this->_data); return static::capture($template_path, $this->_data); }
public function action_index($page = 'petro') { $dir = APPPATH . 'views'; $file = '/dashboard/' . $page . '.md'; $path = \Fuel::clean_path($dir . $file); // var_dump($dir, $file, $path); // var_dump(\Finder::instance()->locate($dir, 'dashboard/index')); die; $data['text'] = \View::forge('dashboard/' . $page . '.md'); $this->template->content = \View::forge('dashboard/index', $data); }
public function test_debug_dump_by_call_fuel_func_array() { // Set to browser mode. \Fuel::$is_cli = false; $expected = '<div class="fuelphp-dump" style="font-size: 13px;background: #EEE !important; border:1px solid #666; color: #000 !important; padding:10px;"><h1 style="border-bottom: 1px solid #CCC; padding: 0 0 5px 0; margin: 0 0 5px 0; font: bold 120% sans-serif;">COREPATH/base.php @ line: 462</h1><pre style="overflow:auto;font-size:100%;"><strong>Variable #1:</strong>' . "\n" . '<i></i> <strong></strong> (Integer): 1' . "\n\n\n" . '<strong>Variable #2:</strong>' . "\n" . '<i></i> <strong></strong> (Integer): 2' . "\n\n\n" . '<strong>Variable #3:</strong>' . "\n" . '<i></i> <strong></strong> (Integer): 3' . "\n\n\n" . '</pre></div>'; ob_start(); call_fuel_func_array('\\Debug::dump', array(1, 2, 3)); $output = ob_get_contents(); ob_end_clean(); $this->assertEquals($expected, $output); }
public static function get($line, array $params = array(), $default = null, $language = null) { $output = parent::get($line, $params, '__NOT__FOUND__', $language); if (!empty($output) && $output != '__NOT__FOUND__') { return $output; } if ($output == '__NOT__FOUND__') { $output = $default; } if (!static::$autosave || !\CMF::$lang_enabled) { return $output; } $language === null and $language = static::get_lang(); $pos = strpos($line, '.'); $group = 'common'; $basename = $line; if ($pos === false) { if (empty($default)) { $default = $line; } $line = "{$group}.{$line}"; } else { $basename = substr($line, $pos + 1); if (empty($default)) { $default = $basename; } $group = substr($line, 0, $pos); } // Try and load from the DB... if (!in_array($group . '_' . $language, static::$loaded)) { static::load("{$group}.db", $group, $language, true, true); static::$loaded[] = $group . '_' . $language; } // Don't continue if it's not the 'common' group if ($group != 'common') { return $output != null ? \Str::tr(\Fuel::value($output), $params) : $default; } $output = \Arr::get(static::$lines, "{$language}.{$line}"); if ($output == null) { // First try and get from the fallback... $output = \Arr::get(static::$lines, static::$fallback[0] . ".{$line}"); if (!in_array($group, static::$to_save)) { static::$to_save[] = $group; } //if (!empty($default) && $default != $line) static::set($line, $default); static::set($line, $default, null, static::$fallback[0]); if ($output == null) { $output = $default; } } return $output != null ? \Str::tr(\Fuel::value($output), $params) : $default; }
public static function run($task, $args) { $task = strtolower($task); // Make sure something is set if (empty($task) or $task === 'help') { static::help(); return; } $module = false; list($module, $task) = array_pad(explode('::', $task), 2, null); if ($task === null) { $task = $module; $module = false; } if ($module) { try { $path = \Fuel::add_module($module); \Finder::instance()->add_path($path); } catch (\FuelException $e) { throw new Exception(sprintf('Module "%s" does not exist.', $module)); } } // Just call and run() or did they have a specific method in mind? list($task, $method) = array_pad(explode(':', $task), 2, 'run'); // Find the task if (!($file = \Finder::search('tasks', $task))) { $files = \Finder::instance()->list_files('tasks'); $possibilities = array(); foreach ($files as $file) { $possible_task = pathinfo($file, \PATHINFO_FILENAME); $difference = levenshtein($possible_task, $task); $possibilities[$difference] = $possible_task; } ksort($possibilities); if ($possibilities and current($possibilities) <= 5) { throw new Exception(sprintf('Task "%s" does not exist. Did you mean "%s"?', $task, current($possibilities))); } else { throw new Exception(sprintf('Task "%s" does not exist.', $task)); } return; } require_once $file; $task = '\\Fuel\\Tasks\\' . ucfirst($task); $new_task = new $task(); // The help option hs been called, so call help instead if (\Cli::option('help') && is_callable(array($new_task, 'help'))) { $method = 'help'; } if ($return = call_user_func_array(array($new_task, $method), $args)) { \Cli::write($return); } }
/** * Sets a signed cookie. Note that all cookie values must be strings and no * automatic serialization will be performed! * * // Set the "theme" cookie * Cookie::set('theme', 'red'); * * @param string name of cookie * @param string value of cookie * @param integer lifetime in seconds * @param string path of the cookie * @param string domain of the cookie * @param boolean if true, the cookie should only be transmitted over a secure HTTPS connection * @param boolean if true, the cookie will be made accessible only through the HTTP protocol * @return boolean */ public static function set($name, $value, $expiration = null, $path = null, $domain = null, $secure = null, $http_only = null) { $value = \Fuel::value($value); // use the class defaults for the other parameters if not provided is_null($expiration) and $expiration = static::$config['expiration']; is_null($path) and $path = static::$config['path']; is_null($domain) and $domain = static::$config['domain']; is_null($secure) and $secure = static::$config['secure']; is_null($http_only) and $http_only = static::$config['http_only']; // add the current time so we have an offset $expiration = $expiration > 0 ? $expiration + time() : 0; return setcookie($name, $value, $expiration, $path, $domain, $secure, $http_only); }
private function write($filepath, $data) { if (!($handle = fopen($filepath, 'w+'))) { throw new Exception('Cannot open file: ' . \Fuel::clean_path($filepath)); } $result = @fwrite($handle, $data); // Write $somecontent to our opened file. if ($result === FALSE) { throw new Exception('Cannot write to file: ' . \Fuel::clean_path($filepath)); } @fclose($handle); chmod($filepath, 0666); return $result; }
public function index() { $this->layout->body_class = ''; $zip_code = Input::query('zip_code', ''); $distance = Input::query('distance', '50'); if (empty($zip_code)) { $this->findLocation(); $zip_code = Session::get('zip_code', ''); } Session::put('zip_code', $zip_code); Session::put('distance', $distance); $data = array('search_text' => '', 'zip_code' => $zip_code, 'distance' => $distance, 'status' => $this->getStatus(), 'makes' => $this->getPropertiesList(Make::orderBy('make')->get(), 'make'), 'bodies' => $this->getPropertiesList(Body::orderBy('body')->get(), 'body'), 'transmissions' => $this->getPropertiesList(Transmission::orderBy('transmission')->get(), 'transmission'), 'drives' => $this->getPropertiesList(Drive::orderBy('drive')->get(), 'drive'), 'interiors' => $this->getPropertiesList(Interior::orderBy('interior', 'DESC')->take(10)->get(), 'interior'), 'exteriors' => $this->getPropertiesList(Exterior::orderBy('exterior', 'DESC')->take(10)->get(), 'exterior'), 'fuels' => $this->getPropertiesList(Fuel::orderBy('fuel')->get(), 'fuel'), 'doors_count' => $this->getDoorsCounts(), 'cylinders_count' => $this->getCylindersCounts()); $this->layout->contents = View::make('search/search-advanced', $data); }
public static function save($file, $config) { if (!is_array($config)) { if (!isset(static::$items[$config])) { return false; } $config = static::$items[$config]; } $content = <<<CONF <?php /** * Fuel is a fast, lightweight, community driven PHP5 framework. * * @package\t\tFuel * @version\t\t1.0 * @author\t\tFuel Development Team * @license\t\tMIT License * @copyright\t2011 Fuel Development Team * @link\t\thttp://fuelphp.com */ CONF; $content .= 'return ' . str_replace(' ', "\t", var_export($config, true)) . ';'; if (!($path = \Fuel::find_file('config', $file, '.php'))) { if ($pos = strripos($file, '::')) { // get the namespace path if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($file, 0, $pos)))) { // strip the namespace from the filename $file = substr($file, $pos + 2); // strip the classes directory as we need the module root // and construct the filename $path = substr($path, 0, -8) . 'config' . DS . $file . '.php'; } else { // invalid namespace requested return false; } } } $content .= <<<CONF CONF; // make sure we have a fallback $path or $path = APPPATH . 'config' . DS . $file . '.php'; $path = pathinfo($path); return File::update($path['dirname'], $path['basename'], $content); }
public function findSelectedFilter($filters, $aggregations, $fuel_filter) { if (!empty($fuel_filter)) { $values = array(); $fuel_ranges = explode("-", $fuel_filter); foreach ($fuel_ranges as $fuel_range) { $fuels = Fuel::where('id', '=', $fuel_range); if ($fuels->count()) { $title = $fuels->first()->fuel; array_push($values, array("title" => $title, "index" => 'fuel-remove-' . $fuel_range)); } } array_push($filters, array("name" => "Fuel", "values" => $values, "modal" => "fuel")); } return $filters; }
public static function load($file, $group = null, $reload = false) { if ( ! is_array($file) && array_key_exists($file, static::$loaded_files) and ! $reload) { return false; } $config = array(); if (is_array($file)) { $config = $file; } elseif ($paths = \Fuel::find_file('config', $file, '.php', true)) { // Reverse the file list so that we load the core configs first and // the app can override anything. $paths = array_reverse($paths); foreach ($paths as $path) { $config = \Fuel::load($path) + $config; } } if ($group === null) { static::$items = $reload ? $config : static::$items + $config; } else { $group = ($group === true) ? $file : $group; if ( ! isset(static::$items[$group]) or $reload) { static::$items[$group] = array(); } static::$items[$group] = static::$items[$group] + $config; } if ( ! is_array($file)) { static::$loaded_files[$file] = true; } return $config; }
public static function run() { $writable_paths = array( APPPATH . 'cache', APPPATH . 'logs', APPPATH . 'tmp' ); foreach ($writable_paths as $path) { if (@chmod($path, 0777)) { \Cli::write("\t" . \Cli::color('Made writable: ' . \Fuel::clean_path($path), 'green')); } else { \Cli::write("\t" . \Cli::color('Failed to make writable: ' . \Fuel::clean_path($path), 'red')); } } }
/** * Load a language file * * @param string * @param string|null name of the group to load to, null for global */ public static function load($file, $group = null, $language = null) { $languages = static::$fallback; array_unshift($languages, $language ?: \Config::get('language')); $lines = array(); foreach ($languages as $lang) { if ($path = \Finder::search('lang/' . $lang, $file, '.php', true)) { foreach ($path as $p) { $lines = \Arr::merge(\Fuel::load($p), $lines); } break; } } if ($group === null) { static::$lines = \Arr::merge($lines, static::$lines); } else { $group = $group === true ? $file : $group; if (!isset(static::$lines[$group])) { static::$lines[$group] = array(); } static::$lines[$group] = \Arr::merge($lines, static::$lines[$group]); } }
public function test_set_cache() { // Save the environment. While we're at it, save the whales, too. $backup = \Fuel::$env; /******************* * TEST A */ // Configure the environment to something that shouldn't allow for caching. \Fuel::$env = 'private'; \Utility::set_cache('test_set_cache', 'testvalue'); try { \Cache::get('test_set_cache'); \Fuel::$env = $backup; // Delete it for subsequent nuns. \Cache::delete('test_set_cache'); $this->fail; } catch (\CacheNotFoundException $e) { //The private and development environments should not cache the requests using \Utility. } /******************* * TEST B */ // Set the environment to allow for caching. \Fuel::$env = 'test'; \Utility::set_cache('test_set_cache', 'testvalue'); try { \Cache::get('test_set_cache'); } catch (\CacheNotFoundException $e) { //The private and development environments should not cache the requests using \Utility. \Fuel::$env = $backup; $this->fail; } // Delete it for subsequent nuns. \Cache::delete('test_set_cache'); // Restore the environment. (Eden?) \Fuel::$env = $backup; }
/** * Loads the given module. If a path is not given, then 'module_paths' is used. * It also accepts an array of modules as the first parameter. * * @param string|array $package The module name or array of modules. * @param string|null $path The path to the module * @return bool True on success * @throws ModuleNotFoundException */ public static function load($module, $path = null) { if (is_array($module)) { foreach ($module as $mod => $path) { if (is_numeric($mod)) { $mod = $path; $path = null; } static::load($mod, $path); } return false; } if (static::loaded($module)) { return; } // if no path is given, try to locate the module if ($path === null) { $paths = \Config::get('module_paths', array()); if (!empty($paths)) { foreach ($paths as $modpath) { if (is_dir($path = $modpath . strtolower($module) . DS)) { break; } } } } // make sure the path exists if (!is_dir($path)) { throw new ModuleNotFoundException("Module '{$module}' could not be found at '" . \Fuel::clean_path($path) . "'"); } // determine the module namespace $ns = '\\' . ucfirst($module); // add the namespace to the autoloader \Autoloader::add_namespaces(array($ns => $path . 'classes' . DS), true); static::$modules[$module] = $path; return true; }
<?php ini_set('default_charset', 'UTF-8'); // Bootstrap the framework DO NOT edit this require COREPATH . 'bootstrap.php'; \Autoloader::add_classes(array()); // Register the autoloader \Autoloader::register(); /** * Your environment. Can be set to any of the following: * * Fuel::DEVELOPMENT * Fuel::TEST * Fuel::STAGING * Fuel::PRODUCTION */ \Fuel::$env = isset($_SERVER['FUEL_ENV']) ? $_SERVER['FUEL_ENV'] : \Fuel::DEVELOPMENT; // Initialize the framework with the config file. \Fuel::init('config.php');