Skip to content

Commit

Permalink
Merge pull request #2018 from phalcon/development
Browse files Browse the repository at this point in the history
0.12.12
  • Loading branch information
sergeyklay authored Nov 25, 2019
2 parents 8b9430c + c8bf7e1 commit 1094502
Show file tree
Hide file tree
Showing 28 changed files with 1,172 additions and 163 deletions.
3 changes: 3 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ return PhpCsFixer\Config::create()
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit48Migration:risky' => true,
'@PSR2' => true,
'php_unit_no_expectation_annotation' => false,
'array_syntax' => ['syntax' => 'short'],
'fopen_flags' => false,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'protected_to_private' => false,
'phpdoc_var_annotation_correct_order' => true,
'no_superfluous_phpdoc_tags' => false,
'single_line_throw' => false,
]);
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ install:
# Prepare Zephir executable
if [ "$BUILD_PHAR" -eq 1 ]
then
echo "Build Zephit PHAR"
echo "Build Zephir PHAR"
.ci/build-phar.sh
sudo ln -s "$(pwd)/zephir.phar" /usr/local/bin/zephir
else
Expand Down Expand Up @@ -184,8 +184,8 @@ script:

# Static Code Analysis
- phpenv config-rm xdebug.ini || true
- if [ "$BUILD_TYPE" == "analysis" ]; then phpcs; fi
- if [ "$BUILD_TYPE" == "analysis" ]; then php-cs-fixer fix --diff --dry-run -v; fi
- if [ "$BUILD_TYPE" == "analysis" ]; then phpcs --version; phpcs; fi
- if [ "$BUILD_TYPE" == "analysis" ]; then php-cs-fixer --version; php-cs-fixer fix --diff --dry-run -v; fi
- if [ "$BUILD_TYPE" == "analysis" ]; then shellcheck .ci/*.sh; fi

after_script:
Expand Down
23 changes: 22 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
## [0.12.12] - 2019-11-25
### Added
- Option to set banner for stubs generator
[#1987](https://github.com/phalcon/zephir/1987)

### Fixed
- Calling object methods from static context yields segmentation fault when
`internal-call-transformation` is set to `TRUE`
[#2000](https://github.com/phalcon/zephir/issues/2000)
- Certain method calls fail when called from static context when
`internal-call-transformation` is set to `TRUE`
[#2005](https://github.com/phalcon/zephir/issues/2005)
- Method context loses track of `this` after calling static method when
`internal-call-transformation` is set to `TRUE`
[#2007](https://github.com/phalcon/zephir/issues/2007)
- Fixed incorrect stubs generation for return type hint
[#1990](https://github.com/phalcon/zephir/issues/1990)
- Fixed incorrect stubs generation for classes in the same namespace
[#2016](https://github.com/phalcon/zephir/issues/2016)

## [0.12.11] - 2019-11-02
### Fixed
- Fixed arithmetical operations with `zvals` which stores `double` numbers
Expand Down Expand Up @@ -319,7 +339,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fixed casting resource to int (only ZendEngine 3)
[#1524](https://github.com/phalcon/zephir/issues/1524)

[Unreleased]: https://github.com/phalcon/zephir/compare/0.12.11...HEAD
[Unreleased]: https://github.com/phalcon/zephir/compare/0.12.12...HEAD
[0.12.12]: https://github.com/phalcon/zephir/compare/0.12.11...0.12.12
[0.12.11]: https://github.com/phalcon/zephir/compare/0.12.10...0.12.11
[0.12.10]: https://github.com/phalcon/zephir/compare/0.12.9...0.12.10
[0.12.9]: https://github.com/phalcon/zephir/compare/0.12.8...0.12.9
Expand Down
5 changes: 4 additions & 1 deletion Library/AliasManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public function isAliasPresentFor(string $className): bool
{
$extractAlias = $this->implicitAlias($className);

return !isset($this->aliases[$extractAlias]);
$isClassDeclarated = \in_array($className, $this->aliases);
$classAlias = array_flip($this->aliases)[$className] ?? null;

return $isClassDeclarated && $classAlias !== $extractAlias;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions Library/Backends/ZendEngine3/FcallManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ public function genFcallCode()
}

$codePrinter->output('ZEPHIR_BACKUP_SCOPE(); \\');
$codePrinter->output('ZEPHIR_BACKUP_THIS_PTR(); \\');
if (!$scope) {
$codePrinter->output('ZEPHIR_SET_THIS(object); \\');
$codePrinter->output('ZEPHIR_SET_SCOPE((Z_OBJ_P(object) ? Z_OBJCE_P(object) : NULL), (Z_OBJ_P(object) ? Z_OBJCE_P(object) : NULL)); \\');
Expand Down Expand Up @@ -156,7 +155,6 @@ public function genFcallCode()
}

$codePrinter->output('ZEPHIR_LAST_CALL_STATUS = EG(exception) ? FAILURE : SUCCESS; \\');
$codePrinter->output('ZEPHIR_RESTORE_THIS_PTR(); \\');

$codePrinter->output('ZEPHIR_RESTORE_SCOPE(); \\');
$codePrinter->decreaseLevel();
Expand Down
3 changes: 2 additions & 1 deletion Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,8 @@ public function stubs(bool $fromGenerate = false)
$stubsGenerator->generate(
$this->config->get('namespace'),
$path,
$this->config->get('indent', 'extra')
$this->config->get('indent', 'extra'),
$this->config->getBanner()
);
}

Expand Down
10 changes: 3 additions & 7 deletions Library/CompilerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -849,13 +849,6 @@ public function compile(Compiler $compiler, StringsManager $stringsManager)
foreach ($this->ir as $topStatement) {
switch ($topStatement['type']) {
case 'class':
if ($interface || $class) {
throw new CompilerException('More than one class defined in the same file', $topStatement);
}
$class = true;
$this->compileClass($compilationContext, $this->namespace, $topStatement);
break;

case 'interface':
if ($interface || $class) {
throw new CompilerException('More than one class defined in the same file', $topStatement);
Expand All @@ -867,6 +860,9 @@ public function compile(Compiler $compiler, StringsManager $stringsManager)
case 'comment':
$this->compileComment($compilationContext, $topStatement);
break;

default:
break;
}
}

Expand Down
11 changes: 11 additions & 0 deletions Library/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Config implements \ArrayAccess, \JsonSerializable
'stubs' => [
'path' => 'ide/%version%/%namespace%/',
'stubs-run-after-generate' => false,
'banner' => '',
],
'api' => [
'path' => 'doc/%version%',
Expand Down Expand Up @@ -328,6 +329,16 @@ public function jsonSerialize()
return $this->container;
}

/**
* Returns banner from configuration file.
*
* @return string
*/
public function getBanner(): string
{
return $this->get('banner', 'stubs') ?? '';
}

/**
* Populate project configuration.
*
Expand Down
3 changes: 2 additions & 1 deletion Library/Console/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io = new SymfonyStyle($input, $output);

if (\extension_loaded('timecop') && 1 == ini_get('timecop.func_override')) {
$io->getErrorStyle()->warning(<<<MSG
$io->getErrorStyle()->warning(
<<<MSG
The timecop extension was detected. It is recommended to disable
it from the launcher during the code generation to avoid potential
issues.
Expand Down
1 change: 0 additions & 1 deletion Library/Documentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ private function prepareThemeOptions($themeConfig, $options = null)
* => check if the command line argument --output-directory was given
* => if not ; check if config config[api][path] was given
*
*
* @param string $outputDir
*
* @return string|null
Expand Down
13 changes: 8 additions & 5 deletions Library/Stubs/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ public function __construct(array $files)
* @param string $namespace
* @param string $path
* @param string $indent
* @param string $banner
*
* @throws Exception\LogicException
*/
public function generate(string $namespace, string $path, string $indent)
public function generate(string $namespace, string $path, string $indent, string $banner)
{
if (empty($path)) {
throw new Exception\LogicException(
Expand All @@ -69,13 +70,13 @@ public function generate(string $namespace, string $path, string $indent)

foreach ($this->files as $file) {
$class = $file->getClassDefinition();
$source = $this->buildClass($class, $indent);
$source = $this->buildClass($class, $indent, $banner);

$filename = ucfirst($class->getName()).'.zep.php';
$filePath = $path.str_replace(
$filePath = $path.str_ireplace(
$namespace,
'',
str_replace($namespace.'\\\\', \DIRECTORY_SEPARATOR, strtolower($class->getNamespace()))
str_replace($namespace.'\\\\', \DIRECTORY_SEPARATOR, $class->getNamespace())
);
$filePath = str_replace('\\', \DIRECTORY_SEPARATOR, $filePath);
$filePath = str_replace(\DIRECTORY_SEPARATOR.\DIRECTORY_SEPARATOR, \DIRECTORY_SEPARATOR, $filePath);
Expand All @@ -94,14 +95,16 @@ public function generate(string $namespace, string $path, string $indent)
*
* @param ClassDefinition $class
* @param string $indent
* @param string $banner
*
* @throws Exception\RuntimeException
*
* @return string
*/
protected function buildClass(ClassDefinition $class, string $indent): string
protected function buildClass(ClassDefinition $class, string $indent, string $banner): string
{
$source = '<?php'.PHP_EOL.PHP_EOL;
$source .= '' === $banner ? '' : $banner.PHP_EOL;
$source .= "namespace {$class->getNamespace()};".PHP_EOL;

/** @var Zephir\AliasManager $aliasManager */
Expand Down
15 changes: 12 additions & 3 deletions Library/Stubs/MethodDocBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Zephir\AliasManager;
use Zephir\ClassMethod;
use Zephir\Types;

/**
* Stubs Generator.
Expand Down Expand Up @@ -40,14 +41,18 @@ class MethodDocBlock extends DocBlock
/** @var ClassMethod */
private $classMethod;

public function __construct(ClassMethod $method, AliasManager $aliasManager, $indent = ' ')
/** @var Types */
private $types;

public function __construct(ClassMethod $method, AliasManager $aliasManager, $indent = ' ', Types $types = null)
{
parent::__construct($method->getDocBlock(), $indent);

$this->deprecated = $method->isDeprecated();
$this->aliasManager = $aliasManager;
$this->shortcutName = $method->isShortcut() ? $method->getShortcutName() : '';
$this->classMethod = $method;
$this->types = $types ?? new Types();
}

/**
Expand Down Expand Up @@ -114,8 +119,12 @@ protected function parseMethodReturnType(ClassMethod $method)
}
}

if (!empty($return)) {
$this->return = [implode('|', $return), ''];
$processedTypes = !empty($method->getReturnClassTypes()) ? $return : null;
$returnType = $this->types->getReturnTypeAnnotation($this->classMethod, $processedTypes);

if (!empty($returnType)) {
// Empty line in array - it's an empty description. Don't remove it!
$this->return = [$returnType, ''];
}
}

Expand Down
Loading

0 comments on commit 1094502

Please sign in to comment.