-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from markhuot/scopes
Adds token scopes
- Loading branch information
Showing
45 changed files
with
1,107 additions
and
449 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
|
||
namespace markhuot\CraftQL\Factories; | ||
|
||
use GraphQL\Type\Definition\EnumType; | ||
|
||
abstract class BaseFactory { | ||
|
||
protected $repository; | ||
protected $request; | ||
private $objects = []; | ||
private $enum; | ||
|
||
function __construct($repository, $request) { | ||
$this->repository = $repository; | ||
$this->request = $request; | ||
} | ||
|
||
// function repository() { | ||
// return $this->repository; | ||
// } | ||
|
||
function get($id, $mode='query') { | ||
if ($this->can($id, $mode) === false) { | ||
return false; | ||
} | ||
|
||
if (isset($this->objects[$id])) { | ||
return $this->objects[$id]; | ||
} | ||
|
||
return $this->objects[$id] = $this->make($this->repository->get($id), $this->request); | ||
} | ||
|
||
abstract function can($id, $mode='query'); | ||
abstract function make($raw, $request); | ||
|
||
function all($mode='query') { | ||
$objects = []; | ||
|
||
foreach ($this->repository->all() as $raw) { | ||
if ($object = $this->get($raw->id, $mode)) { | ||
$objects[] = $object; | ||
} | ||
} | ||
|
||
return $objects; | ||
} | ||
|
||
function enumValueName($object) { | ||
return $object->name; | ||
} | ||
|
||
function enum() { | ||
if (!empty($this->enum)) { | ||
return $this->enum; | ||
} | ||
|
||
$values = []; | ||
|
||
foreach ($this->all() as $index => $object) { | ||
$values[$this->enumValueName($object)] = @$object->config['id']; | ||
} | ||
|
||
$reflect = new \ReflectionClass($this); | ||
return $this->enum = new EnumType([ | ||
'name' => $reflect->getShortName().'sEnum', | ||
'values' => $values, | ||
]); | ||
} | ||
|
||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace markhuot\CraftQL\Factories; | ||
|
||
use markhuot\CraftQL\Factories\BaseFactory; | ||
use markhuot\CraftQL\Types\CategoryGroup as CategoryGroupObjectType; | ||
|
||
class CategoryGroup extends BaseFactory { | ||
|
||
function make($raw, $request) { | ||
return new CategoryGroupObjectType($raw, $request); | ||
} | ||
|
||
function can($id, $mode='query') { | ||
return true; | ||
} | ||
|
||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace markhuot\CraftQL\Factories; | ||
|
||
use markhuot\CraftQL\Factories\BaseFactory; | ||
use markhuot\CraftQL\Types\EntryType as EntryTypeObjectType; | ||
|
||
class EntryType extends BaseFactory { | ||
|
||
function make($raw, $request) { | ||
return new EntryTypeObjectType($raw, $request); | ||
} | ||
|
||
function can($id, $mode='query') { | ||
return $this->request->token()->can("{$mode}:entryType:{$id}"); | ||
} | ||
|
||
} |
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,29 @@ | ||
<?php | ||
|
||
namespace markhuot\CraftQL\Factories; | ||
|
||
use markhuot\CraftQL\Factories\BaseFactory; | ||
use markhuot\CraftQL\Types\Section as SectionObjectType; | ||
|
||
class Section extends BaseFactory { | ||
|
||
function make($raw, $request) { | ||
return new SectionObjectType($raw, $request); | ||
} | ||
|
||
function can($id, $mode='query') { | ||
$section = $this->repository->get($id); | ||
foreach ($section->entryTypes as $type) { | ||
if ($this->request->token()->canNot("{$mode}:entryType:{$type->id}")) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
function enumValueName($object) { | ||
return preg_replace('/Section$/', '', $object->name); | ||
} | ||
|
||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace markhuot\CraftQL\Factories; | ||
|
||
use markhuot\CraftQL\Factories\BaseFactory; | ||
use markhuot\CraftQL\Types\Volume as VolumeObjectType; | ||
|
||
class Volume extends BaseFactory { | ||
|
||
function make($raw, $request) { | ||
return new VolumeObjectType($raw, $request); | ||
} | ||
|
||
function can($id, $mode='query') { | ||
return true; | ||
} | ||
|
||
} |
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
Oops, something went wrong.