/**
  * @param PackageInterface $package
  * @return array
  */
 protected function getPrimaryNamespaceAndEntryPath(PackageInterface $package)
 {
     $autoloadConfigurations = $package->getComposerManifest('autoload');
     $firstAutoloadType = null;
     $firstAutoloadConfiguration = null;
     foreach ($autoloadConfigurations as $autoloadType => $autoloadConfiguration) {
         if (ClassLoader::isAutoloadTypeWithPredictableClassPath($autoloadType)) {
             $firstAutoloadType = $autoloadType;
             $firstAutoloadConfiguration = $autoloadConfiguration;
             break;
         }
     }
     $autoloadPaths = reset($firstAutoloadConfiguration);
     $firstAutoloadPath = is_array($autoloadPaths) ? reset($autoloadPaths) : $autoloadPaths;
     $namespace = key($firstAutoloadConfiguration);
     $autoloadPathPostfix = '';
     if ($firstAutoloadType === ClassLoader::MAPPING_TYPE_PSR0) {
         $autoloadPathPostfix = str_replace('\\', '/', trim($namespace, '\\'));
     }
     return [$namespace, Files::concatenatePaths([$package->getPackagePath(), $firstAutoloadPath, $autoloadPathPostfix]), $firstAutoloadType];
 }
 /**
  * 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)
 {
     $namespaces = $package->getNamespaces();
     $dummyClassName = 'Someclass' . md5(uniqid(mt_rand(), true));
     $fullyQualifiedClassName = '\\' . reset($namespaces) . '\\' . $dummyClassName;
     $dummyClassFilePath = Files::concatenatePaths([$package->getPackagePath(), PackageInterface::DIRECTORY_CLASSES, $dummyClassName . '.php']);
     file_put_contents($dummyClassFilePath, '<?php namespace ' . reset($namespaces) . '; class ' . $dummyClassName . ' {}');
     require $dummyClassFilePath;
     return new $fullyQualifiedClassName();
 }
 /**
  * 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 = [];
     if (isset($policyConfiguration['resources'])) {
         $errors[] = 'deprecated "resources" options';
     }
     if (isset($policyConfiguration['acls'])) {
         $errors[] = 'deprecated "acls" options';
     }
     if ($errors !== []) {
         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);
     }
 }
 /**
  * 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);
 }