2016-10-20 22:09:36 -04:00
|
|
|
<?php declare(strict_types=1);
|
2015-11-16 19:30:04 -05:00
|
|
|
/**
|
2017-02-16 11:09:37 -05:00
|
|
|
* Hummingbird Anime List Client
|
2015-11-16 19:30:04 -05:00
|
|
|
*
|
2017-02-16 11:09:37 -05:00
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
2015-11-16 19:30:04 -05:00
|
|
|
*
|
2016-10-20 22:09:36 -04:00
|
|
|
* PHP version 7
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2015-11-16 19:30:04 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2016-08-30 10:01:18 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2018-01-15 14:43:15 -05:00
|
|
|
* @copyright 2015 - 2018 Timothy J. Warren
|
2016-08-30 10:01:18 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2017-02-16 11:09:37 -05:00
|
|
|
* @version 4.0
|
2017-03-07 20:53:58 -05:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
2015-11-16 19:30:04 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Aviat\AnimeClient;
|
|
|
|
|
2018-08-16 12:10:24 -04:00
|
|
|
use Aviat\Ion\ConfigInterface;
|
2016-02-10 17:30:45 -05:00
|
|
|
use Yosymfony\Toml\Toml;
|
|
|
|
|
2018-08-16 12:10:24 -04:00
|
|
|
/**
|
|
|
|
* Load configuration options from .toml files
|
|
|
|
*
|
|
|
|
* @param string $path - Path to load config
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function loadToml(string $path): array
|
2017-12-06 14:40:13 -05:00
|
|
|
{
|
2018-08-16 12:10:24 -04:00
|
|
|
$output = [];
|
|
|
|
$files = glob("{$path}/*.toml");
|
|
|
|
|
|
|
|
foreach ($files as $file)
|
2016-02-10 17:30:45 -05:00
|
|
|
{
|
2018-08-16 12:10:24 -04:00
|
|
|
$key = str_replace('.toml', '', basename($file));
|
|
|
|
$config = Toml::parseFile($file);
|
2016-02-10 17:30:45 -05:00
|
|
|
|
2018-08-16 12:10:24 -04:00
|
|
|
if ($key === 'config')
|
2016-02-10 17:30:45 -05:00
|
|
|
{
|
2018-08-16 12:10:24 -04:00
|
|
|
foreach($config as $name => $value)
|
2016-02-10 17:30:45 -05:00
|
|
|
{
|
2018-08-16 12:10:24 -04:00
|
|
|
$output[$name] = $value;
|
2016-02-10 17:30:45 -05:00
|
|
|
}
|
|
|
|
|
2018-08-16 12:10:24 -04:00
|
|
|
continue;
|
2016-02-10 17:30:45 -05:00
|
|
|
}
|
|
|
|
|
2018-08-16 12:10:24 -04:00
|
|
|
$output[$key] = $config;
|
2016-02-10 17:30:45 -05:00
|
|
|
}
|
2018-08-16 12:10:24 -04:00
|
|
|
|
|
|
|
return $output;
|
2017-12-06 14:40:13 -05:00
|
|
|
}
|
2018-08-16 12:10:24 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check that folder permissions are correct for proper operation
|
|
|
|
*
|
|
|
|
* @param ConfigInterface $config
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function checkFolderPermissions(ConfigInterface $config): array
|
|
|
|
{
|
|
|
|
$errors = [];
|
|
|
|
$publicDir = $config->get('asset_dir');
|
|
|
|
|
|
|
|
$pathMap = [
|
|
|
|
'app/logs' => realpath(__DIR__ . '/../app/logs'),
|
|
|
|
'public/js/cache' => "{$publicDir}/js/cache",
|
|
|
|
'public/images/avatars' => "{$publicDir}/images/avatars",
|
|
|
|
'public/images/anime' => "{$publicDir}/images/anime",
|
|
|
|
'public/images/characters' => "{$publicDir}/images/characters",
|
|
|
|
'public/images/manga' => "{$publicDir}/images/manga",
|
|
|
|
'public/images/people' => "{$publicDir}/images/people",
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($pathMap as $pretty => $actual)
|
|
|
|
{
|
|
|
|
// Make sure the folder exists first
|
|
|
|
if ( ! is_dir($actual))
|
|
|
|
{
|
|
|
|
$errors['missing'][] = $pretty;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$writable = is_writable($actual) && is_executable($actual);
|
|
|
|
|
|
|
|
if ( ! $writable)
|
|
|
|
{
|
|
|
|
$errors['writable'][] = $pretty;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $errors;
|
|
|
|
}
|