Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #56 from ralphschindler/feature/better-reflection

Feature/better reflection
  • Loading branch information...
commit 0e9607b3130f6b7e2f178b07e94d06e0d8c866f9 2 parents 2815b0e + 96320b0
@Juliens Juliens authored
Showing with 149 additions and 3 deletions.
  1. +15 −3 aop.c
  2. +49 −0 doc/aop.php
  3. +85 −0 doc/php-declaration-generator.php
View
18 aop.c
@@ -107,6 +107,18 @@ zend_object_value aop_create_handler(zend_class_entry *type TSRMLS_DC)
return retval;
}
+ZEND_BEGIN_ARG_INFO(arginfo_aop_args_setArguments, 0)
+ ZEND_ARG_ARRAY_INFO(0, arguments, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_aop_args_setReturnedValue, 0)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO(arginfo_aop_args_setAssignedValue, 0)
+ ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_aop_args_returnbyref, 0, ZEND_RETURN_REFERENCE, -1)
ZEND_END_ARG_INFO()
@@ -114,12 +126,12 @@ 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, setArguments, arginfo_aop_args_setArguments, 0)
PHP_ME(AopJoinpoint, getKindOfAdvice, NULL, 0)
PHP_ME(AopJoinpoint, getReturnedValue, arginfo_aop_args_returnbyref, 0)
PHP_ME(AopJoinpoint, getAssignedValue, arginfo_aop_args_returnbyref, 0)
- PHP_ME(AopJoinpoint, setReturnedValue, NULL, 0)
- PHP_ME(AopJoinpoint, setAssignedValue, NULL, 0)
+ PHP_ME(AopJoinpoint, setReturnedValue, arginfo_aop_args_setReturnedValue, 0)
+ PHP_ME(AopJoinpoint, setAssignedValue, arginfo_aop_args_setAssignedValue, 0)
PHP_ME(AopJoinpoint, getPointcut, NULL, 0)
PHP_ME(AopJoinpoint, getObject, NULL, 0)
PHP_ME(AopJoinpoint, getClassName, NULL, 0)
View
49 doc/aop.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * Generated stub file for code completion purposes
+ */
+
+define('AOP_KIND_BEFORE', 2);
+define('AOP_KIND_AFTER', 4);
+define('AOP_KIND_AROUND', 1);
+define('AOP_KIND_PROPERTY', 32);
+define('AOP_KIND_FUNCTION', 128);
+define('AOP_KIND_METHOD', 64);
+define('AOP_KIND_READ', 8);
+define('AOP_KIND_WRITE', 16);
+define('AOP_KIND_AROUND_WRITE_PROPERTY', 49);
+define('AOP_KIND_AROUND_READ_PROPERTY', 41);
+define('AOP_KIND_BEFORE_WRITE_PROPERTY', 50);
+define('AOP_KIND_BEFORE_READ_PROPERTY', 42);
+define('AOP_KIND_AFTER_WRITE_PROPERTY', 52);
+define('AOP_KIND_AFTER_READ_PROPERTY', 44);
+define('AOP_KIND_BEFORE_METHOD', 66);
+define('AOP_KIND_AFTER_METHOD', 68);
+define('AOP_KIND_AROUND_METHOD', 65);
+define('AOP_KIND_BEFORE_FUNCTION', 130);
+define('AOP_KIND_AFTER_FUNCTION', 132);
+define('AOP_KIND_AROUND_FUNCTION', 129);
+
+function aop_add_before($pointcut, $advice) {}
+function aop_add_after($pointcut, $advice) {}
+function aop_add_around($pointcut, $advice) {}
+
+class AopJoinpoint
+{
+ public function &getArguments() {}
+ public function getPropertyName() {}
+ public function getPropertyValue() {}
+ public function setArguments(array $arguments) {}
+ public function getKindOfAdvice() {}
+ public function &getReturnedValue() {}
+ public function &getAssignedValue() {}
+ public function setReturnedValue($value) {}
+ public function setAssignedValue($value) {}
+ public function getPointcut() {}
+ public function getObject() {}
+ public function getClassName() {}
+ public function getMethodName() {}
+ public function getFunctionName() {}
+ public function getException() {}
+ public function process() {}
+}
View
85 doc/php-declaration-generator.php
@@ -0,0 +1,85 @@
+<?php
+
+define('T', ' ');
+define('N', PHP_EOL);
+
+$functions = array('aop_add_before', 'aop_add_after', 'aop_add_around');
+$classes = array('AopJoinPoint');
+$constant_prefix = 'AOP';
+
+$php = '<?php' . N;
+$php .= '/**' . N . ' * Generated stub file for code completion purposes' . N . ' */';
+$php .= N . N;
+
+//echo ReflectionClass::export('ReflectionMethod');
+foreach (get_defined_constants() as $cname => $cvalue) {
+ if (strpos($cname, $constant_prefix) === 0) {
+ $php .= 'define(\'' . $cname . '\', ' . $cvalue . ');' . N;
+ }
+}
+
+$php .= N;
+
+foreach ($functions as $function) {
+ $refl = new ReflectionFunction($function);
+ $php .= 'function ' . $refl->getName() . '(';
+ foreach ($refl->getParameters() as $i => $parameter) {
+ if ($i >= 1) {
+ $php .= ', ';
+ }
+ if ($typehint = $parameter->getClass()) {
+ $php .= $typehint->getName() . ' ';
+ }
+ $php .= '$' . $parameter->getName();
+ if ($parameter->isDefaultValueAvailable()) {
+ $php .= ' = ' . $parameter->getDefaultValue();
+ }
+ }
+ $php .= ') {}' . N;
+}
+
+$php .= N;
+
+foreach ($classes as $class) {
+ $refl = new ReflectionClass($class);
+ $php .= 'class ' . $refl->getName();
+ if ($parent = $refl->getParentClass()) {
+ $php .= ' extends ' . $parent->getName();
+ }
+ $php .= N . '{' . N;
+ foreach ($refl->getProperties() as $property) {
+ $php .= T . '$' . $property->getName() . ';' . N;
+ }
+ foreach ($refl->getMethods() as $method) {
+ if ($method->isPublic()) {
+ if ($method->getDocComment()) {
+ $php .= T . $method->getDocComment() . N;
+ }
+ $php .= T . 'public function ';
+ if ($method->returnsReference()) {
+ $php .= '&';
+ }
+ $php .= $method->getName() . '(';
+ foreach ($method->getParameters() as $i => $parameter) {
+ if ($i >= 1) {
+ $php .= ', ';
+ }
+ if ($parameter->isArray()) {
+ $php .= 'array ';
+ }
+ if ($typehint = $parameter->getClass()) {
+ $php .= $typehint->getName() . ' ';
+ }
+ $php .= '$' . $parameter->getName();
+ if ($parameter->isDefaultValueAvailable()) {
+ $php .= ' = ' . $parameter->getDefaultValue();
+ }
+ }
+ $php .= ') {}' . N;
+ }
+ }
+ $php .= '}';
+}
+
+echo $php . N;
+
Please sign in to comment.
Something went wrong with that request. Please try again.