Skip to content

Commit

Permalink
#1849 - Add generators example
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Nov 7, 2021
1 parent 7d5847e commit 8564b12
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 42 deletions.
3 changes: 2 additions & 1 deletion ext/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PHP_ARG_ENABLE(stub, whether to enable stub, [ --enable-stub Enable Stub])

if test "$PHP_STUB" = "yes"; then



if ! test "x" = "x"; then
PHP_EVAL_LIBLINE(, STUB_SHARED_LIBADD)
Expand Down Expand Up @@ -79,6 +79,7 @@ if test "$PHP_STUB" = "yes"; then
stub/functional.zep.c
stub/functionexists.zep.c
stub/functions.zep.c
stub/generators.zep.c
stub/geometry.zep.c
stub/globals.zep.c
stub/globals/env.zep.c
Expand Down
58 changes: 29 additions & 29 deletions ext/config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,35 @@ if (PHP_STUB != "no") {
ADD_EXTENSION_DEP("stub", "json");
AC_DEFINE("ZEPHIR_USE_PHP_JSON", 1, "Whether PHP json extension is present at compile time");
}
ADD_SOURCES(configure_module_dirname + "/stub/invokes", "abstractprotected.zep.c abstractinvoker.zep.c abstractinvokercomplex.zep.c invokeprotected.zep.c invokeprotectedcomplex.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arraymanipulation.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1134.zep.c issue1404.zep.c issue1521.zep.c issue663.zep.c issue887.zep.c issue893.zep.c issue914.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c reflection.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spl.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c 13__closure.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/issue2165", "issueextendinterface.zep.c issueinterface.zep.c issue.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/globals/session", "base.zep.c child.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/interfaces", "interfaceint.zep.c interfaceintsignature.zep.c implementint.zep.c implementinterface.zep.c interfacestaticmethod.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo", "abstractstatic.zep.c oodynamica.zep.c abstractclass.zep.c concretestatic.zep.c constantsinterface.zep.c deprecatedmethods.zep.c dynamicprop.zep.c extendpdoclass.zep.c ooconstruct.zep.c ooconstructparams.zep.c oodestruct.zep.c oodynamicb.zep.c oonativeimplements.zep.c oonoconstruct.zep.c ooparams.zep.c param.zep.c propertyaccess.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db/query", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/scopes", "hasprivatemethod.zep.c scopetesterinterface.zep.c abstractclass.zep.c abstractclassmagic.zep.c privatescopetester.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/ooimpl", "zbeginning.zep.c abeginning.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/properties", "publicproperties.zep.c app.zep.c extendspublicproperties.zep.c getobjectvars.zep.c privateproperties.zep.c propertyarray.zep.c propertyupdate.zep.c protectedproperties.zep.c staticprivateproperties.zep.c staticpropertyarray.zep.c staticprotectedproperties.zep.c staticpublicproperties.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/bench", "foo.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/builtin", "arraymethods.zep.c charmethods.zep.c intmethods.zep.c stringmethods.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/constructors", "issue1803.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/flow", "switchflow.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/globals", "env.zep.c post.zep.c server.zep.c serverrequestfactory.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/integration/psr", "extendexternal.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/integration/psr/http/message", "messageinterfaceex.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/mcall", "caller.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/namespaces/a/b", "sub.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/namespaces", "classentry.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db/query/placeholder", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/spl", "arrayobject.zep.c directoryiterator.zep.c doublylinkedlist.zep.c fileinfo.zep.c fileobject.zep.c filesystemiterator.zep.c fixedarray.zep.c globiterator.zep.c heap.zep.c maxheap.zep.c minheap.zep.c priorityqueue.zep.c queue.zep.c recursivedirectoryiterator.zep.c stack.zep.c tempfileobject.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/optimizers", "isscalar.zep.c acos.zep.c arraymerge.zep.c asin.zep.c cos.zep.c createarray.zep.c ldexp.zep.c sin.zep.c sqrt.zep.c strreplace.zep.c substr.zep.c tan.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/requires", "external3.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/router", "exception.zep.c route.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/typehinting", "testabstract.zep.c", "stub");

