hasProviderMapping($type)) { throw new InvalidArgumentException(_(static::MSG_TYPE_REUSE_FORBIDDEN, $type)); } if ($schema instanceof SchemaInterface) { $this->setProviderMapping($type, \get_class($schema)); $this->setResourceToJsonTypeMapping($schema->getType(), $type); $this->setCreatedProvider($type, $schema); } else { $this->setProviderMapping($type, $schema); } } /** * @param callable $callable * * @return SchemaInterface */ protected function createSchemaFromCallable(callable $callable): SchemaInterface { $schema = \call_user_func($callable, $this); return $schema; } /** * @param string $type * * @return bool */ protected function hasProviderMapping(string $type): bool { if (parent::hasProviderMapping($type)) { return true; } foreach ($this->getParentClassesAndInterfaces($type) as $class) { if (parent::hasProviderMapping($class)) { return true; } } return false; } /** * @param string $type * * @return mixed */ protected function getProviderMapping(string $type) { if (parent::hasProviderMapping($type)) { return parent::getProviderMapping($type); } foreach ($this->getParentClassesAndInterfaces($type) as $class) { if (parent::hasProviderMapping($class)) { return parent::getProviderMapping($class); } } throw new InvalidArgumentException(_('Cannot find schema for type `%s`', $type)); } private function getParentClassesAndInterfaces(string $type): array { return class_exists($type) ? @class_parents($type) + @class_implements($type) : []; } }