Returns a complete list of packages and respective details from a composer.lock file

@param string $fileIn
@param array $inParametersArray
@return array
432778
protected function getPackageDetailsFromGivenComposerLockFileEnhanced($fileIn, $inParametersArray = [])
    {
        if (!file_exists($fileIn)) {
            return ['error' => $fileIn . ' was not found'];
        }
        $alnfo    = [];
        $packages = $this->getPkgFileInListOfPackageArrayOut($fileIn);
        $pkgType  = $this->decisionPackageOrPackageDev($inParametersArray);
        foreach ($packages[$pkgType] as $key => $value) {
            $keyToUse = $value['name'];
            if (array_key_exists('Not Grouped By Name', $inParametersArray)) {
                $keyToUse = $key;
            }
            $alnfo[$keyToUse] = $this->mergePackageAttributes($value, $inParametersArray);
            ksort($alnfo[$keyToUse]);
        }
        ksort($alnfo);
        return $alnfo;
    }
650109
private function _packageMapping($packageId = '')
    {
        $this->debug->debug(__FUNCTION__, 'Input PackageId: ' . json_encode($packageId));
        $this->debug->debug(__FUNCTION__, 'List Package: ' . json_encode($this->listPackage));
        if (array_key_exists($packageId, $this->listPackage)) {
            $result = $this->listPackage[$packageId];
        } else {
            $result = [
                'serviceId'   => '',
                'packageId'   => '',
                "commandId"   => "",
                "name"        => "",
                "nameDesc"    => "",
                "descCircle"  => "",
                "usePrice"    => '',
                "priceDesc"   => "",
                "priceCircle" => "",
                'renewCircle' => ''
            ];
        }
        $this->debug->info(__FUNCTION__, 'Final Result: ' . json_encode($result));

        return $result;
    }
1082827
public function parseComposerExtra(PackageInterface $package, $package_dir)
    {
        $presets = array();
        $extra = $package->getExtra();
        if (isset($extra['assets-presets'])) {
            foreach ($extra['assets-presets'] as $index=>$item) {
                $use_item = array();
                foreach (array_keys(Config::get('use-statements')) as $statement) {
                    if (isset($item[$statement])) {
                        $item_statement = is_array($item[$statement]) ?
                            $item[$statement] : array($item[$statement]);
                        $use_item[$statement] = array();
                        foreach ($item_statement as $path) {
                            $use_item[$statement][] = $path;
                        }
                    }
                    if (!empty($use_item)) {
                        $presets[$index] = $use_item;
                    }
                }
            }

            $relative_path = str_replace($this->getAssetsVendorDir() . '/', '', $package_dir);
            if ($relative_path===$package_dir) {
                $relative_path = str_replace($this->getAppBasePath(), '', $package_dir);
            }
            if (strlen($relative_path)) {
                $relative_path = trim($relative_path, '/');
            }

            return array(
                'name'          => $package->getPrettyName(),
                'version'       => $package->getVersion(),
                'relative_path' => $relative_path,
                'assets_presets'=> $presets
            );
        }
        return null;
    }
1054119
protected static function copyDeltasFromPackage(PackageInterface $package, $vendorDir)
    {
        $sp = DIRECTORY_SEPARATOR;
        $path = $vendorDir . $sp . $package->getName() . $sp . 'install/dbdeploy';


        if (false === file_exists($path)) {
            return [];
        }

        $files = glob("$path/*.sql");
        $deltaPath = 'dbdeploy' . $sp . self::CACHE_DELTAS_PATH . $sp;

        if (!file_exists($_SERVER['DOCUMENT_ROOT'] . '/../' . $deltaPath)) {
            mkdir($_SERVER['DOCUMENT_ROOT'] . '/../' . $deltaPath, 0777);
            chmod($_SERVER['DOCUMENT_ROOT'] . '/../' . $deltaPath, 0777);
        }


        $deltas = [];

        foreach ($files as $file) {
            copy($file, $deltaPath . basename($file));
            $deltas[] = $deltaPath . basename($file);
        }

        if (empty($files)) {
            return [];
        }

        return $deltas;
    }
