Releases: razshare/catpaw
Fixing File::size()
Dropping bloat and experimental features
4.0.7 feat(CommandInterface): improved api and implementations
Compile native libraries
Changes
You can now compile native Go libraries directly using php catpaw.phar -g
Here's an example give the following go project structure
php catpaw.phar -g src/lib/Go/Resources/CaptureScreen/main.go
You should get an output like this
❯ php catpaw.phar -g src/lib/Go/Resources/CaptureScreen/main.go
<14>1 2024-07-06T11:29:32.118346+00:00 raz catpaw.phar 130078 catpaw.phar - INFO: Go program compiled successfully into `/home/raz/GitHub/tncrazvan/catpaw/catpaw/src/lib/Go/Resources/CaptureScreen/main.so`.
And the resulting shared object and static (without any macros) header file should now be present in the same directory as your go file.
Note
The full name of the flag is --gompile
.
You can now safely proceed and load the library using GoInterface
<?php
use function CatPaw\Core\anyError;
use function CatPaw\Core\asFileName;
use CatPaw\Core\None;
use function CatPaw\Core\ok;
use CatPaw\Core\Unsafe;
use CatPaw\Go\Interfaces\GoInterface;
interface CaptureScreenInterface {
public function CaptureScreen(string $fileName):void;
}
/**
* @param GoInterface $go
* @return Unsafe<None>
*/
function main(GoInterface $go):Unsafe {
return anyError(function() use ($go) {
$library = $go->load(CaptureScreenInterface::class, asFileName(__DIR__, './lib/Go/Resources/CaptureScreen/main.so'))->try();
$library->CaptureScreen('desktop.png');
return ok();
});
}
Command api finalized
3.2.0 feat(command): finalizing command api, using ini files by default ins…
Catpaw V3
Breaking Changes
-
The Unsafe api has changed.
Previously invokingUnsafe::try($error)
would get the value of the object and possibly assign the error by reference to$error
.
This method has been renamed toUnsafe::uwnrap($error)
, which does the same exact thing.
The oldUnsafe::try()
, still exists, but it now serves a different purpose: it still gets the value of the object, but it now throws the error instead of assigning it to an external variable.
The error management section has been updated, you can read more about these changes there. -
The Server api now uses a fluent api.
The router section has been updated, you can read more about these changes there.
New features
-
Introducing Superstyle!
A new way of writing markup documents by describing the DOM using only CSS.
You can read more about Superstyle here. -
The catpaw.phar bundle now offers a baked in pre-commit feature.
You can use it to execute custom commands before committing, like running tests, formatting, linting etc.
The project starters come with a composer scriptdev:install-pre-commit
which you can run to automatically setup your pre-commit hook.\You can also manually setup the pre-commit hook with the
--install-pre-commit
optionphp catpaw.phar --install-pre-commit="composer prod:test"
whatever string you pass in will be executed as a command before committing.\
And of course you can uninstall the current pre-commit hook with
--uninstall-pre-commit
php catpaw.phar --uninstall-pre-commit
Misc
Previously type safety was a bit relaxed due to some issues and frustrations with psalm during development.
The whole project is now type safe and it uses phpstan for static analysis.
File, Directory apis streamlined & Container providers
File, Directory apis streamlined & Container providers
Changes
-
All methods of both
File
andDirectory
classes no longer returnFuture
s.
The Futures are instead resolved internally. -
The
Container
can now set providers throughContainer::provide()
/** * Set a provider or a singleton. * @param string $name * @param callable|object $value The value to set.\ * If the `$value` is a `callable` then the container treats it as a provider, * otherwise it treats it as a cached singleton. * @return void */ public static function provide(string $name, callable|object $value):void;
For example
Container::provide(MyCustomClass::class, fn () => new MyCustomClass($arg1, $arg2));
Your provider function can also expect parameters, which you can pass down through
Container::create
./** * Create an instance or retrieve a cached instance of the given class. * - This method will take care of dependency injections. * - Services and Singletons are backed by an internal cache, which you can reset by invoking `Container::clear()`. * - Providers' results are not cached. * @template T * @param string $name * @param mixed $args * @return Unsafe<T> */ public static function create(string $name, ...$args):Unsafe;
-
The old
Container::set
method is now deprecated in favor ofContainer::provide
.
Goffi & FileName
Changes
- Removing
asPharFileName
which had been briefly introduced to manage file names within the phar archive. - GoffiContract no longer converts file names to phar file names when in phar mode.
Use the newasFileName()->withPhar()
solution instead. asFileName
no longer returns a string, instead it will return a CatPaw\Core\FileName, which implements Stringable, making the change backward compatible.
The new FileName class offers a->withPhar()
method.
This method will detect if the given file name is present in your .phar file first, if not, then the file name will fallback and try to find the file name in your file system.
When you run the following code
<?php
use function CatPaw\Core\asFilename;
function main(){
echo asFileName(__DIR__, 'main.php')->withPhar().PHP_EOL;
}
with
composer prod:start
it will print the file name found on your file system
/home/raz/Desktop/starter/src/main.php
On the other hand, if you build it to a .phar and then run it
composer prod:build &&\
php app.phar
it will print the file name found in your .phar
phar:///home/raz/Desktop/starter/app.phar/src/main.php
Native Gui & Go FFI finalized
Changes
-
Adding some primitives for native gui support, read more here.
-
Goffi feature finalized and adding support for Goffi in phar mode, aka you can run
composer prod:build
and it will work.
This is achieved by dumping the shared objects and header files in the current directory. -
Adding a new function
asPharFileName()
which takes care of converting a given file name into a file name relative to the archive.<?php use function CatPaw\Core\asPharFileName; function main() { echo asPharFileName("./src/main.php").PHP_EOL; }
When running with
composer prod:start
the program will print
/home/raz/Desktop/starter/src/main.php
.Whereas when running with
composer prod:build &&\ php app.phar
the program will print
phar:///home/raz/Desktop/starter/app.phar/src/main.php
.
Goffi strings
Changes
GoffiContract
will not require interfaces to specifyUnsafe
return types.GoffiContract
will now automatically resolve C strings returned from Go according to the given Php interface, read more here.
Goffi & Signals
Changes
- Adding experimental FFI api with Go, read more here.
- Completing the signals api, read more here.