Esempio n. 1
0
 /**
  * @param string $name
  * @param mixed  $default
  *
  * @return mixed
  */
 protected function attr($name, $default = null)
 {
     if (!array_key_exists($name, $this->paths)) {
         throw new \InvalidArgumentException(sprintf('unknown attribute requested "%s"', $name));
     }
     return \igorw\get_in($this->raw, $this->paths[$name], $default);
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function getDistance(Coordinate $from, Coordinate $to)
 {
     if ($from == $to) {
         return $this->createDistance(0);
     }
     $params = $this->getParams();
     $params['origins'] = $from . '';
     $params['destinations'] = $to . '';
     $params['units'] = 'metric';
     $json = $this->getQueryJson($params);
     if (!isset($json)) {
         throw new ProviderError('Wrong json responce');
     }
     if ($json['status'] == 'OVER_QUERY_LIMIT') {
         throw new QuotaExceeded();
     } elseif ($json['status'] != 'OK') {
         throw new ProviderError('Provider return status: ' . $json->status);
     }
     try {
         $distance = \igorw\get_in($json, ['rows', 0, 'elements', 0, 'distance', 'value']);
     } catch (\InvalidArgumentException $exp) {
         throw new ProviderError('Provider responce format changed');
     }
     return $this->createDistance($distance);
 }
Esempio n. 3
0
 /**
  * @param string $query
  */
 private function executeQuery($query)
 {
     $request = $this->getMessageFactory()->createRequest('GET', $query);
     $content = (string) $this->getHttpClient()->sendRequest($request)->getBody();
     if (empty($content)) {
         throw new NoResult(sprintf('Could not execute query "%s".', $query));
     }
     $json = json_decode($content, true);
     if (!is_array($json) || !count($json)) {
         throw new NoResult(sprintf('Could not execute query "%s".', $query));
     }
     if (!array_key_exists('geoplugin_status', $json) || 200 !== $json['geoplugin_status'] && 206 !== $json['geoplugin_status']) {
         throw new NoResult(sprintf('Could not execute query "%s".', $query));
     }
     $data = array_filter($json);
     $adminLevels = [];
     $region = \igorw\get_in($data, ['geoplugin_regionName']);
     $regionCode = \igorw\get_in($data, ['geoplugin_regionCode']);
     if (null !== $region || null !== $regionCode) {
         $adminLevels[] = ['name' => $region, 'code' => $regionCode, 'level' => 1];
     }
     $results = [];
     $results[] = array_merge($this->getDefaults(), ['locality' => isset($data['geoplugin_city']) ? $data['geoplugin_city'] : null, 'country' => isset($data['geoplugin_countryName']) ? $data['geoplugin_countryName'] : null, 'countryCode' => isset($data['geoplugin_countryCode']) ? $data['geoplugin_countryCode'] : null, 'adminLevels' => $adminLevels, 'latitude' => isset($data['geoplugin_latitude']) ? $data['geoplugin_latitude'] : null, 'longitude' => isset($data['geoplugin_longitude']) ? $data['geoplugin_longitude'] : null]);
     return $this->returnResults($results);
 }
Esempio n. 4
0
 function __get($path)
 {
     $ret = \igorw\get_in(null !== $this->label ? $this->all() : $this->ast, preg_split('/\\s+/', $path));
     if (null === $ret && $this->parent) {
         $ret = $this->parent->{$path};
     }
     return $ret;
 }
 /**
  * @param array $citationData
  * @param string $currentChoice
  * @return bool
  */
 protected function citationMatches(array $citationData, $currentChoice)
 {
     $currentValue = \igorw\get_in($citationData, [$currentChoice], null);
     if (!$currentValue) {
         return false;
     }
     return $this->allWordsNumeric($currentValue);
 }
Esempio n. 6
0
 /**
  * @param array $citationData
  * @return string
  */
 public function render(array $citationData)
 {
     $variableNameWithForm = sprintf('%s-%s', $this->variable, $this->form);
     if ($this->form && isset($citationData[$variableNameWithForm])) {
         return $citationData[$variableNameWithForm];
     }
     $render = \igorw\get_in($citationData, [$this->variable], '');
     $this->publishUsage($render);
     return $render;
 }
Esempio n. 7
0
 /**
  * @param Address $address
  *
  * @return string
  */
 protected function formatName(Address $address)
 {
     $name = [];
     $array = $address->toArray();
     $attrs = [['streetNumber'], ['streetName'], ['postalCode'], ['locality'], ['adminLevels', 2, 'name'], ['adminLevels', 1, 'name'], ['country']];
     foreach ($attrs as $attr) {
         $name[] = \igorw\get_in($array, $attr);
     }
     return implode(', ', array_filter($name));
 }
Esempio n. 8
0
File: Theme.php Progetto: ovr/epilog
 /**
  * @param string $themeFile
  */
 public function __construct($themeFile)
 {
     if (!is_readable($themeFile)) {
         throw new InvalidArgumentException('Invalid theme given.');
     }
     $themes = [];
     $themes[] = $theme = Yaml::parse($themeFile);
     $themeDir = dirname($themeFile);
     while ($theme = \igorw\get_in($theme, ['theme', 'extends'], false)) {
         $themes[] = $theme = Yaml::parse($themeDir . '/' . $theme . '.yml');
     }
     $this->data = call_user_func_array('array_replace_recursive', array_reverse($themes))['theme'];
 }
Esempio n. 9
0
 /**
  * {@inheritDoc}
  */
 public function getDistance(Coordinate $from, Coordinate $to)
 {
     if ($from == $to) {
         return $this->createDistance(0);
     }
     $json = $this->getQueryJson($this->baseUrl . '/table?loc=' . $from . '&loc=' . $to);
     if (!isset($json) || !isset($json['distance_table'])) {
         throw new ProviderError('Wrong json responce');
     }
     try {
         $distance = \igorw\get_in($json, ['distance_table', 0, 0]);
     } catch (\InvalidArgumentException $exp) {
         throw new ProviderError('Provider responce format changed');
     }
     return $this->createDistance($distance);
 }
Esempio n. 10
0
 /**
  * {@inheritDoc}
  */
 public function getDistance(Coordinate $from, Coordinate $to)
 {
     $params = array('locations' => array(array('lat' => $from->getLat(), 'lng' => $from->getLng()), array('lat' => $to->getLat(), 'lng' => $to->getLng())));
     $json = $this->getQueryJson($params);
     if (!isset($json)) {
         throw new ProviderError('Wrong json responce');
     }
     if ($json['count'] <= 0) {
         throw new ProviderError('Provider not return distances');
     }
     try {
         $distance = \igorw\get_in($json, ['distances', 0, 'distance']);
     } catch (\InvalidArgumentException $exp) {
         throw new ProviderError('Provider responce format changed');
     }
     return $this->createDistance($distance);
 }
 public function testSetHost()
 {
     $conf = $this->provideConfiguration(__DIR__ . '/Fixtures/configuration-with-hosts.yml');
     $conf->setHost('http://local.dedicated-host');
     $this->assertEquals('Hosted Man !', \igorw\get_in($conf->getConfig(), ['registry', 'general', 'title']));
     $this->assertEquals('http://local.dedicated-host', \igorw\get_in($conf->getConfig(), ['servername']));
     $this->assertFalse(\igorw\get_in($conf->getConfig(), ['main', 'maintenance']));
     $this->assertFalse(\igorw\get_in($conf->getConfig(), ['border-manager', 'enabled']));
     $conf->setHost('local.dedicated-host');
     $this->assertEquals('Hosted Man !', \igorw\get_in($conf->getConfig(), ['registry', 'general', 'title']));
     $this->assertEquals('http://local.dedicated-host', \igorw\get_in($conf->getConfig(), ['servername']));
     $this->assertFalse(\igorw\get_in($conf->getConfig(), ['main', 'maintenance']));
     $this->assertFalse(\igorw\get_in($conf->getConfig(), ['border-manager', 'enabled']));
     $conf->setHost(null);
     $this->assertEquals('SuperPhraseanet', \igorw\get_in($conf->getConfig(), ['registry', 'general', 'title']));
     $this->assertEquals('http://local.phrasea/', \igorw\get_in($conf->getConfig(), ['servername']));
     $this->assertFalse(\igorw\get_in($conf->getConfig(), ['main', 'maintenance']));
     $this->assertTrue(\igorw\get_in($conf->getConfig(), ['border-manager', 'enabled']));
 }
Esempio n. 12
0
 public function __construct($name, $type, array $options = [])
 {
     $this->name = (string) $name;
     $this->type = $type;
     $this->is_searchable = \igorw\get_in($options, ['searchable'], true);
     $this->is_private = \igorw\get_in($options, ['private'], false);
     $this->facet = \igorw\get_in($options, ['facet']);
     $this->thesaurus_roots = \igorw\get_in($options, ['thesaurus_roots'], null);
     $this->used_by_collections = \igorw\get_in($options, ['used_by_collections'], []);
     Assertion::boolean($this->is_searchable);
     Assertion::boolean($this->is_private);
     if ($this->facet !== self::FACET_DISABLED) {
         Assertion::integer($this->facet);
     }
     if ($this->thesaurus_roots !== null) {
         Assertion::allIsInstanceOf($this->thesaurus_roots, Concept::class);
     }
     Assertion::allScalar($this->used_by_collections);
 }
Esempio n. 13
0
 /**
  * {@inheritDoc}
  */
 public function getDistance(Coordinate $from, Coordinate $to)
 {
     if ($from == $to) {
         return $this->createDistance(0);
     }
     $params = $this->getParams();
     $params['from_point'] = $from->getLat() . ',' . $from->getLng();
     $params['to_point'] = $to->getLat() . ',' . $to->getLng();
     $params['out_array'] = 'distances';
     $json = $this->getQueryJson($params);
     if (!isset($json) || !isset($json['distances'])) {
         throw new ProviderError('Wrong json responce');
     }
     try {
         $distance = \igorw\get_in($json, ['distances', 0, 0]);
     } catch (\InvalidArgumentException $exp) {
         throw new ProviderError('Provider responce format changed');
     }
     return $this->createDistance($distance);
 }
Esempio n. 14
0
 private function hydrate(array &$record, array $fields, array $index_fields)
 {
     if (!isset($record['databox_id'])) {
         throw new Exception('Expected a record with the "databox_id" key set.');
     }
     $values = array();
     $terms = array();
     $filters = array();
     $field_names = array();
     foreach ($fields as $name => $root_concepts) {
         // Loop through all values to prepare bulk query
         $field_values = \igorw\get_in($record, explode('.', $index_fields[$name]));
         if ($field_values !== null) {
             // Concepts are databox's specific, but when no root concepts are
             // given we need to make sure we only match in the right databox.
             $filter = $root_concepts ? Filter::childOfConcepts($record['databox_id'], $root_concepts) : Filter::byDatabox($record['databox_id']);
             foreach ($field_values as $value) {
                 $values[] = $value;
                 $terms[] = Term::parse($value);
                 $filters[] = $filter;
                 $field_names[] = $name;
             }
         }
     }
     $bulk = $this->thesaurus->findConceptsBulk($terms, null, $filters, true);
     foreach ($bulk as $offset => $item_concepts) {
         if ($item_concepts && is_array($item_concepts) && count($item_concepts) > 0) {
             $name = $field_names[$offset];
             foreach ($item_concepts as $concept) {
                 $record['concept_path'][$name][] = $concept->getPath();
             }
         } else {
             $this->candidate_terms->insert($field_names[$offset], $values[$offset]);
         }
     }
 }
Esempio n. 15
0
 private function replaceAdmins($data)
 {
     $adminLevels = [];
     $region = \igorw\get_in($data, ['region']);
     $regionCode = \igorw\get_in($data, ['regionCode']);
     unset($data['region'], $data['regionCode']);
     if (null !== $region || null !== $regionCode) {
         $adminLevels[] = ['name' => $region, 'code' => $regionCode, 'level' => 1];
     }
     $data['adminLevels'] = $adminLevels;
     return $data;
 }
Esempio n. 16
0
 /**
  * @return bool
  */
 public function punctuationInQuote()
 {
     return \igorw\get_in($this->styleOptions, ['punctuationInQuote'], false);
 }
Esempio n. 17
0
 /**
  * @param array $selectedCollections
  * @return array
  */
 private function getAuthorizedCollections(array $selectedCollections = null)
 {
     $inscriptions = $this->registrationManager->getRegistrationSummary();
     $authorizedCollections = [];
     foreach ($this->appbox->get_databoxes() as $databox) {
         foreach ($databox->get_collections() as $collection) {
             if (null !== $selectedCollections && !in_array($collection->get_base_id(), $selectedCollections)) {
                 continue;
             }
             if ($canRegister = \igorw\get_in($inscriptions, [$databox->get_sbas_id(), 'config', 'collections', $collection->get_base_id(), 'can-register'])) {
                 $authorizedCollections[$collection->get_base_id()] = $canRegister;
             }
         }
     }
     return $authorizedCollections;
 }
Esempio n. 18
0
 /**
  * @param  array  $data
  * @param  string $key
  * @return array
  */
 private function readArrayValue(array $data, $key)
 {
     return \igorw\get_in($data, [$key]) ?: [];
 }
Esempio n. 19
0
 /**
  * @SuppressWarnings(PHPMD.ShortMethodName)
  */
 private function in(array $array, array $keys)
 {
     return \igorw\get_in($array, $keys);
 }
Esempio n. 20
0
 /**
  * {@inheritdoc}
  */
 public function getUrl()
 {
     $base = parse_url(\igorw\get_in($this->raw, ['self']), PHP_URL_HOST);
     $proto = parse_url(\igorw\get_in($this->raw, ['self']), PHP_URL_SCHEME);
     return sprintf('%s://%s/browse/%s', $proto, $base, $this->raw['key']);
 }
Esempio n. 21
0
 private function settingOrBlank($settingName)
 {
     return \igorw\get_in($this->settings, [$settingName], '');
 }
 protected function citationMatches(array $citationData, $currentChoice)
 {
     return \igorw\get_in($citationData, ['type']) === $currentChoice;
 }
Esempio n. 23
0
 /**
  * @param string $name
  * @return mixed
  */
 public function __get($name)
 {
     return new $this->maybeClass(\igorw\get_in($this->rawValue, [$name]));
 }
Esempio n. 24
0
 public function get($key, $default = null)
 {
     return \igorw\get_in($this->data, $this->makePath($key), $default);
 }
Esempio n. 25
0
 /**
  * Find concepts linked to the provided Term
  *
  * In strict mode, term context matching is enforced:
  *   `orange (color)` will *not* match `orange` in the index
  *
  * @param  Term|string $term   Term object or a string containing term's value
  * @param  string|null $lang   Input language ("fr", "en", ...) for more effective results
  * @param  Filter|null $filter Filter to restrict search on a specified subset
  * @param  boolean     $strict Whether to enable strict search or not
  * @return Concept[]           Matching concepts
  */
 public function findConcepts($term, $lang = null, Filter $filter = null, $strict = false)
 {
     if (!$term instanceof TermInterface) {
         $term = new Term($term);
     }
     $this->logger->info(sprintf('Searching for term %s', $term), array('strict' => $strict, 'lang' => $lang));
     if ($strict) {
         $field_suffix = '.strict';
     } elseif ($lang) {
         $field_suffix = sprintf('.%s', $lang);
     } else {
         $field_suffix = '';
     }
     $field = sprintf('value%s', $field_suffix);
     $query = array();
     $query['match'][$field]['query'] = $term->getValue();
     $query['match'][$field]['operator'] = 'and';
     // Allow 25% of non-matching tokens
     // (not exactly the same that 75% of matching tokens)
     // $query['match'][$field]['minimum_should_match'] = '-25%';
     if ($term->hasContext()) {
         $value_query = $query;
         $field = sprintf('context%s', $field_suffix);
         $context_query = array();
         $context_query['match'][$field]['query'] = $term->getContext();
         $context_query['match'][$field]['operator'] = 'and';
         $query = array();
         $query['bool']['must'][0] = $value_query;
         $query['bool']['must'][1] = $context_query;
     } elseif ($strict) {
         $context_filter = array();
         $context_filter['missing']['field'] = 'context';
         $query = self::applyQueryFilter($query, $context_filter);
     }
     if ($lang) {
         $lang_filter = array();
         $lang_filter['term']['lang'] = $lang;
         $query = self::applyQueryFilter($query, $lang_filter);
     }
     if ($filter) {
         $this->logger->debug('Using filter', array('filter' => Filter::dump($filter)));
         $query = self::applyQueryFilter($query, $filter->getQueryFilter());
     }
     // Path deduplication
     $aggs = array();
     $aggs['dedup']['terms']['field'] = 'path.raw';
     // Search request
     $params = array();
     $params['index'] = $this->options->getIndexName();
     $params['type'] = TermIndexer::TYPE_NAME;
     $params['body']['query'] = $query;
     $params['body']['aggs'] = $aggs;
     // Arbitrary score low limit, we need find a more granular way to remove
     // inexact concepts.
     // We also need to disable TF/IDF on terms, and try to boost score only
     // when the search match nearly all tokens of term's value field.
     $params['body']['min_score'] = $this->options->getMinScore();
     // No need to get any hits since we extract data from aggs
     $params['body']['size'] = 0;
     $this->logger->debug('Sending search', $params['body']);
     $response = $this->client->search($params);
     // Extract concept paths from response
     $concepts = array();
     $buckets = \igorw\get_in($response, ['aggregations', 'dedup', 'buckets'], []);
     $keys = array();
     foreach ($buckets as $bucket) {
         if (isset($bucket['key'])) {
             $keys[] = $bucket['key'];
             $concepts[] = new Concept($bucket['key']);
         }
     }
     $this->logger->info(sprintf('Found %d matching concepts', count($concepts)), array('concepts' => $keys));
     return $concepts;
 }
Esempio n. 26
0
 /**
  * {@inheritdoc}
  */
 public function getType()
 {
     return \igorw\get_in($this->raw->getIssueType(), ['name']);
 }
Esempio n. 27
0
 /**
  * @param array $settings
  */
 public function __construct(array $settings = [])
 {
     $this->delimiter = \igorw\get_in($settings, ['delimiter']);
 }
Esempio n. 28
0
 /**
  * Gets the value given one or more properties
  *
  * @param array|string $props   The property to get
  * @param mixed        $default The default value to return in case the property is not accessible
  *
  * @return mixed
  */
 public function get($props, $default = null)
 {
     return \igorw\get_in($this->conf->getConfig(), $this->arrayize($props), $default);
 }