Beispiel #1
0
 /**
  * Get filename to export rendered declaration into.
  *
  * @return ClassElement
  */
 public function getFilename()
 {
     $filename = $this->options['directory'] . FilesInterface::SEPARATOR;
     //Default namespace already included into path
     $namespace = trim(substr($this->file->getNamespace(), strlen($this->options['namespace']) + 1), '\\');
     $filename .= str_replace('\\', FilesInterface::SEPARATOR, $namespace);
     return $filename . FilesInterface::SEPARATOR . $this->class->getName() . static::EXTENSION;
 }
Beispiel #2
0
 /**
  * Generate virtual entity representation.
  *
  * @param ReflectionEntity $entity
  * @return ClassElement
  */
 protected function renderEntity(ReflectionEntity $entity)
 {
     $element = new ClassElement($entity->getShortName());
     //We are going to render every entity property as real property due child implementation
     //may clarify it's type
     foreach ($entity->getFields() as $field => $type) {
         if (substr($field, 0, 1) == '_') {
             //Hidden fields
             continue;
         }
         $classType = '';
         $arrayType = false;
         if (is_array($type)) {
             $arrayType = true;
             $type = $type[0];
         }
         $type = str_replace('[]', '', $type);
         if (lcfirst($type) != $type && class_exists($type)) {
             $type = $classType = '\\' . $type;
         }
         if ($arrayType) {
             $type .= '[]';
         }
         $element->property($field, "@var {$type}")->setAccess(AbstractElement::ACCESS_PUBLIC);
         //Let's pre-generate getters and setters
         $setter = $element->method('set' . Inflector::classify($field));
         $getter = $element->method('get' . Inflector::classify($field));
         $setter->parameter($field, $type);
         if (!empty($arrayType)) {
             $setter->parameter($field)->setType('array');
         } elseif (!empty($classType)) {
             $setter->parameter($field)->setType($classType);
         }
         $setter->setComment("@return \$this", true);
         $getter->setComment("@return {$type}");
     }
     foreach ($entity->getAccessors() as $name => $accessor) {
         if (is_array($accessor)) {
             $accessor = $accessor[0];
         }
         $element->property($name, '@var \\' . $accessor);
         $element->method('get' . Inflector::classify($name))->setComment("@return \\" . $accessor);
     }
     return $element;
 }
Beispiel #3
0
 /**
  * Remove unnesessary element methods.
  *
  * @param ClassElement $element
  */
 private function cleanElement(ClassElement $element)
 {
     foreach ($element->getProperties() as $property) {
         $element->removeProperty($property->getName());
     }
     foreach ($element->getConstants() as $constant => $value) {
         $element->removeConstant($constant);
     }
     foreach ($element->getMethods() as $method) {
         //Remove all static, protected or magic methods
         if ($method->isStatic() || $method->getAccess() != AbstractElement::ACCESS_PUBLIC || substr($method->getName(), 0, 2) == '__') {
             $element->removeMethod($method->getName());
         }
         $comment = join("\n", $method->getComment());
         if (strpos($comment, "Record") === false && strpos($comment, "\$this") === false && $method->getName() != 'getIterator') {
             //We don't need methods not related to retrieving documents
             $element->removeMethod($method->getName());
         }
     }
 }