Back to index

php5  5.3.10
reflection_tools.inc
Go to the documentation of this file.
00001 <?php
00002        function inspectClass($class) {
00003 
00004               /* not used: public ReflectionClass[] getInterfaces()  */
00005 
00006               printf("\nInspecting class '%s'\n", $class->getName());
00007               printf("isInternal: %s\n", ($class->isInternal()) ? 'yes' : 'no');
00008               printf("isUserDefined: %s\n", ($class->isUserDefined()) ? 'yes' : 'no');
00009               printf("isInstantiable: %s\n", ($class->isInstantiable()) ? 'yes' : 'no');
00010               printf("isInterface: %s\n", ($class->isInterface()) ? 'yes' : 'no');
00011               printf("isAbstract: %s\n", ($class->isAbstract()) ? 'yes' : 'no');
00012               printf("isFinal: %s\n", ($class->isFinal()) ? 'yes' : 'no');
00013               printf("isIteratable: %s\n", ($class->isIterateable()) ? 'yes' : 'no');
00014               printf("Modifiers: '%d'\n", $class->getModifiers());
00015               printf("Parent Class: '%s'\n", $class->getParentClass());
00016               printf("Extension: '%s'\n", $class->getExtensionName());
00017 
00018               if ($method = $class->getConstructor())
00019                      inspectMethod($method);
00020 
00021               if ($methods = $class->getMethods()) {
00022                      $tmp = array();
00023                      foreach ($methods as $method)
00024                             $tmp[$method->getName()] = $method;
00025 
00026                      ksort($tmp, SORT_STRING);
00027                      foreach ($tmp as $method)
00028                             inspectMethod($method);
00029               }
00030 
00031               if ($properties = $class->getProperties()) {
00032                      $tmp = array();
00033                      foreach ($properties as $prop)
00034                             $tmp[$prop->getName()] = $prop;
00035                      ksort($tmp, SORT_STRING);
00036                      foreach ($tmp as $prop)
00037                      inspectProperty($prop);
00038               }
00039 
00040 
00041               if ($properties = $class->getDefaultProperties()) {
00042                      ksort($properties, SORT_STRING);
00043                      foreach ($properties as $name => $v)
00044                             printf("Default property '%s'\n", $name);
00045               }
00046 
00047               if ($properties = $class->getStaticProperties()) {
00048                      ksort($properties, SORT_STRING);
00049                      foreach ($properties as $name => $v)
00050                             printf("Static property '%s'\n", $name);
00051               }
00052 
00053               if ($constants = $class->getConstants()) {
00054                      ksort($constants, SORT_STRING);
00055                      foreach ($constant as $name => $value)
00056                             printf("Constant '%s' = '%s'\n", $name, $value);
00057               }
00058 
00059        }
00060 
00061        function inspectProperty(&$prop) {
00062 
00063               printf("\nInspecting property '%s'\n", $prop->getName());
00064               printf("isPublic: %s\n", ($prop->isPublic()) ? 'yes' : 'no');
00065               printf("isPrivate: %s\n", ($prop->isPrivate()) ? 'yes' : 'no');
00066               printf("isProtected: %s\n", ($prop->isProtected()) ? 'yes' : 'no');
00067               printf("isStatic: %s\n", ($prop->isStatic()) ? 'yes' : 'no');
00068               printf("isDefault: %s\n", ($prop->isDefault()) ? 'yes' : 'no');
00069               printf("Modifiers: %d\n", $prop->getModifiers());
00070               // printf("Value\n"); var_export($prop->getValue());
00071 
00072        }
00073 
00074        function inspectMethod(&$method) {
00075 
00076               printf("\nInspecting method '%s'\n", $method->getName());
00077               printf("isFinal: %s\n", ($method->isFinal()) ? 'yes' : 'no');
00078               printf("isAbstract: %s\n", ($method->isAbstract()) ? 'yes' : 'no');
00079               printf("isPublic: %s\n", ($method->isPublic()) ? 'yes' : 'no');
00080               printf("isPrivate: %s\n", ($method->isPrivate()) ? 'yes' : 'no');
00081               printf("isProtected: %s\n", ($method->isProtected()) ? 'yes' : 'no');
00082               printf("isStatic: %s\n", ($method->isStatic()) ? 'yes' : 'no');
00083               printf("isConstructor: %s\n", ($method->isConstructor()) ? 'yes' : 'no');
00084               printf("isDestructor: %s\n", ($method->isDestructor()) ? 'yes' : 'no');
00085               printf("isInternal: %s\n", ($method->isInternal()) ? 'yes' : 'no');
00086               printf("isUserDefined: %s\n", ($method->isUserDefined()) ? 'yes' : 'no');
00087               printf("returnsReference: %s\n", ($method->returnsReference()) ? 'yes' : 'no');
00088               printf("Modifiers: %d\n", $method->getModifiers());
00089               printf("Number of Parameters: %d\n", $method->getNumberOfParameters());
00090               printf("Number of Required Parameters: %d\n", $method->getNumberOfRequiredParameters());
00091 
00092               if ($params = $method->getParameters()) {
00093                      $tmp = array();
00094                      foreach ($params as $k => $param)
00095                             $tmp[$param->getName()] = $param;
00096 
00097 //                   ksort($tmp, SORT_STRING);
00098                      foreach ($tmp as $param)
00099                             inspectParameter($method, $param);
00100               }
00101 
00102               if ($static = $method->getStaticVariables()) {
00103                      sort($static, SORT_STRING);
00104                      printf("Static variables: %s\n", implode('/', $static));
00105               }
00106 
00107        }
00108 
00109        function inspectParameter(&$method, &$param) {
00110 
00111               printf("\nInspecting parameter '%s' of method '%s'\n",
00112               $param->getName(), $method->getName());
00113               printf("isArray: %s\n", ($param->isArray()) ? 'yes': 'no');
00114               printf("allowsNull: %s\n", ($param->allowsNull()) ? 'yes' : 'no');
00115               printf("isPassedByReference: %s\n", ($param->isPassedByReference()) ? 'yes' : 'no');
00116               printf("isOptional: %s\n", ($param->isOptional()) ? 'yes' : 'no');
00117               printf("isDefaultValueAvailable: %s\n", ($param->isDefaultValueAvailable()) ? 'yes' : 'no');
00118               // printf("getDefaultValue: %s\n", ($param->getDefaultValue()) ? 'yes' : 'no');
00119 
00120        }
00121 ?>