repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
Assasz/yggdrasil
src/Yggdrasil/Core/Controller/AbstractController.php
AbstractController.redirectToAction
protected function redirectToAction(string $alias = null, array $params = []): RedirectResponse { if (empty($alias)) { $routerConfig = $this->getRouter()->getConfiguration(); $alias = "{$routerConfig->getDefaultController()}:{$routerConfig->getDefaultAction()}"; } $query = $this->getRouter()->getQuery($alias, $params); $headers = $this->getResponse()->headers->all(); return new RedirectResponse($query, Response::HTTP_FOUND, $headers); }
php
protected function redirectToAction(string $alias = null, array $params = []): RedirectResponse { if (empty($alias)) { $routerConfig = $this->getRouter()->getConfiguration(); $alias = "{$routerConfig->getDefaultController()}:{$routerConfig->getDefaultAction()}"; } $query = $this->getRouter()->getQuery($alias, $params); $headers = $this->getResponse()->headers->all(); return new RedirectResponse($query, Response::HTTP_FOUND, $headers); }
[ "protected", "function", "redirectToAction", "(", "string", "$", "alias", "=", "null", ",", "array", "$", "params", "=", "[", "]", ")", ":", "RedirectResponse", "{", "if", "(", "empty", "(", "$", "alias", ")", ")", "{", "$", "routerConfig", "=", "$", ...
Redirects to given action @param string? $alias Alias of action like Controller:action, if left empty default action will be chosen @param array $params Parameters supposed to be passed to the action @return RedirectResponse
[ "Redirects", "to", "given", "action" ]
bee9bef7713b85799cdd3e9b23dccae33154f3b3
https://github.com/Assasz/yggdrasil/blob/bee9bef7713b85799cdd3e9b23dccae33154f3b3/src/Yggdrasil/Core/Controller/AbstractController.php#L92-L103
train
CeusMedia/Common
src/FS/File/CSS/Reader.php
FS_File_CSS_Reader.setFileName
public function setFileName( $fileName ){ $this->fileName = $fileName; $this->sheet = self::load( $fileName ); }
php
public function setFileName( $fileName ){ $this->fileName = $fileName; $this->sheet = self::load( $fileName ); }
[ "public", "function", "setFileName", "(", "$", "fileName", ")", "{", "$", "this", "->", "fileName", "=", "$", "fileName", ";", "$", "this", "->", "sheet", "=", "self", "::", "load", "(", "$", "fileName", ")", ";", "}" ]
Points reader to a CSS file which will be parsed and stored internally. @access public @param string $fileName Relative or absolute file URI @return void
[ "Points", "reader", "to", "a", "CSS", "file", "which", "will", "be", "parsed", "and", "stored", "internally", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Reader.php#L99-L102
train
CeusMedia/Common
src/ADT/Tree/BinaryNode.php
ADT_Tree_BinaryNode.add
public function add( $value ) { if( !isset( $this->value ) ) return $this->value = $value; if( $value == $this->value) return -1; if( $value < $this->value ) { if( $this->left ) $this->left->add( $value ); else $this->left = new ADT_Tree_BinaryNode( $value ); } else if( $value > $this->value ) { if( $this->right ) $this->right->add( $value ); else $this->right = new ADT_Tree_BinaryNode( $value ); } }
php
public function add( $value ) { if( !isset( $this->value ) ) return $this->value = $value; if( $value == $this->value) return -1; if( $value < $this->value ) { if( $this->left ) $this->left->add( $value ); else $this->left = new ADT_Tree_BinaryNode( $value ); } else if( $value > $this->value ) { if( $this->right ) $this->right->add( $value ); else $this->right = new ADT_Tree_BinaryNode( $value ); } }
[ "public", "function", "add", "(", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "value", ")", ")", "return", "$", "this", "->", "value", "=", "$", "value", ";", "if", "(", "$", "value", "==", "$", "this", "->", "value...
Adds a Node to the Tree. @access public @param mixed $value Value to be added to the Tree @return void
[ "Adds", "a", "Node", "to", "the", "Tree", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L65-L85
train
CeusMedia/Common
src/ADT/Tree/BinaryNode.php
ADT_Tree_BinaryNode.countNodes
public function countNodes() { $nodes = 1; if( $this->left || $this->right ) { if( $this->left ) $nodes += $this->left->countNodes(); if( $this->right ) $nodes += $this->right->countNodes(); } return $nodes; }
php
public function countNodes() { $nodes = 1; if( $this->left || $this->right ) { if( $this->left ) $nodes += $this->left->countNodes(); if( $this->right ) $nodes += $this->right->countNodes(); } return $nodes; }
[ "public", "function", "countNodes", "(", ")", "{", "$", "nodes", "=", "1", ";", "if", "(", "$", "this", "->", "left", "||", "$", "this", "->", "right", ")", "{", "if", "(", "$", "this", "->", "left", ")", "$", "nodes", "+=", "$", "this", "->", ...
Returns the amount of Nodes in the Tree. @access public @return int
[ "Returns", "the", "amount", "of", "Nodes", "in", "the", "Tree", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L92-L103
train
CeusMedia/Common
src/ADT/Tree/BinaryNode.php
ADT_Tree_BinaryNode.getHeight
public function getHeight() { $left_height = $this->left ? $this->left->getHeight() : 0; // Rekursiver Aufruf des linken Teilbaumes $right_height = $this->right ? $this->right->getHeight() : 0; // Rekursiver Aufruf des rechten Teilbaumes $height = max( $left_height, $right_height ); // Vergleichen welcher der beiden Teilbäume höher ist $height++; // Höhe hochzählen return $height; }
php
public function getHeight() { $left_height = $this->left ? $this->left->getHeight() : 0; // Rekursiver Aufruf des linken Teilbaumes $right_height = $this->right ? $this->right->getHeight() : 0; // Rekursiver Aufruf des rechten Teilbaumes $height = max( $left_height, $right_height ); // Vergleichen welcher der beiden Teilbäume höher ist $height++; // Höhe hochzählen return $height; }
[ "public", "function", "getHeight", "(", ")", "{", "$", "left_height", "=", "$", "this", "->", "left", "?", "$", "this", "->", "left", "->", "getHeight", "(", ")", ":", "0", ";", "// Rekursiver Aufruf des linken Teilbaumes\r", "$", "right_height", "=", "$", ...
Returns the height of the Tree. @access public @return int
[ "Returns", "the", "height", "of", "the", "Tree", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L110-L117
train
CeusMedia/Common
src/ADT/Tree/BinaryNode.php
ADT_Tree_BinaryNode.search
public function search( $value ) { if( $value == $this->value ) return $this; else if( $value < $this->value ) { if( $this->left ) return $this->left->search( $value ); } else if( $value > $this->value ) { if( $this->right ) return $this->right->search( $value ); } return NULL; }
php
public function search( $value ) { if( $value == $this->value ) return $this; else if( $value < $this->value ) { if( $this->left ) return $this->left->search( $value ); } else if( $value > $this->value ) { if( $this->right ) return $this->right->search( $value ); } return NULL; }
[ "public", "function", "search", "(", "$", "value", ")", "{", "if", "(", "$", "value", "==", "$", "this", "->", "value", ")", "return", "$", "this", ";", "else", "if", "(", "$", "value", "<", "$", "this", "->", "value", ")", "{", "if", "(", "$",...
Indicates wheter a Value can be found in the Tree. @access public @param mixed $value Value to be found in the Tree @return void
[ "Indicates", "wheter", "a", "Value", "can", "be", "found", "in", "the", "Tree", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L159-L174
train
CeusMedia/Common
src/ADT/Tree/BinaryNode.php
ADT_Tree_BinaryNode.toList
public function toList( $dir = NULL ) { $array = array(); if( !$dir || $dir == "lwr" ) { if( $this->left ) $array = array_merge( $array, $this->left->toList( $dir ) ); $array = array_merge( $array, array( $this->value ) ); if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); } else if( $dir == "rwl" ) { if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); $array = array_merge( $array, array ($this->value)); if( $this->left) $array = array_merge( $array, $this->left->toList( $dir ) ); } else if( $dir == "wlr" ) { $array = array_merge( $array, array ($this->value)); if( $this->left ) $array = array_merge( $array, $this->left->toList( $dir ) ); if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); } else if( $dir == "wrl" ) { $array = array_merge( $array, array ($this->value)); if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); if( $this->left ) $array = array_merge( $array, $this->left->toList( $dir ) ); } return $array; }
php
public function toList( $dir = NULL ) { $array = array(); if( !$dir || $dir == "lwr" ) { if( $this->left ) $array = array_merge( $array, $this->left->toList( $dir ) ); $array = array_merge( $array, array( $this->value ) ); if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); } else if( $dir == "rwl" ) { if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); $array = array_merge( $array, array ($this->value)); if( $this->left) $array = array_merge( $array, $this->left->toList( $dir ) ); } else if( $dir == "wlr" ) { $array = array_merge( $array, array ($this->value)); if( $this->left ) $array = array_merge( $array, $this->left->toList( $dir ) ); if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); } else if( $dir == "wrl" ) { $array = array_merge( $array, array ($this->value)); if( $this->right ) $array = array_merge( $array, $this->right->toList( $dir ) ); if( $this->left ) $array = array_merge( $array, $this->left->toList( $dir ) ); } return $array; }
[ "public", "function", "toList", "(", "$", "dir", "=", "NULL", ")", "{", "$", "array", "=", "array", "(", ")", ";", "if", "(", "!", "$", "dir", "||", "$", "dir", "==", "\"lwr\"", ")", "{", "if", "(", "$", "this", "->", "left", ")", "$", "array...
Runs through the Tree in any Directions and returns the Tree as List. @access public @param string $dir Direction to run through the Tree (lwr|rwl|wlr|wrl) @return array
[ "Runs", "through", "the", "Tree", "in", "any", "Directions", "and", "returns", "the", "Tree", "as", "List", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L182-L218
train
CeusMedia/Common
src/ADT/Tree/BinaryNode.php
ADT_Tree_BinaryNode.toTable
public function toTable() { $code = "<table cellspacing=1 cellpadding=0>\n<tr><td colspan=2 align=center><hr>".$this->value."</td></tr>"; if( $this->left || $this->right ) { $code .= "<tr><td align=center valign=top>"; if( $this->left ) $code .= $this->left->toTable(); else $code .= "&nbsp;"; $code .= "</td><td align=center valign=top>"; if( $this->right ) $code .= $this->right->toTable(); else $code .= "&nbsp;"; $code .= "</td></tr>\n"; } $code .= "</table>\n"; return $code; }
php
public function toTable() { $code = "<table cellspacing=1 cellpadding=0>\n<tr><td colspan=2 align=center><hr>".$this->value."</td></tr>"; if( $this->left || $this->right ) { $code .= "<tr><td align=center valign=top>"; if( $this->left ) $code .= $this->left->toTable(); else $code .= "&nbsp;"; $code .= "</td><td align=center valign=top>"; if( $this->right ) $code .= $this->right->toTable(); else $code .= "&nbsp;"; $code .= "</td></tr>\n"; } $code .= "</table>\n"; return $code; }
[ "public", "function", "toTable", "(", ")", "{", "$", "code", "=", "\"<table cellspacing=1 cellpadding=0>\\n<tr><td colspan=2 align=center><hr>\"", ".", "$", "this", "->", "value", ".", "\"</td></tr>\"", ";", "if", "(", "$", "this", "->", "left", "||", "$", "this",...
Returns the Tree as HTML-Table. @access public @return string
[ "Returns", "the", "Tree", "as", "HTML", "-", "Table", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Tree/BinaryNode.php#L225-L244
train
CeusMedia/Common
src/XML/RSS/SimpleParser.php
XML_RSS_SimpleParser.parse
public static function parse( $xml ) { $channelData = array(); $itemList = array(); $xml = new SimpleXMLElement( $xml ); foreach( $xml->channel->children() as $nodeName => $nodeValue ) { if( $nodeName == "image" && $nodeValue->children() ) { $channelData[$nodeName] = self::readSubSet( $nodeValue ); continue; } if( $nodeName == "textInput" && $nodeValue->children() ) { $channelData[$nodeName] = self::readSubSet( $nodeValue ); continue; } if( $nodeName != "item" ) { $channelData[$nodeName] = (string) $nodeValue; continue; } $item = array(); $itemNode = $nodeValue; foreach( $itemNode->children() as $nodeName => $nodeValue ) $item[$nodeName] = (string) $nodeValue; $itemList[] = $item; } $attributes = $xml->attributes(); $data = array( 'encoding' => $attributes['encoding'], 'channelData' => $channelData, 'itemList' => $itemList, ); return $data; }
php
public static function parse( $xml ) { $channelData = array(); $itemList = array(); $xml = new SimpleXMLElement( $xml ); foreach( $xml->channel->children() as $nodeName => $nodeValue ) { if( $nodeName == "image" && $nodeValue->children() ) { $channelData[$nodeName] = self::readSubSet( $nodeValue ); continue; } if( $nodeName == "textInput" && $nodeValue->children() ) { $channelData[$nodeName] = self::readSubSet( $nodeValue ); continue; } if( $nodeName != "item" ) { $channelData[$nodeName] = (string) $nodeValue; continue; } $item = array(); $itemNode = $nodeValue; foreach( $itemNode->children() as $nodeName => $nodeValue ) $item[$nodeName] = (string) $nodeValue; $itemList[] = $item; } $attributes = $xml->attributes(); $data = array( 'encoding' => $attributes['encoding'], 'channelData' => $channelData, 'itemList' => $itemList, ); return $data; }
[ "public", "static", "function", "parse", "(", "$", "xml", ")", "{", "$", "channelData", "=", "array", "(", ")", ";", "$", "itemList", "=", "array", "(", ")", ";", "$", "xml", "=", "new", "SimpleXMLElement", "(", "$", "xml", ")", ";", "foreach", "("...
Reads RSS from XML statically and returns Array containing Channel Data and Items. @access public @static @param string $xml XML String to read @return array
[ "Reads", "RSS", "from", "XML", "statically", "and", "returns", "Array", "containing", "Channel", "Data", "and", "Items", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/RSS/SimpleParser.php#L49-L84
train
CeusMedia/Common
src/XML/RSS/SimpleParser.php
XML_RSS_SimpleParser.readSubSet
protected static function readSubSet( $node ) { $item = array(); foreach( $node->children() as $nodeName => $nodeValue ) $item[$nodeName] = (string) $nodeValue; return $item; }
php
protected static function readSubSet( $node ) { $item = array(); foreach( $node->children() as $nodeName => $nodeValue ) $item[$nodeName] = (string) $nodeValue; return $item; }
[ "protected", "static", "function", "readSubSet", "(", "$", "node", ")", "{", "$", "item", "=", "array", "(", ")", ";", "foreach", "(", "$", "node", "->", "children", "(", ")", "as", "$", "nodeName", "=>", "$", "nodeValue", ")", "$", "item", "[", "$...
Reads Subset of Node. @access protected @static @param SimpleXMLElement $node Subset Node @return array
[ "Reads", "Subset", "of", "Node", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/RSS/SimpleParser.php#L93-L99
train
CeusMedia/Common
src/UI/HTML/Options.php
UI_HTML_Options.buildCode
public function buildCode() { $select = UI_HTML_Elements::Select( $this->name, $this->options, $this->class ); return $select; }
php
public function buildCode() { $select = UI_HTML_Elements::Select( $this->name, $this->options, $this->class ); return $select; }
[ "public", "function", "buildCode", "(", ")", "{", "$", "select", "=", "UI_HTML_Elements", "::", "Select", "(", "$", "this", "->", "name", ",", "$", "this", "->", "options", ",", "$", "this", "->", "class", ")", ";", "return", "$", "select", ";", "}" ...
Builds HTML Code of Select Box. @access public @return string
[ "Builds", "HTML", "Code", "of", "Select", "Box", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Options.php#L69-L73
train
CeusMedia/Common
src/UI/HTML/Options.php
UI_HTML_Options.buildScript
public function buildScript() { $options = array( 'url' => $this->url, 'async' => $this->async, 'cache' => $this->cache, 'data' => $this->data, 'selected' => $this->selected ); return UI_HTML_JQuery::buildPluginCall( 'ajaxOptions', "select[name='".$this->name."']", $options ); }
php
public function buildScript() { $options = array( 'url' => $this->url, 'async' => $this->async, 'cache' => $this->cache, 'data' => $this->data, 'selected' => $this->selected ); return UI_HTML_JQuery::buildPluginCall( 'ajaxOptions', "select[name='".$this->name."']", $options ); }
[ "public", "function", "buildScript", "(", ")", "{", "$", "options", "=", "array", "(", "'url'", "=>", "$", "this", "->", "url", ",", "'async'", "=>", "$", "this", "->", "async", ",", "'cache'", "=>", "$", "this", "->", "cache", ",", "'data'", "=>", ...
Builds JavaScript Code for AJAX Options. @access public @return string
[ "Builds", "JavaScript", "Code", "for", "AJAX", "Options", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Options.php#L80-L90
train
CeusMedia/Common
src/Alg/UnitFormater.php
Alg_UnitFormater.formatNumber
public static function formatNumber( $float, $unit = 1, $precision = 0 ) { Deprecation::getInstance()->setExceptionVersion( '0.8' ) ->message( 'Use one of the other methods instead' ); if( (int) $unit ) { $float = $float / $unit; if( is_int( $precision ) ) $float = round( $float, $precision ); } return $float; }
php
public static function formatNumber( $float, $unit = 1, $precision = 0 ) { Deprecation::getInstance()->setExceptionVersion( '0.8' ) ->message( 'Use one of the other methods instead' ); if( (int) $unit ) { $float = $float / $unit; if( is_int( $precision ) ) $float = round( $float, $precision ); } return $float; }
[ "public", "static", "function", "formatNumber", "(", "$", "float", ",", "$", "unit", "=", "1", ",", "$", "precision", "=", "0", ")", "{", "Deprecation", "::", "getInstance", "(", ")", "->", "setExceptionVersion", "(", "'0.8'", ")", "->", "message", "(", ...
Formats Number. @access public @static @param float $float Number to format @param int $unit Number of Digits for dot to move to left @param int $precision Number of Digits after dot @return void @deprecated uncomplete method, please remove
[ "Formats", "Number", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/UnitFormater.php#L239-L250
train
CeusMedia/Common
src/Alg/Sort/Bubble.php
Alg_Sort_Bubble.sort
public static function sort($list) { for( $i=sizeof( $list ) - 1; $i>=1; $i-- ) for( $j=0; $j<$i; $j++ ) if( $list[$j] > $list[$j+1] ) self::swap( $list, $j, $j + 1 ); return $list; }
php
public static function sort($list) { for( $i=sizeof( $list ) - 1; $i>=1; $i-- ) for( $j=0; $j<$i; $j++ ) if( $list[$j] > $list[$j+1] ) self::swap( $list, $j, $j + 1 ); return $list; }
[ "public", "static", "function", "sort", "(", "$", "list", ")", "{", "for", "(", "$", "i", "=", "sizeof", "(", "$", "list", ")", "-", "1", ";", "$", "i", ">=", "1", ";", "$", "i", "--", ")", "for", "(", "$", "j", "=", "0", ";", "$", "j", ...
Sorts List with Bubble Sort. @access public @static @param array $list List to sort @return array
[ "Sorts", "List", "with", "Bubble", "Sort", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Sort/Bubble.php#L48-L55
train
CeusMedia/Common
src/FS/File/JSON/Config.php
FS_File_JSON_Config.save
public function save(){ $json = $this->data->toJson(); if( $this->format ) $json = ADT_JSON_Formater::format( $json ); return FS_File_Writer::save( $this->fileName, $json ); }
php
public function save(){ $json = $this->data->toJson(); if( $this->format ) $json = ADT_JSON_Formater::format( $json ); return FS_File_Writer::save( $this->fileName, $json ); }
[ "public", "function", "save", "(", ")", "{", "$", "json", "=", "$", "this", "->", "data", "->", "toJson", "(", ")", ";", "if", "(", "$", "this", "->", "format", ")", "$", "json", "=", "ADT_JSON_Formater", "::", "format", "(", "$", "json", ")", ";...
Save node structure to JSON file. @access public @return integer Number of saved bytes
[ "Save", "node", "structure", "to", "JSON", "file", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/JSON/Config.php#L90-L95
train
CeusMedia/Common
src/Alg/Parcel/Packer.php
Alg_Parcel_Packer.calculatePackage
public function calculatePackage( $articleList ) { $this->packetList = array(); // reset Packet List foreach( $articleList as $name => $quantity ) // iterate Article List if( !$quantity ) // and remove all Articles unset( $articleList[$name] ); // without Quantity while( $articleList ) // iterate Article List { // -- ADD FIRST PACKET -- // $largestArticle = $this->getLargestArticle( $articleList ); // get Largest Article in List if( !count( $this->packetList ) ) // no Packets yet in Packet List { $packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article $packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // put Article in new Packet $this->packetList[] = $packet; // add Packet to Packet List $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List continue; // step to next Article } // -- FILL PACKET -- // $found = false; // for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List { $packet = $this->getPacket( $i ); // get current Packet $articleVolume = $this->volumes[$packet->getName()][$largestArticle]; // get Article Volume in this Packet if( $packet->hasVolumeLeft( $articleVolume ) ) // check if Article will fit in Packet { $packet->addArticle( $largestArticle, $articleVolume ); // put Article in Packet $found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article From Article List break; // break Packet Loop } } if( $found ) // Article has been put into a Packet continue; // step to next Article // -- RESIZE PACKET -- // for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List { $packet = $this->getPacket( $i ); // get current Packet while( $this->hasLargerPacket( $packet->getName() ) ) // there is a larger Packet Type { $largerPacketName = $this->getNameOfLargerPacket( $packet->getName() ); $articles = $packet->getArticles(); // get larger Packet $largerPacket = $this->factory->produce( $largerPacketName, $articles ); // produce new Packet and add Articles from old Packet $articleVolume = $this->volumes[$largerPacketName][$largestArticle]; // get Volume of current Article in this Packet if( $largerPacket->hasVolumeLeft( $articleVolume ) ) { $largerPacket->addArticle( $largestArticle, $articleVolume ); // add Article to Packet $this->replacePacket( $i, $largerPacket ); // replace old Packet with new Packet $found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List break; // break Packet Loop } } if( $found ) // Article has been put into a Packet continue; // break Packet Loop } if( $found ) // Article has been put into a Packet continue; // step to next Article // -- ADD NEW PACKET -- // $packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article $packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // produce new Packet and put Article in $this->packetList[] = $packet; // add Packet to Packet List $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List } return $this->packetList; // return final Packet List with Articles }
php
public function calculatePackage( $articleList ) { $this->packetList = array(); // reset Packet List foreach( $articleList as $name => $quantity ) // iterate Article List if( !$quantity ) // and remove all Articles unset( $articleList[$name] ); // without Quantity while( $articleList ) // iterate Article List { // -- ADD FIRST PACKET -- // $largestArticle = $this->getLargestArticle( $articleList ); // get Largest Article in List if( !count( $this->packetList ) ) // no Packets yet in Packet List { $packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article $packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // put Article in new Packet $this->packetList[] = $packet; // add Packet to Packet List $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List continue; // step to next Article } // -- FILL PACKET -- // $found = false; // for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List { $packet = $this->getPacket( $i ); // get current Packet $articleVolume = $this->volumes[$packet->getName()][$largestArticle]; // get Article Volume in this Packet if( $packet->hasVolumeLeft( $articleVolume ) ) // check if Article will fit in Packet { $packet->addArticle( $largestArticle, $articleVolume ); // put Article in Packet $found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article From Article List break; // break Packet Loop } } if( $found ) // Article has been put into a Packet continue; // step to next Article // -- RESIZE PACKET -- // for( $i=0; $i<count( $this->packetList ); $i++ ) // iterate Packets in Packet List { $packet = $this->getPacket( $i ); // get current Packet while( $this->hasLargerPacket( $packet->getName() ) ) // there is a larger Packet Type { $largerPacketName = $this->getNameOfLargerPacket( $packet->getName() ); $articles = $packet->getArticles(); // get larger Packet $largerPacket = $this->factory->produce( $largerPacketName, $articles ); // produce new Packet and add Articles from old Packet $articleVolume = $this->volumes[$largerPacketName][$largestArticle]; // get Volume of current Article in this Packet if( $largerPacket->hasVolumeLeft( $articleVolume ) ) { $largerPacket->addArticle( $largestArticle, $articleVolume ); // add Article to Packet $this->replacePacket( $i, $largerPacket ); // replace old Packet with new Packet $found = $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List break; // break Packet Loop } } if( $found ) // Article has been put into a Packet continue; // break Packet Loop } if( $found ) // Article has been put into a Packet continue; // step to next Article // -- ADD NEW PACKET -- // $packetName = $this->getNameOfSmallestPacketForArticle( $largestArticle ); // get smallest Packet Type for Article $packet = $this->factory->produce( $packetName, array( $largestArticle => 1 ) ); // produce new Packet and put Article in $this->packetList[] = $packet; // add Packet to Packet List $this->removeArticleFromList( $articleList, $largestArticle ); // remove Article from Article List } return $this->packetList; // return final Packet List with Articles }
[ "public", "function", "calculatePackage", "(", "$", "articleList", ")", "{", "$", "this", "->", "packetList", "=", "array", "(", ")", ";", "// reset Packet List", "foreach", "(", "$", "articleList", "as", "$", "name", "=>", "$", "quantity", ")", "// iterat...
Calculates Packages for Articles and returns Packet List. @access public @param array $articleList Array of Articles and their Quantities. @return array
[ "Calculates", "Packages", "for", "Articles", "and", "returns", "Packet", "List", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L75-L142
train
CeusMedia/Common
src/Alg/Parcel/Packer.php
Alg_Parcel_Packer.getLargestArticle
protected function getLargestArticle( $articleList ) { $largestPacketName = $this->getNameOfLargestPacket(); $articleVolumes = $this->volumes[$largestPacketName]; asort( $articleVolumes ); $articleKeys = array_keys( $articleVolumes ); do { $articleName = array_pop( $articleKeys ); if( array_key_exists( $articleName, $articleList ) ) return $articleName; } while( $articleKeys ); }
php
protected function getLargestArticle( $articleList ) { $largestPacketName = $this->getNameOfLargestPacket(); $articleVolumes = $this->volumes[$largestPacketName]; asort( $articleVolumes ); $articleKeys = array_keys( $articleVolumes ); do { $articleName = array_pop( $articleKeys ); if( array_key_exists( $articleName, $articleList ) ) return $articleName; } while( $articleKeys ); }
[ "protected", "function", "getLargestArticle", "(", "$", "articleList", ")", "{", "$", "largestPacketName", "=", "$", "this", "->", "getNameOfLargestPacket", "(", ")", ";", "$", "articleVolumes", "=", "$", "this", "->", "volumes", "[", "$", "largestPacketName", ...
Returns the largest Article from an Article List by Article Volume. @access protected @param array $articleList Array of Articles and their Quantities. @return string
[ "Returns", "the", "largest", "Article", "from", "an", "Article", "List", "by", "Article", "Volume", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L177-L190
train
CeusMedia/Common
src/Alg/Parcel/Packer.php
Alg_Parcel_Packer.getNameOfLargerPacket
protected function getNameOfLargerPacket( $packetName ) { $keys = array_keys( $this->packets ); $index = array_search( $packetName, $keys ); $next = array_pop( array_slice( $keys, $index + 1, 1 ) ); return $next; }
php
protected function getNameOfLargerPacket( $packetName ) { $keys = array_keys( $this->packets ); $index = array_search( $packetName, $keys ); $next = array_pop( array_slice( $keys, $index + 1, 1 ) ); return $next; }
[ "protected", "function", "getNameOfLargerPacket", "(", "$", "packetName", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "this", "->", "packets", ")", ";", "$", "index", "=", "array_search", "(", "$", "packetName", ",", "$", "keys", ")", ";", "$", ...
Returns Name of next larger Packet. @access protected @param string $packetName Packet Name to get next larger Packet for @return string
[ "Returns", "Name", "of", "next", "larger", "Packet", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L198-L204
train
CeusMedia/Common
src/Alg/Parcel/Packer.php
Alg_Parcel_Packer.getNameOfLargestPacket
protected function getNameOfLargestPacket() { $packets = $this->packets; asort( $packets ); $packetName = key( array_slice( $packets, -1 ) ); return $packetName; }
php
protected function getNameOfLargestPacket() { $packets = $this->packets; asort( $packets ); $packetName = key( array_slice( $packets, -1 ) ); return $packetName; }
[ "protected", "function", "getNameOfLargestPacket", "(", ")", "{", "$", "packets", "=", "$", "this", "->", "packets", ";", "asort", "(", "$", "packets", ")", ";", "$", "packetName", "=", "key", "(", "array_slice", "(", "$", "packets", ",", "-", "1", ")"...
Returns Name of largest Packet from Packet Definition. @access protected @return string
[ "Returns", "Name", "of", "largest", "Packet", "from", "Packet", "Definition", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L211-L217
train
CeusMedia/Common
src/Alg/Parcel/Packer.php
Alg_Parcel_Packer.getNameOfSmallestPacketForArticle
protected function getNameOfSmallestPacketForArticle( $articleName ) { foreach( array_keys( $this->packets ) as $packetName ) if( $this->volumes[$packetName][$articleName] <= 1 ) return $packetName; }
php
protected function getNameOfSmallestPacketForArticle( $articleName ) { foreach( array_keys( $this->packets ) as $packetName ) if( $this->volumes[$packetName][$articleName] <= 1 ) return $packetName; }
[ "protected", "function", "getNameOfSmallestPacketForArticle", "(", "$", "articleName", ")", "{", "foreach", "(", "array_keys", "(", "$", "this", "->", "packets", ")", "as", "$", "packetName", ")", "if", "(", "$", "this", "->", "volumes", "[", "$", "packetNam...
Returns Name of smallest Packet for an Article. @access protected @param string $articleName Name of Article to get smallest Article for @return string
[ "Returns", "Name", "of", "smallest", "Packet", "for", "an", "Article", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L225-L230
train
CeusMedia/Common
src/Alg/Parcel/Packer.php
Alg_Parcel_Packer.replacePacket
public function replacePacket( $index, $packet ) { if( !isset( $this->packetList[$index] ) ) throw new OutOfRangeException( 'Invalid Packet Index.' ); $this->packetList[$index] = $packet; }
php
public function replacePacket( $index, $packet ) { if( !isset( $this->packetList[$index] ) ) throw new OutOfRangeException( 'Invalid Packet Index.' ); $this->packetList[$index] = $packet; }
[ "public", "function", "replacePacket", "(", "$", "index", ",", "$", "packet", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "packetList", "[", "$", "index", "]", ")", ")", "throw", "new", "OutOfRangeException", "(", "'Invalid Packet Index.'", ...
Replaces a Packet from current Packet List with another Packet. @access public @param int $index Index of Packet to replace @param Alg_Parcel_packet $packet Packet to set for another Packet @return void
[ "Replaces", "a", "Packet", "from", "current", "Packet", "List", "with", "another", "Packet", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Parcel/Packer.php#L278-L283
train
CeusMedia/Common
src/XML/OPML/FileReader.php
XML_OPML_FileReader.load
public static function load( $fileName ) { $file = new FS_File_Reader( $fileName ); if( !$file->exists() ) throw new Exception( "File '".$fileName."' is not existing." ); $xml = $file->readString(); $parser = new XML_OPML_Parser(); return $parser->parse( $xml ); }
php
public static function load( $fileName ) { $file = new FS_File_Reader( $fileName ); if( !$file->exists() ) throw new Exception( "File '".$fileName."' is not existing." ); $xml = $file->readString(); $parser = new XML_OPML_Parser(); return $parser->parse( $xml ); }
[ "public", "static", "function", "load", "(", "$", "fileName", ")", "{", "$", "file", "=", "new", "FS_File_Reader", "(", "$", "fileName", ")", ";", "if", "(", "!", "$", "file", "->", "exists", "(", ")", ")", "throw", "new", "Exception", "(", "\"File '...
Loads a OPML File statically. @access public @static @param string $fileName URI of OPML File @return bool
[ "Loads", "a", "OPML", "File", "statically", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/OPML/FileReader.php#L62-L70
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parse
public function parse(){ $where = $order = $group = $limit = $q = ''; $source = $this->parseSource(); if($this->stmt->getConditions()) $where = $this->parseWhere(); if($this->stmt instanceof Result && $this->stmt->getGrouping()) $group = $this->parseGrouping(); if($this->stmt->getSorting()) $order = $this->parseSorting(); $this->clauses = array($source, $where, $group, $order); if($this->stmt->getType() === Manager::STMT_SELECT) $q = $this->parseSelectStmt(); elseif($this->stmt->getType() === Manager::STMT_INSERT) $q = $this->parseInsertStmt(); elseif($this->stmt->getType() === Manager::STMT_UPDATE) $q = $this->parseUpdateStmt(); elseif($this->stmt->getType() === Manager::STMT_DELETE) $q = $this->parseDeleteStmt(); return trim($q); }
php
public function parse(){ $where = $order = $group = $limit = $q = ''; $source = $this->parseSource(); if($this->stmt->getConditions()) $where = $this->parseWhere(); if($this->stmt instanceof Result && $this->stmt->getGrouping()) $group = $this->parseGrouping(); if($this->stmt->getSorting()) $order = $this->parseSorting(); $this->clauses = array($source, $where, $group, $order); if($this->stmt->getType() === Manager::STMT_SELECT) $q = $this->parseSelectStmt(); elseif($this->stmt->getType() === Manager::STMT_INSERT) $q = $this->parseInsertStmt(); elseif($this->stmt->getType() === Manager::STMT_UPDATE) $q = $this->parseUpdateStmt(); elseif($this->stmt->getType() === Manager::STMT_DELETE) $q = $this->parseDeleteStmt(); return trim($q); }
[ "public", "function", "parse", "(", ")", "{", "$", "where", "=", "$", "order", "=", "$", "group", "=", "$", "limit", "=", "$", "q", "=", "''", ";", "$", "source", "=", "$", "this", "->", "parseSource", "(", ")", ";", "if", "(", "$", "this", "...
Parses the given statement. @return string The SQL statement
[ "Parses", "the", "given", "statement", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L45-L68
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parseSelectStmt
protected function parseSelectStmt(){ $cols = $this->stmt->getColumns(); list($source, $where, $group, $order) = $this->clauses; foreach($cols as $key => $col){ $col = preg_match('~^[\w.]+$~', $col) ? ":$col" : $col; $cols[$key] = $this->tryDelimite($col); } $cols = implode(', ', $cols); return $this->applyLimit("SELECT $cols\nFROM " . $source . $where . $group . $order); }
php
protected function parseSelectStmt(){ $cols = $this->stmt->getColumns(); list($source, $where, $group, $order) = $this->clauses; foreach($cols as $key => $col){ $col = preg_match('~^[\w.]+$~', $col) ? ":$col" : $col; $cols[$key] = $this->tryDelimite($col); } $cols = implode(', ', $cols); return $this->applyLimit("SELECT $cols\nFROM " . $source . $where . $group . $order); }
[ "protected", "function", "parseSelectStmt", "(", ")", "{", "$", "cols", "=", "$", "this", "->", "stmt", "->", "getColumns", "(", ")", ";", "list", "(", "$", "source", ",", "$", "where", ",", "$", "group", ",", "$", "order", ")", "=", "$", "this", ...
Parses SELECT statement. @return string
[ "Parses", "SELECT", "statement", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L75-L85
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parseInsertStmt
protected function parseInsertStmt(){ $cols = array(); foreach($this->escapeValue($this->stmt->getValues()) as $col => $value){ $cols[] = $this->parseFieldName($col); $values[] = $value; } $data = ' (' . implode(', ', $cols) . ")\nVALUES (" . implode(', ', $values). ')'; return 'INSERT INTO ' . $this->clauses[0] . $data; }
php
protected function parseInsertStmt(){ $cols = array(); foreach($this->escapeValue($this->stmt->getValues()) as $col => $value){ $cols[] = $this->parseFieldName($col); $values[] = $value; } $data = ' (' . implode(', ', $cols) . ")\nVALUES (" . implode(', ', $values). ')'; return 'INSERT INTO ' . $this->clauses[0] . $data; }
[ "protected", "function", "parseInsertStmt", "(", ")", "{", "$", "cols", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "escapeValue", "(", "$", "this", "->", "stmt", "->", "getValues", "(", ")", ")", "as", "$", "col", "=>", "$", "v...
Parses INSERT statement. @return string
[ "Parses", "INSERT", "statement", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L92-L101
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parseSource
protected function parseSource(){ if(!$this->stmt instanceof Result) return $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER); // Simple table if($this->stmt->getTable() !== null){ $source = $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER); } // Sub-select else{ $subq = $this->stmt->getSource(); $alias = $this->escapeValue($subq->getAlias() ? $subq->getAlias() : '_table_', Manager::IDENTIFIER); $source = "(\n\t" . implode("\n\t", explode("\n", $subq)) . "\n) $alias"; } $source = $this->tryDelimite($source); // JOINs foreach($this->stmt->getJoins() as $key => $join){ list($join_source, $cond, $type) = $join; // JOIN sub-select if($join_source instanceof Result){ $join_alias = $this->escapeValue($join_source->getAlias() ? $join_source->getAlias() : '_join_' . ($key+1), Manager::IDENTIFIER); $join_source = "(\n\t" . implode("\n\t", explode("\n", $join_source)) . "\n) $join_alias"; } // JOIN Literal elseif($join_source instanceof Literal){ $join_source = $join_source->value; } // JOIN table elseif(is_scalar($join_source)){ $join_source = $this->parseFieldName($join_source, true); } $type = strtoupper(substr($type, 5)); $type .= ($type === '') ? '' : ' '; $source .= $cond instanceof Literal ? "\n{$type}JOIN $join_source ON $cond->value" : $this->tryDelimite("\n{$type}JOIN $join_source ON $cond"); } return $source; }
php
protected function parseSource(){ if(!$this->stmt instanceof Result) return $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER); // Simple table if($this->stmt->getTable() !== null){ $source = $this->escapeValue($this->stmt->getTable(), Manager::IDENTIFIER); } // Sub-select else{ $subq = $this->stmt->getSource(); $alias = $this->escapeValue($subq->getAlias() ? $subq->getAlias() : '_table_', Manager::IDENTIFIER); $source = "(\n\t" . implode("\n\t", explode("\n", $subq)) . "\n) $alias"; } $source = $this->tryDelimite($source); // JOINs foreach($this->stmt->getJoins() as $key => $join){ list($join_source, $cond, $type) = $join; // JOIN sub-select if($join_source instanceof Result){ $join_alias = $this->escapeValue($join_source->getAlias() ? $join_source->getAlias() : '_join_' . ($key+1), Manager::IDENTIFIER); $join_source = "(\n\t" . implode("\n\t", explode("\n", $join_source)) . "\n) $join_alias"; } // JOIN Literal elseif($join_source instanceof Literal){ $join_source = $join_source->value; } // JOIN table elseif(is_scalar($join_source)){ $join_source = $this->parseFieldName($join_source, true); } $type = strtoupper(substr($type, 5)); $type .= ($type === '') ? '' : ' '; $source .= $cond instanceof Literal ? "\n{$type}JOIN $join_source ON $cond->value" : $this->tryDelimite("\n{$type}JOIN $join_source ON $cond"); } return $source; }
[ "protected", "function", "parseSource", "(", ")", "{", "if", "(", "!", "$", "this", "->", "stmt", "instanceof", "Result", ")", "return", "$", "this", "->", "escapeValue", "(", "$", "this", "->", "stmt", "->", "getTable", "(", ")", ",", "Manager", "::",...
Parses statement source. @return string
[ "Parses", "statement", "source", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L133-L176
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parseWhere
protected function parseWhere(){ $conds = $this->stmt->getConditions(); // Unset glue on last condition unset($conds[count($conds)-1]['glue']); $conditions = array(); foreach($conds as $cond){ // Conditions with modifiers if($cond['simple'] === false){ $values = $this->escapeValue($cond['values'], $cond['types']); $s = '(' . $this->applyModifiers($cond['expr'], $cond['modifiers'], $values) . ')'; if(isset($cond['glue'])) $s .= ' ' . $cond['glue']; $conditions[] = $s; continue; } // Simple conditions $field = $this->parseFieldName($cond['field']); $operator = ''; $value = $cond['value']; if($value === null){ // field IS NULL $value = ' IS NULL'; } elseif($value === true){ // field $value = ''; } elseif($value === false){ // NOT field $value = $field; $field = 'NOT '; } elseif($value instanceof Result){ $operator = ' IN '; $value = $this->escapeValue($value, Manager::SUBQUERY); } elseif(is_array($value) || $value instanceof Traversable){ // field IN (array) $value = ' IN ' . $this->escapeValue($value, Manager::ARR); } elseif($value instanceof Literal){ // field = SQL literal $operator = ' = '; $value = $this->escapeValue($value, Manager::LITERAL); } elseif($value instanceof DateTime){ // field = DateTime $operator = ' = '; $value = $this->escapeValue($value, Manager::DATETIME); } else{ // field = value $operator = ' = '; $value = $this->escapeValue($value); } $s = '(' . $field . $operator . $value . ')'; if(isset($cond['glue'])) $s .= ' '.$cond['glue']; $conditions[] = $s; } return "\nWHERE " . implode(' ', $conditions); }
php
protected function parseWhere(){ $conds = $this->stmt->getConditions(); // Unset glue on last condition unset($conds[count($conds)-1]['glue']); $conditions = array(); foreach($conds as $cond){ // Conditions with modifiers if($cond['simple'] === false){ $values = $this->escapeValue($cond['values'], $cond['types']); $s = '(' . $this->applyModifiers($cond['expr'], $cond['modifiers'], $values) . ')'; if(isset($cond['glue'])) $s .= ' ' . $cond['glue']; $conditions[] = $s; continue; } // Simple conditions $field = $this->parseFieldName($cond['field']); $operator = ''; $value = $cond['value']; if($value === null){ // field IS NULL $value = ' IS NULL'; } elseif($value === true){ // field $value = ''; } elseif($value === false){ // NOT field $value = $field; $field = 'NOT '; } elseif($value instanceof Result){ $operator = ' IN '; $value = $this->escapeValue($value, Manager::SUBQUERY); } elseif(is_array($value) || $value instanceof Traversable){ // field IN (array) $value = ' IN ' . $this->escapeValue($value, Manager::ARR); } elseif($value instanceof Literal){ // field = SQL literal $operator = ' = '; $value = $this->escapeValue($value, Manager::LITERAL); } elseif($value instanceof DateTime){ // field = DateTime $operator = ' = '; $value = $this->escapeValue($value, Manager::DATETIME); } else{ // field = value $operator = ' = '; $value = $this->escapeValue($value); } $s = '(' . $field . $operator . $value . ')'; if(isset($cond['glue'])) $s .= ' '.$cond['glue']; $conditions[] = $s; } return "\nWHERE " . implode(' ', $conditions); }
[ "protected", "function", "parseWhere", "(", ")", "{", "$", "conds", "=", "$", "this", "->", "stmt", "->", "getConditions", "(", ")", ";", "// Unset glue on last condition", "unset", "(", "$", "conds", "[", "count", "(", "$", "conds", ")", "-", "1", "]", ...
Parses WHERE clause. @return string
[ "Parses", "WHERE", "clause", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L183-L238
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parseSorting
protected function parseSorting(){ $order = array(); foreach($this->stmt->getSorting() as $rule){ list($field, $type) = $rule; $order[] = $this->tryDelimite($field) . ($type !== null ? ' ' . $type : ''); } return "\nORDER BY " . implode(', ', $order); }
php
protected function parseSorting(){ $order = array(); foreach($this->stmt->getSorting() as $rule){ list($field, $type) = $rule; $order[] = $this->tryDelimite($field) . ($type !== null ? ' ' . $type : ''); } return "\nORDER BY " . implode(', ', $order); }
[ "protected", "function", "parseSorting", "(", ")", "{", "$", "order", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "stmt", "->", "getSorting", "(", ")", "as", "$", "rule", ")", "{", "list", "(", "$", "field", ",", "$", "type", ...
Parses ORDER BY clause. @return string
[ "Parses", "ORDER", "BY", "clause", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L245-L252
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parseGrouping
protected function parseGrouping(){ list($group, $having) = $this->stmt->getGrouping(); return $this->tryDelimite("\nGROUP BY $group" . ($having !== null ? " HAVING $having" : '')); }
php
protected function parseGrouping(){ list($group, $having) = $this->stmt->getGrouping(); return $this->tryDelimite("\nGROUP BY $group" . ($having !== null ? " HAVING $having" : '')); }
[ "protected", "function", "parseGrouping", "(", ")", "{", "list", "(", "$", "group", ",", "$", "having", ")", "=", "$", "this", "->", "stmt", "->", "getGrouping", "(", ")", ";", "return", "$", "this", "->", "tryDelimite", "(", "\"\\nGROUP BY $group\"", "....
Parses GROUP BY clause. @return string
[ "Parses", "GROUP", "BY", "clause", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L259-L262
train
smasty/Neevo
src/Neevo/Parser.php
Parser.parseFieldName
protected function parseFieldName($field, $table = false){ // preg_replace callback behaviour if(is_array($field)) $field = $field[0]; if($field instanceof Literal) return $field->value; $field = trim($field); if($field === '*') return $field; if(strpos($field, ' ')) return $field; $field = str_replace(':', '', $field); if(strpos($field, '.') !== false || $table === true){ $prefix = $this->stmt->getConnection()->getPrefix(); $field = $prefix . $field; } return $this->stmt->getConnection()->getDriver()->escape($field, Manager::IDENTIFIER); }
php
protected function parseFieldName($field, $table = false){ // preg_replace callback behaviour if(is_array($field)) $field = $field[0]; if($field instanceof Literal) return $field->value; $field = trim($field); if($field === '*') return $field; if(strpos($field, ' ')) return $field; $field = str_replace(':', '', $field); if(strpos($field, '.') !== false || $table === true){ $prefix = $this->stmt->getConnection()->getPrefix(); $field = $prefix . $field; } return $this->stmt->getConnection()->getDriver()->escape($field, Manager::IDENTIFIER); }
[ "protected", "function", "parseFieldName", "(", "$", "field", ",", "$", "table", "=", "false", ")", "{", "// preg_replace callback behaviour", "if", "(", "is_array", "(", "$", "field", ")", ")", "$", "field", "=", "$", "field", "[", "0", "]", ";", "if", ...
Parses column name. @param string|array|Literal $field @param bool $table Parse table name. @return string
[ "Parses", "column", "name", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L271-L294
train
smasty/Neevo
src/Neevo/Parser.php
Parser.applyModifiers
protected function applyModifiers($expr, array $modifiers, array $values){ foreach($modifiers as &$mod){ $mod = preg_quote("/$mod/"); } $expr = $this->tryDelimite($expr); return preg_replace($modifiers, $values, $expr, 1); }
php
protected function applyModifiers($expr, array $modifiers, array $values){ foreach($modifiers as &$mod){ $mod = preg_quote("/$mod/"); } $expr = $this->tryDelimite($expr); return preg_replace($modifiers, $values, $expr, 1); }
[ "protected", "function", "applyModifiers", "(", "$", "expr", ",", "array", "$", "modifiers", ",", "array", "$", "values", ")", "{", "foreach", "(", "$", "modifiers", "as", "&", "$", "mod", ")", "{", "$", "mod", "=", "preg_quote", "(", "\"/$mod/\"", ")"...
Applies modifiers to expression. @param string $expr @param array $modifiers @param array $values @return string
[ "Applies", "modifiers", "to", "expression", "." ]
3a1bf7e8ce24d453bb27dca3a9aca86852789f11
https://github.com/smasty/Neevo/blob/3a1bf7e8ce24d453bb27dca3a9aca86852789f11/src/Neevo/Parser.php#L383-L389
train
CeusMedia/Common
src/UI/HTML/Tree/FolderView.php
UI_HTML_Tree_FolderView.getHtml
public function getHtml( $currentId, $attributes = array(), $linkNodes = FALSE, $classNode = "folder", $classLeaf = "file" ) { $nodes = new ArrayObject(); $this->readRecursive( $this->path, $currentId, $nodes, $linkNodes, $classNode, $classLeaf ); return $this->view->constructTree( $nodes, $currentId, $attributes ); }
php
public function getHtml( $currentId, $attributes = array(), $linkNodes = FALSE, $classNode = "folder", $classLeaf = "file" ) { $nodes = new ArrayObject(); $this->readRecursive( $this->path, $currentId, $nodes, $linkNodes, $classNode, $classLeaf ); return $this->view->constructTree( $nodes, $currentId, $attributes ); }
[ "public", "function", "getHtml", "(", "$", "currentId", ",", "$", "attributes", "=", "array", "(", ")", ",", "$", "linkNodes", "=", "FALSE", ",", "$", "classNode", "=", "\"folder\"", ",", "$", "classLeaf", "=", "\"file\"", ")", "{", "$", "nodes", "=", ...
Returns HTML Code of Tree. @access public @param string $currentId ID current selected in Tree @param array $attributes Attributes for List Tag @param string $linkNodes Link Nodes (no Icons possible) @param string $classNode CSS Class of Nodes / Folders @param string $classLeaf CSS Class of Leafes / Files @return string
[ "Returns", "HTML", "Code", "of", "Tree", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderView.php#L72-L77
train
CeusMedia/Common
src/UI/HTML/Tree/FolderView.php
UI_HTML_Tree_FolderView.getScript
public function getScript( $selector, $cookieId = NULL, $animated = "fast", $unique = FALSE, $collapsed = FALSE ) { return $this->view->buildJavaScript( $selector, $cookieId, $animated, $unique, $collapsed ); }
php
public function getScript( $selector, $cookieId = NULL, $animated = "fast", $unique = FALSE, $collapsed = FALSE ) { return $this->view->buildJavaScript( $selector, $cookieId, $animated, $unique, $collapsed ); }
[ "public", "function", "getScript", "(", "$", "selector", ",", "$", "cookieId", "=", "NULL", ",", "$", "animated", "=", "\"fast\"", ",", "$", "unique", "=", "FALSE", ",", "$", "collapsed", "=", "FALSE", ")", "{", "return", "$", "this", "->", "view", "...
Returns JavaScript Code to call Plugin. @access public @param string $selector JQuery Selector of Tree @param string $cookieId Store Tree in Cookie @param string $animated Speed of Animation (fast|slow) @param bool $unique Flag: open only 1 Node in every Level @param bool $collapsed Flag: start with collapsed Nodes @return string
[ "Returns", "JavaScript", "Code", "to", "call", "Plugin", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderView.php#L89-L92
train
CeusMedia/Common
src/UI/HTML/Tree/FolderView.php
UI_HTML_Tree_FolderView.readRecursive
protected function readRecursive( $path, $currentId, &$nodes, $linkNodes, $classNode = "folder", $classLeaf = "file" ) { $files = array(); $index = new DirectoryIterator( $path ); foreach( $index as $file ) { if( $file->isDot() ) continue; if( preg_match( "@^\.\w@", $file->getFilename() ) ) continue; if( $file->isDir() ) { $children = array(); $this->readRecursive( $file->getPathname(), $currentId, $children, $linkNodes, $classNode, $classLeaf ); $dir = array( 'label' => basename( $file->getPathname() ), 'type' => "node", 'class' => $classNode, 'linked' => $linkNodes, 'children' => $children, ); $nodes[] = $dir; } else { $classes = array(); $info = pathinfo( $file->getFilename() ); if( $classLeaf ) $classes[] = $classLeaf; if( isset( $info['extension'] ) ) $classes[] = "file-".strtolower( $info['extension'] ); $classes = implode( " ", $classes ); $files[] = array( 'label' => $file->getFilename(), 'type' => "leaf", 'class' => $classes, 'linked' => TRUE, ); } } foreach( $files as $file ) $nodes[] = $file; }
php
protected function readRecursive( $path, $currentId, &$nodes, $linkNodes, $classNode = "folder", $classLeaf = "file" ) { $files = array(); $index = new DirectoryIterator( $path ); foreach( $index as $file ) { if( $file->isDot() ) continue; if( preg_match( "@^\.\w@", $file->getFilename() ) ) continue; if( $file->isDir() ) { $children = array(); $this->readRecursive( $file->getPathname(), $currentId, $children, $linkNodes, $classNode, $classLeaf ); $dir = array( 'label' => basename( $file->getPathname() ), 'type' => "node", 'class' => $classNode, 'linked' => $linkNodes, 'children' => $children, ); $nodes[] = $dir; } else { $classes = array(); $info = pathinfo( $file->getFilename() ); if( $classLeaf ) $classes[] = $classLeaf; if( isset( $info['extension'] ) ) $classes[] = "file-".strtolower( $info['extension'] ); $classes = implode( " ", $classes ); $files[] = array( 'label' => $file->getFilename(), 'type' => "leaf", 'class' => $classes, 'linked' => TRUE, ); } } foreach( $files as $file ) $nodes[] = $file; }
[ "protected", "function", "readRecursive", "(", "$", "path", ",", "$", "currentId", ",", "&", "$", "nodes", ",", "$", "linkNodes", ",", "$", "classNode", "=", "\"folder\"", ",", "$", "classLeaf", "=", "\"file\"", ")", "{", "$", "files", "=", "array", "(...
Reads Folder recursive. @access protected @param string $path Path to Folder to index @param string $currentId ID current selected in Tree @param ArrayObject $nodes Array Object of Folders and Files @param string $linkNodes Link Nodes (no Icons possible) @param string $classNode CSS Class of Nodes / Folders @param string $classLeaf CSS Class of Leafes / Files @return void
[ "Reads", "Folder", "recursive", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderView.php#L105-L147
train
CeusMedia/Common
src/FS/File/CSS/Combiner.php
FS_File_CSS_Combiner.combineFile
public function combineFile( $fileUri ) { $pathName = dirname( realpath( $fileUri ) )."/"; $fileBase = preg_replace( "@\.css@", "", basename( $fileUri )); if( !file_exists( $fileUri ) ) throw new Exception( "Style File '".$fileUri."' is not existing." ); $this->statistics = array(); $content = file_get_contents( $fileUri ); $content = $this->combineString( $pathName, $content ); $fileName = $this->prefix.$fileBase.$this->suffix.".css"; $fileUri = $pathName.$fileName; $fileUri = str_replace( "\\", "/", $fileUri ); file_put_contents( $fileUri, $content ); return $fileUri; }
php
public function combineFile( $fileUri ) { $pathName = dirname( realpath( $fileUri ) )."/"; $fileBase = preg_replace( "@\.css@", "", basename( $fileUri )); if( !file_exists( $fileUri ) ) throw new Exception( "Style File '".$fileUri."' is not existing." ); $this->statistics = array(); $content = file_get_contents( $fileUri ); $content = $this->combineString( $pathName, $content ); $fileName = $this->prefix.$fileBase.$this->suffix.".css"; $fileUri = $pathName.$fileName; $fileUri = str_replace( "\\", "/", $fileUri ); file_put_contents( $fileUri, $content ); return $fileUri; }
[ "public", "function", "combineFile", "(", "$", "fileUri", ")", "{", "$", "pathName", "=", "dirname", "(", "realpath", "(", "$", "fileUri", ")", ")", ".", "\"/\"", ";", "$", "fileBase", "=", "preg_replace", "(", "\"@\\.css@\"", ",", "\"\"", ",", "basename...
Combines all CSS Files imported in Style File, saves Combination File and returns File URI of Combination File. @access public @param string $styleFile File Name of Style without Extension (iE. style.css,import.css,default.css) @param bool $verbose Flag: list loaded CSS Files @return string
[ "Combines", "all", "CSS", "Files", "imported", "in", "Style", "File", "saves", "Combination", "File", "and", "returns", "File", "URI", "of", "Combination", "File", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Combiner.php#L58-L76
train
CeusMedia/Common
src/FS/File/CSS/Combiner.php
FS_File_CSS_Combiner.combineString
public function combineString( $path, $content, $throwException = FALSE ) { $listLines = array(); $listImport = array(); $this->statistics['sizeOriginal'] = 0; $this->statistics['sizeCombined'] = 0; $this->statistics['sizeCompressed'] = 0; $this->statistics['numberFiles'] = 0; $this->statistics['filesFound'] = array(); $this->statistics['filesSkipped'] = array(); $content = preg_replace( '/\/\*.+\*\//sU', '', $content ); $lines = explode( "\n", $content ); foreach( $lines as $line ) { $line = trim( $line ); if( !$line ) continue; if( preg_match( $this->importPattern, $line ) ) { preg_match_all( $this->importPattern, $line, $matches ); $fileName = $matches[2][0]; $this->statistics['filesFound'][] = $fileName; if( !file_exists( $path.$fileName ) ) { if( $throwException ) throw new RuntimeException( 'CSS File "'.$fileName.'" is not existing.' ); $this->statistics['filesSkipped'][] = $fileName; continue; } $content = file_get_contents( $path.$fileName ); $content = $this->reviseStyle( $content ); $this->statistics['numberFiles'] ++; $this->statistics['sizeOriginal'] += strlen( $content ); // $depth = substr if( substr_count( $fileName, "/" ) ) $content = preg_replace( "@(\.\./){1}([^\.])@i", "\\2", $content ); $listImport[] = "/* -- ".$fileName." -- */"; $listImport[] = $content."\n"; } else $listLines[] = $line; } $content = implode( "\n", $listImport ).implode( "\n", $listLines ); $this->statistics['sizeCombined'] = strlen( $content ); return $content; }
php
public function combineString( $path, $content, $throwException = FALSE ) { $listLines = array(); $listImport = array(); $this->statistics['sizeOriginal'] = 0; $this->statistics['sizeCombined'] = 0; $this->statistics['sizeCompressed'] = 0; $this->statistics['numberFiles'] = 0; $this->statistics['filesFound'] = array(); $this->statistics['filesSkipped'] = array(); $content = preg_replace( '/\/\*.+\*\//sU', '', $content ); $lines = explode( "\n", $content ); foreach( $lines as $line ) { $line = trim( $line ); if( !$line ) continue; if( preg_match( $this->importPattern, $line ) ) { preg_match_all( $this->importPattern, $line, $matches ); $fileName = $matches[2][0]; $this->statistics['filesFound'][] = $fileName; if( !file_exists( $path.$fileName ) ) { if( $throwException ) throw new RuntimeException( 'CSS File "'.$fileName.'" is not existing.' ); $this->statistics['filesSkipped'][] = $fileName; continue; } $content = file_get_contents( $path.$fileName ); $content = $this->reviseStyle( $content ); $this->statistics['numberFiles'] ++; $this->statistics['sizeOriginal'] += strlen( $content ); // $depth = substr if( substr_count( $fileName, "/" ) ) $content = preg_replace( "@(\.\./){1}([^\.])@i", "\\2", $content ); $listImport[] = "/* -- ".$fileName." -- */"; $listImport[] = $content."\n"; } else $listLines[] = $line; } $content = implode( "\n", $listImport ).implode( "\n", $listLines ); $this->statistics['sizeCombined'] = strlen( $content ); return $content; }
[ "public", "function", "combineString", "(", "$", "path", ",", "$", "content", ",", "$", "throwException", "=", "FALSE", ")", "{", "$", "listLines", "=", "array", "(", ")", ";", "$", "listImport", "=", "array", "(", ")", ";", "$", "this", "->", "stati...
Combines all CSS Files imported in CSS String and returns Combination String; @access public @param string $path Style Path @param string $styleFile File Name of Style without Extension (iE. style.css,import.css,default.css) @return string
[ "Combines", "all", "CSS", "Files", "imported", "in", "CSS", "String", "and", "returns", "Combination", "String", ";" ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/CSS/Combiner.php#L85-L132
train
CeusMedia/Common
src/UI/HTML/Tree/FolderCheckView.php
UI_HTML_Tree_FolderCheckView.buildRecursive
protected function buildRecursive( $path, $level = 0, $pathRoot = NULL ) { if( !$pathRoot ) $pathRoot = $path; $list = array(); // empty Array for current Level Items $lister = new FS_Folder_Lister( $path ); // create Lister for Folder Contents $lister->showFolders( $this->showFolders ); // switch Folders Visibility $lister->showFiles( $this->showFiles ); // switch Files Visibility $index = $lister->getList(); // get Iterator foreach( $index as $item ) // iterate current Path { $ignore = FALSE; $path = str_replace( "\\", "/", $item->getPathname() ); // correct Slashes on Windows $path = substr( $path, strlen( $this->path ) ); // remove Tree Root Path foreach( $this->ignorePatterns as $pattern ) if( preg_match( '@^'.$pattern.'$@', $path ) ) $ignore = TRUE; if( $ignore ) continue; $label = $item->getFilename(); $sublist = ""; // empty Sublist if( $item->isDir() ) // current Path has Folders $sublist = $this->buildRecursive( $item->getPathname(), $level + 1, $pathRoot ); // call Method for nested Folder $state = $this->selected ? in_array( $path, $this->selected ) : TRUE; // current Item is set to be selected or no presets at all $check = UI_HTML_FormElements::CheckBox( $this->inputName.'[]', $path, $state ); // build Checkbox $span = UI_HTML_Tag::create( 'span', $check.$label ); // build Label $item = UI_HTML_Elements::ListItem( $span.$sublist, $level ); // build List Item $list[$label] = $item; // append to List } ksort( $list ); $list = $list ? UI_HTML_Elements::unorderedList( $list, $level ) : ""; // build List return $list; // return List of this Level }
php
protected function buildRecursive( $path, $level = 0, $pathRoot = NULL ) { if( !$pathRoot ) $pathRoot = $path; $list = array(); // empty Array for current Level Items $lister = new FS_Folder_Lister( $path ); // create Lister for Folder Contents $lister->showFolders( $this->showFolders ); // switch Folders Visibility $lister->showFiles( $this->showFiles ); // switch Files Visibility $index = $lister->getList(); // get Iterator foreach( $index as $item ) // iterate current Path { $ignore = FALSE; $path = str_replace( "\\", "/", $item->getPathname() ); // correct Slashes on Windows $path = substr( $path, strlen( $this->path ) ); // remove Tree Root Path foreach( $this->ignorePatterns as $pattern ) if( preg_match( '@^'.$pattern.'$@', $path ) ) $ignore = TRUE; if( $ignore ) continue; $label = $item->getFilename(); $sublist = ""; // empty Sublist if( $item->isDir() ) // current Path has Folders $sublist = $this->buildRecursive( $item->getPathname(), $level + 1, $pathRoot ); // call Method for nested Folder $state = $this->selected ? in_array( $path, $this->selected ) : TRUE; // current Item is set to be selected or no presets at all $check = UI_HTML_FormElements::CheckBox( $this->inputName.'[]', $path, $state ); // build Checkbox $span = UI_HTML_Tag::create( 'span', $check.$label ); // build Label $item = UI_HTML_Elements::ListItem( $span.$sublist, $level ); // build List Item $list[$label] = $item; // append to List } ksort( $list ); $list = $list ? UI_HTML_Elements::unorderedList( $list, $level ) : ""; // build List return $list; // return List of this Level }
[ "protected", "function", "buildRecursive", "(", "$", "path", ",", "$", "level", "=", "0", ",", "$", "pathRoot", "=", "NULL", ")", "{", "if", "(", "!", "$", "pathRoot", ")", "$", "pathRoot", "=", "$", "path", ";", "$", "list", "=", "array", "(", "...
Builds recursively nested HTML Lists and Items from Folder Structure. @access public @param string $path URI (local only) of Folder to list @param int $level Current nesting depth @return string
[ "Builds", "recursively", "nested", "HTML", "Lists", "and", "Items", "from", "Folder", "Structure", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/UI/HTML/Tree/FolderCheckView.php#L88-L120
train
CeusMedia/Common
src/FS/File/Arc/TarBzip.php
FS_File_Arc_TarBzip.open
public function open( $fileName ) { if( !file_exists( $fileName ) ) // If the tar file doesn't exist... throw new RuntimeException( 'TBZ file "'.$fileName.'" is not existing.' ); $this->fileName = $fileName; $this->readBzipTar( $fileName ); }
php
public function open( $fileName ) { if( !file_exists( $fileName ) ) // If the tar file doesn't exist... throw new RuntimeException( 'TBZ file "'.$fileName.'" is not existing.' ); $this->fileName = $fileName; $this->readBzipTar( $fileName ); }
[ "public", "function", "open", "(", "$", "fileName", ")", "{", "if", "(", "!", "file_exists", "(", "$", "fileName", ")", ")", "// If the tar file doesn't exist...\r", "throw", "new", "RuntimeException", "(", "'TBZ file \"'", ".", "$", "fileName", ".", "'\" is not...
Opens an existing Tar Bzip File and loads contents. @access public @param string $fileName Name of Tar Bzip Archive to open @return bool
[ "Opens", "an", "existing", "Tar", "Bzip", "File", "and", "loads", "contents", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Arc/TarBzip.php#L60-L66
train
CeusMedia/Common
src/FS/File/Arc/TarBzip.php
FS_File_Arc_TarBzip.readBzipTar
private function readBzipTar( $fileName ) { $f = new FS_File_Arc_Bzip( $fileName ); $this->content = $f->readString(); $this->parseTar(); // Parse the TAR file return true; }
php
private function readBzipTar( $fileName ) { $f = new FS_File_Arc_Bzip( $fileName ); $this->content = $f->readString(); $this->parseTar(); // Parse the TAR file return true; }
[ "private", "function", "readBzipTar", "(", "$", "fileName", ")", "{", "$", "f", "=", "new", "FS_File_Arc_Bzip", "(", "$", "fileName", ")", ";", "$", "this", "->", "content", "=", "$", "f", "->", "readString", "(", ")", ";", "$", "this", "->", "parseT...
Reads an existing Tar Bzip File. @access private @param string $fileName Name of Tar Bzip Archive to read @return bool
[ "Reads", "an", "existing", "Tar", "Bzip", "File", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Arc/TarBzip.php#L74-L80
train
CeusMedia/Common
src/FS/File/Arc/TarBzip.php
FS_File_Arc_TarBzip.save
public function save( $fileName = false ) { if( !$fileName ) { if( !$this->fileName ) throw new RuntimeException( 'No TBZ file name for saving given.' ); $fileName = $this->fileName; } $this->generateTar(); // Encode processed files into TAR file format $f = new FS_File_Arc_Bzip( $fileName ); $f->writeString( $this->content ); return true; }
php
public function save( $fileName = false ) { if( !$fileName ) { if( !$this->fileName ) throw new RuntimeException( 'No TBZ file name for saving given.' ); $fileName = $this->fileName; } $this->generateTar(); // Encode processed files into TAR file format $f = new FS_File_Arc_Bzip( $fileName ); $f->writeString( $this->content ); return true; }
[ "public", "function", "save", "(", "$", "fileName", "=", "false", ")", "{", "if", "(", "!", "$", "fileName", ")", "{", "if", "(", "!", "$", "this", "->", "fileName", ")", "throw", "new", "RuntimeException", "(", "'No TBZ file name for saving given.'", ")",...
Write down the currently loaded Tar Bzip Archive. @access public @param string $fileName Name of Tar Bzip Archive to save @return bool
[ "Write", "down", "the", "currently", "loaded", "Tar", "Bzip", "Archive", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Arc/TarBzip.php#L88-L100
train
CeusMedia/Common
src/Net/HTTP/Request/Receiver.php
Net_HTTP_Request_Receiver.getAllFromSource
public function getAllFromSource( $source, $strict = FALSE ) { $source = strtolower( $source ); if( isset( $this->sources[$source] ) ) return new ADT_List_Dictionary( $this->sources[$source] ); if( !$strict ) return array(); throw new InvalidArgumentException( 'Invalid source "'.$source.'"' ); }
php
public function getAllFromSource( $source, $strict = FALSE ) { $source = strtolower( $source ); if( isset( $this->sources[$source] ) ) return new ADT_List_Dictionary( $this->sources[$source] ); if( !$strict ) return array(); throw new InvalidArgumentException( 'Invalid source "'.$source.'"' ); }
[ "public", "function", "getAllFromSource", "(", "$", "source", ",", "$", "strict", "=", "FALSE", ")", "{", "$", "source", "=", "strtolower", "(", "$", "source", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "sources", "[", "$", "source", "]", ...
Reads and returns Data from Sources. @access public @param string $source Source key (not case sensitive) (get,post,files[,session,cookie]) @param bool $strict Flag: throw exception if not set, otherwise return NULL @throws InvalidArgumentException if key is not set in source and strict is on @return array Pairs in source (or empty array if not set on strict is off)
[ "Reads", "and", "returns", "Data", "from", "Sources", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Request/Receiver.php#L105-L113
train
CeusMedia/Common
src/Net/HTTP/Request/Receiver.php
Net_HTTP_Request_Receiver.getFromSource
public function getFromSource( $key, $source, $strict = FALSE ) { $data = $this->getAllFromSource( $source ); if( isset( $data[$key] ) ) return $data[$key]; if( !$strict ) return NULL; throw new InvalidArgumentException( 'Invalid key "'.$key.'" in source "'.$source.'"' ); }
php
public function getFromSource( $key, $source, $strict = FALSE ) { $data = $this->getAllFromSource( $source ); if( isset( $data[$key] ) ) return $data[$key]; if( !$strict ) return NULL; throw new InvalidArgumentException( 'Invalid key "'.$key.'" in source "'.$source.'"' ); }
[ "public", "function", "getFromSource", "(", "$", "key", ",", "$", "source", ",", "$", "strict", "=", "FALSE", ")", "{", "$", "data", "=", "$", "this", "->", "getAllFromSource", "(", "$", "source", ")", ";", "if", "(", "isset", "(", "$", "data", "["...
Returns value or null by its key in a specified source. @access public @param string $key ... @param string $source Source key (not case sensitive) (get,post,files[,session,cookie]) @param bool $strict Flag: throw exception if not set, otherwise return NULL @throws InvalidArgumentException if key is not set in source and strict is on @return mixed Value of key in source or NULL if not set
[ "Returns", "value", "or", "null", "by", "its", "key", "in", "a", "specified", "source", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Request/Receiver.php#L124-L132
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.checkboxValue2Boolean
public static function checkboxValue2Boolean($checkboxValue) { $mapping = [ 'on' => true, 'off' => false, ]; $clearValue = strtolower(trim($checkboxValue)); if (isset($mapping[$clearValue])) { return $mapping[$clearValue]; } return false; }
php
public static function checkboxValue2Boolean($checkboxValue) { $mapping = [ 'on' => true, 'off' => false, ]; $clearValue = strtolower(trim($checkboxValue)); if (isset($mapping[$clearValue])) { return $mapping[$clearValue]; } return false; }
[ "public", "static", "function", "checkboxValue2Boolean", "(", "$", "checkboxValue", ")", "{", "$", "mapping", "=", "[", "'on'", "=>", "true", ",", "'off'", "=>", "false", ",", "]", ";", "$", "clearValue", "=", "strtolower", "(", "trim", "(", "$", "checkb...
Converts checkbox value to boolean @param string $checkboxValue Checkbox value @return bool
[ "Converts", "checkbox", "value", "to", "boolean" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L125-L139
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.includeFileExtension
public static function includeFileExtension($fileName, $extension) { $fileExtension = self::getFileExtension($fileName, true); /* * File has given extension? * Nothing to do */ if ($fileExtension === strtolower($extension)) { return $fileName; } return sprintf('%s.%s', $fileName, $extension); }
php
public static function includeFileExtension($fileName, $extension) { $fileExtension = self::getFileExtension($fileName, true); /* * File has given extension? * Nothing to do */ if ($fileExtension === strtolower($extension)) { return $fileName; } return sprintf('%s.%s', $fileName, $extension); }
[ "public", "static", "function", "includeFileExtension", "(", "$", "fileName", ",", "$", "extension", ")", "{", "$", "fileExtension", "=", "self", "::", "getFileExtension", "(", "$", "fileName", ",", "true", ")", ";", "/*\n * File has given extension?\n ...
Returns name of file with given extension after verification if it contains the extension @param string $fileName The file name to verify @param string $extension The extension to verify and include @return string
[ "Returns", "name", "of", "file", "with", "given", "extension", "after", "verification", "if", "it", "contains", "the", "extension" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L159-L172
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getFileExtension
public static function getFileExtension($fileName, $asLowerCase = false) { $extension = ''; $matches = []; if (preg_match('|(.+)\.(.+)|', $fileName, $matches)) { $extension = end($matches); } if ($asLowerCase) { return strtolower($extension); } return $extension; }
php
public static function getFileExtension($fileName, $asLowerCase = false) { $extension = ''; $matches = []; if (preg_match('|(.+)\.(.+)|', $fileName, $matches)) { $extension = end($matches); } if ($asLowerCase) { return strtolower($extension); } return $extension; }
[ "public", "static", "function", "getFileExtension", "(", "$", "fileName", ",", "$", "asLowerCase", "=", "false", ")", "{", "$", "extension", "=", "''", ";", "$", "matches", "=", "[", "]", ";", "if", "(", "preg_match", "(", "'|(.+)\\.(.+)|'", ",", "$", ...
Returns file extension @param string $fileName File name @param bool $asLowerCase (optional) if true extension is returned as lowercase string @return string
[ "Returns", "file", "extension" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L181-L195
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getFileNameFromPath
public static function getFileNameFromPath($path) { $matches = []; $pattern = sprintf('|([^\%s.]+\.[A-Za-z0-9.]+)$|', DIRECTORY_SEPARATOR); if ((bool)preg_match($pattern, $path, $matches)) { return $matches[1]; } return ''; }
php
public static function getFileNameFromPath($path) { $matches = []; $pattern = sprintf('|([^\%s.]+\.[A-Za-z0-9.]+)$|', DIRECTORY_SEPARATOR); if ((bool)preg_match($pattern, $path, $matches)) { return $matches[1]; } return ''; }
[ "public", "static", "function", "getFileNameFromPath", "(", "$", "path", ")", "{", "$", "matches", "=", "[", "]", ";", "$", "pattern", "=", "sprintf", "(", "'|([^\\%s.]+\\.[A-Za-z0-9.]+)$|'", ",", "DIRECTORY_SEPARATOR", ")", ";", "if", "(", "(", "bool", ")",...
Returns file name from given path @param string $path A path that contains file name @return string
[ "Returns", "file", "name", "from", "given", "path" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L203-L213
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getUniqueFileName
public static function getUniqueFileName($originalFileName, $objectId = 0) { $withoutExtension = self::getFileNameWithoutExtension($originalFileName); $extension = self::getFileExtension($originalFileName, true); /* * Let's clear name of file * * Attention. * The name without extension may be cleared / urlized only to avoid incorrect name by replacing "." with "-". */ $withoutExtension = Urlizer::urlize($withoutExtension); // Now I have to complete the template used to build / generate unique name $template = '%s-%s.%s'; // [file's name]-[unique key].[file's extension] // Add some uniqueness $unique = self::getUniqueString(mt_rand()); // Finally build and return the unique name if ($objectId > 0) { $template = '%s-%s-%s.%s'; // [file's name]-[unique key]-[object ID].[file's extension] return sprintf($template, $withoutExtension, $unique, $objectId, $extension); } return sprintf($template, $withoutExtension, $unique, $extension); }
php
public static function getUniqueFileName($originalFileName, $objectId = 0) { $withoutExtension = self::getFileNameWithoutExtension($originalFileName); $extension = self::getFileExtension($originalFileName, true); /* * Let's clear name of file * * Attention. * The name without extension may be cleared / urlized only to avoid incorrect name by replacing "." with "-". */ $withoutExtension = Urlizer::urlize($withoutExtension); // Now I have to complete the template used to build / generate unique name $template = '%s-%s.%s'; // [file's name]-[unique key].[file's extension] // Add some uniqueness $unique = self::getUniqueString(mt_rand()); // Finally build and return the unique name if ($objectId > 0) { $template = '%s-%s-%s.%s'; // [file's name]-[unique key]-[object ID].[file's extension] return sprintf($template, $withoutExtension, $unique, $objectId, $extension); } return sprintf($template, $withoutExtension, $unique, $extension); }
[ "public", "static", "function", "getUniqueFileName", "(", "$", "originalFileName", ",", "$", "objectId", "=", "0", ")", "{", "$", "withoutExtension", "=", "self", "::", "getFileNameWithoutExtension", "(", "$", "originalFileName", ")", ";", "$", "extension", "=",...
Returns unique name for file based on given original name @param string $originalFileName Original name of the file @param int $objectId (optional) Object ID, the ID of database's row. May be included into the generated / unique name. @return string
[ "Returns", "unique", "name", "for", "file", "based", "on", "given", "original", "name" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L223-L250
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getFileNameWithoutExtension
public static function getFileNameWithoutExtension($fileName) { $matches = []; if (is_string($fileName) && (bool)preg_match('|(.+)\.(.+)|', $fileName, $matches)) { return $matches[1]; } return ''; }
php
public static function getFileNameWithoutExtension($fileName) { $matches = []; if (is_string($fileName) && (bool)preg_match('|(.+)\.(.+)|', $fileName, $matches)) { return $matches[1]; } return ''; }
[ "public", "static", "function", "getFileNameWithoutExtension", "(", "$", "fileName", ")", "{", "$", "matches", "=", "[", "]", ";", "if", "(", "is_string", "(", "$", "fileName", ")", "&&", "(", "bool", ")", "preg_match", "(", "'|(.+)\\.(.+)|'", ",", "$", ...
Returns file name without extension @param string $fileName The file name @return string
[ "Returns", "file", "name", "without", "extension" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L258-L267
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.toLatin
public static function toLatin($string, $lowerCaseHuman = true, $replacementChar = '-') { if (is_string($string)) { $string = trim($string); } /* * Empty value? * Nothing to do */ if (empty($string)) { return ''; } $converter = Transliterator::create('Latin-ASCII;'); /* * Oops, cannot instantiate converter * Nothing to do */ if (null === $converter) { return ''; } $converted = $converter->transliterate($string); // Make the string lowercase and human-readable if ($lowerCaseHuman) { $matches = []; $matchCount = preg_match_all('|[A-Z]{1}[^A-Z]*|', $converted, $matches); if ($matchCount > 0) { $parts = $matches[0]; $converted = mb_strtolower(implode($replacementChar, $parts)); } } /* * Let's replace special characters to spaces * ...and finally spaces to $replacementChar */ $replaced = preg_replace('|[^a-zA-Z0-9]|', ' ', $converted); return preg_replace('| +|', $replacementChar, trim($replaced)); }
php
public static function toLatin($string, $lowerCaseHuman = true, $replacementChar = '-') { if (is_string($string)) { $string = trim($string); } /* * Empty value? * Nothing to do */ if (empty($string)) { return ''; } $converter = Transliterator::create('Latin-ASCII;'); /* * Oops, cannot instantiate converter * Nothing to do */ if (null === $converter) { return ''; } $converted = $converter->transliterate($string); // Make the string lowercase and human-readable if ($lowerCaseHuman) { $matches = []; $matchCount = preg_match_all('|[A-Z]{1}[^A-Z]*|', $converted, $matches); if ($matchCount > 0) { $parts = $matches[0]; $converted = mb_strtolower(implode($replacementChar, $parts)); } } /* * Let's replace special characters to spaces * ...and finally spaces to $replacementChar */ $replaced = preg_replace('|[^a-zA-Z0-9]|', ' ', $converted); return preg_replace('| +|', $replacementChar, trim($replaced)); }
[ "public", "static", "function", "toLatin", "(", "$", "string", ",", "$", "lowerCaseHuman", "=", "true", ",", "$", "replacementChar", "=", "'-'", ")", "{", "if", "(", "is_string", "(", "$", "string", ")", ")", "{", "$", "string", "=", "trim", "(", "$"...
Converts given string characters to latin characters @param string $string String to convert @param bool $lowerCaseHuman (optional) If is set to true, converted string is returned as lowercase and human-readable. Otherwise - as original. @param string $replacementChar (optional) Replacement character for all non-latin characters and uppercase letters, if 2nd argument is set to true @return string
[ "Converts", "given", "string", "characters", "to", "latin", "characters" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L310-L354
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getUniqueString
public static function getUniqueString($prefix = '', $hashed = false) { $unique = uniqid($prefix, true); if ($hashed) { return sha1($unique); } return $unique; }
php
public static function getUniqueString($prefix = '', $hashed = false) { $unique = uniqid($prefix, true); if ($hashed) { return sha1($unique); } return $unique; }
[ "public", "static", "function", "getUniqueString", "(", "$", "prefix", "=", "''", ",", "$", "hashed", "=", "false", ")", "{", "$", "unique", "=", "uniqid", "(", "$", "prefix", ",", "true", ")", ";", "if", "(", "$", "hashed", ")", "{", "return", "sh...
Returns unique string @param string $prefix (optional) Prefix of the unique string. May be used while generating the unique string simultaneously on several hosts at the same microsecond. @param bool $hashed (optional) If is set to true, the unique string is hashed additionally. Otherwise - not. @return string
[ "Returns", "unique", "string" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L364-L373
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.replace
public static function replace($subject, $search, $replacement, $quoteStrings = false) { /* * Unknown source or item to find or replacement is an empty array? * Nothing to do */ if (empty($subject) || empty($search) || [] === $replacement) { return $subject; } $effect = $subject; $searchIsString = is_string($search); $searchIsArray = is_array($search); /* * Value to find is neither a string nor an array OR it's an empty string? * Nothing to do */ if ((!$searchIsString && !$searchIsArray) || ($searchIsString && '' === $search)) { return $effect; } $replacementIsString = is_string($replacement); $replacementIsArray = is_array($replacement); $bothAreStrings = $searchIsString && $replacementIsString; $bothAreArrays = $searchIsArray && $replacementIsArray; if ($quoteStrings) { if ($replacementIsString) { $replacement = '\'' . $replacement . '\''; } elseif ($replacementIsArray) { foreach ($replacement as &$item) { if (is_string($item)) { $item = '\'' . $item . '\''; } } unset($item); } } // 1st step: replace strings, simple operation with strings if ($bothAreStrings) { $effect = str_replace($search, $replacement, $subject); } /* * 2nd step: replace with regular expressions. * Attention. Searched and replacement value should be the same type: strings or arrays. */ if ($effect === $subject && ($bothAreStrings || $bothAreArrays)) { /* * I have to avoid string that contains spaces only, e.g. " ". * It's required to avoid bug: preg_replace(): Empty regular expression. */ if ($searchIsArray || ($searchIsString && !empty(trim($search)))) { $replaced = @preg_replace($search, $replacement, $subject); if (null !== $replaced && [] !== $replaced) { $effect = $replaced; } } } /* * 3rd step: complex replace of the replacement defined as an array. * It may be useful when you want to search for a one string and replace the string with multiple values. */ if ($effect === $subject && $searchIsString && $replacementIsArray) { $subjectIsArray = is_array($subject); $effect = ''; if ($subjectIsArray) { $effect = []; } $subject = Arrays::makeArray($subject); // I have to iterate through the subjects, because explode() function expects strings as both arguments // (1st and 2nd) foreach ($subject as $subSubject) { $subEffect = ''; $exploded = explode($search, $subSubject); $explodedCount = count($exploded); foreach ($exploded as $key => $item) { $subEffect .= $item; // The replacement shouldn't be included when the searched string was not found if ($explodedCount > 1 && $key < $explodedCount - 1 && isset($replacement[$key])) { $subEffect .= $replacement[$key]; } } if ($subjectIsArray) { $effect[] = $subEffect; continue; } $effect .= $subEffect; } } return $effect; }
php
public static function replace($subject, $search, $replacement, $quoteStrings = false) { /* * Unknown source or item to find or replacement is an empty array? * Nothing to do */ if (empty($subject) || empty($search) || [] === $replacement) { return $subject; } $effect = $subject; $searchIsString = is_string($search); $searchIsArray = is_array($search); /* * Value to find is neither a string nor an array OR it's an empty string? * Nothing to do */ if ((!$searchIsString && !$searchIsArray) || ($searchIsString && '' === $search)) { return $effect; } $replacementIsString = is_string($replacement); $replacementIsArray = is_array($replacement); $bothAreStrings = $searchIsString && $replacementIsString; $bothAreArrays = $searchIsArray && $replacementIsArray; if ($quoteStrings) { if ($replacementIsString) { $replacement = '\'' . $replacement . '\''; } elseif ($replacementIsArray) { foreach ($replacement as &$item) { if (is_string($item)) { $item = '\'' . $item . '\''; } } unset($item); } } // 1st step: replace strings, simple operation with strings if ($bothAreStrings) { $effect = str_replace($search, $replacement, $subject); } /* * 2nd step: replace with regular expressions. * Attention. Searched and replacement value should be the same type: strings or arrays. */ if ($effect === $subject && ($bothAreStrings || $bothAreArrays)) { /* * I have to avoid string that contains spaces only, e.g. " ". * It's required to avoid bug: preg_replace(): Empty regular expression. */ if ($searchIsArray || ($searchIsString && !empty(trim($search)))) { $replaced = @preg_replace($search, $replacement, $subject); if (null !== $replaced && [] !== $replaced) { $effect = $replaced; } } } /* * 3rd step: complex replace of the replacement defined as an array. * It may be useful when you want to search for a one string and replace the string with multiple values. */ if ($effect === $subject && $searchIsString && $replacementIsArray) { $subjectIsArray = is_array($subject); $effect = ''; if ($subjectIsArray) { $effect = []; } $subject = Arrays::makeArray($subject); // I have to iterate through the subjects, because explode() function expects strings as both arguments // (1st and 2nd) foreach ($subject as $subSubject) { $subEffect = ''; $exploded = explode($search, $subSubject); $explodedCount = count($exploded); foreach ($exploded as $key => $item) { $subEffect .= $item; // The replacement shouldn't be included when the searched string was not found if ($explodedCount > 1 && $key < $explodedCount - 1 && isset($replacement[$key])) { $subEffect .= $replacement[$key]; } } if ($subjectIsArray) { $effect[] = $subEffect; continue; } $effect .= $subEffect; } } return $effect; }
[ "public", "static", "function", "replace", "(", "$", "subject", ",", "$", "search", ",", "$", "replacement", ",", "$", "quoteStrings", "=", "false", ")", "{", "/*\n * Unknown source or item to find or replacement is an empty array?\n * Nothing to do\n ...
Replaces part of string with other string or strings. There is a few combination of what should be searched and with what it should be replaced. @param array|string $subject The string or an array of strings to search and replace @param array|string $search String or pattern or array of patterns to find. It may be: string, an array of strings or an array of patterns. @param array|string $replacement The string or an array of strings to replace. It may be: string or an array of strings. @param bool $quoteStrings (optional) If is set to true, strings are surrounded with single quote sign @return string Example: a) an array of strings to search $subject = [ 'Lorem ipsum dolor sit amet.', 'Etiam ullamcorper. Suspendisse a pellentesque dui, non felis.', ]; b) an array of patterns $search = [ '|ipsum|', '|pellentesque|', ]; c) an array of strings to replace $replacement = [ 'commodo', 'interdum', ]; The result: [ 'Lorem commodo dolor sit amet.', 'Etiam ullamcorper. Suspendisse a interdum dui, non felis.', ];
[ "Replaces", "part", "of", "string", "with", "other", "string", "or", "strings", ".", "There", "is", "a", "few", "combination", "of", "what", "should", "be", "searched", "and", "with", "what", "it", "should", "be", "replaced", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L412-L520
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.substringToWord
public static function substringToWord($text, $maxLength, $suffix = '...') { $effect = $text; $textLength = mb_strlen($text, 'utf-8'); $suffixLength = mb_strlen($suffix, 'utf-8'); $maxLength -= $suffixLength; if ($textLength > $maxLength) { $effect = mb_substr($text, 0, $maxLength, 'utf-8'); $lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8'); if (false !== $lastSpacePosition) { $effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8'); } $effect .= $suffix; } return $effect; }
php
public static function substringToWord($text, $maxLength, $suffix = '...') { $effect = $text; $textLength = mb_strlen($text, 'utf-8'); $suffixLength = mb_strlen($suffix, 'utf-8'); $maxLength -= $suffixLength; if ($textLength > $maxLength) { $effect = mb_substr($text, 0, $maxLength, 'utf-8'); $lastSpacePosition = mb_strrpos($effect, ' ', 'utf-8'); if (false !== $lastSpacePosition) { $effect = mb_substr($effect, 0, $lastSpacePosition, 'utf-8'); } $effect .= $suffix; } return $effect; }
[ "public", "static", "function", "substringToWord", "(", "$", "text", ",", "$", "maxLength", ",", "$", "suffix", "=", "'...'", ")", "{", "$", "effect", "=", "$", "text", ";", "$", "textLength", "=", "mb_strlen", "(", "$", "text", ",", "'utf-8'", ")", ...
Returns part of string preserving words @param string $text The string / text @param int $maxLength Maximum length of given string @param string $suffix (optional) The suffix to add at the end of string @return string
[ "Returns", "part", "of", "string", "preserving", "words" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L566-L587
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.breakLongText
public static function breakLongText( $text, $perLine = 100, $separator = '<br>', $encoding = 'utf-8', $proportionalAberration = 20 ) { $effect = $text; $textLength = mb_strlen($text); if (!empty($text) && $textLength > $perLine) { /* * The html_entity_decode() function is used here, because while operating * on string that contains only special characters the string is divided * incorrectly, e.g. "<<<<<" -> "&lt;&lt;&lt;&lt;&<br />lt;". */ //$text = htmlspecialchars_decode($text); $text = html_entity_decode($text, ENT_QUOTES); $effect = ''; $currentPosition = 0; $charsAberration = ceil($perLine * ($proportionalAberration / 100)); $charsPerLineDefault = $perLine; while ($currentPosition <= $textLength) { $insertSeparator = false; /* * Looking for spaces before and after current position. It was done, because text wasn't * broken properly and some words were breaked and placed into two lines. */ if ($charsAberration > 0) { $length = $perLine + $charsAberration; $lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding); if (!Regex::contains($lineWithAberration, ' ')) { $length = $perLine - $charsAberration; $lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding); } if (Regex::startsWith($lineWithAberration, ' ')) { ++$currentPosition; $lineWithAberration = ltrim($lineWithAberration); } $spacePosition = mb_strrpos($lineWithAberration, ' ', 0, $encoding); if (false !== $spacePosition && 0 < $spacePosition) { /** @var int $spacePosition */ $perLine = $spacePosition; $insertSeparator = true; } } $charsOneLine = mb_substr($text, $currentPosition, $perLine, $encoding); /* * The htmlspecialchars() function is used here, because... * Reason and comment the same as above for html_entity_decode() function. */ $effect .= htmlspecialchars($charsOneLine); //$effect .= $charsOneLine; $currentPosition += $perLine; $oneLineContainsSpace = Regex::contains($charsOneLine, ' '); if (($insertSeparator || !$oneLineContainsSpace) && $currentPosition <= $textLength) { $effect .= $separator; } $perLine = $charsPerLineDefault; } } return $effect; }
php
public static function breakLongText( $text, $perLine = 100, $separator = '<br>', $encoding = 'utf-8', $proportionalAberration = 20 ) { $effect = $text; $textLength = mb_strlen($text); if (!empty($text) && $textLength > $perLine) { /* * The html_entity_decode() function is used here, because while operating * on string that contains only special characters the string is divided * incorrectly, e.g. "<<<<<" -> "&lt;&lt;&lt;&lt;&<br />lt;". */ //$text = htmlspecialchars_decode($text); $text = html_entity_decode($text, ENT_QUOTES); $effect = ''; $currentPosition = 0; $charsAberration = ceil($perLine * ($proportionalAberration / 100)); $charsPerLineDefault = $perLine; while ($currentPosition <= $textLength) { $insertSeparator = false; /* * Looking for spaces before and after current position. It was done, because text wasn't * broken properly and some words were breaked and placed into two lines. */ if ($charsAberration > 0) { $length = $perLine + $charsAberration; $lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding); if (!Regex::contains($lineWithAberration, ' ')) { $length = $perLine - $charsAberration; $lineWithAberration = mb_substr($text, $currentPosition, $length, $encoding); } if (Regex::startsWith($lineWithAberration, ' ')) { ++$currentPosition; $lineWithAberration = ltrim($lineWithAberration); } $spacePosition = mb_strrpos($lineWithAberration, ' ', 0, $encoding); if (false !== $spacePosition && 0 < $spacePosition) { /** @var int $spacePosition */ $perLine = $spacePosition; $insertSeparator = true; } } $charsOneLine = mb_substr($text, $currentPosition, $perLine, $encoding); /* * The htmlspecialchars() function is used here, because... * Reason and comment the same as above for html_entity_decode() function. */ $effect .= htmlspecialchars($charsOneLine); //$effect .= $charsOneLine; $currentPosition += $perLine; $oneLineContainsSpace = Regex::contains($charsOneLine, ' '); if (($insertSeparator || !$oneLineContainsSpace) && $currentPosition <= $textLength) { $effect .= $separator; } $perLine = $charsPerLineDefault; } } return $effect; }
[ "public", "static", "function", "breakLongText", "(", "$", "text", ",", "$", "perLine", "=", "100", ",", "$", "separator", "=", "'<br>'", ",", "$", "encoding", "=", "'utf-8'", ",", "$", "proportionalAberration", "=", "20", ")", "{", "$", "effect", "=", ...
Breaks long text @param string $text The text to check and break @param int $perLine (optional) Characters count per line. Default: 100. @param string $separator (optional) Separator that is placed between lines. Default: "<br>". @param string $encoding (optional) Character encoding. Used by mb_substr(). Default: "UTF-8". @param int $proportionalAberration (optional) Proportional aberration for chars (percent value). Default: 20. @return string
[ "Breaks", "long", "text" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L599-L676
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.removeDirectory
public static function removeDirectory($directoryPath, $contentOnly = false) { /* * Directory does not exist? * Nothing to do */ if (!file_exists($directoryPath)) { return null; } /* * It's not a directory? * Let's treat it like file */ if (!is_dir($directoryPath)) { return unlink($directoryPath); } foreach (scandir($directoryPath, SCANDIR_SORT_ASCENDING) as $item) { if ('.' === $item || '..' === $item) { continue; } if (!self::removeDirectory($directoryPath . DIRECTORY_SEPARATOR . $item)) { return false; } } // Directory should be removed too? if (!$contentOnly) { return rmdir($directoryPath); } return true; }
php
public static function removeDirectory($directoryPath, $contentOnly = false) { /* * Directory does not exist? * Nothing to do */ if (!file_exists($directoryPath)) { return null; } /* * It's not a directory? * Let's treat it like file */ if (!is_dir($directoryPath)) { return unlink($directoryPath); } foreach (scandir($directoryPath, SCANDIR_SORT_ASCENDING) as $item) { if ('.' === $item || '..' === $item) { continue; } if (!self::removeDirectory($directoryPath . DIRECTORY_SEPARATOR . $item)) { return false; } } // Directory should be removed too? if (!$contentOnly) { return rmdir($directoryPath); } return true; }
[ "public", "static", "function", "removeDirectory", "(", "$", "directoryPath", ",", "$", "contentOnly", "=", "false", ")", "{", "/*\n * Directory does not exist?\n * Nothing to do\n */", "if", "(", "!", "file_exists", "(", "$", "directoryPath", ")",...
Removes the directory. If not empty, removes also contents. @param string $directoryPath Directory path @param bool $contentOnly (optional) If is set to true, only content of the directory is removed, not directory itself. Otherwise - directory is removed too (default behaviour). @return null|bool
[ "Removes", "the", "directory", ".", "If", "not", "empty", "removes", "also", "contents", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L687-L721
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getCamelCase
public static function getCamelCase($string, $separator = ' ') { if (empty($string)) { return ''; } $effect = ''; $members = explode($separator, $string); foreach ($members as $key => $value) { $value = mb_strtolower($value); if (0 === $key) { $effect .= self::lowercaseFirst($value); } else { $effect .= self::uppercaseFirst($value); } } return $effect; }
php
public static function getCamelCase($string, $separator = ' ') { if (empty($string)) { return ''; } $effect = ''; $members = explode($separator, $string); foreach ($members as $key => $value) { $value = mb_strtolower($value); if (0 === $key) { $effect .= self::lowercaseFirst($value); } else { $effect .= self::uppercaseFirst($value); } } return $effect; }
[ "public", "static", "function", "getCamelCase", "(", "$", "string", ",", "$", "separator", "=", "' '", ")", "{", "if", "(", "empty", "(", "$", "string", ")", ")", "{", "return", "''", ";", "}", "$", "effect", "=", "''", ";", "$", "members", "=", ...
Returns the string in camel case @param string $string The string to convert e.g. this-is-eXamplE (return: thisIsExample) @param string $separator (optional) Separator used to find parts of the string, e.g. '-' or ',' @return string
[ "Returns", "the", "string", "in", "camel", "case" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L741-L761
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.lowercaseFirst
public static function lowercaseFirst($text, $restLowercase = null) { if (empty($text)) { return ''; } $effect = $text; if ($restLowercase) { $effect = mb_strtolower($effect); } elseif (false === $restLowercase) { $effect = mb_strtoupper($effect); } return lcfirst($effect); }
php
public static function lowercaseFirst($text, $restLowercase = null) { if (empty($text)) { return ''; } $effect = $text; if ($restLowercase) { $effect = mb_strtolower($effect); } elseif (false === $restLowercase) { $effect = mb_strtoupper($effect); } return lcfirst($effect); }
[ "public", "static", "function", "lowercaseFirst", "(", "$", "text", ",", "$", "restLowercase", "=", "null", ")", "{", "if", "(", "empty", "(", "$", "text", ")", ")", "{", "return", "''", ";", "}", "$", "effect", "=", "$", "text", ";", "if", "(", ...
Make a string's first character lowercase @param string $text The text to get first character lowercase @param null|bool $restLowercase (optional) Information that to do with rest of given string @return string Values of the $restLowercase argument: - null (default): nothing is done with the string - true: the rest of string is lowercased - false: the rest of string is uppercased
[ "Make", "a", "string", "s", "first", "character", "lowercase" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L775-L790
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.quoteValue
public static function quoteValue($value, $useApostrophe = true) { if (is_string($value)) { $quotes = '"'; if ($useApostrophe) { $quotes = '\''; } $value = sprintf('%s%s%s', $quotes, $value, $quotes); } return $value; }
php
public static function quoteValue($value, $useApostrophe = true) { if (is_string($value)) { $quotes = '"'; if ($useApostrophe) { $quotes = '\''; } $value = sprintf('%s%s%s', $quotes, $value, $quotes); } return $value; }
[ "public", "static", "function", "quoteValue", "(", "$", "value", ",", "$", "useApostrophe", "=", "true", ")", "{", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "quotes", "=", "'\"'", ";", "if", "(", "$", "useApostrophe", ")", "{", ...
Quotes given value with apostrophes or quotation marks @param mixed $value The value to quote @param bool $useApostrophe (optional) If is set to true, apostrophes are used. Otherwise - quotation marks. @return string
[ "Quotes", "given", "value", "with", "apostrophes", "or", "quotation", "marks" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L828-L841
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getStringWithoutLastElement
public static function getStringWithoutLastElement($string, $separator) { $elements = self::getStringElements($string, $separator); $lastKey = Arrays::getLastKey($elements); unset($elements[$lastKey]); return implode($separator, $elements); }
php
public static function getStringWithoutLastElement($string, $separator) { $elements = self::getStringElements($string, $separator); $lastKey = Arrays::getLastKey($elements); unset($elements[$lastKey]); return implode($separator, $elements); }
[ "public", "static", "function", "getStringWithoutLastElement", "(", "$", "string", ",", "$", "separator", ")", "{", "$", "elements", "=", "self", "::", "getStringElements", "(", "$", "string", ",", "$", "separator", ")", ";", "$", "lastKey", "=", "Arrays", ...
Returns string without the last element. The string should contain given separator. @param string $string The string to check @param string $separator The separator which divides elements of string @return string
[ "Returns", "string", "without", "the", "last", "element", ".", "The", "string", "should", "contain", "given", "separator", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L875-L883
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getStringElements
public static function getStringElements($string, $separator) { $matches = []; $pattern = sprintf('|[^\%s]+|', $separator); $matchCount = preg_match_all($pattern, $string, $matches); if ($matchCount > 1) { return $matches[0]; } return []; }
php
public static function getStringElements($string, $separator) { $matches = []; $pattern = sprintf('|[^\%s]+|', $separator); $matchCount = preg_match_all($pattern, $string, $matches); if ($matchCount > 1) { return $matches[0]; } return []; }
[ "public", "static", "function", "getStringElements", "(", "$", "string", ",", "$", "separator", ")", "{", "$", "matches", "=", "[", "]", ";", "$", "pattern", "=", "sprintf", "(", "'|[^\\%s]+|'", ",", "$", "separator", ")", ";", "$", "matchCount", "=", ...
Returns elements of given string divided by given separator @param string $string The string to check @param string $separator The separator which divides elements of string @return array
[ "Returns", "elements", "of", "given", "string", "divided", "by", "given", "separator" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L892-L903
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getLastElementOfString
public static function getLastElementOfString($string, $separator) { $elements = self::getStringElements($string, $separator); /* * No elements? * Nothing to do */ if (empty($elements)) { return null; } $element = Arrays::getLastElement($elements); return trim($element); }
php
public static function getLastElementOfString($string, $separator) { $elements = self::getStringElements($string, $separator); /* * No elements? * Nothing to do */ if (empty($elements)) { return null; } $element = Arrays::getLastElement($elements); return trim($element); }
[ "public", "static", "function", "getLastElementOfString", "(", "$", "string", ",", "$", "separator", ")", "{", "$", "elements", "=", "self", "::", "getStringElements", "(", "$", "string", ",", "$", "separator", ")", ";", "/*\n * No elements?\n * No...
Returns the last element of given string divided by given separator @param string $string The string to check @param string $separator The separator which divides elements of string @return null|string
[ "Returns", "the", "last", "element", "of", "given", "string", "divided", "by", "given", "separator" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L912-L927
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.concatenatePaths
public static function concatenatePaths($paths) { // If paths are not provided as array, get the paths from methods' arguments if (!is_array($paths)) { $paths = func_get_args(); } // No paths provided? // Nothing to do if (empty($paths)) { return ''; } $concatenated = ''; $firstWindowsBased = false; $separator = DIRECTORY_SEPARATOR; foreach ($paths as $path) { $path = trim($path); // Empty paths are useless if (empty($path)) { continue; } // Does the first path is a Windows-based path? if (Arrays::isFirstElement($paths, $path)) { $firstWindowsBased = Regex::isWindowsBasedPath($path); if ($firstWindowsBased) { $separator = '\\'; } } // Remove the starting / beginning directory's separator $path = self::removeStartingDirectorySeparator($path, $separator); // Removes the ending directory's separator $path = self::removeEndingDirectorySeparator($path, $separator); /* * If OS is Windows, first part of the concatenated path should be the first passed path, * because in Windows paths starts with drive letter, e.g. "C:", and the directory separator is not * necessary at the beginning. */ if ($firstWindowsBased && empty($concatenated)) { $concatenated = $path; continue; } // Concatenate the paths / strings with OS-related directory separator between them (slash or backslash) $concatenated = sprintf('%s%s%s', $concatenated, $separator, $path); } return $concatenated; }
php
public static function concatenatePaths($paths) { // If paths are not provided as array, get the paths from methods' arguments if (!is_array($paths)) { $paths = func_get_args(); } // No paths provided? // Nothing to do if (empty($paths)) { return ''; } $concatenated = ''; $firstWindowsBased = false; $separator = DIRECTORY_SEPARATOR; foreach ($paths as $path) { $path = trim($path); // Empty paths are useless if (empty($path)) { continue; } // Does the first path is a Windows-based path? if (Arrays::isFirstElement($paths, $path)) { $firstWindowsBased = Regex::isWindowsBasedPath($path); if ($firstWindowsBased) { $separator = '\\'; } } // Remove the starting / beginning directory's separator $path = self::removeStartingDirectorySeparator($path, $separator); // Removes the ending directory's separator $path = self::removeEndingDirectorySeparator($path, $separator); /* * If OS is Windows, first part of the concatenated path should be the first passed path, * because in Windows paths starts with drive letter, e.g. "C:", and the directory separator is not * necessary at the beginning. */ if ($firstWindowsBased && empty($concatenated)) { $concatenated = $path; continue; } // Concatenate the paths / strings with OS-related directory separator between them (slash or backslash) $concatenated = sprintf('%s%s%s', $concatenated, $separator, $path); } return $concatenated; }
[ "public", "static", "function", "concatenatePaths", "(", "$", "paths", ")", "{", "// If paths are not provided as array, get the paths from methods' arguments", "if", "(", "!", "is_array", "(", "$", "paths", ")", ")", "{", "$", "paths", "=", "func_get_args", "(", ")...
Returns concatenated given paths The paths may be passed as: - an array of paths / strings - strings passed as following arguments Examples: - concatenatePaths(['path/first', 'path/second', 'path/third']); - concatenatePaths('path/first', 'path/second', 'path/third'); @param array|string $paths Paths co concatenate. As described above: an array of paths / strings or strings passed as following arguments. @return string
[ "Returns", "concatenated", "given", "paths" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L962-L1018
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.removeEndingDirectorySeparator
public static function removeEndingDirectorySeparator($text, $separator = '') { /* * Not a string? * Nothing to do */ if (!is_string($text)) { return ''; } if (empty($separator)) { $separator = DIRECTORY_SEPARATOR; } $effect = trim($text); if (Regex::endsWithDirectorySeparator($effect, $separator)) { $effect = mb_substr($effect, 0, mb_strlen($effect) - mb_strlen($separator)); } return $effect; }
php
public static function removeEndingDirectorySeparator($text, $separator = '') { /* * Not a string? * Nothing to do */ if (!is_string($text)) { return ''; } if (empty($separator)) { $separator = DIRECTORY_SEPARATOR; } $effect = trim($text); if (Regex::endsWithDirectorySeparator($effect, $separator)) { $effect = mb_substr($effect, 0, mb_strlen($effect) - mb_strlen($separator)); } return $effect; }
[ "public", "static", "function", "removeEndingDirectorySeparator", "(", "$", "text", ",", "$", "separator", "=", "''", ")", "{", "/*\n * Not a string?\n * Nothing to do\n */", "if", "(", "!", "is_string", "(", "$", "text", ")", ")", "{", "retu...
Removes the ending directory's separator @param string $text Text that may contain a directory's separator at the end @param string $separator (optional) The directory's separator, e.g. "/". If is empty (not provided), system's separator is used. @return string
[ "Removes", "the", "ending", "directory", "s", "separator" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L1059-L1080
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.fillMissingZeros
public static function fillMissingZeros($number, $length, $before = true) { /* * It's not a number? Empty string is not a number too. * Nothing to do */ if (!is_numeric($number)) { return ''; } $text = trim($number); $textLength = mb_strlen($text); if ($length <= $textLength) { return $text; } for ($i = ($length - $textLength); 0 < $i; --$i) { if ($before) { $text = '0' . $text; continue; } $text .= '0'; } return $text; }
php
public static function fillMissingZeros($number, $length, $before = true) { /* * It's not a number? Empty string is not a number too. * Nothing to do */ if (!is_numeric($number)) { return ''; } $text = trim($number); $textLength = mb_strlen($text); if ($length <= $textLength) { return $text; } for ($i = ($length - $textLength); 0 < $i; --$i) { if ($before) { $text = '0' . $text; continue; } $text .= '0'; } return $text; }
[ "public", "static", "function", "fillMissingZeros", "(", "$", "number", ",", "$", "length", ",", "$", "before", "=", "true", ")", "{", "/*\n * It's not a number? Empty string is not a number too.\n * Nothing to do\n */", "if", "(", "!", "is_numeric",...
Adds missing the "0" characters to given number until given length is reached Example: - number: 201 - length: 6 - will be returned: 000201 If "before" parameter is false, zeros will be inserted after given number. If given number is longer than given length the number will be returned as it was given to the method. @param mixed $number Number for who the "0" characters should be inserted @param int $length Wanted length of final number @param bool $before (optional) If false, 0 characters will be inserted after given number @return string
[ "Adds", "missing", "the", "0", "characters", "to", "given", "number", "until", "given", "length", "is", "reached" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L1144-L1172
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getInvertedColor
public static function getInvertedColor($color) { // Prepare the color for later usage $color = trim($color); $withHash = Regex::startsWith($color, '#'); /* * Verify and get valid value of color. * An exception will be thrown if the value is not a color. */ $validColor = Regex::getValidColorHexValue($color); // Grab color's components $red = hexdec(substr($validColor, 0, 2)); $green = hexdec(substr($validColor, 2, 2)); $blue = hexdec(substr($validColor, 4, 2)); // Calculate inverted color's components $redInverted = self::getValidColorComponent(255 - $red); $greenInverted = self::getValidColorComponent(255 - $green); $blueInverted = self::getValidColorComponent(255 - $blue); // Voila, here is the inverted color $invertedColor = sprintf('%s%s%s', $redInverted, $greenInverted, $blueInverted); if ($withHash) { return sprintf('#%s', $invertedColor); } return $invertedColor; }
php
public static function getInvertedColor($color) { // Prepare the color for later usage $color = trim($color); $withHash = Regex::startsWith($color, '#'); /* * Verify and get valid value of color. * An exception will be thrown if the value is not a color. */ $validColor = Regex::getValidColorHexValue($color); // Grab color's components $red = hexdec(substr($validColor, 0, 2)); $green = hexdec(substr($validColor, 2, 2)); $blue = hexdec(substr($validColor, 4, 2)); // Calculate inverted color's components $redInverted = self::getValidColorComponent(255 - $red); $greenInverted = self::getValidColorComponent(255 - $green); $blueInverted = self::getValidColorComponent(255 - $blue); // Voila, here is the inverted color $invertedColor = sprintf('%s%s%s', $redInverted, $greenInverted, $blueInverted); if ($withHash) { return sprintf('#%s', $invertedColor); } return $invertedColor; }
[ "public", "static", "function", "getInvertedColor", "(", "$", "color", ")", "{", "// Prepare the color for later usage", "$", "color", "=", "trim", "(", "$", "color", ")", ";", "$", "withHash", "=", "Regex", "::", "startsWith", "(", "$", "color", ",", "'#'",...
Returns inverted value of color for given color @param string $color Hexadecimal value of color to invert (with or without hash), e.g. "dd244c" or "#22a5fe" @return string
[ "Returns", "inverted", "value", "of", "color", "for", "given", "color" ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L1239-L1269
train
meritoo/common-library
src/Utilities/Miscellaneous.php
Miscellaneous.getProjectRootPath
public static function getProjectRootPath() { $projectRootPath = ''; $fileName = 'composer.json'; $directoryPath = __DIR__; // Path of directory it's not the path of last directory? while (DIRECTORY_SEPARATOR !== $directoryPath) { $filePath = static::concatenatePaths($directoryPath, $fileName); /* * Is here file we are looking for? * Maybe it's a project's root path */ if (file_exists($filePath)) { $projectRootPath = $directoryPath; } $directoryPath = dirname($directoryPath); } return $projectRootPath; }
php
public static function getProjectRootPath() { $projectRootPath = ''; $fileName = 'composer.json'; $directoryPath = __DIR__; // Path of directory it's not the path of last directory? while (DIRECTORY_SEPARATOR !== $directoryPath) { $filePath = static::concatenatePaths($directoryPath, $fileName); /* * Is here file we are looking for? * Maybe it's a project's root path */ if (file_exists($filePath)) { $projectRootPath = $directoryPath; } $directoryPath = dirname($directoryPath); } return $projectRootPath; }
[ "public", "static", "function", "getProjectRootPath", "(", ")", "{", "$", "projectRootPath", "=", "''", ";", "$", "fileName", "=", "'composer.json'", ";", "$", "directoryPath", "=", "__DIR__", ";", "// Path of directory it's not the path of last directory?", "while", ...
Returns project's root path. Looks for directory that contains composer.json. @return string
[ "Returns", "project", "s", "root", "path", ".", "Looks", "for", "directory", "that", "contains", "composer", ".", "json", "." ]
b166b8b805ae97c15688d27323cae8976bd0f6dc
https://github.com/meritoo/common-library/blob/b166b8b805ae97c15688d27323cae8976bd0f6dc/src/Utilities/Miscellaneous.php#L1277-L1300
train
CeusMedia/Common
src/CLI/Fork/Server/Abstract.php
CLI_Fork_Server_Abstract.handleSignal
protected function handleSignal( $signalNumber ) { switch( $signalNumber ) { case SIGTERM: $this->signalTerm = TRUE; @unlink( $this->filePid ); break; case SIGHUP: $this->signalHangup = TRUE; break; default: $this->report( 'Funny signal: ' . $signalNumber ); } }
php
protected function handleSignal( $signalNumber ) { switch( $signalNumber ) { case SIGTERM: $this->signalTerm = TRUE; @unlink( $this->filePid ); break; case SIGHUP: $this->signalHangup = TRUE; break; default: $this->report( 'Funny signal: ' . $signalNumber ); } }
[ "protected", "function", "handleSignal", "(", "$", "signalNumber", ")", "{", "switch", "(", "$", "signalNumber", ")", "{", "case", "SIGTERM", ":", "$", "this", "->", "signalTerm", "=", "TRUE", ";", "@", "unlink", "(", "$", "this", "->", "filePid", ")", ...
Do funky things with signals
[ "Do", "funky", "things", "with", "signals" ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/CLI/Fork/Server/Abstract.php#L105-L119
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.addRule
public function addRule( ADT_CSS_Rule $rule ){ $got = $this->getRuleBySelector( $rule->selector ); if( $got ) foreach( $rule->getProperties() as $property ) $got->setPropertyByKey( $property->getKey(), $property->getValue() ); else{ if( !preg_match( '/([a-z])|(#|\.[a-z])/i', $rule->getSelector() ) ) throw new InvalidArgumentException( 'Invalid selector' ); $this->rules[] = $rule; } }
php
public function addRule( ADT_CSS_Rule $rule ){ $got = $this->getRuleBySelector( $rule->selector ); if( $got ) foreach( $rule->getProperties() as $property ) $got->setPropertyByKey( $property->getKey(), $property->getValue() ); else{ if( !preg_match( '/([a-z])|(#|\.[a-z])/i', $rule->getSelector() ) ) throw new InvalidArgumentException( 'Invalid selector' ); $this->rules[] = $rule; } }
[ "public", "function", "addRule", "(", "ADT_CSS_Rule", "$", "rule", ")", "{", "$", "got", "=", "$", "this", "->", "getRuleBySelector", "(", "$", "rule", "->", "selector", ")", ";", "if", "(", "$", "got", ")", "foreach", "(", "$", "rule", "->", "getPro...
Add rule object @access public @param ADT_CSS_Rule $rule CSS rule object @return void
[ "Add", "rule", "object" ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L61-L71
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.getSelectors
public function getSelectors(){ $list = array(); foreach( $this->rules as $rule ) $list[] = $rule->getSelector(); return $list; }
php
public function getSelectors(){ $list = array(); foreach( $this->rules as $rule ) $list[] = $rule->getSelector(); return $list; }
[ "public", "function", "getSelectors", "(", ")", "{", "$", "list", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "rules", "as", "$", "rule", ")", "$", "list", "[", "]", "=", "$", "rule", "->", "getSelector", "(", ")", ";", "retur...
Returns a list of selectors. @access public @return array
[ "Returns", "a", "list", "of", "selectors", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L114-L119
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.has
public function has( $selector, $key = NULL ){ $rule = $this->getRuleBySelector( $selector ); if( $rule ) return !$key ? TRUE : $rule->has( $key ); return FALSE; }
php
public function has( $selector, $key = NULL ){ $rule = $this->getRuleBySelector( $selector ); if( $rule ) return !$key ? TRUE : $rule->has( $key ); return FALSE; }
[ "public", "function", "has", "(", "$", "selector", ",", "$", "key", "=", "NULL", ")", "{", "$", "rule", "=", "$", "this", "->", "getRuleBySelector", "(", "$", "selector", ")", ";", "if", "(", "$", "rule", ")", "return", "!", "$", "key", "?", "TRU...
Indicates whether a property is existing by its key. @access public @param string $selector Rule selector @return boolean
[ "Indicates", "whether", "a", "property", "is", "existing", "by", "its", "key", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L127-L132
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.hasRuleBySelector
public function hasRuleBySelector( $selector ){ foreach( $this->rules as $rule ) if( $selector == $rule->getSelector() ) return TRUE; return FALSE; }
php
public function hasRuleBySelector( $selector ){ foreach( $this->rules as $rule ) if( $selector == $rule->getSelector() ) return TRUE; return FALSE; }
[ "public", "function", "hasRuleBySelector", "(", "$", "selector", ")", "{", "foreach", "(", "$", "this", "->", "rules", "as", "$", "rule", ")", "if", "(", "$", "selector", "==", "$", "rule", "->", "getSelector", "(", ")", ")", "return", "TRUE", ";", "...
Indicates whether a rule is existing by its selector. @access public @param string $selector Rule selector @return boolean
[ "Indicates", "whether", "a", "rule", "is", "existing", "by", "its", "selector", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L140-L145
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.remove
public function remove( $selector, $key ){ $rule = $this->getRuleBySelector( $selector ); if( !$rule ) return FALSE; if( $rule->removePropertyByKey( $key ) ){ if( !$rule->getProperties() ) $this->removeRuleBySelector( $selector ); return TRUE; } return FALSE; }
php
public function remove( $selector, $key ){ $rule = $this->getRuleBySelector( $selector ); if( !$rule ) return FALSE; if( $rule->removePropertyByKey( $key ) ){ if( !$rule->getProperties() ) $this->removeRuleBySelector( $selector ); return TRUE; } return FALSE; }
[ "public", "function", "remove", "(", "$", "selector", ",", "$", "key", ")", "{", "$", "rule", "=", "$", "this", "->", "getRuleBySelector", "(", "$", "selector", ")", ";", "if", "(", "!", "$", "rule", ")", "return", "FALSE", ";", "if", "(", "$", "...
Removes a property by its key. @access public @param string $selector Rule selector @param string $key Property key @return boolean
[ "Removes", "a", "property", "by", "its", "key", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L154-L164
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.removeProperty
public function removeProperty( ADT_CSS_Rule $rule, ADT_CSS_Property $property ){ return $this->remove( $rule->getSelector(), $property->getKey() ); }
php
public function removeProperty( ADT_CSS_Rule $rule, ADT_CSS_Property $property ){ return $this->remove( $rule->getSelector(), $property->getKey() ); }
[ "public", "function", "removeProperty", "(", "ADT_CSS_Rule", "$", "rule", ",", "ADT_CSS_Property", "$", "property", ")", "{", "return", "$", "this", "->", "remove", "(", "$", "rule", "->", "getSelector", "(", ")", ",", "$", "property", "->", "getKey", "(",...
Removes a property. @access public @param ADT_CSS_Rule $rule Rule object @param ADT_CSS_Property $property Property object @return boolean
[ "Removes", "a", "property", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L173-L175
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.removeRuleBySelector
public function removeRuleBySelector( $selector ){ foreach( $this->rules as $nr => $rule ){ if( $selector == $rule->getSelector() ){ unset( $this->rules[$nr] ); return TRUE; } } return FALSE; }
php
public function removeRuleBySelector( $selector ){ foreach( $this->rules as $nr => $rule ){ if( $selector == $rule->getSelector() ){ unset( $this->rules[$nr] ); return TRUE; } } return FALSE; }
[ "public", "function", "removeRuleBySelector", "(", "$", "selector", ")", "{", "foreach", "(", "$", "this", "->", "rules", "as", "$", "nr", "=>", "$", "rule", ")", "{", "if", "(", "$", "selector", "==", "$", "rule", "->", "getSelector", "(", ")", ")",...
Removes a rule by its selector. @access public @param string $selector Rule selector @return boolean
[ "Removes", "a", "rule", "by", "its", "selector", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L193-L201
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.set
public function set( $selector, $key, $value = NULL ){ if( $value === NULL || !strlen( $value ) ) return $this->remove( $selector, $key ); $rule = $this->getRuleBySelector( $selector ); if( !$rule ){ $rule = new ADT_CSS_Rule( $selector ); $this->rules[] = $rule; } return $rule->setPropertyByKey( $key, $value ); }
php
public function set( $selector, $key, $value = NULL ){ if( $value === NULL || !strlen( $value ) ) return $this->remove( $selector, $key ); $rule = $this->getRuleBySelector( $selector ); if( !$rule ){ $rule = new ADT_CSS_Rule( $selector ); $this->rules[] = $rule; } return $rule->setPropertyByKey( $key, $value ); }
[ "public", "function", "set", "(", "$", "selector", ",", "$", "key", ",", "$", "value", "=", "NULL", ")", "{", "if", "(", "$", "value", "===", "NULL", "||", "!", "strlen", "(", "$", "value", ")", ")", "return", "$", "this", "->", "remove", "(", ...
Sets a properties value. @access public @param string $selector Rule selector @param string $key Property key @param string $value Property value @return boolean
[ "Sets", "a", "properties", "value", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L211-L220
train
CeusMedia/Common
src/ADT/CSS/Sheet.php
ADT_CSS_Sheet.setProperty
public function setProperty( ADT_CSS_Rule $rule, ADT_CSS_Property $property ){ return $this->set( $rule->getSelector(), $property->getKey(), $property->getValue() ); // }
php
public function setProperty( ADT_CSS_Rule $rule, ADT_CSS_Property $property ){ return $this->set( $rule->getSelector(), $property->getKey(), $property->getValue() ); // }
[ "public", "function", "setProperty", "(", "ADT_CSS_Rule", "$", "rule", ",", "ADT_CSS_Property", "$", "property", ")", "{", "return", "$", "this", "->", "set", "(", "$", "rule", "->", "getSelector", "(", ")", ",", "$", "property", "->", "getKey", "(", ")"...
Sets a property. @access public @param ADT_CSS_Rule $rule Rule object @param ADT_CSS_Property $property Property object @return boolean
[ "Sets", "a", "property", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/CSS/Sheet.php#L229-L231
train
CeusMedia/Common
src/FS/File/SyntaxChecker.php
FS_File_SyntaxChecker.checkFile
public function checkFile( $fileName ) { $output = shell_exec('php -l "'.$fileName.'"'); if( preg_match( "@^No syntax errors detected@", $output ) ) return TRUE; $this->error = $output; return FALSE; }
php
public function checkFile( $fileName ) { $output = shell_exec('php -l "'.$fileName.'"'); if( preg_match( "@^No syntax errors detected@", $output ) ) return TRUE; $this->error = $output; return FALSE; }
[ "public", "function", "checkFile", "(", "$", "fileName", ")", "{", "$", "output", "=", "shell_exec", "(", "'php -l \"'", ".", "$", "fileName", ".", "'\"'", ")", ";", "if", "(", "preg_match", "(", "\"@^No syntax errors detected@\"", ",", "$", "output", ")", ...
Returns whether a PHP Class or Script has valid Syntax. @access public @param string $fileName File Name of PHP File to check @return bool
[ "Returns", "whether", "a", "PHP", "Class", "or", "Script", "has", "valid", "Syntax", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/SyntaxChecker.php#L48-L55
train
CeusMedia/Common
src/FS/File/SyntaxChecker.php
FS_File_SyntaxChecker.getShortError
public function getShortError() { $error = array_shift( explode( "\n", trim( $this->error ) ) ); $error = preg_replace( "@^Parse error: (.*) in (.*) on (.*)$@i", "\\1 on \\3", $error ); return $error; }
php
public function getShortError() { $error = array_shift( explode( "\n", trim( $this->error ) ) ); $error = preg_replace( "@^Parse error: (.*) in (.*) on (.*)$@i", "\\1 on \\3", $error ); return $error; }
[ "public", "function", "getShortError", "(", ")", "{", "$", "error", "=", "array_shift", "(", "explode", "(", "\"\\n\"", ",", "trim", "(", "$", "this", "->", "error", ")", ")", ")", ";", "$", "error", "=", "preg_replace", "(", "\"@^Parse error: (.*) in (.*)...
Returns Error of last File Syntax Check in a shorter Format without File Name and Parser Prefix. @access public @return string
[ "Returns", "Error", "of", "last", "File", "Syntax", "Check", "in", "a", "shorter", "Format", "without", "File", "Name", "and", "Parser", "Prefix", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/SyntaxChecker.php#L72-L77
train
CeusMedia/Common
src/Alg/Tree/Menu/Converter.php
Alg_Tree_Menu_Converter.buildMenuListFromOutlines
protected static function buildMenuListFromOutlines( $lines, &$container ) { foreach( $lines as $line ) { if( isset( $line['outlines'] ) && count( $line['outlines'] ) ) { if( isset ( $line['url'] ) ) $item = new ADT_Tree_Menu_Item( $line['url'], $line['text'] ); else $item = new ADT_Tree_Menu_List( $line['text'] ); self::buildMenuListFromOutlines( $line['outlines'], $item ); $container->addChild( $item ); } else { $item = new ADT_Tree_Menu_Item( $line['url'], $line['text'] ); $container->addChild( $item ); } } }
php
protected static function buildMenuListFromOutlines( $lines, &$container ) { foreach( $lines as $line ) { if( isset( $line['outlines'] ) && count( $line['outlines'] ) ) { if( isset ( $line['url'] ) ) $item = new ADT_Tree_Menu_Item( $line['url'], $line['text'] ); else $item = new ADT_Tree_Menu_List( $line['text'] ); self::buildMenuListFromOutlines( $line['outlines'], $item ); $container->addChild( $item ); } else { $item = new ADT_Tree_Menu_Item( $line['url'], $line['text'] ); $container->addChild( $item ); } } }
[ "protected", "static", "function", "buildMenuListFromOutlines", "(", "$", "lines", ",", "&", "$", "container", ")", "{", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "if", "(", "isset", "(", "$", "line", "[", "'outlines'", "]", ")", "&&",...
Adds Tree Menu Items from OPML Outlines into a given Tree Menu List recursively. @access public @static @param array $outlines Outline Array from OPML Parser @param ADT_Tree_Menu_List $container Current working Menu Container, a Tree Menu List initially. @return void
[ "Adds", "Tree", "Menu", "Items", "from", "OPML", "Outlines", "into", "a", "given", "Tree", "Menu", "List", "recursively", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Tree/Menu/Converter.php#L53-L72
train
CeusMedia/Common
src/Alg/Tree/Menu/Converter.php
Alg_Tree_Menu_Converter.convertFromOpml
public static function convertFromOpml( $opml, $labelRoot, $rootClass = NULL ) { $parser = new XML_OPML_Parser(); $parser->parse( $opml ); $lines = $parser->getOutlines(); $list = new ADT_Tree_Menu_List( $labelRoot, array( 'class' => $rootClass ) ); self::buildMenuListFromOutlines( $lines, $list ); return $list; }
php
public static function convertFromOpml( $opml, $labelRoot, $rootClass = NULL ) { $parser = new XML_OPML_Parser(); $parser->parse( $opml ); $lines = $parser->getOutlines(); $list = new ADT_Tree_Menu_List( $labelRoot, array( 'class' => $rootClass ) ); self::buildMenuListFromOutlines( $lines, $list ); return $list; }
[ "public", "static", "function", "convertFromOpml", "(", "$", "opml", ",", "$", "labelRoot", ",", "$", "rootClass", "=", "NULL", ")", "{", "$", "parser", "=", "new", "XML_OPML_Parser", "(", ")", ";", "$", "parser", "->", "parse", "(", "$", "opml", ")", ...
Converts an OPML String to a Tree Menu List. @access public @static @param string $opml OPML String @param string $labelRoot Label of Top Tree Menu List @param string $rootClass CSS Class of root node @return ADT_Tree_Menu_List
[ "Converts", "an", "OPML", "String", "to", "a", "Tree", "Menu", "List", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Tree/Menu/Converter.php#L83-L92
train
CeusMedia/Common
src/Alg/Tree/Menu/Converter.php
Alg_Tree_Menu_Converter.convertFromOpmlFile
public static function convertFromOpmlFile( $fileName, $labelRoot, $rootClass = NULL ) { $opml = FS_File_Reader::load( $fileName ); return self::convertFromOpml( $opml, $labelRoot, $rootClass ); }
php
public static function convertFromOpmlFile( $fileName, $labelRoot, $rootClass = NULL ) { $opml = FS_File_Reader::load( $fileName ); return self::convertFromOpml( $opml, $labelRoot, $rootClass ); }
[ "public", "static", "function", "convertFromOpmlFile", "(", "$", "fileName", ",", "$", "labelRoot", ",", "$", "rootClass", "=", "NULL", ")", "{", "$", "opml", "=", "FS_File_Reader", "::", "load", "(", "$", "fileName", ")", ";", "return", "self", "::", "c...
Converts an OPML File to a Tree Menu List. @access public @static @param string $fileName File Name of OPML File @param string $labelRoot Label of Top Tree Menu List @param string $rootClass CSS Class of root node @return ADT_Tree_Menu_List
[ "Converts", "an", "OPML", "File", "to", "a", "Tree", "Menu", "List", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Tree/Menu/Converter.php#L103-L107
train
CeusMedia/Common
src/XML/WDDX/FileWriter.php
XML_WDDX_FileWriter.write
public function write() { $wddx = $this->builder->build(); $writer = new FS_File_Writer( $this->fileName ); return $writer->writeString( $wddx ); }
php
public function write() { $wddx = $this->builder->build(); $writer = new FS_File_Writer( $this->fileName ); return $writer->writeString( $wddx ); }
[ "public", "function", "write", "(", ")", "{", "$", "wddx", "=", "$", "this", "->", "builder", "->", "build", "(", ")", ";", "$", "writer", "=", "new", "FS_File_Writer", "(", "$", "this", "->", "fileName", ")", ";", "return", "$", "writer", "->", "w...
Writes collected Data into WDDX File. @access public @param string string String to write to WDDX File @return bool
[ "Writes", "collected", "Data", "into", "WDDX", "File", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/WDDX/FileWriter.php#L78-L83
train
CeusMedia/Common
src/XML/WDDX/FileWriter.php
XML_WDDX_FileWriter.save
public static function save( $fileName, $data, $packetName = NULL ) { if( $packetName === NULL ) $wddx = wddx_serialize_value( $data ); else $wddx = wddx_serialize_value( $data, $packetName ); return FS_File_Writer::save( $fileName, $wddx ); }
php
public static function save( $fileName, $data, $packetName = NULL ) { if( $packetName === NULL ) $wddx = wddx_serialize_value( $data ); else $wddx = wddx_serialize_value( $data, $packetName ); return FS_File_Writer::save( $fileName, $wddx ); }
[ "public", "static", "function", "save", "(", "$", "fileName", ",", "$", "data", ",", "$", "packetName", "=", "NULL", ")", "{", "if", "(", "$", "packetName", "===", "NULL", ")", "$", "wddx", "=", "wddx_serialize_value", "(", "$", "data", ")", ";", "el...
Writes Data into a WDDX File statically. @access public @static @param string $fileName File Name of WDDX File @param array $data Array of Packet Data @param string $packetName Packet Name @return int
[ "Writes", "Data", "into", "a", "WDDX", "File", "statically", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/XML/WDDX/FileWriter.php#L94-L101
train
CeusMedia/Common
src/Net/XMPP/MessageSender.php
Net_XMPP_MessageSender.connect
public function connect( Net_XMPP_JID $sender, $password ) { $this->xmpp = new Net_XMPP_XMPPHP_XMPP( $sender->getDomain(), $this->port, $sender->getNode(), $password, $sender->getResource() ? $sender->getResource() : $this->resource, $sender->getDomain(), $this->printLog, $this->logLevel ); $this->xmpp->use_encyption = $this->encryption; $this->xmpp->connect(); $this->xmpp->processUntil( 'session_start' ); }
php
public function connect( Net_XMPP_JID $sender, $password ) { $this->xmpp = new Net_XMPP_XMPPHP_XMPP( $sender->getDomain(), $this->port, $sender->getNode(), $password, $sender->getResource() ? $sender->getResource() : $this->resource, $sender->getDomain(), $this->printLog, $this->logLevel ); $this->xmpp->use_encyption = $this->encryption; $this->xmpp->connect(); $this->xmpp->processUntil( 'session_start' ); }
[ "public", "function", "connect", "(", "Net_XMPP_JID", "$", "sender", ",", "$", "password", ")", "{", "$", "this", "->", "xmpp", "=", "new", "Net_XMPP_XMPPHP_XMPP", "(", "$", "sender", "->", "getDomain", "(", ")", ",", "$", "this", "->", "port", ",", "$...
Establishs Connection to XMPP Server. @access public @param Net_XMPP_JID $sender JID of sender @param string $password Password of Sender @param int $port Port of XMPP Server @return void
[ "Establishs", "Connection", "to", "XMPP", "Server", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/MessageSender.php#L97-L112
train
CeusMedia/Common
src/Net/XMPP/MessageSender.php
Net_XMPP_MessageSender.disconnect
public function disconnect() { if( $this->xmpp ) { if( $this->printLog ) echo $this->xmpp->log->printout(); $this->xmpp->disconnect(); $this->xmpp = NULL; return TRUE; } return FALSE; }
php
public function disconnect() { if( $this->xmpp ) { if( $this->printLog ) echo $this->xmpp->log->printout(); $this->xmpp->disconnect(); $this->xmpp = NULL; return TRUE; } return FALSE; }
[ "public", "function", "disconnect", "(", ")", "{", "if", "(", "$", "this", "->", "xmpp", ")", "{", "if", "(", "$", "this", "->", "printLog", ")", "echo", "$", "this", "->", "xmpp", "->", "log", "->", "printout", "(", ")", ";", "$", "this", "->", ...
Closes Connection if still open. @access public @return bool
[ "Closes", "Connection", "if", "still", "open", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/MessageSender.php#L119-L130
train
CeusMedia/Common
src/Net/XMPP/MessageSender.php
Net_XMPP_MessageSender.sendMessage
public function sendMessage( $message ) { if( !$this->receiver ) throw new RuntimeException( 'No Receiver set.' ); $this->sendMessageTo( $message, $this->receiver->get() ); }
php
public function sendMessage( $message ) { if( !$this->receiver ) throw new RuntimeException( 'No Receiver set.' ); $this->sendMessageTo( $message, $this->receiver->get() ); }
[ "public", "function", "sendMessage", "(", "$", "message", ")", "{", "if", "(", "!", "$", "this", "->", "receiver", ")", "throw", "new", "RuntimeException", "(", "'No Receiver set.'", ")", ";", "$", "this", "->", "sendMessageTo", "(", "$", "message", ",", ...
Sends Message to set Receiver. @access public @param string $message Message to send to Receiver @return void @throws RuntimeException if no receiver has been set
[ "Sends", "Message", "to", "set", "Receiver", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/MessageSender.php#L139-L144
train
CeusMedia/Common
src/Net/XMPP/MessageSender.php
Net_XMPP_MessageSender.sendMessageTo
public function sendMessageTo( $message, $receiver ) { if( is_string( $receiver ) ) $receiver = new Net_XMPP_JID( $receiver ); if( !$this->xmpp ) throw new RuntimeException( 'Not connected to Server.' ); $this->xmpp->message( $receiver->get(), $message ); }
php
public function sendMessageTo( $message, $receiver ) { if( is_string( $receiver ) ) $receiver = new Net_XMPP_JID( $receiver ); if( !$this->xmpp ) throw new RuntimeException( 'Not connected to Server.' ); $this->xmpp->message( $receiver->get(), $message ); }
[ "public", "function", "sendMessageTo", "(", "$", "message", ",", "$", "receiver", ")", "{", "if", "(", "is_string", "(", "$", "receiver", ")", ")", "$", "receiver", "=", "new", "Net_XMPP_JID", "(", "$", "receiver", ")", ";", "if", "(", "!", "$", "thi...
Sends Message to a Receiver. @access public @param string $message Message to send to Receiver @param string $receiver JID of Receiver @return void @throws RuntimeException if XMPP connection is not established
[ "Sends", "Message", "to", "a", "Receiver", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/MessageSender.php#L154-L161
train
CeusMedia/Common
src/Net/XMPP/MessageSender.php
Net_XMPP_MessageSender.setReceiver
public function setReceiver( $receiver ) { if( is_string( $receiver ) ) $receiver = new Net_XMPP_JID( $receiver ); $this->receiver = $receiver; }
php
public function setReceiver( $receiver ) { if( is_string( $receiver ) ) $receiver = new Net_XMPP_JID( $receiver ); $this->receiver = $receiver; }
[ "public", "function", "setReceiver", "(", "$", "receiver", ")", "{", "if", "(", "is_string", "(", "$", "receiver", ")", ")", "$", "receiver", "=", "new", "Net_XMPP_JID", "(", "$", "receiver", ")", ";", "$", "this", "->", "receiver", "=", "$", "receiver...
Sets Receiver by its JID. @access public @param string $receiver JID of Receiver @return void
[ "Sets", "Receiver", "by", "its", "JID", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/XMPP/MessageSender.php#L225-L230
train
php-toolkit/cli-utils
src/Highlighter.php
Highlighter.highlight
public function highlight(string $source, bool $withLineNumber = false): string { $tokenLines = $this->getHighlightedLines($source); $lines = $this->colorLines($tokenLines); if ($withLineNumber) { return $this->lineNumbers($lines); } return \implode(\PHP_EOL, $lines); }
php
public function highlight(string $source, bool $withLineNumber = false): string { $tokenLines = $this->getHighlightedLines($source); $lines = $this->colorLines($tokenLines); if ($withLineNumber) { return $this->lineNumbers($lines); } return \implode(\PHP_EOL, $lines); }
[ "public", "function", "highlight", "(", "string", "$", "source", ",", "bool", "$", "withLineNumber", "=", "false", ")", ":", "string", "{", "$", "tokenLines", "=", "$", "this", "->", "getHighlightedLines", "(", "$", "source", ")", ";", "$", "lines", "=",...
highlight a full php file content @param string $source @param bool $withLineNumber with line number @return string
[ "highlight", "a", "full", "php", "file", "content" ]
bc60e7744db8f5452a1421770c00e315d00e3153
https://github.com/php-toolkit/cli-utils/blob/bc60e7744db8f5452a1421770c00e315d00e3153/src/Highlighter.php#L71-L81
train
CeusMedia/Common
src/Alg/Validation/PredicateValidator.php
Alg_Validation_PredicateValidator.isClass
public function isClass( $value, $class ) { $method = "is".ucFirst( $class ); if( !method_exists( $this->validator, $method ) ) throw new BadMethodCallException( 'Predicate "'.$method.'" is not defined.' ); return $this->validator->$method( $value, $method ); }
php
public function isClass( $value, $class ) { $method = "is".ucFirst( $class ); if( !method_exists( $this->validator, $method ) ) throw new BadMethodCallException( 'Predicate "'.$method.'" is not defined.' ); return $this->validator->$method( $value, $method ); }
[ "public", "function", "isClass", "(", "$", "value", ",", "$", "class", ")", "{", "$", "method", "=", "\"is\"", ".", "ucFirst", "(", "$", "class", ")", ";", "if", "(", "!", "method_exists", "(", "$", "this", "->", "validator", ",", "$", "method", ")...
Indicates whether a String is of a specific Character Class. @access public @param string $value String to be checked @param string $class Key of Character Class @return bool
[ "Indicates", "whether", "a", "String", "is", "of", "a", "specific", "Character", "Class", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Validation/PredicateValidator.php#L63-L69
train
CeusMedia/Common
src/Alg/Validation/PredicateValidator.php
Alg_Validation_PredicateValidator.validate
public function validate( $value, $predicate, $argument = NULL ) { if( !method_exists( $this->validator, $predicate ) ) throw new BadMethodCallException( 'Predicate "'.$predicate.'" is not defined.' ); try { return $this->validator->$predicate( $value, $argument ); } catch( InvalidArgumentException $e ) { return false; } catch( Exception $e ) { throw $e; } }
php
public function validate( $value, $predicate, $argument = NULL ) { if( !method_exists( $this->validator, $predicate ) ) throw new BadMethodCallException( 'Predicate "'.$predicate.'" is not defined.' ); try { return $this->validator->$predicate( $value, $argument ); } catch( InvalidArgumentException $e ) { return false; } catch( Exception $e ) { throw $e; } }
[ "public", "function", "validate", "(", "$", "value", ",", "$", "predicate", ",", "$", "argument", "=", "NULL", ")", "{", "if", "(", "!", "method_exists", "(", "$", "this", "->", "validator", ",", "$", "predicate", ")", ")", "throw", "new", "BadMethodCa...
Indicates whether a String validates against a Predicate. @access public @param string $value String to be checked @param string $predicate Method Name of Predicate @param string $argument Argument for Predicate @return bool
[ "Indicates", "whether", "a", "String", "validates", "against", "a", "Predicate", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Alg/Validation/PredicateValidator.php#L79-L95
train
CeusMedia/Common
src/FS/File/Gantt/MeetingCollector.php
FS_File_Gantt_MeetingCollector.listProjectFiles
protected static function listProjectFiles( $path ) { $list = array(); $dir = new DirectoryIterator( $path ); foreach( $dir as $entry ) { if( $entry->isDot() ) continue; if( !preg_match( "@\.gan$@", $entry->getFilename() ) ) continue; $list[] = $entry->getPathname(); } return $list; }
php
protected static function listProjectFiles( $path ) { $list = array(); $dir = new DirectoryIterator( $path ); foreach( $dir as $entry ) { if( $entry->isDot() ) continue; if( !preg_match( "@\.gan$@", $entry->getFilename() ) ) continue; $list[] = $entry->getPathname(); } return $list; }
[ "protected", "static", "function", "listProjectFiles", "(", "$", "path", ")", "{", "$", "list", "=", "array", "(", ")", ";", "$", "dir", "=", "new", "DirectoryIterator", "(", "$", "path", ")", ";", "foreach", "(", "$", "dir", "as", "$", "entry", ")",...
Lists all Gantt Project XML Files in a specified Path. @access protected @static @param array $path Path to Gantt Project XML Files @return array
[ "Lists", "all", "Gantt", "Project", "XML", "Files", "in", "a", "specified", "Path", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Gantt/MeetingCollector.php#L114-L127
train
CeusMedia/Common
src/FS/File/Gantt/MeetingCollector.php
FS_File_Gantt_MeetingCollector.readProjectFiles
protected static function readProjectFiles( $fileList ) { $projects = array(); foreach( $fileList as $fileName ) { $reader = new FS_File_Gantt_MeetingReader( $fileName ); $projects[] = $reader->getProjectData(); } return $projects; }
php
protected static function readProjectFiles( $fileList ) { $projects = array(); foreach( $fileList as $fileName ) { $reader = new FS_File_Gantt_MeetingReader( $fileName ); $projects[] = $reader->getProjectData(); } return $projects; }
[ "protected", "static", "function", "readProjectFiles", "(", "$", "fileList", ")", "{", "$", "projects", "=", "array", "(", ")", ";", "foreach", "(", "$", "fileList", "as", "$", "fileName", ")", "{", "$", "reader", "=", "new", "FS_File_Gantt_MeetingReader", ...
Reads Gantt Project XML Files and extracts Project and Meeting Dates. @access protected @static @param array $fileList List of Gantt Project XML Files @return array
[ "Reads", "Gantt", "Project", "XML", "Files", "and", "extracts", "Project", "and", "Meeting", "Dates", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/FS/File/Gantt/MeetingCollector.php#L136-L145
train
CeusMedia/Common
src/ADT/Object.php
ADT_Object.getObjectInfo
public function getObjectInfo() { $info = array( 'name' => $this->getClass(), 'parent' => $this->getParent(), 'methods' => $this->getMethods(), 'vars' => $this->getVars(), ); return $info; }
php
public function getObjectInfo() { $info = array( 'name' => $this->getClass(), 'parent' => $this->getParent(), 'methods' => $this->getMethods(), 'vars' => $this->getVars(), ); return $info; }
[ "public", "function", "getObjectInfo", "(", ")", "{", "$", "info", "=", "array", "(", "'name'", "=>", "$", "this", "->", "getClass", "(", ")", ",", "'parent'", "=>", "$", "this", "->", "getParent", "(", ")", ",", "'methods'", "=>", "$", "this", "->",...
Returns an Array with Information about current Object. @access public @return array
[ "Returns", "an", "Array", "with", "Information", "about", "current", "Object", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Object.php#L65-L74
train
CeusMedia/Common
src/ADT/Object.php
ADT_Object.hasMethod
public function hasMethod( $methodName, $callableOnly = TRUE ) { if( $callableOnly ) return method_exists( $this, $methodName ) && is_callable( array( $this, $methodName ) ); else return method_exists( $this, $methodName ); }
php
public function hasMethod( $methodName, $callableOnly = TRUE ) { if( $callableOnly ) return method_exists( $this, $methodName ) && is_callable( array( $this, $methodName ) ); else return method_exists( $this, $methodName ); }
[ "public", "function", "hasMethod", "(", "$", "methodName", ",", "$", "callableOnly", "=", "TRUE", ")", "{", "if", "(", "$", "callableOnly", ")", "return", "method_exists", "(", "$", "this", ",", "$", "methodName", ")", "&&", "is_callable", "(", "array", ...
Indicates whether an Method is existing within current Object. @access public @param string $methodName Name of Method to check @param bool $callableOnly Flag: also check if Method is callable @return bool
[ "Indicates", "whether", "an", "Method", "is", "existing", "within", "current", "Object", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/ADT/Object.php#L103-L109
train
CeusMedia/Common
src/Net/HTTP/Response.php
Net_HTTP_Response.addHeader
public function addHeader( Net_HTTP_Header_Field $field, $emptyBefore = NULL ) { $this->headers->setField( $field, $emptyBefore ); }
php
public function addHeader( Net_HTTP_Header_Field $field, $emptyBefore = NULL ) { $this->headers->setField( $field, $emptyBefore ); }
[ "public", "function", "addHeader", "(", "Net_HTTP_Header_Field", "$", "field", ",", "$", "emptyBefore", "=", "NULL", ")", "{", "$", "this", "->", "headers", "->", "setField", "(", "$", "field", ",", "$", "emptyBefore", ")", ";", "}" ]
Adds an HTTP header field object. @access public @param Net_HTTP_Header_Field $field HTTP header field object @return void
[ "Adds", "an", "HTTP", "header", "field", "object", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Response.php#L73-L76
train
CeusMedia/Common
src/Net/HTTP/Response.php
Net_HTTP_Response.addHeaderPair
public function addHeaderPair( $name, $value, $emptyBefore = NULL ) { $this->headers->setField( new Net_HTTP_Header_Field( $name, $value ), $emptyBefore ); }
php
public function addHeaderPair( $name, $value, $emptyBefore = NULL ) { $this->headers->setField( new Net_HTTP_Header_Field( $name, $value ), $emptyBefore ); }
[ "public", "function", "addHeaderPair", "(", "$", "name", ",", "$", "value", ",", "$", "emptyBefore", "=", "NULL", ")", "{", "$", "this", "->", "headers", "->", "setField", "(", "new", "Net_HTTP_Header_Field", "(", "$", "name", ",", "$", "value", ")", "...
Adds an HTTP header. @access public @param string $name HTTP header name @param string $value HTTP header value @return void
[ "Adds", "an", "HTTP", "header", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Response.php#L85-L88
train
CeusMedia/Common
src/Net/HTTP/Response.php
Net_HTTP_Response.getHeader
public function getHeader( $key, $first = NULL ) { $fields = $this->headers->getFieldsByName( $key ); // get all header fields with this header name if( !$first ) // all header fields shall be returned return $fields; // return all header fields if( $fields ) // otherwise: header fields (atleat one) are set return $fields[0]; // return first header field return new Net_HTTP_Header_Field( $key, NULL ); // otherwise: return empty fake header field }
php
public function getHeader( $key, $first = NULL ) { $fields = $this->headers->getFieldsByName( $key ); // get all header fields with this header name if( !$first ) // all header fields shall be returned return $fields; // return all header fields if( $fields ) // otherwise: header fields (atleat one) are set return $fields[0]; // return first header field return new Net_HTTP_Header_Field( $key, NULL ); // otherwise: return empty fake header field }
[ "public", "function", "getHeader", "(", "$", "key", ",", "$", "first", "=", "NULL", ")", "{", "$", "fields", "=", "$", "this", "->", "headers", "->", "getFieldsByName", "(", "$", "key", ")", ";", "// get all header fields with this header name", "if", "(", ...
Returns response headers. @access public @param string $string Header name @param bool $first Flag: return first header only @return array|Net_HTTP_Header_Field List of header fields or only one header field if requested so
[ "Returns", "response", "headers", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Response.php#L107-L115
train
CeusMedia/Common
src/Net/HTTP/Response.php
Net_HTTP_Response.setBody
public function setBody( $body ) { if( !is_string( $body ) ) throw new InvalidArgumentException( 'Body must be string' ); $this->body = trim( $body ); $this->headers->setFieldPair( "Content-Length", strlen( $this->body ), TRUE ); }
php
public function setBody( $body ) { if( !is_string( $body ) ) throw new InvalidArgumentException( 'Body must be string' ); $this->body = trim( $body ); $this->headers->setFieldPair( "Content-Length", strlen( $this->body ), TRUE ); }
[ "public", "function", "setBody", "(", "$", "body", ")", "{", "if", "(", "!", "is_string", "(", "$", "body", ")", ")", "throw", "new", "InvalidArgumentException", "(", "'Body must be string'", ")", ";", "$", "this", "->", "body", "=", "trim", "(", "$", ...
Sets response message body. @access public @param string $body Response message body @return void
[ "Sets", "response", "message", "body", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Response.php#L179-L185
train
CeusMedia/Common
src/Net/HTTP/Response.php
Net_HTTP_Response.toString
public function toString() { $lines = array(); $lines[] = $this->protocol.'/'.$this->version.' '.$this->status; // add main protocol header $lines[] = $this->headers->toString(); // add header fields and line break if( strlen( $this->body ) ) // response body is set $lines[] = $this->body; // add response body return join( "\r\n", $lines ); // glue parts with line break and return result }
php
public function toString() { $lines = array(); $lines[] = $this->protocol.'/'.$this->version.' '.$this->status; // add main protocol header $lines[] = $this->headers->toString(); // add header fields and line break if( strlen( $this->body ) ) // response body is set $lines[] = $this->body; // add response body return join( "\r\n", $lines ); // glue parts with line break and return result }
[ "public", "function", "toString", "(", ")", "{", "$", "lines", "=", "array", "(", ")", ";", "$", "lines", "[", "]", "=", "$", "this", "->", "protocol", ".", "'/'", ".", "$", "this", "->", "version", ".", "' '", ".", "$", "this", "->", "status", ...
Renders complete response string. @access public @return string
[ "Renders", "complete", "response", "string", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Response.php#L244-L252
train
CeusMedia/Common
src/Net/HTTP/Sniffer/MimeType.php
Net_HTTP_Sniffer_MimeType.getMimeType
public static function getMimeType( $allowed, $default = false ) { if( !$default) $default = $allowed[0]; $pattern = '@^([a-z\*\+]+(/[a-z\*\+]+)*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$@i'; $accepted = getEnv( 'HTTP_ACCEPT' ); if( !$accepted ) return $default; $accepted = preg_split( '/,\s*/', $accepted ); $curr_mime = $default; $curr_qual = 0; foreach( $accepted as $accept) { if( !preg_match ( $pattern, $accept, $matches ) ) continue; $mime_code = explode ( '/', $matches[1] ); $mime_quality = isset( $matches[3] ) ? (float) $matches[3] : 1.0; while( count( $mime_code ) ) { if( in_array( strtolower( join( '/', $mime_code ) ), $allowed ) ) { if( $mime_quality > $curr_qual ) { $curr_mime = strtolower( join( '/', $mime_code ) ); $curr_qual = $mime_quality; break; } } array_pop( $mime_code ); } } return $curr_mime; }
php
public static function getMimeType( $allowed, $default = false ) { if( !$default) $default = $allowed[0]; $pattern = '@^([a-z\*\+]+(/[a-z\*\+]+)*)(?:;\s*q=(0(?:\.[0-9]{1,3})?|1(?:\.0{1,3})?))?$@i'; $accepted = getEnv( 'HTTP_ACCEPT' ); if( !$accepted ) return $default; $accepted = preg_split( '/,\s*/', $accepted ); $curr_mime = $default; $curr_qual = 0; foreach( $accepted as $accept) { if( !preg_match ( $pattern, $accept, $matches ) ) continue; $mime_code = explode ( '/', $matches[1] ); $mime_quality = isset( $matches[3] ) ? (float) $matches[3] : 1.0; while( count( $mime_code ) ) { if( in_array( strtolower( join( '/', $mime_code ) ), $allowed ) ) { if( $mime_quality > $curr_qual ) { $curr_mime = strtolower( join( '/', $mime_code ) ); $curr_qual = $mime_quality; break; } } array_pop( $mime_code ); } } return $curr_mime; }
[ "public", "static", "function", "getMimeType", "(", "$", "allowed", ",", "$", "default", "=", "false", ")", "{", "if", "(", "!", "$", "default", ")", "$", "default", "=", "$", "allowed", "[", "0", "]", ";", "$", "pattern", "=", "'@^([a-z\\*\\+]+(/[a-z\...
Returns prefered allowed and accepted Mime Types. @access public @static @param array $allowed Array of Mime Types supported and allowed by the Application @param string $default Default Mime Types supported and allowed by the Application @return string
[ "Returns", "prefered", "allowed", "and", "accepted", "Mime", "Types", "." ]
1138adf9341782a6284c05884989f7497532bcf4
https://github.com/CeusMedia/Common/blob/1138adf9341782a6284c05884989f7497532bcf4/src/Net/HTTP/Sniffer/MimeType.php#L50-L82
train