Skip to content

Commit cd81da3

Browse files
authored
Merge pull request #1074 from phalcon/3.2.x
3.2.2
2 parents 310061f + 002d386 commit cd81da3

File tree

10 files changed

+211
-28
lines changed

10 files changed

+211
-28
lines changed

scripts/Phalcon/Builder/Model.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,9 @@ public function build()
383383
foreach ($fields as $field) {
384384
if ($field->getType() === Column::TYPE_CHAR) {
385385
if ($this->options->get('camelize')) {
386-
$fieldName = Text::camelize($field->getName(), '_-');
386+
$fieldName = Utils::lowerCamelize(Utils::camelize($field->getName(), '_-'));
387387
} else {
388-
$fieldName = Text::camelize($field->getName(), '-');
388+
$fieldName = Utils::lowerCamelize(Utils::camelize($field->getName(), '-'));
389389
}
390390
$domain = [];
391391
if (preg_match('/\((.*)\)/', $field->getType(), $matches)) {
@@ -400,9 +400,9 @@ public function build()
400400
}
401401
if ($field->getName() == 'email') {
402402
if ($this->options->get('camelize')) {
403-
$fieldName = Text::camelize($field->getName(), '_-');
403+
$fieldName = Utils::lowerCamelize(Utils::camelize($field->getName(), '_-'));
404404
} else {
405-
$fieldName = Text::camelize($field->getName(), '-');
405+
$fieldName = Utils::lowerCamelize(Utils::camelize($field->getName(), '-'));
406406
}
407407
$validations[] = $this->snippet->getValidateEmail($fieldName);
408408
$uses[] = $this->snippet->getUseAs(EmailValidator::class, 'EmailValidator');
@@ -434,12 +434,12 @@ public function build()
434434
continue;
435435
}
436436
$type = $this->getPHPType($field->getType());
437-
$fieldName = $this->options->get('camelize') ? Utils::lowerCamelize($field->getName()) : $field->getName();
438-
$fieldName = Text::camelize($fieldName, '-');
437+
$fieldName = Utils::lowerCamelizeWithDelimiter($field->getName(), '-', true);
438+
$fieldName = $this->options->get('camelize') ? Utils::lowerCamelize($fieldName) : $fieldName;
439439
$attributes[] = $this->snippet->getAttributes($type, $useSettersGetters ? 'protected' : 'public', $field, $this->options->has( 'annotate' ), $fieldName);
440440

441441
if ($useSettersGetters) {
442-
$methodName = Text::camelize($field->getName(). '_-');
442+
$methodName = Utils::camelize($field->getName(). '_-');
443443
$setters[] = $this->snippet->getSetter($fieldName, $type, $methodName);
444444

445445
if (isset($this->_typeMap[$type])) {

scripts/Phalcon/Builder/Project.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function build()
121121

122122
if ($success === true) {
123123
$this->notifySuccess(sprintf(
124-
'Project "%s" was successfully created.',
124+
"Project '%s' was successfully created.\nPlease choose a password and username to use Database connection. Used default:'root' without password.",
125125
$this->options->get('name')
126126
));
127127
}

scripts/Phalcon/Builder/Scaffold.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ private function _captureFilterInput($var, $fields, $useGetSetters, $identityFie
277277
}
278278
}
279279

280-
$code .= '$'.$var.'->';
280+
$code .= '$' . Text::camelize($var, '-') . '->';
281281
if ($useGetSetters) {
282282
$code .= 'set' . Text::camelize($field) . '(' . $fieldCode . ')';
283283
} else {
284-
$code .= $field . ' = ' . $fieldCode;
284+
$code .= Text::camelize($field, '-') . ' = ' . $fieldCode;
285285
}
286286

287287
$code .= ';' . PHP_EOL . "\t\t";
@@ -307,7 +307,7 @@ private function _assignTagDefaults($var, $fields, $useGetSetters)
307307
$accessor = $field;
308308
}
309309

310-
$code .= '$this->tag->setDefault("' . $field . '", $' . $var . '->' . $accessor . ');' . PHP_EOL . "\t\t\t";
310+
$code .= '$this->tag->setDefault("' . $field . '", $' . Text::camelize($var, '-') . '->' . $accessor . ');' . PHP_EOL . "\t\t\t";
311311
}
312312

313313
return $code;
@@ -491,10 +491,10 @@ private function _makeController()
491491

492492
$code = str_replace('$fullyQualifiedModelName$', $this->options->get('modelClass'), $code);
493493

494-
$code = str_replace('$singularVar$', '$' . $this->options->get('singular'), $code);
494+
$code = str_replace('$singularVar$', '$' . Text::camelize($this->options->get('singular'), '-'), $code);
495495
$code = str_replace('$singular$', $this->options->get('singular'), $code);
496496

497-
$code = str_replace('$pluralVar$', '$' . $this->options->get('plural'), $code);
497+
$code = str_replace('$pluralVar$', '$' . Text::camelize($this->options->get('plural'), '-'), $code);
498498
$code = str_replace('$plural$', $this->options->get('plural'), $code);
499499

500500
$code = str_replace('$className$', $this->options->get('className'), $code);
@@ -522,7 +522,7 @@ private function _makeController()
522522
$code = str_replace('$pkVar$', '$' . $attributes[0], $code);
523523

524524
if ($this->options->get('genSettersGetters')) {
525-
$code = str_replace('$pkGet$', 'get'.Text::camelize($attributes[0]).'()', $code);
525+
$code = str_replace('$pkGet$', 'get' . Text::camelize($attributes[0]) . '()', $code);
526526
} else {
527527
$code = str_replace('$pkGet$', $attributes[0], $code);
528528
}
@@ -668,14 +668,14 @@ private function makeViewVolt($type)
668668
mkdir($dirPath, 0777, true);
669669
}
670670

