Exemple #1
0
 /**
  * Takes a copy of the table name, adds the supplied prefix, then camel-cases the result
  * 
  * @param string $tablePrefix A prefix in lower-case underscored format
  */
 public function setClassPrefix($tablePrefix)
 {
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     foreach ($this->xpath('/database/table') as $table) {
         $table['phpName'] = $filter->filter($tablePrefix . '_' . $table['name']);
     }
 }
 public function testFilterSeparatesCamelCasedWordsWithDashes()
 {
     $string = 'camel_cased_words';
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('CamelCasedWords', $filtered);
 }
Exemple #3
0
 protected static function getClassName(PropelPDO $con)
 {
     // Get the database type
     $type = $con->getAttribute(PDO::ATTR_DRIVER_NAME);
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     $type = $filter->filter($type);
     $class = 'Meshing_Database_Locker_' . $type;
     return $class;
 }
 public function setFromArray(array $data)
 {
     $data = array_intersect_key($data, $this->_data);
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     foreach ($data as $key => $value) {
         $method = 'set' . $filter->filter($key);
         if (!method_exists($this, $method)) {
             throw new Zend_Db_Exception("Can't set property '{$key}' couse method '{$method}' does not exists");
         }
         $this->{$method}($value);
     }
 }
 private function _getPermissionActions()
 {
     $actions = array(array('action' => 'anexar'), array('action' => 'anexar-processo'), array('action' => 'apensar'), array('action' => 'apensar-processo'), array('action' => 'inserir-peca'), array('action' => 'remover-peca'), array('action' => 'desapensar'), array('action' => 'desapensar-processo'), array('action' => 'desanexar'), array('action' => 'desanexar-processo'), array('action' => 'desmembrar', 'controller' => 'desmembrar-desentranhar'), array('action' => 'desentranhar', 'controller' => 'desmembrar-desentranhar'));
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     foreach ($actions as $data) {
         $module = isset($data['module']) ? $data['module'] : null;
         $controller = isset($data['controller']) ? $data['controller'] : null;
         $keyAction = lcfirst($filter->filter(str_replace('-', '_', $data['action'])));
         $permissions[$keyAction] = $this->_hasPermissionAcl($data['action'], $controller, $module);
     }
     return $permissions;
 }
 public function generateGettersAndSetters()
 {
     $filter = new \Zend_Filter_Word_UnderscoreToCamelCase();
     foreach ($this->properties as $property) {
         $propertyName = $property['name'];
         $propertyNameFiltered = lcfirst($filter->filter($property['name']));
         $params = array('name' => $propertyNameFiltered, 'default' => '');
         $content = self::TAB . self::TAB . "\$this->{$propertyName} = \${$propertyNameFiltered};";
         $this->addMethod("set" . ucfirst($propertyNameFiltered), 'public', array($params), $content);
         $content = self::TAB . self::TAB . "return \$this->{$propertyName};";
         $this->addMethod("get" . ucfirst($propertyNameFiltered), 'public', array(), $content);
     }
 }
Exemple #7
0
 /**
  * Batch setter method
  * @param array $data
  */
 public function setData(array $data)
 {
     $methods = get_class_methods($this);
     foreach ($data as $key => $value) {
         // If data key name has underscores in it
         // transform the key name to camel case
         if (stristr($key, "_")) {
             $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
             $key = $filter->filter($key);
         }
         $method = 'set' . ucfirst($key);
         if (in_array($method, $methods)) {
             $this->{$method}($value);
         }
     }
     return $this;
 }
 /**
  * ZF-4097
  */
 public function testSomeFilterValues()
 {
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     $string = 'zend_framework';
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('ZendFramework', $filtered);
     $string = 'zend_Framework';
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('ZendFramework', $filtered);
     $string = 'zendFramework';
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('ZendFramework', $filtered);
     $string = 'zendframework';
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('Zendframework', $filtered);
     $string = '_zendframework';
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('Zendframework', $filtered);
     $string = '_zend_framework';
     $filtered = $filter->filter($string);
     $this->assertNotEquals($string, $filtered);
     $this->assertEquals('ZendFramework', $filtered);
 }
 /**
  * Obtém campos do modelo documento
  * @param \Core_Dto_Search $dtoSearch
  * @return array
  */
 public function getCampoModeloDocumento(\Core_Dto_Abstract $dtoSearch)
 {
     $queryBuilder = $this->_em->createQueryBuilder();
     $queryBuilder->select('pmd.sqPadraoModeloDocumento,pmd.noPadraoModeloDocumento', 'c.noCampo', 'c.noColunaTabela', 'gp.sqGrupoCampo', 'pmdc.inObrigatorio')->from('app:ModeloDocumentoCampo', 'mdc')->innerJoin('mdc.sqPadraoModeloDocumentoCam', 'pmdc')->innerJoin('pmdc.sqPadraoModeloDocumento', 'pmd')->innerJoin('pmdc.sqCampo', 'c')->innerJoin('c.sqGrupoCampo', 'gp')->innerJoin('mdc.sqModeloDocumento', 'md');
     if ($dtoSearch->getSqModeloDocumento()) {
         $queryBuilder->andWhere('md.sqModeloDocumento = :sqModeloDocumento');
         $queryBuilder->setParameter('sqModeloDocumento', $dtoSearch->getSqModeloDocumento());
     } else {
         $queryBuilder->andWhere('md.inAtivo = :inAtivo')->setParameter('inAtivo', "TRUE");
     }
     $out = $queryBuilder->getQuery()->execute();
     $filter = new \Zend_Filter_Word_UnderscoreToCamelCase();
     $arrayField = array();
     foreach ($out as $key => $value) {
         $arrayField[$key]['sqPadraoModeloDocumento'] = $value['sqPadraoModeloDocumento'];
         $arrayField[$key]['noPadraoModeloDocumento'] = $value['noPadraoModeloDocumento'];
         $arrayField[$key]['noCampo'] = $value['noCampo'];
         $arrayField[$key]['noColunaTabela'] = lcfirst($filter->filter($value['noColunaTabela']));
         $arrayField[$key]['sqGrupoCampo'] = $value['sqGrupoCampo'];
         $arrayField[$key]['inObrigatorio'] = $value['inObrigatorio'];
     }
     return $arrayField;
 }
Exemple #10
0
 *  Usage:
 *  ./doctrine original-doctrine-command -module path-to-your-module
 */
// Module name argument
$moduleNameIndex = array_search('-module', $argv);
if ($moduleNameIndex !== false) {
    // Module argument is set
    // Check & Access Module Name
    $moduleName = isset($argv[$moduleNameIndex + 1]) ? $argv[$moduleNameIndex + 1] : null;
    if (!empty($moduleName)) {
        // Module name is not empty and already exist
        if (!is_dir(MODULES_PATH . "/" . $moduleName)) {
            die("** Module path not found! **" . PHP_EOL);
        }
        // Fiter SeperatorToCamelCase Setup
        $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
        $camelCaseModuleName = $filter->setSeparator('-')->filter($moduleName);
        // Replacement Mapping, String Replace and Apply Filter
        $mapping = array('find' => array(APPLICATION_PATH, DEVELOPER_PATH, "Model_"), 'replace' => array(MODULES_PATH . "/" . $moduleName, MODULES_PATH . "/" . $moduleName . "/" . $paths['dev'], $camelCaseModuleName . "_Model_"));
        // Apply New Cli Settings
        $doctrineCliCfgs = str_replace($mapping['find'], $mapping['replace'], array_merge($doctrineCliCfgs, array('generate_models_options' => str_replace($mapping['find'], $mapping['replace'], $doctrineCliCfgs['generate_models_options']))));
        echo "** '" . $moduleName . "' module is being processed... **" . PHP_EOL;
    } else {
        //KBBTODO: Add console code color
        die("** Please type your module path! **" . PHP_EOL . "~\$>./doctrine original-doctrine-command -module path-to-your-module" . PHP_EOL);
    }
}
// -----------------------------------------------------------------------------
// Cli Initialize
$cli = new Doctrine_Cli($doctrineCliCfgs);
$cli->run($argv);
Exemple #11
0
 /**
  * Returns all entities properties as an array
  * @return array
  */
 public function toArray()
 {
     $data = array();
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     foreach ($this->_data as $key => $value) {
         $method = 'get' . $filter->filter($key);
         $value = $this->{$method}();
         $data[$key] = $value;
     }
     return $data;
 }
Exemple #12
0
 /**
  * Convert a word in to the format for a Zend_Db class name. Converts 'table_name' to 'TableName'
  *
  * @param string  $word  Word to classify
  * @return string $word  Classified word
  */
 public static function classify($word)
 {
     $inflector = new Zend_Filter_Word_UnderscoreToCamelCase();
     return $inflector->filter($word);
 }
 public function filter($value)
 {
     return lcfirst(parent::filter($value));
 }
