Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

php - Using PSR- RequestHandlerInterface, returns error, without error log. Where am i doing wrong?

I tried the convert this

require 'vendor/autoload.php';

ini_set('memory_limit', '1G');
set_time_limit(300); // 5 minutes execution

use ComposerConsoleApplication;
use SymfonyComponentConsoleInputArrayInput;
use SymfonyComponentConsoleOutputBufferedOutput as Output;
use SymfonyComponentConsoleOutputOutputInterface;


putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer');

$cikis = new Output;
$giris = new ArrayInput([
    'command' => 'remove', 
    'packages' => ['trying/trying'], 
    '--working-dir' => getcwd(),
]);

$application = new Application();
$application->setAutoExit(false);
$application->run($giris, $cikis);

echo $input;
echo '<hr>';
echo '<pre>' . $cikis->fetch() . '</pre>';

to routed PSR-RequesthandlerInterface compatible version. I write like this

namespace xxxxxx;
use IlluminateSupportArr;
use LaminasDiactorosResponseHtmlResponse;
use PsrHttpMessageResponseInterface as Response;
use PsrHttpMessageServerRequestInterface as Request;
use PsrHttpServerRequestHandlerInterface;
use ComposerConsoleApplication;
use SymfonyComponentConsoleInputArrayInput;
use SymfonyComponentConsoleOutputBufferedOutput as Output;
use SymfonyComponentConsoleOutputOutputInterface;
use xxxoterpackagexxothername

class xxxx implements RequestHandlerInterface {
        protected $view;
        public $packadi;
        public $SiteAnaSayfa;
        public $komut;
    
        public function __construct($view)
        {
            $this->view = $view;
        }
        public function handle(Request $request): Response
        {

        
            if (Arr::post($request->getQueryParams(), 'packadi') != NULL && Arr::post($request->getQueryParams(), 'komut') != NULL)
            { 
                $this->$packadi = Arr::post($request->getQueryParams(), 'packadi');
                $this->$komut = Arr::post($request->getQueryParams(), 'komut');
                $this->yap();
                $SiteAnaSayfa = app(Paths::class)['base'];

                return new JsonResponse({'cikis' , $view->render()});
        
            } 
    
        }
        public function yap() {
                if (null !== $request->getAttribute('actor')->assertAdmin()) {
                if (isset($this->packadi)) {

                ini_set('memory_limit', '1G');
                set_time_limit(300); // 5 minutes execution
                
                putenv('COMPOSER_HOME=' . $SiteAnaSayfa . '/vendor/bin/composer');

                $output = new Output;
                $input = new ArrayInput([
                    'command' => $this->$komut, 
                    'packages' => [$this->$packadi], 
                    '--working-dir' => $SiteAnaSayfa,
                ]);

                $application = new Application();
                $application->setAutoExit(false);
                $application->run($input, $output);
                $cikis = '<hr>';
                $cikis .= '<pre>' . $output->fetch() . '</pre>';
                $view = $this->view->make($cikis);
            }
        }
        }
}   

when i route this its returns error page (There is no wrong in routing its reaching to this class) Im checking logs file but no shown error. Am i do it wrong way. Its my first experience working with this. And my php knowledge is low for understand to wrong thing. But im trying to learn.

edit i forget to explain error page how looks

{
  "type": "error",
  "content": [
    "Oops! Something went wrong. Please reload the page and try again."
  ],
  "controls": false
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...