From dff92c2d58f1683988f1cb8f170c7086e06105c3 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Sun, 14 Feb 2016 18:41:45 +0100 Subject: tests --- server/core/Image.php | 50 ++++++++++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 26 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index 3001eea..125f6ad 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -1,7 +1,4 @@ oidentity->createImage($options); + $image = $this->libClass->createImage($options); return $image; } - /* - * List images + /** + * List the images of the server + * + * @return the list with all images on the server */ - public function list_images(){ + $images["listImages"] = function() { // vérifier si au moins une image - $service = $this->oidentity; - $images = $service->listImages(); - return $images; + $this->libClass->listImages(); + //return $l; } /** @@ -117,7 +115,7 @@ class image{ **/ public function image_details($id){ //vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $image = $service->getImage($id); return $image; } @@ -133,7 +131,7 @@ class image{ **/ public function update_image($id, array $opt){ //vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $image = $service->getImage($id); $options = Array(); @@ -170,7 +168,7 @@ class image{ public function delete_image($id){ // si protected = true, demander de le mettre a false // vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $service->getImage($id)->delete(); } @@ -182,7 +180,7 @@ class image{ **/ public function reactivate_image($id){ // vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $image = $service->getImage($id); $image->reactivate(); } @@ -195,7 +193,7 @@ class image{ **/ public function desactivate_image($id){ // vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $image = $service->getImage($id); $image->deactivate(); } @@ -211,7 +209,7 @@ class image{ **/ public function upload_image($id, $file_name){ // vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $image = $service->getImage($id); $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR $image->uploadData($stream); @@ -225,7 +223,7 @@ class image{ **/ public function download_image($id){ // vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $image = $service->getImage($id); $stream = $image->downloadData(); return $stream; @@ -244,7 +242,7 @@ class image{ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe - $service = $this->oidentity; + $service = $this->libClass; $member_id = $service>getImage($image_id)->addMember($member_id); } @@ -257,7 +255,7 @@ class image{ **/ public function list_member($image_id, $member_id){ // vérifier existence image - $service = $this->oidentity; + $service = $this->libClass; $image = $service->getImage($image_id); $members = $image->listMembers(); return $members; @@ -276,7 +274,7 @@ class image{ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe - $service = $this->oidentity; + $service = $this->libClass; $member = $service>getImage($image_id)->getMember($member_id); return $member; } @@ -294,7 +292,7 @@ class image{ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe - $service = $this->oidentity; + $service = $this->libClass; $service>getImage($image_id)->getMember($member_id)->delete(); } @@ -314,7 +312,7 @@ class image{ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe - $service = $this->oidentity; + $service = $this->libClass; $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); } -- cgit v1.2.3 From a90cc995ff44821234f8ae37cbbb685d3dd75a8e Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 17 Feb 2016 16:09:44 +0100 Subject: Renaming functions --- server/Test/imageTests.php | 56 +++++++++++++++++++++++++--------------------- server/core/Image.php | 32 +++++++++++++------------- 2 files changed, 47 insertions(+), 41 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index b406cee..39e83e1 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -14,51 +14,57 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$new_image = $image->create_image($opt); +//$new_image = $image->createImage($opt); //Liste des images -$images = $image["listImages"]; +$images = $image->listImage(); -echo "Images présentes :"; -echo "
"; - -foreach($images as $i){ - echo $i->name; - if($i->name == "Test"){ - $id_image = $i->id; - $list = $i->tags; - echo $i->status; +if(isset($images)){ + echo "Images présentes :"; + echo "
"; + foreach($images as $i){ + echo $i->name; + if($i->name == "Test"){ + $id_image = $i->id; + $list = $i->tags; + echo $i->status; + } + echo "
"; } echo "
"; -} -echo "
"; -if(isset($list)){ - foreach ($list as $l) { - echo $l; - echo "
"; - } + if(isset($list)){ + foreach ($list as $l) { + echo $l; + echo "
"; + } } +} +else{ + echo "Aucune image présente\n"; +} + + // Détails Image -//$details = $image->image_details($id_image); +//$details = $image->imageDetails($id_image); -//$image->delete_image('123456'); +//$image->deleteImage('123456'); -//$image->desactivate_image($id_image); -//$image->reactivate_image($id_image); +//$image->desactivateImage($id_image); +//$image->reactivateImage($id_image); //$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso"; -//$image->upload_image($id_image, $file_name); +//$image->uploadImage($id_image, $file_name); -//$image->download_image($id_image); +//$image->downloadImage($id_image); /* $opt_update = Array(); $opt_update['name'] = "Test"; $opt_update['tags'] = null; -$update = $image->update_image($id_image, $opt_update); +$update = $image->updateImage($id_image, $opt_update); echo $update->name; */ diff --git a/server/core/Image.php b/server/core/Image.php index 125f6ad..637966c 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -17,7 +17,7 @@ use OpenStack\Common\Error; * ADD CLASS DESCRIPTION * */ -class image implements Core{ +class image { //implements Core /** @var App $app protected, contains the main app object */ @@ -45,7 +45,7 @@ class image implements Core{ } - $images = array(); + private $images = array(); /** * Details about an image @@ -54,7 +54,7 @@ class image implements Core{ * options for the image creation * **/ - public function create_image(array $opt){ + public function createImage(array $opt){ // VOIR SI MAUVAIS TYPE $options = Array(); if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris @@ -100,7 +100,7 @@ class image implements Core{ * * @return the list with all images on the server */ - $images["listImages"] = function() { + public function listImage(){ // vérifier si au moins une image $this->libClass->listImages(); //return $l; @@ -113,7 +113,7 @@ class image implements Core{ * identifier of the image * **/ - public function image_details($id){ + public function detailsImage($id){ //vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -129,7 +129,7 @@ class image implements Core{ * @param array $opt * options for the image creation **/ - public function update_image($id, array $opt){ + public function updateImage($id, array $opt){ //vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -165,7 +165,7 @@ class image implements Core{ * @param string $id * identifier of the image **/ - public function delete_image($id){ + public function imageDelete($id){ // si protected = true, demander de le mettre a false // vérifier existence image $service = $this->libClass; @@ -178,7 +178,7 @@ class image implements Core{ * @param string $id * identifier of the image **/ - public function reactivate_image($id){ + public function reactivateImage($id){ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -191,7 +191,7 @@ class image implements Core{ * @param string $id * identifier of the image **/ - public function desactivate_image($id){ + public function desactivateImage($id){ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -207,7 +207,7 @@ class image implements Core{ * @param string $file_name * path of the image **/ - public function upload_image($id, $file_name){ + public function uploadImage($id, $file_name){ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -221,7 +221,7 @@ class image implements Core{ * @param string $id * identifier of the image **/ - public function download_image($id){ + public function downloadImage($id){ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -238,7 +238,7 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - public function add_member($image_id, $member_id){ + public function addMemberImage($image_id, $member_id){ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe @@ -253,7 +253,7 @@ class image implements Core{ * @param string $image_id * identifier of the image **/ - public function list_member($image_id, $member_id){ + public function listMemberImage($image_id, $member_id){ // vérifier existence image $service = $this->libClass; $image = $service->getImage($image_id); @@ -270,7 +270,7 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - public function detail_member($image_id, $member_id){ + public function detailMemberImage($image_id, $member_id){ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe @@ -288,7 +288,7 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - public function remove_member($image_id, $member_id){ + public function removeMemberImage($image_id, $member_id){ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe @@ -308,7 +308,7 @@ class image implements Core{ * @param string $status * new status for the member **/ - public function update_member($image_id, $member_id, $status){ + public function updateMemberImage($image_id, $member_id, $status){ // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe -- cgit v1.2.3 From 81bc109269722745a475eac0f7aa9d14b3ffe66b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 17 Feb 2016 17:16:57 +0100 Subject: Add control of parameters errors --- server/Test/imageTests.php | 2 +- server/core/Image.php | 83 +++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 80 insertions(+), 5 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 39e83e1..47a69e2 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -49,7 +49,7 @@ else{ // Détails Image //$details = $image->imageDetails($id_image); -//$image->deleteImage('123456'); +$image->deleteImage('123456'); //$image->desactivateImage($id_image); //$image->reactivateImage($id_image); diff --git a/server/core/Image.php b/server/core/Image.php index 637966c..15facc9 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -40,6 +40,9 @@ class image { * @return Image */ public function __construct($app){ + if(!isset($app)){ + // Renvoyer erreur + } $this->app = $app; $this->libClass = $app->getLibClass("Image"); } @@ -54,7 +57,10 @@ class image { * options for the image creation * **/ - public function createImage(array $opt){ + public function createImage(array $opt){ + if(!isset($opt)){ + // Renvoyer erreur + } // VOIR SI MAUVAIS TYPE $options = Array(); if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris @@ -114,6 +120,9 @@ class image { * **/ public function detailsImage($id){ + if(!isset($id)){ + // Renvoyer erreur + } //vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -130,6 +139,12 @@ class image { * options for the image creation **/ public function updateImage($id, array $opt){ + if(!isset($id)){ + // Renvoyer erreur + } + if(!isset($opt)){ + // Renvoyer erreur + } //vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -165,11 +180,26 @@ class image { * @param string $id * identifier of the image **/ - public function imageDelete($id){ + public function deleteImage($id){ // si protected = true, demander de le mettre a false // vérifier existence image - $service = $this->libClass; - $service->getImage($id)->delete(); + if(!isset($id)){ + // Renvoyer erreur + } + try{ + $service = $this->libClass; + $service->getImage($id)->delete(); + }catch(BadResponseError $e){ + echo "YOLO"; + $this->app->getErrorInstance->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } /** @@ -179,6 +209,9 @@ class image { * identifier of the image **/ public function reactivateImage($id){ + if(!isset($id)){ + // Renvoyer erreur + } // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -192,6 +225,9 @@ class image { * identifier of the image **/ public function desactivateImage($id){ + if(!isset($id)){ + // Renvoyer erreur + } // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -208,6 +244,12 @@ class image { * path of the image **/ public function uploadImage($id, $file_name){ + if(!isset($id)){ + // Renvoyer erreur + } + if(!isset($file_name)){ + // Renvoyer erreur + } // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -222,6 +264,9 @@ class image { * identifier of the image **/ public function downloadImage($id){ + if(!isset($id)){ + // Renvoyer erreur + } // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); @@ -239,6 +284,12 @@ class image { * identifier of the member **/ public function addMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + // Renvoyer erreur + } + if(!isset($member_id)){ + // Renvoyer erreur + } // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe @@ -254,6 +305,12 @@ class image { * identifier of the image **/ public function listMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + // Renvoyer erreur + } + if(!isset($member_id)){ + // Renvoyer erreur + } // vérifier existence image $service = $this->libClass; $image = $service->getImage($image_id); @@ -271,6 +328,12 @@ class image { * identifier of the member **/ public function detailMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + // Renvoyer erreur + } + if(!isset($member_id)){ + // Renvoyer erreur + } // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe @@ -289,6 +352,12 @@ class image { * identifier of the member **/ public function removeMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + // Renvoyer erreur + } + if(!isset($member_id)){ + // Renvoyer erreur + } // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe @@ -309,6 +378,12 @@ class image { * new status for the member **/ public function updateMemberImage($image_id, $member_id, $status){ + if(!isset($image_id)){ + // Renvoyer erreur + } + if(!isset($member_id)){ + // Renvoyer erreur + } // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe -- cgit v1.2.3 From 58a936d0158e4f90596bfe88352f5a570094c436 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 17 Feb 2016 17:56:11 +0100 Subject: Add errors features for tests calsses --- server/Test/AppTestClass.php | 13 +++++++++++++ server/core/Image.php | 10 ++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 311b9bf..40a5847 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -1,6 +1,12 @@ openstack = new OpenStack\OpenStack([]); $this->pluginsApi = plugin_api::getInstance(); $this->output = array(); + $this->errorClass = new errorManagement($this); } @@ -70,4 +78,9 @@ class AppTest{ echo json_encode($this->output); } + public function getErrorInstance(){ + + return $this->errorClass; + + } } \ No newline at end of file diff --git a/server/core/Image.php b/server/core/Image.php index 15facc9..bc4834a 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -9,8 +9,11 @@ * * @todo Complete the functions with errors detection and finish the descriptions */ -use OpenStack\Common\Error; - +use OpenStack\Common\Error\BadResponseError; +use OpenStack\Common\Error\BaseError; +use OpenStack\Common\Error\NotImplementedError; +use OpenStack\Common\Error\UserInputError; + /** * Image Class of the back-end application * @@ -190,8 +193,7 @@ class image { $service = $this->libClass; $service->getImage($id)->delete(); }catch(BadResponseError $e){ - echo "YOLO"; - $this->app->getErrorInstance->BadResponseHandler($e); + $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ $this->app->getErrorInstance->UserInputHandler($e); }catch(BaseError $e){ -- cgit v1.2.3 From 16e0328884f318d97ac991ee8e70f43ee1c14b38 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 17 Feb 2016 18:29:03 +0100 Subject: Add errors management --- server/core/Image.php | 366 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 254 insertions(+), 112 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index bc4834a..85a245f 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -46,8 +46,18 @@ class image { if(!isset($app)){ // Renvoyer erreur } - $this->app = $app; - $this->libClass = $app->getLibClass("Image"); + try{ + $this->app = $app; + $this->libClass = $app->getLibClass("Image"); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } @@ -63,44 +73,54 @@ class image { public function createImage(array $opt){ if(!isset($opt)){ // Renvoyer erreur - } - // VOIR SI MAUVAIS TYPE - $options = Array(); - if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris - } - else{ - //ERROR } - if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn - $options['id'] = $opt['id']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker - $options['containerFormat'] = $opt['containerFormat']; - } - if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso - $options['diskFormat'] = $opt['diskFormat']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; - } - if(isset($opt['properties'])){ // type dict ? - $options['properties'] = $opt['properties']; - } - $image = $this->libClass->createImage($options); + try{ + // VOIR SI MAUVAIS TYPE + $options = Array(); + if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris + } + else{ + //ERROR + } + if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn + $options['id'] = $opt['id']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker + $options['containerFormat'] = $opt['containerFormat']; + } + if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso + $options['diskFormat'] = $opt['diskFormat']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['properties'])){ // type dict ? + $options['properties'] = $opt['properties']; + } + $image = $this->libClass->createImage($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $image; } @@ -110,9 +130,20 @@ class image { * @return the list with all images on the server */ public function listImage(){ - // vérifier si au moins une image - $this->libClass->listImages(); - //return $l; + try{ + // vérifier si au moins une image + $l = $this->libClass->listImages(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + return $l; + } /** @@ -126,10 +157,21 @@ class image { if(!isset($id)){ // Renvoyer erreur } - //vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - return $image; + + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + return $image; + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -148,32 +190,42 @@ class image { if(!isset($opt)){ // Renvoyer erreur } - //vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - $options = Array(); - - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); + + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + $options = Array(); + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $image; } @@ -214,10 +266,20 @@ class image { if(!isset($id)){ // Renvoyer erreur } - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - $image->reactivate(); + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + $image->reactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -230,10 +292,20 @@ class image { if(!isset($id)){ // Renvoyer erreur } - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - $image->deactivate(); + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + $image->deactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -252,11 +324,21 @@ class image { if(!isset($file_name)){ // Renvoyer erreur } - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR - $image->uploadData($stream); + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR + $image->uploadData($stream); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -269,11 +351,21 @@ class image { if(!isset($id)){ // Renvoyer erreur } - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - $stream = $image->downloadData(); - return $stream; + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + $stream = $image->downloadData(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + return $stream; } /** @@ -292,11 +384,21 @@ class image { if(!isset($member_id)){ // Renvoyer erreur } - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->libClass; - $member_id = $service>getImage($image_id)->addMember($member_id); + try{ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->libClass; + $member_id = $service>getImage($image_id)->addMember($member_id); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } @@ -313,10 +415,20 @@ class image { if(!isset($member_id)){ // Renvoyer erreur } - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($image_id); - $members = $image->listMembers(); + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + $members = $image->listMembers(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $members; } @@ -336,11 +448,21 @@ class image { if(!isset($member_id)){ // Renvoyer erreur } - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->libClass; - $member = $service>getImage($image_id)->getMember($member_id); + try{ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->libClass; + $member = $service>getImage($image_id)->getMember($member_id); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $member; } @@ -360,11 +482,21 @@ class image { if(!isset($member_id)){ // Renvoyer erreur } - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->libClass; - $service>getImage($image_id)->getMember($member_id)->delete(); + try{ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->libClass; + $service>getImage($image_id)->getMember($member_id)->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -386,12 +518,22 @@ class image { if(!isset($member_id)){ // Renvoyer erreur } - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->libClass; - $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); + try{ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->libClass; + $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } } -?> +?> \ No newline at end of file -- cgit v1.2.3 From 59dfbc78ffebf674591ecc6e7cbda32ee667381b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 24 Feb 2016 14:51:23 +0100 Subject: add some error cases --- server/core/Image.php | 108 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 91 insertions(+), 17 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index 85a245f..dba92ff 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -29,10 +29,6 @@ class image { /** @var OpenStack\Identity $libClass protected, contains the library Identity object */ protected $libClass; - /** @var array $actions protected, contains the functions which can be call by the front-end */ - protected $actions = array(); - - /** * Image constructor * @@ -71,19 +67,33 @@ class image { * **/ public function createImage(array $opt){ + if(!isset($opt)){ // Renvoyer erreur } + try{ // VOIR SI MAUVAIS TYPE $options = Array(); - if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris + if(isset($opt['name'])){ // if the image name already exists -> error + $imagesList = listImage(); + if(isset($images)){ + foreach($imagesList as $image){ + if(strcmp($image->name, $opt['name']) == 0){ + + } + } + } + } else{ //ERROR } if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn + if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error + + } $options['id'] = $opt['id']; } if(isset($opt['visibility'])){ // public, private @@ -131,8 +141,10 @@ class image { */ public function listImage(){ try{ - // vérifier si au moins une image $l = $this->libClass->listImages(); + if(!isset($l)){ // if the list is empty there is no images + + } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -157,11 +169,13 @@ class image { if(!isset($id)){ // Renvoyer erreur } - try{ - //vérifier existence image $service = $this->libClass; $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } + return $image; }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -190,11 +204,15 @@ class image { if(!isset($opt)){ // Renvoyer erreur } - + try{ //vérifier existence image $service = $this->libClass; $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } + $options = Array(); // Voir vérification des types @@ -241,9 +259,14 @@ class image { if(!isset($id)){ // Renvoyer erreur } + try{ $service = $this->libClass; - $service->getImage($id)->delete(); + $image = $this->libClass->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } + $image->delete(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -270,6 +293,9 @@ class image { // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } $image->reactivate(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -296,6 +322,9 @@ class image { // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } $image->deactivate(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -328,6 +357,9 @@ class image { // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR $image->uploadData($stream); }catch(BadResponseError $e){ @@ -355,6 +387,9 @@ class image { // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } $stream = $image->downloadData(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -388,8 +423,14 @@ class image { // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe - $service = $this->libClass; - $member_id = $service>getImage($image_id)->addMember($member_id); + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } + + $member_id = $image->addMember($member_id); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -419,7 +460,13 @@ class image { // vérifier existence image $service = $this->libClass; $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } $members = $image->listMembers(); + if($member == null){ // if the image don't exists -> error + // Renvoyer erreur + } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -452,8 +499,17 @@ class image { // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe - $service = $this->libClass; - $member = $service>getImage($image_id)->getMember($member_id); + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } + + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + // Renvoyer erreur + } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -486,8 +542,17 @@ class image { // vérifier existence image // on doit être le proprio de l'image // vérifier membre existe - $service = $this->libClass; - $service>getImage($image_id)->getMember($member_id)->delete(); + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + // Renvoyer erreur + } + $member->delete(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -523,7 +588,16 @@ class image { // on doit être le proprio de l'image // vérifier membre existe $service = $this->libClass; - $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + // Renvoyer erreur + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + // Renvoyer erreur + } + $member->updateStatus($status); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ -- cgit v1.2.3 From 6349739a6c42d413e1bc1ea5068336187055c277 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 24 Feb 2016 18:23:39 +0100 Subject: architecture update --- server/core/Image.php | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index dba92ff..4d22443 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -20,8 +20,7 @@ use OpenStack\Common\Error\UserInputError; * ADD CLASS DESCRIPTION * */ -class image { - //implements Core +class image implements Core{ /** @var App $app protected, contains the main app object */ protected $app; @@ -57,7 +56,18 @@ class image { } - private $images = array(); + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + + $this->{$action.""}(); + + } /** * Details about an image @@ -66,7 +76,7 @@ class image { * options for the image creation * **/ - public function createImage(array $opt){ + private function createImage(array $opt){ if(!isset($opt)){ // Renvoyer erreur @@ -139,7 +149,7 @@ class image { * * @return the list with all images on the server */ - public function listImage(){ + private function listImage(){ try{ $l = $this->libClass->listImages(); if(!isset($l)){ // if the list is empty there is no images @@ -165,7 +175,7 @@ class image { * identifier of the image * **/ - public function detailsImage($id){ + private function detailsImage($id){ if(!isset($id)){ // Renvoyer erreur } @@ -197,7 +207,7 @@ class image { * @param array $opt * options for the image creation **/ - public function updateImage($id, array $opt){ + private function updateImage($id, array $opt){ if(!isset($id)){ // Renvoyer erreur } @@ -253,7 +263,7 @@ class image { * @param string $id * identifier of the image **/ - public function deleteImage($id){ + private function deleteImage($id){ // si protected = true, demander de le mettre a false // vérifier existence image if(!isset($id)){ @@ -285,7 +295,7 @@ class image { * @param string $id * identifier of the image **/ - public function reactivateImage($id){ + private function reactivateImage($id){ if(!isset($id)){ // Renvoyer erreur } @@ -314,7 +324,7 @@ class image { * @param string $id * identifier of the image **/ - public function desactivateImage($id){ + private function desactivateImage($id){ if(!isset($id)){ // Renvoyer erreur } @@ -346,7 +356,7 @@ class image { * @param string $file_name * path of the image **/ - public function uploadImage($id, $file_name){ + private function uploadImage($id, $file_name){ if(!isset($id)){ // Renvoyer erreur } @@ -379,7 +389,7 @@ class image { * @param string $id * identifier of the image **/ - public function downloadImage($id){ + private function downloadImage($id){ if(!isset($id)){ // Renvoyer erreur } @@ -412,7 +422,7 @@ class image { * @param string $member_id * identifier of the member **/ - public function addMemberImage($image_id, $member_id){ + private function addMemberImage($image_id, $member_id){ if(!isset($image_id)){ // Renvoyer erreur } @@ -449,7 +459,7 @@ class image { * @param string $image_id * identifier of the image **/ - public function listMemberImage($image_id, $member_id){ + private function listMemberImage($image_id, $member_id){ if(!isset($image_id)){ // Renvoyer erreur } @@ -488,7 +498,7 @@ class image { * @param string $member_id * identifier of the member **/ - public function detailMemberImage($image_id, $member_id){ + private function detailMemberImage($image_id, $member_id){ if(!isset($image_id)){ // Renvoyer erreur } @@ -531,7 +541,7 @@ class image { * @param string $member_id * identifier of the member **/ - public function removeMemberImage($image_id, $member_id){ + private function removeMemberImage($image_id, $member_id){ if(!isset($image_id)){ // Renvoyer erreur } @@ -576,7 +586,7 @@ class image { * @param string $status * new status for the member **/ - public function updateMemberImage($image_id, $member_id, $status){ + private function updateMemberImage($image_id, $member_id, $status){ if(!isset($image_id)){ // Renvoyer erreur } -- cgit v1.2.3 From ae1100c16880d4bae77513ec433ac6734da8dea4 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Mon, 29 Feb 2016 15:25:30 +0100 Subject: Error management --- server/Test/AppTestClass.php | 20 +++------- server/Test/imageTests.php | 4 +- server/core/Image.php | 92 ++++++++++++++++++++------------------------ 3 files changed, 48 insertions(+), 68 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 4d1f824..57dd422 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -26,15 +26,10 @@ class AppTest{ $this->pluginsApi = plugin_api::getInstance(); $this->errorClass = new errorManagement($this); $this->output = array(); -<<<<<<< HEAD -<<<<<<< HEAD + $this->errorClass = new errorManagement($this); -======= - $this->postParams = $_POST; ->>>>>>> develop -======= + $this->postParams = $_POST; ->>>>>>> develop } @@ -109,17 +104,12 @@ class AppTest{ return json_encode($this->output); } -<<<<<<< HEAD -<<<<<<< HEAD + public function getErrorInstance(){ return $this->errorClass; } -} -======= } ->>>>>>> develop -======= -} ->>>>>>> develop + + diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 47a69e2..d21eefb 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -17,7 +17,7 @@ $opt['minRam'] = 10; //$new_image = $image->createImage($opt); //Liste des images -$images = $image->listImage(); +$images = $image->action("listImage"); if(isset($images)){ echo "Images présentes :"; @@ -49,7 +49,7 @@ else{ // Détails Image //$details = $image->imageDetails($id_image); -$image->deleteImage('123456'); +//$image->deleteImage('123456'); //$image->desactivateImage($id_image); //$image->reactivateImage($id_image); diff --git a/server/core/Image.php b/server/core/Image.php index 4d22443..4025595 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -39,7 +39,7 @@ class image implements Core{ */ public function __construct($app){ if(!isset($app)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ $this->app = $app; @@ -79,7 +79,7 @@ class image implements Core{ private function createImage(array $opt){ if(!isset($opt)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } @@ -98,7 +98,7 @@ class image implements Core{ } else{ - //ERROR + $this->app->setOutput("Error", "Image name already exists"); } if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error @@ -153,7 +153,7 @@ class image implements Core{ try{ $l = $this->libClass->listImages(); if(!isset($l)){ // if the list is empty there is no images - + $this->app->setOutput("Error", "No image"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -183,7 +183,7 @@ class image implements Core{ $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } return $image; @@ -209,10 +209,10 @@ class image implements Core{ **/ private function updateImage($id, array $opt){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } if(!isset($opt)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect opt parameter"); } try{ @@ -220,7 +220,7 @@ class image implements Core{ $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $options = Array(); @@ -267,14 +267,14 @@ class image implements Core{ // si protected = true, demander de le mettre a false // vérifier existence image if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } try{ $service = $this->libClass; $image = $this->libClass->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $image->delete(); }catch(BadResponseError $e){ @@ -297,14 +297,14 @@ class image implements Core{ **/ private function reactivateImage($id){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $image->reactivate(); }catch(BadResponseError $e){ @@ -326,14 +326,14 @@ class image implements Core{ **/ private function desactivateImage($id){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $image->deactivate(); }catch(BadResponseError $e){ @@ -358,19 +358,19 @@ class image implements Core{ **/ private function uploadImage($id, $file_name){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } if(!isset($file_name)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect file_name parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); $image->uploadData($stream); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -391,14 +391,14 @@ class image implements Core{ **/ private function downloadImage($id){ if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $stream = $image->downloadData(); }catch(BadResponseError $e){ @@ -424,22 +424,18 @@ class image implements Core{ **/ private function addMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } - $member_id = $image->addMember($member_id); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -461,21 +457,21 @@ class image implements Core{ **/ private function listMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ // vérifier existence image $service = $this->libClass; $image = $service->getImage($image_id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $members = $image->listMembers(); if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "No member"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -500,10 +496,10 @@ class image implements Core{ **/ private function detailMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ // vérifier existence image @@ -513,12 +509,12 @@ class image implements Core{ $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -543,24 +539,21 @@ class image implements Core{ **/ private function removeMemberImage($image_id, $member_id){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $member = $image->getMember($member_id); if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Member doesn't exist"); } $member->delete(); }catch(BadResponseError $e){ @@ -588,24 +581,21 @@ class image implements Core{ **/ private function updateMemberImage($image_id, $member_id, $status){ if(!isset($image_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter image_id"); } if(!isset($member_id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect parameter member_id"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error - // Renvoyer erreur + $this->app->setOutput("Error", "Image doesn't exist"); } $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - // Renvoyer erreur + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); } $member->updateStatus($status); }catch(BadResponseError $e){ -- cgit v1.2.3 From 6ce1bbc7be91aa6441c3ff168a734ed25479eb72 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Mon, 29 Feb 2016 15:29:30 +0100 Subject: Add error management --- server/core/Image.php | 571 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 431 insertions(+), 140 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index 3001eea..4025595 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -1,7 +1,4 @@ app = $app; - $this->libClass = $app->getLibClass("Image"); + if(!isset($app)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + $this->app = $app; + $this->libClass = $app->getLibClass("Image"); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } - + /** + * Execute an action + * + * @param String $action name of another function of this class + * + * @return void + */ + public function action($action){ + + $this->{$action.""}(); + + } /** * Details about an image @@ -57,55 +76,96 @@ class image{ * options for the image creation * **/ - public function create_image(array $opt){ - // VOIR SI MAUVAIS TYPE - $options = Array(); - if(isset($opt['name'])){ // string, rendre le nom obligatoire, vérifier nom pas déjà pris - } - else{ - //ERROR - } - if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn - $options['id'] = $opt['id']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker - $options['containerFormat'] = $opt['containerFormat']; - } - if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso - $options['diskFormat'] = $opt['diskFormat']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; + private function createImage(array $opt){ + + if(!isset($opt)){ + $this->app->setOutput("Error", "Incorrect parameter"); } - if(isset($opt['properties'])){ // type dict ? - $options['properties'] = $opt['properties']; - } - $image = $this->oidentity->createImage($options); + try{ + // VOIR SI MAUVAIS TYPE + $options = Array(); + if(isset($opt['name'])){ // if the image name already exists -> error + $imagesList = listImage(); + if(isset($images)){ + foreach($imagesList as $image){ + if(strcmp($image->name, $opt['name']) == 0){ + + } + } + } + + } + else{ + $this->app->setOutput("Error", "Image name already exists"); + } + if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn + if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error + + } + $options['id'] = $opt['id']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + if(isset($opt['containerFormat'])){ // string : ami, ari, aki, bare, ovf, ova, docker + $options['containerFormat'] = $opt['containerFormat']; + } + if(isset($opt['diskFormat'])){ // string : ami, ari, aki, vhd, vmdk, raw, qcow2, vdi, iso + $options['diskFormat'] = $opt['diskFormat']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['properties'])){ // type dict ? + $options['properties'] = $opt['properties']; + } + + $image = $this->libClass->createImage($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $image; } - /* - * List images + /** + * List the images of the server + * + * @return the list with all images on the server */ - public function list_images(){ - // vérifier si au moins une image - $service = $this->oidentity; - $images = $service->listImages(); - return $images; + private function listImage(){ + try{ + $l = $this->libClass->listImages(); + if(!isset($l)){ // if the list is empty there is no images + $this->app->setOutput("Error", "No image"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + return $l; + } /** @@ -115,11 +175,27 @@ class image{ * identifier of the image * **/ - public function image_details($id){ - //vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - return $image; + private function detailsImage($id){ + if(!isset($id)){ + // Renvoyer erreur + } + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + + return $image; + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -131,33 +207,53 @@ class image{ * @param array $opt * options for the image creation **/ - public function update_image($id, array $opt){ - //vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $options = Array(); - - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; + private function updateImage($id, array $opt){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect id parameter"); } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; + if(!isset($opt)){ + $this->app->setOutput("Error", "Incorrect opt parameter"); } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + + $options = Array(); + + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $image; } @@ -167,11 +263,30 @@ class image{ * @param string $id * identifier of the image **/ - public function delete_image($id){ + private function deleteImage($id){ // si protected = true, demander de le mettre a false // vérifier existence image - $service = $this->oidentity; - $service->getImage($id)->delete(); + if(!isset($id)){ + $this->app->setOutput("Error", "Image doesn't exist"); + } + + try{ + $service = $this->libClass; + $image = $this->libClass->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + } /** @@ -180,11 +295,27 @@ class image{ * @param string $id * identifier of the image **/ - public function reactivate_image($id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $image->reactivate(); + private function reactivateImage($id){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->reactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -193,11 +324,27 @@ class image{ * @param string $id * identifier of the image **/ - public function desactivate_image($id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $image->deactivate(); + private function desactivateImage($id){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->deactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -209,12 +356,31 @@ class image{ * @param string $file_name * path of the image **/ - public function upload_image($id, $file_name){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); // A VOIR - $image->uploadData($stream); + private function uploadImage($id, $file_name){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect id parameter"); + } + if(!isset($file_name)){ + $this->app->setOutput("Error", "Incorrect file_name parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $image->uploadData($stream); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -223,12 +389,28 @@ class image{ * @param string $id * identifier of the image **/ - public function download_image($id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($id); - $stream = $image->downloadData(); - return $stream; + private function downloadImage($id){ + if(!isset($id)){ + $this->app->setOutput("Error", "Incorrect parameter"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = $image->downloadData(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } + return $stream; } /** @@ -240,12 +422,30 @@ class image{ * @param string $member_id * identifier of the member **/ - public function add_member($image_id, $member_id){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $member_id = $service>getImage($image_id)->addMember($member_id); + private function addMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member_id = $image->addMember($member_id); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } @@ -255,11 +455,33 @@ class image{ * @param string $image_id * identifier of the image **/ - public function list_member($image_id, $member_id){ - // vérifier existence image - $service = $this->oidentity; - $image = $service->getImage($image_id); - $members = $image->listMembers(); + private function listMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $members = $image->listMembers(); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "No member"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $members; } @@ -272,12 +494,37 @@ class image{ * @param string $member_id * identifier of the member **/ - public function detail_member($image_id, $member_id){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $member = $service>getImage($image_id)->getMember($member_id); + private function detailMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + // vérifier existence image + // on doit être le proprio de l'image + // vérifier membre existe + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } return $member; } @@ -290,12 +537,34 @@ class image{ * @param string $member_id * identifier of the member **/ - public function remove_member($image_id, $member_id){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $service>getImage($image_id)->getMember($member_id)->delete(); + private function removeMemberImage($image_id, $member_id){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } /** @@ -310,13 +579,35 @@ class image{ * @param string $status * new status for the member **/ - public function update_member($image_id, $member_id, $status){ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe - $service = $this->oidentity; - $member = $service>getImage($image_id)->getMember($member_id)->updateStatus($status); + private function updateMemberImage($image_id, $member_id, $status){ + if(!isset($image_id)){ + $this->app->setOutput("Error", "Incorrect parameter image_id"); + } + if(!isset($member_id)){ + $this->app->setOutput("Error", "Incorrect parameter member_id"); + } + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->updateStatus($status); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance->NotImplementedHandler($e); + } } } -?> +?> \ No newline at end of file -- cgit v1.2.3 From 671f03df988218444d5cd889705521415bf14d13 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 2 Mar 2016 13:01:51 +0100 Subject: try to resolve token pb --- server/Test/imageTests.php | 2 +- server/core/Image.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'server/core/Image.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index d21eefb..1bb834b 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -18,7 +18,7 @@ $opt['minRam'] = 10; //Liste des images $images = $image->action("listImage"); - +//$images = $image->listImage(); if(isset($images)){ echo "Images présentes :"; echo "
"; diff --git a/server/core/Image.php b/server/core/Image.php index 4025595..e341fe0 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -14,6 +14,8 @@ use OpenStack\Common\Error\BaseError; use OpenStack\Common\Error\NotImplementedError; use OpenStack\Common\Error\UserInputError; +include("CoreInterface.php"); + /** * Image Class of the back-end application * -- cgit v1.2.3 From 0161194d08050877e958cab885e7c335f2cca2d9 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 2 Mar 2016 15:28:09 +0100 Subject: pb resolu --- server/Test/imageTests.php | 9 ++++++--- server/core/Image.php | 8 ++++++-- 2 files changed, 12 insertions(+), 5 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 1bb834b..a8f16ce 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -17,14 +17,17 @@ $opt['minRam'] = 10; //$new_image = $image->createImage($opt); //Liste des images -$images = $image->action("listImage"); +$image->action("listImage"); //$images = $image->listImage(); +$im = $App->show(); +error_log(var_export(json_decode($im, true), true), 0); +$images = json_decode($im, true)["Images"]; if(isset($images)){ echo "Images présentes :"; echo "
"; foreach($images as $i){ - echo $i->name; - if($i->name == "Test"){ + echo $i['name']; + if($i['name'] == "Test"){ $id_image = $i->id; $list = $i->tags; echo $i->status; diff --git a/server/core/Image.php b/server/core/Image.php index e341fe0..6bc2dbd 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -153,7 +153,11 @@ class image implements Core{ */ private function listImage(){ try{ + $result = array(); $l = $this->libClass->listImages(); + foreach($l as $tmp) + $result[] = $tmp; + error_log(var_export($result, true), 0); if(!isset($l)){ // if the list is empty there is no images $this->app->setOutput("Error", "No image"); } @@ -166,8 +170,8 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $l; - + //return $l; + $this->app->setOutput("Images", $result); } /** -- cgit v1.2.3 From 66baa3ffc8bd119558eeb1e87cb05c6008df9d6f Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 2 Mar 2016 15:58:17 +0100 Subject: Architecture mofification --- server/Test/imageTests.php | 6 ----- server/core/Image.php | 67 +++++++++++++++++++++++++++++----------------- 2 files changed, 43 insertions(+), 30 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index a8f16ce..3af12fc 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -20,18 +20,12 @@ $opt['minRam'] = 10; $image->action("listImage"); //$images = $image->listImage(); $im = $App->show(); -error_log(var_export(json_decode($im, true), true), 0); $images = json_decode($im, true)["Images"]; if(isset($images)){ echo "Images présentes :"; echo "
"; foreach($images as $i){ echo $i['name']; - if($i['name'] == "Test"){ - $id_image = $i->id; - $list = $i->tags; - echo $i->status; - } echo "
"; } echo "
"; diff --git a/server/core/Image.php b/server/core/Image.php index 6bc2dbd..ddd8390 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -79,6 +79,7 @@ class image implements Core{ * **/ private function createImage(array $opt){ + $opt = $this->app->getPostParam("opt"); if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect parameter"); @@ -143,7 +144,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $image; + $this->app->setOutput("Images", $image); } /** @@ -155,11 +156,8 @@ class image implements Core{ try{ $result = array(); $l = $this->libClass->listImages(); - foreach($l as $tmp) + foreach($l as $tmp){ $result[] = $tmp; - error_log(var_export($result, true), 0); - if(!isset($l)){ // if the list is empty there is no images - $this->app->setOutput("Error", "No image"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -170,7 +168,6 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - //return $l; $this->app->setOutput("Images", $result); } @@ -181,9 +178,10 @@ class image implements Core{ * identifier of the image * **/ - private function detailsImage($id){ + private function detailsImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } try{ $service = $this->libClass; @@ -191,8 +189,7 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } - - return $image; + $this->app->setOutput("Images", $image); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -213,7 +210,9 @@ class image implements Core{ * @param array $opt * options for the image creation **/ - private function updateImage($id, array $opt){ + private function updateImage(){ + $id = $this->app->getPostParam("id"); + $opt = $this->app->getPostParam("opt"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } @@ -260,7 +259,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $image; + $this->app->setOutput("Images", $image); } /** @@ -269,9 +268,10 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function deleteImage($id){ + private function deleteImage(){ // si protected = true, demander de le mettre a false // vérifier existence image + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } @@ -291,8 +291,7 @@ class image implements Core{ $this->app->getErrorInstance->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); - } - + } } /** @@ -301,7 +300,8 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function reactivateImage($id){ + private function reactivateImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -330,7 +330,8 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function desactivateImage($id){ + private function desactivateImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -363,6 +364,9 @@ class image implements Core{ * path of the image **/ private function uploadImage($id, $file_name){ + $id = $this->app->getPostParam("id"); + $file_name = $this->app->getPostParam("file_name"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } @@ -396,6 +400,7 @@ class image implements Core{ * identifier of the image **/ private function downloadImage($id){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -416,7 +421,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $stream; + $this->app->setOutput("Images", $stream); } /** @@ -428,7 +433,10 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function addMemberImage($image_id, $member_id){ + private function addMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -461,7 +469,9 @@ class image implements Core{ * @param string $image_id * identifier of the image **/ - private function listMemberImage($image_id, $member_id){ + private function listMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -488,7 +498,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $members; + $this->app->setOutput("Images", $member); } /** @@ -500,7 +510,9 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function detailMemberImage($image_id, $member_id){ + private function detailMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -531,7 +543,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $member; + $this->app->setOutput("Images", $member); } /** @@ -543,7 +555,10 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function removeMemberImage($image_id, $member_id){ + private function removeMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -586,6 +601,10 @@ class image implements Core{ * new status for the member **/ private function updateMemberImage($image_id, $member_id, $status){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + $status = $this->app->getPostParam("status"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } -- cgit v1.2.3 From 0298591cee4365f82e41c077f799270ba1647e5b Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 2 Mar 2016 16:00:46 +0100 Subject: Architecture modification --- server/Test/imageTests.php | 89 ++++++++++++++++------------------------------ server/core/Image.php | 71 ++++++++++++++++++++++++------------ 2 files changed, 79 insertions(+), 81 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 94ff7b6..3af12fc 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -1,35 +1,6 @@ "admin", "password"=>"ae5or6cn", "domain"=>["id"=>"Default"]); -$options["scope"] = Array("project"=>Array("name"=>"admin", "domain"=>["id"=>"Default"])); -$options["authUrl"] = "http://148.60.11.31:5000/v3"; - -$openstack = new OpenStack\OpenStack($options); - -//$identity = $openstack->identityV3(); -//var_dump($identity); -// Since usernames will not be unique across an entire OpenStack installation, -// when authenticating with them you must also provide your domain ID. You do -// not have to do this if you authenticate with a user ID. -/*$token = $identity->generateToken([ - 'user' => [ - 'name' => 'admin', - 'password' => 'ae5or6cn', - 'domain' => [ - 'id' => 'Default' - ] - ] - ]); - */ -//$compute = $openstack->computeV2(["region" => "RegionOne"]); -//$image= $openstack->imagesV2(["region" => "RegionOne"]); -//var_dump($compute->client); -//$servers = $compute->listServers(true); -echo 'toto'; +include('InitTest.php'); +include_once("../core/Image.php"); $image = new Image($App); @@ -43,52 +14,54 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$new_image = $image->create_image($opt); - +//$new_image = $image->createImage($opt); //Liste des images -$images = $image->list_images(); - -echo "Images présentes :"; -echo "
"; - -foreach($images as $i){ - echo $i->name; - if($i->name == "Test"){ - $id_image = $i->id; - $list = $i->tags; - echo $i->status; +$image->action("listImage"); +//$images = $image->listImage(); +$im = $App->show(); +$images = json_decode($im, true)["Images"]; +if(isset($images)){ + echo "Images présentes :"; + echo "
"; + foreach($images as $i){ + echo $i['name']; + echo "
"; } echo "
"; -} -echo "
"; -if(isset($list)){ - foreach ($list as $l) { - echo $l; - echo "
"; - } + if(isset($list)){ + foreach ($list as $l) { + echo $l; + echo "
"; + } +} } +else{ + echo "Aucune image présente\n"; +} + + // Détails Image -//$details = $image->image_details($id_image); +//$details = $image->imageDetails($id_image); -//$image->delete_image('123456'); +//$image->deleteImage('123456'); -//$image->desactivate_image($id_image); -//$image->reactivate_image($id_image); +//$image->desactivateImage($id_image); +//$image->reactivateImage($id_image); //$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso"; -//$image->upload_image($id_image, $file_name); +//$image->uploadImage($id_image, $file_name); -//$image->download_image($id_image); +//$image->downloadImage($id_image); /* $opt_update = Array(); $opt_update['name'] = "Test"; $opt_update['tags'] = null; -$update = $image->update_image($id_image, $opt_update); +$update = $image->updateImage($id_image, $opt_update); echo $update->name; */ diff --git a/server/core/Image.php b/server/core/Image.php index 4025595..ddd8390 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -14,6 +14,8 @@ use OpenStack\Common\Error\BaseError; use OpenStack\Common\Error\NotImplementedError; use OpenStack\Common\Error\UserInputError; +include("CoreInterface.php"); + /** * Image Class of the back-end application * @@ -77,6 +79,7 @@ class image implements Core{ * **/ private function createImage(array $opt){ + $opt = $this->app->getPostParam("opt"); if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect parameter"); @@ -141,7 +144,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $image; + $this->app->setOutput("Images", $image); } /** @@ -151,9 +154,10 @@ class image implements Core{ */ private function listImage(){ try{ + $result = array(); $l = $this->libClass->listImages(); - if(!isset($l)){ // if the list is empty there is no images - $this->app->setOutput("Error", "No image"); + foreach($l as $tmp){ + $result[] = $tmp; } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); @@ -164,8 +168,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $l; - + $this->app->setOutput("Images", $result); } /** @@ -175,9 +178,10 @@ class image implements Core{ * identifier of the image * **/ - private function detailsImage($id){ + private function detailsImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ - // Renvoyer erreur + $this->app->setOutput("Error", "Incorrect id parameter"); } try{ $service = $this->libClass; @@ -185,8 +189,7 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } - - return $image; + $this->app->setOutput("Images", $image); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ @@ -207,7 +210,9 @@ class image implements Core{ * @param array $opt * options for the image creation **/ - private function updateImage($id, array $opt){ + private function updateImage(){ + $id = $this->app->getPostParam("id"); + $opt = $this->app->getPostParam("opt"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } @@ -254,7 +259,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $image; + $this->app->setOutput("Images", $image); } /** @@ -263,9 +268,10 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function deleteImage($id){ + private function deleteImage(){ // si protected = true, demander de le mettre a false // vérifier existence image + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } @@ -285,8 +291,7 @@ class image implements Core{ $this->app->getErrorInstance->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); - } - + } } /** @@ -295,7 +300,8 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function reactivateImage($id){ + private function reactivateImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -324,7 +330,8 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function desactivateImage($id){ + private function desactivateImage(){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -357,6 +364,9 @@ class image implements Core{ * path of the image **/ private function uploadImage($id, $file_name){ + $id = $this->app->getPostParam("id"); + $file_name = $this->app->getPostParam("file_name"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } @@ -390,6 +400,7 @@ class image implements Core{ * identifier of the image **/ private function downloadImage($id){ + $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } @@ -410,7 +421,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $stream; + $this->app->setOutput("Images", $stream); } /** @@ -422,7 +433,10 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function addMemberImage($image_id, $member_id){ + private function addMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -455,7 +469,9 @@ class image implements Core{ * @param string $image_id * identifier of the image **/ - private function listMemberImage($image_id, $member_id){ + private function listMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -482,7 +498,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $members; + $this->app->setOutput("Images", $member); } /** @@ -494,7 +510,9 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function detailMemberImage($image_id, $member_id){ + private function detailMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -525,7 +543,7 @@ class image implements Core{ }catch(NotImplementedError $e){ $this->app->getErrorInstance->NotImplementedHandler($e); } - return $member; + $this->app->setOutput("Images", $member); } /** @@ -537,7 +555,10 @@ class image implements Core{ * @param string $member_id * identifier of the member **/ - private function removeMemberImage($image_id, $member_id){ + private function removeMemberImage(){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } @@ -580,6 +601,10 @@ class image implements Core{ * new status for the member **/ private function updateMemberImage($image_id, $member_id, $status){ + $image_id = $this->app->getPostParam("image_id"); + $member_id = $this->app->getPostParam("member_id"); + $status = $this->app->getPostParam("status"); + if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect parameter image_id"); } -- cgit v1.2.3 From 78a4f8574fb074fef30b2a646c052f68743ee37e Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 9 Mar 2016 14:31:14 +0100 Subject: modif in image constructor --- server/core/Image.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index ddd8390..426cf9d 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -43,18 +43,8 @@ class image implements Core{ if(!isset($app)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - $this->app = $app; - $this->libClass = $app->getLibClass("Image"); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); - } + $this->app = $app; + $this->libClass = $app->getLibClass("Image"); } -- cgit v1.2.3 From 5c6f6c97b7b906476ad5b9ed193e0140dd66f977 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 9 Mar 2016 15:26:01 +0100 Subject: solve syntax error --- server/core/Image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index 426cf9d..b21073b 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -68,7 +68,7 @@ class image implements Core{ * options for the image creation * **/ - private function createImage(array $opt){ + private function createImage(){ $opt = $this->app->getPostParam("opt"); if(!isset($opt)){ -- cgit v1.2.3 From aee0bda9d47f9d279ff9b5b4a4a263fc5613863e Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Wed, 9 Mar 2016 15:39:43 +0100 Subject: correct errors --- server/core/Image.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/core/Image.php b/server/core/Image.php index b21073b..f509cd6 100644 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -353,7 +353,7 @@ class image implements Core{ * @param string $file_name * path of the image **/ - private function uploadImage($id, $file_name){ + private function uploadImage(){ $id = $this->app->getPostParam("id"); $file_name = $this->app->getPostParam("file_name"); @@ -389,7 +389,7 @@ class image implements Core{ * @param string $id * identifier of the image **/ - private function downloadImage($id){ + private function downloadImage(){ $id = $this->app->getPostParam("id"); if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); @@ -590,7 +590,7 @@ class image implements Core{ * @param string $status * new status for the member **/ - private function updateMemberImage($image_id, $member_id, $status){ + private function updateMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); $status = $this->app->getPostParam("status"); -- cgit v1.2.3 From 11dc33c440f97410a2358f7e615d2adc5e69f072 Mon Sep 17 00:00:00 2001 From: EoleDev Date: Tue, 15 Mar 2016 23:45:19 +0100 Subject: Error / Conflict Correction --- server/core/Compute.php | 2 +- server/core/Image.php | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) mode change 100644 => 100755 server/core/Compute.php mode change 100644 => 100755 server/core/Image.php (limited to 'server/core/Image.php') diff --git a/server/core/Compute.php b/server/core/Compute.php old mode 100644 new mode 100755 index 37fc8ad..b658580 --- a/server/core/Compute.php +++ b/server/core/Compute.php @@ -269,7 +269,7 @@ class compute $imageId = $this->app->getPostParam("imageId"); $newName = $this->app->getPostParam("newName"); $adminPass = $this->app->getPostParam("adminPass"); - if(!isset($serverId)|| !isset($imageId) || isset($newName) || isset($adminPass)) ){ + if(!isset($serverId)|| !isset($imageId) || isset($newName) || isset($adminPass)) { $this->app->setOutput("Error", "You'll have to provide server ID and the new image, name and admin password!"); return; } diff --git a/server/core/Image.php b/server/core/Image.php old mode 100644 new mode 100755 index f2af5cc..d37c828 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -70,12 +70,7 @@ class image implements Core{ * options for the image creation * **/ -<<<<<<< HEAD - private function createImage(array $opt){ - -======= private function createImage(){ ->>>>>>> develop $opt = $this->app->getPostParam("opt"); @@ -408,15 +403,9 @@ class image implements Core{ * @param string $id * identifier of the image **/ -<<<<<<< HEAD - private function downloadImage($id){ -<<<<<<< HEAD -======= -======= private function downloadImage(){ ->>>>>>> develop $id = $this->app->getPostParam("id"); ->>>>>>> develop + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } -- cgit v1.2.3 From e01936a73e75350a40fafd80995b1525a11c9da1 Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 09:46:32 +0100 Subject: add commentaries, update error management and correct some mistakes in Image.php, resolve conflict in AppTestClass.php --- server/Test/AppTestClass.php | 12 -- server/core/Image.php | 279 +++++++++++++++++++++---------------------- 2 files changed, 133 insertions(+), 158 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index b398088..5e8efc7 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -1,24 +1,12 @@ >>>>>> Stashed changes -======= -include_once("../core/ErrorManagement.php"); - -use OpenStack\Common\Error\BadResponseError; -use OpenStack\Common\Error\BaseError; -use OpenStack\Common\Error\NotImplementedError; -use OpenStack\Common\Error\UserInputError; ->>>>>>> develop class AppTest{ diff --git a/server/core/Image.php b/server/core/Image.php index d37c828..f309943 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -9,15 +9,13 @@ * * @todo Complete the functions with errors detection and finish the descriptions */ -use OpenStack\Common\Error\BadResponseError; -use OpenStack\Common\Error\BaseError; -use OpenStack\Common\Error\NotImplementedError; -use OpenStack\Common\Error\UserInputError; - +use OpenCloud\Common\Error\BadResponseError; +use OpenCloud\Common\Error\BaseError; +use OpenCloud\Common\Error\NotImplementedError; +use OpenCloud\Common\Error\UserInputError; include("CoreInterface.php"); - /** * Image Class of the back-end application * @@ -37,13 +35,11 @@ class image implements Core{ * * @param App $app the main app object * - * @throws [Type] [] - * * @return Image */ public function __construct($app){ if(!isset($app)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect parameter app"); } $this->app = $app; $this->libClass = $app->getLibClass("Image"); @@ -58,47 +54,46 @@ class image implements Core{ * @return void */ public function action($action){ - - $this->{$action.""}(); - + $this->{$action.""}(); } /** - * Details about an image + * Create a new image * - * @param array $opt - * options for the image creation + * @param array $opt Options for the image creation (name is required, others are optionals) * - **/ + * @return Image + */ private function createImage(){ $opt = $this->app->getPostParam("opt"); - if(!isset($opt)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect parameter opt"); } - try{ - // VOIR SI MAUVAIS TYPE $options = Array(); - if(isset($opt['name'])){ // if the image name already exists -> error + + // Check the image name + if(isset($opt['name'])){ $imagesList = listImage(); - if(isset($images)){ + if(isset($imagesList)){ foreach($imagesList as $image){ - if(strcmp($image->name, $opt['name']) == 0){ - + if(strcmp($image->name, $opt['name']) == 0){ // if the image name already exists -> error + $this->app->setOutput("Error", "Image name already exists"); } } } } else{ - $this->app->setOutput("Error", "Image name already exists"); + $this->app->setOutput("Error", "Missing parameter 'name' for the new image"); } + + // Check optionals arguments if(isset($opt['id'])){ // UUID : nnnnnnnn-nnnn-nnnn-nnnn-nnnnnnnnnnnn if($this->libClass->getImage($opt['id']) != null){ // if the id already exists -> error - + $this->app->setOutput("Error", "Image id already exists"); } $options['id'] = $opt['id']; } @@ -131,11 +126,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $image); @@ -144,7 +139,7 @@ class image implements Core{ /** * List the images of the server * - * @return the list with all images on the server + * @return List of Image */ private function listImage(){ try{ @@ -156,11 +151,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $result); @@ -170,10 +165,10 @@ class image implements Core{ /** * Details about an image * - * @param string $id - * identifier of the image - * - **/ + * @param String $id Identifier of the image + * + * @return Image + */ private function detailsImage(){ $id = $this->app->getPostParam("id"); if(!isset($id)){ @@ -186,29 +181,26 @@ class image implements Core{ if($image == null){ // if the image don't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } - $this->app->setOutput("Images", $image); - }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** - * Details about an image + * Update informations about an image * - * @param string $id - * id of the image - * - * @param array $opt - * options for the image creation - **/ + * @param String $id id of the image + * @param array $opt Options for the image creation + * + * @return Image + */ private function updateImage(){ $id = $this->app->getPostParam("id"); @@ -254,11 +246,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $image); } @@ -266,9 +258,10 @@ class image implements Core{ /** * Delete an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return void + */ private function deleteImage(){ // si protected = true, demander de le mettre a false // vérifier existence image @@ -280,27 +273,28 @@ class image implements Core{ try{ $service = $this->libClass; $image = $this->libClass->getImage($id); - if($image == null){ // if the image don't exists -> error + if($image == null){ // if the image doesn't exists -> error $this->app->setOutput("Error", "Image doesn't exist"); } $image->delete(); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Resactive an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return void + */ private function reactivateImage(){ $id = $this->app->getPostParam("id"); @@ -308,7 +302,6 @@ class image implements Core{ $this->app->setOutput("Error", "Incorrect parameter"); } try{ - // vérifier existence image $service = $this->libClass; $image = $service->getImage($id); if($image == null){ // if the image don't exists -> error @@ -318,20 +311,21 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Desactive an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return void + */ private function desactivateImage(){ $id = $this->app->getPostParam("id"); @@ -349,23 +343,22 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Upload an image * - * @param string $id - * identifier of the image - * - * @param string $file_name - * path of the image - **/ + * @param String $id Identifier of the image + * @param String $file_name Path of the image + * + * @return void + */ private function uploadImage(){ $id = $this->app->getPostParam("id"); $file_name = $this->app->getPostParam("file_name"); @@ -375,7 +368,7 @@ class image implements Core{ $this->app->setOutput("Error", "Incorrect id parameter"); } if(!isset($file_name)){ - $this->app->setOutput("Error", "Incorrect file_name parameter"); + $this->app->setOutput("Error", "Incorrect file name parameter"); } try{ // vérifier existence image @@ -389,25 +382,26 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Download an image * - * @param string $id - * identifier of the image - **/ + * @param String $id Identifier of the image + * + * @return Stream + */ private function downloadImage(){ $id = $this->app->getPostParam("id"); if(!isset($id)){ - $this->app->setOutput("Error", "Incorrect parameter"); + $this->app->setOutput("Error", "Incorrect id parameter"); } try{ // vérifier existence image @@ -420,11 +414,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $stream); } @@ -432,21 +426,20 @@ class image implements Core{ /** * Add a member to image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member - **/ + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * + * @return Member + */ private function addMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ $service = $this->libClass; @@ -456,14 +449,15 @@ class image implements Core{ $this->app->setOutput("Error", "Image doesn't exist"); } $member_id = $image->addMember($member_id); + $this->app->setOutput("Images", $member_id); }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } @@ -471,18 +465,19 @@ class image implements Core{ /** * List members of an image * - * @param string $image_id - * identifier of the image - **/ + * @param String $image_id identifier of the image + * + * @return List of Member + */ private function listMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ // vérifier existence image @@ -492,44 +487,40 @@ class image implements Core{ $this->app->setOutput("Error", "Image doesn't exist"); } $members = $image->listMembers(); - if($member == null){ // if the image don't exists -> error + if($members == null){ // if the image don't exists -> error $this->app->setOutput("Error", "No member"); } }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } - $this->app->setOutput("Images", $member); + $this->app->setOutput("Images", $members); } /** * Show details of a member of an image * - * @param string $image_id - * identifier of the image + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member * - * @param string $member_id - * identifier of the member - **/ + * @return Member + */ private function detailMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ - // vérifier existence image - // on doit être le proprio de l'image - // vérifier membre existe $service = $this->libClass; $image = $service->getImage($id); @@ -544,11 +535,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } $this->app->setOutput("Images", $member); } @@ -556,21 +547,20 @@ class image implements Core{ /** * Remove a member of an image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member - **/ + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * + * @return void + */ private function removeMemberImage(){ $image_id = $this->app->getPostParam("image_id"); $member_id = $this->app->getPostParam("member_id"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ $service = $this->libClass; @@ -587,25 +577,22 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } /** * Update a member of an image * - * @param string $image_id - * identifier of the image - * - * @param string $member_id - * identifier of the member + * @param String $image_id Identifier of the image + * @param String $member_id Identifier of the member + * @param String $status New status for the member * - * @param string $status - * new status for the member + * @return void **/ private function updateMemberImage(){ $image_id = $this->app->getPostParam("image_id"); @@ -613,10 +600,10 @@ class image implements Core{ $status = $this->app->getPostParam("status"); if(!isset($image_id)){ - $this->app->setOutput("Error", "Incorrect parameter image_id"); + $this->app->setOutput("Error", "Incorrect image id parameter"); } if(!isset($member_id)){ - $this->app->setOutput("Error", "Incorrect parameter member_id"); + $this->app->setOutput("Error", "Incorrect member id parameter"); } try{ $service = $this->libClass; @@ -633,11 +620,11 @@ class image implements Core{ }catch(BadResponseError $e){ $this->app->getErrorInstance()->BadResponseHandler($e); }catch(UserInputError $e){ - $this->app->getErrorInstance->UserInputHandler($e); + $this->app->getErrorInstance()->UserInputHandler($e); }catch(BaseError $e){ - $this->app->getErrorInstance->BaseErrorHandler($e); + $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ - $this->app->getErrorInstance->NotImplementedHandler($e); + $this->app->getErrorInstance()->NotImplementedHandler($e); } } -- cgit v1.2.3 From fe0eb3a9e259b4fe09df364f0660ebc62185f9dd Mon Sep 17 00:00:00 2001 From: Yoggzo Date: Thu, 17 Mar 2016 11:34:56 +0100 Subject: add exception management, correct mistakes in error management in Image.php and add function to simplify parameters using in tests --- server/Test/AppTestClass.php | 8 +- server/Test/imageTests.php | 68 ++--- server/core/ErrorManagement.php | 4 + server/core/Image.php | 549 ++++++++++++++++++++++------------------ 4 files changed, 339 insertions(+), 290 deletions(-) (limited to 'server/core/Image.php') diff --git a/server/Test/AppTestClass.php b/server/Test/AppTestClass.php index 5e8efc7..e1631c5 100755 --- a/server/Test/AppTestClass.php +++ b/server/Test/AppTestClass.php @@ -89,10 +89,16 @@ class AppTest{ } public function getPostParam($name){ - + return $this->postParams[$name]; } + + public function setPostParam($name, $value){ + + $this->postParams[$name] = $value; + + } public function setOutput($key, $out){ diff --git a/server/Test/imageTests.php b/server/Test/imageTests.php index 3af12fc..883387d 100644 --- a/server/Test/imageTests.php +++ b/server/Test/imageTests.php @@ -14,55 +14,39 @@ $opt['minDisk'] = 1; $opt['protected'] = false; $opt['minRam'] = 10; -//$new_image = $image->createImage($opt); +//$App->setPostParam('id', 'sdfihlus154dfhj'); +$err = $image->action("createImage"); + //Liste des images $image->action("listImage"); -//$images = $image->listImage(); $im = $App->show(); -$images = json_decode($im, true)["Images"]; -if(isset($images)){ - echo "Images présentes :"; - echo "
"; - foreach($images as $i){ - echo $i['name']; - echo "
"; - } +$images = json_decode($im, true)["Images"]; +$recup; + +echo "Images présentes :"; +echo "
"; +foreach($images as $i){ + $recup = $i; + echo $recup['name']; echo "
"; + //echo $recup['id']; + } +echo "
"; +echo "Erreur capturée: "; +echo "
"; + + /* + //$App->setPostParam('id', $recup['id']); + $App->setPostParam('id', 'sdfihlus154dfhj'); + $err = $image->action("detailsImage"); + $temp = $App->show(); + $ret = json_decode($temp, true)["Images"]; + echo $ret['id']; + */ + //$App->getPostParam("id"); - if(isset($list)){ - foreach ($list as $l) { - echo $l; - echo "
"; - } -} -} -else{ - echo "Aucune image présente\n"; -} - - - -// Détails Image -//$details = $image->imageDetails($id_image); - -//$image->deleteImage('123456'); - -//$image->desactivateImage($id_image); -//$image->reactivateImage($id_image); - -//$file_name = "/home/yogg/Downloads/TinyCore-6.4.1.iso"; -//$image->uploadImage($id_image, $file_name); - -//$image->downloadImage($id_image); -/* -$opt_update = Array(); -$opt_update['name'] = "Test"; -$opt_update['tags'] = null; -$update = $image->updateImage($id_image, $opt_update); -echo $update->name; -*/ ?> \ No newline at end of file diff --git a/server/core/ErrorManagement.php b/server/core/ErrorManagement.php index 4ba3493..ff66339 100755 --- a/server/core/ErrorManagement.php +++ b/server/core/ErrorManagement.php @@ -32,6 +32,10 @@ Class errorManagement{ public function UserInputHandler($error){ } + + public function OtherException($error){ + $this->app->setOutput("Error", $error->getMessage); + } } diff --git a/server/core/Image.php b/server/core/Image.php index f309943..71e19ce 100755 --- a/server/core/Image.php +++ b/server/core/Image.php @@ -131,6 +131,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $image); @@ -156,6 +158,8 @@ class image implements Core{ $this->app->getErrorInstance()->BaseErrorHandler($e); }catch(NotImplementedError $e){ $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); } $this->app->setOutput("Images", $result); @@ -171,26 +175,33 @@ class image implements Core{ */ private function detailsImage(){ $id = $this->app->getPostParam("id"); + if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); - } - try{ - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $this->app->setOutput("Images", $image); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + else{ + echo 'toto'; + $this->app->setOutput("Images", $image); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -209,50 +220,53 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($opt)){ + else if(!isset($opt)){ $this->app->setOutput("Error", "Incorrect opt parameter"); } + else{ + try{ + //vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } - try{ - //vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - - $options = Array(); + $options = Array(); - // Voir vérification des types - if(isset($opt['name'])){ //string - $options['name'] = $opt['name']; - } - if(isset($opt['minDisk'])){ //int - $options['minDisk'] = $opt['minDisk']; - } - if(isset($opt['minRam'])){ // int - $options['minRam'] = $opt['minRam']; - } - if(isset($opt['protected'])){ // boolean - $options['protected'] = $opt['protected']; - } - if(isset($opt['visibility'])){ // public, private - $options['visibility'] = $opt['visibility']; - } - if(isset($opt['tags'])){ // list - $options['tags'] = $opt['tags']; - } - $image->update($options); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $image); + // Voir vérification des types + if(isset($opt['name'])){ //string + $options['name'] = $opt['name']; + } + if(isset($opt['minDisk'])){ //int + $options['minDisk'] = $opt['minDisk']; + } + if(isset($opt['minRam'])){ // int + $options['minRam'] = $opt['minRam']; + } + if(isset($opt['protected'])){ // boolean + $options['protected'] = $opt['protected']; + } + if(isset($opt['visibility'])){ // public, private + $options['visibility'] = $opt['visibility']; + } + if(isset($opt['tags'])){ // list + $options['tags'] = $opt['tags']; + } + $image->update($options); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $image); + } } /** @@ -269,23 +283,26 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Image doesn't exist"); } - - try{ - $service = $this->libClass; - $image = $this->libClass->getImage($id); - if($image == null){ // if the image doesn't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->delete(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + $image = $this->libClass->getImage($id); + if($image == null){ // if the image doesn't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -301,22 +318,27 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->reactivate(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else + { + try{ + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->reactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -332,23 +354,28 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $image->deactivate(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else + { + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $image->deactivate(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -367,26 +394,30 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - if(!isset($file_name)){ + else if(!isset($file_name)){ $this->app->setOutput("Error", "Incorrect file name parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); - $image->uploadData($stream); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = \GuzzleHttp\Psr7\stream_for(fopen($file_name, 'r')); + $image->uploadData($stream); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } } } @@ -403,24 +434,28 @@ class image implements Core{ if(!isset($id)){ $this->app->setOutput("Error", "Incorrect id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $stream = $image->downloadData(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $stream); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $stream = $image->downloadData(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $stream); + } } /** @@ -438,27 +473,31 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member_id = $image->addMember($member_id); - $this->app->setOutput("Images", $member_id); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member_id = $image->addMember($member_id); + $this->app->setOutput("Images", $member_id); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } @@ -476,30 +515,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - // vérifier existence image - $service = $this->libClass; - $image = $service->getImage($image_id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $members = $image->listMembers(); - if($members == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "No member"); - } - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $members); + else{ + try{ + // vérifier existence image + $service = $this->libClass; + $image = $service->getImage($image_id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $members = $image->listMembers(); + if($members == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "No member"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $members); + } } /** @@ -517,31 +560,35 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } - $this->app->setOutput("Images", $member); + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + $this->app->setOutput("Images", $member); + } } /** @@ -559,30 +606,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; - - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->delete(); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + else{ + try{ + $service = $this->libClass; + + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->delete(); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } /** @@ -602,30 +653,34 @@ class image implements Core{ if(!isset($image_id)){ $this->app->setOutput("Error", "Incorrect image id parameter"); } - if(!isset($member_id)){ + else if(!isset($member_id)){ $this->app->setOutput("Error", "Incorrect member id parameter"); } - try{ - $service = $this->libClass; + else{ + try{ + $service = $this->libClass; - $image = $service->getImage($id); - if($image == null){ // if the image don't exists -> error - $this->app->setOutput("Error", "Image doesn't exist"); - } - $member = $image->getMember($member_id); - if($member == null){ // if the member don't exists -> error - $this->app->setOutput("Error", "Member doesn't exist"); - } - $member->updateStatus($status); - }catch(BadResponseError $e){ - $this->app->getErrorInstance()->BadResponseHandler($e); - }catch(UserInputError $e){ - $this->app->getErrorInstance()->UserInputHandler($e); - }catch(BaseError $e){ - $this->app->getErrorInstance()->BaseErrorHandler($e); - }catch(NotImplementedError $e){ - $this->app->getErrorInstance()->NotImplementedHandler($e); - } + $image = $service->getImage($id); + if($image == null){ // if the image don't exists -> error + $this->app->setOutput("Error", "Image doesn't exist"); + } + $member = $image->getMember($member_id); + if($member == null){ // if the member don't exists -> error + $this->app->setOutput("Error", "Member doesn't exist"); + } + $member->updateStatus($status); + }catch(BadResponseError $e){ + $this->app->getErrorInstance()->BadResponseHandler($e); + }catch(UserInputError $e){ + $this->app->getErrorInstance()->UserInputHandler($e); + }catch(BaseError $e){ + $this->app->getErrorInstance()->BaseErrorHandler($e); + }catch(NotImplementedError $e){ + $this->app->getErrorInstance()->NotImplementedHandler($e); + }catch(Exception $e){ + $this->app->getErrorInstance()->OtherException($e); + } + } } } -- cgit v1.2.3