Example #1
0
	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);
		}
	}
Example #2
0
    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);
    }
Example #3
0
File: lang.php Project: nasumi/fuel
	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;
		}
	}
Example #4
0
 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);
     }
 }
Example #5
0
    public static function config($args, $build = true)
    {
        $args = self::_clear_args($args);
        $file = strtolower(array_shift($args));
        $config = array();
        // load the config
        if ($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;
            }
        }
        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') || \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 (\File_Exception $e) {
            throw new Exception("APPPATH/config/{$file}.php could not be written.");
        }
    }
Example #6
0
 /**
  * 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);
 }
Example #7
0
    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);
    }
Example #8
0
	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;
	}
Example #9
0
 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))) {
         $files = \Fuel::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"?', strtolower($task), current($possibilities)));
         } else {
             throw new Exception(sprintf('Task "%s" does not exist.', strtolower($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);
     }
 }
Example #10
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  Fuel_Exception
  */
 public function set_filename($file)
 {
     // set find_file's one-time-only search paths
     \Fuel::$volatile_paths = $this->request_paths;
     // locate the view file
     if (($path = \Fuel::find_file('views', $file, '.' . $this->extension, false, false)) === false) {
         throw new \Fuel_Exception('The requested view could not be found: ' . \Fuel::clean_path($file));
     }
     // Store the file path locally
     $this->_file = $path;
     return $this;
 }
Example #11
0
 public static function load($class)
 {
     $class = ltrim($class, '\\');
     $namespaced = ($pos = strripos($class, '\\')) !== false;
     if (empty(static::$auto_initialize)) {
         static::$auto_initialize = $class;
     }
     if (array_key_exists($class, static::$classes)) {
         include str_replace('/', DS, static::$classes[$class]);
         static::_init_class($class);
         return true;
     } elseif (!$namespaced and $class_name = static::is_core_class($class)) {
         include str_replace('/', DS, static::$classes[$class_name]);
         static::alias_to_namespace($class_name);
         static::_init_class($class);
         return true;
     } elseif (!$namespaced) {
         $file_path = str_replace('_', DS, $class);
         $file_path = \Fuel::find_file('classes', $file_path);
         if ($file_path !== false) {
             require $file_path;
             if (!class_exists($class, false) && class_exists($class_name = 'Fuel\\Core\\' . $class, false)) {
                 static::alias_to_namespace($class_name);
             }
             static::_init_class($class);
             return true;
         }
     } else {
         // need to stick the trimed \ back on...
         $namespace = '\\' . substr($class, 0, $pos);
         foreach (static::$namespaces as $ns => $path) {
             if (strncmp($ns, $namespace, $ns_len = strlen($ns)) === 0) {
                 $class_no_ns = substr($class, $pos + 1);
                 $file_path = strtolower($path . substr($namespace, strlen($ns) + 1) . DS . str_replace('_', DS, $class_no_ns) . '.php');
                 if (is_file($file_path)) {
                     // Fuel::$path_cache[$class] = $file_path;
                     // Fuel::$paths_changed = true;
                     require $file_path;
                     static::_init_class($class);
                     return true;
                 }
             }
         }
     }
     return false;
 }
Example #12
0
	public static function load($class)
	{
		$class = ltrim($class, '\\');
		$namespaced = strpos($class, '\\') !== false;

		if (empty(static::$auto_initialize))
		{
			static::$auto_initialize = $class;
		}
		if (array_key_exists($class, static::$classes))
		{
			include str_replace('/', DS, static::$classes[$class]);
			static::_init_class($class);
			return true;
		}
		elseif ( ! $namespaced and array_key_exists($class_name = 'Fuel\\Core\\'.$class, static::$classes))
		{
			include str_replace('/', DS, static::$classes[$class_name]);
			static::alias_to_namespace($class_name);
			static::_init_class($class);
			return true;
		}
		elseif ( ! $namespaced)
		{
			$file_path = str_replace('_', DS, $class);
			$file_path = \Fuel::find_file('classes', $file_path);
			if ($file_path !== false)
			{
				require $file_path;
				static::_init_class($class);
				return true;
			}
		}
		else
		{
			$file_path = str_replace('_', DS, ltrim(strrchr(strtolower($class), '\\'), '\\'));
			$file_path = \Fuel::find_file('', $file_path);
			if ($file_path !== false)
			{
				require $file_path;
				static::_init_class($class);
				return true;
			}
		}
		return false;
	}
Example #13
0
File: view.php Project: novius/core
	/**
	 * Sets the view filename.
	 *
	 *     $view->set_filename($file);
	 *
	 * @param   string  view filename
	 * @return  View
	 * @throws  Fuel_Exception
	 */
	public function set_filename($file)
	{
		if (($path = \Fuel::find_file('views', $file, '.'.$this->extension, false, false)) === false)
		{
			throw new \Fuel_Exception('The requested view could not be found: '.\Fuel::clean_path($file));
		}

		// Store the file path locally
		$this->_file = $path;

		return $this;
	}