Skip to content

Commit

Permalink
Merge pull request phalcon#1120 from phalcon/3.2.x
Browse files Browse the repository at this point in the history
3.2.6
  • Loading branch information
sergeyklay authored Oct 8, 2017
2 parents 3088ebf + a3c5a12 commit b62a35e
Show file tree
Hide file tree
Showing 24 changed files with 1,260 additions and 123 deletions.
4 changes: 2 additions & 2 deletions scripts/Phalcon/Builder/Scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ private function _captureFilterInput($var, $fields, $useGetSetters, $identityFie

$code .= '$' . Utils::lowerCamelizeWithDelimiter($var, '-', true) . '->';
if ($useGetSetters) {
$code .= 'set' . Text::camelize($field) . '(' . $fieldCode . ')';
$code .= 'set' . Utils::lowerCamelizeWithDelimiter($field, '_', true) . '(' . $fieldCode . ')';
} else {
$code .= Text::camelize($field, '-') . ' = ' . $fieldCode;
$code .= Utils::lowerCamelizeWithDelimiter($field, '-_', true) . ' = ' . $fieldCode;
}

$code .= ';' . PHP_EOL . "\t\t";
Expand Down
21 changes: 11 additions & 10 deletions scripts/Phalcon/Commands/Builtin/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
+------------------------------------------------------------------------+
| Phalcon Developer Tools |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
Expand Down Expand Up @@ -47,13 +47,15 @@ public function getPossibleParams()
'config=s' => 'Configuration file',
'migrations=s' => 'Migrations directory',
'directory=s' => 'Directory where the project was created',
'table=s' => 'Table to migrate. Default: all',
'table=s' => 'Table to migrate. Table name or table prefix with asterisk. Default: all',
'version=s' => 'Version to migrate',
'descr=s' => 'Migration description (used for timestamp based migration)',
'data=s' => 'Export data [always|oncreate] (Import data when run migration)',
'force' => 'Forces to overwrite existing migrations',
'ts-based' => 'Timestamp based migration version',
'log-in-db' => 'Keep migrations log in the database table rather than in file',
'dry' => 'Attempt requested operation without making changes to system (Generating only)',
'verbose' => 'Output of debugging information during operation (Running only)',
'no-auto-increment' => 'Disable auto increment (Generating only)',
'help' => 'Shows this help [optional]',
];
Expand Down Expand Up @@ -111,23 +113,21 @@ public function run(array $parameters)
}

$tableName = $this->isReceivedOption('table') ? $this->getOption('table') : '@';
$descr = $this->getOption('descr');
$exportData = $this->getOption('data');
$action = $this->getOption(['action', 1]);
$version = $this->getOption('version');

