├── .gitignore ├── peachpie ├── README.md ├── tools │ ├── sfpp.php │ └── module_converter.php └── port │ ├── src │ └── iTXTech │ │ └── SimpleFramework │ │ ├── ThreadManager.php │ │ ├── Worker.php │ │ ├── Thread.php │ │ ├── Util │ │ └── ClassLoader.php │ │ └── Scheduler │ │ └── AsyncTask.php │ ├── sfloader.php │ └── autoload.php ├── sf ├── sf.cmd ├── src └── iTXTech │ └── SimpleFramework │ ├── Scheduler │ ├── OnCompletionListener.php │ ├── AsyncWorker.php │ ├── Task.php │ ├── TaskHandler.php │ ├── AsyncTask.php │ └── AsyncPool.php │ ├── Util │ ├── Curl │ │ ├── Preprocessor.php │ │ ├── Callback.php │ │ ├── InterfaceSelector.php │ │ ├── Cookie.php │ │ └── Response.php │ ├── ReversePriorityQueue.php │ ├── Timer.php │ ├── StringUtil.php │ ├── Platform │ │ └── Platform.php │ ├── FrameworkProperties.php │ ├── Curl.php │ └── ClassLoader.php │ ├── Console │ ├── LoggerHandler.php │ ├── Option │ │ ├── Exception │ │ │ ├── ParseException.php │ │ │ ├── MissingArgumentException.php │ │ │ ├── UnrecognizedOptionException.php │ │ │ ├── AmbiguousOptionException.php │ │ │ ├── MissingOptionException.php │ │ │ └── AlreadySelectedException.php │ │ ├── OptionValidator.php │ │ ├── OptionGroup.php │ │ ├── CommandLine.php │ │ ├── OptionBuilder.php │ │ └── Options.php │ ├── Command │ │ ├── Command.php │ │ ├── ClearCommand.php │ │ ├── StopCommand.php │ │ ├── UnpackModuleCommand.php │ │ ├── PackModuleCommand.php │ │ ├── HelpCommand.php │ │ ├── VersionCommand.php │ │ ├── PackSFCommand.php │ │ └── ModulesCommand.php │ ├── CmdLineOpt │ │ ├── CmdLineOpt.php │ │ ├── LoggerSwitches.php │ │ ├── CurlOpts.php │ │ ├── FrameworkInfo.php │ │ └── Properties.php │ ├── CommandProcessor.php │ ├── ConsoleReader.php │ ├── TextFormat.php │ ├── Logger.php │ └── Terminal.php │ ├── Module │ ├── ModuleDependencyResolver.php │ ├── FallbackLoader.php │ ├── Packer.php │ ├── HotPatchThread.php │ ├── ModuleInfo.php │ └── WraithSpireMDR.php │ ├── ThreadManager.php │ ├── Thread.php │ ├── Worker.php │ └── SimpleFramework.php ├── examples ├── win_screen_off.php ├── manual_autoload.php ├── preload.php ├── wrapper.php ├── multi_interface.php ├── single_script.php ├── cli_options.php ├── curl_async.php ├── curl.php └── windows.php ├── README.md ├── sfloader.php └── autoload.php /.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | .idea/ 3 | modules/ 4 | data/ 5 | 6 | config.json 7 | *.log 8 | *.phar 9 | -------------------------------------------------------------------------------- /peachpie/README.md: -------------------------------------------------------------------------------- 1 | # SimpleFramework for [PeachPie](https://github.com/peachpiecompiler/peachpie/) 2 | 3 | * [PeachPie](https://github.com/peachpiecompiler/peachpie/) is a `PHP compiler to .NET` 4 | * `SimpleFramework` aims to provide identical experience on both `ZendVM` and `PeachPie`, but we are currently working in progress. 5 | 6 | ## Tools 7 | 8 | * [Module Converter](tools/module_converter.php) - *Filter source files and convert resource files into `php` files.* 9 | * [SimpleFramework for PeachPie Runtime Generator](tools/sfpp.php) - *Generate `SimpleFramework for PeachPie runtime`* 10 | 11 | ## Use [THIS BRANCH FOR NOW](https://github.com/iTXTech/SimpleFramework/tree/peachpie) 12 | -------------------------------------------------------------------------------- /sf: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | DIR="$(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd)" 3 | cd "$DIR" 4 | 5 | if [ "$PHP_BINARY" == "" ]; then 6 | if [ -f ./bin/php7/bin/php ]; then 7 | PHP_BINARY="./bin/php7/bin/php" 8 | elif [[ ! -z $(type php) ]]; then 9 | PHP_BINARY=$(type -p php) 10 | else 11 | echo "Valid PHP 7 executable not found, please visit https://github.com/iTXTech/SimpleFramework" 12 | exit 1 13 | fi 14 | fi 15 | 16 | if [ "$SF_FILE" == "" ]; then 17 | if [ -f ./SimpleFramework.phar ]; then 18 | SF_FILE="./SimpleFramework.phar" 19 | elif [ -f ./src/iTXTech/SimpleFramework/SimpleFramework.php ]; then 20 | SF_FILE="./src/iTXTech/SimpleFramework/SimpleFramework.php" 21 | else 22 | echo "SimpleFramework executable not found, please visit https://github.com/iTXTech/SimpleFramework" 23 | exit 1 24 | fi 25 | fi 26 | 27 | exec "$PHP_BINARY" "$SF_FILE" $@ 28 | -------------------------------------------------------------------------------- /sf.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | title SimpleFramework 3 | cd /d %~dp0 4 | 5 | REM For Powershell users, do '$env:PHP_BINARY="phpxx"' to set php binary path. 6 | REM For CMD users, do "set PHP_BINARY=phpxx" to set php binary path. 7 | if not defined PHP_BINARY ( 8 | if exist bin\php\php.exe ( 9 | set PHP_BINARY=bin\php\php.exe 10 | ) else ( 11 | set PHP_BINARY=php 12 | ) 13 | ) 14 | 15 | if exist SimpleFramework.phar ( 16 | set SF_FILE=SimpleFramework.phar 17 | ) else ( 18 | set SF_FILE=src\iTXTech\SimpleFramework\SimpleFramework.php 19 | ) 20 | 21 | REM php 7.2 requires VC++ 2015, so XP is not supported 22 | if exist bin\mintty.exe ( 23 | start "" bin\mintty.exe -o Columns=88 -o Rows=32 -o AllowBlinking=0 -o FontQuality=3 -o Font="Consolas" -o FontHeight=10 -o CursorType=0 -o CursorBlinks=1 -h error -t "SimpleFramework" -w max %PHP_BINARY% %SF_FILE% %* 24 | ) else ( 25 | powershell %PHP_BINARY% %SF_FILE% %* 26 | ) 27 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Scheduler/OnCompletionListener.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Scheduler; 25 | 26 | interface OnCompletionListener{ 27 | } 28 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Util/Curl/Preprocessor.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Util\Curl; 25 | 26 | interface Preprocessor{ 27 | public function process(Curl $curl); 28 | } 29 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Util/Curl/Callback.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Util\Curl; 25 | 26 | interface Callback{ 27 | public function onResponse(Response $response); 28 | } 29 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/LoggerHandler.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console; 25 | 26 | interface LoggerHandler{ 27 | public static function println(string $message); 28 | } 29 | -------------------------------------------------------------------------------- /peachpie/tools/sfpp.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | /* 25 | * This script generates SimpleFramework for PeachPie runtime. 26 | */ 27 | 28 | require_once $_ENV["SF_HOME"] . DIRECTORY_SEPARATOR . "sfloader.php"; 29 | 30 | //todo 31 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Util/ReversePriorityQueue.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Util; 25 | 26 | class ReversePriorityQueue extends \SplPriorityQueue{ 27 | 28 | public function compare($priority1, $priority2){ 29 | return (int) -($priority1 - $priority2); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Option/Exception/ParseException.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Option\Exception; 25 | 26 | class ParseException extends \Exception{ 27 | public function __construct(string $message){ 28 | parent::__construct($message, 0, null); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Module/ModuleDependencyResolver.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Module; 25 | 26 | interface ModuleDependencyResolver{ 27 | /** 28 | * @param Module $module 29 | * @return bool 30 | */ 31 | public function resolveDependencies(Module $module): bool; 32 | 33 | public function init(); 34 | } 35 | -------------------------------------------------------------------------------- /examples/win_screen_off.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | /* 25 | SF_SCRIPT_REQUIREMENTS_STARTS 26 | {"php":7.4,"exts":{"ffi":""},"os":"win","info":""} 27 | SF_SCRIPT_REQUIREMENTS_ENDS 28 | */ 29 | 30 | use iTXTech\SimpleFramework\Util\Platform\WindowsPlatform; 31 | 32 | require_once "../autoload.php"; 33 | 34 | WindowsPlatform::postMessage(-1, 0x0112, 0xF170, 2); 35 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Command/Command.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Command; 25 | 26 | interface Command{ 27 | public function getName(): string; 28 | 29 | public function getUsage(): string; 30 | 31 | public function getDescription(): string; 32 | 33 | public function execute(string $command, array $args): bool; 34 | } 35 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Util/Timer.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Util; 25 | 26 | class Timer{ 27 | private $timestamp; 28 | private $diff; 29 | 30 | public function start(){ 31 | $this->timestamp = microtime(true); 32 | } 33 | 34 | public function stop() : float{ 35 | $this->diff = microtime(true) - $this->timestamp; 36 | return $this->diff; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Module/FallbackLoader.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Module; 25 | 26 | use iTXTech\SimpleFramework\Console\Logger; 27 | 28 | class FallbackLoader extends Module{ 29 | public function load(){ 30 | Logger::debug($this->getName() . " has been loaded."); 31 | } 32 | 33 | public function unload(){ 34 | Logger::debug($this->getName() . " has been unloaded."); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/manual_autoload.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | //disable autoload.php 25 | define("SF_LOADER_AUTO_INIT", false); 26 | 27 | require_once "../autoload.php"; 28 | 29 | use iTXTech\SimpleFramework\Console\Logger; 30 | use iTXTech\SimpleFramework\Console\Terminal; 31 | use iTXTech\SimpleFramework\Initializer; 32 | 33 | Initializer::loadSimpleFramework("sf.phar"); 34 | Initializer::initClassLoader(); 35 | 36 | Terminal::init(); 37 | Logger::info("SimpleFramework Location: " . iTXTech\SimpleFramework\PATH); 38 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Command/ClearCommand.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Command; 25 | 26 | class ClearCommand implements Command{ 27 | public function getName() : string{ 28 | return "clear"; 29 | } 30 | 31 | public function getUsage() : string{ 32 | return "clear"; 33 | } 34 | 35 | public function getDescription() : string{ 36 | return "Clears the screen."; 37 | } 38 | 39 | public function execute(string $command, array $args) : bool{ 40 | echo "\x1bc"; 41 | return true; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Option/Exception/MissingArgumentException.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Option\Exception; 25 | 26 | use iTXTech\SimpleFramework\Console\Option\Option; 27 | 28 | class MissingArgumentException extends ParseException{ 29 | /** @var Option */ 30 | private $option; 31 | 32 | public function __construct(Option $option){ 33 | parent::__construct("Missing argument for option: " . $option->getKey()); 34 | $this->option = $option; 35 | } 36 | 37 | public function getOption() : Option{ 38 | return $this->option; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Command/StopCommand.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Command; 25 | 26 | use iTXTech\SimpleFramework\Framework; 27 | 28 | class StopCommand implements Command{ 29 | private $framework; 30 | 31 | public function getName() : string{ 32 | return "stop"; 33 | } 34 | 35 | public function getUsage() : string{ 36 | return "stop"; 37 | } 38 | 39 | public function getDescription() : string{ 40 | return "Stop the framework and all the modules."; 41 | } 42 | 43 | public function execute(string $command, array $args) : bool{ 44 | Framework::getInstance()->shutdown(); 45 | return true; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Option/Exception/UnrecognizedOptionException.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Option\Exception; 25 | 26 | use iTXTech\SimpleFramework\Console\Option\Option; 27 | 28 | class UnrecognizedOptionException extends ParseException{ 29 | /** @var Option */ 30 | private $option; 31 | 32 | public function __construct(string $message, string $option){ 33 | parent::__construct($message); 34 | $this->option = $option; 35 | } 36 | 37 | /** 38 | * Returns the unrecognized option. 39 | * 40 | * @return Option 41 | */ 42 | public function getOption() : Option{ 43 | return $this->option; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Module/Packer.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Module; 25 | 26 | use iTXTech\SimpleFramework\Util\StringUtil; 27 | 28 | abstract class Packer{ 29 | public const VARIANT_TYPICAL = 0; 30 | public const VARIANT_COMPOSER = 1; 31 | 32 | public function processFile(int $variant, \Phar $phar, string $file, string $path){ 33 | if($variant == self::VARIANT_COMPOSER or 34 | ($variant == self::VARIANT_TYPICAL 35 | and !StringUtil::startsWith($path, "vendor") 36 | and !StringUtil::endsWith($path, "composer.lock") 37 | and !StringUtil::endsWith($path, "composer.json"))){ 38 | $phar->addFile($file, $path); 39 | } 40 | } 41 | 42 | public function end(\Phar $phar){ 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Scheduler/AsyncWorker.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Scheduler; 25 | 26 | use iTXTech\SimpleFramework\Console\Logger; 27 | use iTXTech\SimpleFramework\Worker; 28 | 29 | class AsyncWorker extends Worker{ 30 | 31 | private $id; 32 | 33 | public function __construct($id){ 34 | $this->id = $id; 35 | } 36 | 37 | public function run(){ 38 | $this->registerClassLoader(); 39 | gc_enable(); 40 | ini_set("memory_limit", -1); 41 | 42 | global $store; 43 | $store = []; 44 | } 45 | 46 | public function handleException(\Throwable $e){ 47 | Logger::logException($e); 48 | } 49 | 50 | public function getThreadName(){ 51 | return "Asynchronous Worker #" . $this->id; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Util/Curl/InterfaceSelector.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Util\Curl; 25 | 26 | abstract class InterfaceSelector{ 27 | private static $GLOBAL_INTERFACES = ""; 28 | private static $INTERFACES = [];//compatible with multi threads 29 | 30 | public static function registerInterface(string $if, int $chance = 1){ 31 | for($i = 0; $i < $chance; $i++){ 32 | self::$GLOBAL_INTERFACES .= $if . ";"; 33 | } 34 | self::$GLOBAL_INTERFACES = substr(self::$GLOBAL_INTERFACES, 1); 35 | } 36 | 37 | public static function select() : string{ 38 | if(self::$GLOBAL_INTERFACES == ""){ 39 | return ""; 40 | } 41 | if(self::$INTERFACES == []){ 42 | self::$INTERFACES = explode(";", self::$GLOBAL_INTERFACES); 43 | } 44 | return self::$INTERFACES[array_rand(self::$INTERFACES)]; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Util/StringUtil.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Util; 25 | 26 | abstract class StringUtil{ 27 | public static function startsWith(string $str, string $prefix) : bool{ 28 | return substr($str, 0, strlen($prefix)) === $prefix; 29 | } 30 | 31 | public static function endsWith(string $str, string $suffix) : bool{ 32 | return substr($str, strlen($str) - strlen($suffix), strlen($suffix)) === $suffix; 33 | } 34 | 35 | public static function contains(string $str, string $s) : bool{ 36 | return strpos($str, $s) !== false; 37 | } 38 | 39 | public static function between(string $string, string $after, string $before, int $offset = 0) : string{ 40 | return substr($string, $pos = strpos($string, $after, $offset) + strlen($after), 41 | strpos($string, $before, $pos) - $pos); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/preload.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | // .\sf p=example\preload.php -h 25 | // and see if -d option has been modified 26 | 27 | // .\sf p=phar://modules/A.phar/src/B/Preload.php p=phar://modules/AA.phar/preload.php p=p.php 28 | 29 | use iTXTech\SimpleFramework\Console\CmdLineOpt\CmdLineOpt; 30 | use iTXTech\SimpleFramework\Console\Option\CommandLine; 31 | use iTXTech\SimpleFramework\Console\Option\OptionBuilder; 32 | use iTXTech\SimpleFramework\Console\Option\Options; 33 | 34 | CmdLineOpt::reg(ExtraOpts::class); 35 | 36 | class ExtraOpts extends CmdLineOpt{ 37 | public static function register(Options $options){ 38 | $options->addOption((new OptionBuilder("d"))->longOpt("test") 39 | ->desc("Test opt")->hasArg()->argName("test-arg")->build()); 40 | } 41 | 42 | public static function process(CommandLine $cmd, Options $options){ 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Option/Exception/AmbiguousOptionException.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Option\Exception; 25 | 26 | class AmbiguousOptionException extends UnrecognizedOptionException{ 27 | /** @var array */ 28 | private $matchingOptions; 29 | 30 | public function __construct(string $option, array $matchingOptions){ 31 | parent::__construct($this->createMessage($option, $matchingOptions), $option); 32 | $this->matchingOptions = $matchingOptions; 33 | } 34 | 35 | public function getMatchingOptions() : array{ 36 | return $this->matchingOptions; 37 | } 38 | 39 | private function createMessage(string $option, array $matchingOptions){ 40 | $buf = "Ambiguous option:" . $option . "' (could be: "; 41 | foreach($matchingOptions as $option){ 42 | $buf .= "'" . $option . "', "; 43 | } 44 | $buf = substr($buf, 0, strlen($buf) - 2); 45 | return $buf; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Option/Exception/MissingOptionException.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Option\Exception; 25 | 26 | use iTXTech\SimpleFramework\Console\Option\OptionGroup; 27 | 28 | class MissingOptionException extends ParseException{ 29 | /** @var array */ 30 | private $missingOptions; 31 | 32 | public function __construct(array $missingOptions){ 33 | parent::__construct($this->createMessage($missingOptions)); 34 | $this->missingOptions = $missingOptions; 35 | } 36 | 37 | /** 38 | * @return string[]|OptionGroup[] 39 | */ 40 | public function getMissingOptions() : array{ 41 | return $this->missingOptions; 42 | } 43 | 44 | private function createMessage(array $missingOptions) : string{ 45 | $buf = "Missing required option" . (count($missingOptions) === 1 ? "" : "s") . ": "; 46 | $buf .= implode(", ", $missingOptions); 47 | 48 | return $buf; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Scheduler/Task.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Scheduler; 25 | 26 | abstract class Task{ 27 | 28 | /** @var TaskHandler */ 29 | private $taskHandler = null; 30 | 31 | /** 32 | * @return TaskHandler 33 | */ 34 | public final function getHandler(){ 35 | return $this->taskHandler; 36 | } 37 | 38 | /** 39 | * @return int 40 | */ 41 | public final function getTaskId(){ 42 | if($this->taskHandler !== null){ 43 | return $this->taskHandler->getTaskId(); 44 | } 45 | 46 | return -1; 47 | } 48 | 49 | /** 50 | * @param TaskHandler $taskHandler 51 | */ 52 | public final function setHandler($taskHandler){ 53 | if($this->taskHandler === null or $taskHandler === null){ 54 | $this->taskHandler = $taskHandler; 55 | } 56 | } 57 | 58 | /** 59 | * Actions to execute when run 60 | * 61 | * @param $currentTick 62 | * 63 | * @return void 64 | */ 65 | public abstract function onRun($currentTick); 66 | 67 | /** 68 | * Actions to execute if the Task is cancelled 69 | */ 70 | public function onCancel(){ 71 | 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /peachpie/port/src/iTXTech/SimpleFramework/ThreadManager.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework; 25 | 26 | class ThreadManager{ 27 | 28 | /** @var ThreadManager */ 29 | private static $instance = null; 30 | 31 | public static function init(){ 32 | self::$instance = new ThreadManager(); 33 | } 34 | 35 | /** 36 | * @return ThreadManager 37 | */ 38 | public static function getInstance(){ 39 | return self::$instance; 40 | } 41 | 42 | /** 43 | * @param Worker|Thread $thread 44 | */ 45 | public function add($thread){ 46 | if($thread instanceof Thread or $thread instanceof Worker){ 47 | $this->{spl_object_hash($thread)} = $thread; 48 | } 49 | } 50 | 51 | /** 52 | * @param Worker|Thread $thread 53 | */ 54 | public function remove($thread){ 55 | if($thread instanceof Thread or $thread instanceof Worker){ 56 | unset($this->{spl_object_hash($thread)}); 57 | } 58 | } 59 | 60 | /** 61 | * @return Worker[]|Thread[] 62 | */ 63 | public function getAll(){ 64 | $array = []; 65 | foreach($this as $key => $thread){ 66 | $array[$key] = $thread; 67 | } 68 | 69 | return $array; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/ThreadManager.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework; 25 | 26 | class ThreadManager extends \Volatile{ 27 | 28 | /** @var ThreadManager */ 29 | private static $instance = null; 30 | 31 | public static function init(){ 32 | self::$instance = new ThreadManager(); 33 | } 34 | 35 | /** 36 | * @return ThreadManager 37 | */ 38 | public static function getInstance(){ 39 | return self::$instance; 40 | } 41 | 42 | /** 43 | * @param Worker|Thread $thread 44 | */ 45 | public function add($thread){ 46 | if($thread instanceof Thread or $thread instanceof Worker){ 47 | $this->{spl_object_hash($thread)} = $thread; 48 | } 49 | } 50 | 51 | /** 52 | * @param Worker|Thread $thread 53 | */ 54 | public function remove($thread){ 55 | if($thread instanceof Thread or $thread instanceof Worker){ 56 | unset($this->{spl_object_hash($thread)}); 57 | } 58 | } 59 | 60 | /** 61 | * @return Worker[]|Thread[] 62 | */ 63 | public function getAll(){ 64 | $array = []; 65 | foreach($this as $key => $thread){ 66 | $array[$key] = $thread; 67 | } 68 | 69 | return $array; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Module/HotPatchThread.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Module; 25 | 26 | use iTXTech\SimpleFramework\Thread; 27 | 28 | class HotPatchThread extends Thread{ 29 | private $file; 30 | private $class; 31 | private $method; 32 | private $loader; 33 | private $path; 34 | private $code; 35 | 36 | public function __construct(string $class, string $method, \ClassLoader $loader){ 37 | $this->class = $class; 38 | $this->method = $method; 39 | $this->file = (new \ReflectionClass($class))->getFileName(); 40 | $this->loader = serialize($loader); 41 | $this->path = (new \ReflectionClass($loader))->getFileName(); 42 | } 43 | 44 | public function run(){ 45 | require_once $this->path; 46 | $classLoader = unserialize($this->loader); 47 | $classLoader->register(true); 48 | require_once $this->file; 49 | $method = (new \ReflectionClass($this->class))->getMethod($this->method); 50 | $this->code = implode("", array_slice(file($this->file), $method->getStartLine() - 1, 51 | $method->getEndLine() - $method->getStartLine() + 1)); 52 | } 53 | 54 | public function getCode(){ 55 | return $this->code; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Util/Curl/Cookie.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Util\Curl; 25 | 26 | class Cookie{ 27 | private $name; 28 | private $value; 29 | private $prop; 30 | 31 | public function __construct(string $payload){ 32 | $parts = explode("; ", $payload); 33 | list($this->name, $this->value) = explode("=", $parts[0]); 34 | array_shift($parts); 35 | foreach($parts as $part){ 36 | $p = explode("=", $part); 37 | $this->prop[$p[0]] = $p[1] ?? ""; 38 | } 39 | } 40 | 41 | public function getName(){ 42 | return $this->name; 43 | } 44 | 45 | public function getValue(){ 46 | return $this->value; 47 | } 48 | 49 | public function hasProperty(string $name){ 50 | return isset($this->prop[$name]); 51 | } 52 | 53 | public function getProperty(string $name) : ?string{ 54 | return $this->prop[$name] ?? null; 55 | } 56 | 57 | public function __toString(){ 58 | $buffer = $this->name . "=" . $this->value . "; "; 59 | foreach($this->prop as $k => $v){ 60 | if($v === ""){ 61 | $buffer .= $k . "; "; 62 | }else{ 63 | $buffer .= $k . "=$v; "; 64 | } 65 | } 66 | return substr($buffer, 0, strlen($buffer) - 2); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/iTXTech/SimpleFramework/Console/Option/Exception/AlreadySelectedException.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | namespace iTXTech\SimpleFramework\Console\Option\Exception; 25 | 26 | use iTXTech\SimpleFramework\Console\Option\Option; 27 | use iTXTech\SimpleFramework\Console\Option\OptionGroup; 28 | 29 | class AlreadySelectedException extends ParseException{ 30 | /** @var OptionGroup */ 31 | private $group; 32 | /** @var Option */ 33 | private $option; 34 | 35 | public function __construct(OptionGroup $group, Option $option){ 36 | parent::__construct("The option '" . $option->getKey() . "' was specified but an option from this group " 37 | . "has already been selected: '" . $group->getSelected() . "'"); 38 | $this->group = $group; 39 | $this->option = $option; 40 | } 41 | 42 | /** 43 | * Returns the option that was added to the group and triggered the exception. 44 | * 45 | * @return Option 46 | */ 47 | public function getOption() : Option{ 48 | return $this->option; 49 | } 50 | 51 | /** 52 | * Returns the option group where another option has been selected. 53 | * 54 | * @return OptionGroup 55 | */ 56 | public function getGroup() : OptionGroup{ 57 | return $this->group; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/wrapper.php: -------------------------------------------------------------------------------- 1 | . 21 | * 22 | */ 23 | 24 | /* 25 | * This script checks the requirements of targeting script before interpreting. 26 | */ 27 | 28 | use iTXTech\SimpleFramework\Console\Logger; 29 | use iTXTech\SimpleFramework\Initializer; 30 | use iTXTech\SimpleFramework\Util\Platform\WindowsPlatform; 31 | use iTXTech\SimpleFramework\Util\Util; 32 | 33 | require_once "../autoload.php"; 34 | 35 | // a for admin 36 | 37 | Initializer::initTerminal(true); 38 | 39 | $file = $argv[1] ?? null; 40 | if($file == null){ 41 | Logger::error("Missing the script to run."); 42 | Logger::info("Usage: php wrapper.php