Extract metadata from document

@param  ZipArchive $package ZipArchive OpenXML package
@return array    Key-value pairs containing document meta data
11782
protected function extractMetaData(ZipArchive $package)
    {
        // Data holders
        $coreProperties = array();

        // Read relations and search for core properties
        $relations = simplexml_load_string($package->getFromName("_rels/.rels"));
        foreach ($relations->Relationship as $rel) {
            if ($rel["Type"] == Zend_Search_Lucene_Document_OpenXml::SCHEMA_COREPROPERTIES) {
                // Found core properties! Read in contents...
                $contents = simplexml_load_string(
                    $package->getFromName(dirname($rel["Target"]) . "/" . basename($rel["Target"]))
                );

                foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_DUBLINCORE) as $child) {
                    $coreProperties[$child->getName()] = (string)$child;
                }
                foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_COREPROPERTIES) as $child) {
                    $coreProperties[$child->getName()] = (string)$child;
                }
                foreach ($contents->children(Zend_Search_Lucene_Document_OpenXml::SCHEMA_DUBLINCORETERMS) as $child) {
                    $coreProperties[$child->getName()] = (string)$child;
                }
            }
        }

        return $coreProperties;
    }
898208
public function getFileList( PackageInterface $package, $map ) {
    $directory = $this->getDirectory( $package );
    $result    = [];

    try {

      foreach( $map as $source => $destination ) {
        if( !is_dir( $directory . $source ) ) $result[ $directory . $source ] = Autoload::DIRECTORY . $destination;
        else {

          $iterator = new \RecursiveIteratorIterator(
            new \RecursiveDirectoryIterator( $directory . $source, \RecursiveDirectoryIterator::SKIP_DOTS ),
            \RecursiveIteratorIterator::SELF_FIRST
          );

          foreach( $iterator as $item ) {
            /** @var SplFileInfo $item */
            if( !$item->isDir() ) {
              $result[ $item->getRealPath() ] = Autoload::DIRECTORY . $destination . DIRECTORY_SEPARATOR . call_user_func( [ $iterator, 'getSubPathName' ] );
            }
          }
        }
      }

    } catch( \Throwable $e ) {
      $this->io->writeError( "Spoom\\Composer: Skip {$package->getPrettyName()} public copy, due to an error" );
    }

    return $result;
  }
1028902
public function parseZip($packageHandle, $packageVersion, $path, $relDirectory = '', $searchDictionaryFiles = self::DICTIONARY_ALL)
    {
        $zip = $this->app->make(DecompressedPackage::class, ['packageArchive' => $path, 'volatileDirectory' => null]);
        $zip->extract();
        $result = $this->parseDirectory($packageHandle, $packageVersion, $zip->getExtractedWorkDir(), $relDirectory, $searchDictionaryFiles);
        unset($zip);

        return $result;
    }
90106
public function findPackageConfiguration($package)
    {
        $paths = [
            $this->paths->getBasePath().'vendor/%s/src/config',
            $this->paths->getBasePath().'vendor/%s/config',
            $this->paths->getRocketeerPath().'/vendor/%s/src/config',
            $this->paths->getRocketeerPath().'/vendor/%s/config',
            $this->paths->getUserHomeFolder().'/.composer/vendor/%s/src/config',
            $this->paths->getUserHomeFolder().'/.composer/vendor/%s/config',
        ];

        // Check for the first configuration path that exists
        $paths = array_map(function ($path) use ($package) {
            return sprintf($path, $package);
        }, $paths);

        return $paths;
    }
1278591
protected function processPackage(Package $package)
    {
        $extra = $package->getExtra();
        $files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null;
        $this->originalFiles[$package->getPrettyName()] = $files;

        if (is_array($files)) {
            $this->addFiles($package, $files);
        }
        if ($package->isRoot()) {
            $this->loadDotEnv($package);
            if (!empty($extra[self::EXTRA_DEV_OPTION_NAME])) {
                $this->addFiles($package, $extra[self::EXTRA_DEV_OPTION_NAME]);
            }
        }

        $aliases = $package->collectAliases();

        $this->builder->mergeAliases($aliases);
        $this->builder->setPackage($package->getPrettyName(), array_filter([
            'name' => $package->getPrettyName(),
            'version' => $package->getVersion(),
            'reference' => $package->getSourceReference() ?: $package->getDistReference(),
            'aliases' => $aliases,
        ]));
    }
1356432
private function getFileMap(PackageInterface $package, $directory)
    {
        $files = [];
        $root  = $this->getInstallPath($package);

        if (!file_exists($root . '/' . $directory)) {
            return [];
        }

        $iterator = new RecursiveDirectoryIterator($root . '/' . $directory, RecursiveDirectoryIterator::SKIP_DOTS);

        /** @var SplFileInfo $file */
        foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as $file) {
            if ($file->isFile()) {
                $path = str_replace($root . '/' . $directory . '/', '', $file->getPathname());

                $files[$directory . '/' . $path] = $path;
            }
        }

        return $files;
    }
1157740
public void extract(@NotNull final byte[] xmpBytes, @NotNull Metadata metadata)
    {
        extract(xmpBytes, metadata, null);
    }