671-
$viewPath = $dirPath . DIRECTORY_SEPARATOR .$type. '.volt';
671+
$viewPath = $dirPath . DIRECTORY_SEPARATOR . $type . '.volt';
672672
if (file_exists($viewPath)) {
673673
if (!$this->options->contains('force')) {
674674
return;
675675
}
676676
}
677677

678-
$templatePath = $this->options->templatePath . '/scaffold/no-forms/views/' .$type. '.volt';
678+
$templatePath = $this->options->templatePath . '/scaffold/no-forms/views/' . $type . '.volt';
679679
if (!file_exists($templatePath)) {
680680
throw new BuilderException(sprintf('Template "%s" does not exist.', $templatePath));
681681
}
@@ -726,7 +726,7 @@ private function _makeViewSearch()
726726
$rowCode .= "\t\t\t" . '<td><?php echo ';
727727
if (!isset($this->options->allReferences[$fieldName])) {
728728
if ($this->options->genSettersGetters) {
729-
$rowCode .= '$' . $this->options->singular . '->get' . Text::camelize($fieldName) . '()';
729+
$rowCode .= '$' . Text::camelize($this->options->singular, '-') . '->get' . Text::camelize($fieldName) . '()';
730730
} else {
731731
$rowCode .= '$' . $this->options->singular . '->' . $fieldName;
732732
}
@@ -747,7 +747,7 @@ private function _makeViewSearch()
747747
$code = str_replace('$plural$', $this->options->plural, $code);
748748
$code = str_replace('$headerColumns$', $headerCode, $code);
749749
$code = str_replace('$rowColumns$', $rowCode, $code);
750-
$code = str_replace('$singularVar$', '$' . $this->options->singular, $code);
750+
$code = str_replace('$singularVar$', '$' . Text::camelize($this->options->singular, '-'), $code);
751751
$code = str_replace('$pk$', $idField, $code);
752752

753753
if ($this->isConsole()) {
@@ -791,7 +791,7 @@ private function _makeViewSearchVolt()
791791
$rowCode .= "\t\t\t" . '<td>{{ ';
792792
if (!isset($this->options->allReferences[$fieldName])) {
793793
if ($this->options->contains('genSettersGetters')) {
794-
$rowCode .= $this->options->singular . '.get' . Text::camelize($fieldName) . '()';
794+
$rowCode .= Text::camelize($this->options->singular, '-') . '.get' . Text::camelize($fieldName) . '()';
795795
} else {
796796
$rowCode .= $this->options->singular . '.' . $fieldName;
797797
}
@@ -812,7 +812,7 @@ private function _makeViewSearchVolt()
812812
$code = str_replace('$plural$', $this->options->plural, $code);
813813
$code = str_replace('$headerColumns$', $headerCode, $code);
814814
$code = str_replace('$rowColumns$', $rowCode, $code);
815-
$code = str_replace('$singularVar$', $this->options->singular, $code);
815+
$code = str_replace('$singularVar$', Text::camelize($this->options->singular, '-'), $code);
816816
$code = str_replace('$pk$', $idField, $code);
817817

818818
if ($this->isConsole()) {

scripts/Phalcon/Commands/Builtin/Model.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
namespace Phalcon\Commands\Builtin;
2222

2323
use Phalcon\Text;
24+
use Phalcon\Utils;
2425
use Phalcon\Builder;
2526
use Phalcon\Script\Color;
2627
use Phalcon\Commands\Command;
@@ -71,7 +72,7 @@ public function getPossibleParams()
7172
public function run(array $parameters)
7273
{
7374
$name = $this->getOption(['name', 1]);
74-
$className = Text::camelize(isset($parameters[1]) ? $parameters[1] : $name, '_-');
75+
$className = Utils::camelize(isset($parameters[1]) ? $parameters[1] : $name, '_-');
7576

7677
$modelBuilder = new ModelBuilder(
7778
[

scripts/Phalcon/Commands/Builtin/Project.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class Project extends Command
4141
public function getPossibleParams()
4242
{
4343
return [
44-
'name' => 'Name of the new project',
44+
'name=s' => 'Name of the new project',
4545
'enable-webtools' => 'Determines if webtools should be enabled [optional]',
4646
'directory=s' => 'Base path on which project will be created [optional]',
4747
'type=s' => 'Type of the application to be generated (cli, micro, simple, modules)',

scripts/Phalcon/Db/Dialect/PostgresqlExtended.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function describeReferences($table, $schema = NULL)
4343
tc.table_name as TABLE_NAME,
4444
kcu.column_name as COLUMN_NAME,
4545
tc.constraint_name as CONSTRAINT_NAME,
46-
tc.table_catalog as REFERENCED_TABLE_SCHEMA,
46+
tc.table_schema as REFERENCED_TABLE_SCHEMA,
4747
ccu.table_name AS REFERENCED_TABLE_NAME,
4848
ccu.column_name AS REFERENCED_COLUMN_NAME,
4949
rc.update_rule AS UPDATE_RULE,

scripts/Phalcon/Mvc/Model/Migration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ public static function generate(ItemInterface $version, $table, $exportData = nu
355355

356356
$referenceDefinition = [];
357357
$referenceDefinition[] = "'referencedTable' => '".$dbReference->getReferencedTable()."'";
358+
$referenceDefinition[] = "'referencedSchema' => '".$dbReference->getReferencedSchema()."'";
358359
$referenceDefinition[] = "'columns' => [".join(",", array_unique($columns))."]";
359360
$referenceDefinition[] = "'referencedColumns' => [".join(",", array_unique($referencedColumns))."]";
360361
$referenceDefinition[] = "'onUpdate' => '".$dbReference->getOnUpdate()."'";
@@ -693,6 +694,7 @@ public function morphTable($tableName, $definition)
693694
foreach ($activeReferences as $activeReference) {
694695
$localReferences[$activeReference->getName()] = [
695696
'referencedTable' => $activeReference->getReferencedTable(),
697+
"referencedSchema" => $activeReference->getReferencedSchema(),
696698
'columns' => $activeReference->getColumns(),
697699
'referencedColumns' => $activeReference->getReferencedColumns(),
698700
];

scripts/Phalcon/Utils.php

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,64 @@ class Utils
3131
* Converts the underscore_notation to the UpperCamelCase
3232
*
3333
* @param string $string
34+
* @param string $delimiter
3435
* @return string
3536
*/
36-
public static function camelize($string)
37+
public static function camelize($string, $delimiter = '_')
3738
{
38-
$stringParts = explode('_', $string);
39-
$stringParts = array_map('ucfirst', $stringParts);
39+
if (empty($delimiter)) {
40+
throw new \InvalidArgumentException('Please, specify the delimiter');
41+
}
42+
43+
$delimiterArray = str_split($delimiter);
44+
45+
foreach ($delimiterArray as $delimiter) {
46+
$stringParts = explode($delimiter, $string);
47+
$stringParts = array_map('ucfirst', $stringParts);
48+
49+
$string = implode('', $stringParts);
50+
}
4051

41-
return implode('', $stringParts);
52+
return $string;
53+
54+
}
55+
56+
/**
57+
* Convert string foo_bar to FooBar or fooBar
58+
*
59+
* <code>
60+
* echo Phalcon\Utils::lowerCamelizeWithDelimiter('coco_bongo'); // coco_bongo
61+
* echo Phalcon\Utils::lowerCamelizeWithDelimiter('coco_bongo', '_'); // CocoBongo
62+
* echo Phalcon\Utils::lowerCamelizeWithDelimiter('coco_bongo', '_', true); // cocoBongo
63+
* </code>
64+
*
65+
* @param string $string
66+
* @param string $delimiter
67+
* @param boolean $useLow
68+
* @return string
69+
*/
70+
public static function lowerCamelizeWithDelimiter($string, $delimiter = '', $useLow = false)
71+
{
72+
if (empty($string)) {
73+
throw new \InvalidArgumentException('Please, specify the string');
74+
}
75+
76+
if (!empty($delimiter)) {
77+
$delimiterArray = str_split($delimiter);
78+
79+
foreach ($delimiterArray as $delimiter) {
80+
$stringParts = explode($delimiter, $string);
81+
$stringParts = array_map('ucfirst', $stringParts);
82+
83+
$string = implode('', $stringParts);
84+
}
85+
}
86+
87+
if ($useLow) {
88+
$string = lcfirst($string);
89+
}
90+
91+
return $string;
4292
}
4393

4494
/**

tests/_support/Helper/Db/Dialect/PostgresqlTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function getReferenceObject()
4141
return
4242
['test_describereferences' => new Reference('test_describereferences', [
4343
'referencedTable' => 'foreign_key_parent',
44-
'referencedSchema' => 'devtools',
44+
'referencedSchema' => 'public',
4545
'columns' => ['child_int'],
4646
'referencedColumns' => ['refer_int'],
4747
'onUpdate' => 'CASCADE',

0 commit comments

Comments
 (0)