/** * Create inspection for model field. * * @param string $field * @return FieldInspection */ private function inspectField($field) { $filters = $this->reflection->getSetters() + $this->reflection->getAccessors(); $fillable = true; if ($this->reflection->getSecured() === '*' || in_array($field, $this->reflection->getSecured())) { $fillable = false; } if ($this->reflection->getFillable() != []) { $fillable = in_array($field, $this->reflection->getFillable()); } return new FieldInspection($this->inspector, $field, $this->reflection->getFields()[$field], $fillable, in_array($field, $this->reflection->getHidden()), isset($filters[$field]), array_key_exists($field, $this->reflection->getValidates())); }
/** * 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; }