490467
protected function searchProvides($package)
    {
        $packageName = $package instanceof Package ? $package->getName() : $package;
        $providesJsonLocation = base_path("vendor/{$packageName}/provides.json");
        if (file_exists($providesJsonLocation)) {
            $provides = json_decode(str_replace('\\', '\\\\', file_get_contents($providesJsonLocation)), true);
            $return = array('providers' => array(), 'aliases' => array());
            if (isset($provides['providers']) && is_array($provides['providers'])) {
                $return['providers'] = $provides['providers'];
            }
            if (isset($provides['aliases']) && is_array($provides['aliases'])) {
                $return['aliases'] = $provides['aliases'];
            }
            return $return;
        }
        return false;
    }
1235836
private function loadPackageRuleSet(Package $package)
    {
        $ruleSet = new RuleSet();
        $key = $package->generatePackageKey();

        if ($this->cache->has($key)) {
            $ruleSet = $this->cache->getCachedRuleSet($key);
        } elseif (is_dir($path = $package->getPackagePath(self::PACKAGE_PATH))) {
            $ruleSet = $this->traverser->traverse($path);
            $this->cache->cacheRuleSet($key, $ruleSet);
        } else {
            // there is no vendor package in the given path
        }

        return $ruleSet;
    }
1315787
private function getMappedPackageList(array $packages): array
    {
        $groupedPackages = $this->groupPackagesByName($packages);

        $mappedPackages = [];
        foreach ($groupedPackages as $name => $packages) {
            $highest = $this->getHighestVersion($packages);

            $mappedPackages[$name] = [
                'highest' => $highest,
                'abandoned' => $highest instanceof CompletePackageInterface ? $highest->isAbandoned() : false,
                'replacement' => $highest instanceof CompletePackageInterface ? $highest->getReplacementPackage() : null,
                'versions' => $this->getDescSortedVersions($packages),
            ];
        }

        return $mappedPackages;
    }
847979
protected function extractArchive($archiveFile)
    {
        $archiveDir    = dirname($archiveFile);
        $archiveObj    = new ZipArchive();
        $archiveHandle = $archiveObj->open($archiveFile);
        if (true !== $archiveHandle) {
            return array('error' => __('Could not open archive'));
        }

        if (!$archiveObj->extractTo($archiveDir)) {
            $archiveObj->close();
            return array('error' => __('Could not extract archive'));
        }
        $archiveObj->close();
        return $archiveDir;
    }
1063844
protected function extractPatchData(PackageInterface $package, $patchData)
    {
        $levels = null;
        if (is_string($patchData)) {
            $path = $patchData;
        } else {
            if (!is_array($patchData) || !isset($patchData['path']) || is_string($patchData['path'])) {
                throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...]', $package, "The value of a patch must be a string or an array with a 'path' node value.");
            }
            $path = $patchData['path'];
            if (isset($patchData['levels'])) {
                $levels = $patchData['levels'];
                if (!is_array($levels) || empty($levels)) {
                    throw new Exception\InvalidPackageConfigurationValue($package, 'extra.patches.[...].levels', $package, 'The patch levels must be an array of strings.');
                }
            }
        }
        if ($levels === null) {
            $levels = $this->getDefaultPatchLevels();
        }

        return array($path, $levels);
    }
1372162
public static function readFile($package)
    {
        $root = dirname(dirname(dirname(dirname(dirname(dirname(__FILE__))))));
        $path = implode(DIRECTORY_SEPARATOR, array($root, $package, 'composer.json'));
        Logger::trace("Reading composer file %s", $path);
        if (file_exists($path)) {
            $composer = json_decode(file_get_contents($path), true);
            if (array_key_exists('require', $composer) && !empty($composer['require'])) {
                $directories = array($package);
                Logger::trace("Checking dependencies for package %s", $package);
                foreach ($composer['require'] as $requirement => $version) {
                    $directories = array_merge(self::readFile($requirement), $directories);
                }
                return $directories;
            } else {
                Logger::trace("Package %s has no dependencies", $package);
                return array($package);
            }
        } else {
            return array();
        }
    }
88802
protected function getAppViewPaths(string $package): array
    {
        return \array_map(function ($path) use ($package) {
            return "{$path}/packages/{$package}";
        }, $this->app->make('config')->get('view.paths', []));
    }
1021879
protected function getPackageEntryPoints(PackageInterface $package)
    {
        $dir = $this->composer->getInstallationManager()->getInstallPath($package);
        $entry = $this->getPackageExtra($package, 'wordpress-muplugin-entry');
        $entryPoints = $entry ? (is_array($entry) ? $entry : [ $entry ]) : [];

        if (empty($entryPoints)) {
            $phpFiles = glob(rtrim($dir, '/') . '/*.php', GLOB_NOSORT);

            foreach ($phpFiles as $file) {
                $entryPoints[] = basename($file);
            }
        }

        foreach ($entryPoints as $index => $file) {
            $entryPoints[ $index ] = $dir . $file;
        }

        return array_filter($entryPoints, [ $this, 'looksLikePlugin' ]);
    }
1264300
public function bind(Package $package = null)
    {
        $package = $package ?: new Package();
        $xml     = $this->xml;

        // Epub version:
        $package->version = (string) $xml['version'];
        
        $this->processMetadataElement($xml->metadata, $package->metadata);
        $this->processManifestElement($xml->manifest, $package->manifest);
        $this->processSpineElement($xml->spine, $package->spine, $package->manifest, $package->navigation);

        if ($xml->guide) {
            $this->processGuideElement($xml->guide, $package->guide);
        }

        return $package;
    }
1066241
protected function getPackageMigrationPaths(string $package): array
    {
        return collect($this->option('path') ?: 'database/migrations')
                    ->map(function ($path) use ($package) {
                        return $this->packagePath.'/'.$package.'/'.$path;
                    })->all();
    }