Skip to content

Commit

Permalink
Use PSR-7 request interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
nohponex committed Jun 7, 2016
1 parent 2d9759d commit f9806aa
Show file tree
Hide file tree
Showing 28 changed files with 676 additions and 330 deletions.
6 changes: 4 additions & 2 deletions composer.json
Expand Up @@ -14,14 +14,16 @@
"require": {
"php": ">=7",
"phramework/phramework": "dev-dev-2.x",
"ext-json": "*"
"ext-json": "*",
"psr/http-message": "^1.0"
},
"require-dev": {
"squizlabs/php_codesniffer": "*",
"phpunit/phpunit": "5.*",
"phpdocumentor/phpdocumentor": "2.9",
"satooshi/php-coveralls": "dev-master",
"codacy/coverage": "^1.0"
"codacy/coverage": "^1.0",
"zendframework/zend-diactoros": "^1.3"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
15 changes: 8 additions & 7 deletions src/Controller/Controller.php
Expand Up @@ -20,6 +20,7 @@
use Phramework\JSONAPI\InternalModel;
use Phramework\JSONAPI\RelationshipResource;
use Phramework\JSONAPI\Resource;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand All @@ -46,7 +47,7 @@ protected static function getById(
}

protected static function includeRelationshipResources(
\stdClass $request,
ServerRequestInterface $request,
InternalModel $model,
array $resources,
Directive ...$directives
Expand Down Expand Up @@ -129,7 +130,7 @@ public static function viewData(

return true;
}

/**
* @param string[] $classes
* @param Directive[] $directives
Expand All @@ -155,7 +156,7 @@ public static function getByClasses(
/**
* @param string[] $classes
* @param InternalModel $model
* @param \stdClass $request
* @param ServerRequestInterface $request
* @param Directive[] $directives
* @param bool $ignoreIfExists
* @param bool $overwrite
Expand All @@ -164,7 +165,7 @@ public static function getByClasses(
public static function parseDirectives(
array $classes,
InternalModel $model,
\stdClass $request,
ServerRequestInterface $request,
array $directives,
bool $ignoreIfExists = true,
bool $overwrite = false
Expand Down Expand Up @@ -193,9 +194,9 @@ function ($d) {
$overwrite
&& (
$key = array_search(
$directiveClass,
$existClasses,
true
$directiveClass,
$existClasses,
true
) !== false)
) {
$directives[$key] = $parsed;
Expand Down
62 changes: 62 additions & 0 deletions src/Controller/Delete.php
@@ -0,0 +1,62 @@
<?php
/**
* Copyright 2015-2016 Xenofon Spafaridis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Phramework\JSONAPI\Controller;

use Phramework\JSONAPI\Controller\Helper\RequestBodyQueue;
use Phramework\JSONAPI\Directive\Directive;
use Phramework\JSONAPI\InternalModel;
use Phramework\Phramework;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
* @author Xenofon Spafaridis <nohponex@gmail.com>
* @since 3.0.0
*/
trait Delete
{
use Controller;
use RequestBodyQueue;

//prototype
public static function handleDelete(
ServerRequestInterface $request,
InternalModel $model,
string $id,
array $validationCallbacks = [],
callable $viewCallback = null,
int $bulkLimit = null,
array $directives
) {
//gather data as a queue

//check bulk limit

//on each validate

//prefer PATCH validation model
$validationModel = $model->getValidationModel(
'DELETE'
);

//check if exists

//on each call validation callback

//204 or view callback
}
}
3 changes: 2 additions & 1 deletion src/Controller/Get.php
Expand Up @@ -23,6 +23,7 @@
use Phramework\JSONAPI\Directive\Page;
use Phramework\JSONAPI\Directive\Sort;
use Phramework\JSONAPI\InternalModel;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand All @@ -34,7 +35,7 @@ trait Get
use Controller;

public static function handleGet(
\stdClass $request,
ServerRequestInterface $request,
InternalModel $model,
array $directives
) {
Expand Down
9 changes: 5 additions & 4 deletions src/Controller/GetById.php
Expand Up @@ -23,6 +23,7 @@
use Phramework\JSONAPI\Directive\Filter;
use Phramework\JSONAPI\Directive\Directive;
use Phramework\JSONAPI\InternalModel;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand All @@ -34,14 +35,14 @@ trait GetById
use Controller;

/**
* @param \stdClass $request
* @param string $id
* @param InternalModel $model
* @param ServerRequestInterface $request
* @param string $id
* @param InternalModel $model
* @param Directive[] $directives
* @throws \Phramework\Exceptions\NotFoundException
*/
public static function handleGetById(
\stdClass $request,
ServerRequestInterface $request,
string $id,
InternalModel $model,
array $directives
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Patch.php
Expand Up @@ -20,6 +20,7 @@
use Phramework\JSONAPI\Directive\Directive;
use Phramework\JSONAPI\InternalModel;
use Phramework\Phramework;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand All @@ -33,7 +34,7 @@ trait Patch

//prototype
public static function handlePatch(
\stdClass $request,
ServerRequestInterface $request,
InternalModel $model,
string $id,
array $validationCallbacks = [],
Expand All @@ -49,7 +50,7 @@ public static function handlePatch(

//prefer PATCH validation model
$validationModel = $model->getValidationModel(
Phramework::METHOD_PATCH
'PATCH'
);

//check if exists
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/Post.php
Expand Up @@ -20,6 +20,7 @@
use Phramework\JSONAPI\Directive\Directive;
use Phramework\JSONAPI\InternalModel;
use Phramework\Phramework;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand All @@ -33,7 +34,7 @@ trait Post

//prototype
public static function handlePost(
\stdClass $request,
ServerRequestInterface $request,
InternalModel $model,
array $validationCallbacks = [],
callable $viewCallback = null,
Expand All @@ -48,7 +49,7 @@ public static function handlePost(

//prefer POST validation model
$validationModel = $model->getValidationModel(
Phramework::METHOD_POST
'POST'
);

//on each call validation callback
Expand Down
62 changes: 62 additions & 0 deletions src/Controller/Put.php
@@ -0,0 +1,62 @@
<?php
/**
* Copyright 2015-2016 Xenofon Spafaridis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Phramework\JSONAPI\Controller;

use Phramework\JSONAPI\Controller\Helper\RequestBodyQueue;
use Phramework\JSONAPI\Directive\Directive;
use Phramework\JSONAPI\InternalModel;
use Phramework\Phramework;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
* @author Xenofon Spafaridis <nohponex@gmail.com>
* @since 3.0.0
*/
trait Put
{
use Controller;
use RequestBodyQueue;

//prototype
public static function handlePut(
ServerRequestInterface $request,
InternalModel $model,
string $id,
array $validationCallbacks = [],
callable $viewCallback = null,
int $bulkLimit = null,
array $directives
) {
//gather data as a queue

//check bulk limit

//on each validate

//prefer PATCH validation model
$validationModel = $model->getValidationModel(
Phramework::METHOD_PUT
);

//check if exists

//on each call validation callback

//204 or view callback
}
}
27 changes: 27 additions & 0 deletions src/Controller/Relationship.php
@@ -0,0 +1,27 @@
<?php
/**
* Copyright 2015-2016 Xenofon Spafaridis
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace Phramework\JSONAPI\Controller;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
* @author Xenofon Spafaridis <nohponex@gmail.com>
* @since 3.0.0
*/
trait Relationship
{

}
3 changes: 2 additions & 1 deletion src/Directive/AdditionalParameter.php
Expand Up @@ -17,6 +17,7 @@
namespace Phramework\JSONAPI\Directive;

use Phramework\JSONAPI\InternalModel;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand Down Expand Up @@ -64,7 +65,7 @@ public function validate(InternalModel $model) : bool
}

public static function parseFromRequest(
\stdClass $request,
ServerRequestInterface $request,
InternalModel $model
) {
return null;
Expand Down
3 changes: 2 additions & 1 deletion src/Directive/AdditionalRelationshipsParameter.php
Expand Up @@ -17,6 +17,7 @@
namespace Phramework\JSONAPI\Directive;

use Phramework\JSONAPI\InternalModel;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand Down Expand Up @@ -81,7 +82,7 @@ public function validate(InternalModel $model) : bool
* @inheritDoc
*/
public static function parseFromRequest(
\stdClass $request,
ServerRequestInterface $request,
InternalModel $model
) {
return null;
Expand Down
9 changes: 5 additions & 4 deletions src/Directive/Directive.php
Expand Up @@ -17,6 +17,7 @@
namespace Phramework\JSONAPI\Directive;

use Phramework\JSONAPI\InternalModel;
use Psr\Http\Message\ServerRequestInterface;

/**
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0
Expand All @@ -29,12 +30,12 @@ abstract public function validate(InternalModel $model) : bool;

/**
* @todo define request object in phramework
* @param \stdClass $request
* @param InternalModel $model
* @return Directive|null
* @param ServerRequestInterface $request
* @param InternalModel $model
* @return null|Directive
*/
abstract public static function parseFromRequest(
\stdClass $request,
ServerRequestInterface $request,
InternalModel $model
);

Expand Down

0 comments on commit f9806aa

Please sign in to comment.