Skip to content

Commit

Permalink
Merge pull request #1308 from phalcon/3.4.x
Browse files Browse the repository at this point in the history
3.4.2
  • Loading branch information
Jeckerson authored Jun 28, 2019
2 parents 5ec8a37 + 83a4ad9 commit ee13e2c
Show file tree
Hide file tree
Showing 29 changed files with 452 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install:
- if [ "$PHP_MAJOR" == "7" ]; then composer require --dev phpstan/phpstan:^0.9; fi;

before_script:
- ln -s $PWD/phalcon.php ~/bin/phalcon
- ln -s $PWD/phalcon ~/bin/phalcon

script:
- vendor/bin/phpcs
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ cd phalcon-devtools
```

This method requires a little bit more of setup. Probably the best way would be to symlink
the `phalcon.php` to a directory in your `PATH`, so you can issue phalcon commands in each directory
the `phalcon` file to a directory in your `PATH`, so you can issue phalcon commands in each directory
where a phalcon project resides.

```bash
cd phalcon-devtools
ln -s $(pwd)/phalcon.php /usr/bin/phalcon
ln -s $(pwd)/phalcon /usr/bin/phalcon
chmod ugo+x /usr/bin/phalcon
```

If you get a `"phalcon: command not found"` message while creating the symlink, make an alias.

```bash
alias phalcon=/home/[USERNAME]/phalcon-devtools/phalcon.php
alias phalcon=/home/[USERNAME]/phalcon-devtools/phalcon
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"main": "phalcon.php",
"main": "phalcon",
"output": "phalcon.phar",
"chmod": "0755",
"directories": [
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"forum": "https://forum.phalconphp.com/"
},
"require": {
"php": ">=5.5",
"php": ">=5.5 < 7.3.2 || >7.3.3",
"ext-phalcon": "~3.3",
"psy/psysh": "~0.9",
"nikic/php-parser": "^3.1"
Expand Down Expand Up @@ -52,5 +52,5 @@
"tests/_support/helpers.php"
]
},
"bin": ["phalcon.php"]
"bin": ["phalcon"]
}
33 changes: 28 additions & 5 deletions ide/gen-stubs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,44 @@
/**
* This scripts generates the stubs to be used on IDEs
*
* Change the CPHALCON_DIR constant to point to the dev/ directory in the Phalcon source code
* Specify CPHALCON_DIR env variable to point to the dev/ directory in the Phalcon source code
*
* php ide/gen-stubs.php
* *nix: CPHALCON_DIR=/path/to/cphalcon/ext/ php ide/gen-stubs.php
* Win: set CPHALCON_DIR=C:\Path\To\cphalcon\ext\ php ide/gen-stubs.php
*
* Alternative stubs generation
*
* cd cphalcon
* zephir stubs
*/

if (!extension_loaded('phalcon')) {
throw new Exception("phalcon extension isn't installed");
}

