This document discusses building a RESTful web application with Angular.js and Bear.Sunday. It describes using Bear.Sunday as a RESTful backend CMS and Angular.js for the frontend. Key points include everything being a resource, relationships between resources, overriding functionality through AOP, dependency injection, testing, and integrating Angular.js components like routes, directives and services with the Bear.Sunday API.
8. In most MVC application frameworks,
CRUD and OOP paradigms are mapped
to HTTP methods and resources. But the
opposite is not true. - Akihito Koriyama
9. EVERYTHING IS A RESOURCE
Request: /api/resources/index?_start=1
Request Method: GET
Status Code: 200 OK
15. namespace MackstarSpoutAdminResourceAppResources;
/**
* Resources Index
*
* @Db
*/
class Index extends ResourceObject
{
/**
* @Link(rel="type", href="app://self/resources/detail?type={slug}&slug={slug}")
* @DbPager(5)
*/
public function onGet()
{
$sql = "SELECT {$this->table}.*, type.name as type_name, type.title_label FROM {$this->table} ";
$sql .= "INNER JOIN resource_types AS type ";
$sql .= "ON type.slug = {$this->table}.type";
$stmt = $this->db->query($sql);
$this['resources'] = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $this;
}
16. CUSTOM RESOURCES CAN CALL OTHER
RESOURCES
public function onGet($id = null)
{
$this['types'] = $this->resource->get->uri('app://self/resources/types')
}
RESOURCES OF A TYPE HAVE RESOURCE AND
RESOURCE INDEX RELATIONSHIPS
19. namespace MackstarSpoutAdminInterceptorUsers;
use RayAopMethodInterceptor;
use RayAopMethodInvocation;
use RayDiDiInject;
use SymfonyComponentHttpFoundationSessionSession as PhpSession;
class Session implements MethodInterceptor
{
private $session;
/**
* @Inject
*/
public function setSession(PhpSession $session)
{
$this->session = $session;
}
public function invoke(MethodInvocation $invocation)
{
$response = $invocation->proceed();
$response->body['_user'] = $this->session->get('user');
return $response;
}
45. STUFF TO DO
▸ Security
▸ DB/API Schema lock-down
▸ Create as composer component / Assetic
▸ More field types (locations/times/md etc)
▸ Blocks
▸ Get others input