public static function minimalBootstrap() { if (!defined('VENDOR_PATH')) { define('VENDOR_PATH', 'vendor'); } if (VENDOR_PATH == '../vendor') { $kwfPath = '..'; } else { $kwfPath = VENDOR_PATH . '/koala-framework/koala-framework'; } if (!defined('KWF_PATH')) { define('KWF_PATH', $kwfPath); } //reset include path, don't use anything from php.ini set_include_path('.' . PATH_SEPARATOR . $kwfPath . PATH_SEPARATOR . self::_getZendPath()); require_once $kwfPath . '/Kwf/Loader.php'; Kwf_Loader::registerAutoload(); Zend_Registry::setClassName('Kwf_Registry'); $configSection = call_user_func(array(Kwf_Setup::$configClass, 'getDefaultConfigSection')); Kwf_Setup::$configSection = $configSection; error_reporting(E_ALL ^ E_STRICT); class_exists('Kwf_Trl'); //trigger autoload umask(00); //nicht 002 weil wwwrun und kwcms in unterschiedlichen gruppen }
/** * Set include path used for Kwf_Loader::isValidClass * * called exactly once in setup * * get_include_path is not used, because some external library might have changed that. * * @internal */ public static function setIncludePath($ip) { if (self::$_includePath) { throw new Kwf_Exception("include path is already set"); } self::$_includePath = $ip; set_include_path($ip); }
public static function setup() { require_once KWF_PATH . '/Kwf/Loader.php'; require_once KWF_PATH . '/Kwf/Setup.php'; Kwf_Loader::registerAutoload(); date_default_timezone_set('Europe/Berlin'); mb_internal_encoding('UTF-8'); Zend_Registry::setClassName('Kwf_Registry'); // auskommentiert, da main() sowieso nicht aufgerufen wird // require_once KWF_PATH.'/tests/TestConfiguration.php'; require_once 'PHPUnit/Framework/TestSuite.php'; require_once 'PHPUnit/TextUI/TestRunner.php'; }
public function getControllerClass(Zend_Controller_Request_Abstract $request) { $module = $request->getModuleName(); if ($module == 'component' && $request->getControllerName() == 'component' || $module == 'component_test' && $request->getControllerName() == 'component_test') { if ($module == 'component_test') { //FnF models setzen damit tests nicht in echte tabellen schreiben Kwf_Component_Cache::setInstance(Kwf_Component_Cache::CACHE_BACKEND_FNF); Kwf_Test_SeparateDb::setDbFromCookie(); // setzt es nur wenn es das cookie wirklich gibt if (!Kwf_Loader::isValidClass($request->getParam('root'))) { throw new Kwf_Exception_NotFound("Invalid root component"); } Kwf_Component_Data_Root::setComponentClass($request->getParam('root')); $root = Kwf_Component_Data_Root::getInstance(); $root->setFilename('kwf/kwctest/' . $request->getParam('root')); Kwf_Registry::get('acl')->getComponentAcl()->allowComponent('guest', null); //hick hack, für Kwf_Component_Abstract_Admin::getControllerUrl Zend_Registry::set('testRootComponentClass', $request->getParam('root')); } $class = $request->getParam('class'); $controller = $request->getParam('componentController'); $controller .= 'Controller'; if ($controller == 'IndexController') { $controller = 'Controller'; } if (($pos = strpos($class, '!')) !== false) { $controller = substr($class, $pos + 1) . 'Controller'; $class = substr($class, 0, $pos); } if (!in_array($class, Kwc_Abstract::getComponentClasses())) { //unknown component class return false; } $className = Kwc_Admin::getComponentClass($class, $controller); if (!$className) { return false; } class_exists($className); //trigger autoloader } else { $className = parent::getControllerClass($request); } return $className; }
/** * @dataProvider findFileProvider */ public function testFindFile(array $composerNamespaces, array $psr4Namespaces, $class, $expectedFile) { foreach ($composerNamespaces as &$dirs) { foreach ($dirs as &$dir) { $dir = getcwd() . '/' . $dir; } } unset($dirs); unset($dir); foreach ($psr4Namespaces as &$dirs) { foreach ($dirs as &$dir) { $dir = getcwd() . '/' . $dir; } } unset($dirs); unset($dir); $namespaces = Kwf_Loader::_prepareNamespaces($composerNamespaces, $psr4Namespaces); $file = Kwf_Loader::_findFile($class, $namespaces, array()); $this->assertEquals(getcwd() . '/' . $expectedFile, $file); }
protected function _afterInsert() { parent::_afterInsert(); $c = Kwc_Shop_Cart_Checkout_Payment_Wirecard_LogModel::decodeCallback($this->custom); if ($c && $c['cb']) { $ret = false; if (Kwf_Loader::isValidClass($c['cb'])) { $ret = call_user_func(array($c['cb'], 'processIpn'), $this, $c['data']); } else { if (Kwf_Component_Data_Root::getComponentClass()) { $component = Kwf_Component_Data_Root::getInstance()->getComponentById($c['cb']); if ($component) { $ret = $component->getComponent()->processIpn($this, $c['data']); } } } $this->callback_success = $ret; $this->save(); } }
public static function dispatch() { Kwf_Loader::registerAutoload(); if (php_sapi_name() == 'cli') { $quiet = isset($_SERVER['argv'][2]) && trim($_SERVER['argv'][2]) == 'quiet'; } else { $role = false; try { $role = Kwf_Registry::get('userModel')->getAuthedUserRole(); } catch (Exception $e) { } if ($role != 'admin') { if (empty($_SERVER['PHP_AUTH_USER']) || empty($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] != 'vivid' || $_SERVER['PHP_AUTH_PW'] != 'planet') { header('WWW-Authenticate: Basic realm="Check Config"'); throw new Kwf_Exception_AccessDenied(); } } $quiet = isset($_GET['quiet']); } self::_check($quiet); }
public static function dispatch() { Kwf_Loader::registerAutoload(); if (empty($_REQUEST['progressNum'])) { throw new Kwf_Exception('progressNum required'); } $pbarAdapter = new Kwf_Util_ProgressBar_Adapter_Cache($_REQUEST['progressNum']); $pbarStatus = $pbarAdapter->getStatus(); if (!$pbarStatus) { $pbarStatus = array(); } $pbarStatus['success'] = true; if (isset($_REQUEST['outputFile']) && isset($_REQUEST['pid'])) { $processes = Kwf_Util_Process::getRunningProcesses(); if (isset($processes[$_REQUEST['pid']])) { $pbarStatus['bgFinished'] = false; } else { $pbarStatus['bgFinished'] = true; if (!preg_match('#^bgproc[a-z0-9]+$#i', $_REQUEST['outputFile'])) { throw new Kwf_Exception_AccessDenied(); } $output = file_get_contents('./temp/' . $_REQUEST['outputFile']); $outputErr = file_get_contents('./temp/' . $_REQUEST['outputFile'] . '.err'); $outputJson = json_decode($output); if (!$outputJson) { //assign as string $pbarStatus['bgError'] = $outputErr; } else { $pbarStatus['bgResponse'] = $outputJson; $pbarStatus['bgError'] = file_get_contents('./temp/' . $_REQUEST['outputFile'] . '.err'); $pbarStatus['bgError'] = preg_replace('#^(PHP )?Deprecated: .*$#m', '', $pbarStatus['bgError']); //ignore errors from deprecated php.ini settings $pbarStatus['bgError'] = trim($pbarStatus['bgError']); } } } echo Zend_Json::encode($pbarStatus); exit; }
public static function loadClass($class) { parent::loadClass($class); Kwf_Benchmark::count('classes included', $class); }
private static function _findComponentFile($c) { static $cache = array(); if (isset($cache[$c])) { return $cache[$c]; } static $dirs; if (!isset($dirs)) { $dirs = array_reverse(explode(PATH_SEPARATOR, get_include_path())); } static $namespaces; if (!isset($namespaces)) { $composerNamespaces = (include VENDOR_PATH . '/composer/autoload_namespaces.php'); $psr4Namespaces = (include VENDOR_PATH . '/composer/autoload_psr4.php'); $namespaces = Kwf_Loader::_prepareNamespaces($composerNamespaces, $psr4Namespaces); } static $classMap; if (!isset($classMap)) { $classMap = (include VENDOR_PATH . '/composer/autoload_classmap.php'); } $file = Kwf_Loader::_findFile($c, $namespaces, $classMap); if (substr($file, 0, strlen(getcwd())) == getcwd()) { $path = substr($file, strlen(getcwd()) + 1); } else { if (KWF_PATH == '..') { $cwd = getcwd(); $parentCwd = substr($cwd, 0, strrpos($cwd, '/')); if (substr($file, 0, strlen($parentCwd)) != $parentCwd) { throw new Kwf_Exception("'{$file}' is not in web directory '{$parentCwd}'"); } if ($file == $parentCwd) { $path = '..'; } else { $path = '../' . substr($file, strlen($parentCwd) + 1); } } else { $file = str_replace('_', '/', $c) . '.php'; foreach ($dirs as $dir) { $path = $dir . ($dir ? '/' : '') . $file; if (is_file($path)) { break; } } if (!is_file($path)) { throw new Kwf_Exception("Can't find file"); } } } $path = str_replace(DIRECTORY_SEPARATOR, '/', $path); $cache[$c] = $path; return $path; }
private static function _getOutputWithoutCheckingIsValid($class, $id, $type) { $cacheId = self::createCacheId($class, $id, $type); $output = Kwf_Media_MemoryCache::getInstance()->load($cacheId); if ($output && !isset($output['file']) && !isset($output['contents'])) { //scaled image is not cached in apc as it might be larger - load from disk $output['file'] = 'cache/media/' . $cacheId; } if (isset($output['file']) && !file_exists($output['file'])) { $output = false; } if ($output && isset($output['mtimeFiles'])) { foreach ($output['mtimeFiles'] as $f) { if (filemtime($f) > $output['mtime']) { Kwf_Media_MemoryCache::getInstance()->remove($cacheId); $output = false; break; } } } if (!$output) { $classWithoutDot = strpos($class, '.') ? substr($class, 0, strpos($class, '.')) : $class; if (!Kwf_Loader::isValidClass($classWithoutDot) || !is_instance_of($classWithoutDot, 'Kwf_Media_Output_Interface')) { throw new Kwf_Exception_NotFound(); } $output = call_user_func(array($classWithoutDot, 'getMediaOutput'), $id, $type, $class); $specificLifetime = false; $useCache = true; if (isset($output['lifetime'])) { $specificLifetime = $output['lifetime']; if (!$output['lifetime']) { $useCache = false; } } if (!isset($output['mtime'])) { if (isset($output['file'])) { $output['mtime'] = filemtime($output['file']); } else { if (isset($output['mtimeFiles'])) { $output['mtime'] = 0; foreach ($output['mtimeFiles'] as $f) { $output['mtime'] = max($output['mtime'], filemtime($f)); } } else { $output['mtime'] = time(); } } } if ($useCache) { $cacheData = $output; if (isset($cacheData['contents']) && strlen($cacheData['contents']) > 20 * 1024) { //don't cache contents larger than 20k in apc, use separate file cache file_put_contents('cache/media/' . $cacheId, $cacheData['contents']); unset($cacheData['contents']); } Kwf_Media_MemoryCache::getInstance()->save($cacheData, $cacheId, $specificLifetime); } } return $output; }
private static function _getOutputWithoutCheckingIsValid($class, $id, $type) { $cacheId = self::createCacheId($class, $id, $type); $output = Kwf_Media_MemoryCache::getInstance()->load($cacheId); if ($output && !isset($output['file']) && !isset($output['contents'])) { //cache entry from older kwf version where file was not set $output = false; } if (isset($output['file']) && !file_exists($output['file'])) { $output = false; } if ($output && isset($output['mtimeFiles'])) { foreach ($output['mtimeFiles'] as $f) { if (filemtime($f) > $output['mtime']) { Kwf_Media_MemoryCache::getInstance()->remove($cacheId); $output = false; break; } } } if (!$output) { $classWithoutDot = strpos($class, '.') ? substr($class, 0, strpos($class, '.')) : $class; if (!Kwf_Loader::isValidClass($classWithoutDot) || !is_instance_of($classWithoutDot, 'Kwf_Media_Output_Interface')) { throw new Kwf_Exception_NotFound(); } $output = call_user_func(array($classWithoutDot, 'getMediaOutput'), $id, $type, $class); $specificLifetime = false; $useCache = true; if (isset($output['lifetime'])) { $specificLifetime = $output['lifetime']; if (!$output['lifetime']) { $useCache = false; } } if (!isset($output['mtime'])) { if (isset($output['file'])) { $output['mtime'] = filemtime($output['file']); } else { if (isset($output['mtimeFiles'])) { $output['mtime'] = 0; foreach ($output['mtimeFiles'] as $f) { $output['mtime'] = max($output['mtime'], filemtime($f)); } } else { $output['mtime'] = time(); } } } if ($useCache) { $cacheData = $output; if (isset($cacheData['contents']) && strlen($cacheData['contents']) > 20 * 1024) { //don't cache contents larger than 20k in apc, use separate file cache $cacheFileName = Kwf_Config::getValue('mediaCacheDir') . '/' . $class . '/' . $id . '/' . $type; if (!is_dir(dirname($cacheFileName))) { @mkdir(dirname($cacheFileName), 0777, true); } file_put_contents($cacheFileName, $cacheData['contents']); $cacheData['file'] = $cacheFileName; unset($cacheData['contents']); } Kwf_Media_MemoryCache::getInstance()->save($cacheData, $cacheId, $specificLifetime); } } return $output; }
private static function _findComponentFile($c) { static $cache = array(); if (isset($cache[$c])) { return $cache[$c]; } static $dirs; if (!isset($dirs)) { $dirs = array_reverse(explode(PATH_SEPARATOR, get_include_path())); } static $namespaces; if (!isset($namespaces)) { $composerNamespaces = (include VENDOR_PATH . '/composer/autoload_namespaces.php'); $psr4Namespaces = (include VENDOR_PATH . '/composer/autoload_psr4.php'); $namespaces = Kwf_Loader::_prepareNamespaces($composerNamespaces, $psr4Namespaces); } static $classMap; if (!isset($classMap)) { $classMap = (include VENDOR_PATH . '/composer/autoload_classmap.php'); } $file = Kwf_Loader::_findFile($c, $namespaces, $classMap); if (substr($file, 0, strlen(getcwd())) == getcwd()) { $path = substr($file, strlen(getcwd()) + 1); } else { $file = str_replace('_', '/', $c) . '.php'; foreach ($dirs as $dir) { $path = $dir . ($dir ? '/' : '') . $file; if (is_file($path)) { break; } } } $cache[$c] = $path; return $path; }