Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use callable to return the ResourceModel instead of using resource model as argument at Relationship constructor Fixes #45
- Loading branch information
Showing
11 changed files
with
320 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/* | ||
* 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\APP\Models; | ||
|
||
use Phramework\JSONAPI\APP\DataSource\MemoryDataSource; | ||
use Phramework\JSONAPI\Directive\Directive; | ||
use Phramework\JSONAPI\Relationship; | ||
use Phramework\JSONAPI\ResourceModel; | ||
use Phramework\JSONAPI\Model; | ||
use Phramework\JSONAPI\ModelTrait; | ||
|
||
/** | ||
* @since 3.0.0 | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 | ||
* @author Xenofon Spafaridis <nohponex@gmail.com> | ||
*/ | ||
class A extends Model | ||
{ | ||
use ModelTrait; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected static function defineModel() : ResourceModel | ||
{ | ||
$model = (new ResourceModel('A', new MemoryDataSource())) | ||
->addVariable('table', 'user') | ||
->setRelationships((object) [ | ||
'A' => new Relationship( | ||
function () | ||
{ | ||
return A::getResourceModel(); | ||
}, | ||
Relationship::TYPE_TO_ONE, | ||
'referrer-user_id' | ||
) | ||
]); | ||
|
||
return $model; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
declare(strict_types=1); | ||
/* | ||
* 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\APP\Models; | ||
|
||
use Phramework\JSONAPI\APP\DataSource\MemoryDataSource; | ||
use Phramework\JSONAPI\Model; | ||
use Phramework\JSONAPI\ModelTrait; | ||
use Phramework\JSONAPI\Relationship; | ||
use Phramework\JSONAPI\ResourceModel; | ||
|
||
/** | ||
* @since 3.0.0 | ||
* @license https://www.apache.org/licenses/LICENSE-2.0 Apache-2.0 | ||
* @author Xenofon Spafaridis <nohponex@gmail.com> | ||
*/ | ||
class Article extends Model | ||
{ | ||
use ModelTrait; | ||
|
||
protected static function defineModel() : ResourceModel | ||
{ | ||
return (new ResourceModel('article', new MemoryDataSource())) | ||
->addVariable('table', 'article') | ||
->setRelationships( | ||
(object) [ | ||
'author' => new Relationship( | ||
function () { | ||
return User::getResourceModel(); | ||
}, | ||
Relationship::TYPE_TO_ONE, | ||
'creator-user_id' | ||
), | ||
'tag' => new Relationship( | ||
function () { | ||
return Tag::getResourceModel(); | ||
}, | ||
Relationship::TYPE_TO_MANY, | ||
null,//'tag_id' | ||
(object) [ | ||
/** | ||
* @param string $articleId | ||
* @return string[] | ||
*/ | ||
'GET' => function (string $articleId) { | ||
$ids = []; | ||
return $ids; | ||
} | ||
] | ||
) | ||
] | ||
); | ||
} | ||
} | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.