<?php
/**
 * MetaTagSet Model Manager
 *
 * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
 */
namespace VisualM\TagManagerBundle\Model;

use VisualM\ModelManagementBundle\Doctrine\ORM\ManagerAbstract;
use VisualM\TagManagerBundle\Model\TagSet\MetaTagSetFactoryInterface;

/**
 * MetaTagSet Model Manager
 *
 * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl>
 */
abstract class MetaTagSetManager extends ManagerAbstract
{
    private $factories = array();

    /**
     * Add Factory
     *
     * @param MetaTagSetFactoryInterface $factory
     * @param string $reference
     */
    public function addFactory(MetaTagSetFactoryInterface $factory, $reference)
    {
        $this->factories[$reference] = $factory;
    }

	/**
     * Get Factory for given reference
     *
     * @param string $reference Reference
     *
     * @return MetaTagSetFactoryInterface|null Factory
     */
    public function getFactory($reference)
    {
        if (isset($this->factories[$reference])) {
            return $this->factories[$reference];
        }
        else if (!empty($this->factories)) {
            return current($this->factories);
        }
        else {
            return null;
        }
    }

    /**
     * Return list of available factories
     *
     * @return array Factories
     */
    public function getFactories()
    {
        return $this->factories;
    }
}
