This repository has been archived by the owner on Feb 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCallbackProcessor.php
78 lines (72 loc) · 1.78 KB
/
CallbackProcessor.php
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
namespace Box\Component\Processor;
/**
* Uses callbacks to check for support and process file contents.
*
* @author Kevin Herrera <[email protected]>
*/
class CallbackProcessor extends AbstractProcessor
{
/**
* The processing callback.
*
* @var callable
*/
private $processor;
/**
* The support callback.
*
* @var callable
*/
private $support;
/**
* Sets the processing and support callbacks.
*
* @param callable $support The support callback.
* @param callable $processor The processing callback.
*/
public function __construct(callable $support, callable $processor)
{
$this->processor = $processor;
$this->support = $support;
}
/**
* Invokes the support call back and returns the result.
*
* The following is an example of a support callback:
*
* ```php
* function ($file) {
* // ... check for support ...
* }
* ```
*
* @param string $file The path to the file.
*
* @return boolean Returns `true` if supported, `false` if not.
*/
public function supports($file)
{
return call_user_func($this->support, $file);
}
/**
* Invokes the processing callback and returns the result.
*
* The following is an example of a processing callback.
*
* ```php
* function ($file, $contents) {
* // ... process contents ...
* }
* ```
*
* @param string $file The path to the file.
* @param string $contents The contents of the file.
*
* @return string The processed contents of the file.
*/
protected function doProcessing($file, $contents)
{
return call_user_func($this->processor, $file, $contents);
}
}