public function testReflectionAnnotatedClass() { $reflection = new ReflectionAnnotatedClass('Example'); $this->assertTrue($reflection->hasAnnotation('FirstAnnotation')); $this->assertTrue($reflection->hasAnnotation('SecondAnnotation')); $this->assertFalse($reflection->hasAnnotation('NonExistentAnnotation')); $this->assertIsA($reflection->getAnnotation('FirstAnnotation'), 'FirstAnnotation'); $this->assertIsA($reflection->getAnnotation('SecondAnnotation'), 'SecondAnnotation'); $annotations = $reflection->getAnnotations(); $this->assertEqual(count($annotations), 2); $this->assertIsA($annotations[0], 'FirstAnnotation'); $this->assertIsA($annotations[1], 'SecondAnnotation'); $this->assertFalse($reflection->getAnnotation('NonExistentAnnotation')); $this->assertIsA($reflection->getConstructor(), 'ReflectionAnnotatedMethod'); $this->assertIsA($reflection->getMethod('exampleMethod'), 'ReflectionAnnotatedMethod'); foreach ($reflection->getMethods() as $method) { $this->assertIsA($method, 'ReflectionAnnotatedMethod'); } $this->assertIsA($reflection->getProperty('exampleProperty'), 'ReflectionAnnotatedProperty'); foreach ($reflection->getProperties() as $property) { $this->assertIsA($property, 'ReflectionAnnotatedProperty'); } foreach ($reflection->getInterfaces() as $interface) { $this->assertIsA($interface, 'ReflectionAnnotatedClass'); } $this->assertIsA($reflection->getParentClass(), 'ReflectionAnnotatedClass'); }
function process($webscript, $method) { $this->deleteInvalidTickets(); try { $reflectedWebscript = new ReflectionAnnotatedClass(ucfirst($webscript) . "Webscript"); if ($reflectedWebscript->hasMethod($method)) { $methodInstance = $reflectedWebscript->getMethod($method); if ($methodInstance->isPublic()) { $args = ""; $ticket = ""; if ($methodInstance->hasAnnotation("Get")) { $args = $_GET['data']; $ticket = $_GET['ticket']; } if ($methodInstance->hasAnnotation("Post")) { $args = $_POST['data']; $ticket = $_POST['ticket']; } if ($methodInstance->hasAnnotation("RequiresAuthentication")) { if ($this->checkAuthentication($ticket, $methodInstance->getAnnotation("RequiresAuthentication"))) { $this->extendAuthentication($ticket); } else { return $this->authenticationFailed(); } } return $methodInstance->invoke($reflectedWebscript->newInstance(), $args, $ticket); } } else { return $this->notFound(); } } catch (ReflectionException $e) { return $this->notFound(); } }
public function handle($inteceptor) { $re = new ReflectionAnnotatedClass(get_class($this->CI)); $method = $re->getMethod($inteceptor->call_method); if ($method->hasAnnotation('RunRule')) { $run = $method->getAnnotations('RunRule'); $run = $run[0]; // Clear the clips context if needed if ($run->clear) { $this->clips->clear(); } if ($run->templates) { if (is_string($run->templates)) { $run->templates = array($run->templates); } foreach ($run->templates as $t) { $this->clips->template($t); } } // Let the call method to add the facts $ret = $inteceptor->process(); // Load the rules if ($run->rules) { if (is_string($run->rules)) { $run->value = array($run->rules); } if (is_array($run->rules)) { $run->value = $run->rules; } } if (isset($run->value)) { if (is_string($run->value)) { $run->value = array($run->value); } foreach ($run->value as $v) { $this->clips->load('ci://config/rules/' . $v); } } // Run the clips context $this->clips->run(); // Return the original return return $ret; } return $inteceptor->process(); }
public function testMultiTargetAnnotationThrowsErrorWhenOnWrongPlace() { $this->expectError("Annotation 'ClassOrPropertyRestrictedAnnotation' not allowed on BadlyAnnotatedClass::method2"); $reflection = new ReflectionAnnotatedClass('BadlyAnnotatedClass'); $method = $reflection->getMethod('method2'); }
public function testSuccesfullyNestedAnnotationThrowsNoError() { $reflection = new ReflectionAnnotatedClass('SuccesfullyAnnotatedClass'); $reflection->getMethod('method2')->getAnnotation('MethodRestrictedAnnotation'); }
static function page_load() { self::magic_quotes_gpc_off(); session_start(); global $rule; $uri = self::get_url(); if ("/" == trim($uri)) { $uri .= home_page . "/"; } foreach ($rule as $r) { $filter = str_replace("{*}", "(.*)", $r["alias"]); $filter = str_replace("/", "\\/", $filter); if (eregi($filter, $uri)) { preg_match("/^{$filter}/U", $uri, $matches); $uri = str_replace($matches[0], "", $uri); array_shift($matches); $page_args = array(); for ($i = 0; $i < count($matches); $i++) { $param = $r["request"][$i]; if (empty($param)) { $param = "param_{$i}"; } $page_args[$param] = $matches[$i]; } $class_name = $r["class"]; $class_path = controller_root . "/" . $r["file"]; $items = trim($uri, "/"); $items = split("/", $items); if ($r["method"]) { $method = $r["method"]; } else { if (count($items) && !($method = array_shift($items))) { $method = "index"; } } $method_arguments = $items; break; } } if (!file_exists($class_path)) { die("Page Not Found"); } else { require_once $class_path; } if (!method_exists($class_name, $method)) { die("Action Not Found"); } else { self::set_module_name($class_name); self::set_action_name($method); eval("\$class = new {$class_name}();"); $class->page_parameters = (array) $page_args; $reflection = new ReflectionAnnotatedClass($class); $r = $reflection->getMethod($method); // Attribute Page'e parametre olarak aldığı sınıfın instanceof ile kontrol eder. // Ornegin View Interface'inden implement edilmis ise View Layout bilgilerini alir gibi. $attributes = $r->getAnnotations(); foreach ($attributes as $attr) { $attr->Run(&$class); } # $output = array(); # $method_arguments = array($method_arguments, &$output); call_user_method_array($method, $class, $method_arguments); // TODO: // if ($class instanceof IView) { // $class->view->items = array_merge($output, $class->view->items); // } // if ($class->is_serialize) { // $class->serialize(); // } // else { // $class->render(); // } // var_dump($output); } }