Skip to content

Commit

Permalink
Update from internal 0.10 release
Browse files Browse the repository at this point in the history
  • Loading branch information
alenpokos committed Jul 11, 2018
1 parent 4482c01 commit a20092c
Show file tree
Hide file tree
Showing 160 changed files with 1,008 additions and 528 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
tests/Resources/app/cache/
tests/Resources/app/data/
tests/Resources/app/logs/
docker-compose.override.yml
docker-compose.override.yml
/.php_cs.cache
33 changes: 33 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
variables:
COMPOSE_PROJECT_NAME: "jsonapibundle${CI_BUILD_ID}"

stages:
- test
- lint

after_script:
- cd tests/Resources/docker/
- echo "Fixing permissions after docker..."
- bin/php chmod -R 0777 ../../../*
- docker-compose down
- echo "All Done!"

ci:
stage: test
tags:
- docker-compose
script:
- cd tests/Resources/docker/
- bin/build.sh
- bin/setup_fixtures.sh
- docker-compose run --no-deps --rm php php vendor/bin/phpunit --debug --colors=never --coverage-text=php://stdout --coverage-html=logs/coverage
- bin/php php ../../../vendor/bin/security-checker security:check ../../../composer.lock

lint:
stage: lint
tags:
- docker-compose
script:
- cd tests/Resources/docker/
- bin/build.sh
- bin/php_cs --dry-run --using-cache=no
43 changes: 43 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

use PhpCsFixer\Fixer\Import\OrderedImportsFixer;

$finder = PhpCsFixer\Finder::create()
->name('console')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
])
;

return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@DoctrineAnnotation' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'list_syntax' => ['syntax' => 'short'],
'no_empty_phpdoc' => false,
'phpdoc_align' => '',
'phpdoc_no_empty_return' => false,
'phpdoc_summary' => false,
'ordered_imports' => [
'sortAlgorithm' => OrderedImportsFixer::SORT_ALPHA,
'importsOrder' => [
OrderedImportsFixer::IMPORT_TYPE_CONST,
OrderedImportsFixer::IMPORT_TYPE_FUNCTION,
OrderedImportsFixer::IMPORT_TYPE_CLASS,
],
],
'class_definition' => ['multiLineExtendsEachSingleLine' => true],
'ternary_to_null_coalescing' => true,
'yoda_style' => true,
'compact_nullable_typehint' => true,
'visibility_required' => true,
])
->setRiskyAllowed(true)
->setFinder($finder)
;
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Json Api CRUD Bundle

[![pipeline status](https://gitlab.trikoder.net/trikoder/jsonapibundle/badges/master/pipeline.svg)](https://gitlab.trikoder.net/trikoder/jsonapibundle/commits/master)
[![coverage report](https://gitlab.trikoder.net/trikoder/jsonapibundle/badges/master/coverage.svg)](https://gitlab.trikoder.net/trikoder/jsonapibundle/commits/master)

Package to provide out-of-the box support for jsonapi in symfony with as native as possible way.

# Under development
Expand Down Expand Up @@ -51,9 +54,36 @@ This will build whole docker setup, load fixtures and run all test suites.

For development of the package, we are using the same tools as for testing.
Position yourself inside `tests/Resources/docker` and run `bin/start.sh`
PHP cli commands can be run from same directory using `bin/console`.
PHP cli commands can be run from same directory using `bin/console`.
There is also php access script `bin/php [CMD]` (eg. `bin/php bash` to enter bash).

### Coding standards

When contributing to this package, you will need to adhere to our conding standards.
They are following PSR-2 with some additional rules. To check your code during development
you can use provided config for php-cs-fixer. it's in root of the project, file:

`.php_cs.dist`

**Checking your code**

First you need to setup test enviroment (as described in paragraph above).

Then:

Checking code:

```
bin/php_cs --dry-run
```
If you want automatic fix, just ommit ``--dry-run`:

```
bin/php_cs
```
This will check and fix your code.


## Credits

Copyright (C) 2017 Trikoder
Expand Down
29 changes: 29 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# Upgrade Guide

This file provides notes on how to upgrade between versions.


# Upgrade from v0.9.*

## Bundle changes
- bundle moves to support symfony 4 with default private services and autowiring
- changes in demo code to reflect `controllers as services` change

## Schema autowiring
!NOTE - change described below will be updated in future version with option to have bundle perform this action automatically by scaning your schemas..
To use any non public services in your schemas, you must redefine `Trikoder\JsonApiBundle\Services\Neomerx\ServiceContainer` and call `set` for each of used service, ie:
```yaml
Trikoder\JsonApiBundle\Services\Neomerx\ServiceContainer:
calls:
- method: set
arguments:
- 'Symfony\Component\Routing\RouterInterface'
- '@router'
```
## Service definitions
All services should use Interface hinting names as described by Symfony documentation on autowiring. https://symfony.com/doc/current/service_container/autowiring.html
Bundle defines aliases for old naming to keep compatibility with existing implementations.
This will be removed in later version.
## Abstract controller
1. No longer inherits `Symfony\Bundle\FrameworkBundle\Controller\Controller` but instead moves to be `Controller as Service`.
2. It defines required setter injection for several services listed below. NOTE - this is subject to change in future versions
`setSchemaClassMapProvider` in abstract controller, and usage of trait `\Trikoder\JsonApiBundle\Controller\Traits\Polyfill\SymfonyAutowiredServicesTrait`
39 changes: 22 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@
"description": "Json API bundle for Symfony",
"type": "symfony-bundle",
"require": {
"php": ">=7.0.0",
"symfony/framework-bundle": "^3.1",
"php": ">=7.0.0|>=7.1.0",
"symfony/framework-bundle": "^3.1|^4.0",
"symfony/dependency-injection": "^3.1|^4.0",
"neomerx/json-api": "^1.0",
"doctrine/orm": "~2.4,<2.5|^2.5",
"doctrine/doctrine-bundle": "~1.6",
"sensio/framework-extra-bundle": "^3.0",
"symfony/form": "^3.1",
"symfony/translation": "^3.3",
"symfony/validator": "^3.3",
"doctrine/orm": "~2.4,<2.5|2.5|^2.6",
"doctrine/doctrine-bundle": "~1.6|^1.8",
"sensio/framework-extra-bundle": "^3.0|^5.1",
"symfony/form": "^3.1|^4.0",
"symfony/translation": "^3.3|^4.0",
"symfony/validator": "^3.3|^4.0",
"symfony/monolog-bundle": "^3.1"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"sensio/generator-bundle": "3.0.*|3.1.*|3.2.*|3.3.*",
"phpunit/phpunit": "^5.7",
"phpunit/php-code-coverage": "^4.0",
"symfony/phpunit-bridge": "^3.0",
"symfony/phpunit-bridge": "^3.0|^4.0",
"justinrainbow/json-schema": "^1.6",
"doctrine/doctrine-fixtures-bundle": "^2.3",
"fzaninotto/faker": "^1.5",
"sensiolabs/security-checker": "^4.1",
"symfony/security-bundle": "^3.1",
"symfony/twig-bundle": "^3.3",
"symfony/security-bundle": "^3.1|^4.0",
"symfony/twig-bundle": "^3.3|^4.0",
"doctrine/cache": "^1.6",
"symfony/debug-bundle": "^3.3",
"symfony/web-profiler-bundle": "^3.3",
"symfony/web-server-bundle": "^3.3",
"symfony/browser-kit": "^3.3"
"symfony/debug-bundle": "^3.3|^4.0",
"symfony/web-profiler-bundle": "^3.3|^4.0",
"symfony/web-server-bundle": "^3.3|^4.0",
"symfony/browser-kit": "^3.3|^4.0",
"friendsofphp/php-cs-fixer": "^2.8"
},
"autoload": {
"psr-4": {
Expand All @@ -39,7 +41,10 @@
"autoload-dev": {
"psr-4": {
"Trikoder\\JsonApiBundle\\Tests\\": "tests/"
}
},
"files": [
"tests/Resources/app/AppKernel.php"
]
},
"authors": [
{
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
>
<php>
<server name="KERNEL_DIR" value="tests/Resources/app" />
<server name="KERNEL_CLASS" value="\AppKernel" />
</php>
<testsuites>
<testsuite name="Unit">
Expand Down
9 changes: 5 additions & 4 deletions src/Bridge/Doctrine/DoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/**
* Class DoctrineRepository
* @package Trikoder\JsonApiBundle\Bridge\Doctrine
*/
class DoctrineRepository implements RepositoryInterface
{
Expand All @@ -23,6 +22,7 @@ class DoctrineRepository implements RepositoryInterface

/**
* DoctrineRepository constructor.
*
* @param EntityRepository $entityRepository
* @param EntityManager $entityManager
*/
Expand All @@ -33,7 +33,7 @@ public function __construct(EntityRepository $entityRepository, EntityManager $e
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function getList($filter = [], $sort = [], $limit = null, $offset = null)
{
Expand All @@ -47,17 +47,18 @@ public function getList($filter = [], $sort = [], $limit = null, $offset = null)
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function getOne($id, $filter = [])
{
// TODO - this should check which fields is indentifier
$filter['id'] = $id;

return $this->entityRepository->findOneBy($filter);
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function save($model)
{
Expand Down
1 change: 1 addition & 0 deletions src/Bridge/Doctrine/ObjectListCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ObjectListCollection implements ObjectListCollectionInterface

/**
* ObjectListCollection constructor.
*
* @param array $collection
* @param null $total
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Bridge/Doctrine/RepositoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class RepositoryFactory implements RepositoryFactoryInterface

/**
* RepositoryFactory constructor.
*
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager)
Expand All @@ -24,9 +25,10 @@ public function __construct(EntityManager $entityManager)

/**
* @param string $modelClass
*
* @return RepositoryInterface
*/
public function create(string $modelClass) : RepositoryInterface
public function create(string $modelClass): RepositoryInterface
{
return new DoctrineRepository(
$this->entityManager->getRepository($modelClass),
Expand Down
9 changes: 1 addition & 8 deletions src/Config/Annotation/UpdateConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,8 @@

namespace Trikoder\JsonApiBundle\Config\Annotation;

use Closure;
use Trikoder\JsonApiBundle\Contracts\Config\ApiConfigInterface;
use Doctrine\Common\Annotations\Annotation;
use Doctrine\Common\Annotations\Annotation\Target;
use Trikoder\JsonApiBundle\Contracts\Config\CreateConfigInterface;
use Trikoder\JsonApiBundle\Contracts\Config\IndexConfigInterface;
use Trikoder\JsonApiBundle\Contracts\Config\UpdateConfigInterface;
use Trikoder\JsonApiBundle\Contracts\RepositoryInterface;
use Trikoder\JsonApiBundle\Contracts\RequestBodyDecoderInterface;

/**
* @Annotation
Expand All @@ -27,4 +20,4 @@ class UpdateConfig
* @return array|null
*/
public $requiredRoles;
}
}
7 changes: 2 additions & 5 deletions src/Config/ApiConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
use Trikoder\JsonApiBundle\Contracts\Config\ApiConfigInterface;
use Trikoder\JsonApiBundle\Contracts\RepositoryInterface;
use Trikoder\JsonApiBundle\Contracts\RequestBodyDecoderInterface;
use Trikoder\JsonApiBundle\Repository\RepositoryFactoryInterface;
use Trikoder\JsonApiBundle\Repository\RepositoryResolverInterface;

/**
* Class ApiConfig
* @package Trikoder\JsonApiBundle\Config
*/
class ApiConfig implements ApiConfigInterface
{
Expand Down Expand Up @@ -50,6 +47,7 @@ class ApiConfig implements ApiConfigInterface

/**
* ApiConfig constructor.
*
* @param string $modelClass
* @param $repository
* @param array|null $fixedFiltering
Expand All @@ -65,7 +63,6 @@ public function __construct(
RequestBodyDecoderInterface $requestBodyDecoder,
bool $allowExtraParams
) {

$this->modelClass = $modelClass;
$this->fixedFiltering = $fixedFiltering;
$this->allowedIncludePaths = $allowedIncludePaths;
Expand Down Expand Up @@ -115,7 +112,7 @@ public function getRequestBodyDecoder()
}

/**
* @return boolean
* @return bool
*/
public function getAllowExtraParams()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

/**
* Class Config
* @package Trikoder\JsonApiBundle\Config
*/
final class Config implements ConfigInterface
{
Expand Down Expand Up @@ -42,6 +41,7 @@ final class Config implements ConfigInterface

/**
* Config constructor.
*
* @param ApiConfigInterface $api
* @param CreateConfigInterface $create
* @param IndexConfigInterface $index
Expand Down
Loading

0 comments on commit a20092c

Please sign in to comment.