コード例 #1
0
 public function addAnnotationClassCompiler($id, array &$attributes)
 {
     if (!isset($attributes['alias'])) {
         throw new \Exception(sprintf("service(%s, tags:{name: %s}) require tag alias", $id, self::CLASS_TAG_NAME));
     }
     $name = $attributes['alias'];
     $camelize_name = PhpHelper::camelize($name);
     if (!PhpHelper::isClassName($camelize_name) || in_array($name, $this->_ignore_name_list)) {
         throw new \Exception(sprintf("service(%s, tags:{name: %s, alias: %s}) tag alias invalid", $id, self::CLASS_TAG_NAME, $name));
     }
     if (isset($this->class_builders[$name])) {
         throw new \Exception(sprintf("service(%s, tags:{name: %s, alias: %s}) conflict with service(%s)", $id, self::CLASS_TAG_NAME, $name, $this->getClassBuilderByName($name)->getId()));
     }
     $builder = new SymforceAnnotationClassBuilder();
     $builder->setId($id);
     $builder->setName($name);
     $builder->setCamelizeName($camelize_name);
     if (isset($attributes['parent'])) {
         $builder->setParentName($attributes['parent']);
     }
     if (isset($attributes['group'])) {
         $builder->setGroupId((int) $attributes['group']);
     }
     if (isset($attributes['target'])) {
         $builder->setTarget($attributes['target']);
     }
     if (isset($attributes['properties'])) {
         $_properties = $builder->setPublicProperties($attributes['properties']);
         if (!empty($_properties)) {
             foreach ($_properties as $_property_name => $_property_type) {
                 if (!PhpHelper::isPropertyName($_property_name) || in_array($_property_name, $this->_ignore_name_list)) {
                     throw new \Exception(sprintf("service(%s, tags:{name: %s, alias: %s }) properties(name:%s, type:%s)  name invalid", $id, self::CLASS_TAG_NAME, $name, $_property_name, $_property_type));
                 }
                 $_property_builder = new SymforceAnnotationPropertyBuilder();
                 $_property_builder->setId($id);
                 $_property_builder->setName($_property_name);
                 $builder->addPropertyBuilder($_property_builder);
                 if (!in_array($_property_type, $this->_default_property_types)) {
                     throw new \Exception(sprintf("service(%s, tags:{name: %s, alias: %s}) properties(name:%s, type:%s) type must be one of(%s)", $id, self::CLASS_TAG_NAME, $name, $_property_name, $_property_type, join(',', $this->_default_property_types)));
                 }
                 $_property_builder->setType($_property_type);
             }
         }
     }
     if (isset($attributes['value'])) {
         $builder->setValuePropertyName($attributes['value']);
     }
     if (isset($attributes['as_key'])) {
         $builder->setValueAsKey($attributes['as_key']);
     }
     if (isset($attributes['not_null'])) {
         $builder->setValueNotNull($attributes['not_null']);
     }
     $this->class_builders[$name] = $builder;
 }
コード例 #2
0
 public function addEventBuilder($id, array &$attributes)
 {
     if (!isset($attributes['alias'])) {
         throw new \Exception(sprintf("service(%s) with tags(name=%s) require alias", $id, self::TAG_NAME));
     }
     $name = $attributes['alias'];
     if (!PhpHelper::isClassName($name) || in_array($name, $this->_ignore_name_list)) {
         throw new \Exception(sprintf("service(%s) with tags(name=%s, alias=%s) alias invalid", $id, self::TAG_NAME, $name));
     }
     if ($this->hasEventBuilder($name)) {
         throw new \Exception(sprintf("service(%s) with tags(name=%s, alias=%s) conflict with service(%s)", $id, self::TAG_NAME, $name, $this->getEventBuilderByName($name)->getId()));
     }
     $builder = new SymforceEventBuilder();
     $builder->setId($id);
     $builder->setIndex(count($this->_events));
     $builder->setName($name);
     if (isset($attributes['parent'])) {
         $builder->setParentName($attributes['parent']);
     }
     $this->_events[$name] = $builder;
 }