Пример #1
0
 /**
  * Set up environment
  *
  * @param  string  $type
  * @param  string  $name
  */
 public function __construct($type, $name = 'all')
 {
     // Check type
     Assets::require_valid_type($type);
     // Set type and name
     $this->_type = $type;
     $this->_name = $name;
     // Set asset file and web file
     $this->_destination_file = Assets::file_path($type, $name . '.' . $type);
     $this->_destination_web = Assets::web_path($type, $name . '.' . $type);
 }
Пример #2
0
 /**
  * Set up the environment
  *
  * @param string $type
  * @param string $file
  * @param string $options
  * @param string $destination_path
  * @param bool   $copy
  * @param string $folder
  */
 function __construct($type, $file, array $options = array(), $destination_path = NULL, $copy = TRUE, $folder = NULL)
 {
     // Set processor to use
     $this->_processor = Arr::get($options, 'processor', Arr::get(Kohana::$config->load('asset-merger')->get('processor'), $type));
     // Set condition
     $this->_condition = Arr::get($options, 'condition');
     $this->_folder = $folder;
     // Set weight
     if (!empty($options['weight'])) {
         $this->_weight = $options['weight'];
     }
     // Set load paths
     if (!empty($options['load_paths'])) {
         $this->_load_paths = $options['load_paths'][$type];
     } elseif ($load_paths = Kohana::$config->load('asset-merger')->get('load_paths')) {
         $this->_load_paths = Arr::get($load_paths, $type);
     }
     // Set media
     if (!empty($options['media'])) {
         $this->_media = $options['media'];
     }
     // Set type and file
     $this->_type = $type;
     $this->_file = $file;
     $this->_copy = $copy;
     // Check if the type is a valid type
     Assets::require_valid_type($type);
     if (Valid::url($file)) {
         // No remote files allowed
         throw new Kohana_Exception('The asset :file must be local file', array(':file' => $file));
     }
     // Look for the specified file in each load path
     foreach ((array) $this->_load_paths as $path) {
         $path = rtrim($path, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
         if (is_file($path . $file)) {
             // Set the destination and source file
             $this->_destination_file = Assets::file_path($type, $file, $destination_path, $this->_folder);
             $this->_source_file = $path . $file;
             // Don't continue
             break;
         }
     }
     if (!$this->source_file()) {
         // File not found
         throw new Kohana_Exception('Asset :file of type :type not found inside :paths', array(':file' => $file, ':type' => $type, ':paths' => join(', ', (array) Arr::get(Kohana::$config->load('asset-merger')->get('load_paths'), $type))));
     }
     if (!is_dir(dirname($this->destination_file())) and $this->copy()) {
         // Create directory for destination file
         mkdir(dirname($this->destination_file()), 0777, TRUE);
     }
     // Get the file parts
     $fileparts = explode('.', basename($file));
     // Extension index
     $extension_index = array_search($this->type(), $fileparts);
     // Set engines
     $this->_engines = array_reverse(array_slice($fileparts, $extension_index + 1));
     // Set the web destination
     $this->_destination_web = Assets::web_path($type, $file, $destination_path, $this->_folder);
 }
Пример #3
0
 protected function set_destinations()
 {
     $hash = $this->hash_content();
     $this->_destination_file = Assets::file_path($this->type(), $this->name() . '-' . $hash . '.' . $this->type(), $this->destination_path(), $this->folder());
     $this->_destination_web = Assets::web_path($this->type(), $this->name() . '-' . $hash . '.' . $this->type(), $this->destination_path(), $this->folder());
 }
Пример #4
0
 public function test_file_path()
 {
     $this->assertEquals($this->data_dir() . 'assets' . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'test.js', Assets::file_path('js', 'test.js'));
     $this->assertEquals('assets/js/test.js', Assets::web_path('js', 'test.js'));
 }
Пример #5
0
 /**
  * Set up the environment
  *
  * @param  string  $type
  * @param  string  $file
  * @param  array   $options
  */
 function __construct($type, $file, array $options = array())
 {
     // Set processor to use
     $this->_processor = Arr::get($options, 'processor', Kohana::$config->load('asset-merger.processor.' . $type));
     // Set condition
     $this->_condition = Arr::get($options, 'condition');
     // Set type and file
     $this->_type = $type;
     $this->_file = $file;
     // Check if the type is a valid type
     Assets::require_valid_type($type);
     if (Valid::url($file)) {
         // No remote files allowed
         throw new Kohana_Exception('The asset :file must be local file', array(':file' => $file));
     }
     // Look for the specified file in each load path
     foreach ((array) Kohana::$config->load('asset-merger.load_paths.' . $type) as $path) {
         if (is_file($path . $file)) {
             // Set the destination and source file
             $this->_destination_file = Assets::file_path($type, $file);
             $this->_source_file = $path . $file;
             // Don't continue
             break;
         }
     }
     if (!$this->source_file()) {
         // File not found
         throw new Kohana_Exception('Asset :file of type :type not found inside :paths', array(':file' => $file, ':type' => $type, ':paths' => join(', ', (array) Kohana::$config->load('asset-merger.load_paths.' . $type))));
     }
     if (!is_dir(dirname($this->destination_file()))) {
         // Create directory for destination file
         mkdir(dirname($this->destination_file()), 0777, TRUE);
     }
     // Get the file parts
     $fileparts = explode('.', basename($file));
     // Extension index
     $extension_index = array_search($this->type(), $fileparts);
     // Set engines
     $this->_engines = array_reverse(array_slice($fileparts, $extension_index + 1));
     // Set the web destination
     $this->_destination_web = Assets::web_path($type, $file);
 }