/** * 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 $constant_name * @param boolean|string $class_name * @param boolean $validate * * * @return mixed|null */ static function get_constant($constant_name, $class_name = false, $validate = false) { if (!$class_name) { $class_name = get_called_class(); } if (is_object($class_name)) { $class_name = get_class($class_name); } $value = defined($constant_ref = "{$class_name}::{$constant_name}") ? constant($constant_ref) : null; if (!$value && $validate) { $message = "No %s constant set in class %s."; Util::log_error(sprintf($message, $constant_name, $class_name)); } return $value; }