code
stringlengths 17
247k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
protected function _log_response_code($http_code)
{
if ($this->_insert_id == '') {
return false;
}
$payload['response_code'] = $http_code;
return $this->rest->db->update(
$this->config->item('rest_logs_table'), $payload, [
'id' => $this->_insert_id,
]);
} | Updates the log table with HTTP response code
@author Justin Chen
@param $http_code int HTTP status code
@return bool TRUE log table updated; otherwise, FALSE | _log_response_code | php | RamonSilva20/mapos | application/libraries/REST_Controller.php | https://github.com/RamonSilva20/mapos/blob/master/application/libraries/REST_Controller.php | Apache-2.0 |
protected function _check_access()
{
// If we don't want to check access, just return TRUE
if ($this->config->item('rest_enable_access') === false) {
return true;
}
// Fetch controller based on path and controller name
$controller = implode(
'/', [
$this->router->directory,
$this->router->class,
]);
// Remove any double slashes for safety
$controller = str_replace('//', '/', $controller);
//check if the key has all_access
$accessRow = $this->rest->db
->where('key', $this->rest->key)
->where('controller', $controller)
->get($this->config->item('rest_access_table'))->row_array();
if (! empty($accessRow) && ! empty($accessRow['all_access'])) {
return true;
}
return false;
} | Check to see if the API key has access to the controller and methods
@return bool TRUE the API key has access; otherwise, FALSE | _check_access | php | RamonSilva20/mapos | application/libraries/REST_Controller.php | https://github.com/RamonSilva20/mapos/blob/master/application/libraries/REST_Controller.php | Apache-2.0 |
protected function setupImageManager()
{
$this->image = new ImageManager(['driver' => $this->getDriver()]);
} | Create a ImageManager instance. | setupImageManager | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function name($nameOrInitials)
{
$nameOrInitials = $this->translate($nameOrInitials);
$this->name = $nameOrInitials;
$this->initials_generator->name($nameOrInitials);
return $this;
} | Set the name used for generating initials.
@param string $nameOrInitials
@return $this | name | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function glyph($char)
{
$uChar = json_decode(sprintf('"\u%s"', $char), false);
$this->name($uChar);
return $this;
} | Transforms a unicode string to the proper format.
@param string $char the code to be converted (e.g., f007 would mean the "user" symbol)
@return $this | glyph | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function length($length = 2)
{
$this->initials_generator->length($length);
return $this;
} | Set the length of the generated initials.
@param int $length
@return $this | length | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function size($size)
{
$this->width = (int) $size;
$this->height = (int) $size;
return $this;
} | Set the avatar/image size in pixels.
@param int $size
@return $this | size | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function height($height)
{
$this->height = (int) $height;
return $this;
} | Set the avatar/image height in pixels.
@param int $height
@return $this | height | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function width($width)
{
$this->width = (int) $width;
return $this;
} | Set the avatar/image width in pixels.
@param int $width
@return $this | width | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function preferBold()
{
$this->preferBold = true;
return $this;
} | Prefer bold fonts (if possible).
@return $this | preferBold | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function preferRegular()
{
$this->preferBold = false;
return $this;
} | Prefer regular fonts (if possible).
@return $this | preferRegular | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function randomBackground($random = true, int $saturation = 85, int $luminance = 60)
{
$this->randomBgColor = (bool) $random;
if ($random) {
// Generate an initial random color
$this->generateRandomColor($saturation, $luminance);
}
return $this;
} | Set background color to be randomly generated for each avatar.
@param bool $random
@param int $saturation Saturation value (0-100)
@param int $luminance Luminance value (0-100)
@return $this | randomBackground | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function autoColor(bool $foreground = true, bool $background = true, int $saturation = 85, int $luminance = 60)
{
$hue = (crc32($this->name) % 360) / 360;
$saturation /= 100;
$luminance /= 100;
$this->bgColor = $this->convertHSLtoRGB($hue, $saturation, $luminance);
$this->fontColor = $this->getContrastColor($this->bgColor);
return $this;
} | Automatically set a font and/or background color based on the supplied name.
@param bool $foreground
@param bool $background
@return $this | autoColor | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function font($font)
{
$this->fontFile = $font;
return $this;
} | Set the font file by path or int (1-5).
@param string|int $font
@return $this | font | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function fontName($name)
{
$this->fontName = $name;
return $this;
} | Set the font name.
Example: "Open Sans"
@param string $name
@return $this | fontName | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function rounded($rounded = true)
{
$this->rounded = (bool) $rounded;
return $this;
} | Set if should make a round image or not.
@param bool $rounded
@return $this | rounded | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function autoFont($autofont = true)
{
$this->autofont = (bool) $autofont;
return $this;
} | Set if should detect character script
and use a font that supports it.
@param bool $autofont
@return $this | autoFont | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function smooth($smooth = true)
{
$this->smooth = (bool) $smooth;
return $this;
} | Set if should make a rounding smoother with a resizing hack.
@param bool $smooth
@return $this | smooth | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function keepCase($keepCase = true)
{
$this->keepCase = (bool) $keepCase;
return $this;
} | Set if should skip uppercasing the name.
@param bool $keepCase
@return $this | keepCase | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function allowSpecialCharacters($allowSpecialCharacters = true)
{
$this->allowSpecialCharacters = (bool) $allowSpecialCharacters;
return $this;
} | Set if should allow (or remove) special characters.
@param bool $allowSpecialCharacters
@return $this | allowSpecialCharacters | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function fontSize($size = 0.5)
{
$this->fontSize = (float) round($size, 2);
return $this;
} | Set the font size in percentage
(0.1 = 10%).
@param float $size
@return $this | fontSize | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getInitials()
{
return $this->initials_generator->keepCase($this->getKeepCase())
->allowSpecialCharacters($this->getAllowSpecialCharacters())
->name($this->name)
->getInitials();
} | Will return the generated initials.
@return string | getInitials | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getBackgroundColor()
{
if ($this->randomBgColor) {
// Generate a new random color each time this method is called
$this->generateRandomColor();
}
return $this->bgColor;
} | Will return the background color parameter.
If randomBgColor is enabled, generates a new random color each time.
@return string | getBackgroundColor | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getRandomBackgroundColor()
{
return $this->randomBgColor;
} | Will return whether random background color is enabled.
@return bool | getRandomBackgroundColor | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getColor()
{
return $this->fontColor;
} | Will return the font color parameter.
@return string | getColor | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getFontSize()
{
return $this->fontSize;
} | Will return the font size parameter.
@return float | getFontSize | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getFontFile()
{
return $this->fontFile;
} | Will return the font file parameter.
@return string|int | getFontFile | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getFontName()
{
return $this->fontName;
} | Will return the font name parameter for SVGs.
@return string | getFontName | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getRounded()
{
return $this->rounded;
} | Will return the round parameter.
@return bool | getRounded | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getSmooth()
{
return $this->smooth;
} | Will return the smooth parameter.
@return bool | getSmooth | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getKeepCase()
{
return $this->keepCase;
} | Will return the keepCase parameter.
@return bool | getKeepCase | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getAllowSpecialCharacters()
{
return $this->allowSpecialCharacters;
} | Will return the allowSpecialCharacters parameter.
@return bool | getAllowSpecialCharacters | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function getAutoFont()
{
return $this->autofont;
} | Will return the autofont parameter.
@return bool | getAutoFont | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function language($language)
{
$this->language = $language ?: 'en';
return $this;
} | Set language of name, pls use `language` before `name`, just like
```php
$avatar->language('en')->name('Mr Green'); // Right
$avatar->name('Mr Green')->language('en'); // Wrong
```.
@param string $language
@return $this | language | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
protected function getTranslator()
{
if ($this->translator instanceof Base && $this->translator->getSourceLanguage() === $this->language) {
return $this->translator;
}
$translatorClass = array_key_exists($this->language, $this->translatorMap) ? $this->translatorMap[$this->language] : 'LasseRafn\\InitialAvatarGenerator\\Translator\\En';
return $this->translator = new $translatorClass();
} | Instance the translator by language.
@return Base | getTranslator | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
protected function getContrastColor($hexColor)
{
// hexColor RGB
$R1 = hexdec(substr($hexColor, 1, 2));
$G1 = hexdec(substr($hexColor, 3, 2));
$B1 = hexdec(substr($hexColor, 5, 2));
// Black RGB
$blackColor = '#000000';
$R2BlackColor = hexdec(substr($blackColor, 1, 2));
$G2BlackColor = hexdec(substr($blackColor, 3, 2));
$B2BlackColor = hexdec(substr($blackColor, 5, 2));
// Calc contrast ratio
$L1 = 0.2126 * pow($R1 / 255, 2.2) +
0.7152 * pow($G1 / 255, 2.2) +
0.0722 * pow($B1 / 255, 2.2);
$L2 = 0.2126 * pow($R2BlackColor / 255, 2.2) +
0.7152 * pow($G2BlackColor / 255, 2.2) +
0.0722 * pow($B2BlackColor / 255, 2.2);
$contrastRatio = 0;
if ($L1 > $L2) {
$contrastRatio = (int) (($L1 + 0.05) / ($L2 + 0.05));
} else {
$contrastRatio = (int) (($L2 + 0.05) / ($L1 + 0.05));
}
// If contrast is more than 5, return black color
if ($contrastRatio > 5) {
return '#000000';
} else {
// if not, return white color.
return '#FFFFFF';
}
} | Get contrasting foreground color for autoColor background. | getContrastColor | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
protected function generateRandomColor(int $saturation = 85, int $luminance = 60)
{
// Generate a random hue (0-1)
$hue = mt_rand(0, 359) / 360;
$saturation /= 100;
$luminance /= 100;
$hexColor = $this->convertHSLtoRGB($hue, $saturation, $luminance);
$this->bgColor = $hexColor;
$this->fontColor = $this->getContrastColor($hexColor);
return $hexColor;
} | Generate a random background color.
@param int $saturation Saturation value (0-100)
@param int $luminance Luminance value (0-100)
@return string The generated hex color | generateRandomColor | php | LasseRafn/php-initial-avatar-generator | src/InitialAvatar.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/InitialAvatar.php | MIT |
public function __construct()
{
$this->inherent = new Pinyin();
} | ZhCN constructor, set the instance of PinYin. | __construct | php | LasseRafn/php-initial-avatar-generator | src/Translator/ZhCN.php | https://github.com/LasseRafn/php-initial-avatar-generator/blob/master/src/Translator/ZhCN.php | MIT |
public function setHtmlCompressOptions($value)
{
return $this;
} | @param $value array options for compressing output result
* extra - use more compact algorithm
* no-comments - cut all the html comments
@return $this
@deprecated >= 1.4 | setHtmlCompressOptions | php | skeeks-semenov/yii2-assets-auto-compress | src/AssetsAutoCompressComponent.php | https://github.com/skeeks-semenov/yii2-assets-auto-compress/blob/master/src/AssetsAutoCompressComponent.php | BSD-3-Clause |
private function scheduleTimer(TimerInterface $timer)
{
$flags = Event::TIMEOUT;
if ($timer->isPeriodic()) {
$flags |= Event::PERSIST;
}
$event = new Event($this->eventBase, -1, $flags, $this->timerCallback, $timer);
$this->timerEvents[$timer] = $event;
$event->add($timer->getInterval());
} | Schedule a timer for execution.
@param TimerInterface $timer | scheduleTimer | php | reactphp/event-loop | src/ExtEventLoop.php | https://github.com/reactphp/event-loop/blob/master/src/ExtEventLoop.php | MIT |
private function createTimerCallback()
{
$this->timerCallback = function ($_, $__, $timer) {
\call_user_func($timer->getCallback(), $timer);
if (!$timer->isPeriodic() && $this->timerEvents->contains($timer)) {
$this->cancelTimer($timer);
}
};
} | Create a callback used as the target of timer events.
A reference is kept to the callback for the lifetime of the loop
to prevent "Cannot destroy active lambda function" fatal error from
the event extension. | createTimerCallback | php | reactphp/event-loop | src/ExtEventLoop.php | https://github.com/reactphp/event-loop/blob/master/src/ExtEventLoop.php | MIT |
private function createStreamCallback()
{
$this->streamCallback = function ($stream, $flags) {
$key = (int) $stream;
if (Event::READ === (Event::READ & $flags) && isset($this->readListeners[$key])) {
\call_user_func($this->readListeners[$key], $stream);
}
if (Event::WRITE === (Event::WRITE & $flags) && isset($this->writeListeners[$key])) {
\call_user_func($this->writeListeners[$key], $stream);
}
};
} | Create a callback used as the target of stream events.
A reference is kept to the callback for the lifetime of the loop
to prevent "Cannot destroy active lambda function" fatal error from
the event extension. | createStreamCallback | php | reactphp/event-loop | src/ExtEventLoop.php | https://github.com/reactphp/event-loop/blob/master/src/ExtEventLoop.php | MIT |
public static function set(LoopInterface $loop)
{
self::$instance = $loop;
} | Internal undocumented method, behavior might change or throw in the
future. Use with caution and at your own risk.
@internal
@return void | set | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function addReadStream($stream, $listener)
{
(self::$instance ?? self::get())->addReadStream($stream, $listener);
} | [Advanced] Register a listener to be notified when a stream is ready to read.
@param resource $stream
@param callable $listener
@return void
@throws \Exception
@see LoopInterface::addReadStream() | addReadStream | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function addWriteStream($stream, $listener)
{
(self::$instance ?? self::get())->addWriteStream($stream, $listener);
} | [Advanced] Register a listener to be notified when a stream is ready to write.
@param resource $stream
@param callable $listener
@return void
@throws \Exception
@see LoopInterface::addWriteStream() | addWriteStream | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function removeReadStream($stream)
{
if (self::$instance !== null) {
self::$instance->removeReadStream($stream);
}
} | Remove the read event listener for the given stream.
@param resource $stream
@return void
@see LoopInterface::removeReadStream() | removeReadStream | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function removeWriteStream($stream)
{
if (self::$instance !== null) {
self::$instance->removeWriteStream($stream);
}
} | Remove the write event listener for the given stream.
@param resource $stream
@return void
@see LoopInterface::removeWriteStream() | removeWriteStream | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function addTimer($interval, $callback)
{
return (self::$instance ?? self::get())->addTimer($interval, $callback);
} | Enqueue a callback to be invoked once after the given interval.
@param float $interval
@param callable $callback
@return TimerInterface
@see LoopInterface::addTimer() | addTimer | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function addPeriodicTimer($interval, $callback)
{
return (self::$instance ?? self::get())->addPeriodicTimer($interval, $callback);
} | Enqueue a callback to be invoked repeatedly after the given interval.
@param float $interval
@param callable $callback
@return TimerInterface
@see LoopInterface::addPeriodicTimer() | addPeriodicTimer | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function futureTick($listener)
{
(self::$instance ?? self::get())->futureTick($listener);
} | Schedule a callback to be invoked on a future tick of the event loop.
@param callable $listener
@return void
@see LoopInterface::futureTick() | futureTick | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function addSignal($signal, $listener)
{
(self::$instance ?? self::get())->addSignal($signal, $listener);
} | Register a listener to be notified when a signal has been caught by this process.
@param int $signal
@param callable $listener
@return void
@see LoopInterface::addSignal() | addSignal | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function removeSignal($signal, $listener)
{
if (self::$instance !== null) {
self::$instance->removeSignal($signal, $listener);
}
} | Removes a previously added signal listener.
@param int $signal
@param callable $listener
@return void
@see LoopInterface::removeSignal() | removeSignal | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function run()
{
(self::$instance ?? self::get())->run();
} | Run the event loop until there are no more tasks to perform.
@return void
@see LoopInterface::run() | run | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public static function stop()
{
self::$stopped = true;
if (self::$instance !== null) {
self::$instance->stop();
}
} | Instruct a running event loop to stop.
@return void
@see LoopInterface::stop() | stop | php | reactphp/event-loop | src/Loop.php | https://github.com/reactphp/event-loop/blob/master/src/Loop.php | MIT |
public function __construct($interval, $callback, $periodic = false)
{
if ($interval < self::MIN_INTERVAL) {
$interval = self::MIN_INTERVAL;
}
$this->interval = (float) $interval;
$this->callback = $callback;
$this->periodic = (bool) $periodic;
} | Constructor initializes the fields of the Timer
@param float $interval The interval after which this timer will execute, in seconds
@param callable $callback The callback that will be executed when this timer elapses
@param bool $periodic Whether the time is periodic | __construct | php | reactphp/event-loop | src/Timer/Timer.php | https://github.com/reactphp/event-loop/blob/master/src/Timer/Timer.php | MIT |
public function add($listener)
{
$this->queue->enqueue($listener);
} | Add a callback to be invoked on a future tick of the event loop.
Callbacks are guaranteed to be executed in the order they are enqueued.
@param callable $listener The callback to invoke. | add | php | reactphp/event-loop | src/Tick/FutureTickQueue.php | https://github.com/reactphp/event-loop/blob/master/src/Tick/FutureTickQueue.php | MIT |
public function isEmpty()
{
return $this->queue->isEmpty();
} | Check if the next tick queue is empty.
@return boolean | isEmpty | php | reactphp/event-loop | src/Tick/FutureTickQueue.php | https://github.com/reactphp/event-loop/blob/master/src/Tick/FutureTickQueue.php | MIT |
protected function forkSendSignal($signal)
{
$currentPid = posix_getpid();
$childPid = pcntl_fork();
if ($childPid == -1) {
$this->fail("Failed to fork child process!");
} else if ($childPid === 0) {
// this is executed in the child process
usleep(20000);
posix_kill($currentPid, constant($signal));
die();
}
} | fork child process to send signal to current process id | forkSendSignal | php | reactphp/event-loop | tests/StreamSelectLoopTest.php | https://github.com/reactphp/event-loop/blob/master/tests/StreamSelectLoopTest.php | MIT |
public function numberOfTests()
{
return [[], [], []];
} | Run several tests several times to ensure we reset the loop between tests and code is still behavior as expected.
@return array<array> | numberOfTests | php | reactphp/event-loop | tests/LoopTest.php | https://github.com/reactphp/event-loop/blob/master/tests/LoopTest.php | MIT |
private function subAddReadStreamReceivesDataFromStreamReference()
{
list ($input, $output) = $this->createSocketPair();
fwrite($input, 'hello');
fclose($input);
$this->loop->addReadStream($output, function ($output) {
$chunk = fread($output, 1024);
if ($chunk === '') {
$this->received .= 'X';
$this->loop->removeReadStream($output);
fclose($output);
} else {
$this->received .= '[' . $chunk . ']';
}
});
} | Helper for above test. This happens in another helper method to verify
the loop keeps track of assigned stream resources (refcount). | subAddReadStreamReceivesDataFromStreamReference | php | reactphp/event-loop | tests/AbstractLoopTest.php | https://github.com/reactphp/event-loop/blob/master/tests/AbstractLoopTest.php | MIT |
function output()
{
return app()->get('output');
} | Get cli console output object.
@return OutputInterface | output | php | fastdlabs/fastD | helpers.php | https://github.com/fastdlabs/fastD/blob/master/helpers.php | MIT |
protected function getConnection()
{
try {
return $this->createDefaultDBConnection(database($this->connection)->pdo);
} catch (\Exception $exception) {
return null;
}
} | Returns the test database connection.
@return \PHPUnit_Extensions_Database_DB_IDatabaseConnection|null | getConnection | php | fastdlabs/fastD | src/TestCase.php | https://github.com/fastdlabs/fastD/blob/master/src/TestCase.php | MIT |
protected function write(array $record = [])
{
$record['context'] = $this->logContextFormat();
parent::write($record);
} | Writes the record down to the log of the implementing handler.
@param array $record | write | php | fastdlabs/fastD | src/Logger/HandlerAbstract.php | https://github.com/fastdlabs/fastD/blob/master/src/Logger/HandlerAbstract.php | MIT |
protected function configure()
{
$this->setName('process');
$this->addArgument('process', InputArgument::OPTIONAL, 'process name');
$this->addArgument('action', InputArgument::OPTIONAL, 'process action, <comment>status|start|stop</comment>', 'status');
$this->addOption('pid', '-p', InputOption::VALUE_OPTIONAL, 'set process pid path.');
$this->addOption('name', null, InputOption::VALUE_OPTIONAL, 'set process name.', null);
$this->addOption('daemon', '-d', InputOption::VALUE_NONE, 'set process daemonize.');
$this->setDescription('Create new processor.');
} | php bin/console process {name} {args} {options}. | configure | php | fastdlabs/fastD | src/Process/ProcessManager.php | https://github.com/fastdlabs/fastD/blob/master/src/Process/ProcessManager.php | MIT |
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
} | Get a validator for an incoming registration request.
@return \Illuminate\Contracts\Validation\Validator | validator | php | larajournal/larajournal | app/Http/Controllers/Auth/RegisterController.php | https://github.com/larajournal/larajournal/blob/master/app/Http/Controllers/Auth/RegisterController.php | MIT |
protected function create(array $data)
{
/** @phpstan-ignore-next-line */
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
} | Create a new user instance after a valid registration.
@return User | create | php | larajournal/larajournal | app/Http/Controllers/Auth/RegisterController.php | https://github.com/larajournal/larajournal/blob/master/app/Http/Controllers/Auth/RegisterController.php | MIT |
public function fetchUsing(...$fetchUsing)
{
$this->fetchUsing = $fetchUsing;
return $this;
} | Specify arguments for the PDOStatement::fetchAll / fetch functions.
@param mixed ...$fetchUsing
@return $this | fetchUsing | php | illuminate/database | Query/Builder.php | https://github.com/illuminate/database/blob/master/Query/Builder.php | MIT |
public static function trim(int|float $number)
{
return json_decode(json_encode($number));
} | Remove any trailing zero digits after the decimal point of the given number.
@param int|float $number
@return int|float | trim | php | laravel/framework | src/Illuminate/Support/Number.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Number.php | MIT |
public static function withCurrency(string $currency, callable $callback)
{
$previousCurrency = static::$currency;
static::useCurrency($currency);
return tap($callback(), fn () => static::useCurrency($previousCurrency));
} | Execute the given callback using the given currency.
@param string $currency
@param callable $callback
@return mixed | withCurrency | php | laravel/framework | src/Illuminate/Support/Number.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Number.php | MIT |
protected static function ensureIntlExtensionIsInstalled()
{
if (! extension_loaded('intl')) {
$method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2)[1]['function'];
throw new RuntimeException('The "intl" PHP extension is required to use the ['.$method.'] method.');
}
} | Ensure the "intl" PHP extension is installed.
@return void | ensureIntlExtensionIsInstalled | php | laravel/framework | src/Illuminate/Support/Number.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Number.php | MIT |
public function __construct(protected Uri $uri)
{
//
} | Create a new URI query string instance. | __construct | php | laravel/framework | src/Illuminate/Support/UriQueryString.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/UriQueryString.php | MIT |
protected function data($key = null, $default = null)
{
return $this->get($key, $default);
} | Retrieve data from the instance.
@param string|null $key
@param mixed $default
@return mixed | data | php | laravel/framework | src/Illuminate/Support/UriQueryString.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/UriQueryString.php | MIT |
public function toArray()
{
return QueryString::extract($this->value());
} | Convert the query string into an array. | toArray | php | laravel/framework | src/Illuminate/Support/UriQueryString.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/UriQueryString.php | MIT |
function blank($value)
{
if (is_null($value)) {
return true;
}
if (is_string($value)) {
return trim($value) === '';
}
if (is_numeric($value) || is_bool($value)) {
return false;
}
if ($value instanceof Model) {
return false;
}
if ($value instanceof Countable) {
return count($value) === 0;
}
if ($value instanceof Stringable) {
return trim((string) $value) === '';
}
return empty($value);
} | Determine if the given value is "blank".
@phpstan-assert-if-false !=null|'' $value
@phpstan-assert-if-true !=numeric|bool $value
@param mixed $value
@return bool | blank | php | laravel/framework | src/Illuminate/Support/helpers.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php | MIT |
function fluent($value)
{
return new Fluent($value);
} | Create a Fluent object from the given value.
@param object|array $value
@return \Illuminate\Support\Fluent | fluent | php | laravel/framework | src/Illuminate/Support/helpers.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php | MIT |
function literal(...$arguments)
{
if (count($arguments) === 1 && array_is_list($arguments)) {
return $arguments[0];
}
return (object) $arguments;
} | Return a new literal or anonymous object using named arguments.
@return \stdClass | literal | php | laravel/framework | src/Illuminate/Support/helpers.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php | MIT |
function laravel_cloud()
{
return ($_ENV['LARAVEL_CLOUD'] ?? false) === '1' ||
($_SERVER['LARAVEL_CLOUD'] ?? false) === '1';
} | Determine if the application is running on Laravel Cloud.
@return bool | laravel_cloud | php | laravel/framework | src/Illuminate/Support/helpers.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php | MIT |
function once(callable $callback)
{
$onceable = Onceable::tryFromTrace(
debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, 2),
$callback,
);
return $onceable ? Once::instance()->value($onceable) : call_user_func($callback);
} | Ensures a callable is only called once, and returns the result on subsequent calls.
@template TReturnType
@param callable(): TReturnType $callback
@return TReturnType | once | php | laravel/framework | src/Illuminate/Support/helpers.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php | MIT |
function retry($times, callable $callback, $sleepMilliseconds = 0, $when = null)
{
$attempts = 0;
$backoff = [];
if (is_array($times)) {
$backoff = $times;
$times = count($times) + 1;
}
beginning:
$attempts++;
$times--;
try {
return $callback($attempts);
} catch (Throwable $e) {
if ($times < 1 || ($when && ! $when($e))) {
throw $e;
}
$sleepMilliseconds = $backoff[$attempts - 1] ?? $sleepMilliseconds;
if ($sleepMilliseconds) {
Sleep::usleep(value($sleepMilliseconds, $attempts, $e) * 1000);
}
goto beginning;
}
} | Retry an operation a given number of times.
@template TValue
@param int|array<int, int> $times
@param callable(int): TValue $callback
@param int|\Closure(int, \Throwable): int $sleepMilliseconds
@param (callable(\Throwable): bool)|null $when
@return TValue
@throws \Throwable | retry | php | laravel/framework | src/Illuminate/Support/helpers.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php | MIT |
function str($string = null)
{
if (func_num_args() === 0) {
return new class
{
public function __call($method, $parameters)
{
return Str::$method(...$parameters);
}
public function __toString()
{
return '';
}
};
}
return new SupportStringable($string);
} | Get a new stringable object from the given string.
@param string|null $string
@return ($string is null ? object : \Illuminate\Support\Stringable) | str | php | laravel/framework | src/Illuminate/Support/helpers.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/helpers.php | MIT |
protected function replaceConfigRecursivelyFrom($path, $key)
{
if (! ($this->app instanceof CachesConfiguration && $this->app->configurationIsCached())) {
$config = $this->app->make('config');
$config->set($key, array_replace_recursive(
require $path, $config->get($key, [])
));
}
} | Replace the given configuration with the existing configuration recursively.
@param string $path
@param string $key
@return void | replaceConfigRecursivelyFrom | php | laravel/framework | src/Illuminate/Support/ServiceProvider.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ServiceProvider.php | MIT |
protected function loadTranslationsFrom($path, $namespace = null)
{
$this->callAfterResolving('translator', fn ($translator) => is_null($namespace)
? $translator->addPath($path)
: $translator->addNamespace($namespace, $path));
} | Register a translation file namespace or path.
@param string $path
@param string|null $namespace
@return void | loadTranslationsFrom | php | laravel/framework | src/Illuminate/Support/ServiceProvider.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ServiceProvider.php | MIT |
protected function publishesMigrations(array $paths, $groups = null)
{
$this->publishes($paths, $groups);
if ($this->app->config->get('database.migrations.update_date_on_publish', false)) {
static::$publishableMigrationPaths = array_unique(array_merge(static::$publishableMigrationPaths, array_keys($paths)));
}
} | Register migration paths to be published by the publish command.
@param array $paths
@param mixed $groups
@return void | publishesMigrations | php | laravel/framework | src/Illuminate/Support/ServiceProvider.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ServiceProvider.php | MIT |
public static function publishableMigrationPaths()
{
return static::$publishableMigrationPaths;
} | Get the migration paths available for publishing.
@return array | publishableMigrationPaths | php | laravel/framework | src/Illuminate/Support/ServiceProvider.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ServiceProvider.php | MIT |
protected function optimizes(?string $optimize = null, ?string $clear = null, ?string $key = null)
{
$key ??= (string) Str::of(get_class($this))
->classBasename()
->before('ServiceProvider')
->kebab()
->lower()
->trim();
if (empty($key)) {
$key = class_basename(get_class($this));
}
if ($optimize) {
static::$optimizeCommands[$key] = $optimize;
}
if ($clear) {
static::$optimizeClearCommands[$key] = $clear;
}
} | Register commands that should run on "optimize" or "optimize:clear".
@param string|null $optimize
@param string|null $clear
@param string|null $key
@return void | optimizes | php | laravel/framework | src/Illuminate/Support/ServiceProvider.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ServiceProvider.php | MIT |
public static function addProviderToBootstrapFile(string $provider, ?string $path = null)
{
$path ??= app()->getBootstrapProvidersPath();
if (! file_exists($path)) {
return false;
}
if (function_exists('opcache_invalidate')) {
opcache_invalidate($path, true);
}
$providers = (new Collection(require $path))
->merge([$provider])
->unique()
->sort()
->values()
->map(fn ($p) => ' '.$p.'::class,')
->implode(PHP_EOL);
$content = '<?php
return [
'.$providers.'
];';
file_put_contents($path, $content.PHP_EOL);
return true;
} | Add the given provider to the application's provider bootstrap file.
@param string $provider
@param string $path
@return bool | addProviderToBootstrapFile | php | laravel/framework | src/Illuminate/Support/ServiceProvider.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ServiceProvider.php | MIT |
protected function getPrimaryOptions($url)
{
return array_filter([
'driver' => $this->getDriver($url),
'database' => $this->getDatabase($url),
'host' => $url['host'] ?? null,
'port' => $url['port'] ?? null,
'username' => $url['user'] ?? null,
'password' => $url['pass'] ?? null,
], fn ($value) => ! is_null($value));
} | Get the primary database connection options.
@param array $url
@return array | getPrimaryOptions | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
protected function getDriver($url)
{
$alias = $url['scheme'] ?? null;
if (! $alias) {
return;
}
return static::$driverAliases[$alias] ?? $alias;
} | Get the database driver from the URL.
@param array $url
@return string|null | getDriver | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
protected function getDatabase($url)
{
$path = $url['path'] ?? null;
return $path && $path !== '/' ? substr($path, 1) : null;
} | Get the database name from the URL.
@param array $url
@return string|null | getDatabase | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
protected function getQueryOptions($url)
{
$queryString = $url['query'] ?? null;
if (! $queryString) {
return [];
}
$query = [];
parse_str($queryString, $query);
return $this->parseStringsToNativeTypes($query);
} | Get all of the additional database options from the query string.
@param array $url
@return array | getQueryOptions | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
protected function parseUrl($url)
{
$url = preg_replace('#^(sqlite3?):///#', '$1://null/', $url);
$parsedUrl = parse_url($url);
if ($parsedUrl === false) {
throw new InvalidArgumentException('The database configuration URL is malformed.');
}
return $parsedUrl;
} | Parse the string URL to an array of components.
@param string $url
@return array
@throws \InvalidArgumentException | parseUrl | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
protected function parseStringsToNativeTypes($value)
{
if (is_array($value)) {
return array_map($this->parseStringsToNativeTypes(...), $value);
}
if (! is_string($value)) {
return $value;
}
$parsedValue = json_decode($value, true);
if (json_last_error() === JSON_ERROR_NONE) {
return $parsedValue;
}
return $value;
} | Convert string casted values to their native types.
@param mixed $value
@return mixed | parseStringsToNativeTypes | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
public static function getDriverAliases()
{
return static::$driverAliases;
} | Get all of the current drivers' aliases.
@return array | getDriverAliases | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
public static function addDriverAlias($alias, $driver)
{
static::$driverAliases[$alias] = $driver;
} | Add the given driver alias to the driver aliases array.
@param string $alias
@param string $driver
@return void | addDriverAlias | php | laravel/framework | src/Illuminate/Support/ConfigurationUrlParser.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/ConfigurationUrlParser.php | MIT |
public static function after($subject, $search)
{
return $search === '' ? $subject : array_reverse(explode($search, $subject, 2))[0];
} | Return the remainder of a string after the first occurrence of a given value.
@param string $subject
@param string $search
@return string | after | php | laravel/framework | src/Illuminate/Support/Str.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php | MIT |
public static function ascii($value, $language = 'en')
{
return ASCII::to_ascii((string) $value, $language, replace_single_chars_only: false);
} | Transliterate a UTF-8 value to ASCII.
@param string $value
@param string $language
@return string | ascii | php | laravel/framework | src/Illuminate/Support/Str.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php | MIT |
public static function transliterate($string, $unknown = '?', $strict = false)
{
return ASCII::to_transliterate($string, $unknown, $strict);
} | Transliterate a string to its closest ASCII representation.
@param string $string
@param string|null $unknown
@param bool|null $strict
@return string | transliterate | php | laravel/framework | src/Illuminate/Support/Str.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php | MIT |
public static function before($subject, $search)
{
if ($search === '') {
return $subject;
}
$result = strstr($subject, (string) $search, true);
return $result === false ? $subject : $result;
} | Get the portion of a string before the first occurrence of a given value.
@param string $subject
@param string $search
@return string | before | php | laravel/framework | src/Illuminate/Support/Str.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php | MIT |
public static function betweenFirst($subject, $from, $to)
{
if ($from === '' || $to === '') {
return $subject;
}
return static::before(static::after($subject, $from), $to);
} | Get the smallest possible portion of a string between two given values.
@param string $subject
@param string $from
@param string $to
@return string | betweenFirst | php | laravel/framework | src/Illuminate/Support/Str.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php | MIT |
public static function charAt($subject, $index)
{
$length = mb_strlen($subject);
if ($index < 0 ? $index < -$length : $index > $length - 1) {
return false;
}
return mb_substr($subject, $index, 1);
} | Get the character at the specified index.
@param string $subject
@param int $index
@return string|false | charAt | php | laravel/framework | src/Illuminate/Support/Str.php | https://github.com/laravel/framework/blob/master/src/Illuminate/Support/Str.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.