1: <?php
2:
3: /*
4: * The MIT License
5: *
6: * Copyright 2014 Damien Doussaud (namide.com).
7: *
8: * Permission is hereby granted, free of charge, to any person obtaining a copy
9: * of this software and associated documentation files (the "Software"), to deal
10: * in the Software without restriction, including without limitation the rights
11: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12: * copies of the Software, and to permit persons to whom the Software is
13: * furnished to do so, subject to the following conditions:
14: *
15: * The above copyright notice and this permission notice shall be included in
16: * all copies or substantial portions of the Software.
17: *
18: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24: * THE SOFTWARE.
25: */
26:
27: namespace Flea;
28:
29: /**
30: * Datas used to the return of a function.
31: * With this object you can detect errors and you can list their informations.
32: *
33: * @author namide.com
34: */
35: class ValueObject {
36:
37: /**
38: * If true, an error has occurred.
39: * Check the error list to find your error.
40: *
41: * @var bool If false, check the return in the propertie content
42: */
43: public $error = false;
44:
45: /**
46: * All the errors who have occurred.
47: *
48: * @var array List of the errors
49: */
50: public $errorList;
51:
52: /**
53: * Return of the method.
54: *
55: * @var type Before recover this one, check the errors
56: */
57: public $content;
58:
59: /**
60: * Construct the reponse of a function with this object.
61: *
62: * @param type $content Return of the function
63: * @param type $error True if an error has occurred
64: */
65: public function __construct($content, $error = false, $errorList = null) {
66: $this->error = $error;
67: $this->content = $content;
68: if ($errorList !== null) {
69: $this->errorList = $errorList;
70: } else {
71: $this->errorList = array();
72: }
73: }
74:
75: }
76: