Skip to content

Commit 2c71d16

Browse files
author
janatzend
committed
added Composer support and modified Autoloader
1 parent dc74309 commit 2c71d16

File tree

4 files changed

+91
-27
lines changed

4 files changed

+91
-27
lines changed

composer.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name" : "ZendServerDeploymentHelper",
3+
"require" : {
4+
"zendframework/zendframework" : "=2.4.8",
5+
"phpunit/phpunit" : "=3.7.32",
6+
"mockery/mockery" : "=0.9.4"
7+
},
8+
"repositories" : [ {
9+
"type" : "composer",
10+
"url" : "https://packagist.org/"
11+
} ]
12+
}

deph.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,10 @@
88
*/
99

1010
define('SCRIPT_ROOT', dirname(__FILE__));
11-
set_include_path(join(PATH_SEPARATOR, array(
12-
'/usr/local/zend/share/ZendFramework2/library', // Zend Server 6.0
13-
'/usr/local/zend/var/libraries/Zend_Framework_2/default/library', // Zend Server 6.1
14-
get_include_path()
15-
)));
16-
require_once 'Zend/Loader/StandardAutoloader.php';
11+
chdir(__DIR__);
1712

18-
$autoLoader = new \Zend\Loader\StandardAutoloader(array(
19-
'namespaces' => array(
20-
'ZendDevOps\DepH' => __DIR__ . '/ZendDevOps/DepH',
21-
),
22-
23-
'fallback_autoloader' => true,
24-
));
25-
26-
// register our StandardAutoloader with the SPL autoloader
27-
$autoLoader->register();
13+
// Setup autoloading
14+
require 'init_autoloader.php';
2815

2916
use \ZendDevOps\DepH\ServiceManager\ServiceManager as ZendDevOpsDepH;
3017

init_autoloader.php

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?php
2+
/**
3+
* Zend Framework (http://framework.zend.com/)
4+
*
5+
* @link http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
6+
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
7+
* @license http://framework.zend.com/license/new-bsd New BSD License
8+
*/
9+
10+
/**
11+
* This autoloading setup is really more complicated than it needs to be for most
12+
* applications. The added complexity is simply to reduce the time it takes for
13+
* new developers to be productive with a fresh skeleton. It allows autoloading
14+
* to be correctly configured, regardless of the installation method and keeps
15+
* the use of composer completely optional. This setup should work fine for
16+
* most users, however, feel free to configure autoloading however you'd like.
17+
*/
18+
/*
19+
$autoLoader = new \Zend\Loader\StandardAutoloader(array(
20+
'namespaces' => array(
21+
'ZendDevOps\DepH' => __DIR__ . '/ZendDevOps/DepH',
22+
),
23+
24+
'fallback_autoloader' => true,
25+
));
26+
*/
27+
28+
29+
// Composer autoloading
30+
if (file_exists('vendor/autoload.php')) {
31+
$loader = include 'vendor/autoload.php';
32+
}
33+
34+
if (class_exists('Zend\Loader\AutoloaderFactory')) {
35+
$config = array(
36+
'Zend\Loader\StandardAutoloader' => array(
37+
'namespaces' => array(
38+
'ZendDevOps\DepH' => __DIR__ . '/ZendDevOps/DepH'
39+
),
40+
),
41+
);
42+
Zend\Loader\AutoloaderFactory::factory($config);
43+
return;
44+
}
45+
46+
$zf2Path = false;
47+
48+
if (is_dir('vendor/ZF2/library')) {
49+
$zf2Path = 'vendor/ZF2/library';
50+
} elseif (getenv('ZF2_PATH')) { // Support for ZF2_PATH environment variable or git submodule
51+
$zf2Path = getenv('ZF2_PATH');
52+
} elseif (get_cfg_var('zf2_path')) { // Support for zf2_path directive value
53+
$zf2Path = get_cfg_var('zf2_path');
54+
}
55+
56+
if ($zf2Path) {
57+
if (isset($loader)) {
58+
$loader->add('Zend', $zf2Path);
59+
$loader->add('ZendXml', $zf2Path);
60+
} else {
61+
include $zf2Path . '/Zend/Loader/AutoloaderFactory.php';
62+
Zend\Loader\AutoloaderFactory::factory(array(
63+
'Zend\Loader\StandardAutoloader' => array(
64+
'autoregister_zf' => true
65+
)
66+
));
67+
}
68+
}
69+
70+
if (!class_exists('Zend\Loader\AutoloaderFactory')) {
71+
throw new RuntimeException('Unable to load ZF2. Run `php composer.phar install` or define a ZF2_PATH environment variable.');
72+
}

tests/bootstrap.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
<?php
2+
chdir(dirname(__DIR__));
3+
24
$paths = array(
35
dirname(__DIR__),
46
dirname(__FILE__) . '/lib',
57
get_include_path()
68
);
79

810
set_include_path(join(PATH_SEPARATOR, $paths));
9-
require_once 'Zend/Loader/StandardAutoloader.php';
10-
11-
$autoLoader = new \Zend\Loader\StandardAutoloader(array(
12-
'namespaces' => array(
13-
'ZendDevOps\DepH' => __DIR__ . '/ZendDevOps/DepH'
14-
),
15-
16-
'fallback_autoloader' => true,
17-
));
1811

19-
// register our StandardAutoloader with the SPL autoloader
20-
$autoLoader->register();
12+
// Setup autoloading
13+
require 'init_autoloader.php';
2114

2215
define('SCRIPT_ROOT', dirname(__FILE__));

0 commit comments

Comments
 (0)