本文整理汇总了PHP中Nette\Utils\Arrays::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Arrays::get方法的具体用法?PHP Arrays::get怎么用?PHP Arrays::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Utils\Arrays
的用法示例。
在下文中一共展示了Arrays::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadConfiguration
public function loadConfiguration()
{
$container = $this->getContainerBuilder();
$config = $this->getConfig($this->defaults);
$entities = $collections = array();
foreach ($config['entity'] as $domain => $entity) {
$service = $container->addDefinition($entities[$domain] = $this->prefix($domain . '.entity'));
Compiler::parseService($service, $entity);
$service->setClass('NiceORM\\Entity')->setParameters(array('data' => NULL))->setShared(FALSE);
$container->addDefinition($collections[$domain] = $this->prefix($domain . '.collection'))->setClass('NiceORM\\ICollection')->setFactory('NiceORM\\TableCollection', array($domain, '%data%'))->setParameters(array('data'))->setShared(FALSE);
}
$fields = $refs = $related = array();
foreach ($config['tables'] as $domain => $table) {
$fields[$domain] = $refs[$domain] = $related[$domain] = array();
foreach (Arrays::get($config['fields'], $domain, array()) as $name => $column) {
$fields[$domain][is_int($name) ? $column : $name] = $column;
}
foreach (Arrays::get($config['relations'], $domain, array()) as $name => $column) {
if (is_int($name)) {
$refs[$domain][$column] = array($column, NULL, $column);
} else {
$column = array_values((array) $column);
switch (count($column)) {
case 0:
$refs[$domain][$name] = array($name, NULL, $name);
break;
case 1:
$refs[$domain][$name] = array($name, $column[0], $name);
break;
case 2:
$refs[$domain][$name] = array($column[0], $column[1], $name);
break;
default:
$refs[$domain][$name] = array($column[0], $column[1], $column[2]);
}
}
}
}
foreach ($refs as $domain => $tableRefs) {
foreach ($tableRefs as $name => $ref) {
list($table, $column, $type) = $ref;
if ($type === $name || empty($related[$type][$domain . 's'])) {
$related[$type][$domain . 's'] = array($config['tables'][$domain], $column, $domain);
} elseif (!isset($refs[$domain][$type])) {
unset($related[$type][$domain . 's']);
}
$related[$type][$domain . 's:' . $name] = array($config['tables'][$domain], $column, $domain);
}
}
$mappers = $accessors = array();
foreach ($config['tables'] as $domain => $table) {
$mapper = $container->addDefinition($mappers[$domain] = $this->prefix($domain . '.mapper'))->setClass('NiceORM\\ActiveRowMapper', array($domain, $table, $fields[$domain], $refs[$domain], $related[$domain]));
$container->addDefinition($accessors[$domain] = $this->prefix($domain . '.accessor'))->setClass('NiceORM\\ActiveRowAccessor', array('%data%', $mapper))->setParameters(array('data'))->setShared(FALSE);
}
$entityFactory = $container->addDefinition($this->prefix('entityFactory'))->setClass('NiceORM\\DIEntityFactory', array($entities));
$collectionFactory = $container->addDefinition($this->prefix('collectionFactory'))->setClass('NiceORM\\DICollectionFactory', array($collections));
$accessorFactory = $container->addDefinition($this->prefix('accessorFactory'))->setClass('NiceORM\\DIAccessorFactory', array($accessors));
$mapperAccessor = $container->addDefinition($this->prefix('mapperAccessor'))->setClass('NiceORM\\DIMapperAccessor', array($mappers));
$container->addDefinition($this->prefix('manager'))->setClass('NiceORM\\Manager')->setFactory('NiceORM\\Manager', array($entityFactory, $collectionFactory, $accessorFactory, $mapperAccessor));
}
示例2: run
/**
* @param array $args
* @return int
*/
public function run(array $args = [])
{
/** @var ICollection|Addon[] $addons */
$addons = $this->addonRepository->findBowers();
// DO YOUR JOB ===============================================
$counter = 0;
foreach ($addons as $addon) {
// Skip addon with bad data
if ($extra = $addon->github->extra) {
if ($bower = $extra->get('bower', FALSE)) {
// Create bower entity if not exist
if (!$addon->bower) {
$addon->bower = new Bower();
}
// Downloads
if ($stats = $this->bower->repo($bower['name'])) {
$addon->bower->downloads = Arrays::get($stats, ['hits'], 0);
}
// Keywords
$keywords = Arrays::get($bower, 'keywords', []);
$addon->bower->keywords = $keywords ? implode(',', $keywords) : NULL;
// Persist
$this->addonRepository->persistAndFlush($addon);
// Increase counting
$counter++;
} else {
$this->log('Skip (bower) [no bower data]: ' . $addon->fullname);
}
} else {
$this->log('Skip (bower) [no extra data]: ' . $addon->fullname);
}
}
return $counter;
}
示例3: loadConfigFiles
/**
* @param Configurator $configurator
*/
protected function loadConfigFiles(Configurator $configurator)
{
if ($this->autoloadConfig === TRUE || is_array($this->autoloadConfig)) {
$scanDirs = $this->autoloadConfig === TRUE ? [$this->appDir] : $this->autoloadConfig;
$cache = $this->createCache();
$files = $cache->load(self::CACHE_NAMESPACE);
if ($files === NULL) {
$files = [0 => []];
foreach (Finder::findFiles('*.neon')->from($scanDirs) as $path => $file) {
$content = Neon::decode(file_get_contents($path));
if (!is_array($content) || !array_key_exists('autoload', $content)) {
continue;
}
$autoload = Arrays::get($content, ['autoload', 0], FALSE);
if ($autoload === FALSE) {
continue;
}
$autoload = is_int($autoload) ? $autoload : 0;
if (!isset($files[$autoload])) {
$files[$autoload] = [];
}
$files[$autoload][] = $path;
}
$cache->save(self::CACHE_NAMESPACE, $files);
}
foreach ($files as $priorityFiles) {
foreach ($priorityFiles as $config) {
$configurator->addConfig($config);
}
}
}
foreach ($this->configs as $config) {
$configurator->addConfig($config);
}
}
示例4: loadHttpData
/**
* Loads HTTP data.
*
* @return void
*/
public function loadHttpData()
{
$path = $this->getHtmlName();
// img_x or img['x']
$path = explode('[', strtr(str_replace(']', '', strpos($path, '[') === false ? $path . '.x' : substr($path, 0, -2)), '.', '_'));
$this->setValue(Nette\Utils\Arrays::get($this->getForm()->getHttpData(), $path, null));
}
示例5: getHttpData
/**
* @return mixed|NULL
*/
private function getHttpData()
{
if ($this->http_post === NULL) {
$path = explode(self::NAME_SEPARATOR, $this->lookupPath('Nette\\Forms\\Form'));
$this->http_post = Nette\Utils\Arrays::get($this->getForm()->getHttpData(), $path, NULL);
}
return $this->http_post;
}
示例6: translate
/**
* @param string $message
* @param int $count
* @return string
*/
function translate($message, $count = 0)
{
if (substr($message, 0, 5) != "book.") {
return "";
}
$this->loadTexts();
return Arrays::get($this->texts, substr($message, 5), "");
}
示例7: get
/**
* @param string $name
* @param mixed $default
* @return mixed
*/
public function get($name, $default = NULL)
{
if (func_num_args() > 1) {
return Arrays::get($this->parameters, $name, $default);
} else {
return Arrays::get($this->parameters, $name);
}
}
示例8: loadHttpData
/**
* Loads HTTP data.
* @return void
*/
public function loadHttpData()
{
$path = \explode('[', \strtr(\str_replace(array('[]', ']'), '', $this->getHtmlName()), '.', '_'));
$origValue = Arrays::get($this->getForm()->getHttpData(), $path);
$from = isset($origValue['from']) ? $origValue['from'] : '';
$to = isset($origValue['to']) ? $origValue['to'] : '';
$value = array('from' => $from, 'to' => $to);
$this->setValue($value);
}
示例9: expand
/**
* Expands %placeholders%.
* @param mixed
* @param array
* @param bool
* @return mixed
* @throws Nette\InvalidArgumentException
*/
public static function expand($var, array $params, $recursive = FALSE)
{
if (is_array($var)) {
$res = array();
foreach ($var as $key => $val) {
$res[$key] = self::expand($val, $params, $recursive);
}
return $res;
} elseif ($var instanceof \stdClass || $var instanceof Statement) {
$res = clone $var;
foreach ($var as $key => $val) {
$res->$key = self::expand($val, $params, $recursive);
}
return $res;
} elseif (!is_string($var)) {
return $var;
}
$parts = preg_split('#%([\w.-]*)%#i', $var, -1, PREG_SPLIT_DELIM_CAPTURE);
$res = '';
foreach ($parts as $n => $part) {
if ($n % 2 === 0) {
$res .= $part;
} elseif ($part === '') {
$res .= '%';
} elseif (isset($recursive[$part])) {
throw new Nette\InvalidArgumentException(sprintf('Circular reference detected for variables: %s.', implode(', ', array_keys($recursive))));
} else {
try {
$val = Nette\Utils\Arrays::get($params, explode('.', $part));
} catch (Nette\InvalidArgumentException $e) {
throw new Nette\InvalidArgumentException("Missing parameter '$part'.", 0, $e);
}
if ($recursive) {
$val = self::expand($val, $params, (is_array($recursive) ? $recursive : array()) + array($part => 1));
}
if (strlen($part) + 2 === strlen($var)) {
return $val;
}
if (!is_scalar($val)) {
throw new Nette\InvalidArgumentException("Unable to concatenate non-scalar parameter '$part' into '$var'.");
}
$res .= $val;
}
}
return $res;
}
示例10: run
/**
* @param array $args
* @return int
*/
public function run(array $args = [])
{
/** @var ICollection|Addon[] $addons */
$addons = $this->addonRepository->findComposers();
// DO YOUR JOB ===============================================
$counter = 0;
foreach ($addons as $addon) {
try {
// Skip addon with bad data
if ($extra = $addon->github->extra) {
if ($composer = $extra->get('composer', FALSE)) {
if (!isset($composer['name'])) {
throw new InvalidStateException('No composer name at ' . $addon->fullname);
}
list($owner, $repo) = explode('/', $composer['name']);
// Create composer entity if not exist
if (!$addon->composer) {
$addon->composer = new Composer();
}
// Basic info
$addon->composer->name = Arrays::get($composer, 'name', NULL);
$addon->composer->description = Arrays::get($composer, 'description', NULL);
$addon->composer->type = Arrays::get($composer, 'type', NULL);
// Downloads
if ($stats = $this->composer->repo($owner, $repo)) {
$addon->composer->downloads = Arrays::get($stats, ['package', 'downloads', 'total'], 0);
}
// Keywords
$keywords = Arrays::get($composer, 'keywords', []);
$addon->composer->keywords = $keywords ? implode(',', $keywords) : NULL;
// Persist
$this->addonRepository->persistAndFlush($addon);
// Increase counting
$counter++;
} else {
$this->log('Skip (composer) [no composer data]: ' . $addon->fullname);
}
} else {
$this->log('Skip (composer) [no extra data]: ' . $addon->fullname);
}
} catch (Exception $e) {
Debugger::log($e, Debugger::EXCEPTION);
$this->log('Skip (composer) [exception]: ' . $e->getMessage());
}
}
return $counter;
}
示例11: getValue
public function getValue()
{
if (!$this->_valueLoaded) {
$path = explode('[', strtr(str_replace(array('[]', ']'), '', $this->getHtmlName()), '.', '_'));
unset($path[count($path) - 1]);
$values = \Nette\Utils\Arrays::get((array) $this->getForm()->getHttpData(), $path, NULL);
// remove photos
if ($this->multi) {
if (!$this->fileEntity) {
$this->fileEntity = new ArrayCollection();
}
foreach ($this->fileEntity as $file) {
$delete = isset($values[$this->name . '_delete_' . $file->id]) && $values[$this->name . '_delete_' . $file->id] == 'on';
if ($delete) {
$coll = $this->fileEntity;
$coll->removeElement($file);
}
}
} else {
if ($this->fileEntity) {
$delete = isset($values[$this->name . '_delete_' . $this->fileEntity->id]) && $values[$this->name . '_delete_' . $this->fileEntity->id] == 'on';
if ($delete) {
return NULL;
}
}
}
// get photos
if ($values) {
if ($this->multi) {
for ($i = 0; $i < 20; $i++) {
if ($values[$this->name . '-' . $i] && $values[$this->name . '-' . $i]->isOk()) {
$this->fileEntity[] = $entity = new FileEntity();
$entity->setFile($values[$this->name . '-' . $i]);
}
}
} else {
if ($values[$this->name] && $values[$this->name]->isOk()) {
$this->fileEntity = $entity = new FileEntity();
$entity->setFile($values[$this->name]);
}
}
}
$this->_valueLoaded = true;
}
return $this->fileEntity;
}
示例12: extractHttpData
/**
* Extracts and sanitizes submitted form data for single control.
* @param array submitted data
* @param string control HTML name
* @param string type Form::DATA_TEXT, DATA_LINE, DATA_FILE
* @return string|string[]
*/
public static function extractHttpData(array $data, $htmlName, $type)
{
$name = explode('[', str_replace(array('[]', ']', '.'), array('', '', '_'), $htmlName));
$data = Nette\Utils\Arrays::get($data, $name, NULL);
if (substr($htmlName, -2) === '[]') {
$arr = array();
foreach (is_array($data) ? $data : array() as $v) {
$arr[] = $v = static::sanitize($type, $v);
if ($v === NULL) {
return array();
}
}
return $arr;
} else {
return static::sanitize($type, $data);
}
}
示例13: expand
/**
* Expands %placeholders%.
* @param mixed
* @param array
* @param bool
* @return mixed
* @throws Nette\InvalidArgumentException
*/
public static function expand($var, array $params, $recursive = FALSE)
{
if (is_array($var)) {
$res = array();
foreach ($var as $key => $val) {
$res[$key] = self::expand($val, $params, $recursive);
}
return $res;
} elseif ($var instanceof Statement) {
return new Statement(self::expand($var->entity, $params, $recursive), self::expand($var->arguments, $params, $recursive));
} elseif (!is_string($var)) {
return $var;
}
$parts = preg_split('#%([\\w.-]*)%#i', $var, -1, PREG_SPLIT_DELIM_CAPTURE);
$res = '';
foreach ($parts as $n => $part) {
if ($n % 2 === 0) {
$res .= $part;
} elseif ($part === '') {
$res .= '%';
} elseif (isset($recursive[$part])) {
throw new Nette\InvalidArgumentException('Circular reference detected for variables: ' . implode(', ', array_keys($recursive)) . '.');
} else {
$val = Nette\Utils\Arrays::get($params, explode('.', $part));
if ($recursive) {
$val = self::expand($val, $params, (is_array($recursive) ? $recursive : array()) + array($part => 1));
}
if (strlen($part) + 2 === strlen($var)) {
return $val;
}
if (!is_scalar($val)) {
throw new Nette\InvalidArgumentException("Unable to concatenate non-scalar parameter '{$part}' into '{$var}'.");
}
$res .= $val;
}
}
return $res;
}
示例14: extractHttpData
/**
* Extracts and sanitizes submitted form data for single control.
* @param array submitted data
* @param string control HTML name
* @param string type Form::DATA_TEXT, DATA_LINE, DATA_FILE, DATA_KEYS
* @return string|string[]
* @internal
*/
public static function extractHttpData(array $data, $htmlName, $type)
{
$name = explode('[', str_replace(array('[]', ']', '.'), array('', '', '_'), $htmlName));
$data = Nette\Utils\Arrays::get($data, $name, NULL);
$itype = $type & ~Form::DATA_KEYS;
if (substr($htmlName, -2) === '[]') {
if (!is_array($data)) {
return array();
}
foreach ($data as $k => $v) {
$data[$k] = $v = static::sanitize($itype, $v);
if ($v === NULL) {
unset($data[$k]);
}
}
if ($type & Form::DATA_KEYS) {
return $data;
}
return array_values($data);
} else {
return static::sanitize($itype, $data);
}
}
示例15: getFile
/**
* Returns uploaded file.
* @param string key (or more keys)
* @return FileUpload
*/
public final function getFile($key)
{
$args = func_get_args();
return Nette\Utils\Arrays::get($this->files, $args, NULL);
}