_id stringlengths 2 7 | title stringlengths 3 151 | partition stringclasses 3
values | text stringlengths 83 13k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q240600 | LongLog.setJobName | train | public function setJobName($name)
{
if (!is_string($name)) {
throw new InvalidArgumentException('Job name must be a string');
}
$name = trim($name);
$strlen = mb_strlen($name);
if (!$strlen) {
throw new InvalidArgumentException('Job name cannot be em... | php | {
"resource": ""
} |
q240601 | LongLog.setPayload | train | public function setPayload($data)
{
if (!is_string($data)) {
if (is_array($data)) {
$data = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} else {
$data = serialize($data);
}
}
$maxLength = 255;
... | php | {
"resource": ""
} |
q240602 | LongLog.setDuration | train | public function setDuration($seconds)
{
$seconds = round($seconds, 3);
if ($seconds < 0 || $seconds > 999999.999) {
throw new InvalidArgumentException('Duration seconds must be in range 0-999999.999');
}
$this->duration = $seconds;
return $this;
} | php | {
"resource": ""
} |
q240603 | FloatObject.round | train | public function round(int $precision = 0, ?RoundingMode $roundingMode = null): FloatObject
{
if ($roundingMode === null) {
$roundingMode = RoundingMode::HALF_UP();
}
return new static((float) round($this->value, $precision, $roundingMode->value()));
} | php | {
"resource": ""
} |
q240604 | QueryBuilder.setModel | train | public function setModel($model)
{
$this->model = $model;
$this->from($this->model->metableTable() . ' AS m');
if ($this->model->metableTableSoftDeletes()) {
$this->whereNull('m.' . $this->model->getDeletedAtColumn());
}
return $this;
} | php | {
"resource": ""
} |
q240605 | QueryBuilder.whereAnyMetaId | train | public function whereAnyMetaId(array $metas)
{
$filters = array();
foreach ($metas as $meta => $data) {
$value = is_array($data) ? Arr::get($data, 0) : $data;
$operator = is_array($data) ? Arr::get($data, 1, '=') : '=';
$filters[] = array('id' => $meta, 'value' => $value, 'operator' => $operator);
... | php | {
"resource": ""
} |
q240606 | Encrypt.encode | train | public function encode($string)
{
if (empty($string) || empty($this->key)) {
throw new \Exception("Can not encrypt with an empty key or no data");
return false;
}
$publicKey = $this->generateKey($string);
$privateKey = $this->key;
//Get a SHA-1 has... | php | {
"resource": ""
} |
q240607 | Encrypt.generateKey | train | public static function generateKey($txt, $length = null)
{
date_default_timezone_set('UTC');
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
$maxlength = (empty($length) || (int)$length > strlen($possible)) ? strlen($possible) : (int)$length;
$random = "";
$... | php | {
"resource": ""
} |
q240608 | Encrypt.decode | train | public function decode($encrypted)
{
//$cipher_all = explode("/", $cipher_in);
//$cipher = $cipher_all[0];
$blocks = explode("|x", $encrypted);
$delimiter = array_search("::", $blocks);
$cipherStream = array_slice($blocks, 0, (int)$delimiter);
unset($blocks[(int... | php | {
"resource": ""
} |
q240609 | Udp.send | train | public function send(MessageInterface $message, $target)
{
$msg = $message->getMessageString();
if (strpos($target, ':')) {
list($host, $port) = explode(':', $target);
} else {
$host = $target;
$port = self::DEFAULT_UDP_PORT;
}
$sock = soc... | php | {
"resource": ""
} |
q240610 | OptimizeJsTask.getMainJsFileName | train | private static function getMainJsFileName(string $realPath): string
{
$parts = pathinfo($realPath);
return $parts['dirname'].'/'.$parts['filename'].'.main.'.$parts['extension'];
} | php | {
"resource": ""
} |
q240611 | OptimizeJsTask.minimizeResource | train | protected function minimizeResource(string $resource, ?string $fullPathName): string
{
list($std_out, $std_err) = $this->runProcess($this->minifyCommand, $resource);
if ($std_err) $this->logInfo($std_err);
return $std_out;
} | php | {
"resource": ""
} |
q240612 | OptimizeJsTask.combine | train | private function combine(string $realPath): array
{
$config = $this->extractConfigFromMainFile(self::getMainJsFileName($realPath));
// Create temporary file with config.
$tmp_name1 = tempnam('.', 'abc_');
$handle = fopen($tmp_name1, 'w');
fwrite($handle, $config);
fclose($handle);
// ... | php | {
"resource": ""
} |
q240613 | OptimizeJsTask.execCommand | train | private function execCommand(array $command): array
{
$this->logVerbose('Execute: %s', implode(' ', $command));
list($output, $ret) = ProgramExecution::exec1($command, null);
if ($ret!=0)
{
foreach ($output as $line)
{
$this->logInfo($line);
}
$this->logError("Error exe... | php | {
"resource": ""
} |
q240614 | OptimizeJsTask.extractPaths | train | private function extractPaths(string $mainJsFile): array
{
$command = [$this->nodePath,
__DIR__.'/../../lib/extract_config.js',
$mainJsFile];
$output = $this->execCommand($command);
$config = json_decode(implode(PHP_EOL, $output), true);
return [$config['baseUrl'], $... | php | {
"resource": ""
} |
q240615 | OptimizeJsTask.getFullPathFromClassName | train | private function getFullPathFromClassName(string $className): string
{
$file_name = str_replace('\\', '/', $className).$this->extension;
$full_path = $this->resourceDirFullPath.'/'.$file_name;
return $full_path;
} | php | {
"resource": ""
} |
q240616 | OptimizeJsTask.getFullPathFromNamespace | train | private function getFullPathFromNamespace(string $namespace): string
{
$file_name = $namespace.$this->extension;
$full_path = $this->resourceDirFullPath.'/'.$file_name;
return $full_path;
} | php | {
"resource": ""
} |
q240617 | OptimizeJsTask.getMainWithHashedPaths | train | private function getMainWithHashedPaths(string $realPath): string
{
$main_js_file = self::getMainJsFileName($realPath);
// Read the main file.
$js = file_get_contents($main_js_file);
if ($js===false) $this->logError("Unable to read file '%s'.", $realPath);
// Extract paths from main.
preg_mat... | php | {
"resource": ""
} |
q240618 | OptimizeJsTask.getNamespaceFromResourceFilename | train | private function getNamespaceFromResourceFilename(string $resourceFilename): string
{
$name = $this->getPathInResources($resourceFilename);
// Remove resource dir from name.
$len = strlen(trim($this->resourceDir, '/'));
if ($len>0)
{
$name = substr($name, $len + 2);
}
// Remove ext... | php | {
"resource": ""
} |
q240619 | Form.FetchFields | train | private function FetchFields($parent)
{
$child= $this->tree->FirstChildOf($parent);
while ($child)
{
$this->HandleField($child);
$this->FetchFields($child);
$child = $this->tree->NextOf($child);
}
} | php | {
"resource": ""
} |
q240620 | Form.SaveToTable | train | private function SaveToTable($table)
{
$sql = Access::SqlBuilder();
$fields = array();
$setList = null;
foreach ($this->Elements()->GetElements() as $element)
{
$this->HandleElement($table, $element, $fields, $setList);
}
if ($setList)
{
... | php | {
"resource": ""
} |
q240621 | FormHelper.prepareSentryPermissionInput | train | public function prepareSentryPermissionInput(array &$input, $operation, $field_name = "permissions") {
$input[$field_name] = isset($input[$field_name]) ? [$input[$field_name] => $operation] : '';
} | php | {
"resource": ""
} |
q240622 | Bitflag.jsonSerialize | train | public function jsonSerialize()
{
$ret = new StdClass;
foreach ($this->map as $key => $value) {
$ret->$key = (bool)($this->source & $value);
}
return $ret;
} | php | {
"resource": ""
} |
q240623 | Zend_Loader_StandardAutoloader.autoload | train | public function autoload($class)
{
$isFallback = $this->isFallbackAutoloader();
if (false !== strpos($class, self::NS_SEPARATOR)) {
if ($this->loadClass($class, self::LOAD_NS)) {
return $class;
} elseif ($isFallback) {
return $this->loadClass($... | php | {
"resource": ""
} |
q240624 | Zend_Loader_StandardAutoloader.transformClassNameToFilename | train | protected function transformClassNameToFilename($class, $directory)
{
// $class may contain a namespace portion, in which case we need
// to preserve any underscores in that portion.
$matches = array();
preg_match('/(?P<namespace>.+\\\)?(?P<class>[^\\\]+$)/', $class, $matches);
... | php | {
"resource": ""
} |
q240625 | Zend_Loader_StandardAutoloader.normalizeDirectory | train | protected function normalizeDirectory($directory)
{
$last = $directory[strlen($directory) - 1];
if (in_array($last, array('/', '\\'))) {
$directory[strlen($directory) - 1] = DIRECTORY_SEPARATOR;
return $directory;
}
$directory .= DIRECTORY_SEPARATOR;
r... | php | {
"resource": ""
} |
q240626 | ConfigBuilder.addResource | train | public function addResource($resource, $prefix = null)
{
$this->resources[] = [$resource, $prefix, true];
return $this;
} | php | {
"resource": ""
} |
q240627 | ConfigBuilder.addOptionalResource | train | public function addOptionalResource($resource, $prefix = null)
{
$this->resources[] = [$resource, $prefix, false];
return $this;
} | php | {
"resource": ""
} |
q240628 | ConfigBuilder.loadResource | train | protected function loadResource($resource, $required)
{
foreach ($this->loaders as $loader) {
if (!$loader->supports($resource)) {
continue;
}
try {
return $loader->load($resource);
} catch (ResourceNotFoundException $e) {
... | php | {
"resource": ""
} |
q240629 | ConfigBuilder.getConfig | train | public function getConfig(Schema $schema = null)
{
if (!$schema) {
$schema = new Schema();
}
$config = new Config();
foreach ($this->resources as $resource) {
$values = $this->loadResource($resource[0], $resource[2]);
if (is_string($prefix = $res... | php | {
"resource": ""
} |
q240630 | View.templateFile | train | private function templateFile($name)
{
$filename = $this->viewPath . '/' . str_replace('.', DIRECTORY_SEPARATOR, $name) . '.blade.php';
if (file_exists($filename)) {
return $filename;
}
if (self::$manifest === null) {
if (file_exists($this->pluginManifestOfVi... | php | {
"resource": ""
} |
q240631 | View.isCacheUpToDate | train | private function isCacheUpToDate($cachedFile, $templateFile)
{
if (!file_exists($cachedFile)) {
return false;
}
$cacheTime = filemtime($cachedFile);
$templTime = filemtime($templateFile);
return $cacheTime == $templTime;
} | php | {
"resource": ""
} |
q240632 | View.saveFile | train | private function saveFile($file, $content, $time)
{
// create directory if not exists
if (!is_dir($dir = dirname($file))) {
// @codeCoverageIgnoreStart
if (!make_dir($dir, 0775)) {
throw new RuntimeException(sprintf('View Template Engine was not able to create... | php | {
"resource": ""
} |
q240633 | View.storeSection | train | private function storeSection($section, $content)
{
if (!isset($this->scope->sections[$section])) {
$this->scope->sections[$section] = $content;
}
} | php | {
"resource": ""
} |
q240634 | FileAccessException.Read | train | public static function Read(
string $file, string $message = null, int $code = \E_USER_ERROR, \Throwable $previous = null )
: FileAccessException
{
return new FileAccessException (
$file,
FileAccessException::ACCESS_READ,
$message,
$code,
$previous
)... | php | {
"resource": ""
} |
q240635 | FileAccessException.Write | train | public static function Write(
string $file, string $message = null, int $code = \E_USER_ERROR, \Throwable $previous = null )
: FileAccessException
{
return new FileAccessException (
$file,
FileAccessException::ACCESS_WRITE,
$message,
$code,
$previous
... | php | {
"resource": ""
} |
q240636 | MbAsset.runAssets | train | public function runAssets($pageSlug, $isShortcode = false)
{
$cssList = $this->css;
$jsList = $this->js;
MbWPActionHook::addActionCallback($this->getActionEnqueue(), function () use ($pageSlug, $cssList, $jsList) {
foreach ($cssList as $i => $css) {
wp_enqueue_st... | php | {
"resource": ""
} |
q240637 | MbAsset.autoEnqueue | train | protected function autoEnqueue()
{
$request = MocaBonita::getInstance()->getMbRequest();
if ($request->isLoginPage()) {
$this->actionEnqueue = "login_enqueue_scripts";
} elseif ($request->isAdmin()) {
$this->actionEnqueue = "admin_enqueue_scripts";
} else {
... | php | {
"resource": ""
} |
q240638 | MbAsset.setActionEnqueue | train | public function setActionEnqueue($typePage)
{
switch ($typePage) {
case 'admin' :
$this->actionEnqueue = "admin_enqueue_scripts";
break;
case 'login' :
$this->actionEnqueue = "login_enqueue_scripts";
break;
d... | php | {
"resource": ""
} |
q240639 | ConnectionFactory.create | train | public function create($type, $host, $port, $database, $user, $password)
{
return new PDO(
sprintf(
'%s:host=%s;port=%s;dbname=%s',
$type,
$host,
$port,
$database
),
$user,
$passwo... | php | {
"resource": ""
} |
q240640 | AbstractRequest.addHeaders | train | public function addHeaders(array $headers)
{
foreach ($headers as $key => $value) {
$header = NULL;
//Handle Array of String based Headers
if (is_numeric($key) && strpos($value,":") !== FALSE) {
$arr = explode(":",$value,2);
if (count($arr... | php | {
"resource": ""
} |
q240641 | AbstractRequest.compileOptions | train | private function compileOptions(){
$this->CurlOptions = array();
$this->configureHTTPMethod($this->method);
$this->configureUrl($this->url);
$this->configureBody($this->body);
$this->configureHeaders($this->headers);
$this->configureOptions($this->options);
return... | php | {
"resource": ""
} |
q240642 | AbstractRequest.configureHTTPMethod | train | protected function configureHTTPMethod($method)
{
switch ($method) {
case self::HTTP_GET:
break;
case self::HTTP_POST:
return $this->addCurlOption(CURLOPT_POST, TRUE);
default:
return $this->addCurlOption(CURLOPT_CUSTOMREQUE... | php | {
"resource": ""
} |
q240643 | AbstractRequest.configureHeaders | train | protected function configureHeaders(array $headers){
$configuredHeaders = array();
foreach($headers as $header => $value){
$configuredHeaders[] = "$header: $value";
}
return $this->addCurlOption(CURLOPT_HTTPHEADER, $configuredHeaders);
} | php | {
"resource": ""
} |
q240644 | AbstractRequest.configureBody | train | protected function configureBody($body){
$upload = $this->getUpload();
switch ($this->method) {
case self::HTTP_GET:
if (!$upload){
if (is_array($body) || is_object($body)){
$queryParams = http_build_query($body);
... | php | {
"resource": ""
} |
q240645 | AbstractRequest.init | train | protected function init()
{
$this->setMethod(static::$_DEFAULT_HTTP_METHOD);
$this->setHeaders(static::$_DEFAULT_HEADERS);
$this->setOptions(static::$_DEFAULT_OPTIONS);
$this->body = NULL;
$this->error = NULL;
$this->status = self::STATUS_INIT;
if (self::$_AUT... | php | {
"resource": ""
} |
q240646 | AbstractRequest.configureCurl | train | private function configureCurl()
{
foreach($this->getCurlOptions() as $option => $value){
curl_setopt($this->CurlRequest,$option,$value);
}
return TRUE;
} | php | {
"resource": ""
} |
q240647 | AbstractRequest.executeCurl | train | private function executeCurl()
{
if ($this->initCurl()){
$this->configureCurl();
$this->CurlResponse = curl_exec($this->CurlRequest);
$this->checkForError();
return TRUE;
}
return FALSE;
} | php | {
"resource": ""
} |
q240648 | AbstractRequest.checkForError | train | private function checkForError(){
$curlErrNo = curl_errno($this->CurlRequest);
if ($curlErrNo !== CURLE_OK) {
$this->error = TRUE;
$this->CurlError = array(
'error' => $curlErrNo,
'error_message' => curl_error($this->CurlRequest)
);
... | php | {
"resource": ""
} |
q240649 | GitIgnoreFile.setFile | train | public function setFile($filePath = '.gitignore')
{
$this->fileContent = array();
$this->afterLine = null;
$this->filePath = $filePath;
$this->checkPermissions();
$this->parse();
} | php | {
"resource": ""
} |
q240650 | GitIgnoreFile.setLines | train | public function setLines($lines)
{
if (!is_array($lines)) {
$this->lines = array(
$lines
);
} else {
$this->lines = $lines;
}
return $this;
} | php | {
"resource": ""
} |
q240651 | FileUtils.isAbsolute | train | public static function isAbsolute($path)
{
return ((isset($path[0])
? ($path[0] == '/'
|| (ctype_alpha($path[0]) && ($path[1] == ':')))
: '')
|| (parse_url($path, PHP_URL_SCHEME) === true))
? true
: false;
} | php | {
"resource": ""
} |
q240652 | FileUtils.getMime | train | public static function getMime($file)
{
$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($fileInfo, $file);
return empty($mime) ? : $mime;
} | php | {
"resource": ""
} |
q240653 | TextSprite.render | train | public function render(): Image {
$ftbbox = imageftbbox($this->fontSize, 0, $this->fontFile, $this->text, $this->extraInfo);
$width = max($ftbbox[2] - $ftbbox[6], 1);
$height = max($ftbbox[3] - $ftbbox[7], 1);
// Getting an offset for the first symbol of text
$ftbbox = imageftb... | php | {
"resource": ""
} |
q240654 | TokenBlacklistRepositoryEloquent.check | train | public function check($token)
{
$blacklistedToken = $this->model
->where('user_id', $this->Token->getSubject($token))
->where('expiry', '>', Carbon::now())
->whereToken($token)
->first();
if ($blacklistedToken === null) {
return true;
... | php | {
"resource": ""
} |
q240655 | TokenBlacklistRepositoryEloquent.findByToken | train | public function findByToken($token)
{
$blacklistedToken = $this->model->whereToken($token)->first();
if ($blacklistedToken === null)
{
throw new ModelNotFoundException();
}
return $blacklistedToken->toArray();
} | php | {
"resource": ""
} |
q240656 | TokenBlacklistRepositoryEloquent.findAllExpired | train | public function findAllExpired()
{
$expiredBlacklistedTokens = $this->model->where('expiry', '<', Carbon::now())->get();
return $expiredBlacklistedTokens->toArray();
} | php | {
"resource": ""
} |
q240657 | TokenBlacklistRepositoryEloquent.deleteAllExpired | train | public function deleteAllExpired()
{
$expiredBlacklistedTokens = $this->findAllExpired();
foreach ($expiredBlacklistedTokens as $expiredBlacklistedToken)
{
$this->delete($expiredBlacklistedToken['id']);
}
} | php | {
"resource": ""
} |
q240658 | QueryObject.updateCollection | train | public function updateCollection(EntityChangeEventInterface $event)
{
$collection = $event->getCollection();
if ($collection->getId()) {
$collectionMap = $this->getCollectionsMap();
$collectionMap
->set($collection->getId(), $collection);
}
} | php | {
"resource": ""
} |
q240659 | QueryObject.query | train | protected function query(Select $sql)
{
$cid = $this->getId($sql);
$collection = $this->repository
->getCollectionsMap()
->get($cid, false);
if (false === $collection) {
$collection = $this->getCollection($sql, $cid);
}
return $collection... | php | {
"resource": ""
} |
q240660 | QueryObject.getCollection | train | protected function getCollection(Select $sql, $cid)
{
$this->triggerBeforeSelect(
$sql,
$this->getRepository()->getEntityDescriptor()
);
$data = $this->adapter->query($sql, $sql->getParameters());
$collection = $this->repository->getEntityMapper()
... | php | {
"resource": ""
} |
q240661 | QueryObject.getCollectionsMap | train | protected function getCollectionsMap()
{
if (null == $this->collectionsMap) {
$this->collectionsMap = $this->repository->getCollectionsMap();
}
return $this->collectionsMap;
} | php | {
"resource": ""
} |
q240662 | QueryObject.registerEventsTo | train | protected function registerEventsTo(EntityCollection $collection, $cid)
{
$collection->setId($cid);
$collection->getEmitter()
->addListener(
EntityAdded::ACTION_ADD,
[$this, 'updateCollection']
);
$collection->getEmitter()
-... | php | {
"resource": ""
} |
q240663 | QueryObject.getId | train | protected function getId(Select $query)
{
$str = $query->getQueryString();
$search = array_keys($query->getParameters());
$values = array_values($query->getParameters());
return str_replace($search, $values, $str);
} | php | {
"resource": ""
} |
q240664 | QueryObject.updateIdentityMap | train | protected function updateIdentityMap(EntityCollection $collection)
{
if ($collection->isEmpty()) {
return $this;
}
foreach ($collection as $entity)
{
$this->repository->getIdentityMap()->set($entity);
}
return $this;
} | php | {
"resource": ""
} |
q240665 | SourceRoad.resourcePathMatch | train | protected function resourcePathMatch(File $file) {
$source_dirpath = str_replace('#', '\#', $this->sourceDir->getAbsolutePath());
$source_dirpath = str_replace('[', '\[', $source_dirpath);
$source_dirpath = str_replace(']', '\]', $source_dirpath);
$source_dirpath = str_replace('(', '\(',... | php | {
"resource": ""
} |
q240666 | SourceRoad.releaseResource | train | public function releaseResource(AbstractResourceFile $resource) {
if (is_null($this->getReleaseDir())) {
throw new Exception("ERROR: RELEASE DIR IS NULL: " . $resource->getRealPath());
}
if (!$this->getReleaseDir()->exists()) {
$this->getReleaseDir()->mkdirs();
}
... | php | {
"resource": ""
} |
q240667 | SourceRoad.makeReleaseFile | train | public final function makeReleaseFile(AbstractResourceFile $resource) {
if (!isset($this->__release__file__map[$resource->getMemberId()])) {
$this->__release__file__map[$resource->getMemberId()] = new File($this->makeReleaseRelativePath($resource), $this->getReleaseDir()->getAbsolutePath());
... | php | {
"resource": ""
} |
q240668 | SourceRoad.getParentProject | train | public final function getParentProject() {
if (\is_null($this->__parent__project)) {
$result = ProjectUtil::searchRelativeProject($this);
if (\count($result) < 1) {
throw new ProjectMemberNotFoundException("SOURCE ROAD NOT FOUND");
}
$this->__paren... | php | {
"resource": ""
} |
q240669 | Field.setCondition | train | public function setCondition($field_name, $value, $operation = '=')
{
$this->condition[$field_name] = [
'value' => $value,
'operation' => $operation
];
return $this;
} | php | {
"resource": ""
} |
q240670 | Field.asQuestion | train | public function asQuestion()
{
$instance = $this->questionClassInstance()
->setMaxAttempts($this->maxAttempt);
// Set question instance hidden if defined by the field.
if ($this->hidden) {
$instance->setHidden(true);
}
// Set validation callback if f... | php | {
"resource": ""
} |
q240671 | Field.questionClassInstance | train | protected function questionClassInstance()
{
$classname = $this->questionClass();
if (!class_exists($classname)) {
throw new \Exception('Invalid question class.');
}
$instance = (new \ReflectionClass($classname))
->newInstanceArgs($this->questionClassArgs())... | php | {
"resource": ""
} |
q240672 | Container.singleton | train | public function singleton($alias, $callback, $share = false)
{
return $this->add($alias, $callback, $share)->setSingleton(true);
} | php | {
"resource": ""
} |
q240673 | Container.resolve | train | public function resolve($alias, array $args = [])
{
// if it is an alias we will solve the orjinal one
if (isset($this->aliases[$alias])) {
$alias = $this->aliases[$alias];
}
$singleton = $this->getBoundManager()->singleton($alias);
// determine the alias alrea... | php | {
"resource": ""
} |
q240674 | Container.resolveObject | train | private function resolveObject($definition, $alias)
{
if ($definition instanceof \Closure) {
return $this->resolveClosure(
$alias,
$definition
);
}
try {
$class = new \ReflectionClass($definition);
} catch (\Reflec... | php | {
"resource": ""
} |
q240675 | PHPArray.each | train | public static function each(array $arr, \Closure $action){
foreach($arr as $k => $v){
$action($v, $k);
}
} | php | {
"resource": ""
} |
q240676 | PHPArray.filter | train | public static function filter(array $arr, \Closure $predicate){
$ret = array();
foreach($arr as $k => $v){
if($predicate($v, $k)){
$ret[$k] = $v;
}
}
return $ret;
} | php | {
"resource": ""
} |
q240677 | PHPArray.findKey | train | public static function findKey(array $arr, \Closure $predicate){
foreach($arr as $k => $v){
if($predicate($v, $k)){
return $k;
}
}
return null;
} | php | {
"resource": ""
} |
q240678 | PHPArray.keysExist | train | public static function keysExist(array $arr /*, $key1, $key2, etc...*/){
for($i = 1, $l = \func_num_args() - 1; $i <= $l; ++$i){
if(!\array_key_exists(\func_get_arg($i), $arr)){
return false;
}
}
return true;
} | php | {
"resource": ""
} |
q240679 | PHPArray.map | train | public static function map(array $arr, \Closure $callback){
$ret = array();
foreach($arr as $k => $v){
$ret[$k] = $callback($v, $k);
}
return $ret;
} | php | {
"resource": ""
} |
q240680 | PHPArray.single | train | public static function single(array $arr, \Closure $predicate){
foreach($arr as $k => $v){
if($predicate($v, $k)){
return $v;
}
}
return null;
} | php | {
"resource": ""
} |
q240681 | PHPArray.some | train | public static function some(array $arr, \Closure $predicate){
foreach($arr as $k => $v){
if($predicate($v, $k)){
return true;
}
}
return false;
} | php | {
"resource": ""
} |
q240682 | PackageInformation.getPackageInfo | train | public function getPackageInfo($packageName)
{
$composerLock = json_decode($this->finder->get('composer.lock'));
foreach ($composerLock->packages as $package) {
if ($package->name == $packageName) {
return $package;
}
}
} | php | {
"resource": ""
} |
q240683 | Addressable.getAddressInfo | train | public function getAddressInfo()
{
$address = new Address();
$address->setAddress($this->getAddress());
$address->setPostalCode($this->getPostalCode());
$address->setCity($this->getCity());
if(!is_null($this->getState()))$address->setState($this->getState());
$addres... | php | {
"resource": ""
} |
q240684 | HttpClient.send | train | public function send(RequestInterface $request)
{
/** @var RequestEvent $event */
$event = new RequestEvent($request);
$event = $this->eventDispatcher->dispatch(ClientEvents::REQUEST, $event);
$request = $event->getRequest();
$response = $this->httpClient->send($request);
... | php | {
"resource": ""
} |
q240685 | Model.update | train | public function update($attributes)
{
try {
self::init();
foreach ($attributes as $column => $value) {
$columns[] = $column. ' = :'.$column;
}
$sql = 'UPDATE ' . self::$modelTable . ' SET ' . implode(', ', $columns) . ' WHERE id = ' . $this->id... | php | {
"resource": ""
} |
q240686 | Model.select | train | public static function select()
{
try {
self::init();
$columns = func_get_args();
$query = 'SELECT ' . implode(', ', $columns) . ' FROM ' . self::$modelTable;
return new QueryBuilder(self::$connect, $query);
} catch (\Exception $exception) {
... | php | {
"resource": ""
} |
q240687 | Model.find | train | public static function find($id)
{
self::init();
$query = 'SELECT * FROM ' . self::$modelTable . ' WHERE id = '.$id;
$qb = new QueryBuilder(self::$connect, $query);
$rows = $qb->get();
$collection = self::makeCollection($rows);
return !empty($collection) ? array_shift... | php | {
"resource": ""
} |
q240688 | Model.makeCollection | train | public static function makeCollection($rows)
{
$collection = [];
foreach ($rows as $row)
{
$obj = new static;
$collection[] = $obj->setAttributes(get_object_vars($row));
}
return $collection;
} | php | {
"resource": ""
} |
q240689 | FileSystem.fgets | train | public function fgets( $length = null )
{
return $this->validHandle() ? fgets( $this->_fileHandle, $length ) : false;
} | php | {
"resource": ""
} |
q240690 | FileSystem.makePath | train | public static function makePath( $validate = true, $forceCreate = false )
{
$_arguments = func_get_args();
$_validate = $_path = null;
foreach ( $_arguments as $_part )
{
if ( is_bool( $_part ) )
{
$_validate = $_part;
continue... | php | {
"resource": ""
} |
q240691 | FileSystem.rmdir | train | public static function rmdir( $dirPath, $force = false )
{
$_path = rtrim( $dirPath ) . DIRECTORY_SEPARATOR;
if ( !$force )
{
return rmdir( $_path );
}
if ( !is_dir( $_path ) )
{
throw new \InvalidArgumentException( '"' . $_path . '" is not a... | php | {
"resource": ""
} |
q240692 | Joyst_Model.FilterFields | train | function FilterFields($array, $operation = 'where') {
if (!$array)
return;
$out = array();
foreach ($array as $field => $value) {
if ($operation == 'where' && $this->source == 'internal' && preg_match('/^(.*) (.*)$/', $field, $matches)) { // special CI syntax in key e.g. 'status !=' => 'something' (only for... | php | {
"resource": ""
} |
q240693 | Joyst_Model.GetCache | train | function GetCache($type, $id) {
if (!isset($this->cache[$type]) || !$this->cache[$type]) // Dont cache this type of call
return FALSE;
if (isset($this->_cache[$type][$id]))
return $this->_cache[$type][$id];
return FALSE;
} | php | {
"resource": ""
} |
q240694 | Joyst_Model.SetCache | train | function SetCache($type, $id, $value) {
if (!isset($this->cache[$type]) || !$this->cache[$type]) // Dont cache this type of call
return $value;
if ($value) {
if (!isset($this->_cache[$type]))
$this->_cache[$type] = array();
$this->_cache[$type][$id] = $value;
return $this->_cache[$type][$id];
} el... | php | {
"resource": ""
} |
q240695 | Joyst_Model.ClearCache | train | function ClearCache($type = null, $id = null) {
if (!$type) { // Clear everything
$this->_cache = array();
} elseif (!$id) { // Clear on section
$this->_cache[$type] = array();
} else { // Clear a specific type/id combination
$this->SetCache($type, $id, null);
}
} | php | {
"resource": ""
} |
q240696 | Joyst_Model.Get | train | function Get($id) {
$this->continue = TRUE;
$this->LoadSchema();
if ($value = $this->GetCache('get', $id))
return $value;
$this->ResetQuery(array(
'method' => 'get',
'table' => $this->table,
'where' => array(
$this->schema['_id']['field'] => $id,
),
'limit' => 1,
));
$this->db->from(... | php | {
"resource": ""
} |
q240697 | Joyst_Model.GetAll | train | function GetAll($where = null, $orderby = null, $limit = null, $offset = null) {
$this->LoadSchema();
if ($this->UseCache('getall')) {
$params = func_get_args();
$cacheid = md5(json_encode($params));
if ($value = $this->GetCache('getall', $cacheid))
return $value;
}
$this->ResetQuery(array(
'm... | php | {
"resource": ""
} |
q240698 | Joyst_Model.UnCastType | train | function UnCastType($type, $data, &$row = null) {
switch ($type) {
case 'json':
return json_encode($data);
case 'json-import':
if (!is_array($data))
$data = array();
foreach ($row as $key => $val) {
if (substr($key, 0, 1) == '_') // Skip meta fields
continue;
if (!isset($this->s... | php | {
"resource": ""
} |
q240699 | Joyst_Model.Create | train | function Create($data) {
if (!$this->allowBlankCreate && !$data)
return;
$this->LoadSchema();
if ($this->enforceTypes)
foreach ($this->schema as $key => $props)
if (isset($data[$key]) || $props['type'] == 'json-import')
$data[$key] = $this->UnCastType($props['type'], isset($data[$key]) ? $data[$ke... | php | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.