Example #1
0
 /**
  * @return void
  */
 protected function _generateFileStructure()
 {
     $classes = $this->_extension->getClassNames();
     foreach ($classes as $class) {
         $reflectionClass = new \ReflectionClass($class);
         $output = "<?php\n\n";
         $output .= $this->_exportNamespace($reflectionClass);
         $output .= $this->_exportDefinition($reflectionClass);
         $output .= "\n{\n\n";
         $output .= $this->_exportClassConstants($reflectionClass);
         $output .= $this->_exportClassProperties($reflectionClass);
         $output .= $this->_exportClassMethods($reflectionClass);
         $output .= "}";
         $dir_class = str_replace('\\', DIRECTORY_SEPARATOR, $reflectionClass->getNamespaceName());
         $dir = $this->_targetDir . DIRECTORY_SEPARATOR . $this->_extension->getVersion() . DIRECTORY_SEPARATOR . $dir_class;
         if (!is_dir($dir)) {
             mkdir($dir, 0777, true);
         }
         $file = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php';
         $path = $this->_targetDir . DIRECTORY_SEPARATOR . $this->_extension->getVersion() . DIRECTORY_SEPARATOR . $file;
         $fp = fopen($path, 'w+');
         fputs($fp, $output);
         fclose($fp);
     }
 }
Example #2
0
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new MemoryPackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     foreach (get_loaded_extensions() as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
 }
Example #3
0
 /**
  * 欢迎页面
  */
 public function welcomeOp()
 {
     /**
      * 管理员信息
      */
     $model_admin = Model('admin');
     $tmp = $this->getAdminInfo();
     $condition['admin_id'] = $tmp['id'];
     $admin_info = $model_admin->infoAdmin($condition);
     $admin_info['admin_login_time'] = date('Y-m-d H:i:s', $admin_info['admin_login_time'] == '' ? time() : $admin_info['admin_login_time']);
     /**
      * 系统信息
      */
     $version = C('version');
     $setup_date = C('setup_date');
     $statistics['os'] = PHP_OS;
     $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
     $statistics['php_version'] = PHP_VERSION;
     $statistics['sql_version'] = Db::getServerInfo();
     $statistics['shop_version'] = $version;
     $statistics['setup_date'] = substr($setup_date, 0, 10);
     // 运维舫 c extension
     try {
         $r = new ReflectionExtension('shopnc');
         $statistics['php_version'] .= ' / ' . $r->getVersion();
     } catch (ReflectionException $ex) {
     }
     Tpl::output('statistics', $statistics);
     Tpl::output('admin_info', $admin_info);
     Tpl::showpage('welcome');
 }
Example #4
0
 function __construct()
 {
     if (!extension_loaded(self::EXTENSION_NAME)) {
         throw new \Exception("no " . self::EXTENSION_NAME . " extension.");
     }
     $this->rf_ext = new ReflectionExtension(self::EXTENSION_NAME);
     $this->version = $this->rf_ext->getVersion();
 }
Example #5
0
 /**
  * Returns this extension's version
  * @return string
  */
 public function getVersion()
 {
     if ($this->reflectionSource) {
         return $this->reflectionSource->getVersion();
     } else {
         return parent::getVersion();
     }
 }
Example #6
0
 public static function tExtension($test, $ext)
 {
     try {
         $ref = new ReflectionExtension($ext);
         $v = $ref->getVersion();
         self::setTestData($test, '%s found%s', $ref->getName(), $v ? ' v' . $v : '');
         return true;
     } catch (ReflectionException $e) {
         self::setTestData($test, $e->getMessage());
     }
     return false;
 }
 /**
  * Constructor.
  */
 protected function __construct()
 {
     $this->memcached = new \Memcached();
     $this->memcached->addServer(Config::getCacheHost(), Config::getCachePort());
     $this->memcached->setOption(\Memcached::OPT_PREFIX_KEY, Config::getCachePrefix());
     //determine if deleteMulti() is supported
     if (defined('HHVM_VERSION')) {
         $this->hasMultiDelete = false;
     } else {
         $ext = new \ReflectionExtension('memcached');
         $this->hasMultiDelete = version_compare($ext->getVersion(), '2.0.0', '>=');
     }
 }
Example #8
0
 /**
  * @return array
  */
 public function opcodeCacheData()
 {
     $cacheData = array();
     foreach (static::$opcacheExtenstions as $name => $data) {
         list($title, $iniSetting) = $data;
         if ($this->hasCache($name, $iniSetting)) {
             $cacheData['title'] = $title;
             $cacheData['name'] = $name;
             $ref = new \ReflectionExtension($name);
             $cacheData['version'] = $ref->getVersion();
             $cacheData['settings'] = $ref->getINIEntries();
             break;
         }
     }
     return $cacheData;
 }
function export_ext($ext)
{
    $rf_ext = new ReflectionExtension($ext);
    $funcs = $rf_ext->getFunctions();
    $classes = $rf_ext->getClasses();
    $consts = $rf_ext->getConstants();
    $version = $rf_ext->getVersion();
    $defines = '';
    $sp4 = str_repeat(' ', 4);
    $fdefs = getFuncDef($funcs, $version);
    $class_def = '';
    foreach ($consts as $k => $v) {
        if (!is_numeric($v)) {
            $v = "'{$v}'";
        }
        $defines .= "define('{$k}',{$v});\n";
    }
    foreach ($classes as $k => $v) {
        $prop_str = '';
        $props = $v->getProperties();
        array_walk($props, function ($v, $k) {
            global $prop_str, $sp4;
            $modifiers = implode(' ', Reflection::getModifierNames($v->getModifiers()));
            $prop_str .= "{$sp4}/**\n{$sp4}*@var \$" . $v->name . " " . $v->class . "\n{$sp4}*/\n{$sp4} {$modifiers}  \$" . $v->name . ";\n\n";
        });
        if ($v->getParentClass()) {
            $k .= ' extends ' . $v->getParentClass()->name;
        }
        $modifier = 'class';
        if ($v->isInterface()) {
            $modifier = 'interface';
        }
        $mdefs = getMethodsDef($v->getMethods(), $version);
        $class_def .= sprintf("/**\n*@since %s\n*/\n%s %s{\n%s%s\n}\n", $version, $modifier, $k, $prop_str, $mdefs);
    }
    if (!file_exists('./ext')) {
        mkdir('./ext', 777, TRUE);
    }
    file_put_contents("./ext/" . $ext . ".php", "<?php\n" . $defines . $fdefs . $class_def);
}
Example #10
0
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     // Add each of the override versions as options.
     // Later we might even replace the extensions instead.
     foreach ($this->overrides as $override) {
         // Check that it's a platform package.
         if (!preg_match(self::PLATFORM_PACKAGE_REGEX, $override['name'])) {
             throw new \InvalidArgumentException('Invalid platform package name in config.platform: ' . $override['name']);
         }
         $version = $versionParser->normalize($override['version']);
         $package = new CompletePackage($override['name'], $version, $override['version']);
         $package->setDescription('Package overridden via config.platform');
         $package->setExtra(array('config.platform' => true));
         parent::addPackage($package);
     }
     $prettyVersion = PluginInterface::PLUGIN_API_VERSION;
     $version = $versionParser->normalize($prettyVersion);
     $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion);
     $composerPluginApi->setDescription('The Composer Plugin API');
     $this->addPackage($composerPluginApi);
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new CompletePackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     $this->addPackage($php);
     if (PHP_INT_SIZE === 8) {
         $php64 = new CompletePackage('php-64bit', $version, $prettyVersion);
         $php64->setDescription('The PHP interpreter, 64bit');
         $this->addPackage($php64);
     }
     $loadedExtensions = get_loaded_extensions();
     // Extensions scanning
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $packageName = $this->buildPackageName($name);
         $ext = new CompletePackage($packageName, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         $this->addPackage($ext);
     }
     // Another quick loop, just for possible libraries
     // Doing it this way to know that functions or constants exist before
     // relying on them.
     foreach ($loadedExtensions as $name) {
         $prettyVersion = null;
         $description = 'The ' . $name . ' PHP library';
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'intl':
                 $name = 'ICU';
                 if (defined('INTL_ICU_VERSION')) {
                     $prettyVersion = INTL_ICU_VERSION;
                 } else {
                     $reflector = new \ReflectionExtension('intl');
                     ob_start();
                     $reflector->info();
                     $output = ob_get_clean();
                     preg_match('/^ICU version => (.*)$/m', $output, $matches);
                     $prettyVersion = $matches[1];
                 }
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]*).*}', function ($match) {
                     if (empty($match[2])) {
                         return $match[1];
                     }
                     // OpenSSL versions add another letter when they reach Z.
                     // e.g. OpenSSL 0.9.8zh 3 Dec 2015
                     if (!preg_match('{^z*[a-z]$}', $match[2])) {
                         // 0.9.8abc is garbage
                         return 0;
                     }
                     $len = strlen($match[2]);
                     $patchVersion = ($len - 1) * 26;
                     // All Z
                     $patchVersion += ord($match[2][$len - 1]) - 96;
                     return $match[1] . '.' . $patchVersion;
                 }, OPENSSL_VERSION_TEXT);
                 $description = OPENSSL_VERSION_TEXT;
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 // None handled extensions have no special cases, skip
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription($description);
         $this->addPackage($lib);
     }
     if (defined('HHVM_VERSION')) {
         try {
             $prettyVersion = HHVM_VERSION;
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', HHVM_VERSION);
             $version = $versionParser->normalize($prettyVersion);
         }
         $hhvm = new CompletePackage('hhvm', $version, $prettyVersion);
         $hhvm->setDescription('The HHVM Runtime (64bit)');
         $this->addPackage($hhvm);
     }
 }
<?php

