"Fossies" - the Fresh Open Source Software Archive

Member "ampache-5.0.0/src/Module/Application/LocalPlay/AddInstanceAction.php" (31 Aug 2021, 2848 Bytes) of package /linux/www/ampache-5.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "AddInstanceAction.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 /*
    3  * vim:set softtabstop=4 shiftwidth=4 expandtab:
    4  *
    5  * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
    6  * Copyright 2001 - 2020 Ampache.org
    7  *
    8  * This program is free software: you can redistribute it and/or modify
    9  * it under the terms of the GNU Affero General Public License as published by
   10  * the Free Software Foundation, either version 3 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This program is distributed in the hope that it will be useful,
   14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  * GNU Affero General Public License for more details.
   17  *
   18  * You should have received a copy of the GNU Affero General Public License
   19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
   20  *
   21  */
   22 
   23 declare(strict_types=0);
   24 
   25 namespace Ampache\Module\Application\LocalPlay;
   26 
   27 use Ampache\Config\ConfigContainerInterface;
   28 use Ampache\Config\ConfigurationKeyEnum;
   29 use Ampache\Module\Application\Exception\AccessDeniedException;
   30 use Ampache\Module\Authorization\AccessLevelEnum;
   31 use Ampache\Module\Authorization\GuiGatekeeperInterface;
   32 use Ampache\Module\Playback\Localplay\LocalPlay;
   33 use Ampache\Module\Util\UiInterface;
   34 use Psr\Http\Message\ResponseFactoryInterface;
   35 use Psr\Http\Message\ResponseInterface;
   36 use Psr\Http\Message\ServerRequestInterface;
   37 use Teapot\StatusCode;
   38 
   39 final class AddInstanceAction extends AbstractLocalPlayAction
   40 {
   41     public const REQUEST_KEY = 'add_instance';
   42 
   43     private ConfigContainerInterface $configContainer;
   44 
   45     private ResponseFactoryInterface $responseFactory;
   46 
   47     private UiInterface $ui;
   48 
   49     public function __construct(
   50         ConfigContainerInterface $configContainer,
   51         ResponseFactoryInterface $responseFactory,
   52         UiInterface $ui
   53     ) {
   54         parent::__construct($configContainer, $ui);
   55         $this->configContainer = $configContainer;
   56         $this->responseFactory = $responseFactory;
   57         $this->ui              = $ui;
   58     }
   59 
   60     protected function handle(
   61         ServerRequestInterface $request,
   62         GuiGatekeeperInterface $gatekeeper
   63     ): ?ResponseInterface {
   64         // This requires 75 or better!
   65         if ($gatekeeper->mayAccess(AccessLevelEnum::TYPE_LOCALPLAY, AccessLevelEnum::LEVEL_MANAGER) === false) {
   66             throw new AccessDeniedException();
   67         }
   68 
   69         // Setup the object
   70         $localplay = new LocalPlay($this->configContainer->get(ConfigurationKeyEnum::LOCALPLAY_CONTROLLER));
   71         $localplay->add_instance($_POST);
   72 
   73         return $this->responseFactory
   74             ->createResponse(StatusCode::FOUND)
   75             ->withHeader(
   76                 'Location',
   77                 sprintf('%s/localplay.php?action=show_instances', $this->configContainer->getWebPath())
   78             );
   79     }
   80 }