Methods

Source

LineCode
1
<?php
2
3
namespace AuthStack\UserDirectory\Service;
4
5
use AuthStack\UserDirectory\Exceptions\PolicyException;
6
use AuthStack\UserDirectory\Model\Policy as PolicyModel;
7
8
class Policy extends RESTService
9
{
10
    /**
11
     * @param array $data
12
     * @return mixed
13
     */
14
    public function create(array $data)
15
    {
16
        return $this->remote(function() use (&$data): PolicyModel
17
        {
18
            return new PolicyModel($this->json('create', $data));
19
20
        }, PolicyException::class);
21
    }
22
23
    /**
24
     * @param int $id
25
     * @return PolicyModel
26
     */
27
    public function read(int $id): PolicyModel
28
    {
29
        return $this->remote(function() use ($id)
30
        {
31
            return new PolicyModel($this->json('read', [], [$id]));
32
33
        }, PolicyException::class);
34
    }
35
36
    /**
37
     * @param int $id
38
     * @param array $data
39
     * @return bool
40
     */
41
    public function update(int $id, array $data): bool
42
    {
43
        return $this->remote(function() use ($id, &$data)
44
        {
45
            $result = $this->json('update', $data, [$id]);
46
47
            return $result['result'];
48
49
        }, PolicyException::class);
50
    }
51
52
    /**
53
     * @param int $id
54
     * @return bool
55
     */
56
    public function delete(int $id): bool
57
    {
58
        return $this->remote(function() use ($id)
59
        {
60
            $result = $this->json('delete', [], [$id]);
61
62
            return $result['result'];
63
64
        }, PolicyException::class);
65
    }
66
67
    /**
68
     * @param array $options
69
     * @return array
70
     */
71
    public function listing(array $options = []): array
72
    {
73
        return $this->remote(function() use (&$options)
74
        {
75
            $result = $this->json('listing', [], [], $options);
76
77
            return $result;
78
79
        }, PolicyException::class);
80
    }
81
}