예제 #1
0
파일: php.php 프로젝트: takawasitobi/pembit
 /**
  * Formats the output and saved it to disc.
  *
  * @param   string     $identifier  filename
  * @param   $contents  $contents    language array to save
  * @return  bool       \File::update result
  */
 public function save($identifier, $contents)
 {
     // store the current filename
     $file = $this->file;
     // save it
     $return = parent::save($identifier, $contents);
     // existing file? saved? and do we need to flush the opcode cache?
     if ($file == $this->file and $return and static::$flush_needed) {
         if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) {
             // locate the file
             if ($pos = strripos($identifier, '::')) {
                 // get the namespace path
                 if ($file = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) {
                     // strip the namespace from the filename
                     $identifier = substr($identifier, $pos + 2);
                     // strip the classes directory as we need the module root
                     $file = substr($file, 0, -8) . 'lang' . DS . $identifier;
                 } else {
                     // invalid namespace requested
                     return false;
                 }
             } else {
                 $file = \Finder::search('lang', $identifier);
             }
         }
         // make sure we have a fallback
         $file or $file = APPPATH . 'lang' . DS . $identifier;
         // flush the opcode caches that are active
         static::$uses_opcache and opcache_invalidate($file, true);
         static::$uses_apc and apc_compile_file($file);
     }
     return $return;
 }
예제 #2
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 = \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.");
        }
    }
예제 #3
0
 /**
  * Finds the given config files
  *
  * @param   bool  $multiple  Whether to load multiple files or not
  * @return  array
  */
 protected function find_file()
 {
     $paths = \Finder::search('config', $this->file, $this->ext, true);
     $paths = array_merge(\Finder::search('config/' . \Fuel::$env, $this->file, $this->ext, true), $paths);
     if (count($paths) > 0) {
         return array_reverse($paths);
     }
     throw new \ConfigException(sprintf('File "%s" does not exist.', $this->file));
 }
예제 #4
0
 public static function run($task, $args = array())
 {
     $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 {
             \Module::load($module);
             $path = \Module::exists($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 has been called, so call help instead
     if ((\Cli::option('help') or $method == 'help') and is_callable(array($new_task, 'help'))) {
         $method = 'help';
     } else {
         // if the task has an init method, call it now
         is_callable($task . '::_init') and $task::_init();
     }
     if ($return = call_fuel_func_array(array($new_task, $method), $args)) {
         \Cli::write($return);
     }
 }
예제 #5
0
파일: theme.php 프로젝트: rundiz/fuel-start
 /**
  * find view file<br>
  * this method that extends fuelphp core theme is for re-arrange priority of theme and views.
  * 
  * @param string $view
  * @param string $themes
  * @return string
  */
 protected function find_file($view, $themes = null)
 {
     if ($themes === null) {
         $themes = array($this->active, $this->fallback);
     }
     // determine the path prefix and optionally the module path
     $path_prefix = '';
     $module_path = null;
     if ($this->config['use_modules'] and class_exists('Request', false) and $request = \Request::active() and $module = $request->module) {
         // we're using module name prefixing
         $path_prefix = $module . DS;
         // and modules are in a separate path
         is_string($this->config['use_modules']) and $path_prefix = trim($this->config['use_modules'], '\\/') . DS . $path_prefix;
         // do we need to check the module too?
         $this->config['use_modules'] === true and $module_path = \Module::exists($module) . 'themes' . DS;
     }
     foreach ($themes as $theme) {
         $ext = pathinfo($view, PATHINFO_EXTENSION) ? '.' . pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext'];
         $file = (pathinfo($view, PATHINFO_DIRNAME) ? str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)) . DS : '') . pathinfo($view, PATHINFO_FILENAME);
         if (empty($theme['find_file'])) {
             if ($module_path and !empty($theme['name']) and is_file($path = $module_path . $theme['name'] . DS . $file . $ext)) {
                 // if use_modules is true then this $path will be /www/root/modules/<module name>/themes/<theme name>/<$view>.php
                 return $path;
             } elseif (is_file($path = $theme['path'] . $path_prefix . $file . $ext)) {
                 // if use_modules is true then $path will be /www/root/<theme path>/<theme name>/<module name>/<$view>.php
                 // if use_modules is 'modules' then $path will be /www/root/<theme path>/<theme name>/modules/<module name>/<$view>.php
                 return $path;
             } elseif (is_file($path = \Module::exists($module) . 'views' . DS . $file . $ext)) {
                 /**
                  * this condition was added by Vee W.
                  * look directly in modules/module_name/views. this $path will be /www/root/<modules path>/<module name>/views/<$view>.php
                  * 
                  * @author Vee W.
                  */
                 return $path;
             } elseif (is_file($path = $theme['path'] . $file . $ext)) {
                 // this will not look into module name anymore. $path will be /www/root/<theme path>/<theme name>/<$view>.php
                 return $path;
             }
         } else {
             if ($path = \Finder::search($theme['path'] . $path_prefix, $file, $ext)) {
                 return $path;
             }
         }
     }
     // not found, return the viewname to fall back to the standard View processing
     return $view;
 }
