ffmpeg-mappable-media/src/FFMpeg/FFProbe/DataMapping/AbstractData.php

95 lines
1.7 KiB
PHP
Raw Normal View History

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 bool
2013-06-25 10:03:20 +02:00
*/
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
* @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
*/
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];
}
/**
* Sets the property value given its name.
*
2013-12-17 17:39:24 +01:00
* @param string $property
* @param mixed $value
*
* @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(): int
2013-06-25 10:03:20 +02:00
{
return count($this->properties);
}
}