31. 実装(bootstrap)
$di = new FactoryDefault();
// Database connection is created based in the parameters defined in the configuration file
$di->set('db', function() use ($config) {
return new Database(array(
"host" => $config->database->host,
"username" => $config->database->username,
"password" => $config->database->password,
"dbname" => $config->database->name
));
});
// Registering an autoloader
$loader = new Loader();
$loader->registerDirs(
array(
$config->application->modelsDir
)
)->register();
32. 実装(API)
$app = new Micro($di);
// Retrieves all robots
$app->get('/api/robots', function () use ($app) {
});
// Retrieves robots based on primary key
$app->get('/api/robots/{id:[0-9]+}', function ($id) use ($app) {
});
// Adds a new robot
$app->post(('/api/robots', function () use ($app) {
});
// Updates robots based on primary key
$app->put('/api/robots/{id:[0-9]+}', function ($id) use ($app) {
});
// Deletes robots based on primary key
$app->delete('/api/robots/{id:[0-9]+}', function ($id) use ($app) {
});
$app->handle();
41. Credits
Special thanks to all the people who made and
released these awesome resources for free:
? Presentation template by 狠狠撸sCarnival
? Photographs by Unsplash