|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @filesource |
|
4
|
|
|
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de) |
|
5
|
|
|
* @license MIT |
|
6
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
7
|
|
|
* @since 0.27 |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace Auth\Dependency; |
|
10
|
|
|
|
|
11
|
|
|
use Zend\EventManager\EventManagerAwareTrait; |
|
12
|
|
|
use Zend\EventManager\EventInterface; |
|
13
|
|
|
use Auth\Entity\UserInterface as User; |
|
14
|
|
|
use Zend\Mvc\Router\RouteInterface as Router; |
|
15
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* |
|
19
|
|
|
* @author Miroslav Fedeleš <[email protected]> |
|
20
|
|
|
* @author Mathias Gelhausen <[email protected]> |
|
21
|
|
|
* @since 0.27 |
|
22
|
|
|
*/ |
|
23
|
|
|
class Manager |
|
24
|
|
|
{ |
|
25
|
|
|
use EventManagerAwareTrait; |
|
26
|
|
|
|
|
27
|
|
|
const EVENT_GET_LISTS = 'getLists'; |
|
28
|
|
|
const EVENT_REMOVE_ITEMS = 'removeItems'; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var DocumentManager |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $documentManager; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param DocumentManager $documentManager |
|
37
|
|
|
*/ |
|
38
|
|
|
public function __construct(DocumentManager $documentManager) |
|
39
|
|
|
{ |
|
40
|
|
|
$this->documentManager = $documentManager; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param User $user |
|
|
|
|
|
|
45
|
|
|
* @param Router $router |
|
|
|
|
|
|
46
|
|
|
* @return ListInterface[] |
|
|
|
|
|
|
47
|
|
|
*/ |
|
48
|
|
|
public function getLists() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->getEventManager()->trigger(static::EVENT_GET_LISTS, $this); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @param User $user |
|
55
|
|
|
* @param Router $router |
|
|
|
|
|
|
56
|
|
|
* @return \Zend\EventManager\ResponseCollection |
|
|
|
|
|
|
57
|
|
|
*/ |
|
58
|
|
|
public function removeItems(User $user) |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
|
|
try { |
|
61
|
|
|
$this->getEventManager()->trigger(static::EVENT_REMOVE_ITEMS, $this, compact('user')); |
|
62
|
|
|
$this->documentManager->flush(); |
|
63
|
|
|
return true; |
|
64
|
|
|
} catch (\Exception $e) { |
|
65
|
|
|
$this->documentManager->clear(); |
|
66
|
|
|
return false; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
protected function attachDefaultListeners() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->getEventManager()->attach(static::EVENT_REMOVE_ITEMS, function (EventInterface $event) { |
|
73
|
|
|
$user = $event->getParam('user'); |
|
74
|
|
|
foreach ($this->getLists() as $list) { |
|
75
|
|
|
foreach ($list->getEntities($user) as $entity) { |
|
76
|
|
|
$this->documentManager->remove($entity); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
}); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.