-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollection.php
More file actions
29 lines (26 loc) · 771 Bytes
/
Collection.php
File metadata and controls
29 lines (26 loc) · 771 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
<?php namespace Devtools;
use Exception;
abstract class Collection
{
protected function processEach(
$objects, $callback, $requiredInstance = null
) {
foreach ($objects as $key => $object) {
$this->validateObject($object, $requiredInstance, $key);
if (!is_numeric($key)) {
$object = array($key => $object);
}
call_user_func(array($this, $callback), $object);
}
}
private function validateObject($object, $requiredInstance)
{
if (!is_null($requiredInstance)
&& !is_subclass_of($object, $requiredInstance)
) {
throw new Exception(
'Invalid observer: ' . get_class($object)
);
}
}
}