Permalink
Browse files

implementation of getPropertyValue

  • Loading branch information...
1 parent f9d16ef commit c03167e136f0be90faf3dcdcc7e7105a9c812ee6 @Juliens Juliens committed Feb 9, 2013
Showing with 48 additions and 18 deletions.
  1. +3 −1 CHANGELOG
  2. +5 −15 aop.c
  3. +3 −2 aop.h
  4. +16 −0 aop_joinpoint.c
  5. +1 −0 aop_joinpoint.h
  6. +20 −0 tests/properties/010.phpt
View
@@ -1,3 +1,5 @@
+0.3
+getPointcutValue
0.2
AopTriggeredJoinPoint was renamed AopJoinPoint
AopJoinPoint->getTriggering* was renamed AopJoinPoint->get*
@@ -6,4 +8,4 @@ lots of bug fixes
performances improvements
0.1
-First Beta
+First Beta
View
20 aop.c
@@ -27,6 +27,7 @@
#include "aop.h"
#include "Zend/zend_operators.h"
+#define DEBUG_OBJECT_HANDLERS 1
static void php_aop_init_globals(zend_aop_globals *aop_globals)
{
@@ -78,8 +79,6 @@ zend_object_handlers AopJoinpoint_object_handlers;
void aop_free_storage(void *object TSRMLS_DC)
{
AopJoinpoint_object *obj = (AopJoinpoint_object *)object;
-// zend_hash_destroy(obj->std.properties);
-// FREE_HASHTABLE(obj->std.properties);
if (obj->value!=NULL) {
zval_ptr_dtor(&obj->value);
}
@@ -99,9 +98,6 @@ zend_object_value aop_create_handler(zend_class_entry *type TSRMLS_DC)
memset(obj, 0, sizeof(AopJoinpoint_object));
obj->std.ce = type;
-// ALLOC_HASHTABLE(obj->std.properties);
-// zend_hash_init(obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0);
-
retval.handle = zend_objects_store_put(obj, NULL,
aop_free_storage, NULL TSRMLS_CC);
retval.handlers = &AopJoinpoint_object_handlers;
@@ -115,6 +111,7 @@ ZEND_END_ARG_INFO()
static const zend_function_entry aop_methods[] = {
PHP_ME(AopJoinpoint, getArguments, arginfo_aop_args_returnbyref, 0)
PHP_ME(AopJoinpoint, getPropertyName, NULL, 0)
+ PHP_ME(AopJoinpoint, getPropertyValue, NULL, 0)
PHP_ME(AopJoinpoint, setArguments, NULL, 0)
PHP_ME(AopJoinpoint, getKindOfAdvice, NULL, 0)
PHP_ME(AopJoinpoint, getReturnedValue, arginfo_aop_args_returnbyref, 0)
@@ -175,14 +172,6 @@ PHP_RINIT_FUNCTION(aop)
ALLOC_HASHTABLE(aop_g(function_cache));
zend_hash_init(aop_g(function_cache), 16, NULL, free_pointcut_cache,0);
-/*
- aop_g(object_cache_write_size) = 1024;
- aop_g(object_cache_write) = ecalloc(1024, sizeof(HashTable *));
- aop_g(object_cache_read_size) = 1024;
- aop_g(object_cache_read) = ecalloc(1024, sizeof(HashTable *));
- aop_g(object_cache_func_size) = 1024;
- aop_g(object_cache_func) = ecalloc(1024, sizeof(HashTable *));
-*/
return SUCCESS;
}
@@ -241,7 +230,6 @@ static void free_pointcut(void *pc)
}
//*/
efree(_pc);
- /* Need to free members */
}
static zval *get_aopJoinpoint () {
@@ -285,15 +273,17 @@ static zval *get_aopJoinpoint () {
}
ZEND_DLEXPORT zval **zend_std_get_property_ptr_ptr_overload(zval *object, zval *member AOP_KEY_D TSRMLS_DC) {
+ zval **try_return;
zend_execute_data *ex = EG(current_execute_data);
//Test if ++
if (ex->opline->opcode != ZEND_PRE_INC_OBJ && ex->opline->opcode != ZEND_POST_INC_OBJ && ex->opline->opcode != ZEND_PRE_DEC_OBJ && ex->opline->opcode != ZEND_POST_DEC_OBJ) {
- return zend_std_get_property_ptr_ptr(object, member AOP_KEY_C TSRMLS_CC);
+ try_return = zend_std_get_property_ptr_ptr(object, member AOP_KEY_C TSRMLS_CC);
} else {
// Call original to not have a notice
zend_std_get_property_ptr_ptr(object, member AOP_KEY_C TSRMLS_CC);
return NULL;
}
+ return try_return;
}
ZEND_DLEXPORT zval * zend_std_read_property_overload(zval *object, zval *member, int type AOP_KEY_D TSRMLS_DC) {
View
5 aop.h
@@ -215,13 +215,14 @@ static int pointcut_match_zend_function (pointcut *pc, zend_function *curr_func,
#if ZEND_MODULE_API_NO < 20100525
static void (*zend_std_write_property)(zval *object, zval *member, zval *value TSRMLS_DC);
#endif
-static zval * (*zend_std_read_property)(zval *object, zval *member, int type AOP_KEY_D TSRMLS_DC);
-static zval ** (*zend_std_get_property_ptr_ptr)(zval *object, zval *member AOP_KEY_D TSRMLS_DC);
+zval * (*zend_std_read_property)(zval *object, zval *member, int type AOP_KEY_D TSRMLS_DC);
+zval ** (*zend_std_get_property_ptr_ptr)(zval *object, zval *member AOP_KEY_D TSRMLS_DC);
void _test_write_pointcut_and_execute(HashPosition pos, HashTable *ht, zval *object, zval *member, zval *value, zend_class_entry *current_scope AOP_KEY_D);
static void execute_pointcut (pointcut *pointcut_to_execute, zval *arg);
static int test_property_scope (pointcut *current_pc, zend_class_entry *ce, zval *member AOP_KEY_D);
static void execute_context (zend_execute_data *ex, zval *object, zend_class_entry *calling_scope, zend_class_entry *called_scope, int args_overloaded, zval *args, zval ** to_return_ptr_ptr);
+ZEND_DLEXPORT zval **zend_std_get_property_ptr_ptr_overload(zval *object, zval *member AOP_KEY_D TSRMLS_DC);
HashTable *calculate_function_pointcuts (zval *object, zend_execute_data *ex);
HashTable *calculate_property_pointcuts (zval *object, zval *member, int kind AOP_KEY_D);
View
@@ -37,6 +37,22 @@ PHP_METHOD(AopJoinpoint, getPropertyName){
}
RETURN_NULL();
}
+
+PHP_METHOD(AopJoinpoint, getPropertyValue){
+ AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
+ zval **to_return;
+ if (!(obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY)) {
+ zend_error(E_ERROR, "getPropertyValue is only available when the JoinPoint is a property operation (read or write)");
+ }
+#if ZEND_MODULE_API_NO >= 20100525
+ zend_literal *key = NULL;
+#endif
+ if (obj->object!=NULL && obj->member!=NULL) {
+ to_return = zend_std_get_property_ptr_ptr_overload(obj->object, obj->member AOP_KEY_C TSRMLS_CC);
+ }
+ RETURN_ZVAL (*to_return, 1, 0);
+}
+
PHP_METHOD(AopJoinpoint, getArguments){
AopJoinpoint_object *obj = (AopJoinpoint_object *)zend_object_store_get_object(getThis() TSRMLS_CC);
if (obj->current_pointcut->kind_of_advice & AOP_KIND_PROPERTY) {
View
@@ -20,6 +20,7 @@
PHP_METHOD(AopJoinpoint, getArguments);
PHP_METHOD(AopJoinpoint, getPropertyName);
+PHP_METHOD(AopJoinpoint, getPropertyValue);
PHP_METHOD(AopJoinpoint, setArguments);
PHP_METHOD(AopJoinpoint, getKindOfAdvice);
PHP_METHOD(AopJoinpoint, getReturnedValue);
View
@@ -0,0 +1,20 @@
+--TEST--
+getPropertyValue
+--FILE--
+<?php
+class Foo {
+ public $bar = "orig";
+}
+
+aop_add_before('Foo->bar', function(AopJoinPoint $jp) {
+ echo $jp->getPropertyValue();
+});
+
+$foo = new Foo();
+$test = $foo->bar;
+$foo->bar = "test";
+$foo->bar = "test2";
+
+?>
+--EXPECT--
+origorigtest

0 comments on commit c03167e

Please sign in to comment.