Created
February 1, 2016 17:56
-
-
Save SebLours/3375af85dcafe0d6add4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace AppBundle\Pomm\Resolver; | |
use ArrayObject; | |
use PommProject\ModelManager\Model\FlexibleEntity; | |
class ModelClassResolver extends ArrayObject | |
{ | |
/** | |
* @param Array $modelClasses | |
*/ | |
public function __construct(Array $modelClasses) | |
{ | |
foreach ($modelClasses as $modelClass) { | |
$this[$modelClass::FLEXIBLE_ENTITY_CLASS] = $modelClass; | |
} | |
} | |
/** | |
* Resolve the model class for a flexible entity. | |
* | |
* @param FlexibleEntity $entity | |
* | |
* @return string | |
*/ | |
public function resolve(FlexibleEntity $entity) | |
{ | |
$flexibleEntityCLass = get_class($entity); | |
if (!isset($this[$flexibleEntityCLass])) { | |
throw new \Exception('Could not resolve model class'); | |
} | |
return $this[$flexibleEntityCLass]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment