<?php
namespace App\Controller;
use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;
use Symfony\VarDumper;
use PHPMailer\PHPMailer\PHPMailer;
use Doctrine\DBAL\ParameterType;
class Base extends AbstractKasController
{
public function __construct(RequestStack $requestStack, Database $db, PageInfo $pageInfo)
{
parent::__construct($requestStack, $db, $pageInfo);
$this->request = $requestStack->getCurrentRequest();
}
public function clearCacheDev(): Response
{
if ($this->request->query->get('key') !== 'Gz3mtvbLIQW55Tn0fRi1') {
throw $this->createAccessDeniedException();
}
$kernel = new Kernel('dev', true);
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'cache:clear'
]);
$output = new BufferedOutput();
try {
$application->run($input, $output);
} catch (\Exception $e) {
return new Response($e->getMessage());
}
$content = $output->fetch();
return new Response($content);
}
/**
* @Route("/cache-clear")
* @Route("/cache-clear-prod")
* @return Response
*/
public function clearCacheProd(): Response
{
if ($this->request->query->get('key') !== 'Gz3mtvbLIQW55Tn0fRi1') {
throw $this->createAccessDeniedException();
}
$kernel = new Kernel('prod', true);
$application = new Application($kernel);
$application->setAutoExit(false);
$input = new ArrayInput([
'cache:clear'
]);
$output = new BufferedOutput();
try {
$application->run($input, $output);
} catch (\Exception $e) {
return new Response($e->getMessage());
}
$content = $output->fetch();
return new Response($content);
}
/**
* @Route("/403")
* @Route("/error403")
* @return Response
*/
public function error403(): Response
{
return $this->render('/pages/403.html.twig', [
'pageinfo' => $this->pageInfo
]);
}
/**
* @Route("/404")
* @Route("/error404")
* @return Response
*/
public function error404(): Response
{
return $this->render('/pages/404.html.twig', [
'pageinfo' => $this->pageInfo
]);
}
/**
* @Route("/500")
* @Route("/error500")
* @return Response
*/
public function error500(): Response
{
return $this->render('/pages/500.html.twig', [
'pageinfo' => $this->pageInfo
]);
}
/**
* @Route("/test-mail")
* @return Response
*/
/*public function testMail(): Response
{
$mail = new PHPMailer(true);
$mail->setLanguage('cz');
$mail->isSMTP();
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => false
)
);
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = getenv('AP_EMAIL_HOST');
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
$mail->Username = getenv('AP_EMAIL_USR');
$mail->Password = getenv('AP_EMAIL_PWD');
$mail->setFrom(getenv('AP_EMAIL'), 'test');
$mail->CharSet = "utf-8";
$mail->Subject = 'Pozdrav z webmaxu';
$mail->addAddress('kalous.it@gmail.com');
$mail->msgHTML('<h2>Ahoj Tome</h2><p>toto je testovacà mail.</p><hr/><p>Odesláno z kas.webmax.cloud</p>');
//send the message, check for errors
if ($mail->send()) {
$html = 'ok';
} else {
$html = 'error';
}
return new Response('test mail - '.$html);
}*/
}
?>