Skip to content

Commit

Permalink
#2308 - Fix support of string type in struct globals
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeckerson committed Oct 8, 2021
1 parent e147e70 commit 59336dd
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Library/Code/Builder/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public function getCDefault(string $name, array $global, string $namespace): str
case 'bool':
return '';

case 'string':
return "\t".$namespace.'_globals->'.$this->simpleName.'.'.$name.' = ZSTR_VAL(zend_string_init(ZEND_STRL("'.$global['default'].'"), 0));';

case 'int':
case 'uint':
case 'long':
Expand Down Expand Up @@ -192,6 +195,9 @@ protected function convertToCType(string $type): string
case 'hash':
return 'HashTable* ';

case 'string':
return 'zend_string* ';

case 'int':
case 'uint':
case 'long':
Expand Down
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
"type": "bool",
"default": true
},
"orm.cache_prefix": {
"type": "string",
"default": "prefix-string-"
},
"extension.test_ini_variable": {
"type": "bool",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions ext/php_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct _zephir_struct_db {
typedef struct _zephir_struct_orm {
int cache_level;
zend_bool cache_enable;
zend_string* cache_prefix;
} zephir_struct_orm;

typedef struct _zephir_struct_extension {
Expand Down
2 changes: 2 additions & 0 deletions ext/stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ 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_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)
Expand Down Expand Up @@ -520,6 +521,7 @@ static void php_zephir_init_globals(zend_stub_globals *stub_globals)
stub_globals->db.my_setting_3 = 7.5;
stub_globals->orm.cache_level = 3;

stub_globals->orm.cache_prefix = ZSTR_VAL(zend_string_init(ZEND_STRL("prefix-string-"), 0));

stub_globals->my_setting_1 = 1;
stub_globals->test_setting_1 = 1;
Expand Down
37 changes: 37 additions & 0 deletions ext/stub/globals.zep.c

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

16 changes: 16 additions & 0 deletions ext/stub/globals.zep.h

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

13 changes: 13 additions & 0 deletions stub/globals.zep
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class Globals
globals_set("orm.cache_level", value);
}

public function setDefaultGlobalsOrmCachePrefix(string value) -> void
{
globals_set("orm.cache_prefix", value);
}

/* Get Default Properties */

/**
Expand Down Expand Up @@ -108,4 +113,12 @@ class Globals
{
return globals_get("orm.cache_level");
}

/**
* @return mixed
*/
public function getDefaultGlobalsOrmCachePrefix()
{
return globals_get("orm.cache_prefix");
}
}
17 changes: 17 additions & 0 deletions tests/Extension/GlobalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,23 @@ public function testSetStringValue(): void

$this->test->setStringValue('Long Text without any sense...');
$this->assertSame('Long Text without any sense...', $this->test->getDefaultGlobals8());

/**
* Get and set string value from globals struct.
*/
$this->assertSame('prefix-string-', $this->test->getDefaultGlobalsOrmCachePrefix());

$this->test->setDefaultGlobalsOrmCachePrefix('1');
$this->assertSame('1', $this->test->getDefaultGlobalsOrmCachePrefix());

$this->test->setDefaultGlobalsOrmCachePrefix('c');
$this->assertSame('c', $this->test->getDefaultGlobalsOrmCachePrefix());

$this->test->setDefaultGlobalsOrmCachePrefix('char');
$this->assertSame('char', $this->test->getDefaultGlobalsOrmCachePrefix());

$this->test->setDefaultGlobalsOrmCachePrefix('Long Text without any sense...');
$this->assertSame('Long Text without any sense...', $this->test->getDefaultGlobalsOrmCachePrefix());
}

public function testSetBoolValueUsingInt(): void
Expand Down

0 comments on commit 59336dd

Please sign in to comment.