b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / composer / composer / src / Composer / Repository /
Filename/home/dev2.destoffenstraat.com/vendor/composer/composer/src/Composer/Repository/ArrayRepository.php
Size5.96 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified29-Sep-2023 10:50
Last accessed23-Aug-2025 03:56
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php

/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Composer\Repository;

use Composer\Package\AliasPackage;
use Composer\Package\PackageInterface;
use Composer\Package\CompletePackageInterface;
use Composer\Package\Version\VersionParser;
use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Constraint\Constraint;

/**
* A repository implementation that simply stores packages in an array
*
* @author Nils Adermann <naderman@naderman.de>
*/
class ArrayRepository extends BaseRepository
{
/** @var PackageInterface[] */
protected $packages;

/**
* @var PackageInterface[] indexed by package unique name and used to cache hasPackage calls
*/
protected $packageMap;

public function __construct(array $packages = array())
{
foreach ($packages as $package) {
$this->addPackage($package);
}
}

/**
* {@inheritDoc}
*/
public function findPackage($name, $constraint)
{
$name = strtolower($name);

if (!$constraint instanceof ConstraintInterface) {
$versionParser = new VersionParser();
$constraint = $versionParser->parseConstraints($constraint);
}

foreach ($this->getPackages() as $package) {
if ($name === $package->getName()) {
$pkgConstraint = new Constraint('==', $package->getVersion());
if ($constraint->matches($pkgConstraint)) {
return $package;
}
}
}

return null;
}

/**
* {@inheritDoc}
*/
public function findPackages($name, $constraint = null)
{
// normalize name
$name = strtolower($name);
$packages = array();

if (null !== $constraint && !$constraint instanceof ConstraintInterface) {
$versionParser = new VersionParser();
$constraint = $versionParser->parseConstraints($constraint);
}

foreach ($this->getPackages() as $package) {
if ($name === $package->getName()) {
$pkgConstraint = new Constraint('==', $package->getVersion());
if (null === $constraint || $constraint->matches($pkgConstraint)) {
$packages[] = $package;
}
}
}

return $packages;
}

/**
* {@inheritDoc}
*/
public function search($query, $mode = 0, $type = null)
{
$regex = '{(?:'.implode('|', preg_split('{\s+}', $query)).')}i';

$matches = array();
foreach ($this->getPackages() as $package) {
$name = $package->getName();
if (isset($matches[$name])) {
continue;
}
if (preg_match($regex, $name)
|| ($mode === self::SEARCH_FULLTEXT && $package instanceof CompletePackageInterface && preg_match($regex, implode(' ', (array) $package->getKeywords()) . ' ' . $package->getDescription()))
) {
if (null !== $type && $package->getType() !== $type) {
continue;
}

$matches[$name] = array(
'name' => $package->getPrettyName(),
'description' => $package instanceof CompletePackageInterface ? $package->getDescription() : null,
);
}
}

return array_values($matches);
}

/**
* {@inheritDoc}
*/
public function hasPackage(PackageInterface $package)
{
if ($this->packageMap === null) {
$this->packageMap = array();
foreach ($this->getPackages() as $repoPackage) {
$this->packageMap[$repoPackage->getUniqueName()] = $repoPackage;
}
}

return isset($this->packageMap[$package->getUniqueName()]);
}

/**
* Adds a new package to the repository
*
* @param PackageInterface $package
*/
public function addPackage(PackageInterface $package)
{
if (null === $this->packages) {
$this->initialize();
}
$package->setRepository($this);
$this->packages[] = $package;

if ($package instanceof AliasPackage) {
$aliasedPackage = $package->getAliasOf();
if (null === $aliasedPackage->getRepository()) {
$this->addPackage($aliasedPackage);
}
}

// invalidate package map cache
$this->packageMap = null;
}

protected function createAliasPackage(PackageInterface $package, $alias, $prettyAlias)
{
return new AliasPackage($package instanceof AliasPackage ? $package->getAliasOf() : $package, $alias, $prettyAlias);
}

/**
* Removes package from repository.
*
* @param PackageInterface $package package instance
*/
public function removePackage(PackageInterface $package)
{
$packageId = $package->getUniqueName();

foreach ($this->getPackages() as $key => $repoPackage) {
if ($packageId === $repoPackage->getUniqueName()) {
array_splice($this->packages, $key, 1);

// invalidate package map cache
$this->packageMap = null;

return;
}
}
}

/**
* {@inheritDoc}
*/
public function getPackages()
{
if (null === $this->packages) {
$this->initialize();
}

return $this->packages;
}

/**
* Returns the number of packages in this repository
*
* @return int Number of packages
*/
public function count()
{
return count($this->packages);
}

/**
* Initializes the packages array. Mostly meant as an extension point.
*/
protected function initialize()
{
$this->packages = array();
}
}