2016-10-20 22:09:36 -04:00
|
|
|
<?php declare(strict_types=1);
|
2016-04-14 19:10:03 -04:00
|
|
|
/**
|
2017-02-15 16:13:32 -05:00
|
|
|
* Hummingbird Anime List Client
|
2016-04-14 19:10:03 -04:00
|
|
|
*
|
2018-08-22 13:48:27 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2016-04-14 19:10:03 -04:00
|
|
|
*
|
2021-02-04 11:57:01 -05:00
|
|
|
* PHP version 8
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2017-02-15 16:13:32 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2016-08-30 10:01:18 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2021-01-13 01:52:03 -05:00
|
|
|
* @copyright 2015 - 2021 Timothy J. Warren
|
2016-08-30 10:01:18 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-12-10 17:06:50 -05:00
|
|
|
* @version 5.2
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2017-01-11 10:34:24 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient\Model;
|
2016-04-14 19:10:03 -04:00
|
|
|
|
2018-01-18 16:21:45 -05:00
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
2017-01-05 13:41:32 -05:00
|
|
|
use PDOException;
|
2016-04-14 19:10:03 -04:00
|
|
|
|
2020-04-21 19:22:56 -04:00
|
|
|
use Query\QueryBuilderInterface;
|
2019-07-10 10:20:37 -04:00
|
|
|
use function Query;
|
|
|
|
|
2016-04-14 19:10:03 -04:00
|
|
|
/**
|
|
|
|
* Base model for anime and manga collections
|
|
|
|
*/
|
2022-03-03 17:26:09 -05:00
|
|
|
class Collection extends DB
|
|
|
|
{
|
2019-01-07 14:29:15 -05:00
|
|
|
/**
|
|
|
|
* The query builder object
|
|
|
|
*/
|
2021-02-12 19:17:39 -05:00
|
|
|
protected ?QueryBuilderInterface $db;
|
2016-04-14 19:10:03 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new collection object
|
|
|
|
*/
|
|
|
|
public function __construct(ContainerInterface $container)
|
2017-09-14 16:18:13 -04:00
|
|
|
{
|
2017-02-15 15:35:41 -05:00
|
|
|
parent::__construct($container);
|
2016-04-14 19:10:03 -04:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2019-07-10 10:20:37 -04:00
|
|
|
$this->db = Query($this->dbConfig);
|
2016-04-14 19:10:03 -04:00
|
|
|
}
|
2021-02-12 19:17:39 -05:00
|
|
|
catch (PDOException)
|
2019-12-09 16:17:25 -05:00
|
|
|
{
|
|
|
|
$this->db = Query([
|
|
|
|
'type' => 'sqlite',
|
|
|
|
'file' => ':memory:',
|
|
|
|
]);
|
|
|
|
}
|
2016-04-14 19:10:03 -04:00
|
|
|
|
|
|
|
// Is database valid? If not, set a flag so the
|
|
|
|
// app can be run without a valid database
|
2018-10-05 14:32:05 -04:00
|
|
|
if ($this->dbConfig['type'] === 'sqlite')
|
2016-04-14 19:10:03 -04:00
|
|
|
{
|
2018-10-05 14:32:05 -04:00
|
|
|
$dbFileName = $this->dbConfig['file'];
|
2016-04-14 19:10:03 -04:00
|
|
|
|
2021-02-10 17:17:51 -05:00
|
|
|
if ($dbFileName !== ':memory:')
|
2016-04-14 19:10:03 -04:00
|
|
|
{
|
2021-02-10 17:17:51 -05:00
|
|
|
$rawFile = file_get_contents($dbFileName);
|
|
|
|
$dbFile = ($rawFile !== FALSE) ? $rawFile : '';
|
2021-02-12 19:17:39 -05:00
|
|
|
$this->db = (str_starts_with($dbFile, 'SQLite format 3')) ? $this->db : NULL;
|
2016-04-14 19:10:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-03 13:25:10 -05:00
|
|
|
|
2022-03-03 17:26:09 -05:00
|
|
|
// End of Collection.php
|