Download the PHP package pz/doctrine-rest without Composer

On this page you can find all versions of the php package pz/doctrine-rest. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package doctrine-rest

doctrine-rest

Build Status Scrutinizer Code Quality Scrutinizer Code Coverage

Framework agnostic, library provides basic tools for implementation of JSON API over Doctrine library

Using by default symfony/http-foundation for requests/responses and league/fractal for Rest response build.

Install

Add composer package to your project

composer require pz/doctrine-rest

Usage

Package provides different actions for data manipulation and formatting.

Create entity and fractal trasformer for the entity.

// Entity class to work with
$entityClass = 'User';
$entityTransformer = new EntityTransformer();

If you want to use JSON API please implement JsonApiResource on your doctrine entity and add next header to request:

Accept: application/vnd.api+json

Change entity repository to RestRepository or create new one.

// Provide configured entity manager
$entityManager = getEntityManager()

// Repository that action will work with
$restRepository = new RestRepository($entityManager, $entityManager->getClassMetadata($entityClass));

Prepare RestRequest entity or implement RestRequestContract on your custom RestRequest implementation.

// Get http request from framework or init yourself
$httpRequest = Symfony\Component\HttpFoundation\Request::createFromGlobals();
$restRequest = new RestRequest($httpRequest);

Collection (Index) action

Route request GET http://localhost/api/{resourceKey}

$action = new CollectionAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

Regular response

{
    'data': [
        { ...transformer data },
        { ...transformer data },
        { ...transformer data },
    ],
    'meta': [
        'pagination': { ... paginator data },
    ]
}

Json api response

{
    'data': [
        {
            'id': {entityId},
            'type': {etntityResourceKey},
            'attributes': { ...transformer data },
            'relationships': { ..transformer includes },
            'links': {
                'self': 'http://localhost/api/resourceKey/{entityId}
            }
        },
        ... Other entities
    ],
    'meta': [
        'pagination': { ... paginator data },
    ]
}

Item (Get) action

Route request GET http://localhost/api/{resourceKey}/{id}.

$action = new ItemAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

Regular response

{
    'data': [
        'id': {id},
         { ...transformer data }
    ],
}

Json api response

{
    'data': {
        'id': {entityId},
        'type': {etntityResourceKey},
        'attributes': { ...transformer data },
        'relationships': { ..transformer includes },
        'links': {
            'self': 'http://localhost/api/resourceKey/{entityId}
        }
    },
}

Create action

Route request POST http://localhost/api/{resourceKey}.

$action = new CreateAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

Regular response

{
    'data': [
        'id': {id},
         { ...transformer data }
    ],
}

Json api response

{
    'data': {
        'id': {entityId},
        'type': {etntityResourceKey},
        'attributes': { ...transformer data },
        'relationships': { ..transformer includes },
        'links': {
            'self': 'http://localhost/api/resourceKey/{entityId}
        }
    },
}

Update action

Route request PATCH http://localhost/api/{resourceKey}/{id}.

$action = new UpdateAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

Regular response

{
    'data': [
        'id': {id},
         { ...transformer data }
    ],
}

Json api response

{
    'data': {
        'id': {entityId},
        'type': {etntityResourceKey},
        'attributes': { ...transformer data },
        'relationships': { ..transformer includes },
        'links': {
            'self': 'http://localhost/api/resourceKey/{entityId}
        }
    },
}

Delete action

Route request DELETE http://localhost/api/{resourceKey}/{id}.

$action = new DeleteAction($restRepository, $entityTransformer);

/** @var RestResponse|Symfony\Component\HttpFoundation\Response */
$response = $action->dispatch($restRequest);

Response

HTTP STATUS 204 NO CONTENT

Development

Generate doctrine migration diff

We using doctrine migrations for unit tests database schema.

Run tests


All versions of doctrine-rest with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-json Version *
doctrine/orm Version ^2.14
doctrine/annotations Version ^2.0
league/fractal Version ^0.20
symfony/http-foundation Version ^6.0
symfony/validator Version ^5.0
pmill/doctrine-array-hydrator Version ^0.1.2
symfony/cache Version ^6.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package pz/doctrine-rest contains the following files

Loading the files please wait ....