Exemple #14
0
    /**
     * Metodo para tranformar as variaveis vindas do bd em variaveis PHP
     * id_usuario => idUsuario
     * 
     * @param string $value
     */
    protected function _underToCamel($value)
    {
        $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
        $filter->setSeparator('_');

        return lcfirst($filter->filter($value));
    }
 public function __construct($modelsFolder, $di, $namespaceName = 'Model')
 {
     $filter = new \Zend_Filter_Word_UnderscoreToCamelCase();
     $phalconGenerator = new \Models\Phalcon\Generator($di);
     $tables = $phalconGenerator->getTablesData();
     if (!is_dir($modelsFolder . "\\" . 'Generated')) {
         mkdir($modelsFolder . "\\" . 'Generated', 0777, true);
     }
     $namespace = $namespaceName;
     $namespaceGenerated = $namespace . "\\Generated";
     foreach ($tables as $table) {
         $cg = new ClassGenerator($table['model'], 'Common', $namespaceGenerated);
         $fieldList = array();
         foreach ($table['columns'] as $field) {
             $cg->addProperty($field, 'protected');
             $fieldList[] = lcfirst($filter->filter($field));
         }
         $cg->addProperty('fieldList', 'protected', $fieldList);
         $content = "        return \"{$table['name']}\";";
         $cg->addMethod('getSource', 'public', array(), $content);
         $content = "";
         if (isset($table['ref_one_to_many'])) {
             foreach ($table['ref_one_to_many'] as $ref) {
                 $content .= "        \$this->belongsTo(\"{$ref['column']}\", '{$namespaceName}\\{$ref['model']}', \"{$ref['ref_column']}\", array('alias' => '{$ref['model']}'));\n";
                 $content2 = "        return \$this->getRelated('{$ref['model']}', \$parameters);";
                 $cg->addMethod('get' . $ref['model'], 'public', array(array('name' => 'parameters', 'default' => 'null')), $content2, "@return \\{$namespaceName}\\{$ref['model']}");
             }
         }
         if (isset($table['ref_many_to_one'])) {
             foreach ($table['ref_many_to_one'] as $ref) {
                 $content .= "        \$this->hasMany(\"{$ref['column']}\", '{$namespaceName}\\{$ref['model']}', \"{$ref['ref_column']}\", array('alias' => '{$ref['model']}'));\n";
                 $content2 = "        return \$this->getRelated('{$ref['model']}', \$parameters);";
                 $cg->addMethod('get' . self::getNameMany($ref['model']), 'public', array(array('name' => 'parameters', 'default' => 'null')), $content2, "@return \\{$namespaceName}\\{$ref['model']}[] ");
                 $varName = lcfirst($ref['model']);
                 $content3 = "        \$this->{$ref['model']} = array(\${$varName});";
                 $cg->addMethod('add' . $ref['model'], 'public', array(array('name' => $varName, 'type' => "\\{$namespaceName}\\{$ref['model']}")), $content3, "@return void");
             }
         }
         if (isset($table['ref_one_to_one'])) {
             foreach ($table['ref_one_to_one'] as $ref) {
                 $content .= "        \$this->hasOne(\"{$ref['column']}\", '{$namespaceName}\\{$ref['model']}', \"{$ref['ref_column']}\", array('alias' => '{$ref['model']}'));\n";
                 $content2 = "        return \$this->getRelated('{$ref['model']}', \$parameters);";
                 $cg->addMethod('get' . $ref['model'], 'public', array(array('name' => 'parameters', 'default' => 'null')), $content2, "@return \\{$namespaceName}\\{$ref['model']}");
             }
         }
         if ($content) {
             $cg->addMethod('initialize', 'public', array(), $content);
         }
         $content = "        return parent::findFirst(\$parameters);";
         $cg->addMethod('findFirst', 'public static', array(array('name' => 'parameters', 'default' => 'null')), $content, "@return \\{$namespaceName}\\{$table['model']}");
         $content = "        return parent::find(\$parameters);";
         $cg->addMethod('find', 'public static', array(array('name' => 'parameters', 'default' => 'null')), $content, "@return \\{$namespaceName}\\{$table['model']}[]");
         $content = "        return new \\{$namespaceName}\\{$table['model']}();";
         $cg->addMethod('get', 'public static', array(), $content, "@return \\{$namespaceName}\\{$table['model']}");
         $cg->generateGettersAndSetters();
         file_put_contents($modelsFolder . "\\Generated\\" . $table['model'] . '.php', $cg);
         if (!is_file($modelsFolder . "\\" . $table['model'] . '.php')) {
             $cg = new ClassGenerator($table['model'], "\\{$namespaceGenerated}\\{$table['model']}", 'Model');
             file_put_contents($modelsFolder . "\\" . $table['model'] . '.php', $cg);
         }
     }
     $cg = new ClassGenerator("Common", "\\Phalcon\\Mvc\\Model", "{$namespaceGenerated}");
     $content = "        \$query = new \\Phalcon\\Mvc\\Model\\Query(\$phql);\n";
     $content .= "        \$query->setDI(\$this->getDI());\n";
     $content .= "        return \$query;\n";
     $cg->addMethod('getQuery', 'public', array(array('name' => 'phql', 'default' => '')), $content, "@return \\Phalcon\\Mvc\\Model\\Query");
     $cg->addProperty('fieldList', 'protected', 'array()');
     $content = "        \$filter = new \\Zend_Filter_Word_UnderscoreToCamelCase();\n";
     $content .= "        foreach (\$data as \$k => \$v) {\n";
     $content .= "            if (in_array(\$k, \$this->fieldList)) {\n";
     $content .= "                \$fn = \"set\" . ucfirst(\$filter->filter(\$k));\n";
     $content .= "                \$this->\$fn(\$v);\n";
     $content .= "            }\n";
     $content .= "        }\n";
     $cg->addMethod('populate', 'public', array(array('name' => 'data', 'default' => 'array()')), $content, "@return null");
     file_put_contents($modelsFolder . "\\Generated\\Common.php", $cg);
 }
