*/ function timeout($seconds = 0): Promise { $promise = new Promise; Loop\setTimeout([$promise, 'fulfill'], $seconds); return $promise; } /** * Returns a promise that is fulfilled once the passed event was triggered on the passed EventEmitter * * @param EmitterInterface $emitter * @param string $event * @return Promise */ function waitForEvent(EmitterInterface $emitter, string $event): Promise { $p = new Promise; $emitter->once($event, [$p, 'fulfill']); return $p; } /** * Returns the part of $b that is not overlapped by $a * Example: * * stripStringOverlap('whatevergetUri())['path']; $vendorDir = getVendorDir($composerJson); return strpos($path, "/$vendorDir/") !== false; } /** * Check a given URI against the composer.json to see if it * is a vendored URI * * @param string $uri * @param \stdClass|null $composerJson * @return string|null */ function getPackageName(string $uri, \stdClass $composerJson = null) { $vendorDir = str_replace('/', '\/', getVendorDir($composerJson)); preg_match("/\/$vendorDir\/([^\/]+\/[^\/]+)\//", $uri, $matches); return $matches[1] ?? null; } /** * Helper function to get the vendor directory from composer.json * or default to 'vendor' * * @param \stdClass|null $composerJson * @return string */ function getVendorDir(\stdClass $composerJson = null): string { return $composerJson->config->{'vendor-dir'} ?? 'vendor'; }