/**
  * createBuiltinClient
  *
  * Return an instance of a builtin inspector from its short name. Throws an
  * exception if the built in inspector does not exist.
  *
  * @param   string $identifier
  * @throws  FoundationException
  * @return  ClientInterface
  */
 private function createBuiltinClient($identifier)
 {
     $class_name = sprintf("\\PommProject\\Foundation\\Inspector\\%sInspector", Inflector::studlyCaps($identifier));
     if (!class_exists($class_name)) {
         throw new FoundationException(sprintf("Unknown built in inspector '%s'. Default inspector clients are {%s}.", $identifier, 'database, schema, relation, type, role'));
     }
     return new $class_name();
 }
Example #2
0
 /**
  * generate
  *
  * Generate structure file.
  *
  * @see BaseGenerator
  */
 public function generate(ParameterHolder $input, array $output = [])
 {
     $schema_oid = $this->getSession()->getInspector()->getSchemaOid($this->schema);
     if ($schema_oid === null) {
         throw new GeneratorException(sprintf("Schema '%s' does not exist.", $this->schema));
     }
     $relations_info = $this->getSession()->getInspector()->getSchemaRelations($schema_oid, new Where('cl.relname = $*', [$this->relation]));
     if ($relations_info->isEmpty()) {
         throw new GeneratorException(sprintf("Relation '%s.%s' does not exist.", $this->schema, $this->relation));
     }
     $this->checkOverwrite($input)->outputFileCreation($output)->saveFile($this->filename, $this->mergeTemplate(['entity' => Inflector::studlyCaps($this->relation), 'namespace' => trim($this->namespace, '\\'), 'trait' => $relations_info->current()['type'] === 'table' ? 'WriteQueries' : 'ReadQueries', 'relation_type' => $relations_info->current()['type'], 'relation' => $this->relation]));
     return $output;
 }
    /**
     * generate
     *
     * Generate structure file.
     *
     * @see BaseGenerator
     */
    public function generate(ParameterHolder $input, array $output = [])
    {
        $table_oid = $this->checkRelationInformation();
        $field_information = $this->getFieldInformation($table_oid);
        $primary_key = $this->getPrimaryKey($table_oid);
        $table_comment = $this->getTableComment($table_oid);
        if ($table_comment === null) {
            $table_comment = <<<TEXT

Class and fields comments are inspected from table and fields comments. Just add comments in your database and they will appear here.
@see http://www.postgresql.org/docs/9.0/static/sql-comment.html
TEXT;
        }
        $this->outputFileCreation($output)->saveFile($this->filename, $this->mergeTemplate(['namespace' => $this->namespace, 'class_name' => $input->getParameter('class_name', Inflector::studlyCaps($this->relation)), 'relation' => sprintf("%s.%s", $this->schema, $this->relation), 'primary_key' => join(', ', array_map(function ($val) {
            return sprintf("'%s'", $val);
        }, $primary_key)), 'add_fields' => $this->formatAddFields($field_information), 'table_comment' => $this->createPhpDocBlockFromText($table_comment), 'fields_comment' => $this->formatFieldsComment($field_information)]));
        return $output;
    }
Example #4
0
 public function testUnderscore()
 {
     $this->variable(PommInflector::underscore(null))->isNull()->string(PommInflector::underscore(''))->length->isEqualTo(0)->string(PommInflector::underscore('one'))->isEqualTo('one')->string(PommInflector::underscore('oneTwo'))->isEqualTo('one_two')->string(PommInflector::underscore('twoThreeFour'))->isEqualTo('two_three_four')->string(PommInflector::underscore('one_Two'))->isEqualTo('one__two')->string(PommInflector::underscore('one2Three'))->isEqualTo('one2_three')->string(PommInflector::underscore('one_2Three'))->isEqualTo('one_2_three')->string(PommInflector::underscore('One'))->isEqualTo('one');
 }
Example #5
0
 /**
  * generate
  *
  * Generate Entity file.
  *
  * @see BaseGenerator
  */
 public function generate(ParameterHolder $input, array $output = [])
 {
     $this->checkOverwrite($input)->outputFileCreation($output)->saveFile($this->filename, $this->mergeTemplate(['namespace' => $this->namespace, 'entity' => Inflector::studlyCaps($this->relation), 'relation' => $this->relation, 'schema' => $this->schema, 'flexible_container' => $this->flexible_container, 'flexible_container_class' => array_reverse(explode('\\', $this->flexible_container))[0]]));
     return $output;
 }
Example #6
0
 protected function createWhereByCriteria($criteria = array())
 {
     $where = new Where();
     foreach ($criteria as $colname => $value) {
         $colname = Inflector::underscore($colname);
         $element = sprintf('%s = $*', $colname);
         $subWhere = new Where($element, array($value));
         $where->andWhere($subWhere);
     }
     return $where;
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 public function offsetExists($offset)
 {
     $method_name = "has" . Inflector::studlyCaps($offset);
     return $this->{$method_name}();
 }
Example #8
0
 /**
  * __call
  *
  * Create handy methods to access clients through a pooler.
  *
  * @access  public
  * @param   string                   $method
  * @param   array                    $arguments
  * @throws  \BadFunctionCallException if unknown method
  * @throws  FoundationException      if no poolers found
  * @return  ClientInterface
  */
 public function __call($method, $arguments)
 {
     if (!preg_match('/get([A-Z][A-Za-z]+)/', $method, $matches)) {
         throw new \BadFunctionCallException(sprintf("Unknown method 'Session::%s()'.", $method));
     }
     return $this->getClientUsingPooler(Inflector::underscore($matches[1]), count($arguments) > 0 ? $arguments[0] : null);
 }
 /**
  * extractMethodName
  *
  * Get container field name from method name.
  * It returns an array with the operation (get, set, etc.) as first member
  * and the name of the attribute as second member.
  *
  * @access protected
  * @param  string   $argument
  * @return array
  * @throws ModelException
  */
 protected function extractMethodName($argument)
 {
     $split = preg_split('/(?=[A-Z])/', $argument, 2);
     if (count($split) !== 2) {
         throw new ModelException(sprintf('No such argument "%s:%s()"', get_class($this), $argument));
     }
     return [$split[0], Inflector::underscore($split[1])];
 }
Example #10
0
 /**
  * getNamespace
  *
  * Create namespace from parameters.
  *
  * @access protected
  * @param  string $config_name
  * @param  string $extra_ns
  * @return string
  */
 protected function getNamespace($config_name, $extra_ns = '')
 {
     $elements = [$this->prefix_ns, Inflector::studlyCaps($config_name), Inflector::studlyCaps(sprintf("%s_schema", $this->schema)), $extra_ns];
     return join('\\', array_filter($elements, function ($val) {
         return $val != null;
     }));
 }