/** * Fetch configuration details for a named adapter * * @param string $name * @return ContentNegotiationEntity|false */ public function fetch($name) { $config = $this->globalConfig->fetch(true); if (!isset($config['zf-content-negotiation']['selectors'][$name]) || !is_array($config['zf-content-negotiation']['selectors'][$name])) { return false; } return new ContentNegotiationEntity($name, $config['zf-content-negotiation']['selectors'][$name]); }
/** * Delete the REST configuration associated with the given * service * * @param DoctrineRestServiceEntity $entity */ public function deleteDoctrineRestConfig(DoctrineRestServiceEntity $entity) { // Get hydrator name $config = $this->configResource->fetch(true); $hydratorName = $config['zf-hal']['metadata_map'][$entity->entityClass]['hydrator']; $objectManagerClass = $config['doctrine-hydrator'][$hydratorName]['object_manager']; $key = ['doctrine-hydrator', $hydratorName]; $this->configResource->deleteKey($key); $key = ['zf-apigility', 'doctrine-connected', $entity->resourceClass]; $this->configResource->deleteKey($key); $key = ['zf-rest', $entity->controllerServiceName]; $this->configResource->deleteKey($key); $key = ['zf-content-negotiation', 'controllers', $entity->controllerServiceName]; $this->configResource->deleteKey($key); $key = ['zf-content-negotiation', 'accept-whitelist', $entity->controllerServiceName]; $this->configResource->deleteKey($key); $key = ['zf-content-negotiation', 'content-type-whitelist', $entity->controllerServiceName]; $this->configResource->deleteKey($key); $key = ['zf-hal', 'metadata_map', $entity->collectionClass]; $this->configResource->deleteKey($key); $key = ['zf-hal', 'metadata_map', $entity->entityClass]; $this->configResource->deleteKey($key); $validator = $config['zf-content-validation'][$entity->controllerServiceName]['input_filter']; $key = ['zf-content-validation', $entity->controllerServiceName]; $this->configResource->deleteKey($key); $key = ['input_filter_specs', $validator]; $this->configResource->deleteKey($key); }
/** * Remove a url from OAuth2 route * * Since Apigility 1.1 * * @param string $url * @return boolean */ protected function removeOAuth2Route($url) { $config = $this->globalConfig->fetch(true); if (! isset($config['router']['routes']['oauth']['options']['regex'])) { return false; } $routes = $this->fromOAuth2RegexToArray($config); $index = array_search($url, $routes); if (false === $index) { return false; } unset($routes[$index]); if (count($routes)>0) { usort($routes, function ($a, $b) { return strlen($b) - strlen($a); }); $options = array( 'spec' => '%oauth%', 'regex' => '(?P<oauth>(' . implode('|', $routes) . '))' ); $this->globalConfig->patchKey('router.routes.oauth.options', $options); $this->globalConfig->patchKey('router.routes.oauth.type', 'regex'); return true; } $this->globalConfig->deleteKey('router.routes.oauth'); return true; }
/** * Delete any versionin configuration for a service * * Only for version 1; later versions will do nothing * * @param string $routeName * @param string $serviceName */ public function deleteVersioningConfig($routeName, $serviceName) { if (false === strstr($serviceName, '\\V1\\')) { // > V1; nothing to do return; } $config = $this->configResource->fetch(true); if (! isset($config['zf-versioning']['uri'])) { return; } if (! in_array($routeName, $config['zf-versioning']['uri'], true)) { return; } $versioning = array_filter($config['zf-versioning']['uri'], function ($value) use ($routeName) { if ($routeName === $value) { return false; } return true; }); $key = array('zf-versioning', 'uri'); $this->configResource->patchKey($key, $versioning); }
/** * Removes the route configuration for a named route * * @param string $routeName */ public function deleteRouteConfig($routeName) { $config = $this->configResource->fetch(true); $key = array('router', 'routes', $routeName); $this->configResource->deleteKey($key); $key = array('zf-versioning', 'uri', array_search($routeName, $config['zf-versioning']['uri'])); $this->configResource->deleteKey($key); }
/** * Fetch configuration details for a named adapter * * @param $name * @return bool|DoctrineAdapterEntity */ public function fetch($name) { $config = $this->localConfig->fetch(true); if (!isset($config['doctrine']) || !isset($config['doctrine']['connection']) || !is_array($config['doctrine']['connection']) || !isset($config['doctrine']['connection'][$name]) || !is_array($config['doctrine']['connection'][$name])) { return false; } return new DoctrineAdapterEntity($name, $config['doctrine']['connection'][$name]); }
/** * Fetch configuration details for a named adapter * * @param string $name * @return DbAdapterEntity|false */ public function fetch($name) { $config = $this->localConfig->fetch(true); if (!isset($config['db']['adapters'][$name]) || !is_array($config['db']['adapters'][$name])) { return false; } return new DbAdapterEntity($name, $config['db']['adapters'][$name]); }
/** * Fetch authorization list for a given module by version * * @param int $version * @return AuthorizationEntity */ public function fetch($version = 1) { $allConfig = $this->configResource->fetch(true); if (!isset($allConfig['zf-mvc-auth']['authorization'])) { // Determine existing services, and return defaults for them return $this->createDefaultPrivileges($version, $allConfig); } $config = $allConfig['zf-mvc-auth']['authorization']; // Strip out any services that are not for the current $version $config = $this->filterServicesByVersion($config, $version); // Ensure services are mapped correctly, and create entity $config = $this->remapServiceNamesForPayload($config); $entity = new AuthorizationEntity($config); // Determine if we have any services missing, and create default // entries for them $this->injectServicesWithoutPrivileges($entity, $version, $allConfig); return $entity; }
/** * Update the documentation to add a new $version based on the $previous * * @param int $previous Previous version * @param int $version New version * @return true */ protected function updateDocumentationVersion($previous, $version) { if (!$this->docsConfigResource) { // Nothing to do return true; } $originalDocs = $this->docsConfigResource->fetch(true); $newDocs = $this->changeVersionArray($originalDocs, $previous, $version); $this->docsConfigResource->patch($newDocs, true); return true; }
/** * Traverse an array for a subkey * * Subkey is given in "." notation, which is then split, and * the configuration is traversed until no more keys are available, * or a corresponding entry is not found; in the latter case, * the $default will be provided. * * @param string $subKey * @param array|mixed $default * @return mixed */ protected function getConfigForSubkey($subKey, $default = []) { $config = $this->configResource->fetch(true); $keys = explode('.', $subKey); do { $key = array_shift($keys); if (!isset($config[$key])) { return $default; } $config = $config[$key]; } while (count($keys)); return $config; }
/** * Fetch all OAuth2 configuration from global and local files * * @param array $config * @return array|false */ protected function fetchOAuth2Configuration(array $config) { $oauth2Config = array('route_match' => '/oauth'); if (isset($config['router']['routes']['oauth']['options']['route'])) { $oauth2Config['route_match'] = $config['router']['routes']['oauth']['options']['route']; } $localConfig = $this->localConfig->fetch(true); if (isset($localConfig['zf-oauth2']['db']) && is_array($localConfig['zf-oauth2']['db'])) { return array_merge($oauth2Config, $localConfig['zf-oauth2']['db']); } if (isset($localConfig['zf-oauth2']['mongo']) && is_array($localConfig['zf-oauth2']['mongo'])) { return array_merge($oauth2Config, $localConfig['zf-oauth2']['mongo']); } return false; }
/** * Delete the RPC configuration for a named RPC service * * @param string $serviceName */ public function deleteDoctrineRpcConfig($serviceName) { $key = ['zf-rpc', $serviceName]; $this->configResource->deleteKey($key); $key = ['zf-rpc-doctrine-controller', $serviceName]; $this->configResource->deleteKey($key); $config = $this->configResource->fetch(); if (isset($config['controllers.aliases.' . $serviceName])) { $fullClassName = $config['controllers.aliases.' . $serviceName]; $key = ['controllers', 'aliases', $serviceName]; $this->configResource->deleteKey($key); $key = ['controllers', 'factories', $fullClassName]; $this->configResource->deleteKey($key); } $key = ['controllers', 'invokables', $serviceName]; $this->configResource->deleteKey($key); $key = ['zf-content-negotiation', 'accept_whitelist', $serviceName]; $this->configResource->deleteKey($key); $key = ['zf-content-negotiation', 'content_type_whitelist', $serviceName]; $this->configResource->deleteKey($key); }
public function testFetchWithTreeFlagSetToTrueReturnsConfigurationUnmodified() { $config = ['foo' => 'bar', 'bar' => ['baz' => 'bat', 'bat' => 'bogus'], 'baz' => 'not what you think']; $configResource = new ConfigResource($config, $this->file, $this->writer); $this->assertEquals($config, $configResource->fetch(true)); }