switch ($action) {
case 'generate':
Migrations::generate([
'directory' => $path,
'tableName' => $tableName,
'exportData' => $exportData,
'exportData' => $this->getOption('data'),
'migrationsDir' => $migrationsDir,
'version' => $version,
'version' => $this->getOption('version'),
'force' => $this->isReceivedOption('force'),
'noAutoIncrement' => $this->isReceivedOption('no-auto-increment'),
'config' => $config,
'descr' => $descr,
'descr' => $this->getOption('descr'),
'verbose' => $this->isReceivedOption('dry'),
]);
break;
case 'run':
Expand All @@ -138,8 +138,9 @@ public function run(array $parameters)
'force' => $this->isReceivedOption('force'),
'tsBased' => $migrationsTsBased,
'config' => $config,
'version' => $version,
'version' => $this->getOption('version'),
'migrationsInDb' => $migrationsInDb,
'verbose' => $this->isReceivedOption('verbose'),
]);
break;
case 'list':
Expand All @@ -150,7 +151,7 @@ public function run(array $parameters)
'force' => $this->isReceivedOption('force'),
'tsBased' => $migrationsTsBased,
'config' => $config,
'version' => $version,
'version' => $this->getOption('version'),
'migrationsInDb' => $migrationsInDb,
]);
break;
Expand Down
4 changes: 2 additions & 2 deletions scripts/Phalcon/Commands/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
+------------------------------------------------------------------------+
| Phalcon Developer Tools |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
Expand Down Expand Up @@ -135,7 +135,7 @@ protected function getConfig($path)
{
foreach (['app/config/', 'config/'] as $configPath) {
foreach (['ini', 'php', 'json', 'yaml', 'yml'] as $extension) {
if (file_exists($path . $configPath . "/config." . $extension)) {
if (file_exists($path . $configPath . "config." . $extension)) {
return $this->loadConfig($path . $configPath . "/config." . $extension);
}
}
Expand Down
1 change: 1 addition & 0 deletions scripts/Phalcon/Commands/CommandsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function beforeCommand(Event $event, Command $command)

if ($command->canBeExternal() == false) {
$path = $command->getOption('directory');
if ($path) $path = realpath($path) . DIRECTORY_SEPARATOR;
if (!file_exists($path.'.phalcon') || !is_dir($path.'.phalcon')) {
throw new DotPhalconMissingException();
}
Expand Down
49 changes: 49 additions & 0 deletions scripts/Phalcon/Console/OptionParserTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Developer Tools |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Sergii Svyrydenko <[email protected]> |
+------------------------------------------------------------------------+
*/

namespace Phalcon\Console;

/**
* \Phalcon\Utils\OptionParserTrait
*
* Parsing CLI options
*
* @package Phalcon\Utils
* @copyright Copyright (c) 2011-2017 Phalcon Team ([email protected])
* @license New BSD License
*/
trait OptionParserTrait
{
/**
* Get prefix from the option
*
* @param string $prefix
* @param mixed $prefixEnd
*
* @return mixed
*/
public function getPrefixOption($prefix, $prefixEnd = '*')
{
if (substr($prefix, -1) != $prefixEnd) {
return '';
}

return substr($prefix, 0, -1);
}
}
146 changes: 146 additions & 0 deletions scripts/Phalcon/Console/OptionStack.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Developer Tools |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Sergii Svyrydenko <[email protected]> |
+------------------------------------------------------------------------+
*/

namespace Phalcon\Console;

use Phalcon\Console\OptionParserTrait;

/**
* Phalcon\Console\OptionStack
*
* CLI options
*
* @package Phalcon\Console;
* @copyright Copyright (c) 2011-2017 Phalcon Team ([email protected])
* @license New BSD License
*/
class OptionStack
{
use OptionParserTrait;

/**
* Parameters received by the script.
* @var array
*/
protected $options = [];

/**
* Set recieved options
*
* @param array $options
*/
public function setOptions(array $options)
{
$this->options = array_merge($this->options, $options);
}

/**
* Add option to array
*
* @param mixed $key
* @param mixed $option
* @param mixed $defaultValue
*/
public function setOption($key, $option, $defaultValue = '')
{
if (!empty($option)) {
$this->options[$key] = $option;

return;
}

$this->options[$key] = $defaultValue;
}

/**
* Set option if value isn't exist
*
* @param string $key
* @param mixed $defaultValue
*/
public function setDefaultOption($key, $defaultValue)
{
if (!isset($this->options[$key])) {
$this->options[$key] = $defaultValue;
}
}

/**
* Get recieved options
*
* @return mixed
*/
public function getOptions()
{
return $this->options;
}

/**
* Get option
* @param string $key
*
* @return mixed
*/
public function getOption($key)
{
if (!isset($this->options[$key])) {
return '';
}

return $this->options[$key];
}

/**
* Get option if existence or get default option
*
* @param string $key
* @param mixed $defaultOption
*
* @return mixed
*/
public function getValidOption($key, $defaultOption = '')
{
if (isset($this->options[$key])) {
return $this->options[$key];
}

return $defaultOption;
}

/**
* Count options
*
* @return integer
*/
public function countOptions()
{
return count($this->options);
}

/**
* Indicates whether the script was a particular option.
*
* @param string $key
* @return boolean
*/
public function isReceivedOption($key)
{
return isset($this->options[$key]);
}
}
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, 3, 4, 1];
return [3, 2, 5, 4, 0];
}
}
52 changes: 52 additions & 0 deletions scripts/Phalcon/Listeners/DbProfilerListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
+------------------------------------------------------------------------+
| Phalcon Developer Tools |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2017 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Sergii Svyrydenko <[email protected]> |
+------------------------------------------------------------------------+
*/

namespace Phalcon\Listeners;

use Phalcon\Mvc\Model\Migration\Profiler;
use Phalcon\Events\Event;

/**
* Phalcon\Listeners\DbProfilerListener
*
* Db event listener
*
* @package Phalcon\Listeners
*/
class DbProfilerListener
{
protected $_profiler;

public function __construct()
{
$this->_profiler = new Profiler();
}

public function beforeQuery(Event $event, $connection)
{
$this->_profiler->startProfile(
$connection->getSQLStatement()
);
}

public function afterQuery()
{
$this->_profiler->stopProfile();
}
}
Loading

0 comments on commit b62a35e

Please sign in to comment.