$r = new ReflectionExtension("mysql");
printf("Name: %s\n", $r->name);
printf("Version: %s\n", $r->getVersion());
$classes = $r->getClasses();
if (!empty($classes)) {
    printf("[002] Expecting no class\n");
    asort($classes);
    var_dump($classes);
}
$ignore = array();
$functions = $r->getFunctions();
asort($functions);
printf("Functions:\n");
foreach ($functions as $func) {
    if (isset($ignore[$func->name])) {
        unset($ignore[$func->name]);
    } else {
        printf("  %s\n", $func->name);
    }
}
if (!empty($ignore)) {
    printf("Dumping version dependent and missing functions\n");
    var_dump($ignore);
}
print "done!";
 echo "Environment Check{$n}";
 echo "-----------------{$n}{$n}";
 echo "\"-\" indicates success.{$n}";
 echo "\"*\" indicates error.{$n}{$n}";
 // check version
 check('You have a supported version of PHP (>= 5.3.3).', 'You need PHP 5.3.3 or greater.', function () {
     return version_compare(PHP_VERSION, '5.3.3', '>=');
 });
 // check phar extension
 check('You have the "phar" extension installed.', 'You need to have the "phar" extension installed.', function () {
     return extension_loaded('phar');
 });
 // check phar extension version
 check('You have a supported version of the "phar" extension.', 'You need a newer version of the "phar" extension (>=2.0).', function () {
     $phar = new ReflectionExtension('phar');
     return version_compare($phar->getVersion(), '2.0', '>=');
 });
 // check openssl extension
 check('You have the "openssl" extension installed.', 'Notice: The "openssl" extension will be needed to sign with private keys.', function () {
     return extension_loaded('openssl');
 }, false);
 // check phar readonly setting
 check('The "phar.readonly" setting is off.', 'Notice: The "phar.readonly" setting needs to be off to create Phars.', function () {
     return false == ini_get('phar.readonly');
 }, false);
 // check detect unicode setting
 check('The "detect_unicode" setting is off.', 'The "detect_unicode" setting needs to be off.', function () {
     return false == ini_get('detect_unicode');
 });
 // check suhosin setting
 if (extension_loaded('suhosin')) {
Example #13
0
 public function checkZkState()
 {
     /*{{{*/
     $ext = new ReflectionExtension('zookeeper');
     $ver = $ext->getVersion();
     if (version_compare($ver, '0.2.0') < 0) {
         //throw new LogConfException("Required version of extension($name) is at least $version_min!");
         return;
     }
     $state = getState($this->zkClient_);
     if (ZOK != $state) {
         throw new LogConfException("zookeeper connection state wrong: {$state}");
     }
 }
Example #14
0
--TEST--
Reflection Extension -> basic
--FILE--
<?php 
$r = new ReflectionExtension("core");
var_dump($r->getName());
var_dump($r->getVersion());
try {
    $r = new ReflectionExtension("unknown");
} catch (ReflectionException $e) {
    var_dump($e->getMessage());
}
?>
--EXPECTF--
string(4) "Core"
string(%d) "%d.%s
string(32) "Extension unknown does not exist"
 /**
  * Load PHP extension (module) if absent
  * @param string $mod
  * @param string $version
  * @param string $compare
  * @return bool $success
  */
 public static function loadModuleIfAbsent($mod, $version = null, $compare = '>=')
 {
     if (!extension_loaded($mod)) {
         if (!get_cfg_var('enable_dl')) {
             return false;
         }
         if (!@dl(basename($mod) . '.so')) {
             return false;
         }
     }
     if (!$version) {
         return true;
     }
     try {
         $ext = new \ReflectionExtension($mod);
         return version_compare($ext->getVersion(), $version, $compare);
     } catch (\ReflectionException $e) {
         return false;
     }
 }
Example #16
0
 /**
  * Get all info about function
  * @param string|function $extensionName Function or function name
  * @return array|bool
  */
 protected static function _getExtension($extensionName)
 {
     if (!extension_loaded($extensionName)) {
         return false;
     }
     $ext = new ReflectionExtension($extensionName);
     $result = array();
     $result['name'] = $ext->name;
     $result['version'] = $ext->getVersion();
     if ($constants = $ext->getConstants()) {
         $result['constants'] = $constants;
     }
     if ($classesName = $ext->getClassNames()) {
         $result['classesName'] = $classesName;
     }
     if ($functions = $ext->getFunctions()) {
         $result['functions'] = $functions;
     }
     if ($dependencies = $ext->getDependencies()) {
         $result['dependencies'] = $dependencies;
     }
     if ($INIEntries = $ext->getINIEntries()) {
         $result['INIEntries'] = $INIEntries;
     }
     $functions = $ext->getFunctions();
     if (is_array($functions) && count($functions) > 0) {
         $result['functions'] = array();
         foreach ($functions as $function) {
             $funcName = $function->getName();
             $result['functions'][$funcName] = self::_getFunction($funcName);
         }
     }
     return $result;
 }
<?php

/**
 * @author rugk
 * @copyright Copyright (c) 2015-2016 rugk
 * @license MIT
 */
$EOL = "<br>\n";
// method1
$timeStart = microtime();
$ext = new ReflectionExtension('libsodium');
var_dump($ext->getVersion());
$timeEnd = microtime();
echo $EOL . $timeEnd - $timeStart . ' μs' . $EOL;
// method2
echo $EOL;
$timeStart = microtime();
var_dump(phpversion('libsodium'));
$timeEnd = microtime();
echo $EOL . $timeEnd - $timeStart . ' μs' . $EOL;
Example #18
0
                <?php 
    echo '<img src="data:image/png;base64,' . Image::PHALCON . '" class="ext-logo">';
    ?>
                <?php 
    echo "Phalcon Version: " . $ext->getVersion() . "</br>";
    ?>
            </div>
        <?php 
}
?>

        <?php 
if (extension_loaded('Lynx')) {
    ?>
            <div class="row">
                <?php 
    $ext = new ReflectionExtension('lynx');
    ?>
                <?php 
    echo '<img src="http://dmtry.me/img/logos/lynx_bnw.svg" class="ext-logo">';
    ?>
                <?php 
    echo "Lynx Version: " . $ext->getVersion() . "</br>";
    ?>
            </div>
        <?php 
}
?>
    </div>
</body>
</html>
 /**
  * Try to disable APC.
  *
  * @return bool Return true on success, false if not.
  */
 public static function disableApc()
 {
     if (in_array('ini_set', self::getDisabledFunctions())) {
         return false;
     }
     $apc = new \ReflectionExtension('apc');
     if (version_compare($apc->getVersion(), self::APC_MIN_VERSION_RUNTIME_CACHE_BY_DEFAULT, '<')) {
         return false;
     }
     return ini_set('apc.cache_by_default', 0) !== false;
 }
Example #20
0
 /**
  * Creates a package from the data in the source folder
  * @param string $sourceFolder
  * @param string $destinationFolder
  * @param string $fileName
  * @param array  $extraProperties
  * @param string $customVersion
  *
  * @return string path to the created zpk
  */
 public function pack($sourceFolder, $destinationFolder = ".", $fileName = null, array $extraProperties = null, $customVersion = "")
 {
     if (!file_exists($sourceFolder . "/deployment.xml")) {
         throw new RuntimeException('The specified directory does not have deployment.xml.');
     }
     // get the current meta information
     $xml = new \SimpleXMLElement(file_get_contents($sourceFolder . "/deployment.xml"));
     $name = sprintf("%s", $xml->name);
     $version = sprintf("%s", $xml->version->release);
     $appDir = trim(sprintf("%s", $xml->appdir));
     $scriptsDir = trim(sprintf("%s", $xml->scriptsdir));
     $type = sprintf("%s", $xml->type);
     $icon = sprintf("%s", $xml->icon);
     if (!empty($customVersion)) {
         $version = $customVersion;
         $xml->version->release = $version;
         $xml->asXML($sourceFolder . "/deployment.xml");
         $fixedContent = $this->updateXML($sourceFolder . "/deployment.xml", array());
         if ($fixedContent) {
             file_put_contents($sourceFolder . "/deployment.xml", $fixedContent);
         }
     }
     $properties = $this->getProperties($sourceFolder . "/deployment.properties");
     if ($extraProperties !== null) {
         $properties = array_merge_recursive($properties, $extraProperties);
         foreach ($properties as $key => $value) {
             $properties[$key] = array_unique($value);
         }
     }
     if (!$fileName) {
         $fileName = "{$name}-{$version}.zpk";
     }
     $fileName = str_replace(array('/'), array('.'), $fileName);
     $outZipPath = $destinationFolder . '/' . $fileName;
     $ext = new \ReflectionExtension('zip');
     $zipVersion = $ext->getVersion();
     if (!version_compare($zipVersion, '1.11.0', '>=')) {
         error_log("WARNING: Non-Ascii file/folder names are supported only with PHP zip extension >=1.11.0 (your version is: {$zipVersion})\n\t(http://pecl.php.net/package-changelog.php?package=zip&release=1.11.0)");
     }
     $zpk = new \ZipArchive();
     $zpk->open($outZipPath, \ZIPARCHIVE::CREATE | \ZIPARCHIVE::OVERWRITE);
     $zpk->addFile($sourceFolder . "/deployment.xml", 'deployment.xml');
     // Add the icon file that was specified!
     if (!empty($icon)) {
         $zpk->addFile($sourceFolder . "/" . $icon, $icon);
     }
     // Get the include map
     $includeMap = array();
     if ($type == self::TYPE_LIBRARY) {
         $appDir = '';
     }
     $includeMap['appdir'] = $this->getAppPaths($appDir, $properties['appdir.includes']);
     // get script paths
     if (!empty($scriptsDir) && isset($properties['scriptsdir.includes'])) {
         $includeMap['scriptsdir'] = $this->getScriptPaths($scriptsDir, $properties['scriptsdir.includes'], $sourceFolder);
     }
     ErrorHandler::start();
     foreach ($includeMap as $type => $paths) {
         $excludes = array();
         if (isset($properties[$type . '.excludes'])) {
             $excludes = $properties[$type . '.excludes'];
         }
         $excludedEndings = array();
         $excludedFileSuffixes = array();
         foreach ($excludes as $exclude) {
             $exclude = trim($exclude);
             $exclude = rtrim($exclude, '/');
             # no trailing slashes
             if (strlen($exclude) == 0) {
                 continue;
             }
             // We support **/<something> syntax. It means all entries that have <something> as name
             // will be excluded from the list of files
             if (preg_match("/^\\*\\*\\/(.*?)\$/", $exclude, $matches)) {
                 $excludedEndings[$matches[1]] = strlen($matches[1]);
             }
             // We support also the *<something>. It means all FILES with names ending with <something>
             if (preg_match("/^\\*([^\\*]+)\$/", $exclude, $matches)) {
                 $excludedFileSuffixes[$matches[1]] = strlen($matches[1]);
             }
         }
         foreach ($paths as $localPath => $zpkPath) {
             $this->addPathToZpk($zpk, $sourceFolder, $localPath, $zpkPath, $excludes, $excludedEndings, $excludedFileSuffixes);
         }
     }
     if (!$zpk->close()) {
         throw new RuntimeException('Failed creating zpk file: ' . $outZipPath . ". " . $zpk->getStatusString());
     }
     ErrorHandler::stop(true);
     return $outZipPath;
 }
