Dieser Commit ist enthalten in:
Ursprung
2b21070b1a
Commit
f7a7c71f86
1583 geänderte Dateien mit 454759 neuen und 0 gelöschten Zeilen
1
library/.htaccess
Normale Datei
1
library/.htaccess
Normale Datei
|
|
@ -0,0 +1 @@
|
|||
Deny from all
|
||||
500
library/Debug.php
Normale Datei
500
library/Debug.php
Normale Datei
|
|
@ -0,0 +1,500 @@
|
|||
<?php
|
||||
/**
|
||||
* Statische Klasse für Debug-Ausgaben.
|
||||
*
|
||||
* Die Klassenkonstanten sind global mit dem Präfix <i>DEBUG_</i> verfügbar.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @author D4rk4ng3l
|
||||
* @version 0.3
|
||||
* @copyright 2010 Stefan 'D4rk4ng3l' Krenz
|
||||
*/
|
||||
/**
|
||||
* Debug class by Stefan Krenz
|
||||
*
|
||||
* @package MySQLDumper
|
||||
*
|
||||
*/
|
||||
class Debug
|
||||
{
|
||||
/**
|
||||
* Debug-Ausgabe als einfacher Text.
|
||||
*/
|
||||
const OUTPUT_PLAIN = 0x000001;
|
||||
|
||||
/**
|
||||
* Debug-Ausgabe als HTML-Quelltext.
|
||||
*/
|
||||
const OUTPUT_HTML = 0x000002;
|
||||
|
||||
/**
|
||||
* Debug-Ausgabe als HTML-Kommentar.
|
||||
*/
|
||||
const OUTPUT_HTML_COMMENT = 0x000003;
|
||||
|
||||
/**
|
||||
* Debug-Ausgabe in einer Datei als einfacher Text.
|
||||
* {@link Debug::setOutputFilename()}
|
||||
*/
|
||||
const OUTPUT_FILE = 0x000004;
|
||||
|
||||
/**
|
||||
* Debug-Ausgabe als Javascript Kommentar.
|
||||
*/
|
||||
const OUTPUT_JAVASCRIPT = 0x000005;
|
||||
|
||||
/**
|
||||
* Alias für {@link Debug::OUTPUT_JAVASCRIPT}
|
||||
*/
|
||||
const OUTPUT_JS = 0x000005;
|
||||
|
||||
/**
|
||||
* Backtrace-Ausgabe deaktivieren.
|
||||
*/
|
||||
const BACKTRACE_NONE = 0x000100;
|
||||
|
||||
/**
|
||||
* Einfache Backtrace-Ausgabe. Gibt nur die <i>Debug::out()</i>
|
||||
* aufrufende Funktion aus.
|
||||
*/
|
||||
const BACKTRACE_SIMPLE = 0x000200;
|
||||
|
||||
/**
|
||||
* Komplexe Backtrace-Ausgabe. Gibt alle aufrufenden Funktionen aus.
|
||||
*/
|
||||
const BACKTRACE_COMPLETE = 0x000300;
|
||||
|
||||
/**
|
||||
* HTML-Quelltext im HTML-Format ausgeben.
|
||||
*/
|
||||
const HTMLMODE_HTML = 0x010000;
|
||||
|
||||
/**
|
||||
* HTML-Quelltext im XHTML-Format ausgeben.
|
||||
*/
|
||||
const HTMLMODE_XHTML = 0x020000;
|
||||
|
||||
/**
|
||||
* Speichert den Modus für die Debug-Ausgabe.
|
||||
*
|
||||
* Siehe auch:
|
||||
* {@link Debug::OUTPUT_PLAIN}
|
||||
* {@link Debug::OUTPUT_HTML}
|
||||
* {@link Debug::OUTPUT_HTML_COMMENT}
|
||||
* {@link Debug::OUTPUT_FILE}
|
||||
*
|
||||
* @var int Ausgabemodus
|
||||
* @static
|
||||
*/
|
||||
private static $_outputMode = self::OUTPUT_HTML;
|
||||
|
||||
/**
|
||||
* Speichert den Modus für die Backtrace-Ausgabe.
|
||||
*
|
||||
* Siehe auch:
|
||||
* {@link Debug::BACKTRACE_NONE}
|
||||
* {@link Debug::BACKTRACE_SIMPLE}
|
||||
* {@link Debug::BACKTRACE_COMPLETE}
|
||||
*
|
||||
* @var int Backtracemodus
|
||||
* @static
|
||||
*/
|
||||
private static $_backtraceMode = self::BACKTRACE_SIMPLE;
|
||||
|
||||
/**
|
||||
* Speichert den Modus für die HTML-Ausgabe.
|
||||
*
|
||||
* Siehe auch: {@link Debug::HTMLMODE_HTML, Debug::HTMLMODE_XHTML}
|
||||
*
|
||||
* @var int HTML-Quelltext-Modus
|
||||
* @static
|
||||
*/
|
||||
private static $_htmlMode = self::HTMLMODE_HTML;
|
||||
|
||||
/**
|
||||
* Speichert Informationen über die registrierten Callback-Funktionen.
|
||||
*
|
||||
* Nähere Informationen zum <i>callback</i> Typ:
|
||||
* siehe PHP-Manual
|
||||
*
|
||||
* @var array Benutzerdefinierte Callback-Funktionen
|
||||
* @static
|
||||
*/
|
||||
private static $_callbacks = array(
|
||||
self::OUTPUT_PLAIN => array(__CLASS__, 'defaultCallback'),
|
||||
self::OUTPUT_HTML => array(__CLASS__, 'defaultCallback'),
|
||||
self::OUTPUT_HTML_COMMENT => array(__CLASS__, 'defaultCallback'),
|
||||
self::OUTPUT_FILE => array(__CLASS__, 'defaultCallback'),
|
||||
self::OUTPUT_JAVASCRIPT => array(__CLASS__, 'defaultCallback'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Speichert den Inhalt der zuletzt ausgegebenen Variablen.
|
||||
*
|
||||
* @var mixed Letzte ausgegebene Variable.
|
||||
* @static
|
||||
*/
|
||||
private static $_lastVariable = null;
|
||||
|
||||
/**
|
||||
* Speichert den Backtrace der letzten Debug-Ausgabe.
|
||||
*
|
||||
* @var array Backtrace der letzten Debug-Ausgabe
|
||||
* @static
|
||||
*/
|
||||
private static $_lastBacktrace = null;
|
||||
|
||||
/**
|
||||
* Speichert den HTML-Quellcode für den Zeilenumbruch,
|
||||
* basierend auf dem aktuellen HTML-Ausgabe-Modus.
|
||||
*
|
||||
* @var string Zeilenumbruch für HTML-Ausgabe
|
||||
*/
|
||||
private static $_htmlLineBreak = "<br>\n";
|
||||
|
||||
/**
|
||||
* Speichert den Dateinamen für die Dateiausgabe.
|
||||
*
|
||||
* Siehe auch: {@link Debug::OUTPUT_FILE}
|
||||
*
|
||||
* @var string Dateiname für die Debug-Ausgabe
|
||||
*/
|
||||
private static $_outputFilename = 'debug.txt';
|
||||
|
||||
/**
|
||||
* Deaktivierter Konstruktor. Klasse ist nur statisch zu benutzen.
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Deaktiviertes klonen.
|
||||
*/
|
||||
private function __clone()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt eine typbasierte Ausgabe zurück.
|
||||
*
|
||||
* Ist $arg ein Array, so wird 'Array' zurückgeben.
|
||||
* Ist $arg ein Objekt, so wird der Name der Klasse zurückgeben.
|
||||
* Ist $arg ein Boolean, so wird 'TRUE' bzw. 'FALSE' zurückgeben.
|
||||
* Ist $arg ein String, so wird er in Anführungsstriche gesetzt.
|
||||
* Ist $arg null, so wird 'NULL' zurückgeben.
|
||||
* Ist der Typ der Variablen $arg unbekannt,
|
||||
* so wird die Variable selbst zurückgegeben.
|
||||
*
|
||||
* @param mixed $arg Funktionparameter
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function getArg($arg)
|
||||
{
|
||||
if (is_array($arg)) {
|
||||
$result = 'Array';
|
||||
} elseif (is_object($arg)) {
|
||||
$result = get_class($arg);
|
||||
} elseif (is_bool($arg)) {
|
||||
$result = $arg ? 'TRUE' : 'FALSE';
|
||||
} elseif (is_string($arg)) {
|
||||
$result = '"' . $arg . '"';
|
||||
} elseif (is_null($arg)) {
|
||||
$result = 'NULL';
|
||||
} else {
|
||||
$result = $arg;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function _getBacktrace($backtrace, $outputBacktraceType)
|
||||
{
|
||||
$outputBacktrace = '';
|
||||
switch ($outputBacktraceType) {
|
||||
case self::BACKTRACE_NONE:
|
||||
break;
|
||||
case self::BACKTRACE_SIMPLE:
|
||||
$outputBacktrace = 'Debugoutput called from '
|
||||
. $backtrace[0]['file'] . '['
|
||||
. $backtrace[0]['line'] . ']';
|
||||
break;
|
||||
case self::BACKTRACE_COMPLETE:
|
||||
foreach ($backtrace as $traceNum => $trace) {
|
||||
$args = (count($trace['args']) > 0) ?
|
||||
self::getArg($trace['args'][0]) : '';
|
||||
for ($i = 1; $i < count($trace['args']); $i++) {
|
||||
$args .= ', ' . self::getArg($trace['args'][$i]);
|
||||
}
|
||||
$outputBacktrace .= '#' . $traceNum . ': ' . $trace['file']
|
||||
. '[' . $trace['line'] . '] ' . $trace['class']
|
||||
. $trace['type'] . $trace['function'] . '('
|
||||
. $args . ")\n";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$outputBacktrace = 'Debugoutput called from '
|
||||
. $backtrace[0]['file'] . '[' . $backtrace[0]['line'] . ']';
|
||||
break;
|
||||
}
|
||||
return $outputBacktrace;
|
||||
}
|
||||
|
||||
private static function _doOutput(
|
||||
$outputFormatType,
|
||||
$outputBacktrace,
|
||||
$dumpedVar,
|
||||
$outputHtmlModeType
|
||||
)
|
||||
{
|
||||
switch ($outputFormatType) {
|
||||
case self::OUTPUT_PLAIN:
|
||||
echo $outputBacktrace;
|
||||
echo $dumpedVar;
|
||||
break;
|
||||
case self::OUTPUT_HTML:
|
||||
echo '<strong>' .
|
||||
nl2br(
|
||||
$outputBacktrace,
|
||||
($outputHtmlModeType == self::HTMLMODE_XHTML)
|
||||
) . '</strong>' . self::$_htmlLineBreak;
|
||||
echo '<pre>';
|
||||
echo htmlspecialchars($dumpedVar);
|
||||
echo '</pre>';
|
||||
break;
|
||||
case self::OUTPUT_HTML_COMMENT:
|
||||
echo '<!--' . "\n" . $outputBacktrace . "\n\n";
|
||||
echo $dumpedVar;
|
||||
echo "\n" . '-->'. "\n";
|
||||
break;
|
||||
case self::OUTPUT_FILE:
|
||||
$output = $outputBacktrace . "\n";
|
||||
$output .= $dumpedVar . "\n\n";
|
||||
$filePointer = fopen(self::$_outputFilename, "a+");
|
||||
fwrite($filePointer, $output);
|
||||
fclose($filePointer);
|
||||
break;
|
||||
case self::OUTPUT_JAVASCRIPT:
|
||||
echo "/*\n";
|
||||
echo $outputBacktrace . "\n\n";
|
||||
echo $dumpedVar;
|
||||
echo "\n*/\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard Callback-Funktion
|
||||
*
|
||||
* Siehe auch: {@link Debug::$_callbacks}
|
||||
*
|
||||
* @param mixed $var Variable, die ausgegeben werden soll.
|
||||
* @param array $backtrace Backtrace des Aufrufs von <i>Debug::out()</i>
|
||||
* @param int $outputFormat Ausgabe-Format
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function defaultCallback($var, $backtrace, $outputFormat)
|
||||
{
|
||||
$outputFormatType = ($outputFormat | 0xFFFFFF00) ^ 0xFFFFFF00;
|
||||
$outputBacktraceType = ($outputFormat | 0xFFFF00FF) ^ 0xFFFF00FF;
|
||||
$outputHtmlModeType = ($outputFormat | 0xFF00FFFF) ^ 0xFF00FFFF;
|
||||
|
||||
if ($outputFormatType == 0) {
|
||||
$outputFormatType = self::$_outputMode;
|
||||
}
|
||||
|
||||
if ($outputBacktraceType == 0) {
|
||||
$outputBacktraceType = self::$_backtraceMode;
|
||||
}
|
||||
|
||||
if ($outputHtmlModeType == 0) {
|
||||
$outputHtmlModeType = self::$_htmlMode;
|
||||
}
|
||||
|
||||
self::$_htmlLineBreak = nl2br(
|
||||
"\n",
|
||||
($outputHtmlModeType == self::HTMLMODE_XHTML)
|
||||
);
|
||||
|
||||
ob_start();
|
||||
var_dump($var);
|
||||
$dumpedVar = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
$outputBacktrace = self::_getBacktrace(
|
||||
$backtrace,
|
||||
$outputBacktraceType
|
||||
);
|
||||
|
||||
self::_doOutput(
|
||||
$outputFormatType,
|
||||
$outputBacktrace,
|
||||
$dumpedVar,
|
||||
$outputHtmlModeType
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Erzeugt eine Ausgabe, die beim Auffinden
|
||||
* von Fehlern (debugging) unterstützt.
|
||||
*
|
||||
* @param mixed $var Variable, die ausgegeben werden soll.
|
||||
* @param int $outputFormat Format für die Ausgabe.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function out($var, $outputFormat = null)
|
||||
{
|
||||
if ($outputFormat === null) {
|
||||
$outputFormat = self::$_outputMode |
|
||||
self::$_backtraceMode |
|
||||
self::$_htmlMode;
|
||||
}
|
||||
|
||||
$outputFormatType = ($outputFormat | 0xFFFFFF00) ^ 0xFFFFFF00;
|
||||
if ($outputFormatType == 0) {
|
||||
$outputFormatType = self::$_outputMode;
|
||||
$outputFormat = self::$_outputMode | $outputFormat;
|
||||
}
|
||||
$backtrace = debug_backtrace();
|
||||
if (isset(self::$_callbacks[$outputFormatType])) {
|
||||
call_user_func_array(
|
||||
self::$_callbacks[$outputFormatType],
|
||||
array($var, $backtrace, $outputFormat)
|
||||
);
|
||||
} else {
|
||||
$message = 'Für das angegebene Ausgabeformat wurde keine '
|
||||
. 'Callback-Funktion definiert. Format: 0x'
|
||||
. sprintf('%8.8X', $outputFormatType);
|
||||
throw new Exception($message);
|
||||
}
|
||||
|
||||
self::$_lastBacktrace = $backtrace;
|
||||
self::$_lastVariable = $var;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Backtrace des letzten Aufrufs von <i>Debug::out()</i> zurück.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getLastBacktrace()
|
||||
{
|
||||
return self::$_lastBacktrace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Inhalt der zuletzt ausgegebenen Variablen zurück.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getLastVariable()
|
||||
{
|
||||
return self::$_lastVariable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt eine Callback-Funktion zum Stack hinzu,
|
||||
* diese wird beim Aufruf von <i>Debug::out()</i>
|
||||
* automatisch aufgerufen. Diese Funktion muss gleichzeitig den Inhalt
|
||||
* des <i>Debug::out()</i> Aufrufs ausgeben.
|
||||
*
|
||||
* Für nähere Informationen über mögliche
|
||||
* Callback-Funktionen {@link Debug::$_callbacks}
|
||||
*
|
||||
* Die Callback-Funktion muss dem folgenden Format entsprechen:
|
||||
* method null callback($var, $backtrace, $outputFormat)
|
||||
* {@link Debug::defaultCallback()}
|
||||
*
|
||||
* Benutze für das Ausgabeformat ($outputFormat)
|
||||
* einen Integer zwischen 0x10 und 0xFF.
|
||||
*
|
||||
* Alternativ kann für $outputFormat auch ein Array übergeben werden.
|
||||
* Es gilt dann die Konvention:
|
||||
* Index 0: Ausgabeformat (entspricht $outputFormat mit einem Integer)
|
||||
* Index 1: Callback-Information (entspricht $callbackFunction)
|
||||
*
|
||||
* Ausgabeformate sollten global mit dem Präfix
|
||||
* 'DEBUG_OUTPUT_' registriert werden.
|
||||
* Zusätzliche Ausgabeinformationen können in den
|
||||
* Bytes 3 und 4 (0xFFFF0000) übergeben werden.
|
||||
*
|
||||
* @param mixed $outputFormat Ausgabeformat
|
||||
* @param mixed $callbackFunction Informationen über die Callback-Funktion
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function registerCallbackFunction(
|
||||
$outputFormat,
|
||||
$callbackFunction = null
|
||||
)
|
||||
{
|
||||
if (is_array($outputFormat)) {
|
||||
self::$_callbacks[$outputFormat[0]] = $outputFormat[1];
|
||||
return is_callable($outputFormat[1]);
|
||||
} else {
|
||||
self::$_callbacks[$outputFormat] = $callbackFunction;
|
||||
return is_callable($callbackFunction);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt eine Callback-Funktion vom Stack.
|
||||
*
|
||||
* @param int $outputFormat Ausgabeformat
|
||||
*/
|
||||
public static function unregisterCallbackFunction($outputFormat)
|
||||
{
|
||||
unset(self::$_callbacks[$outputFormat]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Modus für die Ausgabe.
|
||||
* {@link Debug::$_outputMode}
|
||||
*
|
||||
* @param int $outputMode Ausgabemodus
|
||||
*/
|
||||
public static function setDefaultOutputMode($outputMode)
|
||||
{
|
||||
self::$_outputMode = $outputMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Modus für den Backtrace.
|
||||
* {@link Debug::$_backtraceMode}
|
||||
*
|
||||
* @param int $backtraceMode Backtrace-Modus
|
||||
*/
|
||||
public static function setDefaultBacktraceMode($backtraceMode)
|
||||
{
|
||||
self::$_backtraceMode = $backtraceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Modus für die HTML-Ausgabe
|
||||
* {@link Debug::$_htmlMode}
|
||||
*
|
||||
* @param int $htmlMode HTML-Modus
|
||||
*/
|
||||
public static function setDefaultHtmlMode($htmlMode)
|
||||
{
|
||||
self::$_htmlMode = $htmlMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt den Dateinamen für die Dateiausgabe.
|
||||
* {@link Debug::$_outputFilename}
|
||||
*
|
||||
* @param string $outputFilename Dateiname
|
||||
*/
|
||||
public static function setOutputFilename($outputFilename = 'debug.txt')
|
||||
{
|
||||
self::$_outputFilename = $outputFilename;
|
||||
}
|
||||
}
|
||||
|
||||
$debugReflection = new ReflectionClass('Debug');
|
||||
$constants = $debugReflection->getConstants();
|
||||
foreach ($constants as $constantName => $constantValue) {
|
||||
define('DEBUG_' . $constantName, $constantValue);
|
||||
}
|
||||
59
library/Msd/Action/Helper/AssignConfigAndLanguage.php
Normale Datei
59
library/Msd/Action/Helper/AssignConfigAndLanguage.php
Normale Datei
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Controllers
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Assign config- and language to view
|
||||
*
|
||||
* Helper to auto assign the config- and language instance to view instances
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Action_Helper
|
||||
*/
|
||||
class Msd_Action_Helper_AssignConfigAndLanguage
|
||||
extends Zend_Controller_Action_Helper_Abstract
|
||||
{
|
||||
/**
|
||||
* Actual Zend_View instance
|
||||
* @var Zend_View
|
||||
*/
|
||||
protected $_view;
|
||||
|
||||
/**
|
||||
* PreDispatcher
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preDispatch()
|
||||
{
|
||||
$controllerName = $this->getRequest()->getControllerName();
|
||||
if ($controllerName == 'install') {
|
||||
return;
|
||||
}
|
||||
$view = $this->getView();
|
||||
$view->config = Msd_Configuration::getInstance();
|
||||
$view->lang = Msd_Language::getInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view instance of the actual controller
|
||||
*
|
||||
* @return Zend_View
|
||||
*/
|
||||
public function getView()
|
||||
{
|
||||
if (null !== $this->_view) {
|
||||
return $this->_view;
|
||||
} else {
|
||||
$controller = $this->getActionController();
|
||||
$this->_view = $controller->view;
|
||||
return $this->_view;
|
||||
}
|
||||
}
|
||||
}
|
||||
116
library/Msd/Auth/Adapter/Ini.php
Normale Datei
116
library/Msd/Auth/Adapter/Ini.php
Normale Datei
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Auth_adapter
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Adapter to use Zend_Auth with INI files.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Auth_adapter
|
||||
*/
|
||||
class Msd_Auth_Adapter_Ini implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* User database
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_users = null;
|
||||
|
||||
/**
|
||||
* Username for authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_username = null;
|
||||
|
||||
/**
|
||||
* Password for authentication.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_password = null;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $iniFilename Filename for registered users
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($iniFilename)
|
||||
{
|
||||
if (!file_exists($iniFilename)) {
|
||||
throw new Msd_Exception(
|
||||
'INI file with authentication information doesn\'t exists!'
|
||||
);
|
||||
}
|
||||
$this->_users = parse_ini_file($iniFilename, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* set the username, which is used for authentication.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->_username = (string) $username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the password, which is used for authentication.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->_password = (string) $password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate with the given credentials.
|
||||
*
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
if ($this->_username == null || $this->_password == null) {
|
||||
throw new Msd_Exception(
|
||||
'You must set the username and password first!'
|
||||
);
|
||||
}
|
||||
|
||||
$authResult = false;
|
||||
foreach ($this->_users as $userId => $user) {
|
||||
if (
|
||||
$this->_username == $user['name'] &&
|
||||
md5($this->_password) == $user['pass']
|
||||
) {
|
||||
$authResult = array(
|
||||
'id' => $userId,
|
||||
'name' => $user['name'],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($authResult === false) {
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
array(),
|
||||
array('L_LOGIN_INVALID_USER')
|
||||
);
|
||||
}
|
||||
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::SUCCESS,
|
||||
$authResult
|
||||
);
|
||||
}
|
||||
}
|
||||
318
library/Msd/Configuration.php
Normale Datei
318
library/Msd/Configuration.php
Normale Datei
|
|
@ -0,0 +1,318 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Configuration
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Configuration class implemented as singleton
|
||||
*
|
||||
* Handles getting and setting of configuration variables
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Configuration
|
||||
*/
|
||||
class Msd_Configuration
|
||||
{
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @var Msd_Configuration
|
||||
*/
|
||||
private static $_instance = NULL;
|
||||
/**
|
||||
* Configuration params
|
||||
*
|
||||
* @var StdClass
|
||||
*/
|
||||
private $_data = null;
|
||||
|
||||
/**
|
||||
* Session to old values
|
||||
*
|
||||
* @var Zend_Session_Namespace
|
||||
*/
|
||||
private $_session = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $configName The name of the configuration file to load.
|
||||
* If not set we will load the config from
|
||||
* session if present.
|
||||
* @param bool $forceLoading Force loading of configuration from file
|
||||
*/
|
||||
private function __construct($configName = '', $forceLoading = false)
|
||||
{
|
||||
$this->_session = new Zend_Session_Namespace('MySQLDumper');
|
||||
if ($forceLoading === false && isset($this->_session->dynamic->configFile)) {
|
||||
$this->loadConfigFromSession();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_data = new stdClass;
|
||||
|
||||
if ($configName == '') {
|
||||
$configName = 'defaultConfig';
|
||||
}
|
||||
$this->_data->dynamic = Msd_ConfigurationPhpValues::getDynamicValues();
|
||||
$this->_data->paths = $this->_loadUserDirectories();
|
||||
$this->loadConfiguration($configName);
|
||||
$this->set('dynamic.configFile', $configName);
|
||||
|
||||
$defaultDb = $this->get('config.dbuser.defaultDb');
|
||||
if ($defaultDb != '') {
|
||||
$this->set('dynamic.dbActual', $defaultDb);
|
||||
}
|
||||
|
||||
$this->saveConfigToSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* No cloning for singleton
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
throw new Msd_Exception('Cloning is not allowed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration instance
|
||||
*
|
||||
* @param string $configName The name of the configuration file to load.
|
||||
* If not set we will load the config from
|
||||
* session if present.
|
||||
* @param boolean $forceLoading If set the config will be read from file.
|
||||
*
|
||||
* @return Msd_Configuration
|
||||
*/
|
||||
public static function getInstance($configName = '', $forceLoading = false)
|
||||
{
|
||||
if (null == self::$_instance) {
|
||||
self::$_instance = new self($configName, $forceLoading);
|
||||
}
|
||||
if ($forceLoading) {
|
||||
self::$_instance->loadConfiguration($configName, true);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a key to a val
|
||||
*
|
||||
* @param string $configPath Must begin with "config", "dynamic" or "paths"
|
||||
* @param string $val The value to set
|
||||
*
|
||||
* @return Msd_Configuration
|
||||
*/
|
||||
public function set($configPath, $val)
|
||||
{
|
||||
$args = explode('.', $configPath);
|
||||
if (!in_array($args[0], array('config', 'paths', 'dynamic'))) {
|
||||
$msg = 'Trying to set config value with illegal key. First key '
|
||||
. 'must be "config", "paths" or "dynamic"';
|
||||
throw new Msd_Exception($msg);
|
||||
}
|
||||
switch (count($args)) {
|
||||
case 2:
|
||||
list($type, $var) = $args;
|
||||
$this->_data->$type->$var = $val;
|
||||
break;
|
||||
case 3:
|
||||
list($type, $section, $var) = $args;
|
||||
$this->_data->$type->$section->$var = $val;
|
||||
break;
|
||||
default:
|
||||
$backTrace = debug_backtrace(false);
|
||||
throw new Msd_Exception(
|
||||
'Path couldn\'t be set!' . PHP_EOL . $configPath .
|
||||
' invoked from ' . $backTrace[0]['file'] . '[' .
|
||||
$backTrace[0]['line'] . ']',
|
||||
E_USER_NOTICE
|
||||
);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a config parameter
|
||||
*
|
||||
* If first part isn't config, paths or dynamic, we assume config is meant.
|
||||
*
|
||||
* @param string $key Path to get
|
||||
*
|
||||
* @return string|array
|
||||
*/
|
||||
public function get($key)
|
||||
{
|
||||
$params = explode('.', $key);
|
||||
if (!in_array($params[0], array('config', 'paths', 'dynamic'))) {
|
||||
$msg = 'Trying to get config value with illegal key. First key '
|
||||
. 'must be "config", "paths" or "dynamic"';
|
||||
throw new Msd_Exception($msg);
|
||||
}
|
||||
$values = $this->_data->$params[0];
|
||||
if (!is_array($values)) {
|
||||
$values = $this->_data->$params[0]->toArray();
|
||||
}
|
||||
if (sizeof($params) == 1) {
|
||||
return $values;
|
||||
}
|
||||
unset($params[0]);
|
||||
foreach ($params as $index) {
|
||||
if (isset($values[$index])) {
|
||||
$values = $values[$index];
|
||||
} else {
|
||||
$values = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save configurations to file
|
||||
*
|
||||
* @param string $fileName Name of configuration without extension .ini
|
||||
* @param array $configArray Data to save as array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save($fileName = null, $configArray = null)
|
||||
{
|
||||
if ($fileName === null) {
|
||||
$fileName = $this->get('dynamic.configFile');
|
||||
}
|
||||
$fileName .= '.ini';
|
||||
// save branch config and skip groups "dynamic" and "paths"
|
||||
if ($configArray !== null) {
|
||||
$configData = new Zend_Config($configArray, true);
|
||||
} else {
|
||||
$configData = $this->_data->config;
|
||||
}
|
||||
$configWriter = new Zend_Config_Writer_Ini(
|
||||
array(
|
||||
'filename' => $this->get('paths.config') . DS . $fileName,
|
||||
'config' => $configData,
|
||||
)
|
||||
);
|
||||
$configWriter->write();
|
||||
$this->_data->config = $configData;
|
||||
$this->set('dynamic.configFile', basename($fileName, '.ini'));
|
||||
$this->saveConfigToSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save config to session
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function saveConfigToSession()
|
||||
{
|
||||
$this->_session->unsetAll();
|
||||
$this->_session->config = $this->_data->config;
|
||||
$this->_session->dynamic = $this->_data->dynamic;
|
||||
$this->_session->paths = $this->_data->paths;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get config from session
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function loadConfigFromSession()
|
||||
{
|
||||
if (isset($this->_session->config)) {
|
||||
$this->_data->config = $this->_session->config;
|
||||
}
|
||||
if (isset($this->_session->dynamic)) {
|
||||
$this->_data->dynamic = $this->_session->dynamic;
|
||||
}
|
||||
if (isset($this->_session->paths)) {
|
||||
$this->_data->paths = $this->_session->paths;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration file
|
||||
*
|
||||
* @param string $configName The configuration file to load
|
||||
* @param boolean $applyValues Whether to apply loaded values to config
|
||||
*
|
||||
* @return Zend_Config_ini Loaded configuration as Zend_Config_Ini
|
||||
*/
|
||||
public function loadConfiguration($configName, $applyValues = true)
|
||||
{
|
||||
$this->_loadUserDirectories();
|
||||
if ($configName != 'defaultConfig') {
|
||||
$configName .= '.ini';
|
||||
$configPath = $this->get('paths.config');
|
||||
$configFile = $configPath . DS . $configName;
|
||||
} else {
|
||||
// special case - defaultConfig.ini is in application/configs
|
||||
$configFile = realpath(APPLICATION_PATH . DS . 'configs')
|
||||
. DS . 'defaultConfig.ini';
|
||||
}
|
||||
if (!is_readable($configFile)) {
|
||||
throw new Msd_Exception(
|
||||
'Couldn\'t read configuration file ' . $configFile
|
||||
);
|
||||
}
|
||||
$options = array('allowModifications' => true);
|
||||
$config = new Zend_Config_Ini($configFile, null, $options);
|
||||
if (!$applyValues) {
|
||||
return $config;
|
||||
}
|
||||
$this->_data->config = null;
|
||||
$this->_data->config = $config;
|
||||
$this->set('dynamic.configFile', basename($configFile, '.ini'));
|
||||
$iconPath = 'css/' . $this->get('config.interface.theme') . '/icons';
|
||||
$this->set('paths.iconpath', $iconPath);
|
||||
$this->saveConfigToSession();
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user directories and save them to config
|
||||
*
|
||||
* @return Zend_Config Directories as object
|
||||
*/
|
||||
private function _loadUserDirectories()
|
||||
{
|
||||
// set paths
|
||||
$workRoot = realpath(APPLICATION_PATH . DS . '..') . DS . 'work' . DS;
|
||||
$directories = array(
|
||||
'work' => $workRoot,
|
||||
'log' => $workRoot . 'log',
|
||||
'backup' => $workRoot . 'backup',
|
||||
'config' => $workRoot . 'config'
|
||||
);
|
||||
return new Zend_Config($directories, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return name of configuration
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->get('config.general.title');
|
||||
}
|
||||
|
||||
/**
|
||||
* Reloads the configuration from the current ini file.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function reloadConfig()
|
||||
{
|
||||
$this->loadConfiguration($this->get('dynamic.configFile'));
|
||||
}
|
||||
}
|
||||
136
library/Msd/ConfigurationPhpValues.php
Normale Datei
136
library/Msd/ConfigurationPhpValues.php
Normale Datei
|
|
@ -0,0 +1,136 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Configuration
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Helper for getting dynamic configuration values like phpRam etc.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Configuration
|
||||
*/
|
||||
class Msd_ConfigurationPhpValues
|
||||
{
|
||||
/**
|
||||
* Read dynamic PHP config values
|
||||
*
|
||||
* @return Zend_Config
|
||||
*/
|
||||
public static function getDynamicValues ()
|
||||
{
|
||||
$phpRam = self::_getPhpRam();
|
||||
$dynConfig = array(
|
||||
'sendmailCall' => self::_getConfigSetting('sendmail_path'),
|
||||
'safeMode' => self::_getConfigSetting('safe_mode', true),
|
||||
'magicQuotesGpc' => get_magic_quotes_gpc(),
|
||||
'disabledPhpFunctions' =>
|
||||
str_replace(
|
||||
',',
|
||||
', ',
|
||||
self::_getConfigSetting('disable_functions')
|
||||
),
|
||||
'maxExecutionTime' => self::_getMaxExecutionTime(),
|
||||
'uploadMaxFilesize' => self::_getUploadMaxFilesize(),
|
||||
'phpextensions' => implode(', ', get_loaded_extensions()),
|
||||
'phpRam' => $phpRam,
|
||||
'memoryLimit' => round($phpRam * 1024 * 1024 * 0.9, 0),
|
||||
'compression' => self::_hasZlib(),
|
||||
);
|
||||
return new Zend_Config($dynConfig, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read PHP's max_execution_time
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private static function _getMaxExecutionTime()
|
||||
{
|
||||
$maxExecutionTime =
|
||||
self::_getConfigSetting('max_execution_time', true);
|
||||
if ($maxExecutionTime <= 5) {
|
||||
// we didn't get the real value from the server - some deliver "-1"
|
||||
$maxExecutionTime = 30;
|
||||
} elseif ($maxExecutionTime > 30) {
|
||||
// we don't use more than 30 seconds to avoid brower timeouts
|
||||
$maxExecutionTime = 30;
|
||||
}
|
||||
return $maxExecutionTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PHP's upload_max_filesize
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
private static function _getUploadMaxFilesize()
|
||||
{
|
||||
$uploadMaxFilesize = self::_getConfigSetting('upload_max_filesize');
|
||||
// Is value in Megabytes? If yes create output
|
||||
if (strpos($uploadMaxFilesize, 'M')) {
|
||||
$uploadMaxFilesize = str_replace('M', '', $uploadMaxFilesize);
|
||||
$uploadMaxFilesize = trim($uploadMaxFilesize);
|
||||
// re-calculate to Bytes
|
||||
$uploadMaxFilesize *= 1024 * 1024;
|
||||
}
|
||||
return (int) $uploadMaxFilesize;;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get PHP's ram size
|
||||
*
|
||||
* @return integer The memory limit in MB
|
||||
*/
|
||||
private static function _getPhpRam()
|
||||
{
|
||||
$ram = self::_getConfigSetting('memory_limit');
|
||||
// we don't trust the value delivered by server config if < 16
|
||||
if ($ram < 16) {
|
||||
$ram = 16;
|
||||
}
|
||||
return $ram;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect if zlib is installed
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
private static function _hasZlib()
|
||||
{
|
||||
$zlib = false;
|
||||
$extensions = get_loaded_extensions();
|
||||
if (in_array('zlib', $extensions)) {
|
||||
$zlib = true;
|
||||
};
|
||||
return (boolean) $zlib;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a PHP-Setting from ini
|
||||
*
|
||||
* First try to read via ini_get(), then fall back to get_cfg_var()
|
||||
*
|
||||
* @param string $varName The name of the setting to read
|
||||
* @param boolean $returnAsInt Whether to return value as integer
|
||||
*/
|
||||
private function _getConfigSetting($varName, $returnAsInt = false)
|
||||
{
|
||||
$value = @ini_get($varName);
|
||||
|
||||
// fallback if ini_get doesn't work
|
||||
if ($value == '' || $value === null) {
|
||||
$value = @get_cfg_var($varName);
|
||||
}
|
||||
|
||||
if ($returnAsInt) {
|
||||
$value = (int) $value;
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
248
library/Msd/Crypt.php
Normale Datei
248
library/Msd/Crypt.php
Normale Datei
|
|
@ -0,0 +1,248 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Encryption
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Class for text en- and decryption.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Encryption
|
||||
*/
|
||||
class Msd_Crypt
|
||||
{
|
||||
/**
|
||||
* Holds the encryption descriptor
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $_encDescriptor = null;
|
||||
|
||||
/**
|
||||
* Holds the initialization vector
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
private $_initVector = null;
|
||||
|
||||
/**
|
||||
* Holds the algorithm wichc is currently used.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_algorithm = MCRYPT_TWOFISH;
|
||||
|
||||
/**
|
||||
* Holds the current encryption key.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_encryptionKey = null;
|
||||
|
||||
/**
|
||||
* Instance of this class.
|
||||
*
|
||||
* @var Msd_Crypt
|
||||
*/
|
||||
private static $_instance = null;
|
||||
|
||||
/**
|
||||
* Identificator for encrypted text
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_cryptIdent = 'Z';
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param string $cryptKey Encryption key
|
||||
* @param string $algorithm Algorithm for encryption
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct($cryptKey = null, $algorithm = null)
|
||||
{
|
||||
if ($cryptKey === null) {
|
||||
$cryptKey = md5(time());
|
||||
}
|
||||
if ($algorithm === null) {
|
||||
$algorithm = $this->_algorithm;
|
||||
}
|
||||
$this->init($cryptKey, $algorithm);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instance of this class.
|
||||
*
|
||||
* @param string $cryptKey Encryption key
|
||||
* @param string $algorithm Algorithm for encryption
|
||||
*
|
||||
* @return Msd_Crypt
|
||||
*/
|
||||
public static function getInstance($cryptKey = null, $algorithm = null)
|
||||
{
|
||||
if (self::$_instance === null) {
|
||||
self::$_instance = new self($cryptKey, $algorithm);
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the encryption descriptor.
|
||||
*
|
||||
* @param string $encryptionKey Key for encryption
|
||||
* @param string $algorithm Algorithm for encryption
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init($encryptionKey = null, $algorithm = null)
|
||||
{
|
||||
if ($encryptionKey === null) {
|
||||
$encryptionKey = $this->_encryptionKey;
|
||||
}
|
||||
if ($algorithm === null) {
|
||||
$algorithm = $this->_algorithm;
|
||||
}
|
||||
if (!is_resource($this->_encDescriptor)) {
|
||||
$this->_encDescriptor = mcrypt_module_open(
|
||||
$algorithm,
|
||||
'',
|
||||
MCRYPT_MODE_ECB,
|
||||
''
|
||||
);
|
||||
$vectorSize = mcrypt_enc_get_iv_size($this->_encDescriptor);
|
||||
$this->_initVector = mcrypt_create_iv($vectorSize, MCRYPT_RAND);
|
||||
$keySize = mcrypt_enc_get_key_size($this->_encDescriptor);
|
||||
$key = substr(md5($encryptionKey), 0, $keySize);
|
||||
|
||||
mcrypt_generic_init(
|
||||
$this->_encDescriptor,
|
||||
$key,
|
||||
$this->_initVector
|
||||
);
|
||||
$this->_encryptionKey = $encryptionKey;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninitialize the encryption descriptor.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deinit()
|
||||
{
|
||||
if (is_resource($this->_encDescriptor)) {
|
||||
mcrypt_generic_deinit($this->_encDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the encryption descriptor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function close()
|
||||
{
|
||||
$this->deinit();
|
||||
if (is_resource($this->_encDescriptor)) {
|
||||
mcrypt_module_close($this->_encDescriptor);
|
||||
}
|
||||
$this->_encDescriptor = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decodes an base64 encoded string.
|
||||
*
|
||||
* @param string $encodedString base64 encoded string
|
||||
*
|
||||
* @return sting
|
||||
*/
|
||||
private function _base64Decode($encodedString)
|
||||
{
|
||||
if (substr($encodedString, 0, 1) !== $this->_cryptIdent) {
|
||||
return $encodedString;
|
||||
}
|
||||
$encodedString = str_replace(
|
||||
array('.', '_', '-'),
|
||||
array('+', '/', '='),
|
||||
substr($encodedString, 1)
|
||||
);
|
||||
$decodedString = base64_decode($encodedString);
|
||||
return $decodedString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encode a string into base64 notation.
|
||||
*
|
||||
* @param string $plainString Plaintext
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _base64Encode($plainString)
|
||||
{
|
||||
$encodedString = base64_encode($plainString);
|
||||
$encodedString = str_replace(
|
||||
array('+', '/', '='),
|
||||
array('.', '_', '-'),
|
||||
$encodedString
|
||||
);
|
||||
return $this->_cryptIdent . $encodedString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrypts a text.
|
||||
*
|
||||
* @param string $encryptedText Text to decrypt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function decrypt($encryptedText)
|
||||
{
|
||||
$encryptedText = $this->_base64Decode($encryptedText);
|
||||
if (!is_resource($this->_encDescriptor)) {
|
||||
$this->init($this->_encryptionKey);
|
||||
}
|
||||
$clearText = mdecrypt_generic(
|
||||
$this->_encDescriptor,
|
||||
$encryptedText
|
||||
);
|
||||
return trim($clearText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypts a text
|
||||
*
|
||||
* @param string $clearText Text to encrypt
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function encrypt($clearText)
|
||||
{
|
||||
if (!is_resource($this->_encDescriptor)) {
|
||||
$this->init();
|
||||
}
|
||||
$encryptedText = mcrypt_generic(
|
||||
$this->_encDescriptor,
|
||||
$clearText
|
||||
);
|
||||
return $this->_base64Encode($encryptedText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class destructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->close();
|
||||
}
|
||||
}
|
||||
|
||||
346
library/Msd/Db.php
Normale Datei
346
library/Msd/Db.php
Normale Datei
|
|
@ -0,0 +1,346 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
* @version SVN: $rev: 1212 $
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* DB-Factory
|
||||
*
|
||||
* @abstract
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
*/
|
||||
abstract class Msd_Db
|
||||
{
|
||||
// define result set types
|
||||
const ARRAY_NUMERIC = 0; // return resultset as numeric array
|
||||
const ARRAY_ASSOC = 1; // return resultset as associative array
|
||||
const ARRAY_OBJECT = 2; // return resultset as array of object
|
||||
const SIMPLE = 3; // return result as boolean
|
||||
/**
|
||||
* SQL-Server
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_server;
|
||||
|
||||
/**
|
||||
* SQL user used to authenticate at server
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_user;
|
||||
|
||||
/**
|
||||
* SQL user password used to authenticate
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_password;
|
||||
|
||||
/**
|
||||
* Port used for connection to server
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_port;
|
||||
|
||||
/**
|
||||
* Socket used for connection
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_socket;
|
||||
|
||||
/**
|
||||
* List of databases adn default settings
|
||||
* @var array
|
||||
*/
|
||||
protected $_databases = null;
|
||||
|
||||
/**
|
||||
* charset to use (default utf8)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_connectionCharset = 'utf8';
|
||||
|
||||
/**
|
||||
* the selected db
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_dbSelected = '';
|
||||
|
||||
/**
|
||||
* List of cached tables
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_tables = array();
|
||||
|
||||
/**
|
||||
* Meta informations about tables
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_metaTables = array();
|
||||
|
||||
/**
|
||||
* Charsets the server supports (cached)
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_charsets = array();
|
||||
|
||||
/**
|
||||
* Init database object
|
||||
*
|
||||
* @param array $options Array containing connection options
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct ($options)
|
||||
{
|
||||
$this->_server = $options['host'];
|
||||
$this->_user = $options['user'];
|
||||
$this->_password = $options['pass'];
|
||||
$this->_port = (int) $options['port'];
|
||||
$this->_socket = $options['socket'];
|
||||
}
|
||||
/**
|
||||
* Create database adapter
|
||||
*
|
||||
* @param array $options Connection options
|
||||
* @param boolean $forceMysql Whether to force the use of MySQL
|
||||
*
|
||||
* @return MsdDbFactory
|
||||
*/
|
||||
public static function getAdapter($options = null, $forceMysql = false)
|
||||
{
|
||||
if ($options === null) {
|
||||
$config = Msd_Configuration::getInstance();
|
||||
$options = array(
|
||||
'host' => $config->get('config.dbuser.host'),
|
||||
'user' => $config->get('config.dbuser.user'),
|
||||
'pass' => $config->get('config.dbuser.pass'),
|
||||
'port' => (int) $config->get('config.dbuser.port'),
|
||||
'socket' => $config->get('config.dbuser.socket'),
|
||||
);
|
||||
}
|
||||
if (function_exists('mysqli_connect') && !$forceMysql) {
|
||||
$dbObject = new Msd_Db_Mysqli($options);
|
||||
} else {
|
||||
$dbObject = new Msd_Db_Mysql($options);
|
||||
}
|
||||
return $dbObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a connection to SQL-Server. The connection is stored and used
|
||||
* for further DB requests.
|
||||
*
|
||||
* @return bool if connection is successfull
|
||||
* */
|
||||
abstract protected function _dbConnect ();
|
||||
/**
|
||||
* Get selected database
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getSelectedDb ();
|
||||
/**
|
||||
* Get version nr of sql server
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getServerInfo ();
|
||||
/**
|
||||
* Get version nr of sql client
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function getClientInfo ();
|
||||
/**
|
||||
* Get all known character sets of this SQL-Server.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getCharsets ();
|
||||
/**
|
||||
* Set character set of the MySQL-connection.
|
||||
*
|
||||
* Trys to set the connection charset and returns it.
|
||||
* Throw Exception on failure.
|
||||
*
|
||||
* @param string $charset
|
||||
* @throws Exception
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function setConnectionCharset (
|
||||
$charset = 'utf8');
|
||||
/**
|
||||
* Get list of databases
|
||||
*
|
||||
* Gets list of all databases that the actual SQL-Server-User has access to
|
||||
* and saves it in $this->databases.
|
||||
* Returns true on success or false on error.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getDatabases ();
|
||||
/**
|
||||
* Select the given database to use it as the target for following queries.
|
||||
*
|
||||
* Returns true if selection was succesfull otherwise false.
|
||||
*
|
||||
* @throws Exception
|
||||
* @param string $database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function selectDb ($database);
|
||||
/**
|
||||
* Execute a query and set _resultHandle
|
||||
*
|
||||
* If $getRows is true alls rows are fetched and returned
|
||||
*
|
||||
* @param string $query The query to execute
|
||||
* @param const $kind Type of result set
|
||||
* @param boolean $getRows Whether to fetch all rows and return them
|
||||
*
|
||||
* @return boolean|array
|
||||
*/
|
||||
abstract public function query ($query,
|
||||
$kind = self::ARRAY_OBJECT, $getRows = true);
|
||||
|
||||
/**
|
||||
* Get next row from result set
|
||||
*
|
||||
* @param const $kind
|
||||
*
|
||||
* @return array|object
|
||||
*/
|
||||
abstract public function getNextRow($kind);
|
||||
|
||||
/**
|
||||
* Get the list of tables of given database
|
||||
*
|
||||
* @param string $dbName Name of database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getTables ($dbName);
|
||||
/**
|
||||
* Gets extended table information for one or all tables
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getTableStatus ($table = false);
|
||||
/**
|
||||
* Returns the CREATE Statement of a table.
|
||||
*
|
||||
* @throws Exception
|
||||
* @param string $table Get CREATE-Statement for this table
|
||||
*
|
||||
* @return string Create statement
|
||||
*/
|
||||
abstract public function getTableCreate ($table);
|
||||
/**
|
||||
* Gets the full description of all columns of a table
|
||||
*
|
||||
* Saves list to $this->metaTables[$database][$table].
|
||||
*
|
||||
* @param string $table Table to read meta info from
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getTableColumns ($table);
|
||||
/**
|
||||
* Gets the number of affected rows of the last query
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
abstract public function getAffectedRows ();
|
||||
/**
|
||||
* Gets the servers variables
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getVariables ();
|
||||
/**
|
||||
* Escape a value for inserting it in query
|
||||
*
|
||||
* @param string $val
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
abstract public function escape ($val);
|
||||
/**
|
||||
* Optimize a table. Returns true on success or MySQL-Error.
|
||||
*
|
||||
* @param $table string Name of table
|
||||
*
|
||||
* @return string|bool Returned optimize message or false on error
|
||||
*/
|
||||
abstract public function optimizeTable ($table);
|
||||
/**
|
||||
* Creates a new database with the given name, charackter set and collation.
|
||||
*
|
||||
* @abstract
|
||||
*
|
||||
* @param string $databaseName Name of the new database
|
||||
* @param string $databaseCharset Charackter set of the new database
|
||||
* @param string $databaseCollation Collation of the new database
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function createDatabase(
|
||||
$databaseName,
|
||||
$databaseCharset = '',
|
||||
$databaseCollation = ''
|
||||
);
|
||||
/**
|
||||
* Retrieves the collations from information schema.
|
||||
*
|
||||
* @param string|null $charsetName Name of the charset
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getCollations($charsetName = null);
|
||||
/**
|
||||
* Retrieves the default collation for the charset or the given charset.
|
||||
*
|
||||
* @param string|null $charsetName Name of the charset
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
abstract public function getDefaultCollations($charsetName = null);
|
||||
/**
|
||||
* Retrieves the last MySQL error.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function getLastError();
|
||||
/**
|
||||
* Handles a SQL-Error
|
||||
*
|
||||
* @param string $errmsg
|
||||
* @param int $errno
|
||||
* @throws MsdEception
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function sqlError ($errmsg, $errno)
|
||||
{
|
||||
throw new Msd_Exception($errmsg, $errno);
|
||||
}
|
||||
}
|
||||
240
library/Msd/Db/Mysql.php
Normale Datei
240
library/Msd/Db/Mysql.php
Normale Datei
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
* @version SVN: $rev: 1205 $
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Capsules all database related actions.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
*/
|
||||
class Msd_Db_Mysql extends Msd_Db_MysqlCommon
|
||||
{
|
||||
/**
|
||||
* Mysql connection handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $_connectionHandle = null;
|
||||
|
||||
/**
|
||||
* Mysql result handle
|
||||
*
|
||||
* @var resource
|
||||
*/
|
||||
protected $_resultHandle = null;
|
||||
|
||||
/**
|
||||
* Establish a connection to MySQL.
|
||||
*
|
||||
* Creates a connection to the database and stores the connection handle in
|
||||
* $this->_connectionHandle.
|
||||
* Returns true on success or false if connection couldn't be established.
|
||||
*
|
||||
* @throws Exception
|
||||
* @return bool
|
||||
**/
|
||||
protected function _dbConnect()
|
||||
{
|
||||
if (is_resource($this->_connectionHandle)) {
|
||||
return true;
|
||||
}
|
||||
if ($this->_port == 0) {
|
||||
$this->_port = 3306;
|
||||
}
|
||||
$connectionString = $this->_server . ':' . $this->_port;
|
||||
if ($this->_socket != '') {
|
||||
$connectionString .= ':' . $this->_socket;
|
||||
}
|
||||
$this->_connectionHandle = @mysql_connect(
|
||||
$connectionString,
|
||||
$this->_user, $this->_password
|
||||
);
|
||||
if (false === $this->_connectionHandle) {
|
||||
throw new Msd_Exception(mysql_error(), mysql_errno());
|
||||
}
|
||||
$this->setConnectionCharset();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the connection handle if already established or creates one.
|
||||
*
|
||||
* @return resource The connection handle
|
||||
*/
|
||||
private function _getHandle()
|
||||
{
|
||||
if (!is_resource($this->_connectionHandle)) {
|
||||
$this->_dbConnect();
|
||||
}
|
||||
return $this->_connectionHandle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return version nr of MySql server.
|
||||
*
|
||||
* @return string Version number
|
||||
*/
|
||||
public function getServerInfo()
|
||||
{
|
||||
return mysql_get_server_info($this->_getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version nr of MySql client.
|
||||
*
|
||||
* @return string Version nr
|
||||
*/
|
||||
public function getClientInfo()
|
||||
{
|
||||
return mysql_get_client_info();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the character set of the MySQL-connection.
|
||||
*
|
||||
* Trys to set the connection charset and returns it.
|
||||
*
|
||||
* @param string $charset The wanted charset of the connection
|
||||
*
|
||||
* @return string The set charset
|
||||
*/
|
||||
public function setConnectionCharset($charset = 'utf8')
|
||||
{
|
||||
if (function_exists('mysql_set_charset')
|
||||
&& @mysql_set_charset($charset, $this->_getHandle())) {
|
||||
$this->_connectionCharset = $charset;
|
||||
return $this->_connectionCharset;
|
||||
} else {
|
||||
$this->query('SET NAMES \'' . $charset . '\'', self::SIMPLE);
|
||||
$this->_connectionCharset = $charset;
|
||||
return $charset;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the given database to use it as the target for following queries
|
||||
*
|
||||
* Returns true if selection was succesfull otherwise false.
|
||||
*
|
||||
* @throws Exception
|
||||
* @param string $database The database to select
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function selectDb($database)
|
||||
{
|
||||
$res = @mysql_select_db($database, $this->_getHandle());
|
||||
if ($res === false) {
|
||||
throw new Msd_Exception(mysql_error(), mysql_errno());
|
||||
}
|
||||
$this->_dbSelected = $database;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Execute a query and set _resultHandle
|
||||
*
|
||||
* If $getRows is true all rows are fetched and returned.
|
||||
* If $getRows is false, query will be executed, but the result handle
|
||||
* is returned.
|
||||
*
|
||||
* @param string $query The query to execute
|
||||
* @param const $kind Type of result set
|
||||
* @param boolean $getRows Wether to fetch all rows and return them
|
||||
*
|
||||
* @return boolean|array
|
||||
*/
|
||||
public function query($query, $kind = self::ARRAY_OBJECT, $getRows = true)
|
||||
{
|
||||
$this->_resultHandle = @mysql_query($query, $this->_getHandle());
|
||||
if (false === $this->_resultHandle) {
|
||||
$this->sqlError(
|
||||
mysql_error($this->_connectionHandle),
|
||||
mysql_errno($this->_connectionHandle)
|
||||
);
|
||||
}
|
||||
if ($kind === self::SIMPLE || is_bool($this->_resultHandle)) {
|
||||
return $this->_resultHandle;
|
||||
}
|
||||
|
||||
// return result set?
|
||||
if ($getRows) {
|
||||
$ret = array();
|
||||
WHILE ($row = $this->getNextRow($kind)) {
|
||||
$ret[] = $row;
|
||||
}
|
||||
$this->_resultHandle = null;
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next row from a result set that is returned by $this->query().
|
||||
*
|
||||
* Can be used to walk through result sets.
|
||||
*
|
||||
* @param const $kind
|
||||
*
|
||||
* @return array|object
|
||||
*/
|
||||
public function getNextRow($kind)
|
||||
{
|
||||
switch ($kind)
|
||||
{
|
||||
case self::ARRAY_OBJECT:
|
||||
return mysql_fetch_object($this->_resultHandle);
|
||||
break;
|
||||
case self::ARRAY_NUMERIC:
|
||||
return mysql_fetch_array($this->_resultHandle, MYSQL_NUM);
|
||||
break;
|
||||
case self::ARRAY_ASSOC:
|
||||
return mysql_fetch_array($this->_resultHandle, MYSQL_ASSOC);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows for the last query.
|
||||
*
|
||||
* @see inc/classes/db/MsdDbFactory#affectedRows()
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
{
|
||||
return mysql_affected_rows($this->_getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a value with real_escape_string() to use it in a query.
|
||||
*
|
||||
* @see inc/classes/db/MsdDbFactory#escape($val)
|
||||
* @param mixed $val The value to escape
|
||||
* @return mixed
|
||||
*/
|
||||
public function escape($val)
|
||||
{
|
||||
return mysql_real_escape_string($val, $this->_getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the last MySQL error.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getLastError()
|
||||
{
|
||||
return array(
|
||||
'code' => mysql_errno($this->_getHandle()),
|
||||
'message' => mysql_error($this->_getHandle()),
|
||||
);
|
||||
}
|
||||
}
|
||||
533
library/Msd/Db/MysqlCommon.php
Normale Datei
533
library/Msd/Db/MysqlCommon.php
Normale Datei
|
|
@ -0,0 +1,533 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
* @version SVN: $rev: 1205 $
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class offers some db related methods that are equal for Mysql and MySQLi.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
*/
|
||||
abstract class Msd_Db_MysqlCommon extends Msd_Db
|
||||
{
|
||||
/**
|
||||
* Get the list of table and view names of given database
|
||||
*
|
||||
* @param string $dbName Name of database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTables($dbName)
|
||||
{
|
||||
$tables = array();
|
||||
$sql = 'SHOW TABLES FROM `' . $dbName . '`';
|
||||
$res = $this->query($sql, self::ARRAY_NUMERIC);
|
||||
foreach ($res as $val) {
|
||||
$tables[] = $val[0];
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of tables of the given database. The result include tables
|
||||
* meta data.
|
||||
*
|
||||
* @param string $dbName Name of database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTablesMeta($dbName)
|
||||
{
|
||||
$tablesSql = 'SELECT * FROM `information_schema`.`TABLES` '
|
||||
. 'WHERE `TABLE_SCHEMA` = \'' . $this->escape($dbName) . '\'';
|
||||
$rawTables = $this->query($tablesSql, self::ARRAY_ASSOC);
|
||||
$tables = array();
|
||||
foreach ($rawTables as $rawTable) {
|
||||
$tables[$rawTable['TABLE_NAME']] = $rawTable;
|
||||
}
|
||||
return $tables;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information of databases
|
||||
*
|
||||
* Gets list and info of all databases that the actual MySQL-User can access
|
||||
* and saves it in $this->databases.
|
||||
*
|
||||
* @param bool $addViews If set nr of views and routines are added
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDatabases($addViews = false)
|
||||
{
|
||||
$query = 'SELECT `is`.*, count(`t`.`TABLE_NAME`) `tables`'
|
||||
. ' FROM `information_schema`.`SCHEMATA` `is`'
|
||||
. ' LEFT JOIN `information_schema`.`TABLES` `t` '
|
||||
. ' ON `t`.`TABLE_SCHEMA` = `is`.`SCHEMA_NAME`'
|
||||
. ' GROUP BY `is`.`SCHEMA_NAME`'
|
||||
. ' ORDER BY `is`.`SCHEMA_NAME` ASC';
|
||||
$res = $this->query($query, self::ARRAY_ASSOC, true);
|
||||
if ($addViews) {
|
||||
$views = $this->getNrOfViews();
|
||||
$routines = $this->getNrOfRoutines();
|
||||
$sizes = $this->getDatabaseSizes();
|
||||
}
|
||||
foreach ($res as $row) {
|
||||
$database = $row['SCHEMA_NAME'];
|
||||
if ($addViews) {
|
||||
$row['views'] = 0;
|
||||
$row['routines'] = 0;
|
||||
$row['size'] = 0;
|
||||
$row[$database] = 0;
|
||||
if (isset($sizes[$database])) {
|
||||
$row['size'] = $sizes[$database];
|
||||
}
|
||||
// add views
|
||||
if (isset($views[$database])) {
|
||||
$row['views'] = $views[$database];
|
||||
$row['tables'] -= $views[$database];
|
||||
}
|
||||
// add routines
|
||||
if (isset($routines[$database])) {
|
||||
$row['routines'] = $routines[$database];
|
||||
}
|
||||
}
|
||||
unset($row['SCHEMA_NAME']);
|
||||
$this->_databases[$database] = $row;
|
||||
}
|
||||
return $this->_databases;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return assoc array with the names of accessable databases
|
||||
*
|
||||
* @return array Assoc array with database names
|
||||
*/
|
||||
public function getDatabaseNames()
|
||||
{
|
||||
if ($this->_databases == null) {
|
||||
$this->getDatabases();
|
||||
}
|
||||
return array_keys($this->_databases);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the actual selected database.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSelectedDb()
|
||||
{
|
||||
return $this->_dbSelected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the CREATE Statement of a table.
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTableCreate($table)
|
||||
{
|
||||
$sql = 'SHOW CREATE TABLE `' . $table . '`';
|
||||
$res = $this->query($sql, self::ARRAY_ASSOC);
|
||||
return $res[0]['Create Table'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the full description of all columns of a table.
|
||||
*
|
||||
* Saves it to $this->metaTables[$database][$table].
|
||||
*
|
||||
* @param string $table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTableColumns($table)
|
||||
{
|
||||
$dbName = $this->getSelectedDb();
|
||||
$sql = 'SHOW FULL FIELDS FROM `' . $table . '`';
|
||||
$res = $this->query($sql, self::ARRAY_ASSOC);
|
||||
if (!isset($this->_metaTables[$dbName])) {
|
||||
$this->_metaTables[$dbName] = array();
|
||||
}
|
||||
if (is_array($res)) {
|
||||
$this->_metaTables[$dbName][$table] = array();
|
||||
foreach ($res as $r) {
|
||||
$this->_metaTables[$dbName][$table][$r['Field']] = $r;
|
||||
}
|
||||
}
|
||||
return $this->_metaTables[$dbName][$table];
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimize given table.
|
||||
*
|
||||
* Returns false on error or Sql's Msg_text if query succeeds.
|
||||
*
|
||||
* @param string $table Name of table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function optimizeTable($table)
|
||||
{
|
||||
return $this->_executeMaintainAction('OPTIMIZE', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze given table.
|
||||
*
|
||||
* Returns false on error or Sql's Msg_text if query succeeds.
|
||||
*
|
||||
* @param string $table Name of table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function analyzeTable($table)
|
||||
{
|
||||
return $this->_executeMaintainAction('ANALYZE', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check given table.
|
||||
*
|
||||
* Returns false on error or Sql's Msg_text if query succeeds.
|
||||
*
|
||||
* @param string $table Name of table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function checkTable($table)
|
||||
{
|
||||
return $this->_executeMaintainAction('CHECK', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Repair given table.
|
||||
*
|
||||
* Returns false on error or Sql's Msg_text if query succeeds.
|
||||
*
|
||||
* @param string $table Name of table
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function repairTable($table)
|
||||
{
|
||||
return $this->_executeMaintainAction('REPAIR', $table);
|
||||
}
|
||||
|
||||
/**
|
||||
* Truncate a table (delete all records)
|
||||
*
|
||||
* @param string $table The tabel to truncate
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function truncateTable($table)
|
||||
{
|
||||
$sql = 'TRUNCATE `' . $this->escape($table) . '`';
|
||||
$res = $this->query($sql, self::SIMPLE);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute maintaining action on a table (optimize, analyze, check, repair)
|
||||
*
|
||||
* @param string $action Action to perform
|
||||
*
|
||||
* @return array Result array conataining messages
|
||||
*/
|
||||
private function _executeMaintainAction($action, $table)
|
||||
{
|
||||
$sql = $action . ' TABLE `' . $this->escape($table) . '`';
|
||||
try {
|
||||
$res = $this->query($sql, Msd_Db::ARRAY_ASSOC);
|
||||
if (isset($res[0]['Msg_text'])) {
|
||||
return $res[0];
|
||||
}
|
||||
} catch (Msd_Exception $e) {
|
||||
unset($e);
|
||||
}
|
||||
$ret = array('Table' => $table);
|
||||
return array_merge($ret, $this->getLastError());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of known charsets from MySQL-Server.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCharsets()
|
||||
{
|
||||
if (!empty($this->_charsets)) {
|
||||
return $this->_charsets;
|
||||
}
|
||||
$sql = 'SELECT * FROM `information_schema`.`CHARACTER_SETS` ORDER BY `CHARACTER_SET_NAME`';
|
||||
$result = $this->query($sql, self::ARRAY_ASSOC);
|
||||
$this->_charsets = array();
|
||||
foreach ($result as $res) {
|
||||
$this->_charsets[$res['CHARACTER_SET_NAME']] = $res;
|
||||
}
|
||||
return $this->_charsets;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets extended table information for one or all tables.
|
||||
*
|
||||
* @param string | false $tableName
|
||||
* @param string | false $databaseName
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getTableStatus($tableName = false, $databaseName = false)
|
||||
{
|
||||
if ($databaseName === false) {
|
||||
$databaseName = $this->getSelectedDb();
|
||||
}
|
||||
$sql = "SELECT * FROM `information_schema`.`TABLES` WHERE "
|
||||
. "`TABLE_SCHEMA`='" . $this->escape($databaseName) . "'";
|
||||
if ($tableName !== false) {
|
||||
$sql .= " AND `TABLE_NAME` LIKE '" . $this->escape($tableName) . "'";
|
||||
}
|
||||
$res = $this->query($sql, self::ARRAY_ASSOC);
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variables of SQL-Server and return them as assoc array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getVariables()
|
||||
{
|
||||
$ret = array();
|
||||
$variables = $this->query('SHOW VARIABLES', Msd_Db::ARRAY_ASSOC);
|
||||
foreach ($variables as $val) {
|
||||
$ret[$val['Variable_name']] = $val['Value'];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get global status variables of SQL-Server and return them as assoc array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getGlobalStatus()
|
||||
{
|
||||
$ret = array();
|
||||
$variables = $this->query('SHOW GLOBAL STATUS', Msd_Db::ARRAY_ASSOC);
|
||||
foreach ($variables as $val) {
|
||||
$ret[$val['Variable_name']] = $val['Value'];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of records of a table by query SELECT COUNT(*)
|
||||
*
|
||||
* @param string $tableName The name of the table
|
||||
* @param string $dbName The name of the database
|
||||
*
|
||||
* @return integer The number of rows isnide table
|
||||
*/
|
||||
public function getNrOfRowsBySelectCount($tableName, $dbName = null)
|
||||
{
|
||||
if ($dbName === null) {
|
||||
$dbName = $this->getSelectedDb();
|
||||
}
|
||||
;
|
||||
$sql = 'SELECT COUNT(*) as `Rows` FROM `%s`.`%s`';
|
||||
$sql = sprintf($sql, $this->escape($dbName), $this->escape($tableName));
|
||||
$rows = $this->query($sql, Msd_Db::ARRAY_ASSOC);
|
||||
return (int)$rows[0]['Rows'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the collations from information schema.
|
||||
*
|
||||
* @param string|null $charsetName Name of the charset
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getCollations($charsetName = null)
|
||||
{
|
||||
$where = "";
|
||||
if (!empty($charsetName)) {
|
||||
$where = "WHERE `CHARACTER_SET_NAME` = '" . $this->escape($charsetName) . "'";
|
||||
}
|
||||
$collationSql = "SELECT `CHARACTER_SET_NAME` `charset`, "
|
||||
. "GROUP_CONCAT(`COLLATION_NAME` ORDER BY `COLLATION_NAME`) "
|
||||
. "`collations` FROM `information_schema`."
|
||||
. "`COLLATION_CHARACTER_SET_APPLICABILITY` GROUP BY "
|
||||
. "`CHARACTER_SET_NAME` $where";
|
||||
$rawCollations = $this->query($collationSql, Msd_Db::ARRAY_ASSOC);
|
||||
$collations = array();
|
||||
foreach ($rawCollations as $charset) {
|
||||
$collations[$charset['charset']] = explode(
|
||||
",",
|
||||
$charset['collations']
|
||||
);
|
||||
}
|
||||
|
||||
return $collations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the default collation for the charset or the given charset.
|
||||
*
|
||||
* @param string|null $charsetName Name of the charset
|
||||
*
|
||||
* @return array|string
|
||||
*/
|
||||
public function getDefaultCollations($charsetName = null)
|
||||
{
|
||||
if (!empty($charsetName)) {
|
||||
$defaultCollationSql = 'SELECT `DEFAULT_COLLATE_NAME` FROM '
|
||||
. '`information_schema`.`CHARACTER_SETS` WHERE '
|
||||
. '`CHARACTER_SET_NAME` = \'' . $this->escape($charsetName)
|
||||
. '\'';
|
||||
$result = $this->query($defaultCollationSql, self::ARRAY_NUMERIC);
|
||||
$defaultCollation = $result[0][0];
|
||||
} else {
|
||||
$defaultCollationSql = 'SELECT `CHARACTER_SET_NAME` `charset`, '
|
||||
. '`DEFAULT_COLLATE_NAME` `collation` FROM '
|
||||
. '`information_schema`.`CHARACTER_SETS`';
|
||||
$result = $this->query($defaultCollationSql, self::ARRAY_ASSOC);
|
||||
$defaultCollation = array();
|
||||
foreach ($result as $row) {
|
||||
$defaultCollation[$row['charset']] = $row['collation'];
|
||||
}
|
||||
}
|
||||
return $defaultCollation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the views of the given database.
|
||||
*
|
||||
* @param string $dbName Name of database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getViews($dbName)
|
||||
{
|
||||
$sql = 'SELECT * FROM `information_schema`.`VIEWS` WHERE '
|
||||
. '`TABLE_SCHEMA` = \'' . $this->escape($dbName) . '\'';
|
||||
$rawViews = $this->query($sql, self::ARRAY_ASSOC);
|
||||
$views = array();
|
||||
foreach ($rawViews as $rawView) {
|
||||
$views[$rawView['TABLE_NAME']] = $rawView;
|
||||
}
|
||||
return $views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of views per database.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNrOfViews()
|
||||
{
|
||||
$sql = 'SELECT `TABLE_SCHEMA`, count(*) as `views` FROM '
|
||||
. '`information_schema`.`VIEWS` '
|
||||
. ' GROUP BY `TABLE_SCHEMA`';
|
||||
$res = $this->query($sql, self::ARRAY_ASSOC);
|
||||
$views = array();
|
||||
foreach ($res as $view) {
|
||||
$views[$view['TABLE_SCHEMA']] = $view['views'];
|
||||
}
|
||||
return $views;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of routines (procedures and functions).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNrOfRoutines()
|
||||
{
|
||||
$sql = 'SELECT `ROUTINE_SCHEMA`, count(`ROUTINE_NAME`) as `routines`'
|
||||
. ' FROM `information_schema`.`ROUTINES` '
|
||||
. ' GROUP BY `ROUTINE_SCHEMA`';
|
||||
$res = $this->query($sql, self::ARRAY_ASSOC);
|
||||
$routines = array();
|
||||
foreach ($res as $routine) {
|
||||
$routines[$routine['ROUTINE_SCHEMA']] = $routine['routines'];
|
||||
}
|
||||
return $routines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the size of tabledata in bytes
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getDatabaseSizes()
|
||||
{
|
||||
$sql = 'SELECT `TABLE_SCHEMA`, sum(`DATA_LENGTH`) as `size`'
|
||||
. ' FROM `information_schema`.`TABLES` '
|
||||
. ' GROUP BY `TABLE_SCHEMA`';
|
||||
$res = $this->query($sql, self::ARRAY_ASSOC);
|
||||
$sizes = array();
|
||||
foreach ($res as $size) {
|
||||
$sizes[$size['TABLE_SCHEMA']] = $size['size'];
|
||||
}
|
||||
return $sizes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the stored procedurs of the given database.
|
||||
*
|
||||
* @param string $dbName Name of database
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getStoredProcedures($dbName)
|
||||
{
|
||||
$routinesSql = 'SELECT * FROM `information_schema`.`ROUTINES` WHERE '
|
||||
. '`ROUTINE_SCHEMA` = \'' . $this->escape($dbName) . '\'';
|
||||
$rawRoutines = $this->query($routinesSql, self::ARRAY_ASSOC);
|
||||
$routines = array();
|
||||
foreach ($rawRoutines as $rawRoutine) {
|
||||
$routines[$rawRoutine['ROUTINE_NAME']] = $rawRoutine;
|
||||
}
|
||||
return $routines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new database via building a MySQL statement and its execution.
|
||||
*
|
||||
* @param string $databaseName Name of the new database
|
||||
* @param string $databaseCharset Charackter set of the new database
|
||||
* @param string $databaseCollation Collation of the new database
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function createDatabase(
|
||||
$databaseName,
|
||||
$databaseCharset = '',
|
||||
$databaseCollation = ''
|
||||
)
|
||||
{
|
||||
if ($databaseCharset != '') {
|
||||
$databaseCharset = "DEFAULT CHARSET "
|
||||
. $this->escape($databaseCharset);
|
||||
}
|
||||
if ($databaseCollation != '') {
|
||||
$databaseCollation = "DEFAULT COLLATE "
|
||||
. $this->escape($databaseCollation);
|
||||
}
|
||||
$sql = "CREATE DATABASE `" . $databaseName
|
||||
. "` $databaseCharset $databaseCollation";
|
||||
$dbCreated = $this->query($sql, Msd_Db::SIMPLE);
|
||||
return $dbCreated;
|
||||
}
|
||||
}
|
||||
240
library/Msd/Db/Mysqli.php
Normale Datei
240
library/Msd/Db/Mysqli.php
Normale Datei
|
|
@ -0,0 +1,240 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
* @version SVN: $rev: 1208 $
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Capsules all database related actions.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Db
|
||||
*/
|
||||
class Msd_Db_Mysqli extends Msd_Db_MysqlCommon
|
||||
{
|
||||
/**
|
||||
* @var mysqli
|
||||
*/
|
||||
private $_mysqli = null;
|
||||
|
||||
/**
|
||||
* @var resource
|
||||
*/
|
||||
private $_resultHandle = null;
|
||||
/**
|
||||
* Establish a connection to MySQL.
|
||||
*
|
||||
* Create a connection to MySQL and store the connection handle in
|
||||
* $this->connectionHandle.
|
||||
*
|
||||
* @return boolean
|
||||
**/
|
||||
protected function _dbConnect()
|
||||
{
|
||||
$errorReporting = error_reporting(0);
|
||||
if ($this->_port == 0) {
|
||||
$this->_port = 3306;
|
||||
}
|
||||
|
||||
$this->_mysqli = new mysqli(
|
||||
$this->_server,
|
||||
$this->_user,
|
||||
$this->_password,
|
||||
$this->_dbSelected,
|
||||
$this->_port,
|
||||
$this->_socket
|
||||
);
|
||||
error_reporting($errorReporting);
|
||||
if ($this->_mysqli->connect_errno) {
|
||||
$error = $this->_mysqli->connect_error;
|
||||
$errno = $this->_mysqli->connect_errno;
|
||||
$this->_mysqli = null;
|
||||
throw new Msd_Exception($error, $errno);
|
||||
}
|
||||
$this->setConnectionCharset();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the connection handle if already set or creates one.
|
||||
*
|
||||
* @return mysqli The instance of mysqli
|
||||
*/
|
||||
private function _getHandle()
|
||||
{
|
||||
if (!$this->_mysqli instanceof mysqli) {
|
||||
$this->_dbConnect();
|
||||
}
|
||||
return $this->_mysqli;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the version nr of MySql server.
|
||||
*
|
||||
* @return string Version nr
|
||||
*/
|
||||
public function getServerInfo()
|
||||
{
|
||||
return $this->_getHandle()->server_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return version nr of MySql client.
|
||||
*
|
||||
* @return string Version nr
|
||||
*/
|
||||
public function getClientInfo()
|
||||
{
|
||||
return $this->_getHandle()->client_info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the character set of the MySQL-connection.
|
||||
*
|
||||
* Trys to set the connection charset and returns it.
|
||||
*
|
||||
* @param string $charset The wanted charset of the connection
|
||||
*
|
||||
* @return string The set charset
|
||||
*/
|
||||
public function setConnectionCharset($charset = 'utf8')
|
||||
{
|
||||
if (!@$this->_getHandle()->set_charset($charset)) {
|
||||
$this->sqlError(
|
||||
$charset . ' ' . $this->_mysqli->error,
|
||||
$this->_mysqli->errno
|
||||
);
|
||||
}
|
||||
$this->_connectionCharset = $this->_getHandle()->character_set_name();
|
||||
return $this->_connectionCharset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Select the given database to use it as the target for following queries.
|
||||
*
|
||||
* Returns true if selection was succesfull, otherwise false.
|
||||
*
|
||||
* @param string $database Database to select
|
||||
*
|
||||
* @return boolean True on success
|
||||
*/
|
||||
public function selectDb($database)
|
||||
{
|
||||
$res = @$this->_getHandle()->select_db($database);
|
||||
if ($res === false) {
|
||||
return $this->_getHandle()->error;
|
||||
} else {
|
||||
$this->_dbSelected = $database;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a query and set _resultHandle
|
||||
*
|
||||
* If $getRows is true all rows are fetched and returned.
|
||||
* If $getRows is false, query will be executed, but the result handle
|
||||
* is returned.
|
||||
*
|
||||
* @param string $query The query to execute
|
||||
* @param const $kind Type of result set
|
||||
* @param boolean $getRows Wether to fetch all rows and return them
|
||||
*
|
||||
* @return resource|array
|
||||
*/
|
||||
public function query($query, $kind = self::ARRAY_OBJECT, $getRows = true)
|
||||
{
|
||||
try {
|
||||
$this->_resultHandle = $this->_getHandle()->query($query);
|
||||
|
||||
if (false === $this->_resultHandle) {
|
||||
$this->sqlError(
|
||||
$this->_getHandle()->error,
|
||||
$this->_getHandle()->errno
|
||||
);
|
||||
}
|
||||
if (!$this->_resultHandle instanceof mysqli_result
|
||||
|| $kind === self::SIMPLE) {
|
||||
return $this->_resultHandle;
|
||||
}
|
||||
// return result set?
|
||||
if ($getRows) {
|
||||
$ret = array();
|
||||
WHILE ($row = $this->getNextRow($kind)) {
|
||||
$ret[] = $row;
|
||||
}
|
||||
$this->_resultHandle = null;
|
||||
return $ret;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->sqlError(
|
||||
$this->_getHandle()->error,
|
||||
$this->_getHandle()->errno
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get next row from a result set that is returned by $this->query().
|
||||
*
|
||||
* Can be used to walk through result sets.
|
||||
*
|
||||
* @param const $kind
|
||||
*
|
||||
* @return array|object
|
||||
*/
|
||||
public function getNextRow($kind)
|
||||
{
|
||||
switch ($kind)
|
||||
{
|
||||
case self::ARRAY_ASSOC:
|
||||
return $this->_resultHandle->fetch_assoc();
|
||||
case self::ARRAY_OBJECT:
|
||||
return $this->_resultHandle->fetch_object();
|
||||
break;
|
||||
case self::ARRAY_NUMERIC:
|
||||
return $this->_resultHandle->fetch_array(MYSQLI_NUM);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the number of affected rows for the last executed query.
|
||||
*
|
||||
* @see inc/classes/db/MsdDbFactory#affectedRows()
|
||||
* @return integer
|
||||
*/
|
||||
public function getAffectedRows()
|
||||
{
|
||||
return $this->_getHandle()->affected_rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Escape a value with real_escape_string() to use it in a query.
|
||||
*
|
||||
* @see inc/classes/db/MsdDbFactory#escape($val)
|
||||
* @param mixed $val The value to escape
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function escape($val)
|
||||
{
|
||||
return $this->_getHandle()->real_escape_string($val);
|
||||
}
|
||||
/**
|
||||
* Retrieves the last MySQL error.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLastError()
|
||||
{
|
||||
return array(
|
||||
'code' => $this->_getHandle()->errno,
|
||||
'message' => $this->_getHandle()->error,
|
||||
);
|
||||
}
|
||||
}
|
||||
206
library/Msd/Dump.php
Normale Datei
206
library/Msd/Dump.php
Normale Datei
|
|
@ -0,0 +1,206 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Dump
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Dump Class
|
||||
*
|
||||
* Offers some methods to wrap some common SQL-commands
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Dump
|
||||
*/
|
||||
class Msd_Dump
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->dbsToBackup = array();
|
||||
$this->tableInfo = array();
|
||||
$this->recordsTotal = 0;
|
||||
$this->tablesTotal = 0;
|
||||
$this->datasizeTotal = 0;
|
||||
$this->dbActual = null;
|
||||
$this->sumTotal = $this->_initSum();
|
||||
$this->dbo = Msd_Db::getAdapter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get databases to backup and calculate sum array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function prepareDumpProcess()
|
||||
{
|
||||
$taskList = Msd_TaskManager::getInstance('backupTasks', true);
|
||||
$this->dbsToBackup = $this->_getDbsToBackup();
|
||||
$dbNames=array_keys($this->dbsToBackup);
|
||||
foreach ($dbNames as $dbName) {
|
||||
$sumInfo = $this->_getDatabaseSums($dbName);
|
||||
$this->_addDatabaseSums($sumInfo);
|
||||
$this->buildTaskList($dbName, $taskList);
|
||||
}
|
||||
// set db to be dumped first -> start index is needed
|
||||
$this->dbActual = $dbNames[0];
|
||||
//Debug::out($taskList->getTasks());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of databases that shold be dumped
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getDbsToBackup()
|
||||
{
|
||||
$config = Msd_Configuration::getInstance();
|
||||
$databases = $config->get('dynamic.databases');
|
||||
// first check if any db is marked to be dumped
|
||||
$dbToDumpExists = false;
|
||||
if (!empty($databases)) {
|
||||
foreach ($databases as $dbName => $val) {
|
||||
$this->databases[$dbName] = array();
|
||||
if (isset($val['dump']) && $val['dump'] == 1) {
|
||||
$this->dbsToBackup[$dbName] = $val;
|
||||
$dbToDumpExists = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!$dbToDumpExists) {
|
||||
// no db selected for dump -> set actual db to be dumped
|
||||
$index = $config->get('dynamic.dbActual');
|
||||
$this->dbsToBackup[$index] = array();
|
||||
$this->dbsToBackup[$index]['dump'] = 1;
|
||||
}
|
||||
|
||||
return $this->dbsToBackup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get sum of tables, records and data size grouped by table type
|
||||
*
|
||||
* @param string $db The database to check
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _getDatabaseSums($dbName)
|
||||
{
|
||||
$this->dbo->selectDb($dbName);
|
||||
$metaInfo = $this->dbo->getTableStatus();
|
||||
$sum = array();
|
||||
foreach ($metaInfo as $index => $vals) {
|
||||
if ($vals['TABLE_TYPE'] == 'BASE TABLE') {
|
||||
$type = $vals['ENGINE'];
|
||||
if (!isset($sum[$type])) {
|
||||
$sum[$type] = $this->_initSum();
|
||||
}
|
||||
$sum[$type]['tablesTotal']++;
|
||||
if (!in_array($type, array('VIEW', 'MEMORY'))) {
|
||||
$sum[$type]['recordsTotal'] += $vals['TABLE_ROWS'];
|
||||
$sum[$type]['datasizeTotal'] += $vals['DATA_LENGTH'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($sum)) {
|
||||
ksort($sum);
|
||||
}
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add sums of a database to the total sum array $this->sumTotal
|
||||
*
|
||||
* @param $sum Array containing the sum values for a database
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _addDatabaseSums($sum)
|
||||
{
|
||||
$types = array_keys($sum);
|
||||
foreach ($types as $type) {
|
||||
if (!isset($this->sumTotal['tables'][$type])) {
|
||||
$this->sumTotal['tables'][$type] = $this->_initSum();
|
||||
}
|
||||
$this->sumTotal['tables'][$type] =$this->_sumAdd(
|
||||
$this->sumTotal['tables'][$type], $sum[$type]
|
||||
);
|
||||
$this->sumTotal['tablesTotal'] += $sum[$type]['tablesTotal'];
|
||||
$this->sumTotal['recordsTotal'] += $sum[$type]['recordsTotal'];
|
||||
$this->sumTotal['datasizeTotal'] += $sum[$type]['datasizeTotal'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Init a sum array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _initSum()
|
||||
{
|
||||
$sum = array();
|
||||
$sum['tablesTotal'] = 0;
|
||||
$sum['recordsTotal'] = 0;
|
||||
$sum['datasizeTotal'] = 0;
|
||||
return $sum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a sum array
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _sumAdd($baseArr, $addArr)
|
||||
{
|
||||
$baseArr['tablesTotal'] += $addArr['tablesTotal'];
|
||||
$baseArr['recordsTotal'] += $addArr['recordsTotal'];
|
||||
$baseArr['datasizeTotal'] += $addArr['datasizeTotal'];
|
||||
return $baseArr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the task "get create table" for each table to the task list
|
||||
*
|
||||
* @param string $dbName Name of database
|
||||
* @param Msd_TaskManager $tasks TaskManager instance
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function buildTaskList($dbName, Msd_TaskManager $taskList)
|
||||
{
|
||||
$tables = $this->dbo->getTableStatus(false, $dbName);
|
||||
foreach ($tables as $table) {
|
||||
// add create table
|
||||
$taskList->addTask(
|
||||
Msd_TaskManager::GET_CREATE_TABLE,
|
||||
array('db' => $dbName,
|
||||
'table' => $table['TABLE_NAME']
|
||||
)
|
||||
);
|
||||
// add dump data
|
||||
if ($table['TABLE_TYPE'] === 'BASE TABLE') {
|
||||
$taskList->addTask(
|
||||
Msd_TaskManager::BACKUP_TABLE_DATA,
|
||||
array('db' => $dbName,
|
||||
'table' => $table['TABLE_NAME']
|
||||
)
|
||||
);
|
||||
}
|
||||
// add keys and indexes
|
||||
$taskList->addTask(
|
||||
Msd_TaskManager::GET_ALTER_TABLE_ADD_KEYS,
|
||||
array('db' => $dbName,
|
||||
'table' => $table['TABLE_NAME']
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
library/Msd/Exception.php
Normale Datei
19
library/Msd/Exception.php
Normale Datei
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Exception
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* MySQLDumper Exception
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Exception
|
||||
*/
|
||||
class Msd_Exception extends Exception
|
||||
{
|
||||
}
|
||||
130
library/Msd/File.php
Normale Datei
130
library/Msd/File.php
Normale Datei
|
|
@ -0,0 +1,130 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage File
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* File-Helper Class
|
||||
*
|
||||
* Class offers some methods for file handling
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage File
|
||||
*/
|
||||
class Msd_File
|
||||
{
|
||||
/**
|
||||
* Get CHMOD of a file
|
||||
*
|
||||
* @param string $file The file to get chmod for
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public static function getChmod($file)
|
||||
{
|
||||
clearstatcache();
|
||||
return @substr(decoct(fileperms($file)), -3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if file or directory is writable and trys to chmod it.
|
||||
*
|
||||
* Returns if file or directory is writable after chmodding.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $chmod
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isWritable($path, $chmod)
|
||||
{
|
||||
$fileValidator = new Msd_Validate_File_Accessible(
|
||||
array('accessType' => array('write'))
|
||||
);
|
||||
if (!$fileValidator->isValid($path)) {
|
||||
@chmod($path, $chmod);
|
||||
}
|
||||
return $fileValidator->isValid($path);
|
||||
}
|
||||
/**
|
||||
* Get information of latest backup file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getLatestBackupInfo()
|
||||
{
|
||||
$config = Msd_Configuration::getInstance();
|
||||
$latestBackup = array();
|
||||
$dir = new DirectoryIterator($config->get('paths.backup'));
|
||||
foreach ($dir as $file) {
|
||||
if ($file->isFile()) {
|
||||
$fileMtime = $file->getMTime();
|
||||
if (!isset($latestBackup['mtime']) ||
|
||||
$fileMtime > $latestBackup['mtime']) {
|
||||
$filename = $file->getFilename();
|
||||
$latestBackup['filename'] = $filename;
|
||||
$latestBackup['fileMtime'] = date("d.m.Y H:i", $fileMtime);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $latestBackup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array with the names of all saved configuration files
|
||||
*
|
||||
* Strips extensions.
|
||||
*
|
||||
* @return array List of configuration names
|
||||
*/
|
||||
public static function getConfigNames()
|
||||
{
|
||||
$config = Msd_Configuration::getInstance();
|
||||
$configPath = $config->get('paths.config');
|
||||
if (!is_readable($configPath)) {
|
||||
return array();
|
||||
}
|
||||
$dir = new DirectoryIterator($configPath);
|
||||
$files = array();
|
||||
foreach ($dir as $file) {
|
||||
if ($file->isFile()) {
|
||||
$filename = $file->getFilename();
|
||||
if (substr($filename, -4) == '.ini') {
|
||||
$files[] = substr($filename, 0, - 4);
|
||||
}
|
||||
}
|
||||
}
|
||||
@sort($files);
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of available themes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function getThemeList()
|
||||
{
|
||||
$dir = new DirectoryIterator(APPLICATION_PATH . '/../public/css/');
|
||||
$themes = array();
|
||||
while ($dir->valid()) {
|
||||
$current = $dir->current();
|
||||
if ($current->isDir() &&
|
||||
!$current->isDot() &&
|
||||
$current->getBasename() != '.svn'
|
||||
) {
|
||||
$themeName= $current->getBasename();
|
||||
$themes[$themeName] = $themeName;
|
||||
}
|
||||
$dir->next();
|
||||
}
|
||||
|
||||
return $themes;
|
||||
}
|
||||
|
||||
}
|
||||
126
library/Msd/File/Dump.php
Normale Datei
126
library/Msd/File/Dump.php
Normale Datei
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage File
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dumpfile-Helper Class
|
||||
*
|
||||
* Class offers some methods for file handling
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage File
|
||||
*/
|
||||
class Msd_File_Dump extends Msd_File
|
||||
{
|
||||
/**
|
||||
* Get statusline information from backup file
|
||||
*
|
||||
* @param string $filename Name of file to read
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
public static function getStatusline($filename)
|
||||
{
|
||||
$config = Msd_Configuration::getInstance();
|
||||
$path = $config->get('paths.backup'). DS;
|
||||
if (strtolower(substr($filename, -3)) == '.gz') {
|
||||
$fileHandle = gzopen($path . $filename, "r");
|
||||
if ($fileHandle === false) {
|
||||
throw new Exception('Can\'t open file '.$filename);
|
||||
}
|
||||
$statusline = gzgets($fileHandle, 40960);
|
||||
gzclose($fileHandle);
|
||||
} else {
|
||||
$fileHandle=fopen($path . $filename, "r");
|
||||
if ($fileHandle === false) {
|
||||
throw new Exception('Can\'t open file '.$filename);
|
||||
}
|
||||
$statusline = fgets($fileHandle, 5000);
|
||||
fclose($fileHandle);
|
||||
}
|
||||
return self::_explodeStatusline($statusline);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get information from stausline string
|
||||
*
|
||||
* @param string $line
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _explodeStatusline($line)
|
||||
{
|
||||
/*Construction of statusline (first line in backup file):
|
||||
-- Status : NrOfTables : nrOfRecords : Multipart : DatabaseName :
|
||||
script : scriptversion : Comment : MySQLVersion :
|
||||
Backupflags (unused): SQLBefore : SQLAfter : Charset : EXTINFO
|
||||
*/
|
||||
$statusline = array();
|
||||
$compare = substr($line, 0, 8);
|
||||
if ( $compare != '# Status' && $compare != '-- Statu') {
|
||||
// not a backup of MySQLDumper
|
||||
return self::_getDefaultStatusline();
|
||||
} else {
|
||||
// extract informationen
|
||||
$flag = explode(':', $line);
|
||||
if (count($flag)<12) {
|
||||
// fill missing elements for backwards compatibility
|
||||
array_pop($flag);
|
||||
for ($i = count($flag) - 1; $i < 12; $i++) {
|
||||
$flag[]='';
|
||||
}
|
||||
}
|
||||
$statusline['tables'] = $flag[1];
|
||||
$statusline['records'] = $flag[2];
|
||||
if ($flag[3] == '' || $flag[3] == 'MP_0') {
|
||||
$statusline['part']= 'MP_0';
|
||||
} else {
|
||||
$statusline['part'] = $flag[3];
|
||||
}
|
||||
$statusline['dbname'] = $flag[4];
|
||||
$statusline['script'] = $flag[5];
|
||||
$statusline['scriptversion'] = $flag[6];
|
||||
$statusline['comment'] = $flag[7];
|
||||
$statusline['mysqlversion'] = $flag[8];
|
||||
$statusline['flags'] = $flag[9];
|
||||
$statusline['sqlbefore'] = $flag[10];
|
||||
$statusline['sqlafter'] = $flag[11];
|
||||
if ( isset($flag[12]) && trim($flag[12])!='EXTINFO') {
|
||||
$statusline['charset']=$flag[12];
|
||||
} else {
|
||||
$statusline['charset']='?';
|
||||
}
|
||||
}
|
||||
return $statusline;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default statusline
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _getDefaultStatusline()
|
||||
{
|
||||
$statusline['tables'] = -1;
|
||||
$statusline['records'] = -1;
|
||||
$statusline['part'] = 'MP_0';
|
||||
$statusline['dbname'] = 'unknown';
|
||||
$statusline['script'] = '';
|
||||
$statusline['scriptversion'] = '';
|
||||
$statusline['comment'] = '';
|
||||
$statusline['mysqlversion'] = 'unknown';
|
||||
$statusline['flags'] = '2222222';
|
||||
$statusline['sqlbefore'] = '';
|
||||
$statusline['sqlafter'] = '';
|
||||
$statusline['charset'] = '?';
|
||||
return $statusline;
|
||||
}
|
||||
|
||||
}
|
||||
116
library/Msd/Form/Decorator/Abstract.php
Normale Datei
116
library/Msd/Form/Decorator/Abstract.php
Normale Datei
|
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Abstract decorator for form elements of Msd_Form
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
abstract class Msd_Form_Decorator_Abstract extends Zend_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Build and translate the label of an element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildLabel()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$label = $element->getLabel();
|
||||
if (empty($label)) {
|
||||
return '';
|
||||
}
|
||||
$translator = $element->getTranslator();
|
||||
if ($translator !== null) {
|
||||
$label = $translator->translate($label);
|
||||
}
|
||||
$attribs = $element->getAttribs();
|
||||
if (!isset($attribs['noColon']) || $attribs['noColon'] != true) {
|
||||
$label .= ':';
|
||||
}
|
||||
return $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the HTML-Code of the element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildInput()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$helper = $element->helper;
|
||||
$value = $element->getValue();
|
||||
$translator = $element->getTranslator();
|
||||
if ($translator !== null) {
|
||||
$value = $translator->translate($value);
|
||||
}
|
||||
$ret = $element->getView()->$helper(
|
||||
$element->getName(),
|
||||
$value,
|
||||
$this->_getCleanAttribs(),
|
||||
$element->options
|
||||
);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the error message, if there is any.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildErrors()
|
||||
{
|
||||
$lang = Msd_Language::getInstance();
|
||||
$element = $this->getElement();
|
||||
$messages = $element->getMessages();
|
||||
if (empty($messages)) {
|
||||
return '';
|
||||
}
|
||||
$html = '<ul>';
|
||||
foreach (array_keys($messages) as $messageId) {
|
||||
$html .= '<li>' . $lang->translateZendId($messageId) . '</li>';
|
||||
}
|
||||
$html .= '<ul>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the description.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildDescription()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$desc = $element->getDescription();
|
||||
return $desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up attributes we don't want to appear in Html code.
|
||||
*
|
||||
* @return array Array with allowed attributes
|
||||
*/
|
||||
private function _getCleanAttribs()
|
||||
{
|
||||
$attribsToRemove = array(
|
||||
'noColon', 'helper', 'secondLabel' , 'rowclass'
|
||||
);
|
||||
$attribsOfElement = $this->getElement()->getAttribs();
|
||||
foreach ($attribsToRemove as $attrib) {
|
||||
if (isset($attribsOfElement[$attrib])) {
|
||||
unset($attribsOfElement[$attrib]);
|
||||
}
|
||||
}
|
||||
return $attribsOfElement;
|
||||
}
|
||||
}
|
||||
48
library/Msd/Form/Decorator/ConfigForm.php
Normale Datei
48
library/Msd/Form/Decorator/ConfigForm.php
Normale Datei
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Decorator for main ConfigForm.
|
||||
*
|
||||
* Fetches all sub forms, renders all sub elements and returns
|
||||
* the complete form.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_ConfigForm extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Render the form
|
||||
*
|
||||
* @param string $content HTML content rendered so far
|
||||
*
|
||||
* @return string HTML content after decorating the complete form
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$form = '';
|
||||
if (!empty($content)) {
|
||||
$form .= $content;
|
||||
} else {
|
||||
$subForms = $element->getSubForms();
|
||||
foreach (array_keys($subForms) as $subFormKey) {
|
||||
$form .= (string) $subForms[$subFormKey];
|
||||
}
|
||||
$subElements = $element->getElements();
|
||||
foreach (array_keys($subElements) as $subElementKey) {
|
||||
$form .= (string) $subElements[$subElementKey];
|
||||
}
|
||||
}
|
||||
return $form;
|
||||
}
|
||||
}
|
||||
65
library/Msd/Form/Decorator/Default.php
Normale Datei
65
library/Msd/Form/Decorator/Default.php
Normale Datei
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default decorator for form elements
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_Default extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Render the element.
|
||||
*
|
||||
* @param string $content HTML content so far
|
||||
*
|
||||
* @return string HTML content after decorating
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$element = $this->getElement();
|
||||
if (! $element instanceof Zend_Form_Element) {
|
||||
return $content;
|
||||
}
|
||||
if (null === $element->getView()) {
|
||||
return $content;
|
||||
}
|
||||
$label = $this->buildLabel();
|
||||
$input = $this->buildInput();
|
||||
$errors = strip_tags($this->buildErrors());
|
||||
$desc = $this->buildDescription();
|
||||
$descOutput = '';
|
||||
if ($desc != '') {
|
||||
$descOutput = sprintf('<span class="description">%s</span>', $desc);
|
||||
}
|
||||
$attribs = $element->getAttribs();
|
||||
$output = '<tr>';
|
||||
$rowclass = '';
|
||||
if (isset($attribs['rowclass'])) {
|
||||
$rowclass = $attribs['rowclass'];
|
||||
$output = '<tr class="' . $rowclass . '">';
|
||||
}
|
||||
$output .= ' <td>%s</td>
|
||||
<td>%s '. $descOutput . '</td>
|
||||
</tr>';
|
||||
$output = sprintf($output, $label, $input);
|
||||
$separator = $this->getSeparator();
|
||||
$placement = $this->getPlacement();
|
||||
switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $output . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
66
library/Msd/Form/Decorator/DisplayGroup.php
Normale Datei
66
library/Msd/Form/Decorator/DisplayGroup.php
Normale Datei
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Decorator for display groups
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_DisplayGroup extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Decorator for display groups.
|
||||
*
|
||||
* Walks through all sub elements and decorates them.
|
||||
*
|
||||
* @param string $content HTML content so far
|
||||
*
|
||||
* @return string HTML content after decorating all sub elements
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$legend = $element->getLegend();
|
||||
$translator = $element->getTranslator();
|
||||
$attributes = $element->getAttribs();
|
||||
if ($translator !== null) {
|
||||
$legend = $translator->translate($legend);
|
||||
}
|
||||
$sElements = '<fieldset';
|
||||
if (isset($attributes['class'])) {
|
||||
$sElements .= ' class="' . $attributes['class'] . '"';
|
||||
}
|
||||
if (isset($attributes['id'])) {
|
||||
$sElements .= ' id="' . $attributes['id'] . '"';
|
||||
}
|
||||
if (isset($attributes['style'])) {
|
||||
$sElements .= ' style="' . $attributes['style'] . '"';
|
||||
}
|
||||
$sElements .= '>';
|
||||
$sElements .= '<legend>' . $legend . '</legend>';
|
||||
$sElements .= '<table summary="">';
|
||||
$formElements = $element->getElements();
|
||||
foreach (array_keys($formElements) as $formElementKey) {
|
||||
$sElements .= (string) $formElements[$formElementKey];
|
||||
}
|
||||
$sElements .= '</table></fieldset>';
|
||||
|
||||
$placement = $this->getPlacement();
|
||||
$separator = $this->getSeparator();
|
||||
switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $sElements . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $sElements;
|
||||
}
|
||||
}
|
||||
}
|
||||
95
library/Msd/Form/Decorator/DoubleLabel.php
Normale Datei
95
library/Msd/Form/Decorator/DoubleLabel.php
Normale Datei
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Decorator for an element with two labels
|
||||
*
|
||||
* (label -> text input -> second label (unit)) or
|
||||
* (Label -> select box -> second label (unit)
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_DoubleLabel extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Build the second label.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function buildSecondLabel()
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$label = $element->getAttrib('secondLabel');
|
||||
if (empty($label)) {
|
||||
return '';
|
||||
}
|
||||
$translator = $element->getTranslator();
|
||||
if ($translator !== null) {
|
||||
$label = $translator->translate($label);
|
||||
}
|
||||
if ($element->isRequired()) {
|
||||
$label .= '*';
|
||||
}
|
||||
$label .= '';
|
||||
return '<label for="' . $element->getId() . '">' . $label . '</label>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the form element.
|
||||
*
|
||||
* @param string $content HTML content so far
|
||||
*
|
||||
* @return string HTML content after decorating
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$element = $this->getElement();
|
||||
if (! $element instanceof Zend_Form_Element) {
|
||||
return $content;
|
||||
}
|
||||
if (null === $element->getView()) {
|
||||
return $content;
|
||||
}
|
||||
$separator = $this->getSeparator();
|
||||
$placement = $this->getPlacement();
|
||||
$label = $this->buildLabel();
|
||||
$secondLabel = $this->buildSecondLabel();
|
||||
$input = $this->buildInput();
|
||||
|
||||
$errorOutput = '';
|
||||
/*
|
||||
// error output is handled by validators
|
||||
$errors = $this->buildErrors();
|
||||
if ($errors != '') {
|
||||
$errorOutput = sprintf('<span class="error">%s</span>', $errors);
|
||||
}
|
||||
*/
|
||||
|
||||
$descOutput = '';
|
||||
$desc = $this->buildDescription();
|
||||
if ($desc != '') {
|
||||
$descOutput = sprintf('<span class="description">%s</span>', $desc);
|
||||
}
|
||||
|
||||
$output = ' <tr>
|
||||
<td>%s</td>
|
||||
<td>%s %s' . $errorOutput . $descOutput .'</td>
|
||||
</tr>';
|
||||
$output = sprintf($output, $label, $input, $secondLabel);
|
||||
switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $output . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
43
library/Msd/Form/Decorator/LineEnd.php
Normale Datei
43
library/Msd/Form/Decorator/LineEnd.php
Normale Datei
|
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Decorator for an element at the end of a table row
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_LineEnd extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Render Element
|
||||
*
|
||||
* @param string $content HTML content so far
|
||||
*
|
||||
* @return string HTML content after decorating
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$label = $this->buildLabel();
|
||||
if ($label != '' ) {
|
||||
$label = ' ' . $label;
|
||||
}
|
||||
$output = $label . $this->buildInput() . '</td></tr>';
|
||||
$separator = $this->getSeparator();
|
||||
$placement = $this->getPlacement();
|
||||
switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $output . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
44
library/Msd/Form/Decorator/LineMiddle.php
Normale Datei
44
library/Msd/Form/Decorator/LineMiddle.php
Normale Datei
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Decorator for table data between start and end of a table row
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_LineMiddle extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Render element
|
||||
*
|
||||
* @param string $content HTML content so far
|
||||
*
|
||||
* @return string HTML content after decorating
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$label = $this->buildLabel();
|
||||
if ($label != '' ) {
|
||||
$label = ' ' . $label;
|
||||
}
|
||||
$output = $label . $this->buildInput() . ' ';
|
||||
$separator = $this->getSeparator();
|
||||
$placement = $this->getPlacement();
|
||||
switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $output . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
48
library/Msd/Form/Decorator/LineStart.php
Normale Datei
48
library/Msd/Form/Decorator/LineStart.php
Normale Datei
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Decorator for the beginning of a table row
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_LineStart extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Render the element.
|
||||
*
|
||||
* @param string $content HTML content so far
|
||||
*
|
||||
* @return string HTML content after decorating
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$element = $this->getElement();
|
||||
if (! $element instanceof Zend_Form_Element) {
|
||||
return $content;
|
||||
}
|
||||
if (null === $element->getView()) {
|
||||
return $content;
|
||||
}
|
||||
$separator = $this->getSeparator();
|
||||
$placement = $this->getPlacement();
|
||||
$label = $this->buildLabel();
|
||||
$input = $this->buildInput();
|
||||
$output = '<tr><td>' . $label . '</td>' . '<td>' . $input;
|
||||
switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $output . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $output;
|
||||
}
|
||||
}
|
||||
}
|
||||
55
library/Msd/Form/Decorator/SubForm.php
Normale Datei
55
library/Msd/Form/Decorator/SubForm.php
Normale Datei
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Decorator for a complete sub form
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Form_Decorator
|
||||
*/
|
||||
class Msd_Form_Decorator_SubForm extends Msd_Form_Decorator_Abstract
|
||||
{
|
||||
/**
|
||||
* Render content
|
||||
*
|
||||
* @param string $content The HTML content rendered so far
|
||||
*
|
||||
* @return string The HTML content after decorating
|
||||
*/
|
||||
public function render($content)
|
||||
{
|
||||
$element = $this->getElement();
|
||||
$htmlOutput = '<div id="tab_' . $element->getId() . '">';
|
||||
$headElement = $element->getElement('headElement');
|
||||
if ($headElement !== null) {
|
||||
$htmlOutput .='<table summary="">';
|
||||
$htmlOutput .= (string) $headElement;
|
||||
$htmlOutput .= '</table>' . "\n";
|
||||
$htmlOutput .= '<br/><br/>' . "\n";
|
||||
}
|
||||
$displayGroups = $element->getDisplayGroups();
|
||||
foreach (array_keys($displayGroups) as $displayGroupKey) {
|
||||
$htmlOutput .= (string) $displayGroups[$displayGroupKey];
|
||||
}
|
||||
$htmlOutput .= '</div>';
|
||||
|
||||
$separator = $this->getSeparator();
|
||||
$placement = $this->getPlacement();
|
||||
switch ($placement) {
|
||||
case (self::PREPEND):
|
||||
return $htmlOutput . $separator . $content;
|
||||
case (self::APPEND):
|
||||
default:
|
||||
return $content . $separator . $htmlOutput;
|
||||
}
|
||||
|
||||
return $htmlOutput;
|
||||
}
|
||||
}
|
||||
93
library/Msd/Html.php
Normale Datei
93
library/Msd/Html.php
Normale Datei
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Html
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* HTML-Helper Class
|
||||
*
|
||||
* Class has some static methods for building HTML-output
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Html
|
||||
*/
|
||||
class Msd_Html
|
||||
{
|
||||
/**
|
||||
* Escape quotes and/or slashes and double quotes.
|
||||
*
|
||||
* Used for escaping strings in JS-alerts and config-files.
|
||||
*
|
||||
* @param string $string String to escape
|
||||
* @param boolean $escapeSlashes Escape slashes and double quotes
|
||||
*
|
||||
* @return string Escaped string
|
||||
*/
|
||||
public static function getJsQuote($string, $escapeSlashes = false)
|
||||
{
|
||||
if ($escapeSlashes) {
|
||||
$string = str_replace('/', '\/', $string);
|
||||
$string = str_replace('"', '\"', $string);
|
||||
}
|
||||
$string = str_replace("\n", '\n', $string);
|
||||
return str_replace("'", '\\\'', $string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract group prefixes from key names of array
|
||||
*
|
||||
* Returns a new array containing the different prefixes. Used for building
|
||||
* filter select boxes (e.g. sqlserver/show.variables).
|
||||
*
|
||||
* @param array $array Array to scan for prefixes
|
||||
* @param boolean $addNoneOption Whether to add a first entry '---'
|
||||
*
|
||||
* @return $prefix_array array The array conatining the unique prefixes
|
||||
*/
|
||||
public static function getPrefixArray($array, $addNoneOption = true)
|
||||
{
|
||||
$prefixes = array();
|
||||
$keys = array_keys($array);
|
||||
foreach ($keys as $k) {
|
||||
$pos = strpos($k, '_'); // find '_'
|
||||
if ($pos !== false) {
|
||||
$prefix = substr($k, 0, $pos);
|
||||
if (!in_array($prefix, $prefixes)) {
|
||||
$prefixes[$prefix] = $prefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
ksort($prefixes);
|
||||
return $prefixes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build Html option string from array
|
||||
*
|
||||
* @param array $array Array['name'] = $val
|
||||
* @param string $selected Selected key
|
||||
* @param boolean $selectAll Show option to select all
|
||||
*
|
||||
* @return string Html option string
|
||||
*/
|
||||
public static function getHtmlOptions($array, $selected, $selectAll = true)
|
||||
{
|
||||
$options = '';
|
||||
if ($selectAll) {
|
||||
$options = '<option value="">---</option>'."\n";
|
||||
}
|
||||
foreach ($array as $key => $val) {
|
||||
$options .='<option value="' . $key . '"';
|
||||
if ($key === $selected) {
|
||||
$options .=' selected="selected"';
|
||||
}
|
||||
$options .='>' . $val .'</option>'."\n";
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
}
|
||||
192
library/Msd/Ini.php
Normale Datei
192
library/Msd/Ini.php
Normale Datei
|
|
@ -0,0 +1,192 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Ini
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Class to handle ini-files
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Ini
|
||||
*/
|
||||
class Msd_Ini
|
||||
{
|
||||
/**
|
||||
* Data of loaded INI file.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_iniData = null;
|
||||
|
||||
/**
|
||||
* Filename of current INI file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_iniFilename = null;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array|string $options Configuration or filename of INI to load
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (is_string($options)) {
|
||||
$options = array(
|
||||
'filename' => $options,
|
||||
);
|
||||
} elseif (!is_array($options)) {
|
||||
$options = (array) $options;
|
||||
}
|
||||
|
||||
if (isset($options['filename'])) {
|
||||
$this->_iniFilename = (string) $options['filename'];
|
||||
}
|
||||
if ($this->_iniFilename !== null) {
|
||||
$this->loadFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an INI file.
|
||||
*
|
||||
* @param string $filename Name of file to load
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadFile($filename = null)
|
||||
{
|
||||
if ($filename === null) {
|
||||
$filename = $this->_iniFilename;
|
||||
}
|
||||
|
||||
if (realpath($filename) === false) {
|
||||
throw new Msd_Exception(
|
||||
"INI file " . $filename . "doesn't exists."
|
||||
);
|
||||
}
|
||||
$zfConfig = new Zend_Config_Ini(realpath($filename));
|
||||
$this->_iniData = $zfConfig->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save to INI file.
|
||||
*
|
||||
* @param string $filename Name of file to save
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function save($filename = null)
|
||||
{
|
||||
if ($filename === null) {
|
||||
$filename = $this->_iniFilename;
|
||||
}
|
||||
if ($filename === null) {
|
||||
throw new Msd_Exception(
|
||||
'You must specify a filename to save the INI!'
|
||||
);
|
||||
}
|
||||
$fileHandle = fopen($filename, 'w+');
|
||||
fwrite($fileHandle, (string) $this);
|
||||
fclose($fileHandle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts an array into the INI file format.
|
||||
*
|
||||
* @param array $array Array to convert.
|
||||
* @param integer $level Current depthlevel in the array.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _arrayToIniString($array = null, $level = -1)
|
||||
{
|
||||
if ($array === null) {
|
||||
$array = $this->_iniData;
|
||||
}
|
||||
$level++;
|
||||
$resultString = '';
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$resultString .= ($level == 0) ?
|
||||
'[' . $key . ']' . "\n" :
|
||||
$key . '.';
|
||||
$resultString .= $this->_arrayToIniString($value);
|
||||
} else {
|
||||
$newValue = str_replace(
|
||||
array('\\', '"'),
|
||||
array('\\\\', '\\"'),
|
||||
$value
|
||||
);
|
||||
$resultString .= $key . ' = "' . (string) $newValue . '"';
|
||||
}
|
||||
$resultString .= "\n";
|
||||
}
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a variable from the data.
|
||||
*
|
||||
* @param string $key Name of variable
|
||||
* @param string $section Name of section
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $section = null)
|
||||
{
|
||||
if ($section === null) {
|
||||
return $this->_iniData[$key];
|
||||
} else {
|
||||
return $this->_iniData[$section][$key];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a variable
|
||||
*
|
||||
* @param string $key Name of variable
|
||||
* @param mixed $value Value of variable
|
||||
* @param string $section Section of variable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set($key, $value, $section = null)
|
||||
{
|
||||
if ($section === null) {
|
||||
$this->_iniData[$key] = $value;
|
||||
} else {
|
||||
$this->_iniData[$section][$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the complete INI.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAll()
|
||||
{
|
||||
return $this->_iniData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this class into a string.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->_arrayToIniString();
|
||||
}
|
||||
}
|
||||
185
library/Msd/Language.php
Normale Datei
185
library/Msd/Language.php
Normale Datei
|
|
@ -0,0 +1,185 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Language
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Language class implemented as singleton
|
||||
*
|
||||
* Handles translation of language variables.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Language
|
||||
*/
|
||||
class Msd_Language
|
||||
{
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @var Msd_Configuration
|
||||
*/
|
||||
private static $_instance = NULL;
|
||||
|
||||
/**
|
||||
* Translator
|
||||
*
|
||||
* @var Zend_Translate
|
||||
*/
|
||||
private $_translate = NULL;
|
||||
|
||||
/**
|
||||
* Base directory for language files
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_baseLanguageDir = null;
|
||||
|
||||
/**
|
||||
* Constructor gets the configuration params
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function __construct ()
|
||||
{
|
||||
$config = Msd_Configuration::getInstance();
|
||||
$language = $config->get('config.interface.language');
|
||||
$this->loadLanguage($language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load new language.
|
||||
*
|
||||
* @param string $language New language
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function loadLanguage($language)
|
||||
{
|
||||
$this->_baseLanguageDir = APPLICATION_PATH . DS . 'language' . DS;
|
||||
$file = $this->_baseLanguageDir . $language . DS . 'lang.php';
|
||||
$translator = $this->getTranslator();
|
||||
if ($translator === null) {
|
||||
$translator = new Zend_Translate('array', $file, $language);
|
||||
} else {
|
||||
$translator->setAdapter(
|
||||
array(
|
||||
'adapter' => 'array',
|
||||
'content' => $file,
|
||||
'locale' => $language
|
||||
)
|
||||
);
|
||||
}
|
||||
$this->setTranslator($translator);
|
||||
Zend_Registry::set('Zend_Translate', $translator);
|
||||
}
|
||||
/**
|
||||
* No cloning for singleton
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __clone()
|
||||
{
|
||||
throw new Msd_Exception('Cloning of Msd_Language is not allowed!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic getter to keep syntax in rest of script short
|
||||
*
|
||||
* @param mixed $var
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get ($property)
|
||||
{
|
||||
$translated = $this->getTranslator()->_($property);
|
||||
if ($translated == $property && substr($property, 0, 2) == 'L_') {
|
||||
// no translation found -> remove prefix L_
|
||||
return substr($property, 2);
|
||||
}
|
||||
return $translated;
|
||||
}
|
||||
/**
|
||||
* Returns the single instance
|
||||
*
|
||||
* @return Msd_Language
|
||||
*/
|
||||
public static function getInstance ()
|
||||
{
|
||||
if (NULL == self::$_instance) {
|
||||
self::$_instance = new self;
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate a Message from Zend_Validate.
|
||||
*
|
||||
* @param string $zendMessageId Message ID from Zend_Validate
|
||||
* @param string $messageText Pre-translatet message
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function translateZendId($zendMessageId, $messageText = '')
|
||||
{
|
||||
if (substr($zendMessageId, 0, 6) =='access' && $messageText > '') {
|
||||
// message is already translated by validator access
|
||||
return $messageText;
|
||||
}
|
||||
return $this->_translate->_(
|
||||
$this->_transformMessageId($zendMessageId)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a message ID in Zend_Validate format into Msd_Language format.
|
||||
*
|
||||
* @param string $zendMessageId Message ID from Zend_Validate
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _transformMessageId($zendMessageId)
|
||||
{
|
||||
$result = preg_replace('/([A-Z])/', '_${1}', $zendMessageId);
|
||||
$result = strtoupper($result);
|
||||
return 'L_ZEND_ID_' . $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Translator
|
||||
*
|
||||
* @return Zend_Translate
|
||||
*/
|
||||
public function getTranslator()
|
||||
{
|
||||
return $this->_translate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Translator
|
||||
*
|
||||
* @param Zend_Translate $translate
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setTranslator(Zend_Translate $translate)
|
||||
{
|
||||
$this->_translate = $translate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of available languages.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableLanguages()
|
||||
{
|
||||
$lang = array();
|
||||
include $this->_baseLanguageDir . 'lang_list.php';
|
||||
return $lang;
|
||||
}
|
||||
}
|
||||
205
library/Msd/Log.php
Normale Datei
205
library/Msd/Log.php
Normale Datei
|
|
@ -0,0 +1,205 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Log
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Log Class
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Log
|
||||
*/
|
||||
class Msd_Log
|
||||
{
|
||||
// Define constants
|
||||
const PHP = 'PHP-Log';
|
||||
const PERL = 'PERL-Log';
|
||||
const PERL_COMPLETE = 'PERL-Complete-Log';
|
||||
const ERROR = 'Error-Log';
|
||||
|
||||
// Define static Instance
|
||||
private static $_instance = NULL;
|
||||
private $_paths = NULL;
|
||||
|
||||
/**
|
||||
* Init file handles
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// define instance handler
|
||||
$this->handle = array();
|
||||
$this->handle[self::PHP] = false;
|
||||
$this->handle[self::PERL] = false;
|
||||
$this->handle[self::PERL_COMPLETE] = false;
|
||||
$this->handle[self::ERROR] = false;
|
||||
|
||||
// get config
|
||||
$config = Msd_Configuration::getInstance();
|
||||
$this->_paths = (object)$config->get('paths');
|
||||
}
|
||||
|
||||
/**
|
||||
* Close all open file handles on destruct
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
if ($this->handle[self::PHP]) {
|
||||
$this->_close(self::PHP);
|
||||
}
|
||||
if (is_resource($this->handle[self::PERL])) {
|
||||
$this->_close(self::PERL);
|
||||
}
|
||||
if (is_resource($this->handle[self::PERL_COMPLETE])) {
|
||||
$this->_close(self::PERL_COMPLETE);
|
||||
}
|
||||
if (is_resource($this->handle[self::ERROR])) {
|
||||
$this->_close(self::ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Close a filehandle
|
||||
*
|
||||
* @param Loge $file The file to close
|
||||
*/
|
||||
private function _close($file)
|
||||
{
|
||||
$filename = $this->getFile($file);
|
||||
$extension = pathinfo($filename, PATHINFO_EXTENSION);
|
||||
if ($extension == 'gz') {
|
||||
gzclose($this->handle[$file]);
|
||||
} else {
|
||||
fclose($this->handle[$file]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of Msd_Log
|
||||
*
|
||||
* @return Msd_Log
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (self::$_instance === NULL) {
|
||||
self::$_instance = new self;
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of Msd_Log for a special type
|
||||
*
|
||||
* Allowed types are self::PHP, self::PERL, self::PERL_COMPLETE or
|
||||
* self::ERROR
|
||||
*
|
||||
* @param Msd_Log $type
|
||||
*
|
||||
* @return Msd_Log
|
||||
*/
|
||||
public function getLogInstance($type)
|
||||
{
|
||||
if (!isset($this->_logInstance[$type])) {
|
||||
$writer = new Zend_Log_Writer_Stream($this->getFile($type));
|
||||
$formatter =
|
||||
new Zend_Log_Formatter_Simple("%timestamp% %message%\n");
|
||||
$writer->setFormatter($formatter);
|
||||
$this->_logInstance[$type] = new Zend_Log($writer);
|
||||
}
|
||||
return $this->_logInstance[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Write to log file
|
||||
*
|
||||
* @param string $type The type of log file to write to
|
||||
* @param string $message The message to add to the file
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function write($type, $message)
|
||||
{
|
||||
// @todo if log_maxsize reached => archive/delete log
|
||||
$logger = self::getInstance();
|
||||
$log = $logger->getLogInstance($type);
|
||||
return $log->info($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the concrete filename with path for the given type.
|
||||
*
|
||||
* @param const $file
|
||||
*
|
||||
* @return string Filename of logfile
|
||||
*/
|
||||
public function getFile($file)
|
||||
{
|
||||
$filename = '';
|
||||
switch ($file) {
|
||||
case self::PHP:
|
||||
$filename = $this->_paths->log . DS . 'php.log';
|
||||
break;
|
||||
case self::PERL:
|
||||
$filename = $this->_paths->log . DS . 'perl.log';
|
||||
break;
|
||||
case self::PERL_COMPLETE:
|
||||
$filename = $this->_paths->log . DS . 'perlComplete.log';
|
||||
break;
|
||||
case self::ERROR:
|
||||
$filename = $this->_paths->log . DS . 'phpError.log';
|
||||
}
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a log file and recreate it.
|
||||
*
|
||||
* @param string $file Filename
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function delete($type)
|
||||
{
|
||||
$filename = self::getFile($type);
|
||||
@unlink($filename);
|
||||
// re-create log file
|
||||
$translator = Msd_Language::getInstance()->getTranslator();
|
||||
$this->write($type, $translator->_('L_LOG_CREATED'));
|
||||
}
|
||||
/**
|
||||
* Read a logfile and return content as array.
|
||||
*
|
||||
* If $revers is set to true the ordering of lines is reversed.
|
||||
*
|
||||
* @param parent::const $type The type of logfile to read
|
||||
* @param boolean $reverse Wether to place latest entries first
|
||||
*
|
||||
* @return array Log data from file as array
|
||||
*/
|
||||
public function read($type = self::PHP, $reverse = false)
|
||||
{
|
||||
$filename = $this->getFile($type);
|
||||
if (!is_readable($filename)) {
|
||||
$timestamp = Zend_Date::ISO_8601;
|
||||
$lang = Msd_Language::getInstance()->getTranslator();
|
||||
$msg = $timestamp . ' <span class="error">' .
|
||||
sprintf($lang->_('L_LOG_NOT_READABLE'), $filename) . '</span>';
|
||||
return array($msg);
|
||||
} else {
|
||||
$output = file($filename);
|
||||
}
|
||||
if ($reverse == 1) {
|
||||
$output = array_reverse($output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
48
library/Msd/Log/Reader.php
Normale Datei
48
library/Msd/Log/Reader.php
Normale Datei
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Log
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Reader Class
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Log
|
||||
*/
|
||||
class Msd_Log_Reader extends Msd_Log
|
||||
{
|
||||
/**
|
||||
* Read a logfile and return content as array.
|
||||
*
|
||||
* If $revers is set to true the ordering of lines is reversed.
|
||||
*
|
||||
* @param parent::const $type The type of logfile to read
|
||||
* @param boolean $reverse Wether to place latest entries first
|
||||
*
|
||||
* @return array Log data from file as array
|
||||
*/
|
||||
public function read ($type = parent::PHP, $reverse = false)
|
||||
{
|
||||
$filename = parent::getFile($type);
|
||||
|
||||
if (!is_readable($filename)) {
|
||||
$timestamp = Zend_Date::ISO_8601;
|
||||
$lang = Msd_Language::getInstance()->getTranslator();
|
||||
$msg = $timestamp . ' <span class="error">' .
|
||||
sprintf($lang->_('L_LOG_NOT_READABLE'), $filename) . '</span>';
|
||||
return array($msg);
|
||||
} else {
|
||||
$output = file($filename);
|
||||
}
|
||||
if ($reverse == 1) {
|
||||
$output = array_reverse($output);
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
}
|
||||
78
library/Msd/Sqlparser.php
Normale Datei
78
library/Msd/Sqlparser.php
Normale Datei
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Sql
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Sql Parser Class
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Sqlparser
|
||||
*/
|
||||
define('*', 'SQL_TOKEN');
|
||||
class Msd_Sqlparser
|
||||
{
|
||||
/**
|
||||
* @var array Array containing the parsed queries
|
||||
*/
|
||||
private $_queries = array();
|
||||
|
||||
/**
|
||||
* @var string Input text to analyse
|
||||
*/
|
||||
private $_text = '';
|
||||
|
||||
/**
|
||||
* @param string $text Text to be later parsed as sql
|
||||
*/
|
||||
public function __construct($text = '')
|
||||
{
|
||||
$this->addText($text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add text to internal text buffer
|
||||
*
|
||||
* @param string $text The text to add
|
||||
* @return void
|
||||
*/
|
||||
public function addText($text)
|
||||
{
|
||||
$this->_text .= $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse added text as sql und split into queries
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function parse()
|
||||
{
|
||||
//TODO implement parser
|
||||
return $this->_text;
|
||||
$i=1;
|
||||
$tokens = token_get_all('<?php '.$this->_text.'?>');
|
||||
unset($tokens[0]);
|
||||
unset($tokens[count($tokens)]);
|
||||
//unset($tokens[count($tokens)]);
|
||||
//unset($tokens[0]);
|
||||
foreach ($tokens as $token) {
|
||||
if (is_string($token)) {
|
||||
// simple 1-character token
|
||||
echo "<br>$i. $token";
|
||||
} else {
|
||||
// token array
|
||||
list($token, $text) = $token;
|
||||
echo "<br>$i. ". token_name($token)." => "
|
||||
. htmlspecialchars($text);
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
188
library/Msd/TaskManager.php
Normale Datei
188
library/Msd/TaskManager.php
Normale Datei
|
|
@ -0,0 +1,188 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage File
|
||||
* @version SVN: $rev: 1207 $
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Task Manager Class (Singleton)
|
||||
*
|
||||
* Class handles task lists
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage TaskManager
|
||||
*/
|
||||
class Msd_TaskManager
|
||||
{
|
||||
/**
|
||||
* Define task types.
|
||||
* The integer value defines the ordering in wich tasks are executed.
|
||||
* @var int
|
||||
*/
|
||||
const GET_CREATE_TABLE = 100;
|
||||
const BACKUP_TABLE_DATA = 200;
|
||||
const GET_ALTER_TABLE_ADD_KEYS = 300;
|
||||
|
||||
/**
|
||||
* Instance
|
||||
*
|
||||
* @var Msd_Configuration
|
||||
*/
|
||||
private static $_instance = NULL;
|
||||
|
||||
/**
|
||||
* Task Namespace
|
||||
* @var Zend_Session_Namespace
|
||||
*/
|
||||
private $_session;
|
||||
|
||||
private $_tasks = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Get task list from session or init an empty list.
|
||||
*
|
||||
* @param string $taskType Task type to get or create.
|
||||
* Defaults to "backupTasks".
|
||||
* @param boolean Whether to create a new task list and delete all entries
|
||||
* or to get it from the session
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function __construct($taskType, $clear = false)
|
||||
{
|
||||
$this->_session = new Zend_Session_Namespace($taskType, true);
|
||||
if (isset($this->_session->tasks)) {
|
||||
$this->_tasks = $this->_session->tasks;
|
||||
}
|
||||
if ($clear === true) {
|
||||
$this->clearTasks();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the task manager instance
|
||||
*
|
||||
* @param string $configname The name of the configuration file to load.
|
||||
* If not set we will load the config from
|
||||
* session if present.
|
||||
* @param boolean $forceLoading If set the config will be read from file.
|
||||
*
|
||||
* @return Msd_Configuration
|
||||
*/
|
||||
public static function getInstance($taskType = 'backupTasks',
|
||||
$clear = false)
|
||||
{
|
||||
if (null == self::$_instance) {
|
||||
self::$_instance = new self($taskType, $clear);
|
||||
}
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a task
|
||||
*
|
||||
* @param string $type Type of tasks
|
||||
* @param array $options Option array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function addTask($type, $options = array())
|
||||
{
|
||||
$tasks = $this->_tasks;
|
||||
if (empty($tasks[$type])) {
|
||||
$tasks[$type] = array();
|
||||
}
|
||||
$tasks[$type][] = $options;
|
||||
$this->_tasks = $tasks;
|
||||
$this->_saveTasksToSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tasks of given type
|
||||
*
|
||||
* Returns false if type is not present in task list.
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public function getTasks($type = '')
|
||||
{
|
||||
if ($type > '') {
|
||||
if (!isset($this->_tasks[$type])) {
|
||||
return false;
|
||||
}
|
||||
return $this->_tasks[$type];
|
||||
}
|
||||
return $this->_tasks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset tasks array
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearTasks()
|
||||
{
|
||||
$this->_tasks = array();
|
||||
$this->_saveTasksToSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the first task of the given type
|
||||
*
|
||||
* @param string $type
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeActualTask($type)
|
||||
{
|
||||
$tasks = $this->getTasks($type);
|
||||
print_r($tasks);
|
||||
if ($tasks === false) {
|
||||
return;
|
||||
}
|
||||
if (empty($tasks)) {
|
||||
// no task of that type left - remove type
|
||||
unset($this->_tasks[$type]);
|
||||
}
|
||||
unset($tasks[0]);
|
||||
//rebuild index
|
||||
sort($tasks);
|
||||
$this->_tasks[$type] = $tasks;
|
||||
$this->_saveTasksToSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first task of given type or false if there is none.
|
||||
*
|
||||
* @param $type The type of the task to get.
|
||||
*
|
||||
* @return array|false
|
||||
*/
|
||||
public function getActualTask($type)
|
||||
{
|
||||
$tasks = $this->getTasks($type);
|
||||
if (isset($tasks[0])) {
|
||||
return $tasks[0];
|
||||
};
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save task list to session
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function _saveTasksToSession()
|
||||
{
|
||||
$this->_session->tasks = $this->_tasks;
|
||||
}
|
||||
}
|
||||
194
library/Msd/Update.php
Normale Datei
194
library/Msd/Update.php
Normale Datei
|
|
@ -0,0 +1,194 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Update
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Class handles loading of files from MySQLDumper update server.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Update
|
||||
*/
|
||||
class Msd_Update
|
||||
{
|
||||
/**
|
||||
* Cofiguration for updater
|
||||
*
|
||||
* @var Msd_Ini
|
||||
*/
|
||||
private $_updateConfig = null;
|
||||
|
||||
/**
|
||||
* HTTP-Client for updates and update checks
|
||||
*
|
||||
* @var Zend_Http_Client
|
||||
*/
|
||||
private $_httpClient = null;
|
||||
|
||||
/**
|
||||
* Parameters for GET-Request.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_requestParams = array();
|
||||
|
||||
/**
|
||||
* Parameters for update information.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_updateParams = array();
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $updateConfigFile
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($updateConfigFile)
|
||||
{
|
||||
$this->_updateConfig = new Msd_Ini($updateConfigFile);
|
||||
$updateUrl = $this->_buildUpdateUrl();
|
||||
$this->_httpClient = new Zend_Http_Client($updateUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the update for the specified files.
|
||||
*
|
||||
* @param string $updateSection INI-Section with update information
|
||||
* @param array $fileList List of files to update.
|
||||
*
|
||||
* @return true|array
|
||||
*/
|
||||
public function doUpdate($updateSection, $fileList)
|
||||
{
|
||||
$httpClient = $this->_httpClient;
|
||||
$config = $this->_updateConfig->get($updateSection);
|
||||
$params = $this->getRequestParams();
|
||||
$params += $config['request']['params'];
|
||||
while (false !== (list($paramKey, $paramValue) = each($params))) {
|
||||
$params[$paramKey] = $this->_applyUpdateParams($paramValue);
|
||||
}
|
||||
|
||||
$sourceFileKey = $config['request']['sourceFileKey'];
|
||||
$targetPath = $config['targetBaseDir'] . DS;
|
||||
foreach ($fileList as $sourceFile => $targetFile) {
|
||||
$sourceFilename = $this->_applyUpdateParams($sourceFile);
|
||||
$params[$sourceFileKey] = $sourceFile;
|
||||
$httpClient->setParameterGet($params);
|
||||
try {
|
||||
$response = $httpClient->request('GET');
|
||||
} catch(Zend_Http_Exception $e) {
|
||||
return array(
|
||||
'action' => 'connection',
|
||||
'file' => $targetFile,
|
||||
'server' => $httpClient->getUri()->getHost()
|
||||
);
|
||||
}
|
||||
|
||||
if ($response->getStatus() == 200 && $response->getBody() > '') {
|
||||
$targetFilename = $this->_applyUpdateParams($targetFile);
|
||||
if (substr($response->getBody(), 0, 6) == 'Error:') {
|
||||
return array(
|
||||
'action' => 'saveresponse',
|
||||
'file' => $targetFilename,
|
||||
'status' => $response->getBody(),
|
||||
);
|
||||
}
|
||||
$targetFile = $targetPath . $targetFilename;
|
||||
@mkdir(dirname($targetFile), 0777, true);
|
||||
$fileHandle = @fopen($targetFile, 'w+');
|
||||
if ($fileHandle === false) {
|
||||
@chmod($targetFile, 0777);
|
||||
$fileHandle = @fopen($targetFile, 'w+');
|
||||
}
|
||||
if ($fileHandle === false) {
|
||||
return array(
|
||||
'action' => 'createfile',
|
||||
'file' => $targetFile,
|
||||
'status' => 'HTTP/' . $response->getVersion() . ' ' .
|
||||
$response->getStatus() . ' ' .
|
||||
$response->getMessage(),
|
||||
);
|
||||
}
|
||||
if (@fwrite($fileHandle, $response->getBody()) === false) {
|
||||
return array(
|
||||
'action' => 'createfile',
|
||||
'file' => $targetFile,
|
||||
'status' => 'HTTP/' . $response->getVersion() . ' ' .
|
||||
$response->getStatus() . ' ' .
|
||||
$response->getMessage(),
|
||||
);
|
||||
}
|
||||
fclose($fileHandle);
|
||||
} else {
|
||||
return array(
|
||||
'action' => 'getrequest',
|
||||
'file' => $sourceFilename,
|
||||
'status' => 'HTTP/' . $response->getVersion() . ' ' .
|
||||
$response->getStatus() . ' ' . $response->getMessage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the URL for the GET-Requests.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _buildUpdateUrl()
|
||||
{
|
||||
$updateConfig = $this->_updateConfig->get('update');
|
||||
$updateUrl = $updateConfig['protocol'] . '://'
|
||||
. $updateConfig['host'] . $updateConfig['path']
|
||||
. $updateConfig['file'];
|
||||
$updateUrl = $this->_applyUpdateParams($updateUrl);
|
||||
return $updateUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the parameters for the GET-Request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getRequestParams()
|
||||
{
|
||||
return $this->_requestParams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an update information parameter.
|
||||
*
|
||||
* @param string $param Name of the parameter to set
|
||||
* @param string $value Value of the parameter to set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUpdateParam($param, $value)
|
||||
{
|
||||
$this->_updateParams[$param] = (string) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the update information parameters to the given string.
|
||||
*
|
||||
* @param string $string String to apply the update information parameters
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function _applyUpdateParams($string)
|
||||
{
|
||||
foreach ($this->_updateParams as $key => $value) {
|
||||
$string = str_replace(':' . $key, $value, $string);
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
252
library/Msd/User.php
Normale Datei
252
library/Msd/User.php
Normale Datei
|
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Users
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Class for user login and logout actions.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Users
|
||||
*/
|
||||
class Msd_User
|
||||
{
|
||||
/**
|
||||
* The executed process was successfully completed.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const SUCCESS = 0x00;
|
||||
|
||||
/**
|
||||
* There is no file with user identities and credentials.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const NO_USER_FILE = 0x01;
|
||||
|
||||
/**
|
||||
* The user file doesn't contain any valid user logins.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const NO_VALID_USER = 0x02;
|
||||
|
||||
/**
|
||||
* The given identity is unknown or the password is wrong.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const UNKNOWN_IDENTITY = 0x03;
|
||||
|
||||
/**
|
||||
* An unknown error occured.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
const GENERAL_FAILURE = 0xFF;
|
||||
|
||||
/**
|
||||
* Path and filename of the user ini file.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_usersFile;
|
||||
|
||||
/**
|
||||
* Instance to authentication storage.
|
||||
*
|
||||
* @var Zend_Auth_Storage_Session
|
||||
*/
|
||||
private $_authStorage = null;
|
||||
|
||||
/**
|
||||
* Id of currently loggedin user.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
private $_userId = null;
|
||||
|
||||
/**
|
||||
* Name of currently loggedin user.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_userName = null;
|
||||
|
||||
/**
|
||||
* Current login status.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
private $_isLoggedIn = false;
|
||||
|
||||
/**
|
||||
* Messages from Zend_Auth_Result.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $_authMessages = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_usersFile = APPLICATION_PATH . DS . 'configs' . DS
|
||||
. 'users.ini';
|
||||
$this->_authStorage = new Zend_Auth_Storage_Session();
|
||||
$auth = $this->_authStorage->read();
|
||||
if (!empty($auth)) {
|
||||
if (isset($auth['name'])) {
|
||||
$this->_userName = $auth['name'];
|
||||
}
|
||||
if (isset($auth['id'])) {
|
||||
$this->_userId = $auth['id'];
|
||||
}
|
||||
if ($this->_userName !== null && $this->_userId !== null) {
|
||||
$this->_isLoggedIn = true;
|
||||
}
|
||||
} else {
|
||||
$this->_loginByCookie();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the messages which comes from Zend_Auth_Result.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAuthMessages()
|
||||
{
|
||||
return $this->_authMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the loggedin status.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isLoggedIn()
|
||||
{
|
||||
return $this->_isLoggedIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Login the user with the given identity and credentials.
|
||||
* Set cookie if automatic login is wanted.
|
||||
*
|
||||
* Returns true if login was successful, otherwise false.
|
||||
*
|
||||
* @param string $username Identity for login process.
|
||||
* @param string $password Credentials for login procress.
|
||||
* @param boolean $autoLogin Set cookie for automatic login?
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function login($username, $password, $autoLogin = false)
|
||||
{
|
||||
if (!file_exists($this->_usersFile)) {
|
||||
return self::NO_USER_FILE;
|
||||
}
|
||||
|
||||
$usersIni = new Msd_Ini($this->_usersFile);
|
||||
$users = $usersIni->getAll();
|
||||
|
||||
$hasValidUser = false;
|
||||
foreach ($users as $user) {
|
||||
if (isset($user['name']) && isset($user['pass'])) {
|
||||
$hasValidUser = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasValidUser) {
|
||||
return self::NO_VALID_USER;
|
||||
}
|
||||
|
||||
$authAdapter = new Msd_Auth_Adapter_Ini($this->_usersFile);
|
||||
$authAdapter->setUsername($username);
|
||||
$authAdapter->setPassword($password);
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$authResult = $auth->authenticate($authAdapter);
|
||||
$this->_authMessages = $authResult->getMessages();
|
||||
if ($authResult->isValid()) {
|
||||
$this->_isLoggedIn = true;
|
||||
if ($autoLogin) {
|
||||
Zend_Session::regenerateId();
|
||||
$crypt = Msd_Crypt::getInstance('MySQLDumper27112010');
|
||||
$identity = $crypt->encrypt(
|
||||
$username . ':' . $password
|
||||
);
|
||||
if (PHP_SAPI != 'cli') {
|
||||
setcookie(
|
||||
'msd_autologin',
|
||||
$identity . ':' . md5($identity),
|
||||
time() + 365 * 24 * 60 * 60,
|
||||
'/'
|
||||
);
|
||||
}
|
||||
}
|
||||
$this->setDefaultConfiguration();
|
||||
return self::SUCCESS;
|
||||
}
|
||||
return self::UNKNOWN_IDENTITY;
|
||||
}
|
||||
|
||||
private function _loginByCookie()
|
||||
{
|
||||
$request = Zend_Controller_Front::getInstance()->getRequest();
|
||||
$cookie = $request->get('msd_autologin');
|
||||
if ($cookie === null || $cookie == '') {
|
||||
// no cookie found
|
||||
return false;
|
||||
}
|
||||
list($authInfo, $checksum) = explode(':', $cookie);
|
||||
if (md5($authInfo) != $checksum) {
|
||||
// autologin not valid - return
|
||||
return false;
|
||||
}
|
||||
|
||||
$crypt = Msd_Crypt::getInstance('MySQLDumper27112010');
|
||||
list($username, $pass) = explode(':', $crypt->decrypt($authInfo));
|
||||
// Try to login the user and refresh the cookie. Because you want
|
||||
// to stay logged in until you logout.
|
||||
$this->login($username, $pass, true);
|
||||
}
|
||||
/**
|
||||
* Clear the user identity and logout the user.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function logout()
|
||||
{
|
||||
Zend_Auth::getInstance()->clearIdentity();
|
||||
$this->_isLoggedIn = false;
|
||||
$this->setDefaultConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default configuration for user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setDefaultConfiguration()
|
||||
{
|
||||
$configFile = 'defaultConfig';
|
||||
if ($this->_isLoggedIn) {
|
||||
$files = Msd_File::getConfigNames();
|
||||
if (isset($files[0])) {
|
||||
$configFile = $files[0];
|
||||
}
|
||||
}
|
||||
Msd_Configuration::getInstance($configFile, true);
|
||||
}
|
||||
}
|
||||
21
library/Msd/Validate/Exception.php
Normale Datei
21
library/Msd/Validate/Exception.php
Normale Datei
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Exception
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
require_once 'Msd/Exception.php';
|
||||
/**
|
||||
* MySQLDumper Validator Exception
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Exception
|
||||
*/
|
||||
class Msd_Validate_Exception extends Msd_Exception
|
||||
{
|
||||
}
|
||||
246
library/Msd/Validate/File/Accessible.php
Normale Datei
246
library/Msd/Validate/File/Accessible.php
Normale Datei
|
|
@ -0,0 +1,246 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Ini
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Validate/Abstract.php';
|
||||
/**
|
||||
* Class to check the accessibility for files and directories.
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Validate
|
||||
*/
|
||||
class Msd_Validate_File_Accessible extends Zend_Validate_Abstract
|
||||
{
|
||||
/**
|
||||
* @const string Error constant, file/directory doesn't exists.
|
||||
*/
|
||||
const NOT_EXISTS = 'accessNotExists';
|
||||
|
||||
/**
|
||||
* @const string Error constant, file/directory isn't readable.
|
||||
*/
|
||||
const NOT_READABLE = 'accessNotReadable';
|
||||
|
||||
/**
|
||||
* @const string Error constant, file/directory isn't writable.
|
||||
*/
|
||||
const NOT_WRITABLE = 'accessNotWritable';
|
||||
|
||||
/**
|
||||
* @const string Error constant, file/directory isn't executable.
|
||||
*/
|
||||
const NOT_EXECUTABLE = 'accessNotExecutable';
|
||||
|
||||
/**
|
||||
* @const string Error constant, file/directory isn't a directory.
|
||||
*/
|
||||
const NOT_A_DIRECTORY = 'accessNotADirectory';
|
||||
|
||||
/**
|
||||
* @const string Error constant, file/directory isn't file.
|
||||
*/
|
||||
const NOT_A_FILE = 'accessNotAFile';
|
||||
|
||||
/**
|
||||
* @const string Error constant, file/directory isn't link.
|
||||
*/
|
||||
const NOT_A_LINK = 'accessNotALink';
|
||||
|
||||
/**
|
||||
* @const string Error constant, file/directory wasn't uploaded.
|
||||
*/
|
||||
const NOT_UPLOADED = 'accessNotUploaded';
|
||||
|
||||
/**
|
||||
* @var array Error message templates
|
||||
*/
|
||||
protected $_messageTemplates = array();
|
||||
|
||||
/**
|
||||
* @var array Options that determine which access types must checked.
|
||||
*
|
||||
* 'pathPrefix' - Will be prepended to the filename in checking method.
|
||||
* 'accessTypes' - Access variants, that will be checked.
|
||||
*/
|
||||
protected $_options = array(
|
||||
'pathPrefix' => '',
|
||||
'accessTypes' => array(
|
||||
'read' => false,
|
||||
'write' => false,
|
||||
'execute' => false,
|
||||
'dir' => false,
|
||||
'file' => false,
|
||||
'uploaded' => false,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor. creates and initializes an instance of this validator.
|
||||
*
|
||||
* @param array $options Access checking options.
|
||||
* 'pathPrefix' must be a string.
|
||||
* 'accessTypes' could be an array, string or an
|
||||
* instance of Zend_config
|
||||
* @see self::$options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
///get error messages from selected language
|
||||
$lang = Msd_Language::getInstance()->getTranslator();
|
||||
$this->_messageTemplates = array(
|
||||
self::NOT_EXISTS => $lang->_('L_ZEND_ID_ACCESS_NOT_EXISTS'),
|
||||
self::NOT_READABLE => $lang->_('L_ZEND_ID_ACCESS_NOT_READABLE'),
|
||||
self::NOT_WRITABLE => $lang->_('L_ZEND_ID_ACCESS_NOT_WRITABLE'),
|
||||
self::NOT_EXECUTABLE => $lang->_('L_ZEND_ID_ACCESS_NOT_EXECUTABLE'),
|
||||
self::NOT_A_FILE => $lang->_('L_ZEND_ID_ACCESS_NOT_A_FILE'),
|
||||
self::NOT_A_DIRECTORY =>
|
||||
$lang->_('L_ZEND_ID_ACCESS_NOT_A_DIRECTORY'),
|
||||
self::NOT_A_LINK => $lang->_('L_ZEND_ID_ACCESS_NOT_A_LINK'),
|
||||
self::NOT_UPLOADED => $lang->_('L_ZEND_ID_ACCESS_NOT_UPLOADED'),
|
||||
);
|
||||
if ($options !== null) {
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the options for validation.
|
||||
*
|
||||
* @throws Msd_Validate_Exception
|
||||
* @param array $options Options for the validation
|
||||
* @see self::$options
|
||||
* @return void
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
if (!is_array($options)) {
|
||||
include_once 'Msd/Validate/Exception.php';
|
||||
throw new Msd_Validate_Exception(
|
||||
'Options must be an array, string or instance '
|
||||
. 'of Zend_Config!'
|
||||
);
|
||||
}
|
||||
if (isset($options['accessTypes'])) {
|
||||
$accessTypes = array();
|
||||
if (is_array($options['accessTypes'])) {
|
||||
$accessTypes = $options['accessTypes'];
|
||||
} else if (is_string($options['accessTypes'])) {
|
||||
$accessTypes = explode(',', $options['accessTypes']);
|
||||
} else if ($options['accessTypes'] instanceof Zend_Config) {
|
||||
$accessTypes = $options['accessTypes']->toArray();
|
||||
} else {
|
||||
include_once 'Msd/Validate/Exception.php';
|
||||
throw new Msd_Validate_Exception(
|
||||
'Access types must be an array, string or instance '
|
||||
. 'of Zend_Config!'
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($accessTypes as $accessType) {
|
||||
if (isset($this->_options['accessTypes'][$accessType])) {
|
||||
$this->_options['accessTypes'][$accessType] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['pathPrefix'])) {
|
||||
$this->_options['pathPrefix'] = $options['pathPrefix'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current options array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defiend by Zend_Validate_Interface
|
||||
*
|
||||
* Checks the accessibility of a file.
|
||||
*
|
||||
* @param string $fileName Name of the file to be checked.
|
||||
* @return bool
|
||||
*/
|
||||
public function isValid($fileName)
|
||||
{
|
||||
clearstatcache(true, $fileName);
|
||||
$this->_setValue($fileName);
|
||||
$fileName = $this->_options['pathPrefix'] . $fileName;
|
||||
$isValid = true;
|
||||
$accessTypes = $this->_options['accessTypes'];
|
||||
if (!file_exists($fileName)) {
|
||||
$this->_error(self::NOT_EXISTS);
|
||||
$isValid = false;
|
||||
}
|
||||
if ($accessTypes['read']) {
|
||||
if (!is_readable($fileName)) {
|
||||
$this->_throw($fileName, self::NOT_READABLE);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if ($accessTypes['write']) {
|
||||
if (!is_writable($fileName)) {
|
||||
$this->_throw($fileName, self::NOT_WRITABLE);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if ($accessTypes['execute']) {
|
||||
if (!is_executable($fileName)) {
|
||||
$this->_throw($fileName, self::NOT_EXECUTABLE);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if ($accessTypes['dir']) {
|
||||
if (!is_dir($fileName)) {
|
||||
$this->_throw($fileName, self::NOT_A_DIRECTORY);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if ($accessTypes['file']) {
|
||||
if (!is_file($fileName)) {
|
||||
$this->_throw($fileName, self::NOT_A_FILE);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
if ($accessTypes['uploaded']) {
|
||||
if (!is_uploaded_file($fileName)) {
|
||||
$this->_throw($fileName, self::NOT_UPLOADED);
|
||||
$isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws an error of the given type
|
||||
*
|
||||
* @param string $fileName checked file which caused an error
|
||||
* @param string $errorType Type of error
|
||||
* @return false
|
||||
*/
|
||||
protected function _throw($fileName, $errorType)
|
||||
{
|
||||
if ($fileName !== null) {
|
||||
$this->_setValue($fileName);
|
||||
}
|
||||
|
||||
$this->_error($errorType);
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
119
library/Msd/Version.php
Normale Datei
119
library/Msd/Version.php
Normale Datei
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
||||
* http://www.mysqldumper.net
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Version
|
||||
* @version SVN: $Rev$
|
||||
* @author $Author$
|
||||
*/
|
||||
/**
|
||||
* Show MySQLDumper's version number
|
||||
*
|
||||
* @package MySQLDumper
|
||||
* @subpackage Version
|
||||
*/
|
||||
class Msd_Version
|
||||
{
|
||||
/**
|
||||
* Current application version
|
||||
* @var string
|
||||
*/
|
||||
private $_msdVersion = '2.0.0';
|
||||
|
||||
/**
|
||||
* Minimum version of PHP which is required.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_requiredPhpVersion = '5.2.0';
|
||||
|
||||
/**
|
||||
* Minimum version of MySQL which is required.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_requiredMysqlVersion = '4.1.2';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Option-array to overwrite required PHP/MySQL
|
||||
* versions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = array())
|
||||
{
|
||||
if (isset($options['requiredPhpVersion'])) {
|
||||
$this->_requiredPhpVersion = $options['requiredPhpVersion'];
|
||||
}
|
||||
|
||||
if (isset($options['requiredMysqlVersion'])) {
|
||||
$this->_requiredMysqlVersion = $options['requiredMysqlVersion'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get actual MySQLDumper version
|
||||
*
|
||||
* @return string The version number of MySQLDumper
|
||||
*/
|
||||
public function getMsdVersion()
|
||||
{
|
||||
return $this->_msdVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get required PHP version
|
||||
*
|
||||
* @return string The required version number of PHP
|
||||
*/
|
||||
public function getRequiredPhpVersion()
|
||||
{
|
||||
return $this->_requiredPhpVersion;
|
||||
}
|
||||
/**
|
||||
* Get required MySQL version
|
||||
*
|
||||
* @return string The required version number of MySQL
|
||||
*/
|
||||
public function getRequiredMysqlVersion()
|
||||
{
|
||||
return $this->_requiredMysqlVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for required PHP version.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkPhpVersion()
|
||||
{
|
||||
$res = version_compare(PHP_VERSION, $this->_requiredPhpVersion);
|
||||
if ($res >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for required MySQL version.
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function checkMysqlVersion()
|
||||
{
|
||||
$dbObject = Msd_Db::getAdapter();
|
||||
$mysqlVersion = $dbObject->getServerInfo();
|
||||
$res = version_compare(
|
||||
$mysqlVersion,
|
||||
$this->_requiredMysqlVersion
|
||||
);
|
||||
if ($res >= 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
1242
library/Zend/Acl.php
Normale Datei
1242
library/Zend/Acl.php
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
64
library/Zend/Acl/Assert/Interface.php
Normale Datei
64
library/Zend/Acl/Assert/Interface.php
Normale Datei
|
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl
|
||||
*/
|
||||
require_once 'Zend/Acl.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Role_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Resource_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Resource/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Acl_Assert_Interface
|
||||
{
|
||||
/**
|
||||
* Returns true if and only if the assertion conditions are met
|
||||
*
|
||||
* This method is passed the ACL, Role, Resource, and privilege to which the authorization query applies. If the
|
||||
* $role, $resource, or $privilege parameters are null, it means that the query applies to all Roles, Resources, or
|
||||
* privileges, respectively.
|
||||
*
|
||||
* @param Zend_Acl $acl
|
||||
* @param Zend_Acl_Role_Interface $role
|
||||
* @param Zend_Acl_Resource_Interface $resource
|
||||
* @param string $privilege
|
||||
* @return boolean
|
||||
*/
|
||||
public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null,
|
||||
$privilege = null);
|
||||
}
|
||||
36
library/Zend/Acl/Exception.php
Normale Datei
36
library/Zend/Acl/Exception.php
Normale Datei
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Exception extends Zend_Exception
|
||||
{}
|
||||
75
library/Zend/Acl/Resource.php
Normale Datei
75
library/Zend/Acl/Resource.php
Normale Datei
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Resource_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Resource/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Resource implements Zend_Acl_Resource_Interface
|
||||
{
|
||||
/**
|
||||
* Unique id of Resource
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_resourceId;
|
||||
|
||||
/**
|
||||
* Sets the Resource identifier
|
||||
*
|
||||
* @param string $resourceId
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($resourceId)
|
||||
{
|
||||
$this->_resourceId = (string) $resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Resource_Interface; returns the Resource identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceId()
|
||||
{
|
||||
return $this->_resourceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Resource_Interface; returns the Resource identifier
|
||||
* Proxies to getResourceId()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getResourceId();
|
||||
}
|
||||
}
|
||||
37
library/Zend/Acl/Resource/Interface.php
Normale Datei
37
library/Zend/Acl/Resource/Interface.php
Normale Datei
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Acl_Resource_Interface
|
||||
{
|
||||
/**
|
||||
* Returns the string identifier of the Resource
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResourceId();
|
||||
}
|
||||
75
library/Zend/Acl/Role.php
Normale Datei
75
library/Zend/Acl/Role.php
Normale Datei
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Role_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Role implements Zend_Acl_Role_Interface
|
||||
{
|
||||
/**
|
||||
* Unique id of Role
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_roleId;
|
||||
|
||||
/**
|
||||
* Sets the Role identifier
|
||||
*
|
||||
* @param string $roleId
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($roleId)
|
||||
{
|
||||
$this->_roleId = (string) $roleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Role_Interface; returns the Role identifier
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleId()
|
||||
{
|
||||
return $this->_roleId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Acl_Role_Interface; returns the Role identifier
|
||||
* Proxies to getRoleId()
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getRoleId();
|
||||
}
|
||||
}
|
||||
37
library/Zend/Acl/Role/Interface.php
Normale Datei
37
library/Zend/Acl/Role/Interface.php
Normale Datei
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Acl_Role_Interface
|
||||
{
|
||||
/**
|
||||
* Returns the string identifier of the Role
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRoleId();
|
||||
}
|
||||
271
library/Zend/Acl/Role/Registry.php
Normale Datei
271
library/Zend/Acl/Role/Registry.php
Normale Datei
|
|
@ -0,0 +1,271 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Role_Interface
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Role_Registry
|
||||
{
|
||||
/**
|
||||
* Internal Role registry data storage
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_roles = array();
|
||||
|
||||
/**
|
||||
* Adds a Role having an identifier unique to the registry
|
||||
*
|
||||
* The $parents parameter may be a reference to, or the string identifier for,
|
||||
* a Role existing in the registry, or $parents may be passed as an array of
|
||||
* these - mixing string identifiers and objects is ok - to indicate the Roles
|
||||
* from which the newly added Role will directly inherit.
|
||||
*
|
||||
* In order to resolve potential ambiguities with conflicting rules inherited
|
||||
* from different parents, the most recently added parent takes precedence over
|
||||
* parents that were previously added. In other words, the first parent added
|
||||
* will have the least priority, and the last parent added will have the
|
||||
* highest priority.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface $role
|
||||
* @param Zend_Acl_Role_Interface|string|array $parents
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return Zend_Acl_Role_Registry Provides a fluent interface
|
||||
*/
|
||||
public function add(Zend_Acl_Role_Interface $role, $parents = null)
|
||||
{
|
||||
$roleId = $role->getRoleId();
|
||||
|
||||
if ($this->has($roleId)) {
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
throw new Zend_Acl_Role_Registry_Exception("Role id '$roleId' already exists in the registry");
|
||||
}
|
||||
|
||||
$roleParents = array();
|
||||
|
||||
if (null !== $parents) {
|
||||
if (!is_array($parents)) {
|
||||
$parents = array($parents);
|
||||
}
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
foreach ($parents as $parent) {
|
||||
try {
|
||||
if ($parent instanceof Zend_Acl_Role_Interface) {
|
||||
$roleParentId = $parent->getRoleId();
|
||||
} else {
|
||||
$roleParentId = $parent;
|
||||
}
|
||||
$roleParent = $this->get($roleParentId);
|
||||
} catch (Zend_Acl_Role_Registry_Exception $e) {
|
||||
throw new Zend_Acl_Role_Registry_Exception("Parent Role id '$roleParentId' does not exist", 0, $e);
|
||||
}
|
||||
$roleParents[$roleParentId] = $roleParent;
|
||||
$this->_roles[$roleParentId]['children'][$roleId] = $role;
|
||||
}
|
||||
}
|
||||
|
||||
$this->_roles[$roleId] = array(
|
||||
'instance' => $role,
|
||||
'parents' => $roleParents,
|
||||
'children' => array()
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identified Role
|
||||
*
|
||||
* The $role parameter can either be a Role or a Role identifier.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return Zend_Acl_Role_Interface
|
||||
*/
|
||||
public function get($role)
|
||||
{
|
||||
if ($role instanceof Zend_Acl_Role_Interface) {
|
||||
$roleId = $role->getRoleId();
|
||||
} else {
|
||||
$roleId = (string) $role;
|
||||
}
|
||||
|
||||
if (!$this->has($role)) {
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
throw new Zend_Acl_Role_Registry_Exception("Role '$roleId' not found");
|
||||
}
|
||||
|
||||
return $this->_roles[$roleId]['instance'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if and only if the Role exists in the registry
|
||||
*
|
||||
* The $role parameter can either be a Role or a Role identifier.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @return boolean
|
||||
*/
|
||||
public function has($role)
|
||||
{
|
||||
if ($role instanceof Zend_Acl_Role_Interface) {
|
||||
$roleId = $role->getRoleId();
|
||||
} else {
|
||||
$roleId = (string) $role;
|
||||
}
|
||||
|
||||
return isset($this->_roles[$roleId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of an existing Role's parents
|
||||
*
|
||||
* The array keys are the identifiers of the parent Roles, and the values are
|
||||
* the parent Role instances. The parent Roles are ordered in this array by
|
||||
* ascending priority. The highest priority parent Role, last in the array,
|
||||
* corresponds with the parent Role most recently added.
|
||||
*
|
||||
* If the Role does not have any parents, then an empty array is returned.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @uses Zend_Acl_Role_Registry::get()
|
||||
* @return array
|
||||
*/
|
||||
public function getParents($role)
|
||||
{
|
||||
$roleId = $this->get($role)->getRoleId();
|
||||
|
||||
return $this->_roles[$roleId]['parents'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if and only if $role inherits from $inherit
|
||||
*
|
||||
* Both parameters may be either a Role or a Role identifier. If
|
||||
* $onlyParents is true, then $role must inherit directly from
|
||||
* $inherit in order to return true. By default, this method looks
|
||||
* through the entire inheritance DAG to determine whether $role
|
||||
* inherits from $inherit through its ancestor Roles.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @param Zend_Acl_Role_Interface|string $inherit
|
||||
* @param boolean $onlyParents
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return boolean
|
||||
*/
|
||||
public function inherits($role, $inherit, $onlyParents = false)
|
||||
{
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
try {
|
||||
$roleId = $this->get($role)->getRoleId();
|
||||
$inheritId = $this->get($inherit)->getRoleId();
|
||||
} catch (Zend_Acl_Role_Registry_Exception $e) {
|
||||
throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
$inherits = isset($this->_roles[$roleId]['parents'][$inheritId]);
|
||||
|
||||
if ($inherits || $onlyParents) {
|
||||
return $inherits;
|
||||
}
|
||||
|
||||
foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
|
||||
if ($this->inherits($parentId, $inheritId)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the Role from the registry
|
||||
*
|
||||
* The $role parameter can either be a Role or a Role identifier.
|
||||
*
|
||||
* @param Zend_Acl_Role_Interface|string $role
|
||||
* @throws Zend_Acl_Role_Registry_Exception
|
||||
* @return Zend_Acl_Role_Registry Provides a fluent interface
|
||||
*/
|
||||
public function remove($role)
|
||||
{
|
||||
/**
|
||||
* @see Zend_Acl_Role_Registry_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Role/Registry/Exception.php';
|
||||
try {
|
||||
$roleId = $this->get($role)->getRoleId();
|
||||
} catch (Zend_Acl_Role_Registry_Exception $e) {
|
||||
throw new Zend_Acl_Role_Registry_Exception($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
|
||||
foreach ($this->_roles[$roleId]['children'] as $childId => $child) {
|
||||
unset($this->_roles[$childId]['parents'][$roleId]);
|
||||
}
|
||||
foreach ($this->_roles[$roleId]['parents'] as $parentId => $parent) {
|
||||
unset($this->_roles[$parentId]['children'][$roleId]);
|
||||
}
|
||||
|
||||
unset($this->_roles[$roleId]);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all Roles from the registry
|
||||
*
|
||||
* @return Zend_Acl_Role_Registry Provides a fluent interface
|
||||
*/
|
||||
public function removeAll()
|
||||
{
|
||||
$this->_roles = array();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRoles()
|
||||
{
|
||||
return $this->_roles;
|
||||
}
|
||||
|
||||
}
|
||||
36
library/Zend/Acl/Role/Registry/Exception.php
Normale Datei
36
library/Zend/Acl/Role/Registry/Exception.php
Normale Datei
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Acl_Exception
|
||||
*/
|
||||
require_once 'Zend/Acl/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Acl
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Acl_Role_Registry_Exception extends Zend_Acl_Exception
|
||||
{}
|
||||
413
library/Zend/Application.php
Normale Datei
413
library/Zend/Application.php
Normale Datei
|
|
@ -0,0 +1,413 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application
|
||||
{
|
||||
/**
|
||||
* Autoloader to use
|
||||
*
|
||||
* @var Zend_Loader_Autoloader
|
||||
*/
|
||||
protected $_autoloader;
|
||||
|
||||
/**
|
||||
* Bootstrap
|
||||
*
|
||||
* @var Zend_Application_Bootstrap_BootstrapAbstract
|
||||
*/
|
||||
protected $_bootstrap;
|
||||
|
||||
/**
|
||||
* Application environment
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_environment;
|
||||
|
||||
/**
|
||||
* Flattened (lowercase) option keys
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_optionKeys = array();
|
||||
|
||||
/**
|
||||
* Options for Zend_Application
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Initialize application. Potentially initializes include_paths, PHP
|
||||
* settings, and bootstrap class.
|
||||
*
|
||||
* @param string $environment
|
||||
* @param string|array|Zend_Config $options String path to configuration file, or array/Zend_Config of configuration options
|
||||
* @throws Zend_Application_Exception When invalid options are provided
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($environment, $options = null)
|
||||
{
|
||||
$this->_environment = (string) $environment;
|
||||
|
||||
require_once 'Zend/Loader/Autoloader.php';
|
||||
$this->_autoloader = Zend_Loader_Autoloader::getInstance();
|
||||
|
||||
if (null !== $options) {
|
||||
if (is_string($options)) {
|
||||
$options = $this->_loadConfig($options);
|
||||
} elseif ($options instanceof Zend_Config) {
|
||||
$options = $options->toArray();
|
||||
} elseif (!is_array($options)) {
|
||||
throw new Zend_Application_Exception('Invalid options provided; must be location of config file, a config object, or an array');
|
||||
}
|
||||
|
||||
$this->setOptions($options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve current environment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEnvironment()
|
||||
{
|
||||
return $this->_environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve autoloader instance
|
||||
*
|
||||
* @return Zend_Loader_Autoloader
|
||||
*/
|
||||
public function getAutoloader()
|
||||
{
|
||||
return $this->_autoloader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set application options
|
||||
*
|
||||
* @param array $options
|
||||
* @throws Zend_Application_Exception When no bootstrap path is provided
|
||||
* @throws Zend_Application_Exception When invalid bootstrap information are provided
|
||||
* @return Zend_Application
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
if (!empty($options['config'])) {
|
||||
if (is_array($options['config'])) {
|
||||
$_options = array();
|
||||
foreach ($options['config'] as $tmp) {
|
||||
$_options = $this->mergeOptions($_options, $this->_loadConfig($tmp));
|
||||
}
|
||||
$options = $this->mergeOptions($_options, $options);
|
||||
} else {
|
||||
$options = $this->mergeOptions($this->_loadConfig($options['config']), $options);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_options = $options;
|
||||
|
||||
$options = array_change_key_case($options, CASE_LOWER);
|
||||
|
||||
$this->_optionKeys = array_keys($options);
|
||||
|
||||
if (!empty($options['phpsettings'])) {
|
||||
$this->setPhpSettings($options['phpsettings']);
|
||||
}
|
||||
|
||||
if (!empty($options['includepaths'])) {
|
||||
$this->setIncludePaths($options['includepaths']);
|
||||
}
|
||||
|
||||
if (!empty($options['autoloadernamespaces'])) {
|
||||
$this->setAutoloaderNamespaces($options['autoloadernamespaces']);
|
||||
}
|
||||
|
||||
if (!empty($options['autoloaderzfpath'])) {
|
||||
$autoloader = $this->getAutoloader();
|
||||
if (method_exists($autoloader, 'setZfPath')) {
|
||||
$zfPath = $options['autoloaderzfpath'];
|
||||
$zfVersion = !empty($options['autoloaderzfversion'])
|
||||
? $options['autoloaderzfversion']
|
||||
: 'latest';
|
||||
$autoloader->setZfPath($zfPath, $zfVersion);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($options['bootstrap'])) {
|
||||
$bootstrap = $options['bootstrap'];
|
||||
|
||||
if (is_string($bootstrap)) {
|
||||
$this->setBootstrap($bootstrap);
|
||||
} elseif (is_array($bootstrap)) {
|
||||
if (empty($bootstrap['path'])) {
|
||||
throw new Zend_Application_Exception('No bootstrap path provided');
|
||||
}
|
||||
|
||||
$path = $bootstrap['path'];
|
||||
$class = null;
|
||||
|
||||
if (!empty($bootstrap['class'])) {
|
||||
$class = $bootstrap['class'];
|
||||
}
|
||||
|
||||
$this->setBootstrap($path, $class);
|
||||
} else {
|
||||
throw new Zend_Application_Exception('Invalid bootstrap information provided');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve application options (for caching)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is an option present?
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function hasOption($key)
|
||||
{
|
||||
return in_array(strtolower($key), $this->_optionKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single option
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
if ($this->hasOption($key)) {
|
||||
$options = $this->getOptions();
|
||||
$options = array_change_key_case($options, CASE_LOWER);
|
||||
return $options[strtolower($key)];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge options recursively
|
||||
*
|
||||
* @param array $array1
|
||||
* @param mixed $array2
|
||||
* @return array
|
||||
*/
|
||||
public function mergeOptions(array $array1, $array2 = null)
|
||||
{
|
||||
if (is_array($array2)) {
|
||||
foreach ($array2 as $key => $val) {
|
||||
if (is_array($array2[$key])) {
|
||||
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
|
||||
? $this->mergeOptions($array1[$key], $array2[$key])
|
||||
: $array2[$key];
|
||||
} else {
|
||||
$array1[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $array1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set PHP configuration settings
|
||||
*
|
||||
* @param array $settings
|
||||
* @param string $prefix Key prefix to prepend to array values (used to map . separated INI values)
|
||||
* @return Zend_Application
|
||||
*/
|
||||
public function setPhpSettings(array $settings, $prefix = '')
|
||||
{
|
||||
foreach ($settings as $key => $value) {
|
||||
$key = empty($prefix) ? $key : $prefix . $key;
|
||||
if (is_scalar($value)) {
|
||||
ini_set($key, $value);
|
||||
} elseif (is_array($value)) {
|
||||
$this->setPhpSettings($value, $key . '.');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set include path
|
||||
*
|
||||
* @param array $paths
|
||||
* @return Zend_Application
|
||||
*/
|
||||
public function setIncludePaths(array $paths)
|
||||
{
|
||||
$path = implode(PATH_SEPARATOR, $paths);
|
||||
set_include_path($path . PATH_SEPARATOR . get_include_path());
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set autoloader namespaces
|
||||
*
|
||||
* @param array $namespaces
|
||||
* @return Zend_Application
|
||||
*/
|
||||
public function setAutoloaderNamespaces(array $namespaces)
|
||||
{
|
||||
$autoloader = $this->getAutoloader();
|
||||
|
||||
foreach ($namespaces as $namespace) {
|
||||
$autoloader->registerNamespace($namespace);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set bootstrap path/class
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $class
|
||||
* @return Zend_Application
|
||||
*/
|
||||
public function setBootstrap($path, $class = null)
|
||||
{
|
||||
// setOptions() can potentially send a null value; specify default
|
||||
// here
|
||||
if (null === $class) {
|
||||
$class = 'Bootstrap';
|
||||
}
|
||||
|
||||
if (!class_exists($class, false)) {
|
||||
require_once $path;
|
||||
if (!class_exists($class, false)) {
|
||||
throw new Zend_Application_Exception('Bootstrap class not found');
|
||||
}
|
||||
}
|
||||
$this->_bootstrap = new $class($this);
|
||||
|
||||
if (!$this->_bootstrap instanceof Zend_Application_Bootstrap_Bootstrapper) {
|
||||
throw new Zend_Application_Exception('Bootstrap class does not implement Zend_Application_Bootstrap_Bootstrapper');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bootstrap object
|
||||
*
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
*/
|
||||
public function getBootstrap()
|
||||
{
|
||||
if (null === $this->_bootstrap) {
|
||||
$this->_bootstrap = new Zend_Application_Bootstrap_Bootstrap($this);
|
||||
}
|
||||
return $this->_bootstrap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap application
|
||||
*
|
||||
* @param null|string|array $resource
|
||||
* @return Zend_Application
|
||||
*/
|
||||
public function bootstrap($resource = null)
|
||||
{
|
||||
$this->getBootstrap()->bootstrap($resource);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the application
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$this->getBootstrap()->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration file of options
|
||||
*
|
||||
* @param string $file
|
||||
* @throws Zend_Application_Exception When invalid configuration file is provided
|
||||
* @return array
|
||||
*/
|
||||
protected function _loadConfig($file)
|
||||
{
|
||||
$environment = $this->getEnvironment();
|
||||
$suffix = strtolower(pathinfo($file, PATHINFO_EXTENSION));
|
||||
|
||||
switch ($suffix) {
|
||||
case 'ini':
|
||||
$config = new Zend_Config_Ini($file, $environment);
|
||||
break;
|
||||
|
||||
case 'xml':
|
||||
$config = new Zend_Config_Xml($file, $environment);
|
||||
break;
|
||||
|
||||
case 'json':
|
||||
$config = new Zend_Config_Json($file, $environment);
|
||||
break;
|
||||
|
||||
case 'yaml':
|
||||
$config = new Zend_Config_Yaml($file, $environment);
|
||||
break;
|
||||
|
||||
case 'php':
|
||||
case 'inc':
|
||||
$config = include $file;
|
||||
if (!is_array($config)) {
|
||||
throw new Zend_Application_Exception('Invalid configuration file provided; PHP file does not return array value');
|
||||
}
|
||||
return $config;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Zend_Application_Exception('Invalid configuration file provided; unknown config type');
|
||||
}
|
||||
|
||||
return $config->toArray();
|
||||
}
|
||||
}
|
||||
156
library/Zend/Application/Bootstrap/Bootstrap.php
Normale Datei
156
library/Zend/Application/Bootstrap/Bootstrap.php
Normale Datei
|
|
@ -0,0 +1,156 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Concrete base class for bootstrap classes
|
||||
*
|
||||
* Registers and utilizes Zend_Controller_Front by default.
|
||||
*
|
||||
* @uses Zend_Application_Bootstrap_Bootstrap
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Bootstrap_Bootstrap
|
||||
extends Zend_Application_Bootstrap_BootstrapAbstract
|
||||
{
|
||||
/**
|
||||
* Application resource namespace
|
||||
* @var false|string
|
||||
*/
|
||||
protected $_appNamespace = false;
|
||||
|
||||
/**
|
||||
* Application resource autoloader
|
||||
* @var Zend_Loader_Autoloader_Resource
|
||||
*/
|
||||
protected $_resourceLoader;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Ensure FrontController resource is registered
|
||||
*
|
||||
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($application)
|
||||
{
|
||||
parent::__construct($application);
|
||||
|
||||
if ($application->hasOption('resourceloader')) {
|
||||
$this->setOptions(array(
|
||||
'resourceloader' => $application->getOption('resourceloader')
|
||||
));
|
||||
}
|
||||
$this->getResourceLoader();
|
||||
|
||||
if (!$this->hasPluginResource('FrontController')) {
|
||||
$this->registerPluginResource('FrontController');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the application
|
||||
*
|
||||
* Checks to see that we have a default controller directory. If not, an
|
||||
* exception is thrown.
|
||||
*
|
||||
* If so, it registers the bootstrap with the 'bootstrap' parameter of
|
||||
* the front controller, and dispatches the front controller.
|
||||
*
|
||||
* @return mixed
|
||||
* @throws Zend_Application_Bootstrap_Exception
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$front = $this->getResource('FrontController');
|
||||
$default = $front->getDefaultModule();
|
||||
if (null === $front->getControllerDirectory($default)) {
|
||||
throw new Zend_Application_Bootstrap_Exception(
|
||||
'No default controller directory registered with front controller'
|
||||
);
|
||||
}
|
||||
|
||||
$front->setParam('bootstrap', $this);
|
||||
$response = $front->dispatch();
|
||||
if ($front->returnResponse()) {
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set module resource loader
|
||||
*
|
||||
* @param Zend_Loader_Autoloader_Resource $loader
|
||||
* @return Zend_Application_Module_Bootstrap
|
||||
*/
|
||||
public function setResourceLoader(Zend_Loader_Autoloader_Resource $loader)
|
||||
{
|
||||
$this->_resourceLoader = $loader;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve module resource loader
|
||||
*
|
||||
* @return Zend_Loader_Autoloader_Resource
|
||||
*/
|
||||
public function getResourceLoader()
|
||||
{
|
||||
if ((null === $this->_resourceLoader)
|
||||
&& (false !== ($namespace = $this->getAppNamespace()))
|
||||
) {
|
||||
$r = new ReflectionClass($this);
|
||||
$path = $r->getFileName();
|
||||
$this->setResourceLoader(new Zend_Application_Module_Autoloader(array(
|
||||
'namespace' => $namespace,
|
||||
'basePath' => dirname($path),
|
||||
)));
|
||||
}
|
||||
return $this->_resourceLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get application namespace (used for module autoloading)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppNamespace()
|
||||
{
|
||||
return $this->_appNamespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set application namespace (for module autoloading)
|
||||
*
|
||||
* @param string
|
||||
* @return Zend_Application_Bootstrap_Bootstrap
|
||||
*/
|
||||
public function setAppNamespace($value)
|
||||
{
|
||||
$this->_appNamespace = (string) $value;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
770
library/Zend/Application/Bootstrap/BootstrapAbstract.php
Normale Datei
770
library/Zend/Application/Bootstrap/BootstrapAbstract.php
Normale Datei
|
|
@ -0,0 +1,770 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract base class for bootstrap classes
|
||||
*
|
||||
* @uses Zend_Application_Bootstrap_Bootstrapper
|
||||
* @uses Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Application_Bootstrap_BootstrapAbstract
|
||||
implements Zend_Application_Bootstrap_Bootstrapper,
|
||||
Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
{
|
||||
/**
|
||||
* @var Zend_Application|Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
protected $_application;
|
||||
|
||||
/**
|
||||
* @var array Internal resource methods (resource/method pairs)
|
||||
*/
|
||||
protected $_classResources;
|
||||
|
||||
/**
|
||||
* @var object Resource container
|
||||
*/
|
||||
protected $_container;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_environment;
|
||||
|
||||
/**
|
||||
* Flattened (lowercase) option keys used for lookups
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_optionKeys = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* @var Zend_Loader_PluginLoader_Interface
|
||||
*/
|
||||
protected $_pluginLoader;
|
||||
|
||||
/**
|
||||
* @var array Class-based resource plugins
|
||||
*/
|
||||
protected $_pluginResources = array();
|
||||
|
||||
/**
|
||||
* @var array Initializers that have been run
|
||||
*/
|
||||
protected $_run = array();
|
||||
|
||||
/**
|
||||
* @var array Initializers that have been started but not yet completed (circular dependency detection)
|
||||
*/
|
||||
protected $_started = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Sets application object, initializes options, and prepares list of
|
||||
* initializer methods.
|
||||
*
|
||||
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
|
||||
* @return void
|
||||
* @throws Zend_Application_Bootstrap_Exception When invalid application is provided
|
||||
*/
|
||||
public function __construct($application)
|
||||
{
|
||||
$this->setApplication($application);
|
||||
$options = $application->getOptions();
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set class state
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
$this->_options = $this->mergeOptions($this->_options, $options);
|
||||
|
||||
$options = array_change_key_case($options, CASE_LOWER);
|
||||
$this->_optionKeys = array_merge($this->_optionKeys, array_keys($options));
|
||||
|
||||
$methods = get_class_methods($this);
|
||||
foreach ($methods as $key => $method) {
|
||||
$methods[$key] = strtolower($method);
|
||||
}
|
||||
|
||||
if (array_key_exists('pluginpaths', $options)) {
|
||||
$pluginLoader = $this->getPluginLoader();
|
||||
|
||||
foreach ($options['pluginpaths'] as $prefix => $path) {
|
||||
$pluginLoader->addPrefixPath($prefix, $path);
|
||||
}
|
||||
unset($options['pluginpaths']);
|
||||
}
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
$method = 'set' . strtolower($key);
|
||||
|
||||
if (in_array($method, $methods)) {
|
||||
$this->$method($value);
|
||||
} elseif ('resources' == $key) {
|
||||
foreach ($value as $resource => $resourceOptions) {
|
||||
$this->registerPluginResource($resource, $resourceOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current options from bootstrap
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is an option present?
|
||||
*
|
||||
* @param string $key
|
||||
* @return bool
|
||||
*/
|
||||
public function hasOption($key)
|
||||
{
|
||||
return in_array(strtolower($key), $this->_optionKeys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single option
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function getOption($key)
|
||||
{
|
||||
if ($this->hasOption($key)) {
|
||||
$options = $this->getOptions();
|
||||
$options = array_change_key_case($options, CASE_LOWER);
|
||||
return $options[strtolower($key)];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge options recursively
|
||||
*
|
||||
* @param array $array1
|
||||
* @param mixed $array2
|
||||
* @return array
|
||||
*/
|
||||
public function mergeOptions(array $array1, $array2 = null)
|
||||
{
|
||||
if (is_array($array2)) {
|
||||
foreach ($array2 as $key => $val) {
|
||||
if (is_array($array2[$key])) {
|
||||
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
|
||||
? $this->mergeOptions($array1[$key], $array2[$key])
|
||||
: $array2[$key];
|
||||
} else {
|
||||
$array1[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $array1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class resources (as resource/method pairs)
|
||||
*
|
||||
* Uses get_class_methods() by default, reflection on prior to 5.2.6,
|
||||
* as a bug prevents the usage of get_class_methods() there.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClassResources()
|
||||
{
|
||||
if (null === $this->_classResources) {
|
||||
if (version_compare(PHP_VERSION, '5.2.6') === -1) {
|
||||
$class = new ReflectionObject($this);
|
||||
$classMethods = $class->getMethods();
|
||||
$methodNames = array();
|
||||
|
||||
foreach ($classMethods as $method) {
|
||||
$methodNames[] = $method->getName();
|
||||
}
|
||||
} else {
|
||||
$methodNames = get_class_methods($this);
|
||||
}
|
||||
|
||||
$this->_classResources = array();
|
||||
foreach ($methodNames as $method) {
|
||||
if (5 < strlen($method) && '_init' === substr($method, 0, 5)) {
|
||||
$this->_classResources[strtolower(substr($method, 5))] = $method;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_classResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class resource names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClassResourceNames()
|
||||
{
|
||||
$resources = $this->getClassResources();
|
||||
return array_keys($resources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new resource plugin
|
||||
*
|
||||
* @param string|Zend_Application_Resource_Resource $resource
|
||||
* @param mixed $options
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
* @throws Zend_Application_Bootstrap_Exception When invalid resource is provided
|
||||
*/
|
||||
public function registerPluginResource($resource, $options = null)
|
||||
{
|
||||
if ($resource instanceof Zend_Application_Resource_Resource) {
|
||||
$resource->setBootstrap($this);
|
||||
$pluginName = $this->_resolvePluginResourceName($resource);
|
||||
$this->_pluginResources[$pluginName] = $resource;
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!is_string($resource)) {
|
||||
throw new Zend_Application_Bootstrap_Exception('Invalid resource provided to ' . __METHOD__);
|
||||
}
|
||||
|
||||
$this->_pluginResources[$resource] = $options;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister a resource from the bootstrap
|
||||
*
|
||||
* @param string|Zend_Application_Resource_Resource $resource
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
* @throws Zend_Application_Bootstrap_Exception When unknown resource type is provided
|
||||
*/
|
||||
public function unregisterPluginResource($resource)
|
||||
{
|
||||
if ($resource instanceof Zend_Application_Resource_Resource) {
|
||||
if ($index = array_search($resource, $this->_pluginResources, true)) {
|
||||
unset($this->_pluginResources[$index]);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (!is_string($resource)) {
|
||||
throw new Zend_Application_Bootstrap_Exception('Unknown resource type provided to ' . __METHOD__);
|
||||
}
|
||||
|
||||
$resource = strtolower($resource);
|
||||
if (array_key_exists($resource, $this->_pluginResources)) {
|
||||
unset($this->_pluginResources[$resource]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the requested plugin resource registered?
|
||||
*
|
||||
* @param string $resource
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPluginResource($resource)
|
||||
{
|
||||
return (null !== $this->getPluginResource($resource));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a registered plugin resource
|
||||
*
|
||||
* @param string $resourceName
|
||||
* @return Zend_Application_Resource_Resource
|
||||
*/
|
||||
public function getPluginResource($resource)
|
||||
{
|
||||
if (array_key_exists(strtolower($resource), $this->_pluginResources)) {
|
||||
$resource = strtolower($resource);
|
||||
if (!$this->_pluginResources[$resource] instanceof Zend_Application_Resource_Resource) {
|
||||
$resourceName = $this->_loadPluginResource($resource, $this->_pluginResources[$resource]);
|
||||
if (!$resourceName) {
|
||||
throw new Zend_Application_Bootstrap_Exception(sprintf('Unable to resolve plugin "%s"; no corresponding plugin with that name', $resource));
|
||||
}
|
||||
$resource = $resourceName;
|
||||
}
|
||||
return $this->_pluginResources[$resource];
|
||||
}
|
||||
|
||||
foreach ($this->_pluginResources as $plugin => $spec) {
|
||||
if ($spec instanceof Zend_Application_Resource_Resource) {
|
||||
$pluginName = $this->_resolvePluginResourceName($spec);
|
||||
if (0 === strcasecmp($resource, $pluginName)) {
|
||||
unset($this->_pluginResources[$plugin]);
|
||||
$this->_pluginResources[$pluginName] = $spec;
|
||||
return $spec;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (false !== $pluginName = $this->_loadPluginResource($plugin, $spec)) {
|
||||
if (0 === strcasecmp($resource, $pluginName)) {
|
||||
return $this->_pluginResources[$pluginName];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (class_exists($plugin)) { //@SEE ZF-7550
|
||||
$spec = (array) $spec;
|
||||
$spec['bootstrap'] = $this;
|
||||
$instance = new $plugin($spec);
|
||||
$pluginName = $this->_resolvePluginResourceName($instance);
|
||||
unset($this->_pluginResources[$plugin]);
|
||||
$this->_pluginResources[$pluginName] = $instance;
|
||||
|
||||
if (0 === strcasecmp($resource, $pluginName)) {
|
||||
return $instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve all plugin resources
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPluginResources()
|
||||
{
|
||||
foreach (array_keys($this->_pluginResources) as $resource) {
|
||||
$this->getPluginResource($resource);
|
||||
}
|
||||
return $this->_pluginResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve plugin resource names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPluginResourceNames()
|
||||
{
|
||||
$this->getPluginResources();
|
||||
return array_keys($this->_pluginResources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set plugin loader for loading resources
|
||||
*
|
||||
* @param Zend_Loader_PluginLoader_Interface $loader
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
*/
|
||||
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader)
|
||||
{
|
||||
$this->_pluginLoader = $loader;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plugin loader for resources
|
||||
*
|
||||
* @return Zend_Loader_PluginLoader_Interface
|
||||
*/
|
||||
public function getPluginLoader()
|
||||
{
|
||||
if ($this->_pluginLoader === null) {
|
||||
$options = array(
|
||||
'Zend_Application_Resource' => 'Zend/Application/Resource',
|
||||
'ZendX_Application_Resource' => 'ZendX/Application/Resource'
|
||||
);
|
||||
|
||||
$this->_pluginLoader = new Zend_Loader_PluginLoader($options);
|
||||
}
|
||||
|
||||
return $this->_pluginLoader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set application/parent bootstrap
|
||||
*
|
||||
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
*/
|
||||
public function setApplication($application)
|
||||
{
|
||||
if (($application instanceof Zend_Application)
|
||||
|| ($application instanceof Zend_Application_Bootstrap_Bootstrapper)
|
||||
) {
|
||||
if ($application === $this) {
|
||||
throw new Zend_Application_Bootstrap_Exception('Cannot set application to same object; creates recursion');
|
||||
}
|
||||
$this->_application = $application;
|
||||
} else {
|
||||
throw new Zend_Application_Bootstrap_Exception('Invalid application provided to bootstrap constructor (received "' . get_class($application) . '" instance)');
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve parent application instance
|
||||
*
|
||||
* @return Zend_Application|Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
public function getApplication()
|
||||
{
|
||||
return $this->_application;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve application environment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEnvironment()
|
||||
{
|
||||
if (null === $this->_environment) {
|
||||
$this->_environment = $this->getApplication()->getEnvironment();
|
||||
}
|
||||
return $this->_environment;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set resource container
|
||||
*
|
||||
* By default, if a resource callback has a non-null return value, this
|
||||
* value will be stored in a container using the resource name as the
|
||||
* key.
|
||||
*
|
||||
* Containers must be objects, and must allow setting public properties.
|
||||
*
|
||||
* @param object $container
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
*/
|
||||
public function setContainer($container)
|
||||
{
|
||||
if (!is_object($container)) {
|
||||
throw new Zend_Application_Bootstrap_Exception('Resource containers must be objects');
|
||||
}
|
||||
$this->_container = $container;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve resource container
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
if (null === $this->_container) {
|
||||
$this->setContainer(new Zend_Registry());
|
||||
}
|
||||
return $this->_container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a resource has been stored in the container
|
||||
*
|
||||
* During bootstrap resource initialization, you may return a value. If
|
||||
* you do, it will be stored in the {@link setContainer() container}.
|
||||
* You can use this method to determine if a value was stored.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function hasResource($name)
|
||||
{
|
||||
$resource = strtolower($name);
|
||||
$container = $this->getContainer();
|
||||
return isset($container->{$resource});
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a resource from the container
|
||||
*
|
||||
* During bootstrap resource initialization, you may return a value. If
|
||||
* you do, it will be stored in the {@link setContainer() container}.
|
||||
* You can use this method to retrieve that value.
|
||||
*
|
||||
* If no value was returned, this will return a null value.
|
||||
*
|
||||
* @param string $name
|
||||
* @return null|mixed
|
||||
*/
|
||||
public function getResource($name)
|
||||
{
|
||||
$resource = strtolower($name);
|
||||
$container = $this->getContainer();
|
||||
if ($this->hasResource($resource)) {
|
||||
return $container->{$resource};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement PHP's magic to retrieve a ressource
|
||||
* in the bootstrap
|
||||
*
|
||||
* @param string $prop
|
||||
* @return null|mixed
|
||||
*/
|
||||
public function __get($prop)
|
||||
{
|
||||
return $this->getResource($prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implement PHP's magic to ask for the
|
||||
* existence of a ressource in the bootstrap
|
||||
*
|
||||
* @param string $prop
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($prop)
|
||||
{
|
||||
return $this->hasResource($prop);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap individual, all, or multiple resources
|
||||
*
|
||||
* Marked as final to prevent issues when subclassing and naming the
|
||||
* child class 'Bootstrap' (in which case, overriding this method
|
||||
* would result in it being treated as a constructor).
|
||||
*
|
||||
* If you need to override this functionality, override the
|
||||
* {@link _bootstrap()} method.
|
||||
*
|
||||
* @param null|string|array $resource
|
||||
* @return Zend_Application_Bootstrap_BootstrapAbstract
|
||||
* @throws Zend_Application_Bootstrap_Exception When invalid argument was passed
|
||||
*/
|
||||
final public function bootstrap($resource = null)
|
||||
{
|
||||
$this->_bootstrap($resource);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Overloading: intercept calls to bootstrap<resourcename>() methods
|
||||
*
|
||||
* @param string $method
|
||||
* @param array $args
|
||||
* @return void
|
||||
* @throws Zend_Application_Bootstrap_Exception On invalid method name
|
||||
*/
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (9 < strlen($method) && 'bootstrap' === substr($method, 0, 9)) {
|
||||
$resource = substr($method, 9);
|
||||
return $this->bootstrap($resource);
|
||||
}
|
||||
|
||||
throw new Zend_Application_Bootstrap_Exception('Invalid method "' . $method . '"');
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap implementation
|
||||
*
|
||||
* This method may be overridden to provide custom bootstrapping logic.
|
||||
* It is the sole method called by {@link bootstrap()}.
|
||||
*
|
||||
* @param null|string|array $resource
|
||||
* @return void
|
||||
* @throws Zend_Application_Bootstrap_Exception When invalid argument was passed
|
||||
*/
|
||||
protected function _bootstrap($resource = null)
|
||||
{
|
||||
if (null === $resource) {
|
||||
foreach ($this->getClassResourceNames() as $resource) {
|
||||
$this->_executeResource($resource);
|
||||
}
|
||||
|
||||
foreach ($this->getPluginResourceNames() as $resource) {
|
||||
$this->_executeResource($resource);
|
||||
}
|
||||
} elseif (is_string($resource)) {
|
||||
$this->_executeResource($resource);
|
||||
} elseif (is_array($resource)) {
|
||||
foreach ($resource as $r) {
|
||||
$this->_executeResource($r);
|
||||
}
|
||||
} else {
|
||||
throw new Zend_Application_Bootstrap_Exception('Invalid argument passed to ' . __METHOD__);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a resource
|
||||
*
|
||||
* Checks to see if the resource has already been run. If not, it searches
|
||||
* first to see if a local method matches the resource, and executes that.
|
||||
* If not, it checks to see if a plugin resource matches, and executes that
|
||||
* if found.
|
||||
*
|
||||
* Finally, if not found, it throws an exception.
|
||||
*
|
||||
* @param string $resource
|
||||
* @return void
|
||||
* @throws Zend_Application_Bootstrap_Exception When resource not found
|
||||
*/
|
||||
protected function _executeResource($resource)
|
||||
{
|
||||
$resourceName = strtolower($resource);
|
||||
|
||||
if (in_array($resourceName, $this->_run)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->_started[$resourceName]) && $this->_started[$resourceName]) {
|
||||
throw new Zend_Application_Bootstrap_Exception('Circular resource dependency detected');
|
||||
}
|
||||
|
||||
$classResources = $this->getClassResources();
|
||||
if (array_key_exists($resourceName, $classResources)) {
|
||||
$this->_started[$resourceName] = true;
|
||||
$method = $classResources[$resourceName];
|
||||
$return = $this->$method();
|
||||
unset($this->_started[$resourceName]);
|
||||
$this->_markRun($resourceName);
|
||||
|
||||
if (null !== $return) {
|
||||
$this->getContainer()->{$resourceName} = $return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->hasPluginResource($resource)) {
|
||||
$this->_started[$resourceName] = true;
|
||||
$plugin = $this->getPluginResource($resource);
|
||||
$return = $plugin->init();
|
||||
unset($this->_started[$resourceName]);
|
||||
$this->_markRun($resourceName);
|
||||
|
||||
if (null !== $return) {
|
||||
$this->getContainer()->{$resourceName} = $return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Zend_Application_Bootstrap_Exception('Resource matching "' . $resource . '" not found');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a plugin resource
|
||||
*
|
||||
* @param string $resource
|
||||
* @param array|object|null $options
|
||||
* @return string|false
|
||||
*/
|
||||
protected function _loadPluginResource($resource, $options)
|
||||
{
|
||||
$options = (array) $options;
|
||||
$options['bootstrap'] = $this;
|
||||
$className = $this->getPluginLoader()->load(strtolower($resource), false);
|
||||
|
||||
if (!$className) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$instance = new $className($options);
|
||||
|
||||
unset($this->_pluginResources[$resource]);
|
||||
|
||||
if (isset($instance->_explicitType)) {
|
||||
$resource = $instance->_explicitType;
|
||||
}
|
||||
$resource = strtolower($resource);
|
||||
$this->_pluginResources[$resource] = $instance;
|
||||
|
||||
return $resource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark a resource as having run
|
||||
*
|
||||
* @param string $resource
|
||||
* @return void
|
||||
*/
|
||||
protected function _markRun($resource)
|
||||
{
|
||||
if (!in_array($resource, $this->_run)) {
|
||||
$this->_run[] = $resource;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a plugin resource name
|
||||
*
|
||||
* Uses, in order of preference
|
||||
* - $_explicitType property of resource
|
||||
* - Short name of resource (if a matching prefix path is found)
|
||||
* - class name (if none of the above are true)
|
||||
*
|
||||
* The name is then cast to lowercase.
|
||||
*
|
||||
* @param Zend_Application_Resource_Resource $resource
|
||||
* @return string
|
||||
*/
|
||||
protected function _resolvePluginResourceName($resource)
|
||||
{
|
||||
if (isset($resource->_explicitType)) {
|
||||
$pluginName = $resource->_explicitType;
|
||||
} else {
|
||||
$className = get_class($resource);
|
||||
$pluginName = $className;
|
||||
$loader = $this->getPluginLoader();
|
||||
foreach ($loader->getPaths() as $prefix => $paths) {
|
||||
if (0 === strpos($className, $prefix)) {
|
||||
$pluginName = substr($className, strlen($prefix));
|
||||
$pluginName = trim($pluginName, '_');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$pluginName = strtolower($pluginName);
|
||||
return $pluginName;
|
||||
}
|
||||
}
|
||||
94
library/Zend/Application/Bootstrap/Bootstrapper.php
Normale Datei
94
library/Zend/Application/Bootstrap/Bootstrapper.php
Normale Datei
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for bootstrap classes
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Application_Bootstrap_Bootstrapper
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Application $application
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($application);
|
||||
|
||||
/**
|
||||
* Set bootstrap options
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
public function setOptions(array $options);
|
||||
|
||||
/**
|
||||
* Retrieve application object
|
||||
*
|
||||
* @return Zend_Application|Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
public function getApplication();
|
||||
|
||||
/**
|
||||
* Retrieve application environment
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEnvironment();
|
||||
|
||||
/**
|
||||
* Retrieve list of class resource initializers (_init* methods). Returns
|
||||
* as resource/method pairs.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClassResources();
|
||||
|
||||
/**
|
||||
* Retrieve list of class resource initializer names (resource names only,
|
||||
* no method names)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getClassResourceNames();
|
||||
|
||||
/**
|
||||
* Bootstrap application or individual resource
|
||||
*
|
||||
* @param null|string $resource
|
||||
* @return mixed
|
||||
*/
|
||||
public function bootstrap($resource = null);
|
||||
|
||||
/**
|
||||
* Run the application
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run();
|
||||
}
|
||||
38
library/Zend/Application/Bootstrap/Exception.php
Normale Datei
38
library/Zend/Application/Bootstrap/Exception.php
Normale Datei
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Exception
|
||||
*/
|
||||
require_once 'Zend/Application/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Application
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @uses Zend_Application_Exception
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Bootstrap_Exception extends Zend_Application_Exception
|
||||
{
|
||||
}
|
||||
95
library/Zend/Application/Bootstrap/ResourceBootstrapper.php
Normale Datei
95
library/Zend/Application/Bootstrap/ResourceBootstrapper.php
Normale Datei
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for bootstrap classes that utilize resource plugins
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Bootstrap
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
{
|
||||
/**
|
||||
* Register a resource with the bootstrap
|
||||
*
|
||||
* @param string|Zend_Application_Resource_Resource $resource
|
||||
* @param null|array|Zend_Config $options
|
||||
* @return Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
*/
|
||||
public function registerPluginResource($resource, $options = null);
|
||||
|
||||
/**
|
||||
* Unregister a resource from the bootstrap
|
||||
*
|
||||
* @param string|Zend_Application_Resource_Resource $resource
|
||||
* @return Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
*/
|
||||
public function unregisterPluginResource($resource);
|
||||
|
||||
/**
|
||||
* Is the requested resource registered?
|
||||
*
|
||||
* @param string $resource
|
||||
* @return bool
|
||||
*/
|
||||
public function hasPluginResource($resource);
|
||||
|
||||
/**
|
||||
* Retrieve resource
|
||||
*
|
||||
* @param string $resource
|
||||
* @return Zend_Application_Resource_Resource
|
||||
*/
|
||||
public function getPluginResource($resource);
|
||||
|
||||
/**
|
||||
* Get all resources
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPluginResources();
|
||||
|
||||
/**
|
||||
* Get just resource names
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPluginResourceNames();
|
||||
|
||||
/**
|
||||
* Set plugin loader to use to fetch resources
|
||||
*
|
||||
* @param Zend_Loader_PluginLoader_Interface Zend_Loader_PluginLoader
|
||||
* @return Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
*/
|
||||
public function setPluginLoader(Zend_Loader_PluginLoader_Interface $loader);
|
||||
|
||||
/**
|
||||
* Retrieve plugin loader for resources
|
||||
*
|
||||
* @return Zend_Loader_PluginLoader
|
||||
*/
|
||||
public function getPluginLoader();
|
||||
}
|
||||
38
library/Zend/Application/Exception.php
Normale Datei
38
library/Zend/Application/Exception.php
Normale Datei
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Application
|
||||
*
|
||||
* @uses Zend_Exception
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
||||
94
library/Zend/Application/Module/Autoloader.php
Normale Datei
94
library/Zend/Application/Module/Autoloader.php
Normale Datei
|
|
@ -0,0 +1,94 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Module
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id$
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/** @see Zend_Loader_Autoloader_Resource */
|
||||
require_once 'Zend/Loader/Autoloader/Resource.php';
|
||||
|
||||
/**
|
||||
* Resource loader for application module classes
|
||||
*
|
||||
* @uses Zend_Loader_Autoloader_Resource
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Module
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Module_Autoloader extends Zend_Loader_Autoloader_Resource
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array|Zend_Config $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options)
|
||||
{
|
||||
parent::__construct($options);
|
||||
$this->initDefaultResourceTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize default resource types for module resource classes
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initDefaultResourceTypes()
|
||||
{
|
||||
$basePath = $this->getBasePath();
|
||||
$this->addResourceTypes(array(
|
||||
'dbtable' => array(
|
||||
'namespace' => 'Model_DbTable',
|
||||
'path' => 'models/DbTable',
|
||||
),
|
||||
'mappers' => array(
|
||||
'namespace' => 'Model_Mapper',
|
||||
'path' => 'models/mappers',
|
||||
),
|
||||
'form' => array(
|
||||
'namespace' => 'Form',
|
||||
'path' => 'forms',
|
||||
),
|
||||
'model' => array(
|
||||
'namespace' => 'Model',
|
||||
'path' => 'models',
|
||||
),
|
||||
'plugin' => array(
|
||||
'namespace' => 'Plugin',
|
||||
'path' => 'plugins',
|
||||
),
|
||||
'service' => array(
|
||||
'namespace' => 'Service',
|
||||
'path' => 'services',
|
||||
),
|
||||
'viewhelper' => array(
|
||||
'namespace' => 'View_Helper',
|
||||
'path' => 'views/helpers',
|
||||
),
|
||||
'viewfilter' => array(
|
||||
'namespace' => 'View_Filter',
|
||||
'path' => 'views/filters',
|
||||
),
|
||||
));
|
||||
$this->setDefaultResourceType('model');
|
||||
}
|
||||
}
|
||||
128
library/Zend/Application/Module/Bootstrap.php
Normale Datei
128
library/Zend/Application/Module/Bootstrap.php
Normale Datei
|
|
@ -0,0 +1,128 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Module
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @version $Id$
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Bootstrap_Bootstrap
|
||||
*/
|
||||
require_once 'Zend/Application/Bootstrap/Bootstrap.php';
|
||||
|
||||
/**
|
||||
* Base bootstrap class for modules
|
||||
*
|
||||
* @uses Zend_Loader_Autoloader_Resource
|
||||
* @uses Zend_Application_Bootstrap_Bootstrap
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Module
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Application_Module_Bootstrap
|
||||
extends Zend_Application_Bootstrap_Bootstrap
|
||||
{
|
||||
/**
|
||||
* Set this explicitly to reduce impact of determining module name
|
||||
* @var string
|
||||
*/
|
||||
protected $_moduleName;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Application|Zend_Application_Bootstrap_Bootstrapper $application
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($application)
|
||||
{
|
||||
$this->setApplication($application);
|
||||
|
||||
// Use same plugin loader as parent bootstrap
|
||||
if ($application instanceof Zend_Application_Bootstrap_ResourceBootstrapper) {
|
||||
$this->setPluginLoader($application->getPluginLoader());
|
||||
}
|
||||
|
||||
$key = strtolower($this->getModuleName());
|
||||
if ($application->hasOption($key)) {
|
||||
// Don't run via setOptions() to prevent duplicate initialization
|
||||
$this->setOptions($application->getOption($key));
|
||||
}
|
||||
|
||||
if ($application->hasOption('resourceloader')) {
|
||||
$this->setOptions(array(
|
||||
'resourceloader' => $application->getOption('resourceloader')
|
||||
));
|
||||
}
|
||||
$this->initResourceLoader();
|
||||
|
||||
// ZF-6545: ensure front controller resource is loaded
|
||||
if (!$this->hasPluginResource('FrontController')) {
|
||||
$this->registerPluginResource('FrontController');
|
||||
}
|
||||
|
||||
// ZF-6545: prevent recursive registration of modules
|
||||
if ($this->hasPluginResource('modules')) {
|
||||
$this->unregisterPluginResource('modules');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure resource loader is loaded
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initResourceLoader()
|
||||
{
|
||||
$this->getResourceLoader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default application namespace
|
||||
*
|
||||
* Proxies to {@link getModuleName()}, and returns the current module
|
||||
* name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAppNamespace()
|
||||
{
|
||||
return $this->getModuleName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve module name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getModuleName()
|
||||
{
|
||||
if (empty($this->_moduleName)) {
|
||||
$class = get_class($this);
|
||||
if (preg_match('/^([a-z][a-z0-9]*)_/i', $class, $matches)) {
|
||||
$prefix = $matches[1];
|
||||
} else {
|
||||
$prefix = $class;
|
||||
}
|
||||
$this->_moduleName = $prefix;
|
||||
}
|
||||
return $this->_moduleName;
|
||||
}
|
||||
}
|
||||
73
library/Zend/Application/Resource/Cachemanager.php
Normale Datei
73
library/Zend/Application/Resource/Cachemanager.php
Normale Datei
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
/**
|
||||
* Cache Manager resource
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Cachemanager extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Cache_Manager
|
||||
*/
|
||||
protected $_manager = null;
|
||||
|
||||
/**
|
||||
* Initialize Cache_Manager
|
||||
*
|
||||
* @return Zend_Cache_Manager
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
return $this->getCacheManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Zend_Cache_Manager instance
|
||||
*
|
||||
* @return Zend_Cache_Manager
|
||||
*/
|
||||
public function getCacheManager()
|
||||
{
|
||||
if (null === $this->_manager) {
|
||||
$this->_manager = new Zend_Cache_Manager;
|
||||
|
||||
$options = $this->getOptions();
|
||||
foreach ($options as $key => $value) {
|
||||
if ($this->_manager->hasCacheTemplate($key)) {
|
||||
$this->_manager->setTemplateOptions($key, $value);
|
||||
} else {
|
||||
$this->_manager->setCacheTemplate($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_manager;
|
||||
}
|
||||
}
|
||||
193
library/Zend/Application/Resource/Db.php
Normale Datei
193
library/Zend/Application/Resource/Db.php
Normale Datei
|
|
@ -0,0 +1,193 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
/**
|
||||
* Resource for creating database adapter
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Db extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* Adapter to use
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_adapter = null;
|
||||
|
||||
/**
|
||||
* @var Zend_Db_Adapter_Interface
|
||||
*/
|
||||
protected $_db;
|
||||
|
||||
/**
|
||||
* Parameters to use
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_params = array();
|
||||
|
||||
/**
|
||||
* Wether to register the created adapter as default table adapter
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_isDefaultTableAdapter = true;
|
||||
|
||||
/**
|
||||
* Set the adapter
|
||||
*
|
||||
* @param string $adapter
|
||||
* @return Zend_Application_Resource_Db
|
||||
*/
|
||||
public function setAdapter($adapter)
|
||||
{
|
||||
$this->_adapter = $adapter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter type to use
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->_adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the adapter params
|
||||
*
|
||||
* @param string $adapter
|
||||
* @return Zend_Application_Resource_Db
|
||||
*/
|
||||
public function setParams(array $params)
|
||||
{
|
||||
$this->_params = $params;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapter parameters
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getParams()
|
||||
{
|
||||
return $this->_params;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to use this as default table adapter
|
||||
*
|
||||
* @param boolean $defaultTableAdapter
|
||||
* @return Zend_Application_Resource_Db
|
||||
*/
|
||||
public function setIsDefaultTableAdapter($isDefaultTableAdapter)
|
||||
{
|
||||
$this->_isDefaultTableAdapter = $isDefaultTableAdapter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this adapter the default table adapter?
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function isDefaultTableAdapter()
|
||||
{
|
||||
return $this->_isDefaultTableAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve initialized DB connection
|
||||
*
|
||||
* @return null|Zend_Db_Adapter_Interface
|
||||
*/
|
||||
public function getDbAdapter()
|
||||
{
|
||||
if ((null === $this->_db)
|
||||
&& (null !== ($adapter = $this->getAdapter()))
|
||||
) {
|
||||
$this->_db = Zend_Db::factory($adapter, $this->getParams());
|
||||
}
|
||||
return $this->_db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Db_Adapter_Abstract|null
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (null !== ($db = $this->getDbAdapter())) {
|
||||
if ($this->isDefaultTableAdapter()) {
|
||||
Zend_Db_Table::setDefaultAdapter($db);
|
||||
}
|
||||
return $db;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default metadata cache
|
||||
*
|
||||
* @param string|Zend_Cache_Core $cache
|
||||
* @return Zend_Application_Resource_Db
|
||||
*/
|
||||
public function setDefaultMetadataCache($cache)
|
||||
{
|
||||
$metadataCache = null;
|
||||
|
||||
if (is_string($cache)) {
|
||||
$bootstrap = $this->getBootstrap();
|
||||
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
&& $bootstrap->hasPluginResource('CacheManager')
|
||||
) {
|
||||
$cacheManager = $bootstrap->bootstrap('CacheManager')
|
||||
->getResource('CacheManager');
|
||||
if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
|
||||
$metadataCache = $cacheManager->getCache($cache);
|
||||
}
|
||||
}
|
||||
} else if ($cache instanceof Zend_Cache_Core) {
|
||||
$metadataCache = $cache;
|
||||
}
|
||||
|
||||
if ($metadataCache instanceof Zend_Cache_Core) {
|
||||
Zend_Db_Table::setDefaultMetadataCache($metadataCache);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
76
library/Zend/Application/Resource/Dojo.php
Normale Datei
76
library/Zend/Application/Resource/Dojo.php
Normale Datei
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for settings Dojo options
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Dojo
|
||||
extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Dojo_View_Helper_Dojo_Container
|
||||
*/
|
||||
protected $_dojo;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Dojo_View_Helper_Dojo_Container
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
return $this->getDojo();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve Dojo View Helper
|
||||
*
|
||||
* @return Zend_Dojo_View_Dojo_Container
|
||||
*/
|
||||
public function getDojo()
|
||||
{
|
||||
if (null === $this->_dojo) {
|
||||
$this->getBootstrap()->bootstrap('view');
|
||||
$view = $this->getBootstrap()->view;
|
||||
|
||||
Zend_Dojo::enableView($view);
|
||||
$view->dojo()->setOptions($this->getOptions());
|
||||
|
||||
$this->_dojo = $view->dojo();
|
||||
}
|
||||
|
||||
return $this->_dojo;
|
||||
}
|
||||
}
|
||||
40
library/Zend/Application/Resource/Exception.php
Normale Datei
40
library/Zend/Application/Resource/Exception.php
Normale Datei
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Exception
|
||||
*/
|
||||
require_once 'Zend/Application/Exception.php';
|
||||
|
||||
/**
|
||||
* Exception class for Zend_Application
|
||||
*
|
||||
* @uses Zend_Application_Exception
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Exception extends Zend_Application_Exception
|
||||
{
|
||||
}
|
||||
163
library/Zend/Application/Resource/Frontcontroller.php
Normale Datei
163
library/Zend/Application/Resource/Frontcontroller.php
Normale Datei
|
|
@ -0,0 +1,163 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Front Controller resource
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Frontcontroller extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Controller_Front
|
||||
*/
|
||||
protected $_front;
|
||||
|
||||
/**
|
||||
* Initialize Front Controller
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$front = $this->getFrontController();
|
||||
|
||||
foreach ($this->getOptions() as $key => $value) {
|
||||
switch (strtolower($key)) {
|
||||
case 'controllerdirectory':
|
||||
if (is_string($value)) {
|
||||
$front->setControllerDirectory($value);
|
||||
} elseif (is_array($value)) {
|
||||
foreach ($value as $module => $directory) {
|
||||
$front->addControllerDirectory($directory, $module);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'modulecontrollerdirectoryname':
|
||||
$front->setModuleControllerDirectoryName($value);
|
||||
break;
|
||||
|
||||
case 'moduledirectory':
|
||||
if (is_string($value)) {
|
||||
$front->addModuleDirectory($value);
|
||||
} elseif (is_array($value)) {
|
||||
foreach($value as $moduleDir) {
|
||||
$front->addModuleDirectory($moduleDir);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'defaultcontrollername':
|
||||
$front->setDefaultControllerName($value);
|
||||
break;
|
||||
|
||||
case 'defaultaction':
|
||||
$front->setDefaultAction($value);
|
||||
break;
|
||||
|
||||
case 'defaultmodule':
|
||||
$front->setDefaultModule($value);
|
||||
break;
|
||||
|
||||
case 'baseurl':
|
||||
if (!empty($value)) {
|
||||
$front->setBaseUrl($value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'params':
|
||||
$front->setParams($value);
|
||||
break;
|
||||
|
||||
case 'plugins':
|
||||
foreach ((array) $value as $pluginClass) {
|
||||
$stackIndex = null;
|
||||
if(is_array($pluginClass)) {
|
||||
$pluginClass = array_change_key_case($pluginClass, CASE_LOWER);
|
||||
if(isset($pluginClass['class']))
|
||||
{
|
||||
if(isset($pluginClass['stackindex'])) {
|
||||
$stackIndex = $pluginClass['stackindex'];
|
||||
}
|
||||
|
||||
$pluginClass = $pluginClass['class'];
|
||||
}
|
||||
}
|
||||
|
||||
$plugin = new $pluginClass();
|
||||
$front->registerPlugin($plugin, $stackIndex);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'returnresponse':
|
||||
$front->returnResponse((bool) $value);
|
||||
break;
|
||||
|
||||
case 'throwexceptions':
|
||||
$front->throwExceptions((bool) $value);
|
||||
break;
|
||||
|
||||
case 'actionhelperpaths':
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $helperPrefix => $helperPath) {
|
||||
Zend_Controller_Action_HelperBroker::addPath($helperPath, $helperPrefix);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
$front->setParam($key, $value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (null !== ($bootstrap = $this->getBootstrap())) {
|
||||
$this->getBootstrap()->frontController = $front;
|
||||
}
|
||||
|
||||
return $front;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve front controller instance
|
||||
*
|
||||
* @return Zend_Controller_Front
|
||||
*/
|
||||
public function getFrontController()
|
||||
{
|
||||
if (null === $this->_front) {
|
||||
$this->_front = Zend_Controller_Front::getInstance();
|
||||
}
|
||||
return $this->_front;
|
||||
}
|
||||
}
|
||||
70
library/Zend/Application/Resource/Layout.php
Normale Datei
70
library/Zend/Application/Resource/Layout.php
Normale Datei
|
|
@ -0,0 +1,70 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for settings layout options
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Layout
|
||||
extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Layout
|
||||
*/
|
||||
protected $_layout;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Layout
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$this->getBootstrap()->bootstrap('FrontController');
|
||||
return $this->getLayout();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve layout object
|
||||
*
|
||||
* @return Zend_Layout
|
||||
*/
|
||||
public function getLayout()
|
||||
{
|
||||
if (null === $this->_layout) {
|
||||
$this->_layout = Zend_Layout::startMvc($this->getOptions());
|
||||
}
|
||||
return $this->_layout;
|
||||
}
|
||||
}
|
||||
117
library/Zend/Application/Resource/Locale.php
Normale Datei
117
library/Zend/Application/Resource/Locale.php
Normale Datei
|
|
@ -0,0 +1,117 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for initializing the locale
|
||||
*
|
||||
* @uses Zend_Application_Resource_Base
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Locale
|
||||
extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
const DEFAULT_REGISTRY_KEY = 'Zend_Locale';
|
||||
|
||||
/**
|
||||
* @var Zend_Locale
|
||||
*/
|
||||
protected $_locale;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Locale
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
return $this->getLocale();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve locale object
|
||||
*
|
||||
* @return Zend_Locale
|
||||
*/
|
||||
public function getLocale()
|
||||
{
|
||||
if (null === $this->_locale) {
|
||||
$options = $this->getOptions();
|
||||
|
||||
if (!isset($options['default'])) {
|
||||
$this->_locale = new Zend_Locale();
|
||||
} elseif(!isset($options['force']) ||
|
||||
(bool) $options['force'] == false)
|
||||
{
|
||||
// Don't force any locale, just go for auto detection
|
||||
Zend_Locale::setDefault($options['default']);
|
||||
$this->_locale = new Zend_Locale();
|
||||
} else {
|
||||
$this->_locale = new Zend_Locale($options['default']);
|
||||
}
|
||||
|
||||
$key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
|
||||
? $options['registry_key']
|
||||
: self::DEFAULT_REGISTRY_KEY;
|
||||
Zend_Registry::set($key, $this->_locale);
|
||||
}
|
||||
|
||||
return $this->_locale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the cache
|
||||
*
|
||||
* @param string|Zend_Cache_Core $cache
|
||||
* @return Zend_Application_Resource_Locale
|
||||
*/
|
||||
public function setCache($cache)
|
||||
{
|
||||
if (is_string($cache)) {
|
||||
$bootstrap = $this->getBootstrap();
|
||||
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
&& $bootstrap->hasPluginResource('CacheManager')
|
||||
) {
|
||||
$cacheManager = $bootstrap->bootstrap('CacheManager')
|
||||
->getResource('CacheManager');
|
||||
if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
|
||||
$cache = $cacheManager->getCache($cache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($cache instanceof Zend_Cache_Core) {
|
||||
Zend_Locale::setCache($cache);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
78
library/Zend/Application/Resource/Log.php
Normale Datei
78
library/Zend/Application/Resource/Log.php
Normale Datei
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for initializing the locale
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Log
|
||||
extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Log
|
||||
*/
|
||||
protected $_log;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Log
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
return $this->getLog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach logger
|
||||
*
|
||||
* @param Zend_Log $log
|
||||
* @return Zend_Application_Resource_Log
|
||||
*/
|
||||
public function setLog(Zend_Log $log)
|
||||
{
|
||||
$this->_log = $log;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getLog()
|
||||
{
|
||||
if (null === $this->_log) {
|
||||
$options = $this->getOptions();
|
||||
$log = Zend_Log::factory($options);
|
||||
$this->setLog($log);
|
||||
}
|
||||
return $this->_log;
|
||||
}
|
||||
}
|
||||
146
library/Zend/Application/Resource/Mail.php
Normale Datei
146
library/Zend/Application/Resource/Mail.php
Normale Datei
|
|
@ -0,0 +1,146 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
/**
|
||||
* Resource for setting up Mail Transport and default From & ReplyTo addresses
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Mail extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Zend_Mail_Transport_Abstract
|
||||
*/
|
||||
protected $_transport;
|
||||
|
||||
public function init() {
|
||||
return $this->getMail();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Zend_Mail_Transport_Abstract|null
|
||||
*/
|
||||
public function getMail()
|
||||
{
|
||||
if (null === $this->_transport) {
|
||||
$options = $this->getOptions();
|
||||
foreach($options as $key => $option) {
|
||||
$options[strtolower($key)] = $option;
|
||||
}
|
||||
$this->setOptions($options);
|
||||
|
||||
if(isset($options['transport']) &&
|
||||
!is_numeric($options['transport']))
|
||||
{
|
||||
$this->_transport = $this->_setupTransport($options['transport']);
|
||||
if(!isset($options['transport']['register']) ||
|
||||
$options['transport']['register'] == '1' ||
|
||||
(isset($options['transport']['register']) &&
|
||||
!is_numeric($options['transport']['register']) &&
|
||||
(bool) $options['transport']['register'] == true))
|
||||
{
|
||||
Zend_Mail::setDefaultTransport($this->_transport);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_setDefaults('from');
|
||||
$this->_setDefaults('replyTo');
|
||||
}
|
||||
|
||||
return $this->_transport;
|
||||
}
|
||||
|
||||
protected function _setDefaults($type) {
|
||||
$key = strtolower('default' . $type);
|
||||
$options = $this->getOptions();
|
||||
|
||||
if(isset($options[$key]['email']) &&
|
||||
!is_numeric($options[$key]['email']))
|
||||
{
|
||||
$method = array('Zend_Mail', 'setDefault' . ucfirst($type));
|
||||
if(isset($options[$key]['name']) &&
|
||||
!is_numeric($options[$key]['name']))
|
||||
{
|
||||
call_user_func($method, $options[$key]['email'],
|
||||
$options[$key]['name']);
|
||||
} else {
|
||||
call_user_func($method, $options[$key]['email']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function _setupTransport($options)
|
||||
{
|
||||
if(!isset($options['type'])) {
|
||||
$options['type'] = 'sendmail';
|
||||
}
|
||||
|
||||
$transportName = $options['type'];
|
||||
if(!Zend_Loader_Autoloader::autoload($transportName))
|
||||
{
|
||||
$transportName = ucfirst(strtolower($transportName));
|
||||
|
||||
if(!Zend_Loader_Autoloader::autoload($transportName))
|
||||
{
|
||||
$transportName = 'Zend_Mail_Transport_' . $transportName;
|
||||
if(!Zend_Loader_Autoloader::autoload($transportName)) {
|
||||
throw new Zend_Application_Resource_Exception(
|
||||
"Specified Mail Transport '{$transportName}'"
|
||||
. 'could not be found'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($options['type']);
|
||||
|
||||
switch($transportName) {
|
||||
case 'Zend_Mail_Transport_Smtp':
|
||||
if(!isset($options['host'])) {
|
||||
throw new Zend_Application_Resource_Exception(
|
||||
'A host is necessary for smtp transport,'
|
||||
.' but none was given');
|
||||
}
|
||||
|
||||
$transport = new $transportName($options['host'], $options);
|
||||
break;
|
||||
case 'Zend_Mail_Transport_Sendmail':
|
||||
default:
|
||||
$transport = new $transportName($options);
|
||||
break;
|
||||
}
|
||||
|
||||
return $transport;
|
||||
}
|
||||
}
|
||||
138
library/Zend/Application/Resource/Modules.php
Normale Datei
138
library/Zend/Application/Resource/Modules.php
Normale Datei
|
|
@ -0,0 +1,138 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Module bootstrapping resource
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Modules extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var ArrayObject
|
||||
*/
|
||||
protected $_bootstraps;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param mixed $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
$this->_bootstraps = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize modules
|
||||
*
|
||||
* @return array
|
||||
* @throws Zend_Application_Resource_Exception When bootstrap class was not found
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$bootstrap = $this->getBootstrap();
|
||||
$bootstrap->bootstrap('FrontController');
|
||||
$front = $bootstrap->getResource('FrontController');
|
||||
|
||||
$modules = $front->getControllerDirectory();
|
||||
$default = $front->getDefaultModule();
|
||||
$curBootstrapClass = get_class($bootstrap);
|
||||
foreach ($modules as $module => $moduleDirectory) {
|
||||
$bootstrapClass = $this->_formatModuleName($module) . '_Bootstrap';
|
||||
if (!class_exists($bootstrapClass, false)) {
|
||||
$bootstrapPath = dirname($moduleDirectory) . '/Bootstrap.php';
|
||||
if (file_exists($bootstrapPath)) {
|
||||
$eMsgTpl = 'Bootstrap file found for module "%s" but bootstrap class "%s" not found';
|
||||
include_once $bootstrapPath;
|
||||
if (($default != $module)
|
||||
&& !class_exists($bootstrapClass, false)
|
||||
) {
|
||||
throw new Zend_Application_Resource_Exception(sprintf(
|
||||
$eMsgTpl, $module, $bootstrapClass
|
||||
));
|
||||
} elseif ($default == $module) {
|
||||
if (!class_exists($bootstrapClass, false)) {
|
||||
$bootstrapClass = 'Bootstrap';
|
||||
if (!class_exists($bootstrapClass, false)) {
|
||||
throw new Zend_Application_Resource_Exception(sprintf(
|
||||
$eMsgTpl, $module, $bootstrapClass
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ($bootstrapClass == $curBootstrapClass) {
|
||||
// If the found bootstrap class matches the one calling this
|
||||
// resource, don't re-execute.
|
||||
continue;
|
||||
}
|
||||
|
||||
$moduleBootstrap = new $bootstrapClass($bootstrap);
|
||||
$moduleBootstrap->bootstrap();
|
||||
$this->_bootstraps[$module] = $moduleBootstrap;
|
||||
}
|
||||
|
||||
return $this->_bootstraps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get bootstraps that have been run
|
||||
*
|
||||
* @return ArrayObject
|
||||
*/
|
||||
public function getExecutedBootstraps()
|
||||
{
|
||||
return $this->_bootstraps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a module name to the module class prefix
|
||||
*
|
||||
* @param string $name
|
||||
* @return string
|
||||
*/
|
||||
protected function _formatModuleName($name)
|
||||
{
|
||||
$name = strtolower($name);
|
||||
$name = str_replace(array('-', '.'), ' ', $name);
|
||||
$name = ucwords($name);
|
||||
$name = str_replace(' ', '', $name);
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
210
library/Zend/Application/Resource/Multidb.php
Normale Datei
210
library/Zend/Application/Resource/Multidb.php
Normale Datei
|
|
@ -0,0 +1,210 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
require_once 'Zend/Db/Table.php';
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cache Manager resource
|
||||
*
|
||||
* Example configuration:
|
||||
* <pre>
|
||||
* resources.multidb.defaultMetadataCache = "database"
|
||||
*
|
||||
* resources.multidb.db1.adapter = "pdo_mysql"
|
||||
* resources.multidb.db1.host = "localhost"
|
||||
* resources.multidb.db1.username = "webuser"
|
||||
* resources.multidb.db1.password = "XXXX"
|
||||
* resources.multidb.db1.dbname = "db1"
|
||||
* resources.multidb.db1.default = true
|
||||
*
|
||||
* resources.multidb.db2.adapter = "pdo_pgsql"
|
||||
* resources.multidb.db2.host = "example.com"
|
||||
* resources.multidb.db2.username = "dba"
|
||||
* resources.multidb.db2.password = "notthatpublic"
|
||||
* resources.multidb.db2.dbname = "db2"
|
||||
* </pre>
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Multidb extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* Associative array containing all configured db's
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_dbs = array();
|
||||
|
||||
/**
|
||||
* An instance of the default db, if set
|
||||
*
|
||||
* @var null|Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
protected $_defaultDb;
|
||||
|
||||
/**
|
||||
* Initialize the Database Connections (instances of Zend_Db_Table_Abstract)
|
||||
*
|
||||
* @return Zend_Application_Resource_Multidb
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
|
||||
if (isset($options['defaultMetadataCache'])) {
|
||||
$this->_setDefaultMetadataCache($options['defaultMetadataCache']);
|
||||
unset($options['defaultMetadataCache']);
|
||||
}
|
||||
|
||||
foreach ($options as $id => $params) {
|
||||
$adapter = $params['adapter'];
|
||||
$default = (int) (
|
||||
isset($params['isDefaultTableAdapter']) && $params['isDefaultTableAdapter']
|
||||
|| isset($params['default']) && $params['default']
|
||||
);
|
||||
unset(
|
||||
$params['adapter'],
|
||||
$params['default'],
|
||||
$params['isDefaultTableAdapter']
|
||||
);
|
||||
|
||||
$this->_dbs[$id] = Zend_Db::factory($adapter, $params);
|
||||
|
||||
if ($default) {
|
||||
$this->_setDefault($this->_dbs[$id]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given db(identifier) is the default db.
|
||||
*
|
||||
* @param string|Zend_Db_Adapter_Abstract $db The db to determine whether it's set as default
|
||||
* @return boolean True if the given parameter is configured as default. False otherwise
|
||||
*/
|
||||
public function isDefault($db)
|
||||
{
|
||||
if(!$db instanceof Zend_Db_Adapter_Abstract) {
|
||||
$db = $this->getDb($db);
|
||||
}
|
||||
|
||||
return $db === $this->_defaultDb;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the specified database connection
|
||||
*
|
||||
* @param null|string|Zend_Db_Adapter_Abstract $db The adapter to retrieve.
|
||||
* Null to retrieve the default connection
|
||||
* @return Zend_Db_Adapter_Abstract
|
||||
* @throws Zend_Application_Resource_Exception if the given parameter could not be found
|
||||
*/
|
||||
public function getDb($db = null)
|
||||
{
|
||||
if ($db === null) {
|
||||
return $this->getDefaultDb();
|
||||
}
|
||||
|
||||
if (isset($this->_dbs[$db])) {
|
||||
return $this->_dbs[$db];
|
||||
}
|
||||
|
||||
throw new Zend_Application_Resource_Exception(
|
||||
'A DB adapter was tried to retrieve, but was not configured'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default db connection
|
||||
*
|
||||
* @param boolean $justPickOne If true, a random (the first one in the stack)
|
||||
* connection is returned if no default was set.
|
||||
* If false, null is returned if no default was set.
|
||||
* @return null|Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function getDefaultDb($justPickOne = true)
|
||||
{
|
||||
if ($this->_defaultDb !== null) {
|
||||
return $this->_defaultDb;
|
||||
}
|
||||
|
||||
if ($justPickOne) {
|
||||
return reset($this->_dbs); // Return first db in db pool
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default db adapter
|
||||
*
|
||||
* @var Zend_Db_Adapter_Abstract $adapter Adapter to set as default
|
||||
*/
|
||||
protected function _setDefault(Zend_Db_Adapter_Abstract $adapter)
|
||||
{
|
||||
Zend_Db_Table::setDefaultAdapter($adapter);
|
||||
$this->_defaultDb = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default metadata cache
|
||||
*
|
||||
* @param string|Zend_Cache_Core $cache
|
||||
* @return Zend_Application_Resource_Multidb
|
||||
*/
|
||||
protected function _setDefaultMetadataCache($cache)
|
||||
{
|
||||
$metadataCache = null;
|
||||
|
||||
if (is_string($cache)) {
|
||||
$bootstrap = $this->getBootstrap();
|
||||
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
|
||||
$bootstrap->hasPluginResource('CacheManager')
|
||||
) {
|
||||
$cacheManager = $bootstrap->bootstrap('CacheManager')
|
||||
->getResource('CacheManager');
|
||||
if (null !== $cacheManager && $cacheManager->hasCache($cache)) {
|
||||
$metadataCache = $cacheManager->getCache($cache);
|
||||
}
|
||||
}
|
||||
} else if ($cache instanceof Zend_Cache_Core) {
|
||||
$metadataCache = $cache;
|
||||
}
|
||||
|
||||
if ($metadataCache instanceof Zend_Cache_Core) {
|
||||
Zend_Db_Table::setDefaultMetadataCache($metadataCache);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
127
library/Zend/Application/Resource/Navigation.php
Normale Datei
127
library/Zend/Application/Resource/Navigation.php
Normale Datei
|
|
@ -0,0 +1,127 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for setting navigation structure
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @author Dolf Schimmel
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Navigation
|
||||
extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
const DEFAULT_REGISTRY_KEY = 'Zend_Navigation';
|
||||
|
||||
/**
|
||||
* @var Zend_Navigation
|
||||
*/
|
||||
protected $_container;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Navigation
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (!$this->_container) {
|
||||
$options = $this->getOptions();
|
||||
$pages = isset($options['pages']) ? $options['pages'] : array();
|
||||
$this->_container = new Zend_Navigation($pages);
|
||||
|
||||
if(isset($options['defaultPageType'])) {
|
||||
Zend_Navigation_Page::setDefaultPageType($options['defaultPageType']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->store();
|
||||
return $this->_container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores navigation container in registry or Navigation view helper
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function store()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
if (isset($options['storage']['registry']) &&
|
||||
$options['storage']['registry'] == true) {
|
||||
$this->_storeRegistry();
|
||||
} else {
|
||||
$this->_storeHelper();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores navigation container in the registry
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _storeRegistry()
|
||||
{
|
||||
$options = $this->getOptions();
|
||||
if(isset($options['storage']['registry']['key']) &&
|
||||
!is_numeric($options['storage']['registry']['key'])) // see ZF-7461
|
||||
{
|
||||
$key = $options['storage']['registry']['key'];
|
||||
} else {
|
||||
$key = self::DEFAULT_REGISTRY_KEY;
|
||||
}
|
||||
|
||||
Zend_Registry::set($key,$this->getContainer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores navigation container in the Navigation helper
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _storeHelper()
|
||||
{
|
||||
$this->getBootstrap()->bootstrap('view');
|
||||
$view = $this->getBootstrap()->view;
|
||||
$view->getHelper('navigation')->navigation($this->getContainer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns navigation container
|
||||
*
|
||||
* @return Zend_Navigation
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
return $this->_container;
|
||||
}
|
||||
}
|
||||
80
library/Zend/Application/Resource/Resource.php
Normale Datei
80
library/Zend/Application/Resource/Resource.php
Normale Datei
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Interface for bootstrap resources
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Application_Resource_Resource
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Must take an optional single argument, $options.
|
||||
*
|
||||
* @param mixed $options
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($options = null);
|
||||
|
||||
/**
|
||||
* Set the bootstrap to which the resource is attached
|
||||
*
|
||||
* @param Zend_Application_Bootstrap_Bootstrapper $bootstrap
|
||||
* @return Zend_Application_Resource_Resource
|
||||
*/
|
||||
public function setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap);
|
||||
|
||||
/**
|
||||
* Retrieve the bootstrap to which the resource is attached
|
||||
*
|
||||
* @return Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
public function getBootstrap();
|
||||
|
||||
/**
|
||||
* Set resource options
|
||||
*
|
||||
* @param array $options
|
||||
* @return Zend_Application_Resource_Resource
|
||||
*/
|
||||
public function setOptions(array $options);
|
||||
|
||||
/**
|
||||
* Retrieve resource options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions();
|
||||
|
||||
/**
|
||||
* Strategy pattern: initialize resource
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function init();
|
||||
}
|
||||
161
library/Zend/Application/Resource/ResourceAbstract.php
Normale Datei
161
library/Zend/Application/Resource/ResourceAbstract.php
Normale Datei
|
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_Resource
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/Resource.php';
|
||||
|
||||
/**
|
||||
* Abstract class for bootstrap resources
|
||||
*
|
||||
* @uses Zend_Application_Resource_Resource
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Application_Resource_ResourceAbstract implements Zend_Application_Resource_Resource
|
||||
{
|
||||
/**
|
||||
* Parent bootstrap
|
||||
*
|
||||
* @var Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
protected $_bootstrap;
|
||||
|
||||
/**
|
||||
* Options for the resource
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Option keys to skip when calling setOptions()
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_skipOptions = array(
|
||||
'options',
|
||||
'config',
|
||||
);
|
||||
|
||||
/**
|
||||
* Create a instance with options
|
||||
*
|
||||
* @param mixed $options
|
||||
*/
|
||||
public function __construct($options = null)
|
||||
{
|
||||
if (is_array($options)) {
|
||||
$this->setOptions($options);
|
||||
} else if ($options instanceof Zend_Config) {
|
||||
$this->setOptions($options->toArray());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set options from array
|
||||
*
|
||||
* @param array $options Configuration for resource
|
||||
* @return Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
public function setOptions(array $options)
|
||||
{
|
||||
if (array_key_exists('bootstrap', $options)) {
|
||||
$this->setBootstrap($options['bootstrap']);
|
||||
unset($options['bootstrap']);
|
||||
}
|
||||
|
||||
foreach ($options as $key => $value) {
|
||||
if (in_array(strtolower($key), $this->_skipOptions)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$method = 'set' . strtolower($key);
|
||||
if (method_exists($this, $method)) {
|
||||
$this->$method($value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->_options = $this->mergeOptions($this->_options, $options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve resource options
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge options recursively
|
||||
*
|
||||
* @param array $array1
|
||||
* @param mixed $array2
|
||||
* @return array
|
||||
*/
|
||||
public function mergeOptions(array $array1, $array2 = null)
|
||||
{
|
||||
if (is_array($array2)) {
|
||||
foreach ($array2 as $key => $val) {
|
||||
if (is_array($array2[$key])) {
|
||||
$array1[$key] = (array_key_exists($key, $array1) && is_array($array1[$key]))
|
||||
? $this->mergeOptions($array1[$key], $array2[$key])
|
||||
: $array2[$key];
|
||||
} else {
|
||||
$array1[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $array1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the bootstrap to which the resource is attached
|
||||
*
|
||||
* @param Zend_Application_Bootstrap_Bootstrapper $bootstrap
|
||||
* @return Zend_Application_Resource_Resource
|
||||
*/
|
||||
public function setBootstrap(Zend_Application_Bootstrap_Bootstrapper $bootstrap)
|
||||
{
|
||||
$this->_bootstrap = $bootstrap;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the bootstrap to which the resource is attached
|
||||
*
|
||||
* @return null|Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
public function getBootstrap()
|
||||
{
|
||||
return $this->_bootstrap;
|
||||
}
|
||||
}
|
||||
87
library/Zend/Application/Resource/Router.php
Normale Datei
87
library/Zend/Application/Resource/Router.php
Normale Datei
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for initializing the locale
|
||||
*
|
||||
* @uses Zend_Application_Resource_Base
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Router
|
||||
extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
protected $_router;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
return $this->getRouter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve router object
|
||||
*
|
||||
* @return Zend_Controller_Router_Rewrite
|
||||
*/
|
||||
public function getRouter()
|
||||
{
|
||||
if (null === $this->_router) {
|
||||
$bootstrap = $this->getBootstrap();
|
||||
$bootstrap->bootstrap('FrontController');
|
||||
$this->_router = $bootstrap->getContainer()->frontcontroller->getRouter();
|
||||
|
||||
$options = $this->getOptions();
|
||||
if (!isset($options['routes'])) {
|
||||
$options['routes'] = array();
|
||||
}
|
||||
|
||||
if (isset($options['chainNameSeparator'])) {
|
||||
$this->_router->setChainNameSeparator($options['chainNameSeparator']);
|
||||
}
|
||||
|
||||
if (isset($options['useRequestParametersAsGlobal'])) {
|
||||
$this->_router->useRequestParametersAsGlobal($options['useRequestParametersAsGlobal']);
|
||||
}
|
||||
|
||||
$this->_router->addConfig(new Zend_Config($options['routes']));
|
||||
}
|
||||
|
||||
return $this->_router;
|
||||
}
|
||||
}
|
||||
118
library/Zend/Application/Resource/Session.php
Normale Datei
118
library/Zend/Application/Resource/Session.php
Normale Datei
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for setting session options
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Session extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* Save handler to use
|
||||
*
|
||||
* @var Zend_Session_SaveHandler_Interface
|
||||
*/
|
||||
protected $_saveHandler = null;
|
||||
|
||||
/**
|
||||
* Set session save handler
|
||||
*
|
||||
* @param array|string|Zend_Session_SaveHandler_Interface $saveHandler
|
||||
* @return Zend_Application_Resource_Session
|
||||
* @throws Zend_Application_Resource_Exception When $saveHandler is no valid save handler
|
||||
*/
|
||||
public function setSaveHandler($saveHandler)
|
||||
{
|
||||
$this->_saveHandler = $saveHandler;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session save handler
|
||||
*
|
||||
* @return Zend_Session_SaveHandler_Interface
|
||||
*/
|
||||
public function getSaveHandler()
|
||||
{
|
||||
if (!$this->_saveHandler instanceof Zend_Session_SaveHandler_Interface) {
|
||||
if (is_array($this->_saveHandler)) {
|
||||
if (!array_key_exists('class', $this->_saveHandler)) {
|
||||
throw new Zend_Application_Resource_Exception('Session save handler class not provided in options');
|
||||
}
|
||||
$options = array();
|
||||
if (array_key_exists('options', $this->_saveHandler)) {
|
||||
$options = $this->_saveHandler['options'];
|
||||
}
|
||||
$this->_saveHandler = $this->_saveHandler['class'];
|
||||
$this->_saveHandler = new $this->_saveHandler($options);
|
||||
} elseif (is_string($this->_saveHandler)) {
|
||||
$this->_saveHandler = new $this->_saveHandler();
|
||||
}
|
||||
|
||||
if (!$this->_saveHandler instanceof Zend_Session_SaveHandler_Interface) {
|
||||
throw new Zend_Application_Resource_Exception('Invalid session save handler');
|
||||
}
|
||||
}
|
||||
return $this->_saveHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function _hasSaveHandler()
|
||||
{
|
||||
return ($this->_saveHandler !== null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$options = array_change_key_case($this->getOptions(), CASE_LOWER);
|
||||
if (isset($options['savehandler'])) {
|
||||
unset($options['savehandler']);
|
||||
}
|
||||
|
||||
if (count($options) > 0) {
|
||||
Zend_Session::setOptions($options);
|
||||
}
|
||||
|
||||
if ($this->_hasSaveHandler()) {
|
||||
Zend_Session::setSaveHandler($this->getSaveHandler());
|
||||
}
|
||||
}
|
||||
}
|
||||
134
library/Zend/Application/Resource/Translate.php
Normale Datei
134
library/Zend/Application/Resource/Translate.php
Normale Datei
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for setting translation options
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_Translate extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
const DEFAULT_REGISTRY_KEY = 'Zend_Translate';
|
||||
|
||||
/**
|
||||
* @var Zend_Translate
|
||||
*/
|
||||
protected $_translate;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Translate
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
return $this->getTranslate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve translate object
|
||||
*
|
||||
* @return Zend_Translate
|
||||
* @throws Zend_Application_Resource_Exception if registry key was used
|
||||
* already but is no instance of Zend_Translate
|
||||
*/
|
||||
public function getTranslate()
|
||||
{
|
||||
if (null === $this->_translate) {
|
||||
$options = $this->getOptions();
|
||||
|
||||
if (!isset($options['content']) && !isset($options['data'])) {
|
||||
require_once 'Zend/Application/Resource/Exception.php';
|
||||
throw new Zend_Application_Resource_Exception('No translation source data provided.');
|
||||
} else if (array_key_exists('content', $options) && array_key_exists('data', $options)) {
|
||||
require_once 'Zend/Application/Resource/Exception.php';
|
||||
throw new Zend_Application_Resource_Exception(
|
||||
'Conflict on translation source data: choose only one key between content and data.'
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($options['adapter'])) {
|
||||
$options['adapter'] = Zend_Translate::AN_ARRAY;
|
||||
}
|
||||
|
||||
if (!empty($options['data'])) {
|
||||
$options['content'] = $options['data'];
|
||||
unset($options['data']);
|
||||
}
|
||||
|
||||
if (isset($options['options'])) {
|
||||
foreach($options['options'] as $key => $value) {
|
||||
$options[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($options['cache']) && is_string($options['cache'])) {
|
||||
$bootstrap = $this->getBootstrap();
|
||||
if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
|
||||
$bootstrap->hasPluginResource('CacheManager')
|
||||
) {
|
||||
$cacheManager = $bootstrap->bootstrap('CacheManager')
|
||||
->getResource('CacheManager');
|
||||
if (null !== $cacheManager &&
|
||||
$cacheManager->hasCache($options['cache'])
|
||||
) {
|
||||
$options['cache'] = $cacheManager->getCache($options['cache']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
|
||||
? $options['registry_key']
|
||||
: self::DEFAULT_REGISTRY_KEY;
|
||||
unset($options['registry_key']);
|
||||
|
||||
if(Zend_Registry::isRegistered($key)) {
|
||||
$translate = Zend_Registry::get($key);
|
||||
if(!$translate instanceof Zend_Translate) {
|
||||
require_once 'Zend/Application/Resource/Exception.php';
|
||||
throw new Zend_Application_Resource_Exception($key
|
||||
. ' already registered in registry but is '
|
||||
. 'no instance of Zend_Translate');
|
||||
}
|
||||
|
||||
$translate->addTranslation($options);
|
||||
$this->_translate = $translate;
|
||||
} else {
|
||||
$this->_translate = new Zend_Translate($options);
|
||||
Zend_Registry::set($key, $this->_translate);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_translate;
|
||||
}
|
||||
}
|
||||
72
library/Zend/Application/Resource/Useragent.php
Normale Datei
72
library/Zend/Application/Resource/Useragent.php
Normale Datei
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_UserAgent extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_Http_UserAgent
|
||||
*/
|
||||
protected $_userAgent;
|
||||
|
||||
/**
|
||||
* Intialize resource
|
||||
*
|
||||
* @return Zend_Http_UserAgent
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$userAgent = $this->getUserAgent();
|
||||
|
||||
// Optionally seed the UserAgent view helper
|
||||
$bootstrap = $this->getBootstrap();
|
||||
if ($bootstrap->hasResource('view') || $bootstrap->hasPluginResource('view')) {
|
||||
$bootstrap->bootstrap('view');
|
||||
$view = $bootstrap->getResource('view');
|
||||
if (null !== $view) {
|
||||
$view->userAgent($userAgent);
|
||||
}
|
||||
}
|
||||
|
||||
return $userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get UserAgent instance
|
||||
*
|
||||
* @return Zend_Http_UserAgent
|
||||
*/
|
||||
public function getUserAgent()
|
||||
{
|
||||
if (null === $this->_userAgent) {
|
||||
$options = $this->getOptions();
|
||||
$this->_userAgent = new Zend_Http_UserAgent($options);
|
||||
}
|
||||
|
||||
return $this->_userAgent;
|
||||
}
|
||||
}
|
||||
84
library/Zend/Application/Resource/View.php
Normale Datei
84
library/Zend/Application/Resource/View.php
Normale Datei
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Resource_ResourceAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Resource/ResourceAbstract.php';
|
||||
|
||||
|
||||
/**
|
||||
* Resource for settings view options
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Application_Resource_View extends Zend_Application_Resource_ResourceAbstract
|
||||
{
|
||||
/**
|
||||
* @var Zend_View_Interface
|
||||
*/
|
||||
protected $_view;
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_View
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
$view = $this->getView();
|
||||
|
||||
$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();
|
||||
$viewRenderer->setView($view);
|
||||
Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve view object
|
||||
*
|
||||
* @return Zend_View
|
||||
*/
|
||||
public function getView()
|
||||
{
|
||||
if (null === $this->_view) {
|
||||
$options = $this->getOptions();
|
||||
$this->_view = new Zend_View($options);
|
||||
|
||||
if (isset($options['doctype'])) {
|
||||
$this->_view->doctype()->setDoctype(strtoupper($options['doctype']));
|
||||
if (isset($options['charset']) && $this->_view->doctype()->isHtml5()) {
|
||||
$this->_view->headMeta()->setCharset($options['charset']);
|
||||
}
|
||||
}
|
||||
if (isset($options['contentType'])) {
|
||||
$this->_view->headMeta()->appendHttpEquiv('Content-Type', $options['contentType']);
|
||||
}
|
||||
}
|
||||
return $this->_view;
|
||||
}
|
||||
}
|
||||
169
library/Zend/Auth.php
Normale Datei
169
library/Zend/Auth.php
Normale Datei
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth
|
||||
{
|
||||
/**
|
||||
* Singleton instance
|
||||
*
|
||||
* @var Zend_Auth
|
||||
*/
|
||||
protected static $_instance = null;
|
||||
|
||||
/**
|
||||
* Persistent storage handler
|
||||
*
|
||||
* @var Zend_Auth_Storage_Interface
|
||||
*/
|
||||
protected $_storage = null;
|
||||
|
||||
/**
|
||||
* Singleton pattern implementation makes "new" unavailable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __construct()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Singleton pattern implementation makes "clone" unavailable
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function __clone()
|
||||
{}
|
||||
|
||||
/**
|
||||
* Returns an instance of Zend_Auth
|
||||
*
|
||||
* Singleton pattern implementation
|
||||
*
|
||||
* @return Zend_Auth Provides a fluent interface
|
||||
*/
|
||||
public static function getInstance()
|
||||
{
|
||||
if (null === self::$_instance) {
|
||||
self::$_instance = new self();
|
||||
}
|
||||
|
||||
return self::$_instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the persistent storage handler
|
||||
*
|
||||
* Session storage is used by default unless a different storage adapter has been set.
|
||||
*
|
||||
* @return Zend_Auth_Storage_Interface
|
||||
*/
|
||||
public function getStorage()
|
||||
{
|
||||
if (null === $this->_storage) {
|
||||
/**
|
||||
* @see Zend_Auth_Storage_Session
|
||||
*/
|
||||
require_once 'Zend/Auth/Storage/Session.php';
|
||||
$this->setStorage(new Zend_Auth_Storage_Session());
|
||||
}
|
||||
|
||||
return $this->_storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the persistent storage handler
|
||||
*
|
||||
* @param Zend_Auth_Storage_Interface $storage
|
||||
* @return Zend_Auth Provides a fluent interface
|
||||
*/
|
||||
public function setStorage(Zend_Auth_Storage_Interface $storage)
|
||||
{
|
||||
$this->_storage = $storage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates against the supplied adapter
|
||||
*
|
||||
* @param Zend_Auth_Adapter_Interface $adapter
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate(Zend_Auth_Adapter_Interface $adapter)
|
||||
{
|
||||
$result = $adapter->authenticate();
|
||||
|
||||
/**
|
||||
* ZF-7546 - prevent multiple succesive calls from storing inconsistent results
|
||||
* Ensure storage has clean state
|
||||
*/
|
||||
if ($this->hasIdentity()) {
|
||||
$this->clearIdentity();
|
||||
}
|
||||
|
||||
if ($result->isValid()) {
|
||||
$this->getStorage()->write($result->getIdentity());
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if and only if an identity is available from storage
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function hasIdentity()
|
||||
{
|
||||
return !$this->getStorage()->isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identity from storage or null if no identity is available
|
||||
*
|
||||
* @return mixed|null
|
||||
*/
|
||||
public function getIdentity()
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
|
||||
if ($storage->isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $storage->read();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the identity from persistent storage
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clearIdentity()
|
||||
{
|
||||
$this->getStorage()->clear();
|
||||
}
|
||||
}
|
||||
561
library/Zend/Auth/Adapter/DbTable.php
Normale Datei
561
library/Zend/Auth/Adapter/DbTable.php
Normale Datei
|
|
@ -0,0 +1,561 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
require_once 'Zend/Db/Adapter/Abstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Result
|
||||
*/
|
||||
require_once 'Zend/Auth/Result.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_DbTable implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Database Connection
|
||||
*
|
||||
* @var Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
protected $_zendDb = null;
|
||||
|
||||
/**
|
||||
* @var Zend_Db_Select
|
||||
*/
|
||||
protected $_dbSelect = null;
|
||||
|
||||
/**
|
||||
* $_tableName - the table name to check
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_tableName = null;
|
||||
|
||||
/**
|
||||
* $_identityColumn - the column to use as the identity
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_identityColumn = null;
|
||||
|
||||
/**
|
||||
* $_credentialColumns - columns to be used as the credentials
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_credentialColumn = null;
|
||||
|
||||
/**
|
||||
* $_identity - Identity value
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_identity = null;
|
||||
|
||||
/**
|
||||
* $_credential - Credential values
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_credential = null;
|
||||
|
||||
/**
|
||||
* $_credentialTreatment - Treatment applied to the credential, such as MD5() or PASSWORD()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_credentialTreatment = null;
|
||||
|
||||
/**
|
||||
* $_authenticateResultInfo
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_authenticateResultInfo = null;
|
||||
|
||||
/**
|
||||
* $_resultRow - Results of database authentication query
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_resultRow = null;
|
||||
|
||||
/**
|
||||
* $_ambiguityIdentity - Flag to indicate same Identity can be used with
|
||||
* different credentials. Default is FALSE and need to be set to true to
|
||||
* allow ambiguity usage.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_ambiguityIdentity = false;
|
||||
|
||||
/**
|
||||
* __construct() - Sets configuration options
|
||||
*
|
||||
* @param Zend_Db_Adapter_Abstract $zendDb If null, default database adapter assumed
|
||||
* @param string $tableName
|
||||
* @param string $identityColumn
|
||||
* @param string $credentialColumn
|
||||
* @param string $credentialTreatment
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Db_Adapter_Abstract $zendDb = null, $tableName = null, $identityColumn = null,
|
||||
$credentialColumn = null, $credentialTreatment = null)
|
||||
{
|
||||
$this->_setDbAdapter($zendDb);
|
||||
|
||||
if (null !== $tableName) {
|
||||
$this->setTableName($tableName);
|
||||
}
|
||||
|
||||
if (null !== $identityColumn) {
|
||||
$this->setIdentityColumn($identityColumn);
|
||||
}
|
||||
|
||||
if (null !== $credentialColumn) {
|
||||
$this->setCredentialColumn($credentialColumn);
|
||||
}
|
||||
|
||||
if (null !== $credentialTreatment) {
|
||||
$this->setCredentialTreatment($credentialTreatment);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* _setDbAdapter() - set the database adapter to be used for quering
|
||||
*
|
||||
* @param Zend_Db_Adapter_Abstract
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Adapter_DbTable
|
||||
*/
|
||||
protected function _setDbAdapter(Zend_Db_Adapter_Abstract $zendDb = null)
|
||||
{
|
||||
$this->_zendDb = $zendDb;
|
||||
|
||||
/**
|
||||
* If no adapter is specified, fetch default database adapter.
|
||||
*/
|
||||
if(null === $this->_zendDb) {
|
||||
require_once 'Zend/Db/Table/Abstract.php';
|
||||
$this->_zendDb = Zend_Db_Table_Abstract::getDefaultAdapter();
|
||||
if (null === $this->_zendDb) {
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('No database adapter present');
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setTableName() - set the table name to be used in the select query
|
||||
*
|
||||
* @param string $tableName
|
||||
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
|
||||
*/
|
||||
public function setTableName($tableName)
|
||||
{
|
||||
$this->_tableName = $tableName;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setIdentityColumn() - set the column name to be used as the identity column
|
||||
*
|
||||
* @param string $identityColumn
|
||||
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
|
||||
*/
|
||||
public function setIdentityColumn($identityColumn)
|
||||
{
|
||||
$this->_identityColumn = $identityColumn;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setCredentialColumn() - set the column name to be used as the credential column
|
||||
*
|
||||
* @param string $credentialColumn
|
||||
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
|
||||
*/
|
||||
public function setCredentialColumn($credentialColumn)
|
||||
{
|
||||
$this->_credentialColumn = $credentialColumn;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setCredentialTreatment() - allows the developer to pass a parameterized string that is
|
||||
* used to transform or treat the input credential data.
|
||||
*
|
||||
* In many cases, passwords and other sensitive data are encrypted, hashed, encoded,
|
||||
* obscured, or otherwise treated through some function or algorithm. By specifying a
|
||||
* parameterized treatment string with this method, a developer may apply arbitrary SQL
|
||||
* upon input credential data.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* 'PASSWORD(?)'
|
||||
* 'MD5(?)'
|
||||
*
|
||||
* @param string $treatment
|
||||
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
|
||||
*/
|
||||
public function setCredentialTreatment($treatment)
|
||||
{
|
||||
$this->_credentialTreatment = $treatment;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setIdentity() - set the value to be used as the identity
|
||||
*
|
||||
* @param string $value
|
||||
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
|
||||
*/
|
||||
public function setIdentity($value)
|
||||
{
|
||||
$this->_identity = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setCredential() - set the credential value to be used, optionally can specify a treatment
|
||||
* to be used, should be supplied in parameterized form, such as 'MD5(?)' or 'PASSWORD(?)'
|
||||
*
|
||||
* @param string $credential
|
||||
* @return Zend_Auth_Adapter_DbTable Provides a fluent interface
|
||||
*/
|
||||
public function setCredential($credential)
|
||||
{
|
||||
$this->_credential = $credential;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setAmbiguityIdentity() - sets a flag for usage of identical identities
|
||||
* with unique credentials. It accepts integers (0, 1) or boolean (true,
|
||||
* false) parameters. Default is false.
|
||||
*
|
||||
* @param int|bool $flag
|
||||
* @return Zend_Auth_Adapter_DbTable
|
||||
*/
|
||||
public function setAmbiguityIdentity($flag)
|
||||
{
|
||||
if (is_integer($flag)) {
|
||||
$this->_ambiguityIdentity = (1 === $flag ? true : false);
|
||||
} elseif (is_bool($flag)) {
|
||||
$this->_ambiguityIdentity = $flag;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* getAmbiguityIdentity() - returns TRUE for usage of multiple identical
|
||||
* identies with different credentials, FALSE if not used.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getAmbiguityIdentity()
|
||||
{
|
||||
return $this->_ambiguityIdentity;
|
||||
}
|
||||
|
||||
/**
|
||||
* getDbSelect() - Return the preauthentication Db Select object for userland select query modification
|
||||
*
|
||||
* @return Zend_Db_Select
|
||||
*/
|
||||
public function getDbSelect()
|
||||
{
|
||||
if ($this->_dbSelect == null) {
|
||||
$this->_dbSelect = $this->_zendDb->select();
|
||||
}
|
||||
|
||||
return $this->_dbSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* getResultRowObject() - Returns the result row as a stdClass object
|
||||
*
|
||||
* @param string|array $returnColumns
|
||||
* @param string|array $omitColumns
|
||||
* @return stdClass|boolean
|
||||
*/
|
||||
public function getResultRowObject($returnColumns = null, $omitColumns = null)
|
||||
{
|
||||
if (!$this->_resultRow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$returnObject = new stdClass();
|
||||
|
||||
if (null !== $returnColumns) {
|
||||
|
||||
$availableColumns = array_keys($this->_resultRow);
|
||||
foreach ( (array) $returnColumns as $returnColumn) {
|
||||
if (in_array($returnColumn, $availableColumns)) {
|
||||
$returnObject->{$returnColumn} = $this->_resultRow[$returnColumn];
|
||||
}
|
||||
}
|
||||
return $returnObject;
|
||||
|
||||
} elseif (null !== $omitColumns) {
|
||||
|
||||
$omitColumns = (array) $omitColumns;
|
||||
foreach ($this->_resultRow as $resultColumn => $resultValue) {
|
||||
if (!in_array($resultColumn, $omitColumns)) {
|
||||
$returnObject->{$resultColumn} = $resultValue;
|
||||
}
|
||||
}
|
||||
return $returnObject;
|
||||
|
||||
} else {
|
||||
|
||||
foreach ($this->_resultRow as $resultColumn => $resultValue) {
|
||||
$returnObject->{$resultColumn} = $resultValue;
|
||||
}
|
||||
return $returnObject;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* authenticate() - defined by Zend_Auth_Adapter_Interface. This method is called to
|
||||
* attempt an authentication. Previous to this call, this adapter would have already
|
||||
* been configured with all necessary information to successfully connect to a database
|
||||
* table and attempt to find a record matching the provided identity.
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception if answering the authentication query is impossible
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$this->_authenticateSetup();
|
||||
$dbSelect = $this->_authenticateCreateSelect();
|
||||
$resultIdentities = $this->_authenticateQuerySelect($dbSelect);
|
||||
|
||||
if ( ($authResult = $this->_authenticateValidateResultSet($resultIdentities)) instanceof Zend_Auth_Result) {
|
||||
return $authResult;
|
||||
}
|
||||
|
||||
if (true === $this->getAmbiguityIdentity()) {
|
||||
$validIdentities = array ();
|
||||
$zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match');
|
||||
foreach ($resultIdentities as $identity) {
|
||||
if (1 === (int) $identity[$zendAuthCredentialMatchColumn]) {
|
||||
$validIdentities[] = $identity;
|
||||
}
|
||||
}
|
||||
$resultIdentities = $validIdentities;
|
||||
}
|
||||
|
||||
$authResult = $this->_authenticateValidateResult(array_shift($resultIdentities));
|
||||
return $authResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* _authenticateSetup() - This method abstracts the steps involved with
|
||||
* making sure that this adapter was indeed setup properly with all
|
||||
* required pieces of information.
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception - in the event that setup was not done properly
|
||||
* @return true
|
||||
*/
|
||||
protected function _authenticateSetup()
|
||||
{
|
||||
$exception = null;
|
||||
|
||||
if ($this->_tableName == '') {
|
||||
$exception = 'A table must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
|
||||
} elseif ($this->_identityColumn == '') {
|
||||
$exception = 'An identity column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
|
||||
} elseif ($this->_credentialColumn == '') {
|
||||
$exception = 'A credential column must be supplied for the Zend_Auth_Adapter_DbTable authentication adapter.';
|
||||
} elseif ($this->_identity == '') {
|
||||
$exception = 'A value for the identity was not provided prior to authentication with Zend_Auth_Adapter_DbTable.';
|
||||
} elseif ($this->_credential === null) {
|
||||
$exception = 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.';
|
||||
}
|
||||
|
||||
if (null !== $exception) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception($exception);
|
||||
}
|
||||
|
||||
$this->_authenticateResultInfo = array(
|
||||
'code' => Zend_Auth_Result::FAILURE,
|
||||
'identity' => $this->_identity,
|
||||
'messages' => array()
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* _authenticateCreateSelect() - This method creates a Zend_Db_Select object that
|
||||
* is completely configured to be queried against the database.
|
||||
*
|
||||
* @return Zend_Db_Select
|
||||
*/
|
||||
protected function _authenticateCreateSelect()
|
||||
{
|
||||
// build credential expression
|
||||
if (empty($this->_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) {
|
||||
$this->_credentialTreatment = '?';
|
||||
}
|
||||
|
||||
$credentialExpression = new Zend_Db_Expr(
|
||||
'(CASE WHEN ' .
|
||||
$this->_zendDb->quoteInto(
|
||||
$this->_zendDb->quoteIdentifier($this->_credentialColumn, true)
|
||||
. ' = ' . $this->_credentialTreatment, $this->_credential
|
||||
)
|
||||
. ' THEN 1 ELSE 0 END) AS '
|
||||
. $this->_zendDb->quoteIdentifier(
|
||||
$this->_zendDb->foldCase('zend_auth_credential_match')
|
||||
)
|
||||
);
|
||||
|
||||
// get select
|
||||
$dbSelect = clone $this->getDbSelect();
|
||||
$dbSelect->from($this->_tableName, array('*', $credentialExpression))
|
||||
->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity);
|
||||
|
||||
return $dbSelect;
|
||||
}
|
||||
|
||||
/**
|
||||
* _authenticateQuerySelect() - This method accepts a Zend_Db_Select object and
|
||||
* performs a query against the database with that object.
|
||||
*
|
||||
* @param Zend_Db_Select $dbSelect
|
||||
* @throws Zend_Auth_Adapter_Exception - when an invalid select
|
||||
* object is encountered
|
||||
* @return array
|
||||
*/
|
||||
protected function _authenticateQuerySelect(Zend_Db_Select $dbSelect)
|
||||
{
|
||||
try {
|
||||
if ($this->_zendDb->getFetchMode() != Zend_DB::FETCH_ASSOC) {
|
||||
$origDbFetchMode = $this->_zendDb->getFetchMode();
|
||||
$this->_zendDb->setFetchMode(Zend_DB::FETCH_ASSOC);
|
||||
}
|
||||
$resultIdentities = $this->_zendDb->fetchAll($dbSelect->__toString());
|
||||
if (isset($origDbFetchMode)) {
|
||||
$this->_zendDb->setFetchMode($origDbFetchMode);
|
||||
unset($origDbFetchMode);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('The supplied parameters to Zend_Auth_Adapter_DbTable failed to '
|
||||
. 'produce a valid sql statement, please check table and column names '
|
||||
. 'for validity.', 0, $e);
|
||||
}
|
||||
return $resultIdentities;
|
||||
}
|
||||
|
||||
/**
|
||||
* _authenticateValidateResultSet() - This method attempts to make
|
||||
* certain that only one record was returned in the resultset
|
||||
*
|
||||
* @param array $resultIdentities
|
||||
* @return true|Zend_Auth_Result
|
||||
*/
|
||||
protected function _authenticateValidateResultSet(array $resultIdentities)
|
||||
{
|
||||
|
||||
if (count($resultIdentities) < 1) {
|
||||
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
|
||||
$this->_authenticateResultInfo['messages'][] = 'A record with the supplied identity could not be found.';
|
||||
return $this->_authenticateCreateAuthResult();
|
||||
} elseif (count($resultIdentities) > 1 && false === $this->getAmbiguityIdentity()) {
|
||||
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_IDENTITY_AMBIGUOUS;
|
||||
$this->_authenticateResultInfo['messages'][] = 'More than one record matches the supplied identity.';
|
||||
return $this->_authenticateCreateAuthResult();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* _authenticateValidateResult() - This method attempts to validate that
|
||||
* the record in the resultset is indeed a record that matched the
|
||||
* identity provided to this adapter.
|
||||
*
|
||||
* @param array $resultIdentity
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
protected function _authenticateValidateResult($resultIdentity)
|
||||
{
|
||||
$zendAuthCredentialMatchColumn = $this->_zendDb->foldCase('zend_auth_credential_match');
|
||||
|
||||
if ($resultIdentity[$zendAuthCredentialMatchColumn] != '1') {
|
||||
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
|
||||
$this->_authenticateResultInfo['messages'][] = 'Supplied credential is invalid.';
|
||||
return $this->_authenticateCreateAuthResult();
|
||||
}
|
||||
|
||||
unset($resultIdentity[$zendAuthCredentialMatchColumn]);
|
||||
$this->_resultRow = $resultIdentity;
|
||||
|
||||
$this->_authenticateResultInfo['code'] = Zend_Auth_Result::SUCCESS;
|
||||
$this->_authenticateResultInfo['messages'][] = 'Authentication successful.';
|
||||
return $this->_authenticateCreateAuthResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* _authenticateCreateAuthResult() - Creates a Zend_Auth_Result object from
|
||||
* the information that has been collected during the authenticate() attempt.
|
||||
*
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
protected function _authenticateCreateAuthResult()
|
||||
{
|
||||
return new Zend_Auth_Result(
|
||||
$this->_authenticateResultInfo['code'],
|
||||
$this->_authenticateResultInfo['identity'],
|
||||
$this->_authenticateResultInfo['messages']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
252
library/Zend/Auth/Adapter/Digest.php
Normale Datei
252
library/Zend/Auth/Adapter/Digest.php
Normale Datei
|
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Digest implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* Filename against which authentication queries are performed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_filename;
|
||||
|
||||
/**
|
||||
* Digest authentication realm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_realm;
|
||||
|
||||
/**
|
||||
* Digest authentication user
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_username;
|
||||
|
||||
/**
|
||||
* Password for the user of the realm
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_password;
|
||||
|
||||
/**
|
||||
* Sets adapter options
|
||||
*
|
||||
* @param mixed $filename
|
||||
* @param mixed $realm
|
||||
* @param mixed $username
|
||||
* @param mixed $password
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($filename = null, $realm = null, $username = null, $password = null)
|
||||
{
|
||||
$options = array('filename', 'realm', 'username', 'password');
|
||||
foreach ($options as $option) {
|
||||
if (null !== $$option) {
|
||||
$methodName = 'set' . ucfirst($option);
|
||||
$this->$methodName($$option);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the filename option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->_filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filename option value
|
||||
*
|
||||
* @param mixed $filename
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setFilename($filename)
|
||||
{
|
||||
$this->_filename = (string) $filename;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the realm option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getRealm()
|
||||
{
|
||||
return $this->_realm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the realm option value
|
||||
*
|
||||
* @param mixed $realm
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setRealm($realm)
|
||||
{
|
||||
$this->_realm = (string) $realm;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->_username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username option value
|
||||
*
|
||||
* @param mixed $username
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->_username = (string) $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password option value or null if it has not yet been set
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the password option value
|
||||
*
|
||||
* @param mixed $password
|
||||
* @return Zend_Auth_Adapter_Digest Provides a fluent interface
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->_password = (string) $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Adapter_Interface
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
$optionsRequired = array('filename', 'realm', 'username', 'password');
|
||||
foreach ($optionsRequired as $optionRequired) {
|
||||
if (null === $this->{"_$optionRequired"}) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception("Option '$optionRequired' must be set before authentication");
|
||||
}
|
||||
}
|
||||
|
||||
if (false === ($fileHandle = @fopen($this->_filename, 'r'))) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception("Cannot open '$this->_filename' for reading");
|
||||
}
|
||||
|
||||
$id = "$this->_username:$this->_realm";
|
||||
$idLength = strlen($id);
|
||||
|
||||
$result = array(
|
||||
'code' => Zend_Auth_Result::FAILURE,
|
||||
'identity' => array(
|
||||
'realm' => $this->_realm,
|
||||
'username' => $this->_username,
|
||||
),
|
||||
'messages' => array()
|
||||
);
|
||||
|
||||
while ($line = trim(fgets($fileHandle))) {
|
||||
if (substr($line, 0, $idLength) === $id) {
|
||||
if ($this->_secureStringCompare(substr($line, -32), md5("$this->_username:$this->_realm:$this->_password"))) {
|
||||
$result['code'] = Zend_Auth_Result::SUCCESS;
|
||||
} else {
|
||||
$result['code'] = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
|
||||
$result['messages'][] = 'Password incorrect';
|
||||
}
|
||||
return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
|
||||
}
|
||||
}
|
||||
|
||||
$result['code'] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
|
||||
$result['messages'][] = "Username '$this->_username' and realm '$this->_realm' combination not found";
|
||||
return new Zend_Auth_Result($result['code'], $result['identity'], $result['messages']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Securely compare two strings for equality while avoided C level memcmp()
|
||||
* optimisations capable of leaking timing information useful to an attacker
|
||||
* attempting to iteratively guess the unknown string (e.g. password) being
|
||||
* compared against.
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return bool
|
||||
*/
|
||||
protected function _secureStringCompare($a, $b)
|
||||
{
|
||||
if (strlen($a) !== strlen($b)) {
|
||||
return false;
|
||||
}
|
||||
$result = 0;
|
||||
for ($i = 0; $i < strlen($a); $i++) {
|
||||
$result |= ord($a[$i]) ^ ord($b[$i]);
|
||||
}
|
||||
return $result == 0;
|
||||
}
|
||||
}
|
||||
38
library/Zend/Auth/Adapter/Exception.php
Normale Datei
38
library/Zend/Auth/Adapter/Exception.php
Normale Datei
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Zend_Auth_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Exception extends Zend_Auth_Exception
|
||||
{}
|
||||
869
library/Zend/Auth/Adapter/Http.php
Normale Datei
869
library/Zend/Auth/Adapter/Http.php
Normale Datei
|
|
@ -0,0 +1,869 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Authentication Adapter
|
||||
*
|
||||
* Implements a pretty good chunk of RFC 2617.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @todo Support auth-int
|
||||
* @todo Track nonces, nonce-count, opaque for replay protection and stale support
|
||||
* @todo Support Authentication-Info header
|
||||
*/
|
||||
class Zend_Auth_Adapter_Http implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* Reference to the HTTP Request object
|
||||
*
|
||||
* @var Zend_Controller_Request_Http
|
||||
*/
|
||||
protected $_request;
|
||||
|
||||
/**
|
||||
* Reference to the HTTP Response object
|
||||
*
|
||||
* @var Zend_Controller_Response_Http
|
||||
*/
|
||||
protected $_response;
|
||||
|
||||
/**
|
||||
* Object that looks up user credentials for the Basic scheme
|
||||
*
|
||||
* @var Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
protected $_basicResolver;
|
||||
|
||||
/**
|
||||
* Object that looks up user credentials for the Digest scheme
|
||||
*
|
||||
* @var Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
protected $_digestResolver;
|
||||
|
||||
/**
|
||||
* List of authentication schemes supported by this class
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_supportedSchemes = array('basic', 'digest');
|
||||
|
||||
/**
|
||||
* List of schemes this class will accept from the client
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_acceptSchemes;
|
||||
|
||||
/**
|
||||
* Space-delimited list of protected domains for Digest Auth
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_domains;
|
||||
|
||||
/**
|
||||
* The protection realm to use
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_realm;
|
||||
|
||||
/**
|
||||
* Nonce timeout period
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $_nonceTimeout;
|
||||
|
||||
/**
|
||||
* Whether to send the opaque value in the header. True by default
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_useOpaque;
|
||||
|
||||
/**
|
||||
* List of the supported digest algorithms. I want to support both MD5 and
|
||||
* MD5-sess, but MD5-sess won't make it into the first version.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_supportedAlgos = array('MD5');
|
||||
|
||||
/**
|
||||
* The actual algorithm to use. Defaults to MD5
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_algo;
|
||||
|
||||
/**
|
||||
* List of supported qop options. My intetion is to support both 'auth' and
|
||||
* 'auth-int', but 'auth-int' won't make it into the first version.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_supportedQops = array('auth');
|
||||
|
||||
/**
|
||||
* Whether or not to do Proxy Authentication instead of origin server
|
||||
* authentication (send 407's instead of 401's). Off by default.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_imaProxy;
|
||||
|
||||
/**
|
||||
* Flag indicating the client is IE and didn't bother to return the opaque string
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_ieNoOpaque;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $config Configuration settings:
|
||||
* 'accept_schemes' => 'basic'|'digest'|'basic digest'
|
||||
* 'realm' => <string>
|
||||
* 'digest_domains' => <string> Space-delimited list of URIs
|
||||
* 'nonce_timeout' => <int>
|
||||
* 'use_opaque' => <bool> Whether to send the opaque value in the header
|
||||
* 'alogrithm' => <string> See $_supportedAlgos. Default: MD5
|
||||
* 'proxy_auth' => <bool> Whether to do authentication as a Proxy
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
if (!extension_loaded('hash')) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception(__CLASS__ . ' requires the \'hash\' extension');
|
||||
}
|
||||
|
||||
$this->_request = null;
|
||||
$this->_response = null;
|
||||
$this->_ieNoOpaque = false;
|
||||
|
||||
|
||||
if (empty($config['accept_schemes'])) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'accept_schemes\' is required');
|
||||
}
|
||||
|
||||
$schemes = explode(' ', $config['accept_schemes']);
|
||||
$this->_acceptSchemes = array_intersect($schemes, $this->_supportedSchemes);
|
||||
if (empty($this->_acceptSchemes)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('No supported schemes given in \'accept_schemes\'. Valid values: '
|
||||
. implode(', ', $this->_supportedSchemes));
|
||||
}
|
||||
|
||||
// Double-quotes are used to delimit the realm string in the HTTP header,
|
||||
// and colons are field delimiters in the password file.
|
||||
if (empty($config['realm']) ||
|
||||
!ctype_print($config['realm']) ||
|
||||
strpos($config['realm'], ':') !== false ||
|
||||
strpos($config['realm'], '"') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'realm\' is required, and must contain only printable '
|
||||
. 'characters, excluding quotation marks and colons');
|
||||
} else {
|
||||
$this->_realm = $config['realm'];
|
||||
}
|
||||
|
||||
if (in_array('digest', $this->_acceptSchemes)) {
|
||||
if (empty($config['digest_domains']) ||
|
||||
!ctype_print($config['digest_domains']) ||
|
||||
strpos($config['digest_domains'], '"') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'digest_domains\' is required, and must contain '
|
||||
. 'only printable characters, excluding quotation marks');
|
||||
} else {
|
||||
$this->_domains = $config['digest_domains'];
|
||||
}
|
||||
|
||||
if (empty($config['nonce_timeout']) ||
|
||||
!is_numeric($config['nonce_timeout'])) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Config key \'nonce_timeout\' is required, and must be an '
|
||||
. 'integer');
|
||||
} else {
|
||||
$this->_nonceTimeout = (int) $config['nonce_timeout'];
|
||||
}
|
||||
|
||||
// We use the opaque value unless explicitly told not to
|
||||
if (isset($config['use_opaque']) && false == (bool) $config['use_opaque']) {
|
||||
$this->_useOpaque = false;
|
||||
} else {
|
||||
$this->_useOpaque = true;
|
||||
}
|
||||
|
||||
if (isset($config['algorithm']) && in_array($config['algorithm'], $this->_supportedAlgos)) {
|
||||
$this->_algo = $config['algorithm'];
|
||||
} else {
|
||||
$this->_algo = 'MD5';
|
||||
}
|
||||
}
|
||||
|
||||
// Don't be a proxy unless explicitly told to do so
|
||||
if (isset($config['proxy_auth']) && true == (bool) $config['proxy_auth']) {
|
||||
$this->_imaProxy = true; // I'm a Proxy
|
||||
} else {
|
||||
$this->_imaProxy = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the _basicResolver property
|
||||
*
|
||||
* @param Zend_Auth_Adapter_Http_Resolver_Interface $resolver
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setBasicResolver(Zend_Auth_Adapter_Http_Resolver_Interface $resolver)
|
||||
{
|
||||
$this->_basicResolver = $resolver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the _basicResolver property
|
||||
*
|
||||
* @return Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
public function getBasicResolver()
|
||||
{
|
||||
return $this->_basicResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the _digestResolver property
|
||||
*
|
||||
* @param Zend_Auth_Adapter_Http_Resolver_Interface $resolver
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setDigestResolver(Zend_Auth_Adapter_Http_Resolver_Interface $resolver)
|
||||
{
|
||||
$this->_digestResolver = $resolver;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the _digestResolver property
|
||||
*
|
||||
* @return Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
public function getDigestResolver()
|
||||
{
|
||||
return $this->_digestResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Request object
|
||||
*
|
||||
* @param Zend_Controller_Request_Http $request
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setRequest(Zend_Controller_Request_Http $request)
|
||||
{
|
||||
$this->_request = $request;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Request object
|
||||
*
|
||||
* @return Zend_Controller_Request_Http
|
||||
*/
|
||||
public function getRequest()
|
||||
{
|
||||
return $this->_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for the Response object
|
||||
*
|
||||
* @param Zend_Controller_Response_Http $response
|
||||
* @return Zend_Auth_Adapter_Http Provides a fluent interface
|
||||
*/
|
||||
public function setResponse(Zend_Controller_Response_Http $response)
|
||||
{
|
||||
$this->_response = $response;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Response object
|
||||
*
|
||||
* @return Zend_Controller_Response_Http
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
if (empty($this->_request) ||
|
||||
empty($this->_response)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Request and Response objects must be set before calling '
|
||||
. 'authenticate()');
|
||||
}
|
||||
|
||||
if ($this->_imaProxy) {
|
||||
$getHeader = 'Proxy-Authorization';
|
||||
} else {
|
||||
$getHeader = 'Authorization';
|
||||
}
|
||||
|
||||
$authHeader = $this->_request->getHeader($getHeader);
|
||||
if (!$authHeader) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
list($clientScheme) = explode(' ', $authHeader);
|
||||
$clientScheme = strtolower($clientScheme);
|
||||
|
||||
// The server can issue multiple challenges, but the client should
|
||||
// answer with only the selected auth scheme.
|
||||
if (!in_array($clientScheme, $this->_supportedSchemes)) {
|
||||
$this->_response->setHttpResponseCode(400);
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_UNCATEGORIZED,
|
||||
array(),
|
||||
array('Client requested an incorrect or unsupported authentication scheme')
|
||||
);
|
||||
}
|
||||
|
||||
// client sent a scheme that is not the one required
|
||||
if (!in_array($clientScheme, $this->_acceptSchemes)) {
|
||||
// challenge again the client
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
switch ($clientScheme) {
|
||||
case 'basic':
|
||||
$result = $this->_basicAuth($authHeader);
|
||||
break;
|
||||
case 'digest':
|
||||
$result = $this->_digestAuth($authHeader);
|
||||
break;
|
||||
default:
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Unsupported authentication scheme');
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Challenge Client
|
||||
*
|
||||
* Sets a 401 or 407 Unauthorized response code, and creates the
|
||||
* appropriate Authenticate header(s) to prompt for credentials.
|
||||
*
|
||||
* @return Zend_Auth_Result Always returns a non-identity Auth result
|
||||
*/
|
||||
protected function _challengeClient()
|
||||
{
|
||||
if ($this->_imaProxy) {
|
||||
$statusCode = 407;
|
||||
$headerName = 'Proxy-Authenticate';
|
||||
} else {
|
||||
$statusCode = 401;
|
||||
$headerName = 'WWW-Authenticate';
|
||||
}
|
||||
|
||||
$this->_response->setHttpResponseCode($statusCode);
|
||||
|
||||
// Send a challenge in each acceptable authentication scheme
|
||||
if (in_array('basic', $this->_acceptSchemes)) {
|
||||
$this->_response->setHeader($headerName, $this->_basicHeader());
|
||||
}
|
||||
if (in_array('digest', $this->_acceptSchemes)) {
|
||||
$this->_response->setHeader($headerName, $this->_digestHeader());
|
||||
}
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
array(),
|
||||
array('Invalid or absent credentials; challenging client')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Header
|
||||
*
|
||||
* Generates a Proxy- or WWW-Authenticate header value in the Basic
|
||||
* authentication scheme.
|
||||
*
|
||||
* @return string Authenticate header value
|
||||
*/
|
||||
protected function _basicHeader()
|
||||
{
|
||||
return 'Basic realm="' . $this->_realm . '"';
|
||||
}
|
||||
|
||||
/**
|
||||
* Digest Header
|
||||
*
|
||||
* Generates a Proxy- or WWW-Authenticate header value in the Digest
|
||||
* authentication scheme.
|
||||
*
|
||||
* @return string Authenticate header value
|
||||
*/
|
||||
protected function _digestHeader()
|
||||
{
|
||||
$wwwauth = 'Digest realm="' . $this->_realm . '", '
|
||||
. 'domain="' . $this->_domains . '", '
|
||||
. 'nonce="' . $this->_calcNonce() . '", '
|
||||
. ($this->_useOpaque ? 'opaque="' . $this->_calcOpaque() . '", ' : '')
|
||||
. 'algorithm="' . $this->_algo . '", '
|
||||
. 'qop="' . implode(',', $this->_supportedQops) . '"';
|
||||
|
||||
return $wwwauth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic Authentication
|
||||
*
|
||||
* @param string $header Client's Authorization header
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
protected function _basicAuth($header)
|
||||
{
|
||||
if (empty($header)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
|
||||
}
|
||||
if (empty($this->_basicResolver)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('A basicResolver object must be set before doing Basic '
|
||||
. 'authentication');
|
||||
}
|
||||
|
||||
// Decode the Authorization header
|
||||
$auth = substr($header, strlen('Basic '));
|
||||
$auth = base64_decode($auth);
|
||||
if (!$auth) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Unable to base64_decode Authorization header value');
|
||||
}
|
||||
|
||||
// See ZF-1253. Validate the credentials the same way the digest
|
||||
// implementation does. If invalid credentials are detected,
|
||||
// re-challenge the client.
|
||||
if (!ctype_print($auth)) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
// Fix for ZF-1515: Now re-challenges on empty username or password
|
||||
$creds = array_filter(explode(':', $auth));
|
||||
if (count($creds) != 2) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
$password = $this->_basicResolver->resolve($creds[0], $this->_realm);
|
||||
if ($password && $this->_secureStringCompare($password, $creds[1])) {
|
||||
$identity = array('username'=>$creds[0], 'realm'=>$this->_realm);
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
||||
} else {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Digest Authentication
|
||||
*
|
||||
* @param string $header Client's Authorization header
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result Valid auth result only on successful auth
|
||||
*/
|
||||
protected function _digestAuth($header)
|
||||
{
|
||||
if (empty($header)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('The value of the client Authorization header is required');
|
||||
}
|
||||
if (empty($this->_digestResolver)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('A digestResolver object must be set before doing Digest authentication');
|
||||
}
|
||||
|
||||
$data = $this->_parseDigestAuth($header);
|
||||
if ($data === false) {
|
||||
$this->_response->setHttpResponseCode(400);
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_UNCATEGORIZED,
|
||||
array(),
|
||||
array('Invalid Authorization header format')
|
||||
);
|
||||
}
|
||||
|
||||
// See ZF-1052. This code was a bit too unforgiving of invalid
|
||||
// usernames. Now, if the username is bad, we re-challenge the client.
|
||||
if ('::invalid::' == $data['username']) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
// Verify that the client sent back the same nonce
|
||||
if ($this->_calcNonce() != $data['nonce']) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
// The opaque value is also required to match, but of course IE doesn't
|
||||
// play ball.
|
||||
if (!$this->_ieNoOpaque && $this->_calcOpaque() != $data['opaque']) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
// Look up the user's password hash. If not found, deny access.
|
||||
// This makes no assumptions about how the password hash was
|
||||
// constructed beyond that it must have been built in such a way as
|
||||
// to be recreatable with the current settings of this object.
|
||||
$ha1 = $this->_digestResolver->resolve($data['username'], $data['realm']);
|
||||
if ($ha1 === false) {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
|
||||
// If MD5-sess is used, a1 value is made of the user's password
|
||||
// hash with the server and client nonce appended, separated by
|
||||
// colons.
|
||||
if ($this->_algo == 'MD5-sess') {
|
||||
$ha1 = hash('md5', $ha1 . ':' . $data['nonce'] . ':' . $data['cnonce']);
|
||||
}
|
||||
|
||||
// Calculate h(a2). The value of this hash depends on the qop
|
||||
// option selected by the client and the supported hash functions
|
||||
switch ($data['qop']) {
|
||||
case 'auth':
|
||||
$a2 = $this->_request->getMethod() . ':' . $data['uri'];
|
||||
break;
|
||||
case 'auth-int':
|
||||
// Should be REQUEST_METHOD . ':' . uri . ':' . hash(entity-body),
|
||||
// but this isn't supported yet, so fall through to default case
|
||||
default:
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Client requested an unsupported qop option');
|
||||
}
|
||||
// Using hash() should make parameterizing the hash algorithm
|
||||
// easier
|
||||
$ha2 = hash('md5', $a2);
|
||||
|
||||
|
||||
// Calculate the server's version of the request-digest. This must
|
||||
// match $data['response']. See RFC 2617, section 3.2.2.1
|
||||
$message = $data['nonce'] . ':' . $data['nc'] . ':' . $data['cnonce'] . ':' . $data['qop'] . ':' . $ha2;
|
||||
$digest = hash('md5', $ha1 . ':' . $message);
|
||||
|
||||
// If our digest matches the client's let them in, otherwise return
|
||||
// a 401 code and exit to prevent access to the protected resource.
|
||||
if ($this->_secureStringCompare($digest, $data['response'])) {
|
||||
$identity = array('username'=>$data['username'], 'realm'=>$data['realm']);
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $identity);
|
||||
} else {
|
||||
return $this->_challengeClient();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Nonce
|
||||
*
|
||||
* @return string The nonce value
|
||||
*/
|
||||
protected function _calcNonce()
|
||||
{
|
||||
// Once subtle consequence of this timeout calculation is that it
|
||||
// actually divides all of time into _nonceTimeout-sized sections, such
|
||||
// that the value of timeout is the point in time of the next
|
||||
// approaching "boundary" of a section. This allows the server to
|
||||
// consistently generate the same timeout (and hence the same nonce
|
||||
// value) across requests, but only as long as one of those
|
||||
// "boundaries" is not crossed between requests. If that happens, the
|
||||
// nonce will change on its own, and effectively log the user out. This
|
||||
// would be surprising if the user just logged in.
|
||||
$timeout = ceil(time() / $this->_nonceTimeout) * $this->_nonceTimeout;
|
||||
|
||||
$nonce = hash('md5', $timeout . ':' . $this->_request->getServer('HTTP_USER_AGENT') . ':' . __CLASS__);
|
||||
return $nonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Opaque
|
||||
*
|
||||
* The opaque string can be anything; the client must return it exactly as
|
||||
* it was sent. It may be useful to store data in this string in some
|
||||
* applications. Ideally, a new value for this would be generated each time
|
||||
* a WWW-Authenticate header is sent (in order to reduce predictability),
|
||||
* but we would have to be able to create the same exact value across at
|
||||
* least two separate requests from the same client.
|
||||
*
|
||||
* @return string The opaque value
|
||||
*/
|
||||
protected function _calcOpaque()
|
||||
{
|
||||
return hash('md5', 'Opaque Data:' . __CLASS__);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Digest Authorization header
|
||||
*
|
||||
* @param string $header Client's Authorization: HTTP header
|
||||
* @return array|false Data elements from header, or false if any part of
|
||||
* the header is invalid
|
||||
*/
|
||||
protected function _parseDigestAuth($header)
|
||||
{
|
||||
$temp = null;
|
||||
$data = array();
|
||||
|
||||
// See ZF-1052. Detect invalid usernames instead of just returning a
|
||||
// 400 code.
|
||||
$ret = preg_match('/username="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])
|
||||
|| !ctype_print($temp[1])
|
||||
|| strpos($temp[1], ':') !== false) {
|
||||
$data['username'] = '::invalid::';
|
||||
} else {
|
||||
$data['username'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/realm="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!ctype_print($temp[1]) || strpos($temp[1], ':') !== false) {
|
||||
return false;
|
||||
} else {
|
||||
$data['realm'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/nonce="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!ctype_xdigit($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['nonce'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/uri="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
// Section 3.2.2.5 in RFC 2617 says the authenticating server must
|
||||
// verify that the URI field in the Authorization header is for the
|
||||
// same resource requested in the Request Line.
|
||||
$rUri = @parse_url($this->_request->getRequestUri());
|
||||
$cUri = @parse_url($temp[1]);
|
||||
if (false === $rUri || false === $cUri) {
|
||||
return false;
|
||||
} else {
|
||||
// Make sure the path portion of both URIs is the same
|
||||
if ($rUri['path'] != $cUri['path']) {
|
||||
return false;
|
||||
}
|
||||
// Section 3.2.2.5 seems to suggest that the value of the URI
|
||||
// Authorization field should be made into an absolute URI if the
|
||||
// Request URI is absolute, but it's vague, and that's a bunch of
|
||||
// code I don't want to write right now.
|
||||
$data['uri'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
$ret = preg_match('/response="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (32 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['response'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// The spec says this should default to MD5 if omitted. OK, so how does
|
||||
// that square with the algo we send out in the WWW-Authenticate header,
|
||||
// if it can easily be overridden by the client?
|
||||
$ret = preg_match('/algorithm="?(' . $this->_algo . ')"?/', $header, $temp);
|
||||
if ($ret && !empty($temp[1])
|
||||
&& in_array($temp[1], $this->_supportedAlgos)) {
|
||||
$data['algorithm'] = $temp[1];
|
||||
} else {
|
||||
$data['algorithm'] = 'MD5'; // = $this->_algo; ?
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// Not optional in this implementation
|
||||
$ret = preg_match('/cnonce="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!ctype_print($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['cnonce'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// If the server sent an opaque value, the client must send it back
|
||||
if ($this->_useOpaque) {
|
||||
$ret = preg_match('/opaque="([^"]+)"/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
|
||||
// Big surprise: IE isn't RFC 2617-compliant.
|
||||
if (false !== strpos($this->_request->getHeader('User-Agent'), 'MSIE')) {
|
||||
$temp[1] = '';
|
||||
$this->_ieNoOpaque = true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// This implementation only sends MD5 hex strings in the opaque value
|
||||
if (!$this->_ieNoOpaque &&
|
||||
(32 != strlen($temp[1]) || !ctype_xdigit($temp[1]))) {
|
||||
return false;
|
||||
} else {
|
||||
$data['opaque'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
}
|
||||
|
||||
// Not optional in this implementation, but must be one of the supported
|
||||
// qop types
|
||||
$ret = preg_match('/qop="?(' . implode('|', $this->_supportedQops) . ')"?/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (!in_array($temp[1], $this->_supportedQops)) {
|
||||
return false;
|
||||
} else {
|
||||
$data['qop'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
// Not optional in this implementation. The spec says this value
|
||||
// shouldn't be a quoted string, but apparently some implementations
|
||||
// quote it anyway. See ZF-1544.
|
||||
$ret = preg_match('/nc="?([0-9A-Fa-f]{8})"?/', $header, $temp);
|
||||
if (!$ret || empty($temp[1])) {
|
||||
return false;
|
||||
}
|
||||
if (8 != strlen($temp[1]) || !ctype_xdigit($temp[1])) {
|
||||
return false;
|
||||
} else {
|
||||
$data['nc'] = $temp[1];
|
||||
}
|
||||
$temp = null;
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Securely compare two strings for equality while avoided C level memcmp()
|
||||
* optimisations capable of leaking timing information useful to an attacker
|
||||
* attempting to iteratively guess the unknown string (e.g. password) being
|
||||
* compared against.
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return bool
|
||||
*/
|
||||
protected function _secureStringCompare($a, $b)
|
||||
{
|
||||
if (strlen($a) !== strlen($b)) {
|
||||
return false;
|
||||
}
|
||||
$result = 0;
|
||||
for ($i = 0; $i < strlen($a); $i++) {
|
||||
$result |= ord($a[$i]) ^ ord($b[$i]);
|
||||
}
|
||||
return $result == 0;
|
||||
}
|
||||
}
|
||||
40
library/Zend/Auth/Adapter/Http/Resolver/Exception.php
Normale Datei
40
library/Zend/Auth/Adapter/Http/Resolver/Exception.php
Normale Datei
|
|
@ -0,0 +1,40 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Auth Resolver Exception
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Http_Resolver_Exception extends Zend_Auth_Exception
|
||||
{}
|
||||
167
library/Zend/Auth/Adapter/Http/Resolver/File.php
Normale Datei
167
library/Zend/Auth/Adapter/Http/Resolver/File.php
Normale Datei
|
|
@ -0,0 +1,167 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* HTTP Authentication File Resolver
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Http_Resolver_File implements Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
{
|
||||
/**
|
||||
* Path to credentials file
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_file;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $path Complete filename where the credentials are stored
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($path = '')
|
||||
{
|
||||
if (!empty($path)) {
|
||||
$this->setFile($path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the path to the credentials file
|
||||
*
|
||||
* @param string $path
|
||||
* @throws Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
* @return Zend_Auth_Adapter_Http_Resolver_File Provides a fluent interface
|
||||
*/
|
||||
public function setFile($path)
|
||||
{
|
||||
if (empty($path) || !is_readable($path)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Path not readable: ' . $path);
|
||||
}
|
||||
$this->_file = $path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path to the credentials file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFile()
|
||||
{
|
||||
return $this->_file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve credentials
|
||||
*
|
||||
* Only the first matching username/realm combination in the file is
|
||||
* returned. If the file contains credentials for Digest authentication,
|
||||
* the returned string is the password hash, or h(a1) from RFC 2617. The
|
||||
* returned string is the plain-text password for Basic authentication.
|
||||
*
|
||||
* The expected format of the file is:
|
||||
* username:realm:sharedSecret
|
||||
*
|
||||
* That is, each line consists of the user's username, the applicable
|
||||
* authentication realm, and the password or hash, each delimited by
|
||||
* colons.
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $realm Authentication Realm
|
||||
* @throws Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
* @return string|false User's shared secret, if the user is found in the
|
||||
* realm, false otherwise.
|
||||
*/
|
||||
public function resolve($username, $realm)
|
||||
{
|
||||
if (empty($username)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Username is required');
|
||||
} else if (!ctype_print($username) || strpos($username, ':') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Username must consist only of printable characters, '
|
||||
. 'excluding the colon');
|
||||
}
|
||||
if (empty($realm)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Realm is required');
|
||||
} else if (!ctype_print($realm) || strpos($realm, ':') !== false) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Realm must consist only of printable characters, '
|
||||
. 'excluding the colon.');
|
||||
}
|
||||
|
||||
// Open file, read through looking for matching credentials
|
||||
$fp = @fopen($this->_file, 'r');
|
||||
if (!$fp) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Http_Resolver_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Http_Resolver_Exception('Unable to open password file: ' . $this->_file);
|
||||
}
|
||||
|
||||
// No real validation is done on the contents of the password file. The
|
||||
// assumption is that we trust the administrators to keep it secure.
|
||||
while (($line = fgetcsv($fp, 512, ':')) !== false) {
|
||||
if ($line[0] == $username && $line[1] == $realm) {
|
||||
$password = $line[2];
|
||||
fclose($fp);
|
||||
return $password;
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
47
library/Zend/Auth/Adapter/Http/Resolver/Interface.php
Normale Datei
47
library/Zend/Auth/Adapter/Http/Resolver/Interface.php
Normale Datei
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Auth HTTP Resolver Interface
|
||||
*
|
||||
* Defines an interace to resolve a username/realm combination into a shared
|
||||
* secret usable by HTTP Authentication.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter_Http
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Auth_Adapter_Http_Resolver_Interface
|
||||
{
|
||||
/**
|
||||
* Resolve username/realm to password/hash/etc.
|
||||
*
|
||||
* @param string $username Username
|
||||
* @param string $realm Authentication Realm
|
||||
* @return string|false User's shared secret, if the user is found in the
|
||||
* realm, false otherwise.
|
||||
*/
|
||||
public function resolve($username, $realm);
|
||||
}
|
||||
261
library/Zend/Auth/Adapter/InfoCard.php
Normale Datei
261
library/Zend/Auth/Adapter/InfoCard.php
Normale Datei
|
|
@ -0,0 +1,261 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Result
|
||||
*/
|
||||
require_once 'Zend/Auth/Result.php';
|
||||
|
||||
/**
|
||||
* @see Zend_InfoCard
|
||||
*/
|
||||
require_once 'Zend/InfoCard.php';
|
||||
|
||||
/**
|
||||
* A Zend_Auth Authentication Adapter allowing the use of Information Cards as an
|
||||
* authentication mechanism
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_InfoCard implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* The XML Token being authenticated
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_xmlToken;
|
||||
|
||||
/**
|
||||
* The instance of Zend_InfoCard
|
||||
*
|
||||
* @var Zend_InfoCard
|
||||
*/
|
||||
protected $_infoCard;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $strXmlDocument The XML Token provided by the client
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($strXmlDocument)
|
||||
{
|
||||
$this->_xmlToken = $strXmlDocument;
|
||||
$this->_infoCard = new Zend_InfoCard();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InfoCard component Adapter to use
|
||||
*
|
||||
* @param Zend_InfoCard_Adapter_Interface $a
|
||||
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
|
||||
*/
|
||||
public function setAdapter(Zend_InfoCard_Adapter_Interface $a)
|
||||
{
|
||||
$this->_infoCard->setAdapter($a);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the InfoCard component adapter being used
|
||||
*
|
||||
* @return Zend_InfoCard_Adapter_Interface
|
||||
*/
|
||||
public function getAdapter()
|
||||
{
|
||||
return $this->_infoCard->getAdapter();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the InfoCard public key cipher object being used
|
||||
*
|
||||
* @return Zend_InfoCard_Cipher_PKI_Interface
|
||||
*/
|
||||
public function getPKCipherObject()
|
||||
{
|
||||
return $this->_infoCard->getPKCipherObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InfoCard public key cipher object to use
|
||||
*
|
||||
* @param Zend_InfoCard_Cipher_PKI_Interface $cipherObj
|
||||
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
|
||||
*/
|
||||
public function setPKICipherObject(Zend_InfoCard_Cipher_PKI_Interface $cipherObj)
|
||||
{
|
||||
$this->_infoCard->setPKICipherObject($cipherObj);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the Symmetric cipher object being used
|
||||
*
|
||||
* @return Zend_InfoCard_Cipher_Symmetric_Interface
|
||||
*/
|
||||
public function getSymCipherObject()
|
||||
{
|
||||
return $this->_infoCard->getSymCipherObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the InfoCard symmetric cipher object to use
|
||||
*
|
||||
* @param Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj
|
||||
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
|
||||
*/
|
||||
public function setSymCipherObject(Zend_InfoCard_Cipher_Symmetric_Interface $cipherObj)
|
||||
{
|
||||
$this->_infoCard->setSymCipherObject($cipherObj);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Certificate Pair by Key ID from the search list
|
||||
*
|
||||
* @param string $key_id The Certificate Key ID returned from adding the certificate pair
|
||||
* @throws Zend_InfoCard_Exception
|
||||
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
|
||||
*/
|
||||
public function removeCertificatePair($key_id)
|
||||
{
|
||||
$this->_infoCard->removeCertificatePair($key_id);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a Certificate Pair to the list of certificates searched by the component
|
||||
*
|
||||
* @param string $private_key_file The path to the private key file for the pair
|
||||
* @param string $public_key_file The path to the certificate / public key for the pair
|
||||
* @param string $type (optional) The URI for the type of key pair this is (default RSA with OAEP padding)
|
||||
* @param string $password (optional) The password for the private key file if necessary
|
||||
* @throws Zend_InfoCard_Exception
|
||||
* @return string A key ID representing this key pair in the component
|
||||
*/
|
||||
public function addCertificatePair($private_key_file, $public_key_file, $type = Zend_InfoCard_Cipher::ENC_RSA_OAEP_MGF1P, $password = null)
|
||||
{
|
||||
return $this->_infoCard->addCertificatePair($private_key_file, $public_key_file, $type, $password);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Certificate Pair from a key ID
|
||||
*
|
||||
* @param string $key_id The Key ID of the certificate pair in the component
|
||||
* @throws Zend_InfoCard_Exception
|
||||
* @return array An array containing the path to the private/public key files,
|
||||
* the type URI and the password if provided
|
||||
*/
|
||||
public function getCertificatePair($key_id)
|
||||
{
|
||||
return $this->_infoCard->getCertificatePair($key_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the XML Token to be processed
|
||||
*
|
||||
* @param string $strXmlToken The XML token to process
|
||||
* @return Zend_Auth_Adapter_InfoCard Provides a fluent interface
|
||||
*/
|
||||
public function setXmlToken($strXmlToken)
|
||||
{
|
||||
$this->_xmlToken = $strXmlToken;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the XML Token being processed
|
||||
*
|
||||
* @return string The XML token to be processed
|
||||
*/
|
||||
public function getXmlToken()
|
||||
{
|
||||
return $this->_xmlToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates the XML token
|
||||
*
|
||||
* @return Zend_Auth_Result The result of the authentication
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
try {
|
||||
$claims = $this->_infoCard->process($this->getXmlToken());
|
||||
} catch(Exception $e) {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE , null, array('Exception Thrown',
|
||||
$e->getMessage(),
|
||||
$e->getTraceAsString(),
|
||||
serialize($e)));
|
||||
}
|
||||
|
||||
if(!$claims->isValid()) {
|
||||
switch($claims->getCode()) {
|
||||
case Zend_infoCard_Claims::RESULT_PROCESSING_FAILURE:
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE,
|
||||
$claims,
|
||||
array(
|
||||
'Processing Failure',
|
||||
$claims->getErrorMsg()
|
||||
)
|
||||
);
|
||||
break;
|
||||
case Zend_InfoCard_Claims::RESULT_VALIDATION_FAILURE:
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
$claims,
|
||||
array(
|
||||
'Validation Failure',
|
||||
$claims->getErrorMsg()
|
||||
)
|
||||
);
|
||||
break;
|
||||
default:
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE,
|
||||
$claims,
|
||||
array(
|
||||
'Unknown Failure',
|
||||
$claims->getErrorMsg()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::SUCCESS,
|
||||
$claims
|
||||
);
|
||||
}
|
||||
}
|
||||
46
library/Zend/Auth/Adapter/Interface.php
Normale Datei
46
library/Zend/Auth/Adapter/Interface.php
Normale Datei
|
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Result
|
||||
*/
|
||||
require_once 'Zend/Auth/Result.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* Performs an authentication attempt
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception If authentication cannot be performed
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate();
|
||||
}
|
||||
528
library/Zend/Auth/Adapter/Ldap.php
Normale Datei
528
library/Zend/Auth/Adapter/Ldap.php
Normale Datei
|
|
@ -0,0 +1,528 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_Ldap implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* The Zend_Ldap context.
|
||||
*
|
||||
* @var Zend_Ldap
|
||||
*/
|
||||
protected $_ldap = null;
|
||||
|
||||
/**
|
||||
* The array of arrays of Zend_Ldap options passed to the constructor.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_options = null;
|
||||
|
||||
/**
|
||||
* The username of the account being authenticated.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_username = null;
|
||||
|
||||
/**
|
||||
* The password of the account being authenticated.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_password = null;
|
||||
|
||||
/**
|
||||
* The DN of the authenticated account. Used to retrieve the account entry on request.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_authenticatedDn = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options An array of arrays of Zend_Ldap options
|
||||
* @param string $username The username of the account being authenticated
|
||||
* @param string $password The password of the account being authenticated
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array(), $username = null, $password = null)
|
||||
{
|
||||
$this->setOptions($options);
|
||||
if ($username !== null) {
|
||||
$this->setUsername($username);
|
||||
}
|
||||
if ($password !== null) {
|
||||
$this->setPassword($password);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of arrays of Zend_Ldap options of this adapter.
|
||||
*
|
||||
* @return array|null
|
||||
*/
|
||||
public function getOptions()
|
||||
{
|
||||
return $this->_options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the array of arrays of Zend_Ldap options to be used by
|
||||
* this adapter.
|
||||
*
|
||||
* @param array $options The array of arrays of Zend_Ldap options
|
||||
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
|
||||
*/
|
||||
public function setOptions($options)
|
||||
{
|
||||
$this->_options = is_array($options) ? $options : array();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the username of the account being authenticated, or
|
||||
* NULL if none is set.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->_username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the username for binding
|
||||
*
|
||||
* @param string $username The username for binding
|
||||
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->_username = (string) $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password of the account being authenticated, or
|
||||
* NULL if none is set.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->_password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the passwort for the account
|
||||
*
|
||||
* @param string $password The password of the account being authenticated
|
||||
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->_password = (string) $password;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* setIdentity() - set the identity (username) to be used
|
||||
*
|
||||
* Proxies to {@see setUsername()}
|
||||
*
|
||||
* Closes ZF-6813
|
||||
*
|
||||
* @param string $identity
|
||||
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
|
||||
*/
|
||||
public function setIdentity($identity)
|
||||
{
|
||||
return $this->setUsername($identity);
|
||||
}
|
||||
|
||||
/**
|
||||
* setCredential() - set the credential (password) value to be used
|
||||
*
|
||||
* Proxies to {@see setPassword()}
|
||||
*
|
||||
* Closes ZF-6813
|
||||
*
|
||||
* @param string $credential
|
||||
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
|
||||
*/
|
||||
public function setCredential($credential)
|
||||
{
|
||||
return $this->setPassword($credential);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the LDAP Object
|
||||
*
|
||||
* @return Zend_Ldap The Zend_Ldap object used to authenticate the credentials
|
||||
*/
|
||||
public function getLdap()
|
||||
{
|
||||
if ($this->_ldap === null) {
|
||||
/**
|
||||
* @see Zend_Ldap
|
||||
*/
|
||||
require_once 'Zend/Ldap.php';
|
||||
$this->_ldap = new Zend_Ldap();
|
||||
}
|
||||
|
||||
return $this->_ldap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an Ldap connection
|
||||
*
|
||||
* @param Zend_Ldap $ldap An existing Ldap object
|
||||
* @return Zend_Auth_Adapter_Ldap Provides a fluent interface
|
||||
*/
|
||||
public function setLdap(Zend_Ldap $ldap)
|
||||
{
|
||||
$this->_ldap = $ldap;
|
||||
|
||||
$this->setOptions(array($ldap->getOptions()));
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a domain name for the current LDAP options. This is used
|
||||
* for skipping redundant operations (e.g. authentications).
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getAuthorityName()
|
||||
{
|
||||
$options = $this->getLdap()->getOptions();
|
||||
$name = $options['accountDomainName'];
|
||||
if (!$name)
|
||||
$name = $options['accountDomainNameShort'];
|
||||
return $name ? $name : '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticate the user
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
/**
|
||||
* @see Zend_Ldap_Exception
|
||||
*/
|
||||
require_once 'Zend/Ldap/Exception.php';
|
||||
|
||||
$messages = array();
|
||||
$messages[0] = ''; // reserved
|
||||
$messages[1] = ''; // reserved
|
||||
|
||||
$username = $this->_username;
|
||||
$password = $this->_password;
|
||||
|
||||
if (!$username) {
|
||||
$code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
|
||||
$messages[0] = 'A username is required';
|
||||
return new Zend_Auth_Result($code, '', $messages);
|
||||
}
|
||||
if (!$password) {
|
||||
/* A password is required because some servers will
|
||||
* treat an empty password as an anonymous bind.
|
||||
*/
|
||||
$code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
|
||||
$messages[0] = 'A password is required';
|
||||
return new Zend_Auth_Result($code, '', $messages);
|
||||
}
|
||||
|
||||
$ldap = $this->getLdap();
|
||||
|
||||
$code = Zend_Auth_Result::FAILURE;
|
||||
$messages[0] = "Authority not found: $username";
|
||||
$failedAuthorities = array();
|
||||
|
||||
/* Iterate through each server and try to authenticate the supplied
|
||||
* credentials against it.
|
||||
*/
|
||||
foreach ($this->_options as $name => $options) {
|
||||
|
||||
if (!is_array($options)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Adapter options array not an array');
|
||||
}
|
||||
$adapterOptions = $this->_prepareOptions($ldap, $options);
|
||||
$dname = '';
|
||||
|
||||
try {
|
||||
if ($messages[1])
|
||||
$messages[] = $messages[1];
|
||||
$messages[1] = '';
|
||||
$messages[] = $this->_optionsToString($options);
|
||||
|
||||
$dname = $this->_getAuthorityName();
|
||||
if (isset($failedAuthorities[$dname])) {
|
||||
/* If multiple sets of server options for the same domain
|
||||
* are supplied, we want to skip redundant authentications
|
||||
* where the identity or credentials where found to be
|
||||
* invalid with another server for the same domain. The
|
||||
* $failedAuthorities array tracks this condition (and also
|
||||
* serves to supply the original error message).
|
||||
* This fixes issue ZF-4093.
|
||||
*/
|
||||
$messages[1] = $failedAuthorities[$dname];
|
||||
$messages[] = "Skipping previously failed authority: $dname";
|
||||
continue;
|
||||
}
|
||||
|
||||
$canonicalName = $ldap->getCanonicalAccountName($username);
|
||||
$ldap->bind($canonicalName, $password);
|
||||
/*
|
||||
* Fixes problem when authenticated user is not allowed to retrieve
|
||||
* group-membership information or own account.
|
||||
* This requires that the user specified with "username" and optionally
|
||||
* "password" in the Zend_Ldap options is able to retrieve the required
|
||||
* information.
|
||||
*/
|
||||
$requireRebind = false;
|
||||
if (isset($options['username'])) {
|
||||
$ldap->bind();
|
||||
$requireRebind = true;
|
||||
}
|
||||
$dn = $ldap->getCanonicalAccountName($canonicalName, Zend_Ldap::ACCTNAME_FORM_DN);
|
||||
|
||||
$groupResult = $this->_checkGroupMembership($ldap, $canonicalName, $dn, $adapterOptions);
|
||||
if ($groupResult === true) {
|
||||
$this->_authenticatedDn = $dn;
|
||||
$messages[0] = '';
|
||||
$messages[1] = '';
|
||||
$messages[] = "$canonicalName authentication successful";
|
||||
if ($requireRebind === true) {
|
||||
// rebinding with authenticated user
|
||||
$ldap->bind($dn, $password);
|
||||
}
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $canonicalName, $messages);
|
||||
} else {
|
||||
$messages[0] = 'Account is not a member of the specified group';
|
||||
$messages[1] = $groupResult;
|
||||
$failedAuthorities[$dname] = $groupResult;
|
||||
}
|
||||
} catch (Zend_Ldap_Exception $zle) {
|
||||
|
||||
/* LDAP based authentication is notoriously difficult to diagnose. Therefore
|
||||
* we bend over backwards to capture and record every possible bit of
|
||||
* information when something goes wrong.
|
||||
*/
|
||||
|
||||
$err = $zle->getCode();
|
||||
|
||||
if ($err == Zend_Ldap_Exception::LDAP_X_DOMAIN_MISMATCH) {
|
||||
/* This error indicates that the domain supplied in the
|
||||
* username did not match the domains in the server options
|
||||
* and therefore we should just skip to the next set of
|
||||
* server options.
|
||||
*/
|
||||
continue;
|
||||
} else if ($err == Zend_Ldap_Exception::LDAP_NO_SUCH_OBJECT) {
|
||||
$code = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
|
||||
$messages[0] = "Account not found: $username";
|
||||
$failedAuthorities[$dname] = $zle->getMessage();
|
||||
} else if ($err == Zend_Ldap_Exception::LDAP_INVALID_CREDENTIALS) {
|
||||
$code = Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID;
|
||||
$messages[0] = 'Invalid credentials';
|
||||
$failedAuthorities[$dname] = $zle->getMessage();
|
||||
} else {
|
||||
$line = $zle->getLine();
|
||||
$messages[] = $zle->getFile() . "($line): " . $zle->getMessage();
|
||||
$messages[] = str_replace($password, '*****', $zle->getTraceAsString());
|
||||
$messages[0] = 'An unexpected failure occurred';
|
||||
}
|
||||
$messages[1] = $zle->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
$msg = isset($messages[1]) ? $messages[1] : $messages[0];
|
||||
$messages[] = "$username authentication failed: $msg";
|
||||
|
||||
return new Zend_Auth_Result($code, $username, $messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the LDAP specific options on the Zend_Ldap instance
|
||||
*
|
||||
* @param Zend_Ldap $ldap
|
||||
* @param array $options
|
||||
* @return array of auth-adapter specific options
|
||||
*/
|
||||
protected function _prepareOptions(Zend_Ldap $ldap, array $options)
|
||||
{
|
||||
$adapterOptions = array(
|
||||
'group' => null,
|
||||
'groupDn' => $ldap->getBaseDn(),
|
||||
'groupScope' => Zend_Ldap::SEARCH_SCOPE_SUB,
|
||||
'groupAttr' => 'cn',
|
||||
'groupFilter' => 'objectClass=groupOfUniqueNames',
|
||||
'memberAttr' => 'uniqueMember',
|
||||
'memberIsDn' => true
|
||||
);
|
||||
foreach ($adapterOptions as $key => $value) {
|
||||
if (array_key_exists($key, $options)) {
|
||||
$value = $options[$key];
|
||||
unset($options[$key]);
|
||||
switch ($key) {
|
||||
case 'groupScope':
|
||||
$value = (int)$value;
|
||||
if (in_array($value, array(Zend_Ldap::SEARCH_SCOPE_BASE,
|
||||
Zend_Ldap::SEARCH_SCOPE_ONE, Zend_Ldap::SEARCH_SCOPE_SUB), true)) {
|
||||
$adapterOptions[$key] = $value;
|
||||
}
|
||||
break;
|
||||
case 'memberIsDn':
|
||||
$adapterOptions[$key] = ($value === true ||
|
||||
$value === '1' || strcasecmp($value, 'true') == 0);
|
||||
break;
|
||||
default:
|
||||
$adapterOptions[$key] = trim($value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
$ldap->setOptions($options);
|
||||
return $adapterOptions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the group membership of the bound user
|
||||
*
|
||||
* @param Zend_Ldap $ldap
|
||||
* @param string $canonicalName
|
||||
* @param string $dn
|
||||
* @param array $adapterOptions
|
||||
* @return string|true
|
||||
*/
|
||||
protected function _checkGroupMembership(Zend_Ldap $ldap, $canonicalName, $dn, array $adapterOptions)
|
||||
{
|
||||
if ($adapterOptions['group'] === null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($adapterOptions['memberIsDn'] === false) {
|
||||
$user = $canonicalName;
|
||||
} else {
|
||||
$user = $dn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Zend_Ldap_Filter
|
||||
*/
|
||||
require_once 'Zend/Ldap/Filter.php';
|
||||
$groupName = Zend_Ldap_Filter::equals($adapterOptions['groupAttr'], $adapterOptions['group']);
|
||||
$membership = Zend_Ldap_Filter::equals($adapterOptions['memberAttr'], $user);
|
||||
$group = Zend_Ldap_Filter::andFilter($groupName, $membership);
|
||||
$groupFilter = $adapterOptions['groupFilter'];
|
||||
if (!empty($groupFilter)) {
|
||||
$group = $group->addAnd($groupFilter);
|
||||
}
|
||||
|
||||
$result = $ldap->count($group, $adapterOptions['groupDn'], $adapterOptions['groupScope']);
|
||||
|
||||
if ($result === 1) {
|
||||
return true;
|
||||
} else {
|
||||
return 'Failed to verify group membership with ' . $group->toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* getAccountObject() - Returns the result entry as a stdClass object
|
||||
*
|
||||
* This resembles the feature {@see Zend_Auth_Adapter_DbTable::getResultRowObject()}.
|
||||
* Closes ZF-6813
|
||||
*
|
||||
* @param array $returnAttribs
|
||||
* @param array $omitAttribs
|
||||
* @return stdClass|boolean
|
||||
*/
|
||||
public function getAccountObject(array $returnAttribs = array(), array $omitAttribs = array())
|
||||
{
|
||||
if (!$this->_authenticatedDn) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$returnObject = new stdClass();
|
||||
|
||||
$returnAttribs = array_map('strtolower', $returnAttribs);
|
||||
$omitAttribs = array_map('strtolower', $omitAttribs);
|
||||
$returnAttribs = array_diff($returnAttribs, $omitAttribs);
|
||||
|
||||
$entry = $this->getLdap()->getEntry($this->_authenticatedDn, $returnAttribs, true);
|
||||
foreach ($entry as $attr => $value) {
|
||||
if (in_array($attr, $omitAttribs)) {
|
||||
// skip attributes marked to be omitted
|
||||
continue;
|
||||
}
|
||||
if (is_array($value)) {
|
||||
$returnObject->$attr = (count($value) > 1) ? $value : $value[0];
|
||||
} else {
|
||||
$returnObject->$attr = $value;
|
||||
}
|
||||
}
|
||||
return $returnObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts options to string
|
||||
*
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
private function _optionsToString(array $options)
|
||||
{
|
||||
$str = '';
|
||||
foreach ($options as $key => $val) {
|
||||
if ($key === 'password')
|
||||
$val = '*****';
|
||||
if ($str)
|
||||
$str .= ',';
|
||||
$str .= $key . '=' . $val;
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
284
library/Zend/Auth/Adapter/OpenId.php
Normale Datei
284
library/Zend/Auth/Adapter/OpenId.php
Normale Datei
|
|
@ -0,0 +1,284 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_OpenId_Consumer
|
||||
*/
|
||||
require_once 'Zend/OpenId/Consumer.php';
|
||||
|
||||
|
||||
/**
|
||||
* A Zend_Auth Authentication Adapter allowing the use of OpenID protocol as an
|
||||
* authentication mechanism
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Zend_Auth_Adapter
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Adapter_OpenId implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
/**
|
||||
* The identity value being authenticated
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_id = null;
|
||||
|
||||
/**
|
||||
* Reference to an implementation of a storage object
|
||||
*
|
||||
* @var Zend_OpenId_Consumer_Storage
|
||||
*/
|
||||
private $_storage = null;
|
||||
|
||||
/**
|
||||
* The URL to redirect response from server to
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_returnTo = null;
|
||||
|
||||
/**
|
||||
* The HTTP URL to identify consumer on server
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_root = null;
|
||||
|
||||
/**
|
||||
* Extension object or array of extensions objects
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $_extensions = null;
|
||||
|
||||
/**
|
||||
* The response object to perform HTTP or HTML form redirection
|
||||
*
|
||||
* @var Zend_Controller_Response_Abstract
|
||||
*/
|
||||
private $_response = null;
|
||||
|
||||
/**
|
||||
* Enables or disables interaction with user during authentication on
|
||||
* OpenID provider.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $_check_immediate = false;
|
||||
|
||||
/**
|
||||
* HTTP client to make HTTP requests
|
||||
*
|
||||
* @var Zend_Http_Client $_httpClient
|
||||
*/
|
||||
private $_httpClient = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $id the identity value
|
||||
* @param Zend_OpenId_Consumer_Storage $storage an optional implementation
|
||||
* of a storage object
|
||||
* @param string $returnTo HTTP URL to redirect response from server to
|
||||
* @param string $root HTTP URL to identify consumer on server
|
||||
* @param mixed $extensions extension object or array of extensions objects
|
||||
* @param Zend_Controller_Response_Abstract $response an optional response
|
||||
* object to perform HTTP or HTML form redirection
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($id = null,
|
||||
Zend_OpenId_Consumer_Storage $storage = null,
|
||||
$returnTo = null,
|
||||
$root = null,
|
||||
$extensions = null,
|
||||
Zend_Controller_Response_Abstract $response = null) {
|
||||
$this->_id = $id;
|
||||
$this->_storage = $storage;
|
||||
$this->_returnTo = $returnTo;
|
||||
$this->_root = $root;
|
||||
$this->_extensions = $extensions;
|
||||
$this->_response = $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value to be used as the identity
|
||||
*
|
||||
* @param string $id the identity value
|
||||
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
|
||||
*/
|
||||
public function setIdentity($id)
|
||||
{
|
||||
$this->_id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the storage implementation which will be use by OpenId
|
||||
*
|
||||
* @param Zend_OpenId_Consumer_Storage $storage
|
||||
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
|
||||
*/
|
||||
public function setStorage(Zend_OpenId_Consumer_Storage $storage)
|
||||
{
|
||||
$this->_storage = $storage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the HTTP URL to redirect response from server to
|
||||
*
|
||||
* @param string $returnTo
|
||||
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
|
||||
*/
|
||||
public function setReturnTo($returnTo)
|
||||
{
|
||||
$this->_returnTo = $returnTo;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets HTTP URL to identify consumer on server
|
||||
*
|
||||
* @param string $root
|
||||
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
|
||||
*/
|
||||
public function setRoot($root)
|
||||
{
|
||||
$this->_root = $root;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets OpenID extension(s)
|
||||
*
|
||||
* @param mixed $extensions
|
||||
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
|
||||
*/
|
||||
public function setExtensions($extensions)
|
||||
{
|
||||
$this->_extensions = $extensions;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets an optional response object to perform HTTP or HTML form redirection
|
||||
*
|
||||
* @param string $root
|
||||
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
|
||||
*/
|
||||
public function setResponse($response)
|
||||
{
|
||||
$this->_response = $response;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables or disables interaction with user during authentication on
|
||||
* OpenID provider.
|
||||
*
|
||||
* @param bool $check_immediate
|
||||
* @return Zend_Auth_Adapter_OpenId Provides a fluent interface
|
||||
*/
|
||||
public function setCheckImmediate($check_immediate)
|
||||
{
|
||||
$this->_check_immediate = $check_immediate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets HTTP client object to make HTTP requests
|
||||
*
|
||||
* @param Zend_Http_Client $client HTTP client object to be used
|
||||
*/
|
||||
public function setHttpClient($client) {
|
||||
$this->_httpClient = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Authenticates the given OpenId identity.
|
||||
* Defined by Zend_Auth_Adapter_Interface.
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception If answering the authentication query is impossible
|
||||
* @return Zend_Auth_Result
|
||||
*/
|
||||
public function authenticate() {
|
||||
$id = $this->_id;
|
||||
if (!empty($id)) {
|
||||
$consumer = new Zend_OpenId_Consumer($this->_storage);
|
||||
$consumer->setHttpClient($this->_httpClient);
|
||||
/* login() is never returns on success */
|
||||
if (!$this->_check_immediate) {
|
||||
if (!$consumer->login($id,
|
||||
$this->_returnTo,
|
||||
$this->_root,
|
||||
$this->_extensions,
|
||||
$this->_response)) {
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE,
|
||||
$id,
|
||||
array("Authentication failed", $consumer->getError()));
|
||||
}
|
||||
} else {
|
||||
if (!$consumer->check($id,
|
||||
$this->_returnTo,
|
||||
$this->_root,
|
||||
$this->_extensions,
|
||||
$this->_response)) {
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE,
|
||||
$id,
|
||||
array("Authentication failed", $consumer->getError()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$params = (isset($_SERVER['REQUEST_METHOD']) &&
|
||||
$_SERVER['REQUEST_METHOD']=='POST') ? $_POST: $_GET;
|
||||
$consumer = new Zend_OpenId_Consumer($this->_storage);
|
||||
$consumer->setHttpClient($this->_httpClient);
|
||||
if ($consumer->verify(
|
||||
$params,
|
||||
$id,
|
||||
$this->_extensions)) {
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::SUCCESS,
|
||||
$id,
|
||||
array("Authentication successful"));
|
||||
} else {
|
||||
return new Zend_Auth_Result(
|
||||
Zend_Auth_Result::FAILURE,
|
||||
$id,
|
||||
array("Authentication failed", $consumer->getError()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
36
library/Zend/Auth/Exception.php
Normale Datei
36
library/Zend/Auth/Exception.php
Normale Datei
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Exception extends Zend_Exception
|
||||
{}
|
||||
148
library/Zend/Auth/Result.php
Normale Datei
148
library/Zend/Auth/Result.php
Normale Datei
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Result
|
||||
{
|
||||
/**
|
||||
* General Failure
|
||||
*/
|
||||
const FAILURE = 0;
|
||||
|
||||
/**
|
||||
* Failure due to identity not being found.
|
||||
*/
|
||||
const FAILURE_IDENTITY_NOT_FOUND = -1;
|
||||
|
||||
/**
|
||||
* Failure due to identity being ambiguous.
|
||||
*/
|
||||
const FAILURE_IDENTITY_AMBIGUOUS = -2;
|
||||
|
||||
/**
|
||||
* Failure due to invalid credential being supplied.
|
||||
*/
|
||||
const FAILURE_CREDENTIAL_INVALID = -3;
|
||||
|
||||
/**
|
||||
* Failure due to uncategorized reasons.
|
||||
*/
|
||||
const FAILURE_UNCATEGORIZED = -4;
|
||||
|
||||
/**
|
||||
* Authentication success.
|
||||
*/
|
||||
const SUCCESS = 1;
|
||||
|
||||
/**
|
||||
* Authentication result code
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_code;
|
||||
|
||||
/**
|
||||
* The identity used in the authentication attempt
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_identity;
|
||||
|
||||
/**
|
||||
* An array of string reasons why the authentication attempt was unsuccessful
|
||||
*
|
||||
* If authentication was successful, this should be an empty array.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_messages;
|
||||
|
||||
/**
|
||||
* Sets the result code, identity, and failure messages
|
||||
*
|
||||
* @param int $code
|
||||
* @param mixed $identity
|
||||
* @param array $messages
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($code, $identity, array $messages = array())
|
||||
{
|
||||
$code = (int) $code;
|
||||
|
||||
if ($code < self::FAILURE_UNCATEGORIZED) {
|
||||
$code = self::FAILURE;
|
||||
} elseif ($code > self::SUCCESS ) {
|
||||
$code = 1;
|
||||
}
|
||||
|
||||
$this->_code = $code;
|
||||
$this->_identity = $identity;
|
||||
$this->_messages = $messages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the result represents a successful authentication attempt
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isValid()
|
||||
{
|
||||
return ($this->_code > 0) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* getCode() - Get the result code for this authentication attempt
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getCode()
|
||||
{
|
||||
return $this->_code;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identity used in the authentication attempt
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getIdentity()
|
||||
{
|
||||
return $this->_identity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of string reasons why the authentication attempt was unsuccessful
|
||||
*
|
||||
* If authentication was successful, this method returns an empty array.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMessages()
|
||||
{
|
||||
return $this->_messages;
|
||||
}
|
||||
}
|
||||
38
library/Zend/Auth/Storage/Exception.php
Normale Datei
38
library/Zend/Auth/Storage/Exception.php
Normale Datei
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Exception.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Storage_Exception extends Zend_Auth_Exception
|
||||
{}
|
||||
66
library/Zend/Auth/Storage/Interface.php
Normale Datei
66
library/Zend/Auth/Storage/Interface.php
Normale Datei
|
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Auth_Storage_Interface
|
||||
{
|
||||
/**
|
||||
* Returns true if and only if storage is empty
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If it is impossible to determine whether storage is empty
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty();
|
||||
|
||||
/**
|
||||
* Returns the contents of storage
|
||||
*
|
||||
* Behavior is undefined when storage is empty.
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If reading contents from storage is impossible
|
||||
* @return mixed
|
||||
*/
|
||||
public function read();
|
||||
|
||||
/**
|
||||
* Writes $contents to storage
|
||||
*
|
||||
* @param mixed $contents
|
||||
* @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function write($contents);
|
||||
|
||||
/**
|
||||
* Clears contents from storage
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If clearing contents from storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function clear();
|
||||
}
|
||||
95
library/Zend/Auth/Storage/NonPersistent.php
Normale Datei
95
library/Zend/Auth/Storage/NonPersistent.php
Normale Datei
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Storage_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Storage/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* Non-Persistent Auth Storage
|
||||
*
|
||||
* Since HTTP Authentication happens again on each request, this will always be
|
||||
* re-populated. So there's no need to use sessions, this simple value class
|
||||
* will hold the data for rest of the current request.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Storage_NonPersistent implements Zend_Auth_Storage_Interface
|
||||
{
|
||||
/**
|
||||
* Holds the actual auth data
|
||||
*/
|
||||
protected $_data;
|
||||
|
||||
/**
|
||||
* Returns true if and only if storage is empty
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If it is impossible to determine whether storage is empty
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return empty($this->_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the contents of storage
|
||||
* Behavior is undefined when storage is empty.
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If reading contents from storage is impossible
|
||||
* @return mixed
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes $contents to storage
|
||||
*
|
||||
* @param mixed $contents
|
||||
* @throws Zend_Auth_Storage_Exception If writing $contents to storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function write($contents)
|
||||
{
|
||||
$this->_data = $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears contents from storage
|
||||
*
|
||||
* @throws Zend_Auth_Storage_Exception If clearing contents from storage is impossible
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
$this->_data = null;
|
||||
}
|
||||
}
|
||||
150
library/Zend/Auth/Storage/Session.php
Normale Datei
150
library/Zend/Auth/Storage/Session.php
Normale Datei
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Auth_Storage_Interface
|
||||
*/
|
||||
require_once 'Zend/Auth/Storage/Interface.php';
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Session
|
||||
*/
|
||||
require_once 'Zend/Session.php';
|
||||
|
||||
|
||||
/**
|
||||
* @category Zend
|
||||
* @package Zend_Auth
|
||||
* @subpackage Storage
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Auth_Storage_Session implements Zend_Auth_Storage_Interface
|
||||
{
|
||||
/**
|
||||
* Default session namespace
|
||||
*/
|
||||
const NAMESPACE_DEFAULT = 'Zend_Auth';
|
||||
|
||||
/**
|
||||
* Default session object member name
|
||||
*/
|
||||
const MEMBER_DEFAULT = 'storage';
|
||||
|
||||
/**
|
||||
* Object to proxy $_SESSION storage
|
||||
*
|
||||
* @var Zend_Session_Namespace
|
||||
*/
|
||||
protected $_session;
|
||||
|
||||
/**
|
||||
* Session namespace
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_namespace;
|
||||
|
||||
/**
|
||||
* Session object member
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_member;
|
||||
|
||||
/**
|
||||
* Sets session storage options and initializes session namespace object
|
||||
*
|
||||
* @param mixed $namespace
|
||||
* @param mixed $member
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($namespace = self::NAMESPACE_DEFAULT, $member = self::MEMBER_DEFAULT)
|
||||
{
|
||||
$this->_namespace = $namespace;
|
||||
$this->_member = $member;
|
||||
$this->_session = new Zend_Session_Namespace($this->_namespace);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the session namespace
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNamespace()
|
||||
{
|
||||
return $this->_namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the session object member
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMember()
|
||||
{
|
||||
return $this->_member;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return !isset($this->_session->{$this->_member});
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function read()
|
||||
{
|
||||
return $this->_session->{$this->_member};
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @param mixed $contents
|
||||
* @return void
|
||||
*/
|
||||
public function write($contents)
|
||||
{
|
||||
$this->_session->{$this->_member} = $contents;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Auth_Storage_Interface
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function clear()
|
||||
{
|
||||
unset($this->_session->{$this->_member});
|
||||
}
|
||||
}
|
||||
250
library/Zend/Cache.php
Normale Datei
250
library/Zend/Cache.php
Normale Datei
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Cache
|
||||
{
|
||||
|
||||
/**
|
||||
* Standard frontends
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||
|
||||
/**
|
||||
* Standard backends
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform',
|
||||
'Xcache', 'TwoLevels', 'WinCache', 'ZendServer_Disk', 'ZendServer_ShMem');
|
||||
|
||||
/**
|
||||
* Standard backends which implement the ExtendedInterface
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $standardExtendedBackends = array('File', 'Apc', 'TwoLevels', 'Memcached', 'Libmemcached', 'Sqlite', 'WinCache');
|
||||
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @var array
|
||||
* @deprecated
|
||||
*/
|
||||
public static $availableFrontends = array('Core', 'Output', 'Class', 'File', 'Function', 'Page');
|
||||
|
||||
/**
|
||||
* Only for backward compatibility (may be removed in next major release)
|
||||
*
|
||||
* @var array
|
||||
* @deprecated
|
||||
*/
|
||||
public static $availableBackends = array('File', 'Sqlite', 'Memcached', 'Libmemcached', 'Apc', 'ZendPlatform', 'Xcache', 'WinCache', 'TwoLevels');
|
||||
|
||||
/**
|
||||
* Consts for clean() method
|
||||
*/
|
||||
const CLEANING_MODE_ALL = 'all';
|
||||
const CLEANING_MODE_OLD = 'old';
|
||||
const CLEANING_MODE_MATCHING_TAG = 'matchingTag';
|
||||
const CLEANING_MODE_NOT_MATCHING_TAG = 'notMatchingTag';
|
||||
const CLEANING_MODE_MATCHING_ANY_TAG = 'matchingAnyTag';
|
||||
|
||||
/**
|
||||
* Factory
|
||||
*
|
||||
* @param mixed $frontend frontend name (string) or Zend_Cache_Frontend_ object
|
||||
* @param mixed $backend backend name (string) or Zend_Cache_Backend_ object
|
||||
* @param array $frontendOptions associative array of options for the corresponding frontend constructor
|
||||
* @param array $backendOptions associative array of options for the corresponding backend constructor
|
||||
* @param boolean $customFrontendNaming if true, the frontend argument is used as a complete class name ; if false, the frontend argument is used as the end of "Zend_Cache_Frontend_[...]" class name
|
||||
* @param boolean $customBackendNaming if true, the backend argument is used as a complete class name ; if false, the backend argument is used as the end of "Zend_Cache_Backend_[...]" class name
|
||||
* @param boolean $autoload if true, there will no require_once for backend and frontend (useful only for custom backends/frontends)
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||
*/
|
||||
public static function factory($frontend, $backend, $frontendOptions = array(), $backendOptions = array(), $customFrontendNaming = false, $customBackendNaming = false, $autoload = false)
|
||||
{
|
||||
if (is_string($backend)) {
|
||||
$backendObject = self::_makeBackend($backend, $backendOptions, $customBackendNaming, $autoload);
|
||||
} else {
|
||||
if ((is_object($backend)) && (in_array('Zend_Cache_Backend_Interface', class_implements($backend)))) {
|
||||
$backendObject = $backend;
|
||||
} else {
|
||||
self::throwException('backend must be a backend name (string) or an object which implements Zend_Cache_Backend_Interface');
|
||||
}
|
||||
}
|
||||
if (is_string($frontend)) {
|
||||
$frontendObject = self::_makeFrontend($frontend, $frontendOptions, $customFrontendNaming, $autoload);
|
||||
} else {
|
||||
if (is_object($frontend)) {
|
||||
$frontendObject = $frontend;
|
||||
} else {
|
||||
self::throwException('frontend must be a frontend name (string) or an object');
|
||||
}
|
||||
}
|
||||
$frontendObject->setBackend($backendObject);
|
||||
return $frontendObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Backend Constructor
|
||||
*
|
||||
* @param string $backend
|
||||
* @param array $backendOptions
|
||||
* @param boolean $customBackendNaming
|
||||
* @param boolean $autoload
|
||||
* @return Zend_Cache_Backend
|
||||
*/
|
||||
public static function _makeBackend($backend, $backendOptions, $customBackendNaming = false, $autoload = false)
|
||||
{
|
||||
if (!$customBackendNaming) {
|
||||
$backend = self::_normalizeName($backend);
|
||||
}
|
||||
if (in_array($backend, Zend_Cache::$standardBackends)) {
|
||||
// we use a standard backend
|
||||
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||
// security controls are explicit
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||
} else {
|
||||
// we use a custom backend
|
||||
if (!preg_match('~^[\w]+$~D', $backend)) {
|
||||
Zend_Cache::throwException("Invalid backend name [$backend]");
|
||||
}
|
||||
if (!$customBackendNaming) {
|
||||
// we use this boolean to avoid an API break
|
||||
$backendClass = 'Zend_Cache_Backend_' . $backend;
|
||||
} else {
|
||||
$backendClass = $backend;
|
||||
}
|
||||
if (!$autoload) {
|
||||
$file = str_replace('_', DIRECTORY_SEPARATOR, $backendClass) . '.php';
|
||||
if (!(self::_isReadable($file))) {
|
||||
self::throwException("file $file not found in include_path");
|
||||
}
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
return new $backendClass($backendOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Frontend Constructor
|
||||
*
|
||||
* @param string $frontend
|
||||
* @param array $frontendOptions
|
||||
* @param boolean $customFrontendNaming
|
||||
* @param boolean $autoload
|
||||
* @return Zend_Cache_Core|Zend_Cache_Frontend
|
||||
*/
|
||||
public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false)
|
||||
{
|
||||
if (!$customFrontendNaming) {
|
||||
$frontend = self::_normalizeName($frontend);
|
||||
}
|
||||
if (in_array($frontend, self::$standardFrontends)) {
|
||||
// we use a standard frontend
|
||||
// For perfs reasons, with frontend == 'Core', we can interact with the Core itself
|
||||
$frontendClass = 'Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend;
|
||||
// security controls are explicit
|
||||
require_once str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||
} else {
|
||||
// we use a custom frontend
|
||||
if (!preg_match('~^[\w]+$~D', $frontend)) {
|
||||
Zend_Cache::throwException("Invalid frontend name [$frontend]");
|
||||
}
|
||||
if (!$customFrontendNaming) {
|
||||
// we use this boolean to avoid an API break
|
||||
$frontendClass = 'Zend_Cache_Frontend_' . $frontend;
|
||||
} else {
|
||||
$frontendClass = $frontend;
|
||||
}
|
||||
if (!$autoload) {
|
||||
$file = str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php';
|
||||
if (!(self::_isReadable($file))) {
|
||||
self::throwException("file $file not found in include_path");
|
||||
}
|
||||
require_once $file;
|
||||
}
|
||||
}
|
||||
return new $frontendClass($frontendOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throw an exception
|
||||
*
|
||||
* Note : for perf reasons, the "load" of Zend/Cache/Exception is dynamic
|
||||
* @param string $msg Message for the exception
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public static function throwException($msg, Exception $e = null)
|
||||
{
|
||||
// For perfs reasons, we use this dynamic inclusion
|
||||
require_once 'Zend/Cache/Exception.php';
|
||||
throw new Zend_Cache_Exception($msg, 0, $e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize frontend and backend names to allow multiple words TitleCased
|
||||
*
|
||||
* @param string $name Name to normalize
|
||||
* @return string
|
||||
*/
|
||||
protected static function _normalizeName($name)
|
||||
{
|
||||
$name = ucfirst(strtolower($name));
|
||||
$name = str_replace(array('-', '_', '.'), ' ', $name);
|
||||
$name = ucwords($name);
|
||||
$name = str_replace(' ', '', $name);
|
||||
if (stripos($name, 'ZendServer') === 0) {
|
||||
$name = 'ZendServer_' . substr($name, strlen('ZendServer'));
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns TRUE if the $filename is readable, or FALSE otherwise.
|
||||
* This function uses the PHP include_path, where PHP's is_readable()
|
||||
* does not.
|
||||
*
|
||||
* Note : this method comes from Zend_Loader (see #ZF-2891 for details)
|
||||
*
|
||||
* @param string $filename
|
||||
* @return boolean
|
||||
*/
|
||||
private static function _isReadable($filename)
|
||||
{
|
||||
if (!$fh = @fopen($filename, 'r', true)) {
|
||||
return false;
|
||||
}
|
||||
@fclose($fh);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
266
library/Zend/Cache/Backend.php
Normale Datei
266
library/Zend/Cache/Backend.php
Normale Datei
|
|
@ -0,0 +1,266 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend
|
||||
{
|
||||
/**
|
||||
* Frontend or Core directives
|
||||
*
|
||||
* =====> (int) lifetime :
|
||||
* - Cache lifetime (in seconds)
|
||||
* - If null, the cache is valid forever
|
||||
*
|
||||
* =====> (int) logging :
|
||||
* - if set to true, a logging is activated throw Zend_Log
|
||||
*
|
||||
* @var array directives
|
||||
*/
|
||||
protected $_directives = array(
|
||||
'lifetime' => 3600,
|
||||
'logging' => false,
|
||||
'logger' => null
|
||||
);
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options Associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
while (list($name, $value) = each($options)) {
|
||||
$this->setOption($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
if (!is_array($directives)) Zend_Cache::throwException('Directives parameter must be an array');
|
||||
while (list($name, $value) = each($directives)) {
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_directives)) {
|
||||
$this->_directives[$name] = $value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->_loggerSanity();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an option
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setOption($name, $value)
|
||||
{
|
||||
if (!is_string($name)) {
|
||||
Zend_Cache::throwException("Incorrect option name : $name");
|
||||
}
|
||||
$name = strtolower($name);
|
||||
if (array_key_exists($name, $this->_options)) {
|
||||
$this->_options[$name] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the life time
|
||||
*
|
||||
* if $specificLifetime is not false, the given specific life time is used
|
||||
* else, the global lifetime is used
|
||||
*
|
||||
* @param int $specificLifetime
|
||||
* @return int Cache life time
|
||||
*/
|
||||
public function getLifetime($specificLifetime)
|
||||
{
|
||||
if ($specificLifetime === false) {
|
||||
return $this->_directives['lifetime'];
|
||||
}
|
||||
return $specificLifetime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine system TMP directory and detect if we have read access
|
||||
*
|
||||
* inspired from Zend_File_Transfer_Adapter_Abstract
|
||||
*
|
||||
* @return string
|
||||
* @throws Zend_Cache_Exception if unable to determine directory
|
||||
*/
|
||||
public function getTmpDir()
|
||||
{
|
||||
$tmpdir = array();
|
||||
foreach (array($_ENV, $_SERVER) as $tab) {
|
||||
foreach (array('TMPDIR', 'TEMP', 'TMP', 'windir', 'SystemRoot') as $key) {
|
||||
if (isset($tab[$key])) {
|
||||
if (($key == 'windir') or ($key == 'SystemRoot')) {
|
||||
$dir = realpath($tab[$key] . '\\temp');
|
||||
} else {
|
||||
$dir = realpath($tab[$key]);
|
||||
}
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$upload = ini_get('upload_tmp_dir');
|
||||
if ($upload) {
|
||||
$dir = realpath($upload);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if (function_exists('sys_get_temp_dir')) {
|
||||
$dir = sys_get_temp_dir();
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
// Attemp to detect by creating a temporary file
|
||||
$tempFile = tempnam(md5(uniqid(rand(), TRUE)), '');
|
||||
if ($tempFile) {
|
||||
$dir = realpath(dirname($tempFile));
|
||||
unlink($tempFile);
|
||||
if ($this->_isGoodTmpDir($dir)) {
|
||||
return $dir;
|
||||
}
|
||||
}
|
||||
if ($this->_isGoodTmpDir('/tmp')) {
|
||||
return '/tmp';
|
||||
}
|
||||
if ($this->_isGoodTmpDir('\\temp')) {
|
||||
return '\\temp';
|
||||
}
|
||||
Zend_Cache::throwException('Could not determine temp directory, please specify a cache_dir manually');
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify if the given temporary directory is readable and writable
|
||||
*
|
||||
* @param string $dir temporary directory
|
||||
* @return boolean true if the directory is ok
|
||||
*/
|
||||
protected function _isGoodTmpDir($dir)
|
||||
{
|
||||
if (is_readable($dir)) {
|
||||
if (is_writable($dir)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure if we enable logging that the Zend_Log class
|
||||
* is available.
|
||||
* Create a default log object if none is set.
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _loggerSanity()
|
||||
{
|
||||
if (!isset($this->_directives['logging']) || !$this->_directives['logging']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($this->_directives['logger'])) {
|
||||
if ($this->_directives['logger'] instanceof Zend_Log) {
|
||||
return;
|
||||
}
|
||||
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||
}
|
||||
|
||||
// Create a default logger to the standard output stream
|
||||
require_once 'Zend/Log.php';
|
||||
require_once 'Zend/Log/Writer/Stream.php';
|
||||
$logger = new Zend_Log(new Zend_Log_Writer_Stream('php://output'));
|
||||
$this->_directives['logger'] = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log a message at the WARN (4) priority.
|
||||
*
|
||||
* @param string $message
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
protected function _log($message, $priority = 4)
|
||||
{
|
||||
if (!$this->_directives['logging']) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isset($this->_directives['logger'])) {
|
||||
Zend_Cache::throwException('Logging is enabled but logger is not set.');
|
||||
}
|
||||
$logger = $this->_directives['logger'];
|
||||
if (!$logger instanceof Zend_Log) {
|
||||
Zend_Cache::throwException('Logger object is not an instance of Zend_Log class.');
|
||||
}
|
||||
$logger->log($message, $priority);
|
||||
}
|
||||
}
|
||||
355
library/Zend/Cache/Backend/Apc.php
Normale Datei
355
library/Zend/Cache/Backend/Apc.php
Normale Datei
|
|
@ -0,0 +1,355 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Apc extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::clean() : tags are unsupported by the Apc backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND = 'Zend_Cache_Backend_Apc::save() : tags are unsupported by the Apc backend';
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('apc')) {
|
||||
Zend_Cache::throwException('The apc extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* WARNING $doNotTestCacheValidity=true is unsupported by the Apc backend
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string cached datas (or false)
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data datas to cache
|
||||
* @param string $id cache id
|
||||
* @param array $tags array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime if != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
$result = apc_store($id, array($data, time(), $lifetime), $lifetime);
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return apc_delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param array $tags array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return apc_clear_cache('user');
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Apc::clean() : CLEANING_MODE_OLD is unsupported by the Apc backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_APC_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* DEPRECATED : use getCapabilities() instead
|
||||
*
|
||||
* @deprecated
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mem = apc_sma_info(true);
|
||||
$memSize = $mem['num_seg'] * $mem['seg_size'];
|
||||
$memAvailable= $mem['avail_mem'];
|
||||
$memUsed = $memSize - $memAvailable;
|
||||
if ($memSize == 0) {
|
||||
Zend_Cache::throwException('can\'t get apc memory size');
|
||||
}
|
||||
if ($memUsed > $memSize) {
|
||||
return 100;
|
||||
}
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_APC_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$res = array();
|
||||
$array = apc_cache_info('user', false);
|
||||
$records = $array['cache_list'];
|
||||
foreach ($records as $record) {
|
||||
$res[] = $record['info'];
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = apc_fetch($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
apc_store($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => true
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
250
library/Zend/Cache/Backend/BlackHole.php
Normale Datei
250
library/Zend/Cache/Backend/BlackHole.php
Normale Datei
|
|
@ -0,0 +1,250 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_BlackHole
|
||||
extends Zend_Cache_Backend
|
||||
implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param boolean $doNotTestCacheValidity if set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => remove too old cache entries ($tags is not used)
|
||||
* 'matchingTag' => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'notMatchingTag' => remove cache entries not matching one of the given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* 'matchingAnyTag' => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode clean mode
|
||||
* @param tags array $tags array of tags
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
* @throws Zend_Cache_Exception
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => true,
|
||||
'tags' => true,
|
||||
'expired_read' => true,
|
||||
'priority' => true,
|
||||
'infinite_lifetime' => true,
|
||||
'get_list' => true,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* PUBLIC METHOD FOR UNIT TESTING ONLY !
|
||||
*
|
||||
* Force a cache record to expire
|
||||
*
|
||||
* @param string $id cache id
|
||||
*/
|
||||
public function ___expire($id)
|
||||
{
|
||||
}
|
||||
}
|
||||
126
library/Zend/Cache/Backend/ExtendedInterface.php
Normale Datei
126
library/Zend/Cache/Backend/ExtendedInterface.php
Normale Datei
|
|
@ -0,0 +1,126 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/Interface.php';
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Cache_Backend_ExtendedInterface extends Zend_Cache_Backend_Interface
|
||||
{
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds();
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags();
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array());
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage();
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id);
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime);
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities();
|
||||
|
||||
}
|
||||
1006
library/Zend/Cache/Backend/File.php
Normale Datei
1006
library/Zend/Cache/Backend/File.php
Normale Datei
Datei-Diff unterdrückt, da er zu groß ist
Diff laden
99
library/Zend/Cache/Backend/Interface.php
Normale Datei
99
library/Zend/Cache/Backend/Interface.php
Normale Datei
|
|
@ -0,0 +1,99 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
interface Zend_Cache_Backend_Interface
|
||||
{
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives assoc of directives
|
||||
*/
|
||||
public function setDirectives($directives);
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* Note : return value is always "string" (unserialization is done by the core not by the backend)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false);
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id);
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false);
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id);
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags}
|
||||
* ($tags can be an array of strings or a single string)
|
||||
* Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags
|
||||
* ($tags can be an array of strings or a single string)
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @return boolean true if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array());
|
||||
|
||||
}
|
||||
484
library/Zend/Cache/Backend/Libmemcached.php
Normale Datei
484
library/Zend/Cache/Backend/Libmemcached.php
Normale Datei
|
|
@ -0,0 +1,484 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Libmemcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Default Server Values
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 11211;
|
||||
const DEFAULT_WEIGHT = 1;
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::clean() : tags are unsupported by the Libmemcached backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND = 'Zend_Cache_Backend_Libmemcached::save() : tags are unsupported by the Libmemcached backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (array) servers :
|
||||
* an array of memcached server ; each memcached server is described by an associative array :
|
||||
* 'host' => (string) : the name of the memcached server
|
||||
* 'port' => (int) : the port of the memcached server
|
||||
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||
* probability of it being selected. The probability is relative to the total
|
||||
* weight of all servers.
|
||||
* =====> (array) client :
|
||||
* an array of memcached client options ; the memcached client is described by an associative array :
|
||||
* @see http://php.net/manual/memcached.constants.php
|
||||
* - The option name can be the name of the constant without the prefix 'OPT_'
|
||||
* or the integer value of this option constant
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'servers' => array(array(
|
||||
'host' => self::DEFAULT_HOST,
|
||||
'port' => self::DEFAULT_PORT,
|
||||
'weight' => self::DEFAULT_WEIGHT,
|
||||
)),
|
||||
'client' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Memcached object
|
||||
*
|
||||
* @var mixed memcached object
|
||||
*/
|
||||
protected $_memcache = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('memcached')) {
|
||||
Zend_Cache::throwException('The memcached extension must be loaded for using this backend !');
|
||||
}
|
||||
|
||||
// override default client options
|
||||
$this->_options['client'] = array(
|
||||
Memcached::OPT_DISTRIBUTION => Memcached::DISTRIBUTION_CONSISTENT,
|
||||
Memcached::OPT_HASH => Memcached::HASH_MD5,
|
||||
Memcached::OPT_LIBKETAMA_COMPATIBLE => true,
|
||||
);
|
||||
|
||||
parent::__construct($options);
|
||||
|
||||
if (isset($this->_options['servers'])) {
|
||||
$value = $this->_options['servers'];
|
||||
if (isset($value['host'])) {
|
||||
// in this case, $value seems to be a simple associative array (one server only)
|
||||
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
||||
}
|
||||
$this->setOption('servers', $value);
|
||||
}
|
||||
$this->_memcache = new Memcached;
|
||||
|
||||
// setup memcached client options
|
||||
foreach ($this->_options['client'] as $name => $value) {
|
||||
$optId = null;
|
||||
if (is_int($name)) {
|
||||
$optId = $name;
|
||||
} else {
|
||||
$optConst = 'Memcached::OPT_' . strtoupper($name);
|
||||
if (defined($optConst)) {
|
||||
$optId = constant($optConst);
|
||||
} else {
|
||||
$this->_log("Unknown memcached client option '{$name}' ({$optConst})");
|
||||
}
|
||||
}
|
||||
if ($optId) {
|
||||
if (!$this->_memcache->setOption($optId, $value)) {
|
||||
$this->_log("Setting memcached client option '{$optId}' failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// setup memcached servers
|
||||
$servers = array();
|
||||
foreach ($this->_options['servers'] as $server) {
|
||||
if (!array_key_exists('port', $server)) {
|
||||
$server['port'] = self::DEFAULT_PORT;
|
||||
}
|
||||
if (!array_key_exists('weight', $server)) {
|
||||
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||
}
|
||||
|
||||
$servers[] = array($server['host'], $server['port'], $server['weight']);
|
||||
}
|
||||
$this->_memcache->addServers($servers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0])) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return int|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1])) {
|
||||
return (int)$tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
|
||||
// ZF-8856: using set because add needs a second request if item already exists
|
||||
$result = @$this->_memcache->set($id, array($data, time(), $lifetime), $lifetime);
|
||||
if ($result === false) {
|
||||
$rsCode = $this->_memcache->getResultCode();
|
||||
$rsMsg = $this->_memcache->getResultMessage();
|
||||
$this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
|
||||
}
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return $this->_memcache->delete($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return $this->_memcache->flush();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Libmemcached::clean() : CLEANING_MODE_OLD is unsupported by the Libmemcached backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_LIBMEMCACHED_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
parent::setDirectives($directives);
|
||||
$lifetime = $this->getLifetime(false);
|
||||
if ($lifetime > 2592000) {
|
||||
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||
}
|
||||
if ($lifetime === null) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_log("Zend_Cache_Backend_Libmemcached::save() : getting the list of cache ids is unsupported by the Libmemcached backend");
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_LIBMEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mems = $this->_memcache->getStats();
|
||||
if ($mems === false) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$memSize = null;
|
||||
$memUsed = null;
|
||||
foreach ($mems as $key => $mem) {
|
||||
if ($mem === false) {
|
||||
$this->_log('can\'t get stat from ' . $key);
|
||||
continue;
|
||||
}
|
||||
|
||||
$eachSize = $mem['limit_maxbytes'];
|
||||
$eachUsed = $mem['bytes'];
|
||||
if ($eachUsed > $eachSize) {
|
||||
$eachUsed = $eachSize;
|
||||
}
|
||||
|
||||
$memSize += $eachSize;
|
||||
$memUsed += $eachUsed;
|
||||
}
|
||||
|
||||
if ($memSize === null || $memUsed === null) {
|
||||
Zend_Cache::throwException('Can\'t get filling percentage');
|
||||
}
|
||||
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1], $tmp[2])) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (isset($tmp[0], $tmp[1], $tmp[2])) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
// #ZF-5702 : we try replace() first becase set() seems to be slower
|
||||
if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $newLifetime))) {
|
||||
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $newLifetime);
|
||||
if ($result === false) {
|
||||
$rsCode = $this->_memcache->getResultCode();
|
||||
$rsMsg = $this->_memcache->getResultMessage();
|
||||
$this->_log("Memcached::set() failed: [{$rsCode}] {$rsMsg}");
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
504
library/Zend/Cache/Backend/Memcached.php
Normale Datei
504
library/Zend/Cache/Backend/Memcached.php
Normale Datei
|
|
@ -0,0 +1,504 @@
|
|||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to the new BSD license that is bundled
|
||||
* with this package in the file LICENSE.txt.
|
||||
* It is also available through the world-wide-web at this URL:
|
||||
* http://framework.zend.com/license/new-bsd
|
||||
* If you did not receive a copy of the license and are unable to
|
||||
* obtain it through the world-wide-web, please send an email
|
||||
* to license@zend.com so we can send you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend_Interface
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend/ExtendedInterface.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Cache_Backend
|
||||
*/
|
||||
require_once 'Zend/Cache/Backend.php';
|
||||
|
||||
|
||||
/**
|
||||
* @package Zend_Cache
|
||||
* @subpackage Zend_Cache_Backend
|
||||
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Cache_Backend_Memcached extends Zend_Cache_Backend implements Zend_Cache_Backend_ExtendedInterface
|
||||
{
|
||||
/**
|
||||
* Default Values
|
||||
*/
|
||||
const DEFAULT_HOST = '127.0.0.1';
|
||||
const DEFAULT_PORT = 11211;
|
||||
const DEFAULT_PERSISTENT = true;
|
||||
const DEFAULT_WEIGHT = 1;
|
||||
const DEFAULT_TIMEOUT = 1;
|
||||
const DEFAULT_RETRY_INTERVAL = 15;
|
||||
const DEFAULT_STATUS = true;
|
||||
const DEFAULT_FAILURE_CALLBACK = null;
|
||||
|
||||
/**
|
||||
* Log message
|
||||
*/
|
||||
const TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::clean() : tags are unsupported by the Memcached backend';
|
||||
const TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND = 'Zend_Cache_Backend_Memcached::save() : tags are unsupported by the Memcached backend';
|
||||
|
||||
/**
|
||||
* Available options
|
||||
*
|
||||
* =====> (array) servers :
|
||||
* an array of memcached server ; each memcached server is described by an associative array :
|
||||
* 'host' => (string) : the name of the memcached server
|
||||
* 'port' => (int) : the port of the memcached server
|
||||
* 'persistent' => (bool) : use or not persistent connections to this memcached server
|
||||
* 'weight' => (int) : number of buckets to create for this server which in turn control its
|
||||
* probability of it being selected. The probability is relative to the total
|
||||
* weight of all servers.
|
||||
* 'timeout' => (int) : value in seconds which will be used for connecting to the daemon. Think twice
|
||||
* before changing the default value of 1 second - you can lose all the
|
||||
* advantages of caching if your connection is too slow.
|
||||
* 'retry_interval' => (int) : controls how often a failed server will be retried, the default value
|
||||
* is 15 seconds. Setting this parameter to -1 disables automatic retry.
|
||||
* 'status' => (bool) : controls if the server should be flagged as online.
|
||||
* 'failure_callback' => (callback) : Allows the user to specify a callback function to run upon
|
||||
* encountering an error. The callback is run before failover
|
||||
* is attempted. The function takes two parameters, the hostname
|
||||
* and port of the failed server.
|
||||
*
|
||||
* =====> (boolean) compression :
|
||||
* true if you want to use on-the-fly compression
|
||||
*
|
||||
* =====> (boolean) compatibility :
|
||||
* true if you use old memcache server or extension
|
||||
*
|
||||
* @var array available options
|
||||
*/
|
||||
protected $_options = array(
|
||||
'servers' => array(array(
|
||||
'host' => self::DEFAULT_HOST,
|
||||
'port' => self::DEFAULT_PORT,
|
||||
'persistent' => self::DEFAULT_PERSISTENT,
|
||||
'weight' => self::DEFAULT_WEIGHT,
|
||||
'timeout' => self::DEFAULT_TIMEOUT,
|
||||
'retry_interval' => self::DEFAULT_RETRY_INTERVAL,
|
||||
'status' => self::DEFAULT_STATUS,
|
||||
'failure_callback' => self::DEFAULT_FAILURE_CALLBACK
|
||||
)),
|
||||
'compression' => false,
|
||||
'compatibility' => false,
|
||||
);
|
||||
|
||||
/**
|
||||
* Memcache object
|
||||
*
|
||||
* @var mixed memcache object
|
||||
*/
|
||||
protected $_memcache = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $options associative array of options
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $options = array())
|
||||
{
|
||||
if (!extension_loaded('memcache')) {
|
||||
Zend_Cache::throwException('The memcache extension must be loaded for using this backend !');
|
||||
}
|
||||
parent::__construct($options);
|
||||
if (isset($this->_options['servers'])) {
|
||||
$value= $this->_options['servers'];
|
||||
if (isset($value['host'])) {
|
||||
// in this case, $value seems to be a simple associative array (one server only)
|
||||
$value = array(0 => $value); // let's transform it into a classical array of associative arrays
|
||||
}
|
||||
$this->setOption('servers', $value);
|
||||
}
|
||||
$this->_memcache = new Memcache;
|
||||
foreach ($this->_options['servers'] as $server) {
|
||||
if (!array_key_exists('port', $server)) {
|
||||
$server['port'] = self::DEFAULT_PORT;
|
||||
}
|
||||
if (!array_key_exists('persistent', $server)) {
|
||||
$server['persistent'] = self::DEFAULT_PERSISTENT;
|
||||
}
|
||||
if (!array_key_exists('weight', $server)) {
|
||||
$server['weight'] = self::DEFAULT_WEIGHT;
|
||||
}
|
||||
if (!array_key_exists('timeout', $server)) {
|
||||
$server['timeout'] = self::DEFAULT_TIMEOUT;
|
||||
}
|
||||
if (!array_key_exists('retry_interval', $server)) {
|
||||
$server['retry_interval'] = self::DEFAULT_RETRY_INTERVAL;
|
||||
}
|
||||
if (!array_key_exists('status', $server)) {
|
||||
$server['status'] = self::DEFAULT_STATUS;
|
||||
}
|
||||
if (!array_key_exists('failure_callback', $server)) {
|
||||
$server['failure_callback'] = self::DEFAULT_FAILURE_CALLBACK;
|
||||
}
|
||||
if ($this->_options['compatibility']) {
|
||||
// No status for compatibility mode (#ZF-5887)
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval']);
|
||||
} else {
|
||||
$this->_memcache->addServer($server['host'], $server['port'], $server['persistent'],
|
||||
$server['weight'], $server['timeout'],
|
||||
$server['retry_interval'],
|
||||
$server['status'], $server['failure_callback']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available for the given id and (if yes) return it (false else)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @param boolean $doNotTestCacheValidity If set to true, the cache validity won't be tested
|
||||
* @return string|false cached datas
|
||||
*/
|
||||
public function load($id, $doNotTestCacheValidity = false)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp) && isset($tmp[0])) {
|
||||
return $tmp[0];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a cache is available or not (for the given id)
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return mixed|false (a cache is not available) or "last modified" timestamp (int) of the available cache record
|
||||
*/
|
||||
public function test($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
return $tmp[1];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save some string datas into a cache record
|
||||
*
|
||||
* Note : $data is always "string" (serialization is done by the
|
||||
* core not by the backend)
|
||||
*
|
||||
* @param string $data Datas to cache
|
||||
* @param string $id Cache id
|
||||
* @param array $tags Array of strings, the cache record will be tagged by each string entry
|
||||
* @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime)
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function save($data, $id, $tags = array(), $specificLifetime = false)
|
||||
{
|
||||
$lifetime = $this->getLifetime($specificLifetime);
|
||||
if ($this->_options['compression']) {
|
||||
$flag = MEMCACHE_COMPRESSED;
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
|
||||
// ZF-8856: using set because add needs a second request if item already exists
|
||||
$result = @$this->_memcache->set($id, array($data, time(), $lifetime), $flag, $lifetime);
|
||||
|
||||
if (count($tags) > 0) {
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a cache record
|
||||
*
|
||||
* @param string $id Cache id
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function remove($id)
|
||||
{
|
||||
return $this->_memcache->delete($id, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean some cache records
|
||||
*
|
||||
* Available modes are :
|
||||
* 'all' (default) => remove all cache entries ($tags is not used)
|
||||
* 'old' => unsupported
|
||||
* 'matchingTag' => unsupported
|
||||
* 'notMatchingTag' => unsupported
|
||||
* 'matchingAnyTag' => unsupported
|
||||
*
|
||||
* @param string $mode Clean mode
|
||||
* @param array $tags Array of tags
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return boolean True if no problem
|
||||
*/
|
||||
public function clean($mode = Zend_Cache::CLEANING_MODE_ALL, $tags = array())
|
||||
{
|
||||
switch ($mode) {
|
||||
case Zend_Cache::CLEANING_MODE_ALL:
|
||||
return $this->_memcache->flush();
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_OLD:
|
||||
$this->_log("Zend_Cache_Backend_Memcached::clean() : CLEANING_MODE_OLD is unsupported by the Memcached backend");
|
||||
break;
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG:
|
||||
case Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG:
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_MEMCACHED_BACKEND);
|
||||
break;
|
||||
default:
|
||||
Zend_Cache::throwException('Invalid mode for clean() method');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the automatic cleaning is available for the backend
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isAutomaticCleaningAvailable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the frontend directives
|
||||
*
|
||||
* @param array $directives Assoc of directives
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return void
|
||||
*/
|
||||
public function setDirectives($directives)
|
||||
{
|
||||
parent::setDirectives($directives);
|
||||
$lifetime = $this->getLifetime(false);
|
||||
if ($lifetime > 2592000) {
|
||||
// #ZF-3490 : For the memcached backend, there is a lifetime limit of 30 days (2592000 seconds)
|
||||
$this->_log('memcached backend has a limit of 30 days (2592000 seconds) for the lifetime');
|
||||
}
|
||||
if ($lifetime === null) {
|
||||
// #ZF-4614 : we tranform null to zero to get the maximal lifetime
|
||||
parent::setDirectives(array('lifetime' => 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids
|
||||
*
|
||||
* @return array array of stored cache ids (string)
|
||||
*/
|
||||
public function getIds()
|
||||
{
|
||||
$this->_log("Zend_Cache_Backend_Memcached::save() : getting the list of cache ids is unsupported by the Memcache backend");
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored tags
|
||||
*
|
||||
* @return array array of stored tags (string)
|
||||
*/
|
||||
public function getTags()
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which don't match given tags
|
||||
*
|
||||
* In case of multiple tags, a logical OR is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of not matching cache ids (string)
|
||||
*/
|
||||
public function getIdsNotMatchingTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of stored cache ids which match any given tags
|
||||
*
|
||||
* In case of multiple tags, a logical AND is made between tags
|
||||
*
|
||||
* @param array $tags array of tags
|
||||
* @return array array of any matching cache ids (string)
|
||||
*/
|
||||
public function getIdsMatchingAnyTags($tags = array())
|
||||
{
|
||||
$this->_log(self::TAGS_UNSUPPORTED_BY_SAVE_OF_MEMCACHED_BACKEND);
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the filling percentage of the backend storage
|
||||
*
|
||||
* @throws Zend_Cache_Exception
|
||||
* @return int integer between 0 and 100
|
||||
*/
|
||||
public function getFillingPercentage()
|
||||
{
|
||||
$mems = $this->_memcache->getExtendedStats();
|
||||
|
||||
$memSize = null;
|
||||
$memUsed = null;
|
||||
foreach ($mems as $key => $mem) {
|
||||
if ($mem === false) {
|
||||
$this->_log('can\'t get stat from ' . $key);
|
||||
continue;
|
||||
}
|
||||
|
||||
$eachSize = $mem['limit_maxbytes'];
|
||||
$eachUsed = $mem['bytes'];
|
||||
if ($eachUsed > $eachSize) {
|
||||
$eachUsed = $eachSize;
|
||||
}
|
||||
|
||||
$memSize += $eachSize;
|
||||
$memUsed += $eachUsed;
|
||||
}
|
||||
|
||||
if ($memSize === null || $memUsed === null) {
|
||||
Zend_Cache::throwException('Can\'t get filling percentage');
|
||||
}
|
||||
|
||||
return ((int) (100. * ($memUsed / $memSize)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of metadatas for the given cache id
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - expire : the expire timestamp
|
||||
* - tags : a string array of tags
|
||||
* - mtime : timestamp of last modification time
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @return array array of metadatas (false if the cache id is not found)
|
||||
*/
|
||||
public function getMetadatas($id)
|
||||
{
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
return array(
|
||||
'expire' => $mtime + $lifetime,
|
||||
'tags' => array(),
|
||||
'mtime' => $mtime
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give (if possible) an extra lifetime to the given cache id
|
||||
*
|
||||
* @param string $id cache id
|
||||
* @param int $extraLifetime
|
||||
* @return boolean true if ok
|
||||
*/
|
||||
public function touch($id, $extraLifetime)
|
||||
{
|
||||
if ($this->_options['compression']) {
|
||||
$flag = MEMCACHE_COMPRESSED;
|
||||
} else {
|
||||
$flag = 0;
|
||||
}
|
||||
$tmp = $this->_memcache->get($id);
|
||||
if (is_array($tmp)) {
|
||||
$data = $tmp[0];
|
||||
$mtime = $tmp[1];
|
||||
if (!isset($tmp[2])) {
|
||||
// because this record is only with 1.7 release
|
||||
// if old cache records are still there...
|
||||
return false;
|
||||
}
|
||||
$lifetime = $tmp[2];
|
||||
$newLifetime = $lifetime - (time() - $mtime) + $extraLifetime;
|
||||
if ($newLifetime <=0) {
|
||||
return false;
|
||||
}
|
||||
// #ZF-5702 : we try replace() first becase set() seems to be slower
|
||||
if (!($result = $this->_memcache->replace($id, array($data, time(), $newLifetime), $flag, $newLifetime))) {
|
||||
$result = $this->_memcache->set($id, array($data, time(), $newLifetime), $flag, $newLifetime);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an associative array of capabilities (booleans) of the backend
|
||||
*
|
||||
* The array must include these keys :
|
||||
* - automatic_cleaning (is automating cleaning necessary)
|
||||
* - tags (are tags supported)
|
||||
* - expired_read (is it possible to read expired cache records
|
||||
* (for doNotTestCacheValidity option for example))
|
||||
* - priority does the backend deal with priority when saving
|
||||
* - infinite_lifetime (is infinite lifetime can work with this backend)
|
||||
* - get_list (is it possible to get the list of cache ids and the complete list of tags)
|
||||
*
|
||||
* @return array associative of with capabilities
|
||||
*/
|
||||
public function getCapabilities()
|
||||
{
|
||||
return array(
|
||||
'automatic_cleaning' => false,
|
||||
'tags' => false,
|
||||
'expired_read' => false,
|
||||
'priority' => false,
|
||||
'infinite_lifetime' => false,
|
||||
'get_list' => false
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Einige Dateien werden nicht angezeigt, da zu viele Dateien in diesem Diff geändert wurden Mehr anzeigen
Laden …
Tabelle hinzufügen
Einen Link hinzufügen
In neuem Issue referenzieren