repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
desarrolla2/Cache
src/AbstractCache.php
AbstractCache.assertKey
protected function assertKey($key): void { if (!is_string($key)) { $type = (is_object($key) ? get_class($key) . ' ' : '') . gettype($key); throw new InvalidArgumentException("Expected key to be a string, not $type"); } if ($key === '' || preg_match('~[{}()/\\\\@:]~', $key)) { throw new InvalidArgumentException("Invalid key '$key'"); } }
php
protected function assertKey($key): void { if (!is_string($key)) { $type = (is_object($key) ? get_class($key) . ' ' : '') . gettype($key); throw new InvalidArgumentException("Expected key to be a string, not $type"); } if ($key === '' || preg_match('~[{}()/\\\\@:]~', $key)) { throw new InvalidArgumentException("Invalid key '$key'"); } }
[ "protected", "function", "assertKey", "(", "$", "key", ")", ":", "void", "{", "if", "(", "!", "is_string", "(", "$", "key", ")", ")", "{", "$", "type", "=", "(", "is_object", "(", "$", "key", ")", "?", "get_class", "(", "$", "key", ")", ".", "'...
Validate the key @param string $key @return void @throws InvalidArgumentException
[ "Validate", "the", "key" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L99-L109
train
desarrolla2/Cache
src/AbstractCache.php
AbstractCache.assertIterable
protected function assertIterable($subject, $msg): void { $iterable = function_exists('is_iterable') ? is_iterable($subject) : is_array($subject) || $subject instanceof Traversable; if (!$iterable) { throw new InvalidArgumentException($msg); } }
php
protected function assertIterable($subject, $msg): void { $iterable = function_exists('is_iterable') ? is_iterable($subject) : is_array($subject) || $subject instanceof Traversable; if (!$iterable) { throw new InvalidArgumentException($msg); } }
[ "protected", "function", "assertIterable", "(", "$", "subject", ",", "$", "msg", ")", ":", "void", "{", "$", "iterable", "=", "function_exists", "(", "'is_iterable'", ")", "?", "is_iterable", "(", "$", "subject", ")", ":", "is_array", "(", "$", "subject", ...
Assert that the keys are an array or traversable @param iterable $subject @param string $msg @return void @throws InvalidArgumentException if subject are not iterable
[ "Assert", "that", "the", "keys", "are", "an", "array", "or", "traversable" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L119-L128
train
desarrolla2/Cache
src/AbstractCache.php
AbstractCache.keyToId
protected function keyToId($key): string { $this->assertKey($key); return sprintf('%s%s', $this->prefix, $key); }
php
protected function keyToId($key): string { $this->assertKey($key); return sprintf('%s%s', $this->prefix, $key); }
[ "protected", "function", "keyToId", "(", "$", "key", ")", ":", "string", "{", "$", "this", "->", "assertKey", "(", "$", "key", ")", ";", "return", "sprintf", "(", "'%s%s'", ",", "$", "this", "->", "prefix", ",", "$", "key", ")", ";", "}" ]
Turn the key into a cache identifier @param string $key @return string @throws InvalidArgumentException
[ "Turn", "the", "key", "into", "a", "cache", "identifier" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L137-L142
train
desarrolla2/Cache
src/AbstractCache.php
AbstractCache.mapKeysToIds
protected function mapKeysToIds($keys): array { $this->assertIterable($keys, 'keys not iterable'); $map = []; foreach ($keys as $key) { $id = $this->keyToId($key); $map[$id] = $key; } return $map; }
php
protected function mapKeysToIds($keys): array { $this->assertIterable($keys, 'keys not iterable'); $map = []; foreach ($keys as $key) { $id = $this->keyToId($key); $map[$id] = $key; } return $map; }
[ "protected", "function", "mapKeysToIds", "(", "$", "keys", ")", ":", "array", "{", "$", "this", "->", "assertIterable", "(", "$", "keys", ",", "'keys not iterable'", ")", ";", "$", "map", "=", "[", "]", ";", "foreach", "(", "$", "keys", "as", "$", "k...
Create a map with keys and ids @param iterable $keys @return array @throws InvalidArgumentException
[ "Create", "a", "map", "with", "keys", "and", "ids" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L151-L163
train
desarrolla2/Cache
src/AbstractCache.php
AbstractCache.ttlToSeconds
protected function ttlToSeconds($ttl): ?int { if (!isset($ttl)) { return $this->ttl; } if ($ttl instanceof DateInterval) { $reference = new DateTimeImmutable(); $endTime = $reference->add($ttl); $ttl = $endTime->getTimestamp() - $reference->getTimestamp(); } if (!is_int($ttl)) { $type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl); throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type"); } return isset($this->ttl) ? min($ttl, $this->ttl) : $ttl; }
php
protected function ttlToSeconds($ttl): ?int { if (!isset($ttl)) { return $this->ttl; } if ($ttl instanceof DateInterval) { $reference = new DateTimeImmutable(); $endTime = $reference->add($ttl); $ttl = $endTime->getTimestamp() - $reference->getTimestamp(); } if (!is_int($ttl)) { $type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl); throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type"); } return isset($this->ttl) ? min($ttl, $this->ttl) : $ttl; }
[ "protected", "function", "ttlToSeconds", "(", "$", "ttl", ")", ":", "?", "int", "{", "if", "(", "!", "isset", "(", "$", "ttl", ")", ")", "{", "return", "$", "this", "->", "ttl", ";", "}", "if", "(", "$", "ttl", "instanceof", "DateInterval", ")", ...
Convert TTL to seconds from now @param null|int|DateInterval $ttl @return int|null @throws InvalidArgumentException
[ "Convert", "TTL", "to", "seconds", "from", "now" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L252-L271
train
desarrolla2/Cache
src/AbstractCache.php
AbstractCache.ttlToTimestamp
protected function ttlToTimestamp($ttl): ?int { if (!isset($ttl)) { return isset($this->ttl) ? time() + $this->ttl : null; } if (is_int($ttl)) { return time() + (isset($this->ttl) ? min($ttl, $this->ttl) : $ttl); } if ($ttl instanceof DateInterval) { $timestamp = (new DateTimeImmutable())->add($ttl)->getTimestamp(); return isset($this->ttl) ? min($timestamp, time() + $this->ttl) : $timestamp; } $type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl); throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type"); }
php
protected function ttlToTimestamp($ttl): ?int { if (!isset($ttl)) { return isset($this->ttl) ? time() + $this->ttl : null; } if (is_int($ttl)) { return time() + (isset($this->ttl) ? min($ttl, $this->ttl) : $ttl); } if ($ttl instanceof DateInterval) { $timestamp = (new DateTimeImmutable())->add($ttl)->getTimestamp(); return isset($this->ttl) ? min($timestamp, time() + $this->ttl) : $timestamp; } $type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl); throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type"); }
[ "protected", "function", "ttlToTimestamp", "(", "$", "ttl", ")", ":", "?", "int", "{", "if", "(", "!", "isset", "(", "$", "ttl", ")", ")", "{", "return", "isset", "(", "$", "this", "->", "ttl", ")", "?", "time", "(", ")", "+", "$", "this", "->"...
Convert TTL to epoch timestamp @param null|int|DateInterval $ttl @return int|null @throws InvalidArgumentException
[ "Convert", "TTL", "to", "epoch", "timestamp" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L280-L298
train
desarrolla2/Cache
src/Mysqli.php
Mysqli.initialize
protected function initialize() { if ($this->initialized !== false) { return; } $this->query( "CREATE TABLE IF NOT EXISTS `{table}` " . "( `key` VARCHAR(255), `value` TEXT, `ttl` INT UNSIGNED, PRIMARY KEY (`key`) )" ); $this->query( "CREATE EVENT IF NOT EXISTS `apply_ttl_{$this->table}` ON SCHEDULE EVERY 1 HOUR DO BEGIN" . " DELETE FROM {table} WHERE `ttl` < NOW();" . " END" ); $this->initialized = true; }
php
protected function initialize() { if ($this->initialized !== false) { return; } $this->query( "CREATE TABLE IF NOT EXISTS `{table}` " . "( `key` VARCHAR(255), `value` TEXT, `ttl` INT UNSIGNED, PRIMARY KEY (`key`) )" ); $this->query( "CREATE EVENT IF NOT EXISTS `apply_ttl_{$this->table}` ON SCHEDULE EVERY 1 HOUR DO BEGIN" . " DELETE FROM {table} WHERE `ttl` < NOW();" . " END" ); $this->initialized = true; }
[ "protected", "function", "initialize", "(", ")", "{", "if", "(", "$", "this", "->", "initialized", "!==", "false", ")", "{", "return", ";", "}", "$", "this", "->", "query", "(", "\"CREATE TABLE IF NOT EXISTS `{table}` \"", ".", "\"( `key` VARCHAR(255), `value` TEX...
Initialize table. Automatically delete old cache.
[ "Initialize", "table", ".", "Automatically", "delete", "old", "cache", "." ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Mysqli.php#L60-L78
train
desarrolla2/Cache
src/Mysqli.php
Mysqli.query
protected function query($query, ...$params) { $saveParams = array_map([$this, 'quote'], $params); $baseSql = str_replace('{table}', $this->table, $query); $sql = vsprintf($baseSql, $saveParams); $ret = $this->server->query($sql); if ($ret === false) { trigger_error($this->server->error . " $sql", E_USER_NOTICE); } return $ret; }
php
protected function query($query, ...$params) { $saveParams = array_map([$this, 'quote'], $params); $baseSql = str_replace('{table}', $this->table, $query); $sql = vsprintf($baseSql, $saveParams); $ret = $this->server->query($sql); if ($ret === false) { trigger_error($this->server->error . " $sql", E_USER_NOTICE); } return $ret; }
[ "protected", "function", "query", "(", "$", "query", ",", "...", "$", "params", ")", "{", "$", "saveParams", "=", "array_map", "(", "[", "$", "this", ",", "'quote'", "]", ",", "$", "params", ")", ";", "$", "baseSql", "=", "str_replace", "(", "'{table...
Query the MySQL server @param string $query @param mixed[] $params @return \mysqli_result|false
[ "Query", "the", "MySQL", "server" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Mysqli.php#L266-L280
train
desarrolla2/Cache
src/Mysqli.php
Mysqli.quote
protected function quote($value) { if ($value === null) { return 'NULL'; } if (is_array($value)) { return join(', ', array_map([$this, 'quote'], $value)); } return is_string($value) ? ('"' . $this->server->real_escape_string($value) . '"') : (is_float($value) ? (float)$value : (int)$value); }
php
protected function quote($value) { if ($value === null) { return 'NULL'; } if (is_array($value)) { return join(', ', array_map([$this, 'quote'], $value)); } return is_string($value) ? ('"' . $this->server->real_escape_string($value) . '"') : (is_float($value) ? (float)$value : (int)$value); }
[ "protected", "function", "quote", "(", "$", "value", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "return", "'NULL'", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "return", "join", "(", "', '", ",", "array_map",...
Quote a value to be used in an array @param mixed $value @return mixed
[ "Quote", "a", "value", "to", "be", "used", "in", "an", "array" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Mysqli.php#L288-L301
train
desarrolla2/Cache
src/Predis.php
Predis.execCommand
protected function execCommand(string $cmd, ...$args) { $command = $this->predis->createCommand($cmd, $args); $response = $this->predis->executeCommand($command); if ($response instanceof ErrorInterface) { return false; } if ($response instanceof Status) { return $response->getPayload() === 'OK'; } return $response; }
php
protected function execCommand(string $cmd, ...$args) { $command = $this->predis->createCommand($cmd, $args); $response = $this->predis->executeCommand($command); if ($response instanceof ErrorInterface) { return false; } if ($response instanceof Status) { return $response->getPayload() === 'OK'; } return $response; }
[ "protected", "function", "execCommand", "(", "string", "$", "cmd", ",", "...", "$", "args", ")", "{", "$", "command", "=", "$", "this", "->", "predis", "->", "createCommand", "(", "$", "cmd", ",", "$", "args", ")", ";", "$", "response", "=", "$", "...
Run a predis command. @param string $cmd @param mixed @return mixed|bool
[ "Run", "a", "predis", "command", "." ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Predis.php#L70-L84
train
desarrolla2/Cache
src/MongoDB.php
MongoDB.filter
protected function filter($key) { if (is_array($key)) { $key = ['$in' => $key]; } return [ '_id' => $key, '$or' => [ ['ttl' => ['$gt' => new BSONUTCDateTime($this->currentTimestamp() * 1000)]], ['ttl' => null] ] ]; }
php
protected function filter($key) { if (is_array($key)) { $key = ['$in' => $key]; } return [ '_id' => $key, '$or' => [ ['ttl' => ['$gt' => new BSONUTCDateTime($this->currentTimestamp() * 1000)]], ['ttl' => null] ] ]; }
[ "protected", "function", "filter", "(", "$", "key", ")", "{", "if", "(", "is_array", "(", "$", "key", ")", ")", "{", "$", "key", "=", "[", "'$in'", "=>", "$", "key", "]", ";", "}", "return", "[", "'_id'", "=>", "$", "key", ",", "'$or'", "=>", ...
Get filter for key and ttl. @param string|iterable $key @return array
[ "Get", "filter", "for", "key", "and", "ttl", "." ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/MongoDB.php#L74-L87
train
desarrolla2/Cache
src/MongoDB.php
MongoDB.getTtlBSON
protected function getTtlBSON($ttl): ?BSONUTCDatetime { return isset($ttl) ? new BSONUTCDateTime($this->ttlToTimestamp($ttl) * 1000) : null; }
php
protected function getTtlBSON($ttl): ?BSONUTCDatetime { return isset($ttl) ? new BSONUTCDateTime($this->ttlToTimestamp($ttl) * 1000) : null; }
[ "protected", "function", "getTtlBSON", "(", "$", "ttl", ")", ":", "?", "BSONUTCDatetime", "{", "return", "isset", "(", "$", "ttl", ")", "?", "new", "BSONUTCDateTime", "(", "$", "this", "->", "ttlToTimestamp", "(", "$", "ttl", ")", "*", "1000", ")", ":"...
Get TTL as Date type BSON object @param null|int|DateInterval $ttl @return BSONUTCDatetime|null
[ "Get", "TTL", "as", "Date", "type", "BSON", "object" ]
e25b51fe0f9b386161c9c35e1d591f587617fcfa
https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/MongoDB.php#L269-L272
train
fpoirotte/pssht
src/Transport.php
Transport.setAddress
public function setAddress($address) { if (!is_string($address)) { throw new \InvalidArgumentException(); } if ($this->address !== null) { throw new \RuntimeException(); } $this->address = $address; return $this; }
php
public function setAddress($address) { if (!is_string($address)) { throw new \InvalidArgumentException(); } if ($this->address !== null) { throw new \RuntimeException(); } $this->address = $address; return $this; }
[ "public", "function", "setAddress", "(", "$", "address", ")", "{", "if", "(", "!", "is_string", "(", "$", "address", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "if", "(", "$", "this", "->", "address", "!==", ...
Set the IP address of the client associated with this transport layer. \param string $address IP address of the client. \retval Transport Returns this transport layer. \note This method is intended for use with hostbased authentication methods. Moreover, this method may only be called once. Subsequent calls will result in a RuntimeException being raised.
[ "Set", "the", "IP", "address", "of", "the", "client", "associated", "with", "this", "transport", "layer", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L213-L225
train
fpoirotte/pssht
src/Transport.php
Transport.updateWriteStats
public function updateWriteStats($written) { if (!is_int($written)) { throw new \InvalidArgumentException('Not an integer'); } $time = time(); $this->context['rekeyingBytes'] += $written; if (isset($this->context['rekeying'])) { // Do not restart key exchange // if already rekeying. return; } $logging = \Plop\Plop::getInstance(); $stats = array( 'bytes' => $this->context['rekeyingBytes'], 'duration' => $time - $this->context['rekeyingTime'] + $this->rekeyingTime, ); $logging->debug( '%(bytes)d bytes sent in %(duration)d seconds', $stats ); if ($this->context['rekeyingBytes'] >= $this->rekeyingBytes || $time >= $this->context['rekeyingTime']) { $logging->debug('Initiating rekeying'); $this->context['rekeying'] = 'server'; $this->context['rekeyingBytes'] = 0; $this->context['rekeyingTime'] = $time + $this->rekeyingTime; $kexinit = new \fpoirotte\Pssht\Handlers\InitialState(); $kexinit->handleKEXINIT($this, $this->context); } }
php
public function updateWriteStats($written) { if (!is_int($written)) { throw new \InvalidArgumentException('Not an integer'); } $time = time(); $this->context['rekeyingBytes'] += $written; if (isset($this->context['rekeying'])) { // Do not restart key exchange // if already rekeying. return; } $logging = \Plop\Plop::getInstance(); $stats = array( 'bytes' => $this->context['rekeyingBytes'], 'duration' => $time - $this->context['rekeyingTime'] + $this->rekeyingTime, ); $logging->debug( '%(bytes)d bytes sent in %(duration)d seconds', $stats ); if ($this->context['rekeyingBytes'] >= $this->rekeyingBytes || $time >= $this->context['rekeyingTime']) { $logging->debug('Initiating rekeying'); $this->context['rekeying'] = 'server'; $this->context['rekeyingBytes'] = 0; $this->context['rekeyingTime'] = $time + $this->rekeyingTime; $kexinit = new \fpoirotte\Pssht\Handlers\InitialState(); $kexinit->handleKEXINIT($this, $this->context); } }
[ "public", "function", "updateWriteStats", "(", "$", "written", ")", "{", "if", "(", "!", "is_int", "(", "$", "written", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Not an integer'", ")", ";", "}", "$", "time", "=", "time", "("...
Update statistics about the number of bytes written to the client. \param int $written Number of additional bytes written. \return This method does not return anything.
[ "Update", "statistics", "about", "the", "number", "of", "bytes", "written", "to", "the", "client", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L251-L287
train
fpoirotte/pssht
src/Transport.php
Transport.setCompressor
public function setCompressor(\fpoirotte\Pssht\CompressionInterface $compressor) { if ($compressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_COMPRESS) { throw new \InvalidArgumentException(); } $this->compressor = $compressor; return $this; }
php
public function setCompressor(\fpoirotte\Pssht\CompressionInterface $compressor) { if ($compressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_COMPRESS) { throw new \InvalidArgumentException(); } $this->compressor = $compressor; return $this; }
[ "public", "function", "setCompressor", "(", "\\", "fpoirotte", "\\", "Pssht", "\\", "CompressionInterface", "$", "compressor", ")", "{", "if", "(", "$", "compressor", "->", "getMode", "(", ")", "!==", "\\", "fpoirotte", "\\", "Pssht", "\\", "CompressionInterfa...
Set the object used to compress outgoing packets. \param fpoirotte::Pssht::CompressionInterface $compressor Outgoing packets' compressor. \retval Transport Return this transport layer.
[ "Set", "the", "object", "used", "to", "compress", "outgoing", "packets", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L331-L339
train
fpoirotte/pssht
src/Transport.php
Transport.setUncompressor
public function setUncompressor(\fpoirotte\Pssht\CompressionInterface $uncompressor) { if ($uncompressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_UNCOMPRESS) { throw new \InvalidArgumentException(); } $this->uncompressor = $uncompressor; return $this; }
php
public function setUncompressor(\fpoirotte\Pssht\CompressionInterface $uncompressor) { if ($uncompressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_UNCOMPRESS) { throw new \InvalidArgumentException(); } $this->uncompressor = $uncompressor; return $this; }
[ "public", "function", "setUncompressor", "(", "\\", "fpoirotte", "\\", "Pssht", "\\", "CompressionInterface", "$", "uncompressor", ")", "{", "if", "(", "$", "uncompressor", "->", "getMode", "(", ")", "!==", "\\", "fpoirotte", "\\", "Pssht", "\\", "CompressionI...
Set the object used to uncompress incoming packets. \param fpoirotte::Pssht::CompressionInterface $uncompressor Incoming packets' uncompressor. \retval Transport Return this transport layer.
[ "Set", "the", "object", "used", "to", "uncompress", "incoming", "packets", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L361-L369
train
fpoirotte/pssht
src/Transport.php
Transport.getHandler
public function getHandler($type) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } if (isset($this->handlers[$type])) { return $this->handlers[$type]; } return null; }
php
public function getHandler($type) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } if (isset($this->handlers[$type])) { return $this->handlers[$type]; } return null; }
[ "public", "function", "getHandler", "(", "$", "type", ")", "{", "if", "(", "!", "is_int", "(", "$", "type", ")", "||", "$", "type", "<", "0", "||", "$", "type", ">", "255", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", ...
Retrieve the current handler for a given message type. \param int $type Message type. \retval fpoirotte::Pssht::HandlerInterface Handler associated with the given message type. \retval null There is no handler currently registered for the given message type.
[ "Retrieve", "the", "current", "handler", "for", "a", "given", "message", "type", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L547-L557
train
fpoirotte/pssht
src/Transport.php
Transport.setHandler
public function setHandler($type, \fpoirotte\Pssht\HandlerInterface $handler) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } $this->handlers[$type] = $handler; return $this; }
php
public function setHandler($type, \fpoirotte\Pssht\HandlerInterface $handler) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } $this->handlers[$type] = $handler; return $this; }
[ "public", "function", "setHandler", "(", "$", "type", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "HandlerInterface", "$", "handler", ")", "{", "if", "(", "!", "is_int", "(", "$", "type", ")", "||", "$", "type", "<", "0", "||", "$", "type", ">", "...
Register a handler for a specific SSH message type. \param int $type Message type. \param fpoirotte::Pssht::HandlerInterface $handler Handler to register for that message type. \retval Transport Returns this transport layer. \note The given handler will overwrite any previously registered handler for that message type.
[ "Register", "a", "handler", "for", "a", "specific", "SSH", "message", "type", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L575-L583
train
fpoirotte/pssht
src/Transport.php
Transport.unsetHandler
public function unsetHandler($type, \fpoirotte\Pssht\HandlerInterface $handler) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } if (isset($this->handlers[$type]) && $this->handlers[$type] === $handler) { unset($this->handlers[$type]); } return $this; }
php
public function unsetHandler($type, \fpoirotte\Pssht\HandlerInterface $handler) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } if (isset($this->handlers[$type]) && $this->handlers[$type] === $handler) { unset($this->handlers[$type]); } return $this; }
[ "public", "function", "unsetHandler", "(", "$", "type", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "HandlerInterface", "$", "handler", ")", "{", "if", "(", "!", "is_int", "(", "$", "type", ")", "||", "$", "type", "<", "0", "||", "$", "type", ">", ...
Unregister a handler for a specific SSH message type. \param int $type Message type. \param fpoirotte::Pssht::HandlerInterface $handler Handler to unregister for that message type. \retval Transport Returns this transport layer.
[ "Unregister", "a", "handler", "for", "a", "specific", "SSH", "message", "type", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L597-L607
train
fpoirotte/pssht
src/Application/EchoService.php
EchoService.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\CHANNEL\DATA::unserialize($decoder); $channel = $message->getChannel(); $response = new \fpoirotte\Pssht\Messages\CHANNEL\DATA($channel, $message->getData()); $transport->writeMessage($response); return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\CHANNEL\DATA::unserialize($decoder); $channel = $message->getChannel(); $response = new \fpoirotte\Pssht\Messages\CHANNEL\DATA($channel, $message->getData()); $transport->writeMessage($response); return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_CHANNEL_DATA = 94
[ "SSH_MSG_CHANNEL_DATA", "=", "94" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Application/EchoService.php#L24-L35
train
fpoirotte/pssht
src/Handlers/DEBUG.php
DEBUG.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\DEBUG::unserialize($decoder); if ($message->mustAlwaysDisplay()) { echo escape($message->getMessage()) . PHP_EOL; } return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\DEBUG::unserialize($decoder); if ($message->mustAlwaysDisplay()) { echo escape($message->getMessage()) . PHP_EOL; } return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_DEBUG = 4
[ "SSH_MSG_DEBUG", "=", "4" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/DEBUG.php#L20-L31
train
fpoirotte/pssht
src/KeyStore.php
KeyStore.getIdentifier
protected function getIdentifier(\fpoirotte\Pssht\PublicKeyInterface $key) { $encoder = new \fpoirotte\Pssht\Wire\Encoder(); $key->serialize($encoder); return $encoder->getBuffer()->get(0); }
php
protected function getIdentifier(\fpoirotte\Pssht\PublicKeyInterface $key) { $encoder = new \fpoirotte\Pssht\Wire\Encoder(); $key->serialize($encoder); return $encoder->getBuffer()->get(0); }
[ "protected", "function", "getIdentifier", "(", "\\", "fpoirotte", "\\", "Pssht", "\\", "PublicKeyInterface", "$", "key", ")", "{", "$", "encoder", "=", "new", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Encoder", "(", ")", ";", "$", "key", "->...
Return the identifier for a key. \param fpoirotte::Pssht::PublicKeyInterface $key Public or private key. \retval string SSH identifier for the key.
[ "Return", "the", "identifier", "for", "a", "key", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L39-L44
train
fpoirotte/pssht
src/KeyStore.php
KeyStore.add
public function add($user, \fpoirotte\Pssht\PublicKeyInterface $key) { if (!is_string($user)) { throw new \InvalidArgumentException(); } $this->keys[$user][$this->getIdentifier($key)] = $key; }
php
public function add($user, \fpoirotte\Pssht\PublicKeyInterface $key) { if (!is_string($user)) { throw new \InvalidArgumentException(); } $this->keys[$user][$this->getIdentifier($key)] = $key; }
[ "public", "function", "add", "(", "$", "user", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "PublicKeyInterface", "$", "key", ")", "{", "if", "(", "!", "is_string", "(", "$", "user", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ...
Add a new key in the store. \param string $user User the key belongs to. \param fpoirotte::Pssht::PublicKeyInterface $key Public/private key to add.
[ "Add", "a", "new", "key", "in", "the", "store", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L55-L62
train
fpoirotte/pssht
src/KeyStore.php
KeyStore.get
public function get($user) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!isset($this->keys[$user])) { return new \ArrayIterator(); } return new \ArrayIterator($this->keys[$user]); }
php
public function get($user) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!isset($this->keys[$user])) { return new \ArrayIterator(); } return new \ArrayIterator($this->keys[$user]); }
[ "public", "function", "get", "(", "$", "user", ")", "{", "if", "(", "!", "is_string", "(", "$", "user", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "keys", ...
Retrieve a list of the keys currently stored for the given user. \param string $user User whose keys should be retrieved. \retval array Public/private keys for the given user.
[ "Retrieve", "a", "list", "of", "the", "keys", "currently", "stored", "for", "the", "given", "user", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L92-L103
train
fpoirotte/pssht
src/KeyStore.php
KeyStore.exists
public function exists($user, $key) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if ($key instanceof \fpoirotte\Pssht\PublicKeyInterface) { $key = $this->getIdentifier($key); } if (!is_string($key)) { throw new \InvalidArgumentException(); } return isset($this->keys[$user][$key]); }
php
public function exists($user, $key) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if ($key instanceof \fpoirotte\Pssht\PublicKeyInterface) { $key = $this->getIdentifier($key); } if (!is_string($key)) { throw new \InvalidArgumentException(); } return isset($this->keys[$user][$key]); }
[ "public", "function", "exists", "(", "$", "user", ",", "$", "key", ")", "{", "if", "(", "!", "is_string", "(", "$", "user", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "if", "(", "$", "key", "instanceof", "\...
Test whether a given key as been registered for a specific user. \param string $user User for which the key is tested. \param string|fpoirotte::Pssht::PublicKeyInterface $key Key to test. \retval bool \c true if the given key has been registered for the given user, \c false otherwise.
[ "Test", "whether", "a", "given", "key", "as", "been", "registered", "for", "a", "specific", "user", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L119-L133
train
fpoirotte/pssht
src/KeyStore.php
KeyStore.count
public function count($user) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!isset($this->keys[$user])) { return 0; } return count($this->keys[$user]); }
php
public function count($user) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!isset($this->keys[$user])) { return 0; } return count($this->keys[$user]); }
[ "public", "function", "count", "(", "$", "user", ")", "{", "if", "(", "!", "is_string", "(", "$", "user", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "keys", ...
Return the number of keys currently registered for the given user. \param string $user User whose keys must be counted. \retval int Number of available keys for the given user.
[ "Return", "the", "number", "of", "keys", "currently", "registered", "for", "the", "given", "user", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L145-L156
train
fpoirotte/pssht
src/Handlers/CHANNEL/REQUEST.php
REQUEST.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $encoder = new \fpoirotte\Pssht\Wire\Encoder(); $channel = $decoder->decodeUint32(); $type = $decoder->decodeString(); $wantsReply = $decoder->decodeBoolean(); $encoder->encodeUint32($channel); $encoder->encodeString($type); $encoder->encodeBoolean($wantsReply); $decoder->getBuffer()->unget($encoder->getBuffer()->get(0)); $remoteChannel = $this->connection->getChannel($channel); switch ($type) { case 'exec': case 'shell': case 'pty-req': // Normalize the name. // Eg. "pty-req" becomes "PtyReq". $cls = str_replace(' ', '', ucwords(str_replace('-', ' ', $type))); $cls = '\\fpoirotte\\Pssht\\Messages\\CHANNEL\\REQUEST\\' . $cls; $message = $cls::unserialize($decoder); break; default: if ($wantsReply) { $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel); $transport->writeMessage($response); } return true; } if (!$wantsReply) { return true; } if (in_array($type, array('shell', 'exec'), true)) { $response = new \fpoirotte\Pssht\Messages\CHANNEL\SUCCESS($remoteChannel); } else { $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel); } $transport->writeMessage($response); if (in_array($type, array('shell', 'exec'), true)) { $callable = $transport->getApplicationFactory(); if ($callable !== null) { call_user_func($callable, $transport, $this->connection, $message); } } return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $encoder = new \fpoirotte\Pssht\Wire\Encoder(); $channel = $decoder->decodeUint32(); $type = $decoder->decodeString(); $wantsReply = $decoder->decodeBoolean(); $encoder->encodeUint32($channel); $encoder->encodeString($type); $encoder->encodeBoolean($wantsReply); $decoder->getBuffer()->unget($encoder->getBuffer()->get(0)); $remoteChannel = $this->connection->getChannel($channel); switch ($type) { case 'exec': case 'shell': case 'pty-req': // Normalize the name. // Eg. "pty-req" becomes "PtyReq". $cls = str_replace(' ', '', ucwords(str_replace('-', ' ', $type))); $cls = '\\fpoirotte\\Pssht\\Messages\\CHANNEL\\REQUEST\\' . $cls; $message = $cls::unserialize($decoder); break; default: if ($wantsReply) { $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel); $transport->writeMessage($response); } return true; } if (!$wantsReply) { return true; } if (in_array($type, array('shell', 'exec'), true)) { $response = new \fpoirotte\Pssht\Messages\CHANNEL\SUCCESS($remoteChannel); } else { $response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel); } $transport->writeMessage($response); if (in_array($type, array('shell', 'exec'), true)) { $callable = $transport->getApplicationFactory(); if ($callable !== null) { call_user_func($callable, $transport, $this->connection, $message); } } return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_CHANNEL_REQUEST = 98
[ "SSH_MSG_CHANNEL_REQUEST", "=", "98" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/CHANNEL/REQUEST.php#L20-L75
train
fpoirotte/pssht
src/Handlers/KEXDH/INIT.php
INIT.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $hostAlgo = null; foreach ($context['kex']['client']->getServerHostKeyAlgos() as $algo) { if (isset($context['serverKeys'][$algo])) { $hostAlgo = $algo; break; } } if ($hostAlgo === null) { throw new \RuntimeException(); } $response = $this->createResponse($decoder, $transport, $context, $hostAlgo); $logging = \Plop\Plop::getInstance(); $secret = gmp_strval($response->getSharedSecret(), 16); $logging->debug( "Shared secret:\r\n%s", array( wordwrap($secret, 16, ' ', true) ) ); $logging->debug( 'Hash: %s', array( wordwrap(bin2hex($response->getExchangeHash()), 16, ' ', true) ) ); if (!isset($context['sessionIdentifier'])) { $context['sessionIdentifier'] = $response->getExchangeHash(); } $context['DH'] = $response; $transport->writeMessage($response); return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $hostAlgo = null; foreach ($context['kex']['client']->getServerHostKeyAlgos() as $algo) { if (isset($context['serverKeys'][$algo])) { $hostAlgo = $algo; break; } } if ($hostAlgo === null) { throw new \RuntimeException(); } $response = $this->createResponse($decoder, $transport, $context, $hostAlgo); $logging = \Plop\Plop::getInstance(); $secret = gmp_strval($response->getSharedSecret(), 16); $logging->debug( "Shared secret:\r\n%s", array( wordwrap($secret, 16, ' ', true) ) ); $logging->debug( 'Hash: %s', array( wordwrap(bin2hex($response->getExchangeHash()), 16, ' ', true) ) ); if (!isset($context['sessionIdentifier'])) { $context['sessionIdentifier'] = $response->getExchangeHash(); } $context['DH'] = $response; $transport->writeMessage($response); return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_KEXDH_INIT = 30
[ "SSH_MSG_KEXDH_INIT", "=", "30" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/KEXDH/INIT.php#L20-L60
train
fpoirotte/pssht
src/Handlers/USERAUTH/REQUEST.php
REQUEST.failure
protected function failure( \fpoirotte\Pssht\Transport $transport, array &$context, $partial = false ) { if (!is_bool($partial)) { throw new \InvalidArgumentException(); } $remaining = $context['authMethods']; unset($remaining['none']); $remaining = array_keys($remaining); $response = new \fpoirotte\Pssht\Messages\USERAUTH\FAILURE($remaining, $partial); $transport->writeMessage($response); return true; }
php
protected function failure( \fpoirotte\Pssht\Transport $transport, array &$context, $partial = false ) { if (!is_bool($partial)) { throw new \InvalidArgumentException(); } $remaining = $context['authMethods']; unset($remaining['none']); $remaining = array_keys($remaining); $response = new \fpoirotte\Pssht\Messages\USERAUTH\FAILURE($remaining, $partial); $transport->writeMessage($response); return true; }
[ "protected", "function", "failure", "(", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ",", "$", "partial", "=", "false", ")", "{", "if", "(", "!", "is_bool", "(", "$", "partial", ")", ")", ...
Report an authentication failure. \param fpoirotte::Pssht::Transport $transport Transport layer used to report the failure. \param array &$context SSH session context (containing authentication methods that may continue). \param bool $partial (optional) Indicates whether the request ended with a partial success (\b true) or not (\b false). If omitted, \b false is implied. \retval true This method always returns true.
[ "Report", "an", "authentication", "failure", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/USERAUTH/REQUEST.php#L165-L180
train
fpoirotte/pssht
src/Handlers/SERVICE/REQUEST.php
REQUEST.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\SERVICE\REQUEST::unserialize($decoder); $service = $message->getServiceName(); if ($service === 'ssh-userauth') { $response = new \fpoirotte\Pssht\Messages\SERVICE\ACCEPT($service); $transport->setHandler( \fpoirotte\Pssht\Messages\USERAUTH\REQUEST\Base::getMessageId(), $this->userAuthRequestHandler ); } else { $response = new DISCONNECT( DISCONNECT::SSH_DISCONNECT_SERVICE_NOT_AVAILABLE, 'No such service' ); } $transport->writeMessage($response); return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\SERVICE\REQUEST::unserialize($decoder); $service = $message->getServiceName(); if ($service === 'ssh-userauth') { $response = new \fpoirotte\Pssht\Messages\SERVICE\ACCEPT($service); $transport->setHandler( \fpoirotte\Pssht\Messages\USERAUTH\REQUEST\Base::getMessageId(), $this->userAuthRequestHandler ); } else { $response = new DISCONNECT( DISCONNECT::SSH_DISCONNECT_SERVICE_NOT_AVAILABLE, 'No such service' ); } $transport->writeMessage($response); return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_SERVICE_REQUEST = 5
[ "SSH_MSG_SERVICE_REQUEST", "=", "5" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/SERVICE/REQUEST.php#L36-L59
train
fpoirotte/pssht
src/Connection.php
Connection.allocateChannel
public function allocateChannel(\fpoirotte\Pssht\Messages\CHANNEL\OPEN $message) { for ($i = 0; isset($this->channels[$i]); ++$i) { // Do nothing. } $this->channels[$i] = $message->getChannel(); $this->handlers[$i] = array(); return $i; }
php
public function allocateChannel(\fpoirotte\Pssht\Messages\CHANNEL\OPEN $message) { for ($i = 0; isset($this->channels[$i]); ++$i) { // Do nothing. } $this->channels[$i] = $message->getChannel(); $this->handlers[$i] = array(); return $i; }
[ "public", "function", "allocateChannel", "(", "\\", "fpoirotte", "\\", "Pssht", "\\", "Messages", "\\", "CHANNEL", "\\", "OPEN", "$", "message", ")", "{", "for", "(", "$", "i", "=", "0", ";", "isset", "(", "$", "this", "->", "channels", "[", "$", "i"...
Allocate a new communication channel. \param fpoirotte::Pssht::Messages::CHANNEL::OPEN $message Original message requesting channel allocation. \return int Newly allocated channel's identifier.
[ "Allocate", "a", "new", "communication", "channel", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L93-L101
train
fpoirotte/pssht
src/Connection.php
Connection.freeChannel
public function freeChannel($id) { if (!is_int($id)) { throw new \InvalidArgumentException(); } unset($this->channels[$id]); unset($this->handlers[$id]); return $this; }
php
public function freeChannel($id) { if (!is_int($id)) { throw new \InvalidArgumentException(); } unset($this->channels[$id]); unset($this->handlers[$id]); return $this; }
[ "public", "function", "freeChannel", "(", "$", "id", ")", "{", "if", "(", "!", "is_int", "(", "$", "id", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "unset", "(", "$", "this", "->", "channels", "[", "$", "id...
Free a channel allocation. \param int $id Channel identifier. \retval Connection Returns this connection.
[ "Free", "a", "channel", "allocation", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L112-L121
train
fpoirotte/pssht
src/Connection.php
Connection.getChannel
public function getChannel($message) { if (is_int($message)) { return $this->channels[$message]; } return $this->channels[$message->getChannel()]; }
php
public function getChannel($message) { if (is_int($message)) { return $this->channels[$message]; } return $this->channels[$message->getChannel()]; }
[ "public", "function", "getChannel", "(", "$", "message", ")", "{", "if", "(", "is_int", "(", "$", "message", ")", ")", "{", "return", "$", "this", "->", "channels", "[", "$", "message", "]", ";", "}", "return", "$", "this", "->", "channels", "[", "...
Retrieve the channel associated with a message. \param int|fpoirotte::Pssht::Messages::CHANNEL::REQUEST::Base $message Either a message or the message's channel identifier. \retval int Remote channel associated with the message.
[ "Retrieve", "the", "channel", "associated", "with", "a", "message", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L132-L138
train
fpoirotte/pssht
src/Connection.php
Connection.setHandler
public function setHandler( $message, $type, \fpoirotte\Pssht\HandlerInterface $handler ) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } if (!is_int($message)) { if (!($message instanceof \fpoirotte\Pssht\Messages\CHANNEL\REQUEST\Base)) { throw new \InvalidArgumentException(); } $message = $message->getChannel(); } $this->handlers[$message][$type] = $handler; return $this; }
php
public function setHandler( $message, $type, \fpoirotte\Pssht\HandlerInterface $handler ) { if (!is_int($type) || $type < 0 || $type > 255) { throw new \InvalidArgumentException(); } if (!is_int($message)) { if (!($message instanceof \fpoirotte\Pssht\Messages\CHANNEL\REQUEST\Base)) { throw new \InvalidArgumentException(); } $message = $message->getChannel(); } $this->handlers[$message][$type] = $handler; return $this; }
[ "public", "function", "setHandler", "(", "$", "message", ",", "$", "type", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "HandlerInterface", "$", "handler", ")", "{", "if", "(", "!", "is_int", "(", "$", "type", ")", "||", "$", "type", "<", "0", "||", ...
Register a handler. \param int|fpoirotte::Pssht::Messages::CHANNEL::REQUEST::Base $message Either a message or the message's channel identifier. \param int $type Message type. \param fpoirotte::Pssht::HandlerInterface $handler Handler to associate with the message.
[ "Register", "a", "handler", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L152-L170
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.getValidClass
protected function getValidClass($type, $name) { $logging = \Plop\Plop::getInstance();; $w = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890\\'; if (!is_string($name) || strspn($name, $w) !== strlen($name)) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (invalid class name)', array('type' => $type, 'name' => $name) ); return null; } // Non-existing classes. $class = "\\fpoirotte\\Pssht\\$type$name"; if (!class_exists($class)) { if (!interface_exists($class)) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (class does not exist)', array('type' => $type, 'name' => $name) ); } return null; } // Abstract classes. $reflector = new \ReflectionClass($class); if ($reflector->isAbstract()) { return null; } // Classes that implement AvailabilityInterface // where the algorithm is not currently available. $iface = '\\fpoirotte\\Pssht\\AvailabilityInterface'; if ($reflector->implementsInterface($iface) && !$class::isAvailable()) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (not available)', array('type' => $type, 'name' => $name) ); return null; } // Classes that do not implement the proper interface. $iface = $this->interfaces[$type]; if ($iface !== null && !$reflector->implementsInterface($iface)) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (invalid interface)', array('type' => $type, 'name' => $name) ); return null; } return $class; }
php
protected function getValidClass($type, $name) { $logging = \Plop\Plop::getInstance();; $w = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890\\'; if (!is_string($name) || strspn($name, $w) !== strlen($name)) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (invalid class name)', array('type' => $type, 'name' => $name) ); return null; } // Non-existing classes. $class = "\\fpoirotte\\Pssht\\$type$name"; if (!class_exists($class)) { if (!interface_exists($class)) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (class does not exist)', array('type' => $type, 'name' => $name) ); } return null; } // Abstract classes. $reflector = new \ReflectionClass($class); if ($reflector->isAbstract()) { return null; } // Classes that implement AvailabilityInterface // where the algorithm is not currently available. $iface = '\\fpoirotte\\Pssht\\AvailabilityInterface'; if ($reflector->implementsInterface($iface) && !$class::isAvailable()) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (not available)', array('type' => $type, 'name' => $name) ); return null; } // Classes that do not implement the proper interface. $iface = $this->interfaces[$type]; if ($iface !== null && !$reflector->implementsInterface($iface)) { $logging->debug( 'Skipping %(type)s algorithm "%(name)s" (invalid interface)', array('type' => $type, 'name' => $name) ); return null; } return $class; }
[ "protected", "function", "getValidClass", "(", "$", "type", ",", "$", "name", ")", "{", "$", "logging", "=", "\\", "Plop", "\\", "Plop", "::", "getInstance", "(", ")", ";", ";", "$", "w", "=", "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890\\\\...
Check for valid classnames. \param string $type Expected type of class (algorithm name). \param string $name Name of the class. \retval string Full classname (with namespace). \retval null No valid class found with this type and name.
[ "Check", "for", "valid", "classnames", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L129-L181
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.getValidAlgorithm
protected function getValidAlgorithm($class) { $logging = \Plop\Plop::getInstance();; $w = 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . '1234567890-@.'; $name = $class::getName(); if (!is_string($name) || strspn($name, $w) !== strlen($name)) { $logging->debug( 'Skipping algorithm "%(name)s" (invalid algorithm name)', array('name' => $name) ); return null; } return $name; }
php
protected function getValidAlgorithm($class) { $logging = \Plop\Plop::getInstance();; $w = 'abcdefghijklmnopqrstuvwxyz' . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' . '1234567890-@.'; $name = $class::getName(); if (!is_string($name) || strspn($name, $w) !== strlen($name)) { $logging->debug( 'Skipping algorithm "%(name)s" (invalid algorithm name)', array('name' => $name) ); return null; } return $name; }
[ "protected", "function", "getValidAlgorithm", "(", "$", "class", ")", "{", "$", "logging", "=", "\\", "Plop", "\\", "Plop", "::", "getInstance", "(", ")", ";", ";", "$", "w", "=", "'abcdefghijklmnopqrstuvwxyz'", ".", "'ABCDEFGHIJKLMNOPQRSTUVWXYZ'", ".", "'1234...
Check for valid algorithm names. \param string $class Name of the class whose algorithm name must be checked. \retval string The class' algorithm name. \retval null No valid algorithm name for the given class.
[ "Check", "for", "valid", "algorithm", "names", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L195-L210
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.register
public function register($type, $class) { if (is_object($class)) { $class = get_class($class); } if (!is_string($class) || !class_exists($class)) { throw new \InvalidArgumentException(); } if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } $name = $this->getValidAlgorithm($class); if ($name === null) { throw new \InvalidArgumentException(); } $this->algos[$type][$name] = $class; uksort($this->algos[$type], array('self', 'sortAlgorithms')); return $this; }
php
public function register($type, $class) { if (is_object($class)) { $class = get_class($class); } if (!is_string($class) || !class_exists($class)) { throw new \InvalidArgumentException(); } if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } $name = $this->getValidAlgorithm($class); if ($name === null) { throw new \InvalidArgumentException(); } $this->algos[$type][$name] = $class; uksort($this->algos[$type], array('self', 'sortAlgorithms')); return $this; }
[ "public", "function", "register", "(", "$", "type", ",", "$", "class", ")", "{", "if", "(", "is_object", "(", "$", "class", ")", ")", "{", "$", "class", "=", "get_class", "(", "$", "class", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", ...
Register a new algorithm. \param string $type Type of algorithm provided by the class. \param string|object $class Class or object that provides the algorithm. \retval Algorithms Returns the singleton. \note A class registered with this method will overwrite any previously registered class with the same algorithm name.
[ "Register", "a", "new", "algorithm", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L229-L248
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.unregister
public function unregister($type, $name) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } if (!is_string($name)) { throw new \InvalidArgumentException(); } unset($this->algos[$type][$name]); return $this; }
php
public function unregister($type, $name) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } if (!is_string($name)) { throw new \InvalidArgumentException(); } unset($this->algos[$type][$name]); return $this; }
[ "public", "function", "unregister", "(", "$", "type", ",", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "type", ")", "||", "!", "isset", "(", "$", "this", "->", "algos", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "\\...
Unregister an algorithm. \param string $type Algorithm type. \param string $name Name of the algorithm to unregister. \retval Algorithms Returns the singleton.
[ "Unregister", "an", "algorithm", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L262-L272
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.restore
public function restore($type, $name) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } if (isset($this->savedAlgos[$type][$name])) { $this->algos[$type][$name] = $this->savedAlgos[$type][$name]; } return $this; }
php
public function restore($type, $name) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } if (isset($this->savedAlgos[$type][$name])) { $this->algos[$type][$name] = $this->savedAlgos[$type][$name]; } return $this; }
[ "public", "function", "restore", "(", "$", "type", ",", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "type", ")", "||", "!", "isset", "(", "$", "this", "->", "algos", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "\\", ...
Restore an algorithm. Reset the class in charge of providing a given algorithm to its initial value. \param string $type Algorithm type. \param string $name Name of the algorithm to restore. \retval Algorithms Returns the singleton.
[ "Restore", "an", "algorithm", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L289-L298
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.getAlgorithms
public function getAlgorithms($type) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } return array_keys($this->algos[$type]); }
php
public function getAlgorithms($type) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } return array_keys($this->algos[$type]); }
[ "public", "function", "getAlgorithms", "(", "$", "type", ")", "{", "if", "(", "!", "is_string", "(", "$", "type", ")", "||", "!", "isset", "(", "$", "this", "->", "algos", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgument...
Get a list of all registered algorithms with the given type. \param string $type Type of algorithms to retrieve. \retval array A list with the names of all the algorithms currently registered with the given type.
[ "Get", "a", "list", "of", "all", "registered", "algorithms", "with", "the", "given", "type", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L311-L317
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.getClasses
public function getClasses($type) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } return $this->algos[$type]; }
php
public function getClasses($type) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } return $this->algos[$type]; }
[ "public", "function", "getClasses", "(", "$", "type", ")", "{", "if", "(", "!", "is_string", "(", "$", "type", ")", "||", "!", "isset", "(", "$", "this", "->", "algos", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentExc...
Get a list of all registered classes with the given type. \param string $type Type of algorithms to retrieve. \retval array A list with the names of the classes currently registered providing algorithms of the given type.
[ "Get", "a", "list", "of", "all", "registered", "classes", "with", "the", "given", "type", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L330-L336
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.getClass
public function getClass($type, $name) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } if (!is_string($name)) { throw new \InvalidArgumentException(); } if (!isset($this->algos[$type][$name])) { return null; } return $this->algos[$type][$name]; }
php
public function getClass($type, $name) { if (!is_string($type) || !isset($this->algos[$type])) { throw new \InvalidArgumentException(); } if (!is_string($name)) { throw new \InvalidArgumentException(); } if (!isset($this->algos[$type][$name])) { return null; } return $this->algos[$type][$name]; }
[ "public", "function", "getClass", "(", "$", "type", ",", "$", "name", ")", "{", "if", "(", "!", "is_string", "(", "$", "type", ")", "||", "!", "isset", "(", "$", "this", "->", "algos", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "\\",...
Get the class responsible for providing the algorithm with the given type and name. \param string $type Type of algorithm to retrieve. \param string $name Name of the algorithm. \retval string Full name (with namespace) of the class providing the given algorithm. \retval null No class provides an algorithm with the given type and name.
[ "Get", "the", "class", "responsible", "for", "providing", "the", "algorithm", "with", "the", "given", "type", "and", "name", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L356-L368
train
fpoirotte/pssht
src/Algorithms.php
Algorithms.sortAlgorithms
public static function sortAlgorithms($a, $b) { static $preferences = array( // DH (KEX) 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1', // PublicKey 'ecdsa-sha2-nistp256-cert-v01@openssh.com', 'ecdsa-sha2-nistp384-cert-v01@openssh.com', 'ecdsa-sha2-nistp521-cert-v01@openssh.com', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521', 'ssh-ed25519-cert-v01@openssh.com', 'ssh-rsa-cert-v01@openssh.com', 'ssh-dss-cert-v01@openssh.com', 'ssh-rsa-cert-v00@openssh.com', 'ssh-dss-cert-v00@openssh.com', 'ssh-ed25519', 'ssh-rsa', 'ssh-dss', // Encryption 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'chacha20-poly1305@openssh.com', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se', // MAC 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-md5-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96', // Compression 'none', 'zlib@openssh.com', 'zlib', ); $iA = array_search($a, $preferences, true); $iB = array_search($b, $preferences, true); if ($iA === false) { return ($iB === false ? 0 : 1); } if ($iB === false) { return -1; } return ($iA - $iB); }
php
public static function sortAlgorithms($a, $b) { static $preferences = array( // DH (KEX) 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1', // PublicKey 'ecdsa-sha2-nistp256-cert-v01@openssh.com', 'ecdsa-sha2-nistp384-cert-v01@openssh.com', 'ecdsa-sha2-nistp521-cert-v01@openssh.com', 'ecdsa-sha2-nistp256', 'ecdsa-sha2-nistp384', 'ecdsa-sha2-nistp521', 'ssh-ed25519-cert-v01@openssh.com', 'ssh-rsa-cert-v01@openssh.com', 'ssh-dss-cert-v01@openssh.com', 'ssh-rsa-cert-v00@openssh.com', 'ssh-dss-cert-v00@openssh.com', 'ssh-ed25519', 'ssh-rsa', 'ssh-dss', // Encryption 'aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'chacha20-poly1305@openssh.com', 'arcfour256', 'arcfour128', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se', // MAC 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-sha1', 'hmac-md5-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96', // Compression 'none', 'zlib@openssh.com', 'zlib', ); $iA = array_search($a, $preferences, true); $iB = array_search($b, $preferences, true); if ($iA === false) { return ($iB === false ? 0 : 1); } if ($iB === false) { return -1; } return ($iA - $iB); }
[ "public", "static", "function", "sortAlgorithms", "(", "$", "a", ",", "$", "b", ")", "{", "static", "$", "preferences", "=", "array", "(", "// DH (KEX)", "'curve25519-sha256@libssh.org'", ",", "'ecdh-sha2-nistp256'", ",", "'ecdh-sha2-nistp384'", ",", "'ecdh-sha2-nis...
Sort algorithms based on preferences. \param string $a Name of the first algorithm. \param string $b Name of the second algorithm. \retval int An integer that is less than zero if the first algorithm should be preferred, equal to zero if both algorithms have the same preference and greater than zero when the second algorithm should be preferred.
[ "Sort", "algorithms", "based", "on", "preferences", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L385-L468
train
fpoirotte/pssht
src/Handlers/DISCONNECT.php
DISCONNECT.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\DISCONNECT::unserialize($decoder); throw new $message; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\DISCONNECT::unserialize($decoder); throw new $message; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_DISCONNECT = 1
[ "SSH_MSG_DISCONNECT", "=", "1" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/DISCONNECT.php#L20-L28
train
fpoirotte/pssht
src/Buffer.php
Buffer.getLength
protected function getLength($limit) { $size = strlen($this->data); if ($limit <= 0) { $limit += $size; } if ($limit > $size) { return null; } $res = (string) substr($this->data, 0, $limit); $this->data = (string) substr($this->data, $limit); return $res; }
php
protected function getLength($limit) { $size = strlen($this->data); if ($limit <= 0) { $limit += $size; } if ($limit > $size) { return null; } $res = (string) substr($this->data, 0, $limit); $this->data = (string) substr($this->data, $limit); return $res; }
[ "protected", "function", "getLength", "(", "$", "limit", ")", "{", "$", "size", "=", "strlen", "(", "$", "this", "->", "data", ")", ";", "if", "(", "$", "limit", "<=", "0", ")", "{", "$", "limit", "+=", "$", "size", ";", "}", "if", "(", "$", ...
Return a limited amount of data from the buffer. \param int $limit Number of bytes to retrieve from the buffer. \retval string Exactly $limit bytes of data from the buffer. \retval null The buffer contains less than $limit bytes of data.
[ "Return", "a", "limited", "amount", "of", "data", "from", "the", "buffer", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L63-L77
train
fpoirotte/pssht
src/Buffer.php
Buffer.getDelimiter
protected function getDelimiter($limit) { if ($limit === '') { throw new \InvalidArgumentException(); } $pos = strpos($this->data, $limit); if ($pos === false) { return null; } $pos += strlen($limit); $res = substr($this->data, 0, $pos); $this->data = (string) substr($this->data, $pos); return $res; }
php
protected function getDelimiter($limit) { if ($limit === '') { throw new \InvalidArgumentException(); } $pos = strpos($this->data, $limit); if ($pos === false) { return null; } $pos += strlen($limit); $res = substr($this->data, 0, $pos); $this->data = (string) substr($this->data, $pos); return $res; }
[ "protected", "function", "getDelimiter", "(", "$", "limit", ")", "{", "if", "(", "$", "limit", "===", "''", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "$", "pos", "=", "strpos", "(", "$", "this", "->", "data", ","...
Return a delimited string from the buffer. \param string $limit Delimiter. \retval string All the data at the beginning of the buffer up to (and including) the delimiter. \retval null The given delimiter does not appear in the buffer.
[ "Return", "a", "delimited", "string", "from", "the", "buffer", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L93-L108
train
fpoirotte/pssht
src/Buffer.php
Buffer.get
public function get($limit) { if (is_int($limit)) { return $this->getLength($limit); } if (is_string($limit)) { return $this->getDelimiter($limit); } throw new \InvalidArgumentException(); }
php
public function get($limit) { if (is_int($limit)) { return $this->getLength($limit); } if (is_string($limit)) { return $this->getDelimiter($limit); } throw new \InvalidArgumentException(); }
[ "public", "function", "get", "(", "$", "limit", ")", "{", "if", "(", "is_int", "(", "$", "limit", ")", ")", "{", "return", "$", "this", "->", "getLength", "(", "$", "limit", ")", ";", "}", "if", "(", "is_string", "(", "$", "limit", ")", ")", "{...
Get limited data from the beginning of the buffer. \param int|string $limit Either the number of bytes to retrieve from the buffer, or a string delimiter to look for. \retval string The data at the beginning of the buffer, until the given limit is reached. For string delimiters, the delimiter is part of the result.
[ "Get", "limited", "data", "from", "the", "beginning", "of", "the", "buffer", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L123-L134
train
fpoirotte/pssht
src/Buffer.php
Buffer.unget
public function unget($data) { if (!is_string($data)) { throw new \InvalidArgumentException(); } $this->data = $data . $this->data; return $this; }
php
public function unget($data) { if (!is_string($data)) { throw new \InvalidArgumentException(); } $this->data = $data . $this->data; return $this; }
[ "public", "function", "unget", "(", "$", "data", ")", "{", "if", "(", "!", "is_string", "(", "$", "data", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "$", "this", "->", "data", "=", "$", "data", ".", "$", ...
Prepend data to the beginning of the buffer. \param string $data Data to prepend. \retval Buffer Returns this buffer.
[ "Prepend", "data", "to", "the", "beginning", "of", "the", "buffer", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L145-L153
train
fpoirotte/pssht
src/Handlers/CHANNEL/CLOSE.php
CLOSE.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\CHANNEL\CLOSE::unserialize($decoder); $channel = $message->getChannel(); $response = new \fpoirotte\Pssht\Messages\CHANNEL\CLOSE( $this->connection->getChannel($channel) ); $transport->writeMessage($response); $this->connection->freeChannel($channel); return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\CHANNEL\CLOSE::unserialize($decoder); $channel = $message->getChannel(); $response = new \fpoirotte\Pssht\Messages\CHANNEL\CLOSE( $this->connection->getChannel($channel) ); $transport->writeMessage($response); $this->connection->freeChannel($channel); return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_CHANNEL_CLOSE = 97
[ "SSH_MSG_CHANNEL_CLOSE", "=", "97" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/CHANNEL/CLOSE.php#L20-L34
train
fpoirotte/pssht
src/KeyStoreLoader/File.php
File.load
public function load($user, $file) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!is_string($file)) { throw new \InvalidArgumentException(); } $algos = \fpoirotte\Pssht\Algorithms::factory(); $types = array( 'ssh-dss', 'ssh-rsa', # 'ecdsa-sha2-nistp256', # 'ecdsa-sha2-nistp384', # 'ecdsa-sha2-nistp521', ); foreach (file($file) as $line) { $fields = explode(' ', preg_replace('/\\s+/', ' ', trim($line))); $max = count($fields); for ($i = 0; $i < $max; $i++) { if (in_array($fields[$i], $types, true)) { $cls = $algos->getClass('PublicKey', $fields[$i]); $this->store->add($user, $cls::loadPublic($fields[$i+1])); break; } } } return $this; }
php
public function load($user, $file) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!is_string($file)) { throw new \InvalidArgumentException(); } $algos = \fpoirotte\Pssht\Algorithms::factory(); $types = array( 'ssh-dss', 'ssh-rsa', # 'ecdsa-sha2-nistp256', # 'ecdsa-sha2-nistp384', # 'ecdsa-sha2-nistp521', ); foreach (file($file) as $line) { $fields = explode(' ', preg_replace('/\\s+/', ' ', trim($line))); $max = count($fields); for ($i = 0; $i < $max; $i++) { if (in_array($fields[$i], $types, true)) { $cls = $algos->getClass('PublicKey', $fields[$i]); $this->store->add($user, $cls::loadPublic($fields[$i+1])); break; } } } return $this; }
[ "public", "function", "load", "(", "$", "user", ",", "$", "file", ")", "{", "if", "(", "!", "is_string", "(", "$", "user", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", ...
Load the keys in the given file as if they belonged to the specified user. \param string $user User the keys belong to. \param string $file File containing the keys to load. It should follow the format of OpenSSH's authorized_keys file. \retval File Returns this loader.
[ "Load", "the", "keys", "in", "the", "given", "file", "as", "if", "they", "belonged", "to", "the", "specified", "user", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStoreLoader/File.php#L54-L86
train
fpoirotte/pssht
src/KeyStoreLoader/File.php
File.loadBulk
public function loadBulk(array $bulk) { foreach ($bulk as $user => $files) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!is_array($files) && !is_string($files)) { throw new \InvalidArgumentException(); } $files = (array) $files; foreach ($files as $file) { $this->load($user, $file); } } return $this; }
php
public function loadBulk(array $bulk) { foreach ($bulk as $user => $files) { if (!is_string($user)) { throw new \InvalidArgumentException(); } if (!is_array($files) && !is_string($files)) { throw new \InvalidArgumentException(); } $files = (array) $files; foreach ($files as $file) { $this->load($user, $file); } } return $this; }
[ "public", "function", "loadBulk", "(", "array", "$", "bulk", ")", "{", "foreach", "(", "$", "bulk", "as", "$", "user", "=>", "$", "files", ")", "{", "if", "(", "!", "is_string", "(", "$", "user", ")", ")", "{", "throw", "new", "\\", "InvalidArgumen...
Bulk-load keys. \param array $bulk An array with information on the keys to load. The keys in the array indicate users while the values contain (an array of) files containing the keys to load. \retval File Returns this loader.
[ "Bulk", "-", "load", "keys", "." ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStoreLoader/File.php#L100-L117
train
fpoirotte/pssht
src/Handlers/IGNORE.php
IGNORE.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_IGNORE = 2
[ "SSH_MSG_IGNORE", "=", "2" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/IGNORE.php#L20-L27
train
fpoirotte/pssht
src/Handlers/CHANNEL/OPEN.php
OPEN.handle
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\CHANNEL\OPEN::unserialize($decoder); $recipientChannel = $message->getChannel(); if ($message->getType() === 'session') { $response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\CONFIRMATION( $recipientChannel, $this->connection->allocateChannel($message), 0x200000, 0x800000 ); } else { $response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE( $recipientChannel, \fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE::SSH_OPEN_UNKNOWN_CHANNEL_TYPE, 'No such channel type' ); } $transport->writeMessage($response); return true; }
php
public function handle( $msgType, \fpoirotte\Pssht\Wire\Decoder $decoder, \fpoirotte\Pssht\Transport $transport, array &$context ) { $message = \fpoirotte\Pssht\Messages\CHANNEL\OPEN::unserialize($decoder); $recipientChannel = $message->getChannel(); if ($message->getType() === 'session') { $response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\CONFIRMATION( $recipientChannel, $this->connection->allocateChannel($message), 0x200000, 0x800000 ); } else { $response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE( $recipientChannel, \fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE::SSH_OPEN_UNKNOWN_CHANNEL_TYPE, 'No such channel type' ); } $transport->writeMessage($response); return true; }
[ "public", "function", "handle", "(", "$", "msgType", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Wire", "\\", "Decoder", "$", "decoder", ",", "\\", "fpoirotte", "\\", "Pssht", "\\", "Transport", "$", "transport", ",", "array", "&", "$", "context", ")",...
SSH_MSG_CHANNEL_OPEN = 90
[ "SSH_MSG_CHANNEL_OPEN", "=", "90" ]
26bbbc18956144e355317f1e2e468be24bbb3e35
https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/CHANNEL/OPEN.php#L20-L45
train
go1com/flood
Flood.php
Flood.isAllowed
public function isAllowed($name, $threshold, $window = 3600, $identifier = null) { return $threshold > $this->count($name, $window, $identifier); }
php
public function isAllowed($name, $threshold, $window = 3600, $identifier = null) { return $threshold > $this->count($name, $window, $identifier); }
[ "public", "function", "isAllowed", "(", "$", "name", ",", "$", "threshold", ",", "$", "window", "=", "3600", ",", "$", "identifier", "=", "null", ")", "{", "return", "$", "threshold", ">", "$", "this", "->", "count", "(", "$", "name", ",", "$", "wi...
Checks whether a user is allowed to proceed with the specified event. Events can have thresholds saying that each user can only do that event a certain number of times in a time window. This function verifies that the current user has not exceeded this threshold. @param string $name The unique name of the event. @param int $threshold The maximum number of times each user can do this event per time window. @param int $window Number of seconds in the time window for this event (default is 3600 seconds/1 hour). @param $identifier Unique identifier of the current user. Defaults to their IP address. @return bool
[ "Checks", "whether", "a", "user", "is", "allowed", "to", "proceed", "with", "the", "specified", "event", "." ]
2ac77219479f010b0290265ad5d0c02a4b34930a
https://github.com/go1com/flood/blob/2ac77219479f010b0290265ad5d0c02a4b34930a/Flood.php#L67-L70
train
go1com/flood
Flood.php
Flood.register
public function register($name, $window = 3600, $identifier = null) { $this ->connection ->insert($this->tableName, [ 'event' => $name, 'identifier' => $identifier ?: $this->ip(), 'timestamp' => time(), 'expiration' => time() + $window, ]); }
php
public function register($name, $window = 3600, $identifier = null) { $this ->connection ->insert($this->tableName, [ 'event' => $name, 'identifier' => $identifier ?: $this->ip(), 'timestamp' => time(), 'expiration' => time() + $window, ]); }
[ "public", "function", "register", "(", "$", "name", ",", "$", "window", "=", "3600", ",", "$", "identifier", "=", "null", ")", "{", "$", "this", "->", "connection", "->", "insert", "(", "$", "this", "->", "tableName", ",", "[", "'event'", "=>", "$", ...
Registers an event for the current visitor to the flood control mechanism. @param string $name The name of an event. @param int $window Time to live in seconds. @param int $identifier Optional identifier (defaults to the current user's IP address).
[ "Registers", "an", "event", "for", "the", "current", "visitor", "to", "the", "flood", "control", "mechanism", "." ]
2ac77219479f010b0290265ad5d0c02a4b34930a
https://github.com/go1com/flood/blob/2ac77219479f010b0290265ad5d0c02a4b34930a/Flood.php#L91-L101
train
flash-global/entities
src/AbstractEntity.php
AbstractEntity.mapFrom
public function mapFrom($field) { return isset($this->mapping[$field]) ? $this->mapping[$field] : $field; }
php
public function mapFrom($field) { return isset($this->mapping[$field]) ? $this->mapping[$field] : $field; }
[ "public", "function", "mapFrom", "(", "$", "field", ")", "{", "return", "isset", "(", "$", "this", "->", "mapping", "[", "$", "field", "]", ")", "?", "$", "this", "->", "mapping", "[", "$", "field", "]", ":", "$", "field", ";", "}" ]
Map DB field name to property name @param $field @return mixed
[ "Map", "DB", "field", "name", "to", "property", "name" ]
7469b60bb0bb5b63491a78872bf9c3f38d4c8e75
https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/AbstractEntity.php#L127-L130
train
flash-global/entities
src/AbstractEntity.php
AbstractEntity.mapTo
public function mapTo($property) { if (!$this->mappingTo) { $this->mappingTo = array_flip($this->mapping); } return isset($this->mappingTo[$property]) ? $this->mappingTo[$property] : $property; }
php
public function mapTo($property) { if (!$this->mappingTo) { $this->mappingTo = array_flip($this->mapping); } return isset($this->mappingTo[$property]) ? $this->mappingTo[$property] : $property; }
[ "public", "function", "mapTo", "(", "$", "property", ")", "{", "if", "(", "!", "$", "this", "->", "mappingTo", ")", "{", "$", "this", "->", "mappingTo", "=", "array_flip", "(", "$", "this", "->", "mapping", ")", ";", "}", "return", "isset", "(", "$...
Map property name to DB field name @param $property @return mixed
[ "Map", "property", "name", "to", "DB", "field", "name" ]
7469b60bb0bb5b63491a78872bf9c3f38d4c8e75
https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/AbstractEntity.php#L153-L160
train
flash-global/entities
src/Extractor/JsonApiExtractor.php
JsonApiExtractor.extract
public function extract(array $json) { if (!$this->hasData($json)) { return null; } if (!$this->isCollection($json)) { return $this->extractOne($json, $json['data']); } else { $data = $this->extractMultiple($json); if ($this->isPaginated($json)) { return (new PaginatedEntitySet($data)) ->setPerPage($json['meta']['pagination']['per_page']) ->setCurrentPage($json['meta']['pagination']['current_page']) ->setTotal($json['meta']['pagination']['total']); } return new EntitySet($data); } }
php
public function extract(array $json) { if (!$this->hasData($json)) { return null; } if (!$this->isCollection($json)) { return $this->extractOne($json, $json['data']); } else { $data = $this->extractMultiple($json); if ($this->isPaginated($json)) { return (new PaginatedEntitySet($data)) ->setPerPage($json['meta']['pagination']['per_page']) ->setCurrentPage($json['meta']['pagination']['current_page']) ->setTotal($json['meta']['pagination']['total']); } return new EntitySet($data); } }
[ "public", "function", "extract", "(", "array", "$", "json", ")", "{", "if", "(", "!", "$", "this", "->", "hasData", "(", "$", "json", ")", ")", "{", "return", "null", ";", "}", "if", "(", "!", "$", "this", "->", "isCollection", "(", "$", "json", ...
Extract entities form an JSON API data @param array $json @return EntityInterface|EntitySet|PaginatedEntitySet|null
[ "Extract", "entities", "form", "an", "JSON", "API", "data" ]
7469b60bb0bb5b63491a78872bf9c3f38d4c8e75
https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/Extractor/JsonApiExtractor.php#L23-L40
train
flash-global/entities
src/Extractor/JsonApiExtractor.php
JsonApiExtractor.extractOne
protected function extractOne(array $json, array $data) { if ($this->dataHasType($data)) { return $this->createInstanceWithRelations($json, $data); } throw new JsonApiExtractException('No data type provided'); }
php
protected function extractOne(array $json, array $data) { if ($this->dataHasType($data)) { return $this->createInstanceWithRelations($json, $data); } throw new JsonApiExtractException('No data type provided'); }
[ "protected", "function", "extractOne", "(", "array", "$", "json", ",", "array", "$", "data", ")", "{", "if", "(", "$", "this", "->", "dataHasType", "(", "$", "data", ")", ")", "{", "return", "$", "this", "->", "createInstanceWithRelations", "(", "$", "...
Extract an entity from data @param array $json @param array $data @return array|EntityInterface @throws JsonApiExtractException
[ "Extract", "an", "entity", "from", "data" ]
7469b60bb0bb5b63491a78872bf9c3f38d4c8e75
https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/Extractor/JsonApiExtractor.php#L75-L81
train
flash-global/entities
src/Extractor/JsonApiExtractor.php
JsonApiExtractor.isPaginated
protected function isPaginated(array $json) { if (!array_key_exists('links', $json) || !array_key_exists('meta', $json)) { return false; } if (is_array($json['links']) && array_key_exists('self', $json['links']) && array_key_exists('first', $json['links']) && array_key_exists('last', $json['links']) && isset($json['meta']['pagination']) && is_array($json['meta']['pagination']) && array_key_exists('total', $json['meta']['pagination']) && array_key_exists('count', $json['meta']['pagination']) && array_key_exists('per_page', $json['meta']['pagination']) && array_key_exists('current_page', $json['meta']['pagination']) && array_key_exists('total_pages', $json['meta']['pagination']) ) { return true; } return false; }
php
protected function isPaginated(array $json) { if (!array_key_exists('links', $json) || !array_key_exists('meta', $json)) { return false; } if (is_array($json['links']) && array_key_exists('self', $json['links']) && array_key_exists('first', $json['links']) && array_key_exists('last', $json['links']) && isset($json['meta']['pagination']) && is_array($json['meta']['pagination']) && array_key_exists('total', $json['meta']['pagination']) && array_key_exists('count', $json['meta']['pagination']) && array_key_exists('per_page', $json['meta']['pagination']) && array_key_exists('current_page', $json['meta']['pagination']) && array_key_exists('total_pages', $json['meta']['pagination']) ) { return true; } return false; }
[ "protected", "function", "isPaginated", "(", "array", "$", "json", ")", "{", "if", "(", "!", "array_key_exists", "(", "'links'", ",", "$", "json", ")", "||", "!", "array_key_exists", "(", "'meta'", ",", "$", "json", ")", ")", "{", "return", "false", ";...
Test if JSON API data provided is paginated @param array $json @return bool
[ "Test", "if", "JSON", "API", "data", "provided", "is", "paginated" ]
7469b60bb0bb5b63491a78872bf9c3f38d4c8e75
https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/Extractor/JsonApiExtractor.php#L202-L222
train
clue/reactphp-zenity
src/Dialog/AbstractDialog.php
AbstractDialog.getArgs
public function getArgs() { $args = array( '--' . $this->getType() ); foreach ($this as $name => $value) { if (!in_array($name, array('inbuffer')) && $value !== null && $value !== false && !is_array($value)) { $name = $this->decamelize($name); if ($value !== true) { // append value if this is not a boolean arg $name .= '=' . $value; } // all arguments start with a double dash $args []= '--' . $name; } } return $args; }
php
public function getArgs() { $args = array( '--' . $this->getType() ); foreach ($this as $name => $value) { if (!in_array($name, array('inbuffer')) && $value !== null && $value !== false && !is_array($value)) { $name = $this->decamelize($name); if ($value !== true) { // append value if this is not a boolean arg $name .= '=' . $value; } // all arguments start with a double dash $args []= '--' . $name; } } return $args; }
[ "public", "function", "getArgs", "(", ")", "{", "$", "args", "=", "array", "(", "'--'", ".", "$", "this", "->", "getType", "(", ")", ")", ";", "foreach", "(", "$", "this", "as", "$", "name", "=>", "$", "value", ")", "{", "if", "(", "!", "in_arr...
Returns an array of arguments to pass to the zenity bin to produce the current dialog. Internally, this will automatically fetch all properties of the current instance and format them accordingly to zenity arguments. @return string[] @internal
[ "Returns", "an", "array", "of", "arguments", "to", "pass", "to", "the", "zenity", "bin", "to", "produce", "the", "current", "dialog", "." ]
f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964
https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Dialog/AbstractDialog.php#L168-L189
train
clue/reactphp-zenity
src/Zen/ListZen.php
ListZen.parseValue
public function parseValue($value) { if (trim($value) === '') { // TODO: move logic return false; } // always split on separator, even if we only return a single value (explicitly or a checklist) // work around an issue in zenity 3.8: https://bugzilla.gnome.org/show_bug.cgi?id=698683 $value = explode($this->separator, $value); if ($this->single) { $value = $value[0]; } return $value; }
php
public function parseValue($value) { if (trim($value) === '') { // TODO: move logic return false; } // always split on separator, even if we only return a single value (explicitly or a checklist) // work around an issue in zenity 3.8: https://bugzilla.gnome.org/show_bug.cgi?id=698683 $value = explode($this->separator, $value); if ($this->single) { $value = $value[0]; } return $value; }
[ "public", "function", "parseValue", "(", "$", "value", ")", "{", "if", "(", "trim", "(", "$", "value", ")", "===", "''", ")", "{", "// TODO: move logic", "return", "false", ";", "}", "// always split on separator, even if we only return a single value (explicitly or a...
Parses the string returned from the dialog Usually, this will return a single string. If the `setMultiple(true)` option is active or this is a checklist, this will return an array of strings instead. The size of the array depends on the number of rows selected by the user. @internal @see parent::parseValue() @return string|string[] a single or any number of strings depending on the multiple setting @see ListDialog::setMultiple()
[ "Parses", "the", "string", "returned", "from", "the", "dialog" ]
f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964
https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Zen/ListZen.php#L32-L46
train
clue/reactphp-zenity
src/Dialog/FormsDialog.php
FormsDialog.addList
public function addList($name, array $values, array $columns = null, $showHeaders = null) { $this->fields[] = '--add-list=' . $name; $this->fields[] = '--list-values=' . implode('|', $values); // columns given => show headers if it's not explicitly disabled if ($columns !== null && $showHeaders === null) { $showHeaders = true; } if ($showHeaders) { $this->fields[] = '--show-header'; } if ($columns !== null) { $this->fields[] = '--column-values=' . implode('|', $columns); } return $this; }
php
public function addList($name, array $values, array $columns = null, $showHeaders = null) { $this->fields[] = '--add-list=' . $name; $this->fields[] = '--list-values=' . implode('|', $values); // columns given => show headers if it's not explicitly disabled if ($columns !== null && $showHeaders === null) { $showHeaders = true; } if ($showHeaders) { $this->fields[] = '--show-header'; } if ($columns !== null) { $this->fields[] = '--column-values=' . implode('|', $columns); } return $this; }
[ "public", "function", "addList", "(", "$", "name", ",", "array", "$", "values", ",", "array", "$", "columns", "=", "null", ",", "$", "showHeaders", "=", "null", ")", "{", "$", "this", "->", "fields", "[", "]", "=", "'--add-list='", ".", "$", "name", ...
Add a new List in forms dialog. Only one single row can be selected in the list. The default selection is the first row. A simple list can be added like this: <code> $values = array('blue', 'red'); $dialog->addList('Favorite color', $values); </code> Selecting a value in this list will return either 'blue' (which is also the default selection) or 'red'. A table can be added like this: <code> $values = array('Nobody', 'nobody@example.com', 'Frank', 'frank@example.org'); $dialog->addList('Target', $values, array('Name', 'Email')); </code> The $columns will be uses as headers in the table. If you do not want this, you can pass a `$showHeaders = false` flag. This will present a table to the user with no column headers, so the actual column names will not be visible at all. Selecting a row in this table will return all values in this row concatenated with no separator. The default will be 'Nobodynobody@example.com'. Unfortunately, there does not appear to be a way to change this behavior. You can work around this limitation by adding a unique separator to the field values yourself, for example like this: <code> $values = array('Nobody ', 'nobody@example.com'); </code> This will return the string 'Nobody nobody@example.com'. Make sure the values do not contain a "|" character. Internally, this character will be used to separate multiple values from one another. As such, the following two examples are equivalent: <code> $values = array('my|name', 'test'); $values = array('my', 'name', 'test'); </code> Unfortunately, there does not appear to be a way to change this behavior. Attention, support for lists within forms is somewhat limited. Adding a single list works fine, but anything beyond that will *very* likely either confuse or segfault zenity. Neither the man page nor the online documentation seem to list this feature (2014-08-02), see `zenity --help-forms` for (some) details. @param string $name @param array $values @param array|null $columns @param boolean|null $showHeaders @return self chainable @link https://mail.gnome.org/archives/commits-list/2011-October/msg04739.html
[ "Add", "a", "new", "List", "in", "forms", "dialog", "." ]
f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964
https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Dialog/FormsDialog.php#L120-L140
train
clue/reactphp-zenity
src/Launcher.php
Launcher.waitFor
public function waitFor(AbstractDialog $dialog) { $done = false; $ret = null; $loop = $this->loop; $process = $this->launch($dialog); $process->then(function ($result) use (&$ret, &$done, $loop) { $ret = $result; $done = true; $loop->stop(); }, function () use (&$ret, &$done, $loop) { $ret = false; $done = true; $loop->stop(); }); if (!$done) { $loop->run(); } return $ret; }
php
public function waitFor(AbstractDialog $dialog) { $done = false; $ret = null; $loop = $this->loop; $process = $this->launch($dialog); $process->then(function ($result) use (&$ret, &$done, $loop) { $ret = $result; $done = true; $loop->stop(); }, function () use (&$ret, &$done, $loop) { $ret = false; $done = true; $loop->stop(); }); if (!$done) { $loop->run(); } return $ret; }
[ "public", "function", "waitFor", "(", "AbstractDialog", "$", "dialog", ")", "{", "$", "done", "=", "false", ";", "$", "ret", "=", "null", ";", "$", "loop", "=", "$", "this", "->", "loop", ";", "$", "process", "=", "$", "this", "->", "launch", "(", ...
Block while waiting for the given dialog to return If the dialog is already closed, this returns immediately, without doing much at all. If the dialog is not yet opened, it will be opened and this method will wait for the dialog to be handled (i.e. either completed or closed). Clicking "ok" will result in a boolean true value, clicking "cancel" or hitten escape key will or running into a timeout will result in a boolean false. For all other input fields, their respective (parsed) value will be returned. For this to work, this method will temporarily start the event loop and stop it afterwards. Thus, it is *NOT* a good idea to mix this if anything else is listening on the event loop. The recommended way in this case is to avoid using this blocking method call and go for a fully async `self::then()` instead. @param AbstractDialog $dialog @return boolean|string dialog return value @uses Launcher::waitFor()
[ "Block", "while", "waiting", "for", "the", "given", "dialog", "to", "return" ]
f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964
https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Launcher.php#L81-L106
train
clue/reactphp-zenity
src/Zen/FileSelectionZen.php
FileSelectionZen.parseValue
public function parseValue($value) { if ($this->multiple) { $ret = array(); foreach(explode($this->separator, $value) as $path) { $ret[] = new SplFileInfo($path); } return $ret; } return new SplFileInfo($value); }
php
public function parseValue($value) { if ($this->multiple) { $ret = array(); foreach(explode($this->separator, $value) as $path) { $ret[] = new SplFileInfo($path); } return $ret; } return new SplFileInfo($value); }
[ "public", "function", "parseValue", "(", "$", "value", ")", "{", "if", "(", "$", "this", "->", "multiple", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "explode", "(", "$", "this", "->", "separator", ",", "$", "value", ")", ...
Parses the path string returned from the dialog into a SplFileInfo object Usually, this will return a single SplFileInfo object. If the `setMultiple(true)` option is active, this will return an array of SplFileInfo objects instead. The size of the array depends on the number of files selected by the user. @internal @see parent::parseValue() @return SplFileInfo|SplFileInfo[] a single or any number of SplFileInfo objects depending on the multiple setting @see FileSelectionDialog::setMultiple()
[ "Parses", "the", "path", "string", "returned", "from", "the", "dialog", "into", "a", "SplFileInfo", "object" ]
f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964
https://github.com/clue/reactphp-zenity/blob/f49e18fc0443f454c2e4cd270f0fc7a5f0cd3964/src/Zen/FileSelectionZen.php#L33-L45
train
kktsvetkov/krumo
class.krumo.php
krumo.headers
public static function headers() { // disabled ? // if (!self::_debug()) { return false; } if (!function_exists('getallheaders')) { function getallheaders() { $headers = array (); foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $key = str_replace( ' ', '-', ucwords(strtolower( str_replace('_', ' ', substr($name, 5)) )) ); $headers[$key] = $value; } } return $headers; } } // render it // ?> <div class="krumo-title"> This is a list of all HTTP request headers. </div> <?php return self::dump(getallheaders()); }
php
public static function headers() { // disabled ? // if (!self::_debug()) { return false; } if (!function_exists('getallheaders')) { function getallheaders() { $headers = array (); foreach ($_SERVER as $name => $value) { if (substr($name, 0, 5) == 'HTTP_') { $key = str_replace( ' ', '-', ucwords(strtolower( str_replace('_', ' ', substr($name, 5)) )) ); $headers[$key] = $value; } } return $headers; } } // render it // ?> <div class="krumo-title"> This is a list of all HTTP request headers. </div> <?php return self::dump(getallheaders()); }
[ "public", "static", "function", "headers", "(", ")", "{", "// disabled ?\r", "//\r", "if", "(", "!", "self", "::", "_debug", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "function_exists", "(", "'getallheaders'", ")", ")", "{", "fun...
Prints a list of all HTTP request headers.
[ "Prints", "a", "list", "of", "all", "HTTP", "request", "headers", "." ]
fc8bfbb350ca481446820a665afe93ab98423e1e
https://github.com/kktsvetkov/krumo/blob/fc8bfbb350ca481446820a665afe93ab98423e1e/class.krumo.php#L213-L253
train
kktsvetkov/krumo
class.krumo.php
krumo.fetch
public static function fetch($data) { // disabled ? // if (!self::_debug()) { return false; } ob_start(); call_user_func_array( array(__CLASS__, 'dump'), func_get_args() ); return ob_get_clean(); }
php
public static function fetch($data) { // disabled ? // if (!self::_debug()) { return false; } ob_start(); call_user_func_array( array(__CLASS__, 'dump'), func_get_args() ); return ob_get_clean(); }
[ "public", "static", "function", "fetch", "(", "$", "data", ")", "{", "// disabled ?\r", "//\r", "if", "(", "!", "self", "::", "_debug", "(", ")", ")", "{", "return", "false", ";", "}", "ob_start", "(", ")", ";", "call_user_func_array", "(", "array", "(...
Return the dump information about a variable @param mixed $data,...
[ "Return", "the", "dump", "information", "about", "a", "variable" ]
fc8bfbb350ca481446820a665afe93ab98423e1e
https://github.com/kktsvetkov/krumo/blob/fc8bfbb350ca481446820a665afe93ab98423e1e/class.krumo.php#L649-L665
train
kktsvetkov/krumo
class.krumo.php
krumo.&
private static function &_hive(&$bee) { static $_ = array(); // new bee ? // if (!is_null($bee)) { // stain it // $_recursion_marker = self::_marker(); (is_object($bee)) ? (empty($bee->$_recursion_marker) ? $bee->$_recursion_marker = 1 : $bee->$_recursion_marker++ ) : (empty($bee[$_recursion_marker]) ? $bee[$_recursion_marker] = 1 : $bee[$_recursion_marker]++ ); $_[0][] =& $bee; // KT: stupid PHP4 static reference hack } // return all bees // return $_[0]; }
php
private static function &_hive(&$bee) { static $_ = array(); // new bee ? // if (!is_null($bee)) { // stain it // $_recursion_marker = self::_marker(); (is_object($bee)) ? (empty($bee->$_recursion_marker) ? $bee->$_recursion_marker = 1 : $bee->$_recursion_marker++ ) : (empty($bee[$_recursion_marker]) ? $bee[$_recursion_marker] = 1 : $bee[$_recursion_marker]++ ); $_[0][] =& $bee; // KT: stupid PHP4 static reference hack } // return all bees // return $_[0]; }
[ "private", "static", "function", "&", "_hive", "(", "&", "$", "bee", ")", "{", "static", "$", "_", "=", "array", "(", ")", ";", "// new bee ?\r", "//\r", "if", "(", "!", "is_null", "(", "$", "bee", ")", ")", "{", "// stain it\r", "//\r", "$", "_rec...
Adds a variable to the hive of arrays and objects which are tracked for whether they have recursive entries @param mixed &$bee either array or object, not a scallar vale @return array all the bees
[ "Adds", "a", "variable", "to", "the", "hive", "of", "arrays", "and", "objects", "which", "are", "tracked", "for", "whether", "they", "have", "recursive", "entries" ]
fc8bfbb350ca481446820a665afe93ab98423e1e
https://github.com/kktsvetkov/krumo/blob/fc8bfbb350ca481446820a665afe93ab98423e1e/class.krumo.php#L944-L972
train
netgen-layouts/content-browser
bundle/EventListener/SetCurrentBackendListener.php
SetCurrentBackendListener.onKernelRequest
public function onKernelRequest(GetResponseEvent $event): void { if (!$event->isMasterRequest()) { return; } $attributes = $event->getRequest()->attributes; if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) { return; } if (!$attributes->has('itemType')) { return; } $backend = $this->backendRegistry->getBackend($attributes->get('itemType')); $this->container->set('netgen_content_browser.current_backend', $backend); }
php
public function onKernelRequest(GetResponseEvent $event): void { if (!$event->isMasterRequest()) { return; } $attributes = $event->getRequest()->attributes; if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) { return; } if (!$attributes->has('itemType')) { return; } $backend = $this->backendRegistry->getBackend($attributes->get('itemType')); $this->container->set('netgen_content_browser.current_backend', $backend); }
[ "public", "function", "onKernelRequest", "(", "GetResponseEvent", "$", "event", ")", ":", "void", "{", "if", "(", "!", "$", "event", "->", "isMasterRequest", "(", ")", ")", "{", "return", ";", "}", "$", "attributes", "=", "$", "event", "->", "getRequest"...
Injects the current backend into container.
[ "Injects", "the", "current", "backend", "into", "container", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/SetCurrentBackendListener.php#L39-L56
train
zicht/symfony-util
src/Zicht/SymfonyUtil/HttpKernel/Kernel.php
Kernel.getConfigFiles
protected function getConfigFiles() { $ret = []; foreach ($this->getCandidateConfigFiles() as $configFile) { if (is_file($configFile)) { $ret[]= $configFile; break; } } $configFile = join( '/', [ $this->getRootDir(), 'config', sprintf('kernel_%s.yml', $this->getName()) ] ); if (is_file($configFile)) { $ret[]= $configFile; } return $ret; }
php
protected function getConfigFiles() { $ret = []; foreach ($this->getCandidateConfigFiles() as $configFile) { if (is_file($configFile)) { $ret[]= $configFile; break; } } $configFile = join( '/', [ $this->getRootDir(), 'config', sprintf('kernel_%s.yml', $this->getName()) ] ); if (is_file($configFile)) { $ret[]= $configFile; } return $ret; }
[ "protected", "function", "getConfigFiles", "(", ")", "{", "$", "ret", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "getCandidateConfigFiles", "(", ")", "as", "$", "configFile", ")", "{", "if", "(", "is_file", "(", "$", "configFile", ")", ")",...
Get all config files which should be loaded. Can be overridden for custom logic. By default, following files are loaded (relativy to `getRootDir()`) - if `config/config_local.yml` exists, load that. - if `config/config_local.yml` does not exist, load `config/config_{environment}.yml` - additionally: `config/kernel_{name}.yml` @return array
[ "Get", "all", "config", "files", "which", "should", "be", "loaded", ".", "Can", "be", "overridden", "for", "custom", "logic", "." ]
ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d
https://github.com/zicht/symfony-util/blob/ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d/src/Zicht/SymfonyUtil/HttpKernel/Kernel.php#L126-L147
train
zicht/symfony-util
src/Zicht/SymfonyUtil/HttpKernel/Kernel.php
Kernel.attachSession
protected function attachSession(Request $request) { // TODO consider generating this code based on the ContainerBuilder / PhpDumper from Symfony DI. $container = $this->bootLightweightContainer(); if ($this->sessionConfig && @is_readable($this->getRootDir() . '/' . $this->sessionConfig)) { require_once $this->getRootDir() . '/' . $this->sessionConfig; if ($request->cookies->has($container->getParameter('session.name'))) { if (is_readable($this->getCacheDir() . '/classes.php')) { require_once $this->getCacheDir() . '/classes.php'; } $class = $container->getParameter('session.handler.class'); $session = new Session\Session( new Session\Storage\NativeSessionStorage( array( 'cookie_path' => $container->getParameter('session.cookie_path'), 'cookie_domain' => $container->getParameter('session.cookie_domain'), 'name' => $container->getParameter('session.name') ), new $class($container->getParameter('session.handler.save_path')), new Session\Storage\MetadataBag() ), new Session\Attribute\AttributeBag(), new Session\Flash\FlashBag() ); $this->lightweightContainer->set('session', $session); $request->setSession($session); } } }
php
protected function attachSession(Request $request) { // TODO consider generating this code based on the ContainerBuilder / PhpDumper from Symfony DI. $container = $this->bootLightweightContainer(); if ($this->sessionConfig && @is_readable($this->getRootDir() . '/' . $this->sessionConfig)) { require_once $this->getRootDir() . '/' . $this->sessionConfig; if ($request->cookies->has($container->getParameter('session.name'))) { if (is_readable($this->getCacheDir() . '/classes.php')) { require_once $this->getCacheDir() . '/classes.php'; } $class = $container->getParameter('session.handler.class'); $session = new Session\Session( new Session\Storage\NativeSessionStorage( array( 'cookie_path' => $container->getParameter('session.cookie_path'), 'cookie_domain' => $container->getParameter('session.cookie_domain'), 'name' => $container->getParameter('session.name') ), new $class($container->getParameter('session.handler.save_path')), new Session\Storage\MetadataBag() ), new Session\Attribute\AttributeBag(), new Session\Flash\FlashBag() ); $this->lightweightContainer->set('session', $session); $request->setSession($session); } } }
[ "protected", "function", "attachSession", "(", "Request", "$", "request", ")", "{", "// TODO consider generating this code based on the ContainerBuilder / PhpDumper from Symfony DI.", "$", "container", "=", "$", "this", "->", "bootLightweightContainer", "(", ")", ";", "if", ...
Attach a session to the request. @param Request $request @return void
[ "Attach", "a", "session", "to", "the", "request", "." ]
ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d
https://github.com/zicht/symfony-util/blob/ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d/src/Zicht/SymfonyUtil/HttpKernel/Kernel.php#L187-L218
train
zicht/symfony-util
src/Zicht/SymfonyUtil/HttpKernel/Kernel.php
Kernel.bootLightweightContainer
protected function bootLightweightContainer() { if (null === $this->lightweightContainer) { $this->lightweightContainer = $container = new Container(); foreach ($this->getKernelParameters() as $param => $value) { $this->lightweightContainer->setParameter($param, $value); } } return $this->lightweightContainer; }
php
protected function bootLightweightContainer() { if (null === $this->lightweightContainer) { $this->lightweightContainer = $container = new Container(); foreach ($this->getKernelParameters() as $param => $value) { $this->lightweightContainer->setParameter($param, $value); } } return $this->lightweightContainer; }
[ "protected", "function", "bootLightweightContainer", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "lightweightContainer", ")", "{", "$", "this", "->", "lightweightContainer", "=", "$", "container", "=", "new", "Container", "(", ")", ";", "fore...
Boot a lightweight container which can be used for early request handling @return null|Container
[ "Boot", "a", "lightweight", "container", "which", "can", "be", "used", "for", "early", "request", "handling" ]
ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d
https://github.com/zicht/symfony-util/blob/ba6ea81a7d4d12b2ed953d2b1a5cd2aa7b518c1d/src/Zicht/SymfonyUtil/HttpKernel/Kernel.php#L225-L237
train
netgen-layouts/content-browser
bundle/Controller/API/LoadConfig.php
LoadConfig.getAvailableColumns
private function getAvailableColumns(): array { $availableColumns = []; foreach ($this->config->getColumns() as $identifier => $columnData) { $availableColumns[] = [ 'id' => $identifier, 'name' => $this->translator->trans($columnData['name'], [], 'ngcb'), ]; } return $availableColumns; }
php
private function getAvailableColumns(): array { $availableColumns = []; foreach ($this->config->getColumns() as $identifier => $columnData) { $availableColumns[] = [ 'id' => $identifier, 'name' => $this->translator->trans($columnData['name'], [], 'ngcb'), ]; } return $availableColumns; }
[ "private", "function", "getAvailableColumns", "(", ")", ":", "array", "{", "$", "availableColumns", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "config", "->", "getColumns", "(", ")", "as", "$", "identifier", "=>", "$", "columnData", ")", "{",...
Returns the list of available columns from configuration.
[ "Returns", "the", "list", "of", "available", "columns", "from", "configuration", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/Controller/API/LoadConfig.php#L76-L88
train
PhpGt/Input
src/Input.php
Input.contains
public function contains(string $key, string $method = null):bool { if(is_null($method)) { $method = self::DATA_COMBINED; } switch($method) { case self::DATA_QUERYSTRING: $isset = $this->containsQueryStringParameter($key); break; case self::DATA_BODY: $isset =$this->containsBodyParameter($key); break; case self::DATA_FILES: $isset =$this->containsFile($key); break; case self::DATA_COMBINED: $isset = isset($this->parameters[$key]); break; default: throw new InvalidInputMethodException($method); } return $isset; }
php
public function contains(string $key, string $method = null):bool { if(is_null($method)) { $method = self::DATA_COMBINED; } switch($method) { case self::DATA_QUERYSTRING: $isset = $this->containsQueryStringParameter($key); break; case self::DATA_BODY: $isset =$this->containsBodyParameter($key); break; case self::DATA_FILES: $isset =$this->containsFile($key); break; case self::DATA_COMBINED: $isset = isset($this->parameters[$key]); break; default: throw new InvalidInputMethodException($method); } return $isset; }
[ "public", "function", "contains", "(", "string", "$", "key", ",", "string", "$", "method", "=", "null", ")", ":", "bool", "{", "if", "(", "is_null", "(", "$", "method", ")", ")", "{", "$", "method", "=", "self", "::", "DATA_COMBINED", ";", "}", "sw...
Does the input contain the specified key?
[ "Does", "the", "input", "contain", "the", "specified", "key?" ]
2a93bb01d1cb05a958309c0d777bd0085726a198
https://github.com/PhpGt/Input/blob/2a93bb01d1cb05a958309c0d777bd0085726a198/src/Input.php#L146-L173
train
PhpGt/Input
src/Input.php
Input.with
public function with(string...$keys):Trigger { foreach($keys as $key) { if(!$this->parameters->contains($key)) { throw new MissingInputParameterException($key); } } return $this->newTrigger("with", ...$keys); }
php
public function with(string...$keys):Trigger { foreach($keys as $key) { if(!$this->parameters->contains($key)) { throw new MissingInputParameterException($key); } } return $this->newTrigger("with", ...$keys); }
[ "public", "function", "with", "(", "string", "...", "$", "keys", ")", ":", "Trigger", "{", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "parameters", "->", "contains", "(", "$", "key", ")", ")", "{",...
Return a Trigger that will only pass the provided keys to its callback.
[ "Return", "a", "Trigger", "that", "will", "only", "pass", "the", "provided", "keys", "to", "its", "callback", "." ]
2a93bb01d1cb05a958309c0d777bd0085726a198
https://github.com/PhpGt/Input/blob/2a93bb01d1cb05a958309c0d777bd0085726a198/src/Input.php#L234-L242
train
netgen-layouts/content-browser
lib/Form/Type/ContentBrowserMultipleType.php
ContentBrowserMultipleType.getItems
private function getItems($itemValues, string $itemType): array { $items = []; foreach ((array) $itemValues as $itemValue) { try { $backend = $this->backendRegistry->getBackend($itemType); $item = $backend->loadItem($itemValue); $items[$item->getValue()] = $item; } catch (NotFoundException $e) { // Do nothing } } return $items; }
php
private function getItems($itemValues, string $itemType): array { $items = []; foreach ((array) $itemValues as $itemValue) { try { $backend = $this->backendRegistry->getBackend($itemType); $item = $backend->loadItem($itemValue); $items[$item->getValue()] = $item; } catch (NotFoundException $e) { // Do nothing } } return $items; }
[ "private", "function", "getItems", "(", "$", "itemValues", ",", "string", "$", "itemType", ")", ":", "array", "{", "$", "items", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "itemValues", "as", "$", "itemValue", ")", "{", "try", "{", ...
Returns the array of items for all provided item values. @param mixed $itemValues @param string $itemType @return array
[ "Returns", "the", "array", "of", "items", "for", "all", "provided", "item", "values", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/lib/Form/Type/ContentBrowserMultipleType.php#L130-L145
train
netgen-layouts/content-browser
bundle/EventListener/SetCurrentConfigListener.php
SetCurrentConfigListener.onKernelRequest
public function onKernelRequest(GetResponseEvent $event): void { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $attributes = $request->attributes; if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) { return; } if (!$attributes->has('itemType')) { return; } $config = $this->loadConfig($attributes->get('itemType')); $customParams = $request->query->get('customParams', []); if (!is_array($customParams)) { throw new RuntimeException( sprintf( 'Invalid custom parameters specification for "%s" item type.', $attributes->get('itemType') ) ); } $config->addParameters($customParams); $configLoadEvent = new ConfigLoadEvent($config); Kernel::VERSION_ID >= 40300 ? $this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) : $this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent); $this->container->set('netgen_content_browser.current_config', $config); }
php
public function onKernelRequest(GetResponseEvent $event): void { if (!$event->isMasterRequest()) { return; } $request = $event->getRequest(); $attributes = $request->attributes; if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) { return; } if (!$attributes->has('itemType')) { return; } $config = $this->loadConfig($attributes->get('itemType')); $customParams = $request->query->get('customParams', []); if (!is_array($customParams)) { throw new RuntimeException( sprintf( 'Invalid custom parameters specification for "%s" item type.', $attributes->get('itemType') ) ); } $config->addParameters($customParams); $configLoadEvent = new ConfigLoadEvent($config); Kernel::VERSION_ID >= 40300 ? $this->eventDispatcher->dispatch($configLoadEvent, ContentBrowserEvents::CONFIG_LOAD) : $this->eventDispatcher->dispatch(ContentBrowserEvents::CONFIG_LOAD, $configLoadEvent); $this->container->set('netgen_content_browser.current_config', $config); }
[ "public", "function", "onKernelRequest", "(", "GetResponseEvent", "$", "event", ")", ":", "void", "{", "if", "(", "!", "$", "event", "->", "isMasterRequest", "(", ")", ")", "{", "return", ";", "}", "$", "request", "=", "$", "event", "->", "getRequest", ...
Injects the current config into container.
[ "Injects", "the", "current", "config", "into", "container", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/SetCurrentConfigListener.php#L45-L82
train
netgen-layouts/content-browser
bundle/EventListener/SetCurrentConfigListener.php
SetCurrentConfigListener.loadConfig
private function loadConfig(string $itemType): Configuration { $service = 'netgen_content_browser.config.' . $itemType; if (!$this->container->has($service)) { throw new InvalidArgumentException( sprintf( 'Configuration for "%s" item type does not exist.', $itemType ) ); } $config = $this->container->get($service); if (!$config instanceof Configuration) { throw new InvalidArgumentException( sprintf( 'Configuration for "%s" item type is invalid.', $itemType ) ); } return $config; }
php
private function loadConfig(string $itemType): Configuration { $service = 'netgen_content_browser.config.' . $itemType; if (!$this->container->has($service)) { throw new InvalidArgumentException( sprintf( 'Configuration for "%s" item type does not exist.', $itemType ) ); } $config = $this->container->get($service); if (!$config instanceof Configuration) { throw new InvalidArgumentException( sprintf( 'Configuration for "%s" item type is invalid.', $itemType ) ); } return $config; }
[ "private", "function", "loadConfig", "(", "string", "$", "itemType", ")", ":", "Configuration", "{", "$", "service", "=", "'netgen_content_browser.config.'", ".", "$", "itemType", ";", "if", "(", "!", "$", "this", "->", "container", "->", "has", "(", "$", ...
Loads the configuration for provided item type from the container. @throws \Netgen\ContentBrowser\Exceptions\InvalidArgumentException If config could not be found
[ "Loads", "the", "configuration", "for", "provided", "item", "type", "from", "the", "container", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/SetCurrentConfigListener.php#L89-L113
train
netgen-layouts/content-browser
lib/Item/ColumnProvider/ColumnProvider.php
ColumnProvider.provideColumn
private function provideColumn(ItemInterface $item, array $columnConfig): string { if (isset($columnConfig['template'])) { return $this->itemRenderer->renderItem( $item, $columnConfig['template'] ); } if (!isset($this->columnValueProviders[$columnConfig['value_provider']])) { throw new InvalidArgumentException( sprintf( 'Column value provider "%s" does not exist', $columnConfig['value_provider'] ) ); } $columnValue = $this ->columnValueProviders[$columnConfig['value_provider']] ->getValue($item); return $columnValue ?? ''; }
php
private function provideColumn(ItemInterface $item, array $columnConfig): string { if (isset($columnConfig['template'])) { return $this->itemRenderer->renderItem( $item, $columnConfig['template'] ); } if (!isset($this->columnValueProviders[$columnConfig['value_provider']])) { throw new InvalidArgumentException( sprintf( 'Column value provider "%s" does not exist', $columnConfig['value_provider'] ) ); } $columnValue = $this ->columnValueProviders[$columnConfig['value_provider']] ->getValue($item); return $columnValue ?? ''; }
[ "private", "function", "provideColumn", "(", "ItemInterface", "$", "item", ",", "array", "$", "columnConfig", ")", ":", "string", "{", "if", "(", "isset", "(", "$", "columnConfig", "[", "'template'", "]", ")", ")", "{", "return", "$", "this", "->", "item...
Provides the column with specified identifier for selected item. @throws \Netgen\ContentBrowser\Exceptions\InvalidArgumentException If value provider for the column does not exist
[ "Provides", "the", "column", "with", "specified", "identifier", "for", "selected", "item", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/lib/Item/ColumnProvider/ColumnProvider.php#L65-L88
train
netgen-layouts/content-browser
lib/Form/Type/ContentBrowserDynamicType.php
ContentBrowserDynamicType.getEnabledItemTypes
private function getEnabledItemTypes(array $itemTypes): array { $allItemTypes = array_flip( array_map( static function (Configuration $config): string { return $config->getItemName(); }, $this->configRegistry->getConfigs() ) ); if (count($itemTypes) === 0) { return $allItemTypes; } return array_filter( $allItemTypes, static function (string $itemType) use ($itemTypes): bool { return in_array($itemType, $itemTypes, true); } ); }
php
private function getEnabledItemTypes(array $itemTypes): array { $allItemTypes = array_flip( array_map( static function (Configuration $config): string { return $config->getItemName(); }, $this->configRegistry->getConfigs() ) ); if (count($itemTypes) === 0) { return $allItemTypes; } return array_filter( $allItemTypes, static function (string $itemType) use ($itemTypes): bool { return in_array($itemType, $itemTypes, true); } ); }
[ "private", "function", "getEnabledItemTypes", "(", "array", "$", "itemTypes", ")", ":", "array", "{", "$", "allItemTypes", "=", "array_flip", "(", "array_map", "(", "static", "function", "(", "Configuration", "$", "config", ")", ":", "string", "{", "return", ...
Returns the enabled item types based on provided list.
[ "Returns", "the", "enabled", "item", "types", "based", "on", "provided", "list", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/lib/Form/Type/ContentBrowserDynamicType.php#L147-L168
train
netgen-layouts/content-browser
bundle/EventListener/ExceptionSerializerListener.php
ExceptionSerializerListener.onException
public function onException(GetResponseForExceptionEvent $event): void { if (!$event->isMasterRequest()) { return; } $attributes = $event->getRequest()->attributes; if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) { return; } $exception = $event->getException(); $this->logException($exception); $data = [ 'code' => $exception->getCode(), 'message' => $exception->getMessage(), ]; if ($exception instanceof HttpExceptionInterface) { $statusCode = $exception->getStatusCode(); if (isset(Response::$statusTexts[$statusCode])) { $data['status_code'] = $statusCode; $data['status_text'] = Response::$statusTexts[$statusCode]; } } if ($this->outputDebugInfo) { $debugException = $exception; if ($exception->getPrevious() instanceof Exception) { $debugException = $exception->getPrevious(); } $debugException = FlattenException::create($debugException); $data['debug'] = [ 'file' => $debugException->getFile(), 'line' => $debugException->getLine(), 'trace' => $debugException->getTrace(), ]; } $event->setResponse(new JsonResponse($data)); }
php
public function onException(GetResponseForExceptionEvent $event): void { if (!$event->isMasterRequest()) { return; } $attributes = $event->getRequest()->attributes; if ($attributes->get(SetIsApiRequestListener::API_FLAG_NAME) !== true) { return; } $exception = $event->getException(); $this->logException($exception); $data = [ 'code' => $exception->getCode(), 'message' => $exception->getMessage(), ]; if ($exception instanceof HttpExceptionInterface) { $statusCode = $exception->getStatusCode(); if (isset(Response::$statusTexts[$statusCode])) { $data['status_code'] = $statusCode; $data['status_text'] = Response::$statusTexts[$statusCode]; } } if ($this->outputDebugInfo) { $debugException = $exception; if ($exception->getPrevious() instanceof Exception) { $debugException = $exception->getPrevious(); } $debugException = FlattenException::create($debugException); $data['debug'] = [ 'file' => $debugException->getFile(), 'line' => $debugException->getLine(), 'trace' => $debugException->getTrace(), ]; } $event->setResponse(new JsonResponse($data)); }
[ "public", "function", "onException", "(", "GetResponseForExceptionEvent", "$", "event", ")", ":", "void", "{", "if", "(", "!", "$", "event", "->", "isMasterRequest", "(", ")", ")", "{", "return", ";", "}", "$", "attributes", "=", "$", "event", "->", "get...
Serializes the exception.
[ "Serializes", "the", "exception", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/ExceptionSerializerListener.php#L45-L89
train
netgen-layouts/content-browser
bundle/EventListener/ExceptionSerializerListener.php
ExceptionSerializerListener.logException
private function logException(Exception $exception): void { if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) { return; } $this->logger->critical( sprintf( 'Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine() ), ['exception' => $exception] ); }
php
private function logException(Exception $exception): void { if ($exception instanceof HttpExceptionInterface && $exception->getStatusCode() < 500) { return; } $this->logger->critical( sprintf( 'Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine() ), ['exception' => $exception] ); }
[ "private", "function", "logException", "(", "Exception", "$", "exception", ")", ":", "void", "{", "if", "(", "$", "exception", "instanceof", "HttpExceptionInterface", "&&", "$", "exception", "->", "getStatusCode", "(", ")", "<", "500", ")", "{", "return", ";...
Logs all critical errors.
[ "Logs", "all", "critical", "errors", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/EventListener/ExceptionSerializerListener.php#L94-L110
train
netgen-layouts/content-browser
bundle/Controller/API/LoadSubItems.php
LoadSubItems.buildPath
private function buildPath(LocationInterface $location): array { $path = []; while (true) { $path[] = [ 'id' => $location->getLocationId(), 'name' => $location->getName(), ]; if ($location->getParentId() === null) { break; } try { $location = $this->backend->loadLocation($location->getParentId()); } catch (NotFoundException $e) { break; } } return array_reverse($path); }
php
private function buildPath(LocationInterface $location): array { $path = []; while (true) { $path[] = [ 'id' => $location->getLocationId(), 'name' => $location->getName(), ]; if ($location->getParentId() === null) { break; } try { $location = $this->backend->loadLocation($location->getParentId()); } catch (NotFoundException $e) { break; } } return array_reverse($path); }
[ "private", "function", "buildPath", "(", "LocationInterface", "$", "location", ")", ":", "array", "{", "$", "path", "=", "[", "]", ";", "while", "(", "true", ")", "{", "$", "path", "[", "]", "=", "[", "'id'", "=>", "$", "location", "->", "getLocation...
Builds the path array for specified item.
[ "Builds", "the", "path", "array", "for", "specified", "item", "." ]
34403d59b73b0e804f12746d4418ba44e4991d74
https://github.com/netgen-layouts/content-browser/blob/34403d59b73b0e804f12746d4418ba44e4991d74/bundle/Controller/API/LoadSubItems.php#L82-L104
train
koolkode/bpmn
src/Runtime/RuntimeService.php
RuntimeService.startProcessInstance
public function startProcessInstance(ProcessDefinition $def, $businessKey = null, array $variables = []) { $startNode = $def->findNoneStartEvent(); $id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables)); return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne(); }
php
public function startProcessInstance(ProcessDefinition $def, $businessKey = null, array $variables = []) { $startNode = $def->findNoneStartEvent(); $id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables)); return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne(); }
[ "public", "function", "startProcessInstance", "(", "ProcessDefinition", "$", "def", ",", "$", "businessKey", "=", "null", ",", "array", "$", "variables", "=", "[", "]", ")", "{", "$", "startNode", "=", "$", "def", "->", "findNoneStartEvent", "(", ")", ";",...
Start a process from the given definition using a singular @param ProcessDefinition $def @param string $businessKey @param array<string, mixed> $variables @return HistoricProcessInstance
[ "Start", "a", "process", "from", "the", "given", "definition", "using", "a", "singular" ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/RuntimeService.php#L107-L114
train
koolkode/bpmn
src/Runtime/RuntimeService.php
RuntimeService.startProcessInstanceByKey
public function startProcessInstanceByKey($processDefinitionKey, $businessKey = null, array $variables = []) { $query = $this->engine->getRepositoryService()->createProcessDefinitionQuery(); $def = $query->processDefinitionKey($processDefinitionKey)->latestVersion()->findOne(); return $this->startProcessInstance($def, $businessKey, $variables); }
php
public function startProcessInstanceByKey($processDefinitionKey, $businessKey = null, array $variables = []) { $query = $this->engine->getRepositoryService()->createProcessDefinitionQuery(); $def = $query->processDefinitionKey($processDefinitionKey)->latestVersion()->findOne(); return $this->startProcessInstance($def, $businessKey, $variables); }
[ "public", "function", "startProcessInstanceByKey", "(", "$", "processDefinitionKey", ",", "$", "businessKey", "=", "null", ",", "array", "$", "variables", "=", "[", "]", ")", "{", "$", "query", "=", "$", "this", "->", "engine", "->", "getRepositoryService", ...
Start a process using the latest version of the given process definition. @param string $processDefinitionKey @param string $businessKey @param array<string, mixed> $variables @return HistoricProcessInstance
[ "Start", "a", "process", "using", "the", "latest", "version", "of", "the", "given", "process", "definition", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/RuntimeService.php#L124-L130
train
koolkode/bpmn
src/Runtime/RuntimeService.php
RuntimeService.startProcessInstanceByMessage
public function startProcessInstanceByMessage($messageName, $businessKey = null, array $variables = []) { $query = $this->engine->getRepositoryService()->createProcessDefinitionQuery(); $def = $query->messageEventSubscriptionName($messageName)->latestVersion()->findOne(); $startNode = $def->findMessageStartEvent($messageName); $id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables)); return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne(); }
php
public function startProcessInstanceByMessage($messageName, $businessKey = null, array $variables = []) { $query = $this->engine->getRepositoryService()->createProcessDefinitionQuery(); $def = $query->messageEventSubscriptionName($messageName)->latestVersion()->findOne(); $startNode = $def->findMessageStartEvent($messageName); $id = $this->engine->executeCommand(new StartProcessInstanceCommand($def, $startNode, $businessKey, $variables)); return $this->engine->getHistoryService()->createHistoricProcessInstanceQuery()->processInstanceId($id)->findOne(); }
[ "public", "function", "startProcessInstanceByMessage", "(", "$", "messageName", ",", "$", "businessKey", "=", "null", ",", "array", "$", "variables", "=", "[", "]", ")", "{", "$", "query", "=", "$", "this", "->", "engine", "->", "getRepositoryService", "(", ...
Start a process instance by message start event. @param string $messageName @param string $businessKey @param array<string, mixed> $variables @return HistoricProcessInstance
[ "Start", "a", "process", "instance", "by", "message", "start", "event", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/RuntimeService.php#L140-L149
train
koolkode/bpmn
src/Engine/ProcessEngine.php
ProcessEngine.scheduleJob
public function scheduleJob(UUID $executionId, string $handlerType, $data, ?\DateTimeImmutable $runAt = null): ?JobInterface { if ($this->jobExecutor !== null) { return $this->jobExecutor->scheduleJob($executionId, $handlerType, $data, $runAt); } }
php
public function scheduleJob(UUID $executionId, string $handlerType, $data, ?\DateTimeImmutable $runAt = null): ?JobInterface { if ($this->jobExecutor !== null) { return $this->jobExecutor->scheduleJob($executionId, $handlerType, $data, $runAt); } }
[ "public", "function", "scheduleJob", "(", "UUID", "$", "executionId", ",", "string", "$", "handlerType", ",", "$", "data", ",", "?", "\\", "DateTimeImmutable", "$", "runAt", "=", "null", ")", ":", "?", "JobInterface", "{", "if", "(", "$", "this", "->", ...
Schedule a job for execution. This method will not cause an error in case of a missing job executor! @param UUID $executionId Target execution being used by the job. @param string $handlerType The name of the job handler. @param mixed $data Arbitrary data to be passed to the job handler. @param \DateTimeImmutable $runAt Scheduled execution time, a value of null schedules the job for immediate execution. @return JobInterface The persisted job instance or null when no job executor has been configured.
[ "Schedule", "a", "job", "for", "execution", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/ProcessEngine.php#L218-L223
train
koolkode/bpmn
migration/Version20150212110141.php
Version20150212110141.down
public function down() { $def = $this->table('#__bpmn_process_definition'); $def->removeColumn('resource_id'); $def->update(); $subscription = $this->table('#__bpmn_event_subscription'); $subscription->removeColumn('job_id'); $subscription->removeColumn('boundary'); $subscription->update(); $this->dropTable('#__bpmn_job'); }
php
public function down() { $def = $this->table('#__bpmn_process_definition'); $def->removeColumn('resource_id'); $def->update(); $subscription = $this->table('#__bpmn_event_subscription'); $subscription->removeColumn('job_id'); $subscription->removeColumn('boundary'); $subscription->update(); $this->dropTable('#__bpmn_job'); }
[ "public", "function", "down", "(", ")", "{", "$", "def", "=", "$", "this", "->", "table", "(", "'#__bpmn_process_definition'", ")", ";", "$", "def", "->", "removeColumn", "(", "'resource_id'", ")", ";", "$", "def", "->", "update", "(", ")", ";", "$", ...
Migrate down.
[ "Migrate", "down", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/migration/Version20150212110141.php#L64-L76
train
koolkode/bpmn
src/Job/Scheduler/AbstractJobScheduler.php
AbstractJobScheduler.markJobAsScheduled
protected function markJobAsScheduled(Job $job, ?string $externalId = null): void { $stmt = $this->engine->prepareQuery("UPDATE `#__bpmn_job` SET `scheduled_at` = :scheduled, `external_id` = :ex WHERE `id` = :id"); $stmt->bindValue('scheduled', \time()); $stmt->bindValue('ex', $externalId); $stmt->bindValue('id', $job->getId()); $stmt->execute(); }
php
protected function markJobAsScheduled(Job $job, ?string $externalId = null): void { $stmt = $this->engine->prepareQuery("UPDATE `#__bpmn_job` SET `scheduled_at` = :scheduled, `external_id` = :ex WHERE `id` = :id"); $stmt->bindValue('scheduled', \time()); $stmt->bindValue('ex', $externalId); $stmt->bindValue('id', $job->getId()); $stmt->execute(); }
[ "protected", "function", "markJobAsScheduled", "(", "Job", "$", "job", ",", "?", "string", "$", "externalId", "=", "null", ")", ":", "void", "{", "$", "stmt", "=", "$", "this", "->", "engine", "->", "prepareQuery", "(", "\"UPDATE `#__bpmn_job` SET `scheduled_a...
Marks the job is being scheduled by writing a timestamp to the DB. @param Job $job
[ "Marks", "the", "job", "is", "being", "scheduled", "by", "writing", "a", "timestamp", "to", "the", "DB", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Job/Scheduler/AbstractJobScheduler.php#L41-L48
train
koolkode/bpmn
src/Engine/AbstractScopeActivity.php
AbstractScopeActivity.interrupt
public function interrupt(VirtualExecution $execution, ?array $transitions = null): void { $this->leave($execution, $transitions, true); }
php
public function interrupt(VirtualExecution $execution, ?array $transitions = null): void { $this->leave($execution, $transitions, true); }
[ "public", "function", "interrupt", "(", "VirtualExecution", "$", "execution", ",", "?", "array", "$", "transitions", "=", "null", ")", ":", "void", "{", "$", "this", "->", "leave", "(", "$", "execution", ",", "$", "transitions", ",", "true", ")", ";", ...
Interrupt the scope activity.
[ "Interrupt", "the", "scope", "activity", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractScopeActivity.php#L88-L91
train
koolkode/bpmn
src/Engine/AbstractScopeActivity.php
AbstractScopeActivity.leaveConcurrent
public function leaveConcurrent(VirtualExecution $execution, ?Node $node = null, ?array $transitions = null): VirtualExecution { $root = $execution->getScope(); $parent = $root->getParentExecution(); $exec = $parent->createExecution(true); $exec->setNode(($node === null) ? $execution->getNode() : $node); $root->setConcurrent(true); $this->createEventSubscriptions($root, $this->activityId, $execution->getProcessModel()->findNode($this->activityId)); $exec->takeAll($transitions); return $exec; }
php
public function leaveConcurrent(VirtualExecution $execution, ?Node $node = null, ?array $transitions = null): VirtualExecution { $root = $execution->getScope(); $parent = $root->getParentExecution(); $exec = $parent->createExecution(true); $exec->setNode(($node === null) ? $execution->getNode() : $node); $root->setConcurrent(true); $this->createEventSubscriptions($root, $this->activityId, $execution->getProcessModel()->findNode($this->activityId)); $exec->takeAll($transitions); return $exec; }
[ "public", "function", "leaveConcurrent", "(", "VirtualExecution", "$", "execution", ",", "?", "Node", "$", "node", "=", "null", ",", "?", "array", "$", "transitions", "=", "null", ")", ":", "VirtualExecution", "{", "$", "root", "=", "$", "execution", "->",...
Create a new execution concurrent to the given execution and have it take the given transitions. If the given execution is concurrent this method will create a new child execution from the parent execution. Otherwise a new concurrent root will be introduced as parent of the given execution.
[ "Create", "a", "new", "execution", "concurrent", "to", "the", "given", "execution", "and", "have", "it", "take", "the", "given", "transitions", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractScopeActivity.php#L129-L144
train
koolkode/bpmn
src/Engine/AbstractScopeActivity.php
AbstractScopeActivity.findAttachedBoundaryActivities
public function findAttachedBoundaryActivities(VirtualExecution $execution): array { $model = $execution->getProcessModel(); $activities = []; foreach ($model->findNodes() as $node) { $behavior = $node->getBehavior(); if ($behavior instanceof AbstractBoundaryActivity) { if ($this->activityId == $behavior->getAttachedTo()) { $activities[] = $node; } } } return $activities; }
php
public function findAttachedBoundaryActivities(VirtualExecution $execution): array { $model = $execution->getProcessModel(); $activities = []; foreach ($model->findNodes() as $node) { $behavior = $node->getBehavior(); if ($behavior instanceof AbstractBoundaryActivity) { if ($this->activityId == $behavior->getAttachedTo()) { $activities[] = $node; } } } return $activities; }
[ "public", "function", "findAttachedBoundaryActivities", "(", "VirtualExecution", "$", "execution", ")", ":", "array", "{", "$", "model", "=", "$", "execution", "->", "getProcessModel", "(", ")", ";", "$", "activities", "=", "[", "]", ";", "foreach", "(", "$"...
Collect all boundary events connected to the activity of the given execution.
[ "Collect", "all", "boundary", "events", "connected", "to", "the", "activity", "of", "the", "given", "execution", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractScopeActivity.php#L149-L165
train
koolkode/bpmn
src/Runtime/Command/AbstractCreateSubscriptionCommand.php
AbstractCreateSubscriptionCommand.createSubscription
protected function createSubscription(ProcessEngine $engine, ?Job $job = null): void { $execution = $engine->findExecution($this->executionId); $nodeId = ($this->nodeId === null) ? null : $execution->getProcessModel()->findNode($this->nodeId)->getId(); $data = [ 'id' => UUID::createRandom(), 'execution_id' => $execution->getId(), 'activity_id' => $this->activityId, 'node' => $nodeId, 'process_instance_id' => $execution->getRootExecution()->getId(), 'flags' => $this->getSubscriptionFlag(), 'boundary' => $this->boundaryEvent ? 1 : 0, 'name' => $this->name, 'created_at' => \time() ]; if ($job !== null) { $data['job_id'] = $job->getId(); } $engine->getConnection()->insert('#__bpmn_event_subscription', $data); }
php
protected function createSubscription(ProcessEngine $engine, ?Job $job = null): void { $execution = $engine->findExecution($this->executionId); $nodeId = ($this->nodeId === null) ? null : $execution->getProcessModel()->findNode($this->nodeId)->getId(); $data = [ 'id' => UUID::createRandom(), 'execution_id' => $execution->getId(), 'activity_id' => $this->activityId, 'node' => $nodeId, 'process_instance_id' => $execution->getRootExecution()->getId(), 'flags' => $this->getSubscriptionFlag(), 'boundary' => $this->boundaryEvent ? 1 : 0, 'name' => $this->name, 'created_at' => \time() ]; if ($job !== null) { $data['job_id'] = $job->getId(); } $engine->getConnection()->insert('#__bpmn_event_subscription', $data); }
[ "protected", "function", "createSubscription", "(", "ProcessEngine", "$", "engine", ",", "?", "Job", "$", "job", "=", "null", ")", ":", "void", "{", "$", "execution", "=", "$", "engine", "->", "findExecution", "(", "$", "this", "->", "executionId", ")", ...
Create an event subscription entry in the DB.
[ "Create", "an", "event", "subscription", "entry", "in", "the", "DB", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Runtime/Command/AbstractCreateSubscriptionCommand.php#L96-L118
train
koolkode/bpmn
src/Engine/AbstractActivity.php
AbstractActivity.leave
public function leave(VirtualExecution $execution, ?array $transitions = null): void { $execution->getEngine()->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $execution->getEngine())); $this->clearEventSubscriptions($execution, $execution->getNode()->getId()); $execution->takeAll($transitions); }
php
public function leave(VirtualExecution $execution, ?array $transitions = null): void { $execution->getEngine()->notify(new ActivityCompletedEvent($execution->getNode()->getId(), $execution, $execution->getEngine())); $this->clearEventSubscriptions($execution, $execution->getNode()->getId()); $execution->takeAll($transitions); }
[ "public", "function", "leave", "(", "VirtualExecution", "$", "execution", ",", "?", "array", "$", "transitions", "=", "null", ")", ":", "void", "{", "$", "execution", "->", "getEngine", "(", ")", "->", "notify", "(", "new", "ActivityCompletedEvent", "(", "...
Have the given execution leave the activity.
[ "Have", "the", "given", "execution", "leave", "the", "activity", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractActivity.php#L133-L140
train
koolkode/bpmn
src/Engine/AbstractActivity.php
AbstractActivity.passVariablesToExecution
protected function passVariablesToExecution(VirtualExecution $execution, array $variables): void { foreach ($variables as $k => $v) { $execution->setVariable($k, $v); } }
php
protected function passVariablesToExecution(VirtualExecution $execution, array $variables): void { foreach ($variables as $k => $v) { $execution->setVariable($k, $v); } }
[ "protected", "function", "passVariablesToExecution", "(", "VirtualExecution", "$", "execution", ",", "array", "$", "variables", ")", ":", "void", "{", "foreach", "(", "$", "variables", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "execution", "->", "setV...
Pass all variables given to the execution setting them in the executions's scope.
[ "Pass", "all", "variables", "given", "to", "the", "execution", "setting", "them", "in", "the", "executions", "s", "scope", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractActivity.php#L145-L150
train
koolkode/bpmn
src/Engine/AbstractActivity.php
AbstractActivity.delegateSignal
protected function delegateSignal(VirtualExecution $execution, ?string $signal, array $variables, array $delegation): bool { if (empty($delegation['nodeId'])) { return false; } $node = $execution->getProcessModel()->findNode($delegation['nodeId']); $execution->getEngine()->debug('Delegating signal <{signal}> to {node}', [ 'signal' => ($signal === null) ? 'null' : $signal, 'node' => (string) $node ]); $execution->setNode($node); $execution->waitForSignal(); $execution->signal($signal, $variables); return true; }
php
protected function delegateSignal(VirtualExecution $execution, ?string $signal, array $variables, array $delegation): bool { if (empty($delegation['nodeId'])) { return false; } $node = $execution->getProcessModel()->findNode($delegation['nodeId']); $execution->getEngine()->debug('Delegating signal <{signal}> to {node}', [ 'signal' => ($signal === null) ? 'null' : $signal, 'node' => (string) $node ]); $execution->setNode($node); $execution->waitForSignal(); $execution->signal($signal, $variables); return true; }
[ "protected", "function", "delegateSignal", "(", "VirtualExecution", "$", "execution", ",", "?", "string", "$", "signal", ",", "array", "$", "variables", ",", "array", "$", "delegation", ")", ":", "bool", "{", "if", "(", "empty", "(", "$", "delegation", "["...
Delegate signal to a target node using the same execution. @param VirtualExecution $execution @param string $signal @param array $variables @param array $delegation @return boolean Returns true if the signal could be delegated.
[ "Delegate", "signal", "to", "a", "target", "node", "using", "the", "same", "execution", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Engine/AbstractActivity.php#L161-L180
train
koolkode/bpmn
src/Repository/DeploymentBuilder.php
DeploymentBuilder.addExtensions
public function addExtensions($extensions): self { $this->fileExtensions = \array_unique(\array_merge($this->fileExtensions, \array_map('strtolower', (array) $extensions))); return $this; }
php
public function addExtensions($extensions): self { $this->fileExtensions = \array_unique(\array_merge($this->fileExtensions, \array_map('strtolower', (array) $extensions))); return $this; }
[ "public", "function", "addExtensions", "(", "$", "extensions", ")", ":", "self", "{", "$", "this", "->", "fileExtensions", "=", "\\", "array_unique", "(", "\\", "array_merge", "(", "$", "this", "->", "fileExtensions", ",", "\\", "array_map", "(", "'strtolowe...
Add a file extension that shoul be parsed for BPMN 2.0 process definitions. The deployment mechanism will parse ".bpmn" files by default.
[ "Add", "a", "file", "extension", "that", "shoul", "be", "parsed", "for", "BPMN", "2", ".", "0", "process", "definitions", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L60-L65
train
koolkode/bpmn
src/Repository/DeploymentBuilder.php
DeploymentBuilder.isProcessResource
public function isProcessResource(string $name): bool { return \in_array(\strtolower(\pathinfo($name, \PATHINFO_EXTENSION)), $this->fileExtensions); }
php
public function isProcessResource(string $name): bool { return \in_array(\strtolower(\pathinfo($name, \PATHINFO_EXTENSION)), $this->fileExtensions); }
[ "public", "function", "isProcessResource", "(", "string", "$", "name", ")", ":", "bool", "{", "return", "\\", "in_array", "(", "\\", "strtolower", "(", "\\", "pathinfo", "(", "$", "name", ",", "\\", "PATHINFO_EXTENSION", ")", ")", ",", "$", "this", "->",...
Check if the given file will be parsed for BPMN 2.0 process definitions.
[ "Check", "if", "the", "given", "file", "will", "be", "parsed", "for", "BPMN", "2", ".", "0", "process", "definitions", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L70-L73
train
koolkode/bpmn
src/Repository/DeploymentBuilder.php
DeploymentBuilder.addResource
public function addResource(string $name, $resource): self { if ($resource instanceof StreamInterface) { $in = $resource; } elseif (\is_resource($resource)) { $in = new ResourceInputStream($resource); } else { $resource = (string) $resource; if (\preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $resource)) { $in = ResourceInputStream::fromUrl($resource); } else { $in = new StringStream($resource); } } $this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $in; return $this; }
php
public function addResource(string $name, $resource): self { if ($resource instanceof StreamInterface) { $in = $resource; } elseif (\is_resource($resource)) { $in = new ResourceInputStream($resource); } else { $resource = (string) $resource; if (\preg_match("'^/|(?:[^:\\\\/]+://)|(?:[a-z]:[\\\\/])'i", $resource)) { $in = ResourceInputStream::fromUrl($resource); } else { $in = new StringStream($resource); } } $this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $in; return $this; }
[ "public", "function", "addResource", "(", "string", "$", "name", ",", "$", "resource", ")", ":", "self", "{", "if", "(", "$", "resource", "instanceof", "StreamInterface", ")", "{", "$", "in", "=", "$", "resource", ";", "}", "elseif", "(", "\\", "is_res...
Add a resource to the deployment. @param string $name Local path and filename of the resource within the deployment. @param mixed $resource Deployable resource (file), that can be loaded using a stream.
[ "Add", "a", "resource", "to", "the", "deployment", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L81-L100
train
koolkode/bpmn
src/Repository/DeploymentBuilder.php
DeploymentBuilder.addArchive
public function addArchive(string $file): self { if (!\is_file($file)) { throw new \InvalidArgumentException(\sprintf('Archive not found: "%s"', $file)); } if (!\is_readable($file)) { throw new \RuntimeException(\sprintf('Archive not readable: "%s"', $file)); } $zip = new \ZipArchive(); $zip->open($file); try { for ($i = 0; $i < $zip->numFiles; $i++) { $stat = (array) $zip->statIndex($i); // This will skip empty files as well... need a better way to this eventually. if (empty($stat['size'])) { continue; } $name = $zip->getNameIndex($i); // Cap memory at 256KB to allow for large deployments when necessary. $stream = new StringStream('', 262144); $resource = $zip->getStream($name); try { while (!\feof($resource)) { $stream->write(\fread($resource, 8192)); } $stream->rewind(); } finally { @\fclose($resource); } $this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $stream; } } finally { @$zip->close(); } return $this; }
php
public function addArchive(string $file): self { if (!\is_file($file)) { throw new \InvalidArgumentException(\sprintf('Archive not found: "%s"', $file)); } if (!\is_readable($file)) { throw new \RuntimeException(\sprintf('Archive not readable: "%s"', $file)); } $zip = new \ZipArchive(); $zip->open($file); try { for ($i = 0; $i < $zip->numFiles; $i++) { $stat = (array) $zip->statIndex($i); // This will skip empty files as well... need a better way to this eventually. if (empty($stat['size'])) { continue; } $name = $zip->getNameIndex($i); // Cap memory at 256KB to allow for large deployments when necessary. $stream = new StringStream('', 262144); $resource = $zip->getStream($name); try { while (!\feof($resource)) { $stream->write(\fread($resource, 8192)); } $stream->rewind(); } finally { @\fclose($resource); } $this->resources[\trim(\str_replace('\\', '/', $name), '/')] = $stream; } } finally { @$zip->close(); } return $this; }
[ "public", "function", "addArchive", "(", "string", "$", "file", ")", ":", "self", "{", "if", "(", "!", "\\", "is_file", "(", "$", "file", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\\", "sprintf", "(", "'Archive not found: \"%s\...
Add a ZIP archives file contents to the deployment. @throws \InvalidArgumentException When the given archive could not be found. @throws \RuntimeException When the given archive could not be read.
[ "Add", "a", "ZIP", "archives", "file", "contents", "to", "the", "deployment", "." ]
49ff924fa97e0bbe1b74e914393b22760dcf7281
https://github.com/koolkode/bpmn/blob/49ff924fa97e0bbe1b74e914393b22760dcf7281/src/Repository/DeploymentBuilder.php#L108-L153
train