/** * @param string $type * @param array $args */ function __construct($type, $args = array()) { $args['doc_type'] = $type; if (!Util::is_builtin_type($type)) { $args['class_name'] = $type; $args['local_class'] = Util::parse_local_class($type); $args['namespace'] = isset($args['namespace']) ? $args['namespace'] : Util::parse_namespace($type); if (preg_match('#(.*?)\\[\\]$#', $type, $match)) { $args['base_type'] = 'array'; $args['array_of'] = 'object'; $args['class_name'] = $match[1]; } else { $args['base_type'] = 'object'; } } else { $args['base_type'] = $type; if ('[]' === substr($type, -2)) { $args['array_of'] = substr($type, 0, -2); $args['base_type'] = 'array'; } else { if ('array' === $type) { $args['array_of'] = 'mixed'; } } } parent::__construct($args); }
/** * Filters values out that match the core default for the underlying platform. * * @return array * * @example * * No value provided @default=true @missing=false => include in returned $args * No value provided @default=false @missing=false => DO NOT include in returned $args * true provided @default=true @missing=false => include in returned $args * true provided @default=true @missing=true => DO NOT include in returned $args * true provided @default=false @missing=true => DO NOT include in returned $args * * @param Property[]|boolean $properties * * @return boolean|JsonLoader\Property[] */ function filter_redundant($properties = false) { if (!$properties) { $properties = $this->object_properties(); } foreach ($properties as $property_name => $property) { $property_value = $this->get_object_value($property_name); $missing_value = !is_null($property->missing) ? $property->cast($property->missing) : null; if (is_null($property_value) && is_null($missing_value)) { unset($properties[$property_name]); continue; } else { if (!preg_match('#^(!?)\\s*\\$(\\w+)$#', $missing_value, $matches)) { $default_value = $missing_value; } else { if (!$this->has_object_property($default_property_name = $matches[2])) { $err_msg = 'Property %s not declared but referenced in a @%s for %s yet. Must declare before referencing.'; Util::log_error(sprintf($err_msg, $default_property_name, 'missing', $property_name)); } else { $default_value = '!' === $matches[1] ? !$this->get_object_value($default_property_name) : $this->get_object_value($default_property_name); } } } if (is_array($property_value) && is_string($missing_value) && $property->explode) { /* * If the value is an already exploded array but the missing value is not exploded * the implode the value to compare with the missing value. */ $property_value = implode($property->explode, $property_value); } if ($default_value === $property_value) { /* * If the default value and the property value are the same * the we don't need to generate an initializer for them. */ unset($properties[$property_name]); } } return $properties; }
/** * @param string $data_type * @param string $namespace * * @return array */ static function explode_data_types($data_type, $namespace) { $data_types = array_map(function ($data_type) use($namespace) { if (false === strpos($data_type, '\\') && !Util::is_builtin_type($data_type)) { $data_type = "\\{$namespace}\\{$data_type}"; } return $data_type; }, explode('|', $data_type)); return $data_types; }