_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q260700
PodManager.createDocument
test
private function createDocument($type, $data = array(), $new = true) { $document = new Document($this->_toolbox, $type, $data, $new); $this->attachEventsToPod($document); return $this->setupModel($document, $document); }
php
{ "resource": "" }
q260701
PodManager.setupModel
test
private function setupModel(Document $pod) { $name = $this->_toolbox->formatModel($pod); $model = new $name(); if (!($model instanceof AModel)) { throw new PodManagerException("Custom models must inherit from the Paradox Model class."); } $model->loadPod($pod); $pod->loadModel($model); return $model; }
php
{ "resource": "" }
q260702
PodManager.determinePreviouslyStored
test
private function determinePreviouslyStored($model) { $store = $this->_toolbox->getTransactionManager()->searchCommandsByActionAndObject('PodManager:store', $model); $delete = $this->_toolbox->getTransactionManager()->searchCommandsByActionAndObject('PodManager:delete', $model); $storePosition = $store ? $store['position'] : -1; $deletePosition = $delete ? $delete['position'] : -1; if ($deletePosition >= $storePosition) { return false; } else { return $store['id']; } }
php
{ "resource": "" }
q260703
PodManager.addTransactionCommand
test
private function addTransactionCommand($command, $action, $object = null, $isGraph = false, $data = array()) { return $this->_toolbox->getTransactionManager()->addCommand($command, $action, $object, $isGraph, $data); }
php
{ "resource": "" }
q260704
PodManager.validateType
test
public function validateType($type) { if ($this->_toolbox->isGraph()) { if (!in_array(strtolower($type), array('edge', 'vertex'))) { return false; } } return true; }
php
{ "resource": "" }
q260705
ApiHelper.mapList
test
public static function mapList(callable $callback, array $data): array { if (!isset($data[0])) { $data = [$data]; } return array_map($callback, $data); }
php
{ "resource": "" }
q260706
AbstractCrawler.crawl
test
final protected function crawl(string $url, array $params = []): ?Crawler { if ($content = $this->connection->getPageBody($url, $params)) { return new Crawler($content); } return null; }
php
{ "resource": "" }
q260707
AbstractCrawler.parseUrl
test
final protected function parseUrl(Crawler $node, string $attr = 'href'): ?string { if (0 === $node->count()) { return null; } if ($url = $node->attr($attr)) { return preg_replace('/^\//', static::URL_PREFIX.'/', $url); } return null; }
php
{ "resource": "" }
q260708
AbstractCrawler.parseImage
test
final protected function parseImage(Crawler $node): ?Image { $src = $this->parseUrl($node, 'src'); if (!$src) { return null; } return new Image($src); }
php
{ "resource": "" }
q260709
AbstractCrawler.parseString
test
final protected function parseString(Crawler $node, bool $multiline = false): ?string { if (0 === $node->count()) { return null; } $content = $node->attr('content'); if (null === $content) { if ($multiline) { $content = $node->html(); $content = (string) preg_replace('/<p[^>]*?>/', '', $content); $content = str_replace('</p>', static::NEWLINE, $content); $content = (string) preg_replace('/<br\s?\/?>/i', static::NEWLINE, $content); } else { $content = $node->text(); } } return trim(strip_tags($content)); }
php
{ "resource": "" }
q260710
AbstractCrawler.parseDate
test
final protected function parseDate(Crawler $node): ?DateTime { $content = $this->parseString($node); if (null !== $content) { return new DateTime($content); } return null; }
php
{ "resource": "" }
q260711
Autoloader.load
test
public static function load($className) { $className = str_replace(__NAMESPACE__, '', $className); $className = str_replace("\\", DIRECTORY_SEPARATOR, $className); if (file_exists(self::$dirRoot . $className . self::EXTENSION)) { require_once self::$dirRoot . $className . self::EXTENSION; } }
php
{ "resource": "" }
q260712
CovCatcher._start
test
protected function _start() { if (!$this->_isStart && $this->_coverage) { $this->_isStart = true; $this->_coverage->start($this->_hash, true); } }
php
{ "resource": "" }
q260713
CovCatcher._initConfig
test
protected function _initConfig(array $options) { $options = array_filter($options, function ($option) { return null !== $option; }); $this->_config = new Data(array_merge($this->_default, $options)); }
php
{ "resource": "" }
q260714
Vertex.relateTo
test
public function relateTo(AModel $to, $label = null) { $edge = $this->_toolbox->getPodManager()->dispense("edge", $label); $edge->setTo($to); $edge->setFrom($this->getModel()); return $edge; }
php
{ "resource": "" }
q260715
Vertex.getInboundEdges
test
public function getInboundEdges($label = null, $aql = "", $params = array(), $placeholder = "doc") { return $this->_toolbox->getGraphManager()->getInboundEdges($this->getId(), $label, $aql, $params, $placeholder); }
php
{ "resource": "" }
q260716
Vertex.toDriverDocument
test
public function toDriverDocument() { $vertex = new \triagens\ArangoDb\Vertex; foreach ($this->_data as $key => $value) { $vertex->set($key, $value); } if ($this->_id) { $vertex->setInternalId($this->_id); } if ($this->_key) { $vertex->setInternalKey($this->_key); } if ($this->_rev) { $vertex->setRevision($this->_rev); } return $vertex; }
php
{ "resource": "" }
q260717
ApiClient.encodeUTF8
test
private function encodeUTF8($object) { if (\is_array($object)) { return array_map([$this, 'encodeUTF8'], $object); } return mb_convert_encoding((string) $object, 'UTF-8', 'auto'); }
php
{ "resource": "" }
q260718
CollectionManager.createCollection
test
public function createCollection($name) { try { return $this->_toolbox->getCollectionHandler()->create($name); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260719
CollectionManager.deleteCollection
test
public function deleteCollection($name) { try { return $this->_toolbox->getCollectionHandler()->delete($name); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260720
CollectionManager.renameCollection
test
public function renameCollection($collection, $newName) { try { return $this->_toolbox->getCollectionHandler()->rename($collection, $newName); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260721
CollectionManager.wipe
test
public function wipe($collection) { try { return $this->_toolbox->getCollectionHandler()->truncate($collection); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260722
CollectionManager.getCollectionInfo
test
public function getCollectionInfo($collection) { try { $collection = $this->_toolbox->getCollectionHandler()->getProperties($collection); $result = $collection->getAll(); switch ($result['type']) { case 2: $result['type'] = "documents"; break; case 3: $result['type'] = "edges"; break; } return $result; } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260723
CollectionManager.getCollectionStatistics
test
public function getCollectionStatistics($collection) { try { return $this->_toolbox->getCollectionHandler()->getFigures($collection); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260724
CollectionManager.count
test
public function count($collection) { try { return $this->_toolbox->getCollectionHandler()->count($collection); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260725
CollectionManager.loadCollection
test
public function loadCollection($collection) { try { return $this->_toolbox->getCollectionHandler()->load($collection); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260726
CollectionManager.unloadCollection
test
public function unloadCollection($collection) { try { return $this->_toolbox->getCollectionHandler()->unload($collection); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new CollectionManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260727
CollectionManager.getIndexInfo
test
public function getIndexInfo($collection, $indexId) { $result = $this->listIndices($collection, true); return isset($result[$collection . '/' . $indexId]) ? $result[$collection . '/' . $indexId] : null; }
php
{ "resource": "" }
q260728
CollectionManager.getGeoFieldsForAQL
test
public function getGeoFieldsForAQL($collection) { $indices = $this->_toolbox->getCollectionManager()->listIndices($collection, true); foreach ($indices as $index => $info) { //If this is the first geo index we encounter if ($info['type'] == "geo1" || $info['type'] == "geo2") { return $info['fields']; } } return null; }
php
{ "resource": "" }
q260729
Finder.any
test
public function any($type) { if ($this->_toolbox->getTransactionManager()->hasTransaction()) { $this->_toolbox->getTransactionManager()->addReadCollection($type); $this->_toolbox->getTransactionManager()->addCommand("db.$type.any();" , "Finder:any", null, false, array('type' => $type)); } else { try { $result = $this->_toolbox->getCollectionHandler()->any($type); if (!$result) { return null; } $converted = $this->convertToPods($type, array($result)); return reset($converted); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new FinderException($normalised['message'], $normalised['code']); } } }
php
{ "resource": "" }
q260730
Finder.getCollectionName
test
private function getCollectionName($type) { if ($this->_toolbox->isGraph()) { if (!$this->_toolbox->getPodManager()->validateType($type)) { throw new FinderException("When finding documents in graphs, only the types 'vertex' and 'edge' are allowed."); } //Is a vertex if (strtolower($type) == "vertex") { return $this->_toolbox->getVertexCollectionName(); //Is an edge } else { return $this->_toolbox->getEdgeCollectionName(); } } else { return $type; } }
php
{ "resource": "" }
q260731
Server.deleteUser
test
public function deleteUser($username) { try { $this->_toolbox->getUserHandler()->removeUser($username); return true; } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new ServerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260732
Server.getUserInfo
test
public function getUserInfo($username) { try { $details = $this->_toolbox->getUserHandler()->get($username); $result = array(); $result['username'] = $details->get('user'); $result['active'] = $details->get('active'); $result['data'] = $details->get('extra'); return $result; } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new ServerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260733
Server.deleteAQLFunctionsByNamespace
test
public function deleteAQLFunctionsByNamespace($namespace) { try { $userFunction = new AqlUserFunction($this->_toolbox->getConnection()); $userFunction->unregister($namespace, true); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new ServerException($normalised['message'], $normalised['code']); } return true; }
php
{ "resource": "" }
q260734
Server.listAQLFunctions
test
public function listAQLFunctions($namespace = null) { try { $userFunction = new AqlUserFunction($this->_toolbox->getConnection()); $functions = $userFunction->getRegisteredUserFunctions($namespace); $result = array(); foreach ($functions as $function) { $result[$function['name']] = $function['code']; } return $result; } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new ServerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260735
Server.getVersion
test
public function getVersion() { try { return $this->_toolbox->getAdminHandler()->getServerVersion(); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new ServerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260736
Server.getServerInfo
test
public function getServerInfo() { try { return $this->_toolbox->getAdminHandler()->getServerVersion(true); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new ServerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260737
Server.getTime
test
public function getTime() { try { return $this->_toolbox->getAdminHandler()->getServerTime(); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new ServerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260738
Document.set
test
public function set($key, $value) { if (in_array($key, $this->getReservedFields())) { throw new PodException("You cannot set the property $key. This is reserved for system use."); } $this->_changed = true; $this->_data[$key] = $value; }
php
{ "resource": "" }
q260739
Document.remove
test
public function remove($key) { if (in_array($key, $this->getReservedFields())) { throw new PodException("You cannot set the property $key. This is reserved for system use."); } $this->_changed = true; unset($this->_data[$key]); }
php
{ "resource": "" }
q260740
Document.get
test
public function get($key) { if (in_array($key, $this->getReservedFields())) { throw new PodException("You cannot get the system property '$key'. Use the appropriate getter for it."); } return isset($this->_data[$key]) ? $this->_data[$key] : null; }
php
{ "resource": "" }
q260741
Document.setId
test
public function setId($id) { if ($this->_id !== null && $this->_id != $id) { throw new PodException('Cannot update the id of an existing document'); } if (!preg_match('/^\w+\/\w+$/', $id)) { throw new PodException('Invalid format for document id'); } @list(, $documentId) = explode('/', $id, 2); $this->_key = $documentId; $this->_id = (string) $id; }
php
{ "resource": "" }
q260742
Document.setDistanceInfo
test
public function setDistanceInfo($latitude, $longitude, $podId = null) { if (isset($this->_distance) || isset($this->_referenceCoordinates) || isset($this->_referencePodId)) { throw new PodException("Cannot update the distance info from an existing query."); } $this->_distance = $this->_data['_paradox_distance_parameter']; unset($this->_data['_paradox_distance_parameter']); $this->_referenceCoordinates = array('latitude' => $latitude, 'longitude' => $longitude); $this->_referencePodId = $podId; }
php
{ "resource": "" }
q260743
Document.resetMeta
test
public function resetMeta() { $this->_new = true; $this->_changed = true; $this->_id = null; $this->_key = null; $this->_rev = null; }
php
{ "resource": "" }
q260744
Document.toArray
test
public function toArray() { $result = array('_id' => $this->getId(), '_key' => $this->getKey(), '_rev' => $this->getRevision()); return array_merge($result, $this->_data); }
php
{ "resource": "" }
q260745
Document.toJSON
test
public function toJSON() { $result = array('_id' => $this->getId(), '_key' => $this->getKey(), '_rev' => $this->getRevision()); return json_encode(array_merge($result, $this->_data), JSON_FORCE_OBJECT); }
php
{ "resource": "" }
q260746
Document.toTransactionJSON
test
public function toTransactionJSON() { $result = array('_rev' => $this->getRevision()); return json_encode(array_merge($result, $this->_data), JSON_FORCE_OBJECT); }
php
{ "resource": "" }
q260747
Document.toDriverDocument
test
public function toDriverDocument() { $document = new \triagens\ArangoDb\Document; foreach ($this->_data as $key => $value) { $document->set($key, $value); } if ($this->_id) { $document->setInternalId($this->_id); } if ($this->_key) { $document->setInternalKey($this->_key); } if ($this->_rev) { $document->setRevision($this->_rev); } return $document; }
php
{ "resource": "" }
q260748
Document.loadFromDriver
test
public function loadFromDriver(\triagens\ArangoDb\Document $driverDocument) { $values = $driverDocument->getAll(array('_includeInternals' => true)); foreach ($values as $key => $value) { if (!in_array($key, array('_id', '_key', '_rev'))) { $this->_data[$key] = $value; } } $this->setId($driverDocument->getInternalId()); $this->setRevision($driverDocument->getRevision()); $this->setSaved(); }
php
{ "resource": "" }
q260749
Document.loadFromArray
test
public function loadFromArray($data) { foreach ($data as $property => $value) { switch ($property) { case "_id": $this->setId($value); break; case "_key": break; case "_rev": $this->setRevision($value); break; default: $this->_data[$property] = $value; break; } } }
php
{ "resource": "" }
q260750
Document.onEvent
test
public function onEvent(Event $eventObject) { if ($eventObject->getObject() === $this) { switch ($eventObject->getEvent()) { case 'after_dispense': $this->getModel()->afterDispense(); break; case 'after_open': $this->getModel()->afterOpen(); break; case 'before_store': $this->getModel()->beforeStore(); break; case 'after_store': $this->getModel()->afterStore(); break; case 'before_delete': $this->getModel()->beforeDelete(); break; case 'after_delete': $this->getModel()->afterDelete(); break; } } }
php
{ "resource": "" }
q260751
Edge.setTo
test
public function setTo(AModel $to) { $this->_to = $to; $this->setInternalTo($to->getPod()->getId()); }
php
{ "resource": "" }
q260752
Edge.getToId
test
public function getToId() { if (isset($this->_to)) { return $this->_to->getPod()->getId(); } elseif (isset($this->_data['_to'])) { return $this->_data['_to']; } else { return null; } }
php
{ "resource": "" }
q260753
Edge.setFrom
test
public function setFrom(AModel $from) { $this->_from = $from; $this->setInternalFrom($from->getPod()->getId()); }
php
{ "resource": "" }
q260754
Edge.getFromId
test
public function getFromId() { if (isset($this->_from)) { return $this->_from->getPod()->getId(); } elseif (isset($this->_data['_from'])) { return $this->_data['_from']; } else { return null; } }
php
{ "resource": "" }
q260755
Edge.toDriverDocument
test
public function toDriverDocument() { $edge = new \triagens\ArangoDb\Edge; foreach ($this->_data as $key => $value) { $edge->set($key, $value); } if ($this->_id) { $edge->setInternalId($this->_id); } if ($this->_key) { $edge->setInternalKey($this->_key); } if ($this->_rev) { $edge->setRevision($this->_rev); } return $edge; }
php
{ "resource": "" }
q260756
TransactionManager.begin
test
public function begin() { if ($this->_activeTransaction) { throw new TransactionManagerException("An active transaction already exists."); } $this->_activeTransaction = true; $this->_transactionPaused = false; return true; }
php
{ "resource": "" }
q260757
TransactionManager.commit
test
public function commit() { if (!$this->_activeTransaction) { throw new TransactionManagerException("There is no active transaction to commit."); } if (empty($this->_commands)) { throw new TransactionManagerException("There is no transaction operations to commit."); } $commandText = 'function () { var db = require("internal").db; '; //Check if there are graph operations foreach ($this->_commands as $command) { if ($command['isGraph']) { $commandText .= "var g = require('org/arangodb/graph').Graph; var graph = new g('{$this->_toolbox->getGraph()}'); "; break; } } $commandText .= 'var result = {}; '; //Now, add the commands foreach ($this->_commands as $id => $command) { $commandText .= "result.$id = {$command['command']} "; } $commandText .= "return result; }"; //Send the transaction $result = $this->executeTransaction($commandText, $this->_collections['read'], $this->_collections['write']); //Process the result $processed = $this->processResult($result); $this->clearTransactionInfo(); return $processed; }
php
{ "resource": "" }
q260758
TransactionManager.clearTransactionInfo
test
private function clearTransactionInfo() { $this->_activeTransaction = false; $this->_transactionPaused = true; $this->_collections = array('write' => array(), 'read' => array()); $this->_commands = array(); $this->_registeredResults = array(); }
php
{ "resource": "" }
q260759
TransactionManager.addReadCollection
test
public function addReadCollection($collection) { if (!$this->_activeTransaction) { throw new TransactionManagerException("There is no active transaction."); } if (!in_array($collection, $this->_collections['read'])) { $this->_collections['read'][] = $collection; } }
php
{ "resource": "" }
q260760
TransactionManager.addWriteCollection
test
public function addWriteCollection($collection) { if (!$this->_activeTransaction) { throw new TransactionManagerException("There is no active transaction."); } if (!in_array($collection, $this->_collections['write'])) { $this->_collections['write'][] = $collection; } }
php
{ "resource": "" }
q260761
TransactionManager.pause
test
public function pause() { if (!$this->_activeTransaction) { throw new TransactionManagerException("There is no active transaction."); } if ($this->_transactionPaused) { throw new TransactionManagerException("The transaction is already paused."); } $this->_transactionPaused = true; }
php
{ "resource": "" }
q260762
TransactionManager.resume
test
public function resume() { if (!$this->_activeTransaction) { throw new TransactionManagerException("There is no active transaction."); } if (!$this->_transactionPaused) { throw new TransactionManagerException("The transaction is not paused."); } $this->_transactionPaused = false; }
php
{ "resource": "" }
q260763
TransactionManager.addCommand
test
public function addCommand($command, $action, $object = null, $isGraph = false, $data = array()) { if (!$this->_activeTransaction) { throw new TransactionManagerException("There is no active transaction."); } $id = $this->random(); $this->_commands[$id] = array('command' => $command, 'action' => $action, 'object' => $object, 'isGraph' => $isGraph, 'data' => $data); return $id; }
php
{ "resource": "" }
q260764
TransactionManager.searchCommandsByActionAndObject
test
public function searchCommandsByActionAndObject($action, $object) { $position = 0; $length = count($this->_commands); foreach (array_reverse($this->_commands) as $id => $command) { if ($command['action'] == $action && $command['object'] === $object) { return array('position' => $length - 1 - $position, 'id' => $id); } $position++; } return null; }
php
{ "resource": "" }
q260765
TransactionManager.random
test
private function random() { $characters = 'abcdefghijklmnopqrstuvwxyz'; $id = ''; while (strlen($id) < 7 || in_array($id, array_keys($this->_commands))) { $id .= $characters[rand(0, strlen($characters) - 1)]; } return $id; }
php
{ "resource": "" }
q260766
GraphManager.createGraph
test
public function createGraph($name) { try { $graph = new \triagens\ArangoDb\Graph($name); $graph->setVerticesCollection($name . 'VertexCollection'); $graph->setEdgesCollection($name . 'EdgeCollection'); return $this->_toolbox->getGraphHandler()->createGraph($graph); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new GraphManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260767
GraphManager.deleteGraph
test
public function deleteGraph($name) { try { $graphHandler = $this->_toolbox->getGraphHandler(); return $graphHandler->dropGraph($name); } catch (\Exception $e) { $normalised = $this->_toolbox->normaliseDriverExceptions($e); throw new GraphManagerException($normalised['message'], $normalised['code']); } }
php
{ "resource": "" }
q260768
GraphManager.getGraphInfo
test
public function getGraphInfo($name) { $graphHandler = $this->_toolbox->getGraphHandler(); $graph = $graphHandler->getGraph($name); if(!$graph){ throw new GraphManagerException("Graph does not exist"); } $result = array(); $result['id'] = $graph->getKey(); $result['name'] = $graph->getKey(); $result['revision'] = $graph->getRevision(); $result['verticesCollection'] = $graph->getVerticesCollection(); $result['edgesCollection'] = $graph->getEdgesCollection(); return $result; }
php
{ "resource": "" }
q260769
GraphManager.getOutboundEdges
test
public function getOutboundEdges($model, $label = null, $aql = "", $params = array(), $placeholder = "doc") { $id = $this->getVertexId($model); if (!$id) { return array(); } $collectionParameter = $this->_toolbox->generateBindingParameter('@collection', $params); $vertexParameter = $this->_toolbox->generateBindingParameter('vertexid', $params); $directionParameter = $this->_toolbox->generateBindingParameter('direction', $params); if (!$label) { $query = "FOR $placeholder in EDGES(@$collectionParameter, @$vertexParameter, @$directionParameter) " . $aql . " return $placeholder"; } else { $labelParameter = $this->_toolbox->generateBindingParameter('label', $params); $params[$labelParameter] = $label; $query = "FOR $placeholder in EDGES(@$collectionParameter, @$vertexParameter, @$directionParameter, [{'\$label': @$labelParameter}]) " . $aql . " return $placeholder"; } $params[$collectionParameter] = $this->_toolbox->getEdgeCollectionName(); $params[$vertexParameter] = $id; $params[$directionParameter] = "outbound"; if ($this->_toolbox->getTransactionManager()->hasTransaction()) { $this->_toolbox->getTransactionManager()->addReadCollection($this->_toolbox->getEdgeCollectionName()); $statement = json_encode(array('query' => $query, 'bindVars' => $params), JSON_FORCE_OBJECT); $this->_toolbox->getTransactionManager()->addCommand("db._createStatement($statement).execute().elements();", "GraphManager:getOutboundEdges", null, true); } else { try { $result = $this->_toolbox->getQuery()->getAll($query, $params); } catch (\Exception $e) { throw new GraphManagerException($e->getMessage(), $e->getCode()); } if (empty($result)) { return array(); } return $this->convertToPods("edge", $result); } }
php
{ "resource": "" }
q260770
ListFilterHelper.getFilters
test
public function getFilters() { if ($this->_filters) { return $this->_filters; } elseif (isset($this->_View->viewVars['filters'])) { return $this->_View->viewVars['filters']; } return []; }
php
{ "resource": "" }
q260771
ListFilterHelper.renderFilterbox
test
public function renderFilterbox($filters = null) { if ($filters) { $this->_filters = $filters; } $filterBox = $this->openContainer(); $filterBox .= $this->openForm(); $filterBox .= $this->renderAll(); $filterBox .= $this->closeForm(); $filterBox .= $this->closeContainer(); $ret = $this->_View->element('ListFilter.wrapper', [ 'filterBox' => $filterBox, 'options' => $this->config() ]); return $ret; }
php
{ "resource": "" }
q260772
ListFilterHelper.renderAll
test
public function renderAll() { $widgets = []; foreach ($this->getFilters() as $field => $options) { $w = $this->filterWidget($field, $options, false); if ($w) { $widgets = array_merge($widgets, $w); } } // FIXME allow column-layout to be configured with templates. $ret = '<div class="row">'; foreach ($widgets as $i => $widget) { $ret .= '<div class="col-md-6">'; $ret .= $widget; $ret .= '</div>'; if (($i + 1) % 2 === 0) { $ret .= '</div><div class="row">'; } } $ret .= '</div>'; return $ret; }
php
{ "resource": "" }
q260773
ListFilterHelper.openContainer
test
public function openContainer() { $classes = $this->config('containerClasses'); $title = __d('list_filter', 'list_filter.filter_fieldset_title'); if ($this->filterActive()) { $classes .= ' opened'; } else { $classes .= ' closed'; } $ret = $this->templater()->format('containerStart', [ 'attrs' => $this->templater()->formatAttributes([ 'class' => $classes ]) ]); $ret .= $this->header(); $ret .= $this->templater()->format('contentStart', [ 'attrs' => $this->templater()->formatAttributes([ 'class' => $this->config('contentClasses') ]) ]); return $ret; }
php
{ "resource": "" }
q260774
ListFilterHelper.closeContainer
test
public function closeContainer() { $ret = $this->templater()->format('contentEnd', []); $ret .= $this->templater()->format('containerEnd', []); return $ret; }
php
{ "resource": "" }
q260775
ListFilterHelper.openForm
test
public function openForm() { $options = Hash::merge(['url' => $this->here], $this->config('formOptions')); $ret = $this->Form->create('Filter', $options); return $ret; }
php
{ "resource": "" }
q260776
ListFilterHelper.closeForm
test
public function closeForm($includeFilterButton = true, $includeResetButton = true) { $buttons = ''; if ($includeFilterButton) { $buttons .= $this->filterButton(); } if ($includeResetButton) { $buttons .= ' ' . $this->resetButton(); } $ret = $this->templater()->format('buttons', [ 'buttons' => $buttons ]); $ret .= $this->Form->end(); return $ret; }
php
{ "resource": "" }
q260777
ListFilterHelper.filterActive
test
public function filterActive() { $filterActive = (isset($this->_View->viewVars['filterActive']) && $this->_View->viewVars['filterActive'] === true); return $filterActive; }
php
{ "resource": "" }
q260778
ListFilterHelper.filterButton
test
public function filterButton($title = null, array $options = []) { if (!$title) { $title = __d('list_filter', 'list_filter.search'); } $options = Hash::merge($this->config('filterButtonOptions'), $options); return $this->Form->button($title, $options); }
php
{ "resource": "" }
q260779
ListFilterHelper.resetButton
test
public function resetButton($title = null, array $options = []) { if (!$title) { $title = __d('list_filter', 'list_filter.reset'); } $params = $this->_View->request->query; if (!empty($params)) { foreach ($params as $field => $value) { if (substr($field, 0, 7) == 'Filter-') { unset($params[$field]); } } } $options = Hash::merge($this->config('resetButtonOptions'), $options); $url = Hash::merge($this->request->params, [ 'resetFilter' => true ]); return $this->Html->link($title, Router::reverse($url), $options); }
php
{ "resource": "" }
q260780
ListFilterHelper.backToListButton
test
public function backToListButton($title = null, array $url = null, array $options = []) { if (empty($url)) { $url = [ 'action' => 'index' ]; } $options = Hash::merge([ 'class' => 'btn btn-default btn-xs', 'escape' => false, 'additionalClasses' => null, 'useReferer' => false ], $options); if (!empty($options['useReferer']) && $this->request->referer(true) != '/' && $this->request->referer(true) != $this->request->here) { $url = $this->request->referer(true); } if (!$title) { $title = '<span class="button-text">' . __d('list_filter', 'forms.back_to_list') . '</span>'; } if ($options['additionalClasses']) { $options['class'] .= ' ' . $options['additionalClasses']; } if (empty($options['useReferer'])) { $url = $this->addListFilterParams($url); } $button = $this->Html->link('<i class="fa fa-arrow-left"></i> ' . $title, $url, $options); return $button; }
php
{ "resource": "" }
q260781
ListFilterComponent._getPersistendStorageKey
test
protected function _getPersistendStorageKey($key) { if (!isset($this->config[$key]['namespace'])) { $namespace = 'ListFilter'; } else { $namespace = $this->config[$key]['namespace']; } $sessionKey = [ 'namespace' => $namespace, 'plugin' => 'App', 'controller' => $this->_controller->request->controller, 'action' => $this->_controller->request->action ]; if (!empty($this->_controller->request->plugin)) { $sessionKey['plugin'] = $this->_controller->request->plugin; } $sessionKey = implode('.', $sessionKey); return $sessionKey; }
php
{ "resource": "" }
q260782
ListFilterComponent.filterUrlParameterStatus
test
public function filterUrlParameterStatus() { foreach ($this->_controller->request->query as $arg => $value) { if (substr($arg, 0, 7) == 'Filter-') { return true; } } return false; }
php
{ "resource": "" }
q260783
ListFilterComponent._getFulltextSearchConditions
test
protected function _getFulltextSearchConditions($conditionField, $value, array $options) { $searchTerms = explode(' ', $value); $searchTerms = array_map('trim', $searchTerms); $searchTerms = array_map('mb_strtolower', $searchTerms); if (isset($options['termsCallback']) && is_callable($options['termsCallback'])) { $searchTerms = $options['termsCallback']($searchTerms); } $searchFields = [$conditionField]; if (!empty($options['searchFields'])) { $searchFields = $options['searchFields']; } $conditions = []; $conjunction = $this->config['searchTermsConjunction']; foreach ($searchTerms as $key => $term) { $searchFieldConditions = []; if (is_array($term)) { foreach ($term as $item) { foreach ($searchFields as $searchField) { $searchFieldConditions["{$searchField} LIKE"] = "%{$item}%"; } $conditions[$conjunction][$key]['OR'][] = [ 'OR' => $searchFieldConditions ]; } } else { foreach ($searchFields as $searchField) { $searchFieldConditions["{$searchField} LIKE"] = "%{$term}%"; } $conditions[$conjunction][$key] = [ 'OR' => $searchFieldConditions ]; } } return $conditions; }
php
{ "resource": "" }
q260784
ListFilterComponent._flattenValueOptions
test
protected function _flattenValueOptions(array $options) { $flatOptions = $options; if (is_array(current($options))) { $flatOptions = []; foreach ($options as $group => $valueGroup) { $flatOptions = $flatOptions + $valueGroup; } } return $flatOptions; }
php
{ "resource": "" }
q260785
ListFilterComponent.getFilters
test
public function getFilters() { $filters = []; if (method_exists($this->_controller, 'getListFilters')) { $filters = $this->_controller->getListFilters($this->_controller->request->action); } elseif (isset($this->_controller->listFilters) && !empty($this->_controller->listFilters[$this->_controller->request->action])) { $filters = $this->_controller->listFilters[$this->_controller->request->action]; } if (empty($filters)) { return []; } foreach ($filters['fields'] as $field => &$fieldConfig) { if (isset($fieldConfig['type']) && $fieldConfig['type'] == 'select' && !isset($fieldConfig['searchType']) ) { $fieldConfig['searchType'] = 'select'; $fieldConfig['inputOptions']['type'] = 'select'; unset($fieldConfig['type']); } // backwards compatibility if (isset($fieldConfig['type'])) { $fieldConfig['inputOptions']['type'] = $fieldConfig['type']; unset($fieldConfig['type']); } if (isset($fieldConfig['label'])) { $fieldConfig['inputOptions']['label'] = $fieldConfig['label']; unset($fieldConfig['label']); } if (isset($fieldConfig['searchType']) && in_array($fieldConfig['searchType'], ['select', 'multipleselect']) ) { if (!isset($fieldConfig['inputOptions']['type'])) { $fieldConfig['inputOptions']['type'] = 'select'; } if (!isset($fieldConfig['inputOptions']['empty'])) { $fieldConfig['inputOptions']['empty'] = true; } } $fieldConfig = Hash::merge($this->defaultListFilter, $fieldConfig); } return $filters; }
php
{ "resource": "" }
q260786
ListFilterComponent.getRedirectUrlFromPostData
test
public function getRedirectUrlFromPostData(array $postData) { $urlParams = []; foreach ($postData['Filter'] as $model => $fields) { foreach ($fields as $field => $value) { if (is_array($value) && isset($value['year'])) { $value = "{$value['year']}-{$value['month']}-{$value['day']}"; if ($value == '--') { continue; } } if ($value !== 0 && $value !== '0' && empty($value)) { continue; } $urlParams["Filter-{$model}-{$field}"] = $value; } } $passedArgs = $this->_controller->passedArgs; if (!empty($passedArgs)) { $urlParams = Hash::merge($passedArgs, $urlParams); } $params = $this->_controller->request->query; if (!empty($params)) { $cleanParams = []; foreach ($params as $key => $value) { if (substr($key, 0, 7) != 'Filter-') { $cleanParams[$key] = $value; } } $urlParams = Hash::merge($cleanParams, $urlParams); } return $urlParams; }
php
{ "resource": "" }
q260787
ListFilterComponent.addListFilterParams
test
public function addListFilterParams(array $url) { foreach ($this->request->query as $key => $value) { if (substr($key, 0, 7) == 'Filter-' || in_array($key, ['page', 'sort', 'direction'])) { $url[$key] = $value; } } return $url; }
php
{ "resource": "" }
q260788
ListFilterComponent.defaultFilters
test
public function defaultFilters($filters = []) { if (empty($filters)) { return false; } foreach ($filters as $key => $value) { $filterName = 'Filter-' . str_replace('.', '-', $key); $explodedFilterName = explode('-', $filterName); if (count($explodedFilterName) !== 3) { return false; } if (empty($this->_controller->request->query[$filterName])) { // set request POST data so the inputs will be filled $this->_controller->request->data[$explodedFilterName[0]][$explodedFilterName[1]][$explodedFilterName[2]] = $value; $this->_controller->paginate['conditions'][$key] = $value; } elseif ($this->_controller->request->query[$filterName] == 'all') { unset($this->_controller->request->data[$explodedFilterName[0]][$explodedFilterName[1]][$explodedFilterName[2]]); unset($this->_controller->paginate['conditions'][$key]); } } return true; }
php
{ "resource": "" }
q260789
Query.build
test
public static function build($pdo, $sql, array $params) { $bind_values = []; $sql = strtr($sql, "\n", ' '); $sql = preg_replace_callback( '/'.Query::RE_HOLDER.'/', function ($m) use ($pdo, $params, &$bind_values) { $key = $m['key']; $type = $m['type']; if (!isset($params[$key])) { throw new \OutOfRangeException(sprintf('param "%s" expected but not assigned', $key)); } return self::replaceHolder($pdo, $key, $type, $params[$key], $bind_values); }, $sql ); $stmt = $pdo->prepare($sql); foreach ($bind_values as $key => list($type, $value)) { $stmt->bindParam($key, $value, $type); } return $stmt; }
php
{ "resource": "" }
q260790
AggregationTrait.reduce
test
public function reduce(callable $callback, $initial = null) { return i\iterable_reduce($this->iterable, $callback, $initial); }
php
{ "resource": "" }
q260791
TypeHandlingTrait.typeCheck
test
public function typeCheck($type, ?\Throwable $throwable = null) { return $this->then(i\iterable_type_check, $type, $throwable); }
php
{ "resource": "" }
q260792
TypeHandlingTrait.typeCast
test
public function typeCast(string $type, ?\Throwable $throwable = null) { return $this->then(i\iterable_type_cast, $type, $throwable); }
php
{ "resource": "" }
q260793
Silex2ServiceProvider.register
test
public function register(Container $app) { $app['bugsnag.resolver'] = function () { return new SilexResolver(); }; $app['bugsnag'] = function () use ($app) { return $this->makeClient($app); }; $app['bugsnag.notifier'] = function() use ($app) { return function($error) use ($app) { $this->autoNotify($app['bugsnag'], $error); }; }; $app->before(function (Request $request) use ($app) { $app['bugsnag']->setFallbackType('HTTP'); $app['bugsnag.resolver']->set($request); }, Application::EARLY_EVENT); }
php
{ "resource": "" }
q260794
AbstractServiceProvider.makeClient
test
protected function makeClient(Application $app) { try { $config = $app['bugsnag.options']; } catch (InvalidArgumentException $e) { $config = []; } $key = isset($config['api_key']) ? $config['api_key'] : getenv('BUGSNAG_API_KEY'); $guzzle = Client::makeGuzzle(isset($config['endpoint']) ? $config['endpoint'] : null); $client = new Client(new Configuration($key), $app['bugsnag.resolver'], $guzzle); if (!isset($config['callbacks']) || $config['callbacks']) { $client->registerDefaultCallbacks(); } if (!isset($config['user']) || $config['user']) { $this->setupUserDetection($client, $app); } $this->setupPaths($client, isset($config['strip_path']) ? $config['strip_path'] : null, isset($config['project_root']) ? $config['project_root'] : null); $env = getenv('SYMFONY_ENV') ?: null; $stage = isset($config['release_stage']) ? $config['release_stage'] : null; $client->setReleaseStage($stage ?: ($env === 'prod' ? 'production' : $env)); $client->setHostname(isset($config['hostname']) ? $config['hostname'] : null); $client->setFallbackType('Console'); $client->setAppType(isset($config['app_type']) ? $config['app_type'] : null); $client->setAppVersion(isset($config['app_version']) ? $config['app_version'] : null); $client->setBatchSending(isset($config['batch_sending']) ? $config['batch_sending'] : true); $client->setSendCode(isset($config['send_code']) ? $config['send_code'] : true); $client->setNotifier([ 'name' => 'Bugsnag Silex', 'version' => static::VERSION, 'url' => 'https://github.com/bugsnag/bugsnag-silex', ]); if (isset($config['notify_release_stages']) && is_array($config['notify_release_stages'])) { $client->setNotifyReleaseStages($config['notify_release_stages']); } if (isset($config['filters']) && is_array($config['filters'])) { $client->setFilters($config['filters']); } return $client; }
php
{ "resource": "" }
q260795
AbstractServiceProvider.setupUserDetection
test
protected function setupUserDetection(Client $client, Application $app) { try { $tokens = $app['security.token_storage']; $checker = $app['security.authorization_checker']; } catch (InvalidArgumentException $e) { return; } $client->registerCallback(new CustomUser(function () use ($tokens, $checker) { $token = $tokens->getToken(); if (!$token || !$checker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { return; } $user = $token->getUser(); if ($user instanceof UserInterface) { return ['id' => $user->getUsername()]; } return ['id' => (string) $user]; })); }
php
{ "resource": "" }
q260796
AbstractServiceProvider.setupPaths
test
protected function setupPaths(Client $client, $strip, $project) { if ($strip) { $client->setStripPath($strip); if (!$project) { $client->setProjectRoot("{$strip}/src"); } return; } $base = realpath(__DIR__.'/../../../../'); if ($project) { if ($base && substr($project, 0, strlen($base)) === $base) { $client->setStripPath($base); } $client->setProjectRoot($project); return; } if ($base) { $client->setStripPath($base); if ($root = realpath("{$base}/src")) { $client->setProjectRoot($root); } } }
php
{ "resource": "" }
q260797
PipelineBuilder.stub
test
public function stub(string $name): self { $hasStub = i\iterable_has_any($this->steps, function ($step) use ($name) { return $step[0] instanceof Stub && $step[0]->getName() === $name; }); if ($hasStub) { throw new \BadMethodCallException("Pipeline builder already has '$name' stub"); } return $this->then(new Stub($name)); }
php
{ "resource": "" }
q260798
PipelineBuilder.unstub
test
public function unstub(string $name, callable $callable, ...$args): self { $index = i\iterable_find_key($this->steps, function ($step) use ($name) { return $step[0] instanceof Stub && $step[0]->getName() === $name; }); if ($index === null) { throw new \BadMethodCallException("Pipeline builder doesn't have '$name' stub"); } $clone = clone $this; $clone->steps[$index] = [$callable, $args]; return $clone; }
php
{ "resource": "" }
q260799
PipelineBuilder.with
test
public function with(iterable $iterable): Pipeline { $pipeline = new Pipeline($iterable); foreach ($this->steps as [$callback, $args]) { $pipeline = $pipeline->then($callback, ...$args); } return $pipeline; }
php
{ "resource": "" }