id
int32
0
241k
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
238,400
freddieannobil/doo-csrf
src/Session.php
Session.flash
public static function flash( $name, $string = '') { if( self::exists( $name ) ) { $session = self::get( $name ); self::delete( $name ); return $session; }else{ self::set( $name, $string ); } return ''; }
php
public static function flash( $name, $string = '') { if( self::exists( $name ) ) { $session = self::get( $name ); self::delete( $name ); return $session; }else{ self::set( $name, $string ); } return ''; }
[ "public", "static", "function", "flash", "(", "$", "name", ",", "$", "string", "=", "''", ")", "{", "if", "(", "self", "::", "exists", "(", "$", "name", ")", ")", "{", "$", "session", "=", "self", "::", "get", "(", "$", "name", ")", ";", "self", "::", "delete", "(", "$", "name", ")", ";", "return", "$", "session", ";", "}", "else", "{", "self", "::", "set", "(", "$", "name", ",", "$", "string", ")", ";", "}", "return", "''", ";", "}" ]
flash form, alert messages
[ "flash", "form", "alert", "messages" ]
ccecd9a3b8c998dc924c7d8adf44990476397e06
https://github.com/freddieannobil/doo-csrf/blob/ccecd9a3b8c998dc924c7d8adf44990476397e06/src/Session.php#L45-L56
238,401
squire-assistant/dependency-injection
Dumper/XmlDumper.php
XmlDumper.addParameters
private function addParameters(\DOMElement $parent) { $data = $this->container->getParameterBag()->all(); if (!$data) { return; } if ($this->container->isFrozen()) { $data = $this->escape($data); } $parameters = $this->document->createElement('parameters'); $parent->appendChild($parameters); $this->convertParameters($data, 'parameter', $parameters); }
php
private function addParameters(\DOMElement $parent) { $data = $this->container->getParameterBag()->all(); if (!$data) { return; } if ($this->container->isFrozen()) { $data = $this->escape($data); } $parameters = $this->document->createElement('parameters'); $parent->appendChild($parameters); $this->convertParameters($data, 'parameter', $parameters); }
[ "private", "function", "addParameters", "(", "\\", "DOMElement", "$", "parent", ")", "{", "$", "data", "=", "$", "this", "->", "container", "->", "getParameterBag", "(", ")", "->", "all", "(", ")", ";", "if", "(", "!", "$", "data", ")", "{", "return", ";", "}", "if", "(", "$", "this", "->", "container", "->", "isFrozen", "(", ")", ")", "{", "$", "data", "=", "$", "this", "->", "escape", "(", "$", "data", ")", ";", "}", "$", "parameters", "=", "$", "this", "->", "document", "->", "createElement", "(", "'parameters'", ")", ";", "$", "parent", "->", "appendChild", "(", "$", "parameters", ")", ";", "$", "this", "->", "convertParameters", "(", "$", "data", ",", "'parameter'", ",", "$", "parameters", ")", ";", "}" ]
Adds parameters. @param \DOMElement $parent
[ "Adds", "parameters", "." ]
c61d77bf8814369344fd71b015d7238322126041
https://github.com/squire-assistant/dependency-injection/blob/c61d77bf8814369344fd71b015d7238322126041/Dumper/XmlDumper.php#L66-L80
238,402
ricardopedias/string-arguments
src/Expression.php
Expression.addArguments
public function addArguments(array $arguments) { foreach ($arguments as $param => $value) { $this->addArgument($param, $value); } return $this; }
php
public function addArguments(array $arguments) { foreach ($arguments as $param => $value) { $this->addArgument($param, $value); } return $this; }
[ "public", "function", "addArguments", "(", "array", "$", "arguments", ")", "{", "foreach", "(", "$", "arguments", "as", "$", "param", "=>", "$", "value", ")", "{", "$", "this", "->", "addArgument", "(", "$", "param", ",", "$", "value", ")", ";", "}", "return", "$", "this", ";", "}" ]
Adiciona uma lista de argumentos. @param array $arguments @return StringArgs\Expression
[ "Adiciona", "uma", "lista", "de", "argumentos", "." ]
a715b80a93b6232926e91ebbfb88a844065bae65
https://github.com/ricardopedias/string-arguments/blob/a715b80a93b6232926e91ebbfb88a844065bae65/src/Expression.php#L106-L113
238,403
ricardopedias/string-arguments
src/Expression.php
Expression.getArgument
public function getArgument($name) { if (isset($this->arguments[$name])) { return $this->arguments[$name]; } return null; }
php
public function getArgument($name) { if (isset($this->arguments[$name])) { return $this->arguments[$name]; } return null; }
[ "public", "function", "getArgument", "(", "$", "name", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "arguments", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "arguments", "[", "$", "name", "]", ";", "}", "return", "null", ";", "}" ]
Devolve o argumento especificado. @return mixed|null
[ "Devolve", "o", "argumento", "especificado", "." ]
a715b80a93b6232926e91ebbfb88a844065bae65
https://github.com/ricardopedias/string-arguments/blob/a715b80a93b6232926e91ebbfb88a844065bae65/src/Expression.php#L130-L136
238,404
blenderdeluxe/khipu
src/KhipuService/KhipuRecipients.php
KhipuRecipients.addRecipient
public function addRecipient($name, $email, $amount) { if (count($this->recipients) == self::LIMIT_RECIPIENTS) { // El servicio tiene un limite return; } $this->recipients[] = array( 'name' => $name, 'email' => $email, 'amount' => $amount, ); }
php
public function addRecipient($name, $email, $amount) { if (count($this->recipients) == self::LIMIT_RECIPIENTS) { // El servicio tiene un limite return; } $this->recipients[] = array( 'name' => $name, 'email' => $email, 'amount' => $amount, ); }
[ "public", "function", "addRecipient", "(", "$", "name", ",", "$", "email", ",", "$", "amount", ")", "{", "if", "(", "count", "(", "$", "this", "->", "recipients", ")", "==", "self", "::", "LIMIT_RECIPIENTS", ")", "{", "// El servicio tiene un limite", "return", ";", "}", "$", "this", "->", "recipients", "[", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'email'", "=>", "$", "email", ",", "'amount'", "=>", "$", "amount", ",", ")", ";", "}" ]
Metodo que asigna a la variable recipientes un nuevo destinatario.
[ "Metodo", "que", "asigna", "a", "la", "variable", "recipientes", "un", "nuevo", "destinatario", "." ]
ef78fa8ba372c7784936ce95a3d0bd46a35e0143
https://github.com/blenderdeluxe/khipu/blob/ef78fa8ba372c7784936ce95a3d0bd46a35e0143/src/KhipuService/KhipuRecipients.php#L31-L41
238,405
roggeo/glance
src/Check.php
Check.fileNoExtension
public static function fileNoExtension($file, $folder) { if( is_array($file) ) return false; $exts = new Extensions(); //case has extension if( strstr($file, '.') && $exts->check($file) ) return false; $files = self::fileAll($folder); foreach($files as $v){ $exp = explode( DIRECTORY_SEPARATOR, $v ); $file_sch = explode('.',end($exp)); $ky = count($file_sch) -1; $file_ext = $file_sch[$ky]; unset($file_sch[$ky]); if(implode('.', $file_sch) == $file) return $folder . DIRECTORY_SEPARATOR . $file.'.'.$file_ext; } return false; }
php
public static function fileNoExtension($file, $folder) { if( is_array($file) ) return false; $exts = new Extensions(); //case has extension if( strstr($file, '.') && $exts->check($file) ) return false; $files = self::fileAll($folder); foreach($files as $v){ $exp = explode( DIRECTORY_SEPARATOR, $v ); $file_sch = explode('.',end($exp)); $ky = count($file_sch) -1; $file_ext = $file_sch[$ky]; unset($file_sch[$ky]); if(implode('.', $file_sch) == $file) return $folder . DIRECTORY_SEPARATOR . $file.'.'.$file_ext; } return false; }
[ "public", "static", "function", "fileNoExtension", "(", "$", "file", ",", "$", "folder", ")", "{", "if", "(", "is_array", "(", "$", "file", ")", ")", "return", "false", ";", "$", "exts", "=", "new", "Extensions", "(", ")", ";", "//case has extension", "if", "(", "strstr", "(", "$", "file", ",", "'.'", ")", "&&", "$", "exts", "->", "check", "(", "$", "file", ")", ")", "return", "false", ";", "$", "files", "=", "self", "::", "fileAll", "(", "$", "folder", ")", ";", "foreach", "(", "$", "files", "as", "$", "v", ")", "{", "$", "exp", "=", "explode", "(", "DIRECTORY_SEPARATOR", ",", "$", "v", ")", ";", "$", "file_sch", "=", "explode", "(", "'.'", ",", "end", "(", "$", "exp", ")", ")", ";", "$", "ky", "=", "count", "(", "$", "file_sch", ")", "-", "1", ";", "$", "file_ext", "=", "$", "file_sch", "[", "$", "ky", "]", ";", "unset", "(", "$", "file_sch", "[", "$", "ky", "]", ")", ";", "if", "(", "implode", "(", "'.'", ",", "$", "file_sch", ")", "==", "$", "file", ")", "return", "$", "folder", ".", "DIRECTORY_SEPARATOR", ".", "$", "file", ".", "'.'", ".", "$", "file_ext", ";", "}", "return", "false", ";", "}" ]
If no exists extension in file, find file with the your extension @param string $file @param string $folder @return bool|string With address url of the file
[ "If", "no", "exists", "extension", "in", "file", "find", "file", "with", "the", "your", "extension" ]
b01ac6827e39ec8f3d501c8128551a65ec0bf309
https://github.com/roggeo/glance/blob/b01ac6827e39ec8f3d501c8128551a65ec0bf309/src/Check.php#L101-L130
238,406
integratedfordevelopers/integrated-solr-bundle
DependencyInjection/CompilerPass/RegisterConfigFileProviderPass.php
RegisterConfigFileProviderPass.addProvider
protected function addProvider(ContainerBuilder $container, $dir, $bundle) { if ($container->hasDefinition('integrated_solr.converter.config.provider.file.' . $bundle)) { return null; } // If the bundle got a config/solr directory then a provider is created for this bundle. This // however still does not mean that the bundle actually got any solr config files but that is // not really a problem. if (!is_dir($dir . '/Resources/config/solr')) { return null; } $definition = new Definition(XmlProvider::class); $definition->setPublic(false); $definition->setArguments([$this->addFinder($container, $dir . '/Resources/config/solr', $bundle)]); $container->setDefinition('integrated_solr.converter.config.provider.file.' . $bundle, $definition); return new Reference('integrated_solr.converter.config.provider.file.' . $bundle); }
php
protected function addProvider(ContainerBuilder $container, $dir, $bundle) { if ($container->hasDefinition('integrated_solr.converter.config.provider.file.' . $bundle)) { return null; } // If the bundle got a config/solr directory then a provider is created for this bundle. This // however still does not mean that the bundle actually got any solr config files but that is // not really a problem. if (!is_dir($dir . '/Resources/config/solr')) { return null; } $definition = new Definition(XmlProvider::class); $definition->setPublic(false); $definition->setArguments([$this->addFinder($container, $dir . '/Resources/config/solr', $bundle)]); $container->setDefinition('integrated_solr.converter.config.provider.file.' . $bundle, $definition); return new Reference('integrated_solr.converter.config.provider.file.' . $bundle); }
[ "protected", "function", "addProvider", "(", "ContainerBuilder", "$", "container", ",", "$", "dir", ",", "$", "bundle", ")", "{", "if", "(", "$", "container", "->", "hasDefinition", "(", "'integrated_solr.converter.config.provider.file.'", ".", "$", "bundle", ")", ")", "{", "return", "null", ";", "}", "// If the bundle got a config/solr directory then a provider is created for this bundle. This", "// however still does not mean that the bundle actually got any solr config files but that is", "// not really a problem.", "if", "(", "!", "is_dir", "(", "$", "dir", ".", "'/Resources/config/solr'", ")", ")", "{", "return", "null", ";", "}", "$", "definition", "=", "new", "Definition", "(", "XmlProvider", "::", "class", ")", ";", "$", "definition", "->", "setPublic", "(", "false", ")", ";", "$", "definition", "->", "setArguments", "(", "[", "$", "this", "->", "addFinder", "(", "$", "container", ",", "$", "dir", ".", "'/Resources/config/solr'", ",", "$", "bundle", ")", "]", ")", ";", "$", "container", "->", "setDefinition", "(", "'integrated_solr.converter.config.provider.file.'", ".", "$", "bundle", ",", "$", "definition", ")", ";", "return", "new", "Reference", "(", "'integrated_solr.converter.config.provider.file.'", ".", "$", "bundle", ")", ";", "}" ]
Create a provider definition. Create the definition of a file provider instance if there is a possibility that this given bundle got any solr config files. But only if the container does not already contain a service definition with the same name. @param ContainerBuilder $container @param string $dir @param string $bundle @return null | Reference
[ "Create", "a", "provider", "definition", "." ]
9d9bb4071e13ed4686fbc97b6286a475ac5b2162
https://github.com/integratedfordevelopers/integrated-solr-bundle/blob/9d9bb4071e13ed4686fbc97b6286a475ac5b2162/DependencyInjection/CompilerPass/RegisterConfigFileProviderPass.php#L63-L84
238,407
integratedfordevelopers/integrated-solr-bundle
DependencyInjection/CompilerPass/RegisterConfigFileProviderPass.php
RegisterConfigFileProviderPass.addFinder
protected function addFinder(ContainerBuilder $container, $dir, $bundle) { $ref = new Reference('integrated_solr.converter.config.provider.file.' . $bundle . '.finder'); if ($container->hasDefinition('integrated_solr.converter.config.provider.file.' . $bundle . '.finder')) { return $ref; } $container->addResource(new FileResource($dir)); // not really sure what this does $definition = new Definition(Finder::class); $definition->setPublic(false); $definition->addMethodCall('in', [$dir]); $container->setDefinition('integrated_solr.converter.config.provider.file.' . $bundle . '.finder', $definition); return $ref; }
php
protected function addFinder(ContainerBuilder $container, $dir, $bundle) { $ref = new Reference('integrated_solr.converter.config.provider.file.' . $bundle . '.finder'); if ($container->hasDefinition('integrated_solr.converter.config.provider.file.' . $bundle . '.finder')) { return $ref; } $container->addResource(new FileResource($dir)); // not really sure what this does $definition = new Definition(Finder::class); $definition->setPublic(false); $definition->addMethodCall('in', [$dir]); $container->setDefinition('integrated_solr.converter.config.provider.file.' . $bundle . '.finder', $definition); return $ref; }
[ "protected", "function", "addFinder", "(", "ContainerBuilder", "$", "container", ",", "$", "dir", ",", "$", "bundle", ")", "{", "$", "ref", "=", "new", "Reference", "(", "'integrated_solr.converter.config.provider.file.'", ".", "$", "bundle", ".", "'.finder'", ")", ";", "if", "(", "$", "container", "->", "hasDefinition", "(", "'integrated_solr.converter.config.provider.file.'", ".", "$", "bundle", ".", "'.finder'", ")", ")", "{", "return", "$", "ref", ";", "}", "$", "container", "->", "addResource", "(", "new", "FileResource", "(", "$", "dir", ")", ")", ";", "// not really sure what this does", "$", "definition", "=", "new", "Definition", "(", "Finder", "::", "class", ")", ";", "$", "definition", "->", "setPublic", "(", "false", ")", ";", "$", "definition", "->", "addMethodCall", "(", "'in'", ",", "[", "$", "dir", "]", ")", ";", "$", "container", "->", "setDefinition", "(", "'integrated_solr.converter.config.provider.file.'", ".", "$", "bundle", ".", "'.finder'", ",", "$", "definition", ")", ";", "return", "$", "ref", ";", "}" ]
Create a finder definition. Create the definition of a finder instance that will look for files in the bundle. If the finder definition already exists then that one is returned. @param ContainerBuilder $container @param string $dir @param string $bundle @return Reference
[ "Create", "a", "finder", "definition", "." ]
9d9bb4071e13ed4686fbc97b6286a475ac5b2162
https://github.com/integratedfordevelopers/integrated-solr-bundle/blob/9d9bb4071e13ed4686fbc97b6286a475ac5b2162/DependencyInjection/CompilerPass/RegisterConfigFileProviderPass.php#L98-L115
238,408
dcarrith/lxmpd
src/Dcarrith/LxMPD/Connection/MPDConnection.php
MPDConnection.establish
public function establish() { // Check whether the socket is already connected if( isset($this->established) && $this->established ) { return true; } // Try to open the socket connection to MPD with a 5 second timeout if( !$this->socket = @fsockopen( $this->host, $this->port, $errn, $errs, 5 ) ) { // Throw an MPDConnectionException along with the connection errors throw new MPDConnectionException( 'Connection failed: '.$errs, self::MPD_CONNECTION_FAILED ); } // Clear connection messages while( !feof( $this->socket ) ) { $response = trim( fgets( $this->socket ) ); // If the connection messages have cleared if( strncmp( self::MPD_OK, $response, strlen( self::MPD_OK ) ) == 0 ) { // Successully connected $this->established = true; // Parse the MPD version from the response and replace the ending 0 with an x $this->version = preg_replace('/[0]$/','x', current( sscanf( $response, self::MPD_OK . " MPD %s\n" ))); // Connected successfully return true; } // Check to see if there is a connection error message that was sent in the response if( strncmp( self::MPD_ERROR, $response, strlen( self::MPD_ERROR ) ) == 0 ) { // Parse out the error message from the response preg_match( '/^ACK \[(.*?)\@(.*?)\] \{(.*?)\} (.*?)$/', $response, $matches ); // Throw an exception and include the response errors throw new MPDConnectionException( 'Connection failed: '.$matches[4], self::MPD_CONNECTION_FAILED ); } } // Throw a general connection failed exception throw new MPDConnectionException( 'Connection failed', self::MPD_CONNECTION_FAILED ); }
php
public function establish() { // Check whether the socket is already connected if( isset($this->established) && $this->established ) { return true; } // Try to open the socket connection to MPD with a 5 second timeout if( !$this->socket = @fsockopen( $this->host, $this->port, $errn, $errs, 5 ) ) { // Throw an MPDConnectionException along with the connection errors throw new MPDConnectionException( 'Connection failed: '.$errs, self::MPD_CONNECTION_FAILED ); } // Clear connection messages while( !feof( $this->socket ) ) { $response = trim( fgets( $this->socket ) ); // If the connection messages have cleared if( strncmp( self::MPD_OK, $response, strlen( self::MPD_OK ) ) == 0 ) { // Successully connected $this->established = true; // Parse the MPD version from the response and replace the ending 0 with an x $this->version = preg_replace('/[0]$/','x', current( sscanf( $response, self::MPD_OK . " MPD %s\n" ))); // Connected successfully return true; } // Check to see if there is a connection error message that was sent in the response if( strncmp( self::MPD_ERROR, $response, strlen( self::MPD_ERROR ) ) == 0 ) { // Parse out the error message from the response preg_match( '/^ACK \[(.*?)\@(.*?)\] \{(.*?)\} (.*?)$/', $response, $matches ); // Throw an exception and include the response errors throw new MPDConnectionException( 'Connection failed: '.$matches[4], self::MPD_CONNECTION_FAILED ); } } // Throw a general connection failed exception throw new MPDConnectionException( 'Connection failed', self::MPD_CONNECTION_FAILED ); }
[ "public", "function", "establish", "(", ")", "{", "// Check whether the socket is already connected", "if", "(", "isset", "(", "$", "this", "->", "established", ")", "&&", "$", "this", "->", "established", ")", "{", "return", "true", ";", "}", "// Try to open the socket connection to MPD with a 5 second timeout", "if", "(", "!", "$", "this", "->", "socket", "=", "@", "fsockopen", "(", "$", "this", "->", "host", ",", "$", "this", "->", "port", ",", "$", "errn", ",", "$", "errs", ",", "5", ")", ")", "{", "// Throw an MPDConnectionException along with the connection errors", "throw", "new", "MPDConnectionException", "(", "'Connection failed: '", ".", "$", "errs", ",", "self", "::", "MPD_CONNECTION_FAILED", ")", ";", "}", "// Clear connection messages", "while", "(", "!", "feof", "(", "$", "this", "->", "socket", ")", ")", "{", "$", "response", "=", "trim", "(", "fgets", "(", "$", "this", "->", "socket", ")", ")", ";", "// If the connection messages have cleared", "if", "(", "strncmp", "(", "self", "::", "MPD_OK", ",", "$", "response", ",", "strlen", "(", "self", "::", "MPD_OK", ")", ")", "==", "0", ")", "{", "// Successully connected", "$", "this", "->", "established", "=", "true", ";", "// Parse the MPD version from the response and replace the ending 0 with an x ", "$", "this", "->", "version", "=", "preg_replace", "(", "'/[0]$/'", ",", "'x'", ",", "current", "(", "sscanf", "(", "$", "response", ",", "self", "::", "MPD_OK", ".", "\" MPD %s\\n\"", ")", ")", ")", ";", "// Connected successfully", "return", "true", ";", "}", "// Check to see if there is a connection error message that was sent in the response", "if", "(", "strncmp", "(", "self", "::", "MPD_ERROR", ",", "$", "response", ",", "strlen", "(", "self", "::", "MPD_ERROR", ")", ")", "==", "0", ")", "{", "// Parse out the error message from the response", "preg_match", "(", "'/^ACK \\[(.*?)\\@(.*?)\\] \\{(.*?)\\} (.*?)$/'", ",", "$", "response", ",", "$", "matches", ")", ";", "// Throw an exception and include the response errors", "throw", "new", "MPDConnectionException", "(", "'Connection failed: '", ".", "$", "matches", "[", "4", "]", ",", "self", "::", "MPD_CONNECTION_FAILED", ")", ";", "}", "}", "// Throw a general connection failed exception ", "throw", "new", "MPDConnectionException", "(", "'Connection failed'", ",", "self", "::", "MPD_CONNECTION_FAILED", ")", ";", "}" ]
Establishes a connection to the MPD server @return bool
[ "Establishes", "a", "connection", "to", "the", "MPD", "server" ]
337708f6fec08c2ca9dfeb6ca88c47f5479be860
https://github.com/dcarrith/lxmpd/blob/337708f6fec08c2ca9dfeb6ca88c47f5479be860/src/Dcarrith/LxMPD/Connection/MPDConnection.php#L50-L95
238,409
dcarrith/lxmpd
src/Dcarrith/LxMPD/Connection/MPDConnection.php
MPDConnection.close
public function close() { // Make sure nothing unexpected happens try { // Check that a connection exists first if( isset( $this->socket ) ) { // Close the socket fclose( $this->socket ); // Unset the socket property unset($this->socket); // The connection is no longer established $this->established = false; } } catch (Exception $e) { throw new MPDConnectionException( 'Disconnection failed: '.$e->getMessage(), self::MPD_DISCONNECTION_FAILED ); } // We'll assume it was successful return true; }
php
public function close() { // Make sure nothing unexpected happens try { // Check that a connection exists first if( isset( $this->socket ) ) { // Close the socket fclose( $this->socket ); // Unset the socket property unset($this->socket); // The connection is no longer established $this->established = false; } } catch (Exception $e) { throw new MPDConnectionException( 'Disconnection failed: '.$e->getMessage(), self::MPD_DISCONNECTION_FAILED ); } // We'll assume it was successful return true; }
[ "public", "function", "close", "(", ")", "{", "// Make sure nothing unexpected happens", "try", "{", "// Check that a connection exists first", "if", "(", "isset", "(", "$", "this", "->", "socket", ")", ")", "{", "// Close the socket", "fclose", "(", "$", "this", "->", "socket", ")", ";", "// Unset the socket property", "unset", "(", "$", "this", "->", "socket", ")", ";", "// The connection is no longer established", "$", "this", "->", "established", "=", "false", ";", "}", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "MPDConnectionException", "(", "'Disconnection failed: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "self", "::", "MPD_DISCONNECTION_FAILED", ")", ";", "}", "// We'll assume it was successful", "return", "true", ";", "}" ]
Closes the connection to the MPD server @return bool
[ "Closes", "the", "connection", "to", "the", "MPD", "server" ]
337708f6fec08c2ca9dfeb6ca88c47f5479be860
https://github.com/dcarrith/lxmpd/blob/337708f6fec08c2ca9dfeb6ca88c47f5479be860/src/Dcarrith/LxMPD/Connection/MPDConnection.php#L101-L126
238,410
dcarrith/lxmpd
src/Dcarrith/LxMPD/Connection/MPDConnection.php
MPDConnection.determineIfLocal
public function determineIfLocal() { // Default it to false $this->local = false; // Compare the MPD host a few different ways to try and determine if it's local to the Apache server if( ( stream_is_local( $this->socket )) || ( $this->host == (isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : getHostByName( getHostName() ))) || ( $this->host == 'localhost' ) || ( $this->host == '127.0.0.1' )) { $this->local = true; } }
php
public function determineIfLocal() { // Default it to false $this->local = false; // Compare the MPD host a few different ways to try and determine if it's local to the Apache server if( ( stream_is_local( $this->socket )) || ( $this->host == (isset($_SERVER["SERVER_ADDR"]) ? $_SERVER["SERVER_ADDR"] : getHostByName( getHostName() ))) || ( $this->host == 'localhost' ) || ( $this->host == '127.0.0.1' )) { $this->local = true; } }
[ "public", "function", "determineIfLocal", "(", ")", "{", "// Default it to false", "$", "this", "->", "local", "=", "false", ";", "// Compare the MPD host a few different ways to try and determine if it's local to the Apache server", "if", "(", "(", "stream_is_local", "(", "$", "this", "->", "socket", ")", ")", "||", "(", "$", "this", "->", "host", "==", "(", "isset", "(", "$", "_SERVER", "[", "\"SERVER_ADDR\"", "]", ")", "?", "$", "_SERVER", "[", "\"SERVER_ADDR\"", "]", ":", "getHostByName", "(", "getHostName", "(", ")", ")", ")", ")", "||", "(", "$", "this", "->", "host", "==", "'localhost'", ")", "||", "(", "$", "this", "->", "host", "==", "'127.0.0.1'", ")", ")", "{", "$", "this", "->", "local", "=", "true", ";", "}", "}" ]
determineIfLocal tries to determine if the connection to MPD is local @return bool
[ "determineIfLocal", "tries", "to", "determine", "if", "the", "connection", "to", "MPD", "is", "local" ]
337708f6fec08c2ca9dfeb6ca88c47f5479be860
https://github.com/dcarrith/lxmpd/blob/337708f6fec08c2ca9dfeb6ca88c47f5479be860/src/Dcarrith/LxMPD/Connection/MPDConnection.php#L151-L164
238,411
sebardo/ecommerce
EcommerceBundle/Controller/BrandController.php
BrandController.showAction
public function showAction(Brand $brand) { $deleteForm = $this->createDeleteForm($brand); return array( 'entity' => $brand, 'delete_form' => $deleteForm->createView(), ); }
php
public function showAction(Brand $brand) { $deleteForm = $this->createDeleteForm($brand); return array( 'entity' => $brand, 'delete_form' => $deleteForm->createView(), ); }
[ "public", "function", "showAction", "(", "Brand", "$", "brand", ")", "{", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "brand", ")", ";", "return", "array", "(", "'entity'", "=>", "$", "brand", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Finds and displays a Brand entity. @Route("/{id}") @Method("GET") @Template()
[ "Finds", "and", "displays", "a", "Brand", "entity", "." ]
3e17545e69993f10a1df17f9887810c7378fc7f9
https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/BrandController.php#L90-L98
238,412
sebardo/ecommerce
EcommerceBundle/Controller/BrandController.php
BrandController.deleteAction
public function deleteAction(Request $request, Brand $brand) { $form = $this->createDeleteForm($brand); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($brand); $em->flush(); $this->get('session')->getFlashBag()->add('info', 'brand.deleted'); } return $this->redirectToRoute('ecommerce_brand_index'); }
php
public function deleteAction(Request $request, Brand $brand) { $form = $this->createDeleteForm($brand); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($brand); $em->flush(); $this->get('session')->getFlashBag()->add('info', 'brand.deleted'); } return $this->redirectToRoute('ecommerce_brand_index'); }
[ "public", "function", "deleteAction", "(", "Request", "$", "request", ",", "Brand", "$", "brand", ")", "{", "$", "form", "=", "$", "this", "->", "createDeleteForm", "(", "$", "brand", ")", ";", "$", "form", "->", "handleRequest", "(", "$", "request", ")", ";", "if", "(", "$", "form", "->", "isSubmitted", "(", ")", "&&", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "em", "->", "remove", "(", "$", "brand", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "$", "this", "->", "get", "(", "'session'", ")", "->", "getFlashBag", "(", ")", "->", "add", "(", "'info'", ",", "'brand.deleted'", ")", ";", "}", "return", "$", "this", "->", "redirectToRoute", "(", "'ecommerce_brand_index'", ")", ";", "}" ]
Deletes a Brand entity. @Route("/{id}") @Method("DELETE")
[ "Deletes", "a", "Brand", "entity", "." ]
3e17545e69993f10a1df17f9887810c7378fc7f9
https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/BrandController.php#L142-L157
238,413
sebardo/ecommerce
EcommerceBundle/Controller/BrandController.php
BrandController.createDeleteForm
private function createDeleteForm(Brand $brand) { return $this->createFormBuilder() ->setAction($this->generateUrl('ecommerce_brand_delete', array('id' => $brand->getId()))) ->setMethod('DELETE') ->getForm() ; }
php
private function createDeleteForm(Brand $brand) { return $this->createFormBuilder() ->setAction($this->generateUrl('ecommerce_brand_delete', array('id' => $brand->getId()))) ->setMethod('DELETE') ->getForm() ; }
[ "private", "function", "createDeleteForm", "(", "Brand", "$", "brand", ")", "{", "return", "$", "this", "->", "createFormBuilder", "(", ")", "->", "setAction", "(", "$", "this", "->", "generateUrl", "(", "'ecommerce_brand_delete'", ",", "array", "(", "'id'", "=>", "$", "brand", "->", "getId", "(", ")", ")", ")", ")", "->", "setMethod", "(", "'DELETE'", ")", "->", "getForm", "(", ")", ";", "}" ]
Creates a form to delete a Brand entity. @param Brand $brand The Brand entity @return \Symfony\Component\Form\Form The form
[ "Creates", "a", "form", "to", "delete", "a", "Brand", "entity", "." ]
3e17545e69993f10a1df17f9887810c7378fc7f9
https://github.com/sebardo/ecommerce/blob/3e17545e69993f10a1df17f9887810c7378fc7f9/EcommerceBundle/Controller/BrandController.php#L166-L173
238,414
sellerlabs/nucleus
src/SellerLabs/Nucleus/Strings/Rope.php
Rope.upperWords
public function upperWords($delimiters = " \t\r\n\f\v") { return static::of( mb_ucwords($this->contents, $delimiters, $this->encoding), $this->encoding ); }
php
public function upperWords($delimiters = " \t\r\n\f\v") { return static::of( mb_ucwords($this->contents, $delimiters, $this->encoding), $this->encoding ); }
[ "public", "function", "upperWords", "(", "$", "delimiters", "=", "\" \\t\\r\\n\\f\\v\"", ")", "{", "return", "static", "::", "of", "(", "mb_ucwords", "(", "$", "this", "->", "contents", ",", "$", "delimiters", ",", "$", "this", "->", "encoding", ")", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Return the string with all the words in upper case. Delimiters are used to determine what is a word. @param string $delimiters @return Rope
[ "Return", "the", "string", "with", "all", "the", "words", "in", "upper", "case", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Strings/Rope.php#L329-L335
238,415
sellerlabs/nucleus
src/SellerLabs/Nucleus/Strings/Rope.php
Rope.beginsWith
public function beginsWith($prefix) { return $prefix === '' || mb_strpos( $this->contents, (string) $prefix, null, $this->encoding ) === 0; }
php
public function beginsWith($prefix) { return $prefix === '' || mb_strpos( $this->contents, (string) $prefix, null, $this->encoding ) === 0; }
[ "public", "function", "beginsWith", "(", "$", "prefix", ")", "{", "return", "$", "prefix", "===", "''", "||", "mb_strpos", "(", "$", "this", "->", "contents", ",", "(", "string", ")", "$", "prefix", ",", "null", ",", "$", "this", "->", "encoding", ")", "===", "0", ";", "}" ]
Returns true if the string begins with the provided string. @param string|Rope $prefix @return bool
[ "Returns", "true", "if", "the", "string", "begins", "with", "the", "provided", "string", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Strings/Rope.php#L369-L378
238,416
sellerlabs/nucleus
src/SellerLabs/Nucleus/Strings/Rope.php
Rope.endsWith
public function endsWith($suffix) { return $suffix === '' || $suffix === mb_substr( $this->contents, -strlen((string) $suffix), null, $this->encoding ); }
php
public function endsWith($suffix) { return $suffix === '' || $suffix === mb_substr( $this->contents, -strlen((string) $suffix), null, $this->encoding ); }
[ "public", "function", "endsWith", "(", "$", "suffix", ")", "{", "return", "$", "suffix", "===", "''", "||", "$", "suffix", "===", "mb_substr", "(", "$", "this", "->", "contents", ",", "-", "strlen", "(", "(", "string", ")", "$", "suffix", ")", ",", "null", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Returns true if the string ends with the provided string. @param string|Rope $suffix @return bool
[ "Returns", "true", "if", "the", "string", "ends", "with", "the", "provided", "string", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Strings/Rope.php#L387-L396
238,417
sellerlabs/nucleus
src/SellerLabs/Nucleus/Strings/Rope.php
Rope.contains
public function contains($inner) { return mb_strpos( $this->contents, (string) $inner, null, $this->encoding ) !== false; }
php
public function contains($inner) { return mb_strpos( $this->contents, (string) $inner, null, $this->encoding ) !== false; }
[ "public", "function", "contains", "(", "$", "inner", ")", "{", "return", "mb_strpos", "(", "$", "this", "->", "contents", ",", "(", "string", ")", "$", "inner", ",", "null", ",", "$", "this", "->", "encoding", ")", "!==", "false", ";", "}" ]
Returns true if the string contains the provided string. @param string|Rope $inner @return bool
[ "Returns", "true", "if", "the", "string", "contains", "the", "provided", "string", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Strings/Rope.php#L405-L413
238,418
sellerlabs/nucleus
src/SellerLabs/Nucleus/Strings/Rope.php
Rope.reverse
public function reverse() { return static::of( ArrayList::of($this->split())->reverse()->join(), $this->encoding ); }
php
public function reverse() { return static::of( ArrayList::of($this->split())->reverse()->join(), $this->encoding ); }
[ "public", "function", "reverse", "(", ")", "{", "return", "static", "::", "of", "(", "ArrayList", "::", "of", "(", "$", "this", "->", "split", "(", ")", ")", "->", "reverse", "(", ")", "->", "join", "(", ")", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Return the string with all its characters reversed. @return Rope
[ "Return", "the", "string", "with", "all", "its", "characters", "reversed", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Strings/Rope.php#L420-L426
238,419
sellerlabs/nucleus
src/SellerLabs/Nucleus/Strings/Rope.php
Rope.concat
public function concat(...$others) { return static::of( Std::foldl( function ($carry, $part) { return $carry . (string) $part; }, $this->contents, $others ), $this->encoding ); }
php
public function concat(...$others) { return static::of( Std::foldl( function ($carry, $part) { return $carry . (string) $part; }, $this->contents, $others ), $this->encoding ); }
[ "public", "function", "concat", "(", "...", "$", "others", ")", "{", "return", "static", "::", "of", "(", "Std", "::", "foldl", "(", "function", "(", "$", "carry", ",", "$", "part", ")", "{", "return", "$", "carry", ".", "(", "string", ")", "$", "part", ";", "}", ",", "$", "this", "->", "contents", ",", "$", "others", ")", ",", "$", "this", "->", "encoding", ")", ";", "}" ]
Concatenate with other strings. @param array<string|Rope> ...$others @return Rope
[ "Concatenate", "with", "other", "strings", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Strings/Rope.php#L504-L516
238,420
sellerlabs/nucleus
src/SellerLabs/Nucleus/Strings/Rope.php
Rope.equals
public function equals(Rope $other) { return $this->contents === $other->contents && $this->encoding === $other->encoding; }
php
public function equals(Rope $other) { return $this->contents === $other->contents && $this->encoding === $other->encoding; }
[ "public", "function", "equals", "(", "Rope", "$", "other", ")", "{", "return", "$", "this", "->", "contents", "===", "$", "other", "->", "contents", "&&", "$", "this", "->", "encoding", "===", "$", "other", "->", "encoding", ";", "}" ]
Return whether this Rope is equal to another. @param Rope $other @return bool
[ "Return", "whether", "this", "Rope", "is", "equal", "to", "another", "." ]
c05d9c23d424a6bd5ab2e29140805cc6e37e4623
https://github.com/sellerlabs/nucleus/blob/c05d9c23d424a6bd5ab2e29140805cc6e37e4623/src/SellerLabs/Nucleus/Strings/Rope.php#L533-L537
238,421
martinhej/robocloud
src/robocloud/Message/SchemaDiscovery.php
SchemaDiscovery.getMessageDataSchema
public function getMessageDataSchema(MessageInterface $message): \stdClass { $parts = explode('.', $message->getPurpose()); if (empty($parts)) { throw new InvalidMessageDataException('The message "purpose" property should clearly define specific message schema'); } if ($this->cache->has($message->getPurpose())) { return $this->cache->get($message->getPurpose()); } $file_name = array_pop($parts) . '.schema.json'; $purpose_dirs = ''; if (!empty($parts)) { $purpose_dirs = implode(DIRECTORY_SEPARATOR, $parts); } $schema_dirs = array_filter(array_map(function($dir) use ($purpose_dirs, $message) { $schema_dir = $dir . DIRECTORY_SEPARATOR . $message->getVersion() . DIRECTORY_SEPARATOR . $purpose_dirs; if (file_exists($schema_dir)) { return $schema_dir; } return NULL; }, $this->schemaDirs)); $file_locator = new FileLocator($schema_dirs); try { $path = $file_locator->locate($file_name); $schema = json_decode(file_get_contents($path)); $this->cache->set($message->getPurpose(), $schema); return $schema; } catch (FileLocatorFileNotFoundException $e) { throw new InvalidMessageDataException('Could not find message with purpose "' . $message->getPurpose() . '"'); } }
php
public function getMessageDataSchema(MessageInterface $message): \stdClass { $parts = explode('.', $message->getPurpose()); if (empty($parts)) { throw new InvalidMessageDataException('The message "purpose" property should clearly define specific message schema'); } if ($this->cache->has($message->getPurpose())) { return $this->cache->get($message->getPurpose()); } $file_name = array_pop($parts) . '.schema.json'; $purpose_dirs = ''; if (!empty($parts)) { $purpose_dirs = implode(DIRECTORY_SEPARATOR, $parts); } $schema_dirs = array_filter(array_map(function($dir) use ($purpose_dirs, $message) { $schema_dir = $dir . DIRECTORY_SEPARATOR . $message->getVersion() . DIRECTORY_SEPARATOR . $purpose_dirs; if (file_exists($schema_dir)) { return $schema_dir; } return NULL; }, $this->schemaDirs)); $file_locator = new FileLocator($schema_dirs); try { $path = $file_locator->locate($file_name); $schema = json_decode(file_get_contents($path)); $this->cache->set($message->getPurpose(), $schema); return $schema; } catch (FileLocatorFileNotFoundException $e) { throw new InvalidMessageDataException('Could not find message with purpose "' . $message->getPurpose() . '"'); } }
[ "public", "function", "getMessageDataSchema", "(", "MessageInterface", "$", "message", ")", ":", "\\", "stdClass", "{", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "message", "->", "getPurpose", "(", ")", ")", ";", "if", "(", "empty", "(", "$", "parts", ")", ")", "{", "throw", "new", "InvalidMessageDataException", "(", "'The message \"purpose\" property should clearly define specific message schema'", ")", ";", "}", "if", "(", "$", "this", "->", "cache", "->", "has", "(", "$", "message", "->", "getPurpose", "(", ")", ")", ")", "{", "return", "$", "this", "->", "cache", "->", "get", "(", "$", "message", "->", "getPurpose", "(", ")", ")", ";", "}", "$", "file_name", "=", "array_pop", "(", "$", "parts", ")", ".", "'.schema.json'", ";", "$", "purpose_dirs", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "parts", ")", ")", "{", "$", "purpose_dirs", "=", "implode", "(", "DIRECTORY_SEPARATOR", ",", "$", "parts", ")", ";", "}", "$", "schema_dirs", "=", "array_filter", "(", "array_map", "(", "function", "(", "$", "dir", ")", "use", "(", "$", "purpose_dirs", ",", "$", "message", ")", "{", "$", "schema_dir", "=", "$", "dir", ".", "DIRECTORY_SEPARATOR", ".", "$", "message", "->", "getVersion", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "purpose_dirs", ";", "if", "(", "file_exists", "(", "$", "schema_dir", ")", ")", "{", "return", "$", "schema_dir", ";", "}", "return", "NULL", ";", "}", ",", "$", "this", "->", "schemaDirs", ")", ")", ";", "$", "file_locator", "=", "new", "FileLocator", "(", "$", "schema_dirs", ")", ";", "try", "{", "$", "path", "=", "$", "file_locator", "->", "locate", "(", "$", "file_name", ")", ";", "$", "schema", "=", "json_decode", "(", "file_get_contents", "(", "$", "path", ")", ")", ";", "$", "this", "->", "cache", "->", "set", "(", "$", "message", "->", "getPurpose", "(", ")", ",", "$", "schema", ")", ";", "return", "$", "schema", ";", "}", "catch", "(", "FileLocatorFileNotFoundException", "$", "e", ")", "{", "throw", "new", "InvalidMessageDataException", "(", "'Could not find message with purpose \"'", ".", "$", "message", "->", "getPurpose", "(", ")", ".", "'\"'", ")", ";", "}", "}" ]
Gets message schema. @param MessageInterface $message The message for which to get schema. @return object The message data property schema. @throws InvalidMessageDataException @throws InvalidArgumentException
[ "Gets", "message", "schema", "." ]
108dfbc2b6e9aca2a87795c3e7518cbf1cf5d229
https://github.com/martinhej/robocloud/blob/108dfbc2b6e9aca2a87795c3e7518cbf1cf5d229/src/robocloud/Message/SchemaDiscovery.php#L64-L104
238,422
renzelagentur/ra-installer
src/Ra/Installer/RaInstaller.php
RaInstaller.cleanUpOldModules
public static function cleanUpOldModules(Event $event) { $composer = $event->getComposer(); $requires = $composer->getPackage()->getRequires(); $projectPath = str_replace('vendor/vkf/shop', '', $composer->getInstallationManager()->getInstallpath($composer->getPackage())); $modulePath = $projectPath . 'htdocs/modules'; foreach (array('ra', 'vkf') as $renzelVendorDir) { foreach (glob($modulePath . '/' . $renzelVendorDir . '/*') as $file) { if (is_dir($file)) { $packageId = str_replace($modulePath . '/', '', $file); if (!isset($requires[$packageId])) { self::rmdir($file); $event->getIO()->write('Deleted old package ' . $packageId); } } } } }
php
public static function cleanUpOldModules(Event $event) { $composer = $event->getComposer(); $requires = $composer->getPackage()->getRequires(); $projectPath = str_replace('vendor/vkf/shop', '', $composer->getInstallationManager()->getInstallpath($composer->getPackage())); $modulePath = $projectPath . 'htdocs/modules'; foreach (array('ra', 'vkf') as $renzelVendorDir) { foreach (glob($modulePath . '/' . $renzelVendorDir . '/*') as $file) { if (is_dir($file)) { $packageId = str_replace($modulePath . '/', '', $file); if (!isset($requires[$packageId])) { self::rmdir($file); $event->getIO()->write('Deleted old package ' . $packageId); } } } } }
[ "public", "static", "function", "cleanUpOldModules", "(", "Event", "$", "event", ")", "{", "$", "composer", "=", "$", "event", "->", "getComposer", "(", ")", ";", "$", "requires", "=", "$", "composer", "->", "getPackage", "(", ")", "->", "getRequires", "(", ")", ";", "$", "projectPath", "=", "str_replace", "(", "'vendor/vkf/shop'", ",", "''", ",", "$", "composer", "->", "getInstallationManager", "(", ")", "->", "getInstallpath", "(", "$", "composer", "->", "getPackage", "(", ")", ")", ")", ";", "$", "modulePath", "=", "$", "projectPath", ".", "'htdocs/modules'", ";", "foreach", "(", "array", "(", "'ra'", ",", "'vkf'", ")", "as", "$", "renzelVendorDir", ")", "{", "foreach", "(", "glob", "(", "$", "modulePath", ".", "'/'", ".", "$", "renzelVendorDir", ".", "'/*'", ")", "as", "$", "file", ")", "{", "if", "(", "is_dir", "(", "$", "file", ")", ")", "{", "$", "packageId", "=", "str_replace", "(", "$", "modulePath", ".", "'/'", ",", "''", ",", "$", "file", ")", ";", "if", "(", "!", "isset", "(", "$", "requires", "[", "$", "packageId", "]", ")", ")", "{", "self", "::", "rmdir", "(", "$", "file", ")", ";", "$", "event", "->", "getIO", "(", ")", "->", "write", "(", "'Deleted old package '", ".", "$", "packageId", ")", ";", "}", "}", "}", "}", "}" ]
cleanup deleted modules @param Event $event event
[ "cleanup", "deleted", "modules" ]
2a2e5fbd3fba3124cc54c53e5b4be4c7e2604d5c
https://github.com/renzelagentur/ra-installer/blob/2a2e5fbd3fba3124cc54c53e5b4be4c7e2604d5c/src/Ra/Installer/RaInstaller.php#L40-L58
238,423
renzelagentur/ra-installer
src/Ra/Installer/RaInstaller.php
RaInstaller.getInstallPath
public function getInstallPath(PackageInterface $package) { if ($package->getType() === 'oxid-base') { return $this->_locations[$package->getType()]; } $themeName = "ra"; $extra = $package->getExtra(); $installFolder = $this->_locations[$package->getType()] . '/' . str_replace(array($themeName . "/", '-theme'), '', $package->getPrettyName()); if ($extra) { $themeName = $extra["themeName"]; $installFolder = $this->_locations[$package->getType()] . '/' . $themeName; } return $installFolder; }
php
public function getInstallPath(PackageInterface $package) { if ($package->getType() === 'oxid-base') { return $this->_locations[$package->getType()]; } $themeName = "ra"; $extra = $package->getExtra(); $installFolder = $this->_locations[$package->getType()] . '/' . str_replace(array($themeName . "/", '-theme'), '', $package->getPrettyName()); if ($extra) { $themeName = $extra["themeName"]; $installFolder = $this->_locations[$package->getType()] . '/' . $themeName; } return $installFolder; }
[ "public", "function", "getInstallPath", "(", "PackageInterface", "$", "package", ")", "{", "if", "(", "$", "package", "->", "getType", "(", ")", "===", "'oxid-base'", ")", "{", "return", "$", "this", "->", "_locations", "[", "$", "package", "->", "getType", "(", ")", "]", ";", "}", "$", "themeName", "=", "\"ra\"", ";", "$", "extra", "=", "$", "package", "->", "getExtra", "(", ")", ";", "$", "installFolder", "=", "$", "this", "->", "_locations", "[", "$", "package", "->", "getType", "(", ")", "]", ".", "'/'", ".", "str_replace", "(", "array", "(", "$", "themeName", ".", "\"/\"", ",", "'-theme'", ")", ",", "''", ",", "$", "package", "->", "getPrettyName", "(", ")", ")", ";", "if", "(", "$", "extra", ")", "{", "$", "themeName", "=", "$", "extra", "[", "\"themeName\"", "]", ";", "$", "installFolder", "=", "$", "this", "->", "_locations", "[", "$", "package", "->", "getType", "(", ")", "]", ".", "'/'", ".", "$", "themeName", ";", "}", "return", "$", "installFolder", ";", "}" ]
get install path by package @param PackageInterface $package package @return string
[ "get", "install", "path", "by", "package" ]
2a2e5fbd3fba3124cc54c53e5b4be4c7e2604d5c
https://github.com/renzelagentur/ra-installer/blob/2a2e5fbd3fba3124cc54c53e5b4be4c7e2604d5c/src/Ra/Installer/RaInstaller.php#L90-L104
238,424
MehrAlsNix/Notifier
src/Commands/Windows.php
Windows.notify
protected function notify($title, $message, $icon = null) { $app = __DIR__ . '/../../bin/toast.exe'; $title = iconv('UTF-8', 'ASCII//TRANSLIT', $title); $message = iconv('UTF-8', 'ASCII//TRANSLIT', $message); $icon = is_string($icon) ? " -p \"$icon\"" : $this->icon; $this->execute("$app -t \"{$title}\" -m \"{$message}\"$icon"); }
php
protected function notify($title, $message, $icon = null) { $app = __DIR__ . '/../../bin/toast.exe'; $title = iconv('UTF-8', 'ASCII//TRANSLIT', $title); $message = iconv('UTF-8', 'ASCII//TRANSLIT', $message); $icon = is_string($icon) ? " -p \"$icon\"" : $this->icon; $this->execute("$app -t \"{$title}\" -m \"{$message}\"$icon"); }
[ "protected", "function", "notify", "(", "$", "title", ",", "$", "message", ",", "$", "icon", "=", "null", ")", "{", "$", "app", "=", "__DIR__", ".", "'/../../bin/toast.exe'", ";", "$", "title", "=", "iconv", "(", "'UTF-8'", ",", "'ASCII//TRANSLIT'", ",", "$", "title", ")", ";", "$", "message", "=", "iconv", "(", "'UTF-8'", ",", "'ASCII//TRANSLIT'", ",", "$", "message", ")", ";", "$", "icon", "=", "is_string", "(", "$", "icon", ")", "?", "\" -p \\\"$icon\\\"\"", ":", "$", "this", "->", "icon", ";", "$", "this", "->", "execute", "(", "\"$app -t \\\"{$title}\\\" -m \\\"{$message}\\\"$icon\"", ")", ";", "}" ]
Notify with `toast.exe`. @param string $title @param string $message @param string $icon optional @return void
[ "Notify", "with", "toast", ".", "exe", "." ]
9ac9fed8880537157091ac0607965b30dab20bca
https://github.com/MehrAlsNix/Notifier/blob/9ac9fed8880537157091ac0607965b30dab20bca/src/Commands/Windows.php#L38-L47
238,425
PHPPlatform/json-cache
src/JSONCache/Cache.php
Cache.reset
public function reset(){ $originalSettings = $this->settings; $this->settings = array(); if(file_put_contents($this->cacheFileName, "{}") === FALSE){ $this->settings = $originalSettings; return FALSE; } return TRUE; }
php
public function reset(){ $originalSettings = $this->settings; $this->settings = array(); if(file_put_contents($this->cacheFileName, "{}") === FALSE){ $this->settings = $originalSettings; return FALSE; } return TRUE; }
[ "public", "function", "reset", "(", ")", "{", "$", "originalSettings", "=", "$", "this", "->", "settings", ";", "$", "this", "->", "settings", "=", "array", "(", ")", ";", "if", "(", "file_put_contents", "(", "$", "this", "->", "cacheFileName", ",", "\"{}\"", ")", "===", "FALSE", ")", "{", "$", "this", "->", "settings", "=", "$", "originalSettings", ";", "return", "FALSE", ";", "}", "return", "TRUE", ";", "}" ]
resets complete cache to empty @return boolean, TRUE on success , FALSE on failure
[ "resets", "complete", "cache", "to", "empty" ]
e9279ab977a16d586023c2b99d343f3d8c497d9a
https://github.com/PHPPlatform/json-cache/blob/e9279ab977a16d586023c2b99d343f3d8c497d9a/src/JSONCache/Cache.php#L123-L131
238,426
manovotny/wp-url-util
src/classes/class-wp-url-util.php
WP_Url_Util.convert_absolute_path_to_url
function convert_absolute_path_to_url( $absolute_path ) { // Remove WordPress installation path from file path. $file_base = str_replace( ABSPATH, '', $absolute_path ); // Add site url to file base. $file_url = trailingslashit( site_url() ) . $file_base; return $file_url; }
php
function convert_absolute_path_to_url( $absolute_path ) { // Remove WordPress installation path from file path. $file_base = str_replace( ABSPATH, '', $absolute_path ); // Add site url to file base. $file_url = trailingslashit( site_url() ) . $file_base; return $file_url; }
[ "function", "convert_absolute_path_to_url", "(", "$", "absolute_path", ")", "{", "// Remove WordPress installation path from file path.", "$", "file_base", "=", "str_replace", "(", "ABSPATH", ",", "''", ",", "$", "absolute_path", ")", ";", "// Add site url to file base.", "$", "file_url", "=", "trailingslashit", "(", "site_url", "(", ")", ")", ".", "$", "file_base", ";", "return", "$", "file_url", ";", "}" ]
Converts an absolute path to a file into a url to the file. @param string $absolute_path Absolute path to file. @return string Url to file.
[ "Converts", "an", "absolute", "path", "to", "a", "file", "into", "a", "url", "to", "the", "file", "." ]
41219c7744644e06fdba90046b8e6ccab88370bc
https://github.com/manovotny/wp-url-util/blob/41219c7744644e06fdba90046b8e6ccab88370bc/src/classes/class-wp-url-util.php#L56-L66
238,427
manovotny/wp-url-util
src/classes/class-wp-url-util.php
WP_Url_Util.convert_url_to_absolute_path
function convert_url_to_absolute_path( $file_url ) { // Remove WordPress site url from file url. $file_base = str_replace( trailingslashit( site_url() ), '', $file_url ); // Add WordPress installation path to file base. $absolute_path = ABSPATH . $file_base; return $absolute_path; }
php
function convert_url_to_absolute_path( $file_url ) { // Remove WordPress site url from file url. $file_base = str_replace( trailingslashit( site_url() ), '', $file_url ); // Add WordPress installation path to file base. $absolute_path = ABSPATH . $file_base; return $absolute_path; }
[ "function", "convert_url_to_absolute_path", "(", "$", "file_url", ")", "{", "// Remove WordPress site url from file url.", "$", "file_base", "=", "str_replace", "(", "trailingslashit", "(", "site_url", "(", ")", ")", ",", "''", ",", "$", "file_url", ")", ";", "// Add WordPress installation path to file base.", "$", "absolute_path", "=", "ABSPATH", ".", "$", "file_base", ";", "return", "$", "absolute_path", ";", "}" ]
Converts a url to a file into an absolute path to the file. @param string $file_url Url to file. @return string Absolute path to file.
[ "Converts", "a", "url", "to", "a", "file", "into", "an", "absolute", "path", "to", "the", "file", "." ]
41219c7744644e06fdba90046b8e6ccab88370bc
https://github.com/manovotny/wp-url-util/blob/41219c7744644e06fdba90046b8e6ccab88370bc/src/classes/class-wp-url-util.php#L74-L84
238,428
manovotny/wp-url-util
src/classes/class-wp-url-util.php
WP_Url_Util.is_external_file
public function is_external_file( $file_url ) { // Set default return value. $is_external_file = false; // Parse url. $parsed_file_url = parse_url( $file_url ); // Parse site url. $parsed_site_url = parse_url( site_url() ); // Check if hosts don't match. if ( $parsed_file_url[ 'host' ] !== $parsed_site_url[ 'host' ] ) { // We now know the file is externally hosted. $is_external_file = true; } return $is_external_file; }
php
public function is_external_file( $file_url ) { // Set default return value. $is_external_file = false; // Parse url. $parsed_file_url = parse_url( $file_url ); // Parse site url. $parsed_site_url = parse_url( site_url() ); // Check if hosts don't match. if ( $parsed_file_url[ 'host' ] !== $parsed_site_url[ 'host' ] ) { // We now know the file is externally hosted. $is_external_file = true; } return $is_external_file; }
[ "public", "function", "is_external_file", "(", "$", "file_url", ")", "{", "// Set default return value.", "$", "is_external_file", "=", "false", ";", "// Parse url.", "$", "parsed_file_url", "=", "parse_url", "(", "$", "file_url", ")", ";", "// Parse site url.", "$", "parsed_site_url", "=", "parse_url", "(", "site_url", "(", ")", ")", ";", "// Check if hosts don't match.", "if", "(", "$", "parsed_file_url", "[", "'host'", "]", "!==", "$", "parsed_site_url", "[", "'host'", "]", ")", "{", "// We now know the file is externally hosted.", "$", "is_external_file", "=", "true", ";", "}", "return", "$", "is_external_file", ";", "}" ]
Determines if a file is externally hosted based on url. @param string $file_url File url. @return boolean Whether a file is externally hosted or not.
[ "Determines", "if", "a", "file", "is", "externally", "hosted", "based", "on", "url", "." ]
41219c7744644e06fdba90046b8e6ccab88370bc
https://github.com/manovotny/wp-url-util/blob/41219c7744644e06fdba90046b8e6ccab88370bc/src/classes/class-wp-url-util.php#L128-L149
238,429
manovotny/wp-url-util
src/classes/class-wp-url-util.php
WP_Url_Util.is_uploaded_file
public function is_uploaded_file( $file_url ) { // Set default return value. $is_uploaded_file = false; // Get WordPress upload directory information. $wp_upload_directory = wp_upload_dir(); // Check if the WordPress upload directory url matches the file url. if ( false !== strpos( $file_url, $wp_upload_directory[ 'baseurl' ] ) ) { // We now know the file is one that was uploaded to WordPress. $is_uploaded_file = true; } return $is_uploaded_file; }
php
public function is_uploaded_file( $file_url ) { // Set default return value. $is_uploaded_file = false; // Get WordPress upload directory information. $wp_upload_directory = wp_upload_dir(); // Check if the WordPress upload directory url matches the file url. if ( false !== strpos( $file_url, $wp_upload_directory[ 'baseurl' ] ) ) { // We now know the file is one that was uploaded to WordPress. $is_uploaded_file = true; } return $is_uploaded_file; }
[ "public", "function", "is_uploaded_file", "(", "$", "file_url", ")", "{", "// Set default return value.", "$", "is_uploaded_file", "=", "false", ";", "// Get WordPress upload directory information.", "$", "wp_upload_directory", "=", "wp_upload_dir", "(", ")", ";", "// Check if the WordPress upload directory url matches the file url.", "if", "(", "false", "!==", "strpos", "(", "$", "file_url", ",", "$", "wp_upload_directory", "[", "'baseurl'", "]", ")", ")", "{", "// We now know the file is one that was uploaded to WordPress.", "$", "is_uploaded_file", "=", "true", ";", "}", "return", "$", "is_uploaded_file", ";", "}" ]
Determines if a file is a file that was uploaded to WordPress. @param string $file_url File url. @return string Image path.
[ "Determines", "if", "a", "file", "is", "a", "file", "that", "was", "uploaded", "to", "WordPress", "." ]
41219c7744644e06fdba90046b8e6ccab88370bc
https://github.com/manovotny/wp-url-util/blob/41219c7744644e06fdba90046b8e6ccab88370bc/src/classes/class-wp-url-util.php#L157-L175
238,430
GustavoGutierrez/PostType
src/PostType/Builder.php
Builder.register
private function register() { $this->options['labels'] = $this->label; if (!isset($this->options['rewrite'])) { $this->options['rewrite'] = array('slug' => $this->singular); } $_self = &$this; add_action('init', function () use (&$_self) { register_post_type($_self->singular, $_self->options); }); }
php
private function register() { $this->options['labels'] = $this->label; if (!isset($this->options['rewrite'])) { $this->options['rewrite'] = array('slug' => $this->singular); } $_self = &$this; add_action('init', function () use (&$_self) { register_post_type($_self->singular, $_self->options); }); }
[ "private", "function", "register", "(", ")", "{", "$", "this", "->", "options", "[", "'labels'", "]", "=", "$", "this", "->", "label", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "options", "[", "'rewrite'", "]", ")", ")", "{", "$", "this", "->", "options", "[", "'rewrite'", "]", "=", "array", "(", "'slug'", "=>", "$", "this", "->", "singular", ")", ";", "}", "$", "_self", "=", "&", "$", "this", ";", "add_action", "(", "'init'", ",", "function", "(", ")", "use", "(", "&", "$", "_self", ")", "{", "register_post_type", "(", "$", "_self", "->", "singular", ",", "$", "_self", "->", "options", ")", ";", "}", ")", ";", "}" ]
Register the post type @return void
[ "Register", "the", "post", "type" ]
3e9951eca67596e5160453bc8f90b46b2cc264f9
https://github.com/GustavoGutierrez/PostType/blob/3e9951eca67596e5160453bc8f90b46b2cc264f9/src/PostType/Builder.php#L78-L91
238,431
mszewcz/php-light-framework
src/Html/Form/FormConditional.php
FormConditional.generate
public function generate(): string { $condID = (string)$this->attributes['data-conditional-id']; $getState = $this->vHandler->get->get($condID.'_state', Variables::TYPE_INT) == 1; $postState = $this->vHandler->post->get($condID.'_state', Variables::TYPE_INT) == 1; $visible = $getState || $postState; $this->attributes['class'] .= $visible === true ? ' visible' : ''; $elements = []; $elements[] = Controlls\Text::inputHidden($condID.'_state', (int)$visible, ['method-get' => true, 'id' => '']); foreach ($this->elements as $element) { /** @noinspection PhpUndefinedMethodInspection */ $elements[] = $element->generate(); } return Tags::div($elements, $this->attributes); }
php
public function generate(): string { $condID = (string)$this->attributes['data-conditional-id']; $getState = $this->vHandler->get->get($condID.'_state', Variables::TYPE_INT) == 1; $postState = $this->vHandler->post->get($condID.'_state', Variables::TYPE_INT) == 1; $visible = $getState || $postState; $this->attributes['class'] .= $visible === true ? ' visible' : ''; $elements = []; $elements[] = Controlls\Text::inputHidden($condID.'_state', (int)$visible, ['method-get' => true, 'id' => '']); foreach ($this->elements as $element) { /** @noinspection PhpUndefinedMethodInspection */ $elements[] = $element->generate(); } return Tags::div($elements, $this->attributes); }
[ "public", "function", "generate", "(", ")", ":", "string", "{", "$", "condID", "=", "(", "string", ")", "$", "this", "->", "attributes", "[", "'data-conditional-id'", "]", ";", "$", "getState", "=", "$", "this", "->", "vHandler", "->", "get", "->", "get", "(", "$", "condID", ".", "'_state'", ",", "Variables", "::", "TYPE_INT", ")", "==", "1", ";", "$", "postState", "=", "$", "this", "->", "vHandler", "->", "post", "->", "get", "(", "$", "condID", ".", "'_state'", ",", "Variables", "::", "TYPE_INT", ")", "==", "1", ";", "$", "visible", "=", "$", "getState", "||", "$", "postState", ";", "$", "this", "->", "attributes", "[", "'class'", "]", ".=", "$", "visible", "===", "true", "?", "' visible'", ":", "''", ";", "$", "elements", "=", "[", "]", ";", "$", "elements", "[", "]", "=", "Controlls", "\\", "Text", "::", "inputHidden", "(", "$", "condID", ".", "'_state'", ",", "(", "int", ")", "$", "visible", ",", "[", "'method-get'", "=>", "true", ",", "'id'", "=>", "''", "]", ")", ";", "foreach", "(", "$", "this", "->", "elements", "as", "$", "element", ")", "{", "/** @noinspection PhpUndefinedMethodInspection */", "$", "elements", "[", "]", "=", "$", "element", "->", "generate", "(", ")", ";", "}", "return", "Tags", "::", "div", "(", "$", "elements", ",", "$", "this", "->", "attributes", ")", ";", "}" ]
Generates from conditional and returns it @return string
[ "Generates", "from", "conditional", "and", "returns", "it" ]
4d3b46781c387202c2dfbdb8760151b3ae8ef49c
https://github.com/mszewcz/php-light-framework/blob/4d3b46781c387202c2dfbdb8760151b3ae8ef49c/src/Html/Form/FormConditional.php#L54-L69
238,432
Dhii/normalization-helper-base
src/NormalizeArrayCapableTrait.php
NormalizeArrayCapableTrait._normalizeArray
protected function _normalizeArray($value) { if ($value instanceof stdClass) { $value = (array) $value; } if (is_array($value)) { return $value; } if (!($value instanceof Traversable)) { throw $this->_createInvalidArgumentException($this->__('Not an iterable'), null, null, $value); } $value = iterator_to_array($value, true); return $value; }
php
protected function _normalizeArray($value) { if ($value instanceof stdClass) { $value = (array) $value; } if (is_array($value)) { return $value; } if (!($value instanceof Traversable)) { throw $this->_createInvalidArgumentException($this->__('Not an iterable'), null, null, $value); } $value = iterator_to_array($value, true); return $value; }
[ "protected", "function", "_normalizeArray", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "stdClass", ")", "{", "$", "value", "=", "(", "array", ")", "$", "value", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "if", "(", "!", "(", "$", "value", "instanceof", "Traversable", ")", ")", "{", "throw", "$", "this", "->", "_createInvalidArgumentException", "(", "$", "this", "->", "__", "(", "'Not an iterable'", ")", ",", "null", ",", "null", ",", "$", "value", ")", ";", "}", "$", "value", "=", "iterator_to_array", "(", "$", "value", ",", "true", ")", ";", "return", "$", "value", ";", "}" ]
Normalizes a value into an array. @since [*next-version*] @param array|stdClass|Traversable $value The value to normalize. @throws InvalidArgumentException If value cannot be normalized. @return array The normalized value.
[ "Normalizes", "a", "value", "into", "an", "array", "." ]
1b64f0ea6b3e32f9478f854f6049500795b51da7
https://github.com/Dhii/normalization-helper-base/blob/1b64f0ea6b3e32f9478f854f6049500795b51da7/src/NormalizeArrayCapableTrait.php#L29-L46
238,433
squire-assistant/debug
ErrorHandler.php
ErrorHandler.unstackErrors
public static function unstackErrors() { $level = array_pop(self::$stackedErrorLevels); if (null !== $level) { $errorReportingLevel = error_reporting($level); if ($errorReportingLevel !== ($level | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)) { // If the user changed the error level, do not overwrite it error_reporting($errorReportingLevel); } } if (empty(self::$stackedErrorLevels)) { $errors = self::$stackedErrors; self::$stackedErrors = array(); foreach ($errors as $error) { $error[0]->log($error[1], $error[2], $error[3]); } } }
php
public static function unstackErrors() { $level = array_pop(self::$stackedErrorLevels); if (null !== $level) { $errorReportingLevel = error_reporting($level); if ($errorReportingLevel !== ($level | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)) { // If the user changed the error level, do not overwrite it error_reporting($errorReportingLevel); } } if (empty(self::$stackedErrorLevels)) { $errors = self::$stackedErrors; self::$stackedErrors = array(); foreach ($errors as $error) { $error[0]->log($error[1], $error[2], $error[3]); } } }
[ "public", "static", "function", "unstackErrors", "(", ")", "{", "$", "level", "=", "array_pop", "(", "self", "::", "$", "stackedErrorLevels", ")", ";", "if", "(", "null", "!==", "$", "level", ")", "{", "$", "errorReportingLevel", "=", "error_reporting", "(", "$", "level", ")", ";", "if", "(", "$", "errorReportingLevel", "!==", "(", "$", "level", "|", "E_PARSE", "|", "E_ERROR", "|", "E_CORE_ERROR", "|", "E_COMPILE_ERROR", ")", ")", "{", "// If the user changed the error level, do not overwrite it", "error_reporting", "(", "$", "errorReportingLevel", ")", ";", "}", "}", "if", "(", "empty", "(", "self", "::", "$", "stackedErrorLevels", ")", ")", "{", "$", "errors", "=", "self", "::", "$", "stackedErrors", ";", "self", "::", "$", "stackedErrors", "=", "array", "(", ")", ";", "foreach", "(", "$", "errors", "as", "$", "error", ")", "{", "$", "error", "[", "0", "]", "->", "log", "(", "$", "error", "[", "1", "]", ",", "$", "error", "[", "2", "]", ",", "$", "error", "[", "3", "]", ")", ";", "}", "}", "}" ]
Unstacks stacked errors and forwards to the logger.
[ "Unstacks", "stacked", "errors", "and", "forwards", "to", "the", "logger", "." ]
c43819e74eea94cde8faf31c1a6b00f018e607a0
https://github.com/squire-assistant/debug/blob/c43819e74eea94cde8faf31c1a6b00f018e607a0/ErrorHandler.php#L653-L673
238,434
Apatis/Http-Message
src/Message.php
Message.normalizeHeaderKey
public function normalizeHeaderKey(string $key) { $key = strtr(strtolower($key), '_', '-'); if (strpos($key, 'http-') === 0) { $key = substr($key, 5); } return $key; }
php
public function normalizeHeaderKey(string $key) { $key = strtr(strtolower($key), '_', '-'); if (strpos($key, 'http-') === 0) { $key = substr($key, 5); } return $key; }
[ "public", "function", "normalizeHeaderKey", "(", "string", "$", "key", ")", "{", "$", "key", "=", "strtr", "(", "strtolower", "(", "$", "key", ")", ",", "'_'", ",", "'-'", ")", ";", "if", "(", "strpos", "(", "$", "key", ",", "'http-'", ")", "===", "0", ")", "{", "$", "key", "=", "substr", "(", "$", "key", ",", "5", ")", ";", "}", "return", "$", "key", ";", "}" ]
Normalize header name This method transforms header names into a normalized form. This is how we enable case-insensitive header names in the other methods in this class. @param string $key The case-insensitive header name @return string Normalized header name
[ "Normalize", "header", "name" ]
9ede3f8bcdd2400b238e0624a4af8f09c60da222
https://github.com/Apatis/Http-Message/blob/9ede3f8bcdd2400b238e0624a4af8f09c60da222/src/Message.php#L303-L310
238,435
agalbourdin/agl-core
src/Session/Storage/Db.php
Db._read
public function _read($pId) { if (! isset($this->_items[$pId])) { $this->_items[$pId] = Agl::getModel(self::DB_COLLECTION); $this->_items[$pId]->loadByRealid($pId); } if ($this->_items[$pId]->getId()) { return $this->_items[$pId]->getData(); } return ''; }
php
public function _read($pId) { if (! isset($this->_items[$pId])) { $this->_items[$pId] = Agl::getModel(self::DB_COLLECTION); $this->_items[$pId]->loadByRealid($pId); } if ($this->_items[$pId]->getId()) { return $this->_items[$pId]->getData(); } return ''; }
[ "public", "function", "_read", "(", "$", "pId", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_items", "[", "$", "pId", "]", ")", ")", "{", "$", "this", "->", "_items", "[", "$", "pId", "]", "=", "Agl", "::", "getModel", "(", "self", "::", "DB_COLLECTION", ")", ";", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "loadByRealid", "(", "$", "pId", ")", ";", "}", "if", "(", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "getId", "(", ")", ")", "{", "return", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "getData", "(", ")", ";", "}", "return", "''", ";", "}" ]
Read the session identified by the ID parameter and return the session data. @param string $pId Session id @return string
[ "Read", "the", "session", "identified", "by", "the", "ID", "parameter", "and", "return", "the", "session", "data", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Session/Storage/Db.php#L78-L90
238,436
agalbourdin/agl-core
src/Session/Storage/Db.php
Db._write
public function _write($pId, $pData) { Agl::validateParams(array( 'String' => $pData )); $access = time(); if (! isset($this->_items[$pId])) { $this->_items[$pId] = Agl::getModel(self::DB_COLLECTION); $this->_items[$pId]->loadByRealid($pId); } $this->_items[$pId] ->setRealid($pId) ->setAccess($access) ->setData($pData); if (! $this->_items[$pId]->getId()) { $this->_items[$pId]->insert(); } else { $this->_items[$pId]->save(); } return true; }
php
public function _write($pId, $pData) { Agl::validateParams(array( 'String' => $pData )); $access = time(); if (! isset($this->_items[$pId])) { $this->_items[$pId] = Agl::getModel(self::DB_COLLECTION); $this->_items[$pId]->loadByRealid($pId); } $this->_items[$pId] ->setRealid($pId) ->setAccess($access) ->setData($pData); if (! $this->_items[$pId]->getId()) { $this->_items[$pId]->insert(); } else { $this->_items[$pId]->save(); } return true; }
[ "public", "function", "_write", "(", "$", "pId", ",", "$", "pData", ")", "{", "Agl", "::", "validateParams", "(", "array", "(", "'String'", "=>", "$", "pData", ")", ")", ";", "$", "access", "=", "time", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_items", "[", "$", "pId", "]", ")", ")", "{", "$", "this", "->", "_items", "[", "$", "pId", "]", "=", "Agl", "::", "getModel", "(", "self", "::", "DB_COLLECTION", ")", ";", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "loadByRealid", "(", "$", "pId", ")", ";", "}", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "setRealid", "(", "$", "pId", ")", "->", "setAccess", "(", "$", "access", ")", "->", "setData", "(", "$", "pData", ")", ";", "if", "(", "!", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "getId", "(", ")", ")", "{", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "insert", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "save", "(", ")", ";", "}", "return", "true", ";", "}" ]
Write the session to the database. @param string $pId Session id @param string $pData Session data @return bool
[ "Write", "the", "session", "to", "the", "database", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Session/Storage/Db.php#L99-L124
238,437
agalbourdin/agl-core
src/Session/Storage/Db.php
Db._destroy
public function _destroy($pId) { if (! isset($this->_items[$pId])) { $this->_items[$pId] = Agl::getModel(self::DB_COLLECTION); $this->_items[$pId]->loadByRealid($pId); } if ($this->_items[$pId]->getId()) { $this->_items[$pId]->delete(); } return true; }
php
public function _destroy($pId) { if (! isset($this->_items[$pId])) { $this->_items[$pId] = Agl::getModel(self::DB_COLLECTION); $this->_items[$pId]->loadByRealid($pId); } if ($this->_items[$pId]->getId()) { $this->_items[$pId]->delete(); } return true; }
[ "public", "function", "_destroy", "(", "$", "pId", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_items", "[", "$", "pId", "]", ")", ")", "{", "$", "this", "->", "_items", "[", "$", "pId", "]", "=", "Agl", "::", "getModel", "(", "self", "::", "DB_COLLECTION", ")", ";", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "loadByRealid", "(", "$", "pId", ")", ";", "}", "if", "(", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "getId", "(", ")", ")", "{", "$", "this", "->", "_items", "[", "$", "pId", "]", "->", "delete", "(", ")", ";", "}", "return", "true", ";", "}" ]
Destroy the session from the database. @param string $pId Session id @return bool
[ "Destroy", "the", "session", "from", "the", "database", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Session/Storage/Db.php#L132-L144
238,438
agalbourdin/agl-core
src/Session/Storage/Db.php
Db._clean
public function _clean($pMax) { Agl::validateParams(array( 'Digit' => $pMax )); $old = time() - $pMax; $collection = new Collection(self::DB_COLLECTION); $conditions = new Conditions(); $conditions->add('access', Conditions::LT, $old); $collection->load($conditions); $collection->deleteItems(); return true; }
php
public function _clean($pMax) { Agl::validateParams(array( 'Digit' => $pMax )); $old = time() - $pMax; $collection = new Collection(self::DB_COLLECTION); $conditions = new Conditions(); $conditions->add('access', Conditions::LT, $old); $collection->load($conditions); $collection->deleteItems(); return true; }
[ "public", "function", "_clean", "(", "$", "pMax", ")", "{", "Agl", "::", "validateParams", "(", "array", "(", "'Digit'", "=>", "$", "pMax", ")", ")", ";", "$", "old", "=", "time", "(", ")", "-", "$", "pMax", ";", "$", "collection", "=", "new", "Collection", "(", "self", "::", "DB_COLLECTION", ")", ";", "$", "conditions", "=", "new", "Conditions", "(", ")", ";", "$", "conditions", "->", "add", "(", "'access'", ",", "Conditions", "::", "LT", ",", "$", "old", ")", ";", "$", "collection", "->", "load", "(", "$", "conditions", ")", ";", "$", "collection", "->", "deleteItems", "(", ")", ";", "return", "true", ";", "}" ]
Clean the database by deleting old sessions. @param int $pMax Session lifetime @return bool
[ "Clean", "the", "database", "by", "deleting", "old", "sessions", "." ]
1db556f9a49488aa9fab6887fefb7141a79ad97d
https://github.com/agalbourdin/agl-core/blob/1db556f9a49488aa9fab6887fefb7141a79ad97d/src/Session/Storage/Db.php#L152-L169
238,439
cspray/SpraySole
doc/examples/002-using-command-provider.php
SomeCommandProvider.register
public function register(Application $App) { $App->addCommand(new \YourApp\Command\Foo()); $App->addCommand(new \YourApp\Command\Bar()); $App->addCommand(new \YourApp\Command\Baz()); }
php
public function register(Application $App) { $App->addCommand(new \YourApp\Command\Foo()); $App->addCommand(new \YourApp\Command\Bar()); $App->addCommand(new \YourApp\Command\Baz()); }
[ "public", "function", "register", "(", "Application", "$", "App", ")", "{", "$", "App", "->", "addCommand", "(", "new", "\\", "YourApp", "\\", "Command", "\\", "Foo", "(", ")", ")", ";", "$", "App", "->", "addCommand", "(", "new", "\\", "YourApp", "\\", "Command", "\\", "Bar", "(", ")", ")", ";", "$", "App", "->", "addCommand", "(", "new", "\\", "YourApp", "\\", "Command", "\\", "Baz", "(", ")", ")", ";", "}" ]
Add the appropriate Command implementations to the Application. @param \SpraySole\Application $App @return void
[ "Add", "the", "appropriate", "Command", "implementations", "to", "the", "Application", "." ]
f08d3025bdf731c1299eddb5af921683c33349a9
https://github.com/cspray/SpraySole/blob/f08d3025bdf731c1299eddb5af921683c33349a9/doc/examples/002-using-command-provider.php#L24-L28
238,440
jivoo/core
src/Store/PhpStore.php
PhpStore.prettyPrint
public static function prettyPrint($data, $prefix = '') { $php = '[' . PHP_EOL; if (is_array($data) and array_diff_key($data, array_keys(array_keys($data)))) { foreach ($data as $key => $value) { $php .= $prefix . ' ' . var_export($key, true) . ' => '; if (is_array($value)) { $php .= self::prettyPrint($value, $prefix . ' '); } else { $php .= var_export($value, true); } $php .= ',' . PHP_EOL; } } else { foreach ($data as $value) { $php .= $prefix . ' '; if (is_array($value)) { $php .= self::prettyPrint($value, $prefix . ' '); } else { $php .= var_export($value, true); } $php .= ',' . PHP_EOL; } } return $php . $prefix . ']'; }
php
public static function prettyPrint($data, $prefix = '') { $php = '[' . PHP_EOL; if (is_array($data) and array_diff_key($data, array_keys(array_keys($data)))) { foreach ($data as $key => $value) { $php .= $prefix . ' ' . var_export($key, true) . ' => '; if (is_array($value)) { $php .= self::prettyPrint($value, $prefix . ' '); } else { $php .= var_export($value, true); } $php .= ',' . PHP_EOL; } } else { foreach ($data as $value) { $php .= $prefix . ' '; if (is_array($value)) { $php .= self::prettyPrint($value, $prefix . ' '); } else { $php .= var_export($value, true); } $php .= ',' . PHP_EOL; } } return $php . $prefix . ']'; }
[ "public", "static", "function", "prettyPrint", "(", "$", "data", ",", "$", "prefix", "=", "''", ")", "{", "$", "php", "=", "'['", ".", "PHP_EOL", ";", "if", "(", "is_array", "(", "$", "data", ")", "and", "array_diff_key", "(", "$", "data", ",", "array_keys", "(", "array_keys", "(", "$", "data", ")", ")", ")", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "php", ".=", "$", "prefix", ".", "' '", ".", "var_export", "(", "$", "key", ",", "true", ")", ".", "' => '", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "php", ".=", "self", "::", "prettyPrint", "(", "$", "value", ",", "$", "prefix", ".", "' '", ")", ";", "}", "else", "{", "$", "php", ".=", "var_export", "(", "$", "value", ",", "true", ")", ";", "}", "$", "php", ".=", "','", ".", "PHP_EOL", ";", "}", "}", "else", "{", "foreach", "(", "$", "data", "as", "$", "value", ")", "{", "$", "php", ".=", "$", "prefix", ".", "' '", ";", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "php", ".=", "self", "::", "prettyPrint", "(", "$", "value", ",", "$", "prefix", ".", "' '", ")", ";", "}", "else", "{", "$", "php", ".=", "var_export", "(", "$", "value", ",", "true", ")", ";", "}", "$", "php", ".=", "','", ".", "PHP_EOL", ";", "}", "}", "return", "$", "php", ".", "$", "prefix", ".", "']'", ";", "}" ]
Create valid PHP array representation @param array $data Associative array @param string $prefix Prefix to put in front of new lines @return string PHP source
[ "Create", "valid", "PHP", "array", "representation" ]
4ef3445068f0ff9c0a6512cb741831a847013b76
https://github.com/jivoo/core/blob/4ef3445068f0ff9c0a6512cb741831a847013b76/src/Store/PhpStore.php#L50-L75
238,441
CakeCMS/Extensions
src/View/Helper/ExtensionHelper.php
ExtensionHelper.renderPluginParams
public function renderPluginParams() { /** @var Extension $entity */ $tabNav = []; $tabContent = []; $entity = $this->_View->get('entity'); $params = Plugin::getData($entity->getName(), 'params'); foreach ($params->getArrayCopy() as $title => $_params) { $fields = []; $_params = new Data($_params); $tabId = 'tab-' . Str::slug($title); $tabNav[] = $this->_View->element('Extensions.Params/tab', [ 'title' => $title, 'params' => $_params, 'tabId' => $tabId ]); foreach ($_params as $key => $options) { $fieldName = Str::clean('params.' . $key); if (is_callable($options)) { $fields[] = call_user_func($options, $this->_View); continue; } if (isset($options['options']) && is_callable($options['options'])) { $options['options'] = call_user_func($options['options'], $this->_View); } $fields[] = $this->_View->Form->control($fieldName, $options); } $tabContent[$tabId] = implode(PHP_EOL, $fields); } return implode(PHP_EOL, [ $this->_View->element('Extensions.Params/list', ['items' => $tabNav]), $this->_View->element('Extensions.Params/content', ['content' => $tabContent]) ]); }
php
public function renderPluginParams() { /** @var Extension $entity */ $tabNav = []; $tabContent = []; $entity = $this->_View->get('entity'); $params = Plugin::getData($entity->getName(), 'params'); foreach ($params->getArrayCopy() as $title => $_params) { $fields = []; $_params = new Data($_params); $tabId = 'tab-' . Str::slug($title); $tabNav[] = $this->_View->element('Extensions.Params/tab', [ 'title' => $title, 'params' => $_params, 'tabId' => $tabId ]); foreach ($_params as $key => $options) { $fieldName = Str::clean('params.' . $key); if (is_callable($options)) { $fields[] = call_user_func($options, $this->_View); continue; } if (isset($options['options']) && is_callable($options['options'])) { $options['options'] = call_user_func($options['options'], $this->_View); } $fields[] = $this->_View->Form->control($fieldName, $options); } $tabContent[$tabId] = implode(PHP_EOL, $fields); } return implode(PHP_EOL, [ $this->_View->element('Extensions.Params/list', ['items' => $tabNav]), $this->_View->element('Extensions.Params/content', ['content' => $tabContent]) ]); }
[ "public", "function", "renderPluginParams", "(", ")", "{", "/** @var Extension $entity */", "$", "tabNav", "=", "[", "]", ";", "$", "tabContent", "=", "[", "]", ";", "$", "entity", "=", "$", "this", "->", "_View", "->", "get", "(", "'entity'", ")", ";", "$", "params", "=", "Plugin", "::", "getData", "(", "$", "entity", "->", "getName", "(", ")", ",", "'params'", ")", ";", "foreach", "(", "$", "params", "->", "getArrayCopy", "(", ")", "as", "$", "title", "=>", "$", "_params", ")", "{", "$", "fields", "=", "[", "]", ";", "$", "_params", "=", "new", "Data", "(", "$", "_params", ")", ";", "$", "tabId", "=", "'tab-'", ".", "Str", "::", "slug", "(", "$", "title", ")", ";", "$", "tabNav", "[", "]", "=", "$", "this", "->", "_View", "->", "element", "(", "'Extensions.Params/tab'", ",", "[", "'title'", "=>", "$", "title", ",", "'params'", "=>", "$", "_params", ",", "'tabId'", "=>", "$", "tabId", "]", ")", ";", "foreach", "(", "$", "_params", "as", "$", "key", "=>", "$", "options", ")", "{", "$", "fieldName", "=", "Str", "::", "clean", "(", "'params.'", ".", "$", "key", ")", ";", "if", "(", "is_callable", "(", "$", "options", ")", ")", "{", "$", "fields", "[", "]", "=", "call_user_func", "(", "$", "options", ",", "$", "this", "->", "_View", ")", ";", "continue", ";", "}", "if", "(", "isset", "(", "$", "options", "[", "'options'", "]", ")", "&&", "is_callable", "(", "$", "options", "[", "'options'", "]", ")", ")", "{", "$", "options", "[", "'options'", "]", "=", "call_user_func", "(", "$", "options", "[", "'options'", "]", ",", "$", "this", "->", "_View", ")", ";", "}", "$", "fields", "[", "]", "=", "$", "this", "->", "_View", "->", "Form", "->", "control", "(", "$", "fieldName", ",", "$", "options", ")", ";", "}", "$", "tabContent", "[", "$", "tabId", "]", "=", "implode", "(", "PHP_EOL", ",", "$", "fields", ")", ";", "}", "return", "implode", "(", "PHP_EOL", ",", "[", "$", "this", "->", "_View", "->", "element", "(", "'Extensions.Params/list'", ",", "[", "'items'", "=>", "$", "tabNav", "]", ")", ",", "$", "this", "->", "_View", "->", "element", "(", "'Extensions.Params/content'", ",", "[", "'content'", "=>", "$", "tabContent", "]", ")", "]", ")", ";", "}" ]
Render plugin params. @return string @throws MissingElementException
[ "Render", "plugin", "params", "." ]
5c719a8283ff2bc5499658f2ef3d6932d26c55e6
https://github.com/CakeCMS/Extensions/blob/5c719a8283ff2bc5499658f2ef3d6932d26c55e6/src/View/Helper/ExtensionHelper.php#L39-L77
238,442
autarky/twig-templating
src/TemplatingEngine.php
TemplatingEngine.setEventDispatcher
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) { $this->eventDispatcher = $eventDispatcher; $this->twig->setEventDispatcher($eventDispatcher); }
php
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher) { $this->eventDispatcher = $eventDispatcher; $this->twig->setEventDispatcher($eventDispatcher); }
[ "public", "function", "setEventDispatcher", "(", "EventDispatcherInterface", "$", "eventDispatcher", ")", "{", "$", "this", "->", "eventDispatcher", "=", "$", "eventDispatcher", ";", "$", "this", "->", "twig", "->", "setEventDispatcher", "(", "$", "eventDispatcher", ")", ";", "}" ]
Set the event dispatcher instance. @param EventDispatcherInterface $eventDispatcher
[ "Set", "the", "event", "dispatcher", "instance", "." ]
d65ec619f10390f27e64f0d1e0ab30dffde3d0ce
https://github.com/autarky/twig-templating/blob/d65ec619f10390f27e64f0d1e0ab30dffde3d0ce/src/TemplatingEngine.php#L49-L53
238,443
autarky/twig-templating
src/TemplatingEngine.php
TemplatingEngine.addNamespace
public function addNamespace($namespace, $location) { $loader = $this->twig->getLoader(); $loader->addPath($location, $namespace); foreach ($loader->getPaths() as $path) { if (is_dir($dir = $path.'/'.$namespace)) { $loader->prependPath($dir, $namespace); } } }
php
public function addNamespace($namespace, $location) { $loader = $this->twig->getLoader(); $loader->addPath($location, $namespace); foreach ($loader->getPaths() as $path) { if (is_dir($dir = $path.'/'.$namespace)) { $loader->prependPath($dir, $namespace); } } }
[ "public", "function", "addNamespace", "(", "$", "namespace", ",", "$", "location", ")", "{", "$", "loader", "=", "$", "this", "->", "twig", "->", "getLoader", "(", ")", ";", "$", "loader", "->", "addPath", "(", "$", "location", ",", "$", "namespace", ")", ";", "foreach", "(", "$", "loader", "->", "getPaths", "(", ")", "as", "$", "path", ")", "{", "if", "(", "is_dir", "(", "$", "dir", "=", "$", "path", ".", "'/'", ".", "$", "namespace", ")", ")", "{", "$", "loader", "->", "prependPath", "(", "$", "dir", ",", "$", "namespace", ")", ";", "}", "}", "}" ]
Register a template namespace. @param string $namespace @param string $location @return void
[ "Register", "a", "template", "namespace", "." ]
d65ec619f10390f27e64f0d1e0ab30dffde3d0ce
https://github.com/autarky/twig-templating/blob/d65ec619f10390f27e64f0d1e0ab30dffde3d0ce/src/TemplatingEngine.php#L127-L138
238,444
Dhii/file-finder-abstract
src/AbstractFileFinder.php
AbstractFileFinder._setCallbackFilter
protected function _setCallbackFilter($filter) { if (!is_callable($filter, true) && !is_null($filter)) { throw new InvalidArgumentException('Filter must be a callable'); } $this->callbackFilter = $filter; return $this; }
php
protected function _setCallbackFilter($filter) { if (!is_callable($filter, true) && !is_null($filter)) { throw new InvalidArgumentException('Filter must be a callable'); } $this->callbackFilter = $filter; return $this; }
[ "protected", "function", "_setCallbackFilter", "(", "$", "filter", ")", "{", "if", "(", "!", "is_callable", "(", "$", "filter", ",", "true", ")", "&&", "!", "is_null", "(", "$", "filter", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'Filter must be a callable'", ")", ";", "}", "$", "this", "->", "callbackFilter", "=", "$", "filter", ";", "return", "$", "this", ";", "}" ]
Assigns the filter that is optionally used to filter files. @since [*next-version*] @param callable|null $filter The callback. @throws InvalidArgumentException If the filter is not a callable. @return $this
[ "Assigns", "the", "filter", "that", "is", "optionally", "used", "to", "filter", "files", "." ]
3f5ad2a6a9e6ae68bad4870548061428734b231c
https://github.com/Dhii/file-finder-abstract/blob/3f5ad2a6a9e6ae68bad4870548061428734b231c/src/AbstractFileFinder.php#L175-L184
238,445
Dhii/file-finder-abstract
src/AbstractFileFinder.php
AbstractFileFinder._getPaths
protected function _getPaths() { $directories = $this->_createDirectoryIterator($this->_getRootDir()); $flattened = $this->_createRecursiveIteratorIterator($directories); $flattened->setMaxDepth($this->_getMaxDepth()); $filter = $this->_createFilterIterator($flattened, function (SplFileInfo $current, $key, Iterator $iterator) { return $this->_filterFile($current); }); return $filter; }
php
protected function _getPaths() { $directories = $this->_createDirectoryIterator($this->_getRootDir()); $flattened = $this->_createRecursiveIteratorIterator($directories); $flattened->setMaxDepth($this->_getMaxDepth()); $filter = $this->_createFilterIterator($flattened, function (SplFileInfo $current, $key, Iterator $iterator) { return $this->_filterFile($current); }); return $filter; }
[ "protected", "function", "_getPaths", "(", ")", "{", "$", "directories", "=", "$", "this", "->", "_createDirectoryIterator", "(", "$", "this", "->", "_getRootDir", "(", ")", ")", ";", "$", "flattened", "=", "$", "this", "->", "_createRecursiveIteratorIterator", "(", "$", "directories", ")", ";", "$", "flattened", "->", "setMaxDepth", "(", "$", "this", "->", "_getMaxDepth", "(", ")", ")", ";", "$", "filter", "=", "$", "this", "->", "_createFilterIterator", "(", "$", "flattened", ",", "function", "(", "SplFileInfo", "$", "current", ",", "$", "key", ",", "Iterator", "$", "iterator", ")", "{", "return", "$", "this", "->", "_filterFile", "(", "$", "current", ")", ";", "}", ")", ";", "return", "$", "filter", ";", "}" ]
Retrieves a list of file paths. @since [*next-version*] @return string[]|Traversable The file set.
[ "Retrieves", "a", "list", "of", "file", "paths", "." ]
3f5ad2a6a9e6ae68bad4870548061428734b231c
https://github.com/Dhii/file-finder-abstract/blob/3f5ad2a6a9e6ae68bad4870548061428734b231c/src/AbstractFileFinder.php#L193-L203
238,446
Dhii/file-finder-abstract
src/AbstractFileFinder.php
AbstractFileFinder._filterFile
protected function _filterFile(SplFileInfo $fileInfo) { if (!$fileInfo->isFile()) { return false; } if (($expr = $this->_getFilenameRegex()) && !preg_match($expr, $fileInfo->getPathname())) { return false; } if (($callback = $this->_getCallbackFilter()) && !call_user_func_array($callback, array($fileInfo))) { return false; } return true; }
php
protected function _filterFile(SplFileInfo $fileInfo) { if (!$fileInfo->isFile()) { return false; } if (($expr = $this->_getFilenameRegex()) && !preg_match($expr, $fileInfo->getPathname())) { return false; } if (($callback = $this->_getCallbackFilter()) && !call_user_func_array($callback, array($fileInfo))) { return false; } return true; }
[ "protected", "function", "_filterFile", "(", "SplFileInfo", "$", "fileInfo", ")", "{", "if", "(", "!", "$", "fileInfo", "->", "isFile", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "(", "$", "expr", "=", "$", "this", "->", "_getFilenameRegex", "(", ")", ")", "&&", "!", "preg_match", "(", "$", "expr", ",", "$", "fileInfo", "->", "getPathname", "(", ")", ")", ")", "{", "return", "false", ";", "}", "if", "(", "(", "$", "callback", "=", "$", "this", "->", "_getCallbackFilter", "(", ")", ")", "&&", "!", "call_user_func_array", "(", "$", "callback", ",", "array", "(", "$", "fileInfo", ")", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Determines whether or not a file is allowed to be "found". @since [*next-version*] @param SplFileInfo $fileInfo The object that represents information about a file. @return bool True if the file is allowed; false otherwise.
[ "Determines", "whether", "or", "not", "a", "file", "is", "allowed", "to", "be", "found", "." ]
3f5ad2a6a9e6ae68bad4870548061428734b231c
https://github.com/Dhii/file-finder-abstract/blob/3f5ad2a6a9e6ae68bad4870548061428734b231c/src/AbstractFileFinder.php#L214-L229
238,447
apnet/AsseticImporterBundle
src/Apnet/AsseticImporterBundle/Factory/AssetFormulae.php
AssetFormulae.getOption
public function getOption($name) { if ($this->hasOption($name)) { $option = $this->options[$name]; } else { $option = null; } return $option; }
php
public function getOption($name) { if ($this->hasOption($name)) { $option = $this->options[$name]; } else { $option = null; } return $option; }
[ "public", "function", "getOption", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "hasOption", "(", "$", "name", ")", ")", "{", "$", "option", "=", "$", "this", "->", "options", "[", "$", "name", "]", ";", "}", "else", "{", "$", "option", "=", "null", ";", "}", "return", "$", "option", ";", "}" ]
Get option by name @param string $name Option name @return string
[ "Get", "option", "by", "name" ]
104ad3593795c016a5b89ecc8c240d4d96d3de45
https://github.com/apnet/AsseticImporterBundle/blob/104ad3593795c016a5b89ecc8c240d4d96d3de45/src/Apnet/AsseticImporterBundle/Factory/AssetFormulae.php#L133-L141
238,448
weavephp/error-whoops
src/Whoops.php
Whoops.loadWhoopsErrorHandler
protected function loadWhoopsErrorHandler() { $run = new \Whoops\Run; $run->pushHandler(new \Whoops\Handler\PrettyPageHandler); $run->register(); return $run; }
php
protected function loadWhoopsErrorHandler() { $run = new \Whoops\Run; $run->pushHandler(new \Whoops\Handler\PrettyPageHandler); $run->register(); return $run; }
[ "protected", "function", "loadWhoopsErrorHandler", "(", ")", "{", "$", "run", "=", "new", "\\", "Whoops", "\\", "Run", ";", "$", "run", "->", "pushHandler", "(", "new", "\\", "Whoops", "\\", "Handler", "\\", "PrettyPageHandler", ")", ";", "$", "run", "->", "register", "(", ")", ";", "return", "$", "run", ";", "}" ]
Setup the instance of Whoops. @return \Whoops\Run;
[ "Setup", "the", "instance", "of", "Whoops", "." ]
8fc22a0bc9fbb50a43cef1cd1c6c12590c625bcf
https://github.com/weavephp/error-whoops/blob/8fc22a0bc9fbb50a43cef1cd1c6c12590c625bcf/src/Whoops.php#L30-L36
238,449
jnjxp/html
src/Helper/Metas.php
Metas.addProperty
public function addProperty($property, $content, $position = 100) { $attr = [ 'property' => $property, 'content' => $content ]; $this->add($attr, $position); return $this; }
php
public function addProperty($property, $content, $position = 100) { $attr = [ 'property' => $property, 'content' => $content ]; $this->add($attr, $position); return $this; }
[ "public", "function", "addProperty", "(", "$", "property", ",", "$", "content", ",", "$", "position", "=", "100", ")", "{", "$", "attr", "=", "[", "'property'", "=>", "$", "property", ",", "'content'", "=>", "$", "content", "]", ";", "$", "this", "->", "add", "(", "$", "attr", ",", "$", "position", ")", ";", "return", "$", "this", ";", "}" ]
add a property meta tag eg: <meta property="foo" content="bar" /> @param string $property property name @param string $content property value @param int $position sort order @return Metas @access public
[ "add", "a", "property", "meta", "tag" ]
a38f130c19ab0a60ea52bc1d2560a68d2048d292
https://github.com/jnjxp/html/blob/a38f130c19ab0a60ea52bc1d2560a68d2048d292/src/Helper/Metas.php#L59-L67
238,450
jnjxp/html
src/Helper/Metas.php
Metas.image
public function image($image, $position = 100) { $this->add( [ 'name' => 'image', 'property' => 'og:image', 'content' => $image ], $position ); $this->addElement( $position, $this->void( 'link', [ 'rel' => 'image_src', 'href' => $image ] ) ); return $this; }
php
public function image($image, $position = 100) { $this->add( [ 'name' => 'image', 'property' => 'og:image', 'content' => $image ], $position ); $this->addElement( $position, $this->void( 'link', [ 'rel' => 'image_src', 'href' => $image ] ) ); return $this; }
[ "public", "function", "image", "(", "$", "image", ",", "$", "position", "=", "100", ")", "{", "$", "this", "->", "add", "(", "[", "'name'", "=>", "'image'", ",", "'property'", "=>", "'og:image'", ",", "'content'", "=>", "$", "image", "]", ",", "$", "position", ")", ";", "$", "this", "->", "addElement", "(", "$", "position", ",", "$", "this", "->", "void", "(", "'link'", ",", "[", "'rel'", "=>", "'image_src'", ",", "'href'", "=>", "$", "image", "]", ")", ")", ";", "return", "$", "this", ";", "}" ]
set opengraph and rel image @param string $image DESCRIPTION @param int $position sort order @return Metas @access public
[ "set", "opengraph", "and", "rel", "image" ]
a38f130c19ab0a60ea52bc1d2560a68d2048d292
https://github.com/jnjxp/html/blob/a38f130c19ab0a60ea52bc1d2560a68d2048d292/src/Helper/Metas.php#L229-L251
238,451
Dhii/validation-abstract
src/GetValidationErrorsCapableCompositeTrait.php
GetValidationErrorsCapableCompositeTrait._getValidationErrors
protected function _getValidationErrors($subject) { $errors = array(); foreach ($this->_getChildValidators() as $_idx => $_validator) { try { if (!($_validator instanceof ValidatorInterface)) { throw $this->_createOutOfRangeException($this->__('Validator %1$s is invalid', array($_idx)), null, null, $_validator); } $_validator->validate($subject); } catch (ValidationFailedExceptionInterface $e) { $errors[] = $e->getValidationErrors(); } } return $this->_normalizeErrorList($errors); }
php
protected function _getValidationErrors($subject) { $errors = array(); foreach ($this->_getChildValidators() as $_idx => $_validator) { try { if (!($_validator instanceof ValidatorInterface)) { throw $this->_createOutOfRangeException($this->__('Validator %1$s is invalid', array($_idx)), null, null, $_validator); } $_validator->validate($subject); } catch (ValidationFailedExceptionInterface $e) { $errors[] = $e->getValidationErrors(); } } return $this->_normalizeErrorList($errors); }
[ "protected", "function", "_getValidationErrors", "(", "$", "subject", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_getChildValidators", "(", ")", "as", "$", "_idx", "=>", "$", "_validator", ")", "{", "try", "{", "if", "(", "!", "(", "$", "_validator", "instanceof", "ValidatorInterface", ")", ")", "{", "throw", "$", "this", "->", "_createOutOfRangeException", "(", "$", "this", "->", "__", "(", "'Validator %1$s is invalid'", ",", "array", "(", "$", "_idx", ")", ")", ",", "null", ",", "null", ",", "$", "_validator", ")", ";", "}", "$", "_validator", "->", "validate", "(", "$", "subject", ")", ";", "}", "catch", "(", "ValidationFailedExceptionInterface", "$", "e", ")", "{", "$", "errors", "[", "]", "=", "$", "e", "->", "getValidationErrors", "(", ")", ";", "}", "}", "return", "$", "this", "->", "_normalizeErrorList", "(", "$", "errors", ")", ";", "}" ]
Retrieve a list of reasons that make the subject invalid. This implementation uses child validators, and validates the subject with each one sequentially. It then aggregates the errors from all of them into a flat list. @since [*next-version*] @param mixed $subject The value to validate. @throws OutOfRangeException If one of the child validators is not a validator. @throws ValidationExceptionInterface If problem validating. @return string[]|Stringable[]|Traversable|stdClass The list of validation errors. Must be finite.
[ "Retrieve", "a", "list", "of", "reasons", "that", "make", "the", "subject", "invalid", "." ]
dff998ba3476927a0fc6d10bb022425de8f1c844
https://github.com/Dhii/validation-abstract/blob/dff998ba3476927a0fc6d10bb022425de8f1c844/src/GetValidationErrorsCapableCompositeTrait.php#L39-L55
238,452
shizhice/support
src/Time.php
Time.secondToTime
static public function secondToTime($times) { $result = '00:00:00'; if ($times > 0) { $hour = floor($times/3600); $minute = floor(($times-3600 * $hour)/60); $second = floor((($times-3600 * $hour) - 60 * $minute) % 60); $result = str_pad($hour, 2, "0", STR_PAD_LEFT).':'.str_pad($minute, 2, "0", STR_PAD_LEFT).':'.str_pad($second, 2, "0", STR_PAD_LEFT); } return $result; }
php
static public function secondToTime($times) { $result = '00:00:00'; if ($times > 0) { $hour = floor($times/3600); $minute = floor(($times-3600 * $hour)/60); $second = floor((($times-3600 * $hour) - 60 * $minute) % 60); $result = str_pad($hour, 2, "0", STR_PAD_LEFT).':'.str_pad($minute, 2, "0", STR_PAD_LEFT).':'.str_pad($second, 2, "0", STR_PAD_LEFT); } return $result; }
[ "static", "public", "function", "secondToTime", "(", "$", "times", ")", "{", "$", "result", "=", "'00:00:00'", ";", "if", "(", "$", "times", ">", "0", ")", "{", "$", "hour", "=", "floor", "(", "$", "times", "/", "3600", ")", ";", "$", "minute", "=", "floor", "(", "(", "$", "times", "-", "3600", "*", "$", "hour", ")", "/", "60", ")", ";", "$", "second", "=", "floor", "(", "(", "(", "$", "times", "-", "3600", "*", "$", "hour", ")", "-", "60", "*", "$", "minute", ")", "%", "60", ")", ";", "$", "result", "=", "str_pad", "(", "$", "hour", ",", "2", ",", "\"0\"", ",", "STR_PAD_LEFT", ")", ".", "':'", ".", "str_pad", "(", "$", "minute", ",", "2", ",", "\"0\"", ",", "STR_PAD_LEFT", ")", ".", "':'", ".", "str_pad", "(", "$", "second", ",", "2", ",", "\"0\"", ",", "STR_PAD_LEFT", ")", ";", "}", "return", "$", "result", ";", "}" ]
second to time @param $times @return string
[ "second", "to", "time" ]
75b05fb28840767979396d6693120a8d5c22bdbc
https://github.com/shizhice/support/blob/75b05fb28840767979396d6693120a8d5c22bdbc/src/Time.php#L19-L31
238,453
ItinerisLtd/preflight-command
src/CLI/CheckerCollectionPresenter.php
CheckerCollectionPresenter.display
public static function display(array $assocArgs, CheckerCollection $checkerCollection): void { // TODO: Use null coalescing assignment operator. $assocArgs['fields'] = $assocArgs['fields'] ?? self::DEFAULT_FIELDS; $formatter = new Formatter($assocArgs, $assocArgs['fields']); $items = (in_array($formatter->format, ['ids', 'count'], true)) ? self::pluckIds($checkerCollection) : self::toArray($checkerCollection); $formatter->display_items($items); }
php
public static function display(array $assocArgs, CheckerCollection $checkerCollection): void { // TODO: Use null coalescing assignment operator. $assocArgs['fields'] = $assocArgs['fields'] ?? self::DEFAULT_FIELDS; $formatter = new Formatter($assocArgs, $assocArgs['fields']); $items = (in_array($formatter->format, ['ids', 'count'], true)) ? self::pluckIds($checkerCollection) : self::toArray($checkerCollection); $formatter->display_items($items); }
[ "public", "static", "function", "display", "(", "array", "$", "assocArgs", ",", "CheckerCollection", "$", "checkerCollection", ")", ":", "void", "{", "// TODO: Use null coalescing assignment operator.", "$", "assocArgs", "[", "'fields'", "]", "=", "$", "assocArgs", "[", "'fields'", "]", "??", "self", "::", "DEFAULT_FIELDS", ";", "$", "formatter", "=", "new", "Formatter", "(", "$", "assocArgs", ",", "$", "assocArgs", "[", "'fields'", "]", ")", ";", "$", "items", "=", "(", "in_array", "(", "$", "formatter", "->", "format", ",", "[", "'ids'", ",", "'count'", "]", ",", "true", ")", ")", "?", "self", "::", "pluckIds", "(", "$", "checkerCollection", ")", ":", "self", "::", "toArray", "(", "$", "checkerCollection", ")", ";", "$", "formatter", "->", "display_items", "(", "$", "items", ")", ";", "}" ]
Display a checker collection in a given format. @param array $assocArgs Associative CLI argument. @param CheckerCollection $checkerCollection The checker collection instance.
[ "Display", "a", "checker", "collection", "in", "a", "given", "format", "." ]
d1c1360ea8d7de0312b5c0c09c9c486949594049
https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/CLI/CheckerCollectionPresenter.php#L24-L35
238,454
ItinerisLtd/preflight-command
src/CLI/CheckerCollectionPresenter.php
CheckerCollectionPresenter.toArray
private static function toArray(CheckerCollection $checkerCollection): array { return array_map(function (CheckerInterface $checker): array { return [ 'id' => $checker->getId(), 'description' => $checker->getDescription(), 'link' => $checker->getLink(), ]; }, $checkerCollection->all()); }
php
private static function toArray(CheckerCollection $checkerCollection): array { return array_map(function (CheckerInterface $checker): array { return [ 'id' => $checker->getId(), 'description' => $checker->getDescription(), 'link' => $checker->getLink(), ]; }, $checkerCollection->all()); }
[ "private", "static", "function", "toArray", "(", "CheckerCollection", "$", "checkerCollection", ")", ":", "array", "{", "return", "array_map", "(", "function", "(", "CheckerInterface", "$", "checker", ")", ":", "array", "{", "return", "[", "'id'", "=>", "$", "checker", "->", "getId", "(", ")", ",", "'description'", "=>", "$", "checker", "->", "getDescription", "(", ")", ",", "'link'", "=>", "$", "checker", "->", "getLink", "(", ")", ",", "]", ";", "}", ",", "$", "checkerCollection", "->", "all", "(", ")", ")", ";", "}" ]
Converts the underlying checkers into a plain PHP array. @param CheckerCollection $checkerCollection The checker collection instance. @return array
[ "Converts", "the", "underlying", "checkers", "into", "a", "plain", "PHP", "array", "." ]
d1c1360ea8d7de0312b5c0c09c9c486949594049
https://github.com/ItinerisLtd/preflight-command/blob/d1c1360ea8d7de0312b5c0c09c9c486949594049/src/CLI/CheckerCollectionPresenter.php#L58-L67
238,455
monomelodies/ornament
src/Query.php
Query.modelInstance
private static function modelInstance(array $ctor = []) { static $cached; if (!isset($cached)) { $class = new ReflectionClass(get_called_class()); $cached = $class->newInstanceArgs($ctor); } return $cached; }
php
private static function modelInstance(array $ctor = []) { static $cached; if (!isset($cached)) { $class = new ReflectionClass(get_called_class()); $cached = $class->newInstanceArgs($ctor); } return $cached; }
[ "private", "static", "function", "modelInstance", "(", "array", "$", "ctor", "=", "[", "]", ")", "{", "static", "$", "cached", ";", "if", "(", "!", "isset", "(", "$", "cached", ")", ")", "{", "$", "class", "=", "new", "ReflectionClass", "(", "get_called_class", "(", ")", ")", ";", "$", "cached", "=", "$", "class", "->", "newInstanceArgs", "(", "$", "ctor", ")", ";", "}", "return", "$", "cached", ";", "}" ]
Internal helper to retrieve a cached, anonymous instance of the actual model to work on. Needed to ensure dependencies are properly injected etc. @param array $ctor Optional constructor arguments. @return object An instance of the Model being queried.
[ "Internal", "helper", "to", "retrieve", "a", "cached", "anonymous", "instance", "of", "the", "actual", "model", "to", "work", "on", ".", "Needed", "to", "ensure", "dependencies", "are", "properly", "injected", "etc", "." ]
d7d070ad11f5731be141cf55c2756accaaf51402
https://github.com/monomelodies/ornament/blob/d7d070ad11f5731be141cf55c2756accaaf51402/src/Query.php#L75-L83
238,456
mahmoud-birdsol/cors-laravel
src/CORSHelper.php
CORSHelper.handle
public function handle() { if(env('APP_ENV') == 'testing'){ return; } $this->origins(); $this->credentials(); $this->methods(); $this->headers(); }
php
public function handle() { if(env('APP_ENV') == 'testing'){ return; } $this->origins(); $this->credentials(); $this->methods(); $this->headers(); }
[ "public", "function", "handle", "(", ")", "{", "if", "(", "env", "(", "'APP_ENV'", ")", "==", "'testing'", ")", "{", "return", ";", "}", "$", "this", "->", "origins", "(", ")", ";", "$", "this", "->", "credentials", "(", ")", ";", "$", "this", "->", "methods", "(", ")", ";", "$", "this", "->", "headers", "(", ")", ";", "}" ]
Handle a cors request.
[ "Handle", "a", "cors", "request", "." ]
7e7da4286628010092b4ad418bda675d83c18d4a
https://github.com/mahmoud-birdsol/cors-laravel/blob/7e7da4286628010092b4ad418bda675d83c18d4a/src/CORSHelper.php#L20-L31
238,457
mahmoud-birdsol/cors-laravel
src/CORSHelper.php
CORSHelper.origins
private function origins() { if(array_has($_SERVER, 'HTTP_ORIGIN')){ foreach (config('cors.origins') as $origin) { if ($_SERVER['HTTP_ORIGIN'] == $origin) { header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); break; } } if(config('cors.origins') == ['*']){ header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); } } if(!array_has($_SERVER, 'HTTP_ORIGIN') && env('APP_ENV') != 'local' && config('cors.local') != 'true' && config('cors.internal') == false){ abort(403); } }
php
private function origins() { if(array_has($_SERVER, 'HTTP_ORIGIN')){ foreach (config('cors.origins') as $origin) { if ($_SERVER['HTTP_ORIGIN'] == $origin) { header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); break; } } if(config('cors.origins') == ['*']){ header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']); } } if(!array_has($_SERVER, 'HTTP_ORIGIN') && env('APP_ENV') != 'local' && config('cors.local') != 'true' && config('cors.internal') == false){ abort(403); } }
[ "private", "function", "origins", "(", ")", "{", "if", "(", "array_has", "(", "$", "_SERVER", ",", "'HTTP_ORIGIN'", ")", ")", "{", "foreach", "(", "config", "(", "'cors.origins'", ")", "as", "$", "origin", ")", "{", "if", "(", "$", "_SERVER", "[", "'HTTP_ORIGIN'", "]", "==", "$", "origin", ")", "{", "header", "(", "'Access-Control-Allow-Origin: '", ".", "$", "_SERVER", "[", "'HTTP_ORIGIN'", "]", ")", ";", "break", ";", "}", "}", "if", "(", "config", "(", "'cors.origins'", ")", "==", "[", "'*'", "]", ")", "{", "header", "(", "'Access-Control-Allow-Origin: '", ".", "$", "_SERVER", "[", "'HTTP_ORIGIN'", "]", ")", ";", "}", "}", "if", "(", "!", "array_has", "(", "$", "_SERVER", ",", "'HTTP_ORIGIN'", ")", "&&", "env", "(", "'APP_ENV'", ")", "!=", "'local'", "&&", "config", "(", "'cors.local'", ")", "!=", "'true'", "&&", "config", "(", "'cors.internal'", ")", "==", "false", ")", "{", "abort", "(", "403", ")", ";", "}", "}" ]
Set access control origins.
[ "Set", "access", "control", "origins", "." ]
7e7da4286628010092b4ad418bda675d83c18d4a
https://github.com/mahmoud-birdsol/cors-laravel/blob/7e7da4286628010092b4ad418bda675d83c18d4a/src/CORSHelper.php#L36-L59
238,458
mahmoud-birdsol/cors-laravel
src/CORSHelper.php
CORSHelper.methods
private function methods() { $methods = ''; foreach (config('cors.methods') as $method) { $methods = $methods . $method . ', '; } header('Access-Control-Allow-Methods: ' . $methods); }
php
private function methods() { $methods = ''; foreach (config('cors.methods') as $method) { $methods = $methods . $method . ', '; } header('Access-Control-Allow-Methods: ' . $methods); }
[ "private", "function", "methods", "(", ")", "{", "$", "methods", "=", "''", ";", "foreach", "(", "config", "(", "'cors.methods'", ")", "as", "$", "method", ")", "{", "$", "methods", "=", "$", "methods", ".", "$", "method", ".", "', '", ";", "}", "header", "(", "'Access-Control-Allow-Methods: '", ".", "$", "methods", ")", ";", "}" ]
set access control methods
[ "set", "access", "control", "methods" ]
7e7da4286628010092b4ad418bda675d83c18d4a
https://github.com/mahmoud-birdsol/cors-laravel/blob/7e7da4286628010092b4ad418bda675d83c18d4a/src/CORSHelper.php#L72-L79
238,459
mahmoud-birdsol/cors-laravel
src/CORSHelper.php
CORSHelper.headers
private function headers() { $headers = ''; foreach (config('cors.headers') as $header) { $headers = $headers . $header . ', '; } header('Access-Control-Allow-Headers: ' . $headers); }
php
private function headers() { $headers = ''; foreach (config('cors.headers') as $header) { $headers = $headers . $header . ', '; } header('Access-Control-Allow-Headers: ' . $headers); }
[ "private", "function", "headers", "(", ")", "{", "$", "headers", "=", "''", ";", "foreach", "(", "config", "(", "'cors.headers'", ")", "as", "$", "header", ")", "{", "$", "headers", "=", "$", "headers", ".", "$", "header", ".", "', '", ";", "}", "header", "(", "'Access-Control-Allow-Headers: '", ".", "$", "headers", ")", ";", "}" ]
Set access control headers.
[ "Set", "access", "control", "headers", "." ]
7e7da4286628010092b4ad418bda675d83c18d4a
https://github.com/mahmoud-birdsol/cors-laravel/blob/7e7da4286628010092b4ad418bda675d83c18d4a/src/CORSHelper.php#L84-L91
238,460
ThrusterIO/http-message
src/FnStream.php
FnStream.decorate
public static function decorate(StreamInterface $stream, array $methods) { // If any of the required methods were not provided, then simply // proxy to the decorated stream. foreach (array_diff(static::SLOTS, array_keys($methods)) as $diff) { $methods[$diff] = [$stream, $diff]; } return new self($methods); }
php
public static function decorate(StreamInterface $stream, array $methods) { // If any of the required methods were not provided, then simply // proxy to the decorated stream. foreach (array_diff(static::SLOTS, array_keys($methods)) as $diff) { $methods[$diff] = [$stream, $diff]; } return new self($methods); }
[ "public", "static", "function", "decorate", "(", "StreamInterface", "$", "stream", ",", "array", "$", "methods", ")", "{", "// If any of the required methods were not provided, then simply", "// proxy to the decorated stream.", "foreach", "(", "array_diff", "(", "static", "::", "SLOTS", ",", "array_keys", "(", "$", "methods", ")", ")", "as", "$", "diff", ")", "{", "$", "methods", "[", "$", "diff", "]", "=", "[", "$", "stream", ",", "$", "diff", "]", ";", "}", "return", "new", "self", "(", "$", "methods", ")", ";", "}" ]
Adds custom functionality to an underlying stream by intercepting specific method calls. @param StreamInterface $stream Stream to decorate @param array $methods Hash of method name to a closure @return FnStream
[ "Adds", "custom", "functionality", "to", "an", "underlying", "stream", "by", "intercepting", "specific", "method", "calls", "." ]
4e01e94fc38a871aa519caba9c21e912858d7dad
https://github.com/ThrusterIO/http-message/blob/4e01e94fc38a871aa519caba9c21e912858d7dad/src/FnStream.php#L66-L75
238,461
vaccuum/router
source/Traits/TRouterConfiguration.php
TRouterConfiguration.configure
protected function configure(IConfig $config) { $configuration = $config->get('routes'); foreach ($configuration as $route) { $this->map($route); } }
php
protected function configure(IConfig $config) { $configuration = $config->get('routes'); foreach ($configuration as $route) { $this->map($route); } }
[ "protected", "function", "configure", "(", "IConfig", "$", "config", ")", "{", "$", "configuration", "=", "$", "config", "->", "get", "(", "'routes'", ")", ";", "foreach", "(", "$", "configuration", "as", "$", "route", ")", "{", "$", "this", "->", "map", "(", "$", "route", ")", ";", "}", "}" ]
Create routes from config. @param IConfig $config @throws RouterException @return void
[ "Create", "routes", "from", "config", "." ]
7e59eacb1de9c6b2affdf00f3e5b4b2b3333a9a9
https://github.com/vaccuum/router/blob/7e59eacb1de9c6b2affdf00f3e5b4b2b3333a9a9/source/Traits/TRouterConfiguration.php#L16-L24
238,462
noordawod/php-util
src/Arr.php
Arr.flattenAssoc
public static function flattenAssoc( array $kvArray, /*string*/ $kField, /*string|boolean*/ $vField ) { $array = []; if(!empty($kvArray) && self::isAssoc($kvArray)) { foreach($kvArray as $k => $v) { $row = []; if(is_string($vField)) { $row[$vField] = $v; } else if(true === $vField && self::isAssoc($v)) { // Merge associative array values into row. $row = array_merge($row, $v); } $row[$kField] = $k; $array[] = $row; } } return $array; }
php
public static function flattenAssoc( array $kvArray, /*string*/ $kField, /*string|boolean*/ $vField ) { $array = []; if(!empty($kvArray) && self::isAssoc($kvArray)) { foreach($kvArray as $k => $v) { $row = []; if(is_string($vField)) { $row[$vField] = $v; } else if(true === $vField && self::isAssoc($v)) { // Merge associative array values into row. $row = array_merge($row, $v); } $row[$kField] = $k; $array[] = $row; } } return $array; }
[ "public", "static", "function", "flattenAssoc", "(", "array", "$", "kvArray", ",", "/*string*/", "$", "kField", ",", "/*string|boolean*/", "$", "vField", ")", "{", "$", "array", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "kvArray", ")", "&&", "self", "::", "isAssoc", "(", "$", "kvArray", ")", ")", "{", "foreach", "(", "$", "kvArray", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "row", "=", "[", "]", ";", "if", "(", "is_string", "(", "$", "vField", ")", ")", "{", "$", "row", "[", "$", "vField", "]", "=", "$", "v", ";", "}", "else", "if", "(", "true", "===", "$", "vField", "&&", "self", "::", "isAssoc", "(", "$", "v", ")", ")", "{", "// Merge associative array values into row.", "$", "row", "=", "array_merge", "(", "$", "row", ",", "$", "v", ")", ";", "}", "$", "row", "[", "$", "kField", "]", "=", "$", "k", ";", "$", "array", "[", "]", "=", "$", "row", ";", "}", "}", "return", "$", "array", ";", "}" ]
Returns a flattened array for the specified associative array. Keys and values are hosted in a new array, and then inserted as regular rows to be returned as the result. @param array $kvArray associative array to flatten @param string $kField field name for keys @param string $vField field name for values, or TRUE to flatten the value when it's an associative array @return array flattened array (could be empty if original array is empty)
[ "Returns", "a", "flattened", "array", "for", "the", "specified", "associative", "array", ".", "Keys", "and", "values", "are", "hosted", "in", "a", "new", "array", "and", "then", "inserted", "as", "regular", "rows", "to", "be", "returned", "as", "the", "result", "." ]
6458690cc2c8457914a2aa74b131451d4a8e5797
https://github.com/noordawod/php-util/blob/6458690cc2c8457914a2aa74b131451d4a8e5797/src/Arr.php#L76-L96
238,463
edunola13/enolaphp-framework
src/Support/Performance.php
Performance.elapsed
public function elapsed(){ if(isset($this->timeBegin) && isset($this->timeEnd)){ return number_format($this->timeEnd - $this->timeBegin, 5); } else{ if(! isset($this->timeBegin)){ echo "It is necesary execute the method 'start' first"; } else{ echo "It is necesary execute the method 'terminate' before"; } } }
php
public function elapsed(){ if(isset($this->timeBegin) && isset($this->timeEnd)){ return number_format($this->timeEnd - $this->timeBegin, 5); } else{ if(! isset($this->timeBegin)){ echo "It is necesary execute the method 'start' first"; } else{ echo "It is necesary execute the method 'terminate' before"; } } }
[ "public", "function", "elapsed", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "timeBegin", ")", "&&", "isset", "(", "$", "this", "->", "timeEnd", ")", ")", "{", "return", "number_format", "(", "$", "this", "->", "timeEnd", "-", "$", "this", "->", "timeBegin", ",", "5", ")", ";", "}", "else", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "timeBegin", ")", ")", "{", "echo", "\"It is necesary execute the method 'start' first\"", ";", "}", "else", "{", "echo", "\"It is necesary execute the method 'terminate' before\"", ";", "}", "}", "}" ]
Calcula el tiempo consumido entre el inicio y fin del calculo @return float o NULL
[ "Calcula", "el", "tiempo", "consumido", "entre", "el", "inicio", "y", "fin", "del", "calculo" ]
a962bfcd53d7bc129d8c9946aaa71d264285229d
https://github.com/edunola13/enolaphp-framework/blob/a962bfcd53d7bc129d8c9946aaa71d264285229d/src/Support/Performance.php#L47-L59
238,464
adrenth/tvrage
lib/Adrenth/Tvrage/DetailedShow.php
DetailedShow.setAkas
public function setAkas(array $akas) { $this->akas = []; foreach ($akas as $aka) { $this->addAka($aka); } return $this; }
php
public function setAkas(array $akas) { $this->akas = []; foreach ($akas as $aka) { $this->addAka($aka); } return $this; }
[ "public", "function", "setAkas", "(", "array", "$", "akas", ")", "{", "$", "this", "->", "akas", "=", "[", "]", ";", "foreach", "(", "$", "akas", "as", "$", "aka", ")", "{", "$", "this", "->", "addAka", "(", "$", "aka", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set A.K.A's @param array $akas @return $this
[ "Set", "A", ".", "K", ".", "A", "s" ]
291043219e95689f609323f476a25293a53453b0
https://github.com/adrenth/tvrage/blob/291043219e95689f609323f476a25293a53453b0/lib/Adrenth/Tvrage/DetailedShow.php#L183-L192
238,465
fiedsch/datamanagement
src/Fiedsch/Data/Augmentation/Augmentor.php
Augmentor.augment
public function augment($data) { // initialize $this[self::KEY_AUGMENTED] = []; // get rules $rulekeys = array_filter($this->keys(), function($key) { return strpos($key, self::PREFIX_RULE) === 0; }); // apply rules foreach ($rulekeys as $rulename) { $augmentation_step = $this[$rulename]($this, $data); if (!is_array($augmentation_step)) { throw new \RuntimeException("augmentaion rule '$rulename' did not produce data. Make sure to return the array of augmented data."); } // make the augmented data so far available to the next rule $this[self::KEY_AUGMENTED] = array_merge($this[self::KEY_AUGMENTED], $augmentation_step); } $this->checkAugmented(); if ($this->hasColumnOrderSpecification()) { $result = []; foreach ($this[self::KEY_COLOUMN_ORDER] as $key) { $result[$key] = $this[self::KEY_AUGMENTED][$key]; } return $result; } else { return $this[self::KEY_AUGMENTED]; } }
php
public function augment($data) { // initialize $this[self::KEY_AUGMENTED] = []; // get rules $rulekeys = array_filter($this->keys(), function($key) { return strpos($key, self::PREFIX_RULE) === 0; }); // apply rules foreach ($rulekeys as $rulename) { $augmentation_step = $this[$rulename]($this, $data); if (!is_array($augmentation_step)) { throw new \RuntimeException("augmentaion rule '$rulename' did not produce data. Make sure to return the array of augmented data."); } // make the augmented data so far available to the next rule $this[self::KEY_AUGMENTED] = array_merge($this[self::KEY_AUGMENTED], $augmentation_step); } $this->checkAugmented(); if ($this->hasColumnOrderSpecification()) { $result = []; foreach ($this[self::KEY_COLOUMN_ORDER] as $key) { $result[$key] = $this[self::KEY_AUGMENTED][$key]; } return $result; } else { return $this[self::KEY_AUGMENTED]; } }
[ "public", "function", "augment", "(", "$", "data", ")", "{", "// initialize", "$", "this", "[", "self", "::", "KEY_AUGMENTED", "]", "=", "[", "]", ";", "// get rules", "$", "rulekeys", "=", "array_filter", "(", "$", "this", "->", "keys", "(", ")", ",", "function", "(", "$", "key", ")", "{", "return", "strpos", "(", "$", "key", ",", "self", "::", "PREFIX_RULE", ")", "===", "0", ";", "}", ")", ";", "// apply rules", "foreach", "(", "$", "rulekeys", "as", "$", "rulename", ")", "{", "$", "augmentation_step", "=", "$", "this", "[", "$", "rulename", "]", "(", "$", "this", ",", "$", "data", ")", ";", "if", "(", "!", "is_array", "(", "$", "augmentation_step", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"augmentaion rule '$rulename' did not produce data. Make sure to return the array of augmented data.\"", ")", ";", "}", "// make the augmented data so far available to the next rule", "$", "this", "[", "self", "::", "KEY_AUGMENTED", "]", "=", "array_merge", "(", "$", "this", "[", "self", "::", "KEY_AUGMENTED", "]", ",", "$", "augmentation_step", ")", ";", "}", "$", "this", "->", "checkAugmented", "(", ")", ";", "if", "(", "$", "this", "->", "hasColumnOrderSpecification", "(", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "[", "self", "::", "KEY_COLOUMN_ORDER", "]", "as", "$", "key", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "this", "[", "self", "::", "KEY_AUGMENTED", "]", "[", "$", "key", "]", ";", "}", "return", "$", "result", ";", "}", "else", "{", "return", "$", "this", "[", "self", "::", "KEY_AUGMENTED", "]", ";", "}", "}" ]
Augment data according to the rules and return the result. @param array $data contains the data of the current row. @return array the original data (left unchanged) and the augmented data.
[ "Augment", "data", "according", "to", "the", "rules", "and", "return", "the", "result", "." ]
06e8000399d46e83f848944b73afecabf619f52b
https://github.com/fiedsch/datamanagement/blob/06e8000399d46e83f848944b73afecabf619f52b/src/Fiedsch/Data/Augmentation/Augmentor.php#L56-L84
238,466
fiedsch/datamanagement
src/Fiedsch/Data/Augmentation/Augmentor.php
Augmentor.getAugmentedSoFar
public function getAugmentedSoFar() { if (!$this->offsetExists(self::KEY_AUGMENTED)) { $this[self::KEY_AUGMENTED] = []; } return $this[self::KEY_AUGMENTED]; }
php
public function getAugmentedSoFar() { if (!$this->offsetExists(self::KEY_AUGMENTED)) { $this[self::KEY_AUGMENTED] = []; } return $this[self::KEY_AUGMENTED]; }
[ "public", "function", "getAugmentedSoFar", "(", ")", "{", "if", "(", "!", "$", "this", "->", "offsetExists", "(", "self", "::", "KEY_AUGMENTED", ")", ")", "{", "$", "this", "[", "self", "::", "KEY_AUGMENTED", "]", "=", "[", "]", ";", "}", "return", "$", "this", "[", "self", "::", "KEY_AUGMENTED", "]", ";", "}" ]
Access the data that has been augmented so far in the previous augmentation steps. @return array the augmented data so far (or an empty array, should this be called in the first augmentation step).
[ "Access", "the", "data", "that", "has", "been", "augmented", "so", "far", "in", "the", "previous", "augmentation", "steps", "." ]
06e8000399d46e83f848944b73afecabf619f52b
https://github.com/fiedsch/datamanagement/blob/06e8000399d46e83f848944b73afecabf619f52b/src/Fiedsch/Data/Augmentation/Augmentor.php#L195-L201
238,467
fiedsch/datamanagement
src/Fiedsch/Data/Augmentation/Augmentor.php
Augmentor.addRule
public function addRule($name, callable $rule) { if (isset($this[self::rule($name)])) { throw new \RuntimeException("rule '$name' already exists'"); } $this[self::rule($name)] = $this->protect($rule); }
php
public function addRule($name, callable $rule) { if (isset($this[self::rule($name)])) { throw new \RuntimeException("rule '$name' already exists'"); } $this[self::rule($name)] = $this->protect($rule); }
[ "public", "function", "addRule", "(", "$", "name", ",", "callable", "$", "rule", ")", "{", "if", "(", "isset", "(", "$", "this", "[", "self", "::", "rule", "(", "$", "name", ")", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"rule '$name' already exists'\"", ")", ";", "}", "$", "this", "[", "self", "::", "rule", "(", "$", "name", ")", "]", "=", "$", "this", "->", "protect", "(", "$", "rule", ")", ";", "}" ]
Add an augmentation rule. @param string $name the name of the augmentation rule @param callable $rule the code that will be executed @throws \RuntimeException
[ "Add", "an", "augmentation", "rule", "." ]
06e8000399d46e83f848944b73afecabf619f52b
https://github.com/fiedsch/datamanagement/blob/06e8000399d46e83f848944b73afecabf619f52b/src/Fiedsch/Data/Augmentation/Augmentor.php#L210-L216
238,468
fiedsch/datamanagement
src/Fiedsch/Data/Augmentation/Augmentor.php
Augmentor.appendTo
public function appendTo($key, $value) { if (!$this->offsetExists($key)) { $this[$key] = [$value]; return; } $old_value = $this[$key]; if (!is_array($old_value)) { $old_value = [$old_value]; } if (is_array($value)) { $old_value = array_merge($old_value, $value); } else { $old_value[] = $value; } $this[$key] = $old_value; }
php
public function appendTo($key, $value) { if (!$this->offsetExists($key)) { $this[$key] = [$value]; return; } $old_value = $this[$key]; if (!is_array($old_value)) { $old_value = [$old_value]; } if (is_array($value)) { $old_value = array_merge($old_value, $value); } else { $old_value[] = $value; } $this[$key] = $old_value; }
[ "public", "function", "appendTo", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "!", "$", "this", "->", "offsetExists", "(", "$", "key", ")", ")", "{", "$", "this", "[", "$", "key", "]", "=", "[", "$", "value", "]", ";", "return", ";", "}", "$", "old_value", "=", "$", "this", "[", "$", "key", "]", ";", "if", "(", "!", "is_array", "(", "$", "old_value", ")", ")", "{", "$", "old_value", "=", "[", "$", "old_value", "]", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "old_value", "=", "array_merge", "(", "$", "old_value", ",", "$", "value", ")", ";", "}", "else", "{", "$", "old_value", "[", "]", "=", "$", "value", ";", "}", "$", "this", "[", "$", "key", "]", "=", "$", "old_value", ";", "}" ]
Append to an already stored array. @param string $key the key under which we have previously stored data. @param mixed $value the value which we want to append to the existing data. Note, that the following will not work: <code> $container['foo'] = array('bar','baz'); $container['foo'][] = 42; </code> See also: https://github.com/silexphp/Pimple/issues/149 <quote> fabpot commented on Jul 15, 2014 To be more precise, Pimple stores parameters but it should have no knowledge of the parameter value; Pimple just stores what you give it. </quote>
[ "Append", "to", "an", "already", "stored", "array", "." ]
06e8000399d46e83f848944b73afecabf619f52b
https://github.com/fiedsch/datamanagement/blob/06e8000399d46e83f848944b73afecabf619f52b/src/Fiedsch/Data/Augmentation/Augmentor.php#L250-L266
238,469
phlexible/phlexible
src/Phlexible/Component/MediaCache/Worker/WorkerLogger.php
WorkerLogger.applyError
protected function applyError( CacheItem $cacheItem, $status, $message, $inputFilename, $templateType, $templateKey, $logSeverity = 'error' ) { $cacheItem ->setCacheStatus($status) ->setError($message); $logger = $this->getLogger(); if ($logger && method_exists($logger, $logSeverity)) { $logger->$logSeverity($message, array( 'worker' => get_class($this), 'templateType' => $templateType, 'templateKey' => $templateKey, 'fileId' => $cacheItem->getFileId(), 'fileVersion' => $cacheItem->getFileVersion(), 'fileMimeType' => $cacheItem->getMimeType(), 'fileMediaType' => $cacheItem->getMediaType(), 'inputFile' => $inputFilename, )); } }
php
protected function applyError( CacheItem $cacheItem, $status, $message, $inputFilename, $templateType, $templateKey, $logSeverity = 'error' ) { $cacheItem ->setCacheStatus($status) ->setError($message); $logger = $this->getLogger(); if ($logger && method_exists($logger, $logSeverity)) { $logger->$logSeverity($message, array( 'worker' => get_class($this), 'templateType' => $templateType, 'templateKey' => $templateKey, 'fileId' => $cacheItem->getFileId(), 'fileVersion' => $cacheItem->getFileVersion(), 'fileMimeType' => $cacheItem->getMimeType(), 'fileMediaType' => $cacheItem->getMediaType(), 'inputFile' => $inputFilename, )); } }
[ "protected", "function", "applyError", "(", "CacheItem", "$", "cacheItem", ",", "$", "status", ",", "$", "message", ",", "$", "inputFilename", ",", "$", "templateType", ",", "$", "templateKey", ",", "$", "logSeverity", "=", "'error'", ")", "{", "$", "cacheItem", "->", "setCacheStatus", "(", "$", "status", ")", "->", "setError", "(", "$", "message", ")", ";", "$", "logger", "=", "$", "this", "->", "getLogger", "(", ")", ";", "if", "(", "$", "logger", "&&", "method_exists", "(", "$", "logger", ",", "$", "logSeverity", ")", ")", "{", "$", "logger", "->", "$", "logSeverity", "(", "$", "message", ",", "array", "(", "'worker'", "=>", "get_class", "(", "$", "this", ")", ",", "'templateType'", "=>", "$", "templateType", ",", "'templateKey'", "=>", "$", "templateKey", ",", "'fileId'", "=>", "$", "cacheItem", "->", "getFileId", "(", ")", ",", "'fileVersion'", "=>", "$", "cacheItem", "->", "getFileVersion", "(", ")", ",", "'fileMimeType'", "=>", "$", "cacheItem", "->", "getMimeType", "(", ")", ",", "'fileMediaType'", "=>", "$", "cacheItem", "->", "getMediaType", "(", ")", ",", "'inputFile'", "=>", "$", "inputFilename", ",", ")", ")", ";", "}", "}" ]
Apply error to cache item. @param CacheItem $cacheItem @param string $status @param string $message @param string $inputFilename @param string $templateType @param string $templateKey @param string $logSeverity
[ "Apply", "error", "to", "cache", "item", "." ]
132f24924c9bb0dbb6c1ea84db0a463f97fa3893
https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Component/MediaCache/Worker/WorkerLogger.php#L40-L66
238,470
hamjoint/mustard-commerce
src/lib/PostalAddress.php
PostalAddress.toString
public function toString() { return implode(', ', array_filter([ $this->name, $this->street1, $this->street2, $this->city, $this->county, $this->postcode, $this->country($this->country)->name, ])); }
php
public function toString() { return implode(', ', array_filter([ $this->name, $this->street1, $this->street2, $this->city, $this->county, $this->postcode, $this->country($this->country)->name, ])); }
[ "public", "function", "toString", "(", ")", "{", "return", "implode", "(", "', '", ",", "array_filter", "(", "[", "$", "this", "->", "name", ",", "$", "this", "->", "street1", ",", "$", "this", "->", "street2", ",", "$", "this", "->", "city", ",", "$", "this", "->", "county", ",", "$", "this", "->", "postcode", ",", "$", "this", "->", "country", "(", "$", "this", "->", "country", ")", "->", "name", ",", "]", ")", ")", ";", "}" ]
Return address as a comma-separated string. @return string
[ "Return", "address", "as", "a", "comma", "-", "separated", "string", "." ]
886caeb5a88d827c8e9201e90020b64651dd87ad
https://github.com/hamjoint/mustard-commerce/blob/886caeb5a88d827c8e9201e90020b64651dd87ad/src/lib/PostalAddress.php#L58-L69
238,471
tarsana/filesystem
src/AbstractFile.php
AbstractFile.name
public function name($value = false, $overwrite = false) { if ($value === false) { return $this->adapter->basename($this->path); } if (! is_string($value) || strlen($value) == 0) { throw new FilesystemException('Invalid name given to name() method'); } $newPath = substr($this->path, 0, strrpos($this->path, DIRECTORY_SEPARATOR) + 1); $newPath .= $value; return $this->path($newPath, $overwrite); }
php
public function name($value = false, $overwrite = false) { if ($value === false) { return $this->adapter->basename($this->path); } if (! is_string($value) || strlen($value) == 0) { throw new FilesystemException('Invalid name given to name() method'); } $newPath = substr($this->path, 0, strrpos($this->path, DIRECTORY_SEPARATOR) + 1); $newPath .= $value; return $this->path($newPath, $overwrite); }
[ "public", "function", "name", "(", "$", "value", "=", "false", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "$", "value", "===", "false", ")", "{", "return", "$", "this", "->", "adapter", "->", "basename", "(", "$", "this", "->", "path", ")", ";", "}", "if", "(", "!", "is_string", "(", "$", "value", ")", "||", "strlen", "(", "$", "value", ")", "==", "0", ")", "{", "throw", "new", "FilesystemException", "(", "'Invalid name given to name() method'", ")", ";", "}", "$", "newPath", "=", "substr", "(", "$", "this", "->", "path", ",", "0", ",", "strrpos", "(", "$", "this", "->", "path", ",", "DIRECTORY_SEPARATOR", ")", "+", "1", ")", ";", "$", "newPath", ".=", "$", "value", ";", "return", "$", "this", "->", "path", "(", "$", "newPath", ",", "$", "overwrite", ")", ";", "}" ]
Gets or sets the name of the file. @param string $value @param boolean $overwrite @return string|Tarsana\Filesystem\AbstractFile @throws Tarsana\Filesystem\Exceptions\FilesystemException if invalid name given or could not rename the file.
[ "Gets", "or", "sets", "the", "name", "of", "the", "file", "." ]
db6c8f040af38dfb01066e382645aff6c72530fa
https://github.com/tarsana/filesystem/blob/db6c8f040af38dfb01066e382645aff6c72530fa/src/AbstractFile.php#L84-L98
238,472
tarsana/filesystem
src/AbstractFile.php
AbstractFile.path
public function path($value = false, $overwrite = false) { if ($value === false) { return $this->path; } $oldPath = $this->path; if (!$overwrite && $this->adapter->fileExists($value)) { throw new FilesystemException("Cannot rename the file '{$this->path}' to '{$value}' because a file already exists"); } (new static($value, $this->adapter))->remove(); if (! $this->adapter->rename($this->path, $value)) { throw new FilesystemException("Cannot rename the file '{$this->path}' to '{$value}'"); } $this->path = $value; $this->fs = null; $this->pathChanged($oldPath); return $this; }
php
public function path($value = false, $overwrite = false) { if ($value === false) { return $this->path; } $oldPath = $this->path; if (!$overwrite && $this->adapter->fileExists($value)) { throw new FilesystemException("Cannot rename the file '{$this->path}' to '{$value}' because a file already exists"); } (new static($value, $this->adapter))->remove(); if (! $this->adapter->rename($this->path, $value)) { throw new FilesystemException("Cannot rename the file '{$this->path}' to '{$value}'"); } $this->path = $value; $this->fs = null; $this->pathChanged($oldPath); return $this; }
[ "public", "function", "path", "(", "$", "value", "=", "false", ",", "$", "overwrite", "=", "false", ")", "{", "if", "(", "$", "value", "===", "false", ")", "{", "return", "$", "this", "->", "path", ";", "}", "$", "oldPath", "=", "$", "this", "->", "path", ";", "if", "(", "!", "$", "overwrite", "&&", "$", "this", "->", "adapter", "->", "fileExists", "(", "$", "value", ")", ")", "{", "throw", "new", "FilesystemException", "(", "\"Cannot rename the file '{$this->path}' to '{$value}' because a file already exists\"", ")", ";", "}", "(", "new", "static", "(", "$", "value", ",", "$", "this", "->", "adapter", ")", ")", "->", "remove", "(", ")", ";", "if", "(", "!", "$", "this", "->", "adapter", "->", "rename", "(", "$", "this", "->", "path", ",", "$", "value", ")", ")", "{", "throw", "new", "FilesystemException", "(", "\"Cannot rename the file '{$this->path}' to '{$value}'\"", ")", ";", "}", "$", "this", "->", "path", "=", "$", "value", ";", "$", "this", "->", "fs", "=", "null", ";", "$", "this", "->", "pathChanged", "(", "$", "oldPath", ")", ";", "return", "$", "this", ";", "}" ]
Gets or Sets the path. @param string $value @param boolean $overwrite @return string|Tarsana\Filesystem\AbstractFile @throws Tarsana\Filesystem\Exceptions\FilesystemException if could not rename the file.
[ "Gets", "or", "Sets", "the", "path", "." ]
db6c8f040af38dfb01066e382645aff6c72530fa
https://github.com/tarsana/filesystem/blob/db6c8f040af38dfb01066e382645aff6c72530fa/src/AbstractFile.php#L109-L132
238,473
tarsana/filesystem
src/AbstractFile.php
AbstractFile.pathChanged
protected function pathChanged($oldPath) { foreach ($this->pathListeners as $cb) { $cb($oldPath, $this->path); } }
php
protected function pathChanged($oldPath) { foreach ($this->pathListeners as $cb) { $cb($oldPath, $this->path); } }
[ "protected", "function", "pathChanged", "(", "$", "oldPath", ")", "{", "foreach", "(", "$", "this", "->", "pathListeners", "as", "$", "cb", ")", "{", "$", "cb", "(", "$", "oldPath", ",", "$", "this", "->", "path", ")", ";", "}", "}" ]
Notifies the path listeners and passes the old and the new path as parameters to each callback. @return void
[ "Notifies", "the", "path", "listeners", "and", "passes", "the", "old", "and", "the", "new", "path", "as", "parameters", "to", "each", "callback", "." ]
db6c8f040af38dfb01066e382645aff6c72530fa
https://github.com/tarsana/filesystem/blob/db6c8f040af38dfb01066e382645aff6c72530fa/src/AbstractFile.php#L140-L145
238,474
tarsana/filesystem
src/AbstractFile.php
AbstractFile.perms
public function perms($value = false) { if ($value === false) { return substr(sprintf('%o', $this->adapter->fileperms($this->path)), -4); } if (! $this->adapter->chmod($this->path, $value)) { throw new FilesystemException("Unable to apply permissions to '{$this->path}'"); } $this->clearStat(); return $this; }
php
public function perms($value = false) { if ($value === false) { return substr(sprintf('%o', $this->adapter->fileperms($this->path)), -4); } if (! $this->adapter->chmod($this->path, $value)) { throw new FilesystemException("Unable to apply permissions to '{$this->path}'"); } $this->clearStat(); return $this; }
[ "public", "function", "perms", "(", "$", "value", "=", "false", ")", "{", "if", "(", "$", "value", "===", "false", ")", "{", "return", "substr", "(", "sprintf", "(", "'%o'", ",", "$", "this", "->", "adapter", "->", "fileperms", "(", "$", "this", "->", "path", ")", ")", ",", "-", "4", ")", ";", "}", "if", "(", "!", "$", "this", "->", "adapter", "->", "chmod", "(", "$", "this", "->", "path", ",", "$", "value", ")", ")", "{", "throw", "new", "FilesystemException", "(", "\"Unable to apply permissions to '{$this->path}'\"", ")", ";", "}", "$", "this", "->", "clearStat", "(", ")", ";", "return", "$", "this", ";", "}" ]
Gets or Sets the file permissions. @param int $value @return string|Tarsana\Filesystem\AbstractFile @throws Tarsana\Filesystem\Exceptions\FilesystemException if could not apply permissions to file.
[ "Gets", "or", "Sets", "the", "file", "permissions", "." ]
db6c8f040af38dfb01066e382645aff6c72530fa
https://github.com/tarsana/filesystem/blob/db6c8f040af38dfb01066e382645aff6c72530fa/src/AbstractFile.php#L183-L196
238,475
tarsana/filesystem
src/AbstractFile.php
AbstractFile.fs
public function fs() { if (null === $this->fs) $this->fs = new Filesystem($this->getFilesystemPath(), $this->adapter); return $this->fs; }
php
public function fs() { if (null === $this->fs) $this->fs = new Filesystem($this->getFilesystemPath(), $this->adapter); return $this->fs; }
[ "public", "function", "fs", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "fs", ")", "$", "this", "->", "fs", "=", "new", "Filesystem", "(", "$", "this", "->", "getFilesystemPath", "(", ")", ",", "$", "this", "->", "adapter", ")", ";", "return", "$", "this", "->", "fs", ";", "}" ]
Gets the filesystem coresponding to the file. @return Tarsana\Filesystem
[ "Gets", "the", "filesystem", "coresponding", "to", "the", "file", "." ]
db6c8f040af38dfb01066e382645aff6c72530fa
https://github.com/tarsana/filesystem/blob/db6c8f040af38dfb01066e382645aff6c72530fa/src/AbstractFile.php#L203-L208
238,476
tokenly/xchain-client
src/WebHookReceiver.php
WebHookReceiver.validateAndParseWebhookNotificationFromCurrentRequest
public function validateAndParseWebhookNotificationFromCurrentRequest() { // read the JSON input $json_string = file_get_contents('php://input'); $json_data = json_decode($json_string, true); // make sure the message is signed properly // throws an exception if invalid $this->validateWebhookNotification($json_data); // return the payload return $this->parseWebhookNotificationData($json_data); }
php
public function validateAndParseWebhookNotificationFromCurrentRequest() { // read the JSON input $json_string = file_get_contents('php://input'); $json_data = json_decode($json_string, true); // make sure the message is signed properly // throws an exception if invalid $this->validateWebhookNotification($json_data); // return the payload return $this->parseWebhookNotificationData($json_data); }
[ "public", "function", "validateAndParseWebhookNotificationFromCurrentRequest", "(", ")", "{", "// read the JSON input", "$", "json_string", "=", "file_get_contents", "(", "'php://input'", ")", ";", "$", "json_data", "=", "json_decode", "(", "$", "json_string", ",", "true", ")", ";", "// make sure the message is signed properly", "// throws an exception if invalid", "$", "this", "->", "validateWebhookNotification", "(", "$", "json_data", ")", ";", "// return the payload", "return", "$", "this", "->", "parseWebhookNotificationData", "(", "$", "json_data", ")", ";", "}" ]
Reads the input from the current web request and returns the notification Throws an AuthorizationException if validation fails @return array notification
[ "Reads", "the", "input", "from", "the", "current", "web", "request", "and", "returns", "the", "notification", "Throws", "an", "AuthorizationException", "if", "validation", "fails" ]
088925a488f6f66e9a3385c8c023987e79004c49
https://github.com/tokenly/xchain-client/blob/088925a488f6f66e9a3385c8c023987e79004c49/src/WebHookReceiver.php#L28-L40
238,477
tokenly/xchain-client
src/WebHookReceiver.php
WebHookReceiver.validateAndParseWebhookNotificationFromRequest
public function validateAndParseWebhookNotificationFromRequest(\Symfony\Component\HttpFoundation\Request $request) { $json_data = json_decode($request->getContent(), true); if (!is_array($json_data)) { throw new AuthorizationException("Invalid webhook data received"); } // make sure the message is signed properly // throws an exception if invalid $this->validateWebhookNotification($json_data); return $this->parseWebhookNotificationData($json_data); }
php
public function validateAndParseWebhookNotificationFromRequest(\Symfony\Component\HttpFoundation\Request $request) { $json_data = json_decode($request->getContent(), true); if (!is_array($json_data)) { throw new AuthorizationException("Invalid webhook data received"); } // make sure the message is signed properly // throws an exception if invalid $this->validateWebhookNotification($json_data); return $this->parseWebhookNotificationData($json_data); }
[ "public", "function", "validateAndParseWebhookNotificationFromRequest", "(", "\\", "Symfony", "\\", "Component", "\\", "HttpFoundation", "\\", "Request", "$", "request", ")", "{", "$", "json_data", "=", "json_decode", "(", "$", "request", "->", "getContent", "(", ")", ",", "true", ")", ";", "if", "(", "!", "is_array", "(", "$", "json_data", ")", ")", "{", "throw", "new", "AuthorizationException", "(", "\"Invalid webhook data received\"", ")", ";", "}", "// make sure the message is signed properly", "// throws an exception if invalid", "$", "this", "->", "validateWebhookNotification", "(", "$", "json_data", ")", ";", "return", "$", "this", "->", "parseWebhookNotificationData", "(", "$", "json_data", ")", ";", "}" ]
Reads the input from a Symfony request and returns the notification Throws an AuthorizationException if validation fails @return array notification
[ "Reads", "the", "input", "from", "a", "Symfony", "request", "and", "returns", "the", "notification", "Throws", "an", "AuthorizationException", "if", "validation", "fails" ]
088925a488f6f66e9a3385c8c023987e79004c49
https://github.com/tokenly/xchain-client/blob/088925a488f6f66e9a3385c8c023987e79004c49/src/WebHookReceiver.php#L48-L57
238,478
tokenly/xchain-client
src/WebHookReceiver.php
WebHookReceiver.validateWebhookNotification
public function validateWebhookNotification($json_data) { // validate vars if (!strlen($json_data['apiToken'])) { throw new AuthorizationException("API token not found"); } if ($json_data['apiToken'] != $this->api_token) { throw new AuthorizationException("Invalid API token"); } if (!strlen($json_data['signature'])) { throw new AuthorizationException("signature not found"); } $notification_json_string = $json_data['payload']; if (!strlen($notification_json_string)) { throw new AuthorizationException("payload not found"); } // check signature $expected_signature = hash_hmac('sha256', $notification_json_string, $this->api_scret_key, false); $is_valid = ($expected_signature === $json_data['signature']); if (!$is_valid) { throw new AuthorizationException("Invalid signature"); } // this will always be true // otherwise an exception will be thrown by now return $is_valid; }
php
public function validateWebhookNotification($json_data) { // validate vars if (!strlen($json_data['apiToken'])) { throw new AuthorizationException("API token not found"); } if ($json_data['apiToken'] != $this->api_token) { throw new AuthorizationException("Invalid API token"); } if (!strlen($json_data['signature'])) { throw new AuthorizationException("signature not found"); } $notification_json_string = $json_data['payload']; if (!strlen($notification_json_string)) { throw new AuthorizationException("payload not found"); } // check signature $expected_signature = hash_hmac('sha256', $notification_json_string, $this->api_scret_key, false); $is_valid = ($expected_signature === $json_data['signature']); if (!$is_valid) { throw new AuthorizationException("Invalid signature"); } // this will always be true // otherwise an exception will be thrown by now return $is_valid; }
[ "public", "function", "validateWebhookNotification", "(", "$", "json_data", ")", "{", "// validate vars", "if", "(", "!", "strlen", "(", "$", "json_data", "[", "'apiToken'", "]", ")", ")", "{", "throw", "new", "AuthorizationException", "(", "\"API token not found\"", ")", ";", "}", "if", "(", "$", "json_data", "[", "'apiToken'", "]", "!=", "$", "this", "->", "api_token", ")", "{", "throw", "new", "AuthorizationException", "(", "\"Invalid API token\"", ")", ";", "}", "if", "(", "!", "strlen", "(", "$", "json_data", "[", "'signature'", "]", ")", ")", "{", "throw", "new", "AuthorizationException", "(", "\"signature not found\"", ")", ";", "}", "$", "notification_json_string", "=", "$", "json_data", "[", "'payload'", "]", ";", "if", "(", "!", "strlen", "(", "$", "notification_json_string", ")", ")", "{", "throw", "new", "AuthorizationException", "(", "\"payload not found\"", ")", ";", "}", "// check signature", "$", "expected_signature", "=", "hash_hmac", "(", "'sha256'", ",", "$", "notification_json_string", ",", "$", "this", "->", "api_scret_key", ",", "false", ")", ";", "$", "is_valid", "=", "(", "$", "expected_signature", "===", "$", "json_data", "[", "'signature'", "]", ")", ";", "if", "(", "!", "$", "is_valid", ")", "{", "throw", "new", "AuthorizationException", "(", "\"Invalid signature\"", ")", ";", "}", "// this will always be true", "// otherwise an exception will be thrown by now", "return", "$", "is_valid", ";", "}" ]
Parses and validates a notification Throws an AuthorizationException if validation fails @return boolean true if valid (always returns true)
[ "Parses", "and", "validates", "a", "notification", "Throws", "an", "AuthorizationException", "if", "validation", "fails" ]
088925a488f6f66e9a3385c8c023987e79004c49
https://github.com/tokenly/xchain-client/blob/088925a488f6f66e9a3385c8c023987e79004c49/src/WebHookReceiver.php#L64-L80
238,479
RhubarbPHP/Module.Leaf.CommonControls
src/DateTime/Time.php
Time.parseCompositeValue
protected function parseCompositeValue( $compositeValue ) { $time = false; try { $time = new RhubarbTime( $compositeValue ); } catch( \Exception $er ) { } if( $time === false ) { $this->model->hours = ""; $this->model->minutes = ""; } else { $this->model->hours = $time->format( "H" ); $this->model->minutes = $time->format( "i" ); } }
php
protected function parseCompositeValue( $compositeValue ) { $time = false; try { $time = new RhubarbTime( $compositeValue ); } catch( \Exception $er ) { } if( $time === false ) { $this->model->hours = ""; $this->model->minutes = ""; } else { $this->model->hours = $time->format( "H" ); $this->model->minutes = $time->format( "i" ); } }
[ "protected", "function", "parseCompositeValue", "(", "$", "compositeValue", ")", "{", "$", "time", "=", "false", ";", "try", "{", "$", "time", "=", "new", "RhubarbTime", "(", "$", "compositeValue", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "er", ")", "{", "}", "if", "(", "$", "time", "===", "false", ")", "{", "$", "this", "->", "model", "->", "hours", "=", "\"\"", ";", "$", "this", "->", "model", "->", "minutes", "=", "\"\"", ";", "}", "else", "{", "$", "this", "->", "model", "->", "hours", "=", "$", "time", "->", "format", "(", "\"H\"", ")", ";", "$", "this", "->", "model", "->", "minutes", "=", "$", "time", "->", "format", "(", "\"i\"", ")", ";", "}", "}" ]
The place to parse the value property and break into the sub values for sub controls to bind to @param $compositeValue
[ "The", "place", "to", "parse", "the", "value", "property", "and", "break", "into", "the", "sub", "values", "for", "sub", "controls", "to", "bind", "to" ]
fd12390c470304a436ebd78f315e29af7552cc15
https://github.com/RhubarbPHP/Module.Leaf.CommonControls/blob/fd12390c470304a436ebd78f315e29af7552cc15/src/DateTime/Time.php#L61-L83
238,480
RhubarbPHP/Module.Leaf.CommonControls
src/DateTime/Time.php
Time.createCompositeValue
protected function createCompositeValue() { $hours = (int) $this->model->hours; $minutes = (int) $this->model->minutes; $time = new RhubarbTime(); $time->setTime( $hours, $minutes ); return $time; }
php
protected function createCompositeValue() { $hours = (int) $this->model->hours; $minutes = (int) $this->model->minutes; $time = new RhubarbTime(); $time->setTime( $hours, $minutes ); return $time; }
[ "protected", "function", "createCompositeValue", "(", ")", "{", "$", "hours", "=", "(", "int", ")", "$", "this", "->", "model", "->", "hours", ";", "$", "minutes", "=", "(", "int", ")", "$", "this", "->", "model", "->", "minutes", ";", "$", "time", "=", "new", "RhubarbTime", "(", ")", ";", "$", "time", "->", "setTime", "(", "$", "hours", ",", "$", "minutes", ")", ";", "return", "$", "time", ";", "}" ]
The place to combine the model properties for sub values into a single value, array or object. @return mixed
[ "The", "place", "to", "combine", "the", "model", "properties", "for", "sub", "values", "into", "a", "single", "value", "array", "or", "object", "." ]
fd12390c470304a436ebd78f315e29af7552cc15
https://github.com/RhubarbPHP/Module.Leaf.CommonControls/blob/fd12390c470304a436ebd78f315e29af7552cc15/src/DateTime/Time.php#L90-L99
238,481
strident/Trident
src/Trident/Module/TemplatingModule/Twig/Extension/AssetExtension.php
AssetExtension.asset
public function asset($asset, $version = null) { $host = $this->request->getHost(); $port = $this->request->getPort(); $path = $this->request->getBasePath(); if ('/' !== substr($asset, 1)) { $asset = '/'.$asset; } if (80 === $port) { $port = ''; } else { $port = ':'.$port; } return '//'.$host.$port.$path.$asset; }
php
public function asset($asset, $version = null) { $host = $this->request->getHost(); $port = $this->request->getPort(); $path = $this->request->getBasePath(); if ('/' !== substr($asset, 1)) { $asset = '/'.$asset; } if (80 === $port) { $port = ''; } else { $port = ':'.$port; } return '//'.$host.$port.$path.$asset; }
[ "public", "function", "asset", "(", "$", "asset", ",", "$", "version", "=", "null", ")", "{", "$", "host", "=", "$", "this", "->", "request", "->", "getHost", "(", ")", ";", "$", "port", "=", "$", "this", "->", "request", "->", "getPort", "(", ")", ";", "$", "path", "=", "$", "this", "->", "request", "->", "getBasePath", "(", ")", ";", "if", "(", "'/'", "!==", "substr", "(", "$", "asset", ",", "1", ")", ")", "{", "$", "asset", "=", "'/'", ".", "$", "asset", ";", "}", "if", "(", "80", "===", "$", "port", ")", "{", "$", "port", "=", "''", ";", "}", "else", "{", "$", "port", "=", "':'", ".", "$", "port", ";", "}", "return", "'//'", ".", "$", "host", ".", "$", "port", ".", "$", "path", ".", "$", "asset", ";", "}" ]
Get the absolute URL of an asset. @return string
[ "Get", "the", "absolute", "URL", "of", "an", "asset", "." ]
a112f0b75601b897c470a49d85791dc386c29952
https://github.com/strident/Trident/blob/a112f0b75601b897c470a49d85791dc386c29952/src/Trident/Module/TemplatingModule/Twig/Extension/AssetExtension.php#L50-L67
238,482
kaecyra/app-common
src/Store.php
Store.set
public function set($key, $value) { setvalr(trim($key), $this->data, $value); return $value; }
php
public function set($key, $value) { setvalr(trim($key), $this->data, $value); return $value; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ")", "{", "setvalr", "(", "trim", "(", "$", "key", ")", ",", "$", "this", "->", "data", ",", "$", "value", ")", ";", "return", "$", "value", ";", "}" ]
Set a store value @param string $key @param mixed $value @return mixed
[ "Set", "a", "store", "value" ]
8dbcf70c575fb587614b45da8ec02d098e3e843b
https://github.com/kaecyra/app-common/blob/8dbcf70c575fb587614b45da8ec02d098e3e843b/src/Store.php#L94-L97
238,483
kaecyra/app-common
src/Store.php
Store.push
public function push($key, $data) { $key = trim($key); if (!array_key_exists($key, $this->data) || !is_array($this->data[$key])) { $this->data[$key] = []; } array_push($this->data[$key], $data); }
php
public function push($key, $data) { $key = trim($key); if (!array_key_exists($key, $this->data) || !is_array($this->data[$key])) { $this->data[$key] = []; } array_push($this->data[$key], $data); }
[ "public", "function", "push", "(", "$", "key", ",", "$", "data", ")", "{", "$", "key", "=", "trim", "(", "$", "key", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "data", ")", "||", "!", "is_array", "(", "$", "this", "->", "data", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "data", "[", "$", "key", "]", "=", "[", "]", ";", "}", "array_push", "(", "$", "this", "->", "data", "[", "$", "key", "]", ",", "$", "data", ")", ";", "}" ]
Push data onto key @param string $key @param array $data
[ "Push", "data", "onto", "key" ]
8dbcf70c575fb587614b45da8ec02d098e3e843b
https://github.com/kaecyra/app-common/blob/8dbcf70c575fb587614b45da8ec02d098e3e843b/src/Store.php#L157-L163
238,484
asika32764/joomla-framework-console
Command/AbstractCommand.php
AbstractCommand.addArgument
public function addArgument($argument, $description = null, $options = array(), \Closure $code = null) { return $this->addCommand($argument, $description, $options, $code); }
php
public function addArgument($argument, $description = null, $options = array(), \Closure $code = null) { return $this->addCommand($argument, $description, $options, $code); }
[ "public", "function", "addArgument", "(", "$", "argument", ",", "$", "description", "=", "null", ",", "$", "options", "=", "array", "(", ")", ",", "\\", "Closure", "$", "code", "=", "null", ")", "{", "return", "$", "this", "->", "addCommand", "(", "$", "argument", ",", "$", "description", ",", "$", "options", ",", "$", "code", ")", ";", "}" ]
Alias of addCommand for legacy. @param string|AbstractCommand $argument The argument name or Console object. If we just send a string, the object will auto create. @param null $description Console description. @param array $options Console options. @param \Closure $code The closure to execute. @return AbstractCommand Return this object to support chaining. @since 1.0 @deprecated This method will be removed.
[ "Alias", "of", "addCommand", "for", "legacy", "." ]
fe28cf9e1c694049e015121e2bd041268e814249
https://github.com/asika32764/joomla-framework-console/blob/fe28cf9e1c694049e015121e2bd041268e814249/Command/AbstractCommand.php#L464-L467
238,485
asika32764/joomla-framework-console
Command/AbstractCommand.php
AbstractCommand.setOptions
public function setOptions($options) { $options = is_array($options) ? $options : array($options); foreach ($options as $option) { $this->addOption($option); } return $this; }
php
public function setOptions($options) { $options = is_array($options) ? $options : array($options); foreach ($options as $option) { $this->addOption($option); } return $this; }
[ "public", "function", "setOptions", "(", "$", "options", ")", "{", "$", "options", "=", "is_array", "(", "$", "options", ")", "?", "$", "options", ":", "array", "(", "$", "options", ")", ";", "foreach", "(", "$", "options", "as", "$", "option", ")", "{", "$", "this", "->", "addOption", "(", "$", "option", ")", ";", "}", "return", "$", "this", ";", "}" ]
Batch add options to command. @param mixed $options An options array. @return AbstractCommand Return this object to support chaining. @since 1.0
[ "Batch", "add", "options", "to", "command", "." ]
fe28cf9e1c694049e015121e2bd041268e814249
https://github.com/asika32764/joomla-framework-console/blob/fe28cf9e1c694049e015121e2bd041268e814249/Command/AbstractCommand.php#L682-L692
238,486
asika32764/joomla-framework-console
Command/AbstractCommand.php
AbstractCommand.renderAlternatives
public function renderAlternatives($wrongName, $exception) { /** @var $exception \InvalidArgumentException */ $message = $exception->getMessage(); $autoComplete = ''; $alternatives = array(); // Autocomplete foreach ($this->children as $command) { /** @var $command Command */ $commandName = $command->getName(); /* * Here we use "Levenshtein distance" to compare wrong name with every command names. * * If the difference number less than 1/3 of wrong name which user typed, means this is a similar name, * we can notice user to choose these similar names. * * And if the string of wrong name can be found in a command name, we also notice user to choose it. */ if (levenshtein($wrongName, $commandName) <= (strlen($wrongName) / 3) || strpos($commandName, $wrongName) !== false) { $alternatives[] = " " . $commandName; } } if (count($alternatives)) { $autoComplete = "Did you mean one of these?\n"; $autoComplete .= implode($alternatives); } $this->out(''); $this->err("<error>{$message}</error>"); $this->out(''); $this->err($autoComplete); }
php
public function renderAlternatives($wrongName, $exception) { /** @var $exception \InvalidArgumentException */ $message = $exception->getMessage(); $autoComplete = ''; $alternatives = array(); // Autocomplete foreach ($this->children as $command) { /** @var $command Command */ $commandName = $command->getName(); /* * Here we use "Levenshtein distance" to compare wrong name with every command names. * * If the difference number less than 1/3 of wrong name which user typed, means this is a similar name, * we can notice user to choose these similar names. * * And if the string of wrong name can be found in a command name, we also notice user to choose it. */ if (levenshtein($wrongName, $commandName) <= (strlen($wrongName) / 3) || strpos($commandName, $wrongName) !== false) { $alternatives[] = " " . $commandName; } } if (count($alternatives)) { $autoComplete = "Did you mean one of these?\n"; $autoComplete .= implode($alternatives); } $this->out(''); $this->err("<error>{$message}</error>"); $this->out(''); $this->err($autoComplete); }
[ "public", "function", "renderAlternatives", "(", "$", "wrongName", ",", "$", "exception", ")", "{", "/** @var $exception \\InvalidArgumentException */", "$", "message", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "$", "autoComplete", "=", "''", ";", "$", "alternatives", "=", "array", "(", ")", ";", "// Autocomplete", "foreach", "(", "$", "this", "->", "children", "as", "$", "command", ")", "{", "/** @var $command Command */", "$", "commandName", "=", "$", "command", "->", "getName", "(", ")", ";", "/*\n\t\t\t * Here we use \"Levenshtein distance\" to compare wrong name with every command names.\n\t\t\t *\n\t\t\t * If the difference number less than 1/3 of wrong name which user typed, means this is a similar name,\n\t\t\t * we can notice user to choose these similar names.\n\t\t\t *\n\t\t\t * And if the string of wrong name can be found in a command name, we also notice user to choose it.\n\t\t\t */", "if", "(", "levenshtein", "(", "$", "wrongName", ",", "$", "commandName", ")", "<=", "(", "strlen", "(", "$", "wrongName", ")", "/", "3", ")", "||", "strpos", "(", "$", "commandName", ",", "$", "wrongName", ")", "!==", "false", ")", "{", "$", "alternatives", "[", "]", "=", "\" \"", ".", "$", "commandName", ";", "}", "}", "if", "(", "count", "(", "$", "alternatives", ")", ")", "{", "$", "autoComplete", "=", "\"Did you mean one of these?\\n\"", ";", "$", "autoComplete", ".=", "implode", "(", "$", "alternatives", ")", ";", "}", "$", "this", "->", "out", "(", "''", ")", ";", "$", "this", "->", "err", "(", "\"<error>{$message}</error>\"", ")", ";", "$", "this", "->", "out", "(", "''", ")", ";", "$", "this", "->", "err", "(", "$", "autoComplete", ")", ";", "}" ]
Render auto complete alternatives. @param string $wrongName The wrong command name to auto completed. @param CommandNotFoundException $exception The exception of wrong argument. @return void @since 1.0
[ "Render", "auto", "complete", "alternatives", "." ]
fe28cf9e1c694049e015121e2bd041268e814249
https://github.com/asika32764/joomla-framework-console/blob/fe28cf9e1c694049e015121e2bd041268e814249/Command/AbstractCommand.php#L897-L934
238,487
battis/appmetadata
src/AppMetadata.php
AppMetadata.offsetUnset
public function offsetUnset($key) { $_key = $this->sql->real_escape_string($key); if (!$this->sql->query("DELETE FROM `{$this->table}` WHERE `app` = '{$this->app}' AND `key` = '$_key'")) { throw new AppMetadata_Exception( "Unable to delete app metadata (`$_key`). {$this->sql->error}", AppMetadata_Exception::DELETE_FAIL ); } $result = parent::offsetUnset($key); $this->updateDerivedValues($key); return $result; }
php
public function offsetUnset($key) { $_key = $this->sql->real_escape_string($key); if (!$this->sql->query("DELETE FROM `{$this->table}` WHERE `app` = '{$this->app}' AND `key` = '$_key'")) { throw new AppMetadata_Exception( "Unable to delete app metadata (`$_key`). {$this->sql->error}", AppMetadata_Exception::DELETE_FAIL ); } $result = parent::offsetUnset($key); $this->updateDerivedValues($key); return $result; }
[ "public", "function", "offsetUnset", "(", "$", "key", ")", "{", "$", "_key", "=", "$", "this", "->", "sql", "->", "real_escape_string", "(", "$", "key", ")", ";", "if", "(", "!", "$", "this", "->", "sql", "->", "query", "(", "\"DELETE FROM `{$this->table}` WHERE `app` = '{$this->app}' AND `key` = '$_key'\"", ")", ")", "{", "throw", "new", "AppMetadata_Exception", "(", "\"Unable to delete app metadata (`$_key`). {$this->sql->error}\"", ",", "AppMetadata_Exception", "::", "DELETE_FAIL", ")", ";", "}", "$", "result", "=", "parent", "::", "offsetUnset", "(", "$", "key", ")", ";", "$", "this", "->", "updateDerivedValues", "(", "$", "key", ")", ";", "return", "$", "result", ";", "}" ]
Transparently expunge the persistent app_metadata store when the data is unset @param int|string $key Array key whose value will be unset() @return void (unless ArrayObject::offsetUnset() returns a value... then this wil too!) @throws AppMetadata_Exception DELETE_FAIL if the deletion fails
[ "Transparently", "expunge", "the", "persistent", "app_metadata", "store", "when", "the", "data", "is", "unset" ]
16a0d2735a9bc2824e5a5a90d34717262a27b5cd
https://github.com/battis/appmetadata/blob/16a0d2735a9bc2824e5a5a90d34717262a27b5cd/src/AppMetadata.php#L126-L140
238,488
battis/appmetadata
src/AppMetadata.php
AppMetadata.buildDatabase
public function buildDatabase() { if ($this->sql) { if ($this->sql->query(" CREATE TABLE IF NOT EXISTS `{$this->table}` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `key` varchar(255) NOT NULL, `value` text, `validate` text, `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `app` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ); ")) { $this->initialized = true; /* Upgrade pre-v1.2 app_metadata tables to include independent IDs */ $this->sql->query(" ALTER TABLE `{$this->table}` DROP PRIMARY KEY, ADD `id` INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT FIRST; "); } } return $this->initialized; }
php
public function buildDatabase() { if ($this->sql) { if ($this->sql->query(" CREATE TABLE IF NOT EXISTS `{$this->table}` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `key` varchar(255) NOT NULL, `value` text, `validate` text, `timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `app` varchar(255) NOT NULL DEFAULT '', PRIMARY KEY (`id`) ); ")) { $this->initialized = true; /* Upgrade pre-v1.2 app_metadata tables to include independent IDs */ $this->sql->query(" ALTER TABLE `{$this->table}` DROP PRIMARY KEY, ADD `id` INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT FIRST; "); } } return $this->initialized; }
[ "public", "function", "buildDatabase", "(", ")", "{", "if", "(", "$", "this", "->", "sql", ")", "{", "if", "(", "$", "this", "->", "sql", "->", "query", "(", "\"\n\t\t\t\tCREATE TABLE IF NOT EXISTS `{$this->table}` (\n\t\t\t\t\t`id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t`key` varchar(255) NOT NULL,\n\t\t\t\t\t`value` text,\n\t\t\t\t\t`validate` text,\n\t\t\t\t\t`timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n\t\t\t\t\t`app` varchar(255) NOT NULL DEFAULT '',\n\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t);\n\t\t\t\"", ")", ")", "{", "$", "this", "->", "initialized", "=", "true", ";", "/* Upgrade pre-v1.2 app_metadata tables to include independent IDs */", "$", "this", "->", "sql", "->", "query", "(", "\"\n\t\t\t\t\tALTER TABLE `{$this->table}`\n\t\t\t\t\t\tDROP PRIMARY KEY,\n\t\t\t\t\t\tADD `id` INT(11) UNSIGNED PRIMARY KEY AUTO_INCREMENT FIRST;\n\t\t\t\t\"", ")", ";", "}", "}", "return", "$", "this", "->", "initialized", ";", "}" ]
Create the supporting database table @return boolean TRUE iff the database tables were created, FALSE if some tables already existed in database (and were, therefore, not created and not over-written) @throws AppMetadata_Exception INVALID_MYSQLI_OBJECT if no valid mysqli object is provided to access the database @throws AppMetadata_Exception MISSING_SCHEMA if the schema file cannot be found @throws AppMetadata_Exception CREATE_TABLE_FAIL or PREPARE_DATABASE_FAIL if the schema tables cannot be loaded
[ "Create", "the", "supporting", "database", "table" ]
16a0d2735a9bc2824e5a5a90d34717262a27b5cd
https://github.com/battis/appmetadata/blob/16a0d2735a9bc2824e5a5a90d34717262a27b5cd/src/AppMetadata.php#L151-L175
238,489
battis/appmetadata
src/AppMetadata.php
AppMetadata.updateDerivedValues
private function updateDerivedValues($key = null, $value = null) { /* * TODO * I darkly suspect that there is a possibility that you could create a loop * of derived references that would be irresolvable and not currently detected * e.g. A => '@B', B=>'@C', C=>'@A'. Perhaps the best approach would be to * limit the depth of the derivation search? */ $derived = array(); /* determine breadth of derived fields affected */ $derivedPattern = '%@_%'; if (!empty($key)) { $_key = $this->sql->real_escape_string($key); $derivedPattern = "%@$_key%"; if (!empty($value) && is_string($value)) { $derived[$key] = $value; } } /* build a list of affected key => value pairs */ if ($result = $this->sql->query(" SELECT * FROM `{$this->table}` WHERE `value` LIKE '$derivedPattern' ")) { while($row = $result->fetch_assoc()) { $value = unserialize($row['value']); if (is_string($value)) { $derived[$row['key']] = $value; } } } /* generate derived fields based on prior fields */ while (count($derived) > 0) { $next = array(); foreach ($derived as $key => $value) { /* look for @keys in the value */ preg_match_all('/@(\w+)/', $value, $sources, PREG_SET_ORDER); $dirty = false; foreach($sources as $source) { if ($this->offsetExists($source[1]) && is_string($this->offsetGet($source[1]))) { $value = preg_replace("/{$source[0]}/", $this->offsetGet($source[1]), $value); $dirty = true; } } /* ...and queue up again to check */ if ($dirty) { $next[$key] = $value; } else { $this->_offsetSet($key, $value, false); } } /* use new queue */ $derived = $next; } }
php
private function updateDerivedValues($key = null, $value = null) { /* * TODO * I darkly suspect that there is a possibility that you could create a loop * of derived references that would be irresolvable and not currently detected * e.g. A => '@B', B=>'@C', C=>'@A'. Perhaps the best approach would be to * limit the depth of the derivation search? */ $derived = array(); /* determine breadth of derived fields affected */ $derivedPattern = '%@_%'; if (!empty($key)) { $_key = $this->sql->real_escape_string($key); $derivedPattern = "%@$_key%"; if (!empty($value) && is_string($value)) { $derived[$key] = $value; } } /* build a list of affected key => value pairs */ if ($result = $this->sql->query(" SELECT * FROM `{$this->table}` WHERE `value` LIKE '$derivedPattern' ")) { while($row = $result->fetch_assoc()) { $value = unserialize($row['value']); if (is_string($value)) { $derived[$row['key']] = $value; } } } /* generate derived fields based on prior fields */ while (count($derived) > 0) { $next = array(); foreach ($derived as $key => $value) { /* look for @keys in the value */ preg_match_all('/@(\w+)/', $value, $sources, PREG_SET_ORDER); $dirty = false; foreach($sources as $source) { if ($this->offsetExists($source[1]) && is_string($this->offsetGet($source[1]))) { $value = preg_replace("/{$source[0]}/", $this->offsetGet($source[1]), $value); $dirty = true; } } /* ...and queue up again to check */ if ($dirty) { $next[$key] = $value; } else { $this->_offsetSet($key, $value, false); } } /* use new queue */ $derived = $next; } }
[ "private", "function", "updateDerivedValues", "(", "$", "key", "=", "null", ",", "$", "value", "=", "null", ")", "{", "/* \n\t\t * TODO\n\t\t * I darkly suspect that there is a possibility that you could create a loop\n\t\t * of derived references that would be irresolvable and not currently detected\n\t\t * e.g. A => '@B', B=>'@C', C=>'@A'. Perhaps the best approach would be to\n\t\t * limit the depth of the derivation search?\n\t\t */", "$", "derived", "=", "array", "(", ")", ";", "/* determine breadth of derived fields affected */", "$", "derivedPattern", "=", "'%@_%'", ";", "if", "(", "!", "empty", "(", "$", "key", ")", ")", "{", "$", "_key", "=", "$", "this", "->", "sql", "->", "real_escape_string", "(", "$", "key", ")", ";", "$", "derivedPattern", "=", "\"%@$_key%\"", ";", "if", "(", "!", "empty", "(", "$", "value", ")", "&&", "is_string", "(", "$", "value", ")", ")", "{", "$", "derived", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "/* build a list of affected key => value pairs */", "if", "(", "$", "result", "=", "$", "this", "->", "sql", "->", "query", "(", "\"\n\t\t\tSELECT *\n\t\t\t\tFROM `{$this->table}`\n\t\t\t\tWHERE\n\t\t\t\t\t`value` LIKE '$derivedPattern'\n\t\t\t\t\t\n\t\t\"", ")", ")", "{", "while", "(", "$", "row", "=", "$", "result", "->", "fetch_assoc", "(", ")", ")", "{", "$", "value", "=", "unserialize", "(", "$", "row", "[", "'value'", "]", ")", ";", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "derived", "[", "$", "row", "[", "'key'", "]", "]", "=", "$", "value", ";", "}", "}", "}", "/* generate derived fields based on prior fields */", "while", "(", "count", "(", "$", "derived", ")", ">", "0", ")", "{", "$", "next", "=", "array", "(", ")", ";", "foreach", "(", "$", "derived", "as", "$", "key", "=>", "$", "value", ")", "{", "/* look for @keys in the value */", "preg_match_all", "(", "'/@(\\w+)/'", ",", "$", "value", ",", "$", "sources", ",", "PREG_SET_ORDER", ")", ";", "$", "dirty", "=", "false", ";", "foreach", "(", "$", "sources", "as", "$", "source", ")", "{", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "source", "[", "1", "]", ")", "&&", "is_string", "(", "$", "this", "->", "offsetGet", "(", "$", "source", "[", "1", "]", ")", ")", ")", "{", "$", "value", "=", "preg_replace", "(", "\"/{$source[0]}/\"", ",", "$", "this", "->", "offsetGet", "(", "$", "source", "[", "1", "]", ")", ",", "$", "value", ")", ";", "$", "dirty", "=", "true", ";", "}", "}", "/* ...and queue up again to check */", "if", "(", "$", "dirty", ")", "{", "$", "next", "[", "$", "key", "]", "=", "$", "value", ";", "}", "else", "{", "$", "this", "->", "_offsetSet", "(", "$", "key", ",", "$", "value", ",", "false", ")", ";", "}", "}", "/* use new queue */", "$", "derived", "=", "$", "next", ";", "}", "}" ]
Calculate the derived value for a particular offset For example... ```PHP $metadata['A'] = 'foo'; $metadata['B'] = '@A/bar'; echo $metadata['B']; // 'foo/bar'; $metadata['A'] = 'rutabega'; echo $metadata['B']; // 'rutabega/bar' ``` @param string $key (Optional) Limit the updates to values derived from `$key` @param string $value (Optiona) The value that is stored at `$key` which may itself need to be derived further @return void
[ "Calculate", "the", "derived", "value", "for", "a", "particular", "offset" ]
16a0d2735a9bc2824e5a5a90d34717262a27b5cd
https://github.com/battis/appmetadata/blob/16a0d2735a9bc2824e5a5a90d34717262a27b5cd/src/AppMetadata.php#L217-L282
238,490
battis/appmetadata
src/AppMetadata.php
AppMetadata.derivedValues
public function derivedValues($s) { preg_match_all('/@(\w+)/', $s, $possibilities, PREG_SET_ORDER); foreach ($possibilities as $possibility) { if ($this->offsetExists($possibility[1]) && is_string($this->offsetGet($possibility[1]))) { $s = str_replace($possibility[0], $this->offsetGet($possibility[1]), $s); } } return $s; }
php
public function derivedValues($s) { preg_match_all('/@(\w+)/', $s, $possibilities, PREG_SET_ORDER); foreach ($possibilities as $possibility) { if ($this->offsetExists($possibility[1]) && is_string($this->offsetGet($possibility[1]))) { $s = str_replace($possibility[0], $this->offsetGet($possibility[1]), $s); } } return $s; }
[ "public", "function", "derivedValues", "(", "$", "s", ")", "{", "preg_match_all", "(", "'/@(\\w+)/'", ",", "$", "s", ",", "$", "possibilities", ",", "PREG_SET_ORDER", ")", ";", "foreach", "(", "$", "possibilities", "as", "$", "possibility", ")", "{", "if", "(", "$", "this", "->", "offsetExists", "(", "$", "possibility", "[", "1", "]", ")", "&&", "is_string", "(", "$", "this", "->", "offsetGet", "(", "$", "possibility", "[", "1", "]", ")", ")", ")", "{", "$", "s", "=", "str_replace", "(", "$", "possibility", "[", "0", "]", ",", "$", "this", "->", "offsetGet", "(", "$", "possibility", "[", "1", "]", ")", ",", "$", "s", ")", ";", "}", "}", "return", "$", "s", ";", "}" ]
Replace derived values in an abitrary string using AppMetadata @param string $s @return string
[ "Replace", "derived", "values", "in", "an", "abitrary", "string", "using", "AppMetadata" ]
16a0d2735a9bc2824e5a5a90d34717262a27b5cd
https://github.com/battis/appmetadata/blob/16a0d2735a9bc2824e5a5a90d34717262a27b5cd/src/AppMetadata.php#L291-L299
238,491
restrose/water
src/Shop.php
Shop.getGoodsSN
public function getGoodsSN() { $step = 5000; $start = 100; $max = Goods::max('sn'); $max = count($max) && $max > $start ? $max : $start; $sn = $max+1; $sn_str = strval($sn); if(str_contains($sn_str, '4')) { $sn_str = str_replace('4', '5', $sn_str); } $sn = intval($sn_str); $in_offer = Offer::where('sn', $sn)->first(); $max_offer = Offer::max('sn'); if(count($in_offer)) { $sn = $step * ceil($max_offer / $step)+ $step; } return $sn; }
php
public function getGoodsSN() { $step = 5000; $start = 100; $max = Goods::max('sn'); $max = count($max) && $max > $start ? $max : $start; $sn = $max+1; $sn_str = strval($sn); if(str_contains($sn_str, '4')) { $sn_str = str_replace('4', '5', $sn_str); } $sn = intval($sn_str); $in_offer = Offer::where('sn', $sn)->first(); $max_offer = Offer::max('sn'); if(count($in_offer)) { $sn = $step * ceil($max_offer / $step)+ $step; } return $sn; }
[ "public", "function", "getGoodsSN", "(", ")", "{", "$", "step", "=", "5000", ";", "$", "start", "=", "100", ";", "$", "max", "=", "Goods", "::", "max", "(", "'sn'", ")", ";", "$", "max", "=", "count", "(", "$", "max", ")", "&&", "$", "max", ">", "$", "start", "?", "$", "max", ":", "$", "start", ";", "$", "sn", "=", "$", "max", "+", "1", ";", "$", "sn_str", "=", "strval", "(", "$", "sn", ")", ";", "if", "(", "str_contains", "(", "$", "sn_str", ",", "'4'", ")", ")", "{", "$", "sn_str", "=", "str_replace", "(", "'4'", ",", "'5'", ",", "$", "sn_str", ")", ";", "}", "$", "sn", "=", "intval", "(", "$", "sn_str", ")", ";", "$", "in_offer", "=", "Offer", "::", "where", "(", "'sn'", ",", "$", "sn", ")", "->", "first", "(", ")", ";", "$", "max_offer", "=", "Offer", "::", "max", "(", "'sn'", ")", ";", "if", "(", "count", "(", "$", "in_offer", ")", ")", "{", "$", "sn", "=", "$", "step", "*", "ceil", "(", "$", "max_offer", "/", "$", "step", ")", "+", "$", "step", ";", "}", "return", "$", "sn", ";", "}" ]
get shop sn
[ "get", "shop", "sn" ]
b1ca5e0b77ed73a98b532a5589d6c14012b2bef1
https://github.com/restrose/water/blob/b1ca5e0b77ed73a98b532a5589d6c14012b2bef1/src/Shop.php#L21-L41
238,492
restrose/water
src/Shop.php
Shop.getOfferSN
public function getOfferSN() { $start = 5000; $step = 5000; $max = Offer::max('sn'); $max = count($max) && $max > $start ? $max : $start; $sn = $max+1; $sn_str = strval($sn); if(str_contains($sn_str, '4')) { $sn_str = str_replace('4', '5', $sn_str); } $sn = intval($sn_str); $in_goods = Goods::where('sn', $sn)->first(); $max_goods = Goods::max('sn'); if(count($in_goods)) { $sn = $step * ceil($max_goods / $step)+ $step; } return $sn; }
php
public function getOfferSN() { $start = 5000; $step = 5000; $max = Offer::max('sn'); $max = count($max) && $max > $start ? $max : $start; $sn = $max+1; $sn_str = strval($sn); if(str_contains($sn_str, '4')) { $sn_str = str_replace('4', '5', $sn_str); } $sn = intval($sn_str); $in_goods = Goods::where('sn', $sn)->first(); $max_goods = Goods::max('sn'); if(count($in_goods)) { $sn = $step * ceil($max_goods / $step)+ $step; } return $sn; }
[ "public", "function", "getOfferSN", "(", ")", "{", "$", "start", "=", "5000", ";", "$", "step", "=", "5000", ";", "$", "max", "=", "Offer", "::", "max", "(", "'sn'", ")", ";", "$", "max", "=", "count", "(", "$", "max", ")", "&&", "$", "max", ">", "$", "start", "?", "$", "max", ":", "$", "start", ";", "$", "sn", "=", "$", "max", "+", "1", ";", "$", "sn_str", "=", "strval", "(", "$", "sn", ")", ";", "if", "(", "str_contains", "(", "$", "sn_str", ",", "'4'", ")", ")", "{", "$", "sn_str", "=", "str_replace", "(", "'4'", ",", "'5'", ",", "$", "sn_str", ")", ";", "}", "$", "sn", "=", "intval", "(", "$", "sn_str", ")", ";", "$", "in_goods", "=", "Goods", "::", "where", "(", "'sn'", ",", "$", "sn", ")", "->", "first", "(", ")", ";", "$", "max_goods", "=", "Goods", "::", "max", "(", "'sn'", ")", ";", "if", "(", "count", "(", "$", "in_goods", ")", ")", "{", "$", "sn", "=", "$", "step", "*", "ceil", "(", "$", "max_goods", "/", "$", "step", ")", "+", "$", "step", ";", "}", "return", "$", "sn", ";", "}" ]
get offer sn
[ "get", "offer", "sn" ]
b1ca5e0b77ed73a98b532a5589d6c14012b2bef1
https://github.com/restrose/water/blob/b1ca5e0b77ed73a98b532a5589d6c14012b2bef1/src/Shop.php#L47-L67
238,493
php-rest-server/core
src/Core/General/Cyphers/OpenSSLCypher.php
OpenSSLCypher.encode
public function encode($data) { return openssl_encrypt($data, $this->method, $this->key, 0, $this->iv); }
php
public function encode($data) { return openssl_encrypt($data, $this->method, $this->key, 0, $this->iv); }
[ "public", "function", "encode", "(", "$", "data", ")", "{", "return", "openssl_encrypt", "(", "$", "data", ",", "$", "this", "->", "method", ",", "$", "this", "->", "key", ",", "0", ",", "$", "this", "->", "iv", ")", ";", "}" ]
Encode data by openssl_encrypt @param string $data @return string
[ "Encode", "data", "by", "openssl_encrypt" ]
4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888
https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/General/Cyphers/OpenSSLCypher.php#L58-L61
238,494
php-rest-server/core
src/Core/General/Cyphers/OpenSSLCypher.php
OpenSSLCypher.decode
public function decode($data) { return openssl_decrypt($data, $this->method, $this->key, 0, $this->iv); }
php
public function decode($data) { return openssl_decrypt($data, $this->method, $this->key, 0, $this->iv); }
[ "public", "function", "decode", "(", "$", "data", ")", "{", "return", "openssl_decrypt", "(", "$", "data", ",", "$", "this", "->", "method", ",", "$", "this", "->", "key", ",", "0", ",", "$", "this", "->", "iv", ")", ";", "}" ]
Decode data by openssl_decrypt @param string $data @return string
[ "Decode", "data", "by", "openssl_decrypt" ]
4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888
https://github.com/php-rest-server/core/blob/4d1ee0d4b6bd7d170cf1ec924a8b743b5d486888/src/Core/General/Cyphers/OpenSSLCypher.php#L70-L73
238,495
gliverphp/database
src/DbImplement.php
DbImplement.initialize
public function initialize() { //throw exception if no database type has been set if( ! $this->type ) { //Throw exception throw new DbException("Invalid database type provided"); } //check the type of database provided returning instance //set the parameter to check in switch clause switch ($this->type ) { case 'mysql': return new MySQL($this->options); break; default: throw new DbException("Valid database type provided"); break; } }
php
public function initialize() { //throw exception if no database type has been set if( ! $this->type ) { //Throw exception throw new DbException("Invalid database type provided"); } //check the type of database provided returning instance //set the parameter to check in switch clause switch ($this->type ) { case 'mysql': return new MySQL($this->options); break; default: throw new DbException("Valid database type provided"); break; } }
[ "public", "function", "initialize", "(", ")", "{", "//throw exception if no database type has been set", "if", "(", "!", "$", "this", "->", "type", ")", "{", "//Throw exception", "throw", "new", "DbException", "(", "\"Invalid database type provided\"", ")", ";", "}", "//check the type of database provided returning instance", "//set the parameter to check in switch clause", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "'mysql'", ":", "return", "new", "MySQL", "(", "$", "this", "->", "options", ")", ";", "break", ";", "default", ":", "throw", "new", "DbException", "(", "\"Valid database type provided\"", ")", ";", "break", ";", "}", "}" ]
This method initializes a database connection @param null @return object Instance of this database connection @throws DbException If the database type provided is not defined for this system
[ "This", "method", "initializes", "a", "database", "connection" ]
b998bd3d24cb2f269b9bd54438c7df8751377ba9
https://github.com/gliverphp/database/blob/b998bd3d24cb2f269b9bd54438c7df8751377ba9/src/DbImplement.php#L39-L67
238,496
docit/core
src/Parsers/ParsedownExtra.php
ParsedownExtra.blockFencedCode
protected function blockFencedCode($line) { $regex = '/^([' . $line[ 'text' ][ 0 ] . ']{3,})[ ]*([\w-]+)?[ ]*$/'; if (preg_match($regex, $line[ 'text' ], $matches)) { $element = [ 'name' => 'code', 'text' => '', ]; if (isset($matches[ 2 ])) { $class = $this->getConfig('fenced_code_lang_class', 'prettyprint lang-{LANG}'); $class = str_replace('{LANG}', $matches[2], $class); //'prettyprint lang-' . $matches[ 2 ]; $element[ 'attributes' ] = [ 'class' => $class ]; } $block = [ 'char' => $line[ 'text' ][ 0 ], 'element' => [ 'name' => 'pre', 'handler' => 'element', 'text' => $element, ], ]; return $block; } }
php
protected function blockFencedCode($line) { $regex = '/^([' . $line[ 'text' ][ 0 ] . ']{3,})[ ]*([\w-]+)?[ ]*$/'; if (preg_match($regex, $line[ 'text' ], $matches)) { $element = [ 'name' => 'code', 'text' => '', ]; if (isset($matches[ 2 ])) { $class = $this->getConfig('fenced_code_lang_class', 'prettyprint lang-{LANG}'); $class = str_replace('{LANG}', $matches[2], $class); //'prettyprint lang-' . $matches[ 2 ]; $element[ 'attributes' ] = [ 'class' => $class ]; } $block = [ 'char' => $line[ 'text' ][ 0 ], 'element' => [ 'name' => 'pre', 'handler' => 'element', 'text' => $element, ], ]; return $block; } }
[ "protected", "function", "blockFencedCode", "(", "$", "line", ")", "{", "$", "regex", "=", "'/^(['", ".", "$", "line", "[", "'text'", "]", "[", "0", "]", ".", "']{3,})[ ]*([\\w-]+)?[ ]*$/'", ";", "if", "(", "preg_match", "(", "$", "regex", ",", "$", "line", "[", "'text'", "]", ",", "$", "matches", ")", ")", "{", "$", "element", "=", "[", "'name'", "=>", "'code'", ",", "'text'", "=>", "''", ",", "]", ";", "if", "(", "isset", "(", "$", "matches", "[", "2", "]", ")", ")", "{", "$", "class", "=", "$", "this", "->", "getConfig", "(", "'fenced_code_lang_class'", ",", "'prettyprint lang-{LANG}'", ")", ";", "$", "class", "=", "str_replace", "(", "'{LANG}'", ",", "$", "matches", "[", "2", "]", ",", "$", "class", ")", ";", "//'prettyprint lang-' . $matches[ 2 ];", "$", "element", "[", "'attributes'", "]", "=", "[", "'class'", "=>", "$", "class", "]", ";", "}", "$", "block", "=", "[", "'char'", "=>", "$", "line", "[", "'text'", "]", "[", "0", "]", ",", "'element'", "=>", "[", "'name'", "=>", "'pre'", ",", "'handler'", "=>", "'element'", ",", "'text'", "=>", "$", "element", ",", "]", ",", "]", ";", "return", "$", "block", ";", "}", "}" ]
Parse fenced code blocks. @param array $line @return array
[ "Parse", "fenced", "code", "blocks", "." ]
448e1cdca18a8ffb6c08430cad8d22162171ac35
https://github.com/docit/core/blob/448e1cdca18a8ffb6c08430cad8d22162171ac35/src/Parsers/ParsedownExtra.php#L58-L86
238,497
docit/core
src/Parsers/ParsedownExtra.php
ParsedownExtra.blockTable
protected function blockTable($line, array $block = null) { if (! isset($block) or isset($block[ 'type' ]) or isset($block[ 'interrupted' ])) { return; } if (strpos($block[ 'element' ][ 'text' ], '|') !== false and chop($line[ 'text' ], ' -:|') === '') { $alignments = array(); $divider = $line[ 'text' ]; $divider = trim($divider); $divider = trim($divider, '|'); $dividerCells = explode('|', $divider); foreach ($dividerCells as $dividerCell) { $dividerCell = trim($dividerCell); if ($dividerCell === '') { continue; } $alignment = null; if ($dividerCell[ 0 ] === ':') { $alignment = 'left'; } if (substr($dividerCell, -1) === ':') { $alignment = $alignment === 'left' ? 'center' : 'right'; } $alignments[] = $alignment; } $headerElements = array(); $header = $block[ 'element' ][ 'text' ]; $header = trim($header); $header = trim($header, '|'); $headerCells = explode('|', $header); foreach ($headerCells as $index => $headerCell) { $headerCell = trim($headerCell); $headerElement = [ 'name' => 'th', 'text' => $headerCell, 'handler' => 'line', ]; if (isset($alignments[ $index ])) { $alignment = $alignments[ $index ]; $headerElement[ 'attributes' ] = [ 'style' => 'text-align: ' . $alignment . ';', ]; } $headerElements[] = $headerElement; } $block = [ 'alignments' => $alignments, 'identified' => true, 'element' => [ 'name' => 'table', 'handler' => 'elements', 'attributes' => [ 'class' => 'table table-striped table-bordered' ], ], ]; $block[ 'element' ][ 'text' ][] = [ 'name' => 'thead', 'handler' => 'elements', ]; $block[ 'element' ][ 'text' ][] = [ 'name' => 'tbody', 'handler' => 'elements', 'text' => array(), ]; $block[ 'element' ][ 'text' ][ 0 ][ 'text' ][] = [ 'name' => 'tr', 'handler' => 'elements', 'text' => $headerElements, ]; return $block; } }
php
protected function blockTable($line, array $block = null) { if (! isset($block) or isset($block[ 'type' ]) or isset($block[ 'interrupted' ])) { return; } if (strpos($block[ 'element' ][ 'text' ], '|') !== false and chop($line[ 'text' ], ' -:|') === '') { $alignments = array(); $divider = $line[ 'text' ]; $divider = trim($divider); $divider = trim($divider, '|'); $dividerCells = explode('|', $divider); foreach ($dividerCells as $dividerCell) { $dividerCell = trim($dividerCell); if ($dividerCell === '') { continue; } $alignment = null; if ($dividerCell[ 0 ] === ':') { $alignment = 'left'; } if (substr($dividerCell, -1) === ':') { $alignment = $alignment === 'left' ? 'center' : 'right'; } $alignments[] = $alignment; } $headerElements = array(); $header = $block[ 'element' ][ 'text' ]; $header = trim($header); $header = trim($header, '|'); $headerCells = explode('|', $header); foreach ($headerCells as $index => $headerCell) { $headerCell = trim($headerCell); $headerElement = [ 'name' => 'th', 'text' => $headerCell, 'handler' => 'line', ]; if (isset($alignments[ $index ])) { $alignment = $alignments[ $index ]; $headerElement[ 'attributes' ] = [ 'style' => 'text-align: ' . $alignment . ';', ]; } $headerElements[] = $headerElement; } $block = [ 'alignments' => $alignments, 'identified' => true, 'element' => [ 'name' => 'table', 'handler' => 'elements', 'attributes' => [ 'class' => 'table table-striped table-bordered' ], ], ]; $block[ 'element' ][ 'text' ][] = [ 'name' => 'thead', 'handler' => 'elements', ]; $block[ 'element' ][ 'text' ][] = [ 'name' => 'tbody', 'handler' => 'elements', 'text' => array(), ]; $block[ 'element' ][ 'text' ][ 0 ][ 'text' ][] = [ 'name' => 'tr', 'handler' => 'elements', 'text' => $headerElements, ]; return $block; } }
[ "protected", "function", "blockTable", "(", "$", "line", ",", "array", "$", "block", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "block", ")", "or", "isset", "(", "$", "block", "[", "'type'", "]", ")", "or", "isset", "(", "$", "block", "[", "'interrupted'", "]", ")", ")", "{", "return", ";", "}", "if", "(", "strpos", "(", "$", "block", "[", "'element'", "]", "[", "'text'", "]", ",", "'|'", ")", "!==", "false", "and", "chop", "(", "$", "line", "[", "'text'", "]", ",", "' -:|'", ")", "===", "''", ")", "{", "$", "alignments", "=", "array", "(", ")", ";", "$", "divider", "=", "$", "line", "[", "'text'", "]", ";", "$", "divider", "=", "trim", "(", "$", "divider", ")", ";", "$", "divider", "=", "trim", "(", "$", "divider", ",", "'|'", ")", ";", "$", "dividerCells", "=", "explode", "(", "'|'", ",", "$", "divider", ")", ";", "foreach", "(", "$", "dividerCells", "as", "$", "dividerCell", ")", "{", "$", "dividerCell", "=", "trim", "(", "$", "dividerCell", ")", ";", "if", "(", "$", "dividerCell", "===", "''", ")", "{", "continue", ";", "}", "$", "alignment", "=", "null", ";", "if", "(", "$", "dividerCell", "[", "0", "]", "===", "':'", ")", "{", "$", "alignment", "=", "'left'", ";", "}", "if", "(", "substr", "(", "$", "dividerCell", ",", "-", "1", ")", "===", "':'", ")", "{", "$", "alignment", "=", "$", "alignment", "===", "'left'", "?", "'center'", ":", "'right'", ";", "}", "$", "alignments", "[", "]", "=", "$", "alignment", ";", "}", "$", "headerElements", "=", "array", "(", ")", ";", "$", "header", "=", "$", "block", "[", "'element'", "]", "[", "'text'", "]", ";", "$", "header", "=", "trim", "(", "$", "header", ")", ";", "$", "header", "=", "trim", "(", "$", "header", ",", "'|'", ")", ";", "$", "headerCells", "=", "explode", "(", "'|'", ",", "$", "header", ")", ";", "foreach", "(", "$", "headerCells", "as", "$", "index", "=>", "$", "headerCell", ")", "{", "$", "headerCell", "=", "trim", "(", "$", "headerCell", ")", ";", "$", "headerElement", "=", "[", "'name'", "=>", "'th'", ",", "'text'", "=>", "$", "headerCell", ",", "'handler'", "=>", "'line'", ",", "]", ";", "if", "(", "isset", "(", "$", "alignments", "[", "$", "index", "]", ")", ")", "{", "$", "alignment", "=", "$", "alignments", "[", "$", "index", "]", ";", "$", "headerElement", "[", "'attributes'", "]", "=", "[", "'style'", "=>", "'text-align: '", ".", "$", "alignment", ".", "';'", ",", "]", ";", "}", "$", "headerElements", "[", "]", "=", "$", "headerElement", ";", "}", "$", "block", "=", "[", "'alignments'", "=>", "$", "alignments", ",", "'identified'", "=>", "true", ",", "'element'", "=>", "[", "'name'", "=>", "'table'", ",", "'handler'", "=>", "'elements'", ",", "'attributes'", "=>", "[", "'class'", "=>", "'table table-striped table-bordered'", "]", ",", "]", ",", "]", ";", "$", "block", "[", "'element'", "]", "[", "'text'", "]", "[", "]", "=", "[", "'name'", "=>", "'thead'", ",", "'handler'", "=>", "'elements'", ",", "]", ";", "$", "block", "[", "'element'", "]", "[", "'text'", "]", "[", "]", "=", "[", "'name'", "=>", "'tbody'", ",", "'handler'", "=>", "'elements'", ",", "'text'", "=>", "array", "(", ")", ",", "]", ";", "$", "block", "[", "'element'", "]", "[", "'text'", "]", "[", "0", "]", "[", "'text'", "]", "[", "]", "=", "[", "'name'", "=>", "'tr'", ",", "'handler'", "=>", "'elements'", ",", "'text'", "=>", "$", "headerElements", ",", "]", ";", "return", "$", "block", ";", "}", "}" ]
Parse tables. @param array $line @param array $block @return array
[ "Parse", "tables", "." ]
448e1cdca18a8ffb6c08430cad8d22162171ac35
https://github.com/docit/core/blob/448e1cdca18a8ffb6c08430cad8d22162171ac35/src/Parsers/ParsedownExtra.php#L95-L190
238,498
teamelf/core
src/Http/AbstractController.php
AbstractController.validate
protected function validate(array $rules, bool $throwError = true) { $validations = []; $data = []; foreach ($rules as $key => $rule) { $value = $this->request->get($key); $violations = $this->validator->validate($value, $rule); if (count($violations) > 0) { $validations[$key] = []; foreach ($violations as $violation) { $validations[$key][] = $violation->getMessage(); } } else { $data[$key] = $value; } } if ($throwError && count($validations)) { throw new HttpValidationException($validations); } return $data; }
php
protected function validate(array $rules, bool $throwError = true) { $validations = []; $data = []; foreach ($rules as $key => $rule) { $value = $this->request->get($key); $violations = $this->validator->validate($value, $rule); if (count($violations) > 0) { $validations[$key] = []; foreach ($violations as $violation) { $validations[$key][] = $violation->getMessage(); } } else { $data[$key] = $value; } } if ($throwError && count($validations)) { throw new HttpValidationException($validations); } return $data; }
[ "protected", "function", "validate", "(", "array", "$", "rules", ",", "bool", "$", "throwError", "=", "true", ")", "{", "$", "validations", "=", "[", "]", ";", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "rules", "as", "$", "key", "=>", "$", "rule", ")", "{", "$", "value", "=", "$", "this", "->", "request", "->", "get", "(", "$", "key", ")", ";", "$", "violations", "=", "$", "this", "->", "validator", "->", "validate", "(", "$", "value", ",", "$", "rule", ")", ";", "if", "(", "count", "(", "$", "violations", ")", ">", "0", ")", "{", "$", "validations", "[", "$", "key", "]", "=", "[", "]", ";", "foreach", "(", "$", "violations", "as", "$", "violation", ")", "{", "$", "validations", "[", "$", "key", "]", "[", "]", "=", "$", "violation", "->", "getMessage", "(", ")", ";", "}", "}", "else", "{", "$", "data", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "if", "(", "$", "throwError", "&&", "count", "(", "$", "validations", ")", ")", "{", "throw", "new", "HttpValidationException", "(", "$", "validations", ")", ";", "}", "return", "$", "data", ";", "}" ]
validate input value from request @param array $rules ['key' => [new NotBlank(), ...], ...] @param bool $throwError @return array @throws HttpValidationException
[ "validate", "input", "value", "from", "request" ]
653fc6e27f42239c2a8998a5fea325480e9dd39e
https://github.com/teamelf/core/blob/653fc6e27f42239c2a8998a5fea325480e9dd39e/src/Http/AbstractController.php#L111-L131
238,499
teamelf/core
src/Http/AbstractController.php
AbstractController.auth
final protected function auth($member) { if ($member) { $this->session->set('auth_member_id', $member->getId()); } else { $this->session->remove('auth_member_id'); } return $this; }
php
final protected function auth($member) { if ($member) { $this->session->set('auth_member_id', $member->getId()); } else { $this->session->remove('auth_member_id'); } return $this; }
[ "final", "protected", "function", "auth", "(", "$", "member", ")", "{", "if", "(", "$", "member", ")", "{", "$", "this", "->", "session", "->", "set", "(", "'auth_member_id'", ",", "$", "member", "->", "getId", "(", ")", ")", ";", "}", "else", "{", "$", "this", "->", "session", "->", "remove", "(", "'auth_member_id'", ")", ";", "}", "return", "$", "this", ";", "}" ]
set auth user to session @param null|Member $member @return $this
[ "set", "auth", "user", "to", "session" ]
653fc6e27f42239c2a8998a5fea325480e9dd39e
https://github.com/teamelf/core/blob/653fc6e27f42239c2a8998a5fea325480e9dd39e/src/Http/AbstractController.php#L139-L147