Various tweaks

This commit is contained in:
Timothy Warren 2023-10-02 11:48:34 -04:00
parent c8b642be1c
commit 7559f79ef6
4 changed files with 25 additions and 7 deletions

View File

@ -106,7 +106,7 @@ final class Model
public function createListItem(array $data, string $type = 'anime'): ?Request
{
$mediaId = $this->getMediaId($data, $type);
if ($mediaId === NULL)
if ($mediaId === NULL || $mediaId === "undefined")
{
return NULL;
}

View File

@ -14,6 +14,7 @@
namespace Aviat\AnimeClient;
use Aura\Router\Generator;
use Aviat\Ion\ConfigInterface;
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
@ -24,7 +25,7 @@ use Psr\Http\Message\ServerRequestInterface;
/**
* Base for routing/url classes
*/
class RoutingBase
abstract class RoutingBase
{
/**
* Config Object
@ -36,6 +37,11 @@ class RoutingBase
*/
protected ServerRequestInterface $request;
/**
* Aura url generator
*/
protected Generator $routerUrl;
/**
* Constructor
*
@ -47,6 +53,7 @@ class RoutingBase
{
$this->config = $container->get('config');
$this->request = $container->get('request');
$this->routerUrl = $container->get('aura-router')->getGenerator();
}
/**

View File

@ -54,6 +54,11 @@ class UrlGenerator extends RoutingBase
return implode('/', $args);
}
public function fromRoute(string $route, array $args = []): string
{
return $this->hostUrl($this->routerUrl->generate($route, $args));
}
/**
* Generate a proper url from the path
*/
@ -81,9 +86,7 @@ class UrlGenerator extends RoutingBase
$path = implode('/', $pathSegments);
$scheme = $this->config->get('secure_urls') !== FALSE ? 'https:' : 'http:';
return "{$scheme}//{$this->host}/{$path}";
return $this->hostUrl($path);
}
/**
@ -103,6 +106,14 @@ class UrlGenerator extends RoutingBase
throw new InvalidArgumentException("Invalid default type: '{$type}'");
}
private function hostUrl(string $path): string
{
$path = trim($path, '/');
$scheme = $this->config->get('secure_urls') !== FALSE ? 'https:' : 'http:';
return "{$scheme}//{$this->host}/{$path}";
}
}
// End of UrlGenerator.php

View File

@ -25,9 +25,9 @@ const SRC_DIR = __DIR__;
const USER_AGENT = "Tim's Anime Client/5.2";
// Regex patterns
const ALPHA_SLUG_PATTERN = '[a-z_]+';
const ALPHA_SLUG_PATTERN = '[a-zA-Z_]+';
const NUM_PATTERN = '[0-9]+';
const SLUG_PATTERN = '[a-z0-9\-]+';
const SLUG_PATTERN = '[a-zA-Z0-9\-]+';
const SLUG_SPACE_PATTERN = '[a-zA-Z_\- ]+';
// Why doesn't this already exist?