/** * 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(); if (!App_Filesystem_Folder::exists($options['page']['backend']['options']['cache_dir'])) { if (App_Filesystem_Folder::create($options['page']['backend']['options']['cache_dir'])) { $getout = fopen($options['page']['backend']['options']['cache_dir'] . "/index.html", "w") or die("Unable to open file!"); fwrite($getout, "Get out\n"); fclose($getout); } else { } } if (!App_Filesystem_Folder::exists($options['database']['backend']['options']['cache_dir'])) { if (App_Filesystem_Folder::create($options['database']['backend']['options']['cache_dir'])) { $getout = fopen($options['database']['backend']['options']['cache_dir'] . "/index.html", "w") or die("Unable to open file!"); fwrite($getout, "Get out\n"); fclose($getout); } else { } } foreach ($options as $key => $value) { if ($this->_manager->hasCacheTemplate($key)) { $this->_manager->setTemplateOptions($key, $value); } else { $this->_manager->setCacheTemplate($key, $value); } } } return $this->_manager; }
/** * Write contents to a file * * @param string $file The full file path * @param string &$buffer The buffer to write * @param boolean $use_streams Use streams * * @return boolean True on success * * @since 11.1 */ public static function write($file, &$buffer, $use_streams = false) { @set_time_limit(ini_get('max_execution_time')); if (Zend_Registry::isRegistered('logger')) { $logger = Zend_Registry::get('logger'); } // If the destination directory doesn't exist we need to create it if (!file_exists(dirname($file))) { if (App_Filesystem_Folder::create(dirname($file)) == false) { return false; } } if ($use_streams) { $stream = new App_Filesystem_Stream(); // Beef up the chunk size to a meg $stream->set('chunksize', 1024 * 1024); if (!$stream->writeFile($file, $buffer)) { $logger->getLog('filesystem')->log(sprintf(__METHOD__ . ': :write(%1$s): %2$s', $file, $stream->getError()), Zend_Log::WARN); return false; } return true; } else { $file = App_Filesystem_Path::clean($file); return is_int(file_put_contents($file, $buffer)) ? true : false; } }
/** * Initialize log * * @param string $key * @return Zend_Log * * * @links: * - https://ranskills.wordpress.com/2012/03/18/creating-dynamic-log-files-in-zend-framework-zf/ */ protected function _initLog($key) { $logOptions = $this->_options[$key]; if (isset($logOptions['writer'])) { $log = new Zend_Log(); foreach ($logOptions['writer'] as $writerOptions) { $writer = null; switch (strtolower(trim($writerOptions['type']))) { case 'db': $db = $writerOptions['params']['db']; $table = $writerOptions['params']['db']; $columnMap = $writerOptions['params']['db']; $writer = new Zend_Log_Writer_Db($db, $table, $columnMap); break; case 'firebug': $writer = new Zend_Log_Writer_Firebug(); break; case 'mock': $writer = new Zend_Log_Writer_Mock(); break; case 'null': $writer = new Zend_Log_Writer_Null(); break; case 'stream': if (!App_Filesystem_Folder::exists($writerOptions['params']['streamOrUrl'])) { if (App_Filesystem_Folder::create($writerOptions['params']['streamOrUrl'])) { $getout = fopen($writerOptions['params']['streamOrUrl'] . "/index.html", "w") or die("Unable to open file!"); fwrite($getout, "Get out\n"); fclose($getout); } else { } } else { } $streamOrUrl = $writerOptions['params']['streamOrUrl'] . DS . date('dmY') . '.log'; $mode = isset($writerOptions['params']['mode']) ? $writerOptions['params']['mode'] : 'a'; $writer = new Zend_Log_Writer_Stream($streamOrUrl, $mode); break; default: $writer = null; } if (!is_null($writer)) { $log->addWriter($writer); } } if (isset($logOptions['filter'])) { foreach ($logOptions['filter'] as $filter) { if (isset($filter['priority'])) { $priority = $filter['priority']; if (!is_integer($priority)) { $c = 'Zend_Log::' . strtoupper(trim($priority)); $priority = constant($c); } $logFilter = new Zend_Log_Filter_Priority($priority); $log->addFilter($logFilter); } elseif (isset($filter['message'])) { $message = $filter['message']; $logFilter = new Zend_Log_Filter_Message($message); $log->addFilter($logFilter); } } } } return $log; }