From bda597a71e48f20e4bbf12d1617203803dc079f5 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 25 Aug 2014 20:54:53 +0200 Subject: [PATCH] Moved spl to PocketMine-SPL --- .gitmodules | 5 +- .../CompatibleClassLoader.php} | 12 +- src/pocketmine/PocketMine.php | 14 +- src/pocketmine/Server.php | 6 +- .../level/generator/GenerationManager.php | 12 +- .../level/generator/GenerationThread.php | 2 +- src/pocketmine/plugin/PharPluginLoader.php | 4 +- src/pocketmine/scheduler/AsyncWorker.php | 8 +- src/spl | 1 + src/spl/AttachableLogger.php | 40 - src/spl/AttachableThreadedLogger.php | 70 -- src/spl/LogLevel.php | 31 - src/spl/Logger.php | 91 --- src/spl/SplAutoloader.php | 64 -- src/spl/SplClassLoader.php | 244 ------ src/spl/ThreadedLogger.php | 24 - src/spl/ThreadedLoggerAttachment.php | 81 -- src/stubs/pthreads.php | 693 ------------------ src/stubs/uopz.php | 268 ------- src/stubs/weakref.php | 127 ---- src/stubs/yaml.php | 106 --- 21 files changed, 32 insertions(+), 1871 deletions(-) rename src/{spl/LoggerAttachment.php => pocketmine/CompatibleClassLoader.php} (80%) create mode 160000 src/spl delete mode 100644 src/spl/AttachableLogger.php delete mode 100644 src/spl/AttachableThreadedLogger.php delete mode 100644 src/spl/LogLevel.php delete mode 100644 src/spl/Logger.php delete mode 100644 src/spl/SplAutoloader.php delete mode 100644 src/spl/SplClassLoader.php delete mode 100644 src/spl/ThreadedLogger.php delete mode 100644 src/spl/ThreadedLoggerAttachment.php delete mode 100644 src/stubs/pthreads.php delete mode 100644 src/stubs/uopz.php delete mode 100644 src/stubs/weakref.php delete mode 100644 src/stubs/yaml.php diff --git a/.gitmodules b/.gitmodules index 19f1b085a..146a4c9f9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,5 +4,8 @@ branch = master [submodule "src/raklib"] path = src/raklib - url = git@github.com:PocketMine/RakLib.git + url = https://github.com/PocketMine/RakLib.git branch = master +[submodule "src/spl"] + path = src/spl + url = https://github.com/PocketMine/PocketMine-SPL.git diff --git a/src/spl/LoggerAttachment.php b/src/pocketmine/CompatibleClassLoader.php similarity index 80% rename from src/spl/LoggerAttachment.php rename to src/pocketmine/CompatibleClassLoader.php index 35127890d..42bbffec8 100644 --- a/src/spl/LoggerAttachment.php +++ b/src/pocketmine/CompatibleClassLoader.php @@ -19,12 +19,14 @@ * */ -interface LoggerAttachment{ +namespace pocketmine; + +class CompatibleClassLoader extends \BaseClassLoader{ /** - * @param mixed $level - * @param string $message + * @deprecated */ - public function log($level, $message); - + public function add($namespace, $paths){ + $this->addPath(array_shift($paths)); + } } \ No newline at end of file diff --git a/src/pocketmine/PocketMine.php b/src/pocketmine/PocketMine.php index 24485bc14..88f48d040 100644 --- a/src/pocketmine/PocketMine.php +++ b/src/pocketmine/PocketMine.php @@ -89,16 +89,14 @@ function dummy(){ exit(1); } - if(!class_exists("SplClassLoader", false)){ - require_once(\pocketmine\PATH . "src/spl/SplClassLoader.php"); + if(!class_exists("ClassLoader", false)){ + require_once(\pocketmine\PATH . "src/spl/ClassLoader.php"); + require_once(\pocketmine\PATH . "src/spl/BaseClassLoader.php"); + require_once(\pocketmine\PATH . "src/pocketmine/CompatibleClassLoader.php"); } - $autoloader = new \SplClassLoader(); - $autoloader->setMode(\SplAutoloader::MODE_DEBUG); - $autoloader->add("pocketmine", [ - \pocketmine\PATH . "src" - ]); - + $autoloader = new CompatibleClassLoader(); + $autoloader->addPath(\pocketmine\PATH . "src"); $autoloader->register(true); if(!class_exists("raklib\\RakLib", false)){ require(\pocketmine\PATH . "src/raklib/raklib/RakLib.php"); diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index 5d44197a0..e59f39ec9 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -455,7 +455,7 @@ public function getMotd(){ } /** - * @return \SplClassLoader + * @return \ClassLoader */ public function getLoader(){ return $this->autoloader; @@ -1377,13 +1377,13 @@ public static function getInstance(){ } /** - * @param \SplClassLoader $autoloader + * @param \ClassLoader $autoloader * @param \ThreadedLogger $logger * @param string $filePath * @param string $dataPath * @param string $pluginPath */ - public function __construct(\SplClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath){ + public function __construct(\ClassLoader $autoloader, \ThreadedLogger $logger, $filePath, $dataPath, $pluginPath){ self::$instance = $this; $this->autoloader = $autoloader; diff --git a/src/pocketmine/level/generator/GenerationManager.php b/src/pocketmine/level/generator/GenerationManager.php index 27d2f18e6..95278e790 100644 --- a/src/pocketmine/level/generator/GenerationManager.php +++ b/src/pocketmine/level/generator/GenerationManager.php @@ -93,7 +93,7 @@ class GenerationManager{ protected $socket; /** @var \Logger */ protected $logger; - /** @var \SplAutoLoader */ + /** @var \ClassLoader */ protected $loader; /** @var GenerationChunkManager[] */ @@ -110,11 +110,11 @@ class GenerationManager{ protected $shutdown = false; /** - * @param resource $socket - * @param \Logger $logger - * @param \SplAutoloader $loader + * @param resource $socket + * @param \Logger $logger + * @param \ClassLoader $loader */ - public function __construct($socket, \Logger $logger, \SplAutoloader $loader){ + public function __construct($socket, \Logger $logger, \ClassLoader $loader){ $this->socket = $socket; $this->logger = $logger; $this->loader = $loader; @@ -282,7 +282,7 @@ protected function readPacket(){ $namespace = substr($packet, $offset, $len); $offset += $len; $path = substr($packet, $offset); - $this->loader->add($namespace, [$path]); + $this->loader->addPath($path); }elseif($pid === self::PACKET_SHUTDOWN){ foreach($this->levels as $level){ $level->shutdown(); diff --git a/src/pocketmine/level/generator/GenerationThread.php b/src/pocketmine/level/generator/GenerationThread.php index 81c2a6d72..90f5c72a4 100644 --- a/src/pocketmine/level/generator/GenerationThread.php +++ b/src/pocketmine/level/generator/GenerationThread.php @@ -50,7 +50,7 @@ public function getLogger(){ return $this->logger; } - public function __construct(\ThreadedLogger $logger, \SplAutoloader $loader){ + public function __construct(\ThreadedLogger $logger, \ClassLoader $loader){ $this->loader = $loader; $this->logger = $logger; $loadPaths = []; diff --git a/src/pocketmine/plugin/PharPluginLoader.php b/src/pocketmine/plugin/PharPluginLoader.php index 1561376ed..65efa2d8c 100644 --- a/src/pocketmine/plugin/PharPluginLoader.php +++ b/src/pocketmine/plugin/PharPluginLoader.php @@ -58,9 +58,7 @@ public function loadPlugin($file){ } $file = "phar://$file"; $className = $description->getMain(); - $this->server->getLoader()->add(substr($className, 0, strrpos($className, "\\")), array( - "$file/src" - )); + $this->server->getLoader()->addPath("$file/src"); if(class_exists($className, true)){ $plugin = new $className(); diff --git a/src/pocketmine/scheduler/AsyncWorker.php b/src/pocketmine/scheduler/AsyncWorker.php index 550fe2b84..76248ddf0 100644 --- a/src/pocketmine/scheduler/AsyncWorker.php +++ b/src/pocketmine/scheduler/AsyncWorker.php @@ -26,11 +26,9 @@ class AsyncWorker extends Worker{ public function run(){ - require(\pocketmine\PATH . "src/spl/SplClassLoader.php"); - $autoloader = new \SplClassLoader(); - $autoloader->add("pocketmine", array( - \pocketmine\PATH . "src" - )); + require(\pocketmine\PATH . "src/spl/ClassLoader.php"); + $autoloader = new \BaseClassLoader(); + $autoloader->addPath(\pocketmine\PATH . "src"); $autoloader->register(true); } } \ No newline at end of file diff --git a/src/spl b/src/spl new file mode 160000 index 000000000..58e1ee35a --- /dev/null +++ b/src/spl @@ -0,0 +1 @@ +Subproject commit 58e1ee35a99845cebf4419e4b142131aafa48618 diff --git a/src/spl/AttachableLogger.php b/src/spl/AttachableLogger.php deleted file mode 100644 index dfe76830f..000000000 --- a/src/spl/AttachableLogger.php +++ /dev/null @@ -1,40 +0,0 @@ -attachment instanceof \ThreadedLoggerAttachment){ - $this->attachment->addAttachment($attachment); - }else{ - $this->attachment = $attachment; - } - } - - /** - * @param ThreadedLoggerAttachment $attachment - */ - public function removeAttachment(\ThreadedLoggerAttachment $attachment){ - if($this->attachment instanceof \ThreadedLoggerAttachment){ - if($this->attachment === $attachment){ - $this->attachment = null; - foreach($attachment->getAttachments() as $attachment){ - $this->addAttachment($attachment); - } - } - } - } - - public function removeAttachments(){ - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $this->attachment->removeAttachments(); - $this->attachment = null; - } - } - - /** - * @return \ThreadedLoggerAttachment[] - */ - public function getAttachments(){ - $attachments = []; - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $attachments[] = $this->attachment; - $attachments += $this->attachment->getAttachments(); - } - return $attachments; - } -} \ No newline at end of file diff --git a/src/spl/LogLevel.php b/src/spl/LogLevel.php deleted file mode 100644 index 1964d5d40..000000000 --- a/src/spl/LogLevel.php +++ /dev/null @@ -1,31 +0,0 @@ - - */ -interface SplAutoloader{ - /** - * Defines autoloader to work silently if resource is not found. - * - * @const - */ - const MODE_SILENT = 0; - - /** - * Defines autoloader to work normally (requiring an un-existent resource). - * - * @const - */ - const MODE_NORMAL = 1; - - /** - * Defines autoloader to work in debug mode, loading file and validating requested resource. - * - * @const - */ - const MODE_DEBUG = 2; - - /** - * Define the autoloader work mode. - * - * @param integer $mode Autoloader work mode. - */ - public function setMode($mode); - - /** - * Add a new resource lookup path. - * - * @param string $resourceName Resource name, namespace or prefix. - * @param mixed $resourcePath Resource single path or multiple paths (array). - */ - public function add($resourceName, $resourcePath = null); - - /** - * Load a resource through provided resource name. - * - * @param string $resourceName Resource name. - */ - public function load($resourceName); - - /** - * Register this as an autoloader instance. - * - * @param boolean $prepend Whether to prepend the autoloader or not in autoloader's list. - */ - public function register($prepend = false); - - /** - * Unregister this autoloader instance. - * - */ - public function unregister(); -} diff --git a/src/spl/SplClassLoader.php b/src/spl/SplClassLoader.php deleted file mode 100644 index 5df9fcd1b..000000000 --- a/src/spl/SplClassLoader.php +++ /dev/null @@ -1,244 +0,0 @@ -setMode(\SplClassLoader::MODE_NORMAL); - * - * // Add a namespace of classes - * $classLoader->add('Doctrine', array( - * '/path/to/doctrine-common', '/path/to/doctrine-dbal', '/path/to/doctrine-orm' - * )); - * - * // Add a prefix - * $classLoader->add('Swift', '/path/to/swift'); - * - * // Add a prefix through PEAR1 convention, requiring include_path lookup - * $classLoader->add('PEAR'); - * - * // Allow to PHP use the include_path for file path lookup - * $classLoader->setIncludePathLookup(true); - * - * // Possibility to change the default php file extension - * $classLoader->setFileExtension('.php'); - * - * // Register the autoloader, prepending it in the stack - * $classLoader->register(true); - * - * @author Guilherme Blanco - * @author Jonathan H. Wage - * @author Roman S. Borschel - * @author Matthew Weier O'Phinney - * @author Kris Wallsmith - * @author Fabien Potencier - */ -class SplClassLoader implements SplAutoloader{ - /** @var string */ - private $fileExtension = '.php'; - - /** @var boolean */ - private $includePathLookup = false; - - /** @var array */ - private $resources = []; - - /** @var integer */ - private $mode = self::MODE_NORMAL; - - /** - * {@inheritdoc} - */ - public function setMode($mode){ - if($mode & self::MODE_SILENT && $mode & self::MODE_NORMAL){ - throw new \InvalidArgumentException( - sprintf('Cannot have %s working normally and silently at the same time!', __CLASS__) - ); - } - - $this->mode = $mode; - } - - /** - * Define the file extension of resource files in the path of this class loader. - * - * @param string $fileExtension - */ - public function setFileExtension($fileExtension){ - $this->fileExtension = $fileExtension; - } - - /** - * Retrieve the file extension of resource files in the path of this class loader. - * - * @return string - */ - public function getFileExtension(){ - return $this->fileExtension; - } - - /** - * Turns on searching the include for class files. Allows easy loading installed PEAR packages. - * - * @param boolean $includePathLookup - */ - public function setIncludePathLookup($includePathLookup){ - $this->includePathLookup = $includePathLookup; - } - - /** - * Gets the base include path for all class files in the namespace of this class loader. - * - * @return boolean - */ - public function getIncludePathLookup(){ - return $this->includePathLookup; - } - - /** - * {@inheritdoc} - */ - public function register($prepend = false){ - spl_autoload_register(array($this, 'load'), true, $prepend); - } - - /** - * {@inheritdoc} - */ - public function unregister(){ - spl_autoload_unregister(array($this, 'load')); - } - - /** - * {@inheritdoc} - */ - public function add($resource, $resourcePath = null){ - if(isset($this->resources[$resource])){ - foreach((array) $resourcePath as $path){ - if(!in_array($path, $this->resources[$resource], true)){ - $this->resources[$resource][] = $path; - } - } - }else{ - $this->resources[$resource] = (array) $resourcePath; - } - } - - /** - * {@inheritdoc} - */ - public function load($resourceName){ - $resourceAbsolutePath = $this->getResourceAbsolutePath($resourceName); - if($resourceAbsolutePath == ""){ - if($resourceName{0} !== "\\"){ - if(file_exists(dirname(__FILE__) ."/" . $resourceName . $this->fileExtension)){ - require dirname(__FILE__) ."/" . $resourceName . $this->fileExtension; - if($this->isResourceDeclared($resourceName)){ - return; - } - } - } - throw new \RuntimeException( - sprintf('Autoloader couldn\'t find a file to include for %s', $resourceName) - ); - } - switch(true){ - case ($this->mode & self::MODE_SILENT): - if($resourceAbsolutePath !== false){ - require $resourceAbsolutePath; - } - break; - - case ($this->mode & self::MODE_NORMAL): - default: - require $resourceAbsolutePath; - break; - } - - if($this->mode & self::MODE_DEBUG && !$this->isResourceDeclared($resourceName)){ - throw new \RuntimeException( - sprintf('Autoloader expected resource "%s" to be declared in file "%s".', $resourceName, $resourceAbsolutePath) - ); - } - } - - /** - * Transform resource name into its absolute resource path representation. - * - * @param string $resourceName - * - * @return string Resource absolute path. - */ - private function getResourceAbsolutePath($resourceName){ - $resourceRelativePath = $this->getResourceRelativePath($resourceName); - - foreach($this->resources as $resource => $resourcesPath){ - if(strpos($resourceName, $resource) !== 0){ - continue; - } - - foreach($resourcesPath as $resourcePath){ - $resourceAbsolutePath = $resourcePath . DIRECTORY_SEPARATOR . $resourceRelativePath; - - if(is_file($resourceAbsolutePath)){ - return $resourceAbsolutePath; - } - } - } - - if($this->includePathLookup && ($resourceAbsolutePath = stream_resolve_include_path($resourceRelativePath)) !== false){ - return $resourceAbsolutePath; - } - - return false; - } - /** - * Transform resource name into its relative resource path representation. - * - * @param string $resourceName - * - * @return string Resource relative path. - */ - private function getResourceRelativePath($resourceName){ - // We always work with FQCN in this context - $resourceName = ltrim($resourceName, '\\'); - $resourcePath = ''; - - if(($lastNamespacePosition = strrpos($resourceName, '\\')) !== false){ - // Namespaced resource name - $resourceNamespace = substr($resourceName, 0, $lastNamespacePosition); - $resourceName = substr($resourceName, $lastNamespacePosition + 1); - $resourcePath = str_replace('\\', DIRECTORY_SEPARATOR, $resourceNamespace) . DIRECTORY_SEPARATOR; - } - - return $resourcePath . $resourceName . $this->fileExtension; - } - - /** - * Check if resource is declared in user space. - * - * @param string $resourceName - * - * @return boolean - */ - private function isResourceDeclared($resourceName){ - return class_exists($resourceName, false) - || interface_exists($resourceName, false) - || (function_exists('trait_exists') && trait_exists($resourceName, false)); - } -} diff --git a/src/spl/ThreadedLogger.php b/src/spl/ThreadedLogger.php deleted file mode 100644 index 62c3b6cb0..000000000 --- a/src/spl/ThreadedLogger.php +++ /dev/null @@ -1,24 +0,0 @@ -log($level, $message); - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $this->attachment->call($level, $message); - } - } - - /** - * @param ThreadedLoggerAttachment $attachment - */ - public function addAttachment(\ThreadedLoggerAttachment $attachment){ - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $this->attachment->addAttachment($attachment); - }else{ - $this->attachment = $attachment; - } - } - - /** - * @param ThreadedLoggerAttachment $attachment - */ - public function removeAttachment(\ThreadedLoggerAttachment $attachment){ - if($this->attachment instanceof \ThreadedLoggerAttachment){ - if($this->attachment === $attachment){ - $this->attachment = null; - foreach($attachment->getAttachments() as $attachment){ - $this->addAttachment($attachment); - } - } - } - } - - public function removeAttachments(){ - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $this->attachment->removeAttachments(); - $this->attachment = null; - } - } - - /** - * @return \ThreadedLoggerAttachment[] - */ - public function getAttachments(){ - $attachments = []; - if($this->attachment instanceof \ThreadedLoggerAttachment){ - $attachments[] = $this->attachment; - $attachments += $this->attachment->getAttachments(); - } - return $attachments; - } -} \ No newline at end of file diff --git a/src/stubs/pthreads.php b/src/stubs/pthreads.php deleted file mode 100644 index 715241bb9..000000000 --- a/src/stubs/pthreads.php +++ /dev/null @@ -1,693 +0,0 @@ - - * @version 2.0.0 - * @link https://github.com/krakjoe/pthreads/blob/master/examples/stub.php - */ - -/** - * The default inheritance mask used when starting Threads and Workers - */ -define('PTHREADS_INHERIT_ALL', 0x111111); - -/** - * Nothing will be inherited by the new context - */ -define('PTHREADS_INHERIT_NONE', 0); - -/** - * Determines whether the ini entries are inherited by the new context - */ -define('PTHREADS_INHERIT_INI', 0x1); - -/** - * Determines whether the constants are inherited by the new context - */ -define('PTHREADS_INHERIT_CONSTANTS', 0x10); - -/** - * Determines whether the class table is inherited by the new context - */ -define('PTHREADS_INHERIT_CLASSES', 0x100); - -/** - * Determines whether the function table is inherited by the new context - */ -define('PTHREADS_INHERIT_FUNCTIONS', 0x100); - -/** - * Determines whether the included_files table is inherited by the new context - */ -define('PTHREADS_INHERIT_INCLUDES', 0x10000); - -/** - * Determines whether the comments are inherited by the new context - */ -define('PTHREADS_INHERIT_COMMENTS', 0x100000); - -/** - * Allow output headers from the threads - */ -define('PTHREADS_ALLOW_HEADERS', 0x1000000); - -/** - * Allow global inheritance for new threads - */ -define('PTHREADS_ALLOW_GLOBALS', 0x10000000); - -/** - * Threaded class - * - * Threaded objects form the basis of pthreads ability to execute user code asynchronously; - * they expose and include synchronization methods and various useful interfaces. - * - * Threaded objects, most importantly, provide implicit safety for the programmer; - * all operations on the object scope are safe. - * - * @link http://www.php.net/manual/en/class.threaded.php - * @since 2.0.0 - */ -class Threaded implements Traversable, Countable, ArrayAccess{ - /** - * Fetches a chunk of the objects properties table of the given size - * - * @param int $size The number of items to fetch - * - * @link http://www.php.net/manual/en/threaded.chunk.php - * @return array An array of items from the objects member table - */ - public function chunk($size){ - } - - /** - * {@inheritdoc} - */ - public function count(){ - } - - /** - * Retrieves terminal error information from the referenced object - * - * @link http://www.php.net/manual/en/threaded.getterminationinfo.php - * @return array|bool array containing the termination conditions of the referenced object - */ - public function getTerminationInfo(){ - } - - /** - * Tell if the referenced object is executing - * - * @link http://www.php.net/manual/en/threaded.isrunning.php - * @return bool A boolean indication of state - */ - public function isRunning(){ - } - - /** - * Tell if the referenced object exited, suffered fatal errors, or threw uncaught exceptions during execution - * - * @link http://www.php.net/manual/en/threaded.isterminated.php - * @return bool A boolean indication of state - */ - public function isTerminated(){ - } - - /** - * Tell if the referenced object is waiting for notification - * - * @link http://www.php.net/manual/en/threaded.iswaiting.php - * @return bool A boolean indication of state - */ - public function isWaiting(){ - } - - /** - * Lock the referenced objects property table - * - * @link http://www.php.net/manual/en/threaded.lock.php - * @return bool A boolean indication of state - */ - public function lock(){ - } - - /** - * Merges data into the current object - * - * @param mixed $from The data to merge - * @param bool $overwrite Overwrite existing keys flag, by default true - * - * @link http://www.php.net/manual/en/threaded.merge.php - * @return bool A boolean indication of success - */ - public function merge($from, $overwrite = true){ - } - - /** - * Send notification to the referenced object - * - * @link http://www.php.net/manual/en/threaded.notify.php - * @return bool A boolean indication of success - */ - public function notify(){ - } - - /** - * {@inheritdoc} - */ - public function offsetGet($offset){ - } - - /** - * {@inheritdoc} - */ - public function offsetSet($offset, $value){ - } - - /** - * {@inheritdoc} - */ - public function offsetExists($offset){ - } - - /** - * {@inheritdoc} - */ - public function offsetUnset($offset){ - } - - /** - * Pops an item from the objects property table - * - * @link http://www.php.net/manual/en/threaded.pop.php - * @return mixed The last item from the objects properties table - */ - public function pop(){ - } - - /** - * The programmer should always implement the run method for objects that are intended for execution. - * - * @link http://www.php.net/manual/en/threaded.run.php - * @return void The methods return value, if used, will be ignored - */ - public function run(){ - } - - /** - * Shifts an item from the objects properties table - * - * @link http://www.php.net/manual/en/threaded.shift.php - * @return mixed The first item from the objects properties table - */ - public function shift(){ - } - - /** - * Executes the block while retaining the synchronization lock for the current context. - * - * @param \Closure $function The block of code to execute - * @param mixed $args ... Variable length list of arguments to use as function arguments to the block - * - * @link http://www.php.net/manual/en/threaded.synchronized.php - * @return mixed The return value from the block - */ - public function synchronized(\Closure $function, $args = null){ - } - - /** - * Unlock the referenced objects storage for the calling context - * - * @link http://www.php.net/manual/en/threaded.unlock.php - * @return bool A boolean indication of success - */ - public function unlock(){ - } - - /** - * Waits for notification from the Stackable - * - * @param int $timeout An optional timeout in microseconds - * - * @link http://www.php.net/manual/en/threaded.wait.php - * @return bool A boolean indication of success - */ - public function wait($timeout){ - } -} - -/** - * Basic thread implementation - * - * An implementation of a Thread should extend this declaration, implementing the run method. - * When the start method of that object is called, the run method code will be executed in separate Thread. - * - * @link http://www.php.net/manual/en/class.thread.php - */ -class Thread extends Threaded{ - - /** - * Detaches a thread - * - * @return bool A boolean indication of success - */ - public function detach(){ - } - - /** - * Will return the identity of the Thread that created the referenced Thread - * - * @link http://www.php.net/manual/en/thread.getcreatorid.php - * @return int A numeric identity - */ - public function getCreatorId(){ - } - - /** - * Will return the instance of currently executing thread - * - * @return static - */ - public static function getCurrentThread(){ - } - - /** - * Will return the identity of the currently executing thread - * - * @link http://www.php.net/manual/en/thread.getcurrentthreadid.php - * @return int - */ - public static function getCurrentThreadId(){ - } - - /** - * Will return the identity of the referenced Thread - * - * @link http://www.php.net/manual/en/thread.getthreadid.php - * @return int - */ - public function getThreadId(){ - } - - /** - * Tell if the referenced Thread has been joined by another context - * - * @link http://www.php.net/manual/en/thread.isjoined.php - * @return bool A boolean indication of state - */ - public function isJoined(){ - } - - /** - * Tell if the referenced Thread has been started - * - * @link http://www.php.net/manual/en/thread.isstarted.php - * @return bool A boolean indication of state - */ - public function isStarted(){ - } - - /** - * Causes the calling context to wait for the referenced Thread to finish executing - * - * @link http://www.php.net/manual/en/thread.join.php - * @return bool A boolean indication of state - */ - public function join(){ - } - - /** - * Kills the referenced thread, dangerously ! - * - * @link http://www.php.net/manual/en/thread.kill.php - */ - public function kill(){ - } - - /** - * Will start a new Thread to execute the implemented run method - * - * @param int $options An optional mask of inheritance constants, by default PTHREADS_INHERIT_ALL - * - * @link http://www.php.net/manual/en/thread.start.php - * @return bool A boolean indication of success - */ - public function start($options = PTHREADS_INHERIT_ALL){ - } - - /** - * Will execute the Callable in the global scope - * - * @param Callable $block The code to execute - * @param ... $args Variable length list of arguments to pass to the Callable upon execution - * - * @link http://www.php.net/manual/en/thread.start.php - * @return bool A boolean indication of success - */ - public static function globally(Callable $block, $args = null){ - } -} - -/** - * Worker - * - * Worker Threads have a persistent context, as such should be used over Threads in most cases. - * - * When a Worker is started, the run method will be executed, but the Thread will not leave until one - * of the following conditions are met: - * - the Worker goes out of scope (no more references remain) - * - the programmer calls shutdown - * - the script dies - * This means the programmer can reuse the context throughout execution; placing objects on the stack of - * the Worker will cause the Worker to execute the stacked objects run method. - * - * @link http://www.php.net/manual/en/class.worker.php - */ -class Worker extends Thread{ - - /** - * Returns the number of threaded tasks waiting to be executed by the referenced Worker - * - * @link http://www.php.net/manual/en/worker.getstacked.php - * @return int An integral value - */ - public function getStacked(){ - } - - /** - * Tell if the referenced Worker has been shutdown - * - * @link http://www.php.net/manual/en/worker.isshutdown.php - * @return bool A boolean indication of state - */ - public function isShutdown(){ - } - - /** - * Tell if a Worker is executing threaded tasks - * - * @link http://www.php.net/manual/en/worker.isworking.php - * @return bool A boolean indication of state - */ - public function isWorking(){ - } - - /** - * Shuts down the Worker after executing all the threaded tasks previously stacked - * - * @link http://www.php.net/manual/en/worker.shutdown.php - * @return bool A boolean indication of success - */ - public function shutdown(){ - } - - /** - * Appends the referenced object to the stack of the referenced Worker - * - * @param Threaded $work Threaded object to be executed by the referenced Worker - * - * @link http://www.php.net/manual/en/worker.stack.php - * @return int The new length of the stack - */ - public function stack(Threaded &$work){ - } - - /** - * Removes the referenced object ( or all objects if parameter is null ) from stack of the referenced Worker - * - * @param Threaded $work Threaded object previously stacked onto Worker - * - * @link http://www.php.net/manual/en/worker.unstack.php - * @return int The new length of the stack - */ - public function unstack(Threaded &$work = null){ - } -} - -/** - * Mutex class - * - * The static methods contained in the Mutex class provide direct access to Posix Mutex functionality. - * - * @link http://www.php.net/manual/en/class.mutex.php - */ -class Mutex{ - - /** - * Create, and optionally lock a new Mutex for the caller - * - * @param bool $lock Setting lock to true will lock the Mutex for the caller before returning the handle - * - * @link http://www.php.net/manual/en/mutex.create.php - * @return int A newly created and optionally locked Mutex handle - */ - final public static function create($lock = false){ - } - - /** - * Destroy mutex - * - * Destroying Mutex handles must be carried out explicitly by the programmer when they are - * finished with the Mutex handle. - * - * @param int $mutex A handle returned by a previous call to Mutex::create(). - * - * @link http://www.php.net/manual/en/mutex.destroy.php - * @return bool A boolean indication of success - */ - final public static function destroy($mutex){ - } - - /** - * Attempt to lock the Mutex for the caller. - * - * An attempt to lock a Mutex owned (locked) by another Thread will result in blocking. - * - * @param int $mutex A handle returned by a previous call to Mutex::create(). - * - * @link http://www.php.net/manual/en/mutex.lock.php - * @return bool A boolean indication of success - */ - final public static function lock($mutex){ - } - - /** - * Attempt to lock the Mutex for the caller without blocking if the Mutex is owned (locked) by another Thread. - * - * @param int $mutex A handle returned by a previous call to Mutex::create(). - * - * @link http://www.php.net/manual/en/mutex.trylock.php - * @return bool A boolean indication of success - */ - final public static function trylock($mutex){ - } - - /** - * Release mutex - * - * Attempts to unlock the Mutex for the caller, optionally destroying the Mutex handle. - * The calling thread should own the Mutex at the time of the call. - * - * @param int $mutex A handle returned by a previous call to Mutex::create(). - * @param bool $destroy When true pthreads will destroy the Mutex after a successful unlock. - * - * @link http://www.php.net/manual/en/mutex.unlock.php - * @return bool A boolean indication of success - */ - final public static function unlock($mutex, $destroy = false){ - } -} - -/** - * Condition class - * - * The static methods contained in the Cond class provide direct access to Posix Condition Variables. - * - * @link http://www.php.net/manual/en/class.cond.php - */ -class Cond{ - /** - * Broadcast to all Threads blocking on a call to Cond::wait(). - * - * @param int $condition A handle to a Condition Variable returned by a previous call to Cond::create() - * - * @link http://www.php.net/manual/en/cond.broadcast.php - * @return bool A boolean indication of success - */ - final public static function broadcast($condition){ - } - - /** - * Creates a new Condition Variable for the caller. - * - * @link http://www.php.net/manual/en/cond.create.php - * @return int A handle to a Condition Variable - */ - final public static function create(){ - } - - /** - * Destroy a condition - * - * Destroying Condition Variable handles must be carried out explicitly by the programmer when they are - * finished with the Condition Variable. - * No Threads should be blocking on a call to Cond::wait() when the call to Cond::destroy() takes place. - * - * @param int $condition A handle to a Condition Variable returned by a previous call to Cond::create() - * - * @link http://www.php.net/manual/en/cond.destroy.php - * @return bool A boolean indication of success - */ - final public static function destroy($condition){ - } - - /** - * Signal a Condition - * - * @param int $condition A handle to a Condition Variable returned by a previous call to Cond::create() - * - * @link http://www.php.net/manual/en/cond.signal.php - * @return bool A boolean indication of success - */ - final public static function signal($condition){ - } - - /** - * Wait for a signal on a Condition Variable, optionally specifying a timeout to limit waiting time. - * - * @param int $condition A handle to a Condition Variable returned by a previous call to Cond::create() - * @param int $mutex A handle returned by a previous call to Mutex::create() and owned (locked) by the caller. - * @param int $timeout An optional timeout, in microseconds - * - * @return bool A boolean indication of success - */ - final public static function wait($condition, $mutex, $timeout = null){ - } -} - -/** - * Pool class - * - * A Pool is a container for, and controller of, a number of Worker threads, the number of threads can be adjusted - * during execution, additionally the Pool provides an easy mechanism to maintain and collect references in the - * proper way. - * - * @link http://www.php.net/manual/en/class.pool.php - */ -class Pool{ - /** - * The maximum number of Worker threads allowed in this Pool - * - * @var integer - */ - protected $size; - - /** - * The name of the Worker class for this Pool - * - * @var string - */ - protected $class; - - /** - * The array of Worker threads for this Pool - * - * @var array|Worker[] - */ - protected $workers; - - /** - * The array of Stackables submitted to this Pool for execution - * - * @var array|Threaded[] - */ - protected $work; - - /** - * The constructor arguments to be passed by this Pool to new Workers upon construction - * - * @var array - */ - protected $ctor; - - /** - * The numeric identifier for the last Worker used by this Pool - * - * @var integer - */ - protected $last; - - /** - * Construct a new Pool of Workers - * - * @param integer $size The maximum number of Workers this Pool can create - * @param string $class The class for new Workers - * @param array $ctor An array of arguments to be passed to new Workers - * - * @link http://www.php.net/manual/en/pool.__construct.php - */ - public function __construct($size, $class, array $ctor = []){ - } - - /** - * Shuts down all Workers, and collect all Stackables, finally destroys the Pool - * - * @link http://www.php.net/manual/en/pool.__destruct.php - */ - public function __destruct(){ - } - - /** - * Collect references to completed tasks - * - * Allows the Pool to collect references determined to be garbage by the given collector - * - * @param callable $collector - * - * @link http://www.php.net/manual/en/pool.collect.php - */ - public function collect(callable $collector){ - } - - /** - * Resize the Pool - * - * @param integer $size The maximum number of Workers this Pool can create - * - * @link http://www.php.net/manual/en/pool.resize.php - */ - public function resize($size){ - } - - /** - * Shutdown all Workers in this Pool - * - * @link http://www.php.net/manual/en/pool.shutdown.php - */ - public function shutdown(){ - } - - /** - * Submit the task to the next Worker in the Pool - * - * @param Threaded $task The task for execution - * - * @return int the identifier of the Worker executing the object - */ - public function submit(Threaded $task){ - } - - /** - * Submit the task to the specific Worker in the Pool - * - * @param int $worker The worker for execution - * @param Threaded $task The task for execution - * - * @return int the identifier of the Worker that accepted the object - */ - public function submitTo($worker, Threaded $task){ - } -} \ No newline at end of file diff --git a/src/stubs/uopz.php b/src/stubs/uopz.php deleted file mode 100644 index feaa5f10a..000000000 --- a/src/stubs/uopz.php +++ /dev/null @@ -1,268 +0,0 @@ - - * @version 1.0.0 - * @link https://github.com/krakjoe/uopz - */ - -/** - * Invoked by exit() and die(), recieves no arguments. Return boolean TRUE to exit, FALSE to continue - */ -define('ZEND_EXIT', 79); - -/** - * Invoked by object construction, receives the class of object being created as the only argument - */ -define('ZEND_NEW', 68); - -/** - * Invoked by the throw construct, receives the class of exception being thrown as the only argument - */ -define('ZEND_THROW', 108); - -/** - * Determines whether the constants are inherited by the new context - */ -define('ZEND_FETCH_CLASS', 109); - -/** - * Invoked upon composure, - * recieves the class the trait is being added to as the first argument, - * and the name of the trait as the second argument - */ -define('ZEND_ADD_TRAIT', 154); - -/** - * Invoked upon composure, - * recieves the class the interface is being added to as the first argument, - * and the name of the interface as the second argument - */ -define('ZEND_ADD_INTERFACE', 144); - -/** - * Invoked by instanceof operator, - * recieves the object being verified as the first argument, - * and the name of the class which that object should be as the second argument - */ -define('ZEND_INSTANCEOF', 138); - - - -// Modifiers - -/** - * Advance 1 opcode and continue - */ -define('ZEND_USER_OPCODE_CONTINUE', null); //?? - -/** - * Enter into new op_array without recursion - */ -define('ZEND_USER_OPCODE_ENTER', null); //?? - -/** - * Return to calling op_array within the same executor - */ -define('ZEND_USER_OPCODE_LEAVE', null); //?? - -/** - * Dispatch to original opcode handler - */ -define('ZEND_USER_OPCODE_DISPATCH', null); //?? - -/** - * Dispatch to a specific handler (OR'd with ZEND opcode constant) - */ -define('ZEND_USER_OPCODE_DISPATCH_TO', null); //?? - -/** - * Exit from executor (return from function) - */ -define('ZEND_USER_OPCODE_RETURN', null); //?? - - - -//Modifiers - - -/** - * Mark function as public, the default - */ -define('ZEND_USER_ACC_PUBLIC', null); //?? - -/** - * Mark function as protected - */ -define('ZEND_USER_ACC_PROTECTED', null); //?? - -/** - * Mark function as private - */ -define('ZEND_USER_ACC_PRIVATE', null); //?? - -/** - * Mark function as static - */ -define('ZEND_USER_ACC_STATIC', null); //?? - -/** - * Mark function as abstract - */ -define('ZEND_USER_ACC_ABSTRACT', null); //?? - -/** - * Dummy registered for consistency, the default kind of class entry - */ -define('ZEND_USER_ACC_CLASS', null); //?? - -/** - * Mark class as interface - */ -define('ZEND_USER_ACC_INTERFACE', null); //?? - -/** - * Mark class as trait - */ -define('ZEND_USER_ACC_TRAIT', null); //?? - -/** - * Used for getting flags only -*/ -define('ZEND_USER_ACC_FLAGS', null); //?? - -/** - * Backup a function at runtime, to be restored on shutdown - * - * @param string $name Function name or class name - * @param string $classMethod Class method, if $name is a class name - * - * @return void - */ -function uopz_backup($name, $classMethod = null){} - -/** - * Creates a new class of the given name that implements, extends, or uses all of the provided classes - * - * @param string $name A legal class name - * @param array $classes An array of class, interface and trait names - * @param array $methods An associative array of methods, values are either closures or [modifiers => closure] - * @param array $properties An associative array of properties, keys are names, values are modifiers - * @param int $flags Entry type, by default ZEND_ACC_CLASS - */ -function uopz_compose($name, array $classes, array $methods = [], array $properties = [], $flags = ZEND_USER_ACC_CLASS){} - -/** - * Copy a function by name - * - * @param string $name Function name or class name - * @param string $classMethod Class method, if $name is a class name - * - * @return Closure - */ -function uopz_copy($name, $classMethod = null){} - -/** - * Deletes a function or method - * - * @param string $name Function name or class name - * @param string $classMethod Class method, if $name is a class name - * - * @return void - */ -function uopz_delete($name, $classMethod = null){} - -/** - * @param string $class The name of the class to extend - * @param string $parent The name of the class to inherit - * - * @return void - */ -function uopz_extend($class, $parent){} - -/** - * Get or set the flags on a class or function entry at runtime - * - * @param string $name Function name or class name - * @param string $classMethod (optional) Class method, if $name is a class name - * @param int $flags A valid set of ZEND_ACC_ flags, ZEND_ACC_FETCH to read flags - * - * @return void - */ -function uopz_flags($name, $classMethod = null, $flags = null){} - -/** - * Creates a function at runtime - * - * @param string $name Function name or class name - * @param string $classMethod (optional) Class method, if $name is a class name - * @param Closure $handler The Closure for the function - * @param int $modifiers The modifiers for the function, by default copied or ZEND_ACC_PUBLIC - * - * @return void - */ -function uopz_function($name, $classMethod = null, Closure $handler, $modifiers = ZEND_USER_ACC_PUBLIC){} - -/** - * Makes class implement interface - * - * @param string $class - * @param string $interface - */ -function uopz_implement($class, $interface){} - -/** - * Overloads the specified VM opcode with the user defined function - * - * @param int $opcode A valid opcode, see constants for details of supported codes - * @param Callable $callable - * - * @return void - */ -function uopz_overload($opcode, $callable){} - -/** - * Redefines the given constant as value - * - * @param string $name Constant ot class name - * @param string $classConstant (optional) constant to redefine if $name is a class name - * @param mixed $value - * - * @return void - */ -function uopz_redefine($name, $classConstant, $value){} - -/** - * Rename a function at runtime - * Note: If both functions exist, this effectively swaps their names - * - * @param string $name Function name or class name - * @param string $classMethod (optional) Class method, if $name is a class name - * @param string $rename The new name for the function - * - * @return void - */ -function uopz_rename($name, $classMethod = null, $rename){} - -/** - * Restore a previously backed up function - * - * @param string $name Function name or class name - * @param string $classMethod Class method, if $name is a class name - * - * @return void - */ -function uopz_restore($name, $classMethod = null){} - -/** - * Removes the constant at runtime - * - * @param string $name Function name or class name - * @param string $classMethod (optional) Class method, if $name is a class name - * - * @return void - */ -function uopz_undefine($name, $classMethod = null){} \ No newline at end of file diff --git a/src/stubs/weakref.php b/src/stubs/weakref.php deleted file mode 100644 index b53b50abd..000000000 --- a/src/stubs/weakref.php +++ /dev/null @@ -1,127 +0,0 @@ -