2

I defined my postParams where I want to pass "hash" value from db.

What I am trying to accomplish is that if hash exists in my Session table to return TRUE and if not to return FLASE.

Problem is my code always returns TRUE.

What I am missing?

$postData = $this->requirePostParams(['hash']);

$this->container->get('app')->formService(
        $this->data['hash']
    );

if ($postData['hash']) {

    $hash = $this->get('app')->getSessionRepository()->find($this->data['hash']);

    if (!$hash) return false;

} else {

    return true;

}

And my requirePostParams works fine! (tested on other functions)

protected function requirePostParams($params) {

    $currentRequest = $this->get('request_stack')->getCurrentRequest();

    $postData = $currentRequest->request->all();

    $postContent = json_decode($currentRequest->getContent(), true);

    if(!empty($postContent)) $postData = $postContent;

    $this->data = $postData;

    $missingParams = [];

    foreach ($params as $param) {

        if (!array_key_exists($param, $postData)) {

            $missingParams[] = $param;

        }

    }

}

And my service:

$findHash = $this->getSessionRepository()->findOneBy([
        'hash' => $hash
    ]);
Tommy J
  • 109
  • 9

1 Answers1

0

As xmike mentioned in comments, function requirePostParams returns nothing. That's why $postData['hash'] is never set.

Try to replace $postData['hash'] with $this->data['hash']:

$this->requirePostParams(['hash']);

$this->container->get('app')->formService(
        $this->data['hash']
    );

if ($this->data['hash']) {

    $hash = $this->get('app')->getSessionRepository()->find($this->data['hash']);

    if (!$hash) return false;

} else {

    return true;

}
alexsakhnov
  • 311
  • 2
  • 8