ADD_SOURCES(configure_module_dirname + "/stub/invokes", "abstractprotected.zep.c abstractinvoker.zep.c abstractinvokercomplex.zep.c invokeprotected.zep.c invokeprotectedcomplex.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arraymanipulation.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c generators.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1134.zep.c issue1404.zep.c issue1521.zep.c issue663.zep.c issue887.zep.c issue893.zep.c issue914.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c reflection.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spl.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c 13__closure.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/issue2165", "issueextendinterface.zep.c issueinterface.zep.c issue.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/globals/session", "base.zep.c child.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/interfaces", "interfaceint.zep.c interfaceintsignature.zep.c implementint.zep.c implementinterface.zep.c interfacestaticmethod.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo", "abstractstatic.zep.c oodynamica.zep.c abstractclass.zep.c concretestatic.zep.c constantsinterface.zep.c deprecatedmethods.zep.c dynamicprop.zep.c extendpdoclass.zep.c ooconstruct.zep.c ooconstructparams.zep.c oodestruct.zep.c oodynamicb.zep.c oonativeimplements.zep.c oonoconstruct.zep.c ooparams.zep.c param.zep.c propertyaccess.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db/query", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/scopes", "hasprivatemethod.zep.c scopetesterinterface.zep.c abstractclass.zep.c abstractclassmagic.zep.c privatescopetester.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/ooimpl", "zbeginning.zep.c abeginning.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/properties", "publicproperties.zep.c app.zep.c extendspublicproperties.zep.c getobjectvars.zep.c privateproperties.zep.c propertyarray.zep.c propertyupdate.zep.c protectedproperties.zep.c staticprivateproperties.zep.c staticpropertyarray.zep.c staticprotectedproperties.zep.c staticpublicproperties.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/bench", "foo.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/builtin", "arraymethods.zep.c charmethods.zep.c intmethods.zep.c stringmethods.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/constructors", "issue1803.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/flow", "switchflow.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/globals", "env.zep.c post.zep.c server.zep.c serverrequestfactory.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/integration/psr", "extendexternal.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/integration/psr/http/message", "messageinterfaceex.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/mcall", "caller.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/namespaces/a/b", "sub.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/namespaces", "classentry.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db/query/placeholder", "exception.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/spl", "arrayobject.zep.c directoryiterator.zep.c doublylinkedlist.zep.c fileinfo.zep.c fileobject.zep.c filesystemiterator.zep.c fixedarray.zep.c globiterator.zep.c heap.zep.c maxheap.zep.c minheap.zep.c priorityqueue.zep.c queue.zep.c recursivedirectoryiterator.zep.c stack.zep.c tempfileobject.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/optimizers", "isscalar.zep.c acos.zep.c arraymerge.zep.c asin.zep.c cos.zep.c createarray.zep.c ldexp.zep.c sin.zep.c sqrt.zep.c strreplace.zep.c substr.zep.c tan.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/requires", "external3.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/router", "exception.zep.c route.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/typehinting", "testabstract.zep.c", "stub");
ADD_SOURCES(configure_module_dirname + "/stub/types", "mixedtype.zep.c", "stub");
ADD_FLAG("CFLAGS_STUB", "/D ZEPHIR_RELEASE /Oi /Ot /Oy /Ob2 /Gs /GF /Gy /GL");
ADD_FLAG("CFLAGS", "/D ZEPHIR_RELEASE /Oi /Ot /Oy /Ob2 /Gs /GF /Gy /GL");
Expand Down
24 changes: 13 additions & 11 deletions ext/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ zend_class_entry *stub_fortytwo_ce;
zend_class_entry *stub_functional_ce;
zend_class_entry *stub_functionexists_ce;
zend_class_entry *stub_functions_ce;
zend_class_entry *stub_generators_ce;
zend_class_entry *stub_geometry_ce;
zend_class_entry *stub_globals_ce;
zend_class_entry *stub_globals_env_ce;
Expand Down Expand Up @@ -250,9 +251,9 @@ ZEND_DECLARE_MODULE_GLOBALS(stub)

PHP_INI_BEGIN()
STD_PHP_INI_BOOLEAN("stub.db.my_setting_1", "0", PHP_INI_ALL, OnUpdateBool, db.my_setting_1, zend_stub_globals, stub_globals)



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)
Expand Down Expand Up @@ -338,6 +339,7 @@ static PHP_MINIT_FUNCTION(stub)
ZEPHIR_INIT(Stub_FunctionExists);
ZEPHIR_INIT(Stub_Functional);
ZEPHIR_INIT(Stub_Functions);
ZEPHIR_INIT(Stub_Generators);
ZEPHIR_INIT(Stub_Geometry);
ZEPHIR_INIT(Stub_Globals);
ZEPHIR_INIT(Stub_Globals_Env);
Expand Down Expand Up @@ -487,14 +489,14 @@ static PHP_MINIT_FUNCTION(stub)
ZEPHIR_INIT(stub_7__closure);
ZEPHIR_INIT(stub_8__closure);
ZEPHIR_INIT(stub_9__closure);

