"Fossies" - the Fresh Open Source Software Archive

Member "ampache-5.0.0/src/Module/Application/LocalPlay/AbstractLocalPlayAction.php" (31 Aug 2021, 2850 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 "AbstractLocalPlayAction.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 namespace Ampache\Module\Application\LocalPlay;
   24 
   25 use Ampache\Config\ConfigContainerInterface;
   26 use Ampache\Config\ConfigurationKeyEnum;
   27 use Ampache\Module\Application\ApplicationActionInterface;
   28 use Ampache\Module\Application\Exception\AccessDeniedException;
   29 use Ampache\Module\Application\Exception\ApplicationException;
   30 use Ampache\Module\Authorization\AccessLevelEnum;
   31 use Ampache\Module\Authorization\GuiGatekeeperInterface;
   32 use Ampache\Module\Util\Ui;
   33 use Ampache\Module\Util\UiInterface;
   34 use Psr\Http\Message\ResponseInterface;
   35 use Psr\Http\Message\ServerRequestInterface;
   36 
   37 abstract class AbstractLocalPlayAction implements ApplicationActionInterface
   38 {
   39     private ConfigContainerInterface $configContainer;
   40 
   41     private UiInterface $ui;
   42 
   43     protected function __construct(
   44         ConfigContainerInterface $configContainer,
   45         UiInterface $ui
   46     ) {
   47         $this->configContainer = $configContainer;
   48         $this->ui              = $ui;
   49     }
   50 
   51     public function run(ServerRequestInterface $request, GuiGatekeeperInterface $gatekeeper): ?ResponseInterface
   52     {
   53         if (
   54             $this->configContainer->isFeatureEnabled(ConfigurationKeyEnum::ALLOW_LOCALPLAY_PLAYBACK) === false ||
   55             $gatekeeper->mayAccess(AccessLevelEnum::TYPE_INTERFACE, AccessLevelEnum::LEVEL_USER) === false
   56         ) {
   57             throw new AccessDeniedException();
   58         }
   59 
   60         return $this->handle($request, $gatekeeper);
   61     }
   62 
   63     protected function showRefresh(): void
   64     {
   65         $refresh_limit = $this->configContainer->get(ConfigurationKeyEnum::REFRESH_LIMIT) ?? 0;
   66         if ($refresh_limit > 5) {
   67             $ajax_url      = '?page=localplay&action=command&command=refresh';
   68             require_once Ui::find_template('javascript_refresh.inc.php');
   69         }
   70     }
   71 
   72     /**
   73      * @throws ApplicationException
   74      */
   75     abstract protected function handle(
   76         ServerRequestInterface $request,
   77         GuiGatekeeperInterface $gatekeeper
   78     ): ?ResponseInterface;
   79 }