예제 #6
0
 /**
  * Formats the output and saved it to disk.
  *
  * @param   $contents  $contents    config array to save
  * @return  bool       \File::update result
  */
 public function save($contents)
 {
     // store the current filename
     $file = $this->file;
     // save it
     $return = parent::save($contents);
     // existing file? saved? and do we need to flush the opcode cache?
     if ($file == $this->file and $return and static::$flush_needed) {
         if ($this->file[0] !== '/' and (!isset($this->file[1]) or $this->file[1] !== ':')) {
             // locate the file
             $file = \Finder::search('config', $this->file, $this->ext);
         }
         // make sure we have a fallback
         $file or $file = APPPATH . 'config' . DS . $this->file . $this->ext;
         // flush the opcode caches that are active
         static::$uses_opcache and opcache_invalidate($file, true);
         static::$uses_apc and apc_compile_file($file);
     }
     return $return;
 }
예제 #7
0
 /**
  * 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]);
     }
 }
예제 #8
0
파일: view.php 프로젝트: rcrowe/fuel-pjax
 public function set_filename($file)
 {
     // set find_file's one-time-only search paths
     \Finder::instance()->flash($this->request_paths);
     $is_pjax = Input::server('HTTP_X_PJAX') or Input::get('_pjax');
     // Check if this request is being made by PJAX
     if ($is_pjax) {
         $pjax_file = explode('.', $file);
         $pjax_file = $pjax_file[0] . Config::get('pjax.file', '-pjax');
         // locate the pjax view file
         if (($path = \Finder::search('views', $pjax_file, '.' . $this->extension, false, false)) !== false) {
             $this->pjax_file_loaded = true;
         } else {
             // PJAX file not found, carry on looking for normal view file
             if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
                 throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file));
             }
         }
         Log::info('Pjax\\View::forge - loaded WITH PJAX: ' . $path);
     } else {
         // locate the view file
         if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
             throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file));
         }
         Log::info('Pjax\\View::forge - loaded WITHOUT PJAX: ' . $path);
     }
     // Store the file path locally
     $this->file_name = $path;
     return $this;
 }
예제 #9
0
    public static function config($args)
    {
        $file = strtolower(array_shift($args));
        if (empty($file)) {
            throw new Exception('No config filename has been provided.');
        }
        $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'));
        // strip whitespace and add tab
        $export = str_replace(array('  ', 'array ('), array("\t", 'array('), var_export($config, true));
        $content = '<?php' . PHP_EOL . PHP_EOL . 'return ' . $export . ';';
        $content .= <<<CONF


/* End of file {$file}.php */
CONF;
        $module = \Cli::option('module', \Cli::option('m'));
        // add support for `php oil g config module::file arg1:value1`
        if (strpos($file, '::') !== false) {
            list($module, $file) = explode('::', $file);
        }
        // get the namespace path (if available)
        if (!empty($module) and $path = \Autoloader::namespace_path('\\' . ucfirst($module))) {
            // strip the classes directory as we need the module root
            // and construct the filename
            $path = substr($path, 0, -8) . 'config' . DS . $file . '.php';
            $path_name = "\\" . ucfirst($module) . '::';
        } elseif (!empty($module)) {
            throw new Exception("{$module} need to be loaded first, please use config always_load.modules.");
        } else {
            $path = APPPATH . 'config' . DS . $file . '.php';
            $path_name = 'APPPATH/';
        }
        if (!$overwrite and is_file($path)) {
            throw new Exception("{$path_name}/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: {$path_name}config/{$file}.php", 'green');
        } catch (\InvalidPathException $e) {
            throw new Exception("Invalid basepath, cannot update at " . $path_name . "config" . DS . "{$file}.php");
        } catch (\FileAccessException $e) {
            throw new Exception($path_name . "config" . DS . $file . ".php could not be written.");
        }
    }
