2017 © Pedro Peláez
 

symfony-bundle json-api-tools-bundle

JSON API tools for Symfony

image

tyhand/json-api-tools-bundle

JSON API tools for Symfony

  • Monday, August 7, 2017
  • by tyhand
  • Repository
  • 1 Watchers
  • 0 Stars
  • 54 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

JsonApiToolsBundle

A collection of some very rough draft stuff I have for speeding up writing apis for symfony in json api standard. Not done, and very ugly., (*1)

Installation

Add with composer, (*2)

composer require "tyhand/json-api-tools-bundle" "^0.1.2"

Add to AppKernel, (*3)

$bundles = array(
  // ...
  new TyHand\JsonApiToolsBundle\TyHandJsonApiToolsBundle(),
  // ...
);

Create Resource

For example, here is book resource, (*4)

<?php
// BookResource

namespace AppBundle\ApiResource;

use TyHand\JsonApiToolsBundle\Annotation\Resource;
use TyHand\JsonApiToolsBundle\Annotation\Attribute;
use TyHand\JsonApiToolsBundle\Annotation\HasOne;
use TyHand\JsonApiToolsBundle\Annotation\Filter;
use TyHand\JsonApiToolsBundle\Annotation\Validator;
use TyHand\JsonApiToolsBundle\Extra\SearchableResource;

/**
 * @Resource(entity="AppBundle\Entity\Book")
 */
class BookResource extends SearchableResource
{
    /**
     * @Attribute
     */
    public $title;

    /**
     * @Attribute
     */
    public $genre;

    /**
     * @HasOne
     */
    public $author;

    protected function getSearchableEntityFields()
    {
        return [
            'genre',
            'title',
            ['property' => 'author.name', 'joinType' => 'outer']
        ];
    }
}

Here is also an Author resource connected to the above example, (*5)

<?php
// Author Resource
namespace AppBundle\ApiResource;

use TyHand\JsonApiToolsBundle\Annotation\Resource;
use TyHand\JsonApiToolsBundle\Annotation\Attribute;
use TyHand\JsonApiToolsBundle\Annotation\HasMany;
use TyHand\JsonApiToolsBundle\Annotation\Filter;
use TyHand\JsonApiToolsBundle\Annotation\Validator;

use TyHand\JsonApiToolsBundle\ApiResource\JsonApiResource;
use TyHand\JsonApiToolsBundle\ApiResource\Resource as ApiResource;

/**
 * @Resource(entity="AppBundle\Entity\Author")
 */
class AuthorResource extends ApiResource
{
    /**
     * @Attribute
     */
    public $name;

    /**
     * @HasMany
     */
    public $books;
}

Tag Resource

Tag the resources as services, (*6)

# services.yml

services:
    author_resource:
        class: AppBundle\ApiResource\AuthorResource
        tags:
            - { name: jsonapi_tools.resource }
    book_resource:
        class: AppBundle\ApiResource\BookResource
        tags:
            - { name: jsonapi_tools.resource }

Create Controllers

Just inherit the resources controller for quick setup, (*7)

<?php
// BookController

namespace AppBundle\Controller;

use JsonApiBundle\Controller\ResourceController;

class BookController extends ResourceController
{
}

Routing

# routing.yml

jsonapi_author:
    resource: AppBundle\Controller\AuthorController
    type:     jsonapi_resource

jsonapi_book:
    resource: AppBundle\Controller\BookController
    type:     jsonapi_resource

If all is well, then this stuff should work. Real documentation incoming soon., (*8)

The Versions

07/08 2017

dev-master

9999999-dev https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

07/08 2017

v0.1.19

0.1.19.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

04/08 2017

v0.1.18

0.1.18.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

11/07 2017

v0.1.17

0.1.17.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

11/07 2017

v0.1.16

0.1.16.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

24/05 2017

v0.1.15

0.1.15.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

19/05 2017

v0.1.14

0.1.14.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

21/04 2017

v0.1.13

0.1.13.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

21/04 2017

v0.1.12

0.1.12.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

21/04 2017

v0.1.11

0.1.11.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

21/04 2017

v0.1.10

0.1.10.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

11/04 2017

v0.1.9

0.1.9.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

07/04 2017

v0.1.8

0.1.8.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

07/04 2017

v0.1.7

0.1.7.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

04/04 2017

v0.1.6

0.1.6.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

02/04 2017

v0.1.5

0.1.5.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

01/04 2017

v0.1.4

0.1.4.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

01/04 2017

v0.1.3

0.1.3.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

30/03 2017

v0.1.2

0.1.2.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi

29/03 2017

v0.1.1

0.1.1.0 https://github.com/tyhand

JSON API tools for Symfony

  Sources   Download

MIT

The Requires

 

by Tyler Hand

symfony jsonapi