/** * @return array */ public function getBreadcrumbList() { $crumbs = []; $tree = $this->tree; // Work through our parts and see if there is a translation for them foreach (explode('/', $this->uri) as $crumb) { // do a standard lookup first $lang = Arr::get($tree, $crumb, null); // if it's an array, it's a folder, so fetch it's title if (is_array($lang)) { $crumbs[$crumb] = Arr::get($lang, '__title', $crumb); $tree = $lang; } elseif ($lang) { $crumbs[$crumb] = $lang; } else { // start with an untranslated default $crumbs[$crumb] = $crumb; // loop over the translations to find a match foreach ($tree as $name => $lang) { // do we need preprocessing of the filename found? if ($this->preProcessor instanceof Closure) { $lookup = $this->preProcessor->__invoke($name); } else { $lookup = $name; } if ($lookup == $crumb) { $crumbs[$crumb] = $lang; break; } } } } return $crumbs; }
public function html() { // Pull Meter Details if ($meter = Arr::get($this->data, 'Meter')) { foreach ($meter as $key => $value) { $meterDetails[] = '<div class="aeon ' . strtolower($key) . '">' . $value . '</div>'; } $return[] = implode($meterDetails, PHP_EOL) . PHP_EOL; } // Check for key change if ($bss = Arr::get($this->data, 'BSSTTokens.BSSTToken')) { foreach ($bss as $token) { $bssTokens[] = '<div class="aeon bss ' . strtolower($key) . '">' . $value . '</div>'; } $return[] = implode($bssTokens, PHP_EOL) . PHP_EOL; } // Other info $otherInfo['utility'] = Arr::get($this->data, 'Utility'); $otherInfo['custMsg'] = Arr::get($this->data, 'CustMsg'); $otherInfo['vatNo'] = Arr::get($this->data, 'VatNo'); $otherInfo['transRef'] = Arr::get($this->data, 'TransRef'); $otherInfo['tariffName'] = Arr::get($this->data, 'TariffName'); $otherInfo['reference'] = Arr::get($this->data, 'Reference'); $otherInfo['reprint'] = Arr::get($this->data, 'Reprint'); foreach (array_filter($otherInfo) as $key => $value) { $info[] = '<div class="aeon info ' . strtolower($key) . '">' . $value . '</div>'; } $return[] = implode($info, PHP_EOL) . PHP_EOL; // Return all; return implode($return); }
/** * Object constructor * * @param string * @param array */ protected function __construct($name, array $config = array()) { // Grab the form attributes $formAttributes = Arr::get($config, 'form_attributes', array()); $this->form = new Form(); $this->form->setAttributes($formAttributes); $this->form->setName($name); }
/** * Returns the ID * * @return string */ public function getId() { if (isset($this->id)) { return $this->id; } $ignoreKeys = array(); if (isset($this->ignoreKeys)) { $ignoreKeys = $this->ignoreKeys; } // Filter ignored keys $hashData = Arr::filterKeys($this->data, $ignoreKeys, true); return md5(serialize($hashData)); }
/** * Populates the fields using the array passed. * * @param array $data The data to use for population. * * @return \Fuel\Fieldset\InputContainer * * @since 2.0 */ public function populate($data) { // Loop through all the elements assigned and attempt to assign a value to them. foreach ($this->getContents() as $item) { if ($item instanceof InputContainer) { // This is another Fieldset or Form so needs to be populated too $item->populate($data); } else { // Convert the name to a dot notation for better searching $key = $this->inputNameToKey($item->getName()); $value = Arr::get($data, $key); if (!is_null($value)) { $item->setValue($value); } } } return $this; }
/** * Inserts an assoc element to container * * @param string $key * @param mixed $value * @param integer $pos * * @return DataContainer * * @throws RuntimeException */ public function insertAssoc($key, $value, $pos = null) { if ($pos === null) { $this->set($key, $value); } else { if ($this->readOnly) { throw new \RuntimeException('Changing values on this Data Container is not allowed.'); } $this->isModified = true; if (abs($pos) > count($this->data)) { $pos = count($this->data) * min(1, max(-1, $pos)); } if ($key === null) { Arr::insert($this->data, $value, $pos); } else { Arr::insertAssoc($this->data, array($key => $value), $pos); } } return $this; }
/** * Gets a value from the Input config. * * @param string|null $key Dot notated key or null for all * * @return string * * @since 2.0 */ public function config($key = null) { if (is_null($key)) { return $this->config; } return Arr::get($this->config, $key); }
/** * @covers Fuel\Common\Arr::subset * @group Common */ public function testSubset() { $input = array("user" => array("name" => "John", "surname" => "Lastname"), "project" => array("name" => "Fuel", "type" => "Framework")); $expected = array('project' => array('name' => 'Fuel'), 'user' => array('name' => 'John')); $result = Arr::subset($input, array('project.name', 'user.name')); $this->assertEquals($expected, $result); $expected = array('project' => array('name' => 'Fuel', 'manager' => null)); $result = Arr::subset($input, array('project.name', 'project.manager')); $this->assertEquals($expected, $result); $expected = array('project' => array('name' => 'Fuel', 'manager' => 'Not Provided'), 'user' => array('name' => 'John', 'surname' => 'Lastname'), 'not_provided' => 'Not Provided'); $result = Arr::subset($input, array('project.name', 'project.manager', 'user', 'not_provided'), 'Not Provided'); $this->assertEquals($expected, $result); }
/** * @param string $dir * * @return array */ protected function readDir($dir, $order, $translations) { // check if we need to split entries $splitEntries = $order & static::SORT_FILES_FIRST || $order & static::SORT_FOLDERS_FIRST; // temporary storage for results $files = []; $folders = []; if ($title = Arr::get($translations, '__title')) { if ($splitEntries) { $folders['__title'] = $title; } else { $files['__title'] = $title; } } // loop over the given folder $handle = opendir($dir); while (false !== ($entry = readdir($handle))) { // skip directory entries if ($entry == '..' || $entry == '.') { continue; } // construct the FQFN $filename = $dir . DIRECTORY_SEPARATOR . $entry; // if it's a file... if (is_file($filename)) { // do we need preprocessing of the filename found? if ($this->preProcessor instanceof Closure) { $file = $this->preProcessor->__invoke($entry); } else { $file = $entry; } // translate the filename (with or without extension) if needed $files[$entry] = Arr::get($translations, $file, $entry); } elseif (is_dir($filename)) { // recurse to add the folder contents $result = $this->readDir($filename, $order, Arr::get($translations, $entry, [])); // store the result in the correct result array if ($splitEntries) { $folders[$entry] = $result; } else { $files[$entry] = $result; } } } // do we need to other by translation sequence? $translateOrder = []; if ($order & static::SORT_TRANSLATIONS) { foreach ($translations as $name => $unused) { if ($name !== '__title') { if ($order & static::SORT_FOLDERS_FIRST) { foreach ($folders as $folder => $entry) { if ($name === $folder) { $translateOrder[$folder] = $entry; unset($folders[$folder]); break; } } } foreach ($files as $file => $entry) { if ($name === $file or strpos($file, $name . '.') === 0) { $translateOrder[$file] = $entry; unset($files[$file]); break; } } } } } // sort the result if needed if ($order & static::SORT_ASCENDING) { ksort($files); ksort($folders); } elseif ($order & static::SORT_DESCENDING) { krsort($files); krsort($folders); } // and return in the order requested if ($order & static::SORT_FOLDERS_FIRST) { return $translateOrder + $folders + $files; } return $translateOrder + $files + $folders; }
/** * @param string $key * @param null $default * * @return mixed * * @since 2.0 */ public function getMeta($key, $default = null) { return Arr::get($this->metaContainer, $key, $default); }
/** * @return bool true or false depending on the status of the input * * @since 2.0 */ public function isChecked() { return Arr::get($this->attributes, 'checked', false); }
/** * Loads a config file * * @param string $name * @param null|string|boolean $group * * @return array|null */ public function load($name, $group = null) { if ($group === true) { $group = pathinfo($name, PATHINFO_FILENAME); } if ($group and $cached = $this->get($group)) { return $cached; } $name = $this->ensureDefaultFormat($name); $paths = $this->finder->findAllFiles($name); if (empty($paths)) { return false; } $config = array(); foreach ($paths as $path) { $extension = pathinfo($path, PATHINFO_EXTENSION); $handler = $this->getHandler($extension); $config = Arr::merge($config, $handler->load($path)); } if ($group) { $this->set($group, $config); } elseif ($group === null) { $this->merge($config); } return $config; }
/** * @param string $name * * @return ModelCollectionInterface|ModelInterface|null * * @since 2.0 */ protected function loadRelations($name) { // Does it need loading? if (!isset($this->populatedRelations[$name])) { // It does so grab the data $this->populatedRelations[$name] = $this->provider->getRelation($name)->getModels($this); } // Return the relation return Arr::get($this->populatedRelations, $name); }