Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 1 |
| tao_install_services_Service | |
0.00% |
0 / 11 |
|
0.00% |
0 / 9 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setStatus | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getResult | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setResult | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getRequestMethod | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| execute | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| checkData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * Represents a generic service providing programming conveniences |
| 29 | * to write basic REST webservices for the TAO Installer. |
| 30 | * |
| 31 | * @access public |
| 32 | * @author Jerome Bogaerts, <jerome@taotesting.com> |
| 33 | * @package tao |
| 34 | |
| 35 | */ |
| 36 | abstract class tao_install_services_Service |
| 37 | { |
| 38 | /* |
| 39 | * The HTTP Status returned by the Service. |
| 40 | */ |
| 41 | private $status; |
| 42 | |
| 43 | /** |
| 44 | * The result returned by the Service. It must be an instance |
| 45 | * of tao_install_Services_Data. |
| 46 | */ |
| 47 | private $result = null; |
| 48 | |
| 49 | /** |
| 50 | * The request Data handled by the Service. It must be an instance |
| 51 | * of tao_install_services_Data. |
| 52 | */ |
| 53 | private $data = null; |
| 54 | |
| 55 | /** |
| 56 | * Creates a new instance of tao_install_Services_Service with |
| 57 | * its associated request Data. |
| 58 | * |
| 59 | * @param tao_install_services_Data $data The request Data. |
| 60 | */ |
| 61 | public function __construct(tao_install_services_Data $data) |
| 62 | { |
| 63 | // By default, status is OK. |
| 64 | $this->setStatus(200); |
| 65 | $this->setData($data); |
| 66 | $this->checkData(); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Gets the current HTTP status for the current request handled by the Service. |
| 71 | * @return int An HTTP code. |
| 72 | */ |
| 73 | public function getStatus() |
| 74 | { |
| 75 | return $this->status; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Sets the current HTTP status for the current request handled by the Service. |
| 80 | * @param int $status An HTTP Code. |
| 81 | * @return void |
| 82 | */ |
| 83 | protected function setStatus($status) |
| 84 | { |
| 85 | $this->status = $status; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Gets the request Data handled by the Service. |
| 90 | * @return tao_install_services_Data The Data handled by the Service. |
| 91 | */ |
| 92 | protected function getData() |
| 93 | { |
| 94 | return $this->data; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Sets the request Data handled by the Service. |
| 99 | * @param tao_install_Services_Data $data The request Data that must be handled by the service. |
| 100 | * @return void |
| 101 | */ |
| 102 | protected function setData(tao_install_services_Data $data) |
| 103 | { |
| 104 | $this->data = $data; |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Gets the request result that has to be returned by the Service. |
| 109 | * @return tao_install_Services_Data A request result. |
| 110 | */ |
| 111 | public function getResult() |
| 112 | { |
| 113 | return $this->result; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Sets the request result that has to be returned by the Service. |
| 118 | * @param tao_install_services_Data $data The Data that represents the Service result. |
| 119 | * @return void |
| 120 | */ |
| 121 | protected function setResult(tao_install_services_Data $result) |
| 122 | { |
| 123 | $this->result = $result; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Provides the current request method (get,post,put,delete) in lowercase. |
| 128 | * @return string the current request method. |
| 129 | */ |
| 130 | protected static function getRequestMethod() |
| 131 | { |
| 132 | return strtolower($_SERVER['REQUEST_METHOD']); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Contains the business logic of the Service. Any implementation of tao_install_Services_Service |
| 137 | * must implement this method and should take care of setting the tao_install_Services_Service::result |
| 138 | * in their implementation. |
| 139 | * @return tao_install_services_Data The resulting Data. |
| 140 | */ |
| 141 | abstract public function execute(); |
| 142 | |
| 143 | /** |
| 144 | * Contains the logic of checking the input data for a given service implementation. |
| 145 | */ |
| 146 | protected function checkData() |
| 147 | { |
| 148 | return; |
| 149 | } |
| 150 | } |