Browse Source

allow installing yii2-dev and get the Yii.php file in the same place

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
999b42555d
  1. 52
      extensions/composer/Installer.php

52
extensions/composer/Installer.php

@ -38,8 +38,14 @@ class Installer extends LibraryInstaller
*/ */
public function install(InstalledRepositoryInterface $repo, PackageInterface $package) public function install(InstalledRepositoryInterface $repo, PackageInterface $package)
{ {
// install the package the normal composer way
parent::install($repo, $package); parent::install($repo, $package);
// add the package to yiisoft/extensions.php
$this->addPackage($package); $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->linkYiiBaseFiles();
}
} }
/** /**
@ -50,6 +56,10 @@ class Installer extends LibraryInstaller
parent::update($repo, $initial, $target); parent::update($repo, $initial, $target);
$this->removePackage($initial); $this->removePackage($initial);
$this->addPackage($target); $this->addPackage($target);
// ensure the yii2-dev package also provides Yii.php in the same place as yii2 does
if ($package->getName() == 'yiisoft/yii2-dev') {
$this->linkYiiBaseFiles();
}
} }
/** /**
@ -57,8 +67,14 @@ class Installer extends LibraryInstaller
*/ */
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package)
{ {
// uninstall the package the normal composer way
parent::uninstall($repo, $package); parent::uninstall($repo, $package);
// remove the package from yiisoft/extensions.php
$this->removePackage($package); $this->removePackage($package);
// remove links for Yii.php
if ($package->getName() == 'yiisoft/yii2-dev') {
$this->removeYiiBaseFiles();
}
} }
protected function addPackage(PackageInterface $package) protected function addPackage(PackageInterface $package)
@ -145,6 +161,42 @@ class Installer extends LibraryInstaller
file_put_contents($file, "<?php\n\n\$vendorDir = dirname(__DIR__);\n\nreturn $array;\n"); file_put_contents($file, "<?php\n\n\$vendorDir = dirname(__DIR__);\n\nreturn $array;\n");
} }
protected function linkYiiBaseFiles()
{
$yiiDir = $this->vendorDir . '/yiisoft/yii2/yii';
if (!file_exists($yiiDir)) {
mkdir($yiiDir, 0777, true);
}
foreach(['Yii.php', 'YiiBase.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/yii/$file');
EOF
);
}
}
protected function removeYiiBaseFiles()
{
$yiiDir = $this->vendorDir . '/yiisoft/yii2/yii';
foreach(['Yii.php', 'YiiBase.php', 'classes.php'] as $file) {
if (file_exists($yiiDir . '/' . $file)) {
unlink($yiiDir . '/' . $file);
}
}
if (file_exists($yiiDir)) {
rmdir($yiiDir);
}
}
/** /**
* Sets the correct permission for the files and directories listed in the extra section. * Sets the correct permission for the files and directories listed in the extra section.

Loading…
Cancel
Save