Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create custom attribute for special values #2

Merged
merged 1 commit into from
Dec 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/Attribute/Cover.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Mhor\MediaInfo\Attribute;

class Cover
{
/**
* @var string
*/
private $binaryCover;

public function __construct($value)
{
$this->binaryCover = $value;
}

/**
* @return string
*/
public function getBinaryCover()
{
return $this->binaryCover;
}
}
27 changes: 27 additions & 0 deletions src/Attribute/Duration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Mhor\MediaInfo\Attribute;

class Duration
{
/**
* @var int
*/
private $milliseconds;

/**
* @param array $durations
*/
public function __construct(array $durations)
{
$this->milliseconds = $durations[0];
}

/**
* @return mixed
*/
public function getMilliseconds()
{
return $this->milliseconds;
}
}
38 changes: 38 additions & 0 deletions src/Attribute/Mode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Mhor\MediaInfo\Attribute;

class Mode
{
/**
* @var string
*/
private $shortName;

/**
* @var string
*/
private $fullName;

public function __construct(array $rateMode)
{
$this->shortName = $rateMode[0];
$this->fullName = $rateMode[1];
}

/**
* @return string
*/
public function getFullName()
{
return $this->fullName;
}

/**
* @return string
*/
public function getShortName()
{
return $this->shortName;
}
}
24 changes: 24 additions & 0 deletions src/Attribute/Rate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Mhor\MediaInfo\Attribute;

class Rate
{
/**
* @var int
*/
private $absoluteValue;

/**
* @var string
*/
private $textValue;

/**
* @param array $value
*/
public function __construct(array $value) {
$this->absoluteValue = $value[0];
$this->textValue = $value[1];
}
}
25 changes: 25 additions & 0 deletions src/Attribute/Size.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Mhor\MediaInfo\Attribute;

class Size
{

/**
* @var int
*/
protected $bit;

public function __construct(array $sizes)
{
$this->bit = $sizes[0];
}

/**
* @return int
*/
public function getBit()
{
return $this->bit;
}
}
4 changes: 4 additions & 0 deletions src/Builder/MediaInfoContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function addAttributes(AbstractType $trackType, $attributes)
{
$this->mediaInfoContainer;
foreach ($attributes as $attribute => $value) {
if ($attribute[0] === '@') {
continue;
}

$attribute = $this->formatAttribute($attribute);
$trackType->set(
$attribute,
Expand Down
1 change: 0 additions & 1 deletion src/Factory/AudioAttributeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ class AudioAttributeFactory
public static function create($attribute, $value)
{
return GenericAttributeFactory::create($attribute, $value);

}
}
27 changes: 27 additions & 0 deletions src/Factory/GenericAttributeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,38 @@

namespace Mhor\MediaInfo\Factory;

use Mhor\MediaInfo\Attribute\Cover;
use Mhor\MediaInfo\Attribute\Duration;
use Mhor\MediaInfo\Attribute\Mode;
use Mhor\MediaInfo\Attribute\Rate;
use Mhor\MediaInfo\Attribute\Size;

class GenericAttributeFactory
{
public static function create($attribute, $value)
{
switch ($attribute) {
case 'file_size':
case 'stream_size':
return new Size($value);
case 'duration':
return new Duration($value);
case 'channel_s_';
case 'bit_rate';
case 'sampling_rate';
return new Rate($value);
case 'cover_data';
return new Cover($value);
case 'overall_bit_rate_mode':
case 'overall_bit_rate':
case 'bit_rate_mode':
case 'compression_mode':
case 'codec':
case 'kind_of_stream':
return new Mode($value);
case 'file_last_modification_date';
case 'file_last_modification_date__local_';
return new \DateTime($value);
default:
return $value;
break;
Expand Down
17 changes: 11 additions & 6 deletions src/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,28 @@ abstract class AbstractType
/**
* @var array
*/
protected $attributes;
protected $attributes = array();

/**
* @param $attribute
* @param string|object $value
* @return string
*/
public function get($attribute)
public function set($attribute, $value)
{
$this->attributes[$attribute];
$this->attributes[$attribute] = $value;
}

/**
* @param $attribute
* @param $value
*
* @return string|object|null
*/
public function set($attribute, $value)
public function get($attribute)
{
return $this->attributes[$attribute] = $value;
if (isset($this->attributes[$attribute])) {
return $this->attributes[$attribute];
}
return null;
}
}