Example #21
0
<pre>
<?php 
// Создание экземпляра класса ReflectionProperty
$ext = new ReflectionExtension('standard');
// Вывод основной информации
printf("Имя           : %s\n" . "Версия        : %s\n" . "Функции       : [%d] %s\n" . "Константы     : [%d] %s\n" . "Директивы INI : [%d] %s\n" . "Классы        : [%d] %s\n", $ext->getName(), $ext->getVersion() ? $ext->getVersion() : 'NO_VERSION', sizeof($ext->getFunctions()), var_export($ext->getFunctions(), 1), sizeof($ext->getConstants()), var_export($ext->getConstants(), 1), sizeof($ext->getINIEntries()), var_export($ext->getINIEntries(), 1), sizeof($ext->getClassNames()), var_export($ext->getClassNames(), 1));
?>
</pre>
Example #22
0
 public function addServer($host = '127.0.0.1', $port = 6379, $dbIndex = 6, $weight = 1)
 {
     $redis = new Redis();
     $rhost = $host . ':' . $port;
     $connection_string = $rhost . '/' . $dbIndex;
     $redis_ext_refc = new ReflectionExtension('redis');
     if (version_compare($redis_ext_refc->getVersion(), '2.1.0') <= 0) {
         $bret = $redis->pconnect($host, $port, 0);
     } else {
         $bret = $redis->pconnect($host, $port, 0, $connection_string);
     }
     if ($bret) {
         $redis->select($dbIndex);
         // redis-proxy and high redis not support this anymore
         $this->_hash->addTarget($rhost);
         $this->_pool[$rhost] = $redis;
         return true;
     }
     unset($redis);
     return false;
 }
