_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q263200 | VerifyDeployRequest.handle | test | public function handle($request, Closure $next)
{
if ($request->path() === config('auto-deploy.route')) {
if (!config('auto-deploy.require-ssl') || $request->secure()) {
$origin = $this->determineOrigin();
if (null !== $origin) {
if ($origin->isAuthentic()) {
// set the origin type in the controller
$request->offsetSet('origin', $origin);
return $next($request);
} else {
abort(403, 'Forbidden. Could not verify the origin of the request.');
}
} else {
abort(403, 'Forbidden. Could not determine the origin of the request.');
}
} else {
abort(403, 'Forbidden. Webhook requests must be sent using SSL.');
}
}
// Passthrough if it's not our specific route
return $next($request);
} | php | {
"resource": ""
} |
q263201 | ContainerNamespace.importFromVendor | test | public function importFromVendor(string $vendorDir)
{
$mappingFile = $vendorDir . '/container_map.php';
if (!(file_exists($mappingFile) && is_readable($mappingFile)))
{
throw new ContainerNamespaceException("Could not find the the container map file at: " . $mappingFile);
}
$vendorPaths = require $mappingFile;
$this->paths = array_merge($vendorPaths, $this->paths);
} | php | {
"resource": ""
} |
q263202 | ContainerNamespace.has | test | public function has(string $name) : bool
{
return isset($this->paths[$name]) && is_string($this->paths[$name]);
} | php | {
"resource": ""
} |
q263203 | ContainerNamespace.getCodeFromFile | test | protected function getCodeFromFile(string $containerFilePath) : string
{
if (!file_exists($containerFilePath) || !is_readable($containerFilePath))
{
throw new ContainerNamespaceException("The file '" . $containerFilePath . "' is not readable or does not exist.");
}
return file_get_contents($containerFilePath);
} | php | {
"resource": ""
} |
q263204 | ContainerNamespace.getCode | test | public function getCode(string $name) : string
{
if (!$this->has($name))
{
throw new ContainerNamespaceException("There is no path named '" . $name . "' binded to the namespace.");
}
return $this->getCodeFromFile($this->paths[$name]);
} | php | {
"resource": ""
} |
q263205 | ContainerNamespace.parse | test | public function parse(string $containerFilePath)
{
// create a lexer from the given file
$lexer = new ContainerLexer($this->getCodeFromFile($containerFilePath));
// parse the file
$parser = new ScopeParser($lexer->tokens());
// interpret the parsed node
$interpreter = new ContainerInterpreter($this);
$interpreter->handleScope($parser->parse());
} | php | {
"resource": ""
} |
q263206 | ContainerInterpreter.handleScope | test | public function handleScope(ScopeNode $scope)
{
foreach($scope->getNodes() as $node)
{
if ($node instanceof ScopeImportNode)
{
$this->handleScopeImport($node);
}
elseif ($node instanceof ParameterDefinitionNode)
{
$this->handleParameterDefinition($node);
}
elseif ($node instanceof ServiceDefinitionNode)
{
$this->handleServiceDefinition($node);
}
else
{
throw new ContainerInterpreterException("Unexpected node in scope found.");
}
}
} | php | {
"resource": ""
} |
q263207 | ContainerInterpreter.handleScopeImport | test | public function handleScopeImport(ScopeImportNode $import)
{
$path = $import->getPath();
if (is_null($path) || empty($path))
{
throw new ContainerInterpreterException("An import statement cannot be empty.");
}
$code = $this->namespace->getCode($path);
// after retrieving new code we have
// to start a new lexer & and parser
$lexer = new ContainerLexer($code);
$parser = new ScopeParser($lexer->tokens());
$scopeNode = $parser->parse();
unset($lexer, $parser);
// and continue handling the importet scope
$this->handleScope($scopeNode);
} | php | {
"resource": ""
} |
q263208 | ContainerInterpreter.handleParameterDefinition | test | public function handleParameterDefinition(ParameterDefinitionNode $definition)
{
if ($this->namespace->hasParameter($definition->getName()) && $definition->isOverride() === false)
{
throw new ContainerInterpreterException("A parameter named \"{$definition->getName()}\" is already defined, you can prefix the definition with \"override\" to get around this error.");
}
if ($definition->getValue() instanceof ValueNode) {
$this->namespace->setParameter($definition->getName(), $definition->getValue()->getRawValue());
}
elseif ($definition->getValue() instanceof ArrayNode) {
$this->namespace->setParameter($definition->getName(), $definition->getValue()->convertToNativeArray());
}
else {
throw new ContainerInterpreterException("Invalid parameter value given for key \"{$definition->getName()}\".");
}
} | php | {
"resource": ""
} |
q263209 | ContainerInterpreter.createServiceArgumentsFromNode | test | protected function createServiceArgumentsFromNode(ArgumentArrayNode $argumentsNode) : ServiceArguments
{
$arguments = $argumentsNode
->getArguments();
$definition = new ServiceArguments();
foreach($arguments as $argument)
{
if ($argument instanceof ServiceReferenceNode)
{
$definition->addDependency($argument->getName());
}
elseif ($argument instanceof ParameterReferenceNode)
{
$definition->addParameter($argument->getName());
}
elseif ($argument instanceof ArrayNode)
{
$definition->addRaw($argument->convertToNativeArray());
}
elseif ($argument instanceof ValueNode)
{
$definition->addRaw($argument->getRawValue());
}
else
{
throw new ContainerInterpreterException("Unable to handle argument node of type \"" . get_class($argument) . "\".");
}
}
return $definition;
} | php | {
"resource": ""
} |
q263210 | ContainerInterpreter.handleServiceDefinition | test | public function handleServiceDefinition(ServiceDefinitionNode $definition)
{
if ($this->namespace->hasService($definition->getName()) && $definition->isOverride() === false)
{
throw new ContainerInterpreterException("A service named \"{$definition->getName()}\" is already defined, you can prefix the definition with \"override\" to get around this error.");
}
// create a service definition from the node
$service = new ServiceDefinition($definition->getClassName());
if ($definition->hasArguments())
{
$arguments = $definition
->getArguments() // get the definitions arguments
->getArguments(); // and the argument array from the object
foreach($arguments as $argument)
{
if ($argument instanceof ServiceReferenceNode)
{
$service->addDependencyArgument($argument->getName());
}
elseif ($argument instanceof ParameterReferenceNode)
{
$service->addParameterArgument($argument->getName());
}
elseif ($argument instanceof ArrayNode)
{
$service->addRawArgument($argument->convertToNativeArray());
}
elseif ($argument instanceof ValueNode)
{
$service->addRawArgument($argument->getRawValue());
}
else
{
throw new ContainerInterpreterException("Unable to handle argument node of type \"" . get_class($argument) . "\".");
}
}
}
// handle construction actions
foreach($definition->getConstructionActions() as $action)
{
if ($action instanceof ServiceMethodCallNode)
{
if ($action->hasArguments())
{
$service->addMethodCall($action->getName(), $this->createServiceArgumentsFromNode($action->getArguments()));
} else {
$service->calls($action->getName());
}
}
else
{
throw new ContainerInterpreterException("Invalid construction action of type \"" . get_class($action) . "\" given.");
}
}
// handle meta data
foreach($definition->getMetaDataAssignemnts() as $meta)
{
if ($meta instanceof MetaDataAssignmentNode)
{
if ($meta->hasData())
{
$service->addMetaData($meta->getKey(), $meta->getData()->convertToNativeArray());
} else {
$service->addMetaData($meta->getKey(), []);
}
}
else
{
throw new ContainerInterpreterException("Invalid meta data assignment \"" . get_class($meta) . "\" given.");
}
}
// add the node to the namespace
$this->namespace->setService($definition->getName(), $service);
} | php | {
"resource": ""
} |
q263211 | ServiceDefinition.fromArray | test | public static function fromArray(array $serviceConfiguration)
{
if (!isset($serviceConfiguration['class']))
{
throw new InvalidServiceException('The service configuration must define a "class" attribute.');
}
// construct the service definition
$defintion = new static($serviceConfiguration['class'], $serviceConfiguration['arguments'] ?? []);
// add service method calls if configured
if (isset($serviceConfiguration['calls']))
{
foreach($serviceConfiguration['calls'] as $call)
{
if (isset($call['method']) && isset($call['arguments']))
{
$defintion->calls($call['method'], $call['arguments']);
}
else
{
throw new InvalidServiceException('Every service call must have the attributes "method" and "arguments".');
}
}
}
return $defintion;
} | php | {
"resource": ""
} |
q263212 | ServiceDefinition.calls | test | public function calls(string $method, array $arguments = []) : ServiceDefinition
{
return $this->addMethodCall($method, new ServiceArguments($arguments));
} | php | {
"resource": ""
} |
q263213 | ServiceDefinition.addMethodCall | test | public function addMethodCall(string $methodName, ServiceArguments $arguments) : ServiceDefinition
{
$this->methodCallers[] = [$methodName, $arguments]; return $this;
} | php | {
"resource": ""
} |
q263214 | ServiceDefinition.addMetaData | test | public function addMetaData(string $key, array $values)
{
if (!isset($this->metaData[$key])) {
$this->metaData[$key] = [];
}
$this->metaData[$key][] = $values; return $this;
} | php | {
"resource": ""
} |
q263215 | Github.isOrigin | test | public function isOrigin()
{
// Correct IP range for Github maintained here:
// https://help.github.com/articles/what-ip-addresses-does-github-use-that-i-should-whitelist/
$hasGithubHeader = false !== strpos($this->request->header('User-Agent'), 'GitHub-Hookshot');
$hasGithubIp = $this->isIpInRange($this->request->server('REMOTE_ADDR'), '192.30.252.0', 22);
return $hasGithubHeader && $hasGithubIp;
} | php | {
"resource": ""
} |
q263216 | Github.isAuthentic | test | public function isAuthentic()
{
// get the Github signature
$xhub = $this->request->header('X-Hub-Signature') ?: 'nothing';
// reconstruct the hash on this side
$hash = 'sha1='.hash_hmac('sha1', $this->request->getContent(), config('auto-deploy.secret'));
// securely compare them
return hash_equals($xhub, $hash);
} | php | {
"resource": ""
} |
q263217 | ParameterDefinitionNode.setValue | test | public function setValue(AssignableNode $value)
{
// we currently only allow Arrays & scalar values
// it not yet possible assign a reference to a parameter
if (!($value instanceof ValueNode || $value instanceof ArrayNode)) {
throw new LogicalNodeException("It is not possible to pass a reference of a parameter or service to a parameter definition.");
}
$this->value = $value;
} | php | {
"resource": ""
} |
q263218 | WorkoutType.getName | test | static function getName($id)
{
try {
return self::TYPES_NAMES[$id];
} catch (\Exception $e) {
throw new EndomondoWorkoutException('Unknown workout type', $e->getCode(), $e->getPrevious());
}
} | php | {
"resource": ""
} |
q263219 | Point.toString | test | public function toString()
{
if ($this->getTime() !== null) {
$time = $this->getTime()->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d H:i:s \U\T\C');
} else {
$time = '';
}
return $time . ';' .
$this->getInstruction() . ';' .
$this->getLatitude() . ';' .
$this->getLongitude() . ';' .
$this->getDistance() . ';' .
$this->getSpeed() . ';' .
$this->getAltitude() . ';' .
$this->getHeartRate() . ';' .
$this->getCadence() . ';' .
"\n";
} | php | {
"resource": ""
} |
q263220 | Webhook.send | test | public function send(): bool
{
$response = $this->client->request(
'POST',
$this->client->getConfig('base_uri')->getPath(),
$this->buildPayload()
);
return $response->getStatusCode() === 200;
} | php | {
"resource": ""
} |
q263221 | Workout.setTypeId | test | public function setTypeId($id)
{
if (!WorkoutType::exist($id)) {
throw new EndomondoWorkoutException('Unknown workout type');
};
$this->typeId = $id;
return $this;
} | php | {
"resource": ""
} |
q263222 | Workout.getEnd | test | public function getEnd()
{
// if end property is defined, use it
if ($this->end) {
return clone $this->end;
}
$numberOfPosts = count($this->getPoints());
// try to find last time of point and use it as end date
if ($this->haveGPSData()) {
return $this->getPoints()[$numberOfPosts - 1]->getTime();
}
// if there are no points, calculate end date from duration
return $this->getStart()->add(new \DateInterval('PT' . $this->getDuration() . 'S'));
} | php | {
"resource": ""
} |
q263223 | Workout.getPointsAsString | test | public function getPointsAsString()
{
$points = '';
foreach ($this->getPoints() as $point) {
$points .= $point->toString();
}
return $points;
} | php | {
"resource": ""
} |
q263224 | Workout.getGPX | test | public function getGPX()
{
// @TODO use some library to generate GPX files
$xml = new \SimpleXMLElement(
'<gpx xmlns="http://www.topografix.com/GPX/1/1" '
. 'xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" '
. '/>'
);
$trk = $xml->addChild('trk');
$trk->addChild('type', str_replace(', ', '_', strtoupper($this->getTypeName())));
$trkseg = $trk->addChild('trkseg');
foreach ($this->getPoints() as $point) {
$trkpt = $trkseg->addChild('trkpt');
$trkpt->addChild('time', $point->getTime()->setTimezone(new \DateTimeZone('UTC'))->format('Y-m-d\TH:i:s\Z'));
$trkpt->addAttribute('lat', $point->getLatitude());
$trkpt->addAttribute('lon', $point->getLongitude());
if ($point->getAltitude() !== null) {
$trkpt->addChild('ele', $point->getAltitude());
}
if ($point->getHeartRate() !== null) {
$ext = $trkpt->addChild('extensions');
$trackPoint = $ext->addChild('gpxtpx:TrackPointExtension', '', 'gpxtpx');
$trackPoint->addChild('gpxtpx:hr', $point->getHeartRate(), 'gpxtpx');
}
}
return $xml->asXML();
} | php | {
"resource": ""
} |
q263225 | SlimResponseCollector.collect | test | function collect()
{
return [
'content-type' => $this->response->header('Content-Type'),
'status_code' => $this->response->getStatus(),
'headers' => $this->getDataFormatter()->formatVar($this->response->headers->all()),
'cookies' => $this->getDataFormatter()->formatVar($this->response->cookies->all()),
];
} | php | {
"resource": ""
} |
q263226 | Builder.getModels | test | public function getModels($columns = ['*'])
{
$results = $this->query->get($columns);
$connection = $this->model->getConnectionName();
// Check for joined relations
if (!empty($this->joined)) {
foreach ($results as $key => $result) {
$relation_values = [];
foreach ($result as $column => $value) {
Arr::set($relation_values, $column, $value);
}
foreach ($this->joined as $relationName) {
$relation = $this->getRelation($relationName);
$relation_values[$relationName] = $relation->getRelated()->newFromBuilder(
Arr::pull($relation_values, $relationName),
$connection
);
}
$results[$key] = $relation_values;
}
}
return $this->model->hydrate($results, $connection)->all();
} | php | {
"resource": ""
} |
q263227 | Utility.get_ajax_payload | test | public static function get_ajax_payload( $handle = '' ) {
$payload = null;
if ( ! empty( $_POST['payload'] ) ) {
$payload = $_POST['payload']; // Could be either a string or an array.
}
/**
* Filter the Ajax payload.
*
* @param mixed $payload The ajax payload.
* @param string $handle The current handler's handle.
*/
$payload = apply_filters( 'WP_Ajax_Helper\ajax_payload', $payload, $handle );
return $payload;
} | php | {
"resource": ""
} |
q263228 | Utility.get_callback_response | test | public static function get_callback_response( $handle, $callback, $callback_args ) {
$ajax_payload = static::get_ajax_payload( $handle );
$response = static::run_callback(
$callback,
array(
$ajax_payload,
$callback_args,
)
);
/**
* Filter the callback response.
*
* @param mixed $response The callback response.
* @param string $handle The current handle's name.
* @param array $callback_args The arguments passed to the callback function.
* @param mixed $ajax_payload The Ajax payload.
*/
$response = apply_filters( 'WP_Ajax_Helper\callback_response', $response, $handle, $callback_args, $ajax_payload );
return $response;
} | php | {
"resource": ""
} |
q263229 | Utility.run_callback | test | public static function run_callback( $callback = '', $callback_args = array() ) {
if ( ! is_callable( $callback ) ) {
return null;
}
try {
$result = call_user_func_array( $callback, $callback_args );
} catch ( \Exception $caught_exception ) {
$result = $caught_exception;
}
return $result;
} | php | {
"resource": ""
} |
q263230 | Utility.sanitize_handle | test | public static function sanitize_handle( $handle = null ) {
$handle = sanitize_key( $handle );
$handle = str_replace( '-', '_', $handle );
return $handle;
} | php | {
"resource": ""
} |
q263231 | Validator.validate_all | test | public function validate_all() {
foreach ( (array) $this->registered_validations as $condition => $value ) {
if ( ! $this->validate_single( $condition, $value ) ) {
return false;
}
}
return true;
} | php | {
"resource": ""
} |
q263232 | Validator.validate_single | test | private function validate_single( $condition, $value ) {
$validator = array( $this->validations_class, $condition );
if ( is_callable( $validator ) ) {
$result = call_user_func( $validator, $value );
} else {
$result = false;
}
return (bool) $result;
} | php | {
"resource": ""
} |
q263233 | Column.forDevice | test | public function forDevice($device, $width, $offset = null, $push = null, $resets = false)
{
$this->sizes[$device] = array('width' => $width, 'offset' => $offset, 'push' => $push);
if ($resets) {
$this->addReset($device);
}
return $this;
} | php | {
"resource": ""
} |
q263234 | Column.addReset | test | public function addReset($device)
{
if (!in_array($device, $this->resets)) {
$this->resets[] = $device;
}
return $this;
} | php | {
"resource": ""
} |
q263235 | Column.getSize | test | public function getSize($device)
{
if (isset($this->sizes[$device])) {
return $this->sizes[$device];
}
return null;
} | php | {
"resource": ""
} |
q263236 | Column.build | test | public function build()
{
$classes = array();
foreach ($this->sizes as $device => $size) {
if ($size['width']) {
$classes[] = sprintf('col-%s-%s', $device, $size['width']);
} else {
$classes[] = 'hidden-' . $device;
}
if ($size['offset'] !== null) {
$classes[] = sprintf('col-%s-offset-%s', $device, $size['offset']);
}
if ($size['push'] !== null) {
if (is_numeric($size['push'])) {
$push = ($size['push'] < 0) ? 'pull' : 'push';
$classes[] = sprintf('col-%s-%s-%s', $device, $push, $size['push']);
} else {
$classes[] = sprintf('col-%s-%s', $device, $size['push']);
}
}
}
if ($this->class) {
$classes[] = $this->class;
}
return $classes;
} | php | {
"resource": ""
} |
q263237 | Validations.user_is | test | public function user_is( $role ) {
if ( ! is_user_logged_in() ) {
return false;
}
$user = wp_get_current_user();
return in_array( $role, $user->roles );
} | php | {
"resource": ""
} |
q263238 | Walker.begin | test | public function begin()
{
$this->index = 0;
$this->infiniteIndex++;
if ($this->classesOnly) {
return $this->grid->getColumnAsString($this->index);
}
return sprintf(
'%s%s%s<div class="%s">%s',
$this->beginRow(),
PHP_EOL,
$this->grid->getColumnResetsAsString($this->index),
$this->grid->getColumnAsString($this->index),
PHP_EOL
);
} | php | {
"resource": ""
} |
q263239 | Walker.column | test | public function column()
{
$this->index++;
$this->infiniteIndex++;
if (!$this->grid->hasColumn($this->index)) {
$this->index = 0;
}
if ($this->classesOnly) {
return $this->grid->getColumnAsString($this->index);
}
$buffer = sprintf(
'%s</div>%s%s<div class="%s">%s',
PHP_EOL,
PHP_EOL,
$this->grid->getColumnResetsAsString($this->index),
$this->grid->getColumnAsString($this->index),
PHP_EOL
);
return $buffer;
} | php | {
"resource": ""
} |
q263240 | Walker.walk | test | public function walk()
{
if ($this->index < 0) {
return $this->begin();
}
if (!$this->grid->hasColumn($this->index + 1)) {
return $this->end() . $this->begin();
}
return $this->column();
} | php | {
"resource": ""
} |
q263241 | Walker.beginRow | test | public function beginRow()
{
if ($this->classesOnly) {
return trim('row ' . $this->grid->getRowClass());
}
return sprintf('<div class="%s">', trim('row ' . $this->grid->getRowClass()));
} | php | {
"resource": ""
} |
q263242 | Walker.getColumnResets | test | public function getColumnResets($tag = null)
{
if (!$this->infinite || $this->infiniteIndex === 0 || $this->grid->hasColumn($this->infiniteIndex)) {
return $this->grid->getColumnResetsAsString($this->index, $tag);
}
$number = count($this->grid->getColumns());
return $this->grid->getColumnResetsAsString(($this->infiniteIndex % $number), $tag);
} | php | {
"resource": ""
} |
q263243 | Walker.getIndex | test | public function getIndex($ignoreInfinite = false)
{
if ($this->infinite && !$ignoreInfinite) {
return $this->infiniteIndex;
}
return $this->index;
} | php | {
"resource": ""
} |
q263244 | migrate.migrateFromLegacy | test | private function migrateFromLegacy()
{
if (!$this->database->fieldExists('bootstrap_grid', 'tl_content')
&& $this->database->fieldExists('columnset_id', 'tl_content')
) {
$this->database->query(
'ALTER TABLE tl_content ADD bootstrap_grid int(10) unsigned NOT NULL default \'0\';'
);
$this->database->query('UPDATE tl_content SET bootstrap_grid=columnset_id WHERE bootstrap_grid = 0');
}
} | php | {
"resource": ""
} |
q263245 | Handler.handle | test | public function handle( $handle ) {
// Sanitize the handle name.
$this->handle = $this->utility->sanitize_handle( $handle );
// Register this handle with the frontend class.
$this->frontend->register_handle( $this->handle );
// Register the Ajax handler in the WordPress hook system.
add_action( 'wp_ajax_' . $this->handle, array( $this, 'ajax_handler' ) );
add_action( 'wp_ajax_nopriv_' . $this->handle, array( $this, 'ajax_handler' ) );
return $this;
} | php | {
"resource": ""
} |
q263246 | Handler.ajax_handler | test | public function ajax_handler() {
if ( $this->utility->validate_nonce( $this->handle ) && $this->validator->validate_all() ) {
$callback_response = $this->utility->get_callback_response( $this->handle, $this->handle_callback, $this->handle_callback_args );
$this->responder->handle_response( $callback_response );
} else {
http_response_code( 403 ); // Forbidden.
}
die();
} | php | {
"resource": ""
} |
q263247 | Handler.with_callback | test | public function with_callback( $callback = '', $callback_args = array() ) {
$this->handle_callback = $callback;
$this->handle_callback_args = $callback_args;
return $this;
} | php | {
"resource": ""
} |
q263248 | Handler.with_validation | test | public function with_validation( $validations = array() ) {
foreach ( (array) $validations as $condition => $value ) {
$this->validator->add_validation( $condition, $value );
}
return $this;
} | php | {
"resource": ""
} |
q263249 | Responder.handle_response | test | public function handle_response( $callback_response ) {
$this->callback_response = $callback_response;
$this->response_type = $this->get_response_type();
$this->send_response_headers();
$this->send_response_body();
} | php | {
"resource": ""
} |
q263250 | Responder.get_response_type | test | protected function get_response_type() {
if ( is_array( $this->callback_response ) ) {
$response_type = 'json';
} elseif ( is_string( $this->callback_response ) ) {
$response_type = 'plain';
} else {
// For everything else, i.e. null, WP_Error object, caught exception, etc.
$response_type = 'error';
}
return $response_type;
} | php | {
"resource": ""
} |
q263251 | Responder.send_response_headers | test | protected function send_response_headers() {
$http_content_type = 'text/plain';
// Set an HTTP error code if the response type is an error.
if ( 'error' === $this->response_type ) {
http_response_code( 500 ); // Internal server error.
}
// Set the content type to JSON if the callback response is an array.
if ( 'json' === $this->response_type ) {
$http_content_type = 'application/json';
}
header( sprintf( 'Content-Type: %s; charset=%s',
$http_content_type,
get_option( 'blog_charset' )
) );
} | php | {
"resource": ""
} |
q263252 | Responder.send_response_body | test | protected function send_response_body() {
if ( 'json' === $this->response_type ) {
$response_json = wp_json_encode( $this->callback_response );
if ( false !== $response_json ) {
echo $response_json;
}
} elseif ( 'plain' === $this->response_type ) {
echo $this->callback_response;
}
} | php | {
"resource": ""
} |
q263253 | GeoIP2Adapter.getContent | test | public function getContent(string $url): string
{
if (false === filter_var($url, FILTER_VALIDATE_URL)) {
throw new InvalidArgument(
sprintf('"%s" must be called with a valid url. Got "%s" instead.', __METHOD__, $url)
);
}
$ipAddress = parse_url($url, PHP_URL_QUERY);
if (false === filter_var($ipAddress, FILTER_VALIDATE_IP)) {
throw new InvalidArgument('URL must contain a valid query-string (an IP address, 127.0.0.1 for instance)');
}
$result = $this->geoIp2Provider
->{$this->geoIP2Model}($ipAddress)
->jsonSerialize();
return json_encode($result);
} | php | {
"resource": ""
} |
q263254 | GeoIP2Adapter.isSupportedGeoIP2Model | test | protected function isSupportedGeoIP2Model(string $method): bool
{
$availableMethods = [
self::GEOIP2_MODEL_CITY,
self::GEOIP2_MODEL_COUNTRY,
];
return in_array($method, $availableMethods);
} | php | {
"resource": ""
} |
q263255 | ToggleIconCallback.toggleVisibility | test | private function toggleVisibility($recordId, $newState)
{
if (!$this->hasAccess()) {
$this->log(
sprintf('Not enough permission to show/shide record ID "%s"', $recordId),
__METHOD__,
TL_ERROR
);
$this->redirect('contao/main.php?act=error');
}
$versions = new \Versions($this->table, $recordId);
if (isset($GLOBALS['TL_DCA'][$this->table]['fields'][$this->column]['save_callback'])) {
foreach ((array) $GLOBALS['TL_DCA'][$this->table]['fields'][$this->column]['save_callback'] as $callback) {
$instance = new $callback[0];
$instance->{$callback[1]}($newState, $this);
}
}
$this->database
->prepare(sprintf('UPDATE %s %s WHERE id=?', $this->table, '%s'))
->set(array('tstamp' => time(), $this->column => $newState ? '1' : ''))
->execute($recordId);
$versions->create();
} | php | {
"resource": ""
} |
q263256 | ToggleIconCallback.hasAccess | test | private function hasAccess()
{
if ($this->user instanceof \BackendUser) {
return $this->user->hasAccess($this->table . '::' . $this->column, 'alexf');
}
return false;
} | php | {
"resource": ""
} |
q263257 | GridBuilder.build | test | public function build()
{
$grid = new Grid();
foreach ($this->columns as $index => $column) {
$grid->addColumn($column->build());
$grid->addColumnResets($index, $column->getResets());
}
return $grid;
} | php | {
"resource": ""
} |
q263258 | Grid.getColumnAsString | test | public function getColumnAsString($index)
{
if (isset($this->columns[$index])) {
return implode(' ', $this->columns[$index]);
}
return '';
} | php | {
"resource": ""
} |
q263259 | Grid.addColumnReset | test | public function addColumnReset($column, $size)
{
if (!isset($this->columnResets[$column])) {
$this->columnResets[$column] = array();
}
if (!in_array($size, $this->columnResets[$column])) {
$this->columnResets[$column][] = $size;
}
return $this;
} | php | {
"resource": ""
} |
q263260 | Grid.addColumnResets | test | public function addColumnResets($column, array $sizes)
{
if (!isset($this->columnResets[$column])) {
$this->columnResets[$column] = $sizes;
} else {
$this->columnResets[$column] = array_unique(array_merge($this->columnResets[$column], $sizes));
}
return $this;
} | php | {
"resource": ""
} |
q263261 | Grid.getColumnResets | test | public function getColumnResets($index)
{
$index = intval($index);
if (isset($this->columnResets[$index])) {
return $this->columnResets[$index];
}
return array();
} | php | {
"resource": ""
} |
q263262 | Grid.hasColumnResetForSize | test | public function hasColumnResetForSize($column, $size)
{
if (!isset($this->columnResets[$column])) {
return false;
}
return in_array($size, $this->columnResets[$column]);
} | php | {
"resource": ""
} |
q263263 | Grid.getColumnResetsAsString | test | public function getColumnResetsAsString($index, $tag = null)
{
$tag = $tag ?: 'div';
return implode(
PHP_EOL,
array_map(
function ($item) use ($tag) {
return sprintf(
'<%s class="clearfix visible-%s-block"></%s>' . PHP_EOL,
$tag,
$item,
$tag
);
},
$this->getColumnResets($index)
)
);
} | php | {
"resource": ""
} |
q263264 | Frontend.register_handle | test | public function register_handle( $handle = '' ) {
$this->registered_handles[] = $handle;
// Only call add_actions() the first time a handle is registered, as the actions will still be registered for
// subsequent handles.
if ( 1 === count( $this->registered_handles ) ) {
$this->add_actions();
}
} | php | {
"resource": ""
} |
q263265 | Frontend.enqueue_scripts | test | public function enqueue_scripts() {
if ( empty( $this->registered_handles ) ) {
return;
}
$script_url = plugin_dir_url( trailingslashit( __DIR__ ) . '../../../' ) . 'assets/js/wp-ajax-helper.js';
wp_enqueue_script( 'wp-ajax-helper', $script_url, array( 'jquery' ), null, true );
wp_localize_script(
'wp-ajax-helper',
'wpAjaxHelper',
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'handles' => $this->get_nonces(),
)
);
} | php | {
"resource": ""
} |
q263266 | Frontend.get_nonces | test | protected function get_nonces() {
$nonces = array();
foreach ( (array) $this->registered_handles as $handle ) {
$nonces[ $handle ] = wp_create_nonce( $handle );
}
return $nonces;
} | php | {
"resource": ""
} |
q263267 | SemanticHtml5.getGrids | test | public static function getGrids(GetGridsEvent $event)
{
$model = $event->getModel();
$grids = $event->getGrids();
if ($model->type == 'semantic_html5') {
$query = 'SELECT * FROM tl_columnset WHERE published=1 ORDER BY title';
$result = \Database::getInstance()->query($query);
while ($result->next()) {
$key = sprintf($GLOBALS['TL_LANG']['tl_content']['bootstrap_columns'], $result->columns);
$grids[$key][$result->id] = $result->title;
}
}
} | php | {
"resource": ""
} |
q263268 | SemanticHtml5.hookParseTemplate | test | public function hookParseTemplate(\Template $template)
{
if (substr($template->getName(), 0, 3) != 'ce_'
|| $template->type != 'semantic_html5'
|| $template->sh5_tag != 'start'
) {
return;
}
$this->createRow($template);
$this->createColumn($template);
} | php | {
"resource": ""
} |
q263269 | SemanticHtml5.hookGetContentElement | test | public function hookGetContentElement($model, $buffer)
{
if ($model->type === 'semantic_html5'
&& $model->sh5_tag === 'start'
&& $model->bootstrap_isGridElement === 'column'
&& static::$grids[$model->bootstrap_gridRow]
) {
$row = $model->bootstrap_gridRow;
$grid = static::$grids[$row];
// Index is already incremented, so go back
$index = (static::$count[$row] - 1);
$buffer = $grid->getColumnResetsAsString($index) . $buffer;
}
return $buffer;
} | php | {
"resource": ""
} |
q263270 | SemanticHtml5.getGridElements | test | public function getGridElements($dataContainer)
{
$elements = array();
if ($dataContainer->activeRecord) {
$query = <<<SQL
SELECT
c.*, g.title as gridTitle, g.columns as gridColumns
FROM
tl_content c
LEFT JOIN
tl_columnset g
ON
g.id = c.bootstrap_grid
WHERE
(c.ptable=? OR c.ptable=?)
AND c.pid=?
AND c.type=?
AND c.sh5_tag=?
AND c.bootstrap_isGridElement=?
AND c.sorting < ?
ORDER BY
sorting
SQL;
$ptable = $GLOBALS['TL_DCA'][$dataContainer->table]['config']['ptable'];
$result = \Database::getInstance()
->prepare($query)
->execute(
$ptable,
$ptable == 'tl_article' ? '' : $ptable,
$dataContainer->activeRecord->pid,
'semantic_html5',
'start',
'row',
$dataContainer->activeRecord->sorting
);
while ($result->next()) {
$headline = deserialize($result->headline, true);
$elements[$result->id] = ($headline['value'] ?: ('ID ' . $result->id)) . ' [' .
$result->gridColumns . ' - ' . $result->gridTitle . ']';
}
}
return $elements;
} | php | {
"resource": ""
} |
q263271 | SemanticHtml5.createRow | test | private function createRow($template)
{
// semantic html5 element is marked as beginning of new grid row
if ($template->bootstrap_isGridElement == 'row') {
try {
static::$grids[$template->id] = Factory::createById($template->bootstrap_grid);
static::$count[$template->id] = 0;
} catch (\InvalidArgumentException $e) {
echo $e->getMessage();
return;
}
$class = ($template->class ? ' ' : '') . 'row';
if (static::$grids[$template->id]->getRowClass()) {
$class .= ' ' . static::$grids[$template->id]->getRowClass();
}
$template->class .= $class;
}
} | php | {
"resource": ""
} |
q263272 | SemanticHtml5.createColumn | test | private function createColumn($template)
{
// semantic html5 element is marked as an grid column
if ($template->bootstrap_isGridElement == 'column') {
if (static::$grids[$template->bootstrap_gridRow]) {
$row = $template->bootstrap_gridRow;
$grid = static::$grids[$row];
$index = static::$count[$row];
$template->class .= ($template->class ? ' ' : '') . $grid->getColumnAsString($index);
static::$count[$row]++;
}
}
} | php | {
"resource": ""
} |
q263273 | Factory.buildGridColumns | test | private static function buildGridColumns($builder, $result, $classes)
{
$columns = $result->columns;
$sizes = deserialize($result->sizes, true);
for ($i = 0; $i < $columns; $i++) {
$column = $builder->addColumn();
foreach ($sizes as $size) {
$key = 'columnset_' . $size;
$values = deserialize($result->$key, true);
$column->forDevice(
$size,
$values[$i]['width'],
($values[$i]['offset']) ? ($values[$i]['offset'] == 'null' ? 0 : $values[$i]['offset']): null,
$values[$i]['order'] ?: null
);
$index = ($i + 1);
if (!empty($classes[$index])) {
$column->setClass($classes[$index]);
}
}
}
return $builder->build();
} | php | {
"resource": ""
} |
q263274 | Factory.fetchResult | test | private static function fetchResult($gridId, $ignoreError = false)
{
$result = \Database::getInstance()
->prepare('SELECT * FROM tl_columnset WHERE id=? AND published=1')
->limit(1)
->execute($gridId);
if (!$ignoreError && $result->numRows < 1) {
throw new \InvalidArgumentException(sprintf('Could not find columnset with ID "%s"', $gridId));
}
return $result;
} | php | {
"resource": ""
} |
q263275 | Factory.prepareClasses | test | private static function prepareClasses($result)
{
$classes = array();
foreach (deserialize($result->customClasses, true) as $class) {
$classes[$class['column']] = $class['class'];
}
return $classes;
} | php | {
"resource": ""
} |
q263276 | Factory.buildColumnResets | test | private static function buildColumnResets($result, $grid)
{
foreach (deserialize($result->resets, true) as $row) {
foreach (array('xs', 'sm', 'md', 'lg') as $size) {
if (isset($row[$size]) && $row[$size]) {
$grid->addColumnReset(($row['column'] - 1), $size);
}
}
}
} | php | {
"resource": ""
} |
q263277 | Factory.createById | test | public static function createById($gridId, $ignoreError = false)
{
if (isset(static::$cache[$gridId])) {
return static::$cache[$gridId];
}
$result = self::fetchResult($gridId, $ignoreError);
if ($result) {
$builder = GridBuilder::create();
$classes = self::prepareClasses($result);
$grid = self::buildGridColumns($builder, $result, $classes);
$grid->setRowClass($result->rowClass);
self::buildColumnResets($result, $grid);
} else {
$grid = new Grid();
}
static::$cache[$gridId] = $grid;
return static::$cache[$gridId];
} | php | {
"resource": ""
} |
q263278 | Subcolumns.hookParseTemplate | test | public function hookParseTemplate(\Template $template)
{
if (TL_MODE == 'BE'
&& $template->getName() == 'be_subcolumns'
&& Bootstrap::getConfigVar('grid-editor.backend.replace-subcolumns-template')
) {
$template->setName('be_subcolumns_bootstrap');
}
} | php | {
"resource": ""
} |
q263279 | Subcolumns.hookIsVisibleElement | test | public function hookIsVisibleElement(\Model $model, $isVisible)
{
if (static::isActive() && (
($model->getTable() == 'tl_module' && $model->type == 'subcolumns') ||
$model->getTable() == 'tl_content' && ($model->type == 'colsetStart' ||
$model->type == 'colsetPart'
))) {
if ($model->type == 'colsetPart') {
$modelClass = get_class($model);
$parent = $modelClass::findByPk($model->sc_parent);
$type = $parent->sc_type;
$gridId = $parent->bootstrap_grid;
} else {
$type = $model->sc_type;
$gridId = $model->bootstrap_grid;
}
try {
$this->updateSubcolumnsDefinition($gridId, $type);
} catch (\Exception $e) {
// Do not throw the exception in the frontend. If nothing could fetched the fallback is used.
}
}
return $isVisible;
} | php | {
"resource": ""
} |
q263280 | Subcolumns.hookLoadFormField | test | public function hookLoadFormField($widget)
{
if ($widget->type === 'formcolstart') {
$type = $widget->fsc_type;
$gridId = $widget->bootstrap_grid;
$grid = Factory::createById($gridId);
$GLOBALS['TL_SUBCL'][static::$name]['sets'][$type] = $this->prepareContainer($grid);
} elseif ($widget->type === 'formcolpart' || $widget->type === 'formcolend') {
$parent = \FormFieldModel::findByPk($widget->fsc_parent);
$this->updateSubcolumnsDefinition($parent->bootstrap_grid, $parent->fsc_type);
}
return $widget;
} | php | {
"resource": ""
} |
q263281 | Subcolumns.getGrids | test | public static function getGrids(GetGridsEvent $event)
{
$model = $event->getModel();
$grids = $event->getGrids();
if ($model->type == 'colsetStart' || $model->type == 'subcolumns') {
$query = 'SELECT * FROM tl_columnset WHERE published=1 AND columns=? ORDER BY title';
$columns = $model->sc_type;
$result = \Database::getInstance()
->prepare($query)
->execute($columns);
while ($result->next()) {
$grids[$result->id] = $result->title;
}
} elseif ($model->type == 'formcolstart') {
$query = 'SELECT * FROM tl_columnset WHERE published=1 AND columns=? ORDER BY title';
$columns = $model->fsc_type;
$result = \Database::getInstance()
->prepare($query)
->execute($columns);
while ($result->next()) {
$grids[$result->id] = $result->title;
}
}
} | php | {
"resource": ""
} |
q263282 | Subcolumns.prepareContainer | test | protected function prepareContainer(Grid $grid)
{
$container = array();
foreach ($grid->getColumns() as $column) {
$container[] = array(implode(' ', $column));
}
return $container;
} | php | {
"resource": ""
} |
q263283 | Subcolumns.updateSubcolumnsDefinition | test | private function updateSubcolumnsDefinition($gridId, $type)
{
$grid = Factory::createById($gridId);
$GLOBALS['TL_SUBCL'][static::$name]['sets'][$type] = $this->prepareContainer($grid);
if ($grid->getRowClass()) {
$GLOBALS['TL_SUBCL'][static::$name]['scclass'] = 'row ' . $grid->getRowClass();
} else {
$GLOBALS['TL_SUBCL'][static::$name]['scclass'] = 'row';
}
} | php | {
"resource": ""
} |
q263284 | ColumnSet.appendColumnsetIdToPalette | test | public function appendColumnsetIdToPalette($dataContainer)
{
if ($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
return;
}
if ($dataContainer->table == 'tl_content') {
$model = \ContentModel::findByPK($dataContainer->id);
if ($model->sc_type > 0) {
\MetaPalettes::appendFields($dataContainer->table, 'colsetStart', 'colset', array('columnset_id'));
}
} else {
$model = \ModuleModel::findByPk($dataContainer->id);
if ($model->sc_type > 0) {
if ($model->sc_type > 0) {
$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns'] = str_replace(
'sc_type,',
'sc_type,columnset_id,',
$GLOBALS['TL_DCA']['tl_module']['palettes']['subcolumns']
);
}
}
}
} | php | {
"resource": ""
} |
q263285 | ColumnSet.appendColumnSizesToPalette | test | public function appendColumnSizesToPalette($dataContainer)
{
$model = \Database::getInstance()
->prepare('SELECT * FROM tl_columnset WHERE id=?')
->limit(1)
->execute($dataContainer->id);
$sizes = array_merge(deserialize($model->sizes, true));
foreach ($sizes as $size) {
$field = 'columnset_' . $size;
\MetaPalettes::appendFields('tl_columnset', 'columnset', array($field));
}
} | php | {
"resource": ""
} |
q263286 | ColumnSet.getAllTypes | test | public function getAllTypes()
{
if ($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
return array_keys($GLOBALS['TL_SUBCL'][$GLOBALS['TL_CONFIG']['subcolumns']]['sets']);
}
$this->import('Database');
$collection = $this->Database->execute('SELECT columns FROM tl_columnset GROUP BY columns ORDER BY columns');
$types = array();
while ($collection->next()) {
$types[] = $collection->columns;
}
return $types;
} | php | {
"resource": ""
} |
q263287 | ColumnSet.getGrids | test | public function getGrids($dataContainer)
{
if ($dataContainer->activeRecord) {
$dispatcher = $GLOBALS['container']['event-dispatcher'];
$event = new GetGridsEvent($dataContainer->activeRecord);
$dispatcher->dispatch(GetGridsEvent::NAME, $event);
return $event->getGrids()->getArrayCopy();
}
return array();
} | php | {
"resource": ""
} |
q263288 | ColumnSet.getColumnsForModule | test | public function getColumnsForModule($dataContainer)
{
if ($GLOBALS['TL_CONFIG']['subcolumns'] != 'bootstrap_customizable') {
$subcolumns = new \tl_module_sc();
return $subcolumns->getColumns($dataContainer);
}
$model = \ModuleModel::findByPK($dataContainer->currentRecord);
$cols = array();
$translate = array('first', 'second', 'third', 'fourth', 'fith');
for ($i = 0; $i < $model->sc_type; $i++) {
if (!array_key_exists($i, $translate)) {
break;
}
$key = $translate[$i];
$cols[$key] = $GLOBALS['TL_LANG']['MSC']['sc_' . $key];
}
return $cols;
} | php | {
"resource": ""
} |
q263289 | ColumnSet.getColumnOrders | test | public function getColumnOrders()
{
$columns = Bootstrap::getConfigVar('grid-editor.columns');
$values = array();
for ($i = 0; $i <= $columns; $i++) {
$values['push'][] = 'push-' . $i;
$values['pull'][] = 'pull-' . $i;
}
return $values;
} | php | {
"resource": ""
} |
q263290 | ColumnSet.getColumnNumbers | test | public function getColumnNumbers($dataContainer)
{
if ($dataContainer->activeRecord) {
$columns = $dataContainer->activeRecord->columns;
} else {
$columns = Bootstrap::getConfigVar('grid-editor.columns');
}
$values = range(1, $columns);
return $values;
} | php | {
"resource": ""
} |
q263291 | Flash.get | test | public function get(string $key, $default = null)
{
if (array_key_exists($key, $this->data)) {
return $this->data[$key];
}
return array_key_exists($key, $this->session) ? $this->session[$key] : $default;
} | php | {
"resource": ""
} |
q263292 | Flash.has | test | public function has(string $key): bool
{
return array_key_exists($key, $this->data) || array_key_exists($key, $this->session);
} | php | {
"resource": ""
} |
q263293 | Flash.delete | test | public function delete(string $key): self
{
unset($this->data[$key]);
unset($this->session[$key]);
return $this;
} | php | {
"resource": ""
} |
q263294 | Flash.load | test | public function load(string $key, callable $callback)
{
if (!$this->has($key)) {
$this->set($key, $callback($key));
}
return $this->get($key);
} | php | {
"resource": ""
} |
q263295 | Flash.reflash | test | public function reflash(array $keys = null): self
{
if ($keys === null) {
return $this->clear($this->data + $this->session);
}
$session = array_intersect_key($this->session, array_flip($keys));
return $this->clear($this->data + $session);
} | php | {
"resource": ""
} |
q263296 | InsertTag.parseInsertTag | test | public function parseInsertTag(ReplaceInsertTagsEvent $event)
{
if ($event->getTag() != 'grid') {
return;
}
if (TL_MODE !== 'FE') {
$event->setHtml(sprintf('[[%s]]', $event->getRaw()));
return;
}
$walker = $this->getWalker($event);
if (!$walker) {
return;
}
if ($event->getParam(3) === 'infinite' && !in_array($event->getParam(1), array('begin', 'end'))) {
$event->setHtml($walker->column());
} elseif (in_array($event->getParam(1), array('begin', 'walk', 'end'))) {
$method = $event->getParam(1);
$event->setHtml($walker->$method());
} else {
$event->setHtml($walker->column());
}
} | php | {
"resource": ""
} |
q263297 | InsertTag.getWalker | test | private function getWalker(ReplaceInsertTagsEvent $event)
{
$identifier = $event->getParam(0);
if (!isset(static::$walkers[$identifier])) {
list($columnSetId, $infinite) = $this->translateParams($event);
try {
static::$walkers[$identifier] = new Walker(Factory::createById($columnSetId), false, $infinite);
} catch (\Exception $e) {
return null;
}
}
return static::$walkers[$identifier];
} | php | {
"resource": ""
} |
q263298 | InsertTag.translateParams | test | private function translateParams(ReplaceInsertTagsEvent $event)
{
$infinite = false;
$columnSetId = $event->getParam(0);
if ($event->getParam(1) === 'begin' && $event->getParam(2)) {
$columnSetId = $event->getParam(2);
if ($event->getParam(3)) {
$infinite = true;
}
}
return array($columnSetId, $infinite);
} | php | {
"resource": ""
} |
q263299 | GestPayCryptWS.getEncParams | test | private function getEncParams()
{
// Parametri obbligatori
$params = array(
'shopLogin' => $this->getShopLogin(),
'uicCode' => $this->getCurrency(),
'amount' => $this->getAmount(),
'shopTransactionId' => $this->getShopTransactionID(),
);
return array_merge($params, $this->getOptParams());
} | 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.