init
This commit is contained in:
72
vendor/yiisoft/yii2-composer/CHANGELOG.md
vendored
Normal file
72
vendor/yiisoft/yii2-composer/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
Yii Framework 2 composer extension Change Log
|
||||
=============================================
|
||||
|
||||
2.0.7 July 05, 2018
|
||||
-------------------
|
||||
|
||||
- Bug #18: Fixed an error that would occur if the Zend OPcache extension was installed, but its "restrict_api" setting was enabled (angrybrad)
|
||||
|
||||
|
||||
2.0.6 March 21, 2018
|
||||
--------------------
|
||||
|
||||
- Bug #16: Upgrade notes were not shown when upgrading from a patch version (cebe)
|
||||
|
||||
|
||||
2.0.5 December 20, 2016
|
||||
-----------------------
|
||||
|
||||
- Bug #11: `generateCookieValidationKey()` now saves config file only when `cookieValidationKey` was generated (rob006)
|
||||
- Enh #10: Added `yii\composer\Installer::postInstall()` method (rob006)
|
||||
- Enh #12: Added `yii\composer\Installer::copyFiles()` method (rob006)
|
||||
- Enh #14: A note about yii UPGRADE notes file is shown after upgrading Yii to make user aware of it (cebe)
|
||||
|
||||
|
||||
2.0.4 February 06, 2016
|
||||
-----------------------
|
||||
|
||||
- Bug #7735: Composer failed to install extensions with multiple base paths in "psr-4" autoload section (cebe)
|
||||
- Enh #2: Better error handling for the case when installer is unable to change permissions (dbavscc)
|
||||
- Enh #3: `loadExtensions()` and `saveExtensions()` now access `EXTENSION_FILE` constant with late static binding (karneds)
|
||||
|
||||
|
||||
2.0.3 March 01, 2015
|
||||
--------------------
|
||||
|
||||
- no changes in this release.
|
||||
|
||||
|
||||
2.0.2 January 11, 2015
|
||||
----------------------
|
||||
|
||||
- no changes in this release.
|
||||
|
||||
|
||||
2.0.1 December 07, 2014
|
||||
-----------------------
|
||||
|
||||
- no changes in this release.
|
||||
|
||||
|
||||
2.0.0 October 12, 2014
|
||||
----------------------
|
||||
|
||||
- no changes in this release.
|
||||
|
||||
|
||||
2.0.0-rc September 27, 2014
|
||||
---------------------------
|
||||
|
||||
- Bug #3438: Fixed support for non-lowercase package names (cebe)
|
||||
- Chg: Added `yii\composer\Installer::postCreateProject()` and modified the syntax of calling installer methods in composer.json (qiangxue)
|
||||
|
||||
2.0.0-beta April 13, 2014
|
||||
-------------------------
|
||||
|
||||
- Bug #1480: Fixed issue with creating extensions.php when php opcache is enabled (cebe)
|
||||
- Enh: Added support for installing packages conforming to PSR-4 standard (qiangxue)
|
||||
|
||||
2.0.0-alpha, December 1, 2013
|
||||
-----------------------------
|
||||
|
||||
- Initial release.
|
||||
360
vendor/yiisoft/yii2-composer/Installer.php
vendored
Normal file
360
vendor/yiisoft/yii2-composer/Installer.php
vendored
Normal file
@@ -0,0 +1,360 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\composer;
|
||||
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Installer\LibraryInstaller;
|
||||
use Composer\Repository\InstalledRepositoryInterface;
|
||||
use Composer\Script\CommandEvent;
|
||||
use Composer\Script\Event;
|
||||
use Composer\Util\Filesystem;
|
||||
|
||||
/**
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class Installer extends LibraryInstaller
|
||||
{
|
||||
const EXTRA_BOOTSTRAP = 'bootstrap';
|
||||
const EXTENSION_FILE = 'yiisoft/extensions.php';
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function supports($packageType)
|
||||
{
|
||||
return $packageType === 'yii2-extension';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
|
||||
{
|
||||
// install the package the normal composer way
|
||||
parent::install($repo, $package);
|
||||
// add the package to yiisoft/extensions.php
|
||||
$this->addPackage($package);
|
||||
// ensure the yii2-dev package also provides Yii.php in the same place as yii2 does
|
||||
if ($package->getName() == 'yiisoft/yii2-dev') {
|
||||
$this->linkBaseYiiFiles();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target)
|
||||
{
|
||||
parent::update($repo, $initial, $target);
|
||||
$this->removePackage($initial);
|
||||
$this->addPackage($target);
|
||||
// ensure the yii2-dev package also provides Yii.php in the same place as yii2 does
|
||||
if ($initial->getName() == 'yiisoft/yii2-dev') {
|
||||
$this->linkBaseYiiFiles();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
|
||||
{
|
||||
// uninstall the package the normal composer way
|
||||
parent::uninstall($repo, $package);
|
||||
// remove the package from yiisoft/extensions.php
|
||||
$this->removePackage($package);
|
||||
// remove links for Yii.php
|
||||
if ($package->getName() == 'yiisoft/yii2-dev') {
|
||||
$this->removeBaseYiiFiles();
|
||||
}
|
||||
}
|
||||
|
||||
protected function addPackage(PackageInterface $package)
|
||||
{
|
||||
$extension = [
|
||||
'name' => $package->getName(),
|
||||
'version' => $package->getVersion(),
|
||||
];
|
||||
|
||||
$alias = $this->generateDefaultAlias($package);
|
||||
if (!empty($alias)) {
|
||||
$extension['alias'] = $alias;
|
||||
}
|
||||
$extra = $package->getExtra();
|
||||
if (isset($extra[self::EXTRA_BOOTSTRAP])) {
|
||||
$extension['bootstrap'] = $extra[self::EXTRA_BOOTSTRAP];
|
||||
}
|
||||
|
||||
$extensions = $this->loadExtensions();
|
||||
$extensions[$package->getName()] = $extension;
|
||||
$this->saveExtensions($extensions);
|
||||
}
|
||||
|
||||
protected function generateDefaultAlias(PackageInterface $package)
|
||||
{
|
||||
$fs = new Filesystem;
|
||||
$vendorDir = $fs->normalizePath($this->vendorDir);
|
||||
$autoload = $package->getAutoload();
|
||||
|
||||
$aliases = [];
|
||||
|
||||
if (!empty($autoload['psr-0'])) {
|
||||
foreach ($autoload['psr-0'] as $name => $path) {
|
||||
$name = str_replace('\\', '/', trim($name, '\\'));
|
||||
if (!$fs->isAbsolutePath($path)) {
|
||||
$path = $this->vendorDir . '/' . $package->getPrettyName() . '/' . $path;
|
||||
}
|
||||
$path = $fs->normalizePath($path);
|
||||
if (strpos($path . '/', $vendorDir . '/') === 0) {
|
||||
$aliases["@$name"] = '<vendor-dir>' . substr($path, strlen($vendorDir)) . '/' . $name;
|
||||
} else {
|
||||
$aliases["@$name"] = $path . '/' . $name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($autoload['psr-4'])) {
|
||||
foreach ($autoload['psr-4'] as $name => $path) {
|
||||
if (is_array($path)) {
|
||||
// ignore psr-4 autoload specifications with multiple search paths
|
||||
// we can not convert them into aliases as they are ambiguous
|
||||
continue;
|
||||
}
|
||||
$name = str_replace('\\', '/', trim($name, '\\'));
|
||||
if (!$fs->isAbsolutePath($path)) {
|
||||
$path = $this->vendorDir . '/' . $package->getPrettyName() . '/' . $path;
|
||||
}
|
||||
$path = $fs->normalizePath($path);
|
||||
if (strpos($path . '/', $vendorDir . '/') === 0) {
|
||||
$aliases["@$name"] = '<vendor-dir>' . substr($path, strlen($vendorDir));
|
||||
} else {
|
||||
$aliases["@$name"] = $path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $aliases;
|
||||
}
|
||||
|
||||
protected function removePackage(PackageInterface $package)
|
||||
{
|
||||
$packages = $this->loadExtensions();
|
||||
unset($packages[$package->getName()]);
|
||||
$this->saveExtensions($packages);
|
||||
}
|
||||
|
||||
protected function loadExtensions()
|
||||
{
|
||||
$file = $this->vendorDir . '/' . static::EXTENSION_FILE;
|
||||
if (!is_file($file)) {
|
||||
return [];
|
||||
}
|
||||
// invalidate opcache of extensions.php if exists
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
@opcache_invalidate($file, true);
|
||||
}
|
||||
$extensions = require($file);
|
||||
|
||||
$vendorDir = str_replace('\\', '/', $this->vendorDir);
|
||||
$n = strlen($vendorDir);
|
||||
|
||||
foreach ($extensions as &$extension) {
|
||||
if (isset($extension['alias'])) {
|
||||
foreach ($extension['alias'] as $alias => $path) {
|
||||
$path = str_replace('\\', '/', $path);
|
||||
if (strpos($path . '/', $vendorDir . '/') === 0) {
|
||||
$extension['alias'][$alias] = '<vendor-dir>' . substr($path, $n);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $extensions;
|
||||
}
|
||||
|
||||
protected function saveExtensions(array $extensions)
|
||||
{
|
||||
$file = $this->vendorDir . '/' . static::EXTENSION_FILE;
|
||||
if (!file_exists(dirname($file))) {
|
||||
mkdir(dirname($file), 0777, true);
|
||||
}
|
||||
$array = str_replace("'<vendor-dir>", '$vendorDir . \'', var_export($extensions, true));
|
||||
file_put_contents($file, "<?php\n\n\$vendorDir = dirname(__DIR__);\n\nreturn $array;\n");
|
||||
// invalidate opcache of extensions.php if exists
|
||||
if (function_exists('opcache_invalidate')) {
|
||||
opcache_invalidate($file, true);
|
||||
}
|
||||
}
|
||||
|
||||
protected function linkBaseYiiFiles()
|
||||
{
|
||||
$yiiDir = $this->vendorDir . '/yiisoft/yii2';
|
||||
if (!file_exists($yiiDir)) {
|
||||
mkdir($yiiDir, 0777, true);
|
||||
}
|
||||
foreach (['Yii.php', 'BaseYii.php', 'classes.php'] as $file) {
|
||||
file_put_contents($yiiDir . '/' . $file, <<<EOF
|
||||
<?php
|
||||
/**
|
||||
* This is a link provided by the yiisoft/yii2-dev package via yii2-composer plugin.
|
||||
*
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
return require(__DIR__ . '/../yii2-dev/framework/$file');
|
||||
|
||||
EOF
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
protected function removeBaseYiiFiles()
|
||||
{
|
||||
$yiiDir = $this->vendorDir . '/yiisoft/yii2';
|
||||
foreach (['Yii.php', 'BaseYii.php', 'classes.php'] as $file) {
|
||||
if (file_exists($yiiDir . '/' . $file)) {
|
||||
unlink($yiiDir . '/' . $file);
|
||||
}
|
||||
}
|
||||
if (file_exists($yiiDir)) {
|
||||
rmdir($yiiDir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Special method to run tasks defined in `[extra][yii\composer\Installer::postCreateProject]` key in `composer.json`
|
||||
*
|
||||
* @param Event $event
|
||||
*/
|
||||
public static function postCreateProject($event)
|
||||
{
|
||||
static::runCommands($event, __METHOD__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special method to run tasks defined in `[extra][yii\composer\Installer::postInstall]` key in `composer.json`
|
||||
*
|
||||
* @param Event $event
|
||||
* @since 2.0.5
|
||||
*/
|
||||
public static function postInstall($event)
|
||||
{
|
||||
static::runCommands($event, __METHOD__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Special method to run tasks defined in `[extra][$extraKey]` key in `composer.json`
|
||||
*
|
||||
* @param Event $event
|
||||
* @param string $extraKey
|
||||
* @since 2.0.5
|
||||
*/
|
||||
protected static function runCommands($event, $extraKey)
|
||||
{
|
||||
$params = $event->getComposer()->getPackage()->getExtra();
|
||||
if (isset($params[$extraKey]) && is_array($params[$extraKey])) {
|
||||
foreach ($params[$extraKey] as $method => $args) {
|
||||
call_user_func_array([__CLASS__, $method], (array) $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the correct permission for the files and directories listed in the extra section.
|
||||
* @param array $paths the paths (keys) and the corresponding permission octal strings (values)
|
||||
*/
|
||||
public static function setPermission(array $paths)
|
||||
{
|
||||
foreach ($paths as $path => $permission) {
|
||||
echo "chmod('$path', $permission)...";
|
||||
if (is_dir($path) || is_file($path)) {
|
||||
try {
|
||||
if (chmod($path, octdec($permission))) {
|
||||
echo "done.\n";
|
||||
};
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
} else {
|
||||
echo "file not found.\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a cookie validation key for every app config listed in "config" in extra section.
|
||||
* You can provide one or multiple parameters as the configuration files which need to have validation key inserted.
|
||||
*/
|
||||
public static function generateCookieValidationKey()
|
||||
{
|
||||
$configs = func_get_args();
|
||||
$key = self::generateRandomString();
|
||||
foreach ($configs as $config) {
|
||||
if (is_file($config)) {
|
||||
$content = preg_replace('/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/', "\\1'$key'", file_get_contents($config), -1, $count);
|
||||
if ($count > 0) {
|
||||
file_put_contents($config, $content);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected static function generateRandomString()
|
||||
{
|
||||
if (!extension_loaded('openssl')) {
|
||||
throw new \Exception('The OpenSSL PHP extension is required by Yii2.');
|
||||
}
|
||||
$length = 32;
|
||||
$bytes = openssl_random_pseudo_bytes($length);
|
||||
return strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy files to specified locations.
|
||||
* @param array $paths The source files paths (keys) and the corresponding target locations
|
||||
* for copied files (values). Location can be specified as an array - first element is target
|
||||
* location, second defines whether file can be overwritten (by default method don't overwrite
|
||||
* existing files).
|
||||
* @since 2.0.5
|
||||
*/
|
||||
public static function copyFiles(array $paths)
|
||||
{
|
||||
foreach ($paths as $source => $target) {
|
||||
// handle file target as array [path, overwrite]
|
||||
$target = (array) $target;
|
||||
echo "Copying file $source to $target[0] - ";
|
||||
|
||||
if (!is_file($source)) {
|
||||
echo "source file not found.\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_file($target[0]) && empty($target[1])) {
|
||||
echo "target file exists - skip.\n";
|
||||
continue;
|
||||
} elseif (is_file($target[0]) && !empty($target[1])) {
|
||||
echo "target file exists - overwrite - ";
|
||||
}
|
||||
|
||||
try {
|
||||
if (!is_dir(dirname($target[0]))) {
|
||||
mkdir(dirname($target[0]), 0777, true);
|
||||
}
|
||||
if (copy($source, $target[0])) {
|
||||
echo "done.\n";
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
echo $e->getMessage() . "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
29
vendor/yiisoft/yii2-composer/LICENSE.md
vendored
Normal file
29
vendor/yiisoft/yii2-composer/LICENSE.md
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
Copyright © 2008 by Yii Software LLC (http://www.yiisoft.com)
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Yii Software LLC nor the names of its
|
||||
contributors may be used to endorse or promote products derived
|
||||
from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
219
vendor/yiisoft/yii2-composer/Plugin.php
vendored
Normal file
219
vendor/yiisoft/yii2-composer/Plugin.php
vendored
Normal file
@@ -0,0 +1,219 @@
|
||||
<?php
|
||||
/**
|
||||
* @link http://www.yiiframework.com/
|
||||
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||
* @license http://www.yiiframework.com/license/
|
||||
*/
|
||||
|
||||
namespace yii\composer;
|
||||
|
||||
use Composer\Composer;
|
||||
use Composer\DependencyResolver\Operation\UpdateOperation;
|
||||
use Composer\EventDispatcher\EventSubscriberInterface;
|
||||
use Composer\Installer\PackageEvent;
|
||||
use Composer\Installer\PackageEvents;
|
||||
use Composer\IO\IOInterface;
|
||||
use Composer\Plugin\PluginInterface;
|
||||
use Composer\Script;
|
||||
use Composer\Script\ScriptEvents;
|
||||
|
||||
/**
|
||||
* Plugin is the composer plugin that registers the Yii composer installer.
|
||||
*
|
||||
* @author Qiang Xue <qiang.xue@gmail.com>
|
||||
* @since 2.0
|
||||
*/
|
||||
class Plugin implements PluginInterface, EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
* @var array noted package updates.
|
||||
*/
|
||||
private $_packageUpdates = [];
|
||||
/**
|
||||
* @var string path to the vendor directory.
|
||||
*/
|
||||
private $_vendorDir;
|
||||
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function activate(Composer $composer, IOInterface $io)
|
||||
{
|
||||
$installer = new Installer($io, $composer);
|
||||
$composer->getInstallationManager()->addInstaller($installer);
|
||||
$this->_vendorDir = rtrim($composer->getConfig()->get('vendor-dir'), '/');
|
||||
$file = $this->_vendorDir . '/yiisoft/extensions.php';
|
||||
if (!is_file($file)) {
|
||||
@mkdir(dirname($file), 0777, true);
|
||||
file_put_contents($file, "<?php\n\nreturn [];\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @return array The event names to listen to.
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return [
|
||||
PackageEvents::POST_PACKAGE_UPDATE => 'checkPackageUpdates',
|
||||
ScriptEvents::POST_UPDATE_CMD => 'showUpgradeNotes',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Listen to POST_PACKAGE_UPDATE event and take note of the package updates.
|
||||
* @param PackageEvent $event
|
||||
*/
|
||||
public function checkPackageUpdates(PackageEvent $event)
|
||||
{
|
||||
$operation = $event->getOperation();
|
||||
if ($operation instanceof UpdateOperation) {
|
||||
$this->_packageUpdates[$operation->getInitialPackage()->getName()] = [
|
||||
'from' => $operation->getInitialPackage()->getVersion(),
|
||||
'fromPretty' => $operation->getInitialPackage()->getPrettyVersion(),
|
||||
'to' => $operation->getTargetPackage()->getVersion(),
|
||||
'toPretty' => $operation->getTargetPackage()->getPrettyVersion(),
|
||||
'direction' => $event->getPolicy()->versionCompare(
|
||||
$operation->getInitialPackage(),
|
||||
$operation->getTargetPackage(),
|
||||
'<'
|
||||
) ? 'up' : 'down',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to POST_UPDATE_CMD event to display information about upgrade notes if appropriate.
|
||||
* @param Script\Event $event
|
||||
*/
|
||||
public function showUpgradeNotes(Script\Event $event)
|
||||
{
|
||||
$packageName = 'yiisoft/yii2';
|
||||
if (!isset($this->_packageUpdates[$packageName])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$package = $this->_packageUpdates['yiisoft/yii2'];
|
||||
|
||||
// do not show a notice on up/downgrades between dev versions
|
||||
// avoid messages like from version dev-master to dev-master
|
||||
if ($package['fromPretty'] == $package['toPretty']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$io = $event->getIO();
|
||||
|
||||
// print the relevant upgrade notes for the upgrade
|
||||
// - only on upgrade, not on downgrade
|
||||
// - only if the "from" version is non-dev, otherwise we have no idea which notes to show
|
||||
if ($package['direction'] === 'up' && $this->isNumericVersion($package['fromPretty'])) {
|
||||
|
||||
$notes = $this->findUpgradeNotes($packageName, $package['fromPretty']);
|
||||
if ($notes !== false && empty($notes)) {
|
||||
// no relevent upgrade notes, do not show anything.
|
||||
return;
|
||||
}
|
||||
|
||||
$this->printUpgradeIntro($io, $package);
|
||||
|
||||
if ($notes) {
|
||||
// safety check: do not display notes if they are too many
|
||||
if (count($notes) > 250) {
|
||||
$io->write("\n <fg=yellow;options=bold>The relevant notes for your upgrade are too long to be displayed here.</>");
|
||||
} else {
|
||||
$io->write("\n " . trim(implode("\n ", $notes)));
|
||||
}
|
||||
}
|
||||
|
||||
$io->write("\n You can find the upgrade notes for all versions online at:");
|
||||
} else {
|
||||
$this->printUpgradeIntro($io, $package);
|
||||
$io->write("\n You can find the upgrade notes online at:");
|
||||
}
|
||||
$this->printUpgradeLink($io, $package);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print link to upgrade notes
|
||||
* @param IOInterface $io
|
||||
* @param array $package
|
||||
*/
|
||||
private function printUpgradeLink($io, $package)
|
||||
{
|
||||
$maxVersion = $package['direction'] === 'up' ? $package['toPretty'] : $package['fromPretty'];
|
||||
// make sure to always show a valid link, even if $maxVersion is something like dev-master
|
||||
if (!$this->isNumericVersion($maxVersion)) {
|
||||
$maxVersion = 'master';
|
||||
}
|
||||
$io->write(" https://github.com/yiisoft/yii2/blob/$maxVersion/framework/UPGRADE.md\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Print upgrade intro
|
||||
* @param IOInterface $io
|
||||
* @param array $package
|
||||
*/
|
||||
private function printUpgradeIntro($io, $package)
|
||||
{
|
||||
$io->write("\n <fg=yellow;options=bold>Seems you have "
|
||||
. ($package['direction'] === 'up' ? 'upgraded' : 'downgraded')
|
||||
. ' Yii Framework from version '
|
||||
. $package['fromPretty'] . ' to ' . $package['toPretty'] . '.</>'
|
||||
);
|
||||
$io->write("\n <options=bold>Please check the upgrade notes for possible incompatible changes");
|
||||
$io->write(' and adjust your application code accordingly.</>');
|
||||
}
|
||||
|
||||
/**
|
||||
* Read upgrade notes from a files and returns an array of lines
|
||||
* @param string $packageName
|
||||
* @param string $fromVersion until which version to read the notes
|
||||
* @return array|false
|
||||
*/
|
||||
private function findUpgradeNotes($packageName, $fromVersion)
|
||||
{
|
||||
if (preg_match('/^([0-9]\.[0-9]+\.?[0-9]*)/', $fromVersion, $m)) {
|
||||
$fromVersionMajor = $m[1];
|
||||
} else {
|
||||
$fromVersionMajor = $fromVersion;
|
||||
}
|
||||
|
||||
$upgradeFile = $this->_vendorDir . '/' . $packageName . '/UPGRADE.md';
|
||||
if (!is_file($upgradeFile) || !is_readable($upgradeFile)) {
|
||||
return false;
|
||||
}
|
||||
$lines = preg_split('~\R~', file_get_contents($upgradeFile));
|
||||
$relevantLines = [];
|
||||
$consuming = false;
|
||||
// whether an exact match on $fromVersion has been encountered
|
||||
$foundExactMatch = false;
|
||||
foreach($lines as $line) {
|
||||
if (preg_match('/^Upgrade from Yii ([0-9]\.[0-9]+\.?[0-9\.]*)/i', $line, $matches)) {
|
||||
if ($matches[1] === $fromVersion) {
|
||||
$foundExactMatch = true;
|
||||
}
|
||||
if (version_compare($matches[1], $fromVersion, '<') && ($foundExactMatch || version_compare($matches[1], $fromVersionMajor, '<'))) {
|
||||
break;
|
||||
}
|
||||
$consuming = true;
|
||||
}
|
||||
if ($consuming) {
|
||||
$relevantLines[] = $line;
|
||||
}
|
||||
}
|
||||
return $relevantLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a version is numeric, e.g. 2.0.10.
|
||||
* @param string $version
|
||||
* @return bool
|
||||
*/
|
||||
private function isNumericVersion($version)
|
||||
{
|
||||
return (bool) preg_match('~^([0-9]\.[0-9]+\.?[0-9\.]*)~', $version);
|
||||
}
|
||||
}
|
||||
96
vendor/yiisoft/yii2-composer/README.md
vendored
Normal file
96
vendor/yiisoft/yii2-composer/README.md
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
<p align="center">
|
||||
<a href="https://getcomposer.org/" target="_blank" rel="external">
|
||||
<img src="https://getcomposer.org/img/logo-composer-transparent3.png" height="178px">
|
||||
</a>
|
||||
<h1 align="center">Yii 2 Composer Installer</h1>
|
||||
<br>
|
||||
</p>
|
||||
|
||||
This is the composer installer for [Yii framework 2.0](http://www.yiiframework.com) extensions.
|
||||
It implements a new composer package type named `yii2-extension`,
|
||||
which should be used by all Yii 2 extensions if they are distributed as composer packages.
|
||||
|
||||
For license information check the [LICENSE](LICENSE.md)-file.
|
||||
|
||||
[](https://packagist.org/packages/yiisoft/yii2-composer)
|
||||
[](https://packagist.org/packages/yiisoft/yii2-composer)
|
||||
[](https://travis-ci.org/yiisoft/yii2-composer)
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
The Yii 2 Composer Installer is automatically installed with when installing the framework via Composer.
|
||||
|
||||
To use Yii 2 composer installer, simply set the package `type` to be `yii2-extension` in your `composer.json`,
|
||||
like the following:
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "yii2-extension",
|
||||
"require": {
|
||||
"yiisoft/yii2": "~2.0.0"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
You may specify a bootstrapping class in the `extra` section. The `init()` method of the class will be executed each time
|
||||
the Yii 2 application is responding to a request. For example,
|
||||
|
||||
```json
|
||||
{
|
||||
"type": "yii2-extension",
|
||||
...,
|
||||
"extra": {
|
||||
"bootstrap": "yii\\jui\\Extension"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The `Installer` class also implements a static method `postCreateProject()` that can be called after
|
||||
a Yii 2 project is created, through the `post-create-project-cmd` composer script.
|
||||
A similar method exists for running tasks after each `composer install` call, which sis `postInstall()`.
|
||||
These methods allow to run other `Installer` class methods like `setPermission()` or `generateCookieValidationKey()`,
|
||||
depending on the corresponding parameters set in the `extra` section of the `composer.json` file.
|
||||
For example,
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "yiisoft/yii2-app-basic",
|
||||
"type": "project",
|
||||
...
|
||||
"scripts": {
|
||||
"post-create-project-cmd": [
|
||||
"yii\\composer\\Installer::postCreateProject"
|
||||
],
|
||||
"post-install-cmd": [
|
||||
"yii\\composer\\Installer::postInstall"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"yii\\composer\\Installer::postCreateProject": {
|
||||
"setPermission": [
|
||||
{
|
||||
"runtime": "0777",
|
||||
"web/assets": "0777",
|
||||
"yii": "0755"
|
||||
}
|
||||
]
|
||||
},
|
||||
"yii\\composer\\Installer::postInstall": {
|
||||
"copyFiles": [
|
||||
{
|
||||
"config/templates/console-local.php": "config/console-local.php",
|
||||
"config/templates/web-local.php": "config/web-local.php",
|
||||
"config/templates/db-local.php": "config/db-local.php",
|
||||
"config/templates/cache.json": ["runtime/cache.json", true]
|
||||
}
|
||||
],
|
||||
"generateCookieValidationKey": [
|
||||
"config/web-local.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
42
vendor/yiisoft/yii2-composer/composer.json
vendored
Normal file
42
vendor/yiisoft/yii2-composer/composer.json
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "yiisoft/yii2-composer",
|
||||
"description": "The composer plugin for Yii extension installer",
|
||||
"keywords": ["yii2", "composer", "extension installer"],
|
||||
"type": "composer-plugin",
|
||||
"license": "BSD-3-Clause",
|
||||
"support": {
|
||||
"issues": "https://github.com/yiisoft/yii2-composer/issues",
|
||||
"forum": "http://www.yiiframework.com/forum/",
|
||||
"wiki": "http://www.yiiframework.com/wiki/",
|
||||
"irc": "irc://irc.freenode.net/yii",
|
||||
"source": "https://github.com/yiisoft/yii2-composer"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Qiang Xue",
|
||||
"email": "qiang.xue@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Carsten Brandt",
|
||||
"email": "mail@cebe.cc"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"composer-plugin-api": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"composer/composer": "^1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": { "yii\\composer\\": "" }
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": { "tests\\": "tests" }
|
||||
},
|
||||
"extra": {
|
||||
"class": "yii\\composer\\Plugin",
|
||||
"branch-alias": {
|
||||
"dev-master": "2.0.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user