/**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
     }
 }
 /**
  * Creates a dummy class file inside $package's path
  * and requires it for propagation
  *
  * @param PackageInterface $package
  * @return object The dummy object of the class which was created
  */
 protected function createDummyObjectForPackage(PackageInterface $package)
 {
     $dummyClassName = 'Someclass' . md5(uniqid(mt_rand(), TRUE));
     $fullyQualifiedClassName = '\\' . $package->getNamespace() . '\\' . $dummyClassName;
     $dummyClassFilePath = \TYPO3\Flow\Utility\Files::concatenatePaths(array($package->getPackagePath(), PackageInterface::DIRECTORY_CLASSES, $dummyClassName . '.php'));
     file_put_contents($dummyClassFilePath, '<?php namespace ' . $package->getNamespace() . '; class ' . $dummyClassName . ' {}');
     require $dummyClassFilePath;
     return new $fullyQualifiedClassName();
 }
 /**
  * Extracts the namespace from a package
  *
  * @param \TYPO3\Flow\Package\PackageInterface $package
  * @return void
  */
 protected function buildPackageNamespace(\TYPO3\Flow\Package\PackageInterface $package)
 {
     $packageNamespace = $package->getNamespace();
     // Ignore legacy extensions with unkown vendor name
     if ($packageNamespace[0] !== '*') {
         $this->packageNamespaces[$packageNamespace] = array('namespaceLength' => strlen($packageNamespace), 'classesPath' => $package->getClassesPath(), 'packagePath' => $package->getPackagePath(), 'substituteNamespaceInPath' => $package instanceof PackageInterface);
     }
 }
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * Return value is:
  * - 0 if unit tests ran through successfully,
  * - 1 or 2 if the tests failed or an error occured,
  * - 255 if a fatal error occured
  * - 137 ON TIMEOUT
  * - FALSE if the unit / functional test directory does not exist
  *
  *
  * @param \TYPO3\Flow\Package\PackageInterface $package
  * @param integer $timeout the timeout
  * @param string $testType either 'Unit' or 'Functional'
  * @param string $testPath path inside Tests/$testType
  * @param string $additionalArguments additional arguments to be passed to PHPUnit
  * @return null
  */
 protected function runPhpUnitForPackage(\TYPO3\Flow\Package\PackageInterface $package, $timeout, $testType, $testPath = '', $additionalArguments = '')
 {
     $output = array();
     $returnValue = NULL;
     if (!is_dir($package->getPackagePath() . 'Tests/' . $testType)) {
         return FALSE;
     }
     exec(sprintf('timeout %s %s -c %sBuild/BuildEssentials/PhpUnit/%sTests.xml %s %sTests/%s/%s 2>/dev/null', $timeout, $this->phpunitBinary, FLOW_PATH_ROOT, $testType, $additionalArguments, $package->getPackagePath(), $testType, $testPath), $output, $returnValue);
     return $returnValue;
 }