/** * Unregisters a package from the list of available packages * * @param PackageInterface $package The package to be unregistered * @return void * @throws Exception\InvalidPackageStateException */ protected function unregisterPackage(PackageInterface $package) { $packageKey = $package->getPackageKey(); if (!$this->isPackageAvailable($packageKey)) { throw new Exception\InvalidPackageStateException('Package "' . $packageKey . '" is not registered.', 1338996142); } if (!isset($this->packages[$packageKey])) { return; } $composerName = $package->getComposerName(); unset($this->packages[$packageKey], $this->packageKeys[strtolower($packageKey)], $this->packageStatesConfiguration['packages'][$composerName]); $this->sortAndSavePackageStates($this->packageStatesConfiguration); }
/** * Unregisters a package from the list of available packages * * @param PackageInterface $package The package to be unregistered * @return void * @throws Exception\InvalidPackageStateException */ public function unregisterPackage(PackageInterface $package) { $packageKey = $package->getPackageKey(); if (!$this->isPackageAvailable($packageKey)) { throw new Exception\InvalidPackageStateException('Package "' . $packageKey . '" is not registered.', 1338996142); } $this->unregisterPackageByPackageKey($packageKey); }
/** * Add a package to class loader just during runtime, so classes can be loaded without the need for a new request * * @param \TYPO3\Flow\Package\PackageInterface $package * @return ClassLoader */ public function addActivePackage(\TYPO3\Flow\Package\PackageInterface $package) { $packageKey = $package->getPackageKey(); if (!isset($this->packages[$packageKey])) { $this->packages[$packageKey] = $package; $this->buildPackageNamespaceAndClassesPath($package); $this->sortPackageNamespaces(); $this->loadClassFilesFromAutoloadRegistryIntoRuntimeClassInformationCache(array($package)); } return $this; }
/** * Validates the given $policyConfiguration and throws an exception if its not valid * * @param array $policyConfiguration * @param PackageInterface $package * @return void * @throws Exception */ protected function validatePolicyConfiguration(array $policyConfiguration, PackageInterface $package) { $errors = array(); if (isset($policyConfiguration['resources'])) { $errors[] = 'deprecated "resources" options'; } if (isset($policyConfiguration['acls'])) { $errors[] = 'deprecated "acls" options'; } if ($errors !== array()) { throw new Exception(sprintf('The policy configuration for package "%s" is not valid.%sIt contains following error(s):%s Make sure to run all code migrations.', $package->getPackageKey(), chr(10), chr(10) . ' * ' . implode(chr(10) . ' * ', $errors) . chr(10)), 1415717875); } }
/** * Loads a Policy.yaml file and transforms the roles configuration * * @param string $pathAndFilename Full path and filename of the file to load, excluding the file extension (ie. ".yaml") * @param \TYPO3\Flow\Package\PackageInterface $package * @throws InvalidConfigurationException * @return array */ protected function loadPolicyConfigurationFile($pathAndFilename, PackageInterface $package = NULL) { $packageKeyOfCurrentPackage = $package !== NULL ? $package->getPackageKey() : NULL; $configuration = $this->configurationSource->load($pathAndFilename); // Read roles if (isset($configuration['roles']) && is_array($configuration['roles'])) { $localRoles = array_keys($configuration['roles']); foreach ($configuration['roles'] as $roleIdentifier => $parentRoles) { $packageKey = $packageKeyOfCurrentPackage; if ($roleIdentifier === 'Everybody' || $roleIdentifier === 'Anonymous' || $roleIdentifier === 'AuthenticatedUser') { throw new InvalidConfigurationException('You must not redefine the built-in "' . $roleIdentifier . '" role. Please check the configuration of package "' . $packageKeyOfCurrentPackage . '" (' . $pathAndFilename . ').', 1352986475); } if (strpos($roleIdentifier, '.') !== FALSE || strpos($roleIdentifier, ':') !== FALSE) { throw new InvalidConfigurationException('Roles defined in a package policy must not be qualified (that is, using the dot notation), but the role "' . $roleIdentifier . '" is (in package "' . $packageKeyOfCurrentPackage . '"). Please use the short notation with only the role name (for example "Administrator").', 1365447412); } // Add packageKey to parentRoles if ($parentRoles !== array()) { $parentRoles = array_map(function ($roleIdentifier) use($packageKey, $localRoles) { if ($roleIdentifier === 'Everybody' || $roleIdentifier === 'Anonymous' || $roleIdentifier === 'AuthenticatedUser') { return $roleIdentifier; } if (strpos($roleIdentifier, '.') === FALSE && strpos($roleIdentifier, ':') === FALSE && in_array($roleIdentifier, $localRoles)) { return $packageKey . ':' . $roleIdentifier; } return $roleIdentifier; }, $parentRoles, array($packageKey)); } $configuration['roles'][$packageKey . ':' . $roleIdentifier] = $parentRoles; unset($configuration['roles'][$roleIdentifier]); } } // Read acls if (isset($configuration['acls']) && is_array($configuration['acls'])) { foreach ($configuration['acls'] as $aclIndex => $aclConfiguration) { if ($aclIndex === 'Everybody' || $aclIndex === 'Anonymous' || $aclIndex === 'AuthenticatedUser' || preg_match('/^[\\w]+((\\.[\\w]+)*\\:[\\w]+)+$/', $aclIndex) === 1) { $roleIdentifier = $aclIndex; } elseif (preg_match('/^[\\w]+$/', $aclIndex) === 1) { $roleIdentifier = $packageKeyOfCurrentPackage . ':' . $aclIndex; } else { throw new InvalidConfigurationException('Detected invalid role syntax in the acls section of the policy file ' . $pathAndFilename . ': "' . $aclIndex . '" is not a valid role identifier.', 1365516177); } if (!isset($configuration['acls'][$roleIdentifier])) { $configuration['acls'][$roleIdentifier] = array(); } $configuration['acls'][$roleIdentifier] = Arrays::arrayMergeRecursiveOverrule($configuration['acls'][$roleIdentifier], $aclConfiguration); if ($roleIdentifier !== $aclIndex) { unset($configuration['acls'][$aclIndex]); } } } return $configuration; }