Guest User

Untitled

a guest
Jun 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. <?php
  2. class Norm_MapperRegistry
  3. {
  4. private static $_mappers = array();
  5.  
  6. /**
  7. *
  8. * @param $model
  9. * @return Norm_MapperAbstract
  10. */
  11. public static function get($model)
  12. {
  13. if ($model instanceof Norm_DomainObject) {
  14. $class = get_class($model);
  15. } else {
  16. $class = (string) $model;
  17. }
  18.  
  19. if (!self::_hasMapperForClass($class)) {
  20. throw new Norm_Exception('No mapper for type "' . $class . '" found.');
  21. }
  22.  
  23. return self::$_mappers[$class];
  24. }
  25.  
  26. public static function set(Norm_IMapper $mapper)
  27. {
  28. $class = $mapper->getDomainClass();
  29.  
  30. if (self::_hasMapperForClass($class)) {
  31. throw new Norm_Exception('Mapper for class ' . $class . 'has already been registered.');
  32. }
  33.  
  34. self::$_mappers[$class] = $mapper;
  35. }
  36.  
  37. private static function _hasMapperForClass($class)
  38. {
  39. return isset(self::$_mappers[$class]);
  40. }
  41. }
Add Comment
Please, Sign In to add comment