Last active
August 29, 2015 14:21
-
-
Save stephen-hill/6d9fba121eb4931f49fc to your computer and use it in GitHub Desktop.
Atto Planning
This file contains hidden or 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 | |
use Atto\Config; | |
use Atto\Container; | |
use Atto\Dispatcher; | |
use Atto\HttpKernal; | |
use Atto\ODM\Connection; | |
use Atto\ODM\Manager; | |
$config = new Config('config.json'); | |
$connection = new Connection([ | |
'hostname' => $config->get('odm.hostname'), | |
'port' => $config->get('odm.port'), | |
'username' => $config->get('odm.username'), | |
'password' => $config->get('odm.password') | |
]); | |
$manager = new Manager([ | |
'connection' => $connection, | |
'database' => $config->get('odm.database') | |
]); | |
$container = new Container(); | |
$container->setService('config', function($config) | |
{ | |
return $config; | |
}); | |
$container->setService('odm', function($manager) | |
{ | |
return $manager; | |
}); | |
$dispatcher = new Dispatcher(); | |
$dispatcher->urlPrefix('/api'); | |
$dispatcher->namespacePrefix('My\\App\\Controllers\\'); | |
$dispatcher->addRoute(['GET'], '/note/{i:id}', 'Note', 'note'); | |
$kernal = new HttpKernal(); | |
$kernal->setDispatcher($dispatcher); | |
$request = Request::createFromGlobals(); | |
$response = $kernal->handle($request); | |
$response->send(); | |
$kernal->terminate(); |
This file contains hidden or 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
{ | |
"odm": { | |
"hostname": "localhost", | |
"port": 3306, | |
"username": "test", | |
"password": "UyFGp37uq5wKeiPaUFXWdd", | |
"database": "test" | |
} | |
} |
This file contains hidden or 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 My\App\Controllers; | |
use Atto\Controller; | |
class NoteController extends Controller | |
{ | |
public function note($request) | |
{ | |
$odm = $this->get('odm'); | |
$note = $odm->find('Note', $request->query->get('id')); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment