SL Reseplanerare 2 -> Geometry

See https://www.trafiklab.se/api/sl-reseplanerare-2

@link https://www.trafiklab.se/api/sl-reseplanerare-2
@param string $ref
@return mixed
172961
public function slReseplanerare2Geometry($ref) {
        $url = $this->SlReseplanerare2URL.'/geometry.json';

        $params = [
            'key' => $this->slReseplanerare2key,
            'ref' => $ref
        ];

        $request = $this->client->request('GET', $url, [
            'query' => $params
        ]);

        $json = json_decode($request->getBody(), true);
        return $json;
    }
862156
public function getByReference($reference, $type)
    {
        if (!isset($this->store[$type])) {
            return false;
        }

        $count = count($this->store[$type]);

        if ($reference >= $count) {
            throw new DeserializationException('Invalid ' . $type . ' reference: ' . $reference);
        }

        if (!$count) {
            return false;
        }

        return $this->store[$type][$reference];
    }
721119
public function getDocumentByReference(array $ref, $useDocumentPool = true)
    {
        $documentArray = $this->getMongoDB()->getDBRef($ref);
        if (null === $documentArray) {
            return null;
        }

        return $this->getCollection($ref['$ref'])->hydrate($documentArray, $useDocumentPool);
    }
1049070
public function selectByRef(ARef $ref)
    {
        $type  = $ref->getType();
        $type_name = $type->getName();
        $id = $ref->getId();

        $table = $this->getTable($type);

        $query = new QueryBuilder(DB::table($table));
        $query->where($table.'.name', '=', $type_name);

        if($id > 0)
        {
            $query->where($table.'.id', '=', $id);
        }

        return $query;
    }
561185
public function getTraverser()
    {
        if (!$this->traverser) {
            $this->traverser = new NodeTraverser;
            $this->traverser->addVisitor(new NameResolver);
            $this->traverser->addVisitor($this->getVisitor());
        }

        return $this->traverser;
    }
805952
private function resolveSchema($reference)
    {
        $schema = $reference;
        if (property_exists($reference, '$ref')) {
            $schemaResolver = $this->document->getSchemaResolver();
            $ref = new Reference($reference);
            $schema = $schemaResolver->resolveReference($ref)->getDocument();
        } elseif ($reference->type === 'array' && !empty($reference->items)) {
            $schema->items = $this->resolveSchema($reference->items);
        }

        // resolve properties
        if (!empty($schema->properties)) {
            $properties = (array) $schema->properties;
            foreach ($properties as $name => $property) {
                if (isset($property->type)
                    && $property->type === 'array'
                    && isset($property->items)
                    && property_exists($property->items, '$ref')
                    && !isset($schema->properties->$name->items)) {
                    $schema->properties->$name->items = $this->resolveSchema($property->items);
                } elseif (property_exists($property, '$ref') && !isset($schema->properties->$name)) {
                    $schema->properties->$name = $this->resolveSchema($property);
                }
            }
        }

        return $schema;
    }
704316
public function checkout($ref)
    {
        $this->clearAll();

        $what = $ref;
        if ($ref instanceof Branch) {
            $what = $ref->getName();
        } elseif ($ref instanceof TreeishInterface) {
            $what = $ref->getSha();
        }

        $this->addCommandName(self::GIT_CHECKOUT);
        $this->addCommandArgument('-q');
        $this->addCommandSubject($what);

        return $this->getCommand();
    }
475415
public function getDocumentByReference(array $ref, $useDocumentPool = true)
    {
        $documentArray = $this->getMongoCollection()->getDBRef($ref);
        if (null === $documentArray) {
            return null;
        }

        return $this->hydrate($documentArray, $useDocumentPool);
    }
