Пример #1
0
 /**
  * Ads a complexType tag with xmlschema content to the types tag
  * @param string The variable type (Array or class name)
  * @param string The variable name
  * @param domNode Used when adding an inline complexType
  * @return domNode The complexType node
  */
 public function addComplexType($type, $name = false, $parent = false)
 {
     if (!$parent) {
         //outline element
         //check if the complexType doesn't already exists
         if (isset($this->types[$name])) {
             return $this->types[$name];
         }
         //create the complexType tag beneath the xsd:schema tag
         $complexTypeTag = $this->addElement("xsd:complexType", $this->parentElement);
         if ($name) {
             //might be an anonymous element
             $complexTypeTag->setAttribute("name", $name);
             $this->types[$name] = $complexTypeTag;
         }
     } else {
         //inline element
         $complexTypeTag = $this->addElement("xsd:complexType", $parent);
     }
     //check if its an array
     if (strtolower(substr($type, 0, 6)) == 'array(' || substr($type, -2) == '[]') {
         $this->addArray($type, $complexTypeTag);
     } else {
         //it should be an object
         $tag = $this->addElement("xsd:all", $complexTypeTag);
         //check if it has the name 'object()' (kind of a stdClass)
         if (strtolower(substr($type, 0, 6)) == 'object') {
             //stdClass
             $content = substr($type, 7, strlen($type) - 1);
             $properties = split(",", $content);
             //split the content into properties
             foreach ((array) $properties as $property) {
                 if ($pos = strpos($property, "=>")) {
                     //array with keys (order is important, so use 'sequence' tag)
                     $keyType = substr($property, 6, $pos - 6);
                     $valueType = substr($property, $pos + 2, strlen($property) - 7);
                     $el->{$this}->addTypeElement($valueType, $keyType, $tag);
                 } else {
                     throw new WSDLException("Error creating WSDL: expected \"=>\". When using the object() as type, use it as object(paramname=>paramtype,paramname2=>paramtype2)");
                 }
             }
         } else {
             //should be a known class
             if (!class_exists($name)) {
                 throw new WSDLException("Error creating WSDL: no class found with the name '{$name}' / {$type} : {$parent}, so how should we know the structure for this datatype?");
             }
             $v = new IPReflectionClass($name);
             //TODO: check if the class extends another class?
             $properties = $v->getProperties(false, false);
             //not protected and private properties
             foreach ((array) $properties as $property) {
                 if (!$property->isPrivate) {
                     $el = $this->addTypeElement($property->type, $property->name, $tag, $property->optional);
                 }
             }
         }
     }
     return $complexTypeTag;
 }
Пример #2
0
 public function testMethodAnnotations()
 {
     $rel = new IPReflectionClass('extendedAnnotationTestClass');
     $methods = $rel->getMethods();
     $method = $methods['methodB'];
     $ann = $method->getAnnotation('Controller', 'testExtendedAnnotationContainer');
     $this->assertInternalType('object', $ann);
     $this->assertInstanceOf('testExtendedAnnotationContainer', $ann);
     $this->assertEquals(testExtendedAnnotationContainer::TYPE_HTML, $ann->type);
     $this->assertEquals(215, $ann->length);
 }
 /**
  * Ads a complexType tag with xmlschema content to the types tag
  * @param string The variable type (Array or class name)
  * @param string The variable name
  * @param domNode Used when adding an inline complexType
  * @return domNode The complexType node
  */
 public function addComplexType($type, $name = false, $parent = false)
 {
     if (!$parent) {
         //outline element
         if (substr($name, -4) == '[=>]') {
             $name = substr($name, 0, strlen($name) - 4);
         }
         //check if the complexType doesn't already exists
         if (isset($this->types[$name])) {
             return $this->types[$name];
         }
         //create the complexType tag beneath the xsd:schema tag
         $complexTypeTag = $this->addElement("xsd:complexType", $this->parentElement);
         if ($name) {
             //might be an anonymous element
             $complexTypeTag->setAttribute("name", $name);
             $this->types[$name] = $complexTypeTag;
         }
     } else {
         //inline element
         $complexTypeTag = $this->addElement("xsd:complexType", $parent);
     }
     //check if its an array
     if (strtolower(substr($type, 0, 6)) == 'array(' || substr($type, -2) == '[]') {
         $this->addArray($type, $complexTypeTag);
     } else {
         //it should be an object
         if (substr($type, -4) == '[=>]') {
             $type = substr($type, 0, strlen($type) - 4);
             echo "\nAdd type element :{$type} \n";
             $this->addTypeElement($type, $name, $complexTypeTag);
         } else {
             //should be a known class
             $tag = $this->addElement("xsd:all", $complexTypeTag);
             if (!class_exists($name, FALSE)) {
                 throw new WSDLException("Error creating WSDL: no class found with the name '{$name}' / {$type} : {$parent}, so how should we know the structure for this datatype?");
             }
             $v = new IPReflectionClass($name);
             //TODO: check if the class extends another class?
             $properties = $v->getProperties(false, false, false);
             //not protected and private properties
             foreach ((array) $properties as $property) {
                 if (!$property->isPrivate) {
                     $el = $this->addTypeElement($property->type, $property->name, $tag, $property->optional);
                 }
             }
         }
     }
     return $complexTypeTag;
 }
Пример #4
0
 /**
  * Load the class or service definition for doc purpose
  * @param string $classname Name of the class for witch we want the doc, default doc is the service one (controller)
  */
 public function doc($className = "")
 {
     if ($className != "") {
         if (!class_exists($className, false)) {
             throw new jException('jelix~errors.ad.controller.class.unknown', array('WSDL generation', $className, $this->_ctrlpath));
         }
         $classObject = new IPReflectionClass($className);
     } else {
         $classObject = new IPReflectionClass($this->controllerClassName);
     }
     $documentation = array();
     $documentation['menu'] = array();
     if ($classObject) {
         $classObject->properties = $classObject->getProperties(false, false, false);
         $classObject->methods = $classObject->getMethods(false, false, false);
         foreach ((array) $classObject->methods as $method) {
             $method->params = $method->getParameters();
         }
         $documentation['class'] = $classObject;
         $documentation['service'] = $this->module . '~' . $this->controller;
     }
     return $documentation;
 }
Пример #5
0
 /**
  * Ads a complexType tag with xmlschema content to the types tag.
  *
  * @param string The variable type (Array or class name)
  * @param string The variable name
  * @param domNode Used when adding an inline complexType
  *
  * @return domNode The complexType node
  */
 protected function addComplexType($type, $name = false, $parent = false)
 {
     if (!$parent) {
         //outline element
         //check if the complexType doesn't already exists
         if (isset($this->types[$name])) {
             return $this->types[$name];
         }
         //create the complexType tag beneath the xsd:schema tag
         $complexTypeTag = $this->addElement('xsd:complexType', $this->parentElement);
         if ($name) {
             //might be an anonymous element
             $complexTypeTag->setAttribute('name', $name);
             $this->types[$name] = $complexTypeTag;
         }
     } else {
         //inline element
         $complexTypeTag = $this->addElement('xsd:complexType', $parent);
     }
     $tag = $this->addElement('xsd:all', $complexTypeTag);
     //check if it has the name 'object()' (kind of a stdClass)
     if (strtolower(substr($type, 0, 6)) == 'object') {
         //stdClass
         $content = substr($type, 7, -1);
         $properties = explode(',', $content);
         //split the content into properties
         foreach ($properties as $property) {
             if (strpos($property, '=>') !== false) {
                 //array with keys (order is important, so use 'sequence' tag)
                 list($keyType, $valueType) = explode('=>', $property);
                 $el = $this->addTypeElement($valueType, $keyType, $tag);
             } else {
                 throw new WSDLException('Error creating WSDL: expected "=>". When using the object() as type, use it as object(paramname=>paramtype,paramname2=>paramtype2)', 100);
             }
         }
     } else {
         //should be a known class
         if (!class_exists($name)) {
             throw new WSDLException("Error creating WSDL: no class found with the name '{$name}' / {$type} : {$parent}, so how should we know the structure for this datatype?", 101);
         }
         $v = new IPReflectionClass($name);
         $properties = $v->getProperties(false, false, false);
         //not protected and private properties
         foreach ((array) $properties as $property) {
             if (!$property->isPrivate) {
                 $el = $this->addTypeElement($property->type, $property->name, $tag, $property->optional);
             }
         }
     }
     return $complexTypeTag;
 }
Пример #6
0
}
/**
 * @ann1('me'=>'you');
 */
class something
{
    /**
     * @var string
     * @Controller(type => DefaultController::TYPE_PLAIN, length => 100)
     */
    public $propertyA;
    /**
     * @var string
     * @Controller(type => DefaultController::TYPE_HTML, length => 100)
     */
    public function methodB()
    {
        return "aap";
    }
}
/* Annotation example */
$rel = new IPReflectionClass("something");
$properties = $rel->getProperties();
$methods = $rel->getMethods();
var_dump($rel->getAnnotation("ann1", "stdClass"));
$property = $properties["propertyA"];
$ann = $property->getAnnotation("Controller", "DefaultController");
var_dump($ann);
$method = $methods["methodB"];
$ann = $method->getAnnotation("Controller", "DefaultController");
var_dump($ann);