98 if (isset(
$data[
'$ref'])) {
102 } elseif (isset(
$data[
'extends'])) {
106 $data += $extends->toArray();
112 foreach (
$data as $key => $value) {
113 $this->{$key} = $value;
117 $this->required = (bool) $this->required;
118 $this->data = (array) $this->data;
120 if ($this->filters) {
124 if ($this->type ==
'object' && $this->additionalProperties ===
null) {
125 $this->additionalProperties =
true;
136 static $checks = array(
'required',
'description',
'static',
'type',
'format',
'instanceOf',
'location',
'sentAs',
137 'pattern',
'minimum',
'maximum',
'minItems',
'maxItems',
'minLength',
'maxLength',
'data',
'enum',
143 if ($this->parent instanceof
self && $this->parent->getType() ==
'array' && isset($this->name)) {
147 foreach ($checks as $c) {
148 if ($value = $this->{$c}) {
149 $result[$c] = $value;
153 if ($this->
default !==
null) {
157 if ($this->items !==
null) {
158 $result[
'items'] = $this->
getItems()->toArray();
161 if ($this->additionalProperties !==
null) {
163 if ($result[
'additionalProperties'] instanceof
self) {
164 $result[
'additionalProperties'] = $result[
'additionalProperties']->toArray();
168 if ($this->type ==
'object' && $this->properties) {
169 $result[
'properties'] = array();
171 $result[
'properties'][
$name] = $property->toArray();
187 if ($this->
static || ($this->
default !==
null && $value ===
null)) {
209 if ($this->type ==
'boolean' && !is_bool($value)) {
210 $value = filter_var($value, FILTER_VALIDATE_BOOLEAN);
214 if ($this->filters) {
215 foreach ($this->filters as $filter) {
216 if (is_array($filter)) {
218 foreach ($filter[
'args'] as &
$data) {
219 if (
$data ==
'@value') {
221 } elseif (
$data ==
'@api') {
225 $value = call_user_func_array($filter[
'method'], $filter[
'args']);
227 $value = call_user_func($filter, $value);
312 $this->required = (bool) $isRequired;
384 $this->minimum = $min;
408 $this->maximum = $max;
432 $this->minLength = $min;
456 $this->maxLength = $max;
480 $this->maxItems = $max;
504 $this->minItems = $min;
553 $this->sentAs =
$name;
572 if (isset($this->data[
$name])) {
573 return $this->data[
$name];
574 } elseif (isset($this->{$name})) {
575 return $this->{$name};
591 if (is_array($nameOrData)) {
592 $this->data = $nameOrData;
594 $this->data[$nameOrData] =
$data;
619 $this->
static = (bool)
$static;
631 return $this->filters ?: array();
643 $this->filters = array();
661 if (is_array($filter)) {
662 if (!isset($filter[
'method'])) {
667 if (!$this->filters) {
668 $this->filters = array($filter);
670 $this->filters[] = $filter;
707 if (!$this->propertiesCache) {
708 $this->propertiesCache = array();
709 foreach (array_keys($this->properties) as
$name) {
726 if (!isset($this->properties[
$name])) {
730 if (!($this->properties[
$name] instanceof
self)) {
733 $this->properties[
$name]->setParent($this);
736 return $this->properties[
$name];
748 unset($this->properties[
$name]);
749 $this->propertiesCache =
null;
763 $this->properties[$property->
getName()] = $property;
765 $this->propertiesCache =
null;
777 if (is_array($this->additionalProperties)) {
779 $this->additionalProperties->setParent($this);
794 $this->additionalProperties = $additional;
808 if ($this->items =
$items) {
809 $this->items->setParent($this);
822 if (is_array($this->items)) {
824 $this->items->setParent($this);