for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Controllers\Ajax;
use App\Models\PostModel;
use Core\AjaxController;
use Core\Traits\StringFunctions;
use Core\Container;
class PostVerification extends AjaxController
{
use StringFunctions;
Core\Traits\StringFunctions
$childNodes
App\Controllers\Ajax\PostVerification
protected $slug;
public function __construct(Container $container)
$this->loadModules[] = 'Slug';
parent::__construct($container);
}
/**
* checks if the slug is unique
* @return bool is unique
* @throws \Core\JsonException
* @throws \Exception
*/
public function isSlugUnique()
$this->onlyAdmin();
$this->onlyPost();
$postSlug = $this->request->getData("postSlug");
$postId = $this->request->getData("postId");
$data = false;
if (!$this->slug->isSlugValid($postSlug) || !$this->isInt($postId)) {
echo json_encode($data);
die();
exit
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.
$postModel = new PostModel($this->container);
$data = $postModel->isPostSlugUnique($postSlug);
if ($data === false) //slug is not unique, but could be from the same post
$slugOfId = $postModel->getPostSlugFromId($postId);
if ($slugOfId === $postSlug) {
//it's the same post, return true
$data = true;