Code Coverage  | 
      ||||||||||
Lines  | 
       Functions and Methods  | 
       Classes and Traits  | 
      ||||||||
| Total |         | 
       0.00%  | 
       0 / 13  | 
               | 
       0.00%  | 
       0 / 3  | 
       CRAP |         | 
       0.00%  | 
       0 / 1  | 
      
| ExceptionInterpreter |         | 
       0.00%  | 
       0 / 13  | 
               | 
       0.00%  | 
       0 / 3  | 
       20 |         | 
       0.00%  | 
       0 / 1  | 
      
| setException |         | 
       0.00%  | 
       0 / 2  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| getResponse |         | 
       0.00%  | 
       0 / 5  | 
               | 
       0.00%  | 
       0 / 1  | 
       2 | |||
| log |         | 
       0.00%  | 
       0 / 6  | 
               | 
       0.00%  | 
       0 / 1  | 
       6 | |||
| 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) 2017 (original work) Open Assessment Technologies SA | 
| 19 | * | 
| 20 | */ | 
| 21 | |
| 22 | namespace oat\taoLti\models\classes; | 
| 23 | |
| 24 | use oat\oatbox\filesystem\FileSystem; | 
| 25 | use oat\oatbox\filesystem\FileSystemService; | 
| 26 | use oat\tao\model\mvc\error\ExceptionInterpretor; | 
| 27 | use oat\tao\model\mvc\error\ResponseInterface; | 
| 28 | |
| 29 | /** | 
| 30 | * Class ExceptionInterpreter | 
| 31 | * @package oat\taoLti\models\classes | 
| 32 | * @author Aleh Hutnikau, <hutnikau@1pt.com> | 
| 33 | */ | 
| 34 | class ExceptionInterpreter extends ExceptionInterpretor | 
| 35 | { | 
| 36 | public const FILESYSTEM_ID_TO_LOG = 'log'; | 
| 37 | |
| 38 | /** | 
| 39 | * @var LtiException | 
| 40 | */ | 
| 41 | protected $exception; | 
| 42 | |
| 43 | /** | 
| 44 | * set exception to interpet | 
| 45 | * @param \Exception $exception | 
| 46 | * @return ExceptionInterpretor | 
| 47 | */ | 
| 48 | public function setException(\Exception $exception) | 
| 49 | { | 
| 50 | parent::setException($exception); | 
| 51 | return $this; | 
| 52 | } | 
| 53 | |
| 54 | /** | 
| 55 | * return an instance of ResponseInterface | 
| 56 | * @return ResponseInterface | 
| 57 | */ | 
| 58 | public function getResponse() | 
| 59 | { | 
| 60 | $this->log((string) $this->exception); | 
| 61 | |
| 62 | $response = new LtiReturnResponse(new \Renderer()); | 
| 63 | $response->setServiceLocator($this->getServiceLocator()); | 
| 64 | $response->setException($this->exception); | 
| 65 | |
| 66 | return $response; | 
| 67 | } | 
| 68 | |
| 69 | private function log($msg) | 
| 70 | { | 
| 71 | if (!$this->exception instanceof LtiException) { | 
| 72 | return; | 
| 73 | } | 
| 74 | |
| 75 | /** @var FileSystem $fs */ | 
| 76 | $fs = $this->getServiceLocator() | 
| 77 | ->get(FileSystemService::SERVICE_ID) | 
| 78 | ->getFileSystem(self::FILESYSTEM_ID_TO_LOG); | 
| 79 | |
| 80 | $fs->write('lti_' . $this->exception->getKey() . '.log', $msg); | 
| 81 | } | 
| 82 | } |