return SUCCESS;
}

#ifndef ZEPHIR_RELEASE
static PHP_MSHUTDOWN_FUNCTION(stub)
{

zephir_deinitialize_memory();
UNREGISTER_INI_ENTRIES();
return SUCCESS;
Expand All @@ -517,7 +519,7 @@ static void php_zephir_init_globals(zend_stub_globals *stub_globals)
/* Static cache */
memset(stub_globals->scache, '\0', sizeof(zephir_fcall_cache_entry*) * ZEPHIR_MAX_CACHE_SLOTS);


stub_globals->db.my_setting_2 = 100;
stub_globals->db.my_setting_3 = 7.5;
stub_globals->orm.cache_level = 3;
Expand All @@ -530,15 +532,15 @@ static void php_zephir_init_globals(zend_stub_globals *stub_globals)
stub_globals->my_setting_3 = 15.2;
stub_globals->my_setting_4 = 'A';
stub_globals->my_setting_5 = ZSTR_VAL(zend_string_init(ZEND_STRL("custom_value"), 0));

}

/**
* Initialize globals only on each thread started
*/
static void php_zephir_init_module_globals(zend_stub_globals *stub_globals)
{

}

static PHP_RINIT_FUNCTION(stub)
Expand All @@ -551,13 +553,13 @@ static PHP_RINIT_FUNCTION(stub)

zephir_init_static_properties_Stub_Properties_StaticPropertyArray();
zephir_init_static_properties_Stub_SPropertyAccess();

return SUCCESS;
}

static PHP_RSHUTDOWN_FUNCTION(stub)
{

zephir_deinitialize_memory();
return SUCCESS;
}
Expand Down Expand Up @@ -603,7 +605,7 @@ static PHP_GINIT_FUNCTION(stub)

static PHP_GSHUTDOWN_FUNCTION(stub)
{

}

PHP_FUNCTION(g_stub_zephir_global_method_test);
Expand Down
3 changes: 2 additions & 1 deletion ext/stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
#include "stub/functional.zep.h"
#include "stub/functionexists.zep.h"
#include "stub/functions.zep.h"
#include "stub/generators.zep.h"
#include "stub/geometry.zep.h"
#include "stub/globals.zep.h"
#include "stub/globals/env.zep.h"
Expand Down Expand Up @@ -227,4 +228,4 @@
#include "stub/12__closure.zep.h"
#include "stub/13__closure.zep.h"

#endif
#endif
71 changes: 71 additions & 0 deletions ext/stub/generators.zep.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ext/stub/generators.zep.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions stub/generators.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace Stub;

class Generators
{
public function simpleYield()
{
//yield 1;
}
}
32 changes: 32 additions & 0 deletions tests/Extension/GeneratorsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/**
* This file is part of the Zephir.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Extension;

use PHPUnit\Framework\TestCase;
use Stub\Generators;

final class GeneratorsTest extends TestCase
{
private Generators $test;

protected function setUp(): void
{
$this->test = new Generators();
}

public function testYield(): void
{
$this->assertInstanceOf(\Generator::class, $this->test->simpleYield());
}
}

0 comments on commit 8564b12

Please sign in to comment.