public static function set($obj, $id = null, $force = false) { $tags = array(); if (!$obj instanceof ObjectModel\ObjectModelAbstract && !$obj instanceof ObjectModel\ObjectUri) { throw new Exception("no object or of unrecognized heritance"); } if (is_null($id)) { if (($obj instanceof ObjectModel\BaseObject || $obj instanceof ObjectModel\DataObject) && $obj->getUri()) { $prefix = $obj instanceof ObjectModel\BaseObject ? 'obj_' : 'do_'; $id = $prefix . md5($obj->getUri()->asString()); } else { $id = UUID::v4(); } } if ($obj instanceof ObjectModel\BaseObject) { $tags[] = ObjectModel::MODEL; } else { if ($obj instanceof ObjectModel\DataObject) { $tags[] = ObjectModel::DATA; } else { if ($obj instanceof ViewObject) { $tags[] = 'view'; } } } Core::cacheSet($obj, $id, $force, array('tags' => $tags)); return $id; }
/** * Execute the action and returns a result * * @return array */ public function execute($params = null) { if ((!isset($params[$this->queryfield]) || empty($params[$this->queryfield])) && (!isset($params[$this->queryidfield]) || empty($params[$this->queryidfield]))) { return false; } if (isset($params['_offset'])) { $this->setParameter('offset', (int) $params['_offset']); } $extra = isset($params['extra']) ? (array) $params['extra'] : array(); if (Core::getEnvData('cache_datasets') === true) { $hash = serialize($extra); $hash .= isset($params[$this->queryfield]) ? $params[$this->queryfield] : $params[$this->queryidfield]; $md5 = md5($hash); //@todo check unicity, especially with hard-coded conditions having() $ckey = 'ds_ac_' . $this->_cachePrefix . '_' . $md5 . '_' . $this->getParameter('offset') . '_' . $this->getParameter('batch'); if (($data = Core::cacheGet($ckey)) === false) { if (isset($params[$this->queryfield])) { $data = $this->_getSuggestions(trim($params[$this->queryfield]), $extra); } else { $data = $this->_getFromIdentifier(trim($params[$this->queryidfield])); } $data['cache-key'] = $ckey; Core::cacheSet($data, $ckey, true, array('tags' => array('view', 'ac', str_replace('\\', '_', $this->_obj->getClass())))); } } else { if (isset($params[$this->queryfield])) { $data = $this->_getSuggestions(trim($params[$this->queryfield]), $extra); } else { $data = $this->_getFromIdentifier(trim($params[$this->queryidfield])); } } return $data; }
/** * (non-PHPdoc) * @see \t41\ObjectModel\BaseObject::save() */ public function save(Backend\Adapter\AbstractAdapter $backend = null) { if (is_null($backend)) { $this->setKey(Core::cacheSet($this, $this->getKey(), true, array('tags' => 'session'))); return true; } else { return parent::save($backend); } }
/** * Load a file into a Configuration Array * * @param string $file * @param integer $realm * @param array $params * * @return array|false Configuration Array or false if the file don't exists */ public static function loadConfig($file, $realm = Config::REALM_CONFIGS, array $params = null) { // try to get cached version if configs caching is enabled if (Core::getEnvData('cache_configs') === true) { $ckey = self::getCacheKey($file, $realm); if (($cached = Core::cacheGet($ckey)) !== false) { Core::log(sprintf('[Config] Retrieved %s config file from cache', $file)); return $cached; } } if (($filePath = self::findFile($file, $realm)) == null) { /* no matching file name in paths */ Core::log(sprintf('[Config] Failed loading %s config file', $file), \Zend_Log::ERR); return false; } $type = substr($file, strrpos($file, '.') + 1); /* use existing adapter instance or create it */ if (!isset(self::$_adapters[$type])) { $className = sprintf('\\t41\\Config\\Adapter\\%sAdapter', ucfirst(strtolower($type))); try { self::$_adapters[$type] = new $className($filePath, $params); if (!self::$_adapters[$type] instanceof Adapter\AbstractAdapter) { throw new Exception("{$className} is not implementing AbstractAdapter."); } } catch (\Exception $e) { throw new Exception($e->getMessage()); } } else { self::$_adapters[$type]->setPath($filePath); } $config = self::$_adapters[$type]->load(); Core::log(sprintf('[Config] Successfully loaded %s config file', $file)); /* if ckey is set, cache is activated but empty */ if (isset($ckey)) { Core::cacheSet($config, $ckey, true, array('tags' => array('config'))); } return $config; }
/** * Detect all modules directories and try to get config for them * @param string $path */ public static function init($path) { if (Core::getEnvData('cache_configs') !== false) { $ckey = 'configs_acl'; if (($cached = Core::cacheGet($ckey)) !== false) { self::$_config = $cached; return; } } // load application acl configuration file $config = Config\Loader::loadConfig('acl.xml', Config::REALM_CONFIGS); $resources = array(); // add all fragments coming from modules foreach (Core\Module::getConfig() as $vendorId => $vendorModules) { foreach ($vendorModules as $key => $module) { // module menus if (isset($module['controller']) && isset($module['controller']['items'])) { // walk recursively through all module's items (menu elements) $resources += self::_getAcl($module['controller']['base'], $module['controller']['items']); } // and optional menus extensions if (isset($module['controllers_extends'])) { foreach ($module['controllers_extends'] as $controller => $data) { $resources += self::_getAcl($module['controller']['base'], $data['items']); } } } } if (!isset($config['acl']['resources'])) { $config['acl']['resources'] = array(); } $config['acl']['resources'] += $resources; self::$_config = $config['acl']; if (isset($ckey)) { Core::cacheSet($config['acl'], $ckey, true, array('tags' => array('config', 'acl'))); } }
public function register() { $res = Core::cacheSet($this); if ($res !== false) { $this->_id = $res; } return $this->_id; }
/** * Detect all modules directories and try to get config for them * @param string $path */ public static function init($path) { self::$_path = $path . 'application/modules' . DIRECTORY_SEPARATOR; if (!is_dir(self::$_path)) { return false; } // get config from cache if (Core::getEnvData('cache_configs') == "bogus") { $ckey = 'configs_modules'; if (($cached = Core::cacheGet($ckey)) !== false) { self::$_config = $cached; } } if (true) { //! self::$_config) { self::$_config = array(); self::$_modules = array('enabled' => array(), 'disabled' => array()); foreach (scandir(self::$_path) as $vendor) { if (is_dir(self::$_path . $vendor) && substr($vendor, 0, 1) != '.') { foreach (scandir(self::$_path . $vendor) as $entry) { $fpath = self::$_path . $vendor . DIRECTORY_SEPARATOR . $entry . DIRECTORY_SEPARATOR; if (is_dir($fpath) && substr($entry, 0, 1) != '.') { if (is_dir($fpath . 'configs')) { // register path with $vendor as prefix Config::addPath($fpath . 'configs', Config::REALM_MODULES, null, $vendor); } } } } } // load all detected modules configuration file $config = Config\Loader::loadConfig('module.xml', Config::REALM_MODULES); // remove useless "modules" key foreach ($config as $key => $val) { self::$_config[$key] = $val['modules']; } // cache config if cache is enabled if (isset($ckey)) { Core::cacheSet(self::$_config, $ckey); } } unset($ckey); // build menu if (Core::getEnvData('cache_configs') == "bogus") { $ckey = 'configs_menu_main'; if (($cached = Core::cacheGet($ckey)) !== false) { $menu = $cached; } } if (true) { //! isset($menu)) { $menu = new Layout\Menu('main'); $menu->setLabel('Main Menu'); foreach (self::$_config as $prefix => $modules) { foreach ($modules as $key => $module) { if ($module['enabled'] != 'true') { continue; } $path = Core::$basePath . 'application/modules' . DIRECTORY_SEPARATOR . $prefix . DIRECTORY_SEPARATOR . $key; self::bind($module, $path); // if module has controllers, declare them to front controller // then add them to main menu if (isset($module['controller']) || isset($module['controllers_extends'])) { Config::addPath($path . '/controllers/', Config::REALM_CONTROLLERS, null, $module['controller']['base']); } if (isset($module['controller'])) { $menu->addItem($module['controller']['base'], $module['controller']); } // if module extends existing controllers, declare them for inclusion at the end of the process if (isset($module['controllers_extends']) && !empty($module['controllers_extends'])) { $menu->registerExtends($module['controller']['base'], $module['controllers_extends']); } } } // process extends declaration when menu is complete $menu->proceedExtends(); if (isset($ckey)) { Core::cacheSet($menu, $ckey); } } Layout::addMenu('main', $menu); }