1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Mvc\Controller\Traits\Actions\Rest; |
13
|
|
|
|
14
|
|
|
use Phalcon\Filter\Exception; |
15
|
|
|
use Phalcon\Http\ResponseInterface; |
16
|
|
|
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractExpose; |
17
|
|
|
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractQuery; |
18
|
|
|
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractInjectable; |
19
|
|
|
use Zemit\Mvc\Controller\Traits\Abstracts\AbstractRestResponse; |
20
|
|
|
|
21
|
|
|
trait FindFirstAction |
22
|
|
|
{ |
23
|
|
|
use AbstractExpose; |
24
|
|
|
use AbstractQuery; |
25
|
|
|
use AbstractInjectable; |
26
|
|
|
use AbstractRestResponse; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Retrieving a single record |
30
|
|
|
* @link findFirstAction() |
31
|
|
|
* @deprecated use {@link findFirstAction()} |
32
|
|
|
* @throws \Exception |
33
|
|
|
*/ |
34
|
|
|
public function getAction(): ResponseInterface |
35
|
|
|
{ |
36
|
|
|
return $this->findFirstAction(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Retrieving a single record |
41
|
|
|
* @link findFirstWithAction() |
42
|
|
|
* @deprecated use {@link findFirstWithAction()} |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
|
|
public function getWithAction(): ResponseInterface |
46
|
|
|
{ |
47
|
|
|
return $this->findFirstWithAction(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Retrieving a single record |
52
|
|
|
* @throws \Exception |
53
|
|
|
*/ |
54
|
|
|
public function findFirstAction(): ResponseInterface |
55
|
|
|
{ |
56
|
|
|
$result = $this->findFirst(); |
57
|
|
|
|
58
|
|
|
if (!$result) { |
59
|
|
|
return $this->setRestErrorResponse(404); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$this->view->setVar('data', $this->expose($result)); |
63
|
|
|
return $this->setRestResponse(true); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Retrieving a single record |
68
|
|
|
* @throws \Exception |
69
|
|
|
*/ |
70
|
|
|
public function findFirstWithAction(): ResponseInterface |
71
|
|
|
{ |
72
|
|
|
$result = $this->findFirstWith(); |
73
|
|
|
|
74
|
|
|
if (!$result) { |
75
|
|
|
return $this->setRestErrorResponse(404); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$this->view->setVar('data', $this->expose($result)); |
79
|
|
|
return $this->setRestResponse(true); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|