_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q261700 | Map.setStreetViewControl | test | public function setStreetViewControl()
{
$args = func_get_args();
if (isset($args[0]) && ($args[0] instanceof StreetViewControl)) {
$this->streetViewControl = $args[0];
$this->mapOptions['streetViewControl'] = true;
} elseif (isset($args[0]) && is_string($args[0])) {
if ($this->streetViewControl === null) {
$this->streetViewControl = new StreetViewControl();
}
$this->streetViewControl->setControlPosition($args[0]);
$this->mapOptions['streetViewControl'] = true;
} elseif (!isset($args[0])) {
$this->streetViewControl = null;
if (isset($this->mapOptions['streetViewControl'])) {
unset($this->mapOptions['streetViewControl']);
}
} else {
throw MapException::invalidStreetViewControl();
}
} | php | {
"resource": ""
} |
q261701 | Map.setZoomControl | test | public function setZoomControl()
{
$args = func_get_args();
if (isset($args[0]) && ($args[0] instanceof ZoomControl)) {
$this->zoomControl = $args[0];
$this->mapOptions['zoomControl'] = true;
} elseif ((isset($args[0]) && is_string($args[0])) && (isset($args[1]) && is_string($args[1]))) {
if ($this->zoomControl === null) {
$this->zoomControl = new ZoomControl();
}
$this->zoomControl->setControlPosition($args[0]);
$this->zoomControl->setZoomControlStyle($args[1]);
$this->mapOptions['zoomControl'] = true;
} elseif (!isset($args[0])) {
$this->zoomControl = null;
if (isset($this->mapOptions['zoomControl'])) {
unset($this->mapOptions['zoomControl']);
}
} else {
throw MapException::invalidZoomControl();
}
} | php | {
"resource": ""
} |
q261702 | Map.addMarker | test | public function addMarker(Marker $marker)
{
$this->markerCluster->addMarker($marker);
if ($this->autoZoom) {
$this->bound->extend($marker);
}
} | php | {
"resource": ""
} |
q261703 | Map.addInfoWindow | test | public function addInfoWindow(InfoWindow $infoWindow)
{
$this->infoWindows[] = $infoWindow;
if ($this->autoZoom) {
$this->bound->extend($infoWindow);
}
} | php | {
"resource": ""
} |
q261704 | Map.addPolyline | test | public function addPolyline(Polyline $polyline)
{
$this->polylines[] = $polyline;
if ($this->autoZoom) {
$this->bound->extend($polyline);
}
} | php | {
"resource": ""
} |
q261705 | Map.addEncodedPolyline | test | public function addEncodedPolyline(EncodedPolyline $encodedPolyline)
{
$this->encodedPolylines[] = $encodedPolyline;
if ($this->autoZoom) {
$this->bound->extend($encodedPolyline);
}
} | php | {
"resource": ""
} |
q261706 | Map.addPolygon | test | public function addPolygon(Polygon $polygon)
{
$this->polygons[] = $polygon;
if ($this->autoZoom) {
$this->bound->extend($polygon);
}
} | php | {
"resource": ""
} |
q261707 | Map.addRectangle | test | public function addRectangle(Rectangle $rectangle)
{
$this->rectangles[] = $rectangle;
if ($this->autoZoom) {
$this->bound->extend($rectangle);
}
} | php | {
"resource": ""
} |
q261708 | Map.addCircle | test | public function addCircle(Circle $circle)
{
$this->circles[] = $circle;
if ($this->autoZoom) {
$this->bound->extend($circle);
}
} | php | {
"resource": ""
} |
q261709 | Map.addGroundOverlay | test | public function addGroundOverlay(GroundOverlay $groundOverlay)
{
$this->groundOverlays[] = $groundOverlay;
if ($this->autoZoom) {
$this->bound->extend($groundOverlay);
}
} | php | {
"resource": ""
} |
q261710 | FileItem.set | test | public function set($value = null, $ttl = null)
{
$now = new DateTime();
// whoever came up with the idea of allowing int AND datetime...
// so lets convert this to an int (its a time to live, not a date to delete ffs)
if ($ttl instanceof DateTime) {
$ttl = $ttl->getTimestamp() - $now->getTimestamp();
}
$data = [
"updated" => $now,
"value" => $value,
"key" => $this->key,
"ttl" => $ttl
];
return false !== file_put_contents($this->filename, serialize($data));
} | php | {
"resource": ""
} |
q261711 | FileItem.delete | test | public function delete()
{
if (file_exists($this->filename)) {
unlink($this->filename);
}
$this->hit = false;
$this->value = null;
return $this;
} | php | {
"resource": ""
} |
q261712 | DirectionsRequest.setAvoidHighways | test | public function setAvoidHighways($avoidHighways = null)
{
if (!is_bool($avoidHighways) && ($avoidHighways !== null)) {
throw DirectionsException::invalidDirectionsRequestAvoidHighways();
}
$this->avoidHighways = $avoidHighways;
} | php | {
"resource": ""
} |
q261713 | DirectionsRequest.setAvoidTolls | test | public function setAvoidTolls($avoidTolls = null)
{
if (!is_bool($avoidTolls) && ($avoidTolls !== null)) {
throw DirectionsException::invalidDirectionsRequestAvoidTolls();
}
$this->avoidTolls = $avoidTolls;
} | php | {
"resource": ""
} |
q261714 | DirectionsRequest.setDestination | test | public function setDestination()
{
$args = func_get_args();
if (isset($args[0]) && is_string($args[0])) {
$this->destination = $args[0];
} elseif (isset($args[0]) && ($args[0] instanceof Coordinate)) {
$this->destination = $args[0];
} elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
if ($this->destination === null) {
$this->destination = new Coordinate();
}
$this->destination->setLatitude($args[0]);
$this->destination->setLongitude($args[1]);
if (isset($args[2]) && is_bool($args[2])) {
$this->destination->setNoWrap($args[2]);
}
} else {
throw DirectionsException::invalidDirectionsRequestDestination();
}
} | php | {
"resource": ""
} |
q261715 | DirectionsRequest.setOptimizeWaypoints | test | public function setOptimizeWaypoints($optimizeWaypoints = null)
{
if (!is_bool($optimizeWaypoints) && ($optimizeWaypoints !== null)) {
throw DirectionsException::invalidDirectionsRequestOptimizeWaypoints();
}
$this->optimizeWaypoints = $optimizeWaypoints;
} | php | {
"resource": ""
} |
q261716 | DirectionsRequest.setOrigin | test | public function setOrigin()
{
$args = func_get_args();
if (isset($args[0]) && is_string($args[0])) {
$this->origin = $args[0];
} elseif (isset($args[0]) && ($args[0] instanceof Coordinate)) {
$this->origin = $args[0];
} elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
if ($this->origin === null) {
$this->origin = new Coordinate();
}
$this->origin->setLatitude($args[0]);
$this->origin->setLongitude($args[1]);
if (isset($args[2]) && is_bool($args[2])) {
$this->origin->setNoWrap($args[2]);
}
} else {
throw DirectionsException::invalidDirectionsRequestOrigin();
}
} | php | {
"resource": ""
} |
q261717 | DirectionsRequest.setProvideRouteAlternatives | test | public function setProvideRouteAlternatives($provideRouteAlternatives = null)
{
if (!is_bool($provideRouteAlternatives) && ($provideRouteAlternatives !== null)) {
throw DirectionsException::invalidDirectionsRequestProvideRouteAlternatives();
}
$this->provideRouteAlternatives = $provideRouteAlternatives;
} | php | {
"resource": ""
} |
q261718 | DirectionsRequest.setRegion | test | public function setRegion($region = null)
{
if ((!is_string($region) || (strlen($region) !== 2)) && ($region !== null)) {
throw DirectionsException::invalidDirectionsRequestRegion();
}
$this->region = $region;
} | php | {
"resource": ""
} |
q261719 | DirectionsRequest.setLanguage | test | public function setLanguage($language = null)
{
if ((!is_string($language) || ((strlen($language) !== 2) && (strlen($language) !== 5))) && ($language !== null)) {
throw DirectionsException::invalidDirectionsRequestLanguage();
}
$this->language = $language;
} | php | {
"resource": ""
} |
q261720 | DirectionsRequest.setTravelMode | test | public function setTravelMode($travelMode = null)
{
if (!in_array($travelMode, TravelMode::getTravelModes()) && ($travelMode !== null)) {
throw DirectionsException::invalidDirectionsRequestTravelMode();
}
$this->travelMode = $travelMode;
} | php | {
"resource": ""
} |
q261721 | DirectionsRequest.setUnitSystem | test | public function setUnitSystem($unitSystem = null)
{
if (!in_array($unitSystem, UnitSystem::getUnitSystems()) && ($unitSystem !== null)) {
throw DirectionsException::invalidDirectionsRequestUnitSystem();
}
$this->unitSystem = $unitSystem;
} | php | {
"resource": ""
} |
q261722 | DirectionsRequest.setWaypoints | test | public function setWaypoints(array $waypoints = array())
{
$this->waypoints = array();
foreach ($waypoints as $waypoint) {
$this->addWaypoint($waypoint);
}
} | php | {
"resource": ""
} |
q261723 | DirectionsRequest.addWaypoint | test | public function addWaypoint()
{
$args = func_get_args();
if (isset($args[0]) && ($args[0] instanceof DirectionsWaypoint)) {
$this->waypoints[] = $args[0];
} elseif ((isset($args[0]) && is_numeric($args[0])) && (isset($args[1]) && is_numeric($args[1]))) {
$waypoint = new DirectionsWaypoint();
$waypoint->setLocation($args[0], $args[1]);
if (isset($args[2]) && is_bool($args[2])) {
$waypoint->getLocation()->setNoWrap($args[2]);
}
$this->waypoints[] = $waypoint;
} elseif (isset($args[0]) && (is_string($args[0]) || ($args[0] instanceof Coordinate))) {
$waypoint = new DirectionsWaypoint();
$waypoint->setLocation($args[0]);
$this->waypoints[] = $waypoint;
} else {
throw DirectionsException::invalidDirectionsRequestWaypoint();
}
} | php | {
"resource": ""
} |
q261724 | DirectionsRequest.isValid | test | public function isValid()
{
$isValid = $this->hasDestination() && $this->hasOrigin();
for ($i = 0; $isValid && ($i < count($this->waypoints)); $i++) {
$isValid = $this->waypoints[$i]->isValid();
}
if ($this->getTravelMode() === TravelMode::TRANSIT) {
$isValid = $this->hasArrivalTime() || $this->hasDepartureTime();
}
return $isValid;
} | php | {
"resource": ""
} |
q261725 | GitHub.postJson | test | public function postJson(string $url, $data, array $args = []): \StdClass
{
return $this->submitJson($url, $data, array_merge($args, ['method' => 'POST']));
} | php | {
"resource": ""
} |
q261726 | Debugging.logIssue | test | public function logIssue($data = [], string $note = '', string $event = ''): Exception
{
if (func_num_args() === 1 && is_string($data)) {
$note = $data; // Use data as note.
$data = []; // Data empty in this case.
}
$event = $event ?: $this->traceLogEventTrigger();
if (mb_strpos($event, '#') === false) {
$event .= '#issue';
} // Assume this is an issue.
$this->maybeLog($data, $note, $event);
return new Exception($note ? $note : $event);
} | php | {
"resource": ""
} |
q261727 | Debugging.logReview | test | public function logReview($data = [], string $note = '', string $event = ''): int
{
if (func_num_args() === 1 && is_string($data)) {
$note = $data; // Use data as note.
$data = []; // Data empty in this case.
}
$event = $event ?: $this->traceLogEventTrigger();
if (mb_strpos($event, '#') === false) {
$event .= '#review';
} // Assume this is for review.
return $this->maybeLog($data, $note, $event);
} | php | {
"resource": ""
} |
q261728 | Debugging.writeLogFileLines | test | protected function writeLogFileLines(string $event, array $lines): int
{
if (!$lines) { // No lines?
return 0; // Stop; nothing to do here.
}
$this->prepareLogsDir(); // Prepares (and secures).
if (mb_strpos($event, '#') !== false) {
$file_name = mb_strstr($event, '#');
$file_name = $this->c::nameToSlug($file_name);
$file_name .= '.log'; // Add extension now.
}
$file_name = $file_name ?: 'debug.log';
$process_file = $this->logs_dir.'/process.'.$file_name;
$file = $this->logs_dir.'/'.$file_name;
$this->maybeRotateLogFiles($file);
$entry = implode("\n", $lines)."\n\n".str_repeat('-', 3)."\n\n";
if (!isset($this->first_process_writes[$process_file])) {
$this->first_process_writes[$process_file] = -1;
@unlink($process_file); // First-process write.
} // ↑ Empty file on the first write in each process.
file_put_contents($process_file, $entry, LOCK_EX | FILE_APPEND);
return (int) file_put_contents($file, $entry, LOCK_EX | FILE_APPEND);
} | php | {
"resource": ""
} |
q261729 | Debugging.cleanLogEvent | test | protected function cleanLogEvent(string $event): string
{
if (($classes_pos = mb_strripos($event, '\\Classes\\')) !== false) {
$event = mb_substr($event, $classes_pos + 9);
} // This chops off `*\Classes\` from `__METHOD__`.
$event = str_replace($this->App->namespace, '', $event);
return $event = $this->c::mbTrim($event, '', '\\');
} | php | {
"resource": ""
} |
q261730 | Debugging.maybeRotateLogFiles | test | protected function maybeRotateLogFiles(string $file)
{
if (!$file || !is_file($file)) {
return; // Nothing to do at this time.
} elseif (filesize($file) < $this->max_log_file_size) {
return; // Nothing to do at this time.
} // Only rotate when log file becomes large.
rename($file, $this->uniqueSuffixLogFile($file));
foreach ($this->c::dirRegexRecursiveIterator($this->logs_dir, '/\.log$/ui') as $_Resource) {
if ($_Resource->isFile() && $_Resource->getMTime() < $this->max_log_file_age) {
unlink($_Resource->getPathname());
}
} // unset($_Resource); // Housekeeping.
} | php | {
"resource": ""
} |
q261731 | UrlRemote.response | test | public function response(string $url, array $args = []): \StdClass
{
return $this->curl($url, array_merge($args, ['return' => 'object']));
} | php | {
"resource": ""
} |
q261732 | DocumentParser.parse | test | public function parse(string $source): Contracts\Document
{
$content = $this->parseContent($source);
$metadata = $this->parseMetadata($this->parseHeader($source));
return $this->buildDocument($content, $metadata);
} | php | {
"resource": ""
} |
q261733 | DocumentParser.buildDocument | test | public function buildDocument(string $content, array $metadata): Contracts\Document
{
$document = $this->documentResolver;
$document->setContent($content);
$document->set($metadata);
return $document;
} | php | {
"resource": ""
} |
q261734 | DocumentParser.parseSection | test | public function parseSection(string $source, int $offset): string
{
$sections = preg_split(self::SECTION_SPLITTER, $source, 2);
if (count($sections) != 2) {
throw new TooFewSectionsException();
}
return trim($sections[$offset]);
} | php | {
"resource": ""
} |
q261735 | DocumentParser.parseMetadata | test | public function parseMetadata(string $source): array
{
$yaml = Yaml::parse($source);
if (! is_array($yaml)) {
throw new ParseException('The YAML value does not appear to be valid UTF-8.', -1, null, null);
}
return $yaml;
} | php | {
"resource": ""
} |
q261736 | Route.queryVar | test | public function queryVar(string $key): string
{
if (isset($this->query_vars[$key])) {
return $this->query_vars[$key];
}
$value = ''; // Initialize.
if (isset($_REQUEST[$key])) {
$value = (string) $_REQUEST[$key];
$value = $this->c::unslash($value);
$value = $this->c::mbTrim($value);
} elseif (isset($this->rewrite_query_vars[$key])) {
$value = $this->rewrite_query_vars[$key];
}
return $this->query_vars[$key] = $value;
} | php | {
"resource": ""
} |
q261737 | Route.get | test | protected function get(string $file, array $vars = [], string $dir = ''): string
{
$template_vars = $this->vars; // Route vars as template vars.
if (isset($template_vars[$file])) { // File-specific vars?
$template_vars = array_replace_recursive($template_vars, $template_vars[$file]);
}
$template_vars = array_replace_recursive($template_vars, $vars);
$Template = $this->c::getTemplate($file, $dir, ['Route' => $this]);
return $Template->parse($template_vars);
} | php | {
"resource": ""
} |
q261738 | Twitter.getRemote | test | public function getRemote(array $args = []): TwitterOAuth
{
$default_args = $this->default_credentials;
$args += $default_args;
$hash = $this->remoteHash($args);
if (isset($this->remotes[$hash])) {
return $this->remotes[$hash];
}
return $this->remotes[$hash] = new TwitterOAuth(
(string) $args['consumer_key'],
(string) $args['consumer_secret'],
(string) $args['access_token'],
(string) $args['access_token_secret']
);
} | php | {
"resource": ""
} |
q261739 | Twitter.remoteHash | test | protected function remoteHash(array $args = []): string
{
$default_args = $this->default_credentials;
$args += $default_args;
$args = array_intersect_key($args, $default_args);
$args = array_map('strval', $args);
return $hash = sha1(serialize($args));
} | php | {
"resource": ""
} |
q261740 | Transliterate.toAscii | test | public function toAscii($value)
{
if (is_array($value) || is_object($value)) {
foreach ($value as $_key => &$_value) {
$_value = $this->toAscii($_value);
} // unset($_key, $_value);
return $value;
}
if (!($string = (string) $value)) {
return $string; // Nothing to do.
}
return (string) transliterator_transliterate('Any-Latin; Latin-ASCII', $string);
} | php | {
"resource": ""
} |
q261741 | DistanceMatrixStatus.getDistanceMatrixStatus | test | public static function getDistanceMatrixStatus()
{
return array(
self::INVALID_REQUEST,
self::MAX_DIMENSIONS_EXCEEDED,
self::MAX_ELEMENTS_EXCEEDED,
self::OK,
self::OVER_QUERY_LIMIT,
self::REQUEST_DENIED,
self::UNKNOWN_ERROR,
);
} | php | {
"resource": ""
} |
q261742 | Indents.stripLeading | test | public function stripLeading($value, $trim = true)
{
if (is_array($value) || is_object($value)) {
foreach ($value as $_key => &$_value) {
$_value = $this->stripLeading($_value, $trim);
} // unset($_key, $_value);
return $value;
}
if (!($string = (string) $value)) {
return $string; // Nothing to do.
}
if ($trim === true) { // Default (trim).
$_string = $string; // Temporary copy.
$string = ''; // Reinitialize; rebuilding below.
$_line_based_pieces = preg_split('/(['."\r\n".']+)/u', $_string, -1, PREG_SPLIT_DELIM_CAPTURE);
foreach ($_line_based_pieces as $_index => $_piece) {
if (!preg_match('/^\s*$/u', $_piece)) {
$string = implode(array_slice($_line_based_pieces, $_index));
break; // Found the first line that's not just whitespace.
}
} // unset($_string, $_line_based_pieces, $_piece); // Housekeeping.
$string = $this->c::mbRTrim($string); // Now ditch any trailing whitespace.
//
} elseif ($trim === 'html-trim') { // HTML trimming in this case.
$_string = $string; // Temporary copy.
$string = ''; // Reinitialize; rebuilding below.
$_line_based_pieces = preg_split('/(['."\r\n".']+)/u', $_string, -1, PREG_SPLIT_DELIM_CAPTURE);
if (($html_whitespace = &$this->cacheKey(__FUNCTION__.'_html_whitespace')) === null) {
$html_whitespace = implode('|', $this::HTML_WHITESPACE);
}
foreach ($_line_based_pieces as $_index => $_piece) {
if (!preg_match('/^(?:'.$html_whitespace.')*$/u', $_piece)) {
$string = implode(array_slice($_line_based_pieces, $_index));
break; // Found the first line that's not just whitespace.
}
} // unset($_string, $_line_based_pieces, $_piece); // Housekeeping.
$string = $this->c::htmlRTrim($string); // Now ditch any trailing whitespace.
}
if (!$string || !preg_match('/^(?<indentation>['."\t".' ]+)/u', $string, $_m)) {
return $string; // Empty, or no indentation. Nothing to do.
}
return $string = preg_replace('/^'.$_m['indentation'].'/um', '', $string);
} | php | {
"resource": ""
} |
q261743 | DirectionsLeg.setSteps | test | public function setSteps(array $steps)
{
$this->steps = array();
foreach ($steps as $step) {
$this->addStep($step);
}
} | php | {
"resource": ""
} |
q261744 | Directions.route | test | public function route()
{
$args = func_get_args();
if (isset($args[0]) && ($args[0] instanceof DirectionsRequest)) {
$directionsRequest = $args[0];
} elseif ((isset($args[0]) && is_string($args[0])) && (isset($args[1]) && is_string($args[1]))) {
$directionsRequest = new DirectionsRequest();
$directionsRequest->setOrigin($args[0]);
$directionsRequest->setDestination($args[1]);
} else {
throw DirectionsException::invalidDirectionsRequestParameters();
}
if (!$directionsRequest->isValid()) {
throw DirectionsException::invalidDirectionsRequest();
}
$response = $this->send($this->generateUrl($directionsRequest));
$directionsResponse = $this->buildDirectionsResponse($this->parse($response->getBody()));
return $directionsResponse;
} | php | {
"resource": ""
} |
q261745 | Directions.buildDirectionsResponse | test | protected function buildDirectionsResponse(\stdClass $directionsResponse)
{
$routes = $this->buildDirectionsRoutes($directionsResponse->routes);
$status = $directionsResponse->status;
return new DirectionsResponse($routes, $status);
} | php | {
"resource": ""
} |
q261746 | Directions.buildDirectionsRoutes | test | protected function buildDirectionsRoutes(array $directionsRoutes)
{
$results = array();
foreach ($directionsRoutes as $directionsRoute) {
$results[] = $this->buildDirectionsRoute($directionsRoute);
}
return $results;
} | php | {
"resource": ""
} |
q261747 | Directions.buildDirectionsRoute | test | protected function buildDirectionsRoute(\stdClass $directionsRoute)
{
$bound = new Bound(
new Coordinate($directionsRoute->bounds->southwest->lat, $directionsRoute->bounds->southwest->lng),
new Coordinate($directionsRoute->bounds->northeast->lat, $directionsRoute->bounds->northeast->lng)
);
// @see https://github.com/egeloen/IvoryGoogleMapBundle/issues/72
// @codeCoverageIgnoreStart
if (!isset($directionsRoute->copyrights)) {
$directionsRoute->copyrights = '';
}
if (!isset($directionsRoute->summary)) {
$directionsRoute->summary = '';
}
// @codeCoverageIgnoreEnd
$summary = $directionsRoute->summary;
$copyrights = $directionsRoute->copyrights;
$directionsLegs = $this->buildDirectionsLegs($directionsRoute->legs);
$overviewPolyline = new EncodedPolyline($directionsRoute->overview_polyline->points);
// The warnings & waypoint_order properties can not be defined in the xml format.
if (!isset($directionsRoute->warnings)) {
$directionsRoute->warnings = array();
}
if (!isset($directionsRoute->waypoint_order)) {
$directionsRoute->waypoint_order = array();
}
$warnings = $directionsRoute->warnings;
$waypointOrder = $directionsRoute->waypoint_order;
return new DirectionsRoute(
$bound,
$copyrights,
$directionsLegs,
$overviewPolyline,
$summary,
$warnings,
$waypointOrder
);
} | php | {
"resource": ""
} |
q261748 | Directions.buildDirectionsLegs | test | protected function buildDirectionsLegs(array $directionsLegs)
{
$results = array();
foreach ($directionsLegs as $directionsLeg) {
$results[] = $this->buildDirectionsLeg($directionsLeg);
}
return $results;
} | php | {
"resource": ""
} |
q261749 | Directions.buildDirectionsLeg | test | protected function buildDirectionsLeg(\stdClass $directionsLeg)
{
$distance = new Distance($directionsLeg->distance->text, $directionsLeg->distance->value);
$duration = new Duration($directionsLeg->duration->text, $directionsLeg->duration->value);
$endAddress = $directionsLeg->end_address;
$endLocation = new Coordinate($directionsLeg->end_location->lat, $directionsLeg->end_location->lng);
$startAddress = $directionsLeg->start_address;
$startLocation = new Coordinate($directionsLeg->start_location->lat, $directionsLeg->start_location->lng);
$steps = $this->buildDirectionsSteps($directionsLeg->steps);
// The via_waypoint property can not be defined in the xml format.
if (!isset($directionsLeg->via_waypoint)) {
$directionsLeg->via_waypoint = array();
}
$viaWaypoint = $directionsLeg->via_waypoint;
return new DirectionsLeg(
$distance,
$duration,
$endAddress,
$endLocation,
$startAddress,
$startLocation,
$steps,
$viaWaypoint
);
} | php | {
"resource": ""
} |
q261750 | Directions.buildDirectionsSteps | test | protected function buildDirectionsSteps(array $directionsSteps)
{
$results = array();
foreach ($directionsSteps as $directionsStep) {
$results[] = $this->buildDirectionsStep($directionsStep);
}
return $results;
} | php | {
"resource": ""
} |
q261751 | Directions.buildDirectionsStep | test | protected function buildDirectionsStep(\stdClass $directionsStep)
{
$distance = new Distance($directionsStep->distance->text, $directionsStep->distance->value);
$duration = new Duration($directionsStep->duration->text, $directionsStep->duration->value);
$endLocation = new Coordinate($directionsStep->end_location->lat, $directionsStep->end_location->lng);
$instructions = $directionsStep->html_instructions;
$encodedPolyline = new EncodedPolyline($directionsStep->polyline->points);
$startLocation = new Coordinate($directionsStep->start_location->lat, $directionsStep->start_location->lng);
$travelMode = $directionsStep->travel_mode;
return new DirectionsStep(
$distance,
$duration,
$endLocation,
$instructions,
$encodedPolyline,
$startLocation,
$travelMode
);
} | php | {
"resource": ""
} |
q261752 | HSL.lighten | test | public function lighten($pct)
{
$lightness = $this->lightness() + $pct;
$lightness = $lightness > 100 ? 100 : $lightness;
return $this->withLightness($lightness);
} | php | {
"resource": ""
} |
q261753 | HSL.darken | test | public function darken($pct)
{
$lightness = $this->lightness() - $pct;
$lightness = $lightness < 0 ? 0 : $lightness;
return $this->withLightness($lightness);
} | php | {
"resource": ""
} |
q261754 | HSL.saturate | test | public function saturate($pct)
{
$saturation = $this->saturation() + $pct;
$saturation = $saturation > 100 ? 100 : $saturation;
return $this->withSaturation($saturation);
} | php | {
"resource": ""
} |
q261755 | HSL.desaturate | test | public function desaturate($pct)
{
$saturation = $this->saturation() - $pct;
$saturation = $saturation < 0 ? 0 : $saturation;
return $this->withSaturation($saturation);
} | php | {
"resource": ""
} |
q261756 | HSL.mix | test | public function mix(HSL $color)
{
return new self(...mixHSL(
$this->hue(),
$this->saturation(),
$this->lightness(),
$color->hue(),
$color->saturation(),
$color->lightness()
));
} | php | {
"resource": ""
} |
q261757 | Session.start | test | public function start(string $name = '', array $options = [])
{
if (session_status() !== \PHP_SESSION_NONE) {
throw $this->c::issue('Expecting inactive session.');
} // Expecting inactive so we can start below.
if ($name) {
session_name($name);
}
$options += [ // Defaults.
'use_strict_mode' => true,
'use_trans_sid' => false,
'sid_length' => 64,
'sid_bits_per_character' => 6,
'use_cookies' => true,
'use_only_cookies' => true,
'cookie_lifetime' => 0,
'cookie_path' => '/',
'cookie_secure' => true,
'cookie_httponly' => true,
'gc_maxlifetime' => 86400,
'cache_limiter' => 'nocache',
'read_and_close' => false,
];
if (!session_start($options)) {
throw $this->c::issue('Unable to start session.');
}
} | php | {
"resource": ""
} |
q261758 | WsVersion.isValid | test | public function isValid(string $version): bool
{
if (!$version) {
return false; // Nope.
}
return (bool) preg_match($this::WS_VERSION_REGEX_VALID, $version);
} | php | {
"resource": ""
} |
q261759 | WsVersion.isValidDev | test | public function isValidDev(string $version): bool
{
if (!$version) {
return false; // Nope.
}
return (bool) preg_match($this::WS_VERSION_REGEX_VALID_DEV, $version);
} | php | {
"resource": ""
} |
q261760 | WsVersion.isValidStable | test | public function isValidStable(string $version): bool
{
if (!$version) {
return false; // Nope.
}
return (bool) preg_match($this::WS_VERSION_REGEX_VALID_STABLE, $version);
} | php | {
"resource": ""
} |
q261761 | WsVersion.date | test | public function date(string $version, string $format = 'F jS, Y'): string
{
if (!$format) {
return ''; // Not possible.
} elseif (!($time = $this->time($version))) {
return ''; // Not possible.
}
return date($format, $time);
} | php | {
"resource": ""
} |
q261762 | WsVersion.time | test | public function time(string $version): int
{
if (!$version) {
return 0; // Not possible.
} elseif (!$this->isValid($version)) {
return 0; // Invalid version.
}
$Y = substr(date('Y'), 0, 2).substr($version, 0, 2);
$m = substr($version, 2, 2); // Month.
$d = substr($version, 4, 2); // Day.
$time = strtotime($Y.'-'.$m.'-'.$d.' 12:00 am');
if (preg_match('/^[0-9]{6}\.([0-9]+)/u', $version, $_m)) {
$time += $_m[1]; // Seconds into current day.
} // unset($_m); // Housekeeping.
return $time;
} | php | {
"resource": ""
} |
q261763 | Response.withNoCache | test | public function withNoCache(): self
{
$clone = $this->withoutHeader('last-modified');
foreach ($this->App->c::noCacheHeadersArray() as $_header => $_value) {
$clone = $clone->withHeader($_header, $_value);
} // unset($_header, $_value);
return $clone; // Response.
} | php | {
"resource": ""
} |
q261764 | Response.withSuccess | test | public function withSuccess(int $status, $data, bool $as_json = null): self
{
$is_data_array = is_array($data);
if (!isset($as_json) && $is_data_array) {
$as_json = $this->App->c::isApi() || $this->App->c::isAjax();
}
if ($as_json) { // Format as JSON?
$content_type = 'application/json';
$data = $is_data_array ? $data : [];
$content = json_encode(['success' => true] + $data, JSON_PRETTY_PRINT);
} else {
$content = is_string($data) ? $data : '';
$content_type = 'text/'.($this->App->c::isHtml($content, true) ? 'html' : 'plain');
}
$clone = $this->withStatus($status);
$clone = $clone->withHeader('content-type', $content_type.'; charset=utf-8');
$Body = $this->App->c::createReponseBody($content);
return $clone = $clone->withBody($Body);
} | php | {
"resource": ""
} |
q261765 | Response.withError | test | public function withError(int $status, $data, bool $as_json = null): self
{
$is_data_error = $data && $this->App->c::isError($data);
if (!isset($as_json) && $is_data_error) {
$as_json = $this->App->c::isApi() || $this->App->c::isAjax();
}
if ($as_json) { // Format as JSON?
$data = $is_data_error ? $data : null;
$Error = $data ?: $this->App->c::error();
$content_type = 'application/json';
$content = json_encode([
'success' => false,
'error' => [
'code' => $status,
'slug' => $Error->slug(),
'message' => $Error->message(),
],
], JSON_PRETTY_PRINT);
} else {
$data = is_string($data) ? $data : '';
$content = $data ?: $this->App->c::statusHeaderMessage($status);
$content_type = 'text/'.($this->App->c::isHtml($content, true) ? 'html' : 'plain');
}
$clone = $this->withStatus($status);
$clone = $clone->withHeader('content-type', $content_type.'; charset=utf-8');
$Body = $this->App->c::createReponseBody($content);
return $clone = $clone->withBody($Body);
} | php | {
"resource": ""
} |
q261766 | Response.output | test | public function output(array $args = [])
{
$default_args = [
'exit' => false,
];
$args += $default_args; // Merge defaults.
$args['exit'] = (bool) $args['exit'];
if ($this->hasNoCache()) {
$this->App->c::noCacheFlags();
}
$status = $this->getStatusCode();
$protocol = 'HTTP/'.$this->getProtocolVersion();
$this->App->c::statusHeader($status, $protocol);
foreach (array_keys($this->getHeaders()) as $_header) {
header($_header.': '.$this->getHeaderLine($_header));
} // unset($_header); // Housekeeping.
$Body = $this->getBody();
$Body->rewind(); // Rewind.
while (!$Body->eof()) {
echo $Body->read(262144); // 256kbs at a time.
}
if ($args['exit']) {
exit; // Stop here.
}
} | php | {
"resource": ""
} |
q261767 | DirectionsRoute.setLegs | test | public function setLegs(array $legs)
{
$this->legs = array();
foreach ($legs as $leg) {
$this->addLeg($leg);
}
} | php | {
"resource": ""
} |
q261768 | DirectionsRoute.setWarnings | test | public function setWarnings(array $warnings)
{
$this->warnings = array();
foreach ($warnings as $warning) {
$this->addWarning($warning);
}
} | php | {
"resource": ""
} |
q261769 | DirectionsRoute.setWaypointOrder | test | public function setWaypointOrder(array $waypointOrder)
{
$this->waypointOrder = array();
foreach ($waypointOrder as $waypointOrder) {
$this->addWaypointOrder($waypointOrder);
}
} | php | {
"resource": ""
} |
q261770 | ZoomControlStyleHelper.render | test | public function render($zoomControlStyle)
{
switch ($zoomControlStyle) {
case ZoomControlStyle::DEFAULT_:
case ZoomControlStyle::LARGE:
case ZoomControlStyle::SMALL:
return sprintf('google.maps.ZoomControlStyle.%s', strtoupper($zoomControlStyle));
default:
throw HelperException::invalidZoomControlStyle();
}
} | php | {
"resource": ""
} |
q261771 | Document.get | test | public function get(?string $key = null)
{
if (is_null($key)) {
return $this->metadata;
}
if (! array_key_exists($key, $this->metadata)) {
return null;
}
return $this->metadata[$key];
} | php | {
"resource": ""
} |
q261772 | OAuthServer.issueToken | test | public function issueToken(Request $Request, Response $Response)
{
try { // Handles `/(access|refresh)-token` endpoints.
$AuthorizationServer = $this->authorizationServer();
$Response = $AuthorizationServer->respondToAccessTokenRequest($Request, $Response);
$Response->output(['exit' => true]);
//
} catch (OAuthServerException $Exception) {
$Response = $Exception->generateHttpResponse($Response);
$Response->output(['exit' => true]);
//
} catch (\Throwable $Exception) {
$Exception = new OAuthServerException($Exception->getMessage(), 0, 'unknown', 500);
$Response = $Exception->generateHttpResponse($Response);
$Response->output(['exit' => true]);
}
} | php | {
"resource": ""
} |
q261773 | OAuthServer.resourceRequest | test | public function resourceRequest(Request $Request, Response $Response): Request
{
try { // Authenticate resource request.
$ResourceServer = $this->resourceServer();
return $Request = $ResourceServer->validateAuthenticatedRequest($Request);
//
} catch (OAuthServerException $Exception) {
$Response = $Exception->generateHttpResponse($Response);
$Response->output(['exit' => true]);
//
} catch (\Throwable $Exception) {
$Exception = new OAuthServerException($Exception->getMessage(), 0, 'unknown', 500);
$Response = $Exception->generateHttpResponse($Response);
$Response->output(['exit' => true]);
}
} | php | {
"resource": ""
} |
q261774 | OAuthServer.accessTokenRepository | test | protected function accessTokenRepository(): AccessTokenRepository
{
if ($this->AccessTokenRepository) {
return $this->AccessTokenRepository;
}
return $this->AccessTokenRepository = $this->App->Di->get(AccessTokenRepository::class);
} | php | {
"resource": ""
} |
q261775 | Slashes.add | test | public function add($value)
{
if (is_array($value) || is_object($value)) {
foreach ($value as $_key => &$_value) {
$_value = $this->add($_value);
} // unset($_key, $_value);
return $value;
}
$string = (string) $value;
return addslashes($string);
} | php | {
"resource": ""
} |
q261776 | Slashes.remove | test | public function remove($value)
{
if (is_array($value) || is_object($value)) {
foreach ($value as $_key => &$_value) {
$_value = $this->remove($_value);
} // unset($_key, $_value);
return $value;
}
$string = (string) $value;
return stripslashes($string);
} | php | {
"resource": ""
} |
q261777 | ApiHelper.render | test | public function render(
$language = 'en',
array $libraries = array(),
$callback = null,
$api_key = null
)
{
$otherParameters = array();
if (!empty($libraries)) {
$otherParameters['libraries'] = implode(',', $libraries);
}
$otherParameters['language'] = $language;
// Google Maps API warning: NoApiKeys https://developers.google.com/maps/documentation/javascript/error-messages#no-api-keys
if (!is_null($api_key)) {
$otherParameters['key'] = $api_key;
}
$this->jsonBuilder
->reset()
->setValue('[other_params]', urldecode(http_build_query($otherParameters)));
if ($callback !== null) {
$this->jsonBuilder->setValue('[callback]', $callback, false);
}
$callbackFunction = 'load_ivory_google_map_api';
$url = sprintf('//www.google.com/jsapi?callback=%s', $callbackFunction);
$loader = sprintf('google.load("maps", "3", %s);', $this->jsonBuilder->build());
$output = array();
$output[] = '<script type="text/javascript">'.PHP_EOL;
$output[] = sprintf('function %s () { %s };'.PHP_EOL, $callbackFunction, $loader);
$output[] = '</script>'.PHP_EOL;
$output[] = sprintf('<script type="text/javascript" src="%s"></script>'.PHP_EOL, $url);
$this->loaded = true;
return implode('', $output);
} | php | {
"resource": ""
} |
q261778 | DistanceMatrixResponseRow.setElements | test | public function setElements(array $elements)
{
$this->elements = array();
foreach ($elements as $element) {
$this->addElement($element);
}
} | php | {
"resource": ""
} |
q261779 | ControlPositionHelper.render | test | public function render($controlPosition)
{
switch ($controlPosition) {
case ControlPosition::BOTTOM_CENTER:
case ControlPosition::BOTTOM_LEFT:
case ControlPosition::BOTTOM_RIGHT:
case ControlPosition::LEFT_BOTTOM:
case ControlPosition::LEFT_CENTER:
case ControlPosition::LEFT_TOP:
case ControlPosition::RIGHT_BOTTOM:
case ControlPosition::RIGHT_CENTER:
case ControlPosition::RIGHT_TOP:
case ControlPosition::TOP_CENTER:
case ControlPosition::TOP_LEFT:
case ControlPosition::TOP_RIGHT:
return sprintf('google.maps.ControlPosition.%s', strtoupper($controlPosition));
default:
throw HelperException::invalidControlPosition();
}
} | php | {
"resource": ""
} |
q261780 | Ip.current | test | public function current(): string
{
if (($ip = &$this->cacheKey(__FUNCTION__)) !== null) {
return $ip; // Already cached this.
}
if ($this->c::isCli()) {
throw $this->c::issue('Not possible in CLI mode.');
} // @TODO Try detecting IP address in CLI mode.
$sources = [
'HTTP_CF_CONNECTING_IP',
'HTTP_CLIENT_IP',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_FORWARDED',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_VIA',
'REMOTE_ADDR',
];
foreach ($sources as $_source) {
if (!empty($_SERVER[$_source]) && is_string($_SERVER[$_source])) {
if (($_valid_public_ip = $this->getValidPublicFrom($_SERVER[$_source]))) {
return $ip = $_valid_public_ip; // IPv4 or IPv6 address.
}
} // unset($_valid_public_ip); // Housekeeping.
} // unset($_source); // Housekeeping.
if (!empty($_SERVER['REMOTE_ADDR'])) {
return $ip = mb_strtolower((string) $_SERVER['REMOTE_ADDR']);
}
return $ip = 'unknown'; // Not possible.
} | php | {
"resource": ""
} |
q261781 | Ip.region | test | public function region(string $ip): string
{
if (($geo = $this->geoData($ip))) {
return $geo->region;
}
return ''; // Failure.
} | php | {
"resource": ""
} |
q261782 | Ip.country | test | public function country(string $ip): string
{
if (!empty($_SERVER['HTTP_CF_IPCOUNTRY']) // Save time.
&& $ip === $_SERVER['HTTP_CF_CONNECTING_IP'] ?? '' && $ip === $this->current()
&& mb_strlen((string) $_SERVER['HTTP_CF_IPCOUNTRY']) === 2) {
return (string) $_SERVER['HTTP_CF_IPCOUNTRY'];
} // This saves time by using CloudFlare.
if (($geo = $this->geoData($ip))) {
return $geo->country;
}
return ''; // Failure.
} | php | {
"resource": ""
} |
q261783 | RequestType.isAjax | test | public function isAjax(bool $flag = null): bool
{
if (isset($flag)) {
$this->is_ajax = $flag;
}
if (!isset($this->is_ajax) && $this->is_wordpress) {
if (defined('DOING_AJAX') && DOING_AJAX) {
$this->is_ajax = true; // Via WP constants.
}
}
return (bool) $this->is_ajax;
} | php | {
"resource": ""
} |
q261784 | RequestType.isApi | test | public function isApi(bool $flag = null): bool
{
if (isset($flag)) {
$this->is_api = $flag;
}
if (!isset($this->is_api) && $this->is_wordpress) {
if ((defined('XMLRPC_REQUEST') && XMLRPC_REQUEST) || (defined('REST_REQUEST') && REST_REQUEST)) {
$this->is_api = true; // Via WP constants.
}
}
return (bool) $this->is_api;
} | php | {
"resource": ""
} |
q261785 | RequestType.doingRestAction | test | public function doingRestAction(string $action = null): string
{
if (isset($action)) {
$this->doing_rest_action = $action;
$this->doingAction($action, true);
}
return (string) $this->doing_rest_action;
} | php | {
"resource": ""
} |
q261786 | RequestType.doingAction | test | public function doingAction(string $action = '', bool $flag = null): bool
{
if ($action && isset($flag)) {
$this->doing_actions[$action] = $flag;
}
if ($action) {
return $this->doing_actions[$action] ?? false;
} else {
return !empty($this->doing_actions);
}
} | php | {
"resource": ""
} |
q261787 | MailChimpClient.subscribeNewUser | test | public static function subscribeNewUser($email,$listid,$confirm = false){
$data = [
'email_address' => $email,
'status' => ($confirm ? 'pending' : 'subscribed'),
];
if (!empty($merge_fields)) $data['merge_fields'] = $merge_fields;
$action = self::$api_version.'/lists/'.$listid.'/members/';
return self::send($action, 'POST', $data);
} | php | {
"resource": ""
} |
q261788 | MailChimpClient.getMember | test | public function getMember($email,$listid)
{
$action = "lists/".$listid."/members/" . md5($email);
return self::getData($action);
} | php | {
"resource": ""
} |
q261789 | MailChimpClient.updateUser | test | public static function updateUser($listid,$email,$status)
{
$data = [
'status' => $status
];
if (!empty($merge_fields)) $data['merge_fields'] = $merge_fields;
$action = self::$api_version.'/lists/'.$listid.'/members/'. md5($email);
return self::send($action, 'PATCH', $data);
} | php | {
"resource": ""
} |
q261790 | MailChimpClient.deleteUser | test | public static function deleteUser($listid,$email)
{
$email=md5($email);
$action = self::$api_version.'/lists/'.$listid.'/members/'. $email;
return self::send($action, 'DELETE', []);
} | php | {
"resource": ""
} |
q261791 | Color.sha1 | test | public function sha1(string $string, float $adjust = 0): string
{
$hex = '#'.mb_substr(sha1($string), 0, 6);
return $hex = $adjust ? $this->adjustLuminosity($hex, $adjust) : $hex;
} | php | {
"resource": ""
} |
q261792 | Color.adjustLuminosity | test | public function adjustLuminosity(string $hex, float $adjust): string
{
$hex = $this->cleanHex($hex);
for ($adjusted_hex = '', $_dec, $_hex, $_i = 0; $_i < 3; ++$_i) {
$_dec = hexdec(mb_substr($hex, $_i * 2, 2));
$_hex = dechex(round(min(max(0, $_dec + ($_dec * $adjust)), 255)));
$adjusted_hex .= $this->c::mbStrPad($_hex, 2, '0', STR_PAD_LEFT);
} // unset($_dec, $_hex, $_i); // Housekeeping.
return '#'.$adjusted_hex;
} | php | {
"resource": ""
} |
q261793 | Color.cleanHex | test | public function cleanHex(string $hex): string
{
$hex = ltrim($hex, '#');
if (!isset($hex[5])) {
$hex = preg_replace('/(.)/u', '$1$1', $hex);
$hex = $this->c::mbStrPad($hex, 6, '0');
}
return $hex;
} | php | {
"resource": ""
} |
q261794 | App.maybeEmptyNumericConfigArrays | test | public function maybeEmptyNumericConfigArrays(array $base, array $merge): array
{
if (!$merge) { // Save time. Merge is empty?
return $base; // Nothing to do here.
}
foreach ($base as $_key => &$_value) {
if (is_array($_value) && array_key_exists($_key, $merge)) {
if (!$_value || $_value === array_values($_value)) {
$_value = []; // Empty numeric arrays.
} elseif ($merge[$_key] && is_array($merge[$_key])) {
$_value = $this->maybeEmptyNumericConfigArrays($_value, $merge[$_key]);
}
}
} // unset($_key, $_value); // Housekeeping.
return $base; // Return possibly-modified base.
} | php | {
"resource": ""
} |
q261795 | Request.create | test | public function create(array $args = []): Classes\Core\Request
{
return $this->App->Di->get(Classes\Core\Request::class, $args);
} | php | {
"resource": ""
} |
q261796 | Request.createBody | test | public function createBody(string $content = null): Classes\Core\RequestBody
{
return $this->App->Di->get(Classes\Core\RequestBody::class, compact('content'));
} | php | {
"resource": ""
} |
q261797 | ArrayChangeRecursive.maybeEmptyNumericArrays | test | protected function maybeEmptyNumericArrays(array $array, array ...$merge): array
{
if (!$merge) { // Save time. Merge is empty?
return $base; // Nothing to do here.
}
foreach ($array as $_key => &$_value) {
if (is_array($_value)) {
foreach ($merge as $_merge) {
if (array_key_exists($_key, $_merge)) {
if (!$_value || $_value === array_values($_value)) {
$_value = []; // Empty.
} elseif (is_array($_merge[$_key])) {
$_value = $this->maybeEmptyNumericArrays($_value, $_merge[$_key]);
}
}
} // unset($_merge); // Housekeeping.
}
} // unset($_key, $_value); // Housekeeping.
return $array;
} | php | {
"resource": ""
} |
q261798 | RectangleHelper.render | test | public function render(Rectangle $rectangle, Map $map)
{
$this->jsonBuilder
->reset()
->setValue('[map]', $map->getJavascriptVariable(), false)
->setValue('[bounds]', $rectangle->getBound()->getJavascriptVariable(), false)
->setValues($rectangle->getOptions());
return sprintf(
'%s = new google.maps.Rectangle(%s);'.PHP_EOL,
$rectangle->getJavascriptVariable(),
$this->jsonBuilder->build()
);
} | php | {
"resource": ""
} |
q261799 | Array2Xml.toHtml | test | public function toHtml(string $parent_element_name, array $array, array $args = []): string
{
return $this->__invoke($parent_element_name, $array, array_merge($args, ['type' => 'html']));
} | php | {
"resource": ""
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.