Created
October 23, 2014 17:32
-
-
Save devosc/f51162d6e5c4fd5a6404 to your computer and use it in GitHub Desktop.
duality
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Framework\Application; | |
use Framework\Config\Configuration; | |
use Duality\Core\DualityException; | |
use Duality\Core\Container; | |
use Duality\Structure\Storage; | |
use Duality\Structure\File\StreamFile; | |
class Duality | |
implements DualityApplication | |
{ | |
/** | |
* Holds environment configuration | |
* | |
* @var Configuration The original configuration | |
*/ | |
protected $config; | |
/** | |
* Container cache | |
* | |
* @var \Duality\Core\InterfaceStorage The cache storage | |
*/ | |
protected $cache; | |
/** | |
* Holds the application output buffer | |
* | |
* @var \Duality\File\StreamFile The output buffer | |
*/ | |
protected $buffer; | |
/** | |
* Setup default services | |
* | |
* @var array The default Duality services | |
*/ | |
protected $defaults = array( | |
'db' => 'Duality\Service\Database\SQLite', | |
'logger' => 'Duality\Service\Logger', | |
'security' => 'Duality\Service\Security', | |
'validator' => 'Duality\Service\Validator', | |
'session' => 'Duality\Service\Session\Dummy', | |
'auth' => 'Duality\Service\Auth', | |
'cache' => 'Duality\Service\Cache\APC', | |
'mailer' => 'Duality\Service\Mailer', | |
'paginator' => 'Duality\Service\Paginator', | |
'ssh' => 'Duality\Service\SSH', | |
'server' => 'Duality\Service\Server', | |
'locale' => 'Duality\Service\Localization', | |
'cmd' => 'Duality\Service\Commander', | |
'client' => 'Duality\Service\Client', | |
'performance' => 'Duality\Service\Performance' | |
); | |
/** | |
* Holds application working directory | |
* | |
* @var string The base path of the application | |
*/ | |
protected $path; | |
/** | |
* @param string $path | |
* @param array $config | |
*/ | |
public function __construct($path, array $config = []) | |
{ | |
$config['services'] = $this->defaults + $config['services']; | |
$this->config = new Configuration($config); | |
if (!is_dir($path)) { | |
throw new DualityException("Error Application: path not found", 1); | |
} | |
$this->path = $path; | |
} | |
/** | |
* @param array $args | |
* @param callable $callback | |
* @return callable|mixed|null|object | |
*/ | |
public function __invoke(array $args = [], callable $callback = null) | |
{ | |
return (new App($this->config))->call(self::DUALITY, $args, $callback); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment