/*!
\static
\return An associative array with the possible types for a package.
Each entry contains an \c id and a \c name key.
769751
static function typeList()
    {
        $typeList =& $GLOBALS['eZPackageTypeList'];
        if ( !isset( $typeList ) )
        {
            $typeList = array();
            $ini = eZINI::instance( 'package.ini' );
            $types = $ini->variable( 'PackageSettings', 'TypeList' );
            foreach ( $types as $typeID => $typeName )
            {
                $typeList[] = array( 'name' => $typeName,
                                     'id' => $typeID );
            }
        }
        return $typeList;
    }
27031
static function import_php( $package, $silent = false ){
		
		$type = current( explode('.', $package) );
		$paths = self::collect_package( $package, 'php', $silent, 'conf' );
		
		if( !$silent && empty($paths) ){
			trigger_error("Bad import `$package'", E_USER_ERROR );
		}
		
		foreach( $paths as $cname => $path ){
			// leniant inclusion if silent
			if( $silent ){
				include_once $path;
				continue;
			}
			// path should already be validated by collect_package
			require_once $path;
			// Run checks according to type of import
			switch( $type ){
			case 'conf':
				break;
			default:
				// Class or function import must define an entity with the same name as the file
				// testing function first to avoid call to __autoload
				if( ! function_exists($cname) && ! class_exists($cname) ){
					trigger_error( "Class, or function '$cname' not defined in file `$path'", E_USER_ERROR );
				}
			}
		}
	}
875678
public function getAllInstalledPackages(bool $rescan = false): array
    {
        if (!$rescan && !empty(self::$allInstalledPackages)) {
            return self::$allInstalledPackages;
        }

        $compiledFile = $this->pathHelper->realize('{MELIOR_BASE}/Data/Persistent/Compiler/Packages/package.map');
        if (!$rescan && is_file($compiledFile)) {
            $result = \unserialize(\file_get_contents($compiledFile));
        } else {
            $result = array_merge(
                $this->getLibraries($rescan),
                $this->getPlugins($rescan),
                $this->getApplicationPackages($rescan)
            );
        }

        self::$allInstalledPackages = $result;

        return $result;
    }
1148055
public function listDataTypesOptions() {
    $data = $this->loadDataTypeData();

    $return = [];
    foreach ($data as $id => $data_item) {
      $return[$id] = $data_item['label'];
    }

    return $return;
  }
242901
protected function getPackageConfig($key = null)
    {
        if (! file_exists('integrated.json') && ! file_exists('integrated.php')) {
            return [];
        }

        if ( ! $this->packageConfig) {
            $this->loadPreferredConfigFile();
        }

        if ($key) {
            if (! isset($this->packageConfig[$key])) {
                throw new IntegratedException(
                    "Hmm, did you set a '{$key}' key in your integrated.(json|php) file? Can't find it!"
                );
            }

            return $this->packageConfig[$key];
        }

        return $this->packageConfig;
    }
594770
public function get_assoc()
    {
        $out     = array('name' => $this->displayname);
        $typemap = $this->typemap;

        // copy name fields to output array
        foreach (array('firstname','surname','middlename','nickname','organization') as $col) {
            if (strlen($this->$col)) {
                $out[$col] = $this->$col;
            }
        }

        if ($this->raw['N'][0][3])
            $out['prefix'] = $this->raw['N'][0][3];
        if ($this->raw['N'][0][4])
            $out['suffix'] = $this->raw['N'][0][4];

        // convert from raw vcard data into associative data for Roundcube
        foreach (array_flip(self::$fieldmap) as $tag => $col) {
            foreach ((array)$this->raw[$tag] as $i => $raw) {
                if (is_array($raw)) {
                    $k       = -1;
                    $key     = $col;
                    $subtype = '';

                    if (!empty($raw['type'])) {
                        $combined = join(',', self::array_filter((array)$raw['type'], 'internet,pref', true));
                        $combined = strtoupper($combined);

                        if ($typemap[$combined]) {
                            $subtype = $typemap[$combined];
                        }
                        else if ($typemap[$raw['type'][++$k]]) {
                            $subtype = $typemap[$raw['type'][$k]];
                        }
                        else {
                            $subtype = strtolower($raw['type'][$k]);
                        }

                        while ($k < count($raw['type']) && ($subtype == 'internet' || $subtype == 'pref')) {
                            $subtype = $typemap[$raw['type'][++$k]] ?: strtolower($raw['type'][$k]);
                        }
                    }

                    // read vcard 2.1 subtype
                    if (!$subtype) {
                        foreach ($raw as $k => $v) {
                            if (!is_numeric($k) && $v === true && ($k = strtolower($k))
                                && !in_array($k, array('pref','internet','voice','base64'))
                            ) {
                                $k_uc    = strtoupper($k);
                                $subtype = $typemap[$k_uc] ?: $k;
                                break;
                            }
                        }
                    }

                    // force subtype if none set
                    if (!$subtype && preg_match('/^(email|phone|address|website)/', $key)) {
                        $subtype = 'other';
                    }

                    if ($subtype) {
                        $key .= ':' . $subtype;
                    }

                    // split ADR values into assoc array
                    if ($tag == 'ADR') {
                        list(,, $value['street'], $value['locality'], $value['region'], $value['zipcode'], $value['country']) = $raw;
                        $out[$key][] = $value;
                    }
                    else {
                        $out[$key][] = $raw[0];
                    }
                }
                else {
                    $out[$col][] = $raw;
                }
            }
        }

        // handle special IM fields as used by Apple
        foreach ($this->immap as $tag => $type) {
            foreach ((array)$this->raw[$tag] as $i => $raw) {
                $out['im:'.$type][] = $raw[0];
            }
        }

        // copy photo data
        if ($this->raw['PHOTO']) {
            $out['photo'] = $this->raw['PHOTO'][0][0];
        }

        return $out;
    }
1070856
static function languageInfoFromPackageList( $packageNameList, $withLanguageNames = false )
    {
        $languageInfo = array();
        foreach( $packageNameList as $packageName )
        {
            $package = eZPackage::fetch( $packageName, false, false, false );
            if( is_object( $package ) )
            {
                $packageLanguageInfo = $package->languageInfo( $withLanguageNames );
                // merge arrays
                if( $withLanguageNames )
                {
                    // we have array like 'locale' => 'name'. can use array_merge
                    $languageInfo = array_merge( $languageInfo, $packageLanguageInfo );
                }
                else
                {
                    foreach( $packageLanguageInfo as $languageLocale )
                    {
                        if( !in_array( $languageLocale, $languageInfo ) )
                        {
                            $languageInfo[] = $languageLocale;
                        }
                    }
                }
            }
            else
            {
                eZDebug::writeWarning( "Unable to fetch package '$packageName'", __METHOD__ );
            }
        }

        return $languageInfo;
    }
826492
public function getCompatible()
    {
        if (is_array($this->_compatible)) return $this->_compatible;
        $this->_compatible = array();
        if(!isset($this->_packageXml->compatible->package)) {
            return array();
        }
        foreach ($this->_packageXml->compatible->package as $_package) {
            $this->_compatible[] = array(
                'name'    => (string)$_package->name,
                'channel' => (string)$_package->channel,
                'min'     => (string)$_package->min,
                'max'     => (string)$_package->max
            );
        }
        return $this->_compatible;
    }
429014
public function asContainArray()
    {
        $associations = [];
        foreach ($this->_associations as $assoc) {
            $associations += $assoc->asContainArray();
        }
        $config = $this->_config;
        if ($this->_forMatching !== null) {
            $config = ['matching' => $this->_forMatching] + $config;
        }

        return [
            $this->_name => [
                'associations' => $associations,
                'config' => $config
            ]
        ];
    }
298240
function fetchDependentPackages( $dependencyType, &$failedList )
    {
        $packages = array();
        $provides = $this->Parameters['dependencies'][$dependencyType];

        if ( $provides != null )
        {
            foreach ( $provides as $provide )
            {
                // fetch only dependent packages, not package items.
                if ( $provide['type'] == 'ezpackage' )
                {
                    // TODO: Add fetching from URL (not here ?)
                    $package = $this->fetch( $provide['name'] );

                    if ( !$package )
                    {
                        $failedList[] = $provide['name'];
                        continue;
                    }
                    $packages[] =& $package;
                }
            }
        }
        return $packages;
    }
217814
protected function packagesToIgnore()
    {
        if (! file_exists($this->basePath.'/composer.json')) {
            return [];
        }

        $json = json_decode(file_get_contents($this->basePath.'/composer.json'), true);

        return $json['extra']['nano7']['dont-discover'] ? $json['extra']['nano7']['dont-discover'] : [];
    }
1157479
public function getPackageType(): string
    {
        //if it starts with / like /foo/bar
        if (strpos($this->name, '/') === 0) {
            //it's a root package
            return self::TYPE_ROOT;
        }

        //if theres a slash like foo/bar
        if (strpos($this->name, '/') !== false) {
            //it's vendor package
            return self::TYPE_VENDOR;
        }

        //by default it's a pseudo package
        return self::TYPE_PSEUDO;
    }
1289849
public static function getListByPackage($pkg)
    {
        $db = Loader::db();
        $list = [];

        $q = $db->query('SELECT * FROM AuthenticationTypes WHERE pkgID=?', [$pkg->getPackageID()]);
        while ($row = $q->FetchRow()) {
            $list[] = self::load($row);
        }

        return $list;
    }
551193
function &_resolveLink()
    {
        $phpdoctor = $this->_root->phpdoctor();
        $matches = array();
        $return = NULL;
        $packageRegex = '[a-zA-Z0-9_\x7f-\xff .\\\\-]+';
        $labelRegex = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*';
        $regex = '/^\\\\?(?:('.$packageRegex.')[.\\\\])?(?:('.$labelRegex.')(?:#|::))?\$?('.$labelRegex.')(?:\(\))?$/';
        if (preg_match($regex, $this->_link, $matches)) {
            $packageName = $matches[1];
            $className = $matches[2];
            $elementName = $matches[3];

            if ($packageName) { // get package
                $package =& $this->_root->packageNamed($packageName);
                if (!$package) {
                    return $return;
                }
            }
            if ($className) { // get class
                if (isset($package)) {
                    $classes =& $package->allClasses();
                } else {
                    $classes =& $this->_root->classes();
                }
                if ($classes) {
                    foreach ($classes as $key => $class) {
                        if ($class->name() == $className) {
                            break;
                        }
                    }
                    $class =& $classes[$key];
                }
            }
            if ($elementName) { // get element
                if (isset($class)) { // from class
                    $methods =& $class->methods();
                    if ($methods) {
                        foreach ($methods as $key => $method) {
                            if ($method->name() == $elementName) {
                                $element =& $methods[$key];
                                break;
                            }
                        }
                    }
                    if (!isset($element)) {
                        $fields =& $class->fields();
                        if ($fields) {
                            foreach ($fields as $key => $field) {
                                if ($field->name() == $elementName) {
                                    $element =& $fields[$key];
                                    break;
                                }
                            }
                        }
                    }
                } elseif (isset($package)) { // from package
                    $classes =& $package->allClasses();
                    foreach ($classes as $key => $class) {
                        if ($class->name() == $elementName) {
                            $element =& $classes[$key];
                            break;
                        }
                        $methods =& $class->methods();
                        if ($methods) {
                            foreach ($methods as $key => $method) {
                                if ($method->name() == $elementName) {
                                    $element =& $methods[$key];
                                    break 2;
                                }
                            }
                        }
                        if (!isset($element)) {
                            $fields =& $class->fields();
                            if ($fields) {
                                foreach ($fields as $key => $field) {
                                    if ($field->name() == $elementName) {
                                        $element =& $fields[$key];
                                        break 2;
                                    }
                                }
                            }
                        }
                    }
                    if (!isset($element)) {
                        $functions =& $package->functions();
                        if ($functions) {
                            foreach ($functions as $key => $function) {
                                if ($function->name() == $elementName) {
                                    $element =& $functions[$key];
                                    break;
                                }
                            }
                        }
                        if (!isset($element)) {
                            $globals =& $package->globals();
                            if ($globals) {
                                foreach ($globals as $key => $global) {
                                    if ($global->name() == $elementName) {
                                        $element =& $globals[$key];
                                        break;
                                    }
                                }
                            }
                        }
                    }
                } else { // from anywhere
                    $classes =& $this->_root->classes();
                    if ($classes) {
                        foreach ($classes as $key => $class) {
                            if ($class->name() == $elementName) {
                                $element =& $classes[$key];
                                break;
                            }
                            $methods =& $class->methods();
                            if ($methods) {
                                foreach ($methods as $key => $method) {
                                    if ($method->name() == $elementName) {
                                        $element =& $methods[$key];
                                        break 2;
                                    }
                                }
                            }
                            if (!isset($element)) {
                                $fields =& $class->fields();
                                if ($fields) {
                                    foreach ($fields as $key => $field) {
                                        if ($field->name() == $elementName) {
                                            $element =& $fields[$key];
                                            break 2;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (!isset($element)) {
                        $functions =& $this->_root->functions();
                        if ($functions) {
                            foreach ($functions as $key => $function) {
                                if ($function->name() == $elementName) {
                                    $element =& $functions[$key];
                                    break;
                                }
                            }
                        }
                        if (!isset($element)) {
                            $globals =& $this->_root->globals();
                            if ($globals) {
                                foreach ($globals as $key => $global) {
                                    if ($global->name() == $elementName) {
                                        $element =& $globals[$key];
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $return =& $element;
        }

        return $return;
    }
1116511
public static function getListByPackage($pkg)
    {
        $em = \ORM::entityManager();
        return $em->getRepository('\Concrete\Core\Entity\File\StorageLocation\Type\Type')->findBy(
            array('pkgID' => $pkg->getPackageID()), array('fslTypeID' => 'asc')
        );
    }
1162256
public function returnTypeAsString()
    {
        $myPackage =& $this->containingPackage();
        $classDoc =& $this->_returnType->asClassDoc();
        if ($classDoc) {
            $packageDoc =& $classDoc->containingPackage();

            return '<a href="'.str_repeat('../', $myPackage->depth() + 1).$classDoc->asPath().'">'.$classDoc->name().$this->_returnType->dimension().'</a>';
        } else {
            return $this->_returnType->typeName().$this->_returnType->dimension();
        }
    }
965926
public function findPackages()
    {
        $root = new Package($this->composer->getPackage(), $this->composer);
        $this->plainList[$root->getPrettyName()] = $root;
        foreach ($this->composer->getRepositoryManager()->getLocalRepository()->getCanonicalPackages() as $package) {
            $this->plainList[$package->getPrettyName()] = new Package($package, $this->composer);
        }
        $this->orderedList = [];
        $this->iteratePackage($root, true);

        $res = [];
        foreach (array_keys($this->orderedList) as $name) {
            $res[] = $this->plainList[$name];
        }

        return $res;
    }