/** * @param $class Reflection_Class * @param $composite_class_name string * @return Reflection_Property_Value[] */ protected function getProperties(Reflection_Class $class, $composite_class_name = null) { $properties = []; if (isset($composite_class_name) && isA($class->name, Component::class)) { $composite_property = call_user_func([$class->name, 'getCompositeProperties'], $composite_class_name); $composite_property = reset($composite_property); } else { $composite_property = null; } if ($class->getAnnotation('link')->value) { $link_class = new Link_Class($class->name); $composite_link_property = $link_class->getCompositeProperty(); foreach ($link_class->getProperties([T_EXTENDS, T_USE]) as $property) { if ((!$composite_property || $property->name !== $composite_property->name) && (!$composite_link_property || $property->name !== $composite_link_property->name) && !$property->isStatic() && !$property->getListAnnotation('user')->has(User_Annotation::INVISIBLE)) { $properties[] = $property; } } } else { foreach ($class->getProperties([T_EXTENDS, T_USE]) as $property) { if ((empty($composite_property) || $property->name !== $composite_property->name) && !$property->isStatic() && !$property->getListAnnotation('user')->has(User_Annotation::INVISIBLE)) { $properties[] = $property; } } } return $properties; }
/** * Build tabs containing class properties * * @param $class Reflection_Class * @return Tab[] Tabs will contain Reflection_Property[] as content */ public static function build(Reflection_Class $class) { /** @var $group_annotations Group_Annotation[] */ $group_annotations = $class->getAnnotations('group'); $properties = $class->getProperties([T_EXTENDS, T_USE]); return self::buildProperties($properties, $group_annotations); }
public function testAccessPropertiesDone() { $test_order = new Order(date('Y-m-d'), 'CDE001'); $class = new Reflection_Class(Order::class); $class->accessProperties(); $properties = $class->getProperties([T_EXTENDS, T_USE]); $check = []; foreach ($properties as $property) { try { $check[$property->name] = $property->getValue($test_order); } catch (ReflectionException $e) { $check[$property->name] = null; } } $this->assume(__METHOD__, $check, ['date' => null, 'number' => null, 'client' => null, 'delivery_client' => null, 'lines' => null, 'salesmen' => null]); }
/** * Add a link class (using the 'link' class annotation) to joins * * @param $path string the property path * @param $class Link_Class the link class itself (which contains the @link) * @param $linked_class_name string the linked class name (the value of @link) * @param $join_mode string * @return Reflection_Property[] the properties that come from the linked class, * for further exclusion */ private function addLinkedClass($path, $class, $linked_class_name, $join_mode) { $linked_class = new Reflection_Class($linked_class_name); $join = new Join(); $join->master_alias = 't' . ($this->alias_counter - 1); $join->master_column = 'id_' . $class->getCompositeProperty($linked_class_name)->getAnnotation('storage')->value; $join->foreign_alias = 't' . $this->alias_counter++; $join->foreign_column = 'id'; $join->foreign_class = Builder::className($linked_class_name); $join->foreign_table = Dao::storeNameOf($join->foreign_class); $join->mode = $join_mode == Join::LEFT ? Join::LEFT : Join::INNER; $join->type = Join::LINK; if (!isset($this->joins[$path])) { // this ensures that the main path is set before the linked path $this->joins[$path] = null; } $this->joins[($path ? $path . '-' : '') . $join->foreign_table . '-@link'] = $join; $this->id_link_joins[$path] = $join; $this->link_joins[$path] = $join; $more_linked_class_name = $linked_class->getAnnotation('link')->value; $exclude_properties = $more_linked_class_name ? $this->addLinkedClass($path, $class, $more_linked_class_name, $join_mode) : []; foreach ($linked_class->getProperties([T_EXTENDS, T_USE]) as $property) { if (!$property->isStatic()) { if (!isset($exclude_properties[$property->name])) { $this->properties[$linked_class_name][$property->name] = $property; $property_path = ($path ? $path . DOT : '') . $property->name; $type = $property->getType(); if ($type->isClass()) { $this->classes[$property_path] = $property->getType()->getElementTypeAsString(); } $this->link_joins[$property_path] = $join; $exclude_properties[$property->name] = true; } } } return $exclude_properties; }
/** * @return string[] */ protected function getProperties() { // gets all properties from collection element class $class = new Reflection_Class($this->class_name); $properties = $class->getProperties([T_EXTENDS, T_USE]); // remove replaced properties /** @var $properties Reflection_Property[] */ $properties = Replaces_Annotations::removeReplacedProperties($properties); // remove linked class properties $linked_class = $class->getAnnotation('link')->value; if ($linked_class) { foreach (array_keys((new Reflection_Class($linked_class))->getProperties([T_EXTENDS, T_USE])) as $property_name) { unset($properties[$property_name]); } } // remove composite property $property_name = $this->property->getAnnotation('foreign')->value; if (isset($properties[$property_name])) { unset($properties[$property_name]); } // remove static and user-invisible properties foreach ($properties as $property_name => $property) { if ($property->isStatic() || $property->getListAnnotation('user')->has(User_Annotation::INVISIBLE)) { unset($properties[$property_name]); } } // returns properties return $properties; }