-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSplFixedArrayVoter.php
More file actions
41 lines (36 loc) · 895 Bytes
/
Copy pathSplFixedArrayVoter.php
File metadata and controls
41 lines (36 loc) · 895 Bytes
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
<?php
namespace DesignPatterns\Behavioral\TemplateMethod;
/**
* Voter to check if the methods of @see \SplFixedArray could be called.
*
* It corresponds to `ConcreteClass` in the Strategy pattern.
*
* @author Vlad Riabchenko <contact@vria.eu>
*/
class SplFixedArrayVoter extends AbstractVoter
{
/**
* @inheritdoc
*/
protected function supportsObject($object)
{
return $object instanceof \SplFixedArray;
}
/**
* @inheritdoc
*/
protected function supportsAttribute($attribute)
{
// Other methods could be added
return $attribute === 'toArray';
}
/**
* @inheritdoc
*/
protected function hasAccess($object, $attribute)
{
/** @var $object \SplFixedArray */
// Let call `toArray` method only if the fixed array object is not empty
return $object->count() > 0;
}
}