aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/CoreBundle/Repository/SiteCredentialRepository.php
blob: 316ecc75020e5400ef272a7e97664a50b6aa8910 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php

namespace Wallabag\CoreBundle\Repository;

/**
 * SiteCredentialRepository.
 */
class SiteCredentialRepository extends \Doctrine\ORM\EntityRepository
{
    /**
     * Retrieve one username/password for the given host and userId.
     *
     * @param string $host
     * @param int    $userId
     *
     * @return null|array
     */
    public function findOneByHostAndUser($host, $userId)
    {
        return $this->createQueryBuilder('s')
            ->select('s.username', 's.password')
            ->where('s.host = :hostname')->setParameter('hostname', $host)
            ->andWhere('s.user = :userId')->setParameter('userId', $userId)
            ->setMaxResults(1)
            ->getQuery()
            ->getOneOrNullResult();
    }
}