_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q237400
RepositoryAncestorCriteriaTrait.getByAncestor
train
public function getByAncestor(AncestorCriteriaInterface $ancestor) { $this->model = $ancestor->apply($this->model, $this); $results = $this->model->get(); $this->resetModel(); return $this->parserResult($results); }
php
{ "resource": "" }
q237401
Object.getSport
train
public function getSport(ConnectionInterface $con = null) { if ($this->aSport === null && ($this->sport_id !== null)) { $this->aSport = ChildSportQuery::create()->findPk($this->sport_id, $con); /* The following can be used additionally to guarantee the related object ...
php
{ "resource": "" }
q237402
Object.initSkills
train
public function initSkills($overrideExisting = true) { if (null !== $this->collSkills && !$overrideExisting) { return; } $this->collSkills = new ObjectCollection(); $this->collSkills->setModel('\gossi\trixionary\model\Skill'); }
php
{ "resource": "" }
q237403
ContainerLink.getEndpointAsUrl
train
public function getEndpointAsUrl($port, $protocol = 'tcp') { if (!$this->hasEndpoint($port, $protocol)) { throw new Exception('Endpoint is not available'); } $key = $port . '/' . $protocol; return Url::fromString($this->endpoints[$key]); }
php
{ "resource": "" }
q237404
ContainerLink.hasEndpoint
train
public function hasEndpoint($port, $protocol = 'tcp') { $key = $port . '/' . $protocol; return array_key_exists($key, $this->endpoints); }
php
{ "resource": "" }
q237405
CollectionPersister.getPathAndParent
train
private function getPathAndParent(PersistentCollection $coll) { $mapping = $coll->getMapping(); $fields = array(); $parent = $coll->getOwner(); while (null !== ($association = $this->uow->getParentAssociation($parent))) { list($m, $owner, $field) = $association; ...
php
{ "resource": "" }
q237406
Arrays.arrayFilterRecursive
train
public function arrayFilterRecursive(array $array) { foreach ($array as &$value) { if (is_array($value)) { /** @var $value array */ $value = count($value) === 1 && array_key_exists(0, $value) && is_string($value[ 0 ]) && $this->variable->isEmpty(tr...
php
{ "resource": "" }
q237407
AppServiceProvider.makePath
train
public function makePath() { $path = base_path('src'); if (!File::exists($path)) { File::makeDirectory($path, 0775, true); } }
php
{ "resource": "" }
q237408
StringUtil.truncatePreservingTags
train
public function truncatePreservingTags($str, $textMaxLength, $postString = '...', $encoding = 'UTF-8') { // complete string length with tags $htmlLength = mb_strlen($str, $encoding); // cursor position $htmlPos = 0; // extracted text length without tags $textLength = ...
php
{ "resource": "" }
q237409
StreamingResponseFactory.createStreamingResponse
train
public function createStreamingResponse($filePath, $fileName, $type = 'application/octet-stream') { $response = new StreamedResponse(); $this->setStreamCallBack($response, $filePath); $this->setStreamHeaders($response, $fileName, $type); return $response; }
php
{ "resource": "" }
q237410
Parser.parse
train
public function parse($string) { $response = new Response(); // normalize line endings $filtered = preg_replace("/(\n|\r){2,}/", PHP_EOL, $string); $lines = explode(PHP_EOL, $filtered); foreach($lines as $line) { $matches = array(); if(preg_match('/^(\s*)\[(.*)\]$/', $line, $matches)) { // enter...
php
{ "resource": "" }
q237411
Parser.cast
train
public static function cast($value) { $matches = array(); if(strtolower($value) === 'true') { $value = (bool) true; } else if(strtolower($value) === 'false') { $value = (bool) false; } else if(is_numeric($value)) { $value = (int) $value; } else if(preg_match('/^"(.*)"$/', $value, $matches)) { $val...
php
{ "resource": "" }
q237412
Collector.forSum
train
public static function forSum(callable $num): self { return new self( function() { return 0; }, function(&$result, $element) use($num) { $result+= $num($element); } ); }
php
{ "resource": "" }
q237413
Collector.forAverage
train
public static function forAverage(callable $num): self { return new self( function() { return [0, 0]; }, function(&$result, $arg) use($num) { $result[0] += $num($arg); $result[1]++; }, function($result) { return $result[0] / $result[1]; } ); }
php
{ "resource": "" }
q237414
Collector.accumulate
train
public function accumulate($element, $key) { $accumulate = $this->accumulator; $accumulate($this->structure, $element, $key); }
php
{ "resource": "" }
q237415
Collector.finish
train
public function finish() { if (null === $this->finisher) { return $this->structure; } $finish = $this->finisher; return $finish($this->structure); }
php
{ "resource": "" }
q237416
FootprintRegistry.import
train
public function import($file) { if (!file_exists($file)) { throw new \InvalidArgumentException("Footprint file '$file' does not exist"); } $content = file_get_contents($file); $this->importJson($content); }
php
{ "resource": "" }
q237417
FootprintRegistry.importJson
train
public function importJson($jsonData) { $json = json_decode($jsonData, true); if ($json === null) { throw new \InvalidArgumentException("Footprint json is not a valid"); } if (!is_array($json)) { throw new \InvalidArgumentException("Footprint json data is no...
php
{ "resource": "" }
q237418
FootprintRegistry.get
train
public function get($className) { if (isset($this->_footprints[$className])) { return $this->_footprints[$className]; } if (isset($this->_data[$className])) { $data = $this->_data[$className]; $footprint = new ClassFootprint($data); } else { ...
php
{ "resource": "" }
q237419
Base.validate
train
private function validate() { if (!stristr(self::CHARACTER_LIST, $this->value[0])) { throw new \Exception('Invalid first character: ' . $this->value[0]); } if (!in_array($this->value, self::listForCharacter($this->value[0]))) { throw new \Exception('Word not in known...
php
{ "resource": "" }
q237420
Base.randomFor
train
public static function randomFor($char) { $list = self::listForCharacter($char); $class = get_called_class(); return new $class($list[rand(0, count($list) - 1)]); }
php
{ "resource": "" }
q237421
Base.listForCharacter
train
public static function listForCharacter($char) { $file = self::getDataFolder() . '/' . $char; $data = strtolower(file_get_contents($file)); return explode("\n", $data); }
php
{ "resource": "" }
q237422
Relation.firstOrCreate
train
public function firstOrCreate(array $attributes = []) { $model = $this->first(); if (!$model) { $model = $this->create($attributes); } return $model; }
php
{ "resource": "" }
q237423
Result.get
train
public function get() { if( $this->value !== null ) return $this->value; if( $this->error !== null ) throw $this->error; throw new \LogicException("Value and error cannot both be null"); }
php
{ "resource": "" }
q237424
Result._try
train
public static function _try(callable $f) { try { return Result::success($f()); } catch( \Exception $error ) { return Result::error($error); } }
php
{ "resource": "" }
q237425
GuardianComponent.addGuestActions
train
public function addGuestActions($guestActions) { if (!is_array($guestActions)) { $guestActions = [$guestActions]; } $this->_guestActions = Hash::merge($this->_guestActions, $guestActions); }
php
{ "resource": "" }
q237426
GuardianComponent.hasAccess
train
public function hasAccess($url) { if ($this->isGuestAction($url)) { return true; } $path = $this->getPathFromUrl($url); $groupId = $this->Auth->user('group_id'); if ($groupId === null) { return false; } if (!is_array($groupId)) { ...
php
{ "resource": "" }
q237427
GuardianComponent.isGuestAction
train
public function isGuestAction($url) { $path = $this->getPathFromUrl($url); if (in_array($path, $this->_guestActions)) { return true; } return false; }
php
{ "resource": "" }
q237428
GuardianComponent.getPathFromUrl
train
public function getPathFromUrl($url) { $cacheKey = md5(serialize($url)); return Cache::remember($cacheKey, function () use ($url) { $plugin = 'App'; $action = 'index'; $parsedUrl = !is_array($url) ? Router::parse($url) : $url; if (isset($parsedUrl['...
php
{ "resource": "" }
q237429
GuardianComponent.getActionMap
train
public function getActionMap() { $plugins = $this->getLoadedPluginPaths(); $actionMap = []; foreach ($plugins as $plugin => $path) { $controllers = $this->getControllersForPlugin($plugin, $path); foreach ($controllers as $controller) { $actions = $thi...
php
{ "resource": "" }
q237430
GuardianComponent.getLoadedPluginPaths
train
public function getLoadedPluginPaths() { $pluginPaths = []; $plugins = Plugin::loaded() ?? []; foreach ($plugins as $p) { // @TODO load active plugins from plugin manager if (in_array($p, ['DebugKit', 'Migrations'])) { continue; } ...
php
{ "resource": "" }
q237431
GuardianComponent.getControllersForPlugin
train
public function getControllersForPlugin($plugin, $pluginPath) { $controllers = []; $Folder = new Folder(); $ctrlFolder = $Folder->cd($pluginPath . DS . 'src' . DS . 'Controller'); if (!empty($ctrlFolder)) { $files = $Folder->find('.*Controller\.php$'); $subL...
php
{ "resource": "" }
q237432
GuardianComponent.getControllersForApp
train
public function getControllersForApp() { $controllers = []; $ctrlFolder = new Folder(); /** @var Folder $ctrlFolder */ $ctrlFolder->cd(ROOT . DS . 'src' . DS . 'Controller'); if (!empty($ctrlFolder)) { $files = $ctrlFolder->find('.*Controller\.php$'); ...
php
{ "resource": "" }
q237433
GuardianComponent.introspectController
train
public function introspectController($controllerPath) { $content = file_get_contents($controllerPath); preg_match_all('/public\s+function\s+\&?\s*([^(]+)/', $content, $methods); $guardableActions = []; foreach ($methods[1] as $m) { if (in_array($m, ['__construct', 'initi...
php
{ "resource": "" }
q237434
GuardianComponent._getGroupPermissions
train
protected function _getGroupPermissions() { if (get_class($this->GroupPermissions) === 'GroupPermission') { return $this->GroupPermissions; } return $this->GroupPermissions = TableRegistry::get('Wasabi/Core.GroupPermissions'); }
php
{ "resource": "" }
q237435
Captcha.isValid
train
public function isValid( $id, $value, $context = null ) { return $this->createRegeneratable( array( 'id' => $id ) ) ->isValid( $value, $context ); }
php
{ "resource": "" }
q237436
PhpFileMarkerTrait.isFileMarked
train
protected function isFileMarked(string $packageName, string $file): bool { return \is_file($file) && \strpos(\file_get_contents($file), \sprintf('/** > %s **/', $packageName)) !== false; }
php
{ "resource": "" }
q237437
BibConsumer.doRequest
train
protected function doRequest(Client $client, $url, $options = array()) { $options += array( 'urlParams' => array(), 'queryParams' => array(), 'method' => static::METHOD_GET, ); $token = $client->getToken(); // Replace parameters in the url. ...
php
{ "resource": "" }
q237438
BibConsumer.getParameterReplacements
train
protected function getParameterReplacements($parameters, TokenInterface $token) { $replacements = $parameters; foreach ($parameters as $key => $param) { if (strpos($param, '{') === 0 && strpos($param, '}') === strlen($param) - 1) { $replacements[$key] = $token->getParam(s...
php
{ "resource": "" }
q237439
BibConsumer.fetchRequestToken
train
protected function fetchRequestToken() { // Fetching a new request token. Remove any old access tokens. $this->storage->delete(static::BIB_ACCESS_TOKEN); // Fetch a request token. $token = $this->consumer->getRequestToken(); // Persist the token to storage. $this->sto...
php
{ "resource": "" }
q237440
BibConsumer.fetchAccessToken
train
protected function fetchAccessToken($queryData, $retry = true) { if (!$this->hasRequestToken()) { $this->consumer->setCallbackUrl($this->getCurrentUri()); $this->fetchRequestToken(); $this->consumer->redirect(array('hint' => $this->getHint())); } try { ...
php
{ "resource": "" }
q237441
BibConsumer.getCurrentUri
train
protected function getCurrentUri() { $uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : false; if (!$uri) { $uri = $_SERVER['SCRIPT_NAME']; if (isset($_SERVER['argv']) || isset($_SERVER['QUERY_STRING'])) { $uri .= '?'; ...
php
{ "resource": "" }
q237442
BibConsumer.processQueryParameters
train
protected function processQueryParameters($queryParams) { foreach ($queryParams as $name => $value) { if (is_bool($value)) { $queryParams[$name] = $value ? 'true' : 'false'; } } return $queryParams; }
php
{ "resource": "" }
q237443
DataSet.prepare
train
public function prepare(Mapper $mapper) { if ($this->isPrepared()) { throw new DataSetPreparationException('DataSet is already prepared'); } //Split each row of the dataSet into inputs and outputs based on the mapper and the policies //Then re-parse the dataSet to fill in...
php
{ "resource": "" }
q237444
DataSet.map
train
protected function map(Mapper $mapper): DataSet { $this->mapper = $mapper; $this->instances = $this->inputsMatrix = $this->outputsMatrix = []; foreach ($this->rawData as &$row) { //Split each row of the raw DataSet into inputs and outputs list($inputs, $outputs) = $t...
php
{ "resource": "" }
q237445
OsfApplication.run
train
public function run() { $this->init(); try { $this->bootstrap(); $this->route(); $this->dispatch(); } catch (Exception $e) { if (APPLICATION_ENV == self::ENV_DEV) { var_dump($e); } else { throw $e; ...
php
{ "resource": "" }
q237446
OsfApplication.bootstrap
train
public function bootstrap() { $config = Container::getConfig(); $commonConfigFile = APPLICATION_PATH . '/App/' . Router::getDefaultControllerName(true) . '/Config/application.php'; $config->appendConfig(require $commonConfigFile); $bootstrapFile = APPLICATION_PATH . '/App/' . Router:...
php
{ "resource": "" }
q237447
OsfApplication.route
train
public function route() { PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_ROUTE); Container::getRouter()->route(); self::debug('Route: ' . Container::getRouter()->buildUri()); PluginManager::handleApplicationPlugins(PluginManager::STEP_AFTER_ROUTE); return ...
php
{ "resource": "" }
q237448
OsfApplication.dispatch
train
public function dispatch() { $request = Container::getRequest(); $response = Container::getResponse(); PluginManager::handleApplicationPlugins(PluginManager::STEP_BEFORE_DISPATCH_LOOP); //self::debug('Begin dispatch loop...'); while (!$this->dispatched) { ...
php
{ "resource": "" }
q237449
FilteredController._applyFilter
train
private function _applyFilter($chain, $object) { foreach($chain as $filter) { if(!$object = call_user_func($filter, $object)) throw new Exception("Filter returned null"); } return $object; }
php
{ "resource": "" }
q237450
FilteredController.filter
train
protected function filter($request) { return $this->_applyFilter($this->_responses, $this->_controller->execute( $this->_applyFilter($this->_requests, $request) )); }
php
{ "resource": "" }
q237451
Request.getMethod
train
public function getMethod() { $fakeMethod = $this->params['_method']; if ($fakeMethod) { if (in_array($fakeMethod, $this->acceptedMethods)) { return $fakeMethod; } throw new Exceptions\InvalidRequestMethodException( "'$fakeMethod'...
php
{ "resource": "" }
q237452
UriFactory.create
train
public function create($uri) { list($scheme, $host, $port, $path, $query, $fragment, $user, $pass) = $this->parseUrl($uri); return new Uri($scheme, $host, $port, $path, $query, $fragment, $user, $pass); }
php
{ "resource": "" }
q237453
UriFactory.parseUrl
train
protected function parseUrl($uri) { $parsedUrl = parse_url($uri); return [ isset($parsedUrl['scheme']) ? $parsedUrl['scheme'] : '', isset($parsedUrl['host']) ? $parsedUrl['host'] : '', isset($parsedUrl['port']) ? $parsedUrl['port'] : null, isset($pars...
php
{ "resource": "" }
q237454
Formatter.sendTextMsgToXmlString
train
protected function sendTextMsgToXmlString(WxSendTextMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> </xml> XML; $result = sprintf(...
php
{ "resource": "" }
q237455
Formatter.sendImageMsgToXmlString
train
protected function sendImageMsgToXmlString(WxSendImageMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Image> <MediaId><![CDATA[%s]]></MediaId> </Image> </xml> XML; ...
php
{ "resource": "" }
q237456
Formatter.sendVoiceMsgToXmlString
train
protected function sendVoiceMsgToXmlString(WxSendVoiceMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Voice> <MediaId><![CDATA[%s]]></MediaId> </Voice> </xml> XML; ...
php
{ "resource": "" }
q237457
Formatter.sendVideoMsgToXmlString
train
protected function sendVideoMsgToXmlString(WxSendVideoMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Video> <MediaId><![CDATA[%s]]></MediaId> <Title><![CDATA[%s]]></Title...
php
{ "resource": "" }
q237458
Formatter.sendMusicMsgToXmlString
train
protected function sendMusicMsgToXmlString(WxSendMusicMsg $msg) { $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%d</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Music> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Des...
php
{ "resource": "" }
q237459
Formatter.sendNewsMsgToXmlString
train
protected function sendNewsMsgToXmlString(WxSendNewsMsg $msg) { $itemArray = $msg->getAllArticleItems(); $itemStr = ''; foreach ($itemArray as $item) { $itemStr .= $this->sendNewsItemToXmlString($item); } $formatStr = <<<XML <xml> <ToUserName><![CDATA[%s]]></...
php
{ "resource": "" }
q237460
Formatter.toJsonString
train
public function toJsonString(WxSendMsg $msg) { if ($msg instanceof WxSendTextMsg) { return $this->sendTextMsgToJsonString($msg); } elseif ($msg instanceof WxSendImageMsg) { return $this->sendImageMsgToJsonString($msg); } elseif ($msg instanceof WxSendVoiceMsg) { ...
php
{ "resource": "" }
q237461
Formatter.sendTextMsgToJsonString
train
protected function sendTextMsgToJsonString(WxSendTextMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "text": { "content":"%s" } ...
php
{ "resource": "" }
q237462
Formatter.sendImageMsgToJsonString
train
protected function sendImageMsgToJsonString(WxSendImageMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "image": { "media_id":"%s" } ...
php
{ "resource": "" }
q237463
Formatter.sendVoiceMsgToJsonString
train
protected function sendVoiceMsgToJsonString(WxSendVoiceMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "voice": { "media_id":"%s" } ...
php
{ "resource": "" }
q237464
Formatter.sendVideoMsgToJsonString
train
protected function sendVideoMsgToJsonString(WxSendVideoMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "video": { "media_id":"%s", "thumb_media_id":"...
php
{ "resource": "" }
q237465
Formatter.sendMusicMsgToJsonString
train
protected function sendMusicMsgToJsonString(WxSendMusicMsg $msg) { $formatStr = '{ "touser":"%s", "msgtype":"%s", "music": { "title":"%s", "description":"%s", ...
php
{ "resource": "" }
q237466
Formatter.sendNewsMsgToJsonString
train
protected function sendNewsMsgToJsonString(WxSendNewsMsg $msg) { $itemArray = $msg->getAllArticleItems(); $itemStr = ''; foreach ($itemArray as $item) { $itemStr .= $this->sendNewsItemToJsonString($item) . ','; } $itemStr = substr($itemStr, 0, -1); ...
php
{ "resource": "" }
q237467
Formatter.sendNewsItemToJsonString
train
protected function sendNewsItemToJsonString(WxSendNewsMsgItem $item) { $formatStr = '{ "title":"%s", "description":"%s", "url":"%s", "picurl":"%s" }'; $result = sprintf($formatStr...
php
{ "resource": "" }
q237468
AppConfig.load
train
public function load() { if( !$this->path ) { throw new \Exception('Unable to load AppConfig from undefined path'); } $this->data = json_decode(file_get_contents($this->path), true); }
php
{ "resource": "" }
q237469
Functions.getTwig
train
public function getTwig(\Twig_Environment $twig) { $this->functions->rewind(); while ($this->functions->valid()) { $function = $this->functions->current(); $twig->addFunction(new \Twig_SimpleFunction($function->getFunctionName(), array($function, 'getFunctionBody'))); ...
php
{ "resource": "" }
q237470
PostType.onMapMetaCap
train
public function onMapMetaCap($caps, $cap, $user_id, $args) { // post type object // ---------------- $post_type_object = get_post_type_object($this->name); if (is_null($post_type_object)) { return $caps; } if ( $post_type_object->capability_type === 'post' || $post_type_ob...
php
{ "resource": "" }
q237471
ProfileForm.save
train
public function save($isNewRecord) { if ($this->validate()) { $user = $this->user; $data = []; $fn = $user->formName(); if ($isNewRecord) { $data[$fn]['username'] = $this->username; } $data[$fn]['email'] = $...
php
{ "resource": "" }
q237472
Views.addData
train
public function addData(array $data, $templates = null) { $this->engine->addData($data, $templates); return $this->engine; }
php
{ "resource": "" }
q237473
Gdn_Upload.CopyLocal
train
public function CopyLocal($Name) { $Parsed = self::Parse($Name); $LocalPath = ''; $this->EventArguments['Parsed'] = $Parsed; $this->EventArguments['Path'] =& $LocalPath; $this->FireAs('Gdn_Upload')->FireEvent('CopyLocal'); if (!$LocalPath) { $LocalPath = PATH_UPLOADS.'/'.$...
php
{ "resource": "" }
q237474
Gdn_Upload.Delete
train
public function Delete($Name) { $Parsed = $this->Parse($Name); // Throw an event so that plugins that have stored the file somewhere else can delete it. $this->EventArguments['Parsed'] =& $Parsed; $Handled = FALSE; $this->EventArguments['Handled'] =& $Handled; $this->FireAs('Gdn_Upl...
php
{ "resource": "" }
q237475
Gdn_Upload.FormatFileSize
train
public static function FormatFileSize($Bytes, $Precision = 1) { $Units = array('B', 'K', 'M', 'G', 'T'); $Bytes = max((int)$Bytes, 0); $Pow = floor(($Bytes ? log($Bytes) : 0) / log(1024)); $Pow = min($Pow, count($Units) - 1); $Bytes /= pow(1024, $Pow); $Result = round($Bytes, $Precision).$Units[$Pow]; ...
php
{ "resource": "" }
q237476
Gdn_Upload.UnformatFileSize
train
public static function UnformatFileSize($Formatted) { $Units = array('B' => 1, 'K' => 1024, 'M' => 1024 * 1024, 'G' => 1024 * 1024 * 1024, 'T' => 1024 * 1024 * 1024 * 1024); if(preg_match('/([0-9.]+)\s*([A-Z]*)/i', $Formatted, $Matches)) { $Number = floatval($Matches[1]); $Unit = strtoupper(substr($Matches[2...
php
{ "resource": "" }
q237477
Gdn_Upload.Urls
train
public static function Urls($Type = NULL) { static $Urls = NULL; if ($Urls === NULL) { $Urls = array('' => Asset('/uploads', TRUE)); $Sender = new stdClass(); $Sender->Returns = array(); $Sender->EventArguments = array(); $Sender->EventArguments['Urls'...
php
{ "resource": "" }
q237478
Gdn_Upload.ValidateUpload
train
public function ValidateUpload($InputName, $ThrowException = TRUE) { $Ex = FALSE; if (!array_key_exists($InputName, $_FILES) || (!is_uploaded_file($_FILES[$InputName]['tmp_name']) && GetValue('error', $_FILES[$InputName], 0) == 0)) { // Check the content length to see if we exceeded the max post size. $Conte...
php
{ "resource": "" }
q237479
RoutedController._controllerFor
train
private function _controllerFor($name) { if(isset($this->_controllers[$name]) && is_string($this->_controllers[$name])) { return $this->_controllerFor($this->_controllers[$name]); } else if(isset($this->_controllers[$name]) && is_object($this->_controllers[$name])) { return $this->_controllers[$name]; ...
php
{ "resource": "" }
q237480
RoutedController.connect
train
public function connect($url, $name, $controller=null) { $this->_router->connect($url, $name, $controller); // register the controller if one is provided if(!is_null($controller)) { $this->_controllers[$name] = $controller; } return $this; }
php
{ "resource": "" }
q237481
Environment.fequiv_mb_ucfirst
train
protected function fequiv_mb_ucfirst($string, $encoding = 'utf8') { return mb_strtoupper(mb_substr($string, 0, 1, $encoding), $encoding).mb_substr($string, 1, mb_strlen($string, $encoding) - 1, $encoding); }
php
{ "resource": "" }
q237482
Parser.parse
train
public static function parse($path) { if (!file_exists($path)) { throw new \Exception("$path not found"); } $src = file_get_contents($path); if (!$src) { throw new \Exception("could not read $path"); } // first of all do we have any frontmatter i...
php
{ "resource": "" }
q237483
CliRequest.add
train
public function add($key, $value) { if (! isset($this->_params[$key])) { $this->_params[$key] = array(); } $this->_params[$key][] = $value; }
php
{ "resource": "" }
q237484
CliRequest.getAsArray
train
public function getAsArray($key, array $default = array()) { $value = parent::get($key, $default); if (is_array($value) && !$value) $value = $default; return (array)$value; }
php
{ "resource": "" }
q237485
Response.add
train
public function add($object){ if(is_array($object)) { $this->responses = array_merge($this->responses, $object); } else { $implementedInterfaces = class_implements($object); if(array_key_exists("WasabiLib\Ajax\ResponseConfiguratorInterface", $implementedInterfaces))...
php
{ "resource": "" }
q237486
StreamBodyMultiPart.addElements
train
function addElements($multiPart) { if (! is_array($multiPart) ) throw new \InvalidArgumentException(sprintf( 'Accept array of Files; given: "%s".' , \Poirot\Std\flatten($multiPart) )); foreach($multiPart as $name => $element) $thi...
php
{ "resource": "" }
q237487
StreamBodyMultiPart.addElement
train
function addElement($fieldName, $element, $headers = null) { if ($this->_trailingBoundary) throw new \Exception('Trailing Boundary Is Added.'); if (! $headers instanceof iHeaders ) $headers = (! empty($headers) ) ? new CollectionHeader($headers) : new CollectionHeade...
php
{ "resource": "" }
q237488
StreamBodyMultiPart.addElementDone
train
function addElementDone() { ## add trailing boundary as stream if not $this->_trailingBoundary = new STemporary("\r\n"."--{$this->_boundary}--"); $this->_t__wrap_stream->addStream($this->_trailingBoundary->rewind()); }
php
{ "resource": "" }
q237489
Project.generate
train
public static function generate(String $name) : Bool { Post::project($name); $validation = Singleton::class('ZN\Validation\Data'); $validation->rules('project', ['alpha'], 'Project Name'); if( ! $error = $validation->error('string') ) { $source = EXTERNAL_FILES...
php
{ "resource": "" }
q237490
Number.isPrime
train
public static function isPrime($val = null) { if (is_null($val)) { return null; } if ( ($val<=1) || ($val>2 && ($val%2)===0) ) { return false; } for ($i=2;$i<$val;$i++) { if (($val%$i)===0) { ...
php
{ "resource": "" }
q237491
Number.isLuhn
train
public static function isLuhn($val = null) { if (is_null($val)) { return null; } $_num = substr($val, 0, strlen($val)-1); return (bool) (intval($val) == intval($_num.self::getLuhnKey($_num))); }
php
{ "resource": "" }
q237492
TorFeed.getItems
train
public function getItems() { $namespaces = $this->xml->getDocNamespaces(); foreach($namespaces as $namespace => $url) { $this->xml->registerXPathNamespace($namespace, $url); } foreach ($this->xml->xpath($this->itemXpath) as $item) { $this->items[] = new Item ( $this-...
php
{ "resource": "" }
q237493
Assume.assumeThat
train
public static function assumeThat($actual, Matcher $matcher, $message = ''): void { if (!$matcher->matches($actual)) { throw new AssumptionViolatedException($actual, $matcher, $message); } }
php
{ "resource": "" }
q237494
UserHelper.getUserGroups
train
public function getUserGroups() { $db = $this->db; $query = $db->getQuery(true) ->select('a.*, COUNT(DISTINCT b.id) AS level') ->from($db->quoteName('#__usergroups') . ' AS a') ->join('LEFT', $db->quoteName('#__usergroups') . ' AS b ON a.lft ...
php
{ "resource": "" }
q237495
EloquentModelResourceTrait.index
train
public function index() { $model = $this->modelFullName; $collection = $model::all(); if($collection->isEmpty()) throw new NotFoundException('There Are No Resources Named "' . $this->getResourceName() . '" Yet'); return $collection; }
php
{ "resource": "" }
q237496
EloquentModelResourceTrait.show
train
public function show($id) { $modelName = $this->modelFullName; $model = $modelName::find($id); if(!$model) throw new NotFoundException('There is no Resource with id = ' . $id . ' !'); return $model; }
php
{ "resource": "" }
q237497
EloquentModelResourceTrait.validate
train
protected function validate($data, $rules=false) { if(!$rules) { $modelName = $this->modelFullName; $rules = $modelName::$rules; } $validator = \Validator::make($data, $rules); if($validator->fails()) throw new ValidationException($validator); ...
php
{ "resource": "" }
q237498
Filesystem.force
train
public function force($path, $mode = 0777, $recursive = true) { if ($this->exists($path)) { return true; } return $this->makeDirectory($path, $mode, $recursive); }
php
{ "resource": "" }
q237499
Filesystem.fileName
train
public function fileName($filename, $withExt = true) { return $withExt ? pathinfo($filename, PATHINFO_BASENAME) : pathinfo($filename, PATHINFO_FILENAME); }
php
{ "resource": "" }