Skip to content

Commit

Permalink
Merge pull request #1561 from phalcon/development
Browse files Browse the repository at this point in the history
0.9.10
  • Loading branch information
sergeyklay authored Jul 22, 2017
2 parents 868cb1f + 43394b4 commit 1b50721
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Library/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
class Compiler
{
const VERSION = '0.9.9';
const VERSION = '0.9.10';

public $parserCompiled = false;

Expand Down
7 changes: 5 additions & 2 deletions Library/Expression/NativeArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,12 @@ protected function _accessStringOffset($expression, Variable $variableVariable,
}

/**
* @param array $expression
* @param Variable $variableVariable
* @param array $expression
* @param Variable $variableVariable
* @param CompilationContext $compilationContext
* @return CompiledExpression
*
* @throws CompilerException
*/
protected function _accessDimensionArray($expression, Variable $variableVariable, CompilationContext $compilationContext)
{
Expand Down
10 changes: 9 additions & 1 deletion Library/FunctionCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ protected function markReferences($funcName, $parameters, CompilationContext $co
* @param array $expression
* @param Call $call
* @param CompilationContext $compilationContext
* @return bool|mixed
*
* @throws \Exception
*/
protected function optimize($funcName, array $expression, Call $call, CompilationContext $compilationContext)
{
Expand All @@ -218,6 +221,7 @@ protected function optimize($funcName, array $expression, Call $call, Compilatio
if (!isset(self::$_optimizers[$funcName])) {
$camelizeFunctionName = Utils::camelize($funcName);


/**
* Check every optimizer directory for an optimizer
*/
Expand Down Expand Up @@ -257,6 +261,7 @@ protected function optimize($funcName, array $expression, Call $call, Compilatio
* Checks if the function is a built-in provided by Zephir
*
* @param string $functionName
* @return bool
*/
public function isBuiltInFunction($functionName)
{
Expand Down Expand Up @@ -309,8 +314,11 @@ public function functionExists($functionName, CompilationContext $context)
}

/**
* @param array $expression
* @param array $expression
* @param CompilationContext $compilationContext
* @return CompiledExpression
*
* @throws CompilerException
*/
protected function _callNormal(array $expression, CompilationContext $compilationContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

use Zephir\Call;
use Zephir\CompilationContext;
use Zephir\CompilerException;
use Zephir\CompiledExpression;
use Zephir\Optimizers\OptimizerAbstract;
use Zephir\Utils;
Expand Down
84 changes: 67 additions & 17 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,88 @@
version: 0.9.9-{build}
#---------------------------------#
# general configuration #
#---------------------------------#

build: false
# version format
version: 0.9.10-{build}

# branches to build
branches:
# whitelist
only:
- master
- development

#---------------------------------#
# environment configuration #
#---------------------------------#

# environment variables
environment:
matrix:
- PHP_TARGET: 5.6
PHP_VC: 11
PHP_SDK: c:\projects\php-sdk
PHP_DEVPACK: c:\projects\php-devpack

# clone entire repository history if not defined
clone_depth: 1
clone_folder: c:\projects\zephir

branches:
only:
- master
- development
# clone directory
clone_folder: c:\projects\zephir

# scripts that are called at very beginning, before repo cloning
init:
- SET ANSICON=121x90 (121x90)
- SET COMPOSER_NO_INTERACTION=1
- SET PARSER_RELEASE=1.0.3
- SET PARSER_VERSION=1.0.3-258
- ps: IF ($env:APPVEYOR_REPO_BRANCH -eq "development") {$env:APPVEYOR_CACHE_SKIP_SAVE = "true"}

# build cache to preserve files/folders between builds
cache:
- vendor -> composer.json
- composer.phar -> composer.json

matrix:
# immediately finish build once one of the jobs fails
fast_finish: true

# Operating system (build VM template)
os: Windows Server 2012 R2

#---------------------------------#
# build configuration #
#---------------------------------#

# add platforms to build matrix (i.e. x86, x64, AnyCPU):
platform:
- x86

matrix:
fast_finish: true
# disable automatic builds
build: false

# scripts that run after cloning repository
install:
# ==================================================
- echo Setting PHP version...
# ==================================================
- appveyor DownloadFile http://windows.php.net/downloads/releases/sha1sum.txt
- ps: $env:PHP_VERSION=type sha1sum.txt | where { $_ -match "php-(${env:PHP_TARGET}\.\d+)-src" } | foreach { $matches[1] }
- ps: |
$matched_versions = type sha1sum.txt | where { $_ -match "php-(${env:PHP_TARGET}\.\d+)-src" } | foreach { $matches[1] }
$cleaned_version = $matched_versions.Split(' ')[-1]
$env:PHP_VERSION=${cleaned_version}
- ps: $env:PARSER_DOWNLOAD_URL="https://github.com/phalcon/php-zephir-parser/releases/download/v${env:PARSER_RELEASE}/zephir_parser_${env:PLATFORM}_vc${env:PHP_VC}_php${env:PHP_TARGET}_${env:PARSER_VERSION}.zip"

# ==================================================
- echo Initializing Build...
# ==================================================
- cd %APPVEYOR_BUILD_FOLDER%
- git submodule update --init --recursive
- echo Preparing zephir win32 build...

- echo Downloading PHP source code [%PHP_VERSION%]
# ==================================================
- echo Downloading PHP source code [http://windows.php.net/downloads/releases/php-%PHP_VERSION%-Win32-VC%PHP_VC%-%PLATFORM%.zip]
# ==================================================
- ps: (new-object net.webclient).DownloadFile('http://windows.php.net/downloads/releases/php-' + ${env:PHP_VERSION} + '-Win32-VC' + ${env:PHP_VC} + '-' + ${env:PLATFORM} + '.zip', ${env:APPVEYOR_BUILD_FOLDER} + '\..\php.zip')
- cd ..
- 'mkdir php && mv php.zip php\php.zip && cd php'
Expand Down Expand Up @@ -82,23 +117,38 @@ install:
- 'set PATH=%cd%;%PATH%'
- php --ri "Zephir Parser"

# ==================================================
- echo Download tests dependencies...
# ==================================================
#---------------------------------#
# tests configuration #
#---------------------------------#

# disable automatic tests
test: off

# scripts to run before tests
before_test:
- ps: Write-Host "Download tests dependencies.."
- cd %APPVEYOR_BUILD_FOLDER%
- if not exist vendor (php -r "readfile('https://getcomposer.org/installer');" | php && php composer.phar --version)
- if not exist vendor (php composer.phar update --quiet --no-ansi --no-interaction --no-progress --optimize-autoloader --dev --prefer-dist --no-suggest)
- php composer.phar dump-autoload

build_script:
- ps: Write-Host "Start custom build.."
- cd %APPVEYOR_BUILD_FOLDER%
- 'bin\zephir build -Wnonexistent-function -Wnonexistent-class -Wunused-variable'
- 'cd %APPVEYOR_BUILD_FOLDER%\..\php'
- 'echo extension=%APPVEYOR_BUILD_FOLDER%\ext\Release_TS\php_test.dll >> php.ini'
- cd %APPVEYOR_BUILD_FOLDER%
- 'bin\zephir build'

# run custom scripts instead of automatic tests
test_script:
- ps: Write-Host "Start unit test.."
- cd %APPVEYOR_BUILD_FOLDER%
- 'php unit-tests/phpunit -c phpunit.xml.dist --not-exit --debug'

#---------------------------------#
# global handlers #
#---------------------------------#

# on build failure
on_failure:
- 'dir'
- ps: >-
Expand Down
22 changes: 14 additions & 8 deletions kernels/ZendEngine3/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,13 @@ int zephir_fast_count_int(zval *value)
}

/**
* Check if a function exists using explicit char param (using precomputed hash key)
* Check if a function exists using explicit function length
*
* @todo Deprecated. Will be removed in future
*/
int zephir_function_quick_exists_ex(const char *method_name, unsigned int method_len)
int zephir_function_quick_exists_ex(const char *function_name, size_t function_len)
{
if (zend_hash_str_exists(CG(function_table), method_name, method_len)) {
if (zend_hash_str_exists(CG(function_table), function_name, function_len)) {
return SUCCESS;
}

Expand All @@ -267,19 +269,23 @@ int zephir_function_quick_exists_ex(const char *method_name, unsigned int method

/**
* Check if a function exists
*
* @param function_name
* @return
*/
int zephir_function_exists(const zval *function_name)
{
if (zend_hash_str_exists(CG(function_table), Z_STRVAL_P(function_name), Z_STRLEN_P(function_name))) {
return SUCCESS;
}

return zephir_function_quick_exists_ex(
Z_STRVAL_P(function_name),
Z_STRLEN_P(function_name) + 1
);
return FAILURE;
}

/**
* Check if a function exists using explicit char param
* Check if a function exists using explicit function length
*
* @todo Deprecated. Will be removed in future
* @param function_name
* @param function_len strlen(function_name) + 1
*/
Expand Down
33 changes: 33 additions & 0 deletions test/functionexists.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

namespace Test;

class FunctionExists
{
public function testWithPassedName(string func) -> bool
{
return function_exists(func);
}

public function testBuiltInFunctions() -> array
{
var func;
array result = [];

array functions = [
"substr",
"cubstr",
"ucfirst",
"bcfirst",
"stripos",
"ktripos",
"trim",
"prim"
];

for func in functions {
let result[func] = function_exists(func);
}

return result;
}
}
73 changes: 73 additions & 0 deletions unit-tests/Extension/FunctionExistsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/*
+--------------------------------------------------------------------------+
| Zephir Language |
+--------------------------------------------------------------------------+
| Copyright (c) 2013-2017 Zephir Team and contributors |
+--------------------------------------------------------------------------+
| This source file is subject the MIT license, that is bundled with |
| this package in the file LICENSE, and is available through the |
| world-wide-web at the following url: |
| https://zephir-lang.com/license.html |
| |
| If you did not receive a copy of the MIT license and are unable |
| to obtain it through the world-wide-web, please send a note to |
| [email protected] so we can mail you a copy immediately. |
+--------------------------------------------------------------------------+
*/

namespace Extension;

use Test\FunctionExists;

class FunctionExistsTest extends \PHPUnit_Framework_TestCase
{
/**
* @test
* @dataProvider providerInternalFunctions
* @issue 1547
* @param string $func The internal (built-in) function name
*/
public function shouldCorrectDetectestExistenceWithPassedName($func)
{
$t = new FunctionExists();
$this->assertTrue($t->testWithPassedName($func));
}

/**
* @test
* @issue 1547
*/
public function shouldCorrectDetectestExistenceInsideTheZephirCode()
{
$t = new FunctionExists();
$expected = [
"substr" => true,
"cubstr" => false,
"ucfirst" => true,
"bcfirst" => false,
"stripos" => true,
"ktripos" => false,
"trim" => true,
"prim" => false,
];

$this->assertSame($expected, $t->testBuiltInFunctions());
}

public function providerInternalFunctions()
{
$allFunctions = get_defined_functions();
shuffle($allFunctions['internal']);

$functions = array_map(
function ($value) {
return [$value];
},
$allFunctions['internal']
);

return array_slice($functions, 0, 10);
}
}

0 comments on commit 1b50721

Please sign in to comment.