Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 3
0
    /**
     * 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;
    }
Ejemplo n.º 4
0
 public function testStudlyCaps()
 {
     $this->variable(PommInflector::studlyCaps(null))->isNull()->string(PommInflector::studlyCaps(''))->length->isEqualTo(0)->string(PommInflector::studlyCaps('one'))->isEqualTo('One')->string(PommInflector::studlyCaps('oNe'))->isEqualTo('One')->string(PommInflector::studlyCaps('one_two'))->isEqualTo('OneTwo')->string(PommInflector::studlyCaps('one_tWo'))->isEqualTo('OneTwo')->string(PommInflector::studlyCaps('two_three_four'))->isEqualTo('TwoThreeFour')->string(PommInflector::studlyCaps('one__two'))->isEqualTo('One_Two')->string(PommInflector::studlyCaps('one_2_three'))->isEqualTo('One_2Three')->string(PommInflector::studlyCaps('one2_three'))->isEqualTo('One2Three')->string(PommInflector::studlyCaps('_one'))->isEqualTo('One');
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 6
0
 /**
  * {@inheritdoc}
  */
 public function offsetExists($offset)
 {
     $method_name = "has" . Inflector::studlyCaps($offset);
     return $this->{$method_name}();
 }
Ejemplo n.º 7
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;
     }));
 }