Skip to content

Instantly share code, notes, and snippets.

@zircote
Created April 28, 2012 11:51
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zircote/2518383 to your computer and use it in GitHub Desktop.
Save zircote/2518383 to your computer and use it in GitHub Desktop.
Bootstrapping Zend Framework 1.x with composer namespaces
<?php
/**
* Bootstrap the App in an annonymous function preserving global namespace.
*/
call_user_func(function(){
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH',
realpath(dirname(__FILE__) . '/../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ?
getenv('APPLICATION_ENV') : 'production'));
/* Use the namespaces in composer to create an include that that zend can
* Safely.
*/
$paths = array_merge(
array(
get_include_path(),
realpath(APPLICATION_PATH . '/../library'),
),
include dirname(APPLICATION_PATH) .
'/vendor/composer/autoload_namespaces.php'
);
foreach ($paths as $key => $path) {
if(is_array($path)){
foreach ($path as $p){
array_unshift($paths, $p);
}
unset($paths[$key]);
}
}
set_include_path(implode(PATH_SEPARATOR, $paths));
/** Zend_Application */
require_once 'Zend/Application.php';
require_once dirname(APPLICATION_PATH) . '/vendor/autoload.php';
// Create application, bootstrap, and run
$application = new Zend_Application(
APPLICATION_ENV,
APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
->run();
});
@Seldaek
Copy link

Seldaek commented Apr 29, 2012

Please migrate to vendor/composer/autoload_namespaces.php and vendor/autoload.php - the .composer dir is there only for BC these days and will be removed at some point.

@zircote
Copy link
Author

zircote commented Apr 29, 2012

@Seldaek thanks for the heads up on this I wasn't aware of the change, just found the discussion from a few days ago on the google group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment