forked from hechoendrupal/drupal-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrupalAutoloadHelper.php
More file actions
82 lines (67 loc) · 1.89 KB
/
Copy pathDrupalAutoloadHelper.php
File metadata and controls
82 lines (67 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Drupal\AppConsole\Command\Helper;
use Symfony\Component\Console\Helper\Helper;
class DrupalAutoloadHelper extends Helper
{
protected $drupalAutoLoad;
/**
* @param mixed $drupal_root
* @return string
*/
public function findAutoload($drupal_root = false)
{
$currentPath = getcwd() . '/';
$relativePath = '';
$autoloadFound = null;
if ($path = $this->isDrupalAutoload($drupal_root)) {
$this->drupalAutoLoad = $path;
return $path;
}
while (true) {
$path = $currentPath . $relativePath;
if ($autoloadFound = $this->isDrupalAutoload($path)) {
$this->drupalAutoLoad = $autoloadFound;
return $autoloadFound;
} else {
$relativePath .= '../';
}
$realPath = realpath($currentPath . $relativePath);
if ($realPath === '/' || $realPath === false) {
return null;
}
}
}
/**
* @param mixed $drupal_root
* @return string
*/
protected function isDrupalAutoload($drupal_root)
{
$path = realpath($drupal_root);
$path_core_autoload = $path . '/core/vendor/autoload.php';
$path_autoload = $path . '/vendor/autoload.php';
if (is_dir($path)) {
return is_file($path_core_autoload) ?
$path_core_autoload : (is_file($path_autoload) ? $path_autoload : null);
} else {
return null;
}
}
/**
* @return string
*/
public function getDrupalRoot()
{
if (($coreIndex = stripos($this->drupalAutoLoad, 'core')) > 0) {
return substr($this->drupalAutoLoad, 0, $coreIndex);
}
return null;
}
/**
* @inheritdoc
*/
public function getName()
{
return 'drupal-autoload';
}
}