Exemple #16
0
 /**
  * Looks up the table name of a fellow table (e.g. known_node) 
  * 
  * (Useful as the package and the table prefix are not always the same)
  * 
  * @return type 
  */
 protected function getFellowTableName($suffix)
 {
     // Get known node table name (may not be same as package name)
     $knownNodeName = $this->getPackageName() . '_' . $suffix;
     $cameliser = new Zend_Filter_Word_UnderscoreToCamelCase();
     $peerName = $cameliser->filter($knownNodeName) . 'Peer';
     return constant($peerName . '::TABLE_NAME');
 }
Exemple #17
0
 /**
  * Returns a classname for a given schema & class
  * 
  * @param string $schemaName
  * @param string $className
  * @return string
  */
 public static function getNodeClassName($schemaName, $className)
 {
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     $prefix = $filter->filter($schemaName);
     return $prefix . $className;
 }
Exemple #18
0
 /**
  * @param \Vbw\Procurement\Punchout\Order\Item $item
  * @param $path
  * @param $value
  * @return \Vbw\Procurement\Punchout\Order\Item
  */
 public function setMapDestination($item, $path, $value)
 {
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     $method = 'set' . ucfirst($filter->filter($path));
     $item->{$method}($value);
     return $item;
 }
Exemple #19
0
 private function getValueFromModel($field)
 {
     $filter = new Zend_Filter_Word_UnderscoreToCamelCase();
     $getterName = 'get' . $filter->filter($field);
     return $this->model->{$getterName}();
 }
Exemple #20
0
 public function undertocamel($str)
 {
     $a = new Zend_Filter_Word_UnderscoreToCamelCase();
     return $a->filter($str);
 }
Exemple #21
0
 /**
  * Creates a toArray() generator
  * 
  * @param array $fields
  * @return Zend_CodeGenerator_Php_Method
  */
 protected function _generateToArray(array $fields)
 {
     $camelCase = new UnderscoreToCamelCase();
     $body = 'return array(' . PHP_EOL;
     foreach ($fields as $field) {
         $varAndType = explode(':', $field);
         list($varname, $type) = count($varAndType) > 1 ? $varAndType : array($varAndType[0], 'mixed');
         $key = $varname;
         $body .= '    \'' . $varname . '\' => $this->_' . LCFirst::apply($camelCase->filter($varname)) . ',' . PHP_EOL;
     }
     if (!empty($fields)) {
         $body = substr($body, 0, strlen($body) - 2) . PHP_EOL;
     }
     $body .= ');';
     return new Zend_CodeGenerator_Php_Method(array('name' => "toArray", 'body' => $body, 'docblock' => "Returns the model serialized as an array" . PHP_EOL . PHP_EOL . "@return array"));
 }