本文整理汇总了PHP中Composer\Repository\ArrayRepository::initialize方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayRepository::initialize方法的具体用法?PHP ArrayRepository::initialize怎么用?PHP ArrayRepository::initialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Composer\Repository\ArrayRepository
的用法示例。
在下文中一共展示了ArrayRepository::initialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initialize
protected function initialize()
{
parent::initialize();
if (!extension_loaded('openssl') && 'https' === substr($this->url, 0, 5)) {
throw new \RuntimeException('You must enable the openssl extension in your php.ini to load information from ' . $this->url);
}
try {
$json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io));
$data = $json->read();
if (!empty($data['notify'])) {
if ('/' === $data['notify'][0]) {
$this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['notify'], $this->url);
} else {
$this->notifyUrl = $data['notify'];
}
}
$this->cache->write('packages.json', json_encode($data));
} catch (\Exception $e) {
if ($contents = $this->cache->read('packages.json')) {
$this->io->write('<warning>' . $this->url . ' could not be loaded, package information was loaded from the local cache and may be out of date</warning>');
$data = json_decode($contents, true);
} else {
throw $e;
}
}
$loader = new ArrayLoader();
$this->loadRepository($loader, $data);
}
示例2: initialize
protected function initialize()
{
parent::initialize();
$versionParser = new VersionParser();
try {
$prettyVersion = PHP_VERSION;
$version = $versionParser->normalize($prettyVersion);
} catch (\UnexpectedValueException $e) {
$prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
$version = $versionParser->normalize($prettyVersion);
}
$php = new MemoryPackage('php', $version, $prettyVersion);
$php->setDescription('The PHP interpreter');
parent::addPackage($php);
foreach (get_loaded_extensions() as $name) {
if (in_array($name, array('standard', 'Core'))) {
continue;
}
$reflExt = new \ReflectionExtension($name);
try {
$prettyVersion = $reflExt->getVersion();
$version = $versionParser->normalize($prettyVersion);
} catch (\UnexpectedValueException $e) {
$prettyVersion = '0';
$version = $versionParser->normalize($prettyVersion);
}
$ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion);
$ext->setDescription('The ' . $name . ' PHP extension');
parent::addPackage($ext);
}
}
示例3: initialize
protected function initialize()
{
parent::initialize();
$this->io->write('Initializing PEAR repository ' . $this->url);
$this->initializeChannel();
$this->io->write('Packages names will be prefixed with: pear-' . $this->channel . '/');
// try to load as a composer repo
try {
$json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io));
$packages = $json->read();
if ($this->io->isVerbose()) {
$this->io->write('Repository is Composer-compatible, loading via packages.json instead of PEAR protocol');
}
$loader = new ArrayLoader();
foreach ($packages as $data) {
foreach ($data['versions'] as $rev) {
if (strpos($rev['name'], 'pear-' . $this->channel) !== 0) {
$rev['name'] = 'pear-' . $this->channel . '/' . $rev['name'];
}
$this->addPackage($loader->load($rev));
if ($this->io->isVerbose()) {
$this->io->write('Loaded ' . $rev['name'] . ' ' . $rev['version']);
}
}
}
return;
} catch (\Exception $e) {
}
$this->fetchFromServer();
}
示例4: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!$this->file->exists()) {
return;
}
$packages = $this->file->read();
if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
}
$loader = new ArrayLoader();
foreach ($packages as $packageData) {
$package = $loader->load($packageData);
// package was installed as alias, so we only add the alias
if ($this instanceof InstalledRepositoryInterface && !empty($packageData['installed-as-alias'])) {
$alias = $packageData['installed-as-alias'];
$package->setAlias($alias);
$package->setPrettyAlias($alias);
$package->setInstalledAsAlias(true);
$this->addPackage($this->createAliasPackage($package, $alias, $alias));
} else {
// only add regular package - if it's not an installed repo the alias will be created on the fly
$this->addPackage($package);
}
}
}
示例5: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
$loader = new ArrayLoader();
foreach ($this->config as $package) {
$package = $loader->load($package);
$this->addPackage($package);
}
}
示例6: initialize
protected function initialize()
{
parent::initialize();
set_error_handler(function ($severity, $message, $file, $line) {
throw new \ErrorException($message, $severity, $severity, $file, $line);
});
$this->streamContext = StreamContextFactory::getContext();
$this->fetchFromServer();
restore_error_handler();
}
示例7: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!is_numeric(key($this->config))) {
$this->config = array($this->config);
}
$loader = new ArrayLoader();
foreach ($this->config as $package) {
$package = $loader->load($package);
$this->addPackage($package);
}
}
示例8: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
$loader = new ValidatingArrayLoader(new ArrayLoader(null, true), false);
foreach ($this->config as $package) {
try {
$package = $loader->load($package);
} catch (\Exception $e) {
throw new InvalidRepositoryException('A repository of type "package" contains an invalid package definition: ' . $e->getMessage() . "\n\nInvalid package definition:\n" . json_encode($package));
}
$this->addPackage($package);
}
}
示例9: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!$this->file->exists()) {
return;
}
$packages = $this->file->read();
if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the ' . $this->file->getPath() . ' repository');
}
$loader = new ArrayLoader();
foreach ($packages as $package) {
$this->addPackage($loader->load($package));
}
}
示例10: initialize
protected function initialize()
{
parent::initialize();
$json = new JsonFile($this->url . '/packages.json');
$packages = $json->read();
if (!$packages) {
throw new \UnexpectedValueException('Could not parse package list from the ' . $this->url . ' repository');
}
$loader = new ArrayLoader();
foreach ($packages as $data) {
foreach ($data['versions'] as $rev) {
$this->addPackage($loader->load($rev));
}
}
}
示例11: initialize
protected function initialize()
{
parent::initialize();
$loader = new ArrayLoader(null, true);
$directories = glob($this->directory . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR | GLOB_NOSORT);
foreach ($directories as $directory) {
if (!file_exists($directory . DIRECTORY_SEPARATOR . 'composer.json')) {
continue;
}
$jsonFile = new JsonFile($directory . DIRECTORY_SEPARATOR . 'composer.json');
$packageData = $jsonFile->read();
$packageData['version'] = '1.0';
$package = $loader->load($packageData);
$this->addPackage($package);
}
}
示例12: initialize
protected function initialize()
{
parent::initialize();
$this->io->writeError('Initializing PEAR repository ' . $this->url);
$reader = new ChannelReader($this->rfs);
try {
$channelInfo = $reader->read($this->url);
} catch (\Exception $e) {
$this->io->writeError('<warning>PEAR repository from ' . $this->url . ' could not be loaded. ' . $e->getMessage() . '</warning>');
return;
}
$packages = $this->buildComposerPackages($channelInfo, $this->versionParser);
foreach ($packages as $package) {
$this->addPackage($package);
}
}
示例13: initialize
/**
* Initializes repository (reads file, or remote address).
*/
protected function initialize()
{
parent::initialize();
if (!$this->file->exists()) {
return;
}
try {
$packages = $this->file->read();
if (!is_array($packages)) {
throw new \UnexpectedValueException('Could not parse package list from the repository');
}
} catch (\Exception $e) {
throw new InvalidRepositoryException('Invalid repository data in ' . $this->file->getPath() . ', packages could not be loaded: [' . get_class($e) . '] ' . $e->getMessage());
}
$loader = new ArrayLoader();
foreach ($packages as $packageData) {
$package = $loader->load($packageData);
$this->addPackage($package);
}
}
示例14: initialize
protected function initialize()
{
parent::initialize();
try {
$json = new JsonFile($this->url . '/packages.json', new RemoteFilesystem($this->io));
$data = $json->read();
if (!empty($data['notify'])) {
$this->notifyUrl = preg_replace('{(https?://[^/]+).*}i', '$1' . $data['notify'], $this->url);
}
$this->cache->write('packages.json', json_encode($data));
} catch (\Exception $e) {
if ($contents = $this->cache->read('packages.json')) {
$this->io->write('<warning>' . $this->url . ' could not be loaded, package information was loaded from the local cache and may be out of date</warning>');
$data = json_decode($contents, true);
} else {
throw $e;
}
}
$loader = new ArrayLoader();
$this->loadRepository($loader, $data);
}
示例15: initialize
/**
* Initializes path repository.
*
* This method will basically read the folder and add the found package.
*/
protected function initialize()
{
parent::initialize();
$path = $this->getPath();
$composerFilePath = $path . 'composer.json';
if (!file_exists($composerFilePath)) {
throw new \RuntimeException(sprintf('No `composer.json` file found in path repository "%s"', $path));
}
$json = file_get_contents($composerFilePath);
$package = JsonFile::parseJson($json, $composerFilePath);
$package['dist'] = array('type' => 'path', 'url' => $this->url, 'reference' => '');
if (!isset($package['version'])) {
$package['version'] = $this->versionGuesser->guessVersion($package, $path) ?: 'dev-master';
}
if (is_dir($path . '/.git') && 0 === $this->process->execute('git log -n1 --pretty=%H', $output, $path)) {
$package['dist']['reference'] = trim($output);
}
$package = $this->loader->load($package);
$this->addPackage($package);
}