/** * コンテナを追加 * * @param Object $container コンテナオブジェクト * @return void */ private function setContainer($container) { $container['db.get'] = function ($c) { $obj = new Get($this->pdo); $obj->setDebug(true); return $obj; }; $container['db.post'] = function ($c) { $obj = new Post($this->pdo); $obj->setDebug(true); return $obj; }; $container['db.put'] = function ($c) { $obj = new Put($this->pdo); $obj->setDebug(true); return $obj; }; $container['db.delete'] = function ($c) { $obj = new Delete($this->pdo); $obj->setDebug(true); return $obj; }; $container['mailer'] = function ($c) { $transport = new Init($GLOBALS['MAIL_HOST'], $GLOBALS['MAIL_PORT'], $GLOBALS['MAIL_USER'], $GLOBALS['MAIL_PASS']); $mailer = new Mailer($transport); $mailer->setFrom($GLOBALS['MAIL_FROM']); $mailer->setName($GLOBALS['MAIL_NAME']); return $mailer; }; $container['image.original'] = function ($c) { $original = new Original(); $original->setDestination = './'; $original->setFilename = 'test'; $original->setCompress = 0; $original->setImageType = 'png'; return $original; }; $container['image.thumbnail'] = function ($c) { $thumbnail = new Thumbnail(); $thumbnail->setDestination = './'; $thumbnail->setFilename = 'test'; $thumbnail->setPostfix = '_s'; $thumbnail->setCompress = 70; $thumbnail->setWidth = '200'; $thumbnail->setHeight = '200'; $thumbnail->setImageType = 'jpg'; return $thumbnail; }; }
* $sql = 'SELECT * FROM `users` WHERE `id` = ?;'; * $values = array(1); * $res = $db->execute($sql, $values); */ $container['db.pdo'] = function ($c) { $settings = $c->get('settings')['db']; $pdo = new Connect($settings['host'], $settings['name'], $settings['user'], $settings['pass']); $pdo->setPort($settings['port']); $pdo->setCharset($settings['charset']); $pdo->setDebug($c->get('settings')['debug_mode']); return $pdo->getConnection(); }; // GET $container['db.get'] = function ($c) { $pdo = $c->get('db.pdo'); $obj = new Get($pdo); $obj->setDebug($c->get('settings')['debug_mode']); return $obj; }; // POST $container['db.post'] = function ($c) { $pdo = $c->get('db.pdo'); $obj = new Post($pdo); $obj->setDebug($c->get('settings')['debug_mode']); return $obj; }; // PUT $container['db.put'] = function ($c) { $pdo = $c->get('db.pdo'); $obj = new Put($pdo); $obj->setDebug($c->get('settings')['debug_mode']);