public function offsetGet($index) { if ($index == 'db' && !parent::offsetExists($index)) { $v = Kwf_Setup::createDb(); $this->offsetSet('db', $v); return $v; } else { if ($index == 'config' && !parent::offsetExists($index)) { $v = Kwf_Config_Web::getInstance(); $this->offsetSet('config', $v); return $v; } else { if ($index == 'dao' && !parent::offsetExists($index)) { $v = Kwf_Setup::createDao(); $this->offsetSet('dao', $v); return $v; } else { if ($index == 'acl' && !parent::offsetExists($index)) { $v = Kwf_Acl::getInstance(); $this->offsetSet('acl', $v); return $v; } else { if ($index == 'userModel' && !parent::offsetExists($index)) { $v = self::get('config')->user->model; if ($v) { $v = Kwf_Model_Abstract::getInstance($v); } $this->offsetSet('userModel', $v); return $v; } else { if ($index == 'trl' && !parent::offsetExists($index)) { $v = Kwf_Trl::getInstance(); $this->offsetSet('trl', $v); return $v; } } } } } } return parent::offsetGet($index); }
public static function getValue($var) { $cacheId = 'config-' . $var; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if ($success) { return $ret; } $cfg = Kwf_Config_Web::getInstance(); foreach (explode('.', $var) as $i) { if (!isset($cfg->{$i})) { $cfg = null; break; } $cfg = $cfg->{$i}; } $ret = $cfg; if (is_object($ret)) { throw new Kwf_Exception("this would return an object, use getValueArray instead"); } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
public static function getValue($var) { $cacheId = 'config-' . $var; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if ($success) { return $ret; } $cfg = Kwf_Config_Web::getInstance(); foreach (explode('.', $var) as $i) { if (!isset($cfg->{$i})) { $cfg = null; break; } $cfg = $cfg->{$i}; } $ret = $cfg; if (is_object($ret)) { $ret = $ret->toArray(); } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
public function testStaticConfigMerge() { // main config $mainContent = array('foo' => 'bar', 'blubb' => array('firstname' => 'Hermann'), 'tags' => array('tag1', 'tag2', 'tag3')); $main = new Zend_Config($mainContent, true); // config to merge $mergeContent = array('blubb' => array('lastname' => 'Kunz'), 'tags' => array('newtag1', 'newtag2')); $merge = new Zend_Config($mergeContent, true); // do it $merged = Kwf_Config_Web::mergeConfigs($main, $merge); $mergedArray = $merged->toArray(); $expectedResult = $mainContent; $expectedResult['blubb']['lastname'] = 'Kunz'; $expectedResult['tags'] = array('newtag1', 'newtag2'); $this->assertEquals($expectedResult, $mergedArray); // config to merge $mergeContent = array('blubb' => array('firstname' => 'Kurt')); $merge = new Zend_Config($mergeContent, true); // do it $merged = Kwf_Config_Web::mergeConfigs($merged, $merge); $mergedArray = $merged->toArray(); $expectedResult['blubb']['firstname'] = 'Kurt'; $this->assertEquals($expectedResult, $mergedArray); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!file_exists($_SERVER['HOME'] . '/.aws/config')) { throw new \Exception("Can't get aws config, set up eb cli first"); } $awsConfig = parse_ini_file($_SERVER['HOME'] . '/.aws/config', true); $awsConfig = array('key' => $awsConfig['profile eb-cli']['aws_access_key_id'], 'secret' => $awsConfig['profile eb-cli']['aws_secret_access_key']); $s3 = new \Kwf_Util_Aws_S3($awsConfig); \Kwf_Setup::setUp(); $prodSection = $input->getOption('server'); $prodConfig = \Kwf_Config_Web::getInstance($prodSection); $bucket = $prodConfig->aws->uploadsBucket; if (!$bucket) { throw new \Exception("No aws.uploadBucket configured for '{$prodSection}'"); } $model = \Kwf_Model_Abstract::getInstance('Kwf_Uploads_Model'); $select = new \Kwf_Model_Select(); $it = new \Kwf_Model_Iterator_Packages(new \Kwf_Model_Iterator_Rows($model, $select)); $it = new \Kwf_Iterator_ConsoleProgressBar($it); foreach ($it as $row) { $file = $row->getFileSource(); if (file_exists($file)) { if ($s3->if_object_exists($bucket, $row->id)) { echo "already existing: {$row->id}\n"; } else { echo "uploading: {$row->id}"; $contents = file_get_contents($file); $r = $s3->create_object($bucket, $row->id, array('body' => $contents, 'length' => strlen($contents), 'contentType' => $row->mime_type)); if (!$r->isOk()) { throw new \Exception($r->body); } echo " OK\n"; } } } }
public function __construct($section, array $options = array()) { $options['webPath'] = 'tests'; parent::__construct($section, $options); }
/** * Diesen Merge sollte eigentlich das Zend machen, aber das merged nicht so * wie wir das erwarten. Beispiel: * * Main Config: * bla.blubb[] = x * bla.blubb[] = y * bla.blubb[] = z * * Merge Config: * bla.blubb[] = a * bla.blubb[] = b * * Nach den Config-Section regeln würde man erwarten, dass nach dem mergen nur mehr * a und b drin steht. Tatsächlich merget Zend aber so, dass a, b, z überbleibt. * Zend überschreibt die Werte, was wir nicht wollen, deshalb dieses * händische mergen hier. */ public static function mergeConfigs(Zend_Config $main, Zend_Config $merge) { // check if all keys are of type 'integer' and if so, only use merge config $everyKeyIsInteger = true; foreach ($merge as $key => $item) { if (!is_int($key)) { $everyKeyIsInteger = false; break; } } if ($everyKeyIsInteger) { return $merge; } foreach ($merge as $key => $item) { if (isset($main->{$key})) { if ($item instanceof Zend_Config && $main->{$key} instanceof Zend_Config) { $main->{$key} = Kwf_Config_Web::mergeConfigs($main->{$key}, new Zend_Config($item->toArray(), !$main->readOnly())); } else { $main->{$key} = $item; } } else { if ($item instanceof Zend_Config) { $main->{$key} = new Zend_Config($item->toArray(), !$main->readOnly()); } else { $main->{$key} = $item; } } } return $main; }
public static function setUp($configClass = 'Kwf_Config_Web') { error_reporting(E_ALL & ~E_STRICT); define('APP_PATH', getcwd()); Kwf_Setup::$configClass = $configClass; if (PHP_SAPI == 'cli') { //don't use cached setup on cli so clear-cache will always work even if eg. paths change require_once dirname(__FILE__) . '/../Kwf/Util/Setup.php'; Kwf_Util_Setup::minimalBootstrap(); eval(substr(Kwf_Util_Setup::generateCode(), 5)); } else { if (!@(include APP_PATH . '/cache/setup' . self::CACHE_SETUP_VERSION . '.php')) { if (!file_exists(APP_PATH . '/cache/setup' . self::CACHE_SETUP_VERSION . '.php')) { require_once dirname(__FILE__) . '/../Kwf/Util/Setup.php'; Kwf_Util_Setup::minimalBootstrapAndGenerateFile(); } include APP_PATH . '/cache/setup' . self::CACHE_SETUP_VERSION . '.php'; } } if (!defined('VKWF_PATH') && PHP_SAPI != 'cli' && self::getBaseUrl() === null) { //if server.baseUrl is not set try to auto detect it and generate config.local.ini accordingly //this code is not used if server.baseUrl is set to "" in vkwf if (!isset($_SERVER['PHP_SELF'])) { echo "Can't detect baseUrl, PHP_SELF is not set\n"; exit(1); } $baseUrl = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')); if (substr($baseUrl, -16) == '/kwf/maintenance') { $baseUrl = substr($baseUrl, 0, -16); } $cfg = "[production]\n"; $cfg .= "server.domain = \"{$_SERVER['HTTP_HOST']}\"\n"; $cfg .= "server.baseUrl = \"{$baseUrl}\"\n"; $cfg .= "setupFinished = false\n"; if (file_exists('config.local.ini') && filesize('config.local.ini') > 0) { echo "config.local.ini already exists but server.baseUrl is not set\n"; exit(1); } if (!is_writable('.')) { echo "'" . getcwd() . "' is not writable, can't create config.local.ini\n"; exit(1); } file_put_contents('config.local.ini', $cfg); Kwf_Config_Web::reload(); Kwf_Config::deleteValueCache('server.domain'); Kwf_Config::deleteValueCache('server.baseUrl'); unlink('cache/setup' . self::CACHE_SETUP_VERSION . '.php'); echo "<h1>" . Kwf_Config::getValue('application.name') . "</h1>\n"; echo "<a href=\"{$baseUrl}/kwf/maintenance/setup\">[start setup]</a>\n"; exit; } if (isset($_SERVER['REQUEST_URI']) && substr($_SERVER['REQUEST_URI'], 0, 5) == '/kwf/') { if (substr($_SERVER['REQUEST_URI'], 0, 9) == '/kwf/pma/' || $_SERVER['REQUEST_URI'] == '/kwf/pma') { Kwf_Util_Pma::dispatch(); } else { if ($_SERVER['REQUEST_URI'] == '/kwf/check') { $ok = true; $msg = ''; if (Kwf_Setup::hasDb()) { $date = Kwf_Registry::get('db')->query("SELECT NOW()")->fetchColumn(); if (!$date) { $ok = false; $msg .= 'mysql connection failed'; } } if (file_exists('instance_startup')) { //can be used while starting up autoscaling instances $ok = false; $msg .= 'instance startup in progress'; } if (!$ok) { header("HTTP/1.0 500 Error"); echo "<h1>Check failed</h1>"; echo $msg; } else { echo "ok"; } exit; } } } Kwf_Benchmark::checkpoint('setUp'); }
protected function _refreshCache($options) { Kwf_Config_Web::reload(); }
protected static function _getConfigSectionsWithHost() { $webConfigFull = new Zend_Config_Ini('config.ini', null); $sections = array(); $processedDomains = array(); foreach ($webConfigFull as $k => $i) { if ($k == 'dependencies') { continue; } $config = Kwf_Config_Web::getInstance($k); if ($config->server && $config->server->host) { $sections[] = $k; } } return $sections; }
public function warmupCaches() { $cacheFile = $this->_getCacheFileName(); $useCache = false; if (file_exists("{$cacheFile}.sourcetimes")) { $useCache = true; $sourceTimes = unserialize(file_get_contents("{$cacheFile}.sourcetimes")); foreach ($sourceTimes as $i) { if ($i['mtime']) { if (!file_exists($i['file']) || filemtime($i['file']) != $i['mtime']) { //file was modified or deleted $useCache = false; break; } } else { if (file_exists($i['file'])) { //file didn't exist, was created $useCache = false; break; } } } } if (!$useCache) { $fileName = $this->getAbsoluteFileName(); static $loadPath; if (!isset($loadPath)) { $loadPath = array(); foreach (glob(VENDOR_PATH . '/bower_components/*') as $p) { $bowerMain = null; $mainExt = null; if (file_exists($p . '/bower.json')) { $bower = json_decode(file_get_contents($p . '/bower.json')); if (isset($bower->main) && is_string($bower->main)) { $bowerMain = $bower->main; $mainExt = substr($bowerMain, -5); } } if ($mainExt == '.scss' || $mainExt == '.sass') { $mainDir = substr($bowerMain, 0, strrpos($bowerMain, '/')); $loadPath[] = $p . '/' . $mainDir; } else { if (file_exists($p . '/scss')) { $loadPath[] = $p . '/scss'; } } } $loadPath[] = './scss'; if (KWF_PATH == '..') { $loadPath[] = substr(getcwd(), 0, strrpos(getcwd(), '/')) . '/sass/Kwf/stylesheets'; } else { $loadPath[] = KWF_PATH . '/sass/Kwf/stylesheets'; } $loadPath = escapeshellarg(implode(PATH_SEPARATOR, $loadPath)); } if (substr($fileName, 0, 2) == './') { $fileName = getcwd() . substr($fileName, 1); } $bin = Kwf_Config::getValue('server.nodeSassBinary'); if (!$bin) { $bin = getcwd() . "/" . VENDOR_PATH . "/bin/node " . dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/node_modules/node-sass/bin/node-sass'; } $cmd = "{$bin} --include-path {$loadPath} --output-style compressed "; $cmd .= " --source-map " . escapeshellarg($cacheFile . '.map'); $cmd .= " " . escapeshellarg($fileName) . " " . escapeshellarg($cacheFile); $cmd .= " 2>&1"; $out = array(); exec($cmd, $out, $retVal); if ($retVal) { throw new Kwf_Exception("compiling sass failed: " . implode("\n", $out)); } $map = json_decode(file_get_contents("{$cacheFile}.map")); $sourceFiles = array(); foreach ($map->sources as $k => $i) { //sources are relative to cache/sass, strip that if (substr($i, 0, 6) != '../../') { throw new Kwf_Exception('source doesn\'t start with ../../'); } $i = substr($i, 6); $f = self::getPathWithTypeByFileName(getcwd() . '/' . $i); if (!$f) { throw new Kwf_Exception("Can't find path for '" . getcwd() . '/' . $i . "'"); } $map->sources[$k] = $f; $sourceFiles[] = $f; if (substr($f, 0, 16) == 'web/scss/config/') { $sourceFiles[] = 'kwf/sass/Kwf/stylesheets/config/' . substr($f, 16); } else { if (substr($f, 0, 32) == 'kwf/sass/Kwf/stylesheets/config/') { $sourceFiles[] = 'web/scss/config/' . substr($f, 32); } } } $map->file = $cacheFile; file_put_contents("{$cacheFile}.map", json_encode($map)); $ret = file_get_contents($cacheFile); $ret = str_replace("@charset \"UTF-8\";\n", '', $ret); //remove charset, no need to adjust sourcemap as sourcemap doesn't include that (bug in libsass) $ret = preg_replace("#/\\*\\# sourceMappingURL=.* \\*/#", '', $ret); $map = new Kwf_SourceMaps_SourceMap(file_get_contents("{$cacheFile}.map"), $ret); if (strpos($ret, 'cssClass') !== false && (strpos($ret, '$cssClass') !== false || strpos($ret, '.cssClass') !== false)) { $cssClass = $this->_getComponentCssClass(); if ($cssClass) { if (strpos($ret, '.cssClass') !== false) { $map->stringReplace('.cssClass', ".{$cssClass}"); } if (strpos($ret, '$cssClass') !== false) { $map->stringReplace('$cssClass', ".{$cssClass}"); } } } if (strpos($ret, 'kwfup-') !== false) { if (Kwf_Config::getValue('application.uniquePrefix')) { $map->stringReplace('kwfup-', Kwf_Config::getValue('application.uniquePrefix') . '-'); } else { $map->stringReplace('kwfup-', ''); } } $usesVars = false; $assetVars = self::getAssetVariables(); foreach ($assetVars as $k => $i) { $search = 'var(' . $k . ')'; if (strpos($ret, $search) !== false) { $map->stringReplace($search, $i); $usesVars = true; } } $map->save("{$cacheFile}.map", $cacheFile); unset($map); $sourceTimes = array(); foreach ($sourceFiles as $f) { $f = new Kwf_Assets_Dependency_File($f); $f = $f->getAbsoluteFileName(); $sourceTimes[] = array('file' => $f, 'mtime' => file_exists($f) ? filemtime($f) : null); } if ($usesVars) { $files = array('assetVariables.ini', 'config.ini', KWF_PATH . '/config.ini'); if (Kwf_Config::getValue('kwc.theme')) { $files[] = Kwf_Config_Web::findThemeConfigIni(Kwf_Config::getValue('kwc.theme')); } foreach ($files as $f) { $sourceTimes[] = array('file' => $f, 'mtime' => file_exists($f) ? filemtime($f) : null); } } file_put_contents("{$cacheFile}.sourcetimes", serialize($sourceTimes)); } }
public function jsonInstallAction() { $cfg = "[production]\n"; $cfg .= "database.web.username = "******"\n"; $cfg .= "database.web.password = "******"\n"; $cfg .= "database.web.dbname = " . $this->_getParam('db_dbname') . "\n"; $cfg .= "database.web.host = " . $this->_getParam('db_host') . "\n"; $cfg .= "\n"; $cfg .= "server.domain = " . $this->getRequest()->getHttpHost() . "\n"; $cfg .= "server.baseUrl = \"" . $this->getRequest()->getBaseUrl() . "\"\n"; $cfg .= "\n"; $cfg .= "debug.error.log = " . (!$this->_getParam('display_errors') ? 'true' : 'false') . "\n"; file_put_contents('config.local.ini', $cfg); file_put_contents('config_section', $this->_getParam('config_section')); //re-create config to load changed config.local.ini Kwf_Config::deleteValueCache('database'); Kwf_Config_Web::reload(); Zend_Registry::getInstance()->offsetUnset('db'); Zend_Registry::getInstance()->offsetSet('dao', new Kwf_Dao()); $updates = array(); foreach (Kwf_Util_Update_Helper::getUpdateTags() as $tag) { $file = KWF_PATH . '/setup/' . $tag . '.sql'; if (file_exists($file)) { $update = new Kwf_Update_Sql(0, null); $update->sql = file_get_contents($file); $updates[] = $update; } } $updates = array_merge($updates, Kwf_Util_Update_Helper::getUpdates()); $updates[] = new Kwf_Update_Setup_InitialDb('setup/setup.sql'); $updates[] = new Kwf_Update_Setup_InitialUploads('setup/uploads'); $update = new Kwf_Update_Sql(0, null); $db = Kwf_Registry::get('db'); mt_srand((double) microtime() * 1000000); $passwordSalt = substr(md5(uniqid(mt_rand(), true)), 0, 10); $update->sql = "TRUNCATE TABLE kwf_users;\n"; $update->sql .= "INSERT INTO kwf_users SET\n role='admin',\n email=" . $db->quote($this->_getParam('admin_email')) . ",\n password="******",\n password_salt=" . $db->quote($passwordSalt) . ";\n"; $updates[] = $update; $c = new Kwf_Util_ProgressBar_Adapter_Cache($this->_getParam('progressNum')); $runner = new Kwf_Util_Update_Runner($updates); $progress = new Zend_ProgressBar($c, 0, $runner->getProgressSteps()); $runner->setProgressBar($progress); if (!$runner->checkUpdatesSettings()) { throw new Kwf_Exception_Client("checkSettings failed, setup stopped"); } $doneNames = $runner->executeUpdates(array('refreshCache' => false)); $runner->writeExecutedUpdates($doneNames); $errors = $runner->getErrors(); if ($errors) { $errMsg = count($errors) . " setup script(s) failed:\n"; foreach ($errors as $error) { $errMsg .= $error['name'] . ": \n"; $errMsg .= $error['message'] . "\n\n"; } throw new Kwf_Exception_Client(nl2br($errMsg)); } }