public function testGetUrl() { $media = new SimpleMedia(); $variant = new Variant('test'); $variant->setFilename('file.jpg'); $this->cdn->setConfiguration(array('base_url' => 'http://cdn.example.com/')); $this->assertEquals('http://cdn.example.com/file.jpg', $this->cdn->getUrl($media, $variant)); }
public function testGetUrl() { $_SERVER['HTTP_HOST'] = 'localhost'; $media = new SimpleMedia(); $variant = new Variant('test'); $variant->setFilename('file.jpg'); $this->cdn->setConfiguration(array('path' => 'path/')); $this->assertEquals('path/file.jpg', $this->cdn->getUrl($media, $variant)); $options = array('absolute' => TRUE); $this->assertEquals('http://localhost/path/file.jpg', $this->cdn->getUrl($media, $variant, $options)); $options['domain'] = 'example.com'; $this->assertEquals('http://example.com/path/file.jpg', $this->cdn->getUrl($media, $variant, $options)); $options['protocol'] = 'https'; $this->assertEquals('https://example.com/path/file.jpg', $this->cdn->getUrl($media, $variant, $options)); }
/** * {@inheritDoc} */ public function getVariantInstance($variantName) { if (!array_key_exists($variantName, $this->variants)) { throw new InvalidArgumentException(sprintf('media "%s" has no variant named "%s" ', $this, $variantName)); } return Variant::fromArray($this->variants[$variantName]); }
/** * {@inheritDoc} */ public static function fromArray($array) { $variant = new Variant(); if (isset($array['name'])) { $variant->setName($array['name']); } if (isset($array['filename'])) { $variant->setFilename($array['filename']); } if (isset($array['options'])) { $variant->setOptions($array['options']); } if (isset($array['mode'])) { $variant->setMode($array['mode']); } if (isset($array['status'])) { $variant->setStatus($array['status']); } if (isset($array['error'])) { $variant->setError($array['error']); } if (isset($array['meta']) && is_array($array['meta']) && !empty($array['meta'])) { $variant->setMeta($array['meta']); } return $variant; }
public function testFromArray() { $data = array('name' => 'foo', 'filename' => 'bar', 'options' => array('foo' => 'bar'), 'mode' => Variant::MODE_INSTANT, 'status' => Variant::STATUS_ERROR, 'error' => 'test', 'meta' => array('a' => 'b', 'c' => 'd')); $variant = Variant::fromArray($data); foreach ($data as $name => $value) { $getter = 'get' . ucwords($name); $this->assertEquals($value, $variant->{$getter}()); } }
/** * {@inheritDoc} */ public function buildVariantTree() { if ($this->lastTree) { return $this->lastTree; } $tree = new VariantTree(); foreach ($this->variants as $name => $v) { //sets default values if any $mode = VariantInterface::MODE_INSTANT; if (isset($v['mode'])) { $mode = $v['mode']; } $process = array(); if (isset($v['process'])) { $process = $v['process']; } $parent = NULL; if (isset($v['parent'])) { $parent = $v['parent']; } //creates the variant instance $variant = new Variant(); $variant->setName($name); $variant->setMode($mode); $variant->setOptions($process); $tree->add($variant, $parent); } $this->lastTree = $tree; return $tree; }