This class is useful to ensure that any response from any provider will follow the same conventions.
상속: implements IteratorAggregat\IteratorAggregate, implements JsonSerializabl\JsonSerializable
 /**
  *
  */
 public function testPresent()
 {
     $Media = new Media();
     $this->assertFalse($Media->has('foo'));
     $Media = $this->Completer->present($Media);
     $this->assertEquals('bar', $Media->get('foo'));
 }
예제 #2
0
파일: Youtube.php 프로젝트: birah/essence
 /**
  *	{@inheritDoc}
  */
 public function present(Media $Media)
 {
     $url = $Media->get($this->_property);
     if ($url && isset($this->_names[$this->_format])) {
         $thumbnail = str_replace('hqdefault', $this->_names[$this->_format], $url);
         $Media->set($this->_property, $thumbnail);
     }
     return $Media;
 }
예제 #3
0
 /**
  *	Builds an HTML code from the given media's properties to fill its
  *	'html' property.
  *
  *	@param Essence\Media $Media A reference to the Media.
  *	@param array $options Options.
  */
 public function complete(Media $Media, array $options = [])
 {
     if ($Media->has('html')) {
         return;
     }
     $title = htmlspecialchars($Media->get('title', $Media->url));
     $description = $Media->has('description') ? htmlspecialchars($Media->description) : $title;
     $options += $this->_defaults;
     $width = $Media->setDefault('width', $options['width']);
     $height = $Media->setDefault('height', $options['height']);
     switch ($Media->type) {
         // builds an <img> tag pointing to the photo
         case 'photo':
             $Media->set('html', sprintf('<img src="%s" alt="%s" width="%d" height="%d" />', $Media->url, $description, $width, $height));
             break;
             // builds an <iframe> tag pointing to the video
         // builds an <iframe> tag pointing to the video
         case 'video':
             $Media->set('html', sprintf('<iframe src="%s" width="%d" height="%d" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen />', $Media->url, $width, $height));
             break;
             // builds an <a> tag pointing to the original resource
         // builds an <a> tag pointing to the original resource
         default:
             $Media->set('html', sprintf('<a href="%s" alt="%s">%s</a>', $Media->url, $description, $title));
             break;
     }
 }
예제 #4
0
파일: Templater.php 프로젝트: birah/essence
 /**
  *	{@inheritDoc}
  */
 public function present(Media $Media)
 {
     $switch = $Media->get($this->_switch);
     if ($switch && !$Media->has($this->_property)) {
         foreach ($this->_templates as $pattern => $template) {
             if (preg_match($pattern, $switch)) {
                 $Media->set($this->_property, Template::compile($template, $Media->properties(), 'htmlspecialchars'));
                 break;
             }
         }
     }
     return $Media;
 }
 /**
  *	{@inheritDoc}
  */
 public function present(Media $Media)
 {
     return $Media->setProperties(Transform::reindex($Media->properties(), $this->_mapping));
 }
 /**
  *	{@inheritDoc}
  */
 public function present(Media $Media)
 {
     return $Media->setDefaults($this->_defaults);
 }