Beispiel #1
1
 public static function run()
 {
     foreach (glob(app_path() . '/Http/Controllers/*.php') as $filename) {
         $file_parts = explode('/', $filename);
         $file = array_pop($file_parts);
         $file = rtrim($file, '.php');
         if ($file == 'Controller') {
             continue;
         }
         $controllerName = 'App\\Http\\Controllers\\' . $file;
         $controller = new $controllerName();
         if (isset($controller->exclude) && $controller->exclude === true) {
             continue;
         }
         $methods = [];
         $reflector = new \ReflectionClass($controller);
         foreach ($reflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $rMethod) {
             // check whether method is explicitly defined in this class
             if ($rMethod->getDeclaringClass()->getName() == $reflector->getName()) {
                 $methods[] = $rMethod->getName();
             }
         }
         \Route::resource(strtolower(str_replace('Controller', '', $file)), $file, ['only' => $methods]);
     }
 }
Beispiel #2
0
 /**
  * Derives properties from constructor, public instance variables, getters and setters.
  *
  * @param object|null $object If provided, dynamic (run-time) variables are read as well
  * @return \watoki\collections\Map|Property[] indexed by property name
  */
 public function readInterface($object = null)
 {
     $properties = new Map();
     if ($this->class->getConstructor()) {
         foreach ($this->class->getConstructor()->getParameters() as $parameter) {
             $this->accumulate($properties, new property\ConstructorProperty($this->factory, $this->class->getConstructor(), $parameter));
         }
     }
     $declaredProperties = array();
     foreach ($this->class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
         if (!$property->isStatic()) {
             $declaredProperties[] = $property->name;
             $this->accumulate($properties, new property\InstanceVariableProperty($this->factory, $property));
         }
     }
     if (is_object($object)) {
         foreach ($object as $name => $value) {
             if (!in_array($name, $declaredProperties)) {
                 $this->accumulate($properties, new property\DynamicProperty($this->factory, new \ReflectionClass($object), $name));
             }
         }
     }
     foreach ($this->class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         if (property\AccessorProperty::isAccessor($method) && !$method->isStatic()) {
             $this->accumulate($properties, new property\AccessorProperty($this->factory, $method));
         }
     }
     return $properties;
 }
 protected function _parseMethods()
 {
     $methods = $this->_class->getMethods();
     foreach ($methods as $method) {
         $this->_methods[] = new AnnotatedMethod($method);
     }
 }
 /**
  * Exports the PHP code
  *
  * @return string
  */
 public function exportCode()
 {
     $code_lines = array();
     $code_lines[] = '<?php';
     // Export the namespace
     if ($this->_reflection_class->getNamespaceName()) {
         $code_lines[] = '';
         $code_lines[] = 'namespace ' . $this->_reflection_class->getNamespaceName() . ';';
         $code_lines[] = '';
     }
     // Export the class' signature
     $code_lines[] = sprintf('%s%s%s %s%s%s', $this->_reflection_class->isAbstract() ? 'abstract ' : '', $this->_reflection_class->isFinal() ? 'final ' : '', $this->_reflection_class->isInterface() ? 'interface' : ($this->_reflection_class->isTrait() ? 'trait' : 'class'), $this->getClassName(), $this->_getParentClassName() ? " extends {$this->_getParentClassName()}" : '', $this->_getInterfaceNames() ? " implements " . join(', ', $this->_getInterfaceNames()) : '');
     $code_lines[] = '{';
     $code_lines[] = '';
     // Export constants
     foreach ($this->_reflection_class->getConstants() as $name => $value) {
         $reflection_constant = new ReflectionConstant($name, $value);
         $code_lines[] = "\t" . $reflection_constant->exportCode();
         $code_lines[] = '';
     }
     // Export properties
     foreach ($this->_reflection_class->getProperties() as $property) {
         $reflection_property = new ReflectionProperty($property);
         $code_lines[] = "\t" . $reflection_property->exportCode();
         $code_lines[] = '';
     }
     // Export methods
     foreach ($this->_reflection_class->getMethods() as $method) {
         $reflection_method = new ReflectionMethod($method);
         $code_lines[] = "\t" . $reflection_method->exportCode();
         $code_lines[] = '';
     }
     $code_lines[] = '}';
     return join("\n", $code_lines);
 }
Beispiel #5
0
 /**
  * Call to undefined static method.
  * @throws LogicException
  */
 public static function __callStatic($name, $args)
 {
     $rc = new \ReflectionClass(get_called_class());
     $items = array_intersect($rc->getMethods(\ReflectionMethod::IS_PUBLIC), $rc->getMethods(\ReflectionMethod::IS_STATIC));
     $hint = ($t = Helpers::getSuggestion($items, $name)) ? ", did you mean {$t}()?" : '.';
     throw new LogicException("Call to undefined static method {$rc->getName()}::{$name}(){$hint}");
 }
 /**
  * Construct and return Array-Object
  * @param String $class
  * @return Array
  */
 public static function construct($class)
 {
     // If is already an object return the object
     // If not create an instance of the object bypassing a possible
     // class constructor
     if (is_object($class)) {
         $instantiatedClass = $class;
         $class = get_class($class);
     } else {
         $instantiatedClass = self::instantiate($class);
     }
     // Clean arrays
     $properties = array('protected' => array(), 'public' => array());
     $methods = array('protected' => array(), 'public' => array());
     // Reflection get properties and methods names (public and protected)
     $reflect = new \ReflectionClass($instantiatedClass);
     $reflectedClass = array('properties' => array('protected' => $reflect->getProperties(\ReflectionProperty::IS_PROTECTED), 'public' => $reflect->getProperties(\ReflectionProperty::IS_PUBLIC)), 'methods' => array('protected' => $reflect->getMethods(\ReflectionProperty::IS_PROTECTED), 'public' => $reflect->getMethods(\ReflectionProperty::IS_PUBLIC)));
     // Properties foreach's
     foreach ($reflectedClass['properties']['protected'] as $prop) {
         $properties['protected'][] = $prop->name;
     }
     foreach ($reflectedClass['properties']['public'] as $prop) {
         $properties['public'][] = $prop->name;
     }
     // Methods foreach's
     foreach ($reflectedClass['methods']['protected'] as $method) {
         $methods['protected'][] = $method->name;
     }
     foreach ($reflectedClass['methods']['public'] as $method) {
         $methods['public'][] = $method->name;
     }
     // Return Array-Object
     return array('name' => $class, 'object' => $instantiatedClass, 'methods' => $methods, 'properties' => $properties);
 }
 function getMethodNames()
 {
     $ret = [];
     foreach ($this->refl->getMethods() as $method) {
         $ret[] = $method->name;
     }
     return $ret;
 }
 /**
  * @covers PhSpring\Reflection\ReflectionClass::getMethods
  */
 public function testGetMethods()
 {
     $methods = $this->object->getMethods();
     $this->assertInternalType('array', $methods);
     $this->assertNotEmpty($methods);
     $method = array_shift($methods);
     $this->assertInstanceOf(ReflectionMethod::class, $method);
 }
Beispiel #9
0
 /**
  * @param string $className
  */
 private static function mockInjectedMethods($className)
 {
     foreach (self::$reflectedClass->getMethods() as $method) {
         if (substr($method->getName(), 0, 6) === 'inject') {
             self::mockDependenciesFromMethod($className, $method->getName());
         }
     }
 }
Beispiel #10
0
 /**
  * Gets the methods of the object provided.
  *
  * @param int $filter
  *
  * @return array
  */
 public function getMethods($filter = \ReflectionProperty::IS_PUBLIC)
 {
     $methods = array();
     $reflectionMethods = $this->reflectionEntity->getMethods($filter);
     foreach ($reflectionMethods as $method) {
         $methods[] = new Method($method->name, $method->isStatic());
     }
     return $methods;
 }
 /**
  */
 public function testGetMethods()
 {
     $this->assertTrue(is_array($this->object->getMethods()));
     $this->assertEquals(0, count($this->object->getMethods()));
     $method = new ReflectionMethod('testMethod');
     $this->object->addMethod($method);
     $this->assertEquals(1, count($this->object->getMethods()));
     $this->assertEquals($method, array_pop($this->object->getMethods()));
 }
 /**
  * @return bool
  */
 protected function calcHasOwnMethods()
 {
     $class = $this->reflectionClass->getName();
     foreach ($this->reflectionClass->getMethods() as $reflectionMethod) {
         if ($class === $reflectionMethod->getDeclaringClass()->getName()) {
             return TRUE;
         }
     }
     return FALSE;
 }
 /**
  * Returns all calls for the service
  * @return ServiceCallReflector[] An array of ServiceCallReflector objects
  */
 public function getCalls()
 {
     $calls = array();
     foreach ($this->reflClass->getMethods() as $method) {
         if (ServiceCallReflector::isServiceCall($method, $this->reader)) {
             $calls[] = new ServiceCallReflector($method, $this->reader);
         }
     }
     return $calls;
 }
