Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -0,0 +1,2 @@
/composer.lock
/vendor/

View file

@ -0,0 +1 @@
preset: psr2

16
vendor/webflo/drupal-finder/.travis.yml vendored Normal file
View file

@ -0,0 +1,16 @@
language: php
php:
- 5.5
- 5.6
- 7.0
sudo: false
before_install:
- phpenv config-rm xdebug.ini
install:
- composer --verbose install
script:
- ./vendor/bin/phpunit

25
vendor/webflo/drupal-finder/README.md vendored Normal file
View file

@ -0,0 +1,25 @@
# Drupal Finder
[![Travis](https://img.shields.io/travis/webflo/drupal-finder.svg)](https://travis-ci.org/webflo/drupal-finder) [![Packagist](https://img.shields.io/packagist/v/webflo/drupal-finder.svg)](https://packagist.org/packages/webflo/drupal-finder)
Drupal Finder provides a class to locate a Drupal installation in a given path.
## Usage
```PHP
$drupalFinder = new \DrupalFinder\DrupalFinder();
if ($drupalFinder->locateRoot(getcwd())) {
$drupalRoot = $drupalFinder->getDrupalRoot();
$composerRoot = $drupalFinder->getComposerRoot();
...
}
```
## Examples
- [Drupal Console Launcher](https://github.com/hechoendrupal/drupal-console-launcher)
- [Drush Launcher](https://github.com/drush-ops/drush-launcher)
## License
GPL-2.0+

View file

@ -0,0 +1,27 @@
{
"name": "webflo/drupal-finder",
"description": "Helper class to locate a Drupal installation from a given path.",
"license": "GPL-2.0+",
"type": "library",
"authors": [
{
"name": "Florian Weber",
"email": "florian@webflo.org"
}
],
"require": {},
"autoload": {
"classmap": [
"src/DrupalFinder.php"
]
},
"autoload-dev": {
"psr-4": {
"DrupalFinder\\Tests\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"mikey179/vfsStream": "^1.6"
}
}

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite name="DrupalFinder Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>
</phpunit>

View file

@ -0,0 +1,169 @@
<?php
/**
* @file
* Contains \DrupalFinder\DrupalFinder.
*/
namespace DrupalFinder;
class DrupalFinder
{
/**
* Drupal web public directory.
*
* @var string
*/
private $drupalRoot;
/**
* Drupal package composer directory.
*
* @var bool
*/
private $composerRoot;
/**
* Composer vendor directory.
*
* @var string
*
* @see https://getcomposer.org/doc/06-config.md#vendor-dir
*/
private $vendorDir;
public function locateRoot($start_path)
{
$this->drupalRoot = false;
$this->composerRoot = false;
$this->vendorDir = false;
foreach (array(true, false) as $follow_symlinks) {
$path = $start_path;
if ($follow_symlinks && is_link($path)) {
$path = realpath($path);
}
// Check the start path.
if ($this->isValidRoot($path)) {
return true;
} else {
// Move up dir by dir and check each.
while ($path = $this->shiftPathUp($path)) {
if ($follow_symlinks && is_link($path)) {
$path = realpath($path);
}
if ($this->isValidRoot($path)) {
return true;
}
}
}
}
return false;
}
/**
* Returns parent directory.
*
* @param string
* Path to start from
*
* @return string|false
* Parent path of given path or false when $path is filesystem root
*/
private function shiftPathUp($path)
{
$parent = dirname($path);
return in_array($parent, ['.', $path]) ? false : $parent;
}
/**
* @param $path
*
* @return bool
*/
protected function isValidRoot($path)
{
if (!empty($path) && is_dir($path) && file_exists($path . '/autoload.php') && file_exists($path . '/' . $this->getComposerFileName())) {
// Additional check for the presence of core/composer.json to
// grant it is not a Drupal 7 site with a base folder named "core".
$candidate = 'core/includes/common.inc';
if (file_exists($path . '/' . $candidate) && file_exists($path . '/core/core.services.yml')) {
if (file_exists($path . '/core/misc/drupal.js') || file_exists($path . '/core/assets/js/drupal.js')) {
$this->composerRoot = $path;
$this->drupalRoot = $path;
$this->vendorDir = $this->composerRoot . '/vendor';
}
}
}
if (!empty($path) && is_dir($path) && file_exists($path . '/' . $this->getComposerFileName())) {
$json = json_decode(
file_get_contents($path . '/' . $this->getComposerFileName()),
true
);
if (is_array($json)) {
if (isset($json['extra']['installer-paths']) && is_array($json['extra']['installer-paths'])) {
foreach ($json['extra']['installer-paths'] as $install_path => $items) {
if (in_array('type:drupal-core', $items) ||
in_array('drupal/core', $items) ||
in_array('drupal/drupal', $items)) {
$this->composerRoot = $path;
// @todo: Remove this magic and detect the major version instead.
if ($install_path == 'core') {
$install_path = null;
} elseif (substr($install_path, -5) == '/core') {
$install_path = substr($install_path, 0, -5);
}
$this->drupalRoot = rtrim($path . '/' . $install_path, '/');
$this->vendorDir = $this->composerRoot . '/vendor';
}
}
}
}
}
if ($this->composerRoot && file_exists($this->composerRoot . '/' . $this->getComposerFileName())) {
$json = json_decode(
file_get_contents($path . '/' . $this->getComposerFileName()),
true
);
if (is_array($json) && isset($json['config']['vendor-dir'])) {
$this->vendorDir = $this->composerRoot . '/' . $json['config']['vendor-dir'];
}
}
return $this->drupalRoot && $this->composerRoot && $this->vendorDir;
}
/**
* @return string
*/
public function getDrupalRoot()
{
return $this->drupalRoot;
}
/**
* @return string
*/
public function getComposerRoot()
{
return $this->composerRoot;
}
/**
* @return string
*/
protected function getComposerFileName()
{
return trim(getenv('COMPOSER')) ?: 'composer.json';
}
/**
* @return string
*/
public function getVendorDir()
{
return $this->vendorDir;
}
}

View file

@ -0,0 +1,168 @@
<?php
namespace DrupalFinder\Tests;
use org\bovigo\vfs\vfsStream;
class Drupal7FinderTest extends DrupalFinderTestBase
{
/**
* @var \DrupalFinder\DrupalFinder
*/
protected $finder;
protected static $fileStructure = [
'includes' => [
'common.inc' => '',
],
'misc' => [
'drupal.js' => '',
],
'sites' => [
'all' => [
'modules' => []
]
]
];
/**
* @return array
*/
protected function getDrupalComposerStructure()
{
$fileStructure = [
'web' => static::$fileStructure,
'composer.json' => [
'require' => [
'drupal/drupal' => '*',
],
'extra' => [
'installer-paths' => [
'web/' => [
'type:drupal-core',
],
],
],
],
'vendor' => [],
];
return $fileStructure;
}
public function testDrupalComposerStructure()
{
$fileStructure = $this->getDrupalComposerStructure();
$this->assertComposerStructure($fileStructure);
}
public function testDrupalComposerStructureWithoutRequire()
{
$fileStructure = [
'web' => static::$fileStructure,
'composer.json' => [
'extra' => [
'installer-paths' => [
'web' => [
'drupal/drupal',
],
],
],
],
];
$this->assertComposerStructure($fileStructure);
}
public function testNoDrupalRootWithRealFilesystem()
{
$root = $this->tempdir(sys_get_temp_dir());
$this->assertFalse($this->finder->locateRoot($root));
$this->assertFalse($this->finder->getDrupalRoot());
$this->assertFalse($this->finder->getComposerRoot());
$this->assertFalse($this->finder->getVendorDir());
}
public function testDrupalComposerStructureWithRealFilesystem()
{
$root = $this->tempdir(sys_get_temp_dir());
$this->dumpToFileSystem($this->getDrupalComposerStructure(), $root);
$this->assertTrue($this->finder->locateRoot($root));
$this->assertSame($root . '/web', $this->finder->getDrupalRoot());
$this->assertSame($root, $this->finder->getComposerRoot());
$this->assertSame($root . '/vendor', $this->finder->getVendorDir());
// Test symlink implementation
$symlink = $this->tempdir(sys_get_temp_dir());
$this->symlink($root, $symlink . '/foo');
$this->assertTrue($this->finder->locateRoot($symlink . '/foo'));
$this->assertSame($root . '/web', $this->finder->getDrupalRoot());
$this->assertSame($root, $this->finder->getComposerRoot());
$this->assertSame($root . '/vendor', $this->finder->getVendorDir());
}
public function testDrupalWithLinkedModule()
{
$root = $this->tempdir(sys_get_temp_dir());
$this->dumpToFileSystem($this->getDrupalComposerStructure(), $root);
$module = $this->tempdir(sys_get_temp_dir());
$module_link = $root . '/web/sites/all/modules/foo';
$this->symlink($module, $module_link);
$this->assertTrue($this->finder->locateRoot($module_link));
$this->assertSame($root . '/web', realpath($this->finder->getDrupalRoot()));
$this->assertSame($root, realpath($this->finder->getComposerRoot()));
$this->assertSame($root . '/vendor', realpath($this->finder->getVendorDir()));
}
public function testDrupalWithCustomVendor()
{
$root = $this->tempdir(sys_get_temp_dir());
$fileStructure = $this->getDrupalComposerStructure();
$composerJson = $fileStructure['composer.json'];
$composerJson['config']['vendor-dir'] = 'vendor-foo';
$fileStructure['composer.json'] = $composerJson;
$fileStructure['vendor-foo'] = [];
$this->dumpToFileSystem($fileStructure, $root);
$this->assertTrue($this->finder->locateRoot($root));
$this->assertSame($root . '/web', realpath($this->finder->getDrupalRoot()));
$this->assertSame($root, realpath($this->finder->getComposerRoot()));
$this->assertSame($root . '/vendor-foo', realpath($this->finder->getVendorDir()));
}
/**
* @param $fileStructure
*/
protected function assertComposerStructure($fileStructure)
{
$fileStructure = $this->prepareFileStructure($fileStructure);
$root = vfsStream::setup('root', null, $fileStructure);
$this->assertTrue($this->finder->locateRoot($root->url() . '/web'));
$this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$this->assertTrue($this->finder->locateRoot($root->url() . '/web/misc'));
$this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$this->assertTrue($this->finder->locateRoot($root->url()));
$this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$root = vfsStream::setup(
'root',
null,
['nested_folder' => $fileStructure]
);
$this->assertFalse($this->finder->locateRoot($root->url()));
$this->assertFalse($this->finder->getDrupalRoot());
$this->assertFalse($this->finder->getComposerRoot());
$this->assertFalse($this->finder->getVendorDir());
}
}

View file

@ -0,0 +1,282 @@
<?php
namespace DrupalFinder\Tests;
use org\bovigo\vfs\vfsStream;
class Drupal8FinderTest extends DrupalFinderTestBase
{
protected static $fileStructure = [
'autoload.php' => '',
'composer.json' => [
'extra' => [
'installer-paths' => [
'core' => [
'type:drupal-core'
]
]
]
],
'core' => [
'includes' => [
'common.inc' => '',
],
'misc' => [
'drupal.js' => '',
],
'core.services.yml' => '',
],
'modules' => [],
'vendor' => [],
];
/**
* @return array
*/
protected function getDrupalComposerStructure()
{
$fileStructure = [
'web' => static::$fileStructure,
'composer.json' => [
'require' => [
'drupal/core' => '*',
],
'extra' => [
'installer-paths' => [
'web/core' => [
'type:drupal-core',
],
],
],
],
'vendor' => [],
];
unset($fileStructure['web']['composer.json']);
unset($fileStructure['web']['vendor']);
return $fileStructure;
}
protected function setUp()
{
parent::setUp();
$this->finder = new \DrupalFinder\DrupalFinder();
}
public function testDrupalDefaultStructure()
{
$root = vfsStream::setup('root', null, $this->prepareFileStructure(static::$fileStructure));
$this->assertTrue($this->finder->locateRoot($root->url()));
$this->assertSame('vfs://root', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$this->assertTrue($this->finder->locateRoot($root->url() . '/misc'));
$this->assertSame('vfs://root', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$root = vfsStream::setup(
'root',
null,
['project' => $this->prepareFileStructure(static::$fileStructure)]
);
$this->assertFalse(
$this->finder->locateRoot($root->url()),
'Not in the scope of the project'
);
$this->assertFalse($this->finder->getDrupalRoot());
$this->assertFalse($this->finder->getComposerRoot());
$this->assertFalse($this->finder->getVendorDir());
}
public function testDrupalComposerStructure()
{
$fileStructure = $this->getDrupalComposerStructure();
$this->assertComposerStructure($fileStructure);
}
public function testDrupalComposerStructureWithCustomRoot()
{
$fileStructure = [
'src' => static::$fileStructure,
'composer.json' => [
'require' => [
'drupal/core' => '*',
],
'extra' => [
'installer-paths' => [
'src/core' => [
'type:drupal-core',
],
],
],
],
'vendor' => [],
];
unset($fileStructure['src']['composer.json']);
unset($fileStructure['src']['vendor']);
$fileStructure = $this->prepareFileStructure($fileStructure);
$root = vfsStream::setup('root', null, $fileStructure);
$this->assertTrue($this->finder->locateRoot($root->url() . '/src'));
$this->assertSame('vfs://root/src', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$this->assertTrue($this->finder->locateRoot($root->url() . '/src/misc'));
$this->assertSame('vfs://root/src', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$this->assertTrue($this->finder->locateRoot($root->url()));
$this->assertSame('vfs://root/src', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$root = vfsStream::setup(
'root',
null,
['nested_folder' => $fileStructure]
);
$this->assertFalse($this->finder->locateRoot($root->url()));
$this->assertFalse($this->finder->getDrupalRoot());
$this->assertFalse($this->finder->getComposerRoot());
$this->assertFalse($this->finder->getVendorDir());
}
public function testDrupalComposerStructureWithoutRequire()
{
$fileStructure = [
'web' => static::$fileStructure,
'composer.json' => [
'extra' => [
'installer-paths' => [
'web/core' => [
'drupal/core',
],
],
],
],
];
unset($fileStructure['web']['composer.json']);
$this->assertComposerStructure($fileStructure);
}
public function testNoDrupalRootWithRealFilesystem()
{
$root = $this->tempdir(sys_get_temp_dir());
$this->assertFalse($this->finder->locateRoot($root));
$this->assertFalse($this->finder->getDrupalRoot());
$this->assertFalse($this->finder->getComposerRoot());
$this->assertFalse($this->finder->getVendorDir());
}
public function testDrupalDefaultStructureWithRealFilesystem()
{
$root = $this->tempdir(sys_get_temp_dir());
$this->dumpToFileSystem(static::$fileStructure, $root);
$this->assertTrue($this->finder->locateRoot($root));
$this->assertSame($root, $this->finder->getDrupalRoot());
$this->assertSame($root, $this->finder->getComposerRoot());
$this->assertSame($root . '/vendor', $this->finder->getVendorDir());
// Test symlink implementation
$symlink = $this->tempdir(sys_get_temp_dir());
$this->symlink($root, $symlink . '/foo');
$this->assertTrue($this->finder->locateRoot($symlink . '/foo'));
$this->assertSame($root, $this->finder->getDrupalRoot());
$this->assertSame($root, $this->finder->getComposerRoot());
$this->assertSame($root . '/vendor', $this->finder->getVendorDir());
}
public function testDrupalComposerStructureWithRealFilesystem()
{
$root = $this->tempdir(sys_get_temp_dir());
$this->dumpToFileSystem($this->getDrupalComposerStructure(), $root);
$this->assertTrue($this->finder->locateRoot($root));
$this->assertSame($root . '/web', $this->finder->getDrupalRoot());
$this->assertSame($root, $this->finder->getComposerRoot());
$this->assertSame($root . '/vendor', $this->finder->getVendorDir());
// Test symlink implementation
$symlink = $this->tempdir(sys_get_temp_dir());
$this->symlink($root, $symlink . '/foo');
$this->assertTrue($this->finder->locateRoot($symlink . '/foo'));
$this->assertSame($root . '/web', $this->finder->getDrupalRoot());
$this->assertSame($root, $this->finder->getComposerRoot());
$this->assertSame($root . '/vendor', $this->finder->getVendorDir());
}
public function testDrupalWithLinkedModule()
{
$root = $this->tempdir(sys_get_temp_dir());
$this->dumpToFileSystem(static::$fileStructure, $root);
$module = $this->tempdir(sys_get_temp_dir());
$module_link = $root . '/modules/foo';
$this->symlink($module, $module_link);
$this->assertTrue($this->finder->locateRoot($module_link));
$this->assertSame($root, realpath($this->finder->getDrupalRoot()));
$this->assertSame($root, realpath($this->finder->getComposerRoot()));
$this->assertSame($root . '/vendor', realpath($this->finder->getVendorDir()));
}
public function testDrupalWithCustomVendor()
{
$root = $this->tempdir(sys_get_temp_dir());
$fileStructure = static::$fileStructure;
$fileStructure['composer.json'] = [
'config' => [
'vendor-dir' => 'vendor-foo'
]
];
$fileStructure['vendor-foo'] = [];
$this->dumpToFileSystem($fileStructure, $root);
$this->assertTrue($this->finder->locateRoot($root));
$this->assertSame($root, realpath($this->finder->getDrupalRoot()));
$this->assertSame($root, realpath($this->finder->getComposerRoot()));
$this->assertSame($root . '/vendor-foo', realpath($this->finder->getVendorDir()));
}
/**
* @param $fileStructure
*/
protected function assertComposerStructure($fileStructure)
{
$fileStructure = $this->prepareFileStructure($fileStructure);
$root = vfsStream::setup('root', null, $fileStructure);
$this->assertTrue($this->finder->locateRoot($root->url() . '/web'));
$this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$this->assertTrue($this->finder->locateRoot($root->url() . '/web/misc'));
$this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$this->assertTrue($this->finder->locateRoot($root->url()));
$this->assertSame('vfs://root/web', $this->finder->getDrupalRoot());
$this->assertSame('vfs://root', $this->finder->getComposerRoot());
$this->assertSame('vfs://root/vendor', $this->finder->getVendorDir());
$root = vfsStream::setup(
'root',
null,
['nested_folder' => $fileStructure]
);
$this->assertFalse($this->finder->locateRoot($root->url()));
$this->assertFalse($this->finder->getDrupalRoot());
$this->assertFalse($this->finder->getComposerRoot());
$this->assertFalse($this->finder->getVendorDir());
}
}

View file

@ -0,0 +1,109 @@
<?php
namespace DrupalFinder\Tests;
use DrupalFinder\DrupalFinder;
use Exception;
use PHPUnit_Framework_TestCase;
abstract class DrupalFinderTestBase extends PHPUnit_Framework_TestCase
{
/**
* @var \DrupalFinder\DrupalFinder
*/
protected $finder;
protected function setUp()
{
parent::setUp();
$this->finder = new DrupalFinder();
}
protected function dumpToFileSystem($fileStructure, $root)
{
$fileStructure = $this->prepareFileStructure($fileStructure);
foreach ($fileStructure as $name => $content) {
if (is_array($content)) {
mkdir($root . '/' . $name);
$this->dumpToFileSystem($content, $root . '/' . $name);
} else {
file_put_contents($root . '/' . $name, $content);
}
}
}
protected function prepareFileStructure($fileStructure)
{
foreach ($fileStructure as $name => $content) {
if (($name === 'composer.json' || $name === 'composer.lock') && is_array($content)) {
$fileStructure[$name] = json_encode($content, JSON_UNESCAPED_SLASHES);
} elseif (is_array($content)) {
$fileStructure[$name] = $this->prepareFileStructure($content);
}
}
return $fileStructure;
}
protected function tempdir($dir, $prefix = '', $mode = 0700)
{
if (substr($dir, -1) != '/') {
$dir .= '/';
}
do {
$path = $dir . $prefix . mt_rand(0, 9999999);
} while (!mkdir($path, $mode));
register_shutdown_function(
[get_called_class(), 'tempdir_remove'],
$path
);
return realpath($path);
}
public static function tempdir_remove($path)
{
if (is_link($path)) {
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
rmdir($path);
} else {
unlink($path);
}
return;
}
foreach (scandir($path) as $child) {
if (in_array($child, ['.', '..'])) {
continue;
}
$child = "$path/$child";
is_dir($child) ? static::tempdir_remove($child) : unlink($child);
}
rmdir($path);
}
/**
* @param $target
* @param $link
*
* @throws \PHPUnit_Framework_SkippedTestError
*/
protected function symlink($target, $link)
{
try {
return symlink($target, $link);
} catch (Exception $e) {
if (defined('PHP_WINDOWS_VERSION_BUILD')
&& strstr($e->getMessage(), WIN_ERROR_PRIVILEGE_NOT_HELD)
) {
$this->markTestSkipped(<<<'MESSAGE'
No privilege to create symlinks. Run test as Administrator (elevated process).
MESSAGE
);
}
throw $e;
}
}
}
define('WIN_ERROR_PRIVILEGE_NOT_HELD', '1314');