예제 #1
0
 public function setUp()
 {
     $container = new \Pimple\Container();
     $container['ConfigLocal'] = function ($container) {
         return include (string) (__DIR__ . '/../') . 'config.php';
     };
     $container['Database'] = function ($container) {
         $config = $container['ConfigLocal'];
         $database = new \Mwyatt\Core\Database\Pdo();
         $database->connect($config['database.host'], $config['database.basename'], $config['database.username'], $config['database.password']);
         return $database;
     };
     $container['ModelFactory'] = function ($container) {
         return new \Mwyatt\Core\Factory\Model();
     };
     $container['IteratorFactory'] = function ($container) {
         return new \Mwyatt\Core\Factory\Iterator();
     };
     $container['MapperFactory'] = function ($container) {
         return new \Mwyatt\Core\Factory\Mapper($container['Database'], $container['ModelFactory'], $container['IteratorFactory']);
     };
     $container['RepositoryFactory'] = function ($container) {
         return new \Mwyatt\Core\Factory\Repository($container['MapperFactory']);
     };
     $container['View'] = function ($container) {
         return new \Mwyatt\Core\View((string) __DIR__ . '/../' . 'template/');
     };
     $this->controller = new \Mwyatt\Core\Controller\Test($container, $container['View']);
 }
예제 #2
0
 /**
  * @expectedException \Exception
  */
 public function testConnectFail()
 {
     $database = new \Mwyatt\Core\Database\Pdo();
     $config = (include (string) (__DIR__ . '/../') . 'config.php');
     $config['database.password'] = '******';
     $database->connect($config['database.host'], $config['database.basename'], $config['database.username'], $config['database.password']);
 }
예제 #3
0
파일: Kernel.php 프로젝트: mwyatt/core
 public function setServicesOptional()
 {
     $this->services['ErrorHandler'] = function ($services) {
         $config = $services['Config'];
         $log = new \Monolog\Logger('system');
         if ($config->getSetting('core.displayErrors')) {
             // ini_set('display_errors', 1);
             // ini_set('display_startup_errors', 1);
             // error_reporting(E_ALL);
             $log->pushHandler(new \Monolog\Handler\BrowserConsoleHandler());
         }
         $log->pushHandler(new \Monolog\Handler\StreamHandler($services['ProjectPath'] . 'error.txt', \Monolog\Logger::DEBUG));
         return $log;
     };
     \Monolog\ErrorHandler::register($this->services['ErrorHandler']);
     $this->services['ModelFactory'] = function ($services) {
         $config = $services['Config'];
         $modelFactory = new \Mwyatt\Core\Factory\Model();
         $modelFactory->setDefaultNamespace($config->getSetting('projectBaseNamespace') . 'Model\\');
         return $modelFactory;
     };
     $this->services['IteratorFactory'] = function ($services) {
         $config = $services['Config'];
         $iteratorFactory = new \Mwyatt\Core\Factory\Iterator();
         $iteratorFactory->setDefaultNamespace($config->getSetting('projectBaseNamespace') . 'Iterator\\');
         return $iteratorFactory;
     };
     $this->services['MapperFactory'] = function ($services) {
         $config = $services['Config'];
         $mapperFactory = new \Mwyatt\Core\Factory\Mapper($services['Database'], $services['ModelFactory'], $services['IteratorFactory']);
         $mapperFactory->setDefaultNamespace($config->getSetting('projectBaseNamespace') . 'Mapper\\');
         return $mapperFactory;
     };
     $this->services['RepositoryFactory'] = function ($services) {
         $config = $services['Config'];
         $repositoryFactory = new \Mwyatt\Core\Factory\Repository($services['MapperFactory']);
         $repositoryFactory->setDefaultNamespace($config->getSetting('projectBaseNamespace') . 'Repository\\');
         return $repositoryFactory;
     };
     $this->services['Mail'] = function ($services) {
         $config = $services['Config'];
         $transport = \Swift_SmtpTransport::newInstance($config->getSetting('mail.host'), $config->getSetting('mail.port'), $config->getSetting('mail.security'));
         $transport->setUsername($config->getSetting('mail.username'));
         $transport->setPassword($config->getSetting('mail.appPassword'));
         $swiftMailer = \Swift_Mailer::newInstance($transport);
         return new \Mwyatt\Core\Mail($swiftMailer);
     };
     $this->services['Database'] = function ($services) {
         $config = $services['Config'];
         $database = new \Mwyatt\Core\Database\Pdo();
         $database->connect($config->getSetting('database.host'), $config->getSetting('database.basename'), $config->getSetting('database.username'), $config->getSetting('database.password'));
         return $database;
     };
 }