Compare commits
No commits in common. "master" and "1.0.2-dev" have entirely different histories.
16 changed files with 463 additions and 577 deletions
2
LICENCE
2
LICENCE
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2023-2024, flashwave <me@flash.moe>
|
||||
Copyright (c) 2023, flashwave <me@flash.moe>
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
# Sasae
|
||||
|
||||
This library has been deprecated and its functionality is now implemented into [Index](https://patchii.net/flash/index).
|
||||
|
||||
## Original header
|
||||
|
||||
Sasae is a simple wrapper around some of Twig's functionality as well as making `Twig\Environment` a little bit more immutable.
|
||||
|
||||
While it's not a lot of extras, I often implement the added functionality across projects.
|
||||
|
@ -12,7 +8,7 @@ The source file structure is meant to be similar to Twig's own.
|
|||
|
||||
## Requirements and Dependencies
|
||||
|
||||
Sasae currently targets **PHP 8.3**.
|
||||
Sasae currently targets **PHP 8.2**.
|
||||
|
||||
No additional requirements and/or dependencies at this time.
|
||||
|
||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
|||
1.1.1
|
||||
1.0.2-dev
|
||||
|
|
|
@ -2,17 +2,18 @@
|
|||
"name": "flashwave/sasae",
|
||||
"description": "A wrapper for Twig with added common functionality.",
|
||||
"type": "library",
|
||||
"homepage": "https://railgun.sh/sasae",
|
||||
"license": "bsd-3-clause-clear",
|
||||
"minimum-stability": "dev",
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=8.3",
|
||||
"twig/twig": "^3.12",
|
||||
"twig/html-extra": "^3.12",
|
||||
"flashwave/index": "^0.2408.40014"
|
||||
"php": ">=8.2",
|
||||
"twig/twig": "^3.7",
|
||||
"twig/html-extra": "^3.7",
|
||||
"flashwave/index": "dev-master"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^11.2",
|
||||
"phpstan/phpstan": "^1.11"
|
||||
"phpunit/phpunit": "^10.2",
|
||||
"phpstan/phpstan": "^1.10"
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
|
|
814
composer.lock
generated
814
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -31,5 +31,11 @@
|
|||
<ignore-tag>implements</ignore-tag>
|
||||
</ignore-tags>
|
||||
</api>
|
||||
<guide format="rst">
|
||||
<source dsn=".">
|
||||
<path>docs</path>
|
||||
</source>
|
||||
<output>guide</output>
|
||||
</guide>
|
||||
</version>
|
||||
</phpdocumentor>
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
<?php
|
||||
// SasaeFilesystemCache.php
|
||||
// Created: 2024-08-04
|
||||
// Updated: 2024-08-04
|
||||
|
||||
namespace Sasae\Cache;
|
||||
|
||||
use Twig\Cache\FilesystemCache as TwigFilesystemCache;
|
||||
|
||||
/**
|
||||
* Extends Twig's filesystem cache implementation with an alternate constructor.
|
||||
*/
|
||||
class SasaeFilesystemCache extends TwigFilesystemCache {
|
||||
/**
|
||||
* @param string $path Directory path to store the cache in.
|
||||
* @param bool $autoReload Whether to refresh the cache if changes are detected.
|
||||
* string $path Directory path to store the cache in.
|
||||
* bool $autoReload Whether to refresh the cache if changes are detected.
|
||||
*/
|
||||
public function __construct(string $path, bool $autoReload) {
|
||||
parent::__construct(
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
<?php
|
||||
// SasaeExtension.php
|
||||
// Created: 2024-08-04
|
||||
// Updated: 2024-08-04
|
||||
|
||||
namespace Sasae\Extension;
|
||||
|
||||
use Index\{ByteFormat,Index};
|
||||
use Sasae\{Sasae,SasaeEnvironment};
|
||||
use Twig\{TwigFilter,TwigFunction};
|
||||
use Twig\Environment as TwigEnvironment;
|
||||
use Index\ByteFormat;
|
||||
use Index\Environment as NdxEnvironment;
|
||||
use Sasae\SasaeEnvironment;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\Extension\AbstractExtension as TwigAbstractExtension;
|
||||
|
||||
/**
|
||||
|
@ -23,9 +20,9 @@ class SasaeExtension extends TwigAbstractExtension {
|
|||
|
||||
public function getFunctions() {
|
||||
return [
|
||||
new TwigFunction('ndx_version', Index::version(...)),
|
||||
new TwigFunction('sasae_version', Sasae::version(...)),
|
||||
new TwigFunction('twig_version', fn() => TwigEnvironment::VERSION),
|
||||
new TwigFunction('ndx_version', NdxEnvironment::getIndexVersion(...)),
|
||||
new TwigFunction('sasae_version', SasaeEnvironment::getSasaeVersion(...)),
|
||||
new TwigFunction('twig_version', SasaeEnvironment::getTwigVersion(...)),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
// SasaeFilesystemLoader.php
|
||||
// Created: 2024-08-04
|
||||
// Updated: 2024-08-04
|
||||
|
||||
namespace Sasae\Loader;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
// Sasae.php
|
||||
// Created: 2024-08-04
|
||||
// Updated: 2024-08-04
|
||||
|
||||
namespace Sasae;
|
||||
|
||||
/**
|
||||
* Provides information about the Sasae library.
|
||||
*/
|
||||
final class Sasae {
|
||||
public const PATH_SOURCE = __DIR__;
|
||||
public const PATH_ROOT = self::PATH_SOURCE . DIRECTORY_SEPARATOR . '..';
|
||||
public const PATH_VERSION = self::PATH_ROOT . DIRECTORY_SEPARATOR . 'VERSION';
|
||||
|
||||
/**
|
||||
* Gets the current version of the Sasae library.
|
||||
*
|
||||
* Reads the VERSION file in the root of the Sasae directory.
|
||||
* Returns 0.0.0 if reading the file failed for any reason.
|
||||
*
|
||||
* @return string Current version string.
|
||||
*/
|
||||
public static function version(): string {
|
||||
if(!is_file(self::PATH_VERSION))
|
||||
return '0.0.0';
|
||||
|
||||
$version = file_get_contents(self::PATH_VERSION);
|
||||
if($version === false)
|
||||
return '0.0.0';
|
||||
|
||||
return trim($version);
|
||||
}
|
||||
}
|
|
@ -1,8 +1,4 @@
|
|||
<?php
|
||||
// SasaeContext.php
|
||||
// Created: 2024-08-04
|
||||
// Updated: 2024-08-04
|
||||
|
||||
namespace Sasae;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
@ -74,7 +70,7 @@ class SasaeContext implements Stringable {
|
|||
/**
|
||||
* Renders the template to a string, taking additional variables that are not commit to local set.
|
||||
*
|
||||
* @param array<string, mixed>|null $vars Additional local variables, nullable to avoid additional function calls.
|
||||
* @param ?array<string, mixed> $vars Additional local variables, nullable to avoid additional function calls.
|
||||
* @return string Rendered template.
|
||||
*/
|
||||
public function render(?array $vars = null): string {
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
<?php
|
||||
// SasaeEnvironment.php
|
||||
// Created: 2023-08-24
|
||||
// Updated: 2024-08-04
|
||||
// Updated: 2023-08-24
|
||||
|
||||
namespace Sasae;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use UnexpectedValueException;
|
||||
use Index\Version;
|
||||
use Sasae\Cache\SasaeFilesystemCache;
|
||||
use Sasae\Extension\SasaeExtension;
|
||||
use Sasae\Loader\SasaeFilesystemLoader;
|
||||
use Twig\{TwigFilter,TwigFunction,TwigTest};
|
||||
use Twig\Environment as TwigEnvironment;
|
||||
use Twig\TwigFilter;
|
||||
use Twig\TwigFunction;
|
||||
use Twig\TwigTest;
|
||||
use Twig\Cache\CacheInterface as TwigCacheInterface;
|
||||
use Twig\Extension\ExtensionInterface as TwigExtensionInterface;
|
||||
use Twig\Extra\Html\HtmlExtension as TwigHtmlExtension;
|
||||
|
@ -23,6 +26,10 @@ use Twig\Loader\LoaderInterface as TwigLoaderInterface;
|
|||
class SasaeEnvironment {
|
||||
private TwigEnvironment $env;
|
||||
|
||||
private static ?string $sasaeVersionString = null;
|
||||
private static ?Version $sasaeVersion = null;
|
||||
private static ?Version $twigVersion = null;
|
||||
|
||||
/**
|
||||
* @param TwigLoaderInterface|string $loader A template loader instance or a path.
|
||||
* @param TwigCacheInterface|array<string>|string|null $cache A caching driver.
|
||||
|
@ -148,4 +155,50 @@ class SasaeEnvironment {
|
|||
public function render(string $name, array $vars = []): string {
|
||||
return $this->env->render($name, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version of the Sasae library.
|
||||
*
|
||||
* @return Version
|
||||
*/
|
||||
public static function getSasaeVersion(): Version {
|
||||
if(self::$sasaeVersion === null)
|
||||
self::$sasaeVersion = Version::parse(self::getSasaeVersionString());
|
||||
return self::$sasaeVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version of the Sasae library as a string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getSasaeVersionString(): string {
|
||||
if(self::$sasaeVersionString === null) {
|
||||
$body = file_get_contents(__DIR__ . '/../VERSION');
|
||||
if($body === false)
|
||||
throw new UnexpectedValueException('Was unable to read VERSION file.');
|
||||
self::$sasaeVersionString = trim($body);
|
||||
}
|
||||
return self::$sasaeVersionString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version of the Twig library.
|
||||
*
|
||||
* @return Version
|
||||
*/
|
||||
public static function getTwigVersion(): Version {
|
||||
if(self::$twigVersion === null)
|
||||
self::$twigVersion = Version::parse(TwigEnvironment::VERSION);
|
||||
return self::$twigVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version of the Twig library as a string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getTwigVersionString(): string {
|
||||
return TwigEnvironment::VERSION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,22 @@
|
|||
<?php
|
||||
// SasaeTest.php
|
||||
// Created: 2024-08-04
|
||||
// Updated: 2024-08-04
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use PHPUnit\Framework\Attributes\CoversClass;
|
||||
use Index\{Index,XString};
|
||||
use Sasae\{Sasae,SasaeContext,SasaeEnvironment};
|
||||
use Index\Environment;
|
||||
use Index\XString;
|
||||
use Sasae\SasaeContext;
|
||||
use Sasae\SasaeEnvironment;
|
||||
use Sasae\Cache\SasaeFilesystemCache;
|
||||
use Sasae\Extension\SasaeExtension;
|
||||
use Sasae\Loader\SasaeFilesystemLoader;
|
||||
use Twig\Environment as TwigEnvironment;
|
||||
|
||||
#[CoversClass(Sasae::class)]
|
||||
#[CoversClass(SasaeContext::class)]
|
||||
#[CoversClass(SasaeEnvironment::class)]
|
||||
#[CoversClass(SasaeFilesystemCache::class)]
|
||||
#[CoversClass(SasaeExtension::class)]
|
||||
#[CoversClass(SasaeFilesystemLoader::class)]
|
||||
/**
|
||||
* @covers SasaeContext
|
||||
* @covers SasaeEnvironment
|
||||
* @covers SasaeExtension
|
||||
* @covers SasaeFilesystemCache
|
||||
* @covers SasaeFilesystemLoader
|
||||
*/
|
||||
final class SasaeTest extends TestCase {
|
||||
public function testEverything(): void {
|
||||
$env = new SasaeEnvironment(
|
||||
|
@ -31,9 +28,9 @@ final class SasaeTest extends TestCase {
|
|||
|
||||
$env->addGlobal('global_var', 'Sasae global var');
|
||||
$env->addGlobal('expect', [
|
||||
'ndx_version' => Index::version(),
|
||||
'sasae_version' => Sasae::version(),
|
||||
'twig_version' => TwigEnvironment::VERSION,
|
||||
'ndx_version' => (string)Environment::getIndexVersion(),
|
||||
'sasae_version' => SasaeEnvironment::getSasaeVersionString(),
|
||||
'twig_version' => SasaeEnvironment::getTwigVersionString(),
|
||||
]);
|
||||
|
||||
$env->addFilter('test_filter', fn($text) => ('filter:' . $text));
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
$path = (function($path) {
|
||||
if(!str_starts_with($path, '/'))
|
||||
die('Cannot be bothered to support non-UNIX style paths, sorry!' . PHP_EOL);
|
||||
|
||||
while($path !== '/') {
|
||||
$vPath = $path . DIRECTORY_SEPARATOR . 'VERSION';
|
||||
if(is_file($vPath))
|
||||
return $vPath;
|
||||
|
||||
$path = dirname($path);
|
||||
}
|
||||
})(__DIR__);
|
||||
|
||||
$version = file_get_contents($path);
|
||||
if($version === false)
|
||||
die('Failed to read VERSION file.' . PHP_EOL);
|
||||
$version = trim($version);
|
||||
|
||||
$workingDir = getcwd();
|
||||
try {
|
||||
chdir(dirname($path));
|
||||
echo shell_exec(sprintf('git tag v%s', $version));
|
||||
echo shell_exec(sprintf('git push origin v%s', $version));
|
||||
} finally {
|
||||
chdir($workingDir);
|
||||
}
|
||||
|
||||
echo $version . PHP_EOL;
|
|
@ -1,8 +1,8 @@
|
|||
#!/usr/bin/env bash
|
||||
#!/bin/bash
|
||||
|
||||
pushd .
|
||||
cd $(dirname "$0")
|
||||
|
||||
./update-headers
|
||||
php update-headers.php
|
||||
|
||||
popd
|
||||
|
|
1
tools/update-headers → tools/update-headers.php
Executable file → Normal file
1
tools/update-headers → tools/update-headers.php
Executable file → Normal file
|
@ -1,4 +1,3 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
// the point of index was so that i wouldn't have to copy things between projects
|
||||
// here i am copying things from index
|
Reference in a new issue