Beispiel #14
0
 /**
  * @return ReflectedMethod[]
  */
 public function getMethods()
 {
     if (NULL === $this->methods) {
         $this->methods = [];
         foreach ($this->reflectionClass->getMethods() as $method) {
             $this->methods[] = new ReflectedMethod($this, $method);
         }
     }
     return $this->methods;
 }
Beispiel #15
0
 /**
  * Get public methods to be exposed over API
  *
  * @return ReflectionMethod[]
  */
 private function getMethods()
 {
     $methods = array();
     foreach ($this->reflectionClass->getMethods() as $method) {
         if ($method->isPublic() && !$method->isStatic() && substr($method->getName(), 0, 2) != '__') {
             $methods[$method->getName()] = $method;
         }
     }
     return $methods;
 }
 public function getPublicStaticMethods()
 {
     $methods = array();
     foreach ($this->reflector->getMethods(ReflectionMethod::IS_STATIC) as $method) {
         if ($method->isPublic() && $method->getDeclaringClass() == $this->reflector) {
             $methods[] = new FactoryMethod($this, $method);
         }
     }
     return $methods;
 }
Beispiel #17
0
 public function setTargetClass($targetClass)
 {
     $this->targetClass = $targetClass;
     $this->reflection = new \ReflectionClass($targetClass);
     $this->methods = $this->reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
     $fileName = $this->reflection->getFileName();
     if (file_exists($fileName)) {
         $this->contents = file_get_contents($fileName);
     }
     return $this;
 }
Beispiel #18
0
 /**
  * Return all test methods present in the file
  *
  * @return array
  */
 private function getMethods()
 {
     $tests = array();
     $methods = $this->refl->getMethods(\ReflectionMethod::IS_PUBLIC);
     foreach ($methods as $method) {
         if (preg_match(self::$testName, $method->getName()) || preg_match(self::$testAnnotation, $method->getDocComment())) {
             $tests[] = new ParsedFunction($method->getDocComment(), 'public', $method->getName());
         }
     }
     return $tests;
 }
 /**
  * @param $class
  * @param $filter ReflectionMethod::IS_STATIC,..
  * @return array
  */
 public static function get_child_class_methods($class, $filter = '')
 {
     $f = new ReflectionClass($class);
     $methods = array();
     foreach ($filter ? $f->getMethods($filter) : $f->getMethods() as $m) {
         if (strtoupper($m->class) == strtoupper($class)) {
             $methods[] = $m->name;
         }
     }
     return $methods;
 }
Beispiel #20
0
 protected function _processActionableMethods()
 {
     $specialtyRegex = '#(.*)(' . implode('|', $this->_specialties) . ')$#i';
     $methods = $this->_providerReflection->getMethods();
     $actionableMethods = array();
     foreach ($methods as $method) {
         $methodName = $method->getName();
         if (!$method->getDeclaringClass()->isInstantiable() || !$method->isPublic() || $methodName[0] == '_') {
             continue;
         }
         $actionableName = ucfirst($methodName);
         if (substr($actionableName, -6) == 'Action') {
             $actionableName = substr($actionableName, 0, -6);
         }
         $actionableMethods[$methodName]['methodName'] = $methodName;
         if (preg_match($specialtyRegex, $actionableName, $matches)) {
             $actionableMethods[$methodName]['actionName'] = $matches[1];
             $actionableMethods[$methodName]['specialty'] = $matches[2];
         } else {
             $actionableMethods[$methodName]['actionName'] = $actionableName;
             $actionableMethods[$methodName]['specialty'] = '_Global';
         }
         $actionableMethods[$methodName]['action'] = ZendL_Tool_Rpc_Provider_Registry::getInstance()->getAction($actionableMethods[$methodName]['actionName']);
         if (!in_array($actionableMethods[$methodName]['action'], $this->_actions)) {
             $this->_actions[] = $actionableMethods[$methodName]['action'];
         }
         $parameterInfo = array();
         $position = 1;
         foreach ($method->getParameters() as $parameter) {
             $currentParam = $parameter->getName();
             $parameterInfo[$currentParam]['position'] = $position++;
             $parameterInfo[$currentParam]['optional'] = $parameter->isOptional();
             $parameterInfo[$currentParam]['default'] = $parameter->isOptional() ? $parameter->getDefaultValue() : null;
             $parameterInfo[$currentParam]['name'] = $currentParam;
             $parameterInfo[$currentParam]['type'] = 'string';
             $parameterInfo[$currentParam]['description'] = null;
         }
         if (($docComment = $method->getDocComment()) != '' && preg_match_all('/@param\\s+(\\w+)+\\s+(\\$\\S+)\\s+(.*?)(?=(?:\\*\\s*@)|(?:\\*\\/))/s', $docComment, $matches)) {
             for ($i = 0; $i <= count($matches[0]) - 1; $i++) {
                 $currentParam = ltrim($matches[2][$i], '$');
                 if ($currentParam != '' && isset($parameterInfo[$currentParam])) {
                     $parameterInfo[$currentParam]['type'] = $matches[1][$i];
                     $descriptionSource = $matches[3][$i];
                     if ($descriptionSource != '') {
                         $parameterInfo[$currentParam]['description'] = trim($descriptionSource);
                     }
                 }
             }
         }
         $actionableMethods[$methodName]['parameterInfo'] = $parameterInfo;
     }
     $this->_actionableMethods = $actionableMethods;
 }
 /**
  * @param string $classname The class to inspect
  * @param Reader $reader The annotation reader
  * @throws ClassNotFoundException
  */
 public function __construct($classname, Reader $reader)
 {
     try {
         $this->className = $classname;
         $this->reader = $reader;
         $this->reflectionClass = new \ReflectionClass($classname);
         $this->reflectionMethods = $this->reflectionClass->getMethods();
         $this->reflectionProperties = $this->reflectionClass->getProperties();
     } catch (\Exception $ex) {
         throw new ClassNotFoundException(sprintf("cannot find class %s", $classname), $ex->getCode(), $ex);
     }
 }
Beispiel #22
0
 /**
  * Loops through all of the methods and builds items/maps
  * for them.
  */
 public function buildMethods()
 {
     $methods = $this->_reflect->getMethods();
     foreach ($methods as $method) {
         foreach ($this->_optionsFrom($method) as $options) {
             if ($method->getName() == '__construct') {
                 $options['injectWith'] = 'constructor';
             } else {
                 $options['injectWith'] = 'method';
                 $options['injectAs'] = $method->getName();
             }
             $this->_map->add($this->_makeItemFromOptions($options));
         }
     }
 }
 /**
  * @param \Donquixote\HastyReflectionCommon\Canvas\ClassIndex\ClassIndexInterface $classIndex
  * @param string $class
  *
  * @dataProvider provideClassIndexArgs()
  */
 function testClassIndex(ClassIndexInterface $classIndex, $class)
 {
     $classReflection = $classIndex->classGetReflection($class);
     $reflectionClass = new \ReflectionClass($class);
     // Test identity.
     $this->assertTrue($classReflection === $classIndex->classGetReflection($class));
     // Test class type/info.
     $expectedIsClass = !$reflectionClass->isInterface() && !$reflectionClass->isTrait();
     $this->assertEquals($reflectionClass->getName(), $classReflection->getName());
     $this->assertEquals($reflectionClass->getShortName(), $classReflection->getShortName());
     $this->assertEquals($reflectionClass->getDocComment(), $classReflection->getDocComment());
     $this->assertEquals($reflectionClass->isInterface(), $classReflection->isInterface());
     $this->assertEquals($reflectionClass->isTrait(), $classReflection->isTrait());
     $this->assertEquals($expectedIsClass, $classReflection->isClass());
     $this->assertEquals($reflectionClass->isAbstract() && $expectedIsClass, $classReflection->isAbstractClass());
     // Test context.
     $this->assertEquals($reflectionClass->getNamespaceName(), $classReflection->getNamespaceUseContext()->getNamespaceName());
     // Test interfaces
     foreach ($classReflection->getOwnInterfaces() as $interfaceName => $interfaceReflection) {
         $this->assertTrue($reflectionClass->implementsInterface($interfaceName));
     }
     foreach ($reflectionClass->getInterfaceNames() as $interfaceName) {
         $this->assertTrue($classReflection->extendsOrImplementsInterface($interfaceName, FALSE));
     }
     $expectedAllInterfaceNames = $expectedAllAndSelfInterfaceNames = $reflectionClass->getInterfaceNames();
     if ($reflectionClass->isInterface()) {
         array_unshift($expectedAllAndSelfInterfaceNames, $class);
     }
     $this->assertEqualSorted($expectedAllAndSelfInterfaceNames, array_keys($classReflection->getAllInterfaces(TRUE)));
     $this->assertEqualSorted($expectedAllInterfaceNames, array_keys($classReflection->getAllInterfaces(FALSE)));
     $expectedMethodNames = array();
     $expectedOwnMethodNames = array();
     foreach ($reflectionClass->getMethods() as $method) {
         $expectedMethodNames[] = $method->getName();
         if ($method->getDeclaringClass()->getName() === $reflectionClass->getName()) {
             $expectedOwnMethodNames[] = $method->getName();
         }
     }
     $this->assertEquals($expectedOwnMethodNames, array_keys($classReflection->getOwnMethods()));
     $this->assertEqualSorted($expectedMethodNames, array_keys($classReflection->getMethods()));
     $methodReflections = $classReflection->getMethods();
     foreach ($reflectionClass->getMethods() as $reflectionMethod) {
         $methodReflection = $methodReflections[$reflectionMethod->getShortName()];
         $this->assertEqualMethods($reflectionMethod, $methodReflection);
     }
     // isAbstract() is a beast, so we test it least.
     $this->assertEquals($reflectionClass->isAbstract(), $classReflection->isAbstract());
 }
