Skip to content

Commit 3896f27

Browse files
author
Mike Funk
committed
Added composer support
1 parent f958f75 commit 3896f27

11 files changed

+474
-3
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A starting point CodeIgniter App filled with useful goodies.
1212
2. application/logs
1313
2. application/db_cache
1414
3. public/assets/cache
15-
15+
1616
That's it! No submodules because they are a pain.
1717

1818
## Usage
@@ -29,7 +29,8 @@ That's it! No submodules because they are a pain.
2929
* [Pigeon](https://github.com/jamierumbelow/pigeon) and [API_Router](https://github.com/efendibooks/codeigniter-handbook-vol-2/blob/master/application/controllers/api_router.php) for RESTful routing
3030
* Updated [MY_Migration](https://github.com/mikedfunk/MY_Migration). You can set the migration table in ```application/config/migration.php```
3131
* [MY_Form_validation](https://github.com/mikedfunk/MY_Form_validation) for a prefix and suffix for each form error. Set it in ```application/config/form_validation.php```
32-
* Moved all public stuff such as index.php and assets to ```/public/```
32+
* All public stuff such as index.php and assets goes in ```/public/```
33+
* Add a [Composer](http://getcomposer.org) package by editing ```/composer.json```, then run ```php composer.phar install``` on the command line from the root directory.
3334

3435
## But wait, there's more!
3536

composer.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"require": {
3+
// example: "qafoolabs/restclient": "dev-master"
4+
}
5+
}

composer.lock

+100
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.phar

581 KB
Binary file not shown.

public/index.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?php
22

3+
/**
4+
* autoload composer packages
5+
*/
6+
require '../vendor/autoload.php';
7+
38
/*
49
*---------------------------------------------------------------
510
* APPLICATION ENVIRONMENT
@@ -35,7 +40,7 @@
3540
case 'development':
3641
error_reporting(E_ALL);
3742
break;
38-
43+
3944
case 'testing':
4045
case 'production':
4146
error_reporting(0);

vendor/autoload.php

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
// autoload.php generated by Composer
4+
5+
require_once __DIR__ . '/composer' . '/autoload_real.php';
6+
7+
return ComposerAutoloaderInit::getLoader();

vendor/composer/ClassLoader.php

+207
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Composer.
5+
*
6+
* (c) Nils Adermann <[email protected]>
7+
* Jordi Boggiano <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace Composer\Autoload;
14+
15+
/**
16+
* ClassLoader implements a PSR-0 class loader
17+
*
18+
* See https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
19+
*
20+
* $loader = new \Composer\Autoload\ClassLoader();
21+
*
22+
* // register classes with namespaces
23+
* $loader->add('Symfony\Component', __DIR__.'/component');
24+
* $loader->add('Symfony', __DIR__.'/framework');
25+
*
26+
* // activate the autoloader
27+
* $loader->register();
28+
*
29+
* // to enable searching the include path (eg. for PEAR packages)
30+
* $loader->setUseIncludePath(true);
31+
*
32+
* In this example, if you try to use a class in the Symfony\Component
33+
* namespace or one of its children (Symfony\Component\Console for instance),
34+
* the autoloader will first look for the class under the component/
35+
* directory, and it will then fallback to the framework/ directory if not
36+
* found before giving up.
37+
*
38+
* This class is loosely based on the Symfony UniversalClassLoader.
39+
*
40+
* @author Fabien Potencier <[email protected]>
41+
* @author Jordi Boggiano <[email protected]>
42+
*/
43+
class ClassLoader
44+
{
45+
private $prefixes = array();
46+
private $fallbackDirs = array();
47+
private $useIncludePath = false;
48+
private $classMap = array();
49+
50+
public function getPrefixes()
51+
{
52+
return $this->prefixes;
53+
}
54+
55+
public function getFallbackDirs()
56+
{
57+
return $this->fallbackDirs;
58+
}
59+
60+
public function getClassMap()
61+
{
62+
return $this->classMap;
63+
}
64+
65+
/**
66+
* @param array $classMap Class to filename map
67+
*/
68+
public function addClassMap(array $classMap)
69+
{
70+
if ($this->classMap) {
71+
$this->classMap = array_merge($this->classMap, $classMap);
72+
} else {
73+
$this->classMap = $classMap;
74+
}
75+
}
76+
77+
/**
78+
* Registers a set of classes
79+
*
80+
* @param string $prefix The classes prefix
81+
* @param array|string $paths The location(s) of the classes
82+
*/
83+
public function add($prefix, $paths)
84+
{
85+
if (!$prefix) {
86+
foreach ((array) $paths as $path) {
87+
$this->fallbackDirs[] = $path;
88+
}
89+
90+
return;
91+
}
92+
if (isset($this->prefixes[$prefix])) {
93+
$this->prefixes[$prefix] = array_merge(
94+
$this->prefixes[$prefix],
95+
(array) $paths
96+
);
97+
} else {
98+
$this->prefixes[$prefix] = (array) $paths;
99+
}
100+
}
101+
102+
/**
103+
* Turns on searching the include path for class files.
104+
*
105+
* @param bool $useIncludePath
106+
*/
107+
public function setUseIncludePath($useIncludePath)
108+
{
109+
$this->useIncludePath = $useIncludePath;
110+
}
111+
112+
/**
113+
* Can be used to check if the autoloader uses the include path to check
114+
* for classes.
115+
*
116+
* @return bool
117+
*/
118+
public function getUseIncludePath()
119+
{
120+
return $this->useIncludePath;
121+
}
122+
123+
/**
124+
* Registers this instance as an autoloader.
125+
*
126+
* @param bool $prepend Whether to prepend the autoloader or not
127+
*/
128+
public function register($prepend = false)
129+
{
130+
spl_autoload_register(array($this, 'loadClass'), true, $prepend);
131+
}
132+
133+
/**
134+
* Unregisters this instance as an autoloader.
135+
*/
136+
public function unregister()
137+
{
138+
spl_autoload_unregister(array($this, 'loadClass'));
139+
}
140+
141+
/**
142+
* Loads the given class or interface.
143+
*
144+
* @param string $class The name of the class
145+
* @return bool|null True, if loaded
146+
*/
147+
public function loadClass($class)
148+
{
149+
if ($file = $this->findFile($class)) {
150+
include $file;
151+
152+
return true;
153+
}
154+
}
155+
156+
/**
157+
* Finds the path to the file where the class is defined.
158+
*
159+
* @param string $class The name of the class
160+
*
161+
* @return string|null The path, if found
162+
*/
163+
public function findFile($class)
164+
{
165+
if (isset($this->classMap[$class])) {
166+
return $this->classMap[$class];
167+
}
168+
169+
if ('\\' == $class[0]) {
170+
$class = substr($class, 1);
171+
}
172+
173+
if (false !== $pos = strrpos($class, '\\')) {
174+
// namespaced class name
175+
$classPath = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR;
176+
$className = substr($class, $pos + 1);
177+
} else {
178+
// PEAR-like class name
179+
$classPath = null;
180+
$className = $class;
181+
}
182+
183+
$classPath .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
184+
185+
foreach ($this->prefixes as $prefix => $dirs) {
186+
if (0 === strpos($class, $prefix)) {
187+
foreach ($dirs as $dir) {
188+
if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) {
189+
return $dir . DIRECTORY_SEPARATOR . $classPath;
190+
}
191+
}
192+
}
193+
}
194+
195+
foreach ($this->fallbackDirs as $dir) {
196+
if (file_exists($dir . DIRECTORY_SEPARATOR . $classPath)) {
197+
return $dir . DIRECTORY_SEPARATOR . $classPath;
198+
}
199+
}
200+
201+
if ($this->useIncludePath && $file = stream_resolve_include_path($classPath)) {
202+
return $file;
203+
}
204+
205+
$this->classMap[$class] = false;
206+
}
207+
}

vendor/composer/autoload_classmap.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
// autoload_classmap.php generated by Composer
4+
5+
$vendorDir = dirname(__DIR__);
6+
$baseDir = dirname($vendorDir);
7+
8+
return array(
9+
);
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// autoload_namespaces.php generated by Composer
4+
5+
$vendorDir = dirname(__DIR__);
6+
$baseDir = dirname($vendorDir);
7+
8+
return array(
9+
'QafooLabs\\RestClient' => $vendorDir . '/qafoolabs/restclient/src/main',
10+
'QafooLabs\\ErrorHandler' => $vendorDir . '/qafoolabs/errorhandler/src/main',
11+
);

0 commit comments

Comments
 (0)