Пример #1
0
 public function onBeforeGenerate(AbstractMetaSpec $spec, MetaSpecMatcher $matcher, Type $type)
 {
     $hasDefaultElement = false;
     foreach ($type->getAnnotations("Skrz\\Meta\\XML\\XmlElement") as $xmlElement) {
         /** @var XmlElement $xmlElement */
         if ($xmlElement->name === null) {
             $xmlElement->name = $type->getShortName();
         }
         if ($xmlElement->group === XmlElement::DEFAULT_GROUP) {
             $hasDefaultElement = true;
         }
     }
     if (!$hasDefaultElement) {
         $annotations = $type->getAnnotations();
         $annotations[] = $xmlElement = new XmlElement();
         $xmlElement->name = $type->getShortName();
         $type->setAnnotations($annotations);
     }
     foreach ($type->getProperties() as $property) {
         if ($property->hasAnnotation("Skrz\\Meta\\Transient")) {
             continue;
         }
         if ($property->isPrivate()) {
             throw new MetaException("Private property '{$type->getName()}::\${$property->getName()}'. " . "Either make the property protected/public if you need to process it, " . "or mark it using @Transient annotation.");
         }
         if (get_class($property->getType()) === "Skrz\\Meta\\Reflection\\MixedType") {
             throw new MetaException("Property {$type->getName()}::\${$property->getName()} of type mixed. " . "Either add @var annotation with non-mixed type, " . "or mark it using @Transient annotation.");
         }
         $hasDefaultGroup = false;
         foreach ($property->getAnnotations("Skrz\\Meta\\XML\\XmlAnnotationInterface") as $annotation) {
             /** @var XmlAnnotationInterface $annotation */
             if ($annotation->getGroup() === XmlElement::DEFAULT_GROUP) {
                 $hasDefaultGroup = true;
             }
             if ($annotation instanceof XmlElement) {
                 /** @var XmlElement $annotation */
                 if ($annotation->name === null) {
                     $annotation->name = $property->getName();
                 }
             } elseif ($annotation instanceof XmlAttribute) {
                 /** @var XmlAttribute $annotation */
                 if ($annotation->name === null) {
                     $annotation->name = $property->getName();
                 }
             }
         }
         if (!$hasDefaultGroup) {
             $annotations = $property->getAnnotations();
             $annotations[] = $arrayOffset = new XmlElement();
             $arrayOffset->name = $property->getName();
             $property->setAnnotations($annotations);
         }
     }
 }
Пример #2
0
 public function onGenerate(AbstractMetaSpec $spec, MetaSpecMatcher $matcher, Type $type, ClassType $class)
 {
     $class->addConst("CLASS_NAME", $type->getName());
     $class->addConst("SHORT_NAME", $type->getShortName());
     $class->addConst("ENTITY_NAME", lcfirst($type->getShortName()));
     foreach ($type->getProperties() as $property) {
         $const = strtoupper(trim(preg_replace("/([A-Z])/", "_\$1", $property->getName()), "_"));
         if (isset(self::$reserved[$const])) {
             throw new MetaException("Property name constant for {$type->getName()}::\${$property->getName()} would result in reserved word.");
         }
         $class->addConst($const, $property->getName());
     }
 }
Пример #3
0
 public function createMetaClassName(Type $type)
 {
     return $type->getNamespaceName() . "\\Meta\\" . $type->getShortName() . "Meta";
 }