/** * Constructor * * @param Array $ini Array from ini_parse * * @return void */ public function __construct() { # Importing configuration self::$_ini = Library_Configuration_Loader::singleton(); # Initializing self::$_memcache = new Memcached(); }
/** * Accessor to command class instance by command type * * @param String $command Type of command * * @return void */ public static function instance($command) { # Importing configuration $_ini = Library_Configuration_Loader::singleton(); # Instance does not exists if (!isset(self::$_object[$_ini->get($command)]) || $_ini->get($command) != 'Server') { # Switching by API switch ($_ini->get($command)) { case 'Memcache': # PECL Memcache API require_once 'Memcache.php'; self::$_object['Memcache'] = new Library_Command_Memcache(); break; case 'Memcached': # PECL Memcached API require_once 'Memcached.php'; self::$_object['Memcached'] = new Library_Command_Memcached(); break; case 'Server': default: # Server API (eg communicating directly with the memcache server) require_once 'Server.php'; self::$_object['Server'] = new Library_Command_Server(); break; } } return self::$_object[$_ini->get($command)]; }
/** * Check for the latest version, from local cache or via http * Return true if a newer version is available, false otherwise * * @return Boolean */ public static function check() { # Loading ini file $_ini = Library_Configuration_Loader::singleton(); # Version definition file path $path = rtrim($_ini->get('file_path'), '/') . DIRECTORY_SEPARATOR . self::$_file; # Checking if file was modified for less than 15 days ago if (is_array($stats = @stat($path)) && isset($stats['mtime']) && $stats['mtime'] > time() - self::$_time) { # Opening file and checking for latest version return version_compare(CURRENT_VERSION, file_get_contents($path)) == -1; } else { # Getting last version /** * @todo Get latest tag/release via GitHub API */ if ($latest = @file_get_contents(self::$_latest)) { # Saving latest version in file file_put_contents($path, $latest); # Checking for latest version return version_compare(CURRENT_VERSION, $latest) == -1; } else { # To avoid error spam file_put_contents($path, 'Net unreachable'); return true; } } }
/** * Get Library_Configuration_Loader singleton * * @return Library_Configuration_Loader */ public static function singleton() { if (!isset(self::$_instance)) { self::$_instance = new self(); } return self::$_instance; }
/** * Dump cluster list in an HTML select * * @return string */ public static function clusterSelect($name, $selected = '', $class = '', $events = '') { # Loading ini file $_ini = Library_Configuration_Loader::singleton(); # Select Name $clusterList = '<select id="' . $name . '" '; # CSS Class $clusterList .= $class != '' ? 'class="' . $class . '"' : ''; # Javascript Events $clusterList .= ' ' . $events . '>'; foreach ($_ini->get('servers') as $cluster => $servers) { # Option value and selected case $clusterList .= '<option value="' . $cluster . '" '; $clusterList .= $selected == $cluster ? 'selected="selected"' : ''; $clusterList .= '>' . $cluster . ' cluster</option>'; } return $clusterList . '</select>'; }
* ><)))°> ><)))°> ><)))°> ><)))°> ><)))°> ><)))°> ><)))°> ><)))°> ><)))°> * * Stats viewing * * @author c.mahieux@of2m.fr * @since 20/03/2010 */ # Headers header('Content-type: text/html; charset=UTF-8'); header('Cache-Control: no-cache, must-revalidate'); # Require require_once 'Library/Loader.php'; # Date timezone date_default_timezone_set('Europe/Paris'); # Loading ini file $_ini = Library_Configuration_Loader::singleton(); # Initializing requests $request = isset($_GET['show']) ? $_GET['show'] : null; # Getting default cluster if (!isset($_GET['server'])) { $clusters = array_keys($_ini->get('servers')); $cluster = isset($clusters[0]) ? $clusters[0] : null; $_GET['server'] = $cluster; } # Showing header include 'View/Header.tpl'; # Display by request type switch ($request) { # Items : Display of all items for a single slab for a single server case 'items': # Initializing items array
ksort($array); foreach ($array as $cluster => $servers) { # Sorting servers ksort($servers); $array[$cluster] = $servers; } # Updating configuration $_ini->set('servers', $array); # Writing configuration file $write = Library_Configuration_Loader::singleton()->write(); break; # Miscellaneous configuration save # Miscellaneous configuration save case 'miscellaneous': # Updating configuration $_ini->set('connection_timeout', $_POST['connection_timeout']); $_ini->set('max_item_dump', $_POST['max_item_dump']); # Writing configuration file $write = Library_Configuration_Loader::singleton()->write(); break; # Default : No command # Default : No command default: break; } # Showing header include 'View/Header.phtml'; # Showing formulary include 'View/Configure/Configure.phtml'; # Showing footer include 'View/Footer.phtml';
/** * Constructor * * @param Array $ini Array from ini_parse * * @return void */ public function __construct() { # Importing configuration self::$_ini = Library_Configuration_Loader::singleton(); }