예제 #10
0
 /**
  * Find the absolute path to a file in a set of Themes.  You can optionally
  * send an array of themes to search.  If you do not, it will search active
  * then fallback (in that order).
  *
  * @param   string  $view    name of the view to find
  * @param   array   $themes  optional array of themes to search
  * @return  string  absolute path to the view
  * @throws  \ThemeException  when not found
  */
 protected function find_file($view, $themes = null)
 {
     if ($themes === null) {
         $themes = array($this->active, $this->fallback);
     }
     foreach ($themes as $theme) {
         $ext = pathinfo($view, PATHINFO_EXTENSION) ? '.' . pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext'];
         $file = (pathinfo($view, PATHINFO_DIRNAME) ? str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)) . DS : '') . pathinfo($view, PATHINFO_FILENAME);
         if (empty($theme['find_file'])) {
             if (is_file($path = $theme['path'] . $file . $ext)) {
                 return $path;
             }
         } else {
             if ($path = \Finder::search($theme['path'], $file, $ext)) {
                 return $path;
             }
         }
     }
     // not found, return the viewname to fall back to the standard View processing
     return $view;
 }
예제 #11
0
파일: config.php 프로젝트: phabos/fuel-core
    /**
     * Save a config array to disc.
     *
     * @param   string          $file      desired file name
     * @param   string|array    $config    master config array key or config array
     * @return  bool                       false when config is empty or invalid else \File::update result
     */
    public static function save($file, $config)
    {
        if (!is_array($config)) {
            if (!isset(static::$items[$config])) {
                return false;
            }
            $config = static::$items[$config];
        }
        $content = <<<CONF
<?php

CONF;
        $content .= 'return ' . str_replace(array('  ', 'array (', '\'' . APPPATH, '\'' . DOCROOT, '\'' . COREPATH, '\'' . PKGPATH), array("\t", 'array(', 'APPPATH.\'', 'DOCROOT.\'', 'COREPATH.\'', 'PKGPATH.\''), var_export($config, true)) . ";\n";
        if (!($path = \Finder::search('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;
                }
            }
        }
        // absolute path requested?
        if ($file[0] === '/' or isset($file[1]) and $file[1] === ':') {
            $path = $file;
        }
        // make sure we have a fallback
        $path or $path = APPPATH . 'config' . DS . $file . '.php';
        $path = pathinfo($path);
        if (!is_dir($path['dirname'])) {
            mkdir($path['dirname'], 0777, true);
        }
        return \File::update($path['dirname'], $path['basename'], $content);
    }
예제 #12
0
 /**
  * Formats the output and saved it to disc.
  *
  * @param   string     $identifier  filename
  * @param   $contents  $contents    config array to save
  * @return  bool       \File::update result
  */
 public function save($identifier, $contents)
 {
     // get the formatted output
     $output = $this->export_format($contents);
     if (!$output) {
         return false;
     }
     if (!($path = \Finder::search('config', $identifier))) {
         if ($pos = strripos($identifier, '::')) {
             // get the namespace path
             if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($identifier, 0, $pos)))) {
                 // strip the namespace from the filename
                 $identifier = substr($identifier, $pos + 2);
                 // strip the classes directory as we need the module root
                 $path = substr($path, 0, -8) . 'config' . DS . $identifier;
             } else {
                 // invalid namespace requested
                 return false;
             }
         }
     }
     // absolute path requested?
     if ($identifier[0] === '/' or isset($identifier[1]) and $identifier[1] === ':') {
         $path = $identifier;
     }
     // make sure we have a fallback
     $path or $path = APPPATH . 'config' . DS . $identifier;
     $path = pathinfo($path);
     if (!is_dir($path['dirname'])) {
         mkdir($path['dirname'], 0777, true);
     }
     return \File::update($path['dirname'], $path['basename'], $output);
 }
