partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

DeletePreferenceAction.php (1326B)


      1 <?php
      2 
      3 namespace PartKeepr\SystemPreferenceBundle\Action;
      4 
      5 use Dunglas\ApiBundle\Action\ActionUtilTrait;
      6 use Dunglas\ApiBundle\Exception\RuntimeException;
      7 use PartKeepr\CategoryBundle\Exception\RootNodeNotFoundException;
      8 use PartKeepr\SystemPreferenceBundle\Service\SystemPreferenceService;
      9 use Symfony\Component\HttpFoundation\Request;
     10 
     11 /**
     12  * Returns the tree root node.
     13  */
     14 class DeletePreferenceAction
     15 {
     16     use ActionUtilTrait;
     17 
     18     /**
     19      * @var SystemPreferenceService
     20      */
     21     private $systemPreferenceService;
     22 
     23     public function __construct(
     24         SystemPreferenceService $systemPreferenceService
     25     ) {
     26         $this->systemPreferenceService = $systemPreferenceService;
     27     }
     28 
     29     /**
     30      * Retrieves a collection of resources.
     31      *
     32      * @param Request $request
     33      *
     34      * @throws \Exception                                 If the format is invalid
     35      * @throws RuntimeException|RootNodeNotFoundException
     36      *
     37      * @return array|\Dunglas\ApiBundle\Model\PaginatorInterface|\Traversable
     38      */
     39     public function __invoke(Request $request)
     40     {
     41         if ($request->request->has('preferenceKey')) {
     42             $this->systemPreferenceService->deletePreference($request->request->get('preferenceKey'));
     43         } else {
     44             throw new \Exception('Invalid format');
     45         }
     46     }
     47 }