예제 #1
0
 public static function generate(MetaClass $class)
 {
     if (!$class->doBuild()) {
         return null;
     }
     $out = '';
     $out .= "class " . $class->getName();
     $out .= " {\n";
     foreach ($class->getProperties() as $property) {
         $out .= "+get" . ucfirst($property->getName()) . "()\n";
     }
     $out .= "}\n";
     if ($class->getParent()) {
         $out .= $class->getParent()->getName() . " <|-- " . $class->getName() . "\n";
     }
     $out .= "\n";
     return $out;
 }
예제 #2
0
 /**
  * @return MetaConfiguration
  **/
 private function checkSanity(MetaClass $class)
 {
     if ((!$class->getParent() || $class->getFinalParent()->getPattern() instanceof InternalClassPattern) && !$class->getPattern() instanceof ValueObjectPattern && !$class->getPattern() instanceof InternalClassPattern) {
         Assert::isTrue($class->getIdentifier() !== null, 'only value objects can live without identifiers. ' . 'do not use them anyway (' . $class->getName() . ')');
     }
     if ($class->getType() && $class->getTypeId() == MetaClassType::CLASS_SPOOKED) {
         Assert::isFalse(count($class->getProperties()) > 1, 'spooked classes must have only identifier: ' . $class->getName());
         Assert::isTrue($class->getPattern() instanceof SpookedClassPattern || $class->getPattern() instanceof SpookedEnumerationPattern || $class->getPattern() instanceof SpookedEnumPattern || $class->getPattern() instanceof SpookedRegistryPattern, 'spooked classes must use spooked patterns only: ' . $class->getName());
     }
     foreach ($class->getProperties() as $property) {
         if (!$property->getType()->isGeneric() && $property->getType() instanceof ObjectType && $property->getType()->getClass()->getPattern() instanceof ValueObjectPattern) {
             Assert::isTrue($property->isRequired(), 'optional value object is not supported:' . $property->getName() . ' @ ' . $class->getName());
             Assert::isTrue($property->getRelationId() == MetaRelation::ONE_TO_ONE, 'value objects must have OneToOne relation: ' . $property->getName() . ' @ ' . $class->getName());
         } elseif ($property->getFetchStrategyId() == FetchStrategy::LAZY && $property->getType()->isGeneric()) {
             throw new WrongArgumentException('lazy one-to-one is supported only for ' . 'non-generic object types ' . '(' . $property->getName() . ' @ ' . $class->getName() . ')');
         }
     }
     return $this;
 }