_id
stringlengths 2
7
| title
stringlengths 3
151
| partition
stringclasses 3
values | text
stringlengths 83
13k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q240400
|
MString.split
|
train
|
public function split($regex = '//u', $limit = -1){
if(!\is_string($regex)){
throw new \InvalidArgumentException('$regex is not a string');
}
if(!\is_numeric($limit)){
throw new \InvalidArgumentException('$limit is not a number');
}
return \preg_split($regex, $this->_Value, $limit, \PREG_SPLIT_NO_EMPTY);
}
|
php
|
{
"resource": ""
}
|
q240401
|
MString.startsWith
|
train
|
public function startsWith(self $str, MStringComparison $cmp = null){
if($str->isNullOrEmpty()){
throw new \InvalidArgumentException('$str is empty');
}
if($str->count() > $this->count()){
throw new \InvalidArgumentException('$str is longer than $this');
}
if($cmp === null || $cmp->getValue() === MStringComparison::CASE_SENSITIVE){
return $this->substring(0, $str->count())->_Value === $str->_Value;
}
else{
return $this->substring(0, $str->count())->toLower()
->_Value === $str->toLower()->_Value;
}
}
|
php
|
{
"resource": ""
}
|
q240402
|
MString.toCharArray
|
train
|
public function toCharArray(){
$arr = array();
for($i = 0, $l = $this->count(); $i < $l; ++$i){
$arr[] = \mb_substr($this->_Value, $i, 1, $this->_Encoding);
}
return $arr;
}
|
php
|
{
"resource": ""
}
|
q240403
|
MString.trim
|
train
|
public function trim(array $chars = null){
if($chars === null){
return new static(\trim($this->_Value), $this->_Encoding);
}
$chars = \preg_quote(\implode(static::NONE, $chars));
$str = \preg_replace(
\sprintf('/(^[%s]+)|([%s]+$)/us', $chars, $chars),
static::NONE,
$this->_Value);
return new static($str, $this->_Encoding);
}
|
php
|
{
"resource": ""
}
|
q240404
|
MString.trimEnd
|
train
|
public function trimEnd(array $chars = null){
if($chars === null){
return new static(\rtrim($this->_Value), $this->_Encoding);
}
$chars = \preg_quote(\implode(static::NONE, $chars));
$str = \preg_replace(
\sprintf('/[%s]+$/us', $chars),
static::NONE,
$this->_Value);
return new static($str, $this->_Encoding);
}
|
php
|
{
"resource": ""
}
|
q240405
|
MString.trimStart
|
train
|
public function trimStart(array $chars = null){
if($chars === null){
return new static(\ltrim($this->_Value), $this->_Encoding);
}
$chars = \preg_quote(\implode(static::NONE, $chars));
$str = \preg_replace(
\sprintf('/^[%s]+/us', $chars),
static::NONE,
$this->_Value);
return new static($str, $this->_Encoding);
}
|
php
|
{
"resource": ""
}
|
q240406
|
MString.ucfirst
|
train
|
public function ucfirst(){
if($this->isNullOrWhitespace()){
return clone $this;
}
else if($this->count() === 1){
return new static(\mb_strtoupper($this->_Value, $this->_Encoding),
$this->_Encoding);
}
$str = $this[0]->ucfirst() . $this->substring(1);
return new static($str, $this->_Encoding);
}
|
php
|
{
"resource": ""
}
|
q240407
|
MString.unserialize
|
train
|
public function unserialize($serialized) {
$arr = \unserialize($serialized);
$this->_Value = $arr[0];
$this->_Encoding = $arr[1];
}
|
php
|
{
"resource": ""
}
|
q240408
|
File.download
|
train
|
public function download($pathToFile, $name = null, array $headers = array())
{
$response = StaticClient::get($this->offsetGet('_downloadURL'), array(
'headers' => $headers,
'timeout' => $this->timeout,
'save_to' => $pathToFile,
));
file_put_contents($pathToFile, $response->getBody()->getStream());
}
|
php
|
{
"resource": ""
}
|
q240409
|
Response.withType
|
train
|
public function withType($value)
{
$new = clone $this;
$new->headers[Header\ContentType::name()] = [];
$new->headers[Header\ContentType::name()][] = $value;
return $new;
}
|
php
|
{
"resource": ""
}
|
q240410
|
Response.withLanguage
|
train
|
public function withLanguage($value)
{
$new = clone $this;
$new->headers[Header\Language::name()] = [];
$new->headers[Header\Language::name()][] = $value;
return $new;
}
|
php
|
{
"resource": ""
}
|
q240411
|
Response.withTypeNegotiation
|
train
|
public function withTypeNegotiation($strongNegotiation = false)
{
$negotiation = array_intersect(Request\AcceptType::getContent(), Support\TypeSupport::getSupport());
$content = '';
if(count($negotiation) > 0) {
$content = current($negotiation);
}
else {
if($strongNegotiation) {
$this->failTypeNegotiation();
}
else {
$content = Support\TypeSupport::getSupport();
$content = $content[0];
}
}
return $this->withType($content);
}
|
php
|
{
"resource": ""
}
|
q240412
|
Response.withAddedType
|
train
|
public function withAddedType($value)
{
$new = clone $this;
if (empty($new->headers[Header\ContentType::name()])) {
$new->headers[Header\ContentType::name()] = [];
}
$new->headers[Header\ContentType::name()][] = $value;
return $new;
}
|
php
|
{
"resource": ""
}
|
q240413
|
Response.withAddedLanguage
|
train
|
public function withAddedLanguage($value)
{
$new = clone $this;
if (empty($new->headers[Header\Language::name()])) {
$new->headers[Header\Language::name()] = [];
}
$new->headers[Header\Language::name()][] = $value;
return $new;
}
|
php
|
{
"resource": ""
}
|
q240414
|
Response.failTypeNegotiation
|
train
|
protected function failTypeNegotiation()
{
$supported = Request\TypeSupport::getSupport();
$clientSupport = Request\AcceptType::getContent();
$supported = implode(',', $supported);
$clientSupport = implode(',',$clientSupport);
$this->withStatus(406)->withType(Response\ContentType::TEXT)
->write("NOT SUPPORTED\nThis server does not support {$supported}.\nSupported formats: {$clientSupport}")
->send();
exit(1);
}
|
php
|
{
"resource": ""
}
|
q240415
|
Response.overwrite
|
train
|
public function overwrite($data)
{
$body = $this->getBody();
$body->rewind();
$body->write($data);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240416
|
Response.send
|
train
|
public function send()
{
header($this->getStatusStr());
foreach($this->headers as $header => $value) {
header(sprintf("%s: %s", $header, implode(',', $value)));
}
$body = $this->getBody();
if ($body->isAttached()) {
$body->rewind();
while (!$body->eof()) {
echo $body->read($this->bodySize);
}
}
}
|
php
|
{
"resource": ""
}
|
q240417
|
NextrasDbal.dropDatabase
|
train
|
public function dropDatabase(): void
{
$tables = $this->getTables();
if (!empty($tables)) {
$this->connection->query('SET foreign_key_checks = 0');
foreach ($tables as $table) {
$this->connection->query('DROP TABLE %table', $table);
}
$this->connection->query('SET foreign_key_checks = 1');
}
}
|
php
|
{
"resource": ""
}
|
q240418
|
VinceTBaseExtension.camelizeBundle
|
train
|
public function camelizeBundle($string)
{
$string = $this->camelize($string);
$string = str_replace('_bundle', '', $string);
return $string;
}
|
php
|
{
"resource": ""
}
|
q240419
|
StatusController.indexAction
|
train
|
public function indexAction(Request $request)
{
$query = $request->query->get('query');
$limit = $request->query->get('limit');
$start = $request->query->get('start');
$searchProviders = $this->get('search.providers');
$content = '';
$content .= '<h3>Registered Search Providers:</h3><table><tr><th>Class</th><th>Resource</th><th>Search key</th></tr>';
foreach ($searchProviders as $searchProvider) {
$content .= '<tr>';
$content .= '<td>'.get_class($searchProvider).'</td>';
$content .= '<td>'.$searchProvider->getResource().'</td>';
$content .= '<td>'.$searchProvider->getSearchKey().'</td>';
$content .= '</tr>';
}
$content .= '</table>';
$content .= '<h3>Search:</h3>';
$content .= '<form><input name="query" value="'.$query.'"/><input type="submit" value="send" /></form>';
if ($query) {
$content .= '<h3>Results:</h3>';
$search = $this->getContainer()->get('search.search');
$results = $search->search($query);
$content .= '<pre>';
$content .= print_r($results, true);
$content .= '</pre>';
}
return new Response($content);
}
|
php
|
{
"resource": ""
}
|
q240420
|
Assets.loadSiteScripts
|
train
|
public function loadSiteScripts()
{
if (is_singular() && comments_open() && get_option('thread_comments')) {
wp_enqueue_script('comment-reply');
}
$mainHandle = 'site';
$this->loadMainScriptByHandle($mainHandle);
$viewHandle = $this->getViewHandle();
if (file_exists(sprintf('%s/js/views/%s.js', $this->paths->getThemeAssetsDir(), $viewHandle))) {
$viewSrc = sprintf('%s/js/views/%s.js', $this->paths->getThemeAssetsUri(), $viewHandle);
$this->loadScript($viewHandle, $viewSrc, [$mainHandle], true);
}
}
|
php
|
{
"resource": ""
}
|
q240421
|
Assets.loadSiteStyles
|
train
|
public function loadSiteStyles()
{
$this->loadCdnStyles();
$mainHandle = 'site';
$this->loadMainStyleByHandle($mainHandle);
$viewHandle = $this->getViewHandle();
if (file_exists(sprintf('%s/css/views/%s.css', $this->paths->getThemeAssetsDir(), $viewHandle))) {
$viewSrc = sprintf('%s/css/views/%s.css', $this->paths->getThemeAssetsUri(), $viewHandle);
$this->loadStyle($viewHandle, $viewSrc, [$mainHandle]);
}
}
|
php
|
{
"resource": ""
}
|
q240422
|
Assets.loadCustomizeScript
|
train
|
public function loadCustomizeScript()
{
$handle = 'novusopress_customize';
$url = sprintf('%s/js/customize.js', $this->paths->getBaseAssetsUri());
$deps = ['jquery', 'customize-preview'];
$this->loadScript($handle, $url, $deps, true);
}
|
php
|
{
"resource": ""
}
|
q240423
|
Assets.loadCdnStyles
|
train
|
protected function loadCdnStyles()
{
if (file_exists(sprintf('%s/cdn-styles.json', $this->paths->getThemeConfigDir()))) {
$cdnContent = file_get_contents(sprintf('%s/cdn-styles.json', $this->paths->getThemeConfigDir()));
$cdnStyles = json_decode($cdnContent, true);
for ($i = 0; $i < count($cdnStyles); $i++) {
$handle = $i ? 'cdn'.$i : 'cdn';
wp_enqueue_style($handle, $cdnStyles[$i], [], null);
}
}
}
|
php
|
{
"resource": ""
}
|
q240424
|
Assets.loadMainScriptByHandle
|
train
|
protected function loadMainScriptByHandle($mainHandle)
{
$deps = $this->getScriptDeps($mainHandle);
if (file_exists(sprintf('%s/js/%s.js', $this->paths->getThemeAssetsDir(), $mainHandle))) {
$mainSrc = sprintf('%s/js/%s.js', $this->paths->getThemeAssetsUri(), $mainHandle);
} else {
// load empty script in case we need to load dependencies
$mainSrc = sprintf('%s/js/%s.js', $this->paths->getBaseAssetsUri(), $mainHandle);
}
$this->loadScript($mainHandle, $mainSrc, $deps, true);
}
|
php
|
{
"resource": ""
}
|
q240425
|
Assets.loadMainStyleByHandle
|
train
|
protected function loadMainStyleByHandle($mainHandle)
{
$deps = $this->getStyleDeps($mainHandle);
if (file_exists(sprintf('%s/css/%s.css', $this->paths->getThemeAssetsDir(), $mainHandle))) {
$mainSrc = sprintf('%s/css/%s.css', $this->paths->getThemeAssetsUri(), $mainHandle);
} else {
// load styles in case we need to load dependencies
$mainSrc = sprintf('%s/css/%s.css', $this->paths->getBaseAssetsUri(), $mainHandle);
}
$this->loadStyle($mainHandle, $mainSrc, $deps);
}
|
php
|
{
"resource": ""
}
|
q240426
|
Assets.getScriptDeps
|
train
|
protected function getScriptDeps($section)
{
$dependencies = $this->getDependencies();
$deps = isset($dependencies['scripts']) ? $dependencies['scripts'] : [];
return isset($deps[$section]) ? $deps[$section] : [];
}
|
php
|
{
"resource": ""
}
|
q240427
|
Assets.getStyleDeps
|
train
|
protected function getStyleDeps($section)
{
$dependencies = $this->getDependencies();
$deps = isset($dependencies['styles']) ? $dependencies['styles'] : [];
return isset($deps[$section]) ? $deps[$section] : [];
}
|
php
|
{
"resource": ""
}
|
q240428
|
Assets.getDependencies
|
train
|
protected function getDependencies()
{
if (null === $this->dependencies) {
if (file_exists(sprintf('%s/dependencies.json', $this->paths->getThemeConfigDir()))) {
$depsContent = file_get_contents(sprintf('%s/dependencies.json', $this->paths->getThemeConfigDir()));
} else {
$depsContent = file_get_contents(sprintf('%s/dependencies.json', $this->paths->getBaseConfigDir()));
}
$this->dependencies = json_decode($depsContent, true);
}
return $this->dependencies;
}
|
php
|
{
"resource": ""
}
|
q240429
|
Assets.getViewHandle
|
train
|
protected function getViewHandle()
{
if (is_front_page() && is_home()) {
return 'index';
} elseif (is_front_page()) {
return 'front-page';
} elseif (is_home()) {
return 'index';
} elseif (is_page_template()) {
global $wp_query;
$templateName = get_post_meta($wp_query->post->ID, '_wp_page_template', true);
return substr($templateName, 0, -4);
} elseif (is_page()) {
return 'page';
} elseif (is_attachment()) {
return 'attacment';
} elseif (is_single()) {
return 'single';
} elseif (is_archive()) {
return 'archive';
} elseif (is_search()) {
return 'search';
}
return 'not-found';
}
|
php
|
{
"resource": ""
}
|
q240430
|
Router.group
|
train
|
public static function group(array $properties, array $routes)
{
// Translate a single filter to an array of one filter
if (isset($properties['filter'])) {
if (!is_array($properties['filter'])) {
$properties['filter'] = [$properties['filter']];
}
} else {
$properties['filter'] = [];
}
$baseProperties = ['prefix' => '', 'rprefix' => ''];
$properties = array_merge($baseProperties, $properties);
// $routes: [0] = HTTP method, [1] = pattern, [2] = controller/method route
foreach ($routes as $route) {
$httpmethod = $route[0];
if (!method_exists(__CLASS__, $httpmethod)) {
continue;
}
$pattern = $properties['prefix'].$route[1];
$callback = $properties['rprefix'].$route[2];
$options = [
'filter' => $properties['filter']
];
self::$httpmethod($pattern, $callback, $options);
}
}
|
php
|
{
"resource": ""
}
|
q240431
|
Router.route
|
train
|
public static function route(Http\Request $request)
{
$path = $request->REQUEST_URI;
$key = $request->getMethod().'@'.$path;
$keyAny = 'ANY@'.$path;
$matchedRoute = null;
$matchedScore = 0;
if (isset(self::$routes[$key])) {
$matchedRoute = self::$routes[$key];
} elseif (isset(self::$routes[$keyAny])) {
$matchedRoute = self::$routes[$keyAny];
} else {
foreach (self::$routes as $key2 => $route) {
if ($route->getMethod() != 'ANY' && $route->getMethod() != $request->getMethod()) {
continue;
}
$score = $route->getScore($path, $request->getMethod());
if ($score > $matchedScore) {
$matchedRoute = $route;
$matchedScore = $score;
}
}
}
if ($matchedRoute) {
$matchedRoute->setUrl($path);
} elseif (self::$_404route) {
$matchedRoute = self::$_404route;
} else {
throw new Exceptions\RouteException('Route not found');
}
return $matchedRoute;
}
|
php
|
{
"resource": ""
}
|
q240432
|
ServiceProvider.fullBoot
|
train
|
public function fullBoot($package, $dir)
{
$this->mapRoutes($dir);
if (file_exists($dir.'/views')) {
$this->loadViewsFrom($dir.'/views', $package);
}
if (file_exists($dir.'/migrations')) {
$this->publishes([
$dir.'/migrations' => base_path('database/migrations/')
], 'migrations');
}
if (file_exists($dir.'/seeds')) {
$this->publishes([
$dir.'/seeds' => base_path('database/seeds/')
], 'seeds');
}
if (file_exists($dir."config/$package.php")) {
$this->mergeConfigFrom(
$dir."config/$package.php",
$package
);
$this->publishes([
$dir.'/config' => base_path('config')
], 'config');
}
if (file_exists($dir.'/lang')) {
$this->publishes([
$dir.'/lang' => resource_path()."/lang/vendor/$package",
]);
$this->loadTranslationsFrom(
$dir."/lang",
$package
);
}
if (file_exists($dir.'/assets')) {
$this->publishes([
$dir.'/assets' => base_path('resources/assets'),
], 'assets');
}
if(file_exists($dir.'/factories/ModelFactory.php')){
require($dir.'/factories/ModelFactory.php');
}
}
|
php
|
{
"resource": ""
}
|
q240433
|
ArrayQueue.reindex
|
train
|
private function reindex(int $capacity): void
{
$temp = [];
for ($i = 0; $i < $this->count; $i++) {
$temp[$i] = $this->items[($i + $this->front) % $this->cap];
}
$this->items = $temp;
$this->cap = $capacity;
$this->front = 0;
$this->end = $this->count;
}
|
php
|
{
"resource": ""
}
|
q240434
|
GD.jpegToWbmp
|
train
|
public function jpegToWbmp(String $jpegFile, String $wbmpFile, Array $settings = []) : Bool
{
if( is_file($jpegFile) )
{
$height = $settings['height'] ?? $this->height ?? 0;
$width = $settings['width'] ?? $this->width ?? 0;
$threshold = $settings['threshold'] ?? $this->threshold ?? 0;
$this->defaultRevolvingVariables();
return jpeg2wbmp($jpegFile, $wbmpFile, $height, $width, $threshold);
}
else
{
return false;
}
}
|
php
|
{
"resource": ""
}
|
q240435
|
GD.pngToWbmp
|
train
|
public function pngToWbmp(String $pngFile, String $wbmpFile, Array $settings = []) : Bool
{
if( is_file($pngFile) )
{
$height = $settings['height'] ?? 0;
$width = $settings['width'] ?? 0;
$threshold = $settings['threshold'] ?? 0;
return png2wbmp($pngFile, $wbmpFile, $height, $width, $threshold);
}
else
{
return false;
}
}
|
php
|
{
"resource": ""
}
|
q240436
|
GD.alphaBlending
|
train
|
public function alphaBlending(Bool $blendMode = NULL) : GD
{
imagealphablending($this->canvas, (bool) $blendMode);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240437
|
GD.saveAlpha
|
train
|
public function saveAlpha(Bool $save = true) : GD
{
imagesavealpha($this->canvas, $save);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240438
|
GD.pixelIndex
|
train
|
public function pixelIndex(Int $x, Int $y) : Int
{
return imagecolorat($this->canvas, $x, $y);
}
|
php
|
{
"resource": ""
}
|
q240439
|
GD.line
|
train
|
public function line(Array $settings = []) : GD
{
$x1 = $settings['x1'] ?? $this->x1 ?? 0;
$y1 = $settings['y1'] ?? $this->y1 ?? 0;
$x2 = $settings['x2'] ?? $this->x2 ?? 0;
$y2 = $settings['y2'] ?? $this->y2 ?? 0;
$rgb = $settings['color'] ?? $this->color ?? '0|0|0';
$type = $settings['type'] ?? $this->type ?? 'solid';
if( $type === 'solid' )
{
imageline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb));
}
elseif( $type === 'dashed' )
{
imagedashedline($this->canvas, $x1, $y1, $x2, $y2, $this->allocate($rgb));
}
$this->defaultRevolvingVariables();
return $this;
}
|
php
|
{
"resource": ""
}
|
q240440
|
GD.windowDisplay
|
train
|
public function windowDisplay(Int $window, Int $clientArea = 0) : GD
{
$this->canvas = imagegrabwindow($window, $clientArea);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240441
|
GD.layerEffect
|
train
|
public function layerEffect(String $effect = 'normal') : GD
{
imagelayereffect($this->canvas, Helper::toConstant($effect, 'IMG_EFFECT_'));
return $this;
}
|
php
|
{
"resource": ""
}
|
q240442
|
GD.loadFont
|
train
|
public function loadFont(String $file) : Int
{
if( ! is_file($file) )
{
throw new InvalidArgumentException(NULL, '[file]');
}
return imageloadfont($file);
}
|
php
|
{
"resource": ""
}
|
q240443
|
GD.copyPalette
|
train
|
public function copyPalette($source)
{
if( ! is_resource($source) )
{
throw new InvalidArgumentException(NULL, '[resource]');
}
imagepalettecopy($this->canvas, $source);
}
|
php
|
{
"resource": ""
}
|
q240444
|
GD.createImageCanvas
|
train
|
protected function createImageCanvas($image)
{
$this->type = $this->mime->type($image, 1);
$this->imageSize = ! isset($this->width) ? getimagesize($image) : [$this->width ?? 0, $this->height ?? 0];
$this->canvas = $this->createFrom($image,
[
# For type gd2p
'x' => $this->x ?? 0,
'y' => $this->y ?? 0,
'width' => $this->width ?? $this->imageSize[0],
'height' => $this->height ?? $this->imageSize[1]
]);
}
|
php
|
{
"resource": ""
}
|
q240445
|
GD.createEmptyCanvas
|
train
|
protected function createEmptyCanvas($width, $height, $rgb, $real)
{
$width = $this->width ?? $width;
$height = $this->height ?? $height;
$rgb = $this->color ?? $rgb;
$real = $this->real ?? $real;
$this->imageSize = [$width, $height];
if( $real === false )
{
$this->canvas = imagecreate($width, $height);
}
else
{
$this->canvas = imagecreatetruecolor($width, $height);
}
if( ! empty($rgb) )
{
$this->allocate($rgb);
}
}
|
php
|
{
"resource": ""
}
|
q240446
|
GD.alignImageWatermark
|
train
|
protected function alignImageWatermark($source)
{
if( is_string($this->target ?? NULL) )
{
$size = getimagesize($source);
$this->width = $this->width ?? $size[0];
$this->height = $this->height ?? $size[1];
$return = WatermarkImageAligner::align($this->target, $this->width, $this->height, $this->imageSize[0], $this->imageSize[1], $this->margin ?? 0);
$this->target = $return;
if( isset($this->x) ) $this->source[0] = $this->x;
if( isset($this->y) ) $this->source[1] = $this->y;
}
}
|
php
|
{
"resource": ""
}
|
q240447
|
GD.getImageColor
|
train
|
public function getImageColor($rgb, $function)
{
$rgb = explode('|', $rgb);
$red = $rgb[0] ?? 0;
$green = $rgb[1] ?? 0;
$blue = $rgb[2] ?? 0;
$alpha = $rgb[3] ?? 0;
return $function($this->canvas, $red, $green, $blue, $alpha);
}
|
php
|
{
"resource": ""
}
|
q240448
|
GD.defaultVariables
|
train
|
protected function defaultVariables()
{
$this->canvas = NULL;
$this->save = NULL;
$this->output = true;
$this->quality = NULL;
}
|
php
|
{
"resource": ""
}
|
q240449
|
QueryBuilder.select
|
train
|
public function select($fields = '*')
{
$query = new Query\SelectQuery();
if ($this->pdo) {
$query->setPDO($this->pdo);
}
return $query->select($fields);
}
|
php
|
{
"resource": ""
}
|
q240450
|
QueryBuilder.insert
|
train
|
public function insert(array $values)
{
$query = new Query\InsertQuery();
if ($this->pdo) {
$query->setPDO($this->pdo);
}
return $query->values($values);
}
|
php
|
{
"resource": ""
}
|
q240451
|
QueryBuilder.update
|
train
|
public function update($table)
{
$query = new Query\UpdateQuery();
if ($this->pdo) {
$query->setPDO($this->pdo);
}
return $query->table($table);
}
|
php
|
{
"resource": ""
}
|
q240452
|
QueryBuilder.delete
|
train
|
public function delete($from)
{
$query = new Query\DeleteQuery();
if ($this->pdo) {
$query->setPDO($this->pdo);
}
return $query->from($from);
}
|
php
|
{
"resource": ""
}
|
q240453
|
QueryBuilder.raw
|
train
|
public function raw($sql)
{
$query = new Query\SqlQuery();
if ($this->pdo) {
$query->setPDO($this->pdo);
}
return $query->raw($sql);
}
|
php
|
{
"resource": ""
}
|
q240454
|
Database_Query_Builder_Select.select
|
train
|
public function select($columns = null)
{
$columns = func_get_args();
$this->_select = array_merge($this->_select, $columns);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240455
|
Database_Query_Builder_Select.select_array
|
train
|
public function select_array(array $columns, $reset = false)
{
$this->_select = $reset ? $columns : array_merge($this->_select, $columns);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240456
|
Database_Query_Builder_Select.from
|
train
|
public function from($tables)
{
$tables = func_get_args();
$this->_from = array_merge($this->_from, $tables);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240457
|
Database_Query_Builder_Select.and_on
|
train
|
public function and_on($c1, $op, $c2)
{
$this->_last_join->and_on($c1, $op, $c2);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240458
|
Database_Query_Builder_Select.or_on
|
train
|
public function or_on($c1, $op, $c2)
{
$this->_last_join->or_on($c1, $op, $c2);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240459
|
Version.compare
|
train
|
public static function compare(Version $a, Version $b)
{
$aValues = $a->numeric();
$bValues = $b->numeric();
foreach (array_keys(self::$ordinality) as $key) {
$aVal = $aValues[$key];
$bVal = $bValues[$key];
if ($aVal < $bVal) {
return -1;
} elseif ($aVal > $bVal) {
return 1;
}
}
return 0;
}
|
php
|
{
"resource": ""
}
|
q240460
|
Version.increment
|
train
|
public function increment($part)
{
foreach (array_reverse(self::$ordinality) as $currentPart) {
if ($currentPart === $part) {
switch ($part) {
case self::STABILITY:
$this->set(
$currentPart,
self::$stabilities[
array_search(
$this->get($currentPart),
self::$stabilities
) +1
]
);
break;
default:
$this->set($currentPart, $this->get($currentPart) +1);
break;
}
break;
} else {
switch ($currentPart) {
case self::STABILITY_NO:
$this->set($currentPart, null);
break;
case self::STABILITY:
$this->set($currentPart, 'dev');
break;
default:
$this->set($currentPart, '0');
}
}
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q240461
|
Version.set
|
train
|
private function set($part, $value)
{
if (null === $value && isset(self::$defaults[$part])) {
$value = self::$defaults[$part];
}
$this->parts[$part] = $value;
return $this;
}
|
php
|
{
"resource": ""
}
|
q240462
|
Version.format
|
train
|
public function format()
{
$ret = '';
foreach (self::$formats as $key => $format) {
$value = $this->get($key);
// -stable is not added to the version, it is implied
if ($key == self::STABILITY && $value == end(self::$stabilities)) {
break;
}
$ret .= sprintf($format, $value);
// -dev has no stability increments
if ($key == self::STABILITY && $value == self::$stabilities[0]) {
break;
}
}
return $ret;
}
|
php
|
{
"resource": ""
}
|
q240463
|
Version.numeric
|
train
|
public function numeric()
{
$ret = array();
foreach (self::$ordinality as $part) {
if ($part === self::STABILITY) {
$ret[]= array_search($this->get($part), self::$stabilities);
} else {
$ret[]= $this->get($part);
}
}
return $ret;
}
|
php
|
{
"resource": ""
}
|
q240464
|
ResponseBuilder.setBody
|
train
|
public function setBody($responseBody)
{
if($this->initialized !== true)
throw new \Exception('ResponseBuilder not initialized. Call init() first');
// TODO make sure, this can only be a string or a BaseObject
// TODO throws an error when not valid JSON - how to deal with this?
if(gettype($responseBody) != 'string')
$responseBody = $responseBody->getJSONString();
$this->sonicResponse->setBody($responseBody);
return $this;
}
|
php
|
{
"resource": ""
}
|
q240465
|
Inspector.checkFilter
|
train
|
public static function checkFilter($comment_string)
{
//define the regular expression pattern to use for string matching
$pattern = "#(@[a-zA-Z]+\s*[a-zA-Z0-9, ()_].*)#";
//perform the regular expression on the string provided
preg_match_all($pattern, $comment_string, $matches, PREG_PATTERN_ORDER);
//get the meta elements in array
$meta_data_array = $matches[0];
//check meta data was found
if(count($meta_data_array) > 0){
//set array for before and after filters
$beforeFilters = array();
$afterFilters = array();
//loop through array getting before and after filters
foreach($meta_data_array as $key => $value){
//get before filter
if(strpos($value, "@before") !== false){
$strb = explode(' ', trim($value)); $strb = self::clean($strb);
(isset($strb[1])) ? $beforeFilters[] = $strb[1] : '';
(isset($strb[2])) ? $beforeFilters[] = $strb[2] : '';
}
//get after filters
if(strpos($value,"@after") !== false){
$stra = explode(' ', trim($value)); $stra = self::clean($stra);
(isset($stra[1])) ? $afterFilters[] = $stra[1] : '';
(isset($stra[2])) ? $afterFilters[] = $stra[2] : '';
}
}
//define the array to return
$return = array();
//check if before and after filters were empty
if( ! empty($beforeFilters)) $return['before'] = $beforeFilters;
if( ! empty($afterFilters)) $return['after'] = $afterFilters;
return $return;
}
//no meta data found, return false
else return false;
}
|
php
|
{
"resource": ""
}
|
q240466
|
MemoryCache.get
|
train
|
public function get($key)
{
if (!isset($this->records[$key])) {
return null;
}
$record = $this->records[$key];
if ($record['expire'] < time()) {
unset($this->records[$key]);
return null;
}
return $record['nodes'];
}
|
php
|
{
"resource": ""
}
|
q240467
|
MemoryCache.expires
|
train
|
public function expires($key)
{
if (!isset($this->records[$key])) {
return 0;
}
return (int) max(0, $this->records[$key]['expire'] - time());
}
|
php
|
{
"resource": ""
}
|
q240468
|
FlashMessenger.init
|
train
|
public function init()
{
$container = $this->getSessionContainer();
//get the messages and data that was set in the previous request
//clear them afterwards
if (isset($container->messages)) {
$this->messages = $container->messages;
unset($container->messages);
}
if (isset($container->data)) {
$this->data = $container->data;
unset($container->data);
}
}
|
php
|
{
"resource": ""
}
|
q240469
|
FlashMessenger.addMessage
|
train
|
public function addMessage(string $type, $message, string $channel = FlashMessengerInterface::DEFAULT_CHANNEL)
{
if (!is_string($message) && !is_array($message)) {
throw new InvalidArgumentException('Flash message must be a string or an array of strings');
}
$container = $this->getSessionContainer();
if (!isset($container->messages)) {
$container->messages = [];
}
if (!isset($container->messages[$channel])) {
$container->messages[$channel] = [];
}
if (!isset($container->messages[$channel][$type])) {
$container->messages[$channel][$type] = [];
}
$message = (array)$message;
foreach ($message as $msg) {
if (!is_string($msg)) {
throw new InvalidArgumentException('Flash message must be a string or an array of strings');
}
$container->messages[$channel][$type][] = $msg;
}
}
|
php
|
{
"resource": ""
}
|
q240470
|
Reporting.report
|
train
|
public function report() : ReportingResult
{
$sets = [];
$errors = [];
foreach ($this->collectors as $collector) {
$sets[] = $set = $collector->flush();
$errors[] = $this->reportOn($set);
}
return new ReportingResult($sets, array_merge(...$errors));
}
|
php
|
{
"resource": ""
}
|
q240471
|
Reporting.reportOn
|
train
|
private function reportOn(MetricSet $set) : array
{
$errors = [];
foreach ($this->reporters as $reporter) {
try {
$reporter->reportOn($set);
} catch (\Exception $e) {
$errors[] = $e;
}
}
return $errors;
}
|
php
|
{
"resource": ""
}
|
q240472
|
Zend_Loader_ClassMapAutoloader.registerAutoloadMap
|
train
|
public function registerAutoloadMap($map)
{
if (is_string($map)) {
$location = $map;
if ($this === ($map = $this->loadMapFromFile($location))) {
return $this;
}
}
if (!is_array($map)) {
throw new Zend_Loader_Exception_InvalidArgumentException('Map file provided does not return a map');
}
$this->map = array_merge($this->map, $map);
if (isset($location)) {
$this->mapsLoaded[] = $location;
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q240473
|
Zend_Loader_ClassMapAutoloader.registerAutoloadMaps
|
train
|
public function registerAutoloadMaps($locations)
{
if (!is_array($locations) && !($locations instanceof Traversable)) {
throw new Zend_Loader_Exception_InvalidArgumentException('Map list must be an array or implement Traversable');
}
foreach ($locations as $location) {
$this->registerAutoloadMap($location);
}
return $this;
}
|
php
|
{
"resource": ""
}
|
q240474
|
Zend_Loader_ClassMapAutoloader.register
|
train
|
public function register()
{
if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
spl_autoload_register(array($this, 'autoload'), true, true);
} else {
spl_autoload_register(array($this, 'autoload'), true);
}
}
|
php
|
{
"resource": ""
}
|
q240475
|
Zend_Loader_ClassMapAutoloader.loadMapFromFile
|
train
|
protected function loadMapFromFile($location)
{
if (!file_exists($location)) {
throw new Zend_Loader_Exception_InvalidArgumentException('Map file provided does not exist');
}
if (!$path = self::realPharPath($location)) {
$path = realpath($location);
}
if (in_array($path, $this->mapsLoaded)) {
// Already loaded this map
return $this;
}
$map = include $path;
return $map;
}
|
php
|
{
"resource": ""
}
|
q240476
|
Zend_Loader_ClassMapAutoloader.resolvePharParentPath
|
train
|
public static function resolvePharParentPath($value, $key, &$parts)
{
if ($value !== '...') {
return;
}
unset($parts[$key], $parts[$key-1]);
$parts = array_values($parts);
}
|
php
|
{
"resource": ""
}
|
q240477
|
Callback.setCallback
|
train
|
public function setCallback(callable $callback, array $params = [])
{
if ($this->hasCallback()) {
throw new ArchException('Callback already defined');
}
$this->callback = $callback;
$this->callbackParams = $params;
return $this;
}
|
php
|
{
"resource": ""
}
|
q240478
|
GetTermTypeRendererContainerTrait._getTermTypeRenderer
|
train
|
protected function _getTermTypeRenderer($termType, $context = null)
{
$container = $this->_getTermTypeRendererContainer();
return $this->_containerGet($container, $termType);
}
|
php
|
{
"resource": ""
}
|
q240479
|
Loader.ensureFileIsReadable
|
train
|
protected function ensureFileIsReadable()
{
$filePath = $this->filePath;
if (!is_readable($filePath) || !is_file($filePath)) {
throw new InvalidArgumentException(sprintf(
'Dotenv: Environment file .env not found or not readable. '.
'Create file with your environment settings at %s',
$filePath
));
}
}
|
php
|
{
"resource": ""
}
|
q240480
|
Loader.normaliseEnvironmentVariable
|
train
|
protected function normaliseEnvironmentVariable($name, $value)
{
list($name, $value) = $this->splitCompoundStringIntoParts($name, $value);
return array($name, $value);
}
|
php
|
{
"resource": ""
}
|
q240481
|
Loader.readLinesFromFile
|
train
|
protected function readLinesFromFile($filePath)
{
// Read file into an array of lines with auto-detected line endings
$autodetect = ini_get('auto_detect_line_endings');
ini_set('auto_detect_line_endings', '1');
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
ini_set('auto_detect_line_endings', $autodetect);
return $lines;
}
|
php
|
{
"resource": ""
}
|
q240482
|
File.getName
|
train
|
public function getName( $suffix = NULL ) : string
{
$name = $suffix ? basename( $this->path, $suffix ) : basename( $this->path );
return $name;
}
|
php
|
{
"resource": ""
}
|
q240483
|
File.putContents
|
train
|
public function putContents( $contents, $ex_lock = false ) : int
{
$flags = $ex_lock ? LOCK_EX : 0;
$res = file_put_contents( $this->path, $contents, $flags );
if ($res === FALSE){
throw new FileOutputException($this);
}
return $res;
}
|
php
|
{
"resource": ""
}
|
q240484
|
File.rename
|
train
|
public function rename( $new_file )
{
$res = @rename( $this->path, $new_file->getPath() );
if ( $res === FALSE ){
throw new FileRenameException($this, $new_file);
}
}
|
php
|
{
"resource": ""
}
|
q240485
|
File.makeDirectory
|
train
|
public function makeDirectory( $mode = NULL )
{
$mode = $mode ? $mode : 0777;
if ( file_exists($this->path) ){
if ( is_file($this->path) ){
throw new MakeDirectoryException($this);
}
return;
}
$parent_dir = $this->getParent();
if ( !$parent_dir->exists() ){
$parent_dir->makeDirectory( $mode );
}
$res = @mkdir( $this->path, $mode );
if ( $res === FALSE ){
throw new MakeDirectoryException($this);
}
}
|
php
|
{
"resource": ""
}
|
q240486
|
File.listFiles
|
train
|
public function listFiles( $filter = NULL ) : array
{
$path = $this->path;
if ( !file_exists($path) ) return NULL;
if ( !is_readable($path) ) return NULL;
if ( is_file($path) ) return NULL;
$files = array();
$dh = opendir($path);
while( ($file_name = readdir($dh)) !== FALSE ){
if ( $file_name === '.' || $file_name === '..' ){
continue;
}
$file = new File( $file_name, $this );
if ( $filter ){
if ( $filter instanceof FileFilterInterface ){
if ( $filter->accept($file) ){
$files[] = $file;
}
}
else if ( is_callable($filter) ){
if ( $filter($file) ){
$files[] = $file;
}
}
}
else{
$files[] = $file;
}
}
return $files;
}
|
php
|
{
"resource": ""
}
|
q240487
|
File.touch
|
train
|
public function touch( $time = NULL ) : bool
{
if ( $time === NULL ){
return touch( $this->path );
}
return touch( $this->path, $time );
}
|
php
|
{
"resource": ""
}
|
q240488
|
PermissionVoter.supportsAnyAttribute
|
train
|
private function supportsAnyAttribute($attributes)
{
foreach ($attributes as $attribute) {
if ($this->supportsAttribute($attribute)) {
return true;
}
}
return false;
}
|
php
|
{
"resource": ""
}
|
q240489
|
PermissionVoter.getRouteRoles
|
train
|
private function getRouteRoles()
{
$router = $this->router;
$cache = $this->getConfigCacheFactory()->cache(
$this->options['cache_dir'].'/tenside_roles.php',
function (ConfigCacheInterface $cache) use ($router) {
$routes = $router->getRouteCollection();
$roles = [];
foreach ($routes as $name => $route) {
if ($requiredRole = $route->getOption('required_role')) {
$roles[$name] = $requiredRole;
}
}
$cache->write('<?php return ' . var_export($roles, true) . ';', $routes->getResources());
}
);
return require_once $cache->getPath();
}
|
php
|
{
"resource": ""
}
|
q240490
|
Raw.createNew
|
train
|
public function createNew(
int $sourceId,
string $collectionName,
array $data
) : array {
return $this->sendPost(
sprintf('/profiles/%s/raw', $this->userName),
[],
[
'source_id' => $sourceId,
'collection' => $collectionName,
'data' => $data
]
);
}
|
php
|
{
"resource": ""
}
|
q240491
|
Raw.upsertOne
|
train
|
public function upsertOne(
int $sourceId,
string $collectionName,
array $data
) : array {
return $this->sendPut(
sprintf('/profiles/%s/raw', $this->userName),
[],
[
'source_id' => $sourceId,
'collection' => $collectionName,
'data' => $data
]
);
}
|
php
|
{
"resource": ""
}
|
q240492
|
ClientBuilder.get
|
train
|
public function get($name, $throwAway = false)
{
$client = parent::get($name, $throwAway);
if ($client instanceof ApiKeyClientInterface) {
$client->setApiKey(self::$apiKey);
}
return $client;
}
|
php
|
{
"resource": ""
}
|
q240493
|
AdminProductItemFieldDataController.showAction
|
train
|
public function showAction(ProductItemFieldData $productitemfielddata)
{
$editForm = $this->createForm($this->get("amulen.shop.form.product.item.field.data"), $productitemfielddata, array(
'action' => $this->generateUrl('admin_productitemfielddata_update', array('id' => $productitemfielddata->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($productitemfielddata->getId(), 'admin_productitemfielddata_delete');
return array(
'productitemfielddata' => $productitemfielddata, 'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q240494
|
AdminProductItemFieldDataController.newAction
|
train
|
public function newAction()
{
$productitemfielddata = new ProductItemFieldData();
$form = $this->createForm($this->get("amulen.shop.form.product.item.field.data"), $productitemfielddata);
return array(
'productitemfielddata' => $productitemfielddata,
'form' => $form->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q240495
|
AdminProductItemFieldDataController.createAction
|
train
|
public function createAction(Request $request)
{
$productitemfielddata = new ProductItemFieldData();
$form = $this->createForm($this->get("amulen.shop.form.product.item.field.data"), $productitemfielddata);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($productitemfielddata);
$em->flush();
return $this->redirect($this->generateUrl('admin_productitemfielddata_show', array('id' => $productitemfielddata->getId())));
}
return array(
'productitemfielddata' => $productitemfielddata,
'form' => $form->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q240496
|
AdminProductItemFieldDataController.updateAction
|
train
|
public function updateAction(ProductItemFieldData $productitemfielddata, Request $request)
{
$editForm = $this->createForm($this->get("amulen.shop.form.product.item.field.data"), $productitemfielddata, array(
'action' => $this->generateUrl('admin_productitemfielddata_update', array('id' => $productitemfielddata->getid())),
'method' => 'PUT',
));
if ($editForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('admin_productitemfielddata_show', array('id' => $productitemfielddata->getId())));
}
$deleteForm = $this->createDeleteForm($productitemfielddata->getId(), 'admin_productitemfielddata_delete');
return array(
'productitemfielddata' => $productitemfielddata,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
}
|
php
|
{
"resource": ""
}
|
q240497
|
Router.route
|
train
|
public function route()
{
$batch = array();
foreach ($this->request->getCalls() as $call) {
$batch[] = $this->dispatch($call);
}
return $this->response->encode($batch);
}
|
php
|
{
"resource": ""
}
|
q240498
|
Router.dispatch
|
train
|
private function dispatch($call)
{
$path = $call->getAction();
$method = $call->getMethod();
$matches = preg_split('/(?=[A-Z])/',$path);
$route = strtolower(implode('/', $matches));
$route .= "/".$method;
$request = $this->app['request'];
$files = $this->fixFiles($request->files->all());
// create the route request
$routeRequest = Request::create($route, 'POST', $call->getData(), $request->cookies->all(), $files, $request->server->all());
if ('form' == $this->request->getCallType()) {
$result = $this->app->handle($routeRequest, HttpKernelInterface::SUB_REQUEST);
$response = $call->getResponse($result);
} else {
try{
$result = $this->app->handle($routeRequest, HttpKernelInterface::SUB_REQUEST);
$response = $call->getResponse($result);
}catch(\Exception $e){
$response = $call->getException($e);
}
}
return $response;
}
|
php
|
{
"resource": ""
}
|
q240499
|
Gdn_Session.CheckPermission
|
train
|
public function CheckPermission($Permission, $FullMatch = TRUE, $JunctionTable = '', $JunctionID = '') {
if (is_object($this->User)) {
if ($this->User->Banned || GetValue('Deleted', $this->User))
return FALSE;
elseif ($this->User->Admin)
return TRUE;
}
// Allow wildcard permission checks (e.g. 'any' Category)
if ($JunctionID == 'any')
$JunctionID = '';
$Permissions = $this->GetPermissions();
if ($JunctionTable && !C('Garden.Permissions.Disabled.'.$JunctionTable)) {
// Junction permission ($Permissions[PermissionName] = array(JunctionIDs))
if (is_array($Permission)) {
foreach ($Permission as $PermissionName) {
if($this->CheckPermission($PermissionName, FALSE, $JunctionTable, $JunctionID)) {
if(!$FullMatch)
return TRUE;
} else {
if($FullMatch)
return FALSE;
}
}
return TRUE;
} else {
if ($JunctionID !== '') {
$Result = array_key_exists($Permission, $Permissions)
&& is_array($Permissions[$Permission])
&& in_array($JunctionID, $Permissions[$Permission]);
} else {
$Result = array_key_exists($Permission, $Permissions)
&& is_array($Permissions[$Permission])
&& count($Permissions[$Permission]);
}
return $Result;
}
} else {
// Non-junction permission ($Permissions = array(PermissionNames))
if (is_array($Permission)) {
return ArrayInArray($Permission, $Permissions, $FullMatch);
} else {
return in_array($Permission, $Permissions) || array_key_exists($Permission, $Permissions);
}
}
}
|
php
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.