Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Norm_MapperRegistry
- {
- private static $_mappers = array();
- /**
- *
- * @param $model
- * @return Norm_MapperAbstract
- */
- public static function get($model)
- {
- if ($model instanceof Norm_DomainObject) {
- $class = get_class($model);
- } else {
- $class = (string) $model;
- }
- if (!self::_hasMapperForClass($class)) {
- throw new Norm_Exception('No mapper for type "' . $class . '" found.');
- }
- return self::$_mappers[$class];
- }
- public static function set(Norm_IMapper $mapper)
- {
- $class = $mapper->getDomainClass();
- if (self::_hasMapperForClass($class)) {
- throw new Norm_Exception('Mapper for class ' . $class . 'has already been registered.');
- }
- self::$_mappers[$class] = $mapper;
- }
- private static function _hasMapperForClass($class)
- {
- return isset(self::$_mappers[$class]);
- }
- }
Add Comment
Please, Sign In to add comment