Overview

Namespaces

  • Inlm
    • Mappers

Classes

  • Inlm\Mappers\CamelCaseMapper
  • Inlm\Mappers\DefaultMapper
  • Inlm\Mappers\DynamicMapper
  • Inlm\Mappers\PrefixMapper
  • Inlm\Mappers\UnderScoreMapper

Exceptions

  • Inlm\Mappers\DuplicateException
  • Inlm\Mappers\Exception
  • Inlm\Mappers\InvalidArgumentException
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 
<?php

    namespace Inlm\Mappers;

    use LeanMapper;


    class UnderScoreMapper extends DefaultMapper
    {
        /**
         * @inheritdoc
         */
        public function getTable($entityClass)
        {
            return self::toUnderScore($this->trimNamespace($entityClass));
        }


        /**
         * @inheritdoc
         */
        public function getEntityClass($table, LeanMapper\Row $row = NULL)
        {
            return ($this->defaultEntityNamespace !== NULL ? $this->defaultEntityNamespace . '\\' : '')
                . ucfirst(self::toCamelCase($table));
        }


        /**
         * @inheritdoc
         */
        public function getColumn($entityClass, $field)
        {
            return self::toUnderScore($field);
        }


        /**
         * @inheritdoc
         */
        public function getEntityField($table, $column)
        {
            return self::toCamelCase($column);
        }


        /**
         * @inheritdoc
         */
        public function getTableByRepositoryClass($repositoryClass)
        {
            $matches = array();

            if (preg_match('#([a-z0-9]+)repository$#i', $repositoryClass, $matches)) {
                return self::toUnderScore($matches[1]);
            }

            throw new InvalidArgumentException('Cannot determine table name.');
        }


        /**
         * @param  string
         * @return string
         */
        protected static function toUnderScore($s)
        {
            return lcfirst(preg_replace_callback('#(?<=.)([A-Z])#', function ($m) {
                return '_' . strtolower($m[1]);
            }, $s));
        }


        /**
         * @param  string
         * @return string
         */
        protected static function toCamelCase($s)
        {
            return preg_replace_callback('#_(.)#', function ($m) {
                return strtoupper($m[1]);
            }, $s);
        }
    }
inlm/mappers master API documentation API documentation generated by ApiGen