Files
spa-api/laravel/package.php

58 lines
1.2 KiB
PHP
Raw Normal View History

2011-08-18 19:56:29 -05:00
<?php namespace Laravel;
2011-08-02 22:07:40 -05:00
class Package {
/**
* All of the loaded packages.
*
* @var array
*/
public static $loaded = array();
/**
* Load a package or set of packages.
*
* The package name should correspond to a package directory for your application.
*
* <code>
* // Load the "swift-mailer" package
* Package::load('swift-mailer');
*
* // Load the "swift-mailer" and "facebook" package
* Package::load(array('swift-mailer', 'facebook'));
* </code>
*
2011-08-02 22:40:12 -05:00
* @param string|array $packages
* @param string $path
2011-08-02 22:07:40 -05:00
* @return void
*/
public static function load($packages, $path = PACKAGE_PATH)
2011-08-02 22:07:40 -05:00
{
2011-08-02 22:40:12 -05:00
foreach ((array) $packages as $package)
2011-08-02 22:07:40 -05:00
{
if ( ! static::loaded($package) and file_exists($bootstrap = $path.$package.'/bootstrap'.EXT))
2011-08-08 14:28:38 -05:00
{
2011-08-08 14:29:19 -05:00
require $bootstrap;
2011-08-08 14:28:38 -05:00
}
2011-08-02 22:29:48 -05:00
2011-08-08 14:28:38 -05:00
static::$loaded[] = $package;
2011-08-02 22:07:40 -05:00
}
}
2011-08-08 09:21:56 -05:00
/**
* Determine if a given package has been loaded.
*
* <code>
* // Determine if the "swift-mailer" package has been loaded
* $loaded = Package::loaded('swift-mailer');
* </code>
*
2011-08-08 09:21:56 -05:00
* @param string $package
* @return bool
*/
public static function loaded($package)
{
return array_key_exists($package, static::$loaded);
}
2011-08-02 22:07:40 -05:00
}