_id
stringlengths
2
7
title
stringlengths
3
151
partition
stringclasses
3 values
text
stringlengths
83
13k
language
stringclasses
1 value
meta_information
dict
q254800
Config.get
test
public static function get(string $name, bool $getShared = true) { $class = $name; if (($pos = strrpos($name, '\\')) !== false) { $class = substr($name, $pos + 1); } if (! $getShared) { return self::createClass($name); } if (! isset( self::$instances[$class] )) { self::$instances[$class] =...
php
{ "resource": "" }
q254801
Config.createClass
test
private static function createClass(string $name) { if (class_exists($name)) { return new $name(); } $locator = Services::locator(); $file = $locator->locateFile($name, 'Config'); if (empty($file)) { return null; } $name = $locator->getClassname($file); if (empty($name)) { return ...
php
{ "resource": "" }
q254802
BaseService.getSharedInstance
test
protected static function getSharedInstance(string $key, ...$params) { // Returns mock if exists if (isset(static::$mocks[$key])) { return static::$mocks[$key]; } if (! isset(static::$instances[$key])) { // Make sure $getShared is false array_push($params, false); static::$instances[$key] = s...
php
{ "resource": "" }
q254803
BaseService.autoloader
test
public static function autoloader(bool $getShared = true) { if ($getShared) { if (empty(static::$instances['autoloader'])) { static::$instances['autoloader'] = new Autoloader(); } return static::$instances['autoloader']; } return new Autoloader(); }
php
{ "resource": "" }
q254804
BaseService.locator
test
public static function locator(bool $getShared = true) { if ($getShared) { if (empty(static::$instances['locator'])) { static::$instances['locator'] = new FileLocator( static::autoloader() ); } return static::$instances['locator']; } return new FileLocator(static::autoloader()); }
php
{ "resource": "" }
q254805
BaseService.reset
test
public static function reset(bool $init_autoloader = false) { static::$mocks = []; static::$instances = []; if ($init_autoloader) { static::autoloader()->initialize(new Autoload(), new Modules()); } }
php
{ "resource": "" }
q254806
BaseService.injectMock
test
public static function injectMock(string $name, $mock) { $name = strtolower($name); static::$mocks[$name] = $mock; }
php
{ "resource": "" }
q254807
BaseService.discoverServices
test
protected static function discoverServices(string $name, array $arguments) { if (! static::$discovered) { $config = config('Modules'); if ($config->shouldDiscover('services')) { $locator = static::locator(); $files = $locator->search('Config/Services'); if (empty($files)) { // no ...
php
{ "resource": "" }
q254808
CLI.input
test
public static function input(string $prefix = null): string { if (static::$readline_support) { return readline($prefix); } echo $prefix; return fgets(STDIN); }
php
{ "resource": "" }
q254809
CLI.prompt
test
public static function prompt(string $field, $options = null, string $validation = null): string { $extra_output = ''; $default = ''; if (is_string($options)) { $extra_output = ' [' . static::color($options, 'white') . ']'; $default = $options; } if (is_array($options) && $options) { ...
php
{ "resource": "" }
q254810
CLI.validate
test
protected static function validate(string $field, string $value, string $rules): bool { $validation = \Config\Services::validation(null, false); $validation->setRule($field, null, $rules); $validation->run([$field => $value]); if ($validation->hasError($field)) { static::error($validation->getError($fiel...
php
{ "resource": "" }
q254811
CLI.print
test
public static function print(string $text = '', string $foreground = null, string $background = null) { if ($foreground || $background) { $text = static::color($text, $foreground, $background); } static::$lastWrite = null; fwrite(STDOUT, $text); }
php
{ "resource": "" }
q254812
CLI.error
test
public static function error(string $text, string $foreground = 'light_red', string $background = null) { if ($foreground || $background) { $text = static::color($text, $foreground, $background); } fwrite(STDERR, $text . PHP_EOL); }
php
{ "resource": "" }
q254813
CLI.wait
test
public static function wait(int $seconds, bool $countdown = false) { if ($countdown === true) { $time = $seconds; while ($time > 0) { fwrite(STDOUT, $time . '... '); sleep(1); $time --; } static::write(); } else { if ($seconds > 0) { sleep($seconds); } else { ...
php
{ "resource": "" }
q254814
CLI.color
test
public static function color(string $text, string $foreground, string $background = null, string $format = null): string { if (static::isWindows() && ! isset($_SERVER['ANSICON'])) { // @codeCoverageIgnoreStart return $text; // @codeCoverageIgnoreEnd } if (! array_key_exists($foreground, static::$fore...
php
{ "resource": "" }
q254815
CLI.wrap
test
public static function wrap(string $string = null, int $max = 0, int $pad_left = 0): string { if (empty($string)) { return ''; } if ($max === 0) { $max = CLI::getWidth(); } if (CLI::getWidth() < $max) { $max = CLI::getWidth(); } $max = $max - $pad_left; $lines = wordwrap($string, $ma...
php
{ "resource": "" }
q254816
CLI.getOption
test
public static function getOption(string $name) { if (! array_key_exists($name, static::$options)) { return null; } // If the option didn't have a value, simply return TRUE // so they know it was set, otherwise return the actual value. $val = static::$options[$name] === null ? true : static::$options[$n...
php
{ "resource": "" }
q254817
CLI.table
test
public static function table(array $tbody, array $thead = []) { // All the rows in the table will be here until the end $table_rows = []; // We need only indexes and not keys if (! empty($thead)) { $table_rows[] = array_values($thead); } foreach ($tbody as $tr) { $table_rows[] = array_values($t...
php
{ "resource": "" }
q254818
ResponseTrait.respond
test
public function respond($data = null, int $status = null, string $message = '') { // If data is null and status code not provided, exit and bail if ($data === null && $status === null) { $status = 404; // Create the output var here in case of $this->response([]); $output = null; } // If data is null ...
php
{ "resource": "" }
q254819
ResponseTrait.fail
test
public function fail($messages, int $status = 400, string $code = null, string $customMessage = '') { if (! is_array($messages)) { $messages = ['error' => $messages]; } $response = [ 'status' => $status, 'error' => $code === null ? $status : $code, 'messages' => $messages, ]; return $thi...
php
{ "resource": "" }
q254820
ResponseTrait.respondCreated
test
public function respondCreated($data = null, string $message = '') { return $this->respond($data, $this->codes['created'], $message); }
php
{ "resource": "" }
q254821
ResponseTrait.respondDeleted
test
public function respondDeleted($data = null, string $message = '') { return $this->respond($data, $this->codes['deleted'], $message); }
php
{ "resource": "" }
q254822
ResponseTrait.failUnauthorized
test
public function failUnauthorized(string $description = 'Unauthorized', string $code = null, string $message = '') { return $this->fail($description, $this->codes['unauthorized'], $code, $message); }
php
{ "resource": "" }
q254823
ResponseTrait.failServerError
test
public function failServerError(string $description = 'Internal Server Error', string $code = null, string $message = ''): Response { return $this->fail($description, $this->codes['server_error'], $code, $message); }
php
{ "resource": "" }
q254824
CSRF.before
test
public function before(RequestInterface $request) { if ($request->isCLI()) { return; } $security = Services::security(); try { $security->CSRFVerify($request); } catch (SecurityException $e) { if (config('App')->CSRFRedirect && ! $request->isAJAX()) { return redirect()->back()->with...
php
{ "resource": "" }
q254825
Events.initialize
test
public static function initialize() { // Don't overwrite anything.... if (static::$initialized) { return; } $config = config('Modules'); $files = [APPPATH . 'Config/Events.php']; if ($config->shouldDiscover('events')) { $locator = Services::locator(); $files = $locator->search('Config/Eve...
php
{ "resource": "" }
q254826
Events.listeners
test
public static function listeners($event_name): array { if (! isset(static::$listeners[$event_name])) { return []; } // The list is not sorted if (! static::$listeners[$event_name][0]) { // Sort it! array_multisort(static::$listeners[$event_name][1], SORT_NUMERIC, static::$listeners[$event_name][2...
php
{ "resource": "" }
q254827
Events.removeListener
test
public static function removeListener($event_name, callable $listener): bool { if (! isset(static::$listeners[$event_name])) { return false; } foreach (static::$listeners[$event_name][2] as $index => $check) { if ($check === $listener) { unset(static::$listeners[$event_name][1][$index]); un...
php
{ "resource": "" }
q254828
UserAgent.isReferral
test
public function isReferral(): bool { if (! isset($this->referrer)) { if (empty($_SERVER['HTTP_REFERER'])) { $this->referrer = false; } else { $referer_host = @parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST); $own_host = parse_url(\base_url(), PHP_URL_HOST); $this->referrer = (...
php
{ "resource": "" }
q254829
UserAgent.setPlatform
test
protected function setPlatform(): bool { if (is_array($this->config->platforms) && $this->config->platforms) { foreach ($this->config->platforms as $key => $val) { if (preg_match('|' . preg_quote($key) . '|i', $this->agent)) { $this->platform = $val; return true; } } } $this->p...
php
{ "resource": "" }
q254830
UserAgent.setBrowser
test
protected function setBrowser(): bool { if (is_array($this->config->browsers) && $this->config->browsers) { foreach ($this->config->browsers as $key => $val) { if (preg_match('|' . $key . '.*?([0-9\.]+)|i', $this->agent, $match)) { $this->isBrowser = true; $this->version = $match[1]; ...
php
{ "resource": "" }
q254831
UserAgent.setRobot
test
protected function setRobot(): bool { if (is_array($this->config->robots) && $this->config->robots) { foreach ($this->config->robots as $key => $val) { if (preg_match('|' . preg_quote($key) . '|i', $this->agent)) { $this->isRobot = true; $this->robot = $val; $this->setMobile(); ...
php
{ "resource": "" }
q254832
UserAgent.setMobile
test
protected function setMobile(): bool { if (is_array($this->config->mobiles) && $this->config->mobiles) { foreach ($this->config->mobiles as $key => $val) { if (false !== (stripos($this->agent, $key))) { $this->isMobile = true; $this->mobile = $val; return true; } } } ret...
php
{ "resource": "" }
q254833
Forge._attributeType
test
protected function _attributeType(array &$attributes) { // Reset field lengths for data types that don't support it if (isset($attributes['CONSTRAINT']) && stripos($attributes['TYPE'], 'int') !== false) { $attributes['CONSTRAINT'] = null; } switch (strtoupper($attributes['TYPE'])) { case 'TINYINT': ...
php
{ "resource": "" }
q254834
Kernel.initializeConfig
test
private function initializeConfig() { if (!is_dir($this->vbot->config['path'])) { mkdir($this->vbot->config['path'], 0755, true); } $this->vbot->config['storage'] = $this->vbot->config['storage'] ?: 'collection'; $this->vbot->config['path'] = realpath($this->vbot->confi...
php
{ "resource": "" }
q254835
QrCode.show
test
public function show($text) { if (!array_get($this->config, 'qrcode', true)) { return false; } $output = new ConsoleOutput(); static::initQrcodeStyle($output); $pxMap[0] = Console::isWin() ? '<whitec>mm</whitec>' : '<whitec> </whitec>'; $pxMap[1] = '<bla...
php
{ "resource": "" }
q254836
QrCode.initQrcodeStyle
test
private static function initQrcodeStyle(OutputInterface $output) { $style = new OutputFormatterStyle('black', 'black', ['bold']); $output->getFormatter()->setStyle('blackc', $style); $style = new OutputFormatterStyle('white', 'white', ['bold']); $output->getFormatter()->setStyle('whi...
php
{ "resource": "" }
q254837
Content.formatContent
test
public static function formatContent($content) { $content = self::emojiHandle($content); $content = self::replaceBr($content); return self::htmlDecode($content); }
php
{ "resource": "" }
q254838
MessageHandler.heartbeat
test
private function heartbeat($time) { if (time() - $time > 1800) { Text::send('filehelper', 'heart beat '.Carbon::now()->toDateTimeString()); return time(); } return $time; }
php
{ "resource": "" }
q254839
MessageHandler.handleCheckSync
test
public function handleCheckSync($retCode, $selector, $test = false) { if (in_array($retCode, [1100, 1101, 1102, 1205])) { // 微信客户端上登出或者其他设备登录 $this->vbot->console->log('vbot exit normally.'); $this->vbot->cache->forget('session.'.$this->vbot->config['session']); return ...
php
{ "resource": "" }
q254840
MessageHandler.log
test
private function log($message) { if ($this->vbot->messageLog && ($message['ModContactList'] || $message['AddMsgList'])) { $this->vbot->messageLog->info(json_encode($message)); } }
php
{ "resource": "" }
q254841
Server.getUuid
test
protected function getUuid() { $content = $this->vbot->http->get('https://login.weixin.qq.com/jslogin', ['query' => [ 'appid' => 'wx782c26e4c19acffb', 'fun' => 'new', 'lang' => 'zh_CN', '_' => time(), ]]); preg_match('/window.QRLogin.co...
php
{ "resource": "" }
q254842
Server.showQrCode
test
public function showQrCode() { $url = 'https://login.weixin.qq.com/l/'.$this->vbot->config['server.uuid']; $this->vbot->qrCodeObserver->trigger($url); $this->vbot->qrCode->show($url); }
php
{ "resource": "" }
q254843
Server.waitForLogin
test
protected function waitForLogin() { $retryTime = 10; $tip = 1; $this->vbot->console->log('please scan the qrCode with wechat.'); while ($retryTime > 0) { $url = sprintf('https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?tip=%s&uuid=%s&_=%s', $tip, $this->vbot->config...
php
{ "resource": "" }
q254844
Server.getLogin
test
private function getLogin() { $content = $this->vbot->http->get($this->vbot->config['server.uri.redirect']); $data = (array) simplexml_load_string($content, 'SimpleXMLElement', LIBXML_NOCDATA); $this->vbot->config['server.skey'] = $data['skey']; $this->vbot->config['server.sid'] = ...
php
{ "resource": "" }
q254845
Server.saveServer
test
private function saveServer() { $this->vbot->cache->forever('session.'.$this->vbot->config['session'], json_encode($this->vbot->config['server'])); }
php
{ "resource": "" }
q254846
Server.beforeInitSuccess
test
private function beforeInitSuccess() { $this->vbot->console->log('current session: '.$this->vbot->config['session']); $this->vbot->console->log('init begin.'); }
php
{ "resource": "" }
q254847
Server.afterInitSuccess
test
private function afterInitSuccess($content) { $this->vbot->log->info('response:'.json_encode($content)); $this->vbot->console->log('init success.'); $this->vbot->loginSuccessObserver->trigger(); $this->vbot->console->log('init contacts begin.'); }
php
{ "resource": "" }
q254848
Server.statusNotify
test
protected function statusNotify() { $url = sprintf($this->vbot->config['server.uri.base'].'/webwxstatusnotify?lang=zh_CN&pass_ticket=%s', $this->vbot->config['server.passTicket']); $this->vbot->http->json($url, [ 'BaseRequest' => $this->vbot->config['server.baseRequest'], '...
php
{ "resource": "" }
q254849
Multimedia.download
test
public static function download($message, $callback = null) { if (!$callback) { static::autoDownload($message['raw'], true); return true; } if ($callback && !is_callable($callback)) { throw new ArgumentException(); } call_user_func_array...
php
{ "resource": "" }
q254850
Multimedia.getResource
test
private static function getResource($message) { $url = static::getDownloadUrl($message); $content = vbot('http')->get($url, static::getDownloadOption($message)); if (!$content) { vbot('console')->log('download file failed.', Console::WARNING); } else { retur...
php
{ "resource": "" }
q254851
Multimedia.autoDownload
test
protected static function autoDownload($message, $force = false) { $isDownload = vbot('config')['download.'.static::TYPE]; if ($isDownload || $force) { $resource = static::getResource($message); if ($resource) { File::saveTo(vbot('config')['user_path'].stati...
php
{ "resource": "" }
q254852
Sync.checkSync
test
public function checkSync() { $content = $this->vbot->http->get($this->vbot->config['server.uri.push'].'/synccheck', ['timeout' => 35, 'query' => [ 'r' => time(), 'sid' => $this->vbot->config['server.sid'], 'uin' => $this->vbot->config['server.uin'], ...
php
{ "resource": "" }
q254853
Sync.sync
test
public function sync() { $url = sprintf($this->vbot->config['server.uri.base'].'/webwxsync?sid=%s&skey=%s&lang=zh_CN&pass_ticket=%s', $this->vbot->config['server.sid'], $this->vbot->config['server.skey'], $this->vbot->config['server.passTicket'] ); $resul...
php
{ "resource": "" }
q254854
Sync.generateSyncKey
test
public function generateSyncKey($result) { $this->vbot->config['server.syncKey'] = $result['SyncKey']; $syncKey = []; if (is_array($this->vbot->config['server.syncKey.List'])) { foreach ($this->vbot->config['server.syncKey.List'] as $item) { $syncKey[] = $item['...
php
{ "resource": "" }
q254855
Console.log
test
public function log($str, $level = 'INFO', $log = false) { if ($this->isOutput()) { if ($log && in_array($level, array_keys(Logger::getLevels()))) { $this->vbot->log->log($level, $str); } echo '['.Carbon::now()->toDateTimeString().']'."[{$level}] ".$str.PH...
php
{ "resource": "" }
q254856
Console.message
test
public function message($str) { if (array_get($this->config, 'message', true)) { $this->log($str, self::MESSAGE); } }
php
{ "resource": "" }
q254857
Text.send
test
public static function send($username, $word) { if (!$word || !$username) { return false; } return static::sendMsg([ 'Type' => 1, 'Content' => $word, 'FromUserName' => vbot('myself')->username, 'ToUserName' => $usern...
php
{ "resource": "" }
q254858
ContactFactory.fetchAllContacts
test
public function fetchAllContacts($seq = 0) { $url = sprintf($this->vbot->config['server.uri.base'].'/webwxgetcontact?pass_ticket=%s&skey=%s&r=%s&seq=%s', $this->vbot->config['server.passTicket'], $this->vbot->config['server.skey'], time(), $seq ); ...
php
{ "resource": "" }
q254859
ContactFactory.store
test
public function store($memberList) { foreach ($memberList as $contact) { if (in_array($contact['UserName'], static::SPECIAL_USERS)) { $this->vbot->specials->put($contact['UserName'], $contact); } elseif ($this->vbot->officials->isOfficial($contact['VerifyFlag'])) { ...
php
{ "resource": "" }
q254860
ContactFactory.fetchGroupMembers
test
public function fetchGroupMembers() { $url = sprintf($this->vbot->config['server.uri.base'].'/webwxbatchgetcontact?type=ex&r=%s&pass_ticket=%s', time(), $this->vbot->config['server.passTicket'] ); $list = []; $this->vbot->groups->each(function ($item, $key) use (&$list) ...
php
{ "resource": "" }
q254861
ContactFactory.storeMembers
test
private function storeMembers($array) { if (isset($array['ContactList']) && $array['ContactList']) { foreach ($array['ContactList'] as $group) { $groupAccount = $this->vbot->groups->get($group['UserName']); $groupAccount['MemberList'] = $group['MemberList']; ...
php
{ "resource": "" }
q254862
ExceptionHandler.report
test
public function report(Exception $e) { if ($this->shouldntReport($e)) { return true; } if ($this->handler) { call_user_func_array($this->handler, [$e]); } }
php
{ "resource": "" }
q254863
ExceptionHandler.throwFatalException
test
private function throwFatalException(Throwable $e) { foreach ($this->fatalException as $exception) { if ($e instanceof $exception) { throw $e; } } }
php
{ "resource": "" }
q254864
OpenSSL.validateKey
test
private function validateKey($key): void { if (! is_resource($key)) { throw new InvalidArgumentException( 'It was not possible to parse your key, reason: ' . openssl_error_string() ); } $details = openssl_pkey_get_details($key); assert(is_arra...
php
{ "resource": "" }
q254865
Parser.splitJwt
test
private function splitJwt(string $jwt): array { $data = explode('.', $jwt); if (count($data) !== 3) { throw new InvalidArgumentException('The JWT string must have two dots'); } return $data; }
php
{ "resource": "" }
q254866
Parser.parseHeader
test
private function parseHeader(string $data): array { $header = $this->decoder->jsonDecode($this->decoder->base64UrlDecode($data)); if (! is_array($header)) { throw new InvalidArgumentException('Headers must be an array'); } if (isset($header['enc'])) { throw ...
php
{ "resource": "" }
q254867
Parser.parseClaims
test
private function parseClaims(string $data): array { $claims = $this->decoder->jsonDecode($this->decoder->base64UrlDecode($data)); if (! is_array($claims)) { throw new InvalidArgumentException('Claims must be an array'); } if (isset($claims[RegisteredClaims::AUDIENCE])) ...
php
{ "resource": "" }
q254868
Parser.parseSignature
test
private function parseSignature(array $header, string $data): Signature { if ($data === '' || ! isset($header['alg']) || $header['alg'] === 'none') { return Signature::fromEmptyData(); } $hash = $this->decoder->base64UrlDecode($data); return new Signature($hash, $data);...
php
{ "resource": "" }
q254869
LanguageNegotiator.negotiateLanguage
test
public function negotiateLanguage() { $matches = $this->getMatchesFromAcceptedLanguages(); foreach ($matches as $key => $q) { $key = ($this->configRepository->get('laravellocalization.localesMapping')[$key]) ?? $key; if (!empty($this->supportedLanguages[$key])) { ...
php
{ "resource": "" }
q254870
LanguageNegotiator.getMatchesFromAcceptedLanguages
test
private function getMatchesFromAcceptedLanguages() { $matches = []; if ($acceptLanguages = $this->request->header('Accept-Language')) { $acceptLanguages = explode(',', $acceptLanguages); $generic_matches = []; foreach ($acceptLanguages as $option) { ...
php
{ "resource": "" }
q254871
RouteTranslationsCacheCommand.cacheRoutesPerLocale
test
protected function cacheRoutesPerLocale() { // Store the default routes cache, // this way the Application will detect that routes are cached. $allLocales = $this->getSupportedLocales(); array_push($allLocales, null); foreach ($allLocales as $locale) { $routes ...
php
{ "resource": "" }
q254872
RouteTranslationsCacheCommand.buildRouteCacheFile
test
protected function buildRouteCacheFile(RouteCollection $routes) { $stub = $this->files->get( realpath( __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARA...
php
{ "resource": "" }
q254873
LaravelLocalizationServiceProvider.registerBindings
test
protected function registerBindings() { $this->app->singleton(LaravelLocalization::class, function () { return new LaravelLocalization(); }); $this->app->alias(LaravelLocalization::class, 'laravellocalization'); }
php
{ "resource": "" }
q254874
LaravelLocalizationServiceProvider.registerCommands
test
protected function registerCommands() { $this->app->singleton('laravellocalizationroutecache.cache', Commands\RouteTranslationsCacheCommand::class); $this->app->singleton('laravellocalizationroutecache.clear', Commands\RouteTranslationsClearCommand::class); $this->app->singleton('laravelloca...
php
{ "resource": "" }
q254875
LaravelLocalization.setLocale
test
public function setLocale($locale = null) { if (empty($locale) || !\is_string($locale)) { // If the locale has not been passed through the function // it tries to get it from the first segment of the url $locale = $this->request->segment(1); // If the locale ...
php
{ "resource": "" }
q254876
LaravelLocalization.getURLFromRouteNameTranslated
test
public function getURLFromRouteNameTranslated($locale, $transKeyName, $attributes = [], $forceDefaultLocation = false) { if (!$this->checkLocaleInSupportedLocales($locale)) { throw new UnsupportedLocaleException('Locale \''.$locale.'\' is not in the list of supported locales.'); } ...
php
{ "resource": "" }
q254877
LaravelLocalization.getSupportedLocales
test
public function getSupportedLocales() { if (!empty($this->supportedLocales)) { return $this->supportedLocales; } $locales = $this->configRepository->get('laravellocalization.supportedLocales'); if (empty($locales) || !\is_array($locales)) { throw new Support...
php
{ "resource": "" }
q254878
LaravelLocalization.getLocalesOrder
test
public function getLocalesOrder() { $locales = $this->getSupportedLocales(); $order = $this->configRepository->get('laravellocalization.localesOrder'); uksort($locales, function ($a, $b) use ($order) { $pos_a = array_search($a, $order); $pos_b = array_search($b, $or...
php
{ "resource": "" }
q254879
LaravelLocalization.getCurrentLocaleDirection
test
public function getCurrentLocaleDirection() { if (!empty($this->supportedLocales[$this->getCurrentLocale()]['dir'])) { return $this->supportedLocales[$this->getCurrentLocale()]['dir']; } switch ($this->getCurrentLocaleScript()) { // Other (historic) RTL scripts exist...
php
{ "resource": "" }
q254880
LaravelLocalization.getCurrentLocale
test
public function getCurrentLocale() { if ($this->currentLocale) { return $this->currentLocale; } if ($this->useAcceptLanguageHeader() && !$this->app->runningInConsole()) { $negotiator = new LanguageNegotiator($this->defaultLocale, $this->getSupportedLocales(), $this->...
php
{ "resource": "" }
q254881
LaravelLocalization.getCurrentLocaleRegional
test
public function getCurrentLocaleRegional() { // need to check if it exists, since 'regional' has been added // after version 1.0.11 and existing users will not have it if (isset($this->supportedLocales[$this->getCurrentLocale()]['regional'])) { return $this->supportedLocales[$thi...
php
{ "resource": "" }
q254882
LaravelLocalization.checkLocaleInSupportedLocales
test
public function checkLocaleInSupportedLocales($locale) { $locales = $this->getSupportedLocales(); if ($locale !== false && empty($locales[$locale])) { return false; } return true; }
php
{ "resource": "" }
q254883
LaravelLocalization.getRouteNameFromAPath
test
public function getRouteNameFromAPath($path) { $attributes = $this->extractAttributes($path); $path = parse_url($path)['path']; $path = trim(str_replace('/'.$this->currentLocale.'/', '', $path), "/"); foreach ($this->translatedRoutes as $route) { if (trim($this->substit...
php
{ "resource": "" }
q254884
LaravelLocalization.findTranslatedRouteByPath
test
protected function findTranslatedRouteByPath($path, $url_locale) { // check if this url is a translated url foreach ($this->translatedRoutes as $translatedRoute) { if ($this->translator->trans($translatedRoute, [], $url_locale) == rawurldecode($path)) { return $translated...
php
{ "resource": "" }
q254885
LaravelLocalization.findTranslatedRouteByUrl
test
protected function findTranslatedRouteByUrl($url, $attributes, $locale) { if (empty($url)) { return false; } if (isset($this->cachedTranslatedRoutesByUrl[$locale][$url])) { return $this->cachedTranslatedRoutesByUrl[$locale][$url]; } // check if this ...
php
{ "resource": "" }
q254886
LaravelLocalization.createUrlFromUri
test
public function createUrlFromUri($uri) { $uri = ltrim($uri, '/'); if (empty($this->baseUrl)) { return app('url')->to($uri); } return $this->baseUrl.$uri; }
php
{ "resource": "" }
q254887
LaravelLocalization.normalizeAttributes
test
protected function normalizeAttributes($attributes) { if (array_key_exists('data', $attributes) && \is_array($attributes['data']) && ! \count($attributes['data'])) { $attributes['data'] = null; return $attributes; } return $attributes; }
php
{ "resource": "" }
q254888
LoadsTranslatedCachedRoutes.loadCachedRoutes
test
protected function loadCachedRoutes() { $localization = $this->getLaravelLocalization(); $localization->setLocale(); $locale = $localization->getCurrentLocale(); $localeKeys = $localization->getSupportedLanguagesKeys(); // First, try to load the routes specifically cached...
php
{ "resource": "" }
q254889
LoadsTranslatedCachedRoutes.makeLocaleRoutesPath
test
protected function makeLocaleRoutesPath($locale, $localeKeys) { $path = $this->getDefaultCachedRoutePath(); $localeSegment = request()->segment(1); if ( ! $localeSegment || ! in_array($localeSegment, $localeKeys)) { return $path; } return substr($path, 0, -4) . ...
php
{ "resource": "" }
q254890
Produce.encodeMessageSet
test
protected function encodeMessageSet(array $messages, int $compression = self::COMPRESSION_NONE): string { $data = ''; $next = 0; foreach ($messages as $message) { $encodedMessage = $this->encodeMessage($message); $data .= self::pack(self::BIT_B64, (string) $next) ...
php
{ "resource": "" }
q254891
Produce.encodeProducePartition
test
protected function encodeProducePartition(array $values, int $compression): string { if (! isset($values['partition_id'])) { throw new ProtocolException('given produce data invalid. `partition_id` is undefined.'); } if (! isset($values['messages']) || empty($values['messages']))...
php
{ "resource": "" }
q254892
Produce.encodeProduceTopic
test
protected function encodeProduceTopic(array $values, int $compression): string { if (! isset($values['topic_name'])) { throw new ProtocolException('given produce data invalid. `topic_name` is undefined.'); } if (! isset($values['partitions']) || empty($values['partitions'])) { ...
php
{ "resource": "" }
q254893
Produce.produceTopicPair
test
protected function produceTopicPair(string $data, int $version): array { $offset = 0; $topicInfo = $this->decodeString($data, self::BIT_B16); $offset += $topicInfo['length']; $ret = $this->decodeArray(substr($data, $offset), [$this, 'producePartitionPair'], $version); ...
php
{ "resource": "" }
q254894
Produce.producePartitionPair
test
protected function producePartitionPair(string $data, int $version): array { $offset = 0; $partitionId = self::unpack(self::BIT_B32, substr($data, $offset, 4)); $offset += 4; $errorCode = self::unpack(self::BIT_B16_SIGNED, substr($data, $offset, 2)); ...
php
{ "resource": "" }
q254895
Fetch.decodeMessageSet
test
protected function decodeMessageSet(string $data): ?array { if (strlen($data) <= 12) { return null; } $offset = 0; $roffset = self::unpack(self::BIT_B64, substr($data, $offset, 8)); $offset += 8; $messageSize = self::unpack(self::BIT_B32, sub...
php
{ "resource": "" }
q254896
Fetch.decodeMessage
test
protected function decodeMessage(string $data, int $messageSize): ?array { if ($messageSize === 0 || strlen($data) < $messageSize) { return null; } $offset = 0; $crc = self::unpack(self::BIT_B32, substr($data, $offset, 4)); $offset += 4; $magic = se...
php
{ "resource": "" }
q254897
CommonSocket.createSocket
test
protected function createSocket(string $remoteSocket, $context, ?int &$errno, ?string &$errstr) { return stream_socket_client( $remoteSocket, $errno, $errstr, $this->sendTimeoutSec + ($this->sendTimeoutUsec / 1000000), STREAM_CLIENT_CONNECT, ...
php
{ "resource": "" }
q254898
CommonSocket.select
test
protected function select(array $sockets, int $timeoutSec, int $timeoutUsec, bool $isRead = true) { $null = null; if ($isRead) { return @stream_select($sockets, $null, $null, $timeoutSec, $timeoutUsec); } return @stream_select($null, $sockets, $null, $timeoutSec, $timeo...
php
{ "resource": "" }
q254899
Protocol.unpack
test
public static function unpack(string $type, string $bytes) { self::checkLen($type, $bytes); if ($type === self::BIT_B64) { $set = unpack($type, $bytes); $result = ($set[1] & 0xFFFFFFFF) << 32 | ($set[2] & 0xFFFFFFFF); } elseif ($type === self::BIT_B16_SIGNED) { ...
php
{ "resource": "" }