479731
protected function getPackages()
    {
        $translator = $this->container->get('translator');
        $errorMessage = $translator->trans('settings.version.error_parsing_composer');

        $composerPath = $this->getLockPath();
        if (!file_exists($composerPath)) {
            throw new ParseException(
                $translator->trans('settings.version.composer_lock_not_found')
            );
        }

        $json = file_get_contents($composerPath);
        $result = json_decode($json, true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            throw new ParseException($errorMessage.' (#'.json_last_error().')');
        }

        if (array_key_exists('packages', $result) && is_array($result['packages'])) {
            return $result['packages'];
        }

        // No package list in JSON structure
        throw new ParseException($errorMessage);
    }
269661
protected function getVariables(
        $vendor,
        $package,
        $vendorFolderName,
        $packageFolderName
    ) {
        $packageWords = str_replace('-', ' ', Str::snake($packageFolderName));

        $composerDescription = $this->askUser(
            'The composer description?', "A $packageWords"
        );
        $composerKeywords = $this->getComposerKeywords($packageWords);

        $packageHumanName = $this->askUser(
            'The package human name?', Str::title($packageWords)
        );

        return [
            'vendor' => $vendor,
            'package' => $package,
            'vendorFolderName' => $vendorFolderName,
            'packageFolderName' => $packageFolderName,
            'packageHumanName' => $packageHumanName,

            'composerName' => "$vendorFolderName/$packageFolderName",
            'composerDesc' => $composerDescription,
            'composerKeywords' => $composerKeywords,
            'license' => $this->askUser('The package licence?', 'MIT'),
            'phpVersion' => $this->askUser('Php version constraint?', '>=7.0'),

            'aliasName' => $packageFolderName,
            'configFileName' => $packageFolderName,

            'year' => date('Y'),

            'name' => $this->askUser('Your name?'),
            'email' => $this->askUser('Your email?'),
            'githubPackageUrl' => "https://github.com/$vendorFolderName/$packageFolderName",
        ];
    }
1157684
public function convertPackageToArray(PackageInterface $package, PackageInterface $upgrade = null)
    {
        $name = $package->getPrettyName();
        $data = new JsonArray([
            'name'       => $name,
            'version'    => $this->convertPackageVersion($package),
            'constraint' => $this->getConstraint($name),
            'type'       => $package->getType(),
            'locked'     => $this->isLocked($name),
        ]);

        if (null !== ($releaseDate = $package->getReleaseDate())) {
            $data->set('time', $releaseDate->format(\DateTime::ATOM));
        }

        if (null !== $upgrade) {
            $data->set('upgrade_version', $upgrade->getPrettyVersion());
            if (null !== ($upgradeReleaseDate = $upgrade->getReleaseDate())) {
                $data->set('upgrade_time', $upgradeReleaseDate->format(\DateTime::ATOM));
            }
        }

        if ($package instanceof CompletePackageInterface) {
            $this->convertCompletePackage($package, $data);
        }

        return $data;
    }
151183
public static Iterable<File> findFiles(final Collection<URL> inUrls, final String packagePrefix, final Predicate<String> nameFilter) {
        Predicate<File> fileNamePredicate = new Predicate<File>() {
            public boolean apply(File file) {
                String path = file.getRelativePath();
                if (path.startsWith(packagePrefix)) {
                    String filename = path.substring(path.indexOf(packagePrefix) + packagePrefix.length());
                    return !Utils.isEmpty(filename) && nameFilter.apply(filename.substring(1));
                } else {
                    return false;
                }
            }
        };

        return findFiles(inUrls, fileNamePredicate);
    }
654136
public function parseComposerExtra(PackageInterface $package, $assets_package_dir, $vendor_package_dir)
    {
        $data = $this->_autoloader->getAssetsInstaller()->parseComposerExtra($package, $assets_package_dir);
        if (is_null($data)) {
            $data = array();
        }
        $extra = $package->getExtra();
        $assets_package_dir = rtrim($assets_package_dir, '/') . '/';
        if (strlen($vendor_package_dir)) {
            $vendor_package_dir = rtrim($vendor_package_dir, '/') . '/';
        }

        $mapping = array(
            'layouts'=>'layouts_path',
            'views'=>'views_path',
            'views-functions'=>'views_functions'
        );
        foreach ($mapping as $json_name=>$var_name) {
            if (isset($extra[$json_name])) {
                $json_vals = is_array($extra[$json_name]) ? $extra[$json_name] : array($extra[$json_name]);
                $data[$var_name] = array();
                foreach ($json_vals as $json_val) {
                    $data[$var_name][] = $vendor_package_dir . $json_val;
                }
            }
        }
/*
        if (isset($extra['layouts'])) {
            $layouts = is_array($extra['layouts']) ? $extra['layouts'] : array($extra['layouts']);
            $data['layouts_path'] = array();
            foreach ($layouts as $layout_path) {
                $data['layouts_path'][] = $vendor_package_dir . $layout_path;
            }
        }

        if (isset($extra['views'])) {
            $views = is_array($extra['views']) ? $extra['views'] : array($extra['views']);
            $data['views_path'] = array();
            foreach ($views as $view_path) {
                $data['views_path'][] = $vendor_package_dir . $view_path;
            }
        }

        if (isset($extra['views-functions'])) {
            $views_fcts = is_array($extra['views-functions']) ? $extra['views-functions'] : array($extra['views-functions']);
            $data['views_functions'] = array();
            foreach ($views_fcts as $view_fct_path) {
                $data['views_functions'][] = $vendor_package_dir . $view_fct_path;
            }
        }
*/
        return !empty($data) ? $data : null;
    }
330371
static function fetchPackages( $parameters = array(), $filterArray = array() )
    {
        $packageRepositories = eZPackage::packageRepositories( $parameters );

        $packages = array();

        $requiredType = null;
        $requiredPriority = null;
        $requiredVendor = null;
        $requiredExtension = null;
        if ( isset( $filterArray['type'] ) )
            $requiredType = $filterArray['type'];
        if ( isset( $filterArray['priority'] ) )
            $requiredPriority = $filterArray['priority'];
        if ( isset( $filterArray['vendor'] ) )
            $requiredVendor = $filterArray['vendor'];
        if ( isset( $filterArray['extension'] ) )
            $requiredExtension = $filterArray['extension'];
        $repositoryID = false;
        if ( isset( $parameters['repository_id'] ) )
            $repositoryID = $parameters['repository_id'];
        $dbAvailable = true;
        if ( isset( $parameters['db_available'] ) )
            $dbAvailable = $parameters['db_available'];

        foreach ( $packageRepositories as $packageRepository )
        {
            if ( strlen( $repositoryID ) == 0 or
                 $repositoryID == $packageRepository['id'] )
            {
                $path = $packageRepository['path'];
                if ( file_exists( $path ) )
                {
                    $fileList = array();
                    $dir = opendir( $path );
                    while( ( $file = readdir( $dir ) ) !== false )
                    {
                        if ( $file == '.' or
                             $file == '..' )
                            continue;
                        $fileList[] = $file;
                    }
                    closedir( $dir );
                    sort( $fileList );
                    foreach ( $fileList as $file )
                    {
                        $dirPath = $path . '/' . $file;
                        if ( !is_dir( $dirPath ) )
                            continue;
                        $filePath = $dirPath . '/' . eZPackage::definitionFilename();
                        if ( file_exists( $filePath ) )
                        {
                            $fileModification = filemtime( $filePath );
                            $name = $file;
                            $packageCachePath = $dirPath . '/' . eZPackage::cacheDirectory() . '/package.php';
                            unset( $package );
                            $package = false;
                            $cacheExpired = false;
                            if ( eZPackage::useCache() )
                            {
                                $package = eZPackage::fetchFromCache( $dirPath, $fileModification, $cacheExpired );
                            }
                            if ( !$package )
                            {
                                $package = eZPackage::fetchFromFile( $filePath );
                                if ( $package and
                                     $cacheExpired and
                                     eZPackage::useCache() )
                                {
                                    $package->storeCache( $dirPath . '/' . eZPackage::cacheDirectory() );
                                }
                            }
                            if ( !$package )
                                continue;

                            if ( $dbAvailable )
                                $package->getInstallState();

                            if ( $requiredType !== null )
                            {
                                $type = $package->attribute( 'type' );
                                if ( $type != $requiredType )
                                    continue;
                            }

                            if ( $requiredPriority !== null )
                            {
                                $priority = $package->attribute( 'priority' );
                                if ( $priority != $requiredPriority )
                                    continue;
                            }

                            if ( $requiredExtension !== null )
                            {
                                $extension = $package->attribute( 'extension' );
                                if ( $extension != $requiredExtension )
                                    continue;
                            }

                            if ( $requiredVendor !== null )
                            {
                                $vendor = $package->attribute( 'vendor' );
                                if ( $vendor != $requiredVendor )
                                    continue;
                            }

                            $package->setCurrentRepositoryInformation( $packageRepository );

                            $packages[] =& $package;
                        }
                    }
                }
            }
        }
        return $packages;
    }
