mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-10 10:25:36 +08:00
v3 base
This commit is contained in:
63
src/StaticPHP/Attribute/Artifact/AfterBinaryExtract.php
Normal file
63
src/StaticPHP/Attribute/Artifact/AfterBinaryExtract.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Artifact;
|
||||
|
||||
/**
|
||||
* Attribute to register a hook that runs after binary extraction completes.
|
||||
*
|
||||
* This is useful for post-extraction tasks like:
|
||||
* - Setting executable permissions
|
||||
* - Creating symlinks
|
||||
* - Platform-specific binary setup
|
||||
* - Verifying binary integrity
|
||||
*
|
||||
* The callback method signature should be:
|
||||
* ```php
|
||||
* function(string $target_path, string $platform): void
|
||||
* ```
|
||||
*
|
||||
* - `$target_path`: The directory where binary was extracted
|
||||
* - `$platform`: The current platform string (e.g., 'linux-x86_64')
|
||||
*
|
||||
* Multiple hooks can be registered for the same artifact using IS_REPEATABLE.
|
||||
* Use the `$platforms` parameter to filter which platforms the hook should run on.
|
||||
*
|
||||
* @example
|
||||
* ```php
|
||||
* #[AfterBinaryExtract('zig')]
|
||||
* public function setupZig(string $target_path, string $platform): void
|
||||
* {
|
||||
* // Setup zig after extraction (runs on all platforms)
|
||||
* chmod("{$target_path}/zig", 0755);
|
||||
* }
|
||||
*
|
||||
* #[AfterBinaryExtract('pkg-config', ['linux-x86_64', 'linux-aarch64'])]
|
||||
* public function setupPkgConfigLinux(string $target_path): void
|
||||
* {
|
||||
* // Linux-specific setup for pkg-config
|
||||
* symlink("{$target_path}/bin/pkg-config", "/usr/local/bin/pkg-config");
|
||||
* }
|
||||
*
|
||||
* #[AfterBinaryExtract('openssl', ['darwin-aarch64'])]
|
||||
* public function patchOpensslMacM1(string $target_path): void
|
||||
* {
|
||||
* // macOS ARM64 specific patches
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class AfterBinaryExtract
|
||||
{
|
||||
/**
|
||||
* @param string $artifact_name The name of the artifact this hook applies to
|
||||
* @param string[] $platforms Platform filters (empty array means all platforms).
|
||||
* Valid values: 'linux-x86_64', 'linux-aarch64', 'darwin-x86_64',
|
||||
* 'darwin-aarch64', 'windows-x86_64', etc.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $artifact_name,
|
||||
public array $platforms = []
|
||||
) {}
|
||||
}
|
||||
50
src/StaticPHP/Attribute/Artifact/AfterSourceExtract.php
Normal file
50
src/StaticPHP/Attribute/Artifact/AfterSourceExtract.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Artifact;
|
||||
|
||||
/**
|
||||
* Attribute to register a hook that runs after source extraction completes.
|
||||
*
|
||||
* This is useful for post-extraction tasks like:
|
||||
* - Patching source files
|
||||
* - Removing unnecessary directories (tests, docs, etc.)
|
||||
* - Applying platform-specific fixes
|
||||
* - Renaming or reorganizing files
|
||||
*
|
||||
* The callback method signature should be:
|
||||
* ```php
|
||||
* function(string $target_path): void
|
||||
* ```
|
||||
*
|
||||
* - `$target_path`: The directory where source was extracted
|
||||
*
|
||||
* Multiple hooks can be registered for the same artifact using IS_REPEATABLE.
|
||||
*
|
||||
* @example
|
||||
* ```php
|
||||
* #[AfterSourceExtract('php-src')]
|
||||
* public function patchPhpSrc(string $target_path): void
|
||||
* {
|
||||
* // Apply patches after php-src is extracted
|
||||
* FileSystem::replaceFileStr("{$target_path}/configure", 'old', 'new');
|
||||
* }
|
||||
*
|
||||
* #[AfterSourceExtract('openssl')]
|
||||
* public function cleanupOpenssl(string $target_path): void
|
||||
* {
|
||||
* // Remove unnecessary directories
|
||||
* FileSystem::removeDir("{$target_path}/test");
|
||||
* FileSystem::removeDir("{$target_path}/fuzz");
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class AfterSourceExtract
|
||||
{
|
||||
/**
|
||||
* @param string $artifact_name The name of the artifact this hook applies to
|
||||
*/
|
||||
public function __construct(public string $artifact_name) {}
|
||||
}
|
||||
45
src/StaticPHP/Attribute/Artifact/BinaryExtract.php
Normal file
45
src/StaticPHP/Attribute/Artifact/BinaryExtract.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Artifact;
|
||||
|
||||
/**
|
||||
* Attribute to completely take over the binary extraction process for an artifact.
|
||||
*
|
||||
* When this attribute is applied to a method, the standard extraction logic is bypassed,
|
||||
* and the annotated method is responsible for extracting the binary files.
|
||||
*
|
||||
* The callback method signature should be:
|
||||
* ```php
|
||||
* function(Artifact $artifact, string $source_file, string $target_path, string $platform): void
|
||||
* ```
|
||||
*
|
||||
* - `$artifact`: The artifact instance being extracted
|
||||
* - `$source_file`: Path to the downloaded archive or directory
|
||||
* - `$target_path`: The resolved target extraction path from config
|
||||
* - `$platform`: The current platform string (e.g., 'linux-x86_64', 'darwin-aarch64')
|
||||
*
|
||||
* @example
|
||||
* ```php
|
||||
* #[BinaryExtract('special-tool', ['linux-x86_64', 'linux-aarch64'])]
|
||||
* public function extractSpecialTool(Artifact $artifact, string $source_file, string $target_path): void
|
||||
* {
|
||||
* // Custom binary extraction logic
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
readonly class BinaryExtract
|
||||
{
|
||||
/**
|
||||
* @param string $artifact_name The name of the artifact this extraction handler applies to
|
||||
* @param string[] $platforms Platform filters (empty array means all platforms).
|
||||
* Valid values: 'linux-x86_64', 'linux-aarch64', 'darwin-x86_64',
|
||||
* 'darwin-aarch64', 'windows-x86_64', etc.
|
||||
*/
|
||||
public function __construct(
|
||||
public string $artifact_name,
|
||||
public array $platforms = []
|
||||
) {}
|
||||
}
|
||||
11
src/StaticPHP/Attribute/Artifact/CustomBinary.php
Normal file
11
src/StaticPHP/Attribute/Artifact/CustomBinary.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Artifact;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class CustomBinary
|
||||
{
|
||||
public function __construct(public string $artifact_name, public array $support_os) {}
|
||||
}
|
||||
11
src/StaticPHP/Attribute/Artifact/CustomSource.php
Normal file
11
src/StaticPHP/Attribute/Artifact/CustomSource.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Artifact;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class CustomSource
|
||||
{
|
||||
public function __construct(public string $artifact_name) {}
|
||||
}
|
||||
39
src/StaticPHP/Attribute/Artifact/SourceExtract.php
Normal file
39
src/StaticPHP/Attribute/Artifact/SourceExtract.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Artifact;
|
||||
|
||||
/**
|
||||
* Attribute to completely take over the source extraction process for an artifact.
|
||||
*
|
||||
* When this attribute is applied to a method, the standard extraction logic is bypassed,
|
||||
* and the annotated method is responsible for extracting the source files.
|
||||
*
|
||||
* The callback method signature should be:
|
||||
* ```php
|
||||
* function(Artifact $artifact, string $source_file, string $target_path): void
|
||||
* ```
|
||||
*
|
||||
* - `$artifact`: The artifact instance being extracted
|
||||
* - `$source_file`: Path to the downloaded archive or directory
|
||||
* - `$target_path`: The resolved target extraction path from config
|
||||
*
|
||||
* @example
|
||||
* ```php
|
||||
* #[SourceExtract('weird-package')]
|
||||
* public function extractWeirdPackage(Artifact $artifact, string $source_file, string $target_path): void
|
||||
* {
|
||||
* // Custom extraction logic
|
||||
* shell_exec("tar -xf {$source_file} -C {$target_path} --strip-components=2");
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
readonly class SourceExtract
|
||||
{
|
||||
/**
|
||||
* @param string $artifact_name The name of the artifact this extraction handler applies to
|
||||
*/
|
||||
public function __construct(public string $artifact_name) {}
|
||||
}
|
||||
18
src/StaticPHP/Attribute/Doctor/CheckItem.php
Normal file
18
src/StaticPHP/Attribute/Doctor/CheckItem.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Doctor;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class CheckItem
|
||||
{
|
||||
public mixed $callback = null;
|
||||
|
||||
public function __construct(
|
||||
public string $item_name,
|
||||
public ?string $limit_os = null,
|
||||
public int $level = 100,
|
||||
public bool $manual = false,
|
||||
) {}
|
||||
}
|
||||
14
src/StaticPHP/Attribute/Doctor/FixItem.php
Normal file
14
src/StaticPHP/Attribute/Doctor/FixItem.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Doctor;
|
||||
|
||||
/**
|
||||
* Indicate a method is a fix item for doctor check.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class FixItem
|
||||
{
|
||||
public function __construct(public string $name) {}
|
||||
}
|
||||
11
src/StaticPHP/Attribute/Doctor/OptionalCheck.php
Normal file
11
src/StaticPHP/Attribute/Doctor/OptionalCheck.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Doctor;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)]
|
||||
class OptionalCheck
|
||||
{
|
||||
public function __construct(public array $check) {}
|
||||
}
|
||||
14
src/StaticPHP/Attribute/Package/AfterStage.php
Normal file
14
src/StaticPHP/Attribute/Package/AfterStage.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated method should be executed after a specific stage of the build process for a given package.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class AfterStage
|
||||
{
|
||||
public function __construct(public string $package_name, public string $stage, public ?string $only_when_package_resolved = null) {}
|
||||
}
|
||||
14
src/StaticPHP/Attribute/Package/BeforeStage.php
Normal file
14
src/StaticPHP/Attribute/Package/BeforeStage.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated method should be executed before a specific stage of the build process for a given package.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class BeforeStage
|
||||
{
|
||||
public function __construct(public string $package_name, public string $stage, public ?string $only_when_package_resolved = null) {}
|
||||
}
|
||||
17
src/StaticPHP/Attribute/Package/BuildFor.php
Normal file
17
src/StaticPHP/Attribute/Package/BuildFor.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Mark a method as building for a specific OS.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class BuildFor
|
||||
{
|
||||
/**
|
||||
* @param 'Darwin'|'Linux'|'Windows' $os The operating system to build for PHP_OS_FAMILY
|
||||
*/
|
||||
public function __construct(public string $os) {}
|
||||
}
|
||||
14
src/StaticPHP/Attribute/Package/CustomPhpConfigureArg.php
Normal file
14
src/StaticPHP/Attribute/Package/CustomPhpConfigureArg.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates a custom configure argument for PHP build process.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class CustomPhpConfigureArg
|
||||
{
|
||||
public function __construct(public string $os = '') {}
|
||||
}
|
||||
14
src/StaticPHP/Attribute/Package/Extension.php
Normal file
14
src/StaticPHP/Attribute/Package/Extension.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated class defines a PHP extension.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
readonly class Extension
|
||||
{
|
||||
public function __construct(public string $name) {}
|
||||
}
|
||||
8
src/StaticPHP/Attribute/Package/Info.php
Normal file
8
src/StaticPHP/Attribute/Package/Info.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Info {}
|
||||
8
src/StaticPHP/Attribute/Package/InitPackage.php
Normal file
8
src/StaticPHP/Attribute/Package/InitPackage.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class InitPackage {}
|
||||
14
src/StaticPHP/Attribute/Package/Library.php
Normal file
14
src/StaticPHP/Attribute/Package/Library.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated class defines a library package.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
readonly class Library
|
||||
{
|
||||
public function __construct(public string $name) {}
|
||||
}
|
||||
11
src/StaticPHP/Attribute/Package/PatchBeforeBuild.php
Normal file
11
src/StaticPHP/Attribute/Package/PatchBeforeBuild.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class PatchBeforeBuild
|
||||
{
|
||||
public function __construct() {}
|
||||
}
|
||||
11
src/StaticPHP/Attribute/Package/ResolveBuild.php
Normal file
11
src/StaticPHP/Attribute/Package/ResolveBuild.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated method is responsible for initializing the build process for a target package.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD)]
|
||||
class ResolveBuild {}
|
||||
14
src/StaticPHP/Attribute/Package/Stage.php
Normal file
14
src/StaticPHP/Attribute/Package/Stage.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated method defines a specific stage in a package.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class Stage
|
||||
{
|
||||
public function __construct(public string $name) {}
|
||||
}
|
||||
14
src/StaticPHP/Attribute/Package/Target.php
Normal file
14
src/StaticPHP/Attribute/Package/Target.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
/**
|
||||
* Indicates that the annotated class defines a target.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
readonly class Target
|
||||
{
|
||||
public function __construct(public string $name) {}
|
||||
}
|
||||
8
src/StaticPHP/Attribute/Package/Validate.php
Normal file
8
src/StaticPHP/Attribute/Package/Validate.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute\Package;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
class Validate {}
|
||||
11
src/StaticPHP/Attribute/PatchDescription.php
Normal file
11
src/StaticPHP/Attribute/PatchDescription.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace StaticPHP\Attribute;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
|
||||
readonly class PatchDescription
|
||||
{
|
||||
public function __construct(public string $description) {}
|
||||
}
|
||||
Reference in New Issue
Block a user