예제 #13
0
 /**
  * Formats the output and saved it to disc.
  *
  * @param   $contents  $contents    config array to save
  * @return  bool       \File::update result
  */
 public function save($contents)
 {
     // get the formatted output
     $output = $this->export_format($contents);
     if (!$output) {
         return false;
     }
     if (!($path = \Finder::search('config', $this->file, $this->ext))) {
         if ($pos = strripos($this->file, '::')) {
             // get the namespace path
             if ($path = \Autoloader::namespace_path('\\' . ucfirst(substr($this->file, 0, $pos)))) {
                 // strip the namespace from the filename
                 $this->file = substr($this->file, $pos + 2);
                 // strip the classes directory as we need the module root
                 $path = substr($path, 0, -8) . 'config' . DS . $this->file . $this->ext;
             } else {
                 // invalid namespace requested
                 return false;
             }
         }
     }
     // absolute path requested?
     if ($this->file[0] === '/' or isset($this->file[1]) and $this->file[1] === ':') {
         $path = $this->file;
     }
     // make sure we have a fallback
     $path or $path = APPPATH . 'config' . DS . $this->file . $this->ext;
     $path = pathinfo($path);
     if (!is_dir($path['dirname'])) {
         mkdir($path['dirname'], 0777, true);
     }
     $return = \File::update($path['dirname'], $path['basename'], $output);
     if ($return) {
         try {
             \Config::load('file', true);
             chmod($path['dirname'] . DS . $path['basename'], \Config::get('file.chmod.files', 0666));
         } catch (\PhpErrorException $e) {
             // if we get something else then a chmod error, bail out
             if (substr($e->getMessage(), 0, 8) !== 'chmod():') {
                 throw new $e();
             }
         }
     }
     return $return;
 }
예제 #14
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  FuelException
  */
 public function set_filename($file)
 {
     // strip the extension from it
     $pathinfo = pathinfo($file);
     if (!empty($pathinfo['extension'])) {
         $this->extension = $pathinfo['extension'];
         $file = substr($file, 0, strlen($this->extension) * -1 - 1);
     }
     // set find_file's one-time-only search paths
     \Finder::instance()->flash($this->request_paths);
     // locate the view file
     if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
         throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file) . '.' . $this->extension);
     }
     // Store the file path locally
     $this->file_name = $path;
     return $this;
 }
예제 #15
0
 /**
  * Find the absolute path to a file in a set of Themes.  You can optionally
  * send an array of themes to search.  If you do not, it will search active
  * then fallback (in that order).
  *
  * @param   string  $view    name of the view to find
  * @param   array   $themes  optional array of themes to search
  * @return  string  absolute path to the view
  * @throws  \ThemeException  when not found
  */
 protected function find_file($view, $themes = null)
 {
     if ($themes === null) {
         $themes = array($this->active, $this->fallback);
     }
     // determine the path prefix and optionally the module path
     $path_prefix = '';
     $module_path = null;
     if ($this->config['use_modules'] and class_exists('Request', false) and $request = \Request::active() and $module = $request->module) {
         // we're using module name prefixing
         $path_prefix = $module . DS;
         // and modules are in a separate path
         is_string($this->config['use_modules']) and $path_prefix = trim($this->config['use_modules'], '\\/') . DS . $path_prefix;
         // do we need to check the module too?
         $this->config['use_modules'] === true and $module_path = \Module::exists($module) . 'themes' . DS;
     }
     foreach ($themes as $theme) {
         $ext = pathinfo($view, PATHINFO_EXTENSION) ? '.' . pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext'];
         $file = (pathinfo($view, PATHINFO_DIRNAME) ? str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)) . DS : '') . pathinfo($view, PATHINFO_FILENAME);
         if (empty($theme['find_file'])) {
             if ($module_path and !empty($theme['name']) and is_file($path = $module_path . $theme['name'] . DS . $file . $ext)) {
                 return $path;
             } elseif (is_file($path = $theme['path'] . $path_prefix . $file . $ext)) {
                 return $path;
             } elseif (is_file($path = $theme['path'] . $file . $ext)) {
                 return $path;
             }
         } else {
             if ($path = \Finder::search($theme['path'] . $path_prefix, $file, $ext)) {
                 return $path;
             }
         }
     }
     // not found, return the viewname to fall back to the standard View processing
     return $view;
 }
