Commit ec41ba31 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

AJout d'exceptions.

parent 7d850f41
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -2,11 +2,12 @@

namespace UnicaenLeocarte\Controller;

use UnicaenLeocarte\Exception\ExtensionNotLoadedException;
use UnicaenLeocarte\Exception\NotFoundException;
use UnicaenLeocarte\Service\LeocarteServiceAwareInterface;
use UnicaenLeocarte\Service\LeocarteServiceAwareTrait;
use Zend\Http\PhpEnvironment\Response;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\Stdlib\Exception\ExtensionNotLoadedException;

class IndexController extends AbstractActionController implements LeocarteServiceAwareInterface
{
@@ -25,17 +26,22 @@ class IndexController extends AbstractActionController implements LeocarteServic
        $id = $this->params()->fromRoute('id');
        $nocache = (bool) (int) $this->params()->fromQuery('nocache', '0');

        try {
            $autorise = $this->leocarteService->getDroitUtilisationPhoto($id);
            if ($autorise) {
                $content = $this->leocarteService->getPhoto($id);
            }
            else {
            try {
                $content = $this->leocarteService->createPhotoNonAutorisee();
            }
            catch (ExtensionNotLoadedException $e) {
        }
        catch (NotFoundException $e) {
            // Requête infructueuse
            $content = '';
        }
        catch (ExtensionNotLoadedException $e) {
            // Extension 'gd' non installée
            $content = '';
        }

        /** @var Response $response */
+10 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenLeocarte\Exception;

use RuntimeException;

class ExtensionNotLoadedException extends RuntimeException
{

}
 No newline at end of file
+10 −0
Original line number Diff line number Diff line
<?php

namespace UnicaenLeocarte\Exception;

use RuntimeException;

class NotFoundException extends RuntimeException
{

}
 No newline at end of file
+10 −1
Original line number Diff line number Diff line
@@ -2,6 +2,8 @@

namespace UnicaenLeocarte\Service;

use RuntimeException;
use UnicaenLeocarte\Exception\NotFoundException;
use UnicaenLeocarte\Service\Soap\LeocarteSoapClientAwareInterface;
use UnicaenLeocarte\Service\Soap\LeocarteSoapClientAwareTrait;
use Zend\Stdlib\Exception\ExtensionNotLoadedException;
@@ -27,6 +29,10 @@ class LeocarteService implements LeocarteSoapClientAwareInterface
    {
        $result = $this->leocarteSoapClient->getDroitUtilisationPhoto($identifiant);

        if (! isset($result->return->persons)) {
            throw new NotFoundException("Requête infructueuse");
        }

        $string = $result->return->persons->data->value->stringValue;

        return $string === self::UTILISATION_PHOTO_AUTORISEE;
@@ -42,6 +48,10 @@ class LeocarteService implements LeocarteSoapClientAwareInterface
        /** @var \stdClass $result */
        $result =  $this->leocarteSoapClient->getPhoto($identifiant);

        if (! isset($result->return->persons)) {
            throw new NotFoundException("Requête infructueuse");
        }

        // c'est le contenu "binaire" de la photo qui est retourné par le WS
        $imgData = $result->return->persons->data->value->imageValue;

@@ -54,7 +64,6 @@ class LeocarteService implements LeocarteSoapClientAwareInterface
     * @param int $width
     * @param int $height
     * @return string Contenu binaire de l'image
     * @throws ExtensionNotLoadedException Si l'extension gd n'est pas activée
     */
    public function createPhotoNonAutorisee($width = 100, $height = 120)
    {