diff --git a/CHANGELOG.md b/CHANGELOG.md index fef2a5bff..d9db343b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org). ## [Unreleased] +## [0.15.2] - 2021-10-24 +### Fixed +- Fixed output of `string` type INI in globals [#2312](https://github.com/zephir-lang/zephir/issues/2312) + ## [0.15.1] - 2021-10-08 ### Fixed -- Fix support of `string` type in struct globals [#2308](https://github.com/zephir-lang/zephir/issues/2308) +- Fixed support of `string` type in struct globals [#2308](https://github.com/zephir-lang/zephir/issues/2308) ## [0.15.0] - 2021-10-05 ### Added @@ -557,7 +561,8 @@ and this project adheres to [Semantic Versioning](http://semver.org). [#1524](https://github.com/zephir-lang/zephir/issues/1524) -[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.15.1...HEAD +[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.15.2...HEAD +[0.15.2]: https://github.com/zephir-lang/zephir/compare/0.15.1...0.15.2 [0.15.1]: https://github.com/zephir-lang/zephir/compare/0.15.0...0.15.1 [0.15.0]: https://github.com/zephir-lang/zephir/compare/0.14.0...0.15.0 [0.14.0]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.3...0.14.0 diff --git a/Library/AliasManager.php b/Library/AliasManager.php index f500aa788..4d82afe66 100644 --- a/Library/AliasManager.php +++ b/Library/AliasManager.php @@ -1,7 +1,5 @@ implicitAlias($className); - $isClassDeclared = \in_array($className, $this->aliases); + $isClassDeclared = in_array($className, $this->aliases); $classAlias = array_flip($this->aliases)[$className] ?? null; return $isClassDeclared && $classAlias !== $extractAlias; diff --git a/Library/ArgInfoDefinition.php b/Library/ArgInfoDefinition.php index b11cf5488..153107481 100644 --- a/Library/ArgInfoDefinition.php +++ b/Library/ArgInfoDefinition.php @@ -56,8 +56,6 @@ class ArgInfoDefinition private bool $richFormat = true; /** - * ArgInfoDefinition constructor. - * * @param string $name * @param ClassMethod $functionLike * @param CodePrinter $codePrinter diff --git a/Library/BranchGraph.php b/Library/BranchGraph.php index d26ca4730..5c765f733 100644 --- a/Library/BranchGraph.php +++ b/Library/BranchGraph.php @@ -9,31 +9,27 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir; /** - * BranchGraph. - * * Represents a group of branch nodes */ class BranchGraph { - protected $root; + protected ?BranchGraphNode $root = null; - protected $branchMap; + protected array $branchMap = []; /** * Adds a leaf to the branch tree. * * @param Branch $branch */ - public function addLeaf(Branch $branch) + public function addLeaf(Branch $branch): void { - if (isset($this->branchMap[$branch->getUniqueId()])) { - $branchNode = $this->branchMap[$branch->getUniqueId()]; - } else { - $branchNode = new BranchGraphNode($branch); - } + $branchNode = $this->branchMap[$branch->getUniqueId()] ?? new BranchGraphNode($branch); $branchNode->increase(); $tempBranch = $branch->getParentBranch(); @@ -44,6 +40,7 @@ public function addLeaf(Branch $branch) $parentBranchNode = new BranchGraphNode($tempBranch); $this->branchMap[$tempBranch->getUniqueId()] = $parentBranchNode; } + $parentBranchNode->insert($branchNode); $branchNode = $parentBranchNode; $tempBranch = $tempBranch->getParentBranch(); @@ -58,7 +55,7 @@ public function addLeaf(Branch $branch) * * @return BranchGraphNode */ - public function getRoot() + public function getRoot(): BranchGraphNode { return $this->root; } diff --git a/Library/Code/Builder/Struct.php b/Library/Code/Builder/Struct.php index 86a8558f3..1d5c9472a 100644 --- a/Library/Code/Builder/Struct.php +++ b/Library/Code/Builder/Struct.php @@ -171,6 +171,17 @@ public function getInitEntry(string $name, array $global, string $namespace): st $namespace. '_globals, '. $namespace.'_globals)'; + + case 'string': + return sprintf( + 'STD_PHP_INI_ENTRY(%s, %s, %s, NULL, %s, %s, %s)', + '"'.$iniName.'"', + '"'.$global['default'].'"', + $scope, + $structName, + 'zend_'.$namespace.'_globals', + $namespace.'_globals', + ); } return ''; diff --git a/Library/CodePrinter.php b/Library/CodePrinter.php index efb7b2022..0c4aa3a25 100644 --- a/Library/CodePrinter.php +++ b/Library/CodePrinter.php @@ -14,8 +14,6 @@ namespace Zephir; /** - * CodePrinter. - * * Buffers code, making it look pretty */ class CodePrinter diff --git a/Library/Compiler.php b/Library/Compiler.php index ce760f4c3..74c744398 100644 --- a/Library/Compiler.php +++ b/Library/Compiler.php @@ -9,13 +9,19 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir; +use DirectoryIterator; use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; +use RecursiveDirectoryIterator; +use RecursiveIteratorIterator; use ReflectionException; use Zephir\Code\Builder\Struct; use Zephir\Compiler\CompilerFileFactory; +use Zephir\Compiler\FileInterface; use Zephir\Exception\CompilerException; use Zephir\Exception\IllegalStateException; use Zephir\Exception\InvalidArgumentException; @@ -27,9 +33,12 @@ use function count; use function dirname; +use function extension_loaded; use function is_array; use function is_string; +use const DIRECTORY_SEPARATOR; + final class Compiler { use LoggerAwareTrait; @@ -260,15 +269,14 @@ public function getParserManager(): Parser\Manager * Adds a function to the function definitions. * * @param FunctionDefinition $func - * @param array $statement + * @param array|null $statement * * @throws CompilerException */ - public function addFunction(FunctionDefinition $func, $statement = null) + public function addFunction(FunctionDefinition $func, array $statement = []) { $funcName = strtolower($func->getInternalName()); if (isset($this->functionDefinitions[$funcName])) { - // TODO: Cover by test throw new CompilerException( "Function '".$func->getCompleteName()."' was defined more than one time", $statement @@ -292,8 +300,7 @@ public function addFunction(FunctionDefinition $func, $statement = null) */ public function loadExternalClass(string $className, string $location): bool { - $filePath = $location.\DIRECTORY_SEPARATOR. - strtolower(str_replace('\\', \DIRECTORY_SEPARATOR, $className)).'.zep'; + $filePath = $location.DIRECTORY_SEPARATOR.strtolower(str_replace('\\', DIRECTORY_SEPARATOR, $className)).'.zep'; /** * Fix the class name. @@ -347,7 +354,7 @@ public function isClass(string $className): bool } /** - * Allows to check if an interface is part of the compiled extension. + * Allows checking if an interface is part of the compiled extension. * * @param string $className * @@ -378,7 +385,7 @@ public function isInterface(string $className): bool } /** - * Allows to check if a class is part of PHP. + * Allows checking if a class is part of PHP. * * @param string $className * @@ -390,7 +397,7 @@ public function isBundledClass(string $className): bool } /** - * Allows to check if a interface is part of PHP. + * Allows checking if an interface is part of PHP. * * @param string $className * @@ -566,24 +573,22 @@ public function preCompileHeaders() $phpIncludes = $this->getPhpIncludeDirs(); - foreach (new \DirectoryIterator('ext/kernel') as $file) { - if ($file->isDir()) { + /** @var DirectoryIterator $file */ + foreach (new DirectoryIterator('ext/kernel') as $file) { + if ($file->isDir() || $file->getExtension() !== 'h') { continue; } - if (preg_match('/\.h$/', $file)) { - $path = $file->getRealPath(); - - $command = sprintf( - 'cd ext && gcc -c kernel/%s -I. %s -o kernel/%s.gch', - $file->getBaseName(), - $phpIncludes, - $file->getBaseName() - ); + $command = sprintf( + 'cd ext && gcc -c kernel/%s -I. %s -o kernel/%s.gch', + $file->getBaseName(), + $phpIncludes, + $file->getBaseName() + ); - if (!file_exists($path.'.gch') || filemtime($path) > filemtime($path.'.gch')) { - $this->filesystem->system($command, 'stdout', 'compile-header'); - } + $path = $file->getRealPath(); + if (!file_exists($path.'.gch') || filemtime($path) > filemtime($path.'.gch')) { + $this->filesystem->system($command, 'stdout', 'compile-header'); } } } @@ -595,10 +600,8 @@ public function preCompileHeaders() * * @return bool * - * @throws CompilerException * @throws Exception - * @throws IllegalStateException - * @throws InvalidArgumentException + * @throws ReflectionException */ public function generate(bool $fromGenerate = false): bool { @@ -629,7 +632,7 @@ public function generate(bool $fromGenerate = false): bool /** * Round 1. pre-compile all files in memory */ - $this->recursivePreCompile(str_replace('\\', \DIRECTORY_SEPARATOR, $namespace)); + $this->recursivePreCompile(str_replace('\\', DIRECTORY_SEPARATOR, $namespace)); if (!count($this->files)) { throw new Exception( "Zephir files to compile couldn't be found. Did you add a first class to the extension?" @@ -695,7 +698,7 @@ public function generate(bool $fromGenerate = false): bool * Load additional extension prototypes. */ $prototypesPath = $this->resolvePrototypesPath(); - foreach (new \DirectoryIterator($prototypesPath) as $file) { + foreach (new DirectoryIterator($prototypesPath) as $file) { if ($file->isDir() || $file->isDot()) { continue; } @@ -704,7 +707,7 @@ public function generate(bool $fromGenerate = false): bool $realPath = "{$file->getPath()}/{$file->getFilename()}"; $extension = $file->getBasename(".{$file->getExtension()}"); - if (!\extension_loaded($extension)) { + if (!extension_loaded($extension)) { require_once $realPath; } } @@ -718,10 +721,10 @@ public function generate(bool $fromGenerate = false): bool /** * Check if the extension is installed */ - if (!\extension_loaded($prototype)) { + if (!extension_loaded($prototype)) { $prototypeRealpath = realpath($prototypeDir); if ($prototypeRealpath) { - foreach (new \RecursiveDirectoryIterator($prototypeRealpath) as $file) { + foreach (new RecursiveDirectoryIterator($prototypeRealpath) as $file) { if ($file->isDir()) { continue; } @@ -761,8 +764,7 @@ public function generate(bool $fromGenerate = false): bool $files[] = $compiledFile; - $hash .= '|'.$compiledFile.':'.$classDefinition->getClassEntry(). - '['.implode('|', $methods).']'; + $hash .= '|'.$compiledFile.':'.$classDefinition->getClassEntry().'['.implode('|', $methods).']'; } } @@ -821,6 +823,8 @@ public function generate(bool $fromGenerate = false): bool $needConfigure = $this->createConfigFiles($extensionName); $needConfigure |= $this->createProjectFiles($extensionName); $needConfigure |= $this->checkIfPhpized(); + // Bitwise returns `int` instead of `bool`. + $needConfigure = (bool) $needConfigure; /** * When a new file is added or removed we need to run configure again @@ -977,8 +981,9 @@ public function compile(bool $development = false, ?int $jobs = null): void * * @throws ConfigException * @throws Exception + * @throws ReflectionException */ - public function api(array $options = [], bool $fromGenerate = false) + public function api(array $options = [], bool $fromGenerate = false): void { if (!$fromGenerate) { $this->generate(); @@ -999,15 +1004,15 @@ public function api(array $options = [], bool $fromGenerate = false) * @param bool $fromGenerate * * @throws Exception + * @throws ReflectionException */ - public function stubs(bool $fromGenerate = false) + public function stubs(bool $fromGenerate = false): void { if (!$fromGenerate) { $this->generate(); } $this->logger->info('Generating stubs...'); - $stubsGenerator = new Stubs\Generator($this->files); $path = str_replace( [ @@ -1021,7 +1026,7 @@ public function stubs(bool $fromGenerate = false) $this->config->get('path', 'stubs') ); - $stubsGenerator->generate( + (new Stubs\Generator($this->files))->generate( $this->config->get('namespace'), $path, $this->config->get('indent', 'extra'), @@ -1082,14 +1087,15 @@ public function install(bool $development = false): void /** * Create config.m4 and config.w32 for the extension. * + * TODO: move this to backend? + * * @param string $project * - * @throws Exception + * @return bool true if we need to run configure * - * @return bool true if need to run configure - * TODO: move this to backend? + * @throws Exception */ - public function createConfigFiles($project) + public function createConfigFiles(string $project): bool { $contentM4 = $this->backend->getTemplateFileContents('config.m4'); if (empty($contentM4)) { @@ -1101,11 +1107,7 @@ public function createConfigFiles($project) throw new Exception("Template config.w32 doesn't exist"); } - if ('zend' == $project) { - $safeProject = 'zend_'; - } else { - $safeProject = $project; - } + $safeProject = 'zend' === $project ? 'zend_' : $project; $compiledFiles = array_map(function ($file) { return str_replace('.c', '.zep.c', $file); @@ -1126,8 +1128,8 @@ public function createConfigFiles($project) /** * Check extra-libs, extra-cflags, package-dependencies exists */ - $extraLibs = $this->config->get('extra-libs'); - $extraCflags = $this->config->get('extra-cflags'); + $extraLibs = (string) $this->config->get('extra-libs'); + $extraCflags = (string) $this->config->get('extra-cflags'); $contentM4 = $this->generatePackageDependenciesM4($contentM4); $buildDirs = []; @@ -1386,22 +1388,10 @@ public function processExtensionGlobals(string $namespace): array } $globalCode .= "\t".$type.' '.$name.';'.PHP_EOL; - $iniEntry = []; - if (isset($global['ini-entry'])) { - $iniEntry = $global['ini-entry']; - } - if (!isset($iniEntry['name'])) { - $iniName = $namespace.'.'.$name; - } else { - $iniName = $iniEntry['name']; - } - - if (!isset($iniEntry['scope'])) { - $scope = 'PHP_INI_ALL'; - } else { - $scope = $iniEntry['scope']; - } + $iniEntry = $global['ini-entry'] ?? []; + $iniName = $iniEntry['name'] ?? $namespace.'.'.$name; + $scope = $iniEntry['scope'] ?? 'PHP_INI_ALL'; switch ($global['type']) { case 'boolean': @@ -1420,6 +1410,18 @@ public function processExtensionGlobals(string $namespace): array '_globals, '. $namespace.'_globals)'; break; + + case 'string': + $initEntries[] = sprintf( + 'STD_PHP_INI_ENTRY(%s, %s, %s, NULL, %s, %s, %s)', + '"'.$iniName.'"', + '"'.$global['default'].'"', + $scope, + $name, + 'zend_'.$namespace.'_globals', + $namespace.'_globals', + ); + break; } } } @@ -1517,14 +1519,14 @@ public function addExternalDependency(string $namespace, string $location): void * @param CompilerFile[] $files * @param null $_dependency */ - public function calculateDependencies(array $files, $_dependency = null) + public function calculateDependencies(array $files, $_dependency = null): void { - /* + /** * Classes are ordered according to a dependency ranking * Classes with higher rank, need to be initialized first * We first build a dependency tree and then set the rank accordingly */ - if (null == $_dependency) { + if (null === $_dependency) { $dependencyTree = []; foreach ($files as $file) { if (!$file->isExternal()) { @@ -1534,7 +1536,7 @@ public function calculateDependencies(array $files, $_dependency = null) } // Make sure the dependencies are loaded first (recursively) - foreach ($dependencyTree as $className => $dependencies) { + foreach ($dependencyTree as $dependencies) { foreach ($dependencies as $dependency) { $dependency->increaseDependencyRank(0); $this->calculateDependencies($dependencyTree, $dependency); @@ -1560,11 +1562,11 @@ public function calculateDependencies(array $files, $_dependency = null) * * @param string $project * - * @throws Exception - * * @return bool + * + * @throws Exception */ - public function createProjectFiles($project) + public function createProjectFiles(string $project): bool { $needConfigure = $this->checkKernelFiles(); @@ -1586,7 +1588,7 @@ public function createProjectFiles($project) $glbDestructors = ''; $files = array_merge($this->files, $this->anonymousFiles); - /* + /** * Round 1. Calculate the dependency rank */ $this->calculateDependencies($files); @@ -1597,37 +1599,27 @@ public function createProjectFiles($project) $interfaceEntries = []; $interfaceInits = []; - /* + /** * Round 2. Generate the ZEPHIR_INIT calls according to the dependency rank */ + /** @var FileInterface $file */ foreach ($files as $file) { - /** @var \Zephir\Compiler\FileInterface $file */ - if (!$file->isExternal()) { - $classDefinition = $file->getClassDefinition(); - if ($classDefinition) { - $dependencyRank = $classDefinition->getDependencyRank(); - if ('class' == $classDefinition->getType()) { - if (!isset($classInits[$dependencyRank])) { - $classEntries[$dependencyRank] = []; - $classInits[$dependencyRank] = []; - } - $classEntries[$dependencyRank][] = - 'zend_class_entry *'.$classDefinition->getClassEntry().';'; - $classInits[$dependencyRank][] = - 'ZEPHIR_INIT('.$classDefinition->getCNamespace().'_'. - $classDefinition->getName().');'; - } else { - if (!isset($interfaceInits[$dependencyRank])) { - $interfaceEntries[$dependencyRank] = []; - $interfaceInits[$dependencyRank] = []; - } - $interfaceEntries[$dependencyRank][] = - 'zend_class_entry *'.$classDefinition->getClassEntry().';'; - $interfaceInits[$dependencyRank][] = - 'ZEPHIR_INIT('.$classDefinition->getCNamespace().'_'. - $classDefinition->getName().');'; - } - } + if ($file->isExternal()) { + continue; + } + + $classDefinition = $file->getClassDefinition(); + if ($classDefinition === null) { + continue; + } + + $dependencyRank = $classDefinition->getDependencyRank(); + if ('class' === $classDefinition->getType()) { + $classEntries[$dependencyRank][] = 'zend_class_entry *'.$classDefinition->getClassEntry().';'; + $classInits[$dependencyRank][] = 'ZEPHIR_INIT('.$classDefinition->getCNamespace().'_'.$classDefinition->getName().');'; + } else { + $interfaceEntries[$dependencyRank][] = 'zend_class_entry *'.$classDefinition->getClassEntry().';'; + $interfaceInits[$dependencyRank][] = 'ZEPHIR_INIT('.$classDefinition->getCNamespace().'_'.$classDefinition->getName().');'; } } @@ -1660,7 +1652,7 @@ public function createProjectFiles($project) $completeClassEntries = array_merge($completeClassEntries, $rankClassEntries); } - /* + /** * Round 3. Process extension globals */ list($globalCode, $globalStruct, $globalsDefault, $initEntries) = $this->processExtensionGlobals($project); @@ -1675,7 +1667,7 @@ public function createProjectFiles($project) */ $phpInfo = $this->processExtensionInfo(); - /* + /** * Round 5. Generate Function entries (FE) */ list($feHeader, $feEntries) = $this->generateFunctionInformation(); @@ -1793,7 +1785,7 @@ public function createProjectFiles($project) $content = str_replace($mark, $replace, $content); } - /* + /** * Round 5. Generate and place the entry point of the project */ file_put_contents_ex($content, 'ext/'.$safeProject.'.c'); @@ -1922,6 +1914,7 @@ public function generateFunctionInformation(): array ); } } + $entryPrinter->output('ZEND_FE_END'); return [$headerPrinter->getOutput(), $entryPrinter->getOutput()]; @@ -1946,7 +1939,7 @@ public function checkIfPhpized(): bool */ public static function getShortUserPath(string $path): string { - return str_replace('\\', '/', str_replace(getcwd().\DIRECTORY_SEPARATOR, '', $path)); + return str_replace('\\', '/', str_replace(getcwd().DIRECTORY_SEPARATOR, '', $path)); } /** @@ -1958,68 +1951,63 @@ public static function getShortUserPath(string $path): string * * @return string */ - public function generatePackageDependenciesM4($contentM4) + public function generatePackageDependenciesM4(string $contentM4): string { $packageDependencies = $this->config->get('package-dependencies'); - if (is_array($packageDependencies)) { - $pkgconfigM4 = $this->backend->getTemplateFileContents('pkg-config.m4'); - $pkgconfigCheckM4 = $this->backend->getTemplateFileContents('pkg-config-check.m4'); - $extraCFlags = ''; - - foreach ($packageDependencies as $pkg => $version) { - $pkgM4Buf = $pkgconfigCheckM4; - - $operator = '='; - $operatorCmd = '--exact-version'; - $ar = explode('=', $version); - if (1 == count($ar)) { - if ('*' == $version) { - $version = '0.0.0'; + if (!is_array($packageDependencies)) { + return str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', '', $contentM4); + } + + $pkgconfigM4 = $this->backend->getTemplateFileContents('pkg-config.m4'); + $pkgconfigCheckM4 = $this->backend->getTemplateFileContents('pkg-config-check.m4'); + $extraCFlags = ''; + + foreach ($packageDependencies as $pkg => $version) { + $pkgM4Buf = $pkgconfigCheckM4; + + $operator = '='; + $operatorCmd = '--exact-version'; + $ar = explode('=', $version); + + if (1 === count($ar)) { + if ('*' === $version) { + $version = '0.0.0'; + $operator = '>='; + $operatorCmd = '--atleast-version'; + } + } else { + switch ($ar[0]) { + case '<': + $operator = '<='; + $operatorCmd = '--max-version'; + break; + case '>': $operator = '>='; $operatorCmd = '--atleast-version'; - } - } else { - switch ($ar[0]) { - case '<': - $operator = '<='; - $operatorCmd = '--max-version'; - $version = trim($ar[1]); - break; - case '>': - $operator = '>='; - $operatorCmd = '--atleast-version'; - $version = trim($ar[1]); - break; - default: - $version = trim($ar[1]); - break; - } + break; } - $toReplace = [ - '%PACKAGE_LOWER%' => strtolower($pkg), - '%PACKAGE_UPPER%' => strtoupper($pkg), - '%PACKAGE_REQUESTED_VERSION%' => $operator.' '.$version, - '%PACKAGE_PKG_CONFIG_COMPARE_VERSION%' => $operatorCmd.'='.$version, - ]; + $version = trim($ar[1]); + } - foreach ($toReplace as $mark => $replace) { - $pkgM4Buf = str_replace($mark, $replace, $pkgM4Buf); - } + $toReplace = [ + '%PACKAGE_LOWER%' => strtolower($pkg), + '%PACKAGE_UPPER%' => strtoupper($pkg), + '%PACKAGE_REQUESTED_VERSION%' => $operator.' '.$version, + '%PACKAGE_PKG_CONFIG_COMPARE_VERSION%' => $operatorCmd.'='.$version, + ]; - $pkgconfigM4 .= $pkgM4Buf; - $extraCFlags .= '$PHP_'.strtoupper($pkg).'_INCS '; + foreach ($toReplace as $mark => $replace) { + $pkgM4Buf = str_replace($mark, $replace, $pkgM4Buf); } - $contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4); - $contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', $pkgconfigM4, $contentM4); - - return $contentM4; + $pkgconfigM4 .= $pkgM4Buf; + $extraCFlags .= '$PHP_'.strtoupper($pkg).'_INCS '; } - $contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', '', $contentM4); + $contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4); - return $contentM4; + return str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', $pkgconfigM4, $contentM4); } /** @@ -2029,14 +2017,14 @@ public function generatePackageDependenciesM4($contentM4) * * @throws IllegalStateException */ - private function preCompile(string $filePath) + private function preCompile(string $filePath): void { if (!$this->parserManager->isAvailable()) { throw new IllegalStateException($this->parserManager->requirements()); } if (preg_match('#\.zep$#', $filePath)) { - $className = str_replace(\DIRECTORY_SEPARATOR, '\\', $filePath); + $className = str_replace(DIRECTORY_SEPARATOR, '\\', $filePath); $className = preg_replace('#.zep$#', '', $className); $className = implode('\\', array_map('ucfirst', explode('\\', $className))); @@ -2064,7 +2052,7 @@ private function recursivePreCompile(string $path) sprintf( "An invalid path was passed to the compiler. Unable to obtain the '%s%s%s' directory.", getcwd(), - \DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR, $path ) ); @@ -2073,9 +2061,9 @@ private function recursivePreCompile(string $path) /** * Pre compile all files. */ - $iterator = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path), - \RecursiveIteratorIterator::SELF_FIRST + $iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path), + RecursiveIteratorIterator::SELF_FIRST ); $files = []; @@ -2108,7 +2096,7 @@ private function recursivePreCompile(string $path) private function recursiveProcess($src, $dest, $pattern = null, $callback = 'copy') { $success = true; - $iterator = new \DirectoryIterator($src); + $iterator = new DirectoryIterator($src); foreach ($iterator as $item) { $pathName = $item->getPathname(); if (!is_readable($pathName)) { @@ -2120,13 +2108,13 @@ private function recursiveProcess($src, $dest, $pattern = null, $callback = 'cop if ($item->isDir()) { if ('.' != $fileName && '..' != $fileName && '.libs' != $fileName) { - if (!is_dir($dest.\DIRECTORY_SEPARATOR.$fileName)) { - mkdir($dest.\DIRECTORY_SEPARATOR.$fileName, 0755, true); + if (!is_dir($dest.DIRECTORY_SEPARATOR.$fileName)) { + mkdir($dest.DIRECTORY_SEPARATOR.$fileName, 0755, true); } - $this->recursiveProcess($pathName, $dest.\DIRECTORY_SEPARATOR.$fileName, $pattern, $callback); + $this->recursiveProcess($pathName, $dest.DIRECTORY_SEPARATOR.$fileName, $pattern, $callback); } } elseif (!$pattern || ($pattern && 1 === preg_match($pattern, $fileName))) { - $path = $dest.\DIRECTORY_SEPARATOR.$fileName; + $path = $dest.DIRECTORY_SEPARATOR.$fileName; $success = $success && \call_user_func($callback, $pathName, $path); } } @@ -2150,9 +2138,9 @@ private function recursiveDeletePath($path, $mask) return; } - $objects = new \RecursiveIteratorIterator( - new \RecursiveDirectoryIterator($path), - \RecursiveIteratorIterator::SELF_FIRST + $objects = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path), + RecursiveIteratorIterator::SELF_FIRST ); foreach ($objects as $name => $object) { @@ -2200,7 +2188,7 @@ private function processAddSources(array $sources, string $project): array { $groupSources = []; foreach ($sources as $source) { - $dirName = str_replace(\DIRECTORY_SEPARATOR, '/', dirname($source)); + $dirName = str_replace(DIRECTORY_SEPARATOR, '/', dirname($source)); if (!isset($groupSources[$dirName])) { $groupSources[$dirName] = []; } @@ -2210,8 +2198,7 @@ private function processAddSources(array $sources, string $project): array $groups = []; foreach ($groupSources as $dirname => $files) { - $groups[] = 'ADD_SOURCES(configure_module_dirname + "/'.$dirname.'", "'. - implode(' ', $files).'", "'.$project.'");'; + $groups[] = 'ADD_SOURCES(configure_module_dirname + "/'.$dirname.'", "'.implode(' ', $files).'", "'.$project.'");'; } return $groups; @@ -2222,26 +2209,26 @@ private function processAddSources(array $sources, string $project): array * * @throws RuntimeException */ - private function assertRequiredExtensionsIsPresent() + private function assertRequiredExtensionsIsPresent(): void { $extensionRequires = $this->config->get('extensions', 'requires'); - if (true === empty($extensionRequires)) { + if (empty($extensionRequires)) { return; } $extensions = []; - foreach ($extensionRequires as $key => $value) { + foreach ($extensionRequires as $value) { // TODO: We'll use this as an object in the future. - // Right not it should be a string. if (!is_string($value)) { continue; } - if (false === \extension_loaded($value)) { + + if (!extension_loaded($value)) { $extensions[] = $value; } } - if (false === empty($extensions)) { + if (!empty($extensions)) { throw new RuntimeException( sprintf( 'Could not load extension(s): %s. You must load extensions above before build this extension.', @@ -2281,7 +2268,7 @@ private function checkKernelFile(string $src, string $dst): bool */ private function checkKernelFiles(): bool { - $kernelPath = 'ext'.\DIRECTORY_SEPARATOR.'kernel'; + $kernelPath = 'ext'.DIRECTORY_SEPARATOR.'kernel'; if (!file_exists($kernelPath)) { if (!mkdir($kernelPath, 0775, true)) { @@ -2380,7 +2367,7 @@ private function toUnixPaths(array $paths): array { return array_map( static function (string $path): string { - return str_replace(\DIRECTORY_SEPARATOR, '/', $path); + return str_replace(DIRECTORY_SEPARATOR, '/', $path); }, $paths ); diff --git a/Library/Config.php b/Library/Config.php index d2e0bcd67..d7f278630 100644 --- a/Library/Config.php +++ b/Library/Config.php @@ -15,8 +15,6 @@ use JsonSerializable; /** - * Zephir\Config. - * * Manages compiler global configuration. */ class Config implements ArrayAccess, JsonSerializable diff --git a/Library/Zephir.php b/Library/Zephir.php index 5bc19b8a0..45c76411b 100644 --- a/Library/Zephir.php +++ b/Library/Zephir.php @@ -16,7 +16,7 @@ */ final class Zephir { - public const VERSION = '0.15.1-$Id$'; + public const VERSION = '0.15.2-$Id$'; public const LOGO = <<<'ASCII' _____ __ _ diff --git a/ext/php_stub.h b/ext/php_stub.h index 12c03fff5..f77c451e7 100644 --- a/ext/php_stub.h +++ b/ext/php_stub.h @@ -14,7 +14,7 @@ #define PHP_STUB_VERSION "1.0.0" #define PHP_STUB_EXTNAME "stub" #define PHP_STUB_AUTHOR "Phalcon Team and contributors" -#define PHP_STUB_ZEPVERSION "0.15.1-$Id$" +#define PHP_STUB_ZEPVERSION "0.15.2-$Id$" #define PHP_STUB_DESCRIPTION "Description test for
Test Extension." typedef struct _zephir_struct_db { diff --git a/ext/stub.c b/ext/stub.c index fa0ee3d4d..7fd9c1cdf 100644 --- a/ext/stub.c +++ b/ext/stub.c @@ -254,10 +254,11 @@ PHP_INI_BEGIN() STD_PHP_INI_BOOLEAN("stub.orm.cache_enable", "1", PHP_INI_ALL, OnUpdateBool, orm.cache_enable, zend_stub_globals, stub_globals) - + STD_PHP_INI_ENTRY("stub.orm.cache_prefix", "prefix-string-", PHP_INI_ALL, NULL, orm.cache_prefix, zend_stub_globals, stub_globals) STD_PHP_INI_BOOLEAN("extension.test_ini_variable", "1", PHP_INI_ALL, OnUpdateBool, extension.test_ini_variable, zend_stub_globals, stub_globals) STD_PHP_INI_BOOLEAN("ini-entry.my_setting_1", "1", PHP_INI_ALL, OnUpdateBool, my_setting_1, zend_stub_globals, stub_globals) STD_PHP_INI_BOOLEAN("stub.test_setting_1", "1", PHP_INI_ALL, OnUpdateBool, test_setting_1, zend_stub_globals, stub_globals) + STD_PHP_INI_ENTRY("stub.my_setting_5", "custom_value", PHP_INI_ALL, NULL, my_setting_5, zend_stub_globals, stub_globals) PHP_INI_END() static PHP_MINIT_FUNCTION(stub)