90164
public function getByRef(ARef $ref, $asUnitMember = false)
    {
        $ownerType = $ref->getType();
        $owner_name = $ownerType->getName();
        $rank = $ownerType->getRank();

        if($rank === TypeRank::GROUP and $asUnitMember)
        {
            $selectionUnit = $this->tuner->getSelection($owner_name, 'group');

            return $this->select($selectionUnit);
        }

        $owner_id = $ref->getId();

        $key = $owner_name.'_'.$owner_id;

        if(array_key_exists($key, $this->units))
        {
            return $this->units[$key];
        }

        $collection = new MapScalarCollection($this->factory);
        $this->units[$key] = $collection;

        foreach($this->tables as $type_name => $table)
        {
            $query = DB::table($table);
            $query->where($table.'.entity_name', '=', $owner_name);
            $query->where($table.'.entity_id', '=', $owner_id);

            $result = Helpers::laravel_db_result_to_array($query->get(['entity_name', 'entity_id', 'name', 'value']));

            $this->addResultToCollection($type_name, $ownerType, $collection, $result);
        }

        return $collection;
    }
535100
protected function refToArray($ref)
    {
        $offset = 64;

        $len = strlen($ref);

        $div = 0;
        for ($i = 0; $i < $len; $i++) {
            $char = substr($ref, $i, 1);
            if (is_numeric($char)) {
                $div = $i;
                break;
            }
        }
        if ($div < 1) {
            return false;
        }

        $row = substr($ref, $div);

        $place_col = 0;
        $col = 0;
        for ($i = $div - 1; $i >= 0; $i--) {
            $place_weight = pow(26, $place_col);
            $place_value = ord(substr($ref, $i, 1)) - $offset;
            $col += $place_value * $place_weight;
            $place_col++;
        }

        //return as 0 based
        return array("row" => $row - 1, "col" => $col - 1);
    }
338899
public function create(string $ref, string $sha): array
    {
        return $this->getApi()->request($this->getApi()
                                             ->sprintf('/repos/:owner/:repo/git/refs', $this->getGitData()->getOwner(),
                                                 $this->getGitData()->getRepo()), Request::METHOD_POST, [
                'ref' => $ref,
                'sha' => $sha
            ]);
    }
175379
public function update(string $ref, string $sha, bool $force = false): array
    {
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/git/refs/:ref',
            $this->getGitData()->getOwner(), $this->getGitData()->getRepo(), $ref), Request::METHOD_POST, [
                'sha'   => $sha,
                'force' => $force
            ]);
    }
1290067
protected function doGetDBRef(array $reference)
    {
        $riak = $this->riak;
        return $this->retry(function() use ($riak, $reference) {
            return $riak->getDBRef($reference);
        });
    }
856878
public function mapReference($alias)
    {
        //$alias = strval($alias);
        $reference = array_key_exists($alias, $this->aliases);

        if (array_key_exists($alias, $this->aliases)) {
            return $this->aliases[$alias];
        }

        return $alias;
    }
886649
public function reScale($factor=2) {
        $newbuckets = array();
        $newscale = $this->scale * $factor;
        $newstart = (int) ($this->timestart / $factor);
        foreach($this->buckets as $k => $v) {
            $oldtime = ($this->timestart + $k) * $this->scale;
            $newposition = (int) ($oldtime / $newscale);
            $delta = $newposition - $newstart;
            if ( isset($newbuckets[$delta]) ) {
                $newbuckets[$delta] += $v;
            } else {
                $newbuckets[$delta] = $v;
            }
        }
        return $newbuckets;
    }
726678
public function getRef($reference)
    {
        $array = ! isset($reference['$ref']);
        $reference = $array ? $reference : [$reference];
        $database = $this->database;

        $result = array_map(
            function ($ref) use ($database) {
                return MongoDBRef::get($database, $ref);
            },
            $reference
        );

        return $array ? $result : reset($result);
    }
1047023
function getReference($table, $ref = null) {
		if (isset($this->references[$table])) {
			if (!strlen($ref)) {
				return current($this->references[$table]);
			}
			if (isset($this->references[$table][$ref])) {
				return $this->references[$table][$ref];
			}
		}
	}