/** * Uses Prooph\Processing\Environment to initialize with its defaults */ public static function initializeWithDefaultsIn(ConfigLocation $configLocation, ConfigWriter $configWriter) { $env = Environment::setUp(); $instance = new self(['processing' => array_merge($env->getConfig()->toArray(), ["connectors" => [], "js_ticker" => ['enabled' => false, 'interval' => 3]])], $configLocation); $configFilePath = $configLocation->toString() . DIRECTORY_SEPARATOR . self::$configFileName; if (file_exists($configFilePath)) { throw new \RuntimeException("Processing config already exists: " . $configFilePath); } $configWriter->writeNewConfigToDirectory($instance->toArray(), $configFilePath); $instance->recordThat(ProcessingConfigFileWasCreated::in($configLocation, self::$configFileName)); return $instance; }
/** * Ищет перевод по метрике и языку. Если не находит, создает новый с названием оригинала * @param int $metric_id * @param int $lang_id * @return array */ public static function getTranslation($metric_id, $lang_id) { $translation = self::findOne(['feature_metric_id' => $metric_id, 'language_id' => $lang_id]); if (!$translation) { $original_name = FeaturesMetrics::find()->select('feature_metric')->where(['id' => $metric_id])->scalar(); $translation = new self(); $translation->metric_translation = $original_name; $translation->feature_metric_id = $metric_id; $translation->language_id = $lang_id; $translation->save(); } return $translation->toArray(); }
/** * Ищет перевод по категории и языку. Если не находит, создает новый с названием оригинала * @param int $category_id * @param int $lang_id * @return array */ public static function getTranslation($category_id, $lang_id) { $translation = self::findOne(['category_id' => $category_id, 'language_id' => $lang_id]); if (!$translation) { $original_name = Categories::find()->select('name')->where(['id' => $category_id])->scalar(); $translation = new self(); $translation->name = $original_name; $translation->category_id = $category_id; $translation->language_id = $lang_id; $translation->save(); } return $translation->toArray(); }
public function __construct($path, $environment) { $array = parse_ini_file($path, true); if (isset($array[$environment])) { $array = $this->process_key($array[$environment]); if (isset($array['config']) && !empty($array['config'])) { foreach ($array['config'] as $subPath) { $self = new self($subPath, $environment); $this->config = $self->toArray(); } } $this->config = array_merge($this->config, $array); } else { // Gestion erreur } }
/** * Output response as array */ public function toArray() { $res = array(); if ($props = $this->_response->getProperties()) { $res['properties'] = $props; } if ($keys = $this->_response->getItems()) { $res['entities'] = array(); foreach ($keys as $key => $items) { foreach ($items as $item) { if ($item instanceof Response) { $itemRes = new self($item); $item = $itemRes->toArray(); } elseif (is_array($item)) { // Assume entity properties if raw array with no 'properties' key if (!isset($item['properties'])) { $item = array('properties' => $item); } } else { throw new \InvalidArgumentException("Argument 1 passed to " . __METHOD__ . " must be of the type array or " . __CLASS__ . ", " . gettype($item) . " given"); } $res['entities'][] = $item; } } } if ($actions = $this->_response->getForms()) { $res['actions'] = array(); foreach ($actions as $name => $action) { $res['actions'][] = array_merge(array('name' => $name), $action); } } if ($links = $this->_response->getLinks()) { $res['links'] = array(); foreach ($links as $rel => $link) { if (is_array($link)) { $res['links'][] = array_merge(array('rel' => array($rel)), $link); } else { $res['links'][] = array('rel' => array($rel), 'href' => $link); } } } if ($data = $this->_response->getData()) { $res = array_merge($res, $data); } return $res; }
/** * Output response as array */ public function toArray() { $res = array(); // Properties if ($props = $this->_response->getProperties()) { $res = $props; } // Links if ($links = $this->_response->getLinks()) { $res['_links'] = array(); foreach ($links as $rel => $link) { if (is_array($link)) { $res['_links'][$rel] = $link; } else { $res['_links'][$rel] = array('href' => $link); } } } // Forms if ($forms = $this->_response->getForms()) { $res['_forms'] = array(); foreach ($forms as $name => $form) { $res['_forms'][$name] = $form; } } // Embedded items if ($keys = $this->_response->getItems()) { $res['_embedded'] = array(); foreach ($keys as $key => $items) { $options = $this->_response->getItemOptions($key); foreach ($items as $item) { if ($item instanceof Response) { $itemRes = new self($item); $item = $itemRes->toArray(); } elseif (!is_array($item)) { throw new \InvalidArgumentException("Argument 1 passed to " . __METHOD__ . " must be of the type array or " . __CLASS__ . ", " . gettype($item) . " given"); } // If set as a collection if (isset($options['collection']) && $options['collection'] === true) { $res['_embedded'][$key][] = $item; // or adding more than 1 item with the same key } elseif (isset($res['_embedded'][$key])) { if (is_array($res['_embedded'][$key]) && isset($res['_embedded'][$key][0])) { $res['_embedded'][$key][] = $item; } else { // Make into multi-dimensional array $res['_embedded'][$key] = array($res['_embedded'][$key]); $res['_embedded'][$key][] = $item; } } else { $res['_embedded'][$key] = $item; } } } } // Custom set data overrides everything else if ($data = $this->_response->getData()) { $res = array_merge($res, $data); } return $res; }
public function nsdrPopulate($tthis, $context, $data) { $context = (int) $context; $attributes = $tthis->_attributes; $nsdrNamespace = $tthis->_nsdrNamespace; $aliasedNamespace = $tthis->_aliasedNamespace; if ($context == '*') { if (isset($attributes['isDefaultContext']) && $attributes['isDefaultContext']) { // get genericData $objectClass = 'ClinicalNote'; $clinicalNoteId = 0; if (isset($attributes['clinicalNoteId'])) { $clinicalNoteId = (int) $attributes['clinicalNoteId']; } $revisionId = 0; if (isset($attributes['revisionId'])) { $revisionId = (int) $attributes['revisionId']; } $gd = new self(); $gd->objectClass = $objectClass; $gd->objectId = $clinicalNoteId; $gd->name = $nsdrNamespace; $gd->revisionId = $revisionId; $gd->loadValue(); return $gd->value; } else { // all $ret = array(); $gd = new self(); $gdIterator = $gd->getIterator(); foreach ($gdIterator as $g) { $ret[] = $g->toArray(); } return $ret; } } $gd = new self(); $gd->genericDataId = $context; $gd->populate(); return $gd->toArray(); }
/** * Assign the key's value to the property list. Handles the * nest separator for sub-properties. * * @param array $config * @param string $key * @param string $value * @throws Zend_Config_Exception * @return array */ protected function _processKey($config, $key, $value) { if (strpos($key, $this->_nestSeparator) !== false) { $pieces = explode($this->_nestSeparator, $key, 2); if (strlen($pieces[0]) && strlen($pieces[1])) { if (!isset($config[$pieces[0]])) { if ($pieces[0] === '0' && !empty($config)) { // convert the current values in $config into an array $config = array($pieces[0] => $config); } else { $config[$pieces[0]] = array(); } } elseif (!is_array($config[$pieces[0]])) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Cannot create sub-key for '{$pieces[0]}' as key already exists"); } $config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value); } else { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception("Invalid key '{$key}'"); } } else { // checks for inclusion commands (@include special key) if ($key === "@include") { $includedFilesPath = dirname($this->_fileName) . DIRECTORY_SEPARATOR . $value; $includedFiles = glob($includedFilesPath); print_r($includedFiles); $data = array(); foreach ($includedFiles as $file) { $subConfig = new self($file, $this->_rootSections); $data = array_merge($data, $subConfig->toArray()); } $config = array_merge($config, $data); } else { $config[$key] = $value; } } return $config; }
/** * Merge a Registry object into this one * * @param mixed $source Source data to merge. * @param boolean $recursive True to support recursive merge the children values. * @return boolean True on success */ public function merge($source, $recursive = false) { if (!$source) { return false; } // If the source isn't already a Registry // we'll turn it into one if (!$source instanceof Registry && !method_exists($source, 'toArray')) { $source = new self($source); } // Load the variables into the registry's default namespace. $this->bind($this->data, $source->toArray(), $recursive, false); return true; }
/** * Expands any relational properties within a result. * * @param array $model * @param array $result * @param array $namedExc * @param array $namedInc * @param array $namedExp * * @return array */ private function expand(Model $model, array $result, array $namedExc, array $namedInc, array $namedExp) { foreach ($namedExp as $k => $subExp) { $value = array_value($result, $k); if (!$this->isExpandable($model, $k, $value)) { continue; } $subExc = array_value($namedExc, $k); $subInc = array_value($namedInc, $k); // convert exclude, include, and expand into dot notation // then take the keys for a flattened dot notation $flatExc = is_array($subExc) ? array_keys(array_dot($subExc)) : []; $flatInc = is_array($subInc) ? array_keys(array_dot($subInc)) : []; $flatExp = is_array($subExp) ? array_keys(array_dot($subExp)) : []; $relation = $model->relation($k); $serializer = new self($this->request); $serializer->setExclude($flatExc)->setInclude($flatInc)->setExpand($flatExp); if ($relation instanceof Model) { $result[$k] = $serializer->toArray($relation); } else { $result[$k] = $relation; } } return $result; }