Ejemplo n.º 1
0
 public static function inspectClass(ReflectionClass $clazz)
 {
     /*Method[]*/
     $methods = $clazz->getMethods();
     /*ServiceDescriptor*/
     $serviceDescriptor = new ServiceDescriptor($clazz);
     for ($i = 0, $max = count($methods); $i < $max; $i++) {
         /*MethodDescriptor*/
         $descriptor = new MethodDescriptor();
         $descriptor->setMethodName($methods[$i]->getName());
         //      /*Class*/ $returnType = $methods[ $i ].getReturnType();
         $descriptor->setReturnType("Object");
         /*ReflectionParameter[]*/
         $args = $methods[$i]->getParameters();
         for ($k = 0, $arglen = count($args); $k < $arglen; $k++) {
             /*ArgumentDescriptor*/
             $argDesc = new ArgumentDescriptor();
             $argDesc->setArgumentName("arg" . $k);
             $argDesc->setArgumentType($args[$k]->isArray() ? "Array of Object" : $args[$k]->getDeclaringClass()->getName());
             $descriptor->addArgument($argDesc);
         }
         $serviceDescriptor->addMethod($descriptor);
     }
     return $serviceDescriptor;
 }
Ejemplo n.º 2
0
 /**
  * Generates class description and write it to buffer
  *
  * @param FileDescriptor $descriptor  File descriptor
  * @param ServiceDescriptor $descriptor  Service descriptor
  * @param CodeStringBuffer  $buffer  Buffer to write code to
  *
  * @return null
  */
 private function _createService(FileDescriptor $file, ServiceDescriptor $descriptor, CodeStringBuffer $buffer)
 {
     $name = $descriptor->getName();
     $class_frame = "class " . $name . " extends " . self::SERVICE_CLASS . "\n{";
     $buffer->append($class_frame);
     $register_func = 'Register';
     foreach ($descriptor->getMethods() as $method) {
         $register_func = $register_func . $this->_createRegisterMethod($file, $method, $buffer);
         $buffer->append('');
     }
     $buffer->append('function __construct($server_address)')->append('{')->increaseIdentation()->append('$this->InitService($server_address, ' . '\'' . $file->getPackage() . '\'' . ', ' . '\'' . $descriptor->getName() . '\')' . ';')->append('$this->' . $register_func . '()' . ';')->append('$this->InitMethods();')->decreaseIdentation()->append('}');
     foreach ($descriptor->getMethods() as $method) {
         $this->_createUserMethod($method, $buffer);
         $this->_createServiceCommonMethod($buffer);
     }
     $buffer->decreaseIdentation()->append('}');
 }