public function setup() { foreach (array_keys($this->_singletons) as $singleton) { $this->_singletons[$singleton] = Ak::getStaticVar($singleton); Ak::unsetStaticVar($singleton); } }
static function loadConfig($dictionary) { static $_loaded = array(); if (!($return = Ak::getStaticVar('AkInflectorConfig::' . $dictionary))) { $return = Ak::getSettings($dictionary, false); if ($return !== false) { Ak::setStaticVar('AkInflectorConfig::' . $dictionary, $return); $_loaded[$dictionary] = true; } else { trigger_error(Ak::t('Could not load inflector rules file: %file', array('%file' => 'config' . DS . $dictionary . '.yml')), E_USER_ERROR); } } return $return; }
public function connect($options = null) { $this->setOptions($options); if ($this->_meetsDependencies()) { $port = $this->getOption('port'); if (!($Connection = Ak::getStaticVar(__CLASS__ . '_' . $this->_connetion_signature))) { try { $Connection = new Mongo($this->getOption('host') . (empty($port) ? '' : ':' . $port)); } catch (MongoConnectionException $e) { $Connection = false; } Ak::setStaticVar(__CLASS__ . '_' . $this->_connetion_signature, $Connection); } $this->_Mongo[$this->_connetion_signature] = $Connection; if ($Connection && !$this->isConnected()) { $Connection->connect(); } } return $this->isConnected(); }
function populateTables() { $args = func_get_args(); $tables = !empty($args) ? (is_array($args[0]) ? $args[0] : (count($args) > 1 ? $args : Ak::toArray($args))) : array(); foreach ($tables as $table){ $file = AK_TEST_DIR.DS.'fixtures'.DS.'data'.DS.(empty($this->module)?'':$this->module.DS).Ak::sanitize_include($table).'.yaml'; if(!file_exists($file)){ continue; } $class_name = AkInflector::classify($table); if($this->instantiateModel($class_name)){ $contents = &Ak::getStaticVar('yaml_fixture_'.$file); if (!$contents) { ob_start(); require_once($file); $contents = ob_get_clean(); Ak::setStaticVar('yaml_fixture_'.$file, $contents); } $items = Ak::convert('yaml','array',$contents); foreach ($items as $item){ $obj=&$this->{$class_name}->create($item); if (isset($item['created_at'])) { $obj->updateAttribute('created_at',$item['created_at']); } else if (isset($item['created_on'])) { $obj->updateAttribute('created_on',$item['created_on']); } } } } }
public function test_static_var_destruct_all_vars() { $value = new stdClass(); $value->id = 1; $return = Ak::setStaticVar('testVar1', $value); $this->assertEqual(true, $return); $value2 = new stdClass(); $value2->id = 2; $return = Ak::setStaticVar('testVar2', $value2); $this->assertEqual(true, $return); $value3 = new stdClass(); $value3->id = 3; $return = Ak::setStaticVar('testVar3', $value3); $this->assertEqual(true, $return); $null = null; Ak::unsetStaticVar('testVar1'); $storedValue1 =& Ak::getStaticVar('testVar1'); $this->assertEqual($null, $storedValue1); $storedValue2 =& Ak::getStaticVar('testVar2'); $this->assertEqual($value2, $storedValue2); $storedValue3 =& Ak::getStaticVar('testVar3'); $this->assertEqual($value3, $storedValue3); Ak::unsetStaticVar($null); $storedValue1 =& Ak::getStaticVar('testVar1'); $this->assertEqual($null, $storedValue1); $storedValue2 =& Ak::getStaticVar('testVar2'); $this->assertEqual($null, $storedValue2); $storedValue3 =& Ak::getStaticVar('testVar3'); $this->assertEqual($null, $storedValue3); }
function makelos_setting($settings = array()) { Ak::getStaticVar('Makelos')->addSettings($settings); }
/** * Register the reference to an object object * @return void */ function &getObservers() { $staticVarNs='AkActiveRecord::observers::' . $this->_modelName; $key = 'objects'; $array = array(); $observers_arr =& Ak::getStaticVar($staticVarNs); if (isset($observers_arr[$key])) { $observers = &$observers_arr[$key]; } else { $observers = &$array; } return $observers; }
/** * Gets the list of observers for the current model. * @return array */ public function &getObservers() { $staticVarNs = 'AkActiveModel::observers::' . $this->_Model->getModelName(); $key = 'objects'; $array = array(); $observers_arr = Ak::getStaticVar($staticVarNs); if (isset($observers_arr[$key])) { $observers = $observers_arr[$key]; } else { $observers = $array; } return $observers; }
/** * Checks if the user is set * * @return boolean */ function isLoaded() { return Ak::getStaticVar('CurrentUser') != null; }
public function runTaskAsDaemon($task_name, $options = array()) { $this->_ensurePosixAndPcntlAreAvailable(); require_once 'System/Daemon.php'; $app_name = AkInflector::underscore($task_name); $pid_file = AK_BASE_DIR . DS . 'run' . DS . $app_name . DS . $app_name . '.pid'; $log_file = AK_LOG_DIR . DS . 'daemons' . DS . $app_name . '.log'; if (!file_exists($pid_file)) { if (empty($options['attributes']['kill'])) { AkFileSystem::file_put_contents($pid_file, ''); AkFileSystem::file_delete($pid_file); } else { $this->error("Could not kill process for {$task_name}", true); } } else { $pid = (int) file_get_contents($pid_file); if ($pid > 0) { if (!empty($options['attributes']['kill'])) { $this->message("Killing process {$pid}"); `kill {$pid}`; AkFileSystem::file_delete($pid_file); die; } elseif (!empty($options['attributes']['restart'])) { $this->message("Restarting {$task_name}."); $this->message(`kill {$pid}`); } else { $this->error("Daemon for {$task_name} still running ({$pid_file}).\nTask aborted.", true); } } } if (!empty($options['attributes']['kill']) && empty($pid)) { $this->error("No daemon running for task {$task_name}", true); } unset($options['attributes']['restart']); if (!file_exists($log_file)) { AkFileSystem::file_put_contents($log_file, ''); } System_Daemon::setOption('appName', $app_name); System_Daemon::setOption('appDir', AK_BASE_DIR); System_Daemon::setOption('logLocation', $log_file); System_Daemon::setOption('appRunAsUID', posix_geteuid()); System_Daemon::setOption('appRunAsGID', posix_getgid()); System_Daemon::setOption('appPidLocation', $pid_file); $this->message("Staring daemon. ({$log_file})"); System_Daemon::start(); $dsn = Ak::getStaticVar('dsn'); defined('AK_SKIP_DB_CONNECTION') && AK_SKIP_DB_CONNECTION ? null : Ak::db($dsn); $this->runTask($task_name, $options); System_Daemon::stop(); AkFileSystem::file_delete($pid_file); die; }
function _getAvailableHelpers() { $helpers = array(); if (empty($this->available_helpers)) { if (defined('AK_SINTAGS_AVALABLE_HELPERS')) { $helpers = unserialize(AK_SINTAGS_AVALABLE_HELPERS); } else { $AkHelperLoader = Ak::getStaticVar('AkHelperLoader'); $AkHelperLoader->instantiateHelpers(); if ($underscored_helper_names = AkHelperLoader::getInstantiatedHelperNames()) { foreach ($underscored_helper_names as $underscored_helper_name) { $helper_class_name = AkInflector::camelize($underscored_helper_name); if (class_exists($helper_class_name)) { $methods = get_class_methods($helper_class_name); $vars = get_class_vars($helper_class_name); if (AK_PHP5 && isset($vars['dynamic_helpers'])) { $dynamic_helpers = Ak::toArray($vars['dynamic_helpers']); foreach ($dynamic_helpers as $method_name) { $this->dynamic_helpers[$method_name] = $underscored_helper_name; } } foreach (get_class_methods($helper_class_name) as $method_name) { if ($method_name[0] != '_') { $helpers[$method_name] = $underscored_helper_name; } } } } $helpers['render'] = 'controller'; $helpers['render_partial'] = 'controller'; } } $this->available_helpers = $helpers; } return $this->available_helpers; }
static function &getInstance(AkActionController &$Controller) { if (!($CacheHandler = Ak::getStaticVar('AkCacheHandlerSingleton'))) { $settings = Ak::getSettings('caching', false); if (!empty($settings['enabled'])) { $CacheHandler = new AkCacheHandler(); $CacheHandler->init($Controller); Ak::setStaticVar('AkCacheHandlerSingleton', $CacheHandler); } } return $CacheHandler; }
static function getInstance() { if (!($Request = Ak::getStaticVar('AkRequestSingleton'))) { $Request = new AkRequest(); Ak::setStaticVar('AkRequestSingleton', $Request); } return $Request; }
/** * Returns an array of helper names like: * * array('url_helper', 'prototype_helper') */ function getInstantiatedHelperNames() { return Ak::getStaticVar('AkActionView::instantiated_helper_names'); }
/** * @return AkRouter */ static function getInstance() { if (!($Router = Ak::getStaticVar('AkRouterSingleton'))) { $Router = new AkRouter(); $Router->loadMap(); Ak::setStaticVar('AkRouterSingleton', $Router); } return $Router; }
public function &getAdapter() { if (empty($this->_Adapter)) { if (!($this->_Adapter = Ak::getStaticVar($this->getModelName() . '_last_used_Adapter'))) { if (!($this->_Adapter = Ak::getStaticVar('AkActiveDocument_last_used_Adapter'))) { $db = new AkOdbAdapter(); $db->connect(); $this->setAdapter($db); } } } return $this->_Adapter; }
static function getOption($key, $default = null) { $option = Ak::getStaticVar('AkConfig_' . $key); if (is_null($option) && !is_null($default)) { return $default; } return $option; }
function ak_trace_db_query($message, $new_line = true) { if (Ak::getStaticVar('ak_trace_db_query') === false) { return; } if (!AK_TRACE_DB_QUERIES_INCLUDES_DB_TYPE) { $message = preg_replace('/\\([a-z0-9]+\\): /', '', trim($message, "\n-")); } $details = Ak::getLastFileAndLineAndMethod(AK_TRACE_ONLY_APP_DB_QUERIES); if (empty($details)) { $details = array(null, null, null); } $message = trim(html_entity_decode(strip_tags($message))); if (!AK_DEBUG_OUTPUT_AS_HTML) { echo $message . "\n"; } else { Ak::trace($message, $details[1], $details[0], $details[2]); } }
/** * Caching of expensive model scoped methods (like table structure, default values...) */ protected function &_getCacheForModelMethod($method) { if (AK_TEST_MODE) { $false = false; return $false; } return Ak::getStaticVar('AR_' . $this->getModelName() . $method); }
/** * caching the meta info * * @return unknown */ function availableTables($force_lookup = false) { $available_tables = array(); !AK_TEST_MODE && $available_tables = Ak::getStaticVar('available_tables'); if(!$force_lookup && empty($available_tables)){ if (($available_tables = AkDbSchemaCache::get('avaliable_tables')) === false) { if(empty($available_tables)){ $available_tables = $this->connection->MetaTables(); } AkDbSchemaCache::set('avaliable_tables', $available_tables); !AK_TEST_MODE && Ak::setStaticVar('available_tables', $available_tables); } } $available_tables = $force_lookup ? $this->connection->MetaTables() : $available_tables; $force_lookup && !AK_TEST_MODE && Ak::setStaticVar('available_tables', $available_tables); return $available_tables; }
static function getInstance() { if (!($UrlWriter = Ak::getStaticVar('AkUrlWriterSingleton'))) { $UrlWriter = new AkUrlWriter(); Ak::setStaticVar('AkUrlWriterSingleton', $UrlWriter); } return $UrlWriter; }
/** * Add a profile message that can be displayed after executing the script * * You can add benchmark markers by calling * * Ak::profile('Searching for books'); * * To display the results you need to call * * Ak::profile(true); * * You might also find handy adding this to your application controller. * * class ApplicationController extends BaseActionController * { * function __construct(){ * $this->afterFilter('_displayBenchmark'); * parent::__construct(); * } * public function _displayBenchmark(){ * Ak::profile(true); * } * } * * IMPORTANT NOTE: You must define AK_ENABLE_PROFILER to true for this to work. */ function profile($message = '') { if(AK_ENABLE_PROFILER){ if(!$ProfileTimer = $Timer = Ak::getStaticVar('ProfileTimer')){ require_once 'Benchmark/Timer.php'; $ProfileTimer = new Benchmark_Timer(); $ProfileTimer->start(); Ak::setStaticVar('ProfileTimer', $ProfileTimer); }elseif($message === true){ $ProfileTimer->display(); }else { $ProfileTimer->setMarker($message); } } }
static function puts($string) { if ($PutsHandler = Ak::getStaticVar('AppServer.PutsHandler', false)) { $PutsHandler->puts($string); } else { echo $string; } }