Skip to content

Commit

Permalink
Merge pull request phalcon#1124 from phalcon/3.2.x
Browse files Browse the repository at this point in the history
3.2.7
  • Loading branch information
sergeyklay authored Oct 13, 2017
2 parents b62a35e + 4628363 commit 018605a
Show file tree
Hide file tree
Showing 33 changed files with 163 additions and 62 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ env:

before_install:
- export PHP_VERSION=$(php-config --version)
- export PHP_MAJOR="$(echo $TRAVIS_PHP_VERSION | cut -d '.' -f 1)"
- export PHP_EXTENSION_DIR=$(php-config --extension-dir)
- phpenv config-rm xdebug.ini || true
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com $GH_TOKEN; fi;
Expand All @@ -67,12 +68,14 @@ install:

before_script:
- ln -s $PWD/phalcon.php ~/bin/phalcon
- '[[ "$PHP_MAJOR" == "5" ]] || composer require --dev phpstan/phpstan'

script:
- vendor/bin/codecept build
- vendor/bin/codecept run unit -v
- vendor/bin/codecept run functional -v
- vendor/bin/codecept run console -v
- '[[ "$PHP_MAJOR" == "5" ]] || vendor/bin/phpstan analyse -l 1 -c phpstan.neon scripts -vvv'