634544
private function getFilteredLinks(Composer $composer)
    {
        $links = array_values($composer->getPackage()->getRequires());

        // only pick up packages in our filter, if a filter has been set.
        if ($this->hasFilterForPackages()) {
            $packagesFilter = $this->packagesFilter;
            $links = array_filter($links, function (Link $link) use ($packagesFilter) {
                return in_array($link->getTarget(), $packagesFilter);
            });
        }

        return array_values($links);
    }
1202088
protected function getMethods(PackageClass $package_class)
    {
        try {
            $class = new \ReflectionClass($package_class->getName());
        } catch (\ReflectionException $e) {
            return [];
        }
        $methods = $class->getMethods();

        foreach ($methods as $key => $method) {
            if ($method->name === '__construct') {
                // The interface should not contain the constructor
                unset($methods[$key]);
                continue;
            }
            $methods[$key] = new ReflectionMethod($method);
        }

        return $methods;
    }
710615
protected function _getPackages( $manifest, $filter = array() )
	{
		$packageContainer = array();

		if( !isset( $manifest->pkgs ) || !is_array( $manifest->pkgs ) ) {
			throw new MW_Jsb2_Exception( 'No packages found' );
		}

		foreach( $manifest->pkgs as $package )
		{
			if( !isset( $package->name ) || !isset( $package->file ) || !is_object( $package ) ) {
				throw new MW_Jsb2_Exception( 'Invalid package content' );
			}

			if( !isset( $package->fileIncludes ) || !is_array( $package->fileIncludes ) ) {
				throw new MW_Jsb2_Exception( 'No files in package found' );
			}

			if( !in_array( $package->name, $filter ) ) {
				$packageContainer[ pathinfo( $package->file, PATHINFO_EXTENSION ) ][] = $package;
			}
		}

		return $packageContainer;
	}
855423
protected function setComposerLock() {
    if (file_exists($this->getConfigValue('repo.root') . '/composer.lock')) {
      $composer_lock = json_decode(file_get_contents($this->getConfigValue('repo.root') . '/composer.lock'), TRUE);
      $this->composerLock = $composer_lock;

      return $composer_lock;
    }

    return [];
  }
1343632
private function getDatetime($datein, $timein)
    {
        $date = explode('-', $datein);
        $time = explode(':', $timein);
        $datetime = Carbon::create($date[0], $date[1], $date[2], $time[0], $time[1]);

        return $datetime;
    }
645287
private function getNeedles($packageName, $packages, $inverted)
    {
        $needles = [$packageName];
        if ($inverted === false) {
            return $needles;
        }

        // Include replaced packages for inverted lookups as they are then the actual starting point to consider
        $mapCb = function (Link $link) {
            return $link->getTarget();
        };
        foreach ($packages as $package) {
            $needles = array_merge(
                $needles,
                array_map($mapCb, $package->getReplaces())
            );
        }

        return $needles;
    }
442656
protected function getPackagesData()
    {
        $composer = $this->event->getComposer();
        $locker = $composer->getLocker();
        if (isset($locker)) {
            $lockData = $locker->getLockData();
            $allPackages = isset($lockData['packages']) ? $lockData['packages'] : array();
        }

        $packages = array();
        // Only add those packages that we can reasonably
        // assume are components into our packages list
        foreach ($allPackages as $package) {
            if (isset($package['extra']['c33s-building-blocks']) && is_array($package['extra']['c33s-building-blocks'])) {
                $packages[] = $package;
            }
        }

        // Add the root package to the packages list.
        $root = $composer->getPackage();
        if ($root) {
            $dumper = new ArrayDumper();
            $package = $dumper->dump($root);

            if (isset($package['extra']['c33s-building-blocks']) && is_array($package['extra']['c33s-building-blocks'])) {
                $packages[] = $package;
            }
        }

        return $packages;
    }