Skip to content

Commit 310061f

Browse files
authored
Merge pull request #1061 from phalcon/3.2.x
3.2.1
2 parents ebc084b + 606e774 commit 310061f

39 files changed

+1437
-57
lines changed

.gitignore

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
.idea
2-
.DS_Store
3-
phalcon.phar
4-
composer.lock
5-
composer.phar
6-
/vendor/
1+
# Please do not use this ignore file to define platform specific files.
2+
#
3+
# For these purposes create a global .gitignore file, which is a list of rules
4+
# for ignoring files in every Git repository on your computer.
5+
#
6+
# https://help.github.com/articles/ignoring-files/#create-a-global-gitignore
7+
8+
/composer.lock
9+
/vendor

.travis.yml

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ dist: trusty
66
php:
77
- 5.5
88
- 5.6
9+
- 7.1
10+
11+
services:
12+
- postgresql
913

1014
matrix:
1115
include:
@@ -24,17 +28,38 @@ cache:
2428
- vendor
2529
- $HOME/.ccache
2630
- $HOME/.composer/cache
31+
- $HOME/cphalcon
32+
- $HOME/ext
2733

2834
env:
2935
global:
30-
- ZEND_DONT_UNLOAD_MODULES=1
31-
- CC="ccache gcc"
36+
- TEST_DB_POSTGRESQL_HOST="127.0.0.1"
37+
- TEST_DB_POSTGRESQL_PORT="5432"
38+
- TEST_DB_POSTGRESQL_USER="postgres"
39+
- TEST_DB_POSTGRESQL_PASSWD=""
40+
- TEST_DB_POSTGRESQL_NAME="devtools"
3241
- PATH="$PATH:~/bin"
3342
- DISPLAY=":99.0"
34-
- PHALCON_VERSION="v3.0.4"
43+
- PHALCON_VERSION="v3.2.0"
44+
45+
before_install:
46+
- export PHP_VERSION=$(php-config --version)
47+
- export PHP_EXTENSION_DIR=$(php-config --extension-dir)
48+
- phpenv config-rm xdebug.ini || true
49+
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com $GH_TOKEN; fi;
50+
- if [ ! -f "$HOME/cphalcon/tests/_ci/phalcon.ini" ]; then git clone -q --depth=1 https://github.com/phalcon/cphalcon.git $HOME/cphalcon >/dev/null 2>&1; fi;
51+
- bash tests/_ci/setup_dbs.sh
52+
53+
install:
54+
- if [ ! -f $HOME/ext/$PHP_VERSION/phalcon.so ]; then cd $HOME/cphalcon/build && bash ./install --phpize $(phpenv which phpize) --php-config $(phpenv which php-config) && mkdir -p $HOME/ext/$PHP_VERSION && cp $PHP_EXTENSION_DIR/phalcon.so $HOME/ext/$PHP_VERSION/phalcon.so; fi;
55+
- if [ -f $HOME/ext/$PHP_VERSION/phalcon.so ]; then cp $HOME/ext/$PHP_VERSION/phalcon.so $PHP_EXTENSION_DIR/phalcon.so; fi;
56+
- phpenv config-add $HOME/cphalcon/tests/_ci/phalcon.ini
57+
- cd $TRAVIS_BUILD_DIR
58+
- travis_retry composer install --prefer-dist --no-interaction
3559

3660
script:
37-
- true
61+
- vendor/bin/codecept build
62+
- vendor/bin/codecept run unit -v
3863

