Skip to content

Instantly share code, notes, and snippets.

@stephen-hill
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephen-hill/6d9fba121eb4931f49fc to your computer and use it in GitHub Desktop.
Save stephen-hill/6d9fba121eb4931f49fc to your computer and use it in GitHub Desktop.
Atto Planning
<?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();
{
"odm": {
"hostname": "localhost",
"port": 3306,
"username": "test",
"password": "UyFGp37uq5wKeiPaUFXWdd",
"database": "test"
}
}
<?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