Beispiel #24
0
 function __construct($_sFeaturePath, $_iPort = 16816)
 {
     openlog("cuke4php", LOG_PID, LOG_DAEMON);
     if (is_file($_sFeaturePath)) {
         $_sFeaturePath = dirname($_sFeaturePath);
     }
     if ($_iPort > 0) {
         $this->iPort = $_iPort;
     } else {
         $this->iPort = 16816;
     }
     foreach (self::rglob("*.php", 0, $_sFeaturePath . "/support") as $sFilename) {
         require_once $sFilename;
     }
     set_error_handler(array('PHPUnit_Util_ErrorHandler', 'handleError'), E_ALL | E_STRICT);
     require_once "Cucumber.php";
     foreach (self::rglob("*.php", 0, $_sFeaturePath . "/step_definitions") as $sFilename) {
         require_once $sFilename;
     }
     $this->aStepClasses = CucumberSteps::getSubclasses();
     foreach ($this->aStepClasses as $sClass) {
         $oReflection = new ReflectionClass($sClass);
         $aMethods = $oReflection->getMethods();
         foreach ($aMethods as $oMethod) {
             $sComment = $oMethod->getDocComment();
             $aMatches = array();
             $aMethod = array();
             $aMethod['method'] = $oMethod->name;
             $aMethod['class'] = $oMethod->class;
             $aMethod['filename'] = $oMethod->getFileName();
             $aMethod['startline'] = $oMethod->getStartLine();
             if (substr($oMethod->name, 0, 4) === "step") {
                 preg_match("/(?:Given|When|Then) (.+)\$/im", $sComment, $aMatches);
                 $aMethod['regexp'] = $aMatches[1];
                 $this->aWorld['steps'][] = $aMethod;
                 continue;
             }
             preg_match("/(@.+)/im", $sComment, $aMatches);
             if (array_key_exists(1, $aMatches)) {
                 $aMethod['tags'] = explode(" ", str_replace("@", "", $aMatches[1]));
             } else {
                 $aMethod['tags'] = array();
             }
             if (substr($oMethod->name, 0, 6) === "before") {
                 $this->aWorld['before'][] = $aMethod;
                 continue;
             }
             if (substr($oMethod->name, 0, 5) === "after") {
                 $this->aWorld['after'][] = $aMethod;
                 continue;
             }
             if (substr($oMethod->name, 0, 9) == "transform") {
                 preg_match("/(?:Transform) (.+)\$/im", $sComment, $aMatches);
                 $aMethod['regexp'] = $aMatches[1];
                 $this->aWorld['transform'][] = $aMethod;
                 continue;
             }
         }
     }
 }
Beispiel #25
0
 /**
  * {@inheritdoc}
  */
 public function getProperties($class, array $context = array())
 {
     try {
         $reflectionClass = new \ReflectionClass($class);
     } catch (\ReflectionException $reflectionException) {
         return;
     }
     $reflectionProperties = $reflectionClass->getProperties();
     $properties = array();
     foreach ($reflectionProperties as $reflectionProperty) {
         if ($reflectionProperty->isPublic()) {
             $properties[$reflectionProperty->name] = true;
         }
     }
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $reflectionMethod) {
         $propertyName = $this->getPropertyName($reflectionMethod->name, $reflectionProperties);
         if (!$propertyName || isset($properties[$propertyName])) {
             continue;
         }
         if (!preg_match('/^[A-Z]{2,}/', $propertyName)) {
             $propertyName = lcfirst($propertyName);
         }
         $properties[$propertyName] = true;
     }
     return array_keys($properties);
 }
Beispiel #26
0
 /**
  * @param  \ReflectionClass|string
  * @return self
  */
 public static function from($from)
 {
     $from = new \ReflectionClass($from instanceof \ReflectionClass ? $from->getName() : $from);
     if (PHP_VERSION_ID >= 70000 && $from->isAnonymous()) {
         $class = new static('anonymous');
     } else {
         $class = new static($from->getShortName(), new PhpNamespace($from->getNamespaceName()));
     }
     $class->type = $from->isInterface() ? 'interface' : (PHP_VERSION_ID >= 50400 && $from->isTrait() ? 'trait' : 'class');
     $class->final = $from->isFinal() && $class->type === 'class';
     $class->abstract = $from->isAbstract() && $class->type === 'class';
     $class->implements = $from->getInterfaceNames();
     $class->documents = $from->getDocComment() ? array(preg_replace('#^\\s*\\* ?#m', '', trim($from->getDocComment(), "/* \r\n\t"))) : array();
     if ($from->getParentClass()) {
         $class->extends = $from->getParentClass()->getName();
         $class->implements = array_diff($class->implements, $from->getParentClass()->getInterfaceNames());
     }
     foreach ($from->getProperties() as $prop) {
         if ($prop->getDeclaringClass()->getName() === $from->getName()) {
             $class->properties[$prop->getName()] = Property::from($prop);
         }
     }
     foreach ($from->getMethods() as $method) {
         if ($method->getDeclaringClass()->getName() === $from->getName()) {
             $class->methods[$method->getName()] = Method::from($method)->setNamespace($class->namespace);
         }
     }
     return $class;
 }
 public static function saveCorrectDataWithReflection()
 {
     $defaultControllerPath = "controllers\\defaultControllers\\";
     $controllerFileNames = scandir($defaultControllerPath, 1);
     $settingsArrayWithAllControllersAndActions = [];
     $num = 0;
     foreach ($controllerFileNames as $item) {
         $fileName = "controllers\\defaultControllers\\" . $item;
         if (strpos($item, "Controller")) {
             $clasFileName = substr($fileName, 0, -4);
             require_once $fileName;
             $currentClass = new $clasFileName();
             $reflection = new \ReflectionClass($currentClass);
             $methods = $reflection->getMethods();
             foreach ($methods as $i => $method) {
                 $docBlock = $method->getDocComment();
                 $pattern = "/Route\\(([A-Za-z]+)\\/([A-Za-z]+)\\)/";
                 preg_match($pattern, $docBlock, $routeMatch);
                 if (count($routeMatch) > 0) {
                     $objectToSave = (object) array("Controller" => $reflection->getName(), "Action" => $method->getName(), "CustomController" => $routeMatch[1], "CustomAction" => $routeMatch[2]);
                     $num++;
                     array_push($settingsArrayWithAllControllersAndActions, $objectToSave);
                     //echo '<pre>'; print_r($objectToSave); echo '</pre>';
                 }
             }
         }
     }
     $fp = fopen('config/customRoutes.json', 'w');
     fwrite($fp, json_encode($settingsArrayWithAllControllersAndActions));
     fclose($fp);
     //        echo '<pre>';
     //        print_r( json_encode($objectToSave));
     //        echo '</pre>';
 }
 protected function makeConfiguration($packageConfiguration, $resourceName)
 {
     $class = DefinitionHelper::getClassImplementation($this->container, $resourceName, static::NAME, static::BASE_CLASS);
     $refClass = new \ReflectionClass($class);
     $methods = $refClass->getMethods();
     $reader = $this->container->get('AnnotationReader');
     $calls = array();
     foreach ($methods as $method) {
         $annotations = $reader->getMethodAnnotations($method);
         foreach ($annotations as $annotation) {
             if ($annotation instanceof \EVFramework\Annotation\GeneratorCallDICIT) {
                 $calls[$method->getName()] = array("@" . DefinitionHelper::getServiceName($this->container, $annotation->getResource(), $annotation->getType()));
             }
         }
         if ($method->getName() == 'setContainer') {
             $calls[$method->getName()] = array('$container');
         }
     }
     $configuration = array('class' => $class, 'singleton' => 'true', 'arguments' => array('$container', $resourceName));
     if (count($calls)) {
         $configuration['call'] = $calls;
     }
     // var_export($configuration);
     // die();
     return $configuration;
 }
Beispiel #29
0
 public function getModuleActions($module_class, $use_admin_prefix = false)
 {
     $actions = array();
     $controllers_dir = MODULES_PATH . lcfirst(str_replace('Module', '', $module_class)) . '/controllers/';
     $controllers = scandir($controllers_dir);
     foreach ($controllers as $controller) {
         if ($controller[0] == ".") {
             continue;
         }
         $class = str_replace('.php', '', $controller);
         if (!class_exists($class, false)) {
             require_once $controllers_dir . $controller;
         }
         $reflection = new ReflectionClass($class);
         if (!in_array($reflection->getParentClass()->name, array('BaseController', 'AdminController'))) {
             continue;
         }
         $actions_titles = call_user_func(array($class, 'actionsTitles'));
         $methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
         foreach ($methods as $method) {
             if (in_array($method->name, array('actionsTitles', 'actions')) || mb_substr($method->name, 0, 6, 'utf-8') != 'action') {
                 continue;
             }
             $action = str_replace('action', '', $method->name);
             $action_name = str_replace('Controller', '', $class) . '_' . $action;
             $title = isset($actions_titles[$action]) ? $actions_titles[$action] : "";
             if ($title && $use_admin_prefix && strpos($action_name, "Admin_") !== false) {
                 $title .= " (админка)";
             }
             $actions[$action_name] = $title;
         }
     }
     return $actions;
 }
 function procesar()
 {
     toba::logger_ws()->debug('Servicio Llamado: ' . $this->info['basica']['item']);
     toba::logger_ws()->set_checkpoint();
     set_error_handler('toba_logger_ws::manejador_errores_recuperables', E_ALL);
     $this->validar_componente();
     //-- Pide los datos para construir el componente, WSF no soporta entregar objetos creados
     $clave = array();
     $clave['proyecto'] = $this->info['objetos'][0]['objeto_proyecto'];
     $clave['componente'] = $this->info['objetos'][0]['objeto'];
     list($tipo, $clase, $datos) = toba_constructor::get_runtime_clase_y_datos($clave, $this->info['objetos'][0]['clase'], false);
     agregar_dir_include_path(toba_dir() . '/php/3ros/wsf');
     $opciones_extension = toba_servicio_web::_get_opciones($this->info['basica']['item'], $clase);
     $wsdl = strpos($_SERVER['REQUEST_URI'], "?wsdl") !== false;
     $sufijo = 'op__';
     $metodos = array();
     $reflexion = new ReflectionClass($clase);
     foreach ($reflexion->getMethods() as $metodo) {
         if (strpos($metodo->name, $sufijo) === 0) {
             $servicio = substr($metodo->name, strlen($sufijo));
             $prefijo = $wsdl ? '' : '_';
             $metodos[$servicio] = $prefijo . $metodo->name;
         }
     }
     $opciones = array();
     $opciones['serviceName'] = $this->info['basica']['item'];
     $opciones['classes'][$clase]['operations'] = $metodos;
     $opciones = array_merge($opciones, $opciones_extension);
     $this->log->debug("Opciones del servidor: " . var_export($opciones, true), 'toba');
     $opciones['classes'][$clase]['args'] = array($datos);
     toba::logger_ws()->set_checkpoint();
     $service = new WSService($opciones);
     $service->reply();
     $this->log->debug("Fin de servicio web", 'toba');
 }