/** * Loads the cache file * * @return void * @author Dan Cox */ public function __construct($file = 'module_cache.yml', $services = 'module_services.yml') { $this->cache = $this->config; $this->cache->load(CACHE . $file); $this->services = $this->get('config'); $this->services->load(CACHE . $services); }
/** * Set up class vars * * @return void * @author Dan Cox */ public function __construct() { $this->availableModules = array(); $this->config = $this->get('config'); $this->config->load(CONFIG . 'modules.yml'); $this->getAvailable(); }
/** * Set up test environment * * @return void * @author Dan Cox */ public function setUp() { $this->database = new Database(); $this->entity = m::mock('EntityManager'); $this->connection = new Connection(); $config = new ConfigFile(); $config->load(__DIR__ . '/Connections/database_test1.yml'); $this->connection->load($config); }
/** * Bulk loading vars * * @return void * @author Dan Cox */ public function test_bulkLoad() { $this->params->load(array('bar' => 'foo', 'test' => 'value')); $this->assertTrue(isset($this->params->bar)); $this->assertTrue(isset($this->params->test)); $this->assertEquals('foo', $this->params->bar); $this->assertEquals('value', $this->params->test); $this->assertEquals(array('bar' => 'foo', 'test' => 'value'), $this->params->all()); }
/** * Loads or creates the file * * @return void * @author Dan Cox */ public function loadOrCreate() { if ($this->fs->exists(LOGS . $this->file)) { $this->config->load(LOGS . $this->file); } else { $this->config->create(LOGS . $this->file); $this->config->params()->created = array('date' => date('Y-m-d H:i:s')); $this->config->params()->log = array(); $this->config->save(); } }
/** * _getColumnParams * * Retourne les paramètres de la colonne pour la propriété $elmName . * * @param string $elmName Nom de la propriété. * @access private * @return array */ private function _getColumnParams($elmName) { $elmType = $this->getElementType($elmName); if ($elmType == Object::TYPE_BOOL) { return array('Macro' => '%' . $elmName . '%', 'TranslationMap' => array(false => A_NO, true => A_YES), 'Sortable' => true); } if ($elmType == Object::TYPE_CONST) { $method = sprintf('get%sConstArray', $elmName); $arr = call_user_func(array($this->clsname, $method)); return array('Macro' => '%' . $elmName . '%', 'TranslationMap' => $arr, 'Sortable' => false); } if ($elmType == Object::TYPE_FKEY) { return array('Macro' => '%' . $elmName . '%', 'TranslationMap' => array(0 => 'N/A'), 'Sortable' => true); } if ($elmType == Object::TYPE_MANYTOMANY) { $clsName = $this->links[$elmName]['linkClass']; $tmpobject = Object::load($clsName); $macro = call_user_func(array($tmpobject, 'getToStringAttribute')); if (is_array($macro)) { $macro = implode($macro, '% %'); } return array('Macro' => '%' . $macro . '%', 'link' => $elmName, 'Sortable' => true); } $filter = ''; if ($elmType == Object::TYPE_DATE) { $filter = '|formatDate@DATE_LONG'; } if ($elmType == Object::TYPE_DATETIME) { $filter = '|formatDate@DATETIME_LONG'; } if ($elmType == Object::TYPE_FLOAT || $elmType == Object::TYPE_DECIMAL) { $dec_num = isset($this->mapping[$elmName]['dec_num']) ? $this->mapping[$elmName]['dec_num'] : 2; $filter = '|formatNumber@' . $dec_num; } return array('Macro' => '%' . $elmName . $filter . '%', 'Sortable' => true); }
/** * Loads fixtures from the directory * * @return void * @author Dan Cox */ public function load() { $this->loader = new DirectoryLoader($this->directory); $this->fixtureList = $this->loader->load(); }
/** * Loads a service file into the loader. * * @return void * @author Dan Cox */ public static function load($serviceFile) { static::$loader->load($serviceFile . '.yml'); }
/** * Adds a command to the library * * @return Application */ public function add($command) { $tasks = $this->prepper->load(get_class($command))->describe(); $this->library->add(['task' => $tasks, 'class' => $command]); return $this; }
/** * Uses the matcher and Replacement classes to search for matches and systematically replace them. * * @return String * @author Dan Cox */ public function searchAndReplace($str) { $this->matcher->load($str, $this->collection); return $this->matcher->searchAndReplace(); }
/** * Fonction qui remplit un objet récursivement à partir de données POST. * Ex: * pour un objet A qui a les propriétés suivantes: * - name * - child (un objet lié) * - XXXCollection de type *..* * on devrait avoir comme données POST: * - POST['A_name'] = 'toto' * - POST['A_child_ID'] = 0 (l'objet lié n'existe pas il faut le créer) * - POST['child_name'] = 'titi' soit les propriétés de l'objet lié... * - POST['A_XXXCollection'] = array (le chps du form: name='A_XXXCollection[]') * * Cette fonction est donc valable pour les formulaires "dénormalisés", * c'est à dire les formulaires dans lesquels on mélange les propriétés * d'un objet et de ses objets liés. pour un exemple, regarder * SiteAddEdit.php et le template correspondant * lib/templates/Site/SiteAddEdit.html * ### A appeler dans une transaction ! * * @static * @param array $postdata les données POST * @param object $baseObject l'objet de base * @param string $clsname nom de l'objet (si false, on se base sur * $baseObject pour le trouver) * @param string $prefix prefixe ajouté au clé du tableau $postdata * @return void **/ static function autoHandlePostDataWithLinks($postdata, $baseObject, $clsname = false, $prefix = '') { if (!is_array($postdata)) { trigger_error('autoHandlePostDataWithLinks() need POST data.', E_USER_ERROR); } if (!is_object($baseObject)) { trigger_error('autoHandlePostDataWithLinks() need a base object', E_USER_ERROR); } $clsname = false == $clsname ? get_class($baseObject) : $clsname; /** * On remplit l'objet **/ foreach ($baseObject->getProperties() as $property => $class) { $setter = sprintf("set%s", $property); if (!method_exists($baseObject, $setter)) { continue; } $property = $prefix . $clsname . '_' . $property; if (!is_string($class) && isset($postdata[$property])) { // propriétés simples $baseObject->{$setter}($postdata[$property]); } else { if (isset($postdata[$property . '_ID'])) { $id = $postdata[$property . '_ID']; if (isset($id) && intval($id) > 0) { $childObject = Object::load($class, $id); $baseObject->{$setter}($childObject); } else { $baseObject->{$setter}($id); } } } } // Gestion des Collection attributes *..* foreach ($baseObject->getLinks() as $property => $detail) { $setter = sprintf("set%sCollectionIds", $property); if (!method_exists($baseObject, $setter)) { continue; } $property = $prefix . $clsname . '_' . $property . 'Collection'; if (isset($_REQUEST[$property]) && false != $_REQUEST[$property]) { if (!is_array($_REQUEST[$property])) { $_REQUEST[$property] = array($_REQUEST[$property]); } $baseObject->{$setter}($_REQUEST[$property]); } } }
/** * Loads a file by name * * @param String $filename * @return DI * @author Dan Cox */ public function load($filename) { static::$loader->load($filename . '.yml'); return $this; }
/** * Given a UF user object, make sure there is a contact * object for this user. If the user has new values, we need * to update the CRM DB with the new values * * @param Object $user the drupal user object * @param boolean $update has the user object been edited * @param $uf * * @return void * @access public * @static */ function synchronize(&$user, $update, $uf) { $session =& CRM_Core_Session::singleton(); if (!is_object($session)) { return; } if ($uf == 'Drupal') { $key = 'uid'; $mail = 'mail'; } else { if ($uf == 'Mambo') { $key = 'id'; $mail = 'email'; } else { CRM_Utils_System::statusBounce(ts('Please set the user framework variable')); } } // have we already processed this user, if so early // return. $userID = $session->get('userID'); $ufID = $session->get('ufID'); if (!$update && $ufID == $user->{$key}) { return; } // reset the session if we are a different user if ($ufID && $ufID != $user->{$key}) { $session->reset(); } // make sure we load the mambo object to get valid information if ($uf == 'Mambo') { $user->load(); } // if the id of the object is zero (true for drupal), return early if ($user->{$key} == 0) { return; } $ufmatch =& CRM_Core_BAO_UFMatch::synchronizeUFMatch($user, $user->{$key}, $user->{$mail}, $uf); if (!$ufmatch) { return; } $session->set('ufID', $ufmatch->uf_id); $session->set('userID', $ufmatch->contact_id); $session->set('domainID', $ufmatch->domain_id); $session->set('ufEmail', $ufmatch->email); if ($update) { // the only information we care about is email, so lets check that if ($user->{$mail} != $ufmatch->email) { // email has changed, so we need to change all our primary email also $ufmatch->email = $user->{$mail}; $ufmatch->save(); $query = "\nUPDATE civicrm_contact\nLEFT JOIN civicrm_location ON ( civicrm_location.entity_table = 'civicrm_contact' AND\n civicrm_contact.id = civicrm_location.entity_id AND\n civicrm_location.is_primary = 1 )\nLEFT JOIN civicrm_email ON ( civicrm_location.id = civicrm_email.location_id AND\n civicrm_email.is_primary = 1 )\nSET civicrm_email.email = '" . $user->{$mail} . "' WHERE civicrm_contact.id = " . CRM_Utils_Type::escape($ufmatch->contact_id, 'Integer'); CRM_Core_DAO::executeQuery($query); } } }
/** * Test that the helpers throw an exception when it cant find the helper * * @return void * @author Dan Cox */ public function test_throwexceptionOnUnknownHelper() { $this->setExpectedException('Danzabar\\CLI\\Tasks\\Exceptions\\RegisteredHelperClassNotFoundException'); $this->helpers->load('unknown'); }
/** * Set up tests * * @return void * @author Dan Cox */ public function setUp() { parent::setUp(); $this->config = new ConfigFile(); $this->config->load(__DIR__ . '/Connections/database_test1.yml'); }
/** * Verifie des Id passes ds une url: renvoit un tableau avec les Id valides * ou false si aucun id n'est valide * * @static * @access public * @param string $Entity nom de l'entite * @param string $varName nom de la var passee ds l'url * @return array of integer or false **/ static function checkObjectFromUrlQuery($Entity, $varName = 'Id') { $validIdArray = array(); if (!isset($_REQUEST[$varName])) { return false; } if (!is_array($_REQUEST[$varName])) { $Object = Object::load($Entity, $_REQUEST[$varName]); if (Tools::isEmptyObject($Object)) { return false; } else { return $_REQUEST[$varName]; } } else { for ($i = 0; $i < count($_REQUEST[$varName]); $i++) { $Object = Object::load($Entity, $_REQUEST[$varName][$i]); if (Tools::isEmptyObject($Object)) { unset($Object); continue; } $validIdArray[] = $_REQUEST[$varName][$i]; unset($Object); } } if (empty($validIdArray)) { return false; } return $validIdArray; }
/** * return true si l'entité est public et accessible via le Master * * @param string $entity Entité à chercher * @return bool * @access public */ public static function isPublicEntity($entity) { if ($entity == 'Entity') { return true; } $e = Object::load('Entity', array('Name' => $entity, 'Public' => 1)); return DATABASE_ID == 0 && $e instanceof Entity; }
/** * Retourne l'utilisateur (useraccount) connecté ou false. * * @access public * @return mixed object UserAccount ou false */ public function getUser() { if (!self::$hasAuth) { return false; } if (isset($_SESSION[USER_SESSION_NAME])) { return Object::load('UserAccount', $_SESSION[USER_SESSION_NAME]); } return false; }
/** * Test that an exception is thrown if no method is given * * @return void * @author Dan Cox */ public function test_noMethodGiven() { $this->setExpectedException('Masquerade\\Exceptions\\InvalidClassMethodCalled'); $str = '[tester]'; $str = $this->matcher->load($str, $this->collection)->searchAndReplace(); }