/** * @param Logger $logger * @param OptionResult $options * @param string $downloader * * @return BaseDownloader */ public static function getInstance(Logger $logger, OptionResult $options, $downloader = null) { if (is_string($downloader)) { //if we specific a downloader class clearly, then it's the only choice if (class_exists($downloader) && is_subclass_of($downloader, 'PhpBrew\\Downloader\\BaseDownloader')) { return new $downloader($logger, $options); } $downloader = array($downloader); } if (empty($downloader)) { $downloader = array_keys(self::$availableDownloaders); } //if --downloader presents, we will use it as the first choice, even if the caller specific downloader by alias/array if ($options->has('downloader')) { $logger->info("Found --downloader option, try to use {$options->downloader} as default downloader."); $downloader = array_merge(array($options->downloader), $downloader); } $instance = self::create($logger, $options, $downloader); if ($instance === null) { $logger->debug('Downloader not found, falling back to command-based downloader.'); //if all downloader not available, maybe we should throw exceptions here instead of returning null? return self::create($logger, $options, self::$fallbackDownloaders); } else { return $instance; } }
public function testPatch() { if (PHP_OS !== "Darwin") { return $this->markTestSkipped('openssl DSO patch test only runs on darwin platform'); } $logger = new Logger(); $logger->setQuiet(); $fromVersion = '5.5.17'; $sourceFixtureDirectory = getenv('PHPBREW_FIXTURES_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $sourceDirectory = getenv('PHPBREW_BUILD_PHP_DIR'); $this->setupBuildDirectory($fromVersion); $build = new Build($fromVersion); $build->setSourceDirectory($sourceDirectory); $build->enableVariant('openssl'); $this->assertTrue($build->hasVariant('openssl'), 'openssl enabled'); $patch = new OpenSSLDSOPatch(); $matched = $patch->match($build, $logger); $this->assertTrue($matched, 'patch matched'); $patchedCount = $patch->apply($build, $logger); $this->assertEquals(10, $patchedCount); /* We can't assume the file equals because the test may be run on different platform and openssl may be installed into different locations. $sourceExpectedDirectory = getenv('PHPBREW_EXPECTED_PHP_DIR') . DIRECTORY_SEPARATOR . '5.5.17-openssl-dso-patch'; $this->assertFileEquals($sourceExpectedDirectory. '/Makefile', $sourceDirectory . '/Makefile'); */ }
public function executeWrapper(array $args) { if (empty($args)) { $args = [null]; // $args = ['app.phpsgi']; } list($appFile) = $args; $logger = new Logger(); if ($appFile) { if (!file_exists($appFile)) { die("File {$appFile} doesn't exist."); } $app = (require $appFile); } else { $app = function (array &$environment, array $response) { return [200, ['Content-Type' => 'text/plain'], 'Hello World']; }; } if (extension_loaded('event')) { $logger->info("Found 'event' extension, enabling EventHttpServer server."); $server = new EventHttpServer($app); } else { $logger->info("Falling back to StreamSocketServer server."); $server = new StreamSocketServer($app); } return $server->listen(); }
public function testPatch() { $logger = new Logger(); $logger->setQuiet(); $fromVersion = '5.3.29'; $sourceFixtureDirectory = getenv('PHPBREW_FIXTURES_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $sourceDirectory = getenv('PHPBREW_BUILD_PHP_DIR'); if (!is_dir($sourceDirectory)) { return $this->markTestSkipped("{$sourceDirectory} does not exist."); } // Copy the source Makefile to the Makefile // copy($sourceFixtureDirectory . '/Makefile', $sourceDirectory . '/Makefile'); $this->setupBuildDirectory($fromVersion); $build = new Build($fromVersion); $build->setSourceDirectory($sourceDirectory); $build->enableVariant('intl'); $this->assertTrue($build->hasVariant('intl'), 'intl enabled'); $patch = new IntlWith64bitPatch(); $matched = $patch->match($build, $logger); $this->assertTrue($matched, 'patch matched'); $patchedCount = $patch->apply($build, $logger); $this->assertEquals(3, $patchedCount); $sourceExpectedDirectory = getenv('PHPBREW_EXPECTED_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $this->assertFileEquals($sourceExpectedDirectory . '/Makefile', $sourceDirectory . '/Makefile'); }
/** * @param $body */ public function basicPublish($body) { try { $this->getChannel()->basic_publish($this->message->setBody(json_encode($body)), '', $this->queue_name); $this->logger->info('Job published successfully!'); } catch (\AMQPChannelException $e) { $this->logger->error($e->getMessage()); } }
public function test() { $logger = new Logger(); $logger->setQuiet(); $workingDir = new SplFileInfo(getcwd()); $vendorDirName = 'vendor'; $autoloadGenerator = new ComposerAutoloadGenerator($logger); $autoloadGenerator->setVendorDir('vendor'); $autoloadGenerator->setWorkingDir($workingDir->getPathname()); $autoloadGenerator->scanComposerJsonFiles($workingDir . DIRECTORY_SEPARATOR . $vendorDirName); }
public function testBitbucketPackage() { $logger = new Logger(); $logger->setQuiet(); $provider = new BitbucketProvider(); $provider->setOwner('osmanov'); $provider->setRepository('pecl-event'); $provider->setPackageName('event'); $extensionDownloader = new ExtensionDownloader($logger, new OptionResult()); $versionList = $extensionDownloader->knownReleases($provider); $this->assertNotCount(0, $versionList); }
/** * @dataProvider packageNameProvider */ public function testInstallPackages($extensionName, $extensionVersion = 'latest') { $logger = new Logger(); $logger->setDebug(); $manager = new ExtensionManager($logger); $peclProvider = new PeclProvider(); $downloader = new ExtensionDownloader($logger, new OptionResult()); $peclProvider->setPackageName($extensionName); $downloader->download($peclProvider, $extensionVersion); $ext = ExtensionFactory::lookup($extensionName); $this->assertNotNull($ext); $manager->installExtension($ext, array()); }
/** * @dataProvider packageNameProvider */ public function testInstallPackages($build, $extensionName, $extensionVersion, $options) { if (!$build) { $this->markTestSkipped('skip extension build test'); return; } $logger = new Logger(); $logger->setDebug(); $manager = new ExtensionManager($logger); $peclProvider = new PeclProvider(); $downloader = new ExtensionDownloader($logger, new OptionResult()); $peclProvider->setPackageName($extensionName); $downloader->download($peclProvider, $extensionVersion); $ext = ExtensionFactory::lookup($extensionName); $this->assertNotNull($ext); $manager->installExtension($ext, $options); }
public function testPatch() { $logger = new Logger(); $logger->setQuiet(); $fromVersion = '5.5.17'; $sourceFixtureDirectory = getenv('PHPBREW_FIXTURES_PHP_DIR') . DIRECTORY_SEPARATOR . $fromVersion; $sourceDirectory = getenv('PHPBREW_BUILD_PHP_DIR'); if (!is_dir($sourceDirectory)) { return $this->markTestSkipped("{$sourceDirectory} does not exist."); } $this->setupBuildDirectory($fromVersion); $build = new Build($fromVersion); $build->setSourceDirectory($sourceDirectory); $build->enableVariant('apxs2'); $this->assertTrue($build->hasVariant('apxs2'), 'apxs2 enabled'); $patch = new Apache2ModuleNamePatch(); $matched = $patch->match($build, $logger); $this->assertTrue($matched, 'patch matched'); $patchedCount = $patch->apply($build, $logger); $this->assertEquals(107, $patchedCount); $sourceExpectedDirectory = getenv('PHPBREW_EXPECTED_PHP_DIR') . DIRECTORY_SEPARATOR . '5.5.17-apxs-patch'; $this->assertFileEquals($sourceExpectedDirectory . '/Makefile.global', $sourceDirectory . '/Makefile.global'); $this->assertFileEquals($sourceExpectedDirectory . '/configure', $sourceDirectory . '/configure'); }
public function importSchema($schema) { $this->logger->info('Importing schema: ' . get_class($schema)); if ($schema instanceof DeclareSchema) { $sqls = $this->builder->build($schema); $this->query($sqls); } elseif ($schema instanceof BaseModel && method_exists($schema, 'schema')) { $model = $schema; $schema = new DynamicSchemaDeclare($model); $sqls = $this->builder->build($schema); $this->query($sqls); } else { throw new InvalidArgumentException('Unsupported schema type'); } }
public function buildMetaFromName($name) { $path = Config::getBuildDir() . '/' . Config::getCurrentPhpName() . '/ext/' . $name; $xml = $path . '/package.xml'; $m4 = $path . '/config.m4'; if (file_exists($xml)) { $this->logger->warning("===> Using xml extension meta"); $meta = new ExtensionMetaXml($xml); } elseif (file_exists($m4)) { $this->logger->warning("===> Using m4 extension meta"); $meta = new ExtensionMetaM4($m4); } else { $this->logger->warning("===> Using polyfill extension meta"); $meta = new ExtensionMetaPolyfill($name); } return $meta; }
/** * This method is the top logic of an application. when there is no * argument provided, we show help content by default. * * @return bool return true if success */ public function execute() { $options = $this->getOptions(); if ($options->version) { $this->logger->writeln($this->getName() . ' - ' . $this->getVersion()); $this->logger->writeln("cliframework core: " . $this->getCoreVersion()); return true; } $arguments = func_get_args(); // show list and help by default $help = $this->getCommand('help'); $help->setOptions($options); if ($help || $options->help) { $help->executeWrapper($arguments); return true; } throw new CommandNotFoundException($this, 'help'); }
/** * Returns schema objects * * @return array schema objects */ public static function findSchemasByArguments(ConfigLoader $loader, array $args, Logger $logger = null) { if (count($args) && !file_exists($args[0])) { $classes = array(); // it's classnames foreach ($args as $class) { // call class loader to load if (class_exists($class, true)) { $classes[] = $class; } else { if ($logger) { $logger->warn("{$class} not found."); } else { echo ">>> {$class} not found.\n"; } } } return ClassUtils::schema_classes_to_objects(array_unique($classes)); } else { $finder = new SchemaFinder(); if (count($args) && file_exists($args[0])) { $finder->setPaths($args); foreach ($args as $file) { if (is_file($file)) { require_once $file; } } } else { if ($paths = $loader->getSchemaPaths()) { $finder->setPaths($paths); } } $finder->find(); // load class from class map if ($classMap = $loader->getClassMap()) { foreach ($classMap as $file => $class) { if (!is_integer($file) && is_string($file)) { require $file; } } } return SchemaLoader::loadDeclaredSchemas(); } }
public function createSchemaGenerator() { $g = new \LazyRecord\Schema\SchemaGenerator(ConfigLoader::getInstance(), Logger::getInstance()); $g->forceUpdate = true; return $g; }
public function setUp() { $logger = new Logger(); $logger->setQuiet(); $this->manager = new ExtensionManager($logger); }
private static function downloadReleaseListFromOfficialSite($version, OptionResult $options = null) { $max = $options && $options->old ? 1000 : 100; $url = "https://secure.php.net/releases/index.php?json&version={$version}&max={$max}"; $file = DownloadFactory::getInstance(Logger::getInstance(), $options)->download($url); $json = file_get_contents($file); return json_decode($json, true); }
public function createLogger() { $logger = new Logger(); $logger->setQuiet(); return $logger; }
public function apply(Buildable $build, Logger $logger) { $patched = 0; foreach ($this->files as $file) { $path = $build->getSourceDirectory() . DIRECTORY_SEPARATOR . $file; if (!file_exists($path)) { $logger->error("file {$path} doesn't exist in the build directory."); continue; } if ($content = file_get_contents($path)) { $content = $this->applyTextContent($content, $patched); if (false === file_put_contents($path, $content)) { $logger->error("Patch on {$path} write failed."); } } } return $patched; }
public static function recursive_unlink($path, Logger $logger) { $directoryIterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS); $it = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST); foreach ($it as $file) { $logger->debug('Deleting ' . $file->getPathname()); if ($file->isDir()) { rmdir($file->getPathname()); } else { unlink($file->getPathname()); } } if (is_dir($path)) { rmdir($path); } elseif (is_file($path)) { unlink($path); } }
public function setUp() { $this->logger = Logger::getInstance(); $this->logger->setQuiet(); }
<?php $loader = (require "vendor/autoload.php"); require "tests/model_helpers.php"; mb_internal_encoding('UTF-8'); error_reporting(E_ALL); $loader->add(null, 'tests'); $loader->add(null, 'tests/src'); use LazyRecord\Schema\SchemaGenerator; use LazyRecord\ConfigLoader; use CLIFramework\Logger; $config = ConfigLoader::getInstance(); $config->loadFromSymbol(true); $config->initForBuild(); $logger = new Logger(); $logger->quiet(); $logger->info("Building schema class files..."); // build schema class files $schemas = array(new \AuthorBooks\Model\AddressSchema(), new \AuthorBooks\Model\AuthorBookSchema(), new \AuthorBooks\Model\AuthorSchema(), new \AuthorBooks\Model\BookSchema(), new \AuthorBooks\Model\PublisherSchema(), new \AuthorBooks\Model\TagSchema(), new \MetricApp\Model\MetricValueSchema(), new \PageApp\Model\PageSchema(), new \StoreApp\Model\StoreSchema(), new \TestApp\Model\EdmSchema(), new \TestApp\Model\IDNumberSchema(), new \TestApp\Model\NameSchema(), new \TestApp\Model\PostSchema(), new \TestApp\Model\TableSchema(), new \TestApp\Model\UserSchema(), new \TestApp\Model\WineCategorySchema(), new \TestApp\Model\WineSchema()); $g = new \LazyRecord\Schema\SchemaGenerator($config, $logger); $g->setForceUpdate(true); $g->generate($schemas, true); // $logger->info("Starting tests...");