$value) { if (!Util::validateBcp47($key) || !Validator::validate($type, $value, $container) ) { return false; } } return true; } /** * Validate an attribute value * * @param mixed $value * @param mixed $container An object * @param callable $callback A dedicated validator * @return bool */ public function validateListOrObject($value, $container, callable $callback) { Util::subclassOf($container, ObjectType::class, true); // Not supported: Can be a JSON string // Must be a value like an URL, a text if (is_string($value)) { return $callback($value); } if (is_array($value)) { // Can be empty if (!count($value)) { return true; } // A collection if (is_int(key($value))) { return $this->validateObjectCollection($value, $callback); } $value = Util::arrayToType($value); } if (!is_object($value)) { return false; } return $callback($value); } /** * Validate a list of Collection * * @param array $collection * @param callable $callback A dedicated validator * @return bool */ protected function validateObjectCollection(array $collection, callable $callback) { foreach ($collection as $item) { if ($callback($item)) { continue; } return false; } return true; } /** * Validate that a value is a string * * @param string $value * @return bool */ protected function validateString($value) { if (!is_string($value) || strlen($value) < 1) { throw new Exception( sprintf( 'Value must be a non-empty string. Given: "%s"', print_r($value, true) ) ); } return true; } /** * A callback function for validateListOrObject method * * It validate a Link or a named object * * @return callable */ protected function getLinkOrNamedObjectValidator() { return function ($item) { if (is_string($item)) { return Util::validateUrl($item); } if (is_array($item)) { $item = Util::arrayToType($item); } if (is_object($item)) { Util::hasProperties($item, ['type'], true); // Validate Link type if ($item->type == 'Link') { return Util::validateLink($item); } // Validate Object type Util::hasProperties($item, ['name'], true); return is_string($item->name); } }; } /** * A callback function for validateListOrObject method * * Validate a reference with a Link or an Object with an URL * * @return callable */ protected function getLinkOrUrlObjectValidator() { return function ($item) { if (is_array($item)) { $item = Util::arrayToType($item); } if (is_object($item) && Util::isLinkOrUrlObject($item)) { return true; } elseif (Util::validateUrl($item)) { return true; } }; } /** * A callback function for attachment validation * * Validate a reference with a Link, an Object with an URL * or an ObjectType * * @return callable */ protected function getAttachmentValidator() { return function ($item) { if (is_array($item)) { $item = Util::arrayToType($item); } if (is_object($item)) { if (Util::isLinkOrUrlObject($item)) { return true; } return ($item instanceof ObjectType); } elseif (Util::validateUrl($item)) { return true; } }; } /** * Validate that a Question answer is a Note * * @return callable */ protected function getQuestionAnswerValidator() { return function ($item) { if (is_array($item)) { $item = Util::arrayToType($item); } if (!is_object($item)) { return false; } Util::hasProperties($item, ['type', 'name'], true); return $item->type == 'Note' && is_scalar($item->name); }; } /** * Validate that a list of items is valid * * @return callable */ protected function getCollectionItemsValidator() { return function ($item) { if (is_string($item)) { return Util::validateUrl($item); } if (is_array($item)) { $item = Util::arrayToType($item); } if (!is_object($item)) { return false; } return Util::hasProperties($item, ['type'], true); }; } /** * Validate that a list of items are actors * * @return callable */ protected function getCollectionActorsValidator() { return function ($item) { if (is_string($item)) { return Util::validateUrl($item); } if (is_array($item)) { $item = Util::arrayToType($item); } if (!is_object($item)) { return false; } // id must be filled if ($item instanceof AbstractActor) { return !is_null($item->id); } return Util::validateLink($item); }; } } __halt_compiler();----SIGNATURE:----XFDPgkjSdgxPQL/J6a4XPUstfGVTCbzpDZ6rZz/Z0ToUb/ZnB4Tlpq8EP8dZDPyMEtASu8Y4Qd4UI+JzRZUzs4JlDDt56L6dPjrpob1rC9irr06GqrfkdbfvS45f4U0J/Ru9YBpeBk1qe9wlYavIup7ThbKMcMSJI/5NdCOGKFwYe0REEw8I2u22ip81mEHx0aAYIpsB6dnD+j2kh8A2OzPSkGQuCfi0s4DBDpFSFpPjCwr9cW/flUgPpsM8a2ss9wzvRuw6xUk6Q7acgzpqJdRh3J+OX2YHKLQrtmnTxqJMgO5gsWK7NoiJ6rG1D256YStDmvlsJao+oR7wwznALjAdw4vhprkQ8lL6tWrn58E1yBYdauoVnA8DDQVlOi3Fl/AT68buTrhtvWCfLtGKp2/mvDZ97Q1aQ7Psz/y9uPE/tqOeNQaLhdlu7+3cQkN5qXJMXxMWOJac5m/TvZkUuSVAEGZXcwEIC0nhPDnbGCdD22XbBKAaAgiKNtOYcWorytAOuA/MZmSf7kcMKMWAphEYqVrL/nvP8f5+EXTzFlSg1cNgTagzWv5Axx4Xph1DLrTIHOFTf0UTqCb4ZPXLWlctP99kvhwkE7ulAz2PUCSqTZYaFpeLIum7rHtQuPvRKtMqifmXUb+cSwE7ZLEnq4xx2LYkLRWzy+WrPWoSoBs=----ATTACHMENT:----NjIyMDgxNTgxNDQ1MjMyIDYyMDkzNzA5ODc3MTQ5MjcgNTEzNDAzNTUzODE0NDkwMQ==