Skip to content

Commit 4da75af

Browse files
author
Derick Rethans
committed
- Expose date-extension object creation externally.
- Expose DateTime object initialisation externally.
1 parent 6f95046 commit 4da75af

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

ext/date/php_date.c

+16-17
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ const zend_function_entry date_funcs_period[] = {
475475

476476
static char* guess_timezone(const timelib_tzdb *tzdb TSRMLS_DC);
477477
static void date_register_classes(TSRMLS_D);
478-
static zval * date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC);
479478
/* }}} */
480479

481480
ZEND_DECLARE_MODULE_GLOBALS(date)
@@ -1846,7 +1845,7 @@ static void date_period_it_current_data(zend_object_iterator *iter, zval ***data
18461845

18471846
/* Create new object */
18481847
MAKE_STD_ZVAL(iterator->current);
1849-
date_instantiate(date_ce_date, iterator->current TSRMLS_CC);
1848+
php_date_instantiate(date_ce_date, iterator->current TSRMLS_CC);
18501849
newdateobj = (php_date_obj *) zend_object_store_get_object(iterator->current TSRMLS_CC);
18511850
newdateobj->time = timelib_time_ctor();
18521851
*newdateobj->time = *it_time;
@@ -2339,7 +2338,7 @@ static void date_object_free_storage_period(void *object TSRMLS_DC)
23392338
}
23402339

23412340
/* Advanced Interface */
2342-
static zval * date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC)
2341+
PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC)
23432342
{
23442343
Z_TYPE_P(object) = IS_OBJECT;
23452344
object_init_ex(object, pce);
@@ -2359,7 +2358,7 @@ static void update_errors_warnings(timelib_error_container *last_errors TSRMLS_D
23592358
DATEG(last_errors) = last_errors;
23602359
}
23612360

2362-
static int date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC)
2361+
PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC)
23632362
{
23642363
timelib_time *now;
23652364
timelib_tzinfo *tzi;
@@ -2454,8 +2453,8 @@ PHP_FUNCTION(date_create)
24542453
RETURN_FALSE;
24552454
}
24562455

2457-
date_instantiate(date_ce_date, return_value TSRMLS_CC);
2458-
if (!date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
2456+
php_date_instantiate(date_ce_date, return_value TSRMLS_CC);
2457+
if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 0 TSRMLS_CC)) {
24592458
RETURN_FALSE;
24602459
}
24612460
}
@@ -2474,8 +2473,8 @@ PHP_FUNCTION(date_create_from_format)
24742473
RETURN_FALSE;
24752474
}
24762475

2477-
date_instantiate(date_ce_date, return_value TSRMLS_CC);
2478-
if (!date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
2476+
php_date_instantiate(date_ce_date, return_value TSRMLS_CC);
2477+
if (!php_date_initialize(zend_object_store_get_object(return_value TSRMLS_CC), time_str, time_str_len, format_str, timezone_object, 0 TSRMLS_CC)) {
24792478
RETURN_FALSE;
24802479
}
24812480
}
@@ -2493,7 +2492,7 @@ PHP_METHOD(DateTime, __construct)
24932492

24942493
zend_replace_error_handling(EH_THROW, NULL, &error_handling TSRMLS_CC);
24952494
if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|sO", &time_str, &time_str_len, &timezone_object, date_ce_timezone)) {
2496-
date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC);
2495+
php_date_initialize(zend_object_store_get_object(getThis() TSRMLS_CC), time_str, time_str_len, NULL, timezone_object, 1 TSRMLS_CC);
24972496
}
24982497
zend_restore_error_handling(&error_handling TSRMLS_CC);
24992498
}
@@ -2520,7 +2519,7 @@ static int php_date_initialize_from_hash(zval **return_value, php_date_obj **dat
25202519
case TIMELIB_ZONETYPE_ABBR: {
25212520
char *tmp = emalloc(Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 2);
25222521
snprintf(tmp, Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 2, "%s %s", Z_STRVAL_PP(z_date), Z_STRVAL_PP(z_timezone));
2523-
date_initialize(*dateobj, tmp, Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 1, NULL, NULL, 0 TSRMLS_CC);
2522+
php_date_initialize(*dateobj, tmp, Z_STRLEN_PP(z_date) + Z_STRLEN_PP(z_timezone) + 1, NULL, NULL, 0 TSRMLS_CC);
25242523
efree(tmp);
25252524
return 1;
25262525
}
@@ -2531,12 +2530,12 @@ static int php_date_initialize_from_hash(zval **return_value, php_date_obj **dat
25312530
tzi = php_date_parse_tzfile(Z_STRVAL_PP(z_timezone), DATE_TIMEZONEDB TSRMLS_CC);
25322531

25332532
ALLOC_INIT_ZVAL(tmp_obj);
2534-
tzobj = zend_object_store_get_object(date_instantiate(date_ce_timezone, tmp_obj TSRMLS_CC) TSRMLS_CC);
2533+
tzobj = zend_object_store_get_object(php_date_instantiate(date_ce_timezone, tmp_obj TSRMLS_CC) TSRMLS_CC);
25352534
tzobj->type = TIMELIB_ZONETYPE_ID;
25362535
tzobj->tzi.tz = tzi;
25372536
tzobj->initialized = 1;
25382537

2539-
date_initialize(*dateobj, Z_STRVAL_PP(z_date), Z_STRLEN_PP(z_date), NULL, tmp_obj, 0 TSRMLS_CC);
2538+
php_date_initialize(*dateobj, Z_STRVAL_PP(z_date), Z_STRLEN_PP(z_date), NULL, tmp_obj, 0 TSRMLS_CC);
25402539
zval_ptr_dtor(&tmp_obj);
25412540
return 1;
25422541
}
@@ -2560,7 +2559,7 @@ PHP_METHOD(DateTime, __set_state)
25602559

25612560
myht = HASH_OF(array);
25622561

2563-
date_instantiate(date_ce_date, return_value TSRMLS_CC);
2562+
php_date_instantiate(date_ce_date, return_value TSRMLS_CC);
25642563
dateobj = (php_date_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
25652564
php_date_initialize_from_hash(&return_value, &dateobj, myht TSRMLS_CC);
25662565
}
@@ -2901,7 +2900,7 @@ PHP_FUNCTION(date_timezone_get)
29012900
dateobj = (php_date_obj *) zend_object_store_get_object(object TSRMLS_CC);
29022901
DATE_CHECK_INITIALIZED(dateobj->time, DateTime);
29032902
if (dateobj->time->is_localtime/* && dateobj->time->tz_info*/) {
2904-
date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
2903+
php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC);
29052904
tzobj = (php_timezone_obj *) zend_object_store_get_object(return_value TSRMLS_CC);
29062905
tzobj->initialized = 1;
29072906
tzobj->type = dateobj->time->zone_type;
@@ -3125,7 +3124,7 @@ PHP_FUNCTION(date_diff)
31253124
timelib_update_ts(dateobj1->time, NULL);
31263125
timelib_update_ts(dateobj2->time, NULL);
31273126

3128-
date_instantiate(date_ce_interval, return_value TSRMLS_CC);
3127+
php_date_instantiate(date_ce_interval, return_value TSRMLS_CC);
31293128
interval = zend_object_store_get_object(return_value TSRMLS_CC);
31303129
interval->diff = timelib_diff(dateobj1->time, dateobj2->time);
31313130
if (absolute) {
@@ -3171,7 +3170,7 @@ PHP_FUNCTION(timezone_open)
31713170
if (SUCCESS != timezone_initialize(&tzi, tz TSRMLS_CC)) {
31723171
RETURN_FALSE;
31733172
}
3174-
tzobj = zend_object_store_get_object(date_instantiate(date_ce_timezone, return_value TSRMLS_CC) TSRMLS_CC);
3173+
tzobj = zend_object_store_get_object(php_date_instantiate(date_ce_timezone, return_value TSRMLS_CC) TSRMLS_CC);
31753174
tzobj->type = TIMELIB_ZONETYPE_ID;
31763175
tzobj->tzi.tz = tzi;
31773176
tzobj->initialized = 1;
@@ -3563,7 +3562,7 @@ PHP_FUNCTION(date_interval_create_from_date_string)
35633562
RETURN_FALSE;
35643563
}
35653564

3566-
date_instantiate(date_ce_interval, return_value TSRMLS_CC);
3565+
php_date_instantiate(date_ce_interval, return_value TSRMLS_CC);
35673566

35683567
time = timelib_strtotime(time_str, time_str_len, &err, DATE_TIMEZONEDB);
35693568
diobj = (php_interval_obj *) zend_object_store_get_object(return_value TSRMLS_CC);

ext/date/php_date.h

+5
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,9 @@ PHPAPI timelib_tzinfo *get_timezone_info(TSRMLS_D);
177177
PHPAPI zend_class_entry *php_date_get_date_ce(void);
178178
PHPAPI zend_class_entry *php_date_get_timezone_ce(void);
179179

180+
/* Functions for creating DateTime objects, and initializing them from a string */
181+
PHPAPI zval *php_date_instantiate(zend_class_entry *pce, zval *object TSRMLS_DC);
182+
PHPAPI int php_date_initialize(php_date_obj *dateobj, /*const*/ char *time_str, int time_str_len, char *format, zval *timezone_object, int ctor TSRMLS_DC);
183+
184+
180185
#endif /* PHP_DATE_H */

0 commit comments

Comments
 (0)