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 attribute factories #1

Merged
merged 1 commit into from
Dec 7, 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
14 changes: 12 additions & 2 deletions src/Builder/MediaInfoContainerBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Mhor\MediaInfo\Builder;

use Mhor\MediaInfo\Factory\AttributeFactory;
use Mhor\MediaInfo\Factory\TypeFactory;
use Mhor\MediaInfo\Type\AbstractType;
use Mhor\MediaInfo\Type\MediaInfoContainer;
use Mhor\MediaInfo\Type\TypeFactory;

class MediaInfoContainerBuilder
{
Expand Down Expand Up @@ -55,7 +56,16 @@ public function addAttributes(AbstractType $trackType, $attributes)
{
$this->mediaInfoContainer;
foreach ($attributes as $attribute => $value) {
$trackType->set($attribute, $value);
$attribute = $this->formatAttribute($attribute);
$trackType->set(
$attribute,
AttributeFactory::create(get_class($trackType), $attribute, $value)
);
}
}

private function formatAttribute($attribute)
{
return str_replace(' ', '_', strtolower($attribute));
}
}
29 changes: 29 additions & 0 deletions src/Factory/AttributeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Mhor\MediaInfo\Factory;

use Mhor\MediaInfo\Type\MediaInfoContainer;

class AttributeFactory
{
public static function create($attributeTypeClass, $attribute, $value)
{
switch ($attributeTypeClass) {
case MediaInfoContainer::VIDEO_CLASS:
return VideoAttributeFactory::create($attribute, $value);
break;
case MediaInfoContainer::AUDIO_CLASS:
return AudioAttributeFactory::create($attribute, $value);
break;
case MediaInfoContainer::IMAGE_CLASS:
return ImageAttributeFactory::create($attribute, $value);
break;
case MediaInfoContainer::GENERAL_CLASS:
return GeneralAttributeFactory::create($attribute, $value);
break;
default:
throw new \Exception('Type doesn\'t exist');
break;
}
}
}
14 changes: 14 additions & 0 deletions src/Factory/AudioAttributeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php


namespace Mhor\MediaInfo\Factory;


class AudioAttributeFactory
{
public static function create($attribute, $value)
{
return GenericAttributeFactory::create($attribute, $value);

}
}
11 changes: 11 additions & 0 deletions src/Factory/GeneralAttributeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Mhor\MediaInfo\Factory;

class GeneralAttributeFactory
{
public static function create($attribute, $value)
{
return GenericAttributeFactory::create($attribute, $value);
}
}
16 changes: 16 additions & 0 deletions src/Factory/GenericAttributeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php


namespace Mhor\MediaInfo\Factory;

class GenericAttributeFactory
{
public static function create($attribute, $value)
{
switch ($attribute) {
default:
return $value;
break;
}
}
}
15 changes: 15 additions & 0 deletions src/Factory/ImageAttributeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php


namespace Mhor\MediaInfo\Factory;


class ImageAttributeFactory
{
public static function create($attribute, $value)
{
return GenericAttributeFactory::create($attribute, $value);


}
}
6 changes: 5 additions & 1 deletion src/Type/TypeFactory.php → src/Factory/TypeFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

namespace Mhor\MediaInfo\Type;
namespace Mhor\MediaInfo\Factory;

use Mhor\MediaInfo\Type\Audio;
use Mhor\MediaInfo\Type\General;
use Mhor\MediaInfo\Type\Image;

class TypeFactory
{
Expand Down
13 changes: 13 additions & 0 deletions src/Factory/VideoAttributeFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php


namespace Mhor\MediaInfo\Factory;


class VideoAttributeFactory
{
public static function create($attribute, $value)
{
return GenericAttributeFactory::create($attribute, $value);
}
}