define('CPHALCON_DIR' , '/Users/micate/Code/cphalcon/ext/');
if (getenv('CPHALCON_DIR') === false) {
throw new Exception(<<<TEXT
Specify CPHALCON_DIR env variable
*nix: CPHALCON_DIR=/path/to/cphalcon/ext/ php ide/gen-stubs.php
Win: set CPHALCON_DIR=C:\Path\To\cphalcon\ext\ php ide/gen-stubs.php
if (!file_exists(CPHALCON_DIR)) {
TEXT
);
}

if (!file_exists(getenv('CPHALCON_DIR'))) {
throw new Exception("CPHALCON directory does not exist");
}

/**
* Class Stubs_Generator
*
* @deprecated In version 4.x current class will be removed
*/
class Stubs_Generator
{

Expand Down Expand Up @@ -123,7 +146,7 @@ public function getClassDocs()
$versionPieces = explode(' ', $version);
$genVersion = $versionPieces[0];

$api = new Stubs_Generator(CPHALCON_DIR);
$api = new Stubs_Generator(getenv('CPHALCON_DIR'));

$classDocs = $api->getClassDocs();
$docs = $api->getDocs();
Expand Down
2 changes: 1 addition & 1 deletion ide/phpstorm/phalcon.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off

set PTOOLSPATH=.
php %PTOOLSPATH%\phalcon.php %*
php %PTOOLSPATH%\phalcon %*
2 changes: 1 addition & 1 deletion ide/phpstorm/phalcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ if [ -z "$PTOOLSPATH" ]; then
fi

if [ ! -z "$PTOOLSPATH" ]; then
php "$PTOOLSPATH/phalcon.php" $*
php "$PTOOLSPATH/phalcon" $*
else
if [ -n "$ZSH_VERSION" ]; then
echo "Error: Add environment variable PTOOLSPATH to your $HOME/.zsh"
Expand Down
File renamed without changes.
4 changes: 0 additions & 4 deletions phalcon.bat

This file was deleted.

4 changes: 2 additions & 2 deletions phalcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ check_install(){
if [ -z "$PTOOLSPATH" ]; then
printf "\n${YELLOW}Phalcon Developer Tools Installer${NC}"
printf "\n"
printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon.php${NC}"
printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon file${NC}"
printf "\n${PURPLE}and that you are running this with sudo or as root.${NC}"
printf "\n"
printf "\nInstalling Devtools..."
Expand Down Expand Up @@ -147,5 +147,5 @@ init

if check_install; then
devtools=${PTOOLSPATH%/}
php "$devtools/phalcon.php" $*
php "$devtools/phalcon" $*
fi
26 changes: 25 additions & 1 deletion resources/elements/sidebar-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
// Phalcon Docs
[
'link' => [
'href' => 'https://docs.phalconphp.com/en/3.2',
'href' => 'https://phalcon.link/docs',
'icon' => 'fa fa-book',
'local' => false,
'target' => '_blank',
Expand Down Expand Up @@ -224,5 +224,29 @@
'wrap' => 'span',
],
],

// Phalcon Official Forum
[
'link' => [
'href' => 'https://phalcon.link/forum',
'icon' => 'fa fa-comment-o',
'local' => false,
'target' => '_blank',
'text' => 'Phalcon Forum',
'wrap' => 'span',
],
],

// Phalcon Discord Server
[
'link' => [
'href' => 'https://phalcon.link/discord',
'icon' => 'fa fa-comments',
'local' => false,
'target' => '_blank',
'text' => 'Discord Server',
'wrap' => 'span',
]
]
],
];
4 changes: 3 additions & 1 deletion scripts/Phalcon/Builder/AllModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ public function build()
$modelBuilder = new Model([
'name' => $name,
'config' => $config,
'schema' => $schema,
// We need to pass schema exactly as set in argv or config to Model
// get disallows empty values, so we need to access raw options
'schema' => isset($this->options->schema) ? $this->options->schema : null,
'extends' => $this->options->get('extends'),
'namespace' => $this->options->get('namespace'),
'force' => $forceProcess,
Expand Down
60 changes: 49 additions & 11 deletions scripts/Phalcon/Builder/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,48 @@ public function __construct(array $options)
$this->modelOptions->setOption('snippet', new Snippet());
}

/**
* @return ModelOption
*/
public function getModelOptions()
{
return $this->modelOptions;
}

/**
* We should expect schema to be string|null
* OptionsAware throws when getting null option values
* so we need to handle shouldInitSchema logic with the raw $option array
*
* Should setSchema in initialize() only if:
* - $option['schema'] !== ''
*
* @return bool
*/
public function shouldInitSchema()
{
return !isset($this->modelOptions->getOptions()['schema'])
|| $this->modelOptions->getOptions()['schema'] !== '';
}

/**
* @return string
*/
public function getSchema()
{
if ($this->modelOptions->hasOption('schema') && !empty($this->modelOptions->getOption('schema'))) {
$schema = $this->modelOptions->getOption('schema');
} else {
$schema = Utils::resolveDbSchema($this->modelOptions->getOption('config')->database);
}

if (!empty($schema)) {
return $schema;
}

throw new RuntimeException('Cannot find valid schema. Set schema argument or set in config.');
}

/**
* Module build
*
Expand All @@ -102,6 +144,7 @@ public function build()
{
$config = $this->modelOptions->getOption('config');
$snippet = $this->modelOptions->getOption('snippet');
$schema = $this->getSchema();

if ($this->modelOptions->hasOption('directory')) {
$this->path->setRootPath($this->modelOptions->getOption('directory'));
Expand Down Expand Up @@ -153,15 +196,10 @@ public function build()

$initialize = [];

if ($this->modelOptions->hasOption('schema')) {
$schema = $this->modelOptions->getOption('schema');
} else {
$schema = Utils::resolveDbSchema($config->database);
}

if ($schema) {
if ($this->shouldInitSchema()) {
$initialize['schema'] = $snippet->getThisMethod('setSchema', $schema);
}

$initialize['source'] = $snippet->getThisMethod('setSource', $this->modelOptions->getOption('name'));

$table = $this->modelOptions->getOption('name');
Expand All @@ -180,7 +218,7 @@ public function build()
}

$entityNamespace = '';
if ($this->modelOptions->getOption('namespace')) {
if ($this->modelOptions->hasOption('namespace')) {
$entityNamespace = $this->modelOptions->getOption('namespace')."\\";
}

Expand All @@ -198,16 +236,16 @@ public function build()

foreach ($db->describeReferences($this->modelOptions->getOption('name'), $schema) as $reference) {
$entityNamespace = '';
if ($this->modelOptions->getOption('namespace')) {
$entityNamespace = $this->modelOptions->getOption('namespace');
if ($this->modelOptions->hasOption('namespace')) {
$entityNamespace = $this->modelOptions->getOption('namespace')."\\";
}

$refColumns = $reference->getReferencedColumns();
$columns = $reference->getColumns();
$initialize[] = $snippet->getRelation(
'belongsTo',
$this->modelOptions->getOption('camelize') ? Utils::lowerCamelize($columns[0]) : $columns[0],
$this->getEntityClassName($reference, $entityNamespace),
$entityNamespace . Utils::camelize($reference->getReferencedTable()),
$this->modelOptions->getOption('camelize') ? Utils::lowerCamelize($refColumns[0]) : $refColumns[0],
"['alias' => '" . Text::camelize($reference->getReferencedTable(), '_-') . "']"
);
Expand Down
6 changes: 3 additions & 3 deletions scripts/Phalcon/Builder/Scaffold.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private function captureFilterInput($var, $fields, $useGetSetters, $identityFiel

$code .= '$' . Utils::lowerCamelizeWithDelimiter($var, '-', true) . '->';
if ($useGetSetters) {
$code .= 'set' . Utils::lowerCamelizeWithDelimiter($field, '_', true) . '(' . $fieldCode . ')';
$code .= 'set' . Utils::lowerCamelizeWithDelimiter($field, '_') . '(' . $fieldCode . ')';
} else {
$code .= Utils::lowerCamelizeWithDelimiter($field, '-_', true) . ' = ' . $fieldCode;
}
Expand Down Expand Up @@ -602,7 +602,7 @@ private function makeLayouts()
$code .= '<?php $this->tag->stylesheetLink("themes/base") ?>'.PHP_EOL;
$code .= '<div class="ui-layout" align="center">' . PHP_EOL;
} else {
$code .= '<div class="row center-block">' . PHP_EOL;
$code .= '<div class="center-block">' . PHP_EOL;
}
$code .= "\t" . '<?php echo $this->getContent(); ?>' . PHP_EOL . '</div>';

Expand Down Expand Up @@ -642,7 +642,7 @@ private function makeLayoutsVolt()
$code .= '{{ stylesheet_link("themes/base") }}'.PHP_EOL;
$code .= '<div class="ui-layout" align="center">' . PHP_EOL;
} else {
$code .= '<div class="row center-block">' . PHP_EOL;
$code .= '<div class="center-block">' . PHP_EOL;
}

$code .= "\t" . '{{ content() }}' . PHP_EOL . '</div>';
Expand Down
14 changes: 12 additions & 2 deletions scripts/Phalcon/Commands/Builtin/Migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function getPossibleParams()
'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)',
'exportDataFromTables=s' => 'Export data from specific tables, use comma separated string.',
'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',
Expand Down Expand Up @@ -79,6 +80,16 @@ public function run(array $parameters)
$config = $this->getConfig($path);
}

$exportDataFromTables = [];
if ($this->isReceivedOption('exportDataFromTables')) {
$exportDataFromTables = explode(',', $this->getOption('exportDataFromTables'));
} elseif (isset($config['application']['exportDataFromTables'])) {
if ($config['application']['exportDataFromTables'] instanceof Config) {
$exportDataFromTables = $config['application']['exportDataFromTables']->toArray();
} else {
$exportDataFromTables = explode(',', $config['application']['exportDataFromTables']);
}
}

//multiple dir
$migrationsDir = [];
Expand All @@ -88,7 +99,6 @@ public function run(array $parameters)
$migrationsDir = explode(',', $config['application']['migrationsDir']);
}


if (!empty($migrationsDir)) {
foreach ($migrationsDir as $id => $dir) {
if (!$this->path->isAbsolutePath($dir)) {
Expand All @@ -103,7 +113,6 @@ public function run(array $parameters)
$migrationsDir[] = $path . 'migrations';
}


// keep migrations log in db
// either "log-in-db" option or "logInDb" config variable from "application" block
$migrationsInDb = false;
Expand Down Expand Up @@ -131,6 +140,7 @@ public function run(array $parameters)
'directory' => $path,
'tableName' => $tableName,
'exportData' => $this->getOption('data'),
'exportDataFromTables' => $exportDataFromTables,
'migrationsDir' => $migrationsDir,
'version' => $this->getOption('version'),
'force' => $this->isReceivedOption('force'),
Expand Down
Loading

0 comments on commit ee13e2c

Please sign in to comment.