Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
OaiResumption
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 8
110
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 restoreParams
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
6
 saveParams
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
 getId
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setResumptionParameters
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getResumptionParameters
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setExpiry
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getExpiry
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Row Definition for oai_resumption
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Db_Row
25 * @author   Demian Katz <demian.katz@villanova.edu>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org Main Site
28 */
29
30namespace VuFind\Db\Row;
31
32use DateTime;
33use VuFind\Db\Entity\OaiResumptionEntityInterface;
34
35/**
36 * Row Definition for oai_resumption
37 *
38 * @category VuFind
39 * @package  Db_Row
40 * @author   Demian Katz <demian.katz@villanova.edu>
41 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
42 * @link     https://vufind.org Main Site
43 *
44 * @property int    $id
45 * @property string $params
46 * @property string $expires
47 */
48class OaiResumption extends RowGateway implements OaiResumptionEntityInterface
49{
50    /**
51     * Constructor
52     *
53     * @param \Laminas\Db\Adapter\Adapter $adapter Database adapter
54     */
55    public function __construct($adapter)
56    {
57        parent::__construct('id', 'oai_resumption', $adapter);
58    }
59
60    /**
61     * Extract an array of parameters from the object.
62     *
63     * @return array Original saved parameters.
64     *
65     * @deprecated Use parse_str() instead
66     */
67    public function restoreParams()
68    {
69        $parts = explode('&', $this->params);
70        $params = [];
71        foreach ($parts as $part) {
72            [$key, $value] = explode('=', $part);
73            $key = urldecode($key);
74            $value = urldecode($value);
75            $params[$key] = $value;
76        }
77        return $params;
78    }
79
80    /**
81     * Encode an array of parameters into the object.
82     *
83     * @param array $params Parameters to save.
84     *
85     * @return void
86     *
87     * @deprecated Use \VuFind\Db\Service\OaiResumptionService::createAndPersistToken()
88     */
89    public function saveParams($params)
90    {
91        ksort($params);
92        $processedParams = [];
93        foreach ($params as $key => $value) {
94            $processedParams[] = urlencode($key) . '=' . urlencode($value);
95        }
96        $this->params = implode('&', $processedParams);
97    }
98
99    /**
100     * Id getter
101     *
102     * @return int
103     */
104    public function getId(): int
105    {
106        return $this->id;
107    }
108
109    /**
110     * Resumption parameters setter
111     *
112     * @param ?string $params Resumption parameters.
113     *
114     * @return OaiResumptionEntityInterface
115     */
116    public function setResumptionParameters(?string $params): OaiResumptionEntityInterface
117    {
118        $this->params = $params;
119        return $this;
120    }
121
122    /**
123     * Get resumption parameters.
124     *
125     * @return ?string
126     */
127    public function getResumptionParameters(): ?string
128    {
129        return $this->params;
130    }
131
132    /**
133     * Expiry date setter.
134     *
135     * @param DateTime $dateTime Expiration date
136     *
137     * @return OaiResumptionEntityInterface
138     */
139    public function setExpiry(DateTime $dateTime): OaiResumptionEntityInterface
140    {
141        $this->expires = $dateTime->format('Y-m-d H:i:s');
142        return $this;
143    }
144
145    /**
146     * Get expiry date.
147     *
148     * @return DateTime
149     */
150    public function getExpiry(): DateTime
151    {
152        return DateTime::createFromFormat('Y-m-d H:i:s', $this->expires);
153    }
154}