Zf1 whit composer
This commit is contained in:
parent
b16e669369
commit
4e6e9993bc
@ -1,248 +0,0 @@
|
||||
<?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_Loader
|
||||
* @subpackage Exception
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
|
||||
/**
|
||||
* Generate class maps for use with autoloading.
|
||||
*
|
||||
* Usage:
|
||||
* --help|-h Get usage message
|
||||
* --library|-l [ <string> ] Library to parse; if none provided, assumes
|
||||
* current directory
|
||||
* --output|-o [ <string> ] Where to write autoload file; if not provided,
|
||||
* assumes "autoload_classmap.php" in library directory
|
||||
* --append|-a Append to autoload file if it exists
|
||||
* --overwrite|-w Whether or not to overwrite existing autoload
|
||||
* file
|
||||
* --ignore|-i [ <string> ] Comma-separated namespaces to ignore
|
||||
*/
|
||||
|
||||
$libPath = dirname(__FILE__) . '/../library';
|
||||
if (!is_dir($libPath)) {
|
||||
// Try to load StandardAutoloader from include_path
|
||||
if (false === include('Zend/Loader/StandardAutoloader.php')) {
|
||||
echo "Unable to locate autoloader via include_path; aborting" . PHP_EOL;
|
||||
exit(2);
|
||||
}
|
||||
} else {
|
||||
// Try to load StandardAutoloader from library
|
||||
if (false === include(dirname(__FILE__) . '/../library/Zend/Loader/StandardAutoloader.php')) {
|
||||
echo "Unable to locate autoloader via library; aborting" . PHP_EOL;
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath($libPath),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
$libraryPath = getcwd();
|
||||
|
||||
// Setup autoloading
|
||||
$loader = new Zend_Loader_StandardAutoloader(array('autoregister_zf' => true));
|
||||
$loader->setFallbackAutoloader(true);
|
||||
$loader->register();
|
||||
|
||||
$rules = array(
|
||||
'help|h' => 'Get usage message',
|
||||
'library|l-s' => 'Library to parse; if none provided, assumes current directory',
|
||||
'output|o-s' => 'Where to write autoload file; if not provided, assumes "autoload_classmap.php" in library directory',
|
||||
'append|a' => 'Append to autoload file if it exists',
|
||||
'overwrite|w' => 'Whether or not to overwrite existing autoload file',
|
||||
'ignore|i-s' => 'Comma-separated namespaces to ignore',
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt($rules);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit(2);
|
||||
}
|
||||
|
||||
if ($opts->getOption('h')) {
|
||||
echo $opts->getUsageMessage();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
$ignoreNamespaces = array();
|
||||
if (isset($opts->i)) {
|
||||
$ignoreNamespaces = explode(',', $opts->i);
|
||||
}
|
||||
|
||||
$relativePathForClassmap = '';
|
||||
if (isset($opts->l)) {
|
||||
if (!is_dir($opts->l)) {
|
||||
echo 'Invalid library directory provided' . PHP_EOL
|
||||
. PHP_EOL;
|
||||
echo $opts->getUsageMessage();
|
||||
exit(2);
|
||||
}
|
||||
$libraryPath = $opts->l;
|
||||
}
|
||||
$libraryPath = str_replace(DIRECTORY_SEPARATOR, '/', realpath($libraryPath));
|
||||
|
||||
$usingStdout = false;
|
||||
$appending = $opts->getOption('a');
|
||||
$output = $libraryPath . '/autoload_classmap.php';
|
||||
if (isset($opts->o)) {
|
||||
$output = $opts->o;
|
||||
if ('-' == $output) {
|
||||
$output = STDOUT;
|
||||
$usingStdout = true;
|
||||
} elseif (is_dir($output)) {
|
||||
echo 'Invalid output file provided' . PHP_EOL
|
||||
. PHP_EOL;
|
||||
echo $opts->getUsageMessage();
|
||||
exit(2);
|
||||
} elseif (!is_writeable(dirname($output))) {
|
||||
echo "Cannot write to '$output'; aborting." . PHP_EOL
|
||||
. PHP_EOL
|
||||
. $opts->getUsageMessage();
|
||||
exit(2);
|
||||
} elseif (file_exists($output) && !$opts->getOption('w') && !$appending) {
|
||||
echo "Autoload file already exists at '$output'," . PHP_EOL
|
||||
. "but 'overwrite' or 'appending' flag was not specified; aborting." . PHP_EOL
|
||||
. PHP_EOL
|
||||
. $opts->getUsageMessage();
|
||||
exit(2);
|
||||
} else {
|
||||
// We need to add the $libraryPath into the relative path that is created in the classmap file.
|
||||
$classmapPath = str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname($output)));
|
||||
|
||||
// Simple case: $libraryPathCompare is in $classmapPathCompare
|
||||
if (strpos($libraryPath, $classmapPath) === 0) {
|
||||
$relativePathForClassmap = substr($libraryPath, strlen($classmapPath) + 1) . '/';
|
||||
} else {
|
||||
$libraryPathParts = explode('/', $libraryPath);
|
||||
$classmapPathParts = explode('/', $classmapPath);
|
||||
|
||||
// Find the common part
|
||||
$count = count($classmapPathParts);
|
||||
for ($i = 0; $i < $count; $i++) {
|
||||
if (!isset($libraryPathParts[$i]) || $libraryPathParts[$i] != $classmapPathParts[$i]) {
|
||||
// Common part end
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Add parent dirs for the subdirs of classmap
|
||||
$relativePathForClassmap = str_repeat('../', $count - $i);
|
||||
|
||||
// Add library subdirs
|
||||
$count = count($libraryPathParts);
|
||||
for (; $i < $count; $i++) {
|
||||
$relativePathForClassmap .= $libraryPathParts[$i] . '/';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$usingStdout) {
|
||||
if ($appending) {
|
||||
echo "Appending to class file map '$output' for library in '$libraryPath'..." . PHP_EOL;
|
||||
} else {
|
||||
echo "Creating class file map for library in '$libraryPath'..." . PHP_EOL;
|
||||
}
|
||||
}
|
||||
|
||||
// Get the ClassFileLocator, and pass it the library path
|
||||
$l = new Zend_File_ClassFileLocator($libraryPath);
|
||||
|
||||
// Iterate over each element in the path, and create a map of
|
||||
// classname => filename, where the filename is relative to the library path
|
||||
$map = new stdClass;
|
||||
foreach ($l as $file) {
|
||||
$filename = str_replace($libraryPath . '/', '', str_replace(DIRECTORY_SEPARATOR, '/', $file->getPath()) . '/' . $file->getFilename());
|
||||
|
||||
// Add in relative path to library
|
||||
$filename = $relativePathForClassmap . $filename;
|
||||
|
||||
foreach ($file->getClasses() as $class) {
|
||||
foreach ($ignoreNamespaces as $ignoreNs) {
|
||||
if ($ignoreNs == substr($class, 0, strlen($ignoreNs))) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$map->{$class} = $filename;
|
||||
}
|
||||
}
|
||||
|
||||
if ($appending) {
|
||||
$content = var_export((array) $map, true) . ';';
|
||||
|
||||
// Prefix with dirname(__FILE__); modify the generated content
|
||||
$content = preg_replace("#(=> ')#", "=> dirname(__FILE__) . '/", $content);
|
||||
|
||||
// Fix \' strings from injected DIRECTORY_SEPARATOR usage in iterator_apply op
|
||||
$content = str_replace("\\'", "'", $content);
|
||||
|
||||
// Convert to an array and remove the first "array("
|
||||
$content = explode("\n", $content);
|
||||
array_shift($content);
|
||||
|
||||
// Load existing class map file and remove the closing "bracket ");" from it
|
||||
$existing = file($output, FILE_IGNORE_NEW_LINES);
|
||||
array_pop($existing);
|
||||
|
||||
// Merge
|
||||
$content = implode("\n", array_merge($existing, $content));
|
||||
} else {
|
||||
// Create a file with the class/file map.
|
||||
// Stupid syntax highlighters make separating < from PHP declaration necessary
|
||||
$content = '<' . "?php\n"
|
||||
. "// Generated by ZF's ./bin/classmap_generator.php\n"
|
||||
. 'return ' . var_export((array) $map, true) . ';';
|
||||
|
||||
// Prefix with dirname(__FILE__); modify the generated content
|
||||
$content = preg_replace("#(=> ')#", "=> dirname(__FILE__) . '/", $content);
|
||||
|
||||
// Fix \' strings from injected DIRECTORY_SEPARATOR usage in iterator_apply op
|
||||
$content = str_replace("\\'", "'", $content);
|
||||
}
|
||||
|
||||
// Remove unnecessary double-backslashes
|
||||
$content = str_replace('\\\\', '\\', $content);
|
||||
|
||||
// Exchange "array (" width "array("
|
||||
$content = str_replace('array (', 'array(', $content);
|
||||
|
||||
// Align "=>" operators to match coding standard
|
||||
preg_match_all('(\n\s+([^=]+)=>)', $content, $matches, PREG_SET_ORDER);
|
||||
$maxWidth = 0;
|
||||
|
||||
foreach ($matches as $match) {
|
||||
$maxWidth = max($maxWidth, strlen($match[1]));
|
||||
}
|
||||
|
||||
$content = preg_replace('(\n\s+([^=]+)=>)e', "'\n \\1' . str_repeat(' ', " . $maxWidth . " - strlen('\\1')) . '=>'", $content);
|
||||
|
||||
// Make the file end by EOL
|
||||
$content = rtrim($content, "\n") . "\n";
|
||||
|
||||
// Write the contents to disk
|
||||
file_put_contents($output, $content);
|
||||
|
||||
if (!$usingStdout) {
|
||||
echo "Wrote classmap file to '" . realpath($output) . "'" . PHP_EOL;
|
||||
}
|
44
bin/zf.bat
44
bin/zf.bat
@ -1,44 +0,0 @@
|
||||
@ECHO off
|
||||
REM Zend Framework
|
||||
REM
|
||||
REM LICENSE
|
||||
REM
|
||||
REM This source file is subject to the new BSD license that is bundled
|
||||
REM with this package in the file LICENSE.txt.
|
||||
REM It is also available through the world-wide-web at this URL:
|
||||
REM http://framework.zend.com/license/new-bsd
|
||||
REM If you did not receive a copy of the license and are unable to
|
||||
REM obtain it through the world-wide-web, please send an email
|
||||
REM to license@zend.com so we can send you a copy immediately.
|
||||
REM
|
||||
REM Zend
|
||||
REM Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
REM http://framework.zend.com/license/new-bsd New BSD License
|
||||
|
||||
|
||||
REM Test to see if this was installed via pear
|
||||
SET ZTMPZTMPZTMPZ=@ph
|
||||
SET TMPZTMPZTMP=%ZTMPZTMPZTMPZ%p_bin@
|
||||
REM below @php_bin@
|
||||
FOR %%x IN ("@php_bin@") DO (if %%x=="%TMPZTMPZTMP%" GOTO :NON_PEAR_INSTALLED)
|
||||
|
||||
GOTO PEAR_INSTALLED
|
||||
|
||||
:NON_PEAR_INSTALLED
|
||||
REM Assume php.exe is executable, and that zf.php will reside in the
|
||||
REM same file as this one
|
||||
SET PHP_BIN=php.exe
|
||||
SET PHP_DIR=%~dp0
|
||||
GOTO RUN
|
||||
|
||||
:PEAR_INSTALLED
|
||||
REM Assume this was installed via PEAR and use replacements php_bin & php_dir
|
||||
SET PHP_BIN=@php_bin@
|
||||
SET PHP_DIR=@php_dir@
|
||||
GOTO RUN
|
||||
|
||||
:RUN
|
||||
SET ZF_SCRIPT=%PHP_DIR%\zf.php
|
||||
"%PHP_BIN%" -d safe_mode=Off -f "%ZF_SCRIPT%" -- %*
|
||||
|
||||
|
624
bin/zf.php
624
bin/zf.php
@ -1,624 +0,0 @@
|
||||
<?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_Tool
|
||||
* @subpackage Framework
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* ZF
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Tool
|
||||
* @subpackage Framework
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class ZF
|
||||
{
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $_clientLoaded = false;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_mode = 'runTool';
|
||||
|
||||
/**
|
||||
* @var array of messages
|
||||
*/
|
||||
protected $_messages = array();
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_homeDirectory = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_storageDirectory = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $_configFile = null;
|
||||
|
||||
/**
|
||||
* main()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function main()
|
||||
{
|
||||
$zf = new self();
|
||||
$zf->bootstrap();
|
||||
$zf->run();
|
||||
}
|
||||
|
||||
/**
|
||||
* bootstrap()
|
||||
*
|
||||
* @return ZF
|
||||
*/
|
||||
public function bootstrap()
|
||||
{
|
||||
// detect settings
|
||||
$this->_mode = $this->_detectMode();
|
||||
$this->_homeDirectory = $this->_detectHomeDirectory();
|
||||
$this->_storageDirectory = $this->_detectStorageDirectory();
|
||||
$this->_configFile = $this->_detectConfigFile();
|
||||
|
||||
// setup
|
||||
$this->_setupPHPRuntime();
|
||||
$this->_setupToolRuntime();
|
||||
}
|
||||
|
||||
/**
|
||||
* run()
|
||||
*
|
||||
* @return ZF
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
switch ($this->_mode) {
|
||||
case 'runError':
|
||||
$this->_runError();
|
||||
$this->_runInfo();
|
||||
break;
|
||||
case 'runSetup':
|
||||
if ($this->_runSetup() === false) {
|
||||
$this->_runInfo();
|
||||
}
|
||||
break;
|
||||
case 'runInfo':
|
||||
$this->_runInfo();
|
||||
break;
|
||||
case 'runTool':
|
||||
default:
|
||||
$this->_runTool();
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* _detectMode()
|
||||
*
|
||||
* @return ZF
|
||||
*/
|
||||
protected function _detectMode()
|
||||
{
|
||||
$arguments = $_SERVER['argv'];
|
||||
|
||||
$mode = 'runTool';
|
||||
|
||||
if (!isset($arguments[0])) {
|
||||
return $mode;
|
||||
}
|
||||
|
||||
if ($arguments[0] == $_SERVER['PHP_SELF']) {
|
||||
$this->_executable = array_shift($arguments);
|
||||
}
|
||||
|
||||
if (!isset($arguments[0])) {
|
||||
return $mode;
|
||||
}
|
||||
|
||||
if ($arguments[0] == '--setup') {
|
||||
$mode = 'runSetup';
|
||||
} elseif ($arguments[0] == '--info') {
|
||||
$mode = 'runInfo';
|
||||
}
|
||||
|
||||
return $mode;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _detectHomeDirectory() - detect the home directory in a variety of different places
|
||||
*
|
||||
* @param bool $mustExist Should the returned value already exist in the file system
|
||||
* @param bool $returnMessages Should it log messages for output later
|
||||
* @return string
|
||||
*/
|
||||
protected function _detectHomeDirectory($mustExist = true, $returnMessages = true)
|
||||
{
|
||||
$homeDirectory = null;
|
||||
|
||||
$homeDirectory = getenv('ZF_HOME'); // check env var ZF_HOME
|
||||
if ($homeDirectory) {
|
||||
$this->_logMessage('Home directory found in environment variable ZF_HOME with value ' . $homeDirectory, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
|
||||
return $homeDirectory;
|
||||
} else {
|
||||
$this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
$homeDirectory = getenv('HOME'); // HOME environment variable
|
||||
|
||||
if ($homeDirectory) {
|
||||
$this->_logMessage('Home directory found in environment variable HOME with value ' . $homeDirectory, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
|
||||
return $homeDirectory;
|
||||
} else {
|
||||
$this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$homeDirectory = getenv('HOMEPATH');
|
||||
|
||||
if ($homeDirectory) {
|
||||
$this->_logMessage('Home directory found in environment variable HOMEPATH with value ' . $homeDirectory, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
|
||||
return $homeDirectory;
|
||||
} else {
|
||||
$this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
$homeDirectory = getenv('USERPROFILE');
|
||||
|
||||
if ($homeDirectory) {
|
||||
$this->_logMessage('Home directory found in environment variable USERPROFILE with value ' . $homeDirectory, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($homeDirectory))) {
|
||||
return $homeDirectory;
|
||||
} else {
|
||||
$this->_logMessage('Home directory does not exist at ' . $homeDirectory, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* _detectStorageDirectory() - Detect where the storage directory is from a variaty of possiblities
|
||||
*
|
||||
* @param bool $mustExist Should the returned value already exist in the file system
|
||||
* @param bool $returnMessages Should it log messages for output later
|
||||
* @return string
|
||||
*/
|
||||
protected function _detectStorageDirectory($mustExist = true, $returnMessages = true)
|
||||
{
|
||||
$storageDirectory = false;
|
||||
|
||||
$storageDirectory = getenv('ZF_STORAGE_DIR');
|
||||
if ($storageDirectory) {
|
||||
$this->_logMessage('Storage directory path found in environment variable ZF_STORAGE_DIR with value ' . $storageDirectory, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($storageDirectory))) {
|
||||
return $storageDirectory;
|
||||
} else {
|
||||
$this->_logMessage('Storage directory does not exist at ' . $storageDirectory, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
$homeDirectory = ($this->_homeDirectory) ? $this->_homeDirectory : $this->_detectHomeDirectory(true, false);
|
||||
|
||||
if ($homeDirectory) {
|
||||
$storageDirectory = $homeDirectory . '/.zf/';
|
||||
$this->_logMessage('Storage directory assumed in home directory at location ' . $storageDirectory, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($storageDirectory))) {
|
||||
return $storageDirectory;
|
||||
} else {
|
||||
$this->_logMessage('Storage directory does not exist at ' . $storageDirectory, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* _detectConfigFile() - Detect config file location from a variety of possibilities
|
||||
*
|
||||
* @param bool $mustExist Should the returned value already exist in the file system
|
||||
* @param bool $returnMessages Should it log messages for output later
|
||||
* @return string
|
||||
*/
|
||||
protected function _detectConfigFile($mustExist = true, $returnMessages = true)
|
||||
{
|
||||
$configFile = null;
|
||||
|
||||
$configFile = getenv('ZF_CONFIG_FILE');
|
||||
if ($configFile) {
|
||||
$this->_logMessage('Config file found environment variable ZF_CONFIG_FILE at ' . $configFile, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($configFile))) {
|
||||
return $configFile;
|
||||
} else {
|
||||
$this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
$homeDirectory = ($this->_homeDirectory) ? $this->_homeDirectory : $this->_detectHomeDirectory(true, false);
|
||||
if ($homeDirectory) {
|
||||
$configFile = $homeDirectory . '/.zf.ini';
|
||||
$this->_logMessage('Config file assumed in home directory at location ' . $configFile, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($configFile))) {
|
||||
return $configFile;
|
||||
} else {
|
||||
$this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
$storageDirectory = ($this->_storageDirectory) ? $this->_storageDirectory : $this->_detectStorageDirectory(true, false);
|
||||
if ($storageDirectory) {
|
||||
$configFile = $storageDirectory . '/zf.ini';
|
||||
$this->_logMessage('Config file assumed in storage directory at location ' . $configFile, $returnMessages);
|
||||
if (!$mustExist || ($mustExist && file_exists($configFile))) {
|
||||
return $configFile;
|
||||
} else {
|
||||
$this->_logMessage('Config file does not exist at ' . $configFile, $returnMessages);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* _setupPHPRuntime() - parse the config file if it exists for php ini values to set
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _setupPHPRuntime()
|
||||
{
|
||||
// set php runtime settings
|
||||
ini_set('display_errors', true);
|
||||
|
||||
// support the changing of the current working directory, necessary for some providers
|
||||
$cwd = getenv('ZEND_TOOL_CURRENT_WORKING_DIRECTORY');
|
||||
if ($cwd != '' && realpath($cwd)) {
|
||||
chdir($cwd);
|
||||
}
|
||||
|
||||
if (!$this->_configFile) {
|
||||
return;
|
||||
}
|
||||
$zfINISettings = parse_ini_file($this->_configFile);
|
||||
$phpINISettings = ini_get_all();
|
||||
foreach ($zfINISettings as $zfINIKey => $zfINIValue) {
|
||||
if (substr($zfINIKey, 0, 4) === 'php.') {
|
||||
$phpINIKey = substr($zfINIKey, 4);
|
||||
if (array_key_exists($phpINIKey, $phpINISettings)) {
|
||||
ini_set($phpINIKey, $zfINIValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* _setupToolRuntime() - setup the tools include_path and load the proper framwork parts that
|
||||
* enable Zend_Tool to work.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _setupToolRuntime()
|
||||
{
|
||||
|
||||
$includePathPrepend = getenv('ZEND_TOOL_INCLUDE_PATH_PREPEND');
|
||||
$includePathFull = getenv('ZEND_TOOL_INCLUDE_PATH');
|
||||
|
||||
// check if the user has not provided anything
|
||||
if (!($includePathPrepend || $includePathFull)) {
|
||||
if ($this->_tryClientLoad()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// if ZF is not in the include_path, but relative to this file, put it in the include_path
|
||||
if ($includePathPrepend || $includePathFull) {
|
||||
if (isset($includePathPrepend) && ($includePathPrepend !== false)) {
|
||||
set_include_path($includePathPrepend . PATH_SEPARATOR . get_include_path());
|
||||
} elseif (isset($includePathFull) && ($includePathFull !== false)) {
|
||||
set_include_path($includePathFull);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_tryClientLoad()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$zfIncludePath['relativePath'] = dirname(__FILE__) . '/../library/';
|
||||
if (file_exists($zfIncludePath['relativePath'] . 'Zend/Tool/Framework/Client/Console.php')) {
|
||||
set_include_path(realpath($zfIncludePath['relativePath']) . PATH_SEPARATOR . get_include_path());
|
||||
}
|
||||
|
||||
if (!$this->_tryClientLoad()) {
|
||||
$this->_mode = 'runError';
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* _tryClientLoad() - Attempt to load the Zend_Tool_Framework_Client_Console to enable the tool to run.
|
||||
*
|
||||
* This method will return false if its not loaded to allow the consumer to alter the environment in such
|
||||
* a way that it can be called again to try loading the proper file/class.
|
||||
*
|
||||
* @return bool if the client is actuall loaded or not
|
||||
*/
|
||||
protected function _tryClientLoad()
|
||||
{
|
||||
$this->_clientLoaded = false;
|
||||
$fh = @fopen('Zend/Tool/Framework/Client/Console.php', 'r', true);
|
||||
if (!$fh) {
|
||||
return $this->_clientLoaded; // false
|
||||
} else {
|
||||
fclose($fh);
|
||||
unset($fh);
|
||||
include 'Zend/Tool/Framework/Client/Console.php';
|
||||
$this->_clientLoaded = class_exists('Zend_Tool_Framework_Client_Console');
|
||||
}
|
||||
|
||||
return $this->_clientLoaded;
|
||||
}
|
||||
|
||||
/**
|
||||
* _runError() - Output the error screen that tells the user that the tool was not setup
|
||||
* in a sane way
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _runError()
|
||||
{
|
||||
|
||||
echo <<<EOS
|
||||
|
||||
***************************** ZF ERROR ********************************
|
||||
In order to run the zf command, you need to ensure that Zend Framework
|
||||
is inside your include_path. There are a variety of ways that you can
|
||||
ensure that this zf command line tool knows where the Zend Framework
|
||||
library is on your system, but not all of them can be described here.
|
||||
|
||||
The easiest way to get the zf command running is to give it the include
|
||||
path via an environment variable ZEND_TOOL_INCLUDE_PATH or
|
||||
ZEND_TOOL_INCLUDE_PATH_PREPEND with the proper include path to use,
|
||||
then run the command "zf --setup". This command is designed to create
|
||||
a storage location for your user, as well as create the zf.ini file
|
||||
that the zf command will consult in order to run properly on your
|
||||
system.
|
||||
|
||||
Example you would run:
|
||||
|
||||
$ ZEND_TOOL_INCLUDE_PATH=/path/to/library zf --setup
|
||||
|
||||
Your are encourged to read more in the link that follows.
|
||||
|
||||
EOS;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* _runInfo() - this command will produce information about the setup of this script and
|
||||
* Zend_Tool
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _runInfo()
|
||||
{
|
||||
echo 'Zend_Tool & CLI Setup Information' . PHP_EOL
|
||||
. '(available via the command line "zf --info")'
|
||||
. PHP_EOL;
|
||||
|
||||
echo ' * ' . implode(PHP_EOL . ' * ', $this->_messages) . PHP_EOL;
|
||||
|
||||
echo PHP_EOL;
|
||||
|
||||
echo 'To change the setup of this tool, run: "zf --setup"';
|
||||
|
||||
echo PHP_EOL;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* _runSetup() - parse the request to see which setup command to run
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _runSetup()
|
||||
{
|
||||
$setupCommand = (isset($_SERVER['argv'][2])) ? $_SERVER['argv'][2] : null;
|
||||
|
||||
switch ($setupCommand) {
|
||||
case 'storage-directory':
|
||||
$this->_runSetupStorageDirectory();
|
||||
break;
|
||||
case 'config-file':
|
||||
$this->_runSetupConfigFile();
|
||||
break;
|
||||
default:
|
||||
$this->_runSetupMoreInfo();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* _runSetupStorageDirectory() - if the storage directory does not exist, create it
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _runSetupStorageDirectory()
|
||||
{
|
||||
$storageDirectory = $this->_detectStorageDirectory(false, false);
|
||||
|
||||
if (file_exists($storageDirectory)) {
|
||||
echo 'Directory already exists at ' . $storageDirectory . PHP_EOL
|
||||
. 'Cannot create storage directory.';
|
||||
return;
|
||||
}
|
||||
|
||||
mkdir($storageDirectory);
|
||||
|
||||
echo 'Storage directory created at ' . $storageDirectory . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* _runSetupConfigFile()
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _runSetupConfigFile()
|
||||
{
|
||||
$configFile = $this->_detectConfigFile(false, false);
|
||||
|
||||
if (file_exists($configFile)) {
|
||||
echo 'File already exists at ' . $configFile . PHP_EOL
|
||||
. 'Cannot write new config file.';
|
||||
return;
|
||||
}
|
||||
|
||||
$includePath = get_include_path();
|
||||
|
||||
$contents = 'php.include_path = "' . $includePath . '"';
|
||||
|
||||
file_put_contents($configFile, $contents);
|
||||
|
||||
$iniValues = ini_get_all();
|
||||
if ($iniValues['include_path']['global_value'] != $iniValues['include_path']['local_value']) {
|
||||
echo 'NOTE: the php include_path to be used with the tool has been written' . PHP_EOL
|
||||
. 'to the config file, using ZEND_TOOL_INCLUDE_PATH (or other include_path setters)' . PHP_EOL
|
||||
. 'is no longer necessary.' . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
|
||||
echo 'Config file written to ' . $configFile . PHP_EOL;
|
||||
}
|
||||
|
||||
/**
|
||||
* _runSetupMoreInfo() - return more information about what can be setup, and what is setup
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _runSetupMoreInfo()
|
||||
{
|
||||
$homeDirectory = $this->_detectHomeDirectory(false, false);
|
||||
$storageDirectory = $this->_detectStorageDirectory(false, false);
|
||||
$configFile = $this->_detectConfigFile(false, false);
|
||||
|
||||
echo <<<EOS
|
||||
|
||||
ZF Command Line Tool - Setup
|
||||
----------------------------
|
||||
|
||||
Current Paths (Existing or not):
|
||||
Home Directory: {$homeDirectory}
|
||||
Storage Directory: {$storageDirectory}
|
||||
Config File: {$configFile}
|
||||
|
||||
Important Environment Variables:
|
||||
ZF_HOME
|
||||
- the directory this tool will look for a home directory
|
||||
- directory must exist
|
||||
ZF_STORAGE_DIR
|
||||
- where this tool will look for a storage directory
|
||||
- directory must exist
|
||||
ZF_CONFIG_FILE
|
||||
- where this tool will look for a configuration file
|
||||
ZF_TOOL_INCLUDE_PATH
|
||||
- set the include_path for this tool to use this value
|
||||
ZF_TOOL_INCLUDE_PATH_PREPEND
|
||||
- prepend the current php.ini include_path with this value
|
||||
|
||||
Search Order:
|
||||
Home Directory:
|
||||
- ZF_HOME, then HOME (*nix), then HOMEPATH (windows)
|
||||
Storage Directory:
|
||||
- ZF_STORAGE_DIR, then {home}/.zf/
|
||||
Config File:
|
||||
- ZF_CONFIG_FILE, then {home}/.zf.ini, then {home}/zf.ini,
|
||||
then {storage}/zf.ini
|
||||
|
||||
Commands:
|
||||
zf --setup storage-directory
|
||||
- setup the storage directory, directory will be created
|
||||
zf --setup config-file
|
||||
- create the config file with some default values
|
||||
|
||||
|
||||
EOS;
|
||||
}
|
||||
|
||||
/**
|
||||
* _runTool() - This is where the magic happens, dispatch Zend_Tool
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _runTool()
|
||||
{
|
||||
|
||||
$configOptions = array();
|
||||
if (isset($this->_configFile) && $this->_configFile) {
|
||||
$configOptions['configOptions']['configFilepath'] = $this->_configFile;
|
||||
}
|
||||
if (isset($this->_storageDirectory) && $this->_storageDirectory) {
|
||||
$configOptions['storageOptions']['directory'] = $this->_storageDirectory;
|
||||
}
|
||||
|
||||
// ensure that zf.php loads the Zend_Tool_Project features
|
||||
$configOptions['classesToLoad'] = 'Zend_Tool_Project_Provider_Manifest';
|
||||
|
||||
$console = new Zend_Tool_Framework_Client_Console($configOptions);
|
||||
$console->dispatch();
|
||||
}
|
||||
|
||||
/**
|
||||
* _logMessage() - Internal method used to log setup and information messages.
|
||||
*
|
||||
* @param string $message
|
||||
* @param bool $storeMessage
|
||||
* @return void
|
||||
*/
|
||||
protected function _logMessage($message, $storeMessage = true)
|
||||
{
|
||||
if (!$storeMessage) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_messages[] = $message;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!getenv('ZF_NO_MAIN')) {
|
||||
ZF::main();
|
||||
}
|
45
bin/zf.sh
45
bin/zf.sh
@ -1,45 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
#############################################################################
|
||||
# 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.
|
||||
#
|
||||
# Zend
|
||||
# Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
# http://framework.zend.com/license/new-bsd New BSD License
|
||||
#############################################################################
|
||||
|
||||
|
||||
# find php: pear first, command -v second, straight up php lastly
|
||||
if test "@php_bin@" != '@'php_bin'@'; then
|
||||
PHP_BIN="@php_bin@"
|
||||
elif command -v php 1>/dev/null 2>/dev/null; then
|
||||
PHP_BIN=`command -v php`
|
||||
else
|
||||
PHP_BIN=php
|
||||
fi
|
||||
|
||||
# find zf.php: pear first, same directory 2nd,
|
||||
if test "@php_dir@" != '@'php_dir'@'; then
|
||||
PHP_DIR="@php_dir@"
|
||||
else
|
||||
SELF_LINK="$0"
|
||||
SELF_LINK_TMP="$(readlink "$SELF_LINK")"
|
||||
while test -n "$SELF_LINK_TMP"; do
|
||||
SELF_LINK="$SELF_LINK_TMP"
|
||||
SELF_LINK_TMP="$(readlink "$SELF_LINK")"
|
||||
done
|
||||
PHP_DIR="$(dirname "$SELF_LINK")"
|
||||
fi
|
||||
|
||||
"$PHP_BIN" -d safe_mode=Off -f "$PHP_DIR/zf.php" -- "$@"
|
||||
|
20
composer.json
Normal file
20
composer.json
Normal file
@ -0,0 +1,20 @@
|
||||
{
|
||||
"name": "scores/enrichissement",
|
||||
"description": "Enrichissement",
|
||||
"require": {
|
||||
"zendframework/zendframework1": "^1.12"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"application/",
|
||||
"library/Scores/",
|
||||
"library/SdMetier/"
|
||||
]
|
||||
},
|
||||
"authors": [
|
||||
{
|
||||
"name": "Scores et Decisions",
|
||||
"email": "supportdev@scores-decisions.com"
|
||||
}
|
||||
]
|
||||
}
|
1242
library/Zend/Acl.php
1242
library/Zend/Acl.php
File diff suppressed because it is too large
Load Diff
@ -1,64 +0,0 @@
|
||||
<?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-2015 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-2015 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);
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{}
|
@ -1,74 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?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-2015 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-2015 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();
|
||||
}
|
@ -1,74 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
<?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-2015 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-2015 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();
|
||||
}
|
@ -1,271 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{}
|
@ -1,136 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Auth_Abstract */
|
||||
require_once 'Zend/Amf/Auth/Abstract.php';
|
||||
|
||||
/** @see Zend_Acl */
|
||||
require_once 'Zend/Acl.php';
|
||||
|
||||
/** @see Zend_Auth_Result */
|
||||
require_once 'Zend/Auth/Result.php';
|
||||
|
||||
/** @see Zend_Xml_Security */
|
||||
require_once 'Zend/Xml/Security.php';
|
||||
|
||||
/**
|
||||
* This class implements authentication against XML file with roles for Flex Builder.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Adobe
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Adobe_Auth extends Zend_Amf_Auth_Abstract
|
||||
{
|
||||
|
||||
/**
|
||||
* ACL for authorization
|
||||
*
|
||||
* @var Zend_Acl
|
||||
*/
|
||||
protected $_acl;
|
||||
|
||||
/**
|
||||
* Username/password array
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $_users = array();
|
||||
|
||||
/**
|
||||
* Create auth adapter
|
||||
*
|
||||
* @param string $rolefile File containing XML with users and roles
|
||||
*/
|
||||
public function __construct($rolefile)
|
||||
{
|
||||
$this->_acl = new Zend_Acl();
|
||||
$xml = Zend_Xml_Security::scanFile($rolefile);
|
||||
/*
|
||||
Roles file format:
|
||||
<roles>
|
||||
<role id=”admin”>
|
||||
<user name=”user1” password=”pwd”/>
|
||||
</role>
|
||||
<role id=”hr”>
|
||||
<user name=”user2” password=”pwd2”/>
|
||||
</role>
|
||||
</roles>
|
||||
*/
|
||||
foreach($xml->role as $role) {
|
||||
$this->_acl->addRole(new Zend_Acl_Role((string)$role["id"]));
|
||||
foreach($role->user as $user) {
|
||||
$this->_users[(string)$user["name"]] = array("password" => (string)$user["password"],
|
||||
"role" => (string)$role["id"]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ACL with roles from XML file
|
||||
*
|
||||
* @return Zend_Acl
|
||||
*/
|
||||
public function getAcl()
|
||||
{
|
||||
return $this->_acl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform authentication
|
||||
*
|
||||
* @throws Zend_Auth_Adapter_Exception
|
||||
* @return Zend_Auth_Result
|
||||
* @see Zend_Auth_Adapter_Interface#authenticate()
|
||||
*/
|
||||
public function authenticate()
|
||||
{
|
||||
if (empty($this->_username) ||
|
||||
empty($this->_password)) {
|
||||
/**
|
||||
* @see Zend_Auth_Adapter_Exception
|
||||
*/
|
||||
require_once 'Zend/Auth/Adapter/Exception.php';
|
||||
throw new Zend_Auth_Adapter_Exception('Username/password should be set');
|
||||
}
|
||||
|
||||
if(!isset($this->_users[$this->_username])) {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND,
|
||||
null,
|
||||
array('Username not found')
|
||||
);
|
||||
}
|
||||
|
||||
$user = $this->_users[$this->_username];
|
||||
if($user["password"] != $this->_password) {
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
|
||||
null,
|
||||
array('Authentication failed')
|
||||
);
|
||||
}
|
||||
|
||||
$id = new stdClass();
|
||||
$id->role = $user["role"];
|
||||
$id->name = $this->_username;
|
||||
return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $id);
|
||||
}
|
||||
}
|
@ -1,103 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements authentication against XML file with roles for Flex Builder.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Adobe
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Adobe_DbInspector
|
||||
{
|
||||
|
||||
/**
|
||||
* Connect to the database
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @return Zend_Db_Adapter_Abstract
|
||||
* @see Zend_Db::factory()
|
||||
*/
|
||||
protected function _connect($dbType, $dbDescription)
|
||||
{
|
||||
if(is_object($dbDescription)) {
|
||||
$dbDescription = get_object_vars($dbDescription);
|
||||
}
|
||||
return Zend_Db::factory($dbType, $dbDescription);
|
||||
}
|
||||
|
||||
/**
|
||||
* Describe database object.
|
||||
*
|
||||
* Usage example:
|
||||
* $inspector->describeTable('Pdo_Mysql',
|
||||
* array(
|
||||
* 'host' => '127.0.0.1',
|
||||
* 'username' => 'webuser',
|
||||
* 'password' => 'xxxxxxxx',
|
||||
* 'dbname' => 'test'
|
||||
* ),
|
||||
* 'mytable'
|
||||
* );
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @param string $tableName Table name
|
||||
* @return array Table description
|
||||
* @see Zend_Db::describeTable()
|
||||
* @see Zend_Db::factory()
|
||||
*/
|
||||
public function describeTable($dbType, $dbDescription, $tableName)
|
||||
{
|
||||
$db = $this->_connect($dbType, $dbDescription);
|
||||
return $db->describeTable($tableName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test database connection
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @return bool
|
||||
* @see Zend_Db::factory()
|
||||
*/
|
||||
public function connect($dbType, $dbDescription)
|
||||
{
|
||||
$db = $this->_connect($dbType, $dbDescription);
|
||||
$db->listTables();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of database tables
|
||||
*
|
||||
* @param string $dbType Database adapter type for Zend_Db
|
||||
* @param array|object $dbDescription Adapter-specific connection settings
|
||||
* @return array List of the tables
|
||||
*/
|
||||
public function getTables($dbType, $dbDescription)
|
||||
{
|
||||
$db = $this->_connect($dbType, $dbDescription);
|
||||
return $db->listTables();
|
||||
}
|
||||
}
|
@ -1,318 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Parse_TypeLoader */
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
|
||||
/** @see Zend_Reflection_Class */
|
||||
require_once 'Zend/Reflection/Class.php';
|
||||
|
||||
/** @see Zend_Server_Reflection */
|
||||
require_once 'Zend/Server/Reflection.php';
|
||||
|
||||
/**
|
||||
* This class implements a service for generating AMF service descriptions as XML.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Adobe
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Adobe_Introspector
|
||||
{
|
||||
/**
|
||||
* Options used:
|
||||
* - server: instance of Zend_Amf_Server to use
|
||||
* - directories: directories where class files may be looked up
|
||||
*
|
||||
* @var array Introspector options
|
||||
*/
|
||||
protected $_options;
|
||||
|
||||
/**
|
||||
* @var DOMElement DOM element to store types
|
||||
*/
|
||||
protected $_types;
|
||||
|
||||
/**
|
||||
* @var array Map of the known types
|
||||
*/
|
||||
protected $_typesMap = array();
|
||||
|
||||
/**
|
||||
* @var DOMDocument XML document to store data
|
||||
*/
|
||||
protected $_xml;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->_xml = new DOMDocument('1.0', 'utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create XML definition on an AMF service class
|
||||
*
|
||||
* @param string $serviceClass Service class name
|
||||
* @param array $options invocation options
|
||||
* @return string XML with service class introspection
|
||||
*/
|
||||
public function introspect($serviceClass, $options = array())
|
||||
{
|
||||
$this->_options = $options;
|
||||
|
||||
if (strpbrk($serviceClass, '\\/<>')) {
|
||||
return $this->_returnError('Invalid service name');
|
||||
}
|
||||
|
||||
// Transform com.foo.Bar into com_foo_Bar
|
||||
$serviceClass = str_replace('.' , '_', $serviceClass);
|
||||
|
||||
// Introspect!
|
||||
if (!class_exists($serviceClass)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($serviceClass, $this->_getServicePath());
|
||||
}
|
||||
|
||||
$serv = $this->_xml->createElement('service-description');
|
||||
$serv->setAttribute('xmlns', 'http://ns.adobe.com/flex/service-description/2008');
|
||||
|
||||
$this->_types = $this->_xml->createElement('types');
|
||||
$this->_ops = $this->_xml->createElement('operations');
|
||||
|
||||
$r = Zend_Server_Reflection::reflectClass($serviceClass);
|
||||
$this->_addService($r, $this->_ops);
|
||||
|
||||
$serv->appendChild($this->_types);
|
||||
$serv->appendChild($this->_ops);
|
||||
$this->_xml->appendChild($serv);
|
||||
|
||||
return $this->_xml->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* Authentication handler
|
||||
*
|
||||
* @param Zend_Acl $acl
|
||||
* @return unknown_type
|
||||
*/
|
||||
public function initAcl(Zend_Acl $acl)
|
||||
{
|
||||
return false; // we do not need auth for this class
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate map of public class attributes
|
||||
*
|
||||
* @param string $typename type name
|
||||
* @param DOMElement $typexml target XML element
|
||||
* @return void
|
||||
*/
|
||||
protected function _addClassAttributes($typename, DOMElement $typexml)
|
||||
{
|
||||
// Do not try to autoload here because _phpTypeToAS should
|
||||
// have already attempted to load this class
|
||||
if (!class_exists($typename, false)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rc = new Zend_Reflection_Class($typename);
|
||||
foreach ($rc->getProperties() as $prop) {
|
||||
if (!$prop->isPublic()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$propxml = $this->_xml->createElement('property');
|
||||
$propxml->setAttribute('name', $prop->getName());
|
||||
|
||||
$type = $this->_registerType($this->_getPropertyType($prop));
|
||||
$propxml->setAttribute('type', $type);
|
||||
|
||||
$typexml->appendChild($propxml);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build XML service description from reflection class
|
||||
*
|
||||
* @param Zend_Server_Reflection_Class $refclass
|
||||
* @param DOMElement $target target XML element
|
||||
* @return void
|
||||
*/
|
||||
protected function _addService(Zend_Server_Reflection_Class $refclass, DOMElement $target)
|
||||
{
|
||||
foreach ($refclass->getMethods() as $method) {
|
||||
if (!$method->isPublic()
|
||||
|| $method->isConstructor()
|
||||
|| ('__' == substr($method->name, 0, 2))
|
||||
) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($method->getPrototypes() as $proto) {
|
||||
$op = $this->_xml->createElement('operation');
|
||||
$op->setAttribute('name', $method->getName());
|
||||
|
||||
$rettype = $this->_registerType($proto->getReturnType());
|
||||
$op->setAttribute('returnType', $rettype);
|
||||
|
||||
foreach ($proto->getParameters() as $param) {
|
||||
$arg = $this->_xml->createElement('argument');
|
||||
$arg->setAttribute('name', $param->getName());
|
||||
|
||||
$type = $param->getType();
|
||||
if ($type == 'mixed' && ($pclass = $param->getClass())) {
|
||||
$type = $pclass->getName();
|
||||
}
|
||||
|
||||
$ptype = $this->_registerType($type);
|
||||
$arg->setAttribute('type', $ptype);
|
||||
|
||||
if($param->isDefaultValueAvailable()) {
|
||||
$arg->setAttribute('defaultvalue', $param->getDefaultValue());
|
||||
}
|
||||
|
||||
$op->appendChild($arg);
|
||||
}
|
||||
|
||||
$target->appendChild($op);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract type of the property from DocBlock
|
||||
*
|
||||
* @param Zend_Reflection_Property $prop reflection property object
|
||||
* @return string Property type
|
||||
*/
|
||||
protected function _getPropertyType(Zend_Reflection_Property $prop)
|
||||
{
|
||||
$docBlock = $prop->getDocComment();
|
||||
|
||||
if (!$docBlock) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
if (!$docBlock->hasTag('var')) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
$tag = $docBlock->getTag('var');
|
||||
return trim($tag->getDescription());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the array of service directories
|
||||
*
|
||||
* @return array Service class directories
|
||||
*/
|
||||
protected function _getServicePath()
|
||||
{
|
||||
if (isset($this->_options['server'])) {
|
||||
return $this->_options['server']->getDirectory();
|
||||
}
|
||||
|
||||
if (isset($this->_options['directories'])) {
|
||||
return $this->_options['directories'];
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Map from PHP type name to AS type name
|
||||
*
|
||||
* @param string $typename PHP type name
|
||||
* @return string AS type name
|
||||
*/
|
||||
protected function _phpTypeToAS($typename)
|
||||
{
|
||||
if (class_exists($typename)) {
|
||||
$vars = get_class_vars($typename);
|
||||
|
||||
if (isset($vars['_explicitType'])) {
|
||||
return $vars['_explicitType'];
|
||||
}
|
||||
}
|
||||
|
||||
if (false !== ($asname = Zend_Amf_Parse_TypeLoader::getMappedClassName($typename))) {
|
||||
return $asname;
|
||||
}
|
||||
|
||||
return $typename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register new type on the system
|
||||
*
|
||||
* @param string $typename type name
|
||||
* @return string New type name
|
||||
*/
|
||||
protected function _registerType($typename)
|
||||
{
|
||||
// Known type - return its AS name
|
||||
if (isset($this->_typesMap[$typename])) {
|
||||
return $this->_typesMap[$typename];
|
||||
}
|
||||
|
||||
// Standard types
|
||||
if (in_array($typename, array('void', 'null', 'mixed', 'unknown_type'))) {
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
// Arrays
|
||||
if ('array' == $typename) {
|
||||
return 'Unknown[]';
|
||||
}
|
||||
|
||||
if (in_array($typename, array('int', 'integer', 'bool', 'boolean', 'float', 'string', 'object', 'Unknown', 'stdClass'))) {
|
||||
return $typename;
|
||||
}
|
||||
|
||||
// Resolve and store AS name
|
||||
$asTypeName = $this->_phpTypeToAS($typename);
|
||||
$this->_typesMap[$typename] = $asTypeName;
|
||||
|
||||
// Create element for the name
|
||||
$typeEl = $this->_xml->createElement('type');
|
||||
$typeEl->setAttribute('name', $asTypeName);
|
||||
$this->_addClassAttributes($typename, $typeEl);
|
||||
$this->_types->appendChild($typeEl);
|
||||
|
||||
return $asTypeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return error with error message
|
||||
*
|
||||
* @param string $msg Error message
|
||||
* @return string
|
||||
*/
|
||||
protected function _returnError($msg)
|
||||
{
|
||||
return 'ERROR: $msg';
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 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';
|
||||
|
||||
/**
|
||||
* Base abstract class for AMF authentication implementation
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Auth
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Amf_Auth_Abstract implements Zend_Auth_Adapter_Interface
|
||||
{
|
||||
protected $_username;
|
||||
protected $_password;
|
||||
|
||||
public function setCredentials($username, $password) {
|
||||
$this->_username = $username;
|
||||
$this->_password = $password;
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* The following constants are used throughout serialization and
|
||||
* deserialization to detect the AMF marker and encoding types.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
final class Zend_Amf_Constants
|
||||
{
|
||||
const AMF0_NUMBER = 0x00;
|
||||
const AMF0_BOOLEAN = 0x01;
|
||||
const AMF0_STRING = 0x02;
|
||||
const AMF0_OBJECT = 0x03;
|
||||
const AMF0_MOVIECLIP = 0x04;
|
||||
const AMF0_NULL = 0x05;
|
||||
const AMF0_UNDEFINED = 0x06;
|
||||
const AMF0_REFERENCE = 0x07;
|
||||
const AMF0_MIXEDARRAY = 0x08;
|
||||
const AMF0_OBJECTTERM = 0x09;
|
||||
const AMF0_ARRAY = 0x0a;
|
||||
const AMF0_DATE = 0x0b;
|
||||
const AMF0_LONGSTRING = 0x0c;
|
||||
const AMF0_UNSUPPORTED = 0x0e;
|
||||
const AMF0_XML = 0x0f;
|
||||
const AMF0_TYPEDOBJECT = 0x10;
|
||||
const AMF0_AMF3 = 0x11;
|
||||
const AMF0_OBJECT_ENCODING = 0x00;
|
||||
|
||||
const AMF3_UNDEFINED = 0x00;
|
||||
const AMF3_NULL = 0x01;
|
||||
const AMF3_BOOLEAN_FALSE = 0x02;
|
||||
const AMF3_BOOLEAN_TRUE = 0x03;
|
||||
const AMF3_INTEGER = 0x04;
|
||||
const AMF3_NUMBER = 0x05;
|
||||
const AMF3_STRING = 0x06;
|
||||
const AMF3_XML = 0x07;
|
||||
const AMF3_DATE = 0x08;
|
||||
const AMF3_ARRAY = 0x09;
|
||||
const AMF3_OBJECT = 0x0A;
|
||||
const AMF3_XMLSTRING = 0x0B;
|
||||
const AMF3_BYTEARRAY = 0x0C;
|
||||
const AMF3_OBJECT_ENCODING = 0x03;
|
||||
|
||||
// Object encodings for AMF3 object types
|
||||
const ET_PROPLIST = 0x00;
|
||||
const ET_EXTERNAL = 0x01;
|
||||
const ET_DYNAMIC = 0x02;
|
||||
const ET_PROXY = 0x03;
|
||||
|
||||
const FMS_OBJECT_ENCODING = 0x01;
|
||||
|
||||
/**
|
||||
* Special content length value that indicates "unknown" content length
|
||||
* per AMF Specification
|
||||
*/
|
||||
const UNKNOWN_CONTENT_LENGTH = -1;
|
||||
const URL_APPEND_HEADER = 'AppendToGatewayUrl';
|
||||
const RESULT_METHOD = '/onResult';
|
||||
const STATUS_METHOD = '/onStatus';
|
||||
const CREDENTIALS_HEADER = 'Credentials';
|
||||
const PERSISTENT_HEADER = 'RequestPersistentHeader';
|
||||
const DESCRIBE_HEADER = 'DescribeService';
|
||||
|
||||
const GUEST_ROLE = 'anonymous';
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 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';
|
||||
|
||||
/**
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Exception extends Zend_Exception
|
||||
{
|
||||
}
|
@ -1,309 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** Zend_Xml_Security */
|
||||
require_once 'Zend/Xml/Security.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Deserializer */
|
||||
require_once 'Zend/Amf/Parse/Deserializer.php';
|
||||
|
||||
/**
|
||||
* Read an AMF0 input stream and convert it into PHP data types
|
||||
*
|
||||
* @todo Implement Typed Object Class Mapping
|
||||
* @todo Class could be implemented as Factory Class with each data type it's own class
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf0_Deserializer extends Zend_Amf_Parse_Deserializer
|
||||
{
|
||||
/**
|
||||
* An array of objects used for recursively deserializing an object.
|
||||
* @var array
|
||||
*/
|
||||
protected $_reference = array();
|
||||
|
||||
/**
|
||||
* If AMF3 serialization occurs, update to AMF0 0x03
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $_objectEncoding = Zend_Amf_Constants::AMF0_OBJECT_ENCODING;
|
||||
|
||||
/**
|
||||
* Read AMF markers and dispatch for deserialization
|
||||
*
|
||||
* Checks for AMF marker types and calls the appropriate methods
|
||||
* for deserializing those marker types. Markers are the data type of
|
||||
* the following value.
|
||||
*
|
||||
* @param integer $typeMarker
|
||||
* @return mixed whatever the data type is of the marker in php
|
||||
* @throws Zend_Amf_Exception for invalid type
|
||||
*/
|
||||
public function readTypeMarker($typeMarker = null)
|
||||
{
|
||||
if ($typeMarker === null) {
|
||||
$typeMarker = $this->_stream->readByte();
|
||||
}
|
||||
|
||||
switch($typeMarker) {
|
||||
// number
|
||||
case Zend_Amf_Constants::AMF0_NUMBER:
|
||||
return $this->_stream->readDouble();
|
||||
|
||||
// boolean
|
||||
case Zend_Amf_Constants::AMF0_BOOLEAN:
|
||||
return (boolean) $this->_stream->readByte();
|
||||
|
||||
// string
|
||||
case Zend_Amf_Constants::AMF0_STRING:
|
||||
return $this->_stream->readUTF();
|
||||
|
||||
// object
|
||||
case Zend_Amf_Constants::AMF0_OBJECT:
|
||||
return $this->readObject();
|
||||
|
||||
// null
|
||||
case Zend_Amf_Constants::AMF0_NULL:
|
||||
return null;
|
||||
|
||||
// undefined
|
||||
case Zend_Amf_Constants::AMF0_UNDEFINED:
|
||||
return null;
|
||||
|
||||
// Circular references are returned here
|
||||
case Zend_Amf_Constants::AMF0_REFERENCE:
|
||||
return $this->readReference();
|
||||
|
||||
// mixed array with numeric and string keys
|
||||
case Zend_Amf_Constants::AMF0_MIXEDARRAY:
|
||||
return $this->readMixedArray();
|
||||
|
||||
// array
|
||||
case Zend_Amf_Constants::AMF0_ARRAY:
|
||||
return $this->readArray();
|
||||
|
||||
// date
|
||||
case Zend_Amf_Constants::AMF0_DATE:
|
||||
return $this->readDate();
|
||||
|
||||
// longString strlen(string) > 2^16
|
||||
case Zend_Amf_Constants::AMF0_LONGSTRING:
|
||||
return $this->_stream->readLongUTF();
|
||||
|
||||
//internal AS object, not supported
|
||||
case Zend_Amf_Constants::AMF0_UNSUPPORTED:
|
||||
return null;
|
||||
|
||||
// XML
|
||||
case Zend_Amf_Constants::AMF0_XML:
|
||||
return $this->readXmlString();
|
||||
|
||||
// typed object ie Custom Class
|
||||
case Zend_Amf_Constants::AMF0_TYPEDOBJECT:
|
||||
return $this->readTypedObject();
|
||||
|
||||
//AMF3-specific
|
||||
case Zend_Amf_Constants::AMF0_AMF3:
|
||||
return $this->readAmf3TypeMarker();
|
||||
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported marker type: ' . $typeMarker);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read AMF objects and convert to PHP objects
|
||||
*
|
||||
* Read the name value pair objects form the php message and convert them to
|
||||
* a php object class.
|
||||
*
|
||||
* Called when the marker type is 3.
|
||||
*
|
||||
* @param array|null $object
|
||||
* @return object
|
||||
*/
|
||||
public function readObject($object = null)
|
||||
{
|
||||
if ($object === null) {
|
||||
$object = array();
|
||||
}
|
||||
|
||||
while (true) {
|
||||
$key = $this->_stream->readUTF();
|
||||
$typeMarker = $this->_stream->readByte();
|
||||
if ($typeMarker != Zend_Amf_Constants::AMF0_OBJECTTERM ){
|
||||
//Recursivly call readTypeMarker to get the types of properties in the object
|
||||
$object[$key] = $this->readTypeMarker($typeMarker);
|
||||
} else {
|
||||
//encountered AMF object terminator
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->_reference[] = $object;
|
||||
return (object) $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read reference objects
|
||||
*
|
||||
* Used to gain access to the private array of reference objects.
|
||||
* Called when marker type is 7.
|
||||
*
|
||||
* @return object
|
||||
* @throws Zend_Amf_Exception for invalid reference keys
|
||||
*/
|
||||
public function readReference()
|
||||
{
|
||||
$key = $this->_stream->readInt();
|
||||
if (!array_key_exists($key, $this->_reference)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid reference key: '. $key);
|
||||
}
|
||||
return $this->_reference[$key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an array with numeric and string indexes.
|
||||
*
|
||||
* Called when marker type is 8
|
||||
*
|
||||
* @todo As of Flash Player 9 there is not support for mixed typed arrays
|
||||
* so we handle this as an object. With the introduction of vectors
|
||||
* in Flash Player 10 this may need to be reconsidered.
|
||||
* @return array
|
||||
*/
|
||||
public function readMixedArray()
|
||||
{
|
||||
$length = $this->_stream->readLong();
|
||||
return $this->readObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts numerically indexed actiosncript arrays into php arrays.
|
||||
*
|
||||
* Called when marker type is 10
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function readArray()
|
||||
{
|
||||
$length = $this->_stream->readLong();
|
||||
$array = array();
|
||||
while ($length--) {
|
||||
$array[] = $this->readTypeMarker();
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert AS Date to Zend_Date
|
||||
*
|
||||
* @return Zend_Date
|
||||
*/
|
||||
public function readDate()
|
||||
{
|
||||
// get the unix time stamp. Not sure why ActionScript does not use
|
||||
// milliseconds
|
||||
$timestamp = floor($this->_stream->readDouble() / 1000);
|
||||
|
||||
// The timezone offset is never returned to the server; it is always 0,
|
||||
// so read and ignore.
|
||||
$offset = $this->_stream->readInt();
|
||||
|
||||
require_once 'Zend/Date.php';
|
||||
$date = new Zend_Date($timestamp);
|
||||
return $date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert XML to SimpleXml
|
||||
* If user wants DomDocument they can use dom_import_simplexml
|
||||
*
|
||||
* @return SimpleXml Object
|
||||
*/
|
||||
public function readXmlString()
|
||||
{
|
||||
$string = $this->_stream->readLongUTF();
|
||||
return Zend_Xml_Security::scan($string); //simplexml_load_string($string);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read Class that is to be mapped to a server class.
|
||||
*
|
||||
* Commonly used for Value Objects on the server
|
||||
*
|
||||
* @todo implement Typed Class mapping
|
||||
* @return object|array
|
||||
* @throws Zend_Amf_Exception if unable to load type
|
||||
*/
|
||||
public function readTypedObject()
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
// get the remote class name
|
||||
$className = $this->_stream->readUTF();
|
||||
$loader = Zend_Amf_Parse_TypeLoader::loadType($className);
|
||||
$returnObject = new $loader();
|
||||
$properties = get_object_vars($this->readObject());
|
||||
foreach($properties as $key=>$value) {
|
||||
if($key) {
|
||||
$returnObject->$key = $value;
|
||||
}
|
||||
}
|
||||
if($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
|
||||
$returnObject = get_object_vars($returnObject);
|
||||
}
|
||||
return $returnObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* AMF3 data type encountered load AMF3 Deserializer to handle
|
||||
* type markers.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function readAmf3TypeMarker()
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/Amf3/Deserializer.php';
|
||||
$deserializer = new Zend_Amf_Parse_Amf3_Deserializer($this->_stream);
|
||||
$this->_objectEncoding = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
|
||||
return $deserializer->readTypeMarker();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the object encoding to check if an AMF3 object
|
||||
* is going to be return.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getObjectEncoding()
|
||||
{
|
||||
return $this->_objectEncoding;
|
||||
}
|
||||
}
|
@ -1,362 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Serializer */
|
||||
require_once 'Zend/Amf/Parse/Serializer.php';
|
||||
|
||||
/**
|
||||
* Serializer PHP misc types back to there corresponding AMF0 Type Marker.
|
||||
*
|
||||
* @uses Zend_Amf_Parse_Serializer
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf0
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf0_Serializer extends Zend_Amf_Parse_Serializer
|
||||
{
|
||||
/**
|
||||
* @var string Name of the class to be returned
|
||||
*/
|
||||
protected $_className = '';
|
||||
|
||||
/**
|
||||
* An array of reference objects
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceObjects = array();
|
||||
|
||||
/**
|
||||
* Determine type and serialize accordingly
|
||||
*
|
||||
* Checks to see if the type was declared and then either
|
||||
* auto negotiates the type or relies on the user defined markerType to
|
||||
* serialize the data into amf
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param mixed $markerType
|
||||
* @param mixed $dataByVal
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
* @throws Zend_Amf_Exception for unrecognized types or data
|
||||
*/
|
||||
public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $data) && ($dataByVal !== false)) {
|
||||
$data = &$dataByVal;
|
||||
}
|
||||
if (null !== $markerType) {
|
||||
//try to reference the given object
|
||||
if (!$this->writeObjectReference($data, $markerType)) {
|
||||
// Write the Type Marker to denote the following action script data type
|
||||
$this->_stream->writeByte($markerType);
|
||||
switch($markerType) {
|
||||
case Zend_Amf_Constants::AMF0_NUMBER:
|
||||
$this->_stream->writeDouble($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_BOOLEAN:
|
||||
$this->_stream->writeByte($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_STRING:
|
||||
$this->_stream->writeUTF($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_OBJECT:
|
||||
$this->writeObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_NULL:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_REFERENCE:
|
||||
$this->_stream->writeInt($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_MIXEDARRAY:
|
||||
// Write length of numeric keys as zero.
|
||||
$this->_stream->writeLong(0);
|
||||
$this->writeObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_ARRAY:
|
||||
$this->writeArray($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_DATE:
|
||||
$this->writeDate($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_LONGSTRING:
|
||||
$this->_stream->writeLongUTF($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_TYPEDOBJECT:
|
||||
$this->writeTypedObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF0_AMF3:
|
||||
$this->writeAmf3TypeMarker($data);
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception("Unknown Type Marker: " . $markerType);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (is_resource($data)) {
|
||||
$data = Zend_Amf_Parse_TypeLoader::handleResource($data);
|
||||
}
|
||||
switch (true) {
|
||||
case (is_int($data) || is_float($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_NUMBER;
|
||||
break;
|
||||
case (is_bool($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_BOOLEAN;
|
||||
break;
|
||||
case (is_string($data) && (($this->_mbStringFunctionsOverloaded ? mb_strlen($data, '8bit') : strlen($data)) > 65536)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_LONGSTRING;
|
||||
break;
|
||||
case (is_string($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF0_STRING;
|
||||
break;
|
||||
case (is_object($data)):
|
||||
if (($data instanceof DateTime) || ($data instanceof Zend_Date)) {
|
||||
$markerType = Zend_Amf_Constants::AMF0_DATE;
|
||||
} else {
|
||||
|
||||
if($className = $this->getClassName($data)){
|
||||
//Object is a Typed object set classname
|
||||
$markerType = Zend_Amf_Constants::AMF0_TYPEDOBJECT;
|
||||
$this->_className = $className;
|
||||
} else {
|
||||
// Object is a generic classname
|
||||
$markerType = Zend_Amf_Constants::AMF0_OBJECT;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case (null === $data):
|
||||
$markerType = Zend_Amf_Constants::AMF0_NULL;
|
||||
break;
|
||||
case (is_array($data)):
|
||||
// check if it is an associative array
|
||||
$i = 0;
|
||||
foreach (array_keys($data) as $key) {
|
||||
// check if it contains non-integer keys
|
||||
if (!is_numeric($key) || intval($key) != $key) {
|
||||
$markerType = Zend_Amf_Constants::AMF0_OBJECT;
|
||||
break;
|
||||
// check if it is a sparse indexed array
|
||||
} else if ($key != $i) {
|
||||
$markerType = Zend_Amf_Constants::AMF0_MIXEDARRAY;
|
||||
break;
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
// Dealing with a standard numeric array
|
||||
if(!$markerType){
|
||||
$markerType = Zend_Amf_Constants::AMF0_ARRAY;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data));
|
||||
}
|
||||
|
||||
$this->writeTypeMarker($data, $markerType);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given object is in the reference table, write the reference if it exists,
|
||||
* otherwise add the object to the reference table
|
||||
*
|
||||
* @param mixed $object object reference to check for reference
|
||||
* @param string $markerType AMF type of the object to write
|
||||
* @param mixed $objectByVal object to check for reference
|
||||
* @return Boolean true, if the reference was written, false otherwise
|
||||
*/
|
||||
protected function writeObjectReference(&$object, $markerType, $objectByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $object) && ($objectByVal !== false)) {
|
||||
$object = &$objectByVal;
|
||||
}
|
||||
|
||||
if ($markerType == Zend_Amf_Constants::AMF0_OBJECT
|
||||
|| $markerType == Zend_Amf_Constants::AMF0_MIXEDARRAY
|
||||
|| $markerType == Zend_Amf_Constants::AMF0_ARRAY
|
||||
|| $markerType == Zend_Amf_Constants::AMF0_TYPEDOBJECT
|
||||
) {
|
||||
$ref = array_search($object, $this->_referenceObjects, true);
|
||||
//handle object reference
|
||||
if($ref !== false){
|
||||
$this->writeTypeMarker($ref,Zend_Amf_Constants::AMF0_REFERENCE);
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->_referenceObjects[] = $object;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a PHP array with string or mixed keys.
|
||||
*
|
||||
* @param object $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeObject($object)
|
||||
{
|
||||
// Loop each element and write the name of the property.
|
||||
foreach ($object as $key => &$value) {
|
||||
// skip variables starting with an _ private transient
|
||||
if( $key[0] == "_") continue;
|
||||
$this->_stream->writeUTF($key);
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
|
||||
// Write the end object flag
|
||||
$this->_stream->writeInt(0);
|
||||
$this->_stream->writeByte(Zend_Amf_Constants::AMF0_OBJECTTERM);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a standard numeric array to the output stream. If a mixed array
|
||||
* is encountered call writeTypeMarker with mixed array.
|
||||
*
|
||||
* @param array $array
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeArray(&$array)
|
||||
{
|
||||
$length = count($array);
|
||||
if (!$length < 0) {
|
||||
// write the length of the array
|
||||
$this->_stream->writeLong(0);
|
||||
} else {
|
||||
// Write the length of the numeric array
|
||||
$this->_stream->writeLong($length);
|
||||
for ($i=0; $i<$length; $i++) {
|
||||
$value = isset($array[$i]) ? $array[$i] : null;
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the DateTime into an AMF Date
|
||||
*
|
||||
* @param DateTime|Zend_Date $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeDate($data)
|
||||
{
|
||||
if ($data instanceof DateTime) {
|
||||
$dateString = $data->format('U');
|
||||
} elseif ($data instanceof Zend_Date) {
|
||||
$dateString = $data->toString('U');
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid date specified; must be a DateTime or Zend_Date object');
|
||||
}
|
||||
$dateString *= 1000;
|
||||
|
||||
// Make the conversion and remove milliseconds.
|
||||
$this->_stream->writeDouble($dateString);
|
||||
|
||||
// Flash does not respect timezone but requires it.
|
||||
$this->_stream->writeInt(0);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a class mapped object to the output stream.
|
||||
*
|
||||
* @param object $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeTypedObject($data)
|
||||
{
|
||||
$this->_stream->writeUTF($this->_className);
|
||||
$this->writeObject($data);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Encountered and AMF3 Type Marker use AMF3 serializer. Once AMF3 is
|
||||
* encountered it will not return to AMf0.
|
||||
*
|
||||
* @param string $data
|
||||
* @return Zend_Amf_Parse_Amf0_Serializer
|
||||
*/
|
||||
public function writeAmf3TypeMarker(&$data)
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/Amf3/Serializer.php';
|
||||
$serializer = new Zend_Amf_Parse_Amf3_Serializer($this->_stream);
|
||||
$serializer->writeTypeMarker($data);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find if the class name is a class mapped name and return the
|
||||
* respective classname if it is.
|
||||
*
|
||||
* @param object $object
|
||||
* @return false|string $className
|
||||
*/
|
||||
protected function getClassName($object)
|
||||
{
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
//Check to see if the object is a typed object and we need to change
|
||||
$className = '';
|
||||
switch (true) {
|
||||
// the return class mapped name back to actionscript class name.
|
||||
case Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object)):
|
||||
$className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object));
|
||||
break;
|
||||
// Check to see if the user has defined an explicit Action Script type.
|
||||
case isset($object->_explicitType):
|
||||
$className = $object->_explicitType;
|
||||
break;
|
||||
// Check if user has defined a method for accessing the Action Script type
|
||||
case method_exists($object, 'getASClassName'):
|
||||
$className = $object->getASClassName();
|
||||
break;
|
||||
// No return class name is set make it a generic object
|
||||
case ($object instanceof stdClass):
|
||||
$className = '';
|
||||
break;
|
||||
// By default, use object's class name
|
||||
default:
|
||||
$className = get_class($object);
|
||||
break;
|
||||
}
|
||||
if(!$className == '') {
|
||||
return $className;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,425 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Parse_Deserializer */
|
||||
require_once 'Zend/Amf/Parse/Deserializer.php';
|
||||
|
||||
/** Zend_Xml_Security */
|
||||
require_once 'Zend/Xml/Security.php';
|
||||
|
||||
/** Zend_Amf_Parse_TypeLoader */
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
|
||||
/**
|
||||
* Read an AMF3 input stream and convert it into PHP data types.
|
||||
*
|
||||
* @todo readObject to handle Typed Objects
|
||||
* @todo readXMLStrimg to be implemented.
|
||||
* @todo Class could be implemented as Factory Class with each data type it's own class.
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf3_Deserializer extends Zend_Amf_Parse_Deserializer
|
||||
{
|
||||
/**
|
||||
* Total number of objects in the referenceObject array
|
||||
* @var int
|
||||
*/
|
||||
protected $_objectCount;
|
||||
|
||||
/**
|
||||
* An array of reference objects per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceObjects = array();
|
||||
|
||||
/**
|
||||
* An array of reference strings per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceStrings = array();
|
||||
|
||||
/**
|
||||
* An array of reference class definitions per body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceDefinitions = array();
|
||||
|
||||
/**
|
||||
* Read AMF markers and dispatch for deserialization
|
||||
*
|
||||
* Checks for AMF marker types and calls the appropriate methods
|
||||
* for deserializing those marker types. markers are the data type of
|
||||
* the following value.
|
||||
*
|
||||
* @param integer $typeMarker
|
||||
* @return mixed Whatever the corresponding PHP data type is
|
||||
* @throws Zend_Amf_Exception for unidentified marker type
|
||||
*/
|
||||
public function readTypeMarker($typeMarker = null)
|
||||
{
|
||||
if(null === $typeMarker) {
|
||||
$typeMarker = $this->_stream->readByte();
|
||||
}
|
||||
|
||||
switch($typeMarker) {
|
||||
case Zend_Amf_Constants::AMF3_UNDEFINED:
|
||||
return null;
|
||||
case Zend_Amf_Constants::AMF3_NULL:
|
||||
return null;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_FALSE:
|
||||
return false;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_TRUE:
|
||||
return true;
|
||||
case Zend_Amf_Constants::AMF3_INTEGER:
|
||||
return $this->readInteger();
|
||||
case Zend_Amf_Constants::AMF3_NUMBER:
|
||||
return $this->_stream->readDouble();
|
||||
case Zend_Amf_Constants::AMF3_STRING:
|
||||
return $this->readString();
|
||||
case Zend_Amf_Constants::AMF3_DATE:
|
||||
return $this->readDate();
|
||||
case Zend_Amf_Constants::AMF3_ARRAY:
|
||||
return $this->readArray();
|
||||
case Zend_Amf_Constants::AMF3_OBJECT:
|
||||
return $this->readObject();
|
||||
case Zend_Amf_Constants::AMF3_XML:
|
||||
case Zend_Amf_Constants::AMF3_XMLSTRING:
|
||||
return $this->readXmlString();
|
||||
case Zend_Amf_Constants::AMF3_BYTEARRAY:
|
||||
return $this->readString();
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported type marker: ' . $typeMarker);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and deserialize an integer
|
||||
*
|
||||
* AMF 3 represents smaller integers with fewer bytes using the most
|
||||
* significant bit of each byte. The worst case uses 32-bits
|
||||
* to represent a 29-bit number, which is what we would have
|
||||
* done with no compression.
|
||||
* - 0x00000000 - 0x0000007F : 0xxxxxxx
|
||||
* - 0x00000080 - 0x00003FFF : 1xxxxxxx 0xxxxxxx
|
||||
* - 0x00004000 - 0x001FFFFF : 1xxxxxxx 1xxxxxxx 0xxxxxxx
|
||||
* - 0x00200000 - 0x3FFFFFFF : 1xxxxxxx 1xxxxxxx 1xxxxxxx xxxxxxxx
|
||||
* - 0x40000000 - 0xFFFFFFFF : throw range exception
|
||||
*
|
||||
* 0x04 -> integer type code, followed by up to 4 bytes of data.
|
||||
*
|
||||
* Parsing integers on OSFlash for the AMF3 integer data format:
|
||||
* @link http://osflash.org/amf3/parsing_integers
|
||||
* @return int|float
|
||||
*/
|
||||
public function readInteger()
|
||||
{
|
||||
$count = 1;
|
||||
$intReference = $this->_stream->readByte();
|
||||
$result = 0;
|
||||
while ((($intReference & 0x80) != 0) && $count < 4) {
|
||||
$result <<= 7;
|
||||
$result |= ($intReference & 0x7f);
|
||||
$intReference = $this->_stream->readByte();
|
||||
$count++;
|
||||
}
|
||||
if ($count < 4) {
|
||||
$result <<= 7;
|
||||
$result |= $intReference;
|
||||
} else {
|
||||
// Use all 8 bits from the 4th byte
|
||||
$result <<= 8;
|
||||
$result |= $intReference;
|
||||
|
||||
// Check if the integer should be negative
|
||||
if (($result & 0x10000000) != 0) {
|
||||
//and extend the sign bit
|
||||
$result |= ~0xFFFFFFF;
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and deserialize a string
|
||||
*
|
||||
* Strings can be sent as a reference to a previously
|
||||
* occurring String by using an index to the implicit string reference table.
|
||||
* Strings are encoding using UTF-8 - however the header may either
|
||||
* describe a string literal or a string reference.
|
||||
*
|
||||
* - string = 0x06 string-data
|
||||
* - string-data = integer-data [ modified-utf-8 ]
|
||||
* - modified-utf-8 = *OCTET
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function readString()
|
||||
{
|
||||
$stringReference = $this->readInteger();
|
||||
|
||||
//Check if this is a reference string
|
||||
if (($stringReference & 0x01) == 0) {
|
||||
// reference string
|
||||
$stringReference = $stringReference >> 1;
|
||||
if ($stringReference >= count($this->_referenceStrings)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Undefined string reference: ' . $stringReference);
|
||||
}
|
||||
// reference string found
|
||||
return $this->_referenceStrings[$stringReference];
|
||||
}
|
||||
|
||||
$length = $stringReference >> 1;
|
||||
if ($length) {
|
||||
$string = $this->_stream->readBytes($length);
|
||||
$this->_referenceStrings[] = $string;
|
||||
} else {
|
||||
$string = "";
|
||||
}
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read and deserialize a date
|
||||
*
|
||||
* Data is the number of milliseconds elapsed since the epoch
|
||||
* of midnight, 1st Jan 1970 in the UTC time zone.
|
||||
* Local time zone information is not sent to flash.
|
||||
*
|
||||
* - date = 0x08 integer-data [ number-data ]
|
||||
*
|
||||
* @return Zend_Date
|
||||
*/
|
||||
public function readDate()
|
||||
{
|
||||
$dateReference = $this->readInteger();
|
||||
if (($dateReference & 0x01) == 0) {
|
||||
$dateReference = $dateReference >> 1;
|
||||
if ($dateReference>=count($this->_referenceObjects)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Undefined date reference: ' . $dateReference);
|
||||
}
|
||||
return $this->_referenceObjects[$dateReference];
|
||||
}
|
||||
|
||||
$timestamp = floor($this->_stream->readDouble() / 1000);
|
||||
|
||||
require_once 'Zend/Date.php';
|
||||
$dateTime = new Zend_Date($timestamp);
|
||||
$this->_referenceObjects[] = $dateTime;
|
||||
return $dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read amf array to PHP array
|
||||
*
|
||||
* - array = 0x09 integer-data ( [ 1OCTET *amf3-data ] | [OCTET *amf3-data 1] | [ OCTET *amf-data ] )
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function readArray()
|
||||
{
|
||||
$arrayReference = $this->readInteger();
|
||||
if (($arrayReference & 0x01)==0){
|
||||
$arrayReference = $arrayReference >> 1;
|
||||
if ($arrayReference>=count($this->_referenceObjects)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknow array reference: ' . $arrayReference);
|
||||
}
|
||||
return $this->_referenceObjects[$arrayReference];
|
||||
}
|
||||
|
||||
// Create a holder for the array in the reference list
|
||||
$data = array();
|
||||
$this->_referenceObjects[] =& $data;
|
||||
$key = $this->readString();
|
||||
|
||||
// Iterating for string based keys.
|
||||
while ($key != '') {
|
||||
$data[$key] = $this->readTypeMarker();
|
||||
$key = $this->readString();
|
||||
}
|
||||
|
||||
$arrayReference = $arrayReference >>1;
|
||||
|
||||
//We have a dense array
|
||||
for ($i=0; $i < $arrayReference; $i++) {
|
||||
$data[] = $this->readTypeMarker();
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read an object from the AMF stream and convert it into a PHP object
|
||||
*
|
||||
* @todo Rather than using an array of traitsInfo create Zend_Amf_Value_TraitsInfo
|
||||
* @return object|array
|
||||
*/
|
||||
public function readObject()
|
||||
{
|
||||
$traitsInfo = $this->readInteger();
|
||||
$storedObject = ($traitsInfo & 0x01)==0;
|
||||
$traitsInfo = $traitsInfo >> 1;
|
||||
|
||||
// Check if the Object is in the stored Objects reference table
|
||||
if ($storedObject) {
|
||||
$ref = $traitsInfo;
|
||||
if (!isset($this->_referenceObjects[$ref])) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Object reference: ' . $ref);
|
||||
}
|
||||
$returnObject = $this->_referenceObjects[$ref];
|
||||
} else {
|
||||
// Check if the Object is in the stored Definitions reference table
|
||||
$storedClass = ($traitsInfo & 0x01) == 0;
|
||||
$traitsInfo = $traitsInfo >> 1;
|
||||
if ($storedClass) {
|
||||
$ref = $traitsInfo;
|
||||
if (!isset($this->_referenceDefinitions[$ref])) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknows Definition reference: '. $ref);
|
||||
}
|
||||
// Populate the reference attributes
|
||||
$className = $this->_referenceDefinitions[$ref]['className'];
|
||||
$encoding = $this->_referenceDefinitions[$ref]['encoding'];
|
||||
$propertyNames = $this->_referenceDefinitions[$ref]['propertyNames'];
|
||||
} else {
|
||||
// The class was not in the reference tables. Start reading rawdata to build traits.
|
||||
// Create a traits table. Zend_Amf_Value_TraitsInfo would be ideal
|
||||
$className = $this->readString();
|
||||
$encoding = $traitsInfo & 0x03;
|
||||
$propertyNames = array();
|
||||
$traitsInfo = $traitsInfo >> 2;
|
||||
}
|
||||
|
||||
// We now have the object traits defined in variables. Time to go to work:
|
||||
if (!$className) {
|
||||
// No class name generic object
|
||||
$returnObject = new stdClass();
|
||||
} else {
|
||||
// Defined object
|
||||
// Typed object lookup against registered classname maps
|
||||
if ($loader = Zend_Amf_Parse_TypeLoader::loadType($className)) {
|
||||
$returnObject = new $loader();
|
||||
} else {
|
||||
//user defined typed object
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Typed object not found: '. $className . ' ');
|
||||
}
|
||||
}
|
||||
|
||||
// Add the Object to the reference table
|
||||
$this->_referenceObjects[] = $returnObject;
|
||||
|
||||
$properties = array(); // clear value
|
||||
// Check encoding types for additional processing.
|
||||
switch ($encoding) {
|
||||
case (Zend_Amf_Constants::ET_EXTERNAL):
|
||||
// Externalizable object such as {ArrayCollection} and {ObjectProxy}
|
||||
if (!$storedClass) {
|
||||
$this->_referenceDefinitions[] = array(
|
||||
'className' => $className,
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
}
|
||||
$returnObject->externalizedData = $this->readTypeMarker();
|
||||
break;
|
||||
case (Zend_Amf_Constants::ET_DYNAMIC):
|
||||
// used for Name-value encoding
|
||||
if (!$storedClass) {
|
||||
$this->_referenceDefinitions[] = array(
|
||||
'className' => $className,
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
}
|
||||
// not a reference object read name value properties from byte stream
|
||||
do {
|
||||
$property = $this->readString();
|
||||
if ($property != "") {
|
||||
$propertyNames[] = $property;
|
||||
$properties[$property] = $this->readTypeMarker();
|
||||
}
|
||||
} while ($property !="");
|
||||
break;
|
||||
default:
|
||||
// basic property list object.
|
||||
if (!$storedClass) {
|
||||
$count = $traitsInfo; // Number of properties in the list
|
||||
for($i=0; $i< $count; $i++) {
|
||||
$propertyNames[] = $this->readString();
|
||||
}
|
||||
// Add a reference to the class.
|
||||
$this->_referenceDefinitions[] = array(
|
||||
'className' => $className,
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
}
|
||||
foreach ($propertyNames as $property) {
|
||||
$properties[$property] = $this->readTypeMarker();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Add properties back to the return object.
|
||||
if (!is_array($properties)) $properties = array();
|
||||
foreach($properties as $key=>$value) {
|
||||
if($key) {
|
||||
$returnObject->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ($returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection) {
|
||||
if (isset($returnObject->externalizedData)) {
|
||||
$returnObject = $returnObject->externalizedData;
|
||||
} else {
|
||||
$returnObject = get_object_vars($returnObject);
|
||||
}
|
||||
}
|
||||
|
||||
return $returnObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert XML to SimpleXml
|
||||
* If user wants DomDocument they can use dom_import_simplexml
|
||||
*
|
||||
* @return SimpleXml Object
|
||||
*/
|
||||
public function readXmlString()
|
||||
{
|
||||
$xmlReference = $this->readInteger();
|
||||
$length = $xmlReference >> 1;
|
||||
$string = $this->_stream->readBytes($length);
|
||||
return Zend_Xml_Security::scan($string);
|
||||
}
|
||||
}
|
@ -1,534 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
|
||||
/** Zend_Amf_Parse_Serializer */
|
||||
require_once 'Zend/Amf/Parse/Serializer.php';
|
||||
|
||||
/** Zend_Amf_Parse_TypeLoader */
|
||||
require_once 'Zend/Amf/Parse/TypeLoader.php';
|
||||
|
||||
/**
|
||||
* Detect PHP object type and convert it to a corresponding AMF3 object type
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse_Amf3
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Amf3_Serializer extends Zend_Amf_Parse_Serializer
|
||||
{
|
||||
/**
|
||||
* A constant empty string
|
||||
* @var string
|
||||
*/
|
||||
protected $_strEmpty = '';
|
||||
|
||||
/**
|
||||
* An array of reference objects per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceObjects = array();
|
||||
|
||||
/**
|
||||
* An array of reference strings per amf body
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceStrings = array();
|
||||
|
||||
/**
|
||||
* An array of reference class definitions, indexed by classname
|
||||
* @var array
|
||||
*/
|
||||
protected $_referenceDefinitions = array();
|
||||
|
||||
/**
|
||||
* Serialize PHP types to AMF3 and write to stream
|
||||
*
|
||||
* Checks to see if the type was declared and then either
|
||||
* auto negotiates the type or use the user defined markerType to
|
||||
* serialize the data from php back to AMF3
|
||||
*
|
||||
* @param mixed $data
|
||||
* @param int $markerType
|
||||
* @param mixed $dataByVal
|
||||
* @return void
|
||||
*/
|
||||
public function writeTypeMarker(&$data, $markerType = null, $dataByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $data) && ($dataByVal !== false)) {
|
||||
$data = &$dataByVal;
|
||||
}
|
||||
if (null !== $markerType) {
|
||||
// Write the Type Marker to denote the following action script data type
|
||||
$this->_stream->writeByte($markerType);
|
||||
|
||||
switch ($markerType) {
|
||||
case Zend_Amf_Constants::AMF3_NULL:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_FALSE:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_BOOLEAN_TRUE:
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_INTEGER:
|
||||
$this->writeInteger($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_NUMBER:
|
||||
$this->_stream->writeDouble($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_STRING:
|
||||
$this->writeString($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_DATE:
|
||||
$this->writeDate($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_ARRAY:
|
||||
$this->writeArray($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_OBJECT:
|
||||
$this->writeObject($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_BYTEARRAY:
|
||||
$this->writeByteArray($data);
|
||||
break;
|
||||
case Zend_Amf_Constants::AMF3_XMLSTRING;
|
||||
$this->writeXml($data);
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Type Marker: ' . $markerType);
|
||||
}
|
||||
} else {
|
||||
// Detect Type Marker
|
||||
if (is_resource($data)) {
|
||||
$data = Zend_Amf_Parse_TypeLoader::handleResource($data);
|
||||
}
|
||||
switch (true) {
|
||||
case (null === $data):
|
||||
$markerType = Zend_Amf_Constants::AMF3_NULL;
|
||||
break;
|
||||
case (is_bool($data)):
|
||||
if ($data){
|
||||
$markerType = Zend_Amf_Constants::AMF3_BOOLEAN_TRUE;
|
||||
} else {
|
||||
$markerType = Zend_Amf_Constants::AMF3_BOOLEAN_FALSE;
|
||||
}
|
||||
break;
|
||||
case (is_int($data)):
|
||||
if (($data > 0xFFFFFFF) || ($data < -268435456)) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_NUMBER;
|
||||
} else {
|
||||
$markerType = Zend_Amf_Constants::AMF3_INTEGER;
|
||||
}
|
||||
break;
|
||||
case (is_float($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF3_NUMBER;
|
||||
break;
|
||||
case (is_string($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF3_STRING;
|
||||
break;
|
||||
case (is_array($data)):
|
||||
$markerType = Zend_Amf_Constants::AMF3_ARRAY;
|
||||
break;
|
||||
case (is_object($data)):
|
||||
// Handle object types.
|
||||
if (($data instanceof DateTime) || ($data instanceof Zend_Date)) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_DATE;
|
||||
} else if ($data instanceof Zend_Amf_Value_ByteArray) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_BYTEARRAY;
|
||||
} else if (($data instanceof DOMDocument) || ($data instanceof SimpleXMLElement)) {
|
||||
$markerType = Zend_Amf_Constants::AMF3_XMLSTRING;
|
||||
} else {
|
||||
$markerType = Zend_Amf_Constants::AMF3_OBJECT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unsupported data type: ' . gettype($data));
|
||||
}
|
||||
$this->writeTypeMarker($data, $markerType);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an AMF3 integer
|
||||
*
|
||||
* @param int|float $data
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeInteger($int)
|
||||
{
|
||||
if (($int & 0xffffff80) == 0) {
|
||||
$this->_stream->writeByte($int & 0x7f);
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (($int & 0xffffc000) == 0 ) {
|
||||
$this->_stream->writeByte(($int >> 7 ) | 0x80);
|
||||
$this->_stream->writeByte($int & 0x7f);
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (($int & 0xffe00000) == 0) {
|
||||
$this->_stream->writeByte(($int >> 14 ) | 0x80);
|
||||
$this->_stream->writeByte(($int >> 7 ) | 0x80);
|
||||
$this->_stream->writeByte($int & 0x7f);
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->_stream->writeByte(($int >> 22 ) | 0x80);
|
||||
$this->_stream->writeByte(($int >> 15 ) | 0x80);
|
||||
$this->_stream->writeByte(($int >> 8 ) | 0x80);
|
||||
$this->_stream->writeByte($int & 0xff);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send string to output stream, without trying to reference it.
|
||||
* The string is prepended with strlen($string) << 1 | 0x01
|
||||
*
|
||||
* @param string $string
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
protected function writeBinaryString(&$string){
|
||||
$ref = ($this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string)) << 1 | 0x01;
|
||||
$this->writeInteger($ref);
|
||||
$this->_stream->writeBytes($string);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send string to output stream
|
||||
*
|
||||
* @param string $string
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeString(&$string)
|
||||
{
|
||||
$len = $this->_mbStringFunctionsOverloaded ? mb_strlen($string, '8bit') : strlen($string);
|
||||
if(!$len){
|
||||
$this->writeInteger(0x01);
|
||||
return $this;
|
||||
}
|
||||
|
||||
$ref = array_key_exists($string, $this->_referenceStrings)
|
||||
? $this->_referenceStrings[$string]
|
||||
: false;
|
||||
if ($ref === false){
|
||||
$this->_referenceStrings[$string] = count($this->_referenceStrings);
|
||||
$this->writeBinaryString($string);
|
||||
} else {
|
||||
$ref <<= 1;
|
||||
$this->writeInteger($ref);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send ByteArray to output stream
|
||||
*
|
||||
* @param string|Zend_Amf_Value_ByteArray $data
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeByteArray(&$data)
|
||||
{
|
||||
if ($this->writeObjectReference($data)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if (is_string($data)) {
|
||||
//nothing to do
|
||||
} else if ($data instanceof Zend_Amf_Value_ByteArray) {
|
||||
$data = $data->getData();
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid ByteArray specified; must be a string or Zend_Amf_Value_ByteArray');
|
||||
}
|
||||
|
||||
$this->writeBinaryString($data);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send xml to output stream
|
||||
*
|
||||
* @param DOMDocument|SimpleXMLElement $xml
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeXml($xml)
|
||||
{
|
||||
if ($this->writeObjectReference($xml)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if(is_string($xml)) {
|
||||
//nothing to do
|
||||
} else if ($xml instanceof DOMDocument) {
|
||||
$xml = $xml->saveXml();
|
||||
} else if ($xml instanceof SimpleXMLElement) {
|
||||
$xml = $xml->asXML();
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid xml specified; must be a DOMDocument or SimpleXMLElement');
|
||||
}
|
||||
|
||||
$this->writeBinaryString($xml);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert DateTime/Zend_Date to AMF date
|
||||
*
|
||||
* @param DateTime|Zend_Date $date
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeDate($date)
|
||||
{
|
||||
if ($this->writeObjectReference($date)) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
if ($date instanceof DateTime) {
|
||||
$dateString = $date->format('U') * 1000;
|
||||
} elseif ($date instanceof Zend_Date) {
|
||||
$dateString = $date->toString('U') * 1000;
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Invalid date specified; must be a string DateTime or Zend_Date object');
|
||||
}
|
||||
|
||||
$this->writeInteger(0x01);
|
||||
// write time to stream minus milliseconds
|
||||
$this->_stream->writeDouble($dateString);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a PHP array back to the amf output stream
|
||||
*
|
||||
* @param array $array
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeArray(&$array)
|
||||
{
|
||||
// arrays aren't reference here but still counted
|
||||
$this->_referenceObjects[] = $array;
|
||||
|
||||
// have to seperate mixed from numberic keys.
|
||||
$numeric = array();
|
||||
$string = array();
|
||||
foreach ($array as $key => &$value) {
|
||||
if (is_int($key)) {
|
||||
$numeric[] = $value;
|
||||
} else {
|
||||
$string[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
// write the preamble id of the array
|
||||
$length = count($numeric);
|
||||
$id = ($length << 1) | 0x01;
|
||||
$this->writeInteger($id);
|
||||
|
||||
//Write the mixed type array to the output stream
|
||||
foreach($string as $key => &$value) {
|
||||
$this->writeString($key)
|
||||
->writeTypeMarker($value);
|
||||
}
|
||||
$this->writeString($this->_strEmpty);
|
||||
|
||||
// Write the numeric array to ouput stream
|
||||
foreach($numeric as &$value) {
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given object is in the reference table, write the reference if it exists,
|
||||
* otherwise add the object to the reference table
|
||||
*
|
||||
* @param mixed $object object reference to check for reference
|
||||
* @param mixed $objectByVal object to check for reference
|
||||
* @return Boolean true, if the reference was written, false otherwise
|
||||
*/
|
||||
protected function writeObjectReference(&$object, $objectByVal = false)
|
||||
{
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about "Only
|
||||
// variables should be passed by reference"
|
||||
if ((null === $object) && ($objectByVal !== false)) {
|
||||
$object = &$objectByVal;
|
||||
}
|
||||
|
||||
$hash = spl_object_hash($object);
|
||||
$ref = array_key_exists($hash, $this->_referenceObjects)
|
||||
? $this->_referenceObjects[$hash]
|
||||
: false;
|
||||
|
||||
// quickly handle object references
|
||||
if ($ref !== false){
|
||||
$ref <<= 1;
|
||||
$this->writeInteger($ref);
|
||||
return true;
|
||||
}
|
||||
$this->_referenceObjects[$hash] = count($this->_referenceObjects);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write object to ouput stream
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return Zend_Amf_Parse_Amf3_Serializer
|
||||
*/
|
||||
public function writeObject($object)
|
||||
{
|
||||
if($this->writeObjectReference($object)){
|
||||
return $this;
|
||||
}
|
||||
|
||||
$className = '';
|
||||
|
||||
//Check to see if the object is a typed object and we need to change
|
||||
switch (true) {
|
||||
// the return class mapped name back to actionscript class name.
|
||||
case ($className = Zend_Amf_Parse_TypeLoader::getMappedClassName(get_class($object))):
|
||||
break;
|
||||
|
||||
// Check to see if the user has defined an explicit Action Script type.
|
||||
case isset($object->_explicitType):
|
||||
$className = $object->_explicitType;
|
||||
break;
|
||||
|
||||
// Check if user has defined a method for accessing the Action Script type
|
||||
case method_exists($object, 'getASClassName'):
|
||||
$className = $object->getASClassName();
|
||||
break;
|
||||
|
||||
// No return class name is set make it a generic object
|
||||
case ($object instanceof stdClass):
|
||||
$className = '';
|
||||
break;
|
||||
|
||||
// By default, use object's class name
|
||||
default:
|
||||
$className = get_class($object);
|
||||
break;
|
||||
}
|
||||
|
||||
$writeTraits = true;
|
||||
|
||||
//check to see, if we have a corresponding definition
|
||||
if(array_key_exists($className, $this->_referenceDefinitions)){
|
||||
$traitsInfo = $this->_referenceDefinitions[$className]['id'];
|
||||
$encoding = $this->_referenceDefinitions[$className]['encoding'];
|
||||
$propertyNames = $this->_referenceDefinitions[$className]['propertyNames'];
|
||||
|
||||
$traitsInfo = ($traitsInfo << 2) | 0x01;
|
||||
|
||||
$writeTraits = false;
|
||||
} else {
|
||||
$propertyNames = array();
|
||||
|
||||
if($className == ''){
|
||||
//if there is no className, we interpret the class as dynamic without any sealed members
|
||||
$encoding = Zend_Amf_Constants::ET_DYNAMIC;
|
||||
} else {
|
||||
$encoding = Zend_Amf_Constants::ET_PROPLIST;
|
||||
|
||||
foreach($object as $key => $value) {
|
||||
if( $key[0] != "_") {
|
||||
$propertyNames[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->_referenceDefinitions[$className] = array(
|
||||
'id' => count($this->_referenceDefinitions),
|
||||
'encoding' => $encoding,
|
||||
'propertyNames' => $propertyNames,
|
||||
);
|
||||
|
||||
$traitsInfo = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
|
||||
$traitsInfo |= $encoding << 2;
|
||||
$traitsInfo |= (count($propertyNames) << 4);
|
||||
}
|
||||
|
||||
$this->writeInteger($traitsInfo);
|
||||
|
||||
if($writeTraits){
|
||||
$this->writeString($className);
|
||||
foreach ($propertyNames as $value) {
|
||||
$this->writeString($value);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
switch($encoding) {
|
||||
case Zend_Amf_Constants::ET_PROPLIST:
|
||||
//Write the sealed values to the output stream.
|
||||
foreach ($propertyNames as $key) {
|
||||
$this->writeTypeMarker($object->$key);
|
||||
}
|
||||
break;
|
||||
case Zend_Amf_Constants::ET_DYNAMIC:
|
||||
//Write the sealed values to the output stream.
|
||||
foreach ($propertyNames as $key) {
|
||||
$this->writeTypeMarker($object->$key);
|
||||
}
|
||||
|
||||
//Write remaining properties
|
||||
foreach($object as $key => $value){
|
||||
if(!in_array($key,$propertyNames) && $key[0] != "_"){
|
||||
$this->writeString($key);
|
||||
$this->writeTypeMarker($value);
|
||||
}
|
||||
}
|
||||
|
||||
//Write an empty string to end the dynamic part
|
||||
$this->writeString($this->_strEmpty);
|
||||
break;
|
||||
case Zend_Amf_Constants::ET_EXTERNAL:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('External Object Encoding not implemented');
|
||||
break;
|
||||
default:
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Object Encoding type: ' . $encoding);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to writeObject output: ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -1,65 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract cass that all deserializer must implement.
|
||||
*
|
||||
* Logic for deserialization of the AMF envelop is based on resources supplied
|
||||
* by Adobe Blaze DS. For and example of deserialization please review the BlazeDS
|
||||
* source tree.
|
||||
*
|
||||
* @see http://opensource.adobe.com/svn/opensource/blazeds/trunk/modules/core/src/java/flex/messaging/io/amf/
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Amf_Parse_Deserializer
|
||||
{
|
||||
/**
|
||||
* The raw string that represents the AMF request.
|
||||
*
|
||||
* @var Zend_Amf_Parse_InputStream
|
||||
*/
|
||||
protected $_stream;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Amf_Parse_InputStream $stream
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Amf_Parse_InputStream $stream)
|
||||
{
|
||||
$this->_stream = $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks for AMF marker types and calls the appropriate methods
|
||||
* for deserializing those marker types. Markers are the data type of
|
||||
* the following value.
|
||||
*
|
||||
* @param int $typeMarker
|
||||
* @return mixed Whatever the data type is of the marker in php
|
||||
*/
|
||||
public abstract function readTypeMarker($markerType = null);
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Util_BinaryStream */
|
||||
require_once 'Zend/Amf/Util/BinaryStream.php';
|
||||
|
||||
/**
|
||||
* InputStream is used to iterate at a binary level through the AMF request.
|
||||
*
|
||||
* InputStream extends BinaryStream as eventually BinaryStream could be placed
|
||||
* outside of Zend_Amf in order to allow other packages to use the class.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_InputStream extends Zend_Amf_Util_BinaryStream
|
||||
{
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Util_BinaryStream */
|
||||
require_once 'Zend/Amf/Util/BinaryStream.php';
|
||||
|
||||
/**
|
||||
* Iterate at a binary level through the AMF response
|
||||
*
|
||||
* OutputStream extends BinaryStream as eventually BinaryStream could be placed
|
||||
* outside of Zend_Amf in order to allow other packages to use the class.
|
||||
*
|
||||
* @uses Zend_Amf_Util_BinaryStream
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_OutputStream extends Zend_Amf_Util_BinaryStream
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('');
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert mysql result resource to array suitable for passing
|
||||
* to the external entities.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_MysqlResult
|
||||
{
|
||||
/**
|
||||
* @var array List of Mysql types with PHP counterparts
|
||||
*
|
||||
* Key => Value is Mysql type (exact string) => PHP type
|
||||
*/
|
||||
static public $fieldTypes = array(
|
||||
"int" => "int",
|
||||
"timestamp" => "int",
|
||||
"year" => "int",
|
||||
"real" => "float",
|
||||
);
|
||||
/**
|
||||
* Parse resource into array
|
||||
*
|
||||
* @param resource $resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
$result = array();
|
||||
$fieldcnt = mysql_num_fields($resource);
|
||||
$fields_transform = array();
|
||||
for($i=0;$i<$fieldcnt;$i++) {
|
||||
$type = mysql_field_type($resource, $i);
|
||||
if(isset(self::$fieldTypes[$type])) {
|
||||
$fields_transform[mysql_field_name($resource, $i)] = self::$fieldTypes[$type];
|
||||
}
|
||||
}
|
||||
|
||||
while($row = mysql_fetch_object($resource)) {
|
||||
foreach($fields_transform as $fieldname => $fieldtype) {
|
||||
settype($row->$fieldname, $fieldtype);
|
||||
}
|
||||
$result[] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert mysql result resource to array suitable for passing
|
||||
* to the external entities.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_MysqliResult
|
||||
{
|
||||
|
||||
/**
|
||||
* mapping taken from http://forums.mysql.com/read.php?52,255868,255895#msg-255895
|
||||
*/
|
||||
static public $mysqli_type = array(
|
||||
0 => "MYSQLI_TYPE_DECIMAL",
|
||||
1 => "MYSQLI_TYPE_TINYINT",
|
||||
2 => "MYSQLI_TYPE_SMALLINT",
|
||||
3 => "MYSQLI_TYPE_INTEGER",
|
||||
4 => "MYSQLI_TYPE_FLOAT",
|
||||
5 => "MYSQLI_TYPE_DOUBLE",
|
||||
7 => "MYSQLI_TYPE_TIMESTAMP",
|
||||
8 => "MYSQLI_TYPE_BIGINT",
|
||||
9 => "MYSQLI_TYPE_MEDIUMINT",
|
||||
10 => "MYSQLI_TYPE_DATE",
|
||||
11 => "MYSQLI_TYPE_TIME",
|
||||
12 => "MYSQLI_TYPE_DATETIME",
|
||||
13 => "MYSQLI_TYPE_YEAR",
|
||||
14 => "MYSQLI_TYPE_DATE",
|
||||
16 => "MYSQLI_TYPE_BIT",
|
||||
246 => "MYSQLI_TYPE_DECIMAL",
|
||||
247 => "MYSQLI_TYPE_ENUM",
|
||||
248 => "MYSQLI_TYPE_SET",
|
||||
249 => "MYSQLI_TYPE_TINYBLOB",
|
||||
250 => "MYSQLI_TYPE_MEDIUMBLOB",
|
||||
251 => "MYSQLI_TYPE_LONGBLOB",
|
||||
252 => "MYSQLI_TYPE_BLOB",
|
||||
253 => "MYSQLI_TYPE_VARCHAR",
|
||||
254 => "MYSQLI_TYPE_CHAR",
|
||||
255 => "MYSQLI_TYPE_GEOMETRY",
|
||||
);
|
||||
|
||||
// Build an associative array for a type look up
|
||||
static $mysqli_to_php = array(
|
||||
"MYSQLI_TYPE_DECIMAL" => 'float',
|
||||
"MYSQLI_TYPE_NEWDECIMAL" => 'float',
|
||||
"MYSQLI_TYPE_BIT" => 'integer',
|
||||
"MYSQLI_TYPE_TINYINT" => 'integer',
|
||||
"MYSQLI_TYPE_SMALLINT" => 'integer',
|
||||
"MYSQLI_TYPE_MEDIUMINT" => 'integer',
|
||||
"MYSQLI_TYPE_BIGINT" => 'integer',
|
||||
"MYSQLI_TYPE_INTEGER" => 'integer',
|
||||
"MYSQLI_TYPE_FLOAT" => 'float',
|
||||
"MYSQLI_TYPE_DOUBLE" => 'float',
|
||||
"MYSQLI_TYPE_NULL" => 'null',
|
||||
"MYSQLI_TYPE_TIMESTAMP" => 'string',
|
||||
"MYSQLI_TYPE_INT24" => 'integer',
|
||||
"MYSQLI_TYPE_DATE" => 'string',
|
||||
"MYSQLI_TYPE_TIME" => 'string',
|
||||
"MYSQLI_TYPE_DATETIME" => 'string',
|
||||
"MYSQLI_TYPE_YEAR" => 'string',
|
||||
"MYSQLI_TYPE_NEWDATE" => 'string',
|
||||
"MYSQLI_TYPE_ENUM" => 'string',
|
||||
"MYSQLI_TYPE_SET" => 'string',
|
||||
"MYSQLI_TYPE_TINYBLOB" => 'object',
|
||||
"MYSQLI_TYPE_MEDIUMBLOB" => 'object',
|
||||
"MYSQLI_TYPE_LONGBLOB" => 'object',
|
||||
"MYSQLI_TYPE_BLOB" => 'object',
|
||||
"MYSQLI_TYPE_CHAR" => 'string',
|
||||
"MYSQLI_TYPE_VARCHAR" => 'string',
|
||||
"MYSQLI_TYPE_GEOMETRY" => 'object',
|
||||
"MYSQLI_TYPE_BIT" => 'integer',
|
||||
);
|
||||
|
||||
/**
|
||||
* Parse resource into array
|
||||
*
|
||||
* @param resource $resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
|
||||
$result = array();
|
||||
$fieldcnt = mysqli_num_fields($resource);
|
||||
|
||||
|
||||
$fields_transform = array();
|
||||
|
||||
for($i=0;$i<$fieldcnt;$i++) {
|
||||
$finfo = mysqli_fetch_field_direct($resource, $i);
|
||||
|
||||
if(isset(self::$mysqli_type[$finfo->type])) {
|
||||
$fields_transform[$finfo->name] = self::$mysqli_to_php[self::$mysqli_type[$finfo->type]];
|
||||
}
|
||||
}
|
||||
|
||||
while($row = mysqli_fetch_assoc($resource)) {
|
||||
foreach($fields_transform as $fieldname => $fieldtype) {
|
||||
settype($row[$fieldname], $fieldtype);
|
||||
}
|
||||
$result[] = $row;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will convert stream resource to string by just reading it
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Parse_Resource_Stream
|
||||
{
|
||||
/**
|
||||
* Parse resource into string
|
||||
*
|
||||
* @param resource $resource Stream resource
|
||||
* @return array
|
||||
*/
|
||||
public function parse($resource) {
|
||||
return stream_get_contents($resource);
|
||||
}
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Base abstract class for all AMF serializers.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
abstract class Zend_Amf_Parse_Serializer
|
||||
{
|
||||
/**
|
||||
* Reference to the current output stream being constructed
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_stream;
|
||||
|
||||
/**
|
||||
* str* functions overloaded using mbstring.func_overload
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected $mbStringFunctionsOverloaded;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Zend_Amf_Parse_OutputStream $stream
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Zend_Amf_Parse_OutputStream $stream)
|
||||
{
|
||||
$this->_stream = $stream;
|
||||
$this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the PHP object type and convert it into an AMF object type
|
||||
*
|
||||
* @param mixed $content
|
||||
* @param int $markerType
|
||||
* @param mixed $contentByVal
|
||||
* @return void
|
||||
*/
|
||||
public abstract function writeTypeMarker(&$content, $markerType = null, $contentByVal = false);
|
||||
}
|
@ -1,231 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_AcknowledgeMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_AsyncMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_CommandMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/CommandMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_ErrorMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php';
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_RemotingMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php';
|
||||
|
||||
/**
|
||||
* Loads a local class and executes the instantiation of that class.
|
||||
*
|
||||
* @todo PHP 5.3 can drastically change this class w/ namespace and the new call_user_func w/ namespace
|
||||
* @package Zend_Amf
|
||||
* @subpackage Parse
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
final class Zend_Amf_Parse_TypeLoader
|
||||
{
|
||||
/**
|
||||
* @var string callback class
|
||||
*/
|
||||
public static $callbackClass;
|
||||
|
||||
/**
|
||||
* @var array AMF class map
|
||||
*/
|
||||
public static $classMap = array (
|
||||
'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_AsyncMessage',
|
||||
'flex.messaging.messages.CommandMessage' => 'Zend_Amf_Value_Messaging_CommandMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_ErrorMessage',
|
||||
'flex.messaging.messages.RemotingMessage' => 'Zend_Amf_Value_Messaging_RemotingMessage',
|
||||
'flex.messaging.io.ArrayCollection' => 'Zend_Amf_Value_Messaging_ArrayCollection',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Default class map
|
||||
*/
|
||||
protected static $_defaultClassMap = array(
|
||||
'flex.messaging.messages.AcknowledgeMessage' => 'Zend_Amf_Value_Messaging_AcknowledgeMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_AsyncMessage',
|
||||
'flex.messaging.messages.CommandMessage' => 'Zend_Amf_Value_Messaging_CommandMessage',
|
||||
'flex.messaging.messages.ErrorMessage' => 'Zend_Amf_Value_Messaging_ErrorMessage',
|
||||
'flex.messaging.messages.RemotingMessage' => 'Zend_Amf_Value_Messaging_RemotingMessage',
|
||||
'flex.messaging.io.ArrayCollection' => 'Zend_Amf_Value_Messaging_ArrayCollection',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var Zend_Loader_PluginLoader_Interface
|
||||
*/
|
||||
protected static $_resourceLoader = null;
|
||||
|
||||
|
||||
/**
|
||||
* Load the mapped class type into a callback.
|
||||
*
|
||||
* @param string $className
|
||||
* @return object|false
|
||||
*/
|
||||
public static function loadType($className)
|
||||
{
|
||||
$class = self::getMappedClassName($className);
|
||||
if(!$class) {
|
||||
$class = str_replace('.', '_', $className);
|
||||
}
|
||||
if (!class_exists($class)) {
|
||||
return "stdClass";
|
||||
}
|
||||
return $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up the supplied call name to its mapped class name
|
||||
*
|
||||
* @param string $className
|
||||
* @return string
|
||||
*/
|
||||
public static function getMappedClassName($className)
|
||||
{
|
||||
$mappedName = array_search($className, self::$classMap);
|
||||
|
||||
if ($mappedName) {
|
||||
return $mappedName;
|
||||
}
|
||||
|
||||
$mappedName = array_search($className, array_flip(self::$classMap));
|
||||
|
||||
if ($mappedName) {
|
||||
return $mappedName;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Map PHP class names to ActionScript class names
|
||||
*
|
||||
* Allows users to map the class names of there action script classes
|
||||
* to the equivelent php class name. Used in deserialization to load a class
|
||||
* and serialiation to set the class name of the returned object.
|
||||
*
|
||||
* @param string $asClassName
|
||||
* @param string $phpClassName
|
||||
* @return void
|
||||
*/
|
||||
public static function setMapping($asClassName, $phpClassName)
|
||||
{
|
||||
self::$classMap[$asClassName] = $phpClassName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset type map
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function resetMap()
|
||||
{
|
||||
self::$classMap = self::$_defaultClassMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set loader for resource type handlers
|
||||
*
|
||||
* @param Zend_Loader_PluginLoader_Interface $loader
|
||||
*/
|
||||
public static function setResourceLoader(Zend_Loader_PluginLoader_Interface $loader)
|
||||
{
|
||||
self::$_resourceLoader = $loader;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add directory to the list of places where to look for resource handlers
|
||||
*
|
||||
* @param string $prefix
|
||||
* @param string $dir
|
||||
*/
|
||||
public static function addResourceDirectory($prefix, $dir)
|
||||
{
|
||||
if(self::$_resourceLoader) {
|
||||
self::$_resourceLoader->addPrefixPath($prefix, $dir);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get plugin class that handles this resource
|
||||
*
|
||||
* @param resource $resource Resource type
|
||||
* @return string Class name
|
||||
*/
|
||||
public static function getResourceParser($resource)
|
||||
{
|
||||
if(self::$_resourceLoader) {
|
||||
$type = preg_replace("/[^A-Za-z0-9_]/", " ", get_resource_type($resource));
|
||||
$type = str_replace(" ","", ucwords($type));
|
||||
return self::$_resourceLoader->load($type);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert resource to a serializable object
|
||||
*
|
||||
* @param resource $resource
|
||||
* @return mixed
|
||||
*/
|
||||
public static function handleResource($resource)
|
||||
{
|
||||
if(!self::$_resourceLoader) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to handle resources - resource plugin loader not set');
|
||||
}
|
||||
try {
|
||||
while(is_resource($resource)) {
|
||||
$resclass = self::getResourceParser($resource);
|
||||
if(!$resclass) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Can not serialize resource type: '. get_resource_type($resource));
|
||||
}
|
||||
$parser = new $resclass();
|
||||
if(is_callable(array($parser, 'parse'))) {
|
||||
$resource = $parser->parse($resource);
|
||||
} else {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception("Could not call parse() method on class $resclass");
|
||||
}
|
||||
}
|
||||
return $resource;
|
||||
} catch(Zend_Amf_Exception $e) {
|
||||
throw new Zend_Amf_Exception($e->getMessage(), $e->getCode(), $e);
|
||||
} catch(Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Can not serialize resource type: '. get_resource_type($resource), 0, $e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Parse_InputStream */
|
||||
require_once 'Zend/Amf/Parse/InputStream.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Amf0_Deserializer */
|
||||
require_once 'Zend/Amf/Parse/Amf0/Deserializer.php';
|
||||
|
||||
/** @see Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** @see Zend_Amf_Value_MessageHeader */
|
||||
require_once 'Zend/Amf/Value/MessageHeader.php';
|
||||
|
||||
/** @see Zend_Amf_Value_MessageBody */
|
||||
require_once 'Zend/Amf/Value/MessageBody.php';
|
||||
|
||||
/**
|
||||
* Handle the incoming AMF request by deserializing the data to php object
|
||||
* types and storing the data for Zend_Amf_Server to handle for processing.
|
||||
*
|
||||
* @todo Currently not checking if the object needs to be Type Mapped to a server object.
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Request
|
||||
{
|
||||
/**
|
||||
* @var int AMF client type (AMF0, AMF3)
|
||||
*/
|
||||
protected $_clientType = 0; // default AMF0
|
||||
|
||||
/**
|
||||
* @var array Message bodies
|
||||
*/
|
||||
protected $_bodies = array();
|
||||
|
||||
/**
|
||||
* @var array Message headers
|
||||
*/
|
||||
protected $_headers = array();
|
||||
|
||||
/**
|
||||
* @var int Message encoding to use for objects in response
|
||||
*/
|
||||
protected $_objectEncoding = 0;
|
||||
|
||||
/**
|
||||
* @var Zend_Amf_Parse_InputStream
|
||||
*/
|
||||
protected $_inputStream;
|
||||
|
||||
/**
|
||||
* @var Zend_Amf_Parse_AMF0_Deserializer
|
||||
*/
|
||||
protected $_deserializer;
|
||||
|
||||
/**
|
||||
* Time of the request
|
||||
* @var mixed
|
||||
*/
|
||||
protected $_time;
|
||||
|
||||
/**
|
||||
* Prepare the AMF InputStream for parsing.
|
||||
*
|
||||
* @param string $request
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function initialize($request)
|
||||
{
|
||||
$this->_inputStream = new Zend_Amf_Parse_InputStream($request);
|
||||
$this->_deserializer = new Zend_Amf_Parse_Amf0_Deserializer($this->_inputStream);
|
||||
$this->readMessage($this->_inputStream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes the raw AMF input stream and converts it into valid PHP objects
|
||||
*
|
||||
* @param Zend_Amf_Parse_InputStream
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function readMessage(Zend_Amf_Parse_InputStream $stream)
|
||||
{
|
||||
$clientVersion = $stream->readUnsignedShort();
|
||||
if (($clientVersion != Zend_Amf_Constants::AMF0_OBJECT_ENCODING)
|
||||
&& ($clientVersion != Zend_Amf_Constants::AMF3_OBJECT_ENCODING)
|
||||
&& ($clientVersion != Zend_Amf_Constants::FMS_OBJECT_ENCODING)
|
||||
) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unknown Player Version ' . $clientVersion);
|
||||
}
|
||||
|
||||
$this->_bodies = array();
|
||||
$this->_headers = array();
|
||||
$headerCount = $stream->readInt();
|
||||
|
||||
// Iterate through the AMF envelope header
|
||||
while ($headerCount--) {
|
||||
$this->_headers[] = $this->readHeader();
|
||||
}
|
||||
|
||||
// Iterate through the AMF envelope body
|
||||
$bodyCount = $stream->readInt();
|
||||
while ($bodyCount--) {
|
||||
$this->_bodies[] = $this->readBody();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a message header from the input stream.
|
||||
*
|
||||
* A message header is structured as:
|
||||
* - NAME String
|
||||
* - MUST UNDERSTAND Boolean
|
||||
* - LENGTH Int
|
||||
* - DATA Object
|
||||
*
|
||||
* @return Zend_Amf_Value_MessageHeader
|
||||
*/
|
||||
public function readHeader()
|
||||
{
|
||||
$name = $this->_inputStream->readUTF();
|
||||
$mustRead = (bool)$this->_inputStream->readByte();
|
||||
$length = $this->_inputStream->readLong();
|
||||
|
||||
try {
|
||||
$data = $this->_deserializer->readTypeMarker();
|
||||
} catch (Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to parse ' . $name . ' header data: ' . $e->getMessage() . ' '. $e->getLine(), 0, $e);
|
||||
}
|
||||
|
||||
$header = new Zend_Amf_Value_MessageHeader($name, $mustRead, $data, $length);
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserialize a message body from the input stream
|
||||
*
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function readBody()
|
||||
{
|
||||
$targetURI = $this->_inputStream->readUTF();
|
||||
$responseURI = $this->_inputStream->readUTF();
|
||||
$length = $this->_inputStream->readLong();
|
||||
|
||||
try {
|
||||
$data = $this->_deserializer->readTypeMarker();
|
||||
} catch (Exception $e) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Unable to parse ' . $targetURI . ' body data ' . $e->getMessage(), 0, $e);
|
||||
}
|
||||
|
||||
// Check for AMF3 objectEncoding
|
||||
if ($this->_deserializer->getObjectEncoding() == Zend_Amf_Constants::AMF3_OBJECT_ENCODING) {
|
||||
/*
|
||||
* When and AMF3 message is sent to the server it is nested inside
|
||||
* an AMF0 array called Content. The following code gets the object
|
||||
* out of the content array and sets it as the message data.
|
||||
*/
|
||||
if(is_array($data) && $data[0] instanceof Zend_Amf_Value_Messaging_AbstractMessage){
|
||||
$data = $data[0];
|
||||
}
|
||||
|
||||
// set the encoding so we return our message in AMF3
|
||||
$this->_objectEncoding = Zend_Amf_Constants::AMF3_OBJECT_ENCODING;
|
||||
}
|
||||
|
||||
$body = new Zend_Amf_Value_MessageBody($targetURI, $responseURI, $data);
|
||||
return $body;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of the body objects that were found in the amf request.
|
||||
*
|
||||
* @return array {target, response, length, content}
|
||||
*/
|
||||
public function getAmfBodies()
|
||||
{
|
||||
return $this->_bodies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor to private array of message bodies.
|
||||
*
|
||||
* @param Zend_Amf_Value_MessageBody $message
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function addAmfBody(Zend_Amf_Value_MessageBody $message)
|
||||
{
|
||||
$this->_bodies[] = $message;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of headers that were found in the amf request.
|
||||
*
|
||||
* @return array {operation, mustUnderstand, length, param}
|
||||
*/
|
||||
public function getAmfHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the either 0 or 3 for respect AMF version
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getObjectEncoding()
|
||||
{
|
||||
return $this->_objectEncoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the object response encoding
|
||||
*
|
||||
* @param mixed $int
|
||||
* @return Zend_Amf_Request
|
||||
*/
|
||||
public function setObjectEncoding($int)
|
||||
{
|
||||
$this->_objectEncoding = $int;
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -1,80 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Request */
|
||||
require_once 'Zend/Amf/Request.php';
|
||||
|
||||
/**
|
||||
* AMF Request object -- Request via HTTP
|
||||
*
|
||||
* Extends {@link Zend_Amf_Request} to accept a request via HTTP. Request is
|
||||
* built at construction time using a raw POST; if no data is available, the
|
||||
* request is declared a fault.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Request
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Request_Http extends Zend_Amf_Request
|
||||
{
|
||||
/**
|
||||
* Raw AMF request
|
||||
* @var string
|
||||
*/
|
||||
protected $_rawRequest;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Attempts to read from php://input to get raw POST request; if an error
|
||||
* occurs in doing so, or if the AMF body is invalid, the request is declared a
|
||||
* fault.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// php://input allows you to read raw POST data. It is a less memory
|
||||
// intensive alternative to $HTTP_RAW_POST_DATA and does not need any
|
||||
// special php.ini directives
|
||||
$amfRequest = file_get_contents('php://input');
|
||||
|
||||
// Check to make sure that we have data on the input stream.
|
||||
if ($amfRequest != '') {
|
||||
$this->_rawRequest = $amfRequest;
|
||||
$this->initialize($amfRequest);
|
||||
} else {
|
||||
echo '<p>Zend Amf Endpoint</p>' ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve raw AMF Request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRawRequest()
|
||||
{
|
||||
return $this->_rawRequest;
|
||||
}
|
||||
}
|
@ -1,205 +0,0 @@
|
||||
<?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_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Constants */
|
||||
require_once 'Zend/Amf/Constants.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_OutputStream */
|
||||
require_once 'Zend/Amf/Parse/OutputStream.php';
|
||||
|
||||
/** @see Zend_Amf_Parse_Amf0_Serializer */
|
||||
require_once 'Zend/Amf/Parse/Amf0/Serializer.php';
|
||||
|
||||
/**
|
||||
* Handles converting the PHP object ready for response back into AMF
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Response
|
||||
{
|
||||
/**
|
||||
* @var int Object encoding for response
|
||||
*/
|
||||
protected $_objectEncoding = 0;
|
||||
|
||||
/**
|
||||
* Array of Zend_Amf_Value_MessageBody objects
|
||||
* @var array
|
||||
*/
|
||||
protected $_bodies = array();
|
||||
|
||||
/**
|
||||
* Array of Zend_Amf_Value_MessageHeader objects
|
||||
* @var array
|
||||
*/
|
||||
protected $_headers = array();
|
||||
|
||||
/**
|
||||
* @var Zend_Amf_Parse_OutputStream
|
||||
*/
|
||||
protected $_outputStream;
|
||||
|
||||
/**
|
||||
* Instantiate new output stream and start serialization
|
||||
*
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function finalize()
|
||||
{
|
||||
$this->_outputStream = new Zend_Amf_Parse_OutputStream();
|
||||
$this->writeMessage($this->_outputStream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the PHP data types back into Actionscript and
|
||||
* create and AMF stream.
|
||||
*
|
||||
* @param Zend_Amf_Parse_OutputStream $stream
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function writeMessage(Zend_Amf_Parse_OutputStream $stream)
|
||||
{
|
||||
$objectEncoding = $this->_objectEncoding;
|
||||
|
||||
//Write encoding to start of stream. Preamble byte is written of two byte Unsigned Short
|
||||
$stream->writeByte(0x00);
|
||||
$stream->writeByte($objectEncoding);
|
||||
|
||||
// Loop through the AMF Headers that need to be returned.
|
||||
$headerCount = count($this->_headers);
|
||||
$stream->writeInt($headerCount);
|
||||
foreach ($this->getAmfHeaders() as $header) {
|
||||
$serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
|
||||
$stream->writeUTF($header->name);
|
||||
$stream->writeByte($header->mustRead);
|
||||
$stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
|
||||
if (is_object($header->data)) {
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about
|
||||
// "Only variables should be passed by reference"
|
||||
$placeholder = null;
|
||||
$serializer->writeTypeMarker($placeholder, null, $header->data);
|
||||
} else {
|
||||
$serializer->writeTypeMarker($header->data);
|
||||
}
|
||||
}
|
||||
|
||||
// loop through the AMF bodies that need to be returned.
|
||||
$bodyCount = count($this->_bodies);
|
||||
$stream->writeInt($bodyCount);
|
||||
foreach ($this->_bodies as $body) {
|
||||
$serializer = new Zend_Amf_Parse_Amf0_Serializer($stream);
|
||||
$stream->writeUTF($body->getTargetURI());
|
||||
$stream->writeUTF($body->getResponseURI());
|
||||
$stream->writeLong(Zend_Amf_Constants::UNKNOWN_CONTENT_LENGTH);
|
||||
$bodyData = $body->getData();
|
||||
$markerType = ($this->_objectEncoding == Zend_Amf_Constants::AMF0_OBJECT_ENCODING) ? null : Zend_Amf_Constants::AMF0_AMF3;
|
||||
if (is_object($bodyData)) {
|
||||
// Workaround for PHP5 with E_STRICT enabled complaining about
|
||||
// "Only variables should be passed by reference"
|
||||
$placeholder = null;
|
||||
$serializer->writeTypeMarker($placeholder, $markerType, $bodyData);
|
||||
} else {
|
||||
$serializer->writeTypeMarker($bodyData, $markerType);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the output stream content
|
||||
*
|
||||
* @return string The contents of the output stream
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
return $this->_outputStream->getStream();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the output stream content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getResponse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an AMF body to be sent to the Flash Player
|
||||
*
|
||||
* @param Zend_Amf_Value_MessageBody $body
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function addAmfBody(Zend_Amf_Value_MessageBody $body)
|
||||
{
|
||||
$this->_bodies[] = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of AMF bodies to be serialized
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAmfBodies()
|
||||
{
|
||||
return $this->_bodies;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an AMF Header to be sent back to the flash player
|
||||
*
|
||||
* @param Zend_Amf_Value_MessageHeader $header
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function addAmfHeader(Zend_Amf_Value_MessageHeader $header)
|
||||
{
|
||||
$this->_headers[] = $header;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve attached AMF message headers
|
||||
*
|
||||
* @return array Array of Zend_Amf_Value_MessageHeader objects
|
||||
*/
|
||||
public function getAmfHeaders()
|
||||
{
|
||||
return $this->_headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the AMF encoding that will be used for serialization
|
||||
*
|
||||
* @param int $encoding
|
||||
* @return Zend_Amf_Response
|
||||
*/
|
||||
public function setObjectEncoding($encoding)
|
||||
{
|
||||
$this->_objectEncoding = $encoding;
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Response */
|
||||
require_once 'Zend/Amf/Response.php';
|
||||
|
||||
/**
|
||||
* Creates the proper http headers and send the serialized AMF stream to standard out.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Response
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Response_Http extends Zend_Amf_Response
|
||||
{
|
||||
/**
|
||||
* Create the application response header for AMF and sends the serialized AMF string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponse()
|
||||
{
|
||||
if (!headers_sent()) {
|
||||
if ($this->isIeOverSsl()) {
|
||||
header('Cache-Control: cache, must-revalidate');
|
||||
header('Pragma: public');
|
||||
} else {
|
||||
header('Cache-Control: no-cache, must-revalidate');
|
||||
header('Pragma: no-cache');
|
||||
}
|
||||
header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
|
||||
header('Content-Type: application/x-amf');
|
||||
}
|
||||
return parent::getResponse();
|
||||
}
|
||||
|
||||
protected function isIeOverSsl()
|
||||
{
|
||||
$ssl = isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : false;
|
||||
if (!$ssl || ($ssl == 'off')) {
|
||||
// IIS reports "off", whereas other browsers simply don't populate
|
||||
return false;
|
||||
}
|
||||
|
||||
$ua = $_SERVER['HTTP_USER_AGENT'];
|
||||
if (!preg_match('/; MSIE \d+\.\d+;/', $ua)) {
|
||||
// Not MicroSoft Internet Explorer
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,37 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Server
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Exception */
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
|
||||
/**
|
||||
* Zend_Amf_Server_Exception
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Amf
|
||||
* @subpackage Server
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Server_Exception extends Zend_Amf_Exception
|
||||
{
|
||||
}
|
@ -1,297 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Util
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class to walk through a data stream byte by byte with conventional names
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Util
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Util_BinaryStream
|
||||
{
|
||||
/**
|
||||
* @var string Byte stream
|
||||
*/
|
||||
protected $_stream;
|
||||
|
||||
/**
|
||||
* @var int Length of stream
|
||||
*/
|
||||
protected $_streamLength;
|
||||
|
||||
/**
|
||||
* @var bool BigEndian encoding?
|
||||
*/
|
||||
protected $_bigEndian;
|
||||
|
||||
/**
|
||||
* @var int Current position in stream
|
||||
*/
|
||||
protected $_needle;
|
||||
|
||||
/**
|
||||
* @var bool str* functions overloaded using mbstring.func_overload?
|
||||
*/
|
||||
protected $_mbStringFunctionsOverloaded;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Create a reference to a byte stream that is going to be parsed or created
|
||||
* by the methods in the class. Detect if the class should use big or
|
||||
* little Endian encoding.
|
||||
*
|
||||
* @param string $stream use '' if creating a new stream or pass a string if reading.
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($stream)
|
||||
{
|
||||
if (!is_string($stream)) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Inputdata is not of type String');
|
||||
}
|
||||
|
||||
$this->_stream = $stream;
|
||||
$this->_needle = 0;
|
||||
$this->_mbStringFunctionsOverloaded = function_exists('mb_strlen') && (ini_get('mbstring.func_overload') !== '') && ((int)ini_get('mbstring.func_overload') & 2);
|
||||
$this->_streamLength = $this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream);
|
||||
$this->_bigEndian = (pack('l', 1) === "\x00\x00\x00\x01");
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current stream
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getStream()
|
||||
{
|
||||
return $this->_stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the number of bytes in a row for the length supplied.
|
||||
*
|
||||
* @todo Should check that there are enough bytes left in the stream we are about to read.
|
||||
* @param int $length
|
||||
* @return string
|
||||
* @throws Zend_Amf_Exception for buffer underrun
|
||||
*/
|
||||
public function readBytes($length)
|
||||
{
|
||||
if (($length + $this->_needle) > $this->_streamLength) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception('Buffer underrun at needle position: ' . $this->_needle . ' while requesting length: ' . $length);
|
||||
}
|
||||
$bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, $length, '8bit') : substr($this->_stream, $this->_needle, $length);
|
||||
$this->_needle+= $length;
|
||||
return $bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write any length of bytes to the stream
|
||||
*
|
||||
* Usually a string.
|
||||
*
|
||||
* @param string $bytes
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeBytes($bytes)
|
||||
{
|
||||
$this->_stream.= $bytes;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed byte
|
||||
*
|
||||
* @return int Value is in the range of -128 to 127.
|
||||
* @throws Zend_Amf_Exception
|
||||
*/
|
||||
public function readByte()
|
||||
{
|
||||
if (($this->_needle + 1) > $this->_streamLength) {
|
||||
require_once 'Zend/Amf/Exception.php';
|
||||
throw new Zend_Amf_Exception(
|
||||
'Buffer underrun at needle position: '
|
||||
. $this->_needle
|
||||
. ' while requesting length: '
|
||||
. $this->_streamLength
|
||||
);
|
||||
}
|
||||
|
||||
return ord($this->_stream{$this->_needle++});
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the passed string into a signed byte on the stream.
|
||||
*
|
||||
* @param string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeByte($stream)
|
||||
{
|
||||
$this->_stream.= pack('c', $stream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a signed 32-bit integer from the data stream.
|
||||
*
|
||||
* @return int Value is in the range of -2147483648 to 2147483647
|
||||
*/
|
||||
public function readInt()
|
||||
{
|
||||
return ($this->readByte() << 8) + $this->readByte();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an the integer to the output stream as a 32 bit signed integer
|
||||
*
|
||||
* @param int $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeInt($stream)
|
||||
{
|
||||
$this->_stream.= pack('n', $stream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a UTF-8 string from the data stream
|
||||
*
|
||||
* @return string A UTF-8 string produced by the byte representation of characters
|
||||
*/
|
||||
public function readUtf()
|
||||
{
|
||||
$length = $this->readInt();
|
||||
return $this->readBytes($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wite a UTF-8 string to the outputstream
|
||||
*
|
||||
* @param string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeUtf($stream)
|
||||
{
|
||||
$this->writeInt($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
|
||||
$this->_stream.= $stream;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a long UTF string
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function readLongUtf()
|
||||
{
|
||||
$length = $this->readLong();
|
||||
return $this->readBytes($length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a long UTF string to the buffer
|
||||
*
|
||||
* @param string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeLongUtf($stream)
|
||||
{
|
||||
$this->writeLong($this->_mbStringFunctionsOverloaded ? mb_strlen($stream, '8bit') : strlen($stream));
|
||||
$this->_stream.= $stream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a long numeric value
|
||||
*
|
||||
* @return double
|
||||
*/
|
||||
public function readLong()
|
||||
{
|
||||
return ($this->readByte() << 24) + ($this->readByte() << 16) + ($this->readByte() << 8) + $this->readByte();
|
||||
}
|
||||
|
||||
/**
|
||||
* Write long numeric value to output stream
|
||||
*
|
||||
* @param int|string $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeLong($stream)
|
||||
{
|
||||
$this->_stream.= pack('N', $stream);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a 16 bit unsigned short.
|
||||
*
|
||||
* @todo This could use the unpack() w/ S,n, or v
|
||||
* @return double
|
||||
*/
|
||||
public function readUnsignedShort()
|
||||
{
|
||||
$byte1 = $this->readByte();
|
||||
$byte2 = $this->readByte();
|
||||
return (($byte1 << 8) | $byte2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads an IEEE 754 double-precision floating point number from the data stream.
|
||||
*
|
||||
* @return double Floating point number
|
||||
*/
|
||||
public function readDouble()
|
||||
{
|
||||
$bytes = $this->_mbStringFunctionsOverloaded ? mb_substr($this->_stream, $this->_needle, 8, '8bit') : substr($this->_stream, $this->_needle, 8);
|
||||
$this->_needle+= 8;
|
||||
|
||||
if (!$this->_bigEndian) {
|
||||
$bytes = strrev($bytes);
|
||||
}
|
||||
|
||||
$double = unpack('dflt', $bytes);
|
||||
return $double['flt'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes an IEEE 754 double-precision floating point number from the data stream.
|
||||
*
|
||||
* @param string|double $stream
|
||||
* @return Zend_Amf_Util_BinaryStream
|
||||
*/
|
||||
public function writeDouble($stream)
|
||||
{
|
||||
$stream = pack('d', $stream);
|
||||
if (!$this->_bigEndian) {
|
||||
$stream = strrev($stream);
|
||||
}
|
||||
$this->_stream.= $stream;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Wrapper class to store an AMF3 flash.utils.ByteArray
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_ByteArray
|
||||
{
|
||||
/**
|
||||
* @var string ByteString Data
|
||||
*/
|
||||
protected $_data = '';
|
||||
|
||||
/**
|
||||
* Create a ByteArray
|
||||
*
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the byte stream
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
}
|
@ -1,182 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* An AMF Message contains information about the actual individual
|
||||
* transaction that is to be performed. It specifies the remote
|
||||
* operation that is to be performed; a local (client) operation
|
||||
* to be invoked upon success; and, the data to be used in the
|
||||
* operation.
|
||||
* <p/>
|
||||
* This Message structure defines how a local client would
|
||||
* invoke a method/operation on a remote server. Additionally,
|
||||
* the response from the Server is structured identically.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_MessageBody
|
||||
{
|
||||
/**
|
||||
* A string describing which operation, function, or method
|
||||
* is to be remotley invoked.
|
||||
* @var string
|
||||
*/
|
||||
protected $_targetUri = "";
|
||||
|
||||
/**
|
||||
* Universal Resource Identifier that uniquely targets the originator's
|
||||
* Object that should receive the server's response. The server will
|
||||
* use this path specification to target the "OnResult()" or "onStatus()"
|
||||
* handlers within the client. For Flash, it specifies an ActionScript
|
||||
* Object path only. The NetResponse object pointed to by the Response Uri
|
||||
* contains the connection state information. Passing/specifying this
|
||||
* provides a convenient mechanism for the client/server to share access
|
||||
* to an object that is managing the state of the shared connection.
|
||||
*
|
||||
* Since the server will use this field in the event of an error,
|
||||
* this field is required even if a successful server request would
|
||||
* not be expected to return a value to the client.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_responseUri = "";
|
||||
|
||||
/**
|
||||
* Contains the actual data associated with the operation. It contains
|
||||
* the client's parameter data that is passed to the server's operation/method.
|
||||
* When serializing a root level data type or a parameter list array, no
|
||||
* name field is included. That is, the data is anonomously represented
|
||||
* as "Type Marker"/"Value" pairs. When serializing member data, the data is
|
||||
* represented as a series of "Name"/"Type"/"Value" combinations.
|
||||
*
|
||||
* For server generated responses, it may contain any ActionScript
|
||||
* data/objects that the server was expected to provide.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $_data;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $targetUri
|
||||
* @param string $responseUri
|
||||
* @param string $data
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($targetUri, $responseUri, $data)
|
||||
{
|
||||
$this->setTargetUri($targetUri);
|
||||
$this->setResponseUri($responseUri);
|
||||
$this->setData($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve target Uri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTargetUri()
|
||||
{
|
||||
return $this->_targetUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set target Uri
|
||||
*
|
||||
* @param string $targetUri
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setTargetUri($targetUri)
|
||||
{
|
||||
if (null === $targetUri) {
|
||||
$targetUri = '';
|
||||
}
|
||||
$this->_targetUri = (string) $targetUri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get target Uri
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getResponseUri()
|
||||
{
|
||||
return $this->_responseUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response Uri
|
||||
*
|
||||
* @param string $responseUri
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setResponseUri($responseUri)
|
||||
{
|
||||
if (null === $responseUri) {
|
||||
$responseUri = '';
|
||||
}
|
||||
$this->_responseUri = $responseUri;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve response data
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getData()
|
||||
{
|
||||
return $this->_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set response data
|
||||
*
|
||||
* @param mixed $data
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setData($data)
|
||||
{
|
||||
$this->_data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set reply method
|
||||
*
|
||||
* @param string $methodName
|
||||
* @return Zend_Amf_Value_MessageBody
|
||||
*/
|
||||
public function setReplyMethod($methodName)
|
||||
{
|
||||
if (!preg_match('#^[/?]#', $methodName)) {
|
||||
$this->_targetUri = rtrim($this->_targetUri, '/') . '/';
|
||||
}
|
||||
$this->_targetUri = $this->_targetUri . $methodName;
|
||||
return $this;
|
||||
}
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message Headers provide context for the processing of the
|
||||
* the AMF Packet and all subsequent Messages.
|
||||
*
|
||||
* Multiple Message Headers may be included within an AMF Packet.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_MessageHeader
|
||||
{
|
||||
/**
|
||||
* Name of the header
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* Flag if the data has to be parsed on return
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
public $mustRead;
|
||||
|
||||
/**
|
||||
* Length of the data field
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $length;
|
||||
|
||||
/**
|
||||
* Data sent with the header name
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* Used to create and store AMF Header data.
|
||||
*
|
||||
* @param String $name
|
||||
* @param Boolean $mustRead
|
||||
* @param misc $content
|
||||
* @param integer $length
|
||||
*/
|
||||
public function __construct($name, $mustRead, $data, $length=null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->mustRead = (bool) $mustRead;
|
||||
$this->data = $data;
|
||||
if (null !== $length) {
|
||||
$this->length = (int) $length;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* This is the default Implementation of Message, which provides
|
||||
* a convenient base for behavior and association of common endpoints
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_AbstractMessage
|
||||
{
|
||||
/**
|
||||
* @var string Client identifier
|
||||
*/
|
||||
public $clientId;
|
||||
|
||||
/**
|
||||
* @var string Destination
|
||||
*/
|
||||
public $destination;
|
||||
|
||||
/**
|
||||
* @var string Message identifier
|
||||
*/
|
||||
public $messageId;
|
||||
|
||||
/**
|
||||
* @var int Message timestamp
|
||||
*/
|
||||
public $timestamp;
|
||||
|
||||
/**
|
||||
* @var int Message TTL
|
||||
*/
|
||||
public $timeToLive;
|
||||
|
||||
/**
|
||||
* @var object Message headers
|
||||
*/
|
||||
public $headers;
|
||||
|
||||
/**
|
||||
* @var string Message body
|
||||
*/
|
||||
public $body;
|
||||
|
||||
/**
|
||||
* generate a unique id
|
||||
*
|
||||
* Format is: ########-####-####-####-############
|
||||
* Where # is an uppercase letter or number
|
||||
* example: 6D9DC7EC-A273-83A9-ABE3-00005FD752D6
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateId()
|
||||
{
|
||||
return sprintf(
|
||||
'%08X-%04X-%04X-%02X%02X-%012X',
|
||||
mt_rand(),
|
||||
mt_rand(0, 65535),
|
||||
bindec(substr_replace(
|
||||
sprintf('%016b', mt_rand(0, 65535)), '0100', 11, 4)
|
||||
),
|
||||
bindec(substr_replace(sprintf('%08b', mt_rand(0, 255)), '01', 5, 2)),
|
||||
mt_rand(0, 255),
|
||||
mt_rand()
|
||||
);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Value_Messaging_AsyncMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
|
||||
|
||||
/**
|
||||
* This is the type of message returned by the MessageBroker
|
||||
* to endpoints after the broker has routed an endpoint's message
|
||||
* to a service.
|
||||
*
|
||||
* flex.messaging.messages.AcknowledgeMessage
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_AcknowledgeMessage extends Zend_Amf_Value_Messaging_AsyncMessage
|
||||
{
|
||||
/**
|
||||
* Create a new Acknowledge Message
|
||||
*
|
||||
* @param unknown_type $message
|
||||
*/
|
||||
public function __construct($message)
|
||||
{
|
||||
$this->clientId = $this->generateId();
|
||||
$this->destination = null;
|
||||
$this->messageId = $this->generateId();
|
||||
$this->timestamp = time().'00';
|
||||
$this->timeToLive = 0;
|
||||
$this->headers = new STDClass();
|
||||
$this->body = null;
|
||||
|
||||
// correleate the two messages
|
||||
if ($message && isset($message->messageId)) {
|
||||
$this->correlationId = $message->messageId;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Type encapsulating Flex ArrayCollection
|
||||
*
|
||||
* Corresponds to flex.messaging.io.ArrayCollection
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_ArrayCollection extends ArrayObject
|
||||
{
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
|
||||
/** Zend_Amf_Value_Messaging_AbstractMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AbstractMessage.php';
|
||||
|
||||
/**
|
||||
* This type of message contains information necessary to perform
|
||||
* point-to-point or publish-subscribe messaging.
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_AsyncMessage extends Zend_Amf_Value_Messaging_AbstractMessage
|
||||
{
|
||||
/**
|
||||
* The message id to be responded to.
|
||||
* @var String
|
||||
*/
|
||||
public $correlationId;
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Amf_Value_Messaging_AsyncMessage
|
||||
*/
|
||||
require_once 'Zend/Amf/Value/Messaging/AsyncMessage.php';
|
||||
|
||||
/**
|
||||
* A message that represents an infrastructure command passed between
|
||||
* client and server. Subscribe/unsubscribe operations result in
|
||||
* CommandMessage transmissions, as do polling operations.
|
||||
*
|
||||
* Corresponds to flex.messaging.messages.CommandMessage
|
||||
*
|
||||
* Note: THESE VALUES MUST BE THE SAME ON CLIENT AND SERVER
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_CommandMessage extends Zend_Amf_Value_Messaging_AsyncMessage
|
||||
{
|
||||
/**
|
||||
* This operation is used to subscribe to a remote destination.
|
||||
*/
|
||||
const SUBSCRIBE_OPERATION = 0;
|
||||
|
||||
/**
|
||||
* This operation is used to unsubscribe from a remote destination.
|
||||
*/
|
||||
const UNSUSBSCRIBE_OPERATION = 1;
|
||||
|
||||
/**
|
||||
* This operation is used to poll a remote destination for pending,
|
||||
* undelivered messages.
|
||||
*/
|
||||
const POLL_OPERATION = 2;
|
||||
|
||||
/**
|
||||
* This operation is used by a remote destination to sync missed or cached messages
|
||||
* back to a client as a result of a client issued poll command.
|
||||
*/
|
||||
const CLIENT_SYNC_OPERATION = 4;
|
||||
|
||||
/**
|
||||
* This operation is used to test connectivity over the current channel to
|
||||
* the remote endpoint.
|
||||
*/
|
||||
const CLIENT_PING_OPERATION = 5;
|
||||
|
||||
/**
|
||||
* This operation is used to request a list of failover endpoint URIs
|
||||
* for the remote destination based on cluster membership.
|
||||
*/
|
||||
const CLUSTER_REQUEST_OPERATION = 7;
|
||||
|
||||
/**
|
||||
* This operation is used to send credentials to the endpoint so that
|
||||
* the user can be logged in over the current channel.
|
||||
* The credentials need to be Base64 encoded and stored in the <code>body</code>
|
||||
* of the message.
|
||||
*/
|
||||
const LOGIN_OPERATION = 8;
|
||||
|
||||
/**
|
||||
* This operation is used to log the user out of the current channel, and
|
||||
* will invalidate the server session if the channel is HTTP based.
|
||||
*/
|
||||
const LOGOUT_OPERATION = 9;
|
||||
|
||||
/**
|
||||
* This operation is used to indicate that the client's subscription to a
|
||||
* remote destination has been invalidated.
|
||||
*/
|
||||
const SESSION_INVALIDATE_OPERATION = 10;
|
||||
|
||||
/**
|
||||
* This operation is used by the MultiTopicConsumer to subscribe/unsubscribe
|
||||
* from multiple subtopics/selectors in the same message.
|
||||
*/
|
||||
const MULTI_SUBSCRIBE_OPERATION = 11;
|
||||
|
||||
/**
|
||||
* This operation is used to indicate that a channel has disconnected
|
||||
*/
|
||||
const DISCONNECT_OPERATION = 12;
|
||||
|
||||
/**
|
||||
* This is the default operation for new CommandMessage instances.
|
||||
*/
|
||||
const UNKNOWN_OPERATION = 10000;
|
||||
|
||||
/**
|
||||
* The operation to execute for messages of this type
|
||||
* @var int
|
||||
*/
|
||||
public $operation = self::UNKNOWN_OPERATION;
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Amf_Value_Messaging_AcknowledgeMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php';
|
||||
|
||||
/**
|
||||
* Creates the error message to report to flex the issue with the call
|
||||
*
|
||||
* Corresponds to flex.messaging.messages.ErrorMessage
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_ErrorMessage extends Zend_Amf_Value_Messaging_AcknowledgeMessage
|
||||
{
|
||||
/**
|
||||
* Additional data with error
|
||||
* @var object
|
||||
*/
|
||||
public $extendedData = null;
|
||||
|
||||
/**
|
||||
* Error code number
|
||||
* @var string
|
||||
*/
|
||||
public $faultCode;
|
||||
|
||||
/**
|
||||
* Description as to the cause of the error
|
||||
* @var string
|
||||
*/
|
||||
public $faultDetail;
|
||||
|
||||
/**
|
||||
* Short description of error
|
||||
* @var string
|
||||
*/
|
||||
public $faultString = '';
|
||||
|
||||
/**
|
||||
* root cause of error
|
||||
* @var object
|
||||
*/
|
||||
public $rootCause = null;
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** Zend_Amf_Value_Messaging_AbstractMessage */
|
||||
require_once 'Zend/Amf/Value/Messaging/AbstractMessage.php';
|
||||
|
||||
/**
|
||||
* This type of message contains information needed to perform
|
||||
* a Remoting invocation.
|
||||
*
|
||||
* Corresponds to flex.messaging.messages.RemotingMessage
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_Messaging_RemotingMessage extends Zend_Amf_Value_Messaging_AbstractMessage
|
||||
{
|
||||
|
||||
/**
|
||||
* The name of the service to be called including package name
|
||||
* @var String
|
||||
*/
|
||||
public $source;
|
||||
|
||||
/**
|
||||
* The name of the method to be called
|
||||
* @var string
|
||||
*/
|
||||
public $operation;
|
||||
|
||||
/**
|
||||
* The arguments to call the mathod with
|
||||
* @var array
|
||||
*/
|
||||
public $parameters;
|
||||
|
||||
/**
|
||||
* Create a new Remoting Message
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->clientId = $this->generateId();
|
||||
$this->destination = null;
|
||||
$this->messageId = $this->generateId();
|
||||
$this->timestamp = time().'00';
|
||||
$this->timeToLive = 0;
|
||||
$this->headers = new stdClass();
|
||||
$this->body = null;
|
||||
}
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
<?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_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Zend_Amf_Value_TraitsInfo
|
||||
*
|
||||
* @package Zend_Amf
|
||||
* @subpackage Value
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Amf_Value_TraitsInfo
|
||||
{
|
||||
/**
|
||||
* @var string Class name
|
||||
*/
|
||||
protected $_className;
|
||||
|
||||
/**
|
||||
* @var bool Whether or not this is a dynamic class
|
||||
*/
|
||||
protected $_dynamic;
|
||||
|
||||
/**
|
||||
* @var bool Whether or not the class is externalizable
|
||||
*/
|
||||
protected $_externalizable;
|
||||
|
||||
/**
|
||||
* @var array Class properties
|
||||
*/
|
||||
protected $_properties;
|
||||
|
||||
/**
|
||||
* Used to keep track of all class traits of an AMF3 object
|
||||
*
|
||||
* @param string $className
|
||||
* @param boolean $dynamic
|
||||
* @param boolean $externalizable
|
||||
* @param boolean $properties
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($className, $dynamic=false, $externalizable=false, $properties=null)
|
||||
{
|
||||
$this->_className = $className;
|
||||
$this->_dynamic = $dynamic;
|
||||
$this->_externalizable = $externalizable;
|
||||
$this->_properties = $properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the class is a dynamic class
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isDynamic()
|
||||
{
|
||||
return $this->_dynamic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if class is externalizable
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function isExternalizable()
|
||||
{
|
||||
return $this->_externalizable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of properties in the class
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function length()
|
||||
{
|
||||
return count($this->_properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the class name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->_className;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an additional property
|
||||
*
|
||||
* @param string $name
|
||||
* @return Zend_Amf_Value_TraitsInfo
|
||||
*/
|
||||
public function addProperty($name)
|
||||
{
|
||||
$this->_properties[] = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add all properties of the class.
|
||||
*
|
||||
* @param array $props
|
||||
* @return Zend_Amf_Value_TraitsInfo
|
||||
*/
|
||||
public function addAllProperties(array $props)
|
||||
{
|
||||
$this->_properties = $props;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the property at a given index
|
||||
*
|
||||
* @param int $index
|
||||
* @return string
|
||||
*/
|
||||
public function getProperty($index)
|
||||
{
|
||||
return $this->_properties[(int) $index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all properties of the class.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllProperties()
|
||||
{
|
||||
return $this->_properties;
|
||||
}
|
||||
}
|
@ -1,438 +0,0 @@
|
||||
<?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-2015 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-2015 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 = pathinfo($file, PATHINFO_EXTENSION);
|
||||
$suffix = ($suffix === 'dist')
|
||||
? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION)
|
||||
: $suffix;
|
||||
|
||||
switch (strtolower($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':
|
||||
case 'yml':
|
||||
$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();
|
||||
}
|
||||
}
|
@ -1,168 +0,0 @@
|
||||
<?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-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Bootstrap_BootstrapAbstract
|
||||
*/
|
||||
require_once 'Zend/Application/Bootstrap/BootstrapAbstract.php';
|
||||
|
||||
/**
|
||||
* 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-2015 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,784 +0,0 @@
|
||||
<?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-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Bootstrap_Bootstrapper
|
||||
*/
|
||||
require_once 'Zend/Application/Bootstrap/Bootstrapper.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Application_Bootstrap_ResourceBootstrapper
|
||||
*/
|
||||
require_once 'Zend/Application/Bootstrap/ResourceBootstrapper.php';
|
||||
|
||||
/**
|
||||
* 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-2015 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
|
||||
* @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 $resource
|
||||
* @return Zend_Application_Resource_Resource
|
||||
* @throws Zend_Application_Bootstrap_Exception
|
||||
*/
|
||||
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)
|
||||
&& is_subclass_of($plugin, 'Zend_Application_Resource_Resource')
|
||||
) { //@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
|
||||
* @throws Zend_Application_Bootstrap_Exception
|
||||
*/
|
||||
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
|
||||
* @throws Zend_Application_Bootstrap_Exception
|
||||
*/
|
||||
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 resource
|
||||
* 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 resource 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 Zend_Application_Bootstrap_BootstrapAbstract
|
||||
* @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;
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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();
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?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-2015 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-2015 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();
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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');
|
||||
}
|
||||
}
|
@ -1,127 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
<?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-2015 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-2015 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) {
|
||||
// Logger
|
||||
if (isset($value['frontend']['options']['logger'])) {
|
||||
$logger = $value['frontend']['options']['logger'];
|
||||
if (is_array($logger)) {
|
||||
$value['frontend']['options']['logger'] = Zend_Log::factory($logger);
|
||||
}
|
||||
}
|
||||
|
||||
// Cache templates
|
||||
if ($this->_manager->hasCacheTemplate($key)) {
|
||||
$this->_manager->setTemplateOptions($key, $value);
|
||||
} else {
|
||||
$this->_manager->setCacheTemplate($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_manager;
|
||||
}
|
||||
}
|
@ -1,198 +0,0 @@
|
||||
<?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-2015 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-2015 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_Abstract
|
||||
*/
|
||||
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 array $params
|
||||
* @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 bool $isDefaultTableAdapter
|
||||
* @return Zend_Application_Resource_Db
|
||||
*/
|
||||
public function setIsDefaultTableAdapter($isDefaultTableAdapter)
|
||||
{
|
||||
$this->_isDefaultTableAdapter = $isDefaultTableAdapter;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this adapter the default table adapter?
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isDefaultTableAdapter()
|
||||
{
|
||||
return $this->_isDefaultTableAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve initialized DB connection
|
||||
*
|
||||
* @return null|Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
public function getDbAdapter()
|
||||
{
|
||||
if ((null === $this->_db)
|
||||
&& (null !== ($adapter = $this->getAdapter()))
|
||||
) {
|
||||
$this->_db = Zend_Db::factory($adapter, $this->getParams());
|
||||
|
||||
if ($this->_db instanceof Zend_Db_Adapter_Abstract
|
||||
&& $this->isDefaultTableAdapter()
|
||||
) {
|
||||
Zend_Db_Table::setDefaultAdapter($this->_db);
|
||||
}
|
||||
}
|
||||
return $this->_db;
|
||||
}
|
||||
|
||||
/**
|
||||
* Defined by Zend_Application_Resource_Resource
|
||||
*
|
||||
* @return Zend_Db_Adapter_Abstract|null
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
if (null !== ($db = $this->getDbAdapter())) {
|
||||
return $db;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{
|
||||
}
|
@ -1,179 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
* @throws Zend_Application_Exception
|
||||
*/
|
||||
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;
|
||||
|
||||
case 'dispatcher':
|
||||
if (!isset($value['class'])) {
|
||||
require_once 'Zend/Application/Exception.php';
|
||||
throw new Zend_Application_Exception('You must specify both ');
|
||||
}
|
||||
if (!isset($value['params'])) {
|
||||
$value['params'] = array();
|
||||
}
|
||||
|
||||
$dispatchClass = $value['class'];
|
||||
if (!class_exists($dispatchClass)) {
|
||||
require_once 'Zend/Application/Exception.php';
|
||||
throw new Zend_Application_Exception('Dispatcher class not found!');
|
||||
}
|
||||
$front->setDispatcher(new $dispatchClass((array)$value['params']));
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
<?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-2015 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 logger
|
||||
*
|
||||
* @uses Zend_Application_Resource_ResourceAbstract
|
||||
* @category Zend
|
||||
* @package Zend_Application
|
||||
* @subpackage Resource
|
||||
* @copyright Copyright (c) 2005-2015 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve logger object
|
||||
*
|
||||
* @return Zend_Log
|
||||
*/
|
||||
public function getLog()
|
||||
{
|
||||
if (null === $this->_log) {
|
||||
$options = $this->getOptions();
|
||||
$log = Zend_Log::factory($options);
|
||||
$this->setLog($log);
|
||||
}
|
||||
return $this->_log;
|
||||
}
|
||||
}
|
@ -1,151 +0,0 @@
|
||||
<?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-2015 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-2015 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']);
|
||||
unset($options['register']); //@see ZF-11022
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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()
|
||||
{
|
||||
$bootstraps = array();
|
||||
$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;
|
||||
}
|
||||
|
||||
$bootstraps[$module] = $bootstrapClass;
|
||||
}
|
||||
|
||||
return $this->_bootstraps = $this->bootstrapBootstraps($bootstraps);
|
||||
}
|
||||
|
||||
/*
|
||||
* Bootstraps the bootstraps found. Allows for easy extension.
|
||||
* @param array $bootstraps Array containing the bootstraps to instantiate
|
||||
*/
|
||||
protected function bootstrapBootstraps($bootstraps)
|
||||
{
|
||||
$bootstrap = $this->getBootstrap();
|
||||
$out = new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
|
||||
|
||||
foreach ($bootstraps as $module => $bootstrapClass) {
|
||||
$moduleBootstrap = new $bootstrapClass($bootstrap);
|
||||
$moduleBootstrap->bootstrap();
|
||||
$out[$module] = $moduleBootstrap;
|
||||
}
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
@ -1,210 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
<?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-2015 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-2015 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();
|
||||
|
||||
if (isset($options['defaultPageType'])) {
|
||||
Zend_Navigation_Page::setDefaultPageType(
|
||||
$options['defaultPageType']
|
||||
);
|
||||
}
|
||||
|
||||
$pages = isset($options['pages']) ? $options['pages'] : array();
|
||||
$this->_container = new Zend_Navigation($pages);
|
||||
}
|
||||
|
||||
$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();
|
||||
// see ZF-7461
|
||||
if (isset($options['storage']['registry']['key'])
|
||||
&& !is_numeric($options['storage']['registry']['key'])
|
||||
) {
|
||||
$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;
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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();
|
||||
}
|
@ -1,161 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
<?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-2015 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-2015 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 not a valid save handler
|
||||
*/
|
||||
public function setSaveHandler($saveHandler)
|
||||
{
|
||||
$this->_saveHandler = $saveHandler;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get session save handler
|
||||
*
|
||||
* @return Zend_Session_SaveHandler_Interface
|
||||
* @throws Zend_Application_Resource_Exception
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,142 +0,0 @@
|
||||
<?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-2015 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-2015 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['log'])) {
|
||||
if (is_array($options['log'])) {
|
||||
$options['log'] = Zend_Log::factory($options['log']);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
<?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-2015 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-2015 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 = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
|
||||
$viewRenderer->setView($view);
|
||||
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']);
|
||||
}
|
||||
if (isset($options['assign']) && is_array($options['assign'])) {
|
||||
$this->_view->assign($options['assign']);
|
||||
}
|
||||
}
|
||||
return $this->_view;
|
||||
}
|
||||
}
|
@ -1,169 +0,0 @@
|
||||
<?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-2015 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-2015 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();
|
||||
}
|
||||
}
|
@ -1,560 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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);
|
||||
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']
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{}
|
@ -1,868 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{}
|
@ -1,166 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
<?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-2015 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-2015 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);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
<?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-2015 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-2015 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();
|
||||
}
|
@ -1,531 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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[] = preg_replace(
|
||||
'/\b'.preg_quote(substr($password, 0, 15), '/').'\b/',
|
||||
'*****',
|
||||
$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;
|
||||
}
|
||||
}
|
@ -1,283 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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 $response
|
||||
* @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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{}
|
@ -1,147 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
{}
|
@ -1,66 +0,0 @@
|
||||
<?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-2015 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-2015 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();
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
<?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-2015 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-2015 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;
|
||||
}
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
<?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-2015 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-2015 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
|
||||
*/
|
||||
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});
|
||||
}
|
||||
}
|
@ -1,352 +0,0 @@
|
||||
<?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_Barcode
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class for generate Barcode
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Barcode
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Barcode
|
||||
{
|
||||
/**
|
||||
* Factory for Zend_Barcode classes.
|
||||
*
|
||||
* First argument may be a string containing the base of the adapter class
|
||||
* name, e.g. 'int25' corresponds to class Zend_Barcode_Object_Int25. This
|
||||
* is case-insensitive.
|
||||
*
|
||||
* First argument may alternatively be an object of type Zend_Config.
|
||||
* The barcode class base name is read from the 'barcode' property.
|
||||
* The barcode config parameters are read from the 'params' property.
|
||||
*
|
||||
* Second argument is optional and may be an associative array of key-value
|
||||
* pairs. This is used as the argument to the barcode constructor.
|
||||
*
|
||||
* If the first argument is of type Zend_Config, it is assumed to contain
|
||||
* all parameters, and the second argument is ignored.
|
||||
*
|
||||
* @param mixed $barcode String name of barcode class, or Zend_Config object.
|
||||
* @param mixed $renderer String name of renderer class
|
||||
* @param mixed $barcodeConfig OPTIONAL; an array or Zend_Config object with barcode parameters.
|
||||
* @param mixed $rendererConfig OPTIONAL; an array or Zend_Config object with renderer parameters.
|
||||
* @param boolean $automaticRenderError OPTIONAL; set the automatic rendering of exception
|
||||
* @return Zend_Barcode
|
||||
* @throws Zend_Barcode_Exception
|
||||
*/
|
||||
public static function factory(
|
||||
$barcode,
|
||||
$renderer = 'image',
|
||||
$barcodeConfig = array(),
|
||||
$rendererConfig = array(),
|
||||
$automaticRenderError = true
|
||||
) {
|
||||
/*
|
||||
* Convert Zend_Config argument to plain string
|
||||
* barcode name and separate config object.
|
||||
*/
|
||||
if ($barcode instanceof Zend_Config) {
|
||||
if (isset($barcode->rendererParams)) {
|
||||
$rendererConfig = $barcode->rendererParams->toArray();
|
||||
}
|
||||
if (isset($barcode->renderer)) {
|
||||
$renderer = (string) $barcode->renderer;
|
||||
}
|
||||
if (isset($barcode->barcodeParams)) {
|
||||
$barcodeConfig = $barcode->barcodeParams->toArray();
|
||||
}
|
||||
if (isset($barcode->barcode)) {
|
||||
$barcode = (string) $barcode->barcode;
|
||||
} else {
|
||||
$barcode = null;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$barcode = self::makeBarcode($barcode, $barcodeConfig);
|
||||
$renderer = self::makeRenderer($renderer, $rendererConfig);
|
||||
} catch (Zend_Exception $e) {
|
||||
$renderable = ($e instanceof Zend_Barcode_Exception) ? $e->isRenderable() : false;
|
||||
if ($automaticRenderError && $renderable) {
|
||||
$barcode = self::makeBarcode('error', array(
|
||||
'text' => $e->getMessage()
|
||||
));
|
||||
$renderer = self::makeRenderer($renderer, array());
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
$renderer->setAutomaticRenderError($automaticRenderError);
|
||||
return $renderer->setBarcode($barcode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Barcode Constructor
|
||||
*
|
||||
* @param mixed $barcode String name of barcode class, or Zend_Config object.
|
||||
* @param mixed $barcodeConfig OPTIONAL; an array or Zend_Config object with barcode parameters.
|
||||
* @return Zend_Barcode_Object
|
||||
*/
|
||||
public static function makeBarcode($barcode, $barcodeConfig = array())
|
||||
{
|
||||
if ($barcode instanceof Zend_Barcode_Object_ObjectAbstract) {
|
||||
return $barcode;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert Zend_Config argument to plain string
|
||||
* barcode name and separate config object.
|
||||
*/
|
||||
if ($barcode instanceof Zend_Config) {
|
||||
if (isset($barcode->barcodeParams) && $barcode->barcodeParams instanceof Zend_Config) {
|
||||
$barcodeConfig = $barcode->barcodeParams->toArray();
|
||||
}
|
||||
if (isset($barcode->barcode)) {
|
||||
$barcode = (string) $barcode->barcode;
|
||||
} else {
|
||||
$barcode = null;
|
||||
}
|
||||
}
|
||||
if ($barcodeConfig instanceof Zend_Config) {
|
||||
$barcodeConfig = $barcodeConfig->toArray();
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that barcode parameters are in an array.
|
||||
*/
|
||||
if (!is_array($barcodeConfig)) {
|
||||
/**
|
||||
* @see Zend_Barcode_Exception
|
||||
*/
|
||||
require_once 'Zend/Barcode/Exception.php';
|
||||
throw new Zend_Barcode_Exception(
|
||||
'Barcode parameters must be in an array or a Zend_Config object'
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that an barcode name has been specified.
|
||||
*/
|
||||
if (!is_string($barcode) || empty($barcode)) {
|
||||
/**
|
||||
* @see Zend_Barcode_Exception
|
||||
*/
|
||||
require_once 'Zend/Barcode/Exception.php';
|
||||
throw new Zend_Barcode_Exception(
|
||||
'Barcode name must be specified in a string'
|
||||
);
|
||||
}
|
||||
/*
|
||||
* Form full barcode class name
|
||||
*/
|
||||
$barcodeNamespace = 'Zend_Barcode_Object';
|
||||
if (isset($barcodeConfig['barcodeNamespace'])) {
|
||||
$barcodeNamespace = $barcodeConfig['barcodeNamespace'];
|
||||
}
|
||||
|
||||
$barcodeName = strtolower($barcodeNamespace . '_' . $barcode);
|
||||
$barcodeName = str_replace(' ', '_', ucwords(
|
||||
str_replace( '_', ' ', $barcodeName)
|
||||
));
|
||||
|
||||
/*
|
||||
* Load the barcode class. This throws an exception
|
||||
* if the specified class cannot be loaded.
|
||||
*/
|
||||
if (!class_exists($barcodeName)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($barcodeName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an instance of the barcode class.
|
||||
* Pass the config to the barcode class constructor.
|
||||
*/
|
||||
$bcAdapter = new $barcodeName($barcodeConfig);
|
||||
|
||||
/*
|
||||
* Verify that the object created is a descendent of the abstract barcode type.
|
||||
*/
|
||||
if (!$bcAdapter instanceof Zend_Barcode_Object_ObjectAbstract) {
|
||||
/**
|
||||
* @see Zend_Barcode_Exception
|
||||
*/
|
||||
require_once 'Zend/Barcode/Exception.php';
|
||||
throw new Zend_Barcode_Exception(
|
||||
"Barcode class '$barcodeName' does not extend Zend_Barcode_Object_ObjectAbstract"
|
||||
);
|
||||
}
|
||||
return $bcAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renderer Constructor
|
||||
*
|
||||
* @param mixed $renderer String name of renderer class, or Zend_Config object.
|
||||
* @param mixed $rendererConfig OPTIONAL; an array or Zend_Config object with renderer parameters.
|
||||
* @return Zend_Barcode_Renderer
|
||||
*/
|
||||
public static function makeRenderer($renderer = 'image', $rendererConfig = array())
|
||||
{
|
||||
if ($renderer instanceof Zend_Barcode_Renderer_RendererAbstract) {
|
||||
return $renderer;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert Zend_Config argument to plain string
|
||||
* barcode name and separate config object.
|
||||
*/
|
||||
if ($renderer instanceof Zend_Config) {
|
||||
if (isset($renderer->rendererParams)) {
|
||||
$rendererConfig = $renderer->rendererParams->toArray();
|
||||
}
|
||||
if (isset($renderer->renderer)) {
|
||||
$renderer = (string) $renderer->renderer;
|
||||
}
|
||||
}
|
||||
if ($rendererConfig instanceof Zend_Config) {
|
||||
$rendererConfig = $rendererConfig->toArray();
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that barcode parameters are in an array.
|
||||
*/
|
||||
if (!is_array($rendererConfig)) {
|
||||
/**
|
||||
* @see Zend_Barcode_Exception
|
||||
*/
|
||||
require_once 'Zend/Barcode/Exception.php';
|
||||
$e = new Zend_Barcode_Exception(
|
||||
'Barcode parameters must be in an array or a Zend_Config object'
|
||||
);
|
||||
$e->setIsRenderable(false);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that an barcode name has been specified.
|
||||
*/
|
||||
if (!is_string($renderer) || empty($renderer)) {
|
||||
/**
|
||||
* @see Zend_Barcode_Exception
|
||||
*/
|
||||
require_once 'Zend/Barcode/Exception.php';
|
||||
$e = new Zend_Barcode_Exception(
|
||||
'Renderer name must be specified in a string'
|
||||
);
|
||||
$e->setIsRenderable(false);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
/*
|
||||
* Form full barcode class name
|
||||
*/
|
||||
$rendererNamespace = 'Zend_Barcode_Renderer';
|
||||
if (isset($rendererConfig['rendererNamespace'])) {
|
||||
$rendererNamespace = $rendererConfig['rendererNamespace'];
|
||||
}
|
||||
|
||||
$rendererName = strtolower($rendererNamespace . '_' . $renderer);
|
||||
$rendererName = str_replace(' ', '_', ucwords(
|
||||
str_replace( '_', ' ', $rendererName)
|
||||
));
|
||||
|
||||
/*
|
||||
* Load the barcode class. This throws an exception
|
||||
* if the specified class cannot be loaded.
|
||||
*/
|
||||
if (!class_exists($rendererName)) {
|
||||
require_once 'Zend/Loader.php';
|
||||
Zend_Loader::loadClass($rendererName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an instance of the barcode class.
|
||||
* Pass the config to the barcode class constructor.
|
||||
*/
|
||||
$rdrAdapter = new $rendererName($rendererConfig);
|
||||
|
||||
/*
|
||||
* Verify that the object created is a descendent of the abstract barcode type.
|
||||
*/
|
||||
if (!$rdrAdapter instanceof Zend_Barcode_Renderer_RendererAbstract) {
|
||||
/**
|
||||
* @see Zend_Barcode_Exception
|
||||
*/
|
||||
require_once 'Zend/Barcode/Exception.php';
|
||||
$e = new Zend_Barcode_Exception(
|
||||
"Renderer class '$rendererName' does not extend Zend_Barcode_Renderer_RendererAbstract"
|
||||
);
|
||||
$e->setIsRenderable(false);
|
||||
throw $e;
|
||||
}
|
||||
return $rdrAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy to renderer render() method
|
||||
*
|
||||
* @param string | Zend_Barcode_Object | array | Zend_Config $barcode
|
||||
* @param string | Zend_Barcode_Renderer $renderer
|
||||
* @param array | Zend_Config $barcodeConfig
|
||||
* @param array | Zend_Config $rendererConfig
|
||||
*/
|
||||
public static function render(
|
||||
$barcode,
|
||||
$renderer,
|
||||
$barcodeConfig = array(),
|
||||
$rendererConfig = array()
|
||||
) {
|
||||
self::factory($barcode, $renderer, $barcodeConfig, $rendererConfig)->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy to renderer draw() method
|
||||
*
|
||||
* @param string | Zend_Barcode_Object | array | Zend_Config $barcode
|
||||
* @param string | Zend_Barcode_Renderer $renderer
|
||||
* @param array | Zend_Config $barcodeConfig
|
||||
* @param array | Zend_Config $rendererConfig
|
||||
* @return mixed
|
||||
*/
|
||||
public static function draw(
|
||||
$barcode,
|
||||
$renderer,
|
||||
$barcodeConfig = array(),
|
||||
$rendererConfig = array()
|
||||
) {
|
||||
return self::factory($barcode, $renderer, $barcodeConfig, $rendererConfig)->draw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Proxy for setBarcodeFont of Zend_Barcode_Object
|
||||
* @param string $font
|
||||
* @eturn void
|
||||
*/
|
||||
public static function setBarcodeFont($font)
|
||||
{
|
||||
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
|
||||
Zend_Barcode_Object_ObjectAbstract::setBarcodeFont($font);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Zend Framework
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This source file is subject to version 1.0 of the Zend Framework
|
||||
* license, that is bundled with this package in the file LICENSE.txt, and
|
||||
* is available through the world-wide-web at the following URL:
|
||||
* http://framework.zend.com/license/new-bsd. If you did not receive
|
||||
* a copy of the Zend Framework license and are unable to obtain it
|
||||
* through the world-wide-web, please send a note to license@zend.com
|
||||
* so we can mail you a copy immediately.
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Barcode
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
/**
|
||||
* Zend_Exception
|
||||
*/
|
||||
require_once 'Zend/Exception.php';
|
||||
|
||||
/**
|
||||
* Zend_Barcode_Exception
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Barcode
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Barcode_Exception extends Zend_Exception
|
||||
{
|
||||
/**
|
||||
* Is this exception renderable?
|
||||
* @var bool
|
||||
*/
|
||||
protected $_isRenderable = true;
|
||||
|
||||
/**
|
||||
* Set renderable flag
|
||||
*
|
||||
* @param bool $flag
|
||||
* @return Zend_Barcode_Exception
|
||||
*/
|
||||
public function setIsRenderable($flag)
|
||||
{
|
||||
$this->_isRenderable = (bool) $flag;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve renderable flag
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isRenderable()
|
||||
{
|
||||
return $this->_isRenderable;
|
||||
}
|
||||
}
|
@ -1,395 +0,0 @@
|
||||
<?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_Barcode
|
||||
* @subpackage Object
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id: Code25.php 20096 2010-01-06 02:05:09Z bkarwin $
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Barcode_Object_ObjectAbstract
|
||||
*/
|
||||
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Barcode
|
||||
*/
|
||||
require_once 'Zend/Validate/Barcode.php';
|
||||
|
||||
/**
|
||||
* Class for generate Code128 barcode
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Barcode
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Barcode_Object_Code128 extends Zend_Barcode_Object_ObjectAbstract
|
||||
{
|
||||
/**
|
||||
* Drawing of checksum
|
||||
* (even if it's sometime optional, most of time it's required)
|
||||
* @var boolean
|
||||
*/
|
||||
protected $_withChecksum = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $_convertedText = array();
|
||||
|
||||
protected $_codingMap = array(
|
||||
0 => "11011001100", 1 => "11001101100", 2 => "11001100110",
|
||||
3 => "10010011000", 4 => "10010001100", 5 => "10001001100",
|
||||
6 => "10011001000", 7 => "10011000100", 8 => "10001100100",
|
||||
9 => "11001001000", 10 => "11001000100", 11 => "11000100100",
|
||||
12 => "10110011100", 13 => "10011011100", 14 => "10011001110",
|
||||
15 => "10111001100", 16 => "10011101100", 17 => "10011100110",
|
||||
18 => "11001110010", 19 => "11001011100", 20 => "11001001110",
|
||||
21 => "11011100100", 22 => "11001110100", 23 => "11101101110",
|
||||
24 => "11101001100", 25 => "11100101100", 26 => "11100100110",
|
||||
27 => "11101100100", 28 => "11100110100", 29 => "11100110010",
|
||||
30 => "11011011000", 31 => "11011000110", 32 => "11000110110",
|
||||
33 => "10100011000", 34 => "10001011000", 35 => "10001000110",
|
||||
36 => "10110001000", 37 => "10001101000", 38 => "10001100010",
|
||||
39 => "11010001000", 40 => "11000101000", 41 => "11000100010",
|
||||
42 => "10110111000", 43 => "10110001110", 44 => "10001101110",
|
||||
45 => "10111011000", 46 => "10111000110", 47 => "10001110110",
|
||||
48 => "11101110110", 49 => "11010001110", 50 => "11000101110",
|
||||
51 => "11011101000", 52 => "11011100010", 53 => "11011101110",
|
||||
54 => "11101011000", 55 => "11101000110", 56 => "11100010110",
|
||||
57 => "11101101000", 58 => "11101100010", 59 => "11100011010",
|
||||
60 => "11101111010", 61 => "11001000010", 62 => "11110001010",
|
||||
63 => "10100110000", 64 => "10100001100", 65 => "10010110000",
|
||||
66 => "10010000110", 67 => "10000101100", 68 => "10000100110",
|
||||
69 => "10110010000", 70 => "10110000100", 71 => "10011010000",
|
||||
72 => "10011000010", 73 => "10000110100", 74 => "10000110010",
|
||||
75 => "11000010010", 76 => "11001010000", 77 => "11110111010",
|
||||
78 => "11000010100", 79 => "10001111010", 80 => "10100111100",
|
||||
81 => "10010111100", 82 => "10010011110", 83 => "10111100100",
|
||||
84 => "10011110100", 85 => "10011110010", 86 => "11110100100",
|
||||
87 => "11110010100", 88 => "11110010010", 89 => "11011011110",
|
||||
90 => "11011110110", 91 => "11110110110", 92 => "10101111000",
|
||||
93 => "10100011110", 94 => "10001011110", 95 => "10111101000",
|
||||
96 => "10111100010", 97 => "11110101000", 98 => "11110100010",
|
||||
99 => "10111011110", 100 => "10111101110", 101 => "11101011110",
|
||||
102 => "11110101110",
|
||||
103 => "11010000100", 104 => "11010010000", 105 => "11010011100",
|
||||
106 => "1100011101011");
|
||||
|
||||
/**
|
||||
* Character sets ABC
|
||||
* @var array
|
||||
*/
|
||||
protected $_charSets = array(
|
||||
'A' => array(
|
||||
' ', '!', '"', '#', '$', '%', '&', "'",
|
||||
'(', ')', '*', '+', ',', '-', '.', '/',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', ':', ';', '<', '=', '>', '?',
|
||||
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
|
||||
'FNC3', 'FNC2', 'SHIFT', 'Code C', 'Code B', 'FNC4', 'FNC1',
|
||||
'START A', 'START B', 'START C', 'STOP'),
|
||||
'B' => array(
|
||||
' ', '!', '"', '#', '$', '%', '&', "'",
|
||||
'(', ')', '*', '+', ',', '-', '.', '/',
|
||||
'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', ':', ';', '<', '=', '>', '?',
|
||||
'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
||||
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
|
||||
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', '[', '\\', ']', '^', '_',
|
||||
'`', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
|
||||
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o',
|
||||
'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
|
||||
'x', 'y', 'z', '{', '|', '}', '~', 0x7F,
|
||||
'FNC3', 'FNC2', 'SHIFT', 'Code C', 'FNC4', 'Code A', 'FNC1',
|
||||
'START A', 'START B', 'START C', 'STOP',),
|
||||
'C' => array(
|
||||
'00', '01', '02', '03', '04', '05', '06', '07', '08', '09',
|
||||
'10', '11', '12', '13', '14', '15', '16', '17', '18', '19',
|
||||
'20', '21', '22', '23', '24', '25', '26', '27', '28', '29',
|
||||
'30', '31', '32', '33', '34', '35', '36', '37', '38', '39',
|
||||
'40', '41', '42', '43', '44', '45', '46', '47', '48', '49',
|
||||
'50', '51', '52', '53', '54', '55', '56', '57', '58', '59',
|
||||
'60', '61', '62', '63', '64', '65', '66', '67', '68', '69',
|
||||
'70', '71', '72', '73', '74', '75', '76', '77', '78', '79',
|
||||
'80', '81', '82', '83', '84', '85', '86', '87', '88', '89',
|
||||
'90', '91', '92', '93', '94', '95', '96', '97', '98', '99',
|
||||
'Code B', 'Code A', 'FNC1', 'START A', 'START B', 'START C', 'STOP'));
|
||||
/*'A' => array(
|
||||
' '=>0, '!'=>1, '"'=>2, '#'=>3, '$'=>4, '%'=>5, '&'=>6, "'"=>7,
|
||||
'('=>8, ')'=>9, '*'=>10, '+'=>11, ','=>12, '-'=>13, '.'=>14, '/'=>15,
|
||||
'0'=>16, '1'=>17, '2'=>18, '3'=>19, '4'=>20, '5'=>21, '6'=>22, '7'=>23,
|
||||
'8'=>24, '9'=>25, ':'=>26, ';'=>27, '<'=>28, '='=>29, '>'=>30, '?'=>31,
|
||||
'@'=>32, 'A'=>33, 'B'=>34, 'C'=>35, 'D'=>36, 'E'=>37, 'F'=>38, 'G'=>39,
|
||||
'H'=>40, 'I'=>41, 'J'=>42, 'K'=>43, 'L'=>44, 'M'=>45, 'N'=>46, 'O'=>47,
|
||||
'P'=>48, 'Q'=>49, 'R'=>50, 'S'=>51, 'T'=>52, 'U'=>53, 'V'=>54, 'W'=>55,
|
||||
'X'=>56, 'Y'=>57, 'Z'=>58, '['=>59, '\\'=>60, ']'=>61, '^'=>62, '_'=>63,
|
||||
0x00=>64, 0x01=>65, 0x02=>66, 0x03=>67, 0x04=>68, 0x05=>69, 0x06=>70, 0x07=>71,
|
||||
0x08=>72, 0x09=>73, 0x0A=>74, 0x0B=>75, 0x0C=>76, 0x0D=>77, 0x0E=>78, 0x0F=>79,
|
||||
0x10=>80, 0x11=>81, 0x12=>82, 0x13=>83, 0x14=>84, 0x15=>85, 0x16=>86, 0x17=>87,
|
||||
0x18=>88, 0x19=>89, 0x1A=>90, 0x1B=>91, 0x1C=>92, 0x1D=>93, 0x1E=>94, 0x1F=>95,
|
||||
'FNC3'=>96, 'FNC2'=>97, 'SHIFT'=>98, 'Code C'=>99, 'Code B'=>100, 'FNC4'=>101, 'FNC1'=>102, 'START A'=>103,
|
||||
'START B'=>104, 'START C'=>105, 'STOP'=>106),
|
||||
'B' => array(
|
||||
' '=>0, '!'=>1, '"'=>2, '#'=>3, '$'=>4, '%'=>5, '&'=>6, "'"=>7,
|
||||
'('=>8, ')'=>9, '*'=>10, '+'=>11, ','=>12, '-'=>13, '.'=>14, '/'=>15,
|
||||
'0'=>16, '1'=>17, '2'=>18, '3'=>19, '4'=>20, '5'=>21, '6'=>22, '7'=>23,
|
||||
'8'=>24, '9'=>25, ':'=>26, ';'=>27, '<'=>28, '='=>29, '>'=>30, '?'=>31,
|
||||
'@'=>32, 'A'=>33, 'B'=>34, 'C'=>35, 'D'=>36, 'E'=>37, 'F'=>38, 'G'=>39,
|
||||
'H'=>40, 'I'=>41, 'J'=>42, 'K'=>43, 'L'=>44, 'M'=>45, 'N'=>46, 'O'=>47,
|
||||
'P'=>48, 'Q'=>49, 'R'=>50, 'S'=>51, 'T'=>52, 'U'=>53, 'V'=>54, 'W'=>55,
|
||||
'X'=>56, 'Y'=>57, 'Z'=>58, '['=>59, '\\'=>60, ']'=>61, '^'=>62, '_'=>63,
|
||||
'`' =>64, 'a'=>65, 'b'=>66, 'c'=>67, 'd'=>68, 'e'=>69, 'f'=>70, 'g'=>71,
|
||||
'h'=>72, 'i'=>73, 'j'=>74, 'k'=>75, 'l'=>76, 'm'=>77, 'n'=>78, 'o'=>79,
|
||||
'p'=>80, 'q'=>81, 'r'=>82, 's'=>83, 't'=>84, 'u'=>85, 'v'=>86, 'w'=>87,
|
||||
'x'=>88, 'y'=>89, 'z'=>90, '{'=>91, '|'=>92, '}'=>93, '~'=>94, 0x7F=>95,
|
||||
'FNC3'=>96, 'FNC2'=>97, 'SHIFT'=>98, 'Code C'=>99, 'FNC4'=>100, 'Code A'=>101, 'FNC1'=>102, 'START A'=>103,
|
||||
'START B'=>104, 'START C'=>105, 'STOP'=>106,),
|
||||
'C' => array(
|
||||
'00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5, '06'=>6, '07'=>7, '08'=>8, '09'=>9,
|
||||
'10'=>10, '11'=>11, '12'=>12, '13'=>13, '14'=>14, '15'=>15, '16'=>16, '17'=>17, '18'=>18, '19'=>19,
|
||||
'20'=>20, '21'=>21, '22'=>22, '23'=>23, '24'=>24, '25'=>25, '26'=>26, '27'=>27, '28'=>28, '29'=>29,
|
||||
'30'=>30, '31'=>31, '32'=>32, '33'=>33, '34'=>34, '35'=>35, '36'=>36, '37'=>37, '38'=>38, '39'=>39,
|
||||
'40'=>40, '41'=>41, '42'=>42, '43'=>43, '44'=>44, '45'=>45, '46'=>46, '47'=>47, '48'=>48, '49'=>49,
|
||||
'50'=>50, '51'=>51, '52'=>52, '53'=>53, '54'=>54, '55'=>55, '56'=>56, '57'=>57, '58'=>58, '59'=>59,
|
||||
'60'=>60, '61'=>61, '62'=>62, '63'=>63, '64'=>64, '65'=>65, '66'=>66, '67'=>67, '68'=>68, '69'=>69,
|
||||
'70'=>70, '71'=>71, '72'=>72, '73'=>73, '74'=>74, '75'=>75, '76'=>76, '77'=>77, '78'=>78, '79'=>79,
|
||||
'80'=>80, '81'=>81, '82'=>82, '83'=>83, '84'=>84, '85'=>85, '86'=>86, '87'=>87, '88'=>88, '89'=>89,
|
||||
'90'=>90, '91'=>91, '92'=>92, '93'=>93, '94'=>94, '95'=>95, '96'=>96, '97'=>97, '98'=>98, '99'=>99,
|
||||
'Code B'=>100, 'Code A'=>101, 'FNC1'=>102, 'START A'=>103, 'START B'=>104, 'START C'=>105, 'STOP'=>106));*/
|
||||
|
||||
/**
|
||||
* Width of the barcode (in pixels)
|
||||
* @return integer
|
||||
*/
|
||||
protected function _calculateBarcodeWidth()
|
||||
{
|
||||
$quietZone = $this->getQuietZone();
|
||||
// Each characters contain 11 bars...
|
||||
$characterLength = 11 * $this->_barThinWidth * $this->_factor;
|
||||
$convertedChars = count($this->_convertToBarcodeChars($this->getText()));
|
||||
if ($this->_withChecksum) {
|
||||
$convertedChars++;
|
||||
}
|
||||
$encodedData = $convertedChars * $characterLength;
|
||||
// ...except the STOP character (13)
|
||||
$encodedData += $characterLength + 2 * $this->_barThinWidth * $this->_factor;
|
||||
$width = $quietZone + $encodedData + $quietZone;
|
||||
return $width;
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial check of code128 barcode
|
||||
* @return void
|
||||
*/
|
||||
protected function _checkParams()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare array to draw barcode
|
||||
* @return array
|
||||
*/
|
||||
protected function _prepareBarcode()
|
||||
{
|
||||
$barcodeTable = array();
|
||||
|
||||
$convertedChars = $this->_convertToBarcodeChars($this->getText());
|
||||
|
||||
if ($this->_withChecksum) {
|
||||
$convertedChars[] = $this->getChecksum($this->getText());
|
||||
}
|
||||
|
||||
// STOP CHARACTER
|
||||
$convertedChars[] = 106;
|
||||
|
||||
foreach ($convertedChars as $barcodeChar) {
|
||||
$barcodePattern = $this->_codingMap[$barcodeChar];
|
||||
foreach (str_split($barcodePattern) as $c) {
|
||||
$barcodeTable[] = array($c, $this->_barThinWidth, 0, 1);
|
||||
}
|
||||
}
|
||||
return $barcodeTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the next $length chars of $string starting at $pos are numeric.
|
||||
* Returns false if the end of the string is reached.
|
||||
* @param string $string String to search
|
||||
* @param int $pos Starting position
|
||||
* @param int $length Length to search
|
||||
* @return bool
|
||||
*/
|
||||
protected static function _isDigit($string, $pos, $length = 2)
|
||||
{
|
||||
if ($pos + $length > strlen($string)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for ($i = $pos; $i < $pos + $length; $i++) {
|
||||
if (!is_numeric($string[$i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert string to barcode string
|
||||
*
|
||||
* @param $string
|
||||
* @return array
|
||||
*/
|
||||
protected function _convertToBarcodeChars($string)
|
||||
{
|
||||
$string = (string) $string;
|
||||
if (!strlen($string)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
if (isset($this->_convertedText[md5($string)])) {
|
||||
return $this->_convertedText[md5($string)];
|
||||
}
|
||||
|
||||
$currentCharset = null;
|
||||
$sum = 0;
|
||||
$fak = 0;
|
||||
$result = array();
|
||||
|
||||
for ($pos = 0; $pos < strlen($string); $pos++) {
|
||||
$char = $string[$pos];
|
||||
$code = null;
|
||||
|
||||
if (self::_isDigit($string, $pos, 4) && $currentCharset != 'C'
|
||||
|| self::_isDigit($string, $pos, 2) && $currentCharset == 'C') {
|
||||
/**
|
||||
* Switch to C if the next 4 chars are numeric or stay C if the next 2
|
||||
* chars are numeric
|
||||
*/
|
||||
if ($currentCharset != 'C') {
|
||||
if ($pos == 0) {
|
||||
$code = array_search("START C", $this->_charSets['C']);
|
||||
} else {
|
||||
$code = array_search("Code C", $this->_charSets[$currentCharset]);
|
||||
}
|
||||
$result[] = $code;
|
||||
$currentCharset = 'C';
|
||||
}
|
||||
} else if (in_array($char, $this->_charSets['B']) && $currentCharset != 'B'
|
||||
&& !(in_array($char, $this->_charSets['A']) && $currentCharset == 'A')) {
|
||||
/**
|
||||
* Switch to B as B contains the char and B is not the current charset.
|
||||
*/
|
||||
if ($pos == 0) {
|
||||
$code = array_search("START B", $this->_charSets['B']);
|
||||
} else {
|
||||
$code = array_search("Code B", $this->_charSets[$currentCharset]);
|
||||
}
|
||||
$result[] = $code;
|
||||
$currentCharset = 'B';
|
||||
} else if (array_key_exists($char, $this->_charSets['A']) && $currentCharset != 'A'
|
||||
&& !(array_key_exists($char, $this->_charSets['B']) && $currentCharset == 'B')) {
|
||||
/**
|
||||
* Switch to C as C contains the char and C is not the current charset.
|
||||
*/
|
||||
if ($pos == 0) {
|
||||
$code = array_search("START A", $this->_charSets['A']);
|
||||
} else {
|
||||
$code =array_search("Code A", $this->_charSets[$currentCharset]);
|
||||
}
|
||||
$result[] = $code;
|
||||
$currentCharset = 'A';
|
||||
}
|
||||
|
||||
if ($currentCharset == 'C') {
|
||||
$code = array_search(substr($string, $pos, 2), $this->_charSets['C']);
|
||||
$pos++; //Two chars from input
|
||||
} else {
|
||||
$code = array_search($string[$pos], $this->_charSets[$currentCharset]);
|
||||
}
|
||||
$result[] = $code;
|
||||
}
|
||||
|
||||
$this->_convertedText[md5($string)] = $result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set text to encode
|
||||
* @param string $value
|
||||
* @return Zend_Barcode_Object
|
||||
*/
|
||||
public function setText($value)
|
||||
{
|
||||
$this->_text = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve text to encode
|
||||
* @return string
|
||||
*/
|
||||
public function getText()
|
||||
{
|
||||
return $this->_text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get barcode checksum
|
||||
*
|
||||
* @param string $text
|
||||
* @return int
|
||||
*/
|
||||
public function getChecksum($text)
|
||||
{
|
||||
$tableOfChars = $this->_convertToBarcodeChars($text);
|
||||
|
||||
$sum = $tableOfChars[0];
|
||||
unset($tableOfChars[0]);
|
||||
|
||||
$k = 1;
|
||||
foreach ($tableOfChars as $char) {
|
||||
$sum += ($k++) * $char;
|
||||
}
|
||||
|
||||
$checksum = $sum % 103;
|
||||
|
||||
return $checksum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard validation for most of barcode objects
|
||||
*
|
||||
* @param string $value
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
protected function _validateText($value, $options = array())
|
||||
{
|
||||
// @TODO: add code128 validator
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,143 +0,0 @@
|
||||
<?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_Barcode
|
||||
* @subpackage Object
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @see Zend_Barcode_Object_ObjectAbstract
|
||||
*/
|
||||
require_once 'Zend/Barcode/Object/ObjectAbstract.php';
|
||||
|
||||
/**
|
||||
* @see Zend_Validate_Barcode
|
||||
*/
|
||||
require_once 'Zend/Validate/Barcode.php';
|
||||
|
||||
/**
|
||||
* Class for generate Interleaved 2 of 5 barcode
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Barcode
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Barcode_Object_Code25 extends Zend_Barcode_Object_ObjectAbstract
|
||||
{
|
||||
/**
|
||||
* Coding map
|
||||
* - 0 = narrow bar
|
||||
* - 1 = wide bar
|
||||
* @var array
|
||||
*/
|
||||
protected $_codingMap = array(
|
||||
'0' => '00110',
|
||||
'1' => '10001',
|
||||
'2' => '01001',
|
||||
'3' => '11000',
|
||||
'4' => '00101',
|
||||
'5' => '10100',
|
||||
'6' => '01100',
|
||||
'7' => '00011',
|
||||
'8' => '10010',
|
||||
'9' => '01010',
|
||||
);
|
||||
|
||||
/**
|
||||
* Width of the barcode (in pixels)
|
||||
* @return integer
|
||||
*/
|
||||
protected function _calculateBarcodeWidth()
|
||||
{
|
||||
$quietZone = $this->getQuietZone();
|
||||
$startCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor;
|
||||
$characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth + 5 * $this->_barThinWidth)
|
||||
* $this->_factor;
|
||||
$encodedData = strlen($this->getText()) * $characterLength;
|
||||
$stopCharacter = (2 * $this->_barThickWidth + 4 * $this->_barThinWidth) * $this->_factor;
|
||||
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Partial check of interleaved 2 of 5 barcode
|
||||
* @return void
|
||||
*/
|
||||
protected function _checkParams()
|
||||
{
|
||||
$this->_checkRatio();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare array to draw barcode
|
||||
* @return array
|
||||
*/
|
||||
protected function _prepareBarcode()
|
||||
{
|
||||
$barcodeTable = array();
|
||||
|
||||
// Start character (30301)
|
||||
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
|
||||
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
|
||||
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
|
||||
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
|
||||
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
|
||||
$barcodeTable[] = array(0 , $this->_barThinWidth);
|
||||
|
||||
$text = str_split($this->getText());
|
||||
foreach ($text as $char) {
|
||||
$barcodeChar = str_split($this->_codingMap[$char]);
|
||||
foreach ($barcodeChar as $c) {
|
||||
/* visible, width, top, length */
|
||||
$width = $c ? $this->_barThickWidth : $this->_barThinWidth;
|
||||
$barcodeTable[] = array(1 , $width , 0 , 1);
|
||||
$barcodeTable[] = array(0 , $this->_barThinWidth);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop character (30103)
|
||||
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
|
||||
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
|
||||
$barcodeTable[] = array(1 , $this->_barThinWidth , 0 , 1);
|
||||
$barcodeTable[] = array(0 , $this->_barThinWidth , 0 , 1);
|
||||
$barcodeTable[] = array(1 , $this->_barThickWidth , 0 , 1);
|
||||
return $barcodeTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get barcode checksum
|
||||
*
|
||||
* @param string $text
|
||||
* @return int
|
||||
*/
|
||||
public function getChecksum($text)
|
||||
{
|
||||
$this->_checkText($text);
|
||||
$factor = 3;
|
||||
$checksum = 0;
|
||||
|
||||
for ($i = strlen($text); $i > 0; $i --) {
|
||||
$checksum += intval($text{$i - 1}) * $factor;
|
||||
$factor = 4 - $factor;
|
||||
}
|
||||
|
||||
$checksum = (10 - ($checksum % 10)) % 10;
|
||||
|
||||
return $checksum;
|
||||
}
|
||||
}
|
@ -1,179 +0,0 @@
|
||||
<?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_Barcode
|
||||
* @subpackage Object
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/** @see Zend_Barcode_Object_Code25 */
|
||||
require_once 'Zend/Barcode/Object/Code25.php';
|
||||
|
||||
/** @see Zend_Validate_Barcode */
|
||||
require_once 'Zend/Validate/Barcode.php';
|
||||
|
||||
/**
|
||||
* Class for generate Interleaved 2 of 5 barcode
|
||||
*
|
||||
* @category Zend
|
||||
* @package Zend_Barcode
|
||||
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
|
||||
* @license http://framework.zend.com/license/new-bsd New BSD License
|
||||
*/
|
||||
class Zend_Barcode_Object_Code25interleaved extends Zend_Barcode_Object_Code25
|
||||
{
|
||||
/**
|
||||
* Drawing of bearer bars
|
||||
* @var boolean
|
||||
*/
|
||||
private $_withBearerBars = false;
|
||||
|
||||
/**
|
||||
* Default options for Code25interleaved barcode
|
||||
* @return void
|
||||
*/
|
||||
protected function _getDefaultOptions()
|
||||
{
|
||||
$this->_barcodeLength = 'even';
|
||||
}
|
||||
|
||||
/**
|
||||
* Activate/deactivate drawing of bearer bars
|
||||
* @param boolean $value
|
||||
* @return Zend_Barcode_Object_Int25
|
||||
*/
|
||||
public function setWithBearerBars($value)
|
||||
{
|
||||
$this->_withBearerBars = (bool) $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve if bearer bars are enabled
|
||||
* @return boolean
|
||||
*/
|
||||
public function getWithBearerBars()
|
||||
{
|
||||
return $this->_withBearerBars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Width of the barcode (in pixels)
|
||||
* @return integer
|
||||
*/
|
||||
protected function _calculateBarcodeWidth()
|
||||
{
|
||||
$quietZone = $this->getQuietZone();
|
||||
$startCharacter = (4 * $this->_barThinWidth) * $this->_factor;
|
||||
$characterLength = (3 * $this->_barThinWidth + 2 * $this->_barThickWidth) * $this->_factor;
|
||||
$encodedData = strlen($this->getText()) * $characterLength;
|
||||
$stopCharacter = ($this->_barThickWidth + 2 * $this->_barThinWidth) * $this->_factor;
|
||||
return $quietZone + $startCharacter + $encodedData + $stopCharacter + $quietZone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare array to draw barcode
|
||||
* @return array
|
||||
*/
|
||||
protected function _prepareBarcode()
|
||||
{
|
||||
if ($this->_withBearerBars) {
|
||||
$this->_withBorder = false;
|
||||
}
|
||||
|
||||
// Start character (0000)
|
||||
$barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
|
||||
$barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
|
||||
$barcodeTable[] = array(1, $this->_barThinWidth, 0, 1);
|
||||
$barcodeTable[] = array(0, $this->_barThinWidth, 0, 1);
|
||||
|
||||
// Encoded $text
|
||||
$text = $this->getText();
|
||||
for ($i = 0; $i < strlen($text); $i += 2) { // Draw 2 chars at a time
|
||||
$char1 = substr($text, $i, 1);
|
||||
$char2 = substr($text, $i + 1, 1);
|
||||
|
||||
// Interleave
|
||||
for ($ibar = 0; $ibar < 5; $ibar ++) {
|
||||
// Draws char1 bar (fore color)
|
||||
$barWidth = (substr($this->_codingMap[$char1], $ibar, 1))
|
||||
? $this->_barThickWidth
|
||||
: $this->_barThinWidth;
|
||||
|
||||
$barcodeTable[] = array(1, $barWidth, 0, 1);
|
||||
|
||||
// Left space corresponding to char2 (background color)
|
||||
$barWidth = (substr($this->_codingMap[$char2], $ibar, 1))
|
||||
? $this->_barThickWidth
|
||||
: $this->_barThinWidth;
|
||||
$barcodeTable[] = array(0, $barWidth, 0 , 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop character (100)
|
||||
$barcodeTable[] = array(1 , $this->_barThickWidth, 0, 1);
|
||||
$barcodeTable[] = array(0 , $this->_barThinWidth, 0, 1);
|
||||
$barcodeTable[] = array(1 , $this->_barThinWidth, 0, 1);
|
||||
return $barcodeTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Drawing of bearer bars (if enabled)
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function _postDrawBarcode()
|
||||
{
|
||||
if (!$this->_withBearerBars) {
|
||||
return;
|
||||
}
|
||||
|
||||
$width = $this->_barThickWidth * $this->_factor;
|
||||
$point1 = $this->_rotate(-1, -1);
|
||||
$point2 = $this->_rotate($this->_calculateWidth() - 1, -1);
|
||||
$point3 = $this->_rotate($this->_calculateWidth() - 1, $width - 1);
|
||||
$point4 = $this->_rotate(-1, $width - 1);
|
||||
$this->_addPolygon(array(
|
||||
$point1,
|
||||
$point2,
|
||||
$point3,
|
||||
$point4,
|
||||
));
|
||||
$point1 = $this->_rotate(
|
||||
0,
|
||||
0 + $this->_barHeight * $this->_factor - 1
|
||||
);
|
||||
$point2 = $this->_rotate(
|
||||
$this->_calculateWidth() - 1,
|
||||
0 + $this->_barHeight * $this->_factor - 1
|
||||
);
|
||||
$point3 = $this->_rotate(
|
||||
$this->_calculateWidth() - 1,
|
||||
0 + $this->_barHeight * $this->_factor - $width
|
||||
);
|
||||
$point4 = $this->_rotate(
|
||||
0,
|
||||
0 + $this->_barHeight * $this->_factor - $width
|
||||
);
|
||||
$this->_addPolygon(array(
|
||||
$point1,
|
||||
$point2,
|
||||
$point3,
|
||||
$point4,
|
||||
));
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user