notifications:
email:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ This command should display something similar to:
```sh
$ phalcon --help

Phalcon DevTools (3.2.0)
Phalcon DevTools (3.2.7)

Help:
Lists the commands available in Phalcon devtools
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
bootstrap: %rootDir%/../../../tests/phpstan.php

excludes_analyse:
- %rootDir%/../../../scripts/Phalcon/Generator/*
1 change: 1 addition & 0 deletions scripts/Phalcon/Access/Policy/Ip.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
/**
* \Phalcon\Access\Policy\Ip
*
* @property \Phalcon\Http\Request|\Phalcon\Http\RequestInterface $request
* @package Phalcon\Access\Policy
*/
class Ip extends Injectable implements PolicyInterface
Expand Down
2 changes: 2 additions & 0 deletions scripts/Phalcon/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
/**
* \Phalcon\Web\Tools\Library\Bootstrap
*
* @method mixed getShared($name, $parameters=null)
* @method mixed get($name, $parameters=null)
* @package Phalcon\Web\Tools\Library
*/
class Bootstrap
Expand Down
32 changes: 24 additions & 8 deletions scripts/Phalcon/Builder/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use Phalcon\Db\ReferenceInterface;
use Phalcon\Validation\Validator\Email as EmailValidator;
use Phalcon\Text;
use \Phalcon\Db\Adapter\Pdo;


/**
Expand Down Expand Up @@ -241,15 +242,9 @@ public function build()
if (!$db->tableExists($table, $schema)) {
throw new BuilderException(sprintf('Table "%s" does not exist.', $table));
}
$fields = $db->describeColumns($table, $schema);

if (!$this->options->contains('referenceList')) {
foreach ($db->listTables($schema) as $name) {
$referenceList[$name] = $db->describeReferences($name, $schema);;
}
} else {
$referenceList = $this->options->get('referenceList');
}
$fields = $db->describeColumns($table, $schema);
$referenceList = $this->getReferenceList($schema, $db);

foreach ($referenceList as $tableName => $references) {
foreach ($references as $reference) {
Expand Down Expand Up @@ -536,4 +531,25 @@ protected function getEntityClassName(ReferenceInterface $reference, $namespace)

return $fqcn;
}

/**
* Get reference list from option
*
* @param string $schema
* @param Pdo $db
* @return array
*/
protected function getReferenceList($schema, Pdo $db)
{
if ($this->options->contains('referenceList')) {
return $this->options->get('referenceList');
}

$referenceList = [];
foreach ($db->listTables($schema) as $name) {
$referenceList[$name] = $db->describeReferences($name, $schema);;
}

return $referenceList;
}
}
2 changes: 2 additions & 0 deletions scripts/Phalcon/Commands/Builtin/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use Phalcon\Script\Color;
use Phalcon\Commands\Command;
use Phalcon\Builder\Model as ModelBuilder;
use Phalcon\Config;
use Phalcon\Config\Adapter\Ini as ConfigIni;

/**
* Model Command
Expand Down
2 changes: 2 additions & 0 deletions scripts/Phalcon/Commands/DotPhalconMissingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function __construct (string $message = self::DEFAULT_MESSAGE , $code = 0
{
$this->message = $message;
$this->code = $code;

parent::__construct();
}

public function scanPathMessage()
Expand Down
46 changes: 46 additions & 0 deletions scripts/Phalcon/Console/OptionParserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

namespace Phalcon\Console;

use Phalcon\Version\IncrementalItem as IncrementalVersion;
use Phalcon\Version\ItemCollection as VersionCollection;
use Phalcon\Mvc\Model\Migration as ModelMigration;
use InvalidArgumentException;

/**
* \Phalcon\Utils\OptionParserTrait
*
Expand Down Expand Up @@ -46,4 +51,45 @@ public function getPrefixOption($prefix, $prefixEnd = '*')

return substr($prefix, 0, -1);
}

/**
* Get version name to generate migration
*
* @return IncrementalVersion
*/
public function getVersionNameGeneratingMigration()
{
if (empty($this->options)) {
throw new InvalidArgumentException('Options were not defined yet');
}

// Use timestamped version if description is provided
if ($this->options['descr']) {
$this->options['version'] = (string)(int)(microtime(true) * pow(10, 6));
VersionCollection::setType(VersionCollection::TYPE_TIMESTAMPED);
$versionItem = VersionCollection::createItem($this->options['version'] . '_' . $this->options['descr']);

// Elsewhere use old-style incremental versioning
// The version is specified
} elseif ($this->options['version']) {
VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL);
$versionItem = VersionCollection::createItem($this->options['version']);

// The version is guessed automatically
} else {
VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL);
$versionItems = ModelMigration::scanForVersions($this->options['migrationsDir']);

if (!isset($versionItems[0])) {
$versionItem = VersionCollection::createItem('1.0.0');

} else {
/** @var IncrementalVersion $versionItem */
$versionItem = VersionCollection::maximum($versionItems);
$versionItem = $versionItem->addMinor(1);
}
}

return $versionItem;
}
}
2 changes: 1 addition & 1 deletion scripts/Phalcon/Devtools/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class Version extends PhVersion
*/
protected static function _getVersion()
{
return [3, 2, 5, 4, 0];
return [3, 2, 7, 4, 0];
}
}
1 change: 1 addition & 0 deletions scripts/Phalcon/Elements/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
/**
* \Phalcon\Elements\Element
*
* @property \Phalcon\Tag $tag
* @package Phalcon\Elements
*/
class Element extends Component
Expand Down
41 changes: 1 addition & 40 deletions scripts/Phalcon/Migrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public static function isConsole()
public static function generate(array $options)
{
$optionStack = new OptionStack();
$modelMigration = new ModelMigration();
$listTables = new ListTablesDb();
$optionStack->setOptions($options);
$optionStack->setDefaultOption('version', null);
Expand All @@ -91,7 +90,7 @@ public static function generate(array $options)
mkdir($optionStack->getOption('migrationsDir'), 0755, true);
}

$versionItem = self::getVersionNameGeneratingMigration($optionStack);
$versionItem = $optionStack->getVersionNameGeneratingMigration();

// Path to migration dir
$migrationPath = rtrim($optionStack->getOption('migrationsDir'), '\\/') . DIRECTORY_SEPARATOR . $versionItem->getVersion();
Expand Down Expand Up @@ -589,42 +588,4 @@ public static function getCompletedVersions($options)

return array_flip($completedVersions);
}

/**
* Get version name to generate migration
*
* @param OptionStack $optionStack Applications options
* @return IncrementalVersion
*/
protected function getVersionNameGeneratingMigration($optionStack)
{
// Use timestamped version if description is provided
if ($optionStack->getOption('descr')) {
$optionStack->setOption('version', (string)(int)(microtime(true) * pow(10, 6)));
VersionCollection::setType(VersionCollection::TYPE_TIMESTAMPED);
$versionItem = VersionCollection::createItem($optionStack->getOption('version') . '_' . $optionStack->getOption('descr'));

// Elsewhere use old-style incremental versioning
// The version is specified
} elseif ($optionStack->getOption('version')) {
VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL);
$versionItem = VersionCollection::createItem($optionStack->getOption('version'));

// The version is guessed automatically
} else {
VersionCollection::setType(VersionCollection::TYPE_INCREMENTAL);
$versionItems = ModelMigration::scanForVersions($optionStack->getOption('migrationsDir'));

if (!isset($versionItems[0])) {
$versionItem = VersionCollection::createItem('1.0.0');

} else {
/** @var IncrementalVersion $versionItem */
$versionItem = VersionCollection::maximum($versionItems);
$versionItem = $versionItem->addMinor(1);
}
}

return $versionItem;
}
}
6 changes: 6 additions & 0 deletions scripts/Phalcon/Mvc/Controller/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
* @property \Phalcon\Registry $registry
* @property \Phalcon\Elements\Menu\SidebarMenu $sidebar
* @property \Phalcon\Resources\AssetsResource $resource
* @property \Phalcon\Assets\Manager $assets
* @property \Phalcon\Http\Request|\Phalcon\Http\RequestInterface $request
* @property \Phalcon\Mvc\Router|\Phalcon\Mvc\RouterInterface $router
* @property \Phalcon\Http\Response|\Phalcon\Http\ResponseInterface $response
* @property \Phalcon\Mvc\View|\Phalcon\Mvc\ViewInterface $view
* @property \Phalcon\Mvc\Url|\Phalcon\Mvc\UrlInterface $url
*
* @package Phalcon\Mvc\Controller
*/
Expand Down
17 changes: 11 additions & 6 deletions scripts/Phalcon/Mvc/Model/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* Phalcon\Mvc\Model\Migration
*
* Migrations of DML y DDL over databases
* @method afterCreateTable()
*
* @package Phalcon\Mvc\Model
*/
Expand Down Expand Up @@ -605,6 +606,7 @@ public function morphTable($tableName, $definition)
{
$defaultSchema = Utils::resolveDbSchema(self::$_databaseConfig);
$tableExists = self::$_connection->tableExists($tableName, $defaultSchema);
$tableSchema = null;

if (isset($definition['columns'])) {
if (count($definition['columns']) == 0) {
Expand All @@ -621,6 +623,9 @@ public function morphTable($tableName, $definition)
* @var \Phalcon\Db\ColumnInterface[] $fields
*/
$fields[$tableColumn->getName()] = $tableColumn;
if (empty($tableSchema)) {
$tableSchema = $tableColumn->getSchemaName();
}
}

if ($tableExists == true) {
Expand Down Expand Up @@ -789,9 +794,9 @@ public function morphTable($tableName, $definition)
foreach ($definition['indexes'] as $tableIndex) {
if (!isset($localIndexes[$tableIndex->getName()])) {
if ($tableIndex->getName() == 'PRIMARY') {
self::$_connection->addPrimaryKey($tableName, $tableColumn->getSchemaName(), $tableIndex);
self::$_connection->addPrimaryKey($tableName, $tableSchema, $tableIndex);
} else {
self::$_connection->addIndex($tableName, $tableColumn->getSchemaName(), $tableIndex);
self::$_connection->addIndex($tableName, $tableSchema, $tableIndex);
}
} else {
$changed = false;
Expand All @@ -807,19 +812,19 @@ public function morphTable($tableName, $definition)
}
if ($changed == true) {
if ($tableIndex->getName() == 'PRIMARY') {
self::$_connection->dropPrimaryKey($tableName, $tableColumn->getSchemaName());
self::$_connection->dropPrimaryKey($tableName, $tableSchema);
self::$_connection->addPrimaryKey(
$tableName,
$tableColumn->getSchemaName(),
$tableSchema,
$tableIndex
);
} else {
self::$_connection->dropIndex(
$tableName,
$tableColumn->getSchemaName(),
$tableSchema,
$tableIndex->getName()
);
self::$_connection->addIndex($tableName, $tableColumn->getSchemaName(), $tableIndex);
self::$_connection->addIndex($tableName, $tableSchema, $tableIndex);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/Phalcon/Mvc/View/NotFoundListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
/**
* \Phalcon\Mvc\View\NotFoundListener
*
* @property \Phalcon\Logger\AdapterInterface logger
* @property \Phalcon\Logger\AdapterInterface $logger
*
* @package Phalcon\Mvc\View
*/
Expand Down
1 change: 1 addition & 0 deletions scripts/Phalcon/Utils/SystemInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* \Phalcon\Utils\SystemInfo
*
* @property \Phalcon\Registry $registry
* @property \Phalcon\Mvc\Url|\Phalcon\Mvc\UrlInterface $url
*
* @package Phalcon\Utils
*/
Expand Down
5 changes: 2 additions & 3 deletions scripts/Phalcon/Version/ItemCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,10 @@ public static function setType($type)
* Create new version item
*
* @param null|string $version
* @param array $options
*
* @return ItemInterface
*/
public static function createItem($version = null, array $options = [])
public static function createItem($version = null)
{
if (self::TYPE_INCREMENTAL === self::$type) {
$version = $version ?: '0.0.0';
Expand All @@ -77,7 +76,7 @@ public static function createItem($version = null, array $options = [])
} elseif (self::TYPE_TIMESTAMPED === self::$type) {
$version = $version ?: '0000000_0';

return new TimestampedItem($version, $options);
return new TimestampedItem($version);
}

throw new \LogicException('Could not create an item of unknown type.');
Expand Down
3 changes: 1 addition & 2 deletions scripts/Phalcon/Version/TimestampedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ class TimestampedItem implements ItemInterface

/**
* @param string $version String representation of the version
* @param array $options Item specific options
*
* @throws \InvalidArgumentException
*/
public function __construct($version, array $options = [])
public function __construct($version)
{
if ((1 !== preg_match('#^[\d]{7,}(?:\_[a-z0-9]+)*$#', $version)) && $version != '000') {
throw new \InvalidArgumentException('Wrong version number provided');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
/**
* \WebTools\Controllers\ControllersController
*
* @property \Phalcon\Flash\Direct $flash
* @property \Phalcon\Mvc\Dispatcher|\Phalcon\Mvc\DispatcherInterface $dispatcher
* @property \Phalcon\Tag $tag
* @property \Phalcon\Flash\Session $flashSession
*
* @package WebTools\Controllers
*/
class ControllersController extends Base
Expand Down
Loading

0 comments on commit 018605a

Please sign in to comment.