/** * * @param string Url as generated by Kwf_Assets_Package::getPackageUrls * @param string Kwf_Media_Output::ENCODING_* */ public static function getOutputForUrl($url, $encoding) { if (substr($url, 0, 21) != '/assets/dependencies/') { throw new Kwf_Exception("invalid url: '{$url}'"); } $url = substr($url, 21); if (strpos($url, '?') !== false) { $url = substr($url, 0, strpos($url, '?')); } if (substr($url, -4) == '.map' && !self::allowSourceAccess()) { throw new Kwf_Exception_AccessDenied(); } if ($encoding != 'none') { //own cache for encoded contents, not using Kwf_Assets_Cache as we don't need to in two-level cache $cacheId = 'as_' . self::_getCacheIdByUrl($url) . '_' . $encoding; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($ret === false) { $ret = self::_getOutputForUrlNoEncoding($url); $ret['contents'] = Kwf_Media_Output::encode($ret['contents'], $encoding); $ret['encoding'] = $encoding; Kwf_Cache_SimpleStatic::add($cacheId, $ret); } return $ret; } else { return self::_getOutputForUrlNoEncoding($url); } }
public static function getVendorProviders() { $cacheId = 'assets-vendor-providers'; $cachedProviders = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($cachedProviders === false) { $cachedProviders = array(); foreach (glob(VENDOR_PATH . "/*/*") as $i) { if (is_dir($i) && file_exists($i . '/dependencies.ini')) { $config = new Zend_Config_Ini($i . '/dependencies.ini', 'config'); if ($config->provider) { $provider = $config->provider; if (is_string($provider)) { $provider = array($provider); } foreach ($provider as $p) { $cachedProviders[] = array('cls' => $p, 'file' => $i . '/dependencies.ini'); } } } } foreach (glob(VENDOR_PATH . '/bower_components/*') as $i) { $cachedProviders[] = array('cls' => 'Kwf_Assets_Provider_BowerBuiltFile', 'file' => $i); } Kwf_Cache_SimpleStatic::add($cacheId, $cachedProviders); } $providers = array(); foreach ($cachedProviders as $p) { $cls = $p['cls']; $providers[] = new $cls($p['file']); } if (VENDOR_PATH == '../vendor') { $providers[] = new Kwf_Assets_Provider_Ini('../dependencies.ini'); } return $providers; }
public function tearDown() { Kwf_Trl::getInstance()->setWebCodeLanguage(null); Kwf_Trl::getInstance()->unsetTrlElements(); Kwf_Cache_SimpleStatic::clear('trl-'); Kwf_Cache_SimpleStatic::clear('trlp-'); parent::tearDown(); }
public function remove($cacheId) { Kwf_Cache_SimpleStatic::_delete('asb-' . $cacheId); $fileName = self::$_buildDir . '/' . $cacheId; if (file_exists($fileName)) { unlink($fileName); return true; } }
public function remove($cacheIds) { if (!is_array($cacheIds)) { $cacheIds = array($cacheIds); } $staticIds = array(); foreach ($cacheIds as $cacheId) { self::_getFileCacheInstance()->remove(str_replace('-', '_', $cacheId)); $staticIds[] = 'as-' . $cacheId; } Kwf_Cache_SimpleStatic::_delete($staticIds); }
protected function _getUseComponentId() { if (!isset($this->_useComponentId)) { $cacheId = 'useCmpId-' . $this->_class . '-' . $this->_settings['generator']; //cache to delay model creation $this->_useComponentId = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if (!$success) { $this->_useComponentId = $this->_getModel()->hasColumn('component_id'); Kwf_Cache_SimpleStatic::add($cacheId, $this->_useComponentId); } } return $this->_useComponentId; }
public static function getMasterStyles() { $cacheId = 'textMasterSyles'; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($ret !== false) { return $ret; } $package = Kwf_Assets_Package_Default::getInstance('Frontend'); $ret = array(); foreach ($package->getDependency()->getFilteredUniqueDependencies('text/css') as $dep) { $ret = array_merge($ret, self::parseMasterStyles($dep->getContentsSourceString())); } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
public static function getPrivatePart() { $salt = Kwf_Cache_SimpleStatic::fetch('hashpp-'); if (!$salt) { if ($salt = Kwf_Config::getValue('hashPrivatePart')) { //defined in config, required if multiple webservers should share the same salt } else { $hashFile = 'cache/hashprivatepart'; if (!file_exists($hashFile)) { file_put_contents($hashFile, time() . rand(100000, 1000000)); } $salt = file_get_contents($hashFile); Kwf_Cache_SimpleStatic::add('hashpp-', $salt); } } return $salt; }
public static function reload() { $configClass = Kwf_Setup::$configClass; $config = new $configClass(Kwf_Setup::getConfigSection()); $cacheId = 'config_' . str_replace(array('-', '.'), '_', Kwf_Setup::getConfigSection()); Kwf_Config_Cache::getInstance()->save($config, $cacheId); if (extension_loaded('apc')) { $apcCacheId = $cacheId . getcwd(); apc_delete($apcCacheId); apc_delete($apcCacheId . 'mtime'); if (PHP_SAPI == 'cli') { Kwf_Util_Apc::callClearCacheByCli(array(array('cacheIds' => $apcCacheId . ',' . $apcCacheId . 'mtime'))); } Kwf_Cache_SimpleStatic::clear('config-'); } Kwf_Config_Web::clearInstances(); Kwf_Registry::set('config', $config); }
protected function _getConfig() { $ret = parent::_getConfig(); $cacheId = 'extConfig_multiFileUpload_' . $this->_class; $multiFileUpload = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if (!$success) { $multiFileUpload = false; $form = Kwc_Abstract_Form::createChildComponentForm($this->_class, 'child'); if ($form && ($field = $this->_getFileUploadField($form))) { $multiFileUpload = array('allowOnlyImages' => $field->getAllowOnlyImages(), 'maxResolution' => $field->getMaxResolution(), 'maxResolution' => $field->getMaxResolution(), 'fileSizeLimit' => $field->getFileSizeLimit()); } Kwf_Cache_SimpleStatic::add($cacheId, $multiFileUpload); } $ret['list']['multiFileUpload'] = $multiFileUpload; $ret['list']['maxEntries'] = Kwc_Abstract::getSetting($this->_class, 'maxEntries'); $ret['list']['maxEntriesErrorMessage'] = trlKwf("Can't create more than {0} entries.", $ret['list']['maxEntries']); return $ret; }
protected static function _getAllPaths() { static $paths; if (!isset($paths)) { $cacheId = 'assets-file-paths'; $paths = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($paths === false) { $paths = array('webComponents' => 'components', 'webThemes' => 'themes'); $vendors[] = KWF_PATH; //required for kwf tests, in web kwf is twice in $vendors but that's not a problem $vendors[] = '.'; $vendors = array_merge($vendors, glob(VENDOR_PATH . "/*/*")); foreach ($vendors as $i) { if (is_dir($i) && file_exists($i . '/dependencies.ini')) { $c = new Zend_Config_Ini($i . '/dependencies.ini'); if ($c->config) { $dep = new Zend_Config_Ini($i . '/dependencies.ini', 'config'); $pathType = (string) $dep->pathType; if ($pathType) { $paths[$pathType] = $i; } } } } foreach (glob(VENDOR_PATH . '/bower_components/*') as $i) { $type = substr($i, strlen(VENDOR_PATH . '/bower_components/')); if (substr($type, -3) == '.js') { $type = substr($type, 0, -3); } if (substr($type, -2) == 'js') { $paths[$type] = $i; $type = substr($type, 0, -2); } $paths[$type] = $i; } $paths['web'] = '.'; Kwf_Cache_SimpleStatic::add($cacheId, $paths); } } return $paths; }
public function getCartComponentClass() { if ($this->_cartComponentClass) { return $this->_cartComponentClass; } $cacheId = 'kwc-shop-cart-default-cc'; if (!($ret = Kwf_Cache_SimpleStatic::fetch($cacheId))) { $classes = array(); foreach (Kwc_Abstract::getComponentClasses() as $c) { if (is_instance_of($c, 'Kwc_Shop_Cart_Component')) { $classes[] = $c; } } if (count($classes) != 1) { throw new Kwf_Exception("Not exactly one Kwc_Shop_Cart_Component found, set _cartComponentClass manually"); } $ret = $classes[0]; Kwf_Cache_SimpleStatic::add($cacheId, $ret); $this->_cartComponentClass = $ret; } return $ret; }
private function _fireTagEvent($event, $directory, $itemId = null) { $cacheId = 'kwc-dirlistview-isdata-' . $this->_class; $dirIs = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($dirIs === false) { $dirIs = array('data' => false, 'string' => false); foreach (Kwc_Abstract::getComponentClasses() as $class) { if (in_array('Kwc_Directories_List_Component', Kwc_Abstract::getParentClasses($class)) || in_array('Kwc_Directories_List_Trl_Component', Kwc_Abstract::getParentClasses($class))) { if (Kwc_Abstract::hasChildComponentClass($class, 'child', 'view') && $this->_class == Kwc_Abstract::getChildComponentClass($class, 'child', 'view')) { $isData = call_user_func(array(strpos($class, '.') ? substr($class, 0, strpos($class, '.')) : $class, 'getItemDirectoryIsData'), $class); if ($isData) { $dirIs['data'] = true; } else { $dirIs['string'] = true; } } } } Kwf_Cache_SimpleStatic::add($cacheId, $dirIs); } $event = "Kwf_Component_Event_ComponentClass_Tag_{$event}"; if ($itemId) { if ($dirIs['data']) { $this->fireEvent(new $event($this->_class, $directory->componentId, $itemId)); } if ($dirIs['string']) { $this->fireEvent(new $event($this->_class, $directory->componentClass, $itemId)); } } else { if ($dirIs['data']) { $this->fireEvent(new $event($this->_class, $directory->componentId)); } if ($dirIs['string']) { $this->fireEvent(new $event($this->_class, $directory->componentClass)); } } }
public static function dispatchUtils() { if ($_POST['password'] != self::_getHttpPassword()) { throw new Kwf_Exception_AccessDenied(); } $uri = $_SERVER['REQUEST_URI']; $baseUrl = Kwf_Setup::getBaseUrl(); if ($baseUrl && substr($uri, 0, strlen($baseUrl)) == $baseUrl) { $uri = substr($uri, strlen($baseUrl)); } if (substr($uri, 0, 25) == '/kwf/util/apc/clear-cache') { $s = microtime(true); if (isset($_REQUEST['deleteCacheSimple'])) { foreach (explode(',', $_REQUEST['deleteCacheSimple']) as $id) { Kwf_Cache_Simple::delete($id); } } if (isset($_REQUEST['clearCacheSimpleStatic'])) { foreach (explode(',', $_REQUEST['clearCacheSimpleStatic']) as $id) { Kwf_Cache_SimpleStatic::clear($id); } } if (isset($_REQUEST['deleteCacheSimpleStatic'])) { foreach (explode(',', $_REQUEST['deleteCacheSimpleStatic']) as $id) { Kwf_Cache_SimpleStatic::delete($id); } } if (isset($_REQUEST['cacheIds'])) { foreach (explode(',', $_REQUEST['cacheIds']) as $cacheId) { apc_delete($cacheId); } } if (isset($_REQUEST['files']) && function_exists('apc_delete_file')) { foreach (explode(',', $_REQUEST['files']) as $file) { @apc_delete_file($file); } } else { if (isset($_REQUEST['type']) && $_REQUEST['type'] == 'user') { if (extension_loaded('apcu')) { apc_clear_cache(); } else { apc_clear_cache('user'); } } else { if (!extension_loaded('apcu')) { apc_clear_cache('file'); } } } echo 'OK ' . round((microtime(true) - $s) * 1000) . ' ms'; exit; } else { if (substr($uri, 0, 24) == '/kwf/util/apc/save-cache') { $data = unserialize($_REQUEST['data']); if (apc_store($_REQUEST['id'], $data)) { echo 'OK'; } else { echo 'ERROR'; } exit; } else { if (substr($uri, 0, 31) == '/kwf/util/apc/get-counter-value') { $prefix = Kwf_Cache::getUniquePrefix() . 'bench-'; echo apc_fetch($prefix . $_GET['name']); exit; } else { if ($uri == '/kwf/util/apc/stats') { self::stats(); } else { if ($uri == '/kwf/util/apc/iterate') { self::iterate(); } else { if ($uri == '/kwf/util/apc/is-loaded') { if (extension_loaded('apc')) { echo 'OK1'; } else { echo 'OK0'; } exit; } else { if ($uri == '/kwf/util/apc/get-hostname') { echo php_uname('n'); exit; } } } } } } } throw new Kwf_Exception_NotFound(); }
private static function _clearAssetsAll($fileType = null) { if (!$fileType) { self::_clearAssetsAll('js'); self::_clearAssetsAll('defer.js'); self::_clearAssetsAll('css'); self::_clearAssetsAll('printcss'); return; } $fileNames = array('cache/assets/output-cache-ids-' . $fileType, 'build/assets/output-cache-ids-' . $fileType); foreach ($fileNames as $fileName) { if (file_exists($fileName)) { $cacheIds = file($fileName); unlink($fileName); foreach ($cacheIds as $cacheId) { $cacheId = trim($cacheId); echo $cacheId; if (Kwf_Assets_Cache::getInstance()->remove($cacheId)) { echo " [DELETED]"; } if (Kwf_Assets_BuildCache::getInstance()->remove($cacheId)) { echo " [build DELETED]"; } if (Kwf_Cache_SimpleStatic::_delete(array('as_' . $cacheId . '_gzip', 'as_' . $cacheId . '_deflate'))) { echo " [gzip DELETED]"; } if (Kwf_Assets_Cache::getInstance()->remove($cacheId . '_map')) { echo " [map DELETED]"; } if (Kwf_Assets_BuildCache::getInstance()->remove($cacheId . '_map')) { echo " [build map DELETED]"; } if (Kwf_Cache_SimpleStatic::_delete(array('as_' . $cacheId . '_map_gzip', 'as_' . $cacheId . '_map_deflate'))) { echo " [map_gzip DELETED]"; } echo "\n"; } } } $fileName = 'build/assets/package-max-mtime-' . $fileType; if (file_exists($fileName)) { $cacheIds = file($fileName); unlink($fileName); foreach ($cacheIds as $cacheId) { $cacheId = trim($cacheId); echo $cacheId; if (Kwf_Assets_BuildCache::getInstance()->remove($cacheId)) { echo " [DELETED]"; } echo "\n"; } } $a = new Kwf_Util_Build_Types_Assets(); $a->flagAllPackagesOutdated($fileType); self::_informDuckcast($fileType); }
public function getPathTypes() { if (isset($this->_pathTypesCache)) { return $this->_pathTypesCache; } if (isset($this->_pathTypesCacheId)) { $ret = Kwf_Cache_SimpleStatic::fetch($this->_pathTypesCacheId); if ($ret !== false) { $this->_pathTypesCache = $ret; return $ret; } } $ret = array('webComponents' => 'components', 'webThemes' => 'themes'); $vendors[] = KWF_PATH; //required for kwf tests, in web kwf is twice in $vendors but that's not a problem $vendors[] = '.'; $vendors = array_merge($vendors, glob(VENDOR_PATH . "/*/*")); foreach ($vendors as $i) { if (is_dir($i) && file_exists($i . '/dependencies.ini')) { $c = new Zend_Config_Ini($i . '/dependencies.ini'); if ($c->config) { $dep = new Zend_Config_Ini($i . '/dependencies.ini', 'config'); $pathType = (string) $dep->pathType; if ($pathType) { $ret[$pathType] = $i; } } } } foreach ($this->_providers as $p) { $ret = array_merge($ret, $p->getPathTypes()); } $ret['web'] = '.'; Kwf_Cache_SimpleStatic::add($this->_pathTypesCacheId, $ret); $this->_pathTypesCache = $ret; return $ret; }
public static function getComponentTemplate($componentClass, $type = 'Component') { $cacheId = 'twig-cmp-' . $componentClass . '-' . $type; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($ret !== false) { return $ret; } $file = null; if ($type == 'Master' && Kwc_Abstract::hasSetting($componentClass, 'masterTemplate') && Kwc_Abstract::getSetting($componentClass, 'masterTemplate')) { $relativeToIncludePath = Kwc_Abstract::getSetting($componentClass, 'masterTemplate'); } else { static $namespaces; if (!isset($namespaces)) { $namespaces = (include VENDOR_PATH . '/composer/autoload_namespaces.php'); } $pos = strpos($componentClass, '_'); $ns1 = substr($componentClass, 0, $pos + 1); $pos = strpos($componentClass, '_', $pos + 1); if ($pos !== false) { $ns2 = substr($componentClass, 0, $pos + 1); } else { $ns2 = $componentClass; } $relativeToIncludePath = $componentClass; if (substr($relativeToIncludePath, -10) == '_Component') { $relativeToIncludePath = substr($relativeToIncludePath, 0, -10); } $relativeToIncludePath .= '_' . $type; $relativeToIncludePath = str_replace('_', '/', $relativeToIncludePath) . '.twig'; $dirs = false; if (isset($namespaces[$ns2])) { $dirs = $namespaces[$ns2]; } else { if (isset($namespaces[$ns1])) { $dirs = $namespaces[$ns1]; } } if ($dirs !== false) { if (count($dirs) == 1) { $file = $dirs[0] . '/' . $relativeToIncludePath; } else { foreach ($dirs as $dir) { if (file_exists($dir . '/' . $relativeToIncludePath)) { $dir = rtrim($dir, '/'); if (VENDOR_PATH == '../vendor') { //hack for tests. proper solution would be not to change cwd into /tests if ($dir == KWF_PATH) { $dir = '..'; } } $file = $dir . '/' . $relativeToIncludePath; break; } } } } } if ($file) { $ret = $file; } else { $ret = null; foreach (explode(PATH_SEPARATOR, get_include_path()) as $ip) { $file = $ip . '/' . $relativeToIncludePath; if (file_exists(getcwd() . '/' . $file)) { $ret = getcwd() . '/' . $file; break; } } if (!$ret) { throw new Kwf_Exception("Can't find {$type} template for {$componentClass} {$relativeToIncludePath}"); } } if (VENDOR_PATH == '../vendor') { $cwd = getcwd(); $cwd = substr($cwd, 0, strrpos($cwd, '/')); if (substr($ret, 0, strlen($cwd)) != $cwd) { throw new Kwf_Exception("'{$ret}' not in cwd"); } $ret = '../' . substr($ret, strlen($cwd) + 1); } else { if (substr($ret, 0, strlen(getcwd())) != getcwd()) { throw new Kwf_Exception("'{$ret}' not in cwd"); } $ret = substr($ret, strlen(getcwd()) + 1); } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
public static function fireEvent($event) { $logger = Kwf_Events_Log::getInstance(); if ($logger && $logger->indent == 0) { $logger->info('----'); $logger->resetTimer(); } $class = $event->class; $eventClass = get_class($event); $cacheId = '-ev-lst-' . Kwf_Component_Data_Root::getComponentClass() . '-' . $eventClass . '-' . $class; $callbacks = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($callbacks === false) { $listeners = self::getAllListeners(); $callbacks = array(); if ($class && isset($listeners[$eventClass][$class])) { $callbacks = $listeners[$eventClass][$class]; } if (isset($listeners[$eventClass]['all'])) { $callbacks = array_merge($callbacks, $listeners[$eventClass]['all']); } Kwf_Cache_SimpleStatic::add($cacheId, $callbacks); } if ($logger) { $logger->info($event->__toString() . ':'); $logger->indent++; } static $callbackBenchmark = array(); foreach ($callbacks as $callback) { $ev = call_user_func(array($callback['class'], 'getInstance'), $callback['class'], $callback['config']); if ($logger) { $msg = '-> ' . $callback['class'] . '::' . $callback['method'] . '(' . Kwf_Debug::_btArgsString($callback['config']) . ')'; $logger->info($msg . ':'); $start = microtime(true); } $ev->{$callback['method']}($event); if ($logger) { if (!isset($callbackBenchmark[$callback['class'] . '::' . $callback['method']])) { $callbackBenchmark[$callback['class'] . '::' . $callback['method']] = array('calls' => 0, 'time' => 0); } $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['calls']++; $callbackBenchmark[$callback['class'] . '::' . $callback['method']]['time'] += (microtime(true) - $start) * 1000; //ATM includes everything which is missleading } } if ($logger) { $logger->indent--; if ($logger->indent == 0) { foreach ($callbackBenchmark as $cb => $i) { $logger->info(sprintf("% 3d", $i['calls']) . "x " . sprintf("%3d", round($i['time'], 0)) . " ms: {$cb}"); } $callbackBenchmark = array(); } } self::$eventsCount++; }
/** * Returns child components recursively * * This method usually is very efficient and tries to create as less data objects as possible. * It is still a complex operation thus should not get called too often. * * @param Kwf_Component_Select|array what to search for * @param Kwf_Component_Select|array how deep to search * @return array(Kwf_Component_Data) */ public function getRecursiveChildComponents($select = array(), $childSelect = array('page' => false)) { if (is_array($select)) { $select = new Kwf_Component_Select($select); } else { $select = clone $select; } Kwf_Benchmark::count('getRecursiveChildComponents'); if (is_array($childSelect)) { $childSelect = new Kwf_Component_Select($childSelect); } $ret = $this->getChildComponents($select); if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } $genSelect = new Kwf_Component_Select(); $genSelect->copyParts(array(Kwf_Component_Select::WHERE_HOME, Kwf_Component_Select::WHERE_PAGE, Kwf_Component_Select::WHERE_PSEUDO_PAGE, Kwf_Component_Select::WHERE_FLAGS, Kwf_Component_Select::WHERE_BOX, Kwf_Component_Select::WHERE_MULTI_BOX, Kwf_Component_Select::WHERE_SHOW_IN_MENU, Kwf_Component_Select::WHERE_COMPONENT_CLASSES, Kwf_Component_Select::WHERE_PAGE_GENERATOR, Kwf_Component_Select::WHERE_GENERATOR, Kwf_Component_Select::WHERE_HAS_EDIT_COMPONENTS, Kwf_Component_Select::WHERE_INHERIT, Kwf_Component_Select::WHERE_UNIQUE, Kwf_Component_Select::WHERE_GENERATOR_CLASS, Kwf_Component_Select::WHERE_COMPONENT_KEY), $select); $selectHash = md5($genSelect->getHash() . $childSelect->getHash()); $cacheId = 'recCCGen-' . $selectHash . $this->componentClass . implode('__', $this->inheritClasses); $generators = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if (!$success) { //get (statically=fast and cached) all generators that could create the component we are looking for $generators = $this->_getRecursiveGenerators(Kwc_Abstract::getChildComponentClasses($this, $childSelect), $genSelect, $childSelect, $selectHash); Kwf_Cache_SimpleStatic::add($cacheId, $generators); } $noSubPages = $childSelect->hasPart('wherePage') && !$childSelect->getPart('wherePage') || $childSelect->hasPart('wherePseudoPage') && !$childSelect->getPart('wherePseudoPage'); if ($noSubPages) { $select->whereChildOf($this); } else { $select->whereSubroot($this); } foreach ($generators as $g) { if ($g['type'] == 'notStatic') { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key']); $s = clone $select; if (!$noSubPages) { //unset limit as we may have filter away results $s->unsetPart('limitCount'); } foreach ($gen->getChildData(null, $s) as $d) { $add = true; if (!$noSubPages) { // sucht über unterseiten hinweg, wird hier erst im Nachhinein gehandelt, langsam $add = false; $c = $d; while (!$add && $c) { if ($c->componentId == $this->componentId) { $add = true; } $c = $c->parent; } } if ($add && !in_array($d, $ret, true)) { $ret[] = $d; if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } } } } } foreach ($generators as $k => $g) { if ($g['type'] == 'cards') { $lookingForDefault = true; if ($select->hasPart('whereComponentClasses')) { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']); $classes = array_values($gen->getChildComponentClasses()); $defaultCardClass = $classes[0]; if (!in_array($defaultCardClass, $select->getPart('whereComponentClasses'))) { $lookingForDefault = false; } } if ($lookingForDefault) { //we have to look for it like for a static component because it's the default value that might not be in the table //this is not so efficient $generators[$k]['type'] = 'static'; //(kind of hackish to change the type here but works for now) } else { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']); foreach ($gen->getChildData(null, clone $select) as $d) { $ret[] = $d; if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } } } } } $staticGeneratorComponentClasses = array(); foreach ($generators as $k => $g) { if ($g['type'] == 'static') { if ($g['pluginBaseComponentClass']) { $staticGeneratorComponentClasses[] = $g['pluginBaseComponentClass']; } else { $staticGeneratorComponentClasses[] = $g['class']; } } } if ($staticGeneratorComponentClasses) { $pdSelect = clone $childSelect; $pdSelect->whereComponentClasses($staticGeneratorComponentClasses); $pdSelect->copyParts(array('ignoreVisible'), $select); $pd = $this->getRecursiveChildComponents($pdSelect, $childSelect); foreach ($generators as $k => $g) { if ($g['type'] == 'static') { $parentDatas = array(); foreach ($pd as $d) { if ($d->componentClass == $g['class'] || $d->componentClass == $g['pluginBaseComponentClass']) { $parentDatas[] = $d; } } if ($parentDatas) { $gen = Kwf_Component_Generator_Abstract::getInstance($g['class'], $g['key'], array(), $g['pluginBaseComponentClass']); foreach ($gen->getChildData($parentDatas, $select) as $d) { if (!in_array($d, $ret, true)) { $ret[] = $d; if ($select->hasPart('limitCount') && $select->getPart('limitCount') <= count($ret)) { return $ret; } } } } } } } return $ret; }
public static function getFlag($class, $flag) { $cacheId = 'flag-' . $class . '-' . $flag; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if ($success) { return $ret; } $flags = self::getSetting($class, 'flags'); if (!isset($flags[$flag])) { $ret = false; } else { $ret = $flags[$flag]; } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
/** * @param array possible options: types(=all), output(=false), excludeTypes */ public final function build(array $options) { $typeNames = $options['types']; $output = isset($options['output']) ? $options['output'] : false; $excludeTypes = isset($options['excludeTypes']) ? $options['excludeTypes'] : array(); Kwf_Cache_SimpleStatic::disableFileCache(); Kwf_Events_ModelObserver::getInstance()->disable(); Kwf_Util_MemoryLimit::set(1024 * 2); Kwf_Registry::set('db', false); if ($typeNames == 'all') { $types = $this->getTypes(); } else { if (!is_array($typeNames)) { $typeNames = explode(',', $typeNames); } $types = array(); foreach ($this->getTypes() as $t) { if (in_array($t->getTypeName(), $typeNames)) { $types[] = $t; } } } if (is_string($excludeTypes)) { $excludeTypes = explode(',', $excludeTypes); } foreach ($types as $k => $i) { if (in_array($i->getTypeName(), $excludeTypes)) { unset($types[$k]); } } $maxTypeNameLength = 0; $countSteps = 0; foreach ($types as $type) { $type->setVerbosity($output ? Kwf_Util_Build_Types_Abstract::VERBOSE : Kwf_Util_Build_Types_Abstract::SILENT); $maxTypeNameLength = max($maxTypeNameLength, strlen($type->getTypeName())); $countSteps++; } $progress = null; if (isset($options['progressAdapter'])) { $progress = new Zend_ProgressBar($options['progressAdapter'], 0, $countSteps); } if (!file_exists('build')) { mkdir('build'); } $currentStep = 0; foreach ($types as $type) { $currentStep++; if ($progress) { $progress->next(1, "building " . $type->getTypeName()); } if ($output) { echo "[" . str_repeat(' ', 2 - strlen($currentStep)) . "{$currentStep}/{$countSteps}] "; echo "building " . $type->getTypeName() . "..." . str_repeat('.', $maxTypeNameLength - strlen($type->getTypeName())) . " "; } $t = microtime(true); $type->build($options); if ($output) { if ($type->getSuccess()) { echo "[00;32mOK[00m"; } else { echo " [[01;31mERROR[00m]"; return false; } echo " (" . round((microtime(true) - $t) * 1000) . "ms)"; echo "\n"; } } Kwf_Events_ModelObserver::getInstance()->enable(); return $types; }
private function _getGeneratorsForClasses($lookingForClasses) { $cacheId = 'genForCls' . $this->getComponentClass() . str_replace('.', '_', implode('', $lookingForClasses)); if (isset($this->_generatorsForClassesCache[$cacheId])) { } else { if (($generators = Kwf_Cache_SimpleStatic::fetch($cacheId)) !== false) { $ret = array(); foreach ($generators as $g) { $ret[] = Kwf_Component_Generator_Abstract::getInstance($g[0], $g[1]); } $this->_generatorsForClassesCache[$cacheId] = $ret; } else { $generators = array(); foreach (Kwc_Abstract::getComponentClasses() as $c) { foreach (Kwc_Abstract::getSetting($c, 'generators') as $key => $generator) { foreach ($generator['component'] as $childClass) { if (in_array($childClass, $lookingForClasses)) { $generators[$c . $key] = array($c, $key); } } } } $generators = array_values($generators); Kwf_Cache_SimpleStatic::add($cacheId, $generators); $ret = array(); foreach ($generators as $g) { $ret[] = Kwf_Component_Generator_Abstract::getInstance($g[0], $g[1]); } $this->_generatorsForClassesCache[$cacheId] = $ret; } } return $this->_generatorsForClassesCache[$cacheId]; }
public function remove($cacheId) { Kwf_Cache_SimpleStatic::_delete('as-' . $cacheId); return self::_getSlowCache()->remove(str_replace('-', '_', $cacheId)); }
private function _getIconAndType() { $icon = $this->_icon; $type = $this->_type; if (!$type) { static $paths; if (!isset($paths)) { $cacheId = 'asset-paths'; $paths = Kwf_Cache_SimpleStatic::fetch($cacheId); if ($paths === false) { $paths = array('web' => '.'); $vendors = glob(VENDOR_PATH . "/*/*"); $vendors[] = KWF_PATH; //required for kwf tests, in web kwf is twice in $vendors but that's not a problem foreach ($vendors as $i) { if (is_dir($i) && file_exists($i . '/dependencies.ini')) { $dep = new Zend_Config_Ini($i . '/dependencies.ini', 'config'); $paths[$dep->pathType] = $i; } } Kwf_Cache_SimpleStatic::add($cacheId, $paths); } } if (file_exists($paths['silkicons'] . '/' . $icon)) { $filename = $paths['silkicons'] . '/' . $icon; $type = 'silkicons'; } else { if (file_exists($paths['silkicons'] . '/' . $icon . '.png')) { $filename = $paths['silkicons'] . '/' . $icon . '.png'; $type = 'silkicons'; $icon .= '.png'; } else { if (file_exists($paths['kwf'] . '/images/' . $icon . '.png')) { $filename = $paths['kwf'] . '/images/' . $icon . '.png'; $type = 'kwf/images'; $icon .= '.png'; } else { if (file_exists($paths['kwf'] . '/images/' . $icon . '.gif')) { $filename = $paths['kwf'] . '/images/' . $icon . '.gif'; $type = 'kwf/images'; $icon .= '.gif'; } else { if (file_exists($paths['kwf'] . '/images/' . $icon . '.jpg')) { $filename = $paths['kwf'] . '/images/' . $icon . '.jpg'; $type = 'kwf/images'; $icon .= '.jpg'; } else { if (file_exists($paths['kwf'] . '/images/fileicons/' . $icon . '.png')) { $filename = $paths['kwf'] . '/images/fileicons/' . $icon . '.png'; $type = 'kwf/images/fileicons'; $icon .= '.png'; } else { if (file_exists($paths['kwf'] . '/images/fileicons/' . $icon . '.jpg')) { $filename = $paths['kwf'] . '/images/fileicons/' . $icon . '.jpg'; $type = 'kwf/images/fileicons'; $icon .= '.jpg'; } else { if (file_exists($paths['web'] . '/images/icons/' . $icon)) { $filename = $paths['web'] . '/images/icons/' . $icon; $type = 'web/images/icons/'; } else { if (file_exists($paths['web'] . '/images/icons/' . $icon . '.png')) { $filename = $paths['web'] . '/images/icons/' . $icon; $type = 'web/images/icons/'; $icon .= '.png'; } else { throw new Kwf_Exception("Asset '{$icon}' not found"); } } } } } } } } } } return array('type' => $type, 'icon' => $icon); }
/** * Returns componentClasses that match a given class in their inheritance chain * * Fast, as the result is static and will be cached * * @param string * @return string[] */ public static function getComponentClassesByParentClass($class) { if (!is_array($class)) { $class = array($class); } static $prefix; $cacheId = 'cclsbpc-' . implode('-', $class); $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if ($success) { return $ret; } $ret = array(); foreach (Kwc_Abstract::getComponentClasses() as $c) { if (in_array($c, $class) || in_array(strpos($c, '.') ? substr($c, 0, strpos($c, '.')) : $c, $class)) { $ret[] = $c; continue; } foreach (Kwc_Abstract::getParentClasses($c) as $p) { if (in_array($p, $class)) { $ret[] = $c; break; } } } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
private static function _clearAssetsAll($fileType = null) { if (!$fileType) { self::_clearAssetsAll('js'); self::_clearAssetsAll('css'); return; } $fileNames = array('cache/assets/output-cache-ids-' . $fileType, 'build/assets/output-cache-ids-' . $fileType); $assetsCacheIds = array(); $assetsBuildCacheIds = array(); $simpleStaticCacheIds = array(); foreach ($fileNames as $fileName) { if (file_exists($fileName)) { $cacheIds = file($fileName); unlink($fileName); foreach ($cacheIds as $cacheId) { $cacheId = trim($cacheId); echo $cacheId . "\n"; $assetsCacheIds[] = $cacheId; $assetsBuildCacheIds[] = $cacheId; $simpleStaticCacheIds[] = 'as_' . $cacheId . '_gzip'; $simpleStaticCacheIds[] = 'as_' . $cacheId . '_deflate'; $assetsCacheIds[] = $cacheId . '_map'; $assetsBuildCacheIds[] = $cacheId . '_map'; $simpleStaticCacheIds[] = 'as_' . $cacheId . '_map_gzip'; $simpleStaticCacheIds[] = 'as_' . $cacheId . '_map_deflate'; } } } if ($assetsCacheIds) { Kwf_Assets_Cache::getInstance()->remove($assetsCacheIds); } if ($assetsBuildCacheIds) { Kwf_Assets_BuildCache::getInstance()->remove($assetsBuildCacheIds); } if ($simpleStaticCacheIds) { Kwf_Cache_SimpleStatic::_delete($simpleStaticCacheIds); } $a = new Kwf_Util_Build_Types_Assets(); $a->flagAllPackagesOutdated($fileType); self::_informDuckcast($fileType); if ($fileType == 'css') { self::_clearAssetsAll('0.css'); self::_clearAssetsAll('1.css'); self::_clearAssetsAll('ie8.css'); } if ($fileType == 'js') { self::_clearAssetsAll('defer.js'); } }
public function getTemplateVars() { $ret = Kwc_Abstract::getTemplateVars(); $this->_checkWasProcessed(); $ret['isPosted'] = $this->_posted; $ret['showSuccess'] = false; $ret['errors'] = Kwf_Form::formatValidationErrors($this->getErrors()); if ($this->isSaved()) { if (!$ret['errors'] && $this->getSuccessComponent()) { $ret['showSuccess'] = true; } } if ($ret['showSuccess']) { $ret['success'] = $this->getSuccessComponent(); } else { foreach ($this->getData()->getChildComponents(array('generator' => 'child')) as $c) { if ($c->id != 'success') { $ret[$c->id] = $c; } } } if (!$ret['showSuccess']) { $values = $this->getForm()->load(null, $this->_postData); $ret['form'] = $this->getForm()->getTemplateVars($values, '', $this->getData()->componentId . '_'); $dec = $this->_getSetting('decorator'); if ($dec && is_string($dec)) { $dec = new $dec(); $ret['form'] = $dec->processItem($ret['form'], $this->getErrors()); } $ret['formName'] = $this->getData()->componentId; $ret['buttonClass'] = $this->_getSetting('buttonClass'); $ret['formId'] = $this->getForm()->getId(); if ($ret['formId']) { $ret['formIdHash'] = Kwf_Util_Hash::hash($ret['formId']); } $page = $this->getData()->getPage(); if (!$page) { throw new Kwf_Exception('Form must have an url so it must be on a page but is on "' . $this->getData()->componentId . '". (If component is a box it must not be unique)'); } $cachedContent = Kwf_Component_Cache::getInstance()->load($page->componentId, 'componentLink'); if ($cachedContent) { $targetPage = unserialize($cachedContent); $ret['action'] = $targetPage[0]; } else { $ret['action'] = $this->getData()->url; } if (isset($_SERVER["QUERY_STRING"])) { $ret['action'] .= '?' . $_SERVER["QUERY_STRING"]; } $ret['method'] = $this->_getSetting('method'); } $ret['isUpload'] = false; foreach (new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->getForm()->fields)) as $f) { if ($f instanceof Kwf_Form_Field_File) { $ret['isUpload'] = true; break; } } $ret['message'] = null; $cacheId = 'kwcFormCu-' . get_class($this); $controllerUrl = Kwf_Cache_SimpleStatic::fetch($cacheId); if (!$controllerUrl) { $controllerUrl = Kwc_Admin::getInstance(get_class($this))->getControllerUrl('FrontendForm'); Kwf_Cache_SimpleStatic::add($cacheId, $controllerUrl); } $hideForValue = array(); foreach ($this->_form->getHideForValue() as $v) { $hideForValue[] = array('field' => $v['field']->getFieldName(), 'value' => $v['value'], 'hide' => $v['hide']->getFieldName()); } $baseParams = $this->_getBaseParams(); $baseParams['componentId'] = $this->getData()->componentId; $fieldConfig = array(); $iterator = new RecursiveIteratorIterator(new Kwf_Collection_Iterator_RecursiveFormFields($this->_form->fields), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $field) { if ($field->getFieldName()) { $fieldConfig[$field->getFieldName()] = (object) $field->getFrontendMetaData(); } } $errorStyle = $this->_getSetting('errorStyle'); if (!$errorStyle) { $errorStyle = Kwf_Config::getValue('kwc.form.errorStyle'); } $ret['config'] = array('controllerUrl' => $controllerUrl, 'useAjaxRequest' => $this->_getSetting('useAjaxRequest'), 'hideFormOnSuccess' => $this->_getSetting('hideFormOnSuccess'), 'componentId' => $this->getData()->componentId, 'hideForValue' => $hideForValue, 'fieldConfig' => (object) $fieldConfig, 'errorStyle' => $errorStyle, 'baseParams' => $baseParams); $ret['uniquePrefix'] = Kwf_Config::getValue('application.uniquePrefix'); if ($ret['uniquePrefix']) { $ret['uniquePrefix'] .= '-'; } return $ret; }
/** * @internal * * Delete the config cache for one variable. Needed for some tests. */ public static function deleteValueCache($var) { Kwf_Cache_SimpleStatic::_delete('config-' . $var); Kwf_Cache_SimpleStatic::_delete('configAr-' . $var); }
/** * Helper function that returns the dbIdShortcuts that can be used below a componentClass (only across page) * * Static, fast and cached. */ protected function _getPossibleIndirectDbIdShortcuts($class) { $cacheId = '-poss-dbid-sc-' . $this->_class . '-' . $this->getGeneratorKey() . '-' . $class; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if (!$success) { $ret = $this->_getPossibleIndirectDbIdShortcutsImpl($class); $ret = array_unique($ret); Kwf_Cache_SimpleStatic::add($cacheId, $ret); } return $ret; }
public static final function getDependsOnRowInstances() { $ret = array(); $cacheId = 'componentsWithDependsOnRow'; if (!($componentsWithDependsOnRow = Kwf_Cache_SimpleStatic::fetch($cacheId))) { $componentsWithDependsOnRow = array(); foreach (Kwc_Abstract::getComponentClasses() as $c) { $a = Kwc_Admin::getInstance($c); if ($a instanceof Kwf_Component_Abstract_Admin_Interface_DependsOnRow) { $componentsWithDependsOnRow[] = $c; } } Kwf_Cache_SimpleStatic::add($cacheId, $componentsWithDependsOnRow); } foreach ($componentsWithDependsOnRow as $c) { $ret[] = Kwc_Admin::getInstance($c); } return $ret; }