3964
notifications:
4065
email:
@@ -46,9 +71,6 @@ notifications:
4671
addons:
4772
apt:
4873
packages:
49-
- gdb
50-
- re2c
51-
- beanstalkd
5274
- mysql-server-5.6
5375
- mysql-client-core-5.6
5476
- mysql-client-5.6

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Available commands:
130130
scaffold (alias of: create-scaffold)
131131
migration (alias of: create-migration)
132132
webtools (alias of: create-webtools)
133+
serve (alias of: server)
133134
console (alias of: shell, psysh)
134135
```
135136

bootstrap/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
/**
4343
* @const PTOOLSPATH The path to the Phalcon Developers Tools.
4444
*/
45-
defined('PTOOLSPATH') || define('PTOOLSPATH', rtrim(getenv('PTOOLSPATH') ?: dirname(dirname(__FILE__)), '\\/'));
45+
defined('PTOOLSPATH') || define('PTOOLSPATH', rtrim(trim(getenv('PTOOLSPATH'), '\"\'') ?: dirname(dirname(__FILE__)), '\\/'));
4646

4747
/**
4848
* Check for old versions

codeception.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
settings:
8+
# name of bootstrap that will be used
9+
# each bootstrap file should be
10+
# inside a suite directory.
11+
bootstrap: _bootstrap.php
12+
colors: true
13+
# Tests (especially functional) can take a lot of memory
14+
# We set a high limit for them by default.
15+
memory_limit: 1024M
16+
actor_suffix: Tester
17+
extensions:
18+
enabled:
19+
- Codeception\Extension\RunFailed

composer.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,25 @@
2727
"psy/psysh": "@stable"
2828
},
2929
"require-dev": {
30-
"kherge/box": "^2.7"
30+
"kherge/box": "^2.7",
31+
"codeception/codeception": "^2.3",
32+
"phpdocumentor/reflection-docblock": "^2.0",
33+
"phpunit/phpunit": "^4.8",
34+
"codeception/specify": "^0.4",
35+
"codeception/verify": "^0.3"
36+
3137
},
3238
"autoload": {
3339
"psr-4" : {
3440
"Phalcon\\" : "scripts/Phalcon/"
3541
}
3642
},
43+
"autoload-dev": {
44+
"psr-4": {
45+
"Phalcon\\Test\\": "tests/unit",
46+
"Phalcon\\Test\\Models\\": "tests/_data/models",
47+
"Phalcon\\Test\\Module\\": "tests/_support/Module"
48+
}
49+
},
3750
"bin": ["phalcon.php"]
3851
}

phalcon.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@
3434
use Phalcon\Commands\Builtin\Migration;
3535
use Phalcon\Commands\Builtin\Enumerate;
3636
use Phalcon\Commands\Builtin\Controller;
37+
use Phalcon\Commands\Builtin\Serve;
3738
use Phalcon\Commands\Builtin\Console;
3839
use Phalcon\Exception as PhalconException;
40+
use Phalcon\Commands\DotPhalconMissingException;
3941
use Phalcon\Events\Manager as EventsManager;
4042

4143
try {
@@ -61,6 +63,7 @@
6163
Scaffold::class,
6264
Migration::class,
6365
Webtools::class,
66+
Serve::class,
6467
Console::class,
6568
];
6669

@@ -71,6 +74,13 @@
7174
}
7275

7376
$script->run();
77+
} catch (DotPhalconMissingException $e) {
78+
fwrite(STDERR, Color::info($e->getMessage() . " " . $e->scanPathMessage()));
79+
if ($e->promptResolution()) {
80+
$script->run();
81+
} else {
82+
exit(1);
83+
}
7484
} catch (PhalconException $e) {
7585
fwrite(STDERR, Color::error($e->getMessage()) . PHP_EOL);
7686
exit(1);

scripts/Phalcon/Builder/AllModels.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ public function build()
117117
$hasMany = [];
118118
$belongsTo = [];
119119
$foreignKeys = [];
120+
$referenceList = [];
120121
if ($defineRelations || $defineForeignKeys) {
121122
foreach ($db->listTables($schema) as $name) {
122123
if ($defineRelations) {
@@ -133,8 +134,9 @@ public function build()
133134

134135
$camelCaseName = Utils::camelize($name);
135136
$refSchema = ($adapter != 'Postgresql') ? $schema : $config->database->dbname;
137+
$referenceList[$name] = $db->describeReferences($name, $schema);
136138

137-
foreach ($db->describeReferences($name, $schema) as $reference) {
139+
foreach ($referenceList[$name] as $reference) {
138140
$columns = $reference->getColumns();
139141
$referencedColumns = $reference->getReferencedColumns();
140142
$referencedModel = Utils::camelize($reference->getReferencedTable());
@@ -164,6 +166,7 @@ public function build()
164166
$belongsTo[$name] = [];
165167
$foreignKeys[$name] = [];
166168
}
169+
$referenceList[$name] = $db->describeReferences($name, $schema);
167170
}
168171
}
169172

@@ -204,7 +207,9 @@ public function build()
204207
'directory' => $this->options->get('directory'),
205208
'modelsDir' => $this->options->get('modelsDir'),
206209
'mapColumn' => $mapColumn,
207-
'abstract' => $this->options->get('abstract')
210+
'abstract' => $this->options->get('abstract'),
211+
'referenceList' => $referenceList,
212+
'camelize' => $this->options->get('camelize')
208213
]);
209214

210215
$modelBuilder->build();

scripts/Phalcon/Builder/Model.php

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Phalcon\Generator\Snippet;
2929
use Phalcon\Db\ReferenceInterface;
3030
use Phalcon\Validation\Validator\Email as EmailValidator;
31+
use Phalcon\Text;
3132

3233

3334
/**
@@ -75,11 +76,11 @@ public function __construct(array $options)
7576
}
7677

7778
if (!isset($options['className'])) {
78-
$options['className'] = Utils::camelize($options['name']);
79+
$options['className'] = Text::camelize($options['name'], '_-');
7980
}
8081

8182
if (!isset($options['fileName'])) {
82-
$options['fileName'] = $options['name'];
83+
$options['fileName'] = Text::camelize($options['name'], '_-');
8384
}
8485

8586
if (!isset($options['abstract'])) {
@@ -229,19 +230,25 @@ public function build()
229230
if ($schema) {
230231
$initialize['schema'] = $this->snippet->getThisMethod('setSchema', $schema);
231232
}
233+
$initialize['source'] = $this->snippet->getThisMethod('setSource', $this->options->get('name'));
232234

233235
$table = $this->options->get('name');
234-
if ($this->options->get('fileName') != $table && !isset($initialize['schema'])) {
235-
$initialize[] = $this->snippet->getThisMethod('setSource', $table);
236-
}
237236

238237
if (!$db->tableExists($table, $schema)) {
239238
throw new BuilderException(sprintf('Table "%s" does not exist.', $table));
240239
}
241240
$fields = $db->describeColumns($table, $schema);
242241

243-
foreach ($db->listTables() as $tableName) {
244-
foreach ($db->describeReferences($tableName, $schema) as $reference) {
242+
if (!$this->options->contains('referenceList')) {
243+
foreach ($db->listTables($schema) as $name) {
244+
$referenceList[$name] = $db->describeReferences($name, $schema);;
245+
}
246+
} else {
247+
$referenceList = $this->options->get('referenceList');
248+
}
249+
250+
foreach ($referenceList as $tableName => $references) {
251+
foreach ($references as $reference) {
245252
if ($reference->getReferencedTable() != $this->options->get('name')) {
246253
continue;
247254
}
@@ -256,9 +263,9 @@ public function build()
256263
$initialize[] = $this->snippet->getRelation(
257264
'hasMany',
258265
$this->options->get('camelize') ? Utils::lowerCamelize($refColumns[0]) : $refColumns[0],
259-
$entityNamespace . Utils::camelize($tableName),
266+
$entityNamespace . Text::camelize($tableName, '_-'),
260267
$this->options->get('camelize') ? Utils::lowerCamelize($columns[0]) : $columns[0],
261-
"['alias' => '" . Utils::camelize($tableName) . "']"
268+
"['alias' => '" . Text::camelize($tableName, '_-') . "']"
262269
);
263270
}
264271
}
@@ -276,7 +283,7 @@ public function build()
276283
$this->options->get('camelize') ? Utils::lowerCamelize($columns[0]) : $columns[0],
277284
$this->getEntityClassName($reference, $entityNamespace),
278285
$this->options->get('camelize') ? Utils::lowerCamelize($refColumns[0]) : $refColumns[0],
279-
"['alias' => '" . Utils::camelize($reference->getReferencedTable()) . "']"
286+
"['alias' => '" . Text::camelize($reference->getReferencedTable(), '_-') . "']"
280287
);
281288
}
282289

@@ -293,7 +300,7 @@ public function build()
293300
if ($useSettersGetters) {
294301
foreach ($fields as $field) {
295302
/** @var \Phalcon\Db\Column $field */
296-
$methodName = Utils::camelize($field->getName());
303+
$methodName = Text::camelize($field->getName(), '_-');
297304

298305
$possibleMethods['set' . $methodName] = true;
299306
$possibleMethods['get' . $methodName] = true;
@@ -376,9 +383,9 @@ public function build()
376383
foreach ($fields as $field) {
377384
if ($field->getType() === Column::TYPE_CHAR) {
378385
if ($this->options->get('camelize')) {
379-
$fieldName = Utils::lowerCamelize($field->getName());
386+
$fieldName = Text::camelize($field->getName(), '_-');
380387
} else {
381-
$fieldName = $field->getName();
388+
$fieldName = Text::camelize($field->getName(), '-');
382389
}
383390
$domain = [];
384391
if (preg_match('/\((.*)\)/', $field->getType(), $matches)) {
@@ -393,9 +400,9 @@ public function build()
393400
}
394401
if ($field->getName() == 'email') {
395402
if ($this->options->get('camelize')) {
396-
$fieldName = Utils::lowerCamelize($field->getName());
403+
$fieldName = Text::camelize($field->getName(), '_-');
397404
} else {
398-
$fieldName = $field->getName();
405+
$fieldName = Text::camelize($field->getName(), '-');
399406
}
400407
$validations[] = $this->snippet->getValidateEmail($fieldName);
401408
$uses[] = $this->snippet->getUseAs(EmailValidator::class, 'EmailValidator');
@@ -428,10 +435,11 @@ public function build()
428435
}
429436
$type = $this->getPHPType($field->getType());
430437
$fieldName = $this->options->get('camelize') ? Utils::lowerCamelize($field->getName()) : $field->getName();
438+
$fieldName = Text::camelize($fieldName, '-');
431439
$attributes[] = $this->snippet->getAttributes($type, $useSettersGetters ? 'protected' : 'public', $field, $this->options->has( 'annotate' ), $fieldName);
432-
if ($useSettersGetters) {
433-
$methodName = Utils::camelize($field->getName());
434440

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

437445
if (isset($this->_typeMap[$type])) {
@@ -513,7 +521,7 @@ public function build()
513521

514522
if ($this->isConsole()) {
515523
$msgSuccess = ($this->options->contains('abstract') ? 'Abstract ' : '') . 'Model "%s" was successfully created.';
516-
$this->notifySuccess(sprintf($msgSuccess, Utils::camelize($this->options->get('name'))));
524+
$this->notifySuccess(sprintf($msgSuccess, Text::camelize($this->options->get('name'), '_-')));
517525
}
518526
}
519527

scripts/Phalcon/Builder/Scaffold.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ private function _makeController()
520520
$attributes = $this->options->get('attributes');
521521

522522
$code = str_replace('$pkVar$', '$' . $attributes[0], $code);
523+
524+
if ($this->options->get('genSettersGetters')) {
525+
$code = str_replace('$pkGet$', 'get'.Text::camelize($attributes[0]).'()', $code);
526+
} else {
527+
$code = str_replace('$pkGet$', $attributes[0], $code);
528+
}
523529
$code = str_replace('$pk$', $attributes[0], $code);
524530

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

0 commit comments

Comments
 (0)