/**
  * Parses instruction sets and invokes `Medium::make()` for a file
  *
  * @param Model $Model
  * @param string $file Path to a file relative to `baseDirectory`  or an absolute path to a file
  * @return boolean
  */
 function make(&$Model, $file, $overwrite = false)
 {
     extract($this->settings[$Model->alias]);
     list($file, $relativeFile) = $this->_file($Model, $file);
     $relativeDirectory = DS . rtrim(dirname($relativeFile), '.');
     $name = Medium::name($file);
     $filter = Configure::read('Media.filter.' . strtolower($name));
     $hasCallback = method_exists($Model, 'beforeMake');
     foreach ($filter as $version => $instructions) {
         $directory = Folder::slashTerm($filterDirectory . $version . $relativeDirectory);
         $Folder = new Folder($directory, $createDirectory);
         if (!$Folder->pwd()) {
             $message = "MediaBehavior::make - Directory `{$directory}` ";
             $message .= "could not be created or is not writable. ";
             $message .= "Please check the permissions.";
             trigger_error($message, E_USER_WARNING);
             continue;
         }
         if ($hasCallback) {
             $process = compact('overwrite', 'directory', 'name', 'version', 'instructions');
             if ($Model->beforeMake($file, $process)) {
                 continue;
             }
         }
         if (!($Medium = Medium::make($file, $instructions))) {
             $message = "MediaBehavior::make - Failed to make version `{$version}` ";
             $message .= "of file `{$file}`. ";
             trigger_error($message, E_USER_WARNING);
             continue;
         }
         $Medium->store($directory . basename($file), $overwrite);
     }
     return true;
 }
Beispiel #2
0
 /**
  * "makes" a file
  *
  * @param string $file Absolute path to a file
  * @access protected
  * @return boolean
  */
 function _make($file)
 {
     $File = new File($file);
     $name = Medium::name($file);
     $subdir = array_pop(explode(DS, dirname($this->source)));
     if ($name === 'Icon' || strpos($file, 'ico' . DS) !== false) {
         return true;
     }
     if ($this->version) {
         $configString = 'Media.filter.' . strtolower($name) . '.' . $this->version;
         $filter = array(Configure::read($configString));
     } else {
         $configString = 'Media.filter.' . strtolower($name);
         $filter = Configure::read($configString);
     }
     foreach ($filter as $version => $instructions) {
         $directory = Folder::slashTerm(rtrim($this->destination . $version . DS . $subdir, '.'));
         $Folder = new Folder($directory, $this->_createDirectories);
         if (!$Folder->pwd()) {
             $this->err($directory . ' could not be created or is not writable.');
             $this->err('Please check your permissions.');
             return false;
         }
         $Medium = Medium::make($File->pwd(), $instructions);
         if (!$Medium) {
             $this->err('Failed to make version ' . $version . ' of medium.');
             return false;
         }
         $Medium->store($Folder->pwd() . $File->name, $this->overwrite);
     }
     return true;
 }
 function testMake()
 {
     $instructions = array('convert' => 'image/png', 'zoomCrop' => array(10, 10));
     $Medium = Medium::make($this->TestData->getFile('image-jpg.jpg'), $instructions);
     $this->assertIsA($Medium, 'Medium');
 }