note 99606 deleted from function.dl by danbrown

From: Date: Thu, 26 Aug 2010 14:33:16 +0000
Subject: note 99606 deleted from function.dl by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172090@lists.php.net to get a copy of this message
Note Submitter: pas dot svijeta at gmail dot com ---- A class to dl - regarding shaunspiller's way to solve different extension formats class Class_to_dl { private function __construct() { $ext = func_get_arg(); $ext_rgx = '/^(php_)?+(\w++)(\.(?(1)(dll)|(so)))?$/i'; if (preg_match($ext_rgx, $ext, $m) && !extension_loaded($m[2])) { $ext = preg_replace($ext_rgx, PHP_SHLIB_SUFFIX == 'dll' ? 'php_\\2.' : '\\2.', $ext).PHP_SHLIB_SUFFIX; try { if (!($ext = self::isExtension($ext) && dl($ext))) throw new Exception('--!??!--'); } catch (Exception $e) { die($e->__toString()); } } } private static function isExtension() { static $ext_dir; if (is_null($ext_dir)) $ext_dir = scandir(ini_get('extension_dir')); return ($key = array_search(strtolower(func_get_arg(0))), array_map('strtolower', $ext_dir)) ? $ext_dir[$key] : $key; } public static function setExtension() { if (!(function_exists('dl') && ini_get('enable_dl'))) throw new Exception('--!??!--'); for ($i = 0, $n = func_num_args(); $i < $n; ++i) new self(func_get_arg($i)); } } Class_to_dl::setExtension($ext_1 [, $ext_2 [,...]]); where $ext_i can be given in various formats, for example Class_to_dl::setExtension('php_ext_1', 'php_ext_2.dll', 'ext_3', 'ext_4.so');

« previous php.notes (#172090) next »