예제 #16
0
파일: fuel.php 프로젝트: phabos/fuel-core
 /**
  * Finds a file in the given directory.  It allows for a cascading filesystem.
  *
  * @param   string   The directory to look in.
  * @param   string   The name of the file
  * @param   string   The file extension
  * @param   boolean  if true return an array of all files found
  * @param   boolean  if false do not cache the result
  * @return  string   the path to the file
  * @deprecated  Replaced by Finder::search()
  */
 public static function find_file($directory, $file, $ext = '.php', $multiple = false, $cache = true)
 {
     logger(\Fuel::L_WARNING, 'This method is deprecated.  Please use a Finder::search() instead.', __METHOD__);
     return \Finder::search($directory, $file, $ext, $multiple, $cache);
 }
예제 #17
0
파일: theme.php 프로젝트: phabos/fuel-core
 /**
  * Find the absolute path to a file in a set of Themes.  You can optionally
  * send an array of themes to search.  If you do not, it will search active
  * then fallback (in that order).
  *
  * @param   string  $view    name of the view to find
  * @param   array   $themes  optional array of themes to search
  * @return  string  absolute path to the view
  * @throws  \ThemeException  when not found
  */
 protected function find_file($view, $themes = null)
 {
     if ($themes === null) {
         $themes = array($this->active, $this->fallback);
     }
     foreach ($themes as $theme) {
         $ext = pathinfo($view, PATHINFO_EXTENSION) ? '.' . pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext'];
         $file = (pathinfo($view, PATHINFO_DIRNAME) ? str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)) . DS : '') . pathinfo($view, PATHINFO_FILENAME);
         if (empty($theme['find_file'])) {
             if (is_file($path = $theme['path'] . $file . $ext)) {
                 return $path;
             }
         } else {
             if ($path = \Finder::search($theme['path'], $file, $ext)) {
                 return $path;
             }
         }
     }
     throw new \ThemeException(sprintf('Could not locate view "%s" in the theme "%s".', $view, $this->active['name']));
 }
예제 #18
0
 /**
  * Sets the view filename.
  *
  *     $view->set_filename($file);
  *
  * @param   string  view filename
  * @return  View
  * @throws  FuelException
  */
 public function set_filename($file)
 {
     // set find_file's one-time-only search paths
     \Finder::instance()->flash($this->request_paths);
     // locate the view file
     if (($path = \Finder::search('views', $file, '.' . $this->extension, false, false)) === false) {
         throw new \FuelException('The requested view could not be found: ' . \Fuel::clean_path($file));
     }
     // Store the file path locally
     $this->file_name = $path;
     return $this;
 }
예제 #19
0
 /**
  * Find the absolute path to a file in a set of Themes.  You can optionally
  * send an array of themes to search.  If you do not, it will search active
  * then fallback (in that order).
  *
  * @param   string  $view    name of the view to find
  * @param   array   $themes  optional array of themes to search
  * @return  string  absolute path to the view
  * @throws  \ThemeException  when not found
  */
 protected function find_file($view, $themes = null)
 {
     if ($themes === null) {
         $themes = array($this->active, $this->fallback);
     }
     // determine the path prefix
     $path_prefix = '';
     if ($this->config['use_modules'] and $module = \Request::active()->module) {
         // we're using module name prefixing
         $path_prefix = $module . DS;
         // and modules are in a separate path
         is_string($this->config['use_modules']) and $path_prefix = trim($this->config['use_modules'], '\\/') . DS . $path_prefix;
     }
     foreach ($themes as $theme) {
         $ext = pathinfo($view, PATHINFO_EXTENSION) ? '.' . pathinfo($view, PATHINFO_EXTENSION) : $this->config['view_ext'];
         $file = (pathinfo($view, PATHINFO_DIRNAME) ? str_replace(array('/', DS), DS, pathinfo($view, PATHINFO_DIRNAME)) . DS : '') . pathinfo($view, PATHINFO_FILENAME);
         if (empty($theme['find_file'])) {
             if (is_file($path = $theme['path'] . $path_prefix . $file . $ext)) {
                 return $path;
             } elseif (is_file($path = $theme['path'] . $file . $ext)) {
                 return $path;
             }
         } else {
             if ($path = \Finder::search($theme['path'] . $path_prefix, $file, $ext)) {
                 return $path;
             }
         }
     }
     // not found, return the viewname to fall back to the standard View processing
     return $view;
 }