/
access_entity.php
47 lines (39 loc) · 1.08 KB
/
access_entity.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Concrete\Controller\Permissions\Access\Entity;
use Concrete\Core\Controller\Controller;
use Concrete\Core\Permission\Access\Entity\Entity;
use Concrete\Core\Validation\CSRF\Token;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
abstract class AccessEntity extends Controller
{
/**
* @var Token
*/
protected $token;
/**
* @var Request
*/
protected $request;
public function __construct(Token $token)
{
$this->request = Request::createFromGlobals();
$this->token = $token;
}
/**
* @return Entity|null
*/
abstract public function deliverEntity();
public function getOrCreate()
{
$response = [];
if ($this->token->validate('get_or_create')) {
$entity = $this->deliverEntity();
if ($entity) {
$response['peID'] = $entity->getAccessEntityID();
$response['label'] = $entity->getAccessEntityLabel();
}
}
return new JsonResponse($response);
}
}