public static function config(array $config = array()) { if (!$config) { return self::$_config; } self::$_config = $config; }
/** * Retrieve (cached) metadata of a file * * @param Model $Model * @param string $file An absolute path to a file * @param integer $level level of amount of info to add, `0` disable, `1` for basic, `2` for detailed info * @return mixed Array with results or false if file is not readable */ function metadata(&$Model, $file, $level = 1) { if ($level < 1) { return array(); } extract($this->settings[$Model->alias]); $File = new File($file); if (!$File->readable()) { return false; } $checksum = $File->md5(true); if (isset($this->__cached[$Model->alias][$checksum])) { $data = $this->__cached[$Model->alias][$checksum]; } if ($level > 0 && !isset($data[1])) { $data[1] = array('size' => $File->size(), 'mime_type' => Mime_Type::guessType($File->pwd()), 'checksum' => $checksum); } if ($level > 1 && !isset($data[2])) { $data[2] = array(); try { $Info = Media_Info::factory(array('source' => $File->pwd())); foreach ($Info->all() as $key => $value) { $data[2][Inflector::underscore($key)] = $value; } } catch (Exception $E) { } } for ($i = $level, $result = array(); $i > 0; $i--) { $result = array_merge($result, $data[$i]); } $this->__cached[$Model->alias][$checksum] = $data; return $result; }
public function testHasManyWithMissingMediaAdapters() { $_backupConfig = Configure::read('Media'); $_backupProcess = Media_Process::config(); $_backupInfo = Media_Info::config(); $s = array('convert' => 'image/png', 'zoomCrop' => array(100, 100)); $m = array('convert' => 'image/png', 'fitCrop' => array(300, 300)); $l = array('convert' => 'image/png', 'fit' => array(600, 440)); Configure::write('Media.filter', array('audio' => compact('s', 'm'), 'document' => compact('s', 'm'), 'generic' => array(), 'image' => compact('s', 'm', 'l'), 'video' => compact('s', 'm'))); Media_Process::config(array('image' => null)); Media_Info::config(array('image' => null)); $Model = $this->_model('hasMany'); $file = $this->Data->getFile(array('image-jpg.jpg' => 'ta.jpg')); $data = array('Movie' => array('title' => 'Weekend', 'director' => 'Jean-Luc Godard'), 'Attachment' => array(array('file' => $file, 'model' => 'Movie'))); $Model->create(); $result = false; $expected = null; try { $result = $Model->saveAll($data, array('validate' => 'first')); } catch (Exception $exception) { $expected = $exception; } if ($expected === null) { $this->fail('Expected Model::saveAll to raise an error.'); } $this->assertFalse($result); $this->assertTrue(file_exists($this->Data->settings['transfer'] . 'img' . DS . 'ta.jpg')); $result = $Model->find('first', array('conditions' => array('title' => 'Weekend'))); $expected = array(0 => array('id' => '1', 'model' => 'Movie', 'foreign_key' => '4', 'dirname' => 'img', 'basename' => 'ta.jpg', 'checksum' => '073addc9c90e4d20a9a19d8a31e01b39', 'group' => null, 'alternative' => null, 'path' => 'img/ta.jpg')); $this->assertEqual($result['Attachment'], $expected); Media_Process::config($_backupProcess); Media_Info::config($_backupInfo); Configure::write('Media', $_backupConfig); }
public function testMediaFactorySourceFailStream() { $this->setExpectedException('InvalidArgumentException'); Media_Info::factory(array('source' => fopen("{$this->_files}/image_jpg.jpg", 'rb'))); }
if ($cached = Cache::read('mime_type_glob')) { Mime_Type::config('Glob', array('adapter' => 'Memory')); foreach ($cached as $item) { Mime_Type::$glob->register($item); } } else { Mime_Type::config('Glob', array('adapter' => 'Freedesktop', 'file' => $mm . DS . 'data' . DS . 'glob.db')); Cache::write('mime_type_glob', Mime_Type::$glob->to('array')); } /** * Configure the adpters to be used by media process class. Adjust this * mapping of media names to adapters according to your environment. For example: * most PHP installations have GD enabled thus should choose the `Gd` adapter for * image transformations. However the `Imagick` adapter may be more desirable * in other cases and also supports transformations for documents. * * @see GeneratorBehavior */ require_once 'Media/Process.php'; Media_Process::config(array('document' => $hasImagick ? 'Imagick' : null, 'image' => $hasImagick ? 'Imagick' : 'Gd')); /** * Configure the adpters to be used by media info class. Adjust this * mapping of media names to adapters according to your environment. In contrast * to `Media_Proces` which operates only with one adapter per media type * `Media_Info` can use multiple adapter per media type. * * @see MetaBehavior */ require_once 'Media/Info.php'; Media_Info::config(array('image' => $hasImagick ? array('ImageBasic', 'Imagick') : array('ImageBasic')));
function testHasManyWithMissingMediaAdapters() { $_backupConfig = Configure::read('Media'); $_backupProcess = Media_Process::config(); $_backupInfo = Media_Info::config(); $s = array('convert' => 'image/png', 'zoomCrop' => array(100, 100)); $m = array('convert' => 'image/png', 'fitCrop' => array(300, 300)); $l = array('convert' => 'image/png', 'fit' => array(600, 440)); Configure::write('Media.filter', array('audio' => compact('s', 'm'), 'document' => compact('s', 'm'), 'generic' => array(), 'image' => compact('s', 'm', 'l'), 'video' => compact('s', 'm'))); Media_Process::config(array('image' => null)); Media_Info::config(array('image' => null)); $Model = $this->_model('hasMany'); $file = $this->Data->getFile(array('image-jpg.jpg' => 'ta.jpg')); $data = array('Movie' => array('title' => 'Weekend', 'director' => 'Jean-Luc Godard'), 'Attachment' => array(array('file' => $file, 'model' => 'Movie'))); $this->expectError(); $this->expectError(); $this->expectError(); $Model->create(); $result = $Model->saveAll($data, array('validate' => 'first')); $this->assertTrue($result); $this->assertTrue(file_exists($this->Folder->pwd() . 'transfer' . DS . 'img' . DS . 'ta.jpg')); $result = $Model->find('first', array('conditions' => array('title' => 'Weekend'))); $expected = array(0 => array('id' => 1, 'model' => 'Movie', 'foreign_key' => 4, 'dirname' => 'img', 'basename' => 'ta.jpg', 'checksum' => '1920c29e7fbe4d1ad2f9173ef4591133', 'group' => null, 'alternative' => null)); $this->assertEqual($result['Attachment'], $expected); Media_Process::config($_backupProcess); Media_Info::config($_backupInfo); Configure::write('Media', $_backupConfig); }
* in other cases and also supports transformations for documents. * * @see GeneratorBehavior */ require_once 'Media/Process.php'; Media_Process::config(array('document' => $hasImagick ? 'Imagick' : null, 'image' => $hasImagick ? 'Imagick' : 'Gd')); /** * Configure the adpters to be used by media info class. Adjust this * mapping of media names to adapters according to your environment. In contrast * to `Media_Proces` which operates only with one adapter per media type * `Media_Info` can use multiple adapter per media type. * * @see MetaBehavior */ require_once 'Media/Info.php'; Media_Info::config(array('audio' => array('NewWave'), 'document' => $hasImagick ? array('Imagick') : array(), 'image' => $hasImagick ? array('ImageBasic', 'Imagick') : array('ImageBasic'))); /** * Filters and versions * * For each media type a set of filters keyed by version name is configured. * A filter is a set of instructions which are processed by the Media_Process class. * * For more information on available methods see the classes * located in `libs/mm/src/Media/Process`. * * @see GeneratorBehavior */ // $sRGB = $mm . DS . 'data' . DS . 'sRGB_IEC61966-2-1_black_scaled.icc'; $s = array('convert' => 'image/jpeg', 'fitCrop' => array(100, 100)); $m = array('convert' => 'image/jpeg', 'fit' => array(300, 300)); $l = array('convert' => 'image/jpeg', 'fit' => array(600, 440));
* in other cases and also supports transformations for documents. * * @see GeneratorBehavior */ require_once 'Media/Process.php'; Media_Process::config(array('document' => $hasImagick ? 'Imagick' : null, 'image' => $hasImagick ? 'Imagick' : 'Gd')); /** * Configure the adpters to be used by media info class. Adjust this * mapping of media names to adapters according to your environment. In contrast * to `Media_Proces` which operates only with one adapter per media type * `Media_Info` can use multiple adapter per media type. * * @see MetaBehavior */ require_once 'Media/Info.php'; Media_Info::config(array('image' => array('ImageBasic'))); /** * Filters and versions * * For each media type a set of filters keyed by version name is configured. * A filter is a set of instructions which are processed by the Media_Process class. * * For more information on available methods see the classes * located in `libs/mm/src/Media/Process`. * * @see GeneratorBehavior */ // $sRGB = $mm . DS . 'data' . DS . 'sRGB_IEC61966-2-1_black_scaled.icc'; $s = array('convert' => 'image/png', 'zoomCrop' => array(100, 100)); $m = array('convert' => 'image/png', 'fitCrop' => array(300, 300)); $l = array('convert' => 'image/png', 'fit' => array(600, 440));