Example #23
0
 /**
  * The actual task is defined in this method. Here you can access any option or argument that was defined on the
  * command line via $input and write anything to the console via $output argument.
  * In case anything went wrong during the execution you should throw an exception to make sure the user will get a
  * useful error message and to make sure the command does not exit with the status code 0.
  *
  * Ideally, the actual command is quite short as it acts like a controller. It should only receive the input values,
  * execute the task by calling a method of another class and output any useful information.
  *
  * Execute the command like: ./console queuedtracking:test --name="The Piwik Team"
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $systemCheck = new SystemCheck();
     $systemCheck->checkRedisIsInstalled();
     $trackerEnvironment = new Environment('tracker');
     $trackerEnvironment->init();
     Tracker::loadTrackerEnvironment();
     $settings = Queue\Factory::getSettings();
     $output->writeln('<comment>Settings that will be used:</comment>');
     $output->writeln('Host: ' . $settings->redisHost->getValue());
     $output->writeln('Port: ' . $settings->redisPort->getValue());
     $output->writeln('Timeout: ' . $settings->redisTimeout->getValue());
     $output->writeln('Password: '******'Database: ' . $settings->redisDatabase->getValue());
     $output->writeln('NumQueueWorkers: ' . $settings->numQueueWorkers->getValue());
     $output->writeln('NumRequestsToProcess: ' . $settings->numRequestsToProcess->getValue());
     $output->writeln('ProcessDuringTrackingRequest: ' . (int) $settings->processDuringTrackingRequest->getValue());
     $output->writeln('QueueEnabled: ' . (int) $settings->queueEnabled->getValue());
     $output->writeln('');
     $output->writeln('<comment>Version / stats:</comment>');
     $output->writeln('PHP version: ' . phpversion());
     $output->writeln('Uname: ' . php_uname());
     $extension = new \ReflectionExtension('redis');
     $output->writeln('PHPRedis version: ' . $extension->getVersion());
     $backend = Queue\Factory::makeBackend();
     $output->writeln('Redis version: ' . $backend->getServerVersion());
     $output->writeln('Memory: ' . var_export($backend->getMemoryStats(), 1));
     $redis = $backend->getConnection();
     $evictionPolicy = $this->getRedisConfig($redis, 'maxmemory-policy');
     $output->writeln('MaxMemory Eviction Policy config: ' . $evictionPolicy);
     if ($evictionPolicy !== 'allkeys-lru' && $evictionPolicy !== 'noeviction') {
         $output->writeln('<error>The eviction policy can likely lead to errors when memory is low. We recommend to use eviction policy <comment>allkeys-lru</comment> or alternatively <comment>noeviction</comment>. Read more here: http://redis.io/topics/lru-cache</error>');
     }
     $evictionPolicy = $this->getRedisConfig($redis, 'maxmemory');
     $output->writeln('MaxMemory config: ' . $evictionPolicy);
     $output->writeln('');
     $output->writeln('<comment>Performing some tests:</comment>');
     if (method_exists($redis, 'isConnected')) {
         $output->writeln('Redis is connected: ' . (int) $redis->isConnected());
     }
     if ($backend->testConnection()) {
         $output->writeln('Connection works in general');
     } else {
         $output->writeln('Connection does not actually work: ' . $redis->getLastError());
     }
     $this->testRedis($redis, 'set', array('testKey', 'value'), 'testKey', $output);
     $this->testRedis($redis, 'setnx', array('testnxkey', 'value'), 'testnxkey', $output);
     $this->testRedis($redis, 'setex', array('testexkey', 5, 'value'), 'testexkey', $output);
     $this->testRedis($redis, 'set', array('testKeyWithNx', 'value', array('nx')), 'testKeyWithNx', $output);
     $this->testRedis($redis, 'set', array('testKeyWithEx', 'value', array('ex' => 5)), 'testKeyWithEx', $output);
     $backend->delete('foo');
     if (!$backend->setIfNotExists('foo', 'bar', 5)) {
         $output->writeln("setIfNotExists(foo, bar, 1) does not work, most likely we won't be able to acquire a lock:" . $redis->getLastError());
     } else {
         $initialTtl = $redis->ttl('foo');
         if ($initialTtl > 3 && $initialTtl <= 5) {
             $output->writeln('Initial expire seems to be set correctly');
         } else {
             $output->writeln('<error>Initial expire seems to be not set correctly: ' . $initialTtl . ' </error>');
         }
         if ($backend->get('foo') == 'bar') {
             $output->writeln('setIfNotExists works fine');
         } else {
             $output->writeln('There might be a problem with setIfNotExists');
         }
         if ($backend->expireIfKeyHasValue('foo', 'bar', 10)) {
             $output->writeln('expireIfKeyHasValue seems to work fine');
         } else {
             $output->writeln('<error>There might be a problem with expireIfKeyHasValue: ' . $redis->getLastError() . '</error>');
         }
         $extendedTtl = $redis->ttl('foo');
         if ($extendedTtl > 8 && $extendedTtl <= 10) {
             $output->writeln('Extending expire seems to be set correctly');
         } else {
             $output->writeln('<error>Extending expire seems to be not set correctly: ' . $extendedTtl . ' </error>');
         }
         if ($backend->expireIfKeyHasValue('foo', 'invalidValue', 10)) {
             $output->writeln('<error>expireIfKeyHasValue expired a key which it should not have since values does not match</error>');
         } else {
             $output->writeln('expireIfKeyHasValue correctly expires only when the value is correct');
         }
         $extendedTtl = $redis->ttl('foo');
         if ($extendedTtl > 7 && $extendedTtl <= 10) {
             $output->writeln('Expire is still set which is correct');
         } else {
             $output->writeln('<error>Expire missing after a wrong extendExpire: ' . $extendedTtl . ' </error>');
         }
         if ($backend->deleteIfKeyHasValue('foo', 'bar')) {
             $output->writeln('deleteIfKeyHasValue seems to work fine');
         } else {
             $output->writeln('<error>There might be a problem with deleteIfKeyHasValue: ' . $redis->getLastError() . '</error>');
         }
     }
     $redis->delete('fooList');
     $backend->appendValuesToList('fooList', array('value1', 'value2', 'value3'));
     $values = $backend->getFirstXValuesFromList('fooList', 2);
     if ($values == array('value1', 'value2')) {
         $backend->removeFirstXValuesFromList('fooList', 1);
         $backend->removeFirstXValuesFromList('fooList', 1);
         $values = $backend->getFirstXValuesFromList('fooList', 2);
         if ($values == array('value3')) {
             $output->writeln('List feature seems to work fine');
         } else {
             $output->writeln('List feature seems to work only partially: ' . var_export($values, 1));
         }
     } else {
         $output->writeln('<error>List feature seems to not work fine: ' . $redis->getLastError() . '</error>');
     }
     $output->writeln('');
     $output->writeln('<comment>Done</comment>');
 }
Example #24
0
<?php

set_time_limit(getenv('TEST_TIMEOUT') ?: 120);
try {
    $ext = new ReflectionExtension('xdebug');
    $xdebug = '(with xdebug ' . $ext->getVersion() . ')';
} catch (Exception $e) {
    $xdebug = '(without xdebug)';
}
$ext = new ReflectionExtension('amqp');
$srcVersion = $ext->getVersion();
echo 'Running benchmark for php-amqp ', $srcVersion, ' on PHP ', PHP_VERSION, ' ', $xdebug, PHP_EOL;
$iterations = 10000;
if (isset($argv[1])) {
    $iterations = max((int) $argv[1], 0) ?: $iterations;
}
echo '  running ', $iterations, ' iterations:', PHP_EOL, PHP_EOL;
$conn = new AMQPConnection();
$conn->connect();
$ch = new AMQPChannel($conn);
$exchange = new AMQPExchange($ch);
$exchange->setType(AMQP_EX_TYPE_FANOUT);
$exchange->setFlags(AMQP_AUTODELETE);
$exchange->setName('benchmark_exchange_' . microtime(true));
$exchange->declareExchange();
$q = new AMQPQueue($ch);
$q->setFlags(AMQP_AUTODELETE);
$q->declareQueue();
$q->bind($exchange->getName());
$message = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
$timer = microtime(true);
Example #25
0
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     $prettyVersion = PluginInterface::PLUGIN_API_VERSION;
     $version = $versionParser->normalize($prettyVersion);
     $composerPluginApi = new CompletePackage('composer-plugin-api', $version, $prettyVersion);
     $composerPluginApi->setDescription('The Composer Plugin API');
     parent::addPackage($composerPluginApi);
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new CompletePackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     if (PHP_INT_SIZE === 8) {
         $php64 = new CompletePackage('php-64bit', $version, $prettyVersion);
         $php64->setDescription('The PHP interpreter (64bit)');
         parent::addPackage($php64);
     }
     $loadedExtensions = get_loaded_extensions();
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $packageName = $this->buildPackageName($name);
         $ext = new CompletePackage($packageName, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
     foreach ($loadedExtensions as $name) {
         $prettyVersion = null;
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'intl':
                 $name = 'ICU';
                 if (defined('INTL_ICU_VERSION')) {
                     $prettyVersion = INTL_ICU_VERSION;
                 } else {
                     $reflector = new \ReflectionExtension('intl');
                     ob_start();
                     $reflector->info();
                     $output = ob_get_clean();
                     preg_match('/^ICU version => (.*)$/m', $output, $matches);
                     $prettyVersion = $matches[1];
                 }
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
                     return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
                 }, OPENSSL_VERSION_TEXT);
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription('The ' . $name . ' PHP library');
         parent::addPackage($lib);
     }
     if (defined('HHVM_VERSION')) {
         try {
             $prettyVersion = HHVM_VERSION;
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', HHVM_VERSION);
             $version = $versionParser->normalize($prettyVersion);
         }
         $hhvm = new CompletePackage('hhvm', $version, $prettyVersion);
         $hhvm->setDescription('The HHVM Runtime (64bit)');
         parent::addPackage($hhvm);
     }
 }
<?php

$obj = new ReflectionExtension('reflection');
$var = $obj->getVersion() ? $obj->getVersion() : null;
$test = floatval($var) == $var ? true : false;
var_dump($test);
?>
==DONE==
 protected function initialize()
 {
     $loadedExtensions = get_loaded_extensions();
     $packages = array();
     // Extensions scanning
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $ext = new \ReflectionExtension($name);
         try {
             $prettyVersion = $ext->getVersion();
             $prettyVersion = $this->normalizeVersion($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $prettyVersion = $this->normalizeVersion($prettyVersion);
         }
         $packages[$this->buildPackageName($name)] = $prettyVersion;
     }
     foreach ($loadedExtensions as $name) {
         $prettyVersion = null;
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'intl':
                 $name = 'ICU';
                 if (defined('INTL_ICU_VERSION')) {
                     $prettyVersion = INTL_ICU_VERSION;
                 } else {
                     $reflector = new \ReflectionExtension('intl');
                     ob_start();
                     $reflector->info();
                     $output = ob_get_clean();
                     preg_match('/^ICU version => (.*)$/m', $output, $matches);
                     $prettyVersion = $matches[1];
                 }
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
                     return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
                 }, OPENSSL_VERSION_TEXT);
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 // None handled extensions have no special cases, skip
                 continue 2;
         }
         try {
             $prettyVersion = $this->normalizeVersion($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $packages[$this->buildPackageName($name)] = $prettyVersion;
     }
     return $packages;
 }
Example #28
0
<?php

$e = new ReflectionExtension('gearman');
print "<?php\n\n// Gearman Version: " . $e->getVersion() . "\n\n";
foreach ($e->getClasses() as $c) {
    print 'class ' . $c->name . " {\n";
    foreach ($c->getMethods() as $m) {
        print '  ';
        if ($m->isPublic()) {
            print 'public';
        } elseif ($m->isProtected()) {
            print 'protected';
        } elseif ($m->isPrivate()) {
            print 'private';
        }
        print ' function ' . $m->name . '(';
        $sep = '';
        foreach ($m->getParameters() as $p) {
            print $sep;
            $sep = ', ';
            if ($p->isOptional()) {
                print '$' . $p->name . ' = null';
            } else {
                print '$' . $p->name;
            }
        }
        print "){}\n";
    }
    print "}\n\n";
}
// var_dump(class_exists('ReflectionExtension'));
Example #29
0
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^(.+?)(-.+)?$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new MemoryPackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     $loadedExtensions = get_loaded_extensions();
     // Extensions scanning
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $ext = new MemoryPackage('ext-' . $name, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
     // Another quick loop, just for possible libraries
     // Doing it this way to know that functions or constants exist before
     // relying on them.
     foreach ($loadedExtensions as $name) {
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
                     return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
                 }, OPENSSL_VERSION_TEXT);
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 // None handled extensions have no special cases, skip
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new MemoryPackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription('The ' . $name . ' PHP library');
         parent::addPackage($lib);
     }
 }
 protected function initialize()
 {
     parent::initialize();
     $versionParser = new VersionParser();
     try {
         $prettyVersion = PHP_VERSION;
         $version = $versionParser->normalize($prettyVersion);
     } catch (\UnexpectedValueException $e) {
         $prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
         $version = $versionParser->normalize($prettyVersion);
     }
     $php = new CompletePackage('php', $version, $prettyVersion);
     $php->setDescription('The PHP interpreter');
     parent::addPackage($php);
     if (PHP_INT_SIZE === 8) {
         $php64 = new CompletePackage('php-64bit', $version, $prettyVersion);
         $php64->setDescription('The PHP interpreter (64bit)');
         parent::addPackage($php64);
     }
     $loadedExtensions = get_loaded_extensions();
     // Extensions scanning
     foreach ($loadedExtensions as $name) {
         if (in_array($name, array('standard', 'Core'))) {
             continue;
         }
         $reflExt = new \ReflectionExtension($name);
         try {
             $prettyVersion = $reflExt->getVersion();
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             $prettyVersion = '0';
             $version = $versionParser->normalize($prettyVersion);
         }
         $ext = new CompletePackage('ext-' . $name, $version, $prettyVersion);
         $ext->setDescription('The ' . $name . ' PHP extension');
         parent::addPackage($ext);
     }
     // Another quick loop, just for possible libraries
     // Doing it this way to know that functions or constants exist before
     // relying on them.
     foreach ($loadedExtensions as $name) {
         $prettyVersion = null;
         switch ($name) {
             case 'curl':
                 $curlVersion = curl_version();
                 $prettyVersion = $curlVersion['version'];
                 break;
             case 'iconv':
                 $prettyVersion = ICONV_VERSION;
                 break;
             case 'intl':
                 $name = 'ICU';
                 if (defined('INTL_ICU_VERSION')) {
                     $prettyVersion = INTL_ICU_VERSION;
                 } else {
                     $reflector = new \ReflectionExtension('intl');
                     ob_start();
                     $reflector->info();
                     $output = ob_get_clean();
                     preg_match('/^ICU version => (.*)$/m', $output, $matches);
                     $prettyVersion = $matches[1];
                 }
                 break;
             case 'libxml':
                 $prettyVersion = LIBXML_DOTTED_VERSION;
                 break;
             case 'openssl':
                 $prettyVersion = preg_replace_callback('{^(?:OpenSSL\\s*)?([0-9.]+)([a-z]?).*}', function ($match) {
                     return $match[1] . (empty($match[2]) ? '' : '.' . (ord($match[2]) - 96));
                 }, OPENSSL_VERSION_TEXT);
                 break;
             case 'pcre':
                 $prettyVersion = preg_replace('{^(\\S+).*}', '$1', PCRE_VERSION);
                 break;
             case 'uuid':
                 $prettyVersion = phpversion('uuid');
                 break;
             case 'xsl':
                 $prettyVersion = LIBXSLT_DOTTED_VERSION;
                 break;
             default:
                 // None handled extensions have no special cases, skip
                 continue 2;
         }
         try {
             $version = $versionParser->normalize($prettyVersion);
         } catch (\UnexpectedValueException $e) {
             continue;
         }
         $lib = new CompletePackage('lib-' . $name, $version, $prettyVersion);
         $lib->setDescription('The ' . $name . ' PHP library');
         parent::addPackage($lib);
     }
 }