2013-06-25 10:03:20 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file is part of PHP-FFmpeg.
|
|
|
|
|
*
|
|
|
|
|
* (c) Alchemy <info@alchemy.fr>
|
|
|
|
|
*
|
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace FFMpeg\FFProbe\DataMapping;
|
|
|
|
|
|
|
|
|
|
abstract class AbstractData implements \Countable
|
|
|
|
|
{
|
|
|
|
|
private $properties;
|
|
|
|
|
|
|
|
|
|
public function __construct(array $properties)
|
|
|
|
|
{
|
|
|
|
|
$this->properties = $properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-25 10:40:20 +02:00
|
|
|
* Returns true if data has property.
|
2013-06-25 10:03:20 +02:00
|
|
|
*
|
|
|
|
|
* @param string $property
|
|
|
|
|
* @return Boolean
|
|
|
|
|
*/
|
|
|
|
|
public function has($property)
|
|
|
|
|
{
|
|
|
|
|
return isset($this->properties[$property]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-25 10:40:20 +02:00
|
|
|
* Returns the property value given its name.
|
2013-06-25 10:03:20 +02:00
|
|
|
*
|
|
|
|
|
* @param string $property
|
2015-01-30 19:59:13 +01:00
|
|
|
* @param mixed $default
|
2013-06-25 10:03:20 +02:00
|
|
|
*
|
2015-01-30 19:59:13 +01:00
|
|
|
* @return mixed
|
2013-06-25 10:03:20 +02:00
|
|
|
*/
|
2014-11-13 12:40:39 +05:30
|
|
|
public function get($property, $default = null)
|
2013-06-25 10:03:20 +02:00
|
|
|
{
|
|
|
|
|
if (!isset($this->properties[$property])) {
|
2015-01-30 19:59:13 +01:00
|
|
|
return $default;
|
2013-06-25 10:03:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->properties[$property];
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-29 13:25:49 +01:00
|
|
|
/**
|
|
|
|
|
* Sets the property value given its name.
|
|
|
|
|
*
|
2013-12-17 17:39:24 +01:00
|
|
|
* @param string $property
|
|
|
|
|
* @param mixed $value
|
2013-11-29 13:25:49 +01:00
|
|
|
*
|
|
|
|
|
* @return AbstractData
|
|
|
|
|
*/
|
|
|
|
|
public function set($property, $value)
|
|
|
|
|
{
|
|
|
|
|
$this->properties[$property] = $value;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-25 10:03:20 +02:00
|
|
|
/**
|
2013-06-25 10:40:20 +02:00
|
|
|
* Returns all property names.
|
2013-06-25 10:03:20 +02:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function keys()
|
|
|
|
|
{
|
|
|
|
|
return array_keys($this->properties);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-25 10:40:20 +02:00
|
|
|
* Returns all properties and their values.
|
2013-06-25 10:03:20 +02:00
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function all()
|
|
|
|
|
{
|
|
|
|
|
return $this->properties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
|
|
|
|
public function count()
|
|
|
|
|
{
|
|
|
|
|
return count($this->properties);
|
|
|
|
|
}
|
|
|
|
|
}
|