/** * @param $databaseConfig * @param $masterParams * @return array */ private function mapSlavesConfig(Zend_Config $databaseConfig, $masterParams) { $slaves = $databaseConfig->get('slaves'); if (!$slaves || !$slaves instanceof Zend_Config || $slaves->count() === 0) { $slaves = array(); } $slavesParams = array(); foreach ($slaves as $slaveId) { $slaveConfig = $databaseConfig->get($slaveId); if (!$slaveConfig || !$slaveConfig instanceof Zend_Config) { $this->logger->warning(sprintf("Listed slave '%s' has no configuration. Skipping candidate slave.", $slaveId)); continue; } $slaveParams = $this->getParamsFromConfig($slaveConfig); if ($slaveParams['driver'] !== $masterParams['driver']) { $this->logger->warning(sprintf("Listed slave '%s' has different driver ('%s') than master ('%s'). This is not supported. " . 'Skipping candidate slave.', $slaveId, $slaveParams['driver'], $masterParams['driver'])); continue; } $slavesParams[] = $slaveParams; } if (empty($slavesParams)) { $this->logger->warning('No (properly) configured slaves, using master as slave.'); $slavesParams[] = $masterParams; } return $slavesParams; }
/** * Setup db * */ public function setup(Zend_Config $config) { $sessionConfig = $config->get('config'); $configArray = $sessionConfig->toArray(); // save_path handler $configArray = $this->_prependSavePath($configArray); // name handler $configArray = $this->_parseName($configArray); // Setup config Zend_Session::setOptions($configArray); // Setup save handling? $saveHandlerConfig = $config->get('save_handler'); if ($className = $saveHandlerConfig->get('class_name')) { if ($args = $saveHandlerConfig->get('constructor_args')) { if ($args instanceof Zend_Config) { $args = $args->toArray(); } else { $args = (array) $args; } } else { $args = array(); } require_once 'Zend/Loader.php'; Zend_Loader::loadClass($className); $saveHandler = new ReflectionClass($className); $saveHandler = $saveHandler->newInstanceArgs($args); Zend_Session::setSaveHandler($saveHandler); } // Autostart session? if ($config->get('auto_start')) { // Start session Zend_Session::start(); } }
/** * Get device features * * @return Application_Model_Device */ public function getDevice() { if ($this->device == null) { $this->device = false; $devices = Application_Model_DevicesMapper::i()->fetchAll(); /* @var Application_Model_Device $device */ foreach ($devices as $device) { // if exact do an == comparison if ($device->isExact() && $device->getPattern() == $_SERVER['HTTP_USER_AGENT'] || !$device->isExact() && preg_match($device->getPattern(), $_SERVER['HTTP_USER_AGENT']) > 0) { // valid $device found; $this->device = $device; break; } } if ($this->device == false) { // load things from default $this->device = new Application_Model_Device(); if (X_VlcShares_Plugins::broker()->isRegistered('wiimc')) { $this->device->setGuiClass($this->options->get('gui', 'X_VlcShares_Plugins_WiimcPlxRenderer')); } else { $this->device->setGuiClass($this->options->get('gui', 'X_VlcShares_Plugins_WebkitRenderer')); } $this->device->setIdProfile($this->options->get('profile', 1))->setLabel("Unknown device"); } } return $this->device; }
/** * Setup navigation * * @return void */ public function setup(Zend_Config $config) { // determine registry key $confKey = $config->get('registry_key'); $key = is_string($confKey) && strlen($confKey) ? $confKey : self::DEFAULT_REGISTRY_KEY; $nav = new Zym_Navigation($config->get('pages')); Zend_Registry::set($key, $nav); }
/** * Validate config * * @todo finish * @param Zend_Config $config */ public function validateConfig(Zend_Config $config) { // Convert string to object if (is_string($config->get('inflector'))) { // TODO: finish } if (is_string($config->get('view'))) { // TODO: finish } }
/** * Return true if a next page is possible * @return boolean * @throws Exception invalid $items type */ public function hasNext($items, $page = 1, $perPage = null) { if ($perPage === null) { $perPage = $this->options->get('perpage', 25); } if (is_array($items)) { return count($items) > $page * $perPage; } elseif ($items instanceof X_Page_ItemList) { $items = $items->getItems(); return count($items) > $page * $perPage; } else { throw new Exception("Items must be an array or an X_Page_ItemList"); } }
/** * Setup db * */ public function setup(Zend_Config $config) { $sessionConfig = $config->get('config'); $configArray = $sessionConfig->toArray(); // save_path handler $configArray = $this->_prependSavePath($configArray); // name handler $configArray = $this->_parseName($configArray); // Setup config Zend_Session::setOptions($configArray); // Autostart session? if ($config->get('auto_start')) { // Start session Zend_Session::start(); } }
/** * Setup Doctrine * * @return void */ public function setup(Zend_Config $config) { if (is_array($config->path_config)) { $this->setPathConfig($config->path_config); } elseif ($config->path_config instanceof Zend_Config) { $this->setPathConfig($config->path_config->toArray()); } if ($charset = $config->get('charset')) { $listener = new Zym_App_Resource_Doctrine_ConnectionListener(); $listener->setCharset($charset); Doctrine_Manager::getInstance()->addListener($listener); } // determine if config is for a single-db or a multi-db site $connections = $config->connection instanceof Zend_Config ? $config->connection->toArray() : (array) $config->connection; // add connection(s) to doctrine foreach ($connections as $name => $connection) { if ($connection instanceof Zend_Config) { $connection = $connection->toArray(); } if (is_string($name)) { Doctrine_Manager::connection($connection, $name); } else { Doctrine_Manager::connection($connection); } } }
/** * Get transport * * @param Zend_Config $config * @return Zend_Mail_Transport_Sendmail */ public static function getTransport(Zend_Config $config = null) { $host = isset($config->host) ? $config->get('host') : null; $otherConfig = ($config instanceof Zend_Config) ? $config->toArray() : null; return new Zend_Mail_Transport_Smtp($host, $otherConfig); }
/** * add one record * * @param Tinebase_Record_Interface $_record * @return Tinebase_Record_Interface */ public function create(Tinebase_Record_Interface $_record) { $course = parent::create($_record); // add teacher account $i18n = Tinebase_Translation::getTranslation('Courses'); $courseName = strtolower($course->name); $loginName = strtolower($i18n->_('teacher') . '-' . $course->name); $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name); $account = new Tinebase_Model_FullUser(array('accountLoginName' => $loginName, 'accountLoginShell' => '/bin/false', 'accountStatus' => 'enabled', 'accountPrimaryGroup' => $course->group_id, 'accountLastName' => $i18n->_('Teacher'), 'accountDisplayName' => $course->name . ' ' . $i18n->_('Teacher Account'), 'accountFirstName' => $course->name, 'accountExpires' => NULL, 'accountEmailAddress' => isset($this->_config->domain) && !empty($this->_config->domain) ? $loginName . '@' . $this->_config->domain : '', 'accountHomeDirectory' => isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $courseName . '/' . $loginName : '')); if (isset($this->_config->samba)) { $samUser = new Tinebase_Model_SAMUser(array('homePath' => $this->_config->samba->basehomepath . $loginName, 'homeDrive' => $this->_config->samba->homedrive, 'logonScript' => $courseName . $this->_config->samba->logonscript_postfix_teacher, 'profilePath' => $this->_config->samba->baseprofilepath . $schoolName . '\\' . $courseName . '\\' . $loginName)); $account->sambaSAM = $samUser; } if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Created teacher account for course ' . $course->name . ': ' . print_r($account->toArray(), true)); } #$event = new Courses_Event_BeforeAddTeacher($account, $course); #Tinebase_Event::fireEvent($event); $password = $this->_config->get('teacher_password', $account->accountLoginName); $account = Admin_Controller_User::getInstance()->create($account, $password, $password); // add to teacher group if available if (isset($this->_config->teacher_group) && !empty($this->_config->teacher_group)) { Admin_Controller_Group::getInstance()->addGroupMember($this->_config->teacher_group, $account->getId()); } // add to students group if available if (isset($this->_config->students_group) && !empty($this->_config->students_group)) { Admin_Controller_Group::getInstance()->addGroupMember($this->_config->students_group, $account->getId()); } return $course; }
/** * @param Zend_Config $testConfig * @param ReflectionParameter $arg * @throws Exception * @throws KalturaTestException * @return Ambigous */ protected function getArgConfig(Zend_Config $testConfig, ReflectionParameter $arg) { $argName = $arg->getName(); $argConfig = $testConfig->get($argName); KalturaLog::debug("Tests data [{$argName}] config [" . print_r($argConfig, true) . "]"); if (!$argConfig) { if (!$arg->allowsNull()) { throw new Exception("Argument [{$argName}] can't be null for test [" . $this->getName() . "]"); } return null; } if (is_string($argConfig)) { return $argConfig; } switch ($argConfig->objectType) { case 'dependency': throw new KalturaTestException("Argument [{$argName}] taken from dependency"); case 'array': return $this->populateArray($argConfig); case 'native': return $argConfig->value; case 'file': return $argConfig->path; default: return $this->populateObject($argConfig); } }
/** * Returns the configuration of the provided template. * * @param string $template The name of the template. * @return Zend_Config * @throws InvalidArgumentException If the template does not exist. */ protected function getConfigFor($template) { if (!isset($this->templates->{$template})) { $message = 'The template "' . $template . '" does not exist.'; throw new InvalidArgumentException($message); } return $this->templates->get($template); }
/** * // * * @param string $option * @param mixed $default * @return */ public function get($option, $default = null) { $result = parent::get($option, $default); if ($result instanceof Zend_Config) { $result = $result->toArray(); } return $result; }
/** * Load transport settings * * @param Zend_Config $config * @return Zend_Mail_Transport_Abstract */ protected function _loadTransport(Zend_Config $config) { // Make lowercase $defaultTransport = strtolower($config->get('default_transport')); $transportMap = array_change_key_case($config->get('transport_map')->toArray(), CASE_LOWER); // Load transport $transportConfig = $config->get('transport')->get($defaultTransport); $transportClass = $this->_parseTransportMap($defaultTransport, $transportMap); $transport = call_user_func(array($transportClass, 'getTransport'), $transportConfig); if (!$transport instanceof Zend_Mail_Transport_Abstract) { /** * @see Zym_App_Resource_Mail_Exception */ require_once 'Zym/App/Resource/Mail/Exception.php'; throw new Zym_App_Resource_Mail_Exception('Could not load mail transport "' . $defaultTransport . '"'); } return $transport; }
public function init(Zend_Config $options) { $language = new X_VlcShares_Plugins_Helper_Language($options->get('language', new Zend_Config(array()))); $ffmpeg = new X_VlcShares_Plugins_Helper_FFMpeg($options->get('ffmpeg', new Zend_Config(array()))); $devices = new X_VlcShares_Plugins_Helper_Devices($options->get('devices', new Zend_Config(array()))); $stream = new X_VlcShares_Plugins_Helper_Stream($options->get('stream', new Zend_Config(array()))); $paginator = new X_VlcShares_Plugins_Helper_Paginator($options->get('paginator', new Zend_Config(array()))); $hoster = new X_VlcShares_Plugins_Helper_Hoster(); $rtmpdump = new X_VlcShares_Plugins_Helper_RtmpDump($options->get('rtmpdump', new Zend_Config(array()))); $sopcast = new X_VlcShares_Plugins_Helper_SopCast($options->get('sopcast', new Zend_Config(array()))); //$vlc = new X_VlcShares_Plugins_Helper_Vlc($options->get('vlc', new Zend_Config(array()))); $streamer = new X_VlcShares_Plugins_Helper_Streamer($options->get('streamer', new Zend_Config(array()))); $acl = X_VlcShares_Plugins_Helper_Acl::instance($options->get('acl', new Zend_Config(array()))); $this->registerHelper('language', $language, true)->registerHelper('ffmpeg', $ffmpeg, true)->registerHelper('devices', $devices, true)->registerHelper('stream', $stream, true)->registerHelper('paginator', $paginator, true)->registerHelper('hoster', $hoster, true)->registerHelper('rtmpdump', $rtmpdump, true)->registerHelper('streamer', $streamer, true)->registerHelper('sopcast', $sopcast, true)->registerHelper('acl', $acl, true); }
/** * @return X_SopCast */ public function setOptions($options) { if (is_array($options)) { $options = new Zend_Config($options); } if ($options instanceof Zend_Config) { $this->setPath($options->get('path', null)); } return $this; }
private function setConfig() { $frontController = Zend_Controller_Front::getInstance(); $options = new Zend_Config($frontController->getParam('bootstrap')->getOptions(), true); $rest = $options->get('rest', false); if ($rest) { $this->defaultFormat = $rest->default; $this->acceptableFormats = $rest->formats->toArray(); } }
public function get($name, $default = null) { $parts = explode('/', $name); $leaf = array_pop($parts); $node = $this; foreach ($parts as $part) { $node = parent::get($part, new self(null, array())); } if ($node === $this) { return parent::get($leaf, $default); } else { return $node->get($leaf, $default); } }
private function setConfig() { $frontController = Zend_Controller_Front::getInstance(); $options = new Zend_Config($frontController->getParam('bootstrap')->getOptions(), true); $rest = $options->get('rest', false); if ($rest) { $this->defaultFormat = $rest->default; $this->acceptableFormats = $rest->formats->toArray(); foreach ($this->responseTypes as $mime => $format) { if (!in_array($format, $this->acceptableFormats)) { unset($this->responseTypes[$mime]); } } } }
/** * Setup * * @param Zend_Config $config */ public function setup(Zend_Config $config) { // Use non-default autoload function? $class = $config->get('class'); // Allow loading multiple loaders if ($class instanceof Zend_Config) { $classes = $class->toArray(); } else { $classes = (array) $class; } // Register autoload foreach (array_reverse($classes) as $loader) { Zend_Loader::registerAutoload($loader); } }
/** * Set default cache frontend and backend config * * @param Zend_Config $config */ public static function setConfig(Zend_Config $config) { if (!empty($config->default_backend)) { self::setDefaultBackend($config->default_backend); } // Set config $map = array('frontend', 'backend'); foreach ($map as $item) { if (isset($config->{$item})) { foreach ($config->get($item) as $end => $endConfig) { $setConfigFunc = 'set' . ucfirst($item) . 'Options'; self::$setConfigFunc($end, $endConfig->toArray()); } } } }
private function checkHashable(DOMElement $table, DOMDocument $schema) { $allow = false; $disallow = false; if ($this->config->get('hash', false)) { $config = $this->config->hash->toArray(); $allow = true; } if ($this->config->get('notHash', false)) { $config = $this->config->hash->toArray(); $allow = false; } $tableName = $table->getAttribute('name'); //$x = $table->ownerDocument->saveXML($table); $xpath = new DOMXPath($schema); $nodes = $xpath->query('column[@primaryKey="true"]', $table); if ($allow) { if (array_search($tableName, $config[$tableName]) === false && $nodes->length == 1) { $sxe = new SimpleXMLElement('<behavior name="hashable"/>'); $node = dom_import_simplexml($sxe); $behavior = $schema->importNode($node, true); echo "\t" . ' found:' . $tableName . "\n"; $table->appendChild($behavior); } } elseif ($disallow) { if (array_search($tableName, $config[$tableName]) === false && $nodes->length == 1) { $sxe = new SimpleXMLElement('<behavior name="hashable"/>'); $node = dom_import_simplexml($sxe); $behavior = $schema->importNode($node, true); echo "\t" . ' found:' . $tableName . "\n"; $table->appendChild($behavior); } } else { if ($nodes->length == 1) { $sxe = new SimpleXMLElement('<behavior name="hashable"/>'); $node = dom_import_simplexml($sxe); $behavior = $schema->importNode($node, true); echo "\t" . ' found:' . $tableName . "\n"; $table->appendChild($behavior); } } }
/** * import course members * * @param string $tempFileId * @param string $groupId * @param string $courseName * * @todo write test!! */ public function importMembers($tempFileId, $groupId, $courseId) { $tempFile = Tinebase_TempFile::getInstance()->getTempFile($tempFileId); $course = $this->_controller->get($courseId); $schoolName = strtolower(Tinebase_Department::getInstance()->get($course->type)->name); // get definition and start import with admin user import csv plugin $definitionName = $this->_config->get('import_definition', 'admin_user_import_csv'); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Using import definition: ' . $definitionName); } $definition = Tinebase_ImportExportDefinition::getInstance()->getByName($definitionName); $importer = Admin_Import_Csv::createFromDefinition($definition, array('group_id' => $groupId, 'accountEmailDomain' => isset($this->_config->domain) ? $this->_config->domain : '', 'accountHomeDirectoryPrefix' => isset($this->_config->basehomedir) ? $this->_config->basehomedir . $schoolName . '/' . $course->name . '/' : '', 'password' => strtolower($course->name), 'course' => $course, 'samba' => isset($this->_config->samba) ? array('homePath' => $this->_config->samba->basehomepath, 'homeDrive' => $this->_config->samba->homedrive, 'logonScript' => $course->name . $this->_config->samba->logonscript_postfix_member, 'profilePath' => $this->_config->samba->baseprofilepath . $schoolName . '\\' . $course->name . '\\', 'pwdCanChange' => new Tinebase_DateTime('@1'), 'pwdMustChange' => new Tinebase_DateTime('@1')) : array())); $importer->importFile($tempFile->path); // return members to update members grid and add to student group $members = $this->_getCourseMembers($groupId); // add to student group if available if (isset($this->_config->students_group) && !empty($this->_config->students_group)) { $groupController = Admin_Controller_Group::getInstance(); foreach ($members as $member) { $groupController->addGroupMember($this->_config->students_group, $member['id']); } } return array('results' => $members, 'status' => 'success'); }
/** * Setup * * @return void */ public function setup(Zend_Config $config) { // Setup Cache if ($config->get('cache')) { $cache = Zym_Cache::factory('Core'); Zend_Translate::setCache($cache); } $adapter = $config->get('adapter'); $data = $this->_parseDataPath($config->get('data')); $locale = $config->get('locale'); $options = $this->_parseOptions($config->get('options')->toArray()); $translate = new Zend_Translate($adapter, $data, null, $options); // Weird Zend_Translate issues // We cannot set a locale in the constructor $translate->getAdapter()->setLocale($locale); if ((bool) $config->get('registry')->get('enabled')) { /** * @see Zend_Registry */ require_once 'Zend/Registry.php'; Zend_Registry::set($config->get('registry')->get('key'), $translate); } }
/** * Setup * * @return void */ public function setup(Zend_Config $config) { // Setup Cache if ($config->get('cache')) { $cache = Zym_Cache::factory('Core'); Zend_Translate::setCache($cache); } $adapter = $config->get('adapter'); $data = $this->_parseDataPath($config->get('data')); $options = $this->_parseOptions($config->get('options')->toArray()); if (!($locale = $config->get('locale'))) { if (Zend_Registry::isRegistered('Zend_Locale')) { $locale = Zend_Registry::get('Zend_Locale'); } } $translate = new Zend_Translate($adapter, $data, $locale, $options); if ((bool) $config->get('registry')->get('enabled')) { /** * @see Zend_Registry */ require_once 'Zend/Registry.php'; Zend_Registry::set($config->get('registry')->get('key'), $translate); } }
/** * Instantiates route based on passed Zend_Config structure */ public static function getInstance(Zend_Config $config) { $frontController = Zend_Controller_Front::getInstance(); $defs = $config->defaults instanceof Zend_Config ? $config->defaults->toArray() : array(); $dispatcher = $frontController->getDispatcher(); $request = $frontController->getRequest(); $translatable = $config->get('translatable', false); if ($config->get('translator', null) instanceof Zend_Config) { $options = $config->get('translator')->toArray(); if (!isset($options['data'])) { throw new Zend_Controller_Router_Exception('No translation source data provided.'); } $adapter = isset($options['adapter']) ? $options['adapter'] : Zend_Translate::AN_ARRAY; $locale = isset($options['locale']) ? $options['locale'] : null; $translateOptions = isset($options['options']) ? $options['options'] : array(); $translator = new Zend_Translate($adapter, $options['data'], $locale, $translateOptions); } else { $translator = $config->get('translator', null); } $locale = $config->get('locale', null); return new self($defs, $dispatcher, $request, $translatable, $translator, $locale); }
/** * Set a global config * * @param Zend_Config $config */ public static function setConfig(Zend_Config $config) { self::$_config = $config; $adapterPaths = $config->get('adapterpaths'); if ($adapterPaths != null) { self::addAdapterPrefixPaths($adapterPaths->adapterpath->toArray()); } $prefixPaths = $config->get('prefixpaths'); if ($prefixPaths != null) { self::addScrollingStylePrefixPaths($prefixPaths->prefixpath->toArray()); } $scrollingStyle = $config->get('scrollingstyle'); if ($scrollingStyle != null) { self::setDefaultScrollingStyle($scrollingStyle); } }
/** * Set classes such as router, request, dispatcher etc.. * * @param Zend_Config $config */ protected function _setCustomClasses(Zend_Config $config) { $customClassMap = array('router' => $config->get('router'), 'request' => $config->get('request'), 'response' => $config->get('response'), 'dispatcher' => $config->get('dispatcher')); foreach ($customClassMap as $key => $value) { if (!empty($value)) { // Load class if (is_string($value)) { Zend_Loader::loadClass($value); $value = new $value(); } $func = 'set' . ucfirst($key); $this->getFrontController()->{$func}($value); } } }
/** * Kill magic quotes gpc * * Strips the crap that magic quotes does... * * @todo Discuss whether or not to include this hack... * @param Zend_Config $config */ protected function _undoMagicQuotesGpc(Zend_Config $config) { $isMagicQuotesGpc = isset($config->magic_quotes_gpc) && !$config->get('magic_quotes_gpc'); if ($isMagicQuotesGpc && get_magic_quotes_gpc()) { $in = array(&$_GET, &$_POST, &$_COOKIE); while (list($k, $v) = each($in)) { foreach ($v as $key => $val) { if (!is_array($val)) { $in[$k][$key] = stripslashes($val); continue; } $in[] =& $in[$k][$key]; } } unset($in); } }
public function testZF1417_DefaultValues() { $config = new Zend_Config($this->_all); $value = $config->get('notthere', 'default'); $this->assertTrue($value === 'default'); $this->assertTrue($config->notThere === null); }