id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
14,200
dphn/ScContent
src/ScContent/Service/Dir.php
Dir.appUploads
public function appUploads($path = '', $checkIfExists = false) { $appUploadsDir = getcwd() . $this->getRelativeAppUploadsDir(); if ($checkIfExists) { return realpath($appUploadsDir . DS . $path); } if (empty($path)) { return $appUploadsDir; } return $appUploadsDir . DS . $this->normalizePath($path); }
php
public function appUploads($path = '', $checkIfExists = false) { $appUploadsDir = getcwd() . $this->getRelativeAppUploadsDir(); if ($checkIfExists) { return realpath($appUploadsDir . DS . $path); } if (empty($path)) { return $appUploadsDir; } return $appUploadsDir . DS . $this->normalizePath($path); }
[ "public", "function", "appUploads", "(", "$", "path", "=", "''", ",", "$", "checkIfExists", "=", "false", ")", "{", "$", "appUploadsDir", "=", "getcwd", "(", ")", ".", "$", "this", "->", "getRelativeAppUploadsDir", "(", ")", ";", "if", "(", "$", "checkIfExists", ")", "{", "return", "realpath", "(", "$", "appUploadsDir", ".", "DS", ".", "$", "path", ")", ";", "}", "if", "(", "empty", "(", "$", "path", ")", ")", "{", "return", "$", "appUploadsDir", ";", "}", "return", "$", "appUploadsDir", ".", "DS", ".", "$", "this", "->", "normalizePath", "(", "$", "path", ")", ";", "}" ]
Returns the path to the upload directory, or any child path. If the flag "checkIfExists" is set to TRUE, checks for the specified path and if the path was not found, returns FALSE. Usage: <code> $dir = $serviceLocator->get('ScService.Dir'); $uploadedFile = $dir->appUploads('test.jpg'); </code> @api @param string $path @param boolean $checkIfExists optional default false @return string
[ "Returns", "the", "path", "to", "the", "upload", "directory", "or", "any", "child", "path", "." ]
9dd5732490c45fd788b96cedf7b3c7adfacb30d2
https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Service/Dir.php#L236-L246
14,201
andylolz/everypolitician-popolo-php
src/Popolo.php
Popolo.fromFilename
public static function fromFilename($filename) { $contents = file_get_contents($filename); $jsonData = json_decode($contents, true); $instance = new self($jsonData); return $instance; }
php
public static function fromFilename($filename) { $contents = file_get_contents($filename); $jsonData = json_decode($contents, true); $instance = new self($jsonData); return $instance; }
[ "public", "static", "function", "fromFilename", "(", "$", "filename", ")", "{", "$", "contents", "=", "file_get_contents", "(", "$", "filename", ")", ";", "$", "jsonData", "=", "json_decode", "(", "$", "contents", ",", "true", ")", ";", "$", "instance", "=", "new", "self", "(", "$", "jsonData", ")", ";", "return", "$", "instance", ";", "}" ]
Construct from filename @param string $filename name of Popolo json file @return $this
[ "Construct", "from", "filename" ]
701fca91b782871d463cfb56f3c1c7afb121eb9f
https://github.com/andylolz/everypolitician-popolo-php/blob/701fca91b782871d463cfb56f3c1c7afb121eb9f/src/Popolo.php#L48-L54
14,202
andylolz/everypolitician-popolo-php
src/Popolo.php
Popolo.fromUrl
public static function fromUrl($url) { $client = new GuzzleHttp\Client(); $response = $client->get($url); $jsonData = json_decode($response->getBody(), true); $instance = new self($jsonData); return $instance; }
php
public static function fromUrl($url) { $client = new GuzzleHttp\Client(); $response = $client->get($url); $jsonData = json_decode($response->getBody(), true); $instance = new self($jsonData); return $instance; }
[ "public", "static", "function", "fromUrl", "(", "$", "url", ")", "{", "$", "client", "=", "new", "GuzzleHttp", "\\", "Client", "(", ")", ";", "$", "response", "=", "$", "client", "->", "get", "(", "$", "url", ")", ";", "$", "jsonData", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", ",", "true", ")", ";", "$", "instance", "=", "new", "self", "(", "$", "jsonData", ")", ";", "return", "$", "instance", ";", "}" ]
Construct from URL @param string $url location of Popolo json file @return $this
[ "Construct", "from", "URL" ]
701fca91b782871d463cfb56f3c1c7afb121eb9f
https://github.com/andylolz/everypolitician-popolo-php/blob/701fca91b782871d463cfb56f3c1c7afb121eb9f/src/Popolo.php#L63-L70
14,203
hfcorriez/php-childprocess
lib/Pagon/Process.php
Process.register
public function register(\Closure $runner, $options = array()) { $this->runner = $runner; $this->options = $options; return $this; }
php
public function register(\Closure $runner, $options = array()) { $this->runner = $runner; $this->options = $options; return $this; }
[ "public", "function", "register", "(", "\\", "Closure", "$", "runner", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "this", "->", "runner", "=", "$", "runner", ";", "$", "this", "->", "options", "=", "$", "options", ";", "return", "$", "this", ";", "}" ]
Register the runner and options for delay run @param \Closure $runner @param array $options @return $this
[ "Register", "the", "runner", "and", "options", "for", "delay", "run" ]
92481a85783cf2a24fef1760930f1252bb83fa5d
https://github.com/hfcorriez/php-childprocess/blob/92481a85783cf2a24fef1760930f1252bb83fa5d/lib/Pagon/Process.php#L154-L159
14,204
hfcorriez/php-childprocess
lib/Pagon/Process.php
Process.send
public function send($msg) { // Check queue and send messages if ($this->queue && is_resource($this->queue) && msg_stat_queue($this->queue)) { return msg_send($this->queue, 1, array( 'from' => $this->isMaster() ? $this->ppid : $this->pid, 'to' => $this->isMaster() ? $this->pid : $this->ppid, 'body' => $msg ), true, false, $error); } return false; }
php
public function send($msg) { // Check queue and send messages if ($this->queue && is_resource($this->queue) && msg_stat_queue($this->queue)) { return msg_send($this->queue, 1, array( 'from' => $this->isMaster() ? $this->ppid : $this->pid, 'to' => $this->isMaster() ? $this->pid : $this->ppid, 'body' => $msg ), true, false, $error); } return false; }
[ "public", "function", "send", "(", "$", "msg", ")", "{", "// Check queue and send messages", "if", "(", "$", "this", "->", "queue", "&&", "is_resource", "(", "$", "this", "->", "queue", ")", "&&", "msg_stat_queue", "(", "$", "this", "->", "queue", ")", ")", "{", "return", "msg_send", "(", "$", "this", "->", "queue", ",", "1", ",", "array", "(", "'from'", "=>", "$", "this", "->", "isMaster", "(", ")", "?", "$", "this", "->", "ppid", ":", "$", "this", "->", "pid", ",", "'to'", "=>", "$", "this", "->", "isMaster", "(", ")", "?", "$", "this", "->", "pid", ":", "$", "this", "->", "ppid", ",", "'body'", "=>", "$", "msg", ")", ",", "true", ",", "false", ",", "$", "error", ")", ";", "}", "return", "false", ";", "}" ]
Send msg to child process @param mixed $msg @return bool
[ "Send", "msg", "to", "child", "process" ]
92481a85783cf2a24fef1760930f1252bb83fa5d
https://github.com/hfcorriez/php-childprocess/blob/92481a85783cf2a24fef1760930f1252bb83fa5d/lib/Pagon/Process.php#L187-L198
14,205
astronati/php-fantasy-football-quotations-parser
src/Map/MapAbstract.php
MapAbstract.getStartingRow
private function getStartingRow($sheet): int { $row = null; for ($i = 1; $i <= 4 && !$row; $i++) { if ($sheet->getCellByColumnAndRow(1, $i) == "Cod.") { $row = $i + 1; } } return $row; }
php
private function getStartingRow($sheet): int { $row = null; for ($i = 1; $i <= 4 && !$row; $i++) { if ($sheet->getCellByColumnAndRow(1, $i) == "Cod.") { $row = $i + 1; } } return $row; }
[ "private", "function", "getStartingRow", "(", "$", "sheet", ")", ":", "int", "{", "$", "row", "=", "null", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "4", "&&", "!", "$", "row", ";", "$", "i", "++", ")", "{", "if", "(", "$", "sheet", "->", "getCellByColumnAndRow", "(", "1", ",", "$", "i", ")", "==", "\"Cod.\"", ")", "{", "$", "row", "=", "$", "i", "+", "1", ";", "}", "}", "return", "$", "row", ";", "}" ]
Returns the spreadsheet row number for which the extractor should start extracting row data. @param Worksheet $sheet @return int
[ "Returns", "the", "spreadsheet", "row", "number", "for", "which", "the", "extractor", "should", "start", "extracting", "row", "data", "." ]
1214f313c325ac7e9fc4d5218b85b3d7234f7bf3
https://github.com/astronati/php-fantasy-football-quotations-parser/blob/1214f313c325ac7e9fc4d5218b85b3d7234f7bf3/src/Map/MapAbstract.php#L53-L63
14,206
ronan-gloo/jade-php
src/Jade/Filter/AbstractFilter.php
AbstractFilter.getNodeString
protected function getNodeString(Filter $node, Compiler $compiler = null) { return array_reduce($node->block->nodes, function(&$result, $line) use($compiler) { $val = $compiler ? $compiler->interpolate($line->value) : $line->value; return $result .= $val."\n"; }); }
php
protected function getNodeString(Filter $node, Compiler $compiler = null) { return array_reduce($node->block->nodes, function(&$result, $line) use($compiler) { $val = $compiler ? $compiler->interpolate($line->value) : $line->value; return $result .= $val."\n"; }); }
[ "protected", "function", "getNodeString", "(", "Filter", "$", "node", ",", "Compiler", "$", "compiler", "=", "null", ")", "{", "return", "array_reduce", "(", "$", "node", "->", "block", "->", "nodes", ",", "function", "(", "&", "$", "result", ",", "$", "line", ")", "use", "(", "$", "compiler", ")", "{", "$", "val", "=", "$", "compiler", "?", "$", "compiler", "->", "interpolate", "(", "$", "line", "->", "value", ")", ":", "$", "line", "->", "value", ";", "return", "$", "result", ".=", "$", "val", ".", "\"\\n\"", ";", "}", ")", ";", "}" ]
Returns the node string value, line by line. If the compiler is present, that means we need to interpolate line contents @param Filter $node @param Compiler $compiler @return mixed
[ "Returns", "the", "node", "string", "value", "line", "by", "line", ".", "If", "the", "compiler", "is", "present", "that", "means", "we", "need", "to", "interpolate", "line", "contents" ]
77230d2eef2f0d4f045292a5906162f0c0499421
https://github.com/ronan-gloo/jade-php/blob/77230d2eef2f0d4f045292a5906162f0c0499421/src/Jade/Filter/AbstractFilter.php#L21-L27
14,207
ssheduardo/didimo
src/Sms.php
Sms.createSend
public function createSend($sender='', $messages=array(), $scheduledate='') { $message_sender = array(); $index = 0; $url = $this->_setEnvironment.'wcf/Service.svc/rest/CreateSend'; if(is_array($messages)) { foreach($messages as $mobile => $message){ $message_sender[$index]['Mobile'] = $mobile; $message_sender[$index]['Text'] = $message; $index++; } } $json = array( 'UserName' => $this->user, 'Password' => $this->password, 'Sender' => $sender, 'Messages' => $message_sender, 'ScheduleDate' => $scheduledate, ); try { $response = $this->client->post($url,[ 'headers' => [ 'Content-Type' => 'application/json','Accept' => 'application/json' ], 'body' => json_encode($json) ] ); $result = json_decode($response->getBody()->getContents(), true); $result['Status'] = $response->getStatusCode(); $result =json_decode(json_encode($result)); } catch (RequestException $e) { $result = $this->StatusCodeHandling($e); } return $result; }
php
public function createSend($sender='', $messages=array(), $scheduledate='') { $message_sender = array(); $index = 0; $url = $this->_setEnvironment.'wcf/Service.svc/rest/CreateSend'; if(is_array($messages)) { foreach($messages as $mobile => $message){ $message_sender[$index]['Mobile'] = $mobile; $message_sender[$index]['Text'] = $message; $index++; } } $json = array( 'UserName' => $this->user, 'Password' => $this->password, 'Sender' => $sender, 'Messages' => $message_sender, 'ScheduleDate' => $scheduledate, ); try { $response = $this->client->post($url,[ 'headers' => [ 'Content-Type' => 'application/json','Accept' => 'application/json' ], 'body' => json_encode($json) ] ); $result = json_decode($response->getBody()->getContents(), true); $result['Status'] = $response->getStatusCode(); $result =json_decode(json_encode($result)); } catch (RequestException $e) { $result = $this->StatusCodeHandling($e); } return $result; }
[ "public", "function", "createSend", "(", "$", "sender", "=", "''", ",", "$", "messages", "=", "array", "(", ")", ",", "$", "scheduledate", "=", "''", ")", "{", "$", "message_sender", "=", "array", "(", ")", ";", "$", "index", "=", "0", ";", "$", "url", "=", "$", "this", "->", "_setEnvironment", ".", "'wcf/Service.svc/rest/CreateSend'", ";", "if", "(", "is_array", "(", "$", "messages", ")", ")", "{", "foreach", "(", "$", "messages", "as", "$", "mobile", "=>", "$", "message", ")", "{", "$", "message_sender", "[", "$", "index", "]", "[", "'Mobile'", "]", "=", "$", "mobile", ";", "$", "message_sender", "[", "$", "index", "]", "[", "'Text'", "]", "=", "$", "message", ";", "$", "index", "++", ";", "}", "}", "$", "json", "=", "array", "(", "'UserName'", "=>", "$", "this", "->", "user", ",", "'Password'", "=>", "$", "this", "->", "password", ",", "'Sender'", "=>", "$", "sender", ",", "'Messages'", "=>", "$", "message_sender", ",", "'ScheduleDate'", "=>", "$", "scheduledate", ",", ")", ";", "try", "{", "$", "response", "=", "$", "this", "->", "client", "->", "post", "(", "$", "url", ",", "[", "'headers'", "=>", "[", "'Content-Type'", "=>", "'application/json'", ",", "'Accept'", "=>", "'application/json'", "]", ",", "'body'", "=>", "json_encode", "(", "$", "json", ")", "]", ")", ";", "$", "result", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ",", "true", ")", ";", "$", "result", "[", "'Status'", "]", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "$", "result", "=", "json_decode", "(", "json_encode", "(", "$", "result", ")", ")", ";", "}", "catch", "(", "RequestException", "$", "e", ")", "{", "$", "result", "=", "$", "this", "->", "StatusCodeHandling", "(", "$", "e", ")", ";", "}", "return", "$", "result", ";", "}" ]
This operation allows you to send 1 or more messages in a single call. @param string $sender Message sender. If informed, it must be a maximum of 11 characters. If not reported, the API will use the user-defined sender. @param array $messages With the messages to send. @param string $scheduledate Optional. Date and time when you want the message to be delivered at destination. @return object
[ "This", "operation", "allows", "you", "to", "send", "1", "or", "more", "messages", "in", "a", "single", "call", "." ]
6c5bd8b03000f40b13661c3fd6ffa1e44f4da945
https://github.com/ssheduardo/didimo/blob/6c5bd8b03000f40b13661c3fd6ffa1e44f4da945/src/Sms.php#L70-L108
14,208
ssheduardo/didimo
src/Sms.php
Sms.createMessage
public function createMessage($sender='',$mobile='', $message='', $scheduledate='') { $url = $this->_setEnvironment.'wcf/Service.svc/rest/CreateMessage'; $json = array( 'UserName' => $this->user, 'Password' => $this->password, 'Sender' => $sender, 'Mobile' => $mobile, 'Text' => $message, 'ScheduleDate' => $scheduledate, ); try { $response = $this->client->post($url,[ 'headers' => [ 'Content-Type' => 'application/json','Accept' => 'application/json' ], 'body' => json_encode($json) ] ); $result = json_decode($response->getBody()->getContents(), true); $result['Status'] = $response->getStatusCode(); $result =json_decode(json_encode($result)); } catch (RequestException $e) { $result = $this->StatusCodeHandling($e); } return $result; }
php
public function createMessage($sender='',$mobile='', $message='', $scheduledate='') { $url = $this->_setEnvironment.'wcf/Service.svc/rest/CreateMessage'; $json = array( 'UserName' => $this->user, 'Password' => $this->password, 'Sender' => $sender, 'Mobile' => $mobile, 'Text' => $message, 'ScheduleDate' => $scheduledate, ); try { $response = $this->client->post($url,[ 'headers' => [ 'Content-Type' => 'application/json','Accept' => 'application/json' ], 'body' => json_encode($json) ] ); $result = json_decode($response->getBody()->getContents(), true); $result['Status'] = $response->getStatusCode(); $result =json_decode(json_encode($result)); } catch (RequestException $e) { $result = $this->StatusCodeHandling($e); } return $result; }
[ "public", "function", "createMessage", "(", "$", "sender", "=", "''", ",", "$", "mobile", "=", "''", ",", "$", "message", "=", "''", ",", "$", "scheduledate", "=", "''", ")", "{", "$", "url", "=", "$", "this", "->", "_setEnvironment", ".", "'wcf/Service.svc/rest/CreateMessage'", ";", "$", "json", "=", "array", "(", "'UserName'", "=>", "$", "this", "->", "user", ",", "'Password'", "=>", "$", "this", "->", "password", ",", "'Sender'", "=>", "$", "sender", ",", "'Mobile'", "=>", "$", "mobile", ",", "'Text'", "=>", "$", "message", ",", "'ScheduleDate'", "=>", "$", "scheduledate", ",", ")", ";", "try", "{", "$", "response", "=", "$", "this", "->", "client", "->", "post", "(", "$", "url", ",", "[", "'headers'", "=>", "[", "'Content-Type'", "=>", "'application/json'", ",", "'Accept'", "=>", "'application/json'", "]", ",", "'body'", "=>", "json_encode", "(", "$", "json", ")", "]", ")", ";", "$", "result", "=", "json_decode", "(", "$", "response", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ",", "true", ")", ";", "$", "result", "[", "'Status'", "]", "=", "$", "response", "->", "getStatusCode", "(", ")", ";", "$", "result", "=", "json_decode", "(", "json_encode", "(", "$", "result", ")", ")", ";", "}", "catch", "(", "RequestException", "$", "e", ")", "{", "$", "result", "=", "$", "this", "->", "StatusCodeHandling", "(", "$", "e", ")", ";", "}", "return", "$", "result", ";", "}" ]
This operation allows you to send 1 message on a single call. @param string $sender Message sender. If informed, it must be a maximum of 11 characters. If not reported, the API will use the user-defined sender. @param string $mobile Recipient of the message. Information is available in international (+34699999999,003469999999999,34699999999) or national (699999999) formats. It is recommended to use the international format 0034699999999. @param string $message Message text. If the text length is greater than the character limit per SMS (160 for GSM-7 coded text messages, and 70 for Unicode coded messages) @param string $scheduledate Optional. Date and time when you want the message to be delivered at destination. @return object
[ "This", "operation", "allows", "you", "to", "send", "1", "message", "on", "a", "single", "call", "." ]
6c5bd8b03000f40b13661c3fd6ffa1e44f4da945
https://github.com/ssheduardo/didimo/blob/6c5bd8b03000f40b13661c3fd6ffa1e44f4da945/src/Sms.php#L119-L148
14,209
ssheduardo/didimo
src/Sms.php
Sms.statusCodeHandling
protected function statusCodeHandling($e) { $response =(object)array( "Status" => $e->getResponse()->getStatusCode(), "Error" => json_decode($e->getResponse()->getBody(true)->getContents()) ); return $response; }
php
protected function statusCodeHandling($e) { $response =(object)array( "Status" => $e->getResponse()->getStatusCode(), "Error" => json_decode($e->getResponse()->getBody(true)->getContents()) ); return $response; }
[ "protected", "function", "statusCodeHandling", "(", "$", "e", ")", "{", "$", "response", "=", "(", "object", ")", "array", "(", "\"Status\"", "=>", "$", "e", "->", "getResponse", "(", ")", "->", "getStatusCode", "(", ")", ",", "\"Error\"", "=>", "json_decode", "(", "$", "e", "->", "getResponse", "(", ")", "->", "getBody", "(", "true", ")", "->", "getContents", "(", ")", ")", ")", ";", "return", "$", "response", ";", "}" ]
Return message error @param $e @return array
[ "Return", "message", "error" ]
6c5bd8b03000f40b13661c3fd6ffa1e44f4da945
https://github.com/ssheduardo/didimo/blob/6c5bd8b03000f40b13661c3fd6ffa1e44f4da945/src/Sms.php#L257-L264
14,210
cpliakas/search-framework
src/Search/Framework/Collector.php
Collector.queue
public function queue() { $log = $this->getLogger(); $log->info('Queueing operation started', array('collections' => count($this))); $event = new CollectorEvent($this); $this->dispatchEvent(SearchEvents::COLLECTOR_PRE_QUEUE, $event); $num_queued = 0; foreach ($this->_collections as $collection) { $num_queued += $this->queueCollection($collection); } $this->dispatchEvent(SearchEvents::COLLECTOR_POST_QUEUE, $event); $log->info('Queueing operation completed', array('queued' => $num_queued)); return $num_queued; }
php
public function queue() { $log = $this->getLogger(); $log->info('Queueing operation started', array('collections' => count($this))); $event = new CollectorEvent($this); $this->dispatchEvent(SearchEvents::COLLECTOR_PRE_QUEUE, $event); $num_queued = 0; foreach ($this->_collections as $collection) { $num_queued += $this->queueCollection($collection); } $this->dispatchEvent(SearchEvents::COLLECTOR_POST_QUEUE, $event); $log->info('Queueing operation completed', array('queued' => $num_queued)); return $num_queued; }
[ "public", "function", "queue", "(", ")", "{", "$", "log", "=", "$", "this", "->", "getLogger", "(", ")", ";", "$", "log", "->", "info", "(", "'Queueing operation started'", ",", "array", "(", "'collections'", "=>", "count", "(", "$", "this", ")", ")", ")", ";", "$", "event", "=", "new", "CollectorEvent", "(", "$", "this", ")", ";", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "COLLECTOR_PRE_QUEUE", ",", "$", "event", ")", ";", "$", "num_queued", "=", "0", ";", "foreach", "(", "$", "this", "->", "_collections", "as", "$", "collection", ")", "{", "$", "num_queued", "+=", "$", "this", "->", "queueCollection", "(", "$", "collection", ")", ";", "}", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "COLLECTOR_POST_QUEUE", ",", "$", "event", ")", ";", "$", "log", "->", "info", "(", "'Queueing operation completed'", ",", "array", "(", "'queued'", "=>", "$", "num_queued", ")", ")", ";", "return", "$", "num_queued", ";", "}" ]
Queues the items scheduled for indexing for all collections attached to the collector. @return int The number of items sent to the queue.
[ "Queues", "the", "items", "scheduled", "for", "indexing", "for", "all", "collections", "attached", "to", "the", "collector", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Collector.php#L50-L67
14,211
cpliakas/search-framework
src/Search/Framework/Collector.php
Collector.queueCollection
public function queueCollection(CollectionAbstract $collection) { $log = $this->getLogger(); $context = array('collection' => $collection->getId()); $log->info('Begin fetching items that are scheduled for indexing', $context); $event = new CollectionEvent($this, $collection); $this->dispatchEvent(SearchEvents::COLLECTION_PRE_QUEUE, $event, $context); // The producer fetches the items scheduled for indexing from the // collection and publishes them to the indexing queue. $producer = new QueueProducer($this, $collection); foreach ($producer as $message) { // @todo Have this return a boolean suceess flag and modify the log // message accordingly? $message->publish(); $context['item'] = $message->getBody(); $log->debug('Published item scheduled for indexing to queue', $context); } unset($context['item']); // The item is no longer in context. $this->dispatchEvent(SearchEvents::COLLECTION_POST_QUEUE, $event, $context); // Get and log the number of items queued for this collection. $num_queued = count($producer); $context['queued'] = $num_queued; $log->info('Finished fetching and queueing items that are scheduled for indexing', $context); return $num_queued; }
php
public function queueCollection(CollectionAbstract $collection) { $log = $this->getLogger(); $context = array('collection' => $collection->getId()); $log->info('Begin fetching items that are scheduled for indexing', $context); $event = new CollectionEvent($this, $collection); $this->dispatchEvent(SearchEvents::COLLECTION_PRE_QUEUE, $event, $context); // The producer fetches the items scheduled for indexing from the // collection and publishes them to the indexing queue. $producer = new QueueProducer($this, $collection); foreach ($producer as $message) { // @todo Have this return a boolean suceess flag and modify the log // message accordingly? $message->publish(); $context['item'] = $message->getBody(); $log->debug('Published item scheduled for indexing to queue', $context); } unset($context['item']); // The item is no longer in context. $this->dispatchEvent(SearchEvents::COLLECTION_POST_QUEUE, $event, $context); // Get and log the number of items queued for this collection. $num_queued = count($producer); $context['queued'] = $num_queued; $log->info('Finished fetching and queueing items that are scheduled for indexing', $context); return $num_queued; }
[ "public", "function", "queueCollection", "(", "CollectionAbstract", "$", "collection", ")", "{", "$", "log", "=", "$", "this", "->", "getLogger", "(", ")", ";", "$", "context", "=", "array", "(", "'collection'", "=>", "$", "collection", "->", "getId", "(", ")", ")", ";", "$", "log", "->", "info", "(", "'Begin fetching items that are scheduled for indexing'", ",", "$", "context", ")", ";", "$", "event", "=", "new", "CollectionEvent", "(", "$", "this", ",", "$", "collection", ")", ";", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "COLLECTION_PRE_QUEUE", ",", "$", "event", ",", "$", "context", ")", ";", "// The producer fetches the items scheduled for indexing from the", "// collection and publishes them to the indexing queue.", "$", "producer", "=", "new", "QueueProducer", "(", "$", "this", ",", "$", "collection", ")", ";", "foreach", "(", "$", "producer", "as", "$", "message", ")", "{", "// @todo Have this return a boolean suceess flag and modify the log", "// message accordingly?", "$", "message", "->", "publish", "(", ")", ";", "$", "context", "[", "'item'", "]", "=", "$", "message", "->", "getBody", "(", ")", ";", "$", "log", "->", "debug", "(", "'Published item scheduled for indexing to queue'", ",", "$", "context", ")", ";", "}", "unset", "(", "$", "context", "[", "'item'", "]", ")", ";", "// The item is no longer in context.", "$", "this", "->", "dispatchEvent", "(", "SearchEvents", "::", "COLLECTION_POST_QUEUE", ",", "$", "event", ",", "$", "context", ")", ";", "// Get and log the number of items queued for this collection.", "$", "num_queued", "=", "count", "(", "$", "producer", ")", ";", "$", "context", "[", "'queued'", "]", "=", "$", "num_queued", ";", "$", "log", "->", "info", "(", "'Finished fetching and queueing items that are scheduled for indexing'", ",", "$", "context", ")", ";", "return", "$", "num_queued", ";", "}" ]
Queues the items scheduled for indexing for the collection. @param CollectionAbstract $collection The collection that fetches the items scheduled for indexing. @return int The number of items sent to the queue.
[ "Queues", "the", "items", "scheduled", "for", "indexing", "for", "the", "collection", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Collector.php#L78-L108
14,212
antarestupin/Accessible
lib/Accessible/Reader/AutoConstructReader.php
AutoConstructReader.getConstructArguments
public static function getConstructArguments($objectClasses, $annotationReader) { $constructArguments = null; array_reverse($objectClasses); foreach ($objectClasses as $class) { $annotation = $annotationReader->getClassAnnotation($class, self::$constructAnnotationClass); if ($annotation !== null) { $constructArguments = $annotation->getArguments(); break; } } return $constructArguments; }
php
public static function getConstructArguments($objectClasses, $annotationReader) { $constructArguments = null; array_reverse($objectClasses); foreach ($objectClasses as $class) { $annotation = $annotationReader->getClassAnnotation($class, self::$constructAnnotationClass); if ($annotation !== null) { $constructArguments = $annotation->getArguments(); break; } } return $constructArguments; }
[ "public", "static", "function", "getConstructArguments", "(", "$", "objectClasses", ",", "$", "annotationReader", ")", "{", "$", "constructArguments", "=", "null", ";", "array_reverse", "(", "$", "objectClasses", ")", ";", "foreach", "(", "$", "objectClasses", "as", "$", "class", ")", "{", "$", "annotation", "=", "$", "annotationReader", "->", "getClassAnnotation", "(", "$", "class", ",", "self", "::", "$", "constructAnnotationClass", ")", ";", "if", "(", "$", "annotation", "!==", "null", ")", "{", "$", "constructArguments", "=", "$", "annotation", "->", "getArguments", "(", ")", ";", "break", ";", "}", "}", "return", "$", "constructArguments", ";", "}" ]
Get the list of needed arguments for given object's constructor. @param array $objectClasses The classes of the object to read. @param \Doctrine\Common\Annotations\Reader $annotationReader The annotation reader to use. @return array The list of arguments.
[ "Get", "the", "list", "of", "needed", "arguments", "for", "given", "object", "s", "constructor", "." ]
d12ce93d72f74c099dfd2109371fcd6ddfffdca4
https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/Reader/AutoConstructReader.php#L36-L50
14,213
antarestupin/Accessible
lib/Accessible/Reader/AutoConstructReader.php
AutoConstructReader.getPropertiesToInitialize
public static function getPropertiesToInitialize($properties, $annotationReader) { $propertiesValues = array(); foreach ($properties as $propertyName => $property) { $initializeAnnotation = $annotationReader->getPropertyAnnotation($property, self::$initializeAnnotationClass); $initializeObjectAnnotation = $annotationReader->getPropertyAnnotation($property, self::$initializeObjectAnnotationClass); if ($initializeAnnotation !== null && $initializeObjectAnnotation !== null) { throw new \LogicException("Two initial values are given for property $propertyName."); } if ($initializeAnnotation !== null) { $propertiesValues[$propertyName] = array( 'type' => 'initialize', 'value' => $initializeAnnotation->getValue() ); } else if ($initializeObjectAnnotation !== null) { $propertiesValues[$propertyName] = array( 'type' => 'initializeObject', 'value' => $initializeObjectAnnotation->getClassName() ); } } return $propertiesValues; }
php
public static function getPropertiesToInitialize($properties, $annotationReader) { $propertiesValues = array(); foreach ($properties as $propertyName => $property) { $initializeAnnotation = $annotationReader->getPropertyAnnotation($property, self::$initializeAnnotationClass); $initializeObjectAnnotation = $annotationReader->getPropertyAnnotation($property, self::$initializeObjectAnnotationClass); if ($initializeAnnotation !== null && $initializeObjectAnnotation !== null) { throw new \LogicException("Two initial values are given for property $propertyName."); } if ($initializeAnnotation !== null) { $propertiesValues[$propertyName] = array( 'type' => 'initialize', 'value' => $initializeAnnotation->getValue() ); } else if ($initializeObjectAnnotation !== null) { $propertiesValues[$propertyName] = array( 'type' => 'initializeObject', 'value' => $initializeObjectAnnotation->getClassName() ); } } return $propertiesValues; }
[ "public", "static", "function", "getPropertiesToInitialize", "(", "$", "properties", ",", "$", "annotationReader", ")", "{", "$", "propertiesValues", "=", "array", "(", ")", ";", "foreach", "(", "$", "properties", "as", "$", "propertyName", "=>", "$", "property", ")", "{", "$", "initializeAnnotation", "=", "$", "annotationReader", "->", "getPropertyAnnotation", "(", "$", "property", ",", "self", "::", "$", "initializeAnnotationClass", ")", ";", "$", "initializeObjectAnnotation", "=", "$", "annotationReader", "->", "getPropertyAnnotation", "(", "$", "property", ",", "self", "::", "$", "initializeObjectAnnotationClass", ")", ";", "if", "(", "$", "initializeAnnotation", "!==", "null", "&&", "$", "initializeObjectAnnotation", "!==", "null", ")", "{", "throw", "new", "\\", "LogicException", "(", "\"Two initial values are given for property $propertyName.\"", ")", ";", "}", "if", "(", "$", "initializeAnnotation", "!==", "null", ")", "{", "$", "propertiesValues", "[", "$", "propertyName", "]", "=", "array", "(", "'type'", "=>", "'initialize'", ",", "'value'", "=>", "$", "initializeAnnotation", "->", "getValue", "(", ")", ")", ";", "}", "else", "if", "(", "$", "initializeObjectAnnotation", "!==", "null", ")", "{", "$", "propertiesValues", "[", "$", "propertyName", "]", "=", "array", "(", "'type'", "=>", "'initializeObject'", ",", "'value'", "=>", "$", "initializeObjectAnnotation", "->", "getClassName", "(", ")", ")", ";", "}", "}", "return", "$", "propertiesValues", ";", "}" ]
Get the list of properties that have to be initialized automatically during the object construction, plus their value. @param array $properties The properties of the object to read. @param \Doctrine\Common\Annotations\Reader $annotationReader The annotation reader to use. @return array The list of properties and values, in the form ["property" => "value"].
[ "Get", "the", "list", "of", "properties", "that", "have", "to", "be", "initialized", "automatically", "during", "the", "object", "construction", "plus", "their", "value", "." ]
d12ce93d72f74c099dfd2109371fcd6ddfffdca4
https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/Reader/AutoConstructReader.php#L62-L88
14,214
vi-kon/laravel-parser
src/ViKon/Parser/lexer/Lexer.php
Lexer.addSinglePattern
public function addSinglePattern($pattern, $ruleName, $childRuleName) { return $this->addPattern($pattern, $ruleName, self::SINGLE_RULE_PREFIX . $childRuleName); }
php
public function addSinglePattern($pattern, $ruleName, $childRuleName) { return $this->addPattern($pattern, $ruleName, self::SINGLE_RULE_PREFIX . $childRuleName); }
[ "public", "function", "addSinglePattern", "(", "$", "pattern", ",", "$", "ruleName", ",", "$", "childRuleName", ")", "{", "return", "$", "this", "->", "addPattern", "(", "$", "pattern", ",", "$", "ruleName", ",", "self", "::", "SINGLE_RULE_PREFIX", ".", "$", "childRuleName", ")", ";", "}" ]
Add single pattern. If pattern match change to provided rule and immediately back @param string $pattern regexp pattern @param string $ruleName rule name @param string $childRuleName child rule name (next rule) @return \ViKon\Parser\Lexer\Lexer
[ "Add", "single", "pattern", ".", "If", "pattern", "match", "change", "to", "provided", "rule", "and", "immediately", "back" ]
070f0bb9120cb9ca6ff836d4f418e78ee33ee182
https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/lexer/Lexer.php#L83-L85
14,215
vi-kon/laravel-parser
src/ViKon/Parser/lexer/Lexer.php
Lexer.addPattern
protected function addPattern($pattern, $ruleName, $childRuleName = null) { if (!isset($this->patterns[$ruleName])) { $this->patterns[$ruleName] = new LexerPattern($ruleName); } $this->patterns[$ruleName]->addPattern($pattern, $childRuleName); return $this; }
php
protected function addPattern($pattern, $ruleName, $childRuleName = null) { if (!isset($this->patterns[$ruleName])) { $this->patterns[$ruleName] = new LexerPattern($ruleName); } $this->patterns[$ruleName]->addPattern($pattern, $childRuleName); return $this; }
[ "protected", "function", "addPattern", "(", "$", "pattern", ",", "$", "ruleName", ",", "$", "childRuleName", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "patterns", "[", "$", "ruleName", "]", ")", ")", "{", "$", "this", "->", "patterns", "[", "$", "ruleName", "]", "=", "new", "LexerPattern", "(", "$", "ruleName", ")", ";", "}", "$", "this", "->", "patterns", "[", "$", "ruleName", "]", "->", "addPattern", "(", "$", "pattern", ",", "$", "childRuleName", ")", ";", "return", "$", "this", ";", "}" ]
Add pattern to rule patterns @param string $pattern regex pattern @param string $ruleName rule name @param string|null $childRuleName child rule name @return $this
[ "Add", "pattern", "to", "rule", "patterns" ]
070f0bb9120cb9ca6ff836d4f418e78ee33ee182
https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/lexer/Lexer.php#L161-L168
14,216
vi-kon/laravel-parser
src/ViKon/Parser/lexer/Lexer.php
Lexer.reduce
protected function reduce(&$text) { if (!array_key_exists($this->stack->top(), $this->patterns)) { return false; } if ($text !== '' && ($data = $this->patterns[$this->stack->top()]->split($text)) !== false) { list($unmatched, $matched, $text, $childRuleName) = $data; return [$unmatched, $matched, $childRuleName]; } return true; }
php
protected function reduce(&$text) { if (!array_key_exists($this->stack->top(), $this->patterns)) { return false; } if ($text !== '' && ($data = $this->patterns[$this->stack->top()]->split($text)) !== false) { list($unmatched, $matched, $text, $childRuleName) = $data; return [$unmatched, $matched, $childRuleName]; } return true; }
[ "protected", "function", "reduce", "(", "&", "$", "text", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "this", "->", "stack", "->", "top", "(", ")", ",", "$", "this", "->", "patterns", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "text", "!==", "''", "&&", "(", "$", "data", "=", "$", "this", "->", "patterns", "[", "$", "this", "->", "stack", "->", "top", "(", ")", "]", "->", "split", "(", "$", "text", ")", ")", "!==", "false", ")", "{", "list", "(", "$", "unmatched", ",", "$", "matched", ",", "$", "text", ",", "$", "childRuleName", ")", "=", "$", "data", ";", "return", "[", "$", "unmatched", ",", "$", "matched", ",", "$", "childRuleName", "]", ";", "}", "return", "true", ";", "}" ]
Reduce input text length by patterns match @param string $text @return array|bool FALSE if no valid pattern found, TRUE if input text is empty or split is not succeed, otherwise array with unmatched, matched part of text and used patterns rule name
[ "Reduce", "input", "text", "length", "by", "patterns", "match" ]
070f0bb9120cb9ca6ff836d4f418e78ee33ee182
https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/lexer/Lexer.php#L178-L189
14,217
antarestupin/Accessible
lib/Accessible/Reader/AccessReader.php
AccessReader.getAccessProperties
public static function getAccessProperties($properties, $annotationReader) { $objectAccessProperties = array(); foreach ($properties as $propertyName => $property) { if (empty($objectAccessProperties[$propertyName])) { $objectAccessProperties[$propertyName] = array(); } // Getters / Setters related annotations $propertyAccessAnnotation = $annotationReader->getPropertyAnnotation($property, self::$accessAnnotationClass); $accessProperties = array(); if ($propertyAccessAnnotation !== null) { $accessProperties = $propertyAccessAnnotation->getAccessProperties(); } // Collection related annotations $collectionAnnotation = null; foreach (self::$collectionAnnotationClasses as $annotationBehavior => $annotationClass) { $collectionAnnotation = $annotationReader->getPropertyAnnotation($property, $annotationClass); if ($collectionAnnotation !== null) { break; } } $collectionMethods = array(); if ($collectionAnnotation !== null) { $collectionMethods = $collectionAnnotation->getMethods(); } // Merge and save the two arrays $objectAccessProperties[$propertyName] = array_merge($accessProperties, $collectionMethods); } return $objectAccessProperties; }
php
public static function getAccessProperties($properties, $annotationReader) { $objectAccessProperties = array(); foreach ($properties as $propertyName => $property) { if (empty($objectAccessProperties[$propertyName])) { $objectAccessProperties[$propertyName] = array(); } // Getters / Setters related annotations $propertyAccessAnnotation = $annotationReader->getPropertyAnnotation($property, self::$accessAnnotationClass); $accessProperties = array(); if ($propertyAccessAnnotation !== null) { $accessProperties = $propertyAccessAnnotation->getAccessProperties(); } // Collection related annotations $collectionAnnotation = null; foreach (self::$collectionAnnotationClasses as $annotationBehavior => $annotationClass) { $collectionAnnotation = $annotationReader->getPropertyAnnotation($property, $annotationClass); if ($collectionAnnotation !== null) { break; } } $collectionMethods = array(); if ($collectionAnnotation !== null) { $collectionMethods = $collectionAnnotation->getMethods(); } // Merge and save the two arrays $objectAccessProperties[$propertyName] = array_merge($accessProperties, $collectionMethods); } return $objectAccessProperties; }
[ "public", "static", "function", "getAccessProperties", "(", "$", "properties", ",", "$", "annotationReader", ")", "{", "$", "objectAccessProperties", "=", "array", "(", ")", ";", "foreach", "(", "$", "properties", "as", "$", "propertyName", "=>", "$", "property", ")", "{", "if", "(", "empty", "(", "$", "objectAccessProperties", "[", "$", "propertyName", "]", ")", ")", "{", "$", "objectAccessProperties", "[", "$", "propertyName", "]", "=", "array", "(", ")", ";", "}", "// Getters / Setters related annotations", "$", "propertyAccessAnnotation", "=", "$", "annotationReader", "->", "getPropertyAnnotation", "(", "$", "property", ",", "self", "::", "$", "accessAnnotationClass", ")", ";", "$", "accessProperties", "=", "array", "(", ")", ";", "if", "(", "$", "propertyAccessAnnotation", "!==", "null", ")", "{", "$", "accessProperties", "=", "$", "propertyAccessAnnotation", "->", "getAccessProperties", "(", ")", ";", "}", "// Collection related annotations", "$", "collectionAnnotation", "=", "null", ";", "foreach", "(", "self", "::", "$", "collectionAnnotationClasses", "as", "$", "annotationBehavior", "=>", "$", "annotationClass", ")", "{", "$", "collectionAnnotation", "=", "$", "annotationReader", "->", "getPropertyAnnotation", "(", "$", "property", ",", "$", "annotationClass", ")", ";", "if", "(", "$", "collectionAnnotation", "!==", "null", ")", "{", "break", ";", "}", "}", "$", "collectionMethods", "=", "array", "(", ")", ";", "if", "(", "$", "collectionAnnotation", "!==", "null", ")", "{", "$", "collectionMethods", "=", "$", "collectionAnnotation", "->", "getMethods", "(", ")", ";", "}", "// Merge and save the two arrays", "$", "objectAccessProperties", "[", "$", "propertyName", "]", "=", "array_merge", "(", "$", "accessProperties", ",", "$", "collectionMethods", ")", ";", "}", "return", "$", "objectAccessProperties", ";", "}" ]
Get a list of properties and the access that are given to them for given object. @param array $properties The properties of the object to read. @param Reader $annotationReader The annotation reader to use. @return array The list of properties and their access.
[ "Get", "a", "list", "of", "properties", "and", "the", "access", "that", "are", "given", "to", "them", "for", "given", "object", "." ]
d12ce93d72f74c099dfd2109371fcd6ddfffdca4
https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/Reader/AccessReader.php#L22-L58
14,218
Laralum/Dashboard
src/Widgets.php
Widgets.get
public static function get() { $widgets = []; foreach (Packages::all() as $package) { $dir = __DIR__.'/../../'.$package.'/src'; $files = is_dir($dir) ? scandir($dir) : []; foreach ($files as $file) { if ($file == 'Widgets.json') { $file_r = file_get_contents($dir.'/'.$file); foreach (json_decode($file_r, true) as $w) { $w['package'] = $package; array_push($widgets, $w); } break; } } } $widgets = static::orderByPreference($widgets); return $widgets; }
php
public static function get() { $widgets = []; foreach (Packages::all() as $package) { $dir = __DIR__.'/../../'.$package.'/src'; $files = is_dir($dir) ? scandir($dir) : []; foreach ($files as $file) { if ($file == 'Widgets.json') { $file_r = file_get_contents($dir.'/'.$file); foreach (json_decode($file_r, true) as $w) { $w['package'] = $package; array_push($widgets, $w); } break; } } } $widgets = static::orderByPreference($widgets); return $widgets; }
[ "public", "static", "function", "get", "(", ")", "{", "$", "widgets", "=", "[", "]", ";", "foreach", "(", "Packages", "::", "all", "(", ")", "as", "$", "package", ")", "{", "$", "dir", "=", "__DIR__", ".", "'/../../'", ".", "$", "package", ".", "'/src'", ";", "$", "files", "=", "is_dir", "(", "$", "dir", ")", "?", "scandir", "(", "$", "dir", ")", ":", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "==", "'Widgets.json'", ")", "{", "$", "file_r", "=", "file_get_contents", "(", "$", "dir", ".", "'/'", ".", "$", "file", ")", ";", "foreach", "(", "json_decode", "(", "$", "file_r", ",", "true", ")", "as", "$", "w", ")", "{", "$", "w", "[", "'package'", "]", "=", "$", "package", ";", "array_push", "(", "$", "widgets", ",", "$", "w", ")", ";", "}", "break", ";", "}", "}", "}", "$", "widgets", "=", "static", "::", "orderByPreference", "(", "$", "widgets", ")", ";", "return", "$", "widgets", ";", "}" ]
Returns all the widgets.
[ "Returns", "all", "the", "widgets", "." ]
2acbef188bdd2d19ed1ac48e28fd74ec2df6ee4b
https://github.com/Laralum/Dashboard/blob/2acbef188bdd2d19ed1ac48e28fd74ec2df6ee4b/src/Widgets.php#L27-L49
14,219
Laralum/Dashboard
src/Widgets.php
Widgets.orderByPreference
public static function orderByPreference($widgets) { $preference = collect(['laralum', 'dashboard', 'users', 'roles', 'permissions']); $ordered_widgets = []; $final_ordered_widgets = []; $widgets = collect($widgets)->groupBy('package')->toArray(); foreach (Packages::all() as $package) { if (!in_array($package, $preference->toArray())) { $preference->push($package); } } $ordered_widgets = $preference->map(function ($p) use ($widgets) { return array_key_exists($p, $widgets) ? $widgets[$p] : null; })->filter(); foreach ($ordered_widgets as $widget) { foreach ($widget as $w) { array_push($final_ordered_widgets, $w); } } return $final_ordered_widgets; }
php
public static function orderByPreference($widgets) { $preference = collect(['laralum', 'dashboard', 'users', 'roles', 'permissions']); $ordered_widgets = []; $final_ordered_widgets = []; $widgets = collect($widgets)->groupBy('package')->toArray(); foreach (Packages::all() as $package) { if (!in_array($package, $preference->toArray())) { $preference->push($package); } } $ordered_widgets = $preference->map(function ($p) use ($widgets) { return array_key_exists($p, $widgets) ? $widgets[$p] : null; })->filter(); foreach ($ordered_widgets as $widget) { foreach ($widget as $w) { array_push($final_ordered_widgets, $w); } } return $final_ordered_widgets; }
[ "public", "static", "function", "orderByPreference", "(", "$", "widgets", ")", "{", "$", "preference", "=", "collect", "(", "[", "'laralum'", ",", "'dashboard'", ",", "'users'", ",", "'roles'", ",", "'permissions'", "]", ")", ";", "$", "ordered_widgets", "=", "[", "]", ";", "$", "final_ordered_widgets", "=", "[", "]", ";", "$", "widgets", "=", "collect", "(", "$", "widgets", ")", "->", "groupBy", "(", "'package'", ")", "->", "toArray", "(", ")", ";", "foreach", "(", "Packages", "::", "all", "(", ")", "as", "$", "package", ")", "{", "if", "(", "!", "in_array", "(", "$", "package", ",", "$", "preference", "->", "toArray", "(", ")", ")", ")", "{", "$", "preference", "->", "push", "(", "$", "package", ")", ";", "}", "}", "$", "ordered_widgets", "=", "$", "preference", "->", "map", "(", "function", "(", "$", "p", ")", "use", "(", "$", "widgets", ")", "{", "return", "array_key_exists", "(", "$", "p", ",", "$", "widgets", ")", "?", "$", "widgets", "[", "$", "p", "]", ":", "null", ";", "}", ")", "->", "filter", "(", ")", ";", "foreach", "(", "$", "ordered_widgets", "as", "$", "widget", ")", "{", "foreach", "(", "$", "widget", "as", "$", "w", ")", "{", "array_push", "(", "$", "final_ordered_widgets", ",", "$", "w", ")", ";", "}", "}", "return", "$", "final_ordered_widgets", ";", "}" ]
Order the widgets by preference.
[ "Order", "the", "widgets", "by", "preference", "." ]
2acbef188bdd2d19ed1ac48e28fd74ec2df6ee4b
https://github.com/Laralum/Dashboard/blob/2acbef188bdd2d19ed1ac48e28fd74ec2df6ee4b/src/Widgets.php#L54-L80
14,220
ptlis/conneg
src/Preference/Builder/MimePreferenceBuilder.php
MimePreferenceBuilder.getQualityFactor
private function getQualityFactor() { $qFactor = 0.0; if (2 === count(explode('/', $this->variant))) { $qFactor = $this->qFactor; } return $qFactor; }
php
private function getQualityFactor() { $qFactor = 0.0; if (2 === count(explode('/', $this->variant))) { $qFactor = $this->qFactor; } return $qFactor; }
[ "private", "function", "getQualityFactor", "(", ")", "{", "$", "qFactor", "=", "0.0", ";", "if", "(", "2", "===", "count", "(", "explode", "(", "'/'", ",", "$", "this", "->", "variant", ")", ")", ")", "{", "$", "qFactor", "=", "$", "this", "->", "qFactor", ";", "}", "return", "$", "qFactor", ";", "}" ]
Get the variants's quality factor, defaulting to 0 on absent variant. @return float
[ "Get", "the", "variants", "s", "quality", "factor", "defaulting", "to", "0", "on", "absent", "variant", "." ]
04afb568f368ecdd81c13277006c4be041ccb58b
https://github.com/ptlis/conneg/blob/04afb568f368ecdd81c13277006c4be041ccb58b/src/Preference/Builder/MimePreferenceBuilder.php#L86-L95
14,221
christophe-brachet/aspi-framework
src/Framework/Form/Element/AbstractElement.php
AbstractElement.setLabelAttributes
public function setLabelAttributes(array $attribs) { foreach ($attribs as $a => $v) { $this->setLabelAttribute($a, $v); } return $this; }
php
public function setLabelAttributes(array $attribs) { foreach ($attribs as $a => $v) { $this->setLabelAttribute($a, $v); } return $this; }
[ "public", "function", "setLabelAttributes", "(", "array", "$", "attribs", ")", "{", "foreach", "(", "$", "attribs", "as", "$", "a", "=>", "$", "v", ")", "{", "$", "this", "->", "setLabelAttribute", "(", "$", "a", ",", "$", "v", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the attributes of the label of the form element object @param array $attribs @return AbstractElement
[ "Set", "the", "attributes", "of", "the", "label", "of", "the", "form", "element", "object" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/AbstractElement.php#L152-L158
14,222
christophe-brachet/aspi-framework
src/Framework/Form/Element/AbstractElement.php
AbstractElement.setHintAttributes
public function setHintAttributes(array $attribs) { foreach ($attribs as $a => $v) { $this->setHintAttribute($a, $v); } return $this; }
php
public function setHintAttributes(array $attribs) { foreach ($attribs as $a => $v) { $this->setHintAttribute($a, $v); } return $this; }
[ "public", "function", "setHintAttributes", "(", "array", "$", "attribs", ")", "{", "foreach", "(", "$", "attribs", "as", "$", "a", "=>", "$", "v", ")", "{", "$", "this", "->", "setHintAttribute", "(", "$", "a", ",", "$", "v", ")", ";", "}", "return", "$", "this", ";", "}" ]
Set the attributes of the hint of the form element object @param array $attribs @return AbstractElement
[ "Set", "the", "attributes", "of", "the", "hint", "of", "the", "form", "element", "object" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/AbstractElement.php#L177-L183
14,223
christophe-brachet/aspi-framework
src/Framework/Form/Element/AbstractElement.php
AbstractElement.addValidator
public function addValidator($validator) { if (!($validator instanceof \Pop\Validator\AbstractValidator) && !is_callable($validator)) { throw new Exception('Error: The validator must be an instance of Pop\Validator\AbstractValidator or a callable object.'); } $this->validators[] = $validator; return $this; }
php
public function addValidator($validator) { if (!($validator instanceof \Pop\Validator\AbstractValidator) && !is_callable($validator)) { throw new Exception('Error: The validator must be an instance of Pop\Validator\AbstractValidator or a callable object.'); } $this->validators[] = $validator; return $this; }
[ "public", "function", "addValidator", "(", "$", "validator", ")", "{", "if", "(", "!", "(", "$", "validator", "instanceof", "\\", "Pop", "\\", "Validator", "\\", "AbstractValidator", ")", "&&", "!", "is_callable", "(", "$", "validator", ")", ")", "{", "throw", "new", "Exception", "(", "'Error: The validator must be an instance of Pop\\Validator\\AbstractValidator or a callable object.'", ")", ";", "}", "$", "this", "->", "validators", "[", "]", "=", "$", "validator", ";", "return", "$", "this", ";", "}" ]
Add a validator the form element @param mixed $validator @throws Exception @return AbstractElement
[ "Add", "a", "validator", "the", "form", "element" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/AbstractElement.php#L376-L383
14,224
DASPRiD/Pikkuleipa
src/Cookie.php
Cookie.fromJson
public static function fromJson( string $name, bool $endsWithSession, DateTimeImmutable $issuedAt, string $json ) : self { $cookie = new self($name, $endsWithSession, $issuedAt); $cookie->data = json_decode($json, true); if (! is_array($cookie->data)) { throw JsonException::fromJsonDecodeError(json_last_error_msg()); } return $cookie; }
php
public static function fromJson( string $name, bool $endsWithSession, DateTimeImmutable $issuedAt, string $json ) : self { $cookie = new self($name, $endsWithSession, $issuedAt); $cookie->data = json_decode($json, true); if (! is_array($cookie->data)) { throw JsonException::fromJsonDecodeError(json_last_error_msg()); } return $cookie; }
[ "public", "static", "function", "fromJson", "(", "string", "$", "name", ",", "bool", "$", "endsWithSession", ",", "DateTimeImmutable", "$", "issuedAt", ",", "string", "$", "json", ")", ":", "self", "{", "$", "cookie", "=", "new", "self", "(", "$", "name", ",", "$", "endsWithSession", ",", "$", "issuedAt", ")", ";", "$", "cookie", "->", "data", "=", "json_decode", "(", "$", "json", ",", "true", ")", ";", "if", "(", "!", "is_array", "(", "$", "cookie", "->", "data", ")", ")", "{", "throw", "JsonException", "::", "fromJsonDecodeError", "(", "json_last_error_msg", "(", ")", ")", ";", "}", "return", "$", "cookie", ";", "}" ]
Creates a new cookie instance from JSON encoded data. This is primarily used by the `TokenManager` to unserialize a cookie from a JWT token. @throws JsonException When an error occurs during decoding
[ "Creates", "a", "new", "cookie", "instance", "from", "JSON", "encoded", "data", "." ]
e80c6ad7354069d49c18ca3bae0d1ae7f3912bfb
https://github.com/DASPRiD/Pikkuleipa/blob/e80c6ad7354069d49c18ca3bae0d1ae7f3912bfb/src/Cookie.php#L45-L59
14,225
DASPRiD/Pikkuleipa
src/Cookie.php
Cookie.toJson
public function toJson() : string { $json = json_encode($this->data); if (false === $json) { throw JsonException::fromJsonEncodeError(json_last_error_msg()); } return $json; }
php
public function toJson() : string { $json = json_encode($this->data); if (false === $json) { throw JsonException::fromJsonEncodeError(json_last_error_msg()); } return $json; }
[ "public", "function", "toJson", "(", ")", ":", "string", "{", "$", "json", "=", "json_encode", "(", "$", "this", "->", "data", ")", ";", "if", "(", "false", "===", "$", "json", ")", "{", "throw", "JsonException", "::", "fromJsonEncodeError", "(", "json_last_error_msg", "(", ")", ")", ";", "}", "return", "$", "json", ";", "}" ]
Serializes the cookie data as JSON. @throws JsonException When an error occurs during encoding
[ "Serializes", "the", "cookie", "data", "as", "JSON", "." ]
e80c6ad7354069d49c18ca3bae0d1ae7f3912bfb
https://github.com/DASPRiD/Pikkuleipa/blob/e80c6ad7354069d49c18ca3bae0d1ae7f3912bfb/src/Cookie.php#L66-L75
14,226
ssnepenthe/soter
src/class-plugin-provider.php
Plugin_Provider.boot
public function boot( Container $container ) { add_action( 'admin_init', [ $this->proxy( $container, 'options_page' ), 'admin_init' ] ); add_action( 'admin_menu', [ $this->proxy( $container, 'options_page' ), 'admin_menu' ] ); add_action( 'admin_notices', [ $this->proxy( $container, 'options_page' ), 'print_notice_when_no_notifiers_active' ] ); add_action( 'admin_init', [ $this->proxy( $container, 'options_manager' ), 'register_settings' ] ); add_action( 'soter_run_check', [ $this->proxy( $container, 'check_site_job' ), 'run' ] ); add_action( 'soter_site_check_complete', [ $this->proxy( $container, 'notifier_manager' ), 'notify' ] ); $this->boot_upgrader( $container ); }
php
public function boot( Container $container ) { add_action( 'admin_init', [ $this->proxy( $container, 'options_page' ), 'admin_init' ] ); add_action( 'admin_menu', [ $this->proxy( $container, 'options_page' ), 'admin_menu' ] ); add_action( 'admin_notices', [ $this->proxy( $container, 'options_page' ), 'print_notice_when_no_notifiers_active' ] ); add_action( 'admin_init', [ $this->proxy( $container, 'options_manager' ), 'register_settings' ] ); add_action( 'soter_run_check', [ $this->proxy( $container, 'check_site_job' ), 'run' ] ); add_action( 'soter_site_check_complete', [ $this->proxy( $container, 'notifier_manager' ), 'notify' ] ); $this->boot_upgrader( $container ); }
[ "public", "function", "boot", "(", "Container", "$", "container", ")", "{", "add_action", "(", "'admin_init'", ",", "[", "$", "this", "->", "proxy", "(", "$", "container", ",", "'options_page'", ")", ",", "'admin_init'", "]", ")", ";", "add_action", "(", "'admin_menu'", ",", "[", "$", "this", "->", "proxy", "(", "$", "container", ",", "'options_page'", ")", ",", "'admin_menu'", "]", ")", ";", "add_action", "(", "'admin_notices'", ",", "[", "$", "this", "->", "proxy", "(", "$", "container", ",", "'options_page'", ")", ",", "'print_notice_when_no_notifiers_active'", "]", ")", ";", "add_action", "(", "'admin_init'", ",", "[", "$", "this", "->", "proxy", "(", "$", "container", ",", "'options_manager'", ")", ",", "'register_settings'", "]", ")", ";", "add_action", "(", "'soter_run_check'", ",", "[", "$", "this", "->", "proxy", "(", "$", "container", ",", "'check_site_job'", ")", ",", "'run'", "]", ")", ";", "add_action", "(", "'soter_site_check_complete'", ",", "[", "$", "this", "->", "proxy", "(", "$", "container", ",", "'notifier_manager'", ")", ",", "'notify'", "]", ")", ";", "$", "this", "->", "boot_upgrader", "(", "$", "container", ")", ";", "}" ]
Provider-specific boot logic. @param Container $container Plugin container instance. @return void
[ "Provider", "-", "specific", "boot", "logic", "." ]
f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7
https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-plugin-provider.php#L48-L66
14,227
ssnepenthe/soter
src/class-plugin-provider.php
Plugin_Provider.register
public function register( Container $container ) { $container['check_site_job'] = function( Container $c ) { return new Check_Site_Job( $c['checker'], $c['options_manager'] ); }; $container['checker'] = function( Container $c ) { $checker = new Checker( new Api_Client( $c['http'] ), new WP_Package_Manager() ); $checker->add_post_check_callback( function( $vulnerabilities, $response ) { do_action( 'soter_package_check_complete', $vulnerabilities, $response ); } ); return $checker; }; $container['http'] = function( Container $c ) { return new Cached_Http_Client( new WP_Http_Client( $c['user_agent'] ), new WP_Transient_Cache( $c['prefix'], HOUR_IN_SECONDS ) ); }; $container['notifier_manager'] = function( Container $c ) { $options = $c['options_manager']; return new Notifier_Manager( $options, [ new Email_Notifier( $c['plates'], $options ), new Slack_Notifier( $options, $c['user_agent'] ), ] ); }; $container['options_manager'] = function( Container $c ) { return new Options_Manager( new Options_Store( $c['prefix'] ) ); }; $container['options_page'] = function( Container $c ) { return new Options_Page( $c['options_manager'], $c['plates'] ); }; $container['plates'] = function( Container $c ) { $engine = new Engine( $c['dir'] . '/templates' ); // Drop the file extension so we can also load .css files. $engine->setFileExtension( null ); $engine->loadExtension( new Button_Extension() ); $engine->addData( [ 'plugin_url' => $c['url'], 'site_name' => get_bloginfo( 'name' ), 'site_url' => site_url(), ], [ 'emails/html/error.php', 'emails/html/vulnerable.php', 'emails/partials/footer.php', 'emails/partials/header.php', 'emails/text/error.php', 'emails/text/vulnerable.php', ] ); return $engine; }; $container['user_agent'] = function( Container $c ) { return sprintf( '%s (%s) | %s | v%s | %s', get_bloginfo( 'name' ), get_home_url(), $c['name'], $c['version'], $c['url'] ); }; }
php
public function register( Container $container ) { $container['check_site_job'] = function( Container $c ) { return new Check_Site_Job( $c['checker'], $c['options_manager'] ); }; $container['checker'] = function( Container $c ) { $checker = new Checker( new Api_Client( $c['http'] ), new WP_Package_Manager() ); $checker->add_post_check_callback( function( $vulnerabilities, $response ) { do_action( 'soter_package_check_complete', $vulnerabilities, $response ); } ); return $checker; }; $container['http'] = function( Container $c ) { return new Cached_Http_Client( new WP_Http_Client( $c['user_agent'] ), new WP_Transient_Cache( $c['prefix'], HOUR_IN_SECONDS ) ); }; $container['notifier_manager'] = function( Container $c ) { $options = $c['options_manager']; return new Notifier_Manager( $options, [ new Email_Notifier( $c['plates'], $options ), new Slack_Notifier( $options, $c['user_agent'] ), ] ); }; $container['options_manager'] = function( Container $c ) { return new Options_Manager( new Options_Store( $c['prefix'] ) ); }; $container['options_page'] = function( Container $c ) { return new Options_Page( $c['options_manager'], $c['plates'] ); }; $container['plates'] = function( Container $c ) { $engine = new Engine( $c['dir'] . '/templates' ); // Drop the file extension so we can also load .css files. $engine->setFileExtension( null ); $engine->loadExtension( new Button_Extension() ); $engine->addData( [ 'plugin_url' => $c['url'], 'site_name' => get_bloginfo( 'name' ), 'site_url' => site_url(), ], [ 'emails/html/error.php', 'emails/html/vulnerable.php', 'emails/partials/footer.php', 'emails/partials/header.php', 'emails/text/error.php', 'emails/text/vulnerable.php', ] ); return $engine; }; $container['user_agent'] = function( Container $c ) { return sprintf( '%s (%s) | %s | v%s | %s', get_bloginfo( 'name' ), get_home_url(), $c['name'], $c['version'], $c['url'] ); }; }
[ "public", "function", "register", "(", "Container", "$", "container", ")", "{", "$", "container", "[", "'check_site_job'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "return", "new", "Check_Site_Job", "(", "$", "c", "[", "'checker'", "]", ",", "$", "c", "[", "'options_manager'", "]", ")", ";", "}", ";", "$", "container", "[", "'checker'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "$", "checker", "=", "new", "Checker", "(", "new", "Api_Client", "(", "$", "c", "[", "'http'", "]", ")", ",", "new", "WP_Package_Manager", "(", ")", ")", ";", "$", "checker", "->", "add_post_check_callback", "(", "function", "(", "$", "vulnerabilities", ",", "$", "response", ")", "{", "do_action", "(", "'soter_package_check_complete'", ",", "$", "vulnerabilities", ",", "$", "response", ")", ";", "}", ")", ";", "return", "$", "checker", ";", "}", ";", "$", "container", "[", "'http'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "return", "new", "Cached_Http_Client", "(", "new", "WP_Http_Client", "(", "$", "c", "[", "'user_agent'", "]", ")", ",", "new", "WP_Transient_Cache", "(", "$", "c", "[", "'prefix'", "]", ",", "HOUR_IN_SECONDS", ")", ")", ";", "}", ";", "$", "container", "[", "'notifier_manager'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "$", "options", "=", "$", "c", "[", "'options_manager'", "]", ";", "return", "new", "Notifier_Manager", "(", "$", "options", ",", "[", "new", "Email_Notifier", "(", "$", "c", "[", "'plates'", "]", ",", "$", "options", ")", ",", "new", "Slack_Notifier", "(", "$", "options", ",", "$", "c", "[", "'user_agent'", "]", ")", ",", "]", ")", ";", "}", ";", "$", "container", "[", "'options_manager'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "return", "new", "Options_Manager", "(", "new", "Options_Store", "(", "$", "c", "[", "'prefix'", "]", ")", ")", ";", "}", ";", "$", "container", "[", "'options_page'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "return", "new", "Options_Page", "(", "$", "c", "[", "'options_manager'", "]", ",", "$", "c", "[", "'plates'", "]", ")", ";", "}", ";", "$", "container", "[", "'plates'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "$", "engine", "=", "new", "Engine", "(", "$", "c", "[", "'dir'", "]", ".", "'/templates'", ")", ";", "// Drop the file extension so we can also load .css files.", "$", "engine", "->", "setFileExtension", "(", "null", ")", ";", "$", "engine", "->", "loadExtension", "(", "new", "Button_Extension", "(", ")", ")", ";", "$", "engine", "->", "addData", "(", "[", "'plugin_url'", "=>", "$", "c", "[", "'url'", "]", ",", "'site_name'", "=>", "get_bloginfo", "(", "'name'", ")", ",", "'site_url'", "=>", "site_url", "(", ")", ",", "]", ",", "[", "'emails/html/error.php'", ",", "'emails/html/vulnerable.php'", ",", "'emails/partials/footer.php'", ",", "'emails/partials/header.php'", ",", "'emails/text/error.php'", ",", "'emails/text/vulnerable.php'", ",", "]", ")", ";", "return", "$", "engine", ";", "}", ";", "$", "container", "[", "'user_agent'", "]", "=", "function", "(", "Container", "$", "c", ")", "{", "return", "sprintf", "(", "'%s (%s) | %s | v%s | %s'", ",", "get_bloginfo", "(", "'name'", ")", ",", "get_home_url", "(", ")", ",", "$", "c", "[", "'name'", "]", ",", "$", "c", "[", "'version'", "]", ",", "$", "c", "[", "'url'", "]", ")", ";", "}", ";", "}" ]
Provider-specific registration logic. @param Container $container Plugin container instance. @return void
[ "Provider", "-", "specific", "registration", "logic", "." ]
f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7
https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-plugin-provider.php#L86-L160
14,228
ssnepenthe/soter
src/class-plugin-provider.php
Plugin_Provider.boot_upgrader
protected function boot_upgrader( Container $container ) { if ( ! $this->doing_cron() && ! is_admin() ) { return; } $upgrader = new Upgrader( $container['options_manager'] ); add_action( 'init', [ $upgrader, 'perform_upgrade' ] ); }
php
protected function boot_upgrader( Container $container ) { if ( ! $this->doing_cron() && ! is_admin() ) { return; } $upgrader = new Upgrader( $container['options_manager'] ); add_action( 'init', [ $upgrader, 'perform_upgrade' ] ); }
[ "protected", "function", "boot_upgrader", "(", "Container", "$", "container", ")", "{", "if", "(", "!", "$", "this", "->", "doing_cron", "(", ")", "&&", "!", "is_admin", "(", ")", ")", "{", "return", ";", "}", "$", "upgrader", "=", "new", "Upgrader", "(", "$", "container", "[", "'options_manager'", "]", ")", ";", "add_action", "(", "'init'", ",", "[", "$", "upgrader", ",", "'perform_upgrade'", "]", ")", ";", "}" ]
Boots the upgrader object on cron or admin requests. @param Container $container Plugin container instance. @return void
[ "Boots", "the", "upgrader", "object", "on", "cron", "or", "admin", "requests", "." ]
f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7
https://github.com/ssnepenthe/soter/blob/f6d7032f8562e23c2ee8dbf9d60ef1114c8cdce7/src/class-plugin-provider.php#L169-L177
14,229
crysalead/net
src/Headers.php
Headers.push
public function push($headers, $value = '') { if (is_string($headers) && func_num_args() === 2) { $headers = [$headers => $value]; } return $this->_set($headers); }
php
public function push($headers, $value = '') { if (is_string($headers) && func_num_args() === 2) { $headers = [$headers => $value]; } return $this->_set($headers); }
[ "public", "function", "push", "(", "$", "headers", ",", "$", "value", "=", "''", ")", "{", "if", "(", "is_string", "(", "$", "headers", ")", "&&", "func_num_args", "(", ")", "===", "2", ")", "{", "$", "headers", "=", "[", "$", "headers", "=>", "$", "value", "]", ";", "}", "return", "$", "this", "->", "_set", "(", "$", "headers", ")", ";", "}" ]
Sets some headers. @param string|array $headers A header name, string content or an array of headers. @param string|array $value The header value. I set, `$headers` must be an header string name. @return self
[ "Sets", "some", "headers", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Headers.php#L87-L93
14,230
crysalead/net
src/Headers.php
Headers.prepend
public function prepend($headers, $value = '') { if (is_string($headers) && func_num_args() === 2) { $headers = [$headers => $value]; } return $this->_set($headers, true); }
php
public function prepend($headers, $value = '') { if (is_string($headers) && func_num_args() === 2) { $headers = [$headers => $value]; } return $this->_set($headers, true); }
[ "public", "function", "prepend", "(", "$", "headers", ",", "$", "value", "=", "''", ")", "{", "if", "(", "is_string", "(", "$", "headers", ")", "&&", "func_num_args", "(", ")", "===", "2", ")", "{", "$", "headers", "=", "[", "$", "headers", "=>", "$", "value", "]", ";", "}", "return", "$", "this", "->", "_set", "(", "$", "headers", ",", "true", ")", ";", "}" ]
Prepends some headers. @param string|array $headers A header name, string content or an array of headers. @param string|array $value The header value. I set, `$headers` must be an header string name. @return self
[ "Prepends", "some", "headers", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Headers.php#L102-L108
14,231
crysalead/net
src/Headers.php
Headers.offsetExists
public function offsetExists($name) { $name = strtolower($name); if (!array_key_exists($name, $this->_data)) { return false; } return !empty($this->_data[$name]->value()); }
php
public function offsetExists($name) { $name = strtolower($name); if (!array_key_exists($name, $this->_data)) { return false; } return !empty($this->_data[$name]->value()); }
[ "public", "function", "offsetExists", "(", "$", "name", ")", "{", "$", "name", "=", "strtolower", "(", "$", "name", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "_data", ")", ")", "{", "return", "false", ";", "}", "return", "!", "empty", "(", "$", "this", "->", "_data", "[", "$", "name", "]", "->", "value", "(", ")", ")", ";", "}" ]
Checks whether or not an header exists. @param string $name The header name. @return boolean Returns `true` if the header exists, `false` otherwise.
[ "Checks", "whether", "or", "not", "an", "header", "exists", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Headers.php#L128-L135
14,232
crysalead/net
src/Headers.php
Headers.offsetGet
public function offsetGet($name) { if (!isset($this->_data[strtolower($name)])) { $header = $this->_classes['header']; return $this->_data[strtolower($name)] = new $header($name, ''); } return $this->_data[strtolower($name)]; }
php
public function offsetGet($name) { if (!isset($this->_data[strtolower($name)])) { $header = $this->_classes['header']; return $this->_data[strtolower($name)] = new $header($name, ''); } return $this->_data[strtolower($name)]; }
[ "public", "function", "offsetGet", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_data", "[", "strtolower", "(", "$", "name", ")", "]", ")", ")", "{", "$", "header", "=", "$", "this", "->", "_classes", "[", "'header'", "]", ";", "return", "$", "this", "->", "_data", "[", "strtolower", "(", "$", "name", ")", "]", "=", "new", "$", "header", "(", "$", "name", ",", "''", ")", ";", "}", "return", "$", "this", "->", "_data", "[", "strtolower", "(", "$", "name", ")", "]", ";", "}" ]
Returns the value of a specific header. @param string $name The header name. @return string The header value.
[ "Returns", "the", "value", "of", "a", "specific", "header", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Headers.php#L143-L150
14,233
crysalead/net
src/Headers.php
Headers._set
protected function _set($values, $prepend = false) { $header = $this->_classes['header']; $headers = is_string($values) ? explode("\n", $values) : $values; $headers = $headers ? $headers : []; foreach ($headers as $key => $value) { if (!is_numeric($key)) { if ($value instanceof $header) { $value->name($key); } elseif (is_array($value)) { $value = "{$key}: " . join(', ', $value); } else { $value = "{$key}: {$value}"; } } if (is_string($value)) { $value = trim($value); } if (!$value) { continue; } if ($value instanceof $header) { $parsed = $value; } elseif (!$parsed = $header::parse($value)) { throw new NetException("Invalid header: `'{$value}'`."); } $name = strtolower($parsed->name()); if (!$name) { throw new Exception("Error, invalid header name, can't be empty."); } if ($name === 'set-cookie' && isset($this->_data[$name])) { $previsous = $this->_data[$name]; $previsous[] = $parsed->value(); $parsed = $previsous; } if ($prepend) { $this->_data = [$name => $parsed] + $this->_data; } else { $this->_data = array_merge($this->_data, [$name => $parsed]); } } return $this; }
php
protected function _set($values, $prepend = false) { $header = $this->_classes['header']; $headers = is_string($values) ? explode("\n", $values) : $values; $headers = $headers ? $headers : []; foreach ($headers as $key => $value) { if (!is_numeric($key)) { if ($value instanceof $header) { $value->name($key); } elseif (is_array($value)) { $value = "{$key}: " . join(', ', $value); } else { $value = "{$key}: {$value}"; } } if (is_string($value)) { $value = trim($value); } if (!$value) { continue; } if ($value instanceof $header) { $parsed = $value; } elseif (!$parsed = $header::parse($value)) { throw new NetException("Invalid header: `'{$value}'`."); } $name = strtolower($parsed->name()); if (!$name) { throw new Exception("Error, invalid header name, can't be empty."); } if ($name === 'set-cookie' && isset($this->_data[$name])) { $previsous = $this->_data[$name]; $previsous[] = $parsed->value(); $parsed = $previsous; } if ($prepend) { $this->_data = [$name => $parsed] + $this->_data; } else { $this->_data = array_merge($this->_data, [$name => $parsed]); } } return $this; }
[ "protected", "function", "_set", "(", "$", "values", ",", "$", "prepend", "=", "false", ")", "{", "$", "header", "=", "$", "this", "->", "_classes", "[", "'header'", "]", ";", "$", "headers", "=", "is_string", "(", "$", "values", ")", "?", "explode", "(", "\"\\n\"", ",", "$", "values", ")", ":", "$", "values", ";", "$", "headers", "=", "$", "headers", "?", "$", "headers", ":", "[", "]", ";", "foreach", "(", "$", "headers", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "is_numeric", "(", "$", "key", ")", ")", "{", "if", "(", "$", "value", "instanceof", "$", "header", ")", "{", "$", "value", "->", "name", "(", "$", "key", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "value", "=", "\"{$key}: \"", ".", "join", "(", "', '", ",", "$", "value", ")", ";", "}", "else", "{", "$", "value", "=", "\"{$key}: {$value}\"", ";", "}", "}", "if", "(", "is_string", "(", "$", "value", ")", ")", "{", "$", "value", "=", "trim", "(", "$", "value", ")", ";", "}", "if", "(", "!", "$", "value", ")", "{", "continue", ";", "}", "if", "(", "$", "value", "instanceof", "$", "header", ")", "{", "$", "parsed", "=", "$", "value", ";", "}", "elseif", "(", "!", "$", "parsed", "=", "$", "header", "::", "parse", "(", "$", "value", ")", ")", "{", "throw", "new", "NetException", "(", "\"Invalid header: `'{$value}'`.\"", ")", ";", "}", "$", "name", "=", "strtolower", "(", "$", "parsed", "->", "name", "(", ")", ")", ";", "if", "(", "!", "$", "name", ")", "{", "throw", "new", "Exception", "(", "\"Error, invalid header name, can't be empty.\"", ")", ";", "}", "if", "(", "$", "name", "===", "'set-cookie'", "&&", "isset", "(", "$", "this", "->", "_data", "[", "$", "name", "]", ")", ")", "{", "$", "previsous", "=", "$", "this", "->", "_data", "[", "$", "name", "]", ";", "$", "previsous", "[", "]", "=", "$", "parsed", "->", "value", "(", ")", ";", "$", "parsed", "=", "$", "previsous", ";", "}", "if", "(", "$", "prepend", ")", "{", "$", "this", "->", "_data", "=", "[", "$", "name", "=>", "$", "parsed", "]", "+", "$", "this", "->", "_data", ";", "}", "else", "{", "$", "this", "->", "_data", "=", "array_merge", "(", "$", "this", "->", "_data", ",", "[", "$", "name", "=>", "$", "parsed", "]", ")", ";", "}", "}", "return", "$", "this", ";", "}" ]
Sets one or some plain string headers. @param string|array $headers A header string or an array of headers. @param boolean $prepend If true, prepend headers to the beginning. @return self
[ "Sets", "one", "or", "some", "plain", "string", "headers", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Headers.php#L181-L229
14,234
crysalead/net
src/Headers.php
Headers.valid
public function valid() { if (key($this->_data) === null) { return false; } $current = current($this->_data); while (!$current->value()) { $current = $this->next(); if (key($this->_data) === null) { return false; } } return true; }
php
public function valid() { if (key($this->_data) === null) { return false; } $current = current($this->_data); while (!$current->value()) { $current = $this->next(); if (key($this->_data) === null) { return false; } } return true; }
[ "public", "function", "valid", "(", ")", "{", "if", "(", "key", "(", "$", "this", "->", "_data", ")", "===", "null", ")", "{", "return", "false", ";", "}", "$", "current", "=", "current", "(", "$", "this", "->", "_data", ")", ";", "while", "(", "!", "$", "current", "->", "value", "(", ")", ")", "{", "$", "current", "=", "$", "this", "->", "next", "(", ")", ";", "if", "(", "key", "(", "$", "this", "->", "_data", ")", "===", "null", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Returns the current item. @return mixed The current item or `false` on failure.
[ "Returns", "the", "current", "item", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Headers.php#L236-L250
14,235
crysalead/net
src/Headers.php
Headers.toArray
public static function toArray($headers, $options = []) { $data = []; foreach ($headers as $name => $header) { if (strtolower($name) === 'set-cookie') { foreach ($header->data() as $value) { $data[] = $name . ': ' . $value; } } else { $data[] = $name . ': ' . $header->value(); } } return $data; }
php
public static function toArray($headers, $options = []) { $data = []; foreach ($headers as $name => $header) { if (strtolower($name) === 'set-cookie') { foreach ($header->data() as $value) { $data[] = $name . ': ' . $value; } } else { $data[] = $name . ': ' . $header->value(); } } return $data; }
[ "public", "static", "function", "toArray", "(", "$", "headers", ",", "$", "options", "=", "[", "]", ")", "{", "$", "data", "=", "[", "]", ";", "foreach", "(", "$", "headers", "as", "$", "name", "=>", "$", "header", ")", "{", "if", "(", "strtolower", "(", "$", "name", ")", "===", "'set-cookie'", ")", "{", "foreach", "(", "$", "header", "->", "data", "(", ")", "as", "$", "value", ")", "{", "$", "data", "[", "]", "=", "$", "name", ".", "': '", ".", "$", "value", ";", "}", "}", "else", "{", "$", "data", "[", "]", "=", "$", "name", ".", "': '", ".", "$", "header", "->", "value", "(", ")", ";", "}", "}", "return", "$", "data", ";", "}" ]
Gets the headers as an array. @return array Returns the headers.
[ "Gets", "the", "headers", "as", "an", "array", "." ]
4d75abead39e954529b56cbffa3841a9cd3044bb
https://github.com/crysalead/net/blob/4d75abead39e954529b56cbffa3841a9cd3044bb/src/Headers.php#L257-L270
14,236
eddiriarte/console-select
src/Handlers/SelectHandler.php
SelectHandler.handle
public function handle(): array { $this->firstRun = true; $this->output->writeln( '<info>' . $this->question->getMessage() . '</info> [<comment>SPACE=select</>, <comment>ENTER=submit</>]' ); $this->repaint(); $sttyMode = shell_exec('stty -g'); // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead) shell_exec('stty -icanon -echo'); // Read a keypress while (!feof($this->stream)) { $char = fread($this->stream, 1); if (" " === $char) { $this->tryCellSelection(); } elseif ("\033" === $char) { $this->tryCellNavigation($char); } elseif (10 === ord($char)) { //TODO handle valid state... $this->clear(); $this->output->write('> ' . join(', ', $this->question->getSelections())); $this->output->write($char); break; } $this->repaint(); } // Reset stty so it behaves normally again shell_exec(sprintf('stty %s', $sttyMode)); $this->output->writeln(' '); return $this->question->getSelections(); }
php
public function handle(): array { $this->firstRun = true; $this->output->writeln( '<info>' . $this->question->getMessage() . '</info> [<comment>SPACE=select</>, <comment>ENTER=submit</>]' ); $this->repaint(); $sttyMode = shell_exec('stty -g'); // Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead) shell_exec('stty -icanon -echo'); // Read a keypress while (!feof($this->stream)) { $char = fread($this->stream, 1); if (" " === $char) { $this->tryCellSelection(); } elseif ("\033" === $char) { $this->tryCellNavigation($char); } elseif (10 === ord($char)) { //TODO handle valid state... $this->clear(); $this->output->write('> ' . join(', ', $this->question->getSelections())); $this->output->write($char); break; } $this->repaint(); } // Reset stty so it behaves normally again shell_exec(sprintf('stty %s', $sttyMode)); $this->output->writeln(' '); return $this->question->getSelections(); }
[ "public", "function", "handle", "(", ")", ":", "array", "{", "$", "this", "->", "firstRun", "=", "true", ";", "$", "this", "->", "output", "->", "writeln", "(", "'<info>'", ".", "$", "this", "->", "question", "->", "getMessage", "(", ")", ".", "'</info> [<comment>SPACE=select</>, <comment>ENTER=submit</>]'", ")", ";", "$", "this", "->", "repaint", "(", ")", ";", "$", "sttyMode", "=", "shell_exec", "(", "'stty -g'", ")", ";", "// Disable icanon (so we can fread each keypress) and echo (we'll do echoing here instead)", "shell_exec", "(", "'stty -icanon -echo'", ")", ";", "// Read a keypress", "while", "(", "!", "feof", "(", "$", "this", "->", "stream", ")", ")", "{", "$", "char", "=", "fread", "(", "$", "this", "->", "stream", ",", "1", ")", ";", "if", "(", "\" \"", "===", "$", "char", ")", "{", "$", "this", "->", "tryCellSelection", "(", ")", ";", "}", "elseif", "(", "\"\\033\"", "===", "$", "char", ")", "{", "$", "this", "->", "tryCellNavigation", "(", "$", "char", ")", ";", "}", "elseif", "(", "10", "===", "ord", "(", "$", "char", ")", ")", "{", "//TODO handle valid state...", "$", "this", "->", "clear", "(", ")", ";", "$", "this", "->", "output", "->", "write", "(", "'> '", ".", "join", "(", "', '", ",", "$", "this", "->", "question", "->", "getSelections", "(", ")", ")", ")", ";", "$", "this", "->", "output", "->", "write", "(", "$", "char", ")", ";", "break", ";", "}", "$", "this", "->", "repaint", "(", ")", ";", "}", "// Reset stty so it behaves normally again", "shell_exec", "(", "sprintf", "(", "'stty %s'", ",", "$", "sttyMode", ")", ")", ";", "$", "this", "->", "output", "->", "writeln", "(", "' '", ")", ";", "return", "$", "this", "->", "question", "->", "getSelections", "(", ")", ";", "}" ]
Navigates through option items. @return array
[ "Navigates", "through", "option", "items", "." ]
76a6818c128571dfed8f0546a6ac5dd15e64f1ad
https://github.com/eddiriarte/console-select/blob/76a6818c128571dfed8f0546a6ac5dd15e64f1ad/src/Handlers/SelectHandler.php#L70-L106
14,237
guillaumemonet/Rad
src/Rad/Utils/Time.php
Time.get_microtime
public static function get_microtime() { list($tps_usec, $tps_sec) = explode(' ', microtime()); return (float) $tps_usec + (float) $tps_sec; }
php
public static function get_microtime() { list($tps_usec, $tps_sec) = explode(' ', microtime()); return (float) $tps_usec + (float) $tps_sec; }
[ "public", "static", "function", "get_microtime", "(", ")", "{", "list", "(", "$", "tps_usec", ",", "$", "tps_sec", ")", "=", "explode", "(", "' '", ",", "microtime", "(", ")", ")", ";", "return", "(", "float", ")", "$", "tps_usec", "+", "(", "float", ")", "$", "tps_sec", ";", "}" ]
Return current microtime. @return int
[ "Return", "current", "microtime", "." ]
cb9932f570cf3c2a7197f81e1d959c2729989e59
https://github.com/guillaumemonet/Rad/blob/cb9932f570cf3c2a7197f81e1d959c2729989e59/src/Rad/Utils/Time.php#L53-L56
14,238
guillaumemonet/Rad
src/Rad/Utils/Time.php
Time.isFrenchHoliday
public static function isFrenchHoliday($unixTimeStamp = null) { $date = strtotime(date('m/d/Y', $unixTimeStamp == null ? time() : $unixTimeStamp)); $year = date('Y', $date); $holidays = Cache::getHandler('quick')->get('holiday' . $year); if ($holidays == null) { $easterDate = easter_date($year) + 3 * 3600; $easterDay = date('j', $easterDate); $easterMonth = date('n', $easterDate); $easterYear = date('Y', $easterDate); $holidays = array( // Dates fixes mktime(0, 0, 0, 1, 1, $year), // 1er janvier mktime(0, 0, 0, 5, 1, $year), // Fête du travail mktime(0, 0, 0, 5, 8, $year), // Victoire des alliés mktime(0, 0, 0, 7, 14, $year), // Fête nationale mktime(0, 0, 0, 8, 15, $year), // Assomption mktime(0, 0, 0, 11, 1, $year), // Toussaint mktime(0, 0, 0, 11, 11, $year), // Armistice mktime(0, 0, 0, 12, 25, $year), // Noel // Dates variables //Lundi de paques mktime(0, 0, 0, $easterMonth, $easterDay + 1, $easterYear), //Jeudi de l'ascension mktime(0, 0, 0, $easterMonth, $easterDay + 39, $easterYear), //Lundi pentecote mktime(0, 0, 0, $easterMonth, $easterDay + 50, $easterYear), ); Cache::getHandler('quick')->set('holiday' . $year, $holidays); } return in_array($date, $holidays); }
php
public static function isFrenchHoliday($unixTimeStamp = null) { $date = strtotime(date('m/d/Y', $unixTimeStamp == null ? time() : $unixTimeStamp)); $year = date('Y', $date); $holidays = Cache::getHandler('quick')->get('holiday' . $year); if ($holidays == null) { $easterDate = easter_date($year) + 3 * 3600; $easterDay = date('j', $easterDate); $easterMonth = date('n', $easterDate); $easterYear = date('Y', $easterDate); $holidays = array( // Dates fixes mktime(0, 0, 0, 1, 1, $year), // 1er janvier mktime(0, 0, 0, 5, 1, $year), // Fête du travail mktime(0, 0, 0, 5, 8, $year), // Victoire des alliés mktime(0, 0, 0, 7, 14, $year), // Fête nationale mktime(0, 0, 0, 8, 15, $year), // Assomption mktime(0, 0, 0, 11, 1, $year), // Toussaint mktime(0, 0, 0, 11, 11, $year), // Armistice mktime(0, 0, 0, 12, 25, $year), // Noel // Dates variables //Lundi de paques mktime(0, 0, 0, $easterMonth, $easterDay + 1, $easterYear), //Jeudi de l'ascension mktime(0, 0, 0, $easterMonth, $easterDay + 39, $easterYear), //Lundi pentecote mktime(0, 0, 0, $easterMonth, $easterDay + 50, $easterYear), ); Cache::getHandler('quick')->set('holiday' . $year, $holidays); } return in_array($date, $holidays); }
[ "public", "static", "function", "isFrenchHoliday", "(", "$", "unixTimeStamp", "=", "null", ")", "{", "$", "date", "=", "strtotime", "(", "date", "(", "'m/d/Y'", ",", "$", "unixTimeStamp", "==", "null", "?", "time", "(", ")", ":", "$", "unixTimeStamp", ")", ")", ";", "$", "year", "=", "date", "(", "'Y'", ",", "$", "date", ")", ";", "$", "holidays", "=", "Cache", "::", "getHandler", "(", "'quick'", ")", "->", "get", "(", "'holiday'", ".", "$", "year", ")", ";", "if", "(", "$", "holidays", "==", "null", ")", "{", "$", "easterDate", "=", "easter_date", "(", "$", "year", ")", "+", "3", "*", "3600", ";", "$", "easterDay", "=", "date", "(", "'j'", ",", "$", "easterDate", ")", ";", "$", "easterMonth", "=", "date", "(", "'n'", ",", "$", "easterDate", ")", ";", "$", "easterYear", "=", "date", "(", "'Y'", ",", "$", "easterDate", ")", ";", "$", "holidays", "=", "array", "(", "// Dates fixes", "mktime", "(", "0", ",", "0", ",", "0", ",", "1", ",", "1", ",", "$", "year", ")", ",", "// 1er janvier", "mktime", "(", "0", ",", "0", ",", "0", ",", "5", ",", "1", ",", "$", "year", ")", ",", "// Fête du travail", "mktime", "(", "0", ",", "0", ",", "0", ",", "5", ",", "8", ",", "$", "year", ")", ",", "// Victoire des alliés", "mktime", "(", "0", ",", "0", ",", "0", ",", "7", ",", "14", ",", "$", "year", ")", ",", "// Fête nationale", "mktime", "(", "0", ",", "0", ",", "0", ",", "8", ",", "15", ",", "$", "year", ")", ",", "// Assomption", "mktime", "(", "0", ",", "0", ",", "0", ",", "11", ",", "1", ",", "$", "year", ")", ",", "// Toussaint", "mktime", "(", "0", ",", "0", ",", "0", ",", "11", ",", "11", ",", "$", "year", ")", ",", "// Armistice", "mktime", "(", "0", ",", "0", ",", "0", ",", "12", ",", "25", ",", "$", "year", ")", ",", "// Noel", "// Dates variables", "//Lundi de paques", "mktime", "(", "0", ",", "0", ",", "0", ",", "$", "easterMonth", ",", "$", "easterDay", "+", "1", ",", "$", "easterYear", ")", ",", "//Jeudi de l'ascension", "mktime", "(", "0", ",", "0", ",", "0", ",", "$", "easterMonth", ",", "$", "easterDay", "+", "39", ",", "$", "easterYear", ")", ",", "//Lundi pentecote", "mktime", "(", "0", ",", "0", ",", "0", ",", "$", "easterMonth", ",", "$", "easterDay", "+", "50", ",", "$", "easterYear", ")", ",", ")", ";", "Cache", "::", "getHandler", "(", "'quick'", ")", "->", "set", "(", "'holiday'", ".", "$", "year", ",", "$", "holidays", ")", ";", "}", "return", "in_array", "(", "$", "date", ",", "$", "holidays", ")", ";", "}" ]
Return french holiday @param int $unixTimeStamp @return bool
[ "Return", "french", "holiday" ]
cb9932f570cf3c2a7197f81e1d959c2729989e59
https://github.com/guillaumemonet/Rad/blob/cb9932f570cf3c2a7197f81e1d959c2729989e59/src/Rad/Utils/Time.php#L79-L109
14,239
nyeholt/silverstripe-simplewiki
thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/ErrorCollector.php
HTMLPurifier_ErrorCollector.getHTMLFormatted
public function getHTMLFormatted($config, $errors = null) { $ret = array(); $this->generator = new HTMLPurifier_Generator($config, $this->context); if ($errors === null) $errors = $this->errors; // 'At line' message needs to be removed // generation code for new structure goes here. It needs to be recursive. foreach ($this->lines as $line => $col_array) { if ($line == -1) continue; foreach ($col_array as $col => $struct) { $this->_renderStruct($ret, $struct, $line, $col); } } if (isset($this->lines[-1])) { $this->_renderStruct($ret, $this->lines[-1]); } if (empty($errors)) { return '<p>' . $this->locale->getMessage('ErrorCollector: No errors') . '</p>'; } else { return '<ul><li>' . implode('</li><li>', $ret) . '</li></ul>'; } }
php
public function getHTMLFormatted($config, $errors = null) { $ret = array(); $this->generator = new HTMLPurifier_Generator($config, $this->context); if ($errors === null) $errors = $this->errors; // 'At line' message needs to be removed // generation code for new structure goes here. It needs to be recursive. foreach ($this->lines as $line => $col_array) { if ($line == -1) continue; foreach ($col_array as $col => $struct) { $this->_renderStruct($ret, $struct, $line, $col); } } if (isset($this->lines[-1])) { $this->_renderStruct($ret, $this->lines[-1]); } if (empty($errors)) { return '<p>' . $this->locale->getMessage('ErrorCollector: No errors') . '</p>'; } else { return '<ul><li>' . implode('</li><li>', $ret) . '</li></ul>'; } }
[ "public", "function", "getHTMLFormatted", "(", "$", "config", ",", "$", "errors", "=", "null", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "this", "->", "generator", "=", "new", "HTMLPurifier_Generator", "(", "$", "config", ",", "$", "this", "->", "context", ")", ";", "if", "(", "$", "errors", "===", "null", ")", "$", "errors", "=", "$", "this", "->", "errors", ";", "// 'At line' message needs to be removed", "// generation code for new structure goes here. It needs to be recursive.", "foreach", "(", "$", "this", "->", "lines", "as", "$", "line", "=>", "$", "col_array", ")", "{", "if", "(", "$", "line", "==", "-", "1", ")", "continue", ";", "foreach", "(", "$", "col_array", "as", "$", "col", "=>", "$", "struct", ")", "{", "$", "this", "->", "_renderStruct", "(", "$", "ret", ",", "$", "struct", ",", "$", "line", ",", "$", "col", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "lines", "[", "-", "1", "]", ")", ")", "{", "$", "this", "->", "_renderStruct", "(", "$", "ret", ",", "$", "this", "->", "lines", "[", "-", "1", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "errors", ")", ")", "{", "return", "'<p>'", ".", "$", "this", "->", "locale", "->", "getMessage", "(", "'ErrorCollector: No errors'", ")", ".", "'</p>'", ";", "}", "else", "{", "return", "'<ul><li>'", ".", "implode", "(", "'</li><li>'", ",", "$", "ret", ")", ".", "'</li></ul>'", ";", "}", "}" ]
Default HTML formatting implementation for error messages @param $config Configuration array, vital for HTML output nature @param $errors Errors array to display; used for recursion.
[ "Default", "HTML", "formatting", "implementation", "for", "error", "messages" ]
ecffed0d75be1454901e1cb24633472b8f67c967
https://github.com/nyeholt/silverstripe-simplewiki/blob/ecffed0d75be1454901e1cb24633472b8f67c967/thirdparty/htmlpurifier-4.0.0-lite/library/HTMLPurifier/ErrorCollector.php#L144-L169
14,240
reinvanoyen/aegis
lib/Aegis/Cache/Filesystem.php
Filesystem.load
public static function load($id, $subId = null) : CacheEntryInterface { $storageId = $id; if ($subId) { $storageId .= '[' . $subId . ']'; } if (!isset(self::$files[$storageId])) { $filename = static::CACHE_DIR . ($subId ? $subId . '/' : null) . urlencode($id) . '.' . static::CACHE_EXTENSION; self::$files[$storageId] = new File($filename); } return self::$files[$storageId]; }
php
public static function load($id, $subId = null) : CacheEntryInterface { $storageId = $id; if ($subId) { $storageId .= '[' . $subId . ']'; } if (!isset(self::$files[$storageId])) { $filename = static::CACHE_DIR . ($subId ? $subId . '/' : null) . urlencode($id) . '.' . static::CACHE_EXTENSION; self::$files[$storageId] = new File($filename); } return self::$files[$storageId]; }
[ "public", "static", "function", "load", "(", "$", "id", ",", "$", "subId", "=", "null", ")", ":", "CacheEntryInterface", "{", "$", "storageId", "=", "$", "id", ";", "if", "(", "$", "subId", ")", "{", "$", "storageId", ".=", "'['", ".", "$", "subId", ".", "']'", ";", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "files", "[", "$", "storageId", "]", ")", ")", "{", "$", "filename", "=", "static", "::", "CACHE_DIR", ".", "(", "$", "subId", "?", "$", "subId", ".", "'/'", ":", "null", ")", ".", "urlencode", "(", "$", "id", ")", ".", "'.'", ".", "static", "::", "CACHE_EXTENSION", ";", "self", "::", "$", "files", "[", "$", "storageId", "]", "=", "new", "File", "(", "$", "filename", ")", ";", "}", "return", "self", "::", "$", "files", "[", "$", "storageId", "]", ";", "}" ]
Gets the cache file from the filesystem @param $id @param null $subId @return CacheEntryInterface
[ "Gets", "the", "cache", "file", "from", "the", "filesystem" ]
ecd831fd6f3ceb4fb20fb5af83483d73cad8e323
https://github.com/reinvanoyen/aegis/blob/ecd831fd6f3ceb4fb20fb5af83483d73cad8e323/lib/Aegis/Cache/Filesystem.php#L27-L41
14,241
cpliakas/search-framework
src/Search/Framework/Schema.php
Schema.build
public function build(array $options) { if (isset($options['fields'])) { if (!is_array($options['fields'])) { $message = 'Argument 1 passed to ' . __METHOD__ . ' must be an array.'; throw new \InvalidArgumentException($message); } foreach ($options['fields'] as $id => $field_options) { $this->attachField(new SchemaField($id, $field_options)); } } if (isset($options['unique_field'])) { $this->setUniqueField($options['unique_field']); } }
php
public function build(array $options) { if (isset($options['fields'])) { if (!is_array($options['fields'])) { $message = 'Argument 1 passed to ' . __METHOD__ . ' must be an array.'; throw new \InvalidArgumentException($message); } foreach ($options['fields'] as $id => $field_options) { $this->attachField(new SchemaField($id, $field_options)); } } if (isset($options['unique_field'])) { $this->setUniqueField($options['unique_field']); } }
[ "public", "function", "build", "(", "array", "$", "options", ")", "{", "if", "(", "isset", "(", "$", "options", "[", "'fields'", "]", ")", ")", "{", "if", "(", "!", "is_array", "(", "$", "options", "[", "'fields'", "]", ")", ")", "{", "$", "message", "=", "'Argument 1 passed to '", ".", "__METHOD__", ".", "' must be an array.'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "foreach", "(", "$", "options", "[", "'fields'", "]", "as", "$", "id", "=>", "$", "field_options", ")", "{", "$", "this", "->", "attachField", "(", "new", "SchemaField", "(", "$", "id", ",", "$", "field_options", ")", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "options", "[", "'unique_field'", "]", ")", ")", "{", "$", "this", "->", "setUniqueField", "(", "$", "options", "[", "'unique_field'", "]", ")", ";", "}", "}" ]
Builds the schema from an array of options. @param array $options The raw options parsed form the configuration file related to the schema. @throws \InvalidArgumentException
[ "Builds", "the", "schema", "from", "an", "array", "of", "options", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Schema.php#L65-L80
14,242
cpliakas/search-framework
src/Search/Framework/Schema.php
Schema.attachField
public function attachField(SchemaField $field) { $id = $field->getId(); $name = $field->getName(); $this->_fields[$id] = $field; $this->_fieldNameMap[$name] = $id; return $this; }
php
public function attachField(SchemaField $field) { $id = $field->getId(); $name = $field->getName(); $this->_fields[$id] = $field; $this->_fieldNameMap[$name] = $id; return $this; }
[ "public", "function", "attachField", "(", "SchemaField", "$", "field", ")", "{", "$", "id", "=", "$", "field", "->", "getId", "(", ")", ";", "$", "name", "=", "$", "field", "->", "getName", "(", ")", ";", "$", "this", "->", "_fields", "[", "$", "id", "]", "=", "$", "field", ";", "$", "this", "->", "_fieldNameMap", "[", "$", "name", "]", "=", "$", "id", ";", "return", "$", "this", ";", "}" ]
Associates a field with this schema. @param SchemaField $field The field being associated with the schema. @return Schema
[ "Associates", "a", "field", "with", "this", "schema", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Schema.php#L90-L97
14,243
cpliakas/search-framework
src/Search/Framework/Schema.php
Schema.getField
public function getField($id) { if (!isset($this->_fields[$id])) { $message = 'Field "' . $id . '" not associated with this schema.'; throw new \InvalidArgumentException($message); } return $this->_fields[$id]; }
php
public function getField($id) { if (!isset($this->_fields[$id])) { $message = 'Field "' . $id . '" not associated with this schema.'; throw new \InvalidArgumentException($message); } return $this->_fields[$id]; }
[ "public", "function", "getField", "(", "$", "id", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_fields", "[", "$", "id", "]", ")", ")", "{", "$", "message", "=", "'Field \"'", ".", "$", "id", ".", "'\" not associated with this schema.'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "return", "$", "this", "->", "_fields", "[", "$", "id", "]", ";", "}" ]
Returns a field by its unique identifier. @param string $id The unique identifier of the field. @return SchemaField @throw \InvalidArgumentException()
[ "Returns", "a", "field", "by", "its", "unique", "identifier", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Schema.php#L109-L116
14,244
cpliakas/search-framework
src/Search/Framework/Schema.php
Schema.getFieldByName
public function getFieldByName($name) { if (!isset($this->_fieldNameMap[$name])) { $message = 'Field name "' . $name . '" not associated to this schema.'; throw new \InvalidArgumentException($message); } return $this->getField($this->_fieldNameMap[$name]); }
php
public function getFieldByName($name) { if (!isset($this->_fieldNameMap[$name])) { $message = 'Field name "' . $name . '" not associated to this schema.'; throw new \InvalidArgumentException($message); } return $this->getField($this->_fieldNameMap[$name]); }
[ "public", "function", "getFieldByName", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_fieldNameMap", "[", "$", "name", "]", ")", ")", "{", "$", "message", "=", "'Field name \"'", ".", "$", "name", ".", "'\" not associated to this schema.'", ";", "throw", "new", "\\", "InvalidArgumentException", "(", "$", "message", ")", ";", "}", "return", "$", "this", "->", "getField", "(", "$", "this", "->", "_fieldNameMap", "[", "$", "name", "]", ")", ";", "}" ]
Returns a field by its name as stored in the index. @param string $name The name of the field as stored in the index. @return SchemaField @throws \InvalidArgumentException()
[ "Returns", "a", "field", "by", "its", "name", "as", "stored", "in", "the", "index", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Schema.php#L138-L145
14,245
cpliakas/search-framework
src/Search/Framework/Schema.php
Schema.removeField
public function removeField($id) { if (isset($this->_fields[$id])) { $name = $this->_fields[$id]->getName(); unset($this->_fields[$id], $this->_fieldNameMap[$name]); } return $this; }
php
public function removeField($id) { if (isset($this->_fields[$id])) { $name = $this->_fields[$id]->getName(); unset($this->_fields[$id], $this->_fieldNameMap[$name]); } return $this; }
[ "public", "function", "removeField", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_fields", "[", "$", "id", "]", ")", ")", "{", "$", "name", "=", "$", "this", "->", "_fields", "[", "$", "id", "]", "->", "getName", "(", ")", ";", "unset", "(", "$", "this", "->", "_fields", "[", "$", "id", "]", ",", "$", "this", "->", "_fieldNameMap", "[", "$", "name", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
De-references a field from the schema. @param string $id The unique identifier of the field. @return Schema
[ "De", "-", "references", "a", "field", "from", "the", "schema", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Schema.php#L168-L175
14,246
cpliakas/search-framework
src/Search/Framework/Schema.php
Schema.toArray
public function toArray() { $schema_options = array( 'unique_field' => $this->_uniqueField, 'fields' => array(), ); foreach ($this->_fields as $id => $field) { $schema_options['fields'][$id] = $field->toArray(); } return $schema_options; }
php
public function toArray() { $schema_options = array( 'unique_field' => $this->_uniqueField, 'fields' => array(), ); foreach ($this->_fields as $id => $field) { $schema_options['fields'][$id] = $field->toArray(); } return $schema_options; }
[ "public", "function", "toArray", "(", ")", "{", "$", "schema_options", "=", "array", "(", "'unique_field'", "=>", "$", "this", "->", "_uniqueField", ",", "'fields'", "=>", "array", "(", ")", ",", ")", ";", "foreach", "(", "$", "this", "->", "_fields", "as", "$", "id", "=>", "$", "field", ")", "{", "$", "schema_options", "[", "'fields'", "]", "[", "$", "id", "]", "=", "$", "field", "->", "toArray", "(", ")", ";", "}", "return", "$", "schema_options", ";", "}" ]
Returns the array of schema options. @return
[ "Returns", "the", "array", "of", "schema", "options", "." ]
7c5832d38ed998e04837c26e0daef59115563b98
https://github.com/cpliakas/search-framework/blob/7c5832d38ed998e04837c26e0daef59115563b98/src/Search/Framework/Schema.php#L259-L269
14,247
antarestupin/Accessible
lib/Accessible/AutoMethodsTrait.php
AutoMethodsTrait.getMethodCallInfo
private function getMethodCallInfo($name) { $extractedMethod = preg_match("/^(set|get|is|add|remove)([A-Z].*)/", $name, $pregMatches); if ($extractedMethod) { $method = $pregMatches[1]; $property = lcfirst($pregMatches[2]); } else { $method = 'call'; $property = $name; } $collectionProperties = null; if (in_array($method, array('add', 'remove'))) { $collectionProperties = $this->_collectionsItemNames['byItemName'][$property]; $property = $collectionProperties['property']; } // check that the method is accepted by the targeted property if ( empty($this->_accessProperties[$property]) || !in_array($method, $this->_accessProperties[$property]) ) { throw new \BadMethodCallException("Method $name does not exist."); } return array( 'method' => $method, 'property' => $property, 'collectionProperties' => $collectionProperties ); }
php
private function getMethodCallInfo($name) { $extractedMethod = preg_match("/^(set|get|is|add|remove)([A-Z].*)/", $name, $pregMatches); if ($extractedMethod) { $method = $pregMatches[1]; $property = lcfirst($pregMatches[2]); } else { $method = 'call'; $property = $name; } $collectionProperties = null; if (in_array($method, array('add', 'remove'))) { $collectionProperties = $this->_collectionsItemNames['byItemName'][$property]; $property = $collectionProperties['property']; } // check that the method is accepted by the targeted property if ( empty($this->_accessProperties[$property]) || !in_array($method, $this->_accessProperties[$property]) ) { throw new \BadMethodCallException("Method $name does not exist."); } return array( 'method' => $method, 'property' => $property, 'collectionProperties' => $collectionProperties ); }
[ "private", "function", "getMethodCallInfo", "(", "$", "name", ")", "{", "$", "extractedMethod", "=", "preg_match", "(", "\"/^(set|get|is|add|remove)([A-Z].*)/\"", ",", "$", "name", ",", "$", "pregMatches", ")", ";", "if", "(", "$", "extractedMethod", ")", "{", "$", "method", "=", "$", "pregMatches", "[", "1", "]", ";", "$", "property", "=", "lcfirst", "(", "$", "pregMatches", "[", "2", "]", ")", ";", "}", "else", "{", "$", "method", "=", "'call'", ";", "$", "property", "=", "$", "name", ";", "}", "$", "collectionProperties", "=", "null", ";", "if", "(", "in_array", "(", "$", "method", ",", "array", "(", "'add'", ",", "'remove'", ")", ")", ")", "{", "$", "collectionProperties", "=", "$", "this", "->", "_collectionsItemNames", "[", "'byItemName'", "]", "[", "$", "property", "]", ";", "$", "property", "=", "$", "collectionProperties", "[", "'property'", "]", ";", "}", "// check that the method is accepted by the targeted property", "if", "(", "empty", "(", "$", "this", "->", "_accessProperties", "[", "$", "property", "]", ")", "||", "!", "in_array", "(", "$", "method", ",", "$", "this", "->", "_accessProperties", "[", "$", "property", "]", ")", ")", "{", "throw", "new", "\\", "BadMethodCallException", "(", "\"Method $name does not exist.\"", ")", ";", "}", "return", "array", "(", "'method'", "=>", "$", "method", ",", "'property'", "=>", "$", "property", ",", "'collectionProperties'", "=>", "$", "collectionProperties", ")", ";", "}" ]
Extract the info about the method called. @param string $name @return array
[ "Extract", "the", "info", "about", "the", "method", "called", "." ]
d12ce93d72f74c099dfd2109371fcd6ddfffdca4
https://github.com/antarestupin/Accessible/blob/d12ce93d72f74c099dfd2109371fcd6ddfffdca4/lib/Accessible/AutoMethodsTrait.php#L117-L147
14,248
oscarotero/fol
src/App.php
App.getPath
public function getPath(string ...$dirs): string { if (empty($dirs)) { return $this->path; } return self::canonicalize($this->path, ...$dirs); }
php
public function getPath(string ...$dirs): string { if (empty($dirs)) { return $this->path; } return self::canonicalize($this->path, ...$dirs); }
[ "public", "function", "getPath", "(", "string", "...", "$", "dirs", ")", ":", "string", "{", "if", "(", "empty", "(", "$", "dirs", ")", ")", "{", "return", "$", "this", "->", "path", ";", "}", "return", "self", "::", "canonicalize", "(", "$", "this", "->", "path", ",", "...", "$", "dirs", ")", ";", "}" ]
Returns the absolute path of the app.
[ "Returns", "the", "absolute", "path", "of", "the", "app", "." ]
898c9f657adc12fb1b46acc2adbf0199caaebe3b
https://github.com/oscarotero/fol/blob/898c9f657adc12fb1b46acc2adbf0199caaebe3b/src/App.php#L111-L118
14,249
sifophp/sifo-common-instance
models/OAuth/twitter.php
OAuthTwitterModel.getAuth
public function getAuth( $oauth_token ) { try { $this->setToken( $oauth_token ); $token = $this->getAccessToken(); $this->setToken( $token->oauth_token, $token->oauth_token_secret ); return array( 'oauth_token' => $token->oauth_token, 'oauth_token_secret' => $token->oauth_token_secret, 'user_id' => $token->user_id, 'screen_name' => $token->screen_name ); } catch( Exception $e ) { throw new \Sifo\Exception_500( $e->getMessage() ); } }
php
public function getAuth( $oauth_token ) { try { $this->setToken( $oauth_token ); $token = $this->getAccessToken(); $this->setToken( $token->oauth_token, $token->oauth_token_secret ); return array( 'oauth_token' => $token->oauth_token, 'oauth_token_secret' => $token->oauth_token_secret, 'user_id' => $token->user_id, 'screen_name' => $token->screen_name ); } catch( Exception $e ) { throw new \Sifo\Exception_500( $e->getMessage() ); } }
[ "public", "function", "getAuth", "(", "$", "oauth_token", ")", "{", "try", "{", "$", "this", "->", "setToken", "(", "$", "oauth_token", ")", ";", "$", "token", "=", "$", "this", "->", "getAccessToken", "(", ")", ";", "$", "this", "->", "setToken", "(", "$", "token", "->", "oauth_token", ",", "$", "token", "->", "oauth_token_secret", ")", ";", "return", "array", "(", "'oauth_token'", "=>", "$", "token", "->", "oauth_token", ",", "'oauth_token_secret'", "=>", "$", "token", "->", "oauth_token_secret", ",", "'user_id'", "=>", "$", "token", "->", "user_id", ",", "'screen_name'", "=>", "$", "token", "->", "screen_name", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "throw", "new", "\\", "Sifo", "\\", "Exception_500", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "}" ]
Returns the authentication token and secret. @param string $oauth_token Authorization request given by Twitter via GET when calling the callback Url. @return array
[ "Returns", "the", "authentication", "token", "and", "secret", "." ]
52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5
https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/models/OAuth/twitter.php#L70-L91
14,250
todstoychev/icr
src/Processor.php
Processor.upload
public function upload($context, $file, $extension, FilesystemAdapter $filesystemAdapter, $fileName) { // Upload original image $fileName = $this->fileManager->setFileSystemAdapter($filesystemAdapter) ->uploadFile($file, $extension, $context, null, $fileName); $this->processSizes($file, $fileName, $context, $extension, $filesystemAdapter); return $fileName; }
php
public function upload($context, $file, $extension, FilesystemAdapter $filesystemAdapter, $fileName) { // Upload original image $fileName = $this->fileManager->setFileSystemAdapter($filesystemAdapter) ->uploadFile($file, $extension, $context, null, $fileName); $this->processSizes($file, $fileName, $context, $extension, $filesystemAdapter); return $fileName; }
[ "public", "function", "upload", "(", "$", "context", ",", "$", "file", ",", "$", "extension", ",", "FilesystemAdapter", "$", "filesystemAdapter", ",", "$", "fileName", ")", "{", "// Upload original image", "$", "fileName", "=", "$", "this", "->", "fileManager", "->", "setFileSystemAdapter", "(", "$", "filesystemAdapter", ")", "->", "uploadFile", "(", "$", "file", ",", "$", "extension", ",", "$", "context", ",", "null", ",", "$", "fileName", ")", ";", "$", "this", "->", "processSizes", "(", "$", "file", ",", "$", "fileName", ",", "$", "context", ",", "$", "extension", ",", "$", "filesystemAdapter", ")", ";", "return", "$", "fileName", ";", "}" ]
Handles image upload @param string $context @param string $file @param string $extension @param FilesystemAdapter $filesystemAdapter @param string $fileName @return string @throws \Exception
[ "Handles", "image", "upload" ]
0214c7bc76e44488e98758d55deb707b72e24000
https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Processor.php#L71-L79
14,251
todstoychev/icr
src/Processor.php
Processor.rebuild
public function rebuild($fileName, $context, FilesystemAdapter $filesystemAdapter) { // Open original file $originalImage = $filesystemAdapter->get('/' . $context . '/' . $fileName); $originalImage = $this->openImageHandler->loadImage($originalImage); $extension = $this->findExtension($fileName); // Rebuild sizes $this->deleteSizes($fileName, $context, $filesystemAdapter); $this->fileManager->setFileSystemAdapter($filesystemAdapter); $this->processSizes($originalImage, $fileName, $context, $extension, $filesystemAdapter); return true; }
php
public function rebuild($fileName, $context, FilesystemAdapter $filesystemAdapter) { // Open original file $originalImage = $filesystemAdapter->get('/' . $context . '/' . $fileName); $originalImage = $this->openImageHandler->loadImage($originalImage); $extension = $this->findExtension($fileName); // Rebuild sizes $this->deleteSizes($fileName, $context, $filesystemAdapter); $this->fileManager->setFileSystemAdapter($filesystemAdapter); $this->processSizes($originalImage, $fileName, $context, $extension, $filesystemAdapter); return true; }
[ "public", "function", "rebuild", "(", "$", "fileName", ",", "$", "context", ",", "FilesystemAdapter", "$", "filesystemAdapter", ")", "{", "// Open original file", "$", "originalImage", "=", "$", "filesystemAdapter", "->", "get", "(", "'/'", ".", "$", "context", ".", "'/'", ".", "$", "fileName", ")", ";", "$", "originalImage", "=", "$", "this", "->", "openImageHandler", "->", "loadImage", "(", "$", "originalImage", ")", ";", "$", "extension", "=", "$", "this", "->", "findExtension", "(", "$", "fileName", ")", ";", "// Rebuild sizes", "$", "this", "->", "deleteSizes", "(", "$", "fileName", ",", "$", "context", ",", "$", "filesystemAdapter", ")", ";", "$", "this", "->", "fileManager", "->", "setFileSystemAdapter", "(", "$", "filesystemAdapter", ")", ";", "$", "this", "->", "processSizes", "(", "$", "originalImage", ",", "$", "fileName", ",", "$", "context", ",", "$", "extension", ",", "$", "filesystemAdapter", ")", ";", "return", "true", ";", "}" ]
Rebuilds image sizes @param string $fileName @param string $context @param FilesystemAdapter $filesystemAdapter @return bool @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
[ "Rebuilds", "image", "sizes" ]
0214c7bc76e44488e98758d55deb707b72e24000
https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Processor.php#L111-L124
14,252
todstoychev/icr
src/Processor.php
Processor.rename
public function rename($oldFileName, $newFileName, $context, FilesystemAdapter $filesystemAdapter) { if ($filesystemAdapter->exists($context . '/' . $newFileName)) { throw new IcrRuntimeException("File with name {$newFileName} already exists!"); } $image = $filesystemAdapter->get($context . '/' . $oldFileName); $filesystemAdapter->move($context . '/' . $oldFileName, $context . '/' . $newFileName); foreach ($this->config[$context] as $sizeName => $value) { $oldPath = $context . '/' . $sizeName . '/' . $oldFileName; $newPath = $context . '/' . $sizeName . '/' . $newFileName; $filesystemAdapter->move($oldPath, $newPath); } return true; }
php
public function rename($oldFileName, $newFileName, $context, FilesystemAdapter $filesystemAdapter) { if ($filesystemAdapter->exists($context . '/' . $newFileName)) { throw new IcrRuntimeException("File with name {$newFileName} already exists!"); } $image = $filesystemAdapter->get($context . '/' . $oldFileName); $filesystemAdapter->move($context . '/' . $oldFileName, $context . '/' . $newFileName); foreach ($this->config[$context] as $sizeName => $value) { $oldPath = $context . '/' . $sizeName . '/' . $oldFileName; $newPath = $context . '/' . $sizeName . '/' . $newFileName; $filesystemAdapter->move($oldPath, $newPath); } return true; }
[ "public", "function", "rename", "(", "$", "oldFileName", ",", "$", "newFileName", ",", "$", "context", ",", "FilesystemAdapter", "$", "filesystemAdapter", ")", "{", "if", "(", "$", "filesystemAdapter", "->", "exists", "(", "$", "context", ".", "'/'", ".", "$", "newFileName", ")", ")", "{", "throw", "new", "IcrRuntimeException", "(", "\"File with name {$newFileName} already exists!\"", ")", ";", "}", "$", "image", "=", "$", "filesystemAdapter", "->", "get", "(", "$", "context", ".", "'/'", ".", "$", "oldFileName", ")", ";", "$", "filesystemAdapter", "->", "move", "(", "$", "context", ".", "'/'", ".", "$", "oldFileName", ",", "$", "context", ".", "'/'", ".", "$", "newFileName", ")", ";", "foreach", "(", "$", "this", "->", "config", "[", "$", "context", "]", "as", "$", "sizeName", "=>", "$", "value", ")", "{", "$", "oldPath", "=", "$", "context", ".", "'/'", ".", "$", "sizeName", ".", "'/'", ".", "$", "oldFileName", ";", "$", "newPath", "=", "$", "context", ".", "'/'", ".", "$", "sizeName", ".", "'/'", ".", "$", "newFileName", ";", "$", "filesystemAdapter", "->", "move", "(", "$", "oldPath", ",", "$", "newPath", ")", ";", "}", "return", "true", ";", "}" ]
Renames existing file @param string $oldFileName @param string $newFileName @param string $context @param FilesystemAdapter $filesystemAdapter @return boolean
[ "Renames", "existing", "file" ]
0214c7bc76e44488e98758d55deb707b72e24000
https://github.com/todstoychev/icr/blob/0214c7bc76e44488e98758d55deb707b72e24000/src/Processor.php#L198-L214
14,253
liip/LiipDrupalConnectorModule
src/Liip/Drupal/Modules/DrupalConnector/Node.php
Node.node_load
public function node_load($nid = null, $vid = null, $reset = false) { return node_load($nid, $vid, $reset); }
php
public function node_load($nid = null, $vid = null, $reset = false) { return node_load($nid, $vid, $reset); }
[ "public", "function", "node_load", "(", "$", "nid", "=", "null", ",", "$", "vid", "=", "null", ",", "$", "reset", "=", "false", ")", "{", "return", "node_load", "(", "$", "nid", ",", "$", "vid", ",", "$", "reset", ")", ";", "}" ]
Load a node object from the database. @param integer $nid The node ID. @param integer $vid The revision ID. @param boolean $reset Whether to reset the node_load_multiple cache. @return \stdClass|false A fully-populated node object, or FALSE if the node is not found. @link http://api.drupal.org/api/drupal/modules!node!node.module/function/node_load/7
[ "Load", "a", "node", "object", "from", "the", "database", "." ]
6ba161ef0d3a27c108e533f1adbea22ed73b78ce
https://github.com/liip/LiipDrupalConnectorModule/blob/6ba161ef0d3a27c108e533f1adbea22ed73b78ce/src/Liip/Drupal/Modules/DrupalConnector/Node.php#L84-L87
14,254
liip/LiipDrupalConnectorModule
src/Liip/Drupal/Modules/DrupalConnector/Node.php
Node.node_save
public function node_save(&$node) { try { node_save($node); } catch (\Exception $e) { throw new NodeException( sprintf(NodeException::FailedToSaveNodeText, $node->nid), NodeException::FailedToSaveNode, $e->getCode(), $e ); } }
php
public function node_save(&$node) { try { node_save($node); } catch (\Exception $e) { throw new NodeException( sprintf(NodeException::FailedToSaveNodeText, $node->nid), NodeException::FailedToSaveNode, $e->getCode(), $e ); } }
[ "public", "function", "node_save", "(", "&", "$", "node", ")", "{", "try", "{", "node_save", "(", "$", "node", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "NodeException", "(", "sprintf", "(", "NodeException", "::", "FailedToSaveNodeText", ",", "$", "node", "->", "nid", ")", ",", "NodeException", "::", "FailedToSaveNode", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Save changes to a node or add a new node. @param \stdClass &$node The $node object to be saved. If $node->nid is omitted (or $node->is_new is TRUE), a new node will be added. @throws \Liip\Drupal\Modules\DrupalConnector\NodeException in case the node could not be persisted. @link http://api.drupal.org/api/drupal/modules!node!node.module/function/node_save/7
[ "Save", "changes", "to", "a", "node", "or", "add", "a", "new", "node", "." ]
6ba161ef0d3a27c108e533f1adbea22ed73b78ce
https://github.com/liip/LiipDrupalConnectorModule/blob/6ba161ef0d3a27c108e533f1adbea22ed73b78ce/src/Liip/Drupal/Modules/DrupalConnector/Node.php#L113-L125
14,255
incraigulous/contentful-sdk
src/PayloadBuilders/ContentTypeValidation.php
ContentTypeValidation.size
function size($min = null, $max = null) { $size = []; if ($min) $size['min'] = $min; if ($max) $size['max'] = $max; if (count($size)) $this->data['size'] = $size; return $this; }
php
function size($min = null, $max = null) { $size = []; if ($min) $size['min'] = $min; if ($max) $size['max'] = $max; if (count($size)) $this->data['size'] = $size; return $this; }
[ "function", "size", "(", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "size", "=", "[", "]", ";", "if", "(", "$", "min", ")", "$", "size", "[", "'min'", "]", "=", "$", "min", ";", "if", "(", "$", "max", ")", "$", "size", "[", "'max'", "]", "=", "$", "max", ";", "if", "(", "count", "(", "$", "size", ")", ")", "$", "this", "->", "data", "[", "'size'", "]", "=", "$", "size", ";", "return", "$", "this", ";", "}" ]
Validates that the size of a text, object or array is within a range. @param null $min @param null $max @return $this
[ "Validates", "that", "the", "size", "of", "a", "text", "object", "or", "array", "is", "within", "a", "range", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/PayloadBuilders/ContentTypeValidation.php#L13-L19
14,256
incraigulous/contentful-sdk
src/PayloadBuilders/ContentTypeValidation.php
ContentTypeValidation.regexp
function regexp($pattern, $flags = null) { $regexp['pattern'] = $pattern; if ($flags) $regexp['flags'] = $flags; $this->data['regexp'] = $regexp; return $this; }
php
function regexp($pattern, $flags = null) { $regexp['pattern'] = $pattern; if ($flags) $regexp['flags'] = $flags; $this->data['regexp'] = $regexp; return $this; }
[ "function", "regexp", "(", "$", "pattern", ",", "$", "flags", "=", "null", ")", "{", "$", "regexp", "[", "'pattern'", "]", "=", "$", "pattern", ";", "if", "(", "$", "flags", ")", "$", "regexp", "[", "'flags'", "]", "=", "$", "flags", ";", "$", "this", "->", "data", "[", "'regexp'", "]", "=", "$", "regexp", ";", "return", "$", "this", ";", "}" ]
Validates that the value of a field matches a Regular Expression. @param $pattern @param null $flags @return $this
[ "Validates", "that", "the", "value", "of", "a", "field", "matches", "a", "Regular", "Expression", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/PayloadBuilders/ContentTypeValidation.php#L37-L42
14,257
incraigulous/contentful-sdk
src/PayloadBuilders/ContentTypeValidation.php
ContentTypeValidation.dateRange
function dateRange($min = null, $max = null) { $range = []; if ($min) $range['min'] = $min; if ($max) $range['max'] = $max; if (count($range)) $this->data['dateRange'] = $range; return $this; }
php
function dateRange($min = null, $max = null) { $range = []; if ($min) $range['min'] = $min; if ($max) $range['max'] = $max; if (count($range)) $this->data['dateRange'] = $range; return $this; }
[ "function", "dateRange", "(", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "range", "=", "[", "]", ";", "if", "(", "$", "min", ")", "$", "range", "[", "'min'", "]", "=", "$", "min", ";", "if", "(", "$", "max", ")", "$", "range", "[", "'max'", "]", "=", "$", "max", ";", "if", "(", "count", "(", "$", "range", ")", ")", "$", "this", "->", "data", "[", "'dateRange'", "]", "=", "$", "range", ";", "return", "$", "this", ";", "}" ]
Validates that the value of a field is within a date range. It's defined specifying the min and max values of that range. @param null $min @param null $max @return $this
[ "Validates", "that", "the", "value", "of", "a", "field", "is", "within", "a", "date", "range", ".", "It", "s", "defined", "specifying", "the", "min", "and", "max", "values", "of", "that", "range", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/PayloadBuilders/ContentTypeValidation.php#L50-L56
14,258
incraigulous/contentful-sdk
src/PayloadBuilders/ContentTypeValidation.php
ContentTypeValidation.assetFileSize
function assetFileSize($min = null, $max = null) { $range = []; if ($min) $range['min'] = $min; if ($max) $range['max'] = $max; if (count($range)) $this->data['assetFileSize'] = $range; return $this; }
php
function assetFileSize($min = null, $max = null) { $range = []; if ($min) $range['min'] = $min; if ($max) $range['max'] = $max; if (count($range)) $this->data['assetFileSize'] = $range; return $this; }
[ "function", "assetFileSize", "(", "$", "min", "=", "null", ",", "$", "max", "=", "null", ")", "{", "$", "range", "=", "[", "]", ";", "if", "(", "$", "min", ")", "$", "range", "[", "'min'", "]", "=", "$", "min", ";", "if", "(", "$", "max", ")", "$", "range", "[", "'max'", "]", "=", "$", "max", ";", "if", "(", "count", "(", "$", "range", ")", ")", "$", "this", "->", "data", "[", "'assetFileSize'", "]", "=", "$", "range", ";", "return", "$", "this", ";", "}" ]
Validates that the size of an asset is within a range. It's defined specifying the min and max values of that range. min and max are inclusive. @param null $min @param null $max @return $this
[ "Validates", "that", "the", "size", "of", "an", "asset", "is", "within", "a", "range", ".", "It", "s", "defined", "specifying", "the", "min", "and", "max", "values", "of", "that", "range", ".", "min", "and", "max", "are", "inclusive", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/PayloadBuilders/ContentTypeValidation.php#L64-L70
14,259
incraigulous/contentful-sdk
src/PayloadBuilders/ContentTypeValidation.php
ContentTypeValidation.assetImageDimensions
function assetImageDimensions($height = null, $width = null) { $imageDimensions = []; if ($height) $imageDimensions['height'] = $height; if ($width) $imageDimensions['width'] = $width; if (count($imageDimensions)) $this->data['assetImageDimensions'] = $imageDimensions; return $this; }
php
function assetImageDimensions($height = null, $width = null) { $imageDimensions = []; if ($height) $imageDimensions['height'] = $height; if ($width) $imageDimensions['width'] = $width; if (count($imageDimensions)) $this->data['assetImageDimensions'] = $imageDimensions; return $this; }
[ "function", "assetImageDimensions", "(", "$", "height", "=", "null", ",", "$", "width", "=", "null", ")", "{", "$", "imageDimensions", "=", "[", "]", ";", "if", "(", "$", "height", ")", "$", "imageDimensions", "[", "'height'", "]", "=", "$", "height", ";", "if", "(", "$", "width", ")", "$", "imageDimensions", "[", "'width'", "]", "=", "$", "width", ";", "if", "(", "count", "(", "$", "imageDimensions", ")", ")", "$", "this", "->", "data", "[", "'assetImageDimensions'", "]", "=", "$", "imageDimensions", ";", "return", "$", "this", ";", "}" ]
Validates that the dimensions of an image are within a range. @param null $height @param null $width @return $this
[ "Validates", "that", "the", "dimensions", "of", "an", "image", "are", "within", "a", "range", "." ]
29399b11b0e085a06ea5976661378c379fe5a731
https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/PayloadBuilders/ContentTypeValidation.php#L78-L84
14,260
iP1SMS/ip1-php-sdk
src/Recipient/Membership.php
Membership.getGroup
public function getGroup(Communicator $communicator): ProcessedGroup { $groupJSON = $communicator->get('api/groups/'.$this->groupID); $group = RecipientFactory::createProcessedGroupFromJSON($groupJSON); return $group; }
php
public function getGroup(Communicator $communicator): ProcessedGroup { $groupJSON = $communicator->get('api/groups/'.$this->groupID); $group = RecipientFactory::createProcessedGroupFromJSON($groupJSON); return $group; }
[ "public", "function", "getGroup", "(", "Communicator", "$", "communicator", ")", ":", "ProcessedGroup", "{", "$", "groupJSON", "=", "$", "communicator", "->", "get", "(", "'api/groups/'", ".", "$", "this", "->", "groupID", ")", ";", "$", "group", "=", "RecipientFactory", "::", "createProcessedGroupFromJSON", "(", "$", "groupJSON", ")", ";", "return", "$", "group", ";", "}" ]
Returns the Group this membership is referenced to. @param Communicator $communicator Used to fetch the Group from the API. @return ProcessedGroup
[ "Returns", "the", "Group", "this", "membership", "is", "referenced", "to", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Recipient/Membership.php#L66-L71
14,261
iP1SMS/ip1-php-sdk
src/Recipient/Membership.php
Membership.getContact
public function getContact(Communicator $communicator): ProcessedContact { $contactJSON = $communicator->get('api/groups/'.$this->contactID); $contact = RecipientFactory::createProcessedGroupFromJSON($contactJSON); return $contact; }
php
public function getContact(Communicator $communicator): ProcessedContact { $contactJSON = $communicator->get('api/groups/'.$this->contactID); $contact = RecipientFactory::createProcessedGroupFromJSON($contactJSON); return $contact; }
[ "public", "function", "getContact", "(", "Communicator", "$", "communicator", ")", ":", "ProcessedContact", "{", "$", "contactJSON", "=", "$", "communicator", "->", "get", "(", "'api/groups/'", ".", "$", "this", "->", "contactID", ")", ";", "$", "contact", "=", "RecipientFactory", "::", "createProcessedGroupFromJSON", "(", "$", "contactJSON", ")", ";", "return", "$", "contact", ";", "}" ]
Returns the Contact this membership is referenced to. @param Communicator $communicator Used to fetch the Contact from the API. @return ProcessedContact
[ "Returns", "the", "Contact", "this", "membership", "is", "referenced", "to", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Recipient/Membership.php#L77-L82
14,262
iP1SMS/ip1-php-sdk
src/Recipient/ProcessedContact.php
ProcessedContact.getGroups
public function getGroups(Communicator $communicator = null): ClassValidationArray { if ($communicator !== null) { $groupsJSON = $communicator->get('api/contacts/'.$this->contactID. '/groups'); $groupStd = json_decode($groupsJSON); $groups = RecipientFactory::createProcessedGroupsFromStdClassArray($groupStd); $this->groups = $groups; $this->fetchedGroups = true; } return $this->groups; }
php
public function getGroups(Communicator $communicator = null): ClassValidationArray { if ($communicator !== null) { $groupsJSON = $communicator->get('api/contacts/'.$this->contactID. '/groups'); $groupStd = json_decode($groupsJSON); $groups = RecipientFactory::createProcessedGroupsFromStdClassArray($groupStd); $this->groups = $groups; $this->fetchedGroups = true; } return $this->groups; }
[ "public", "function", "getGroups", "(", "Communicator", "$", "communicator", "=", "null", ")", ":", "ClassValidationArray", "{", "if", "(", "$", "communicator", "!==", "null", ")", "{", "$", "groupsJSON", "=", "$", "communicator", "->", "get", "(", "'api/contacts/'", ".", "$", "this", "->", "contactID", ".", "'/groups'", ")", ";", "$", "groupStd", "=", "json_decode", "(", "$", "groupsJSON", ")", ";", "$", "groups", "=", "RecipientFactory", "::", "createProcessedGroupsFromStdClassArray", "(", "$", "groupStd", ")", ";", "$", "this", "->", "groups", "=", "$", "groups", ";", "$", "this", "->", "fetchedGroups", "=", "true", ";", "}", "return", "$", "this", "->", "groups", ";", "}" ]
Returns an array of all the Groups the group is referenced in. If a communicator is not provided it will not fetch memberships from the API but return those that has been fetched, if any. @param Communicator $communicator Used to fetch Groups from the API. @return ClassValidationArray An array of Group objects.
[ "Returns", "an", "array", "of", "all", "the", "Groups", "the", "group", "is", "referenced", "in", ".", "If", "a", "communicator", "is", "not", "provided", "it", "will", "not", "fetch", "memberships", "from", "the", "API", "but", "return", "those", "that", "has", "been", "fetched", "if", "any", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Recipient/ProcessedContact.php#L144-L154
14,263
iP1SMS/ip1-php-sdk
src/Recipient/ProcessedContact.php
ProcessedContact.addGroup
public function addGroup(Communicator $communicator, ProcessedGroup $group): ProcessedMembership { $response = $communicator->post('api/memberships', new Membership($group->getID(), $this->contactID)); $returnValue = RecipientFactory::createProcessedMembershipFromJSON($response); if ($this->memberShipsFetched) { $this->memberships[] = $returnValue; } return $returnValue; }
php
public function addGroup(Communicator $communicator, ProcessedGroup $group): ProcessedMembership { $response = $communicator->post('api/memberships', new Membership($group->getID(), $this->contactID)); $returnValue = RecipientFactory::createProcessedMembershipFromJSON($response); if ($this->memberShipsFetched) { $this->memberships[] = $returnValue; } return $returnValue; }
[ "public", "function", "addGroup", "(", "Communicator", "$", "communicator", ",", "ProcessedGroup", "$", "group", ")", ":", "ProcessedMembership", "{", "$", "response", "=", "$", "communicator", "->", "post", "(", "'api/memberships'", ",", "new", "Membership", "(", "$", "group", "->", "getID", "(", ")", ",", "$", "this", "->", "contactID", ")", ")", ";", "$", "returnValue", "=", "RecipientFactory", "::", "createProcessedMembershipFromJSON", "(", "$", "response", ")", ";", "if", "(", "$", "this", "->", "memberShipsFetched", ")", "{", "$", "this", "->", "memberships", "[", "]", "=", "$", "returnValue", ";", "}", "return", "$", "returnValue", ";", "}" ]
Adds the contact to the given group and returns the membership. @param Communicator $communicator Used to fetch Groups from the API. @param ProcessedGroup $group The group the contact should be added to. @return ProcessedMembership
[ "Adds", "the", "contact", "to", "the", "given", "group", "and", "returns", "the", "membership", "." ]
348e6572a279363ba689c9e0f5689b83a25930f5
https://github.com/iP1SMS/ip1-php-sdk/blob/348e6572a279363ba689c9e0f5689b83a25930f5/src/Recipient/ProcessedContact.php#L161-L169
14,264
unimapper/unimapper
src/Convention.php
Convention.classToName
public static function classToName($class, $type) { if (!class_exists($class)) { throw new InvalidArgumentException( "Class '" . $class . "' not found!" ); } $class = self::_trimNamespace($class); if (!isset(self::$masks[$type])) { throw new InvalidArgumentException( "Invalid mask type " . $type . "!" ); } $mask = self::_trimNamespace(self::$masks[$type]); if ($mask === "*") { return $class; } preg_match("/" . str_replace("*", "(.*)", $mask) . "/", $class, $match); return $match[1]; }
php
public static function classToName($class, $type) { if (!class_exists($class)) { throw new InvalidArgumentException( "Class '" . $class . "' not found!" ); } $class = self::_trimNamespace($class); if (!isset(self::$masks[$type])) { throw new InvalidArgumentException( "Invalid mask type " . $type . "!" ); } $mask = self::_trimNamespace(self::$masks[$type]); if ($mask === "*") { return $class; } preg_match("/" . str_replace("*", "(.*)", $mask) . "/", $class, $match); return $match[1]; }
[ "public", "static", "function", "classToName", "(", "$", "class", ",", "$", "type", ")", "{", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Class '\"", ".", "$", "class", ".", "\"' not found!\"", ")", ";", "}", "$", "class", "=", "self", "::", "_trimNamespace", "(", "$", "class", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "masks", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Invalid mask type \"", ".", "$", "type", ".", "\"!\"", ")", ";", "}", "$", "mask", "=", "self", "::", "_trimNamespace", "(", "self", "::", "$", "masks", "[", "$", "type", "]", ")", ";", "if", "(", "$", "mask", "===", "\"*\"", ")", "{", "return", "$", "class", ";", "}", "preg_match", "(", "\"/\"", ".", "str_replace", "(", "\"*\"", ",", "\"(.*)\"", ",", "$", "mask", ")", ".", "\"/\"", ",", "$", "class", ",", "$", "match", ")", ";", "return", "$", "match", "[", "1", "]", ";", "}" ]
Converts class to name @param string $class @param integer $type Mask type @return string @throws InvalidArgumentException
[ "Converts", "class", "to", "name" ]
a63b39f38a790fec7e852c8ef1e4c31653e689f7
https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Convention.php#L67-L90
14,265
unimapper/unimapper
src/Convention.php
Convention.nameToClass
public static function nameToClass($name, $type) { if (!isset(self::$masks[$type])) { throw new InvalidArgumentException( "Invalid mask type " . $type . "!" ); } return str_replace("*", $name, self::$masks[$type]); }
php
public static function nameToClass($name, $type) { if (!isset(self::$masks[$type])) { throw new InvalidArgumentException( "Invalid mask type " . $type . "!" ); } return str_replace("*", $name, self::$masks[$type]); }
[ "public", "static", "function", "nameToClass", "(", "$", "name", ",", "$", "type", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "masks", "[", "$", "type", "]", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Invalid mask type \"", ".", "$", "type", ".", "\"!\"", ")", ";", "}", "return", "str_replace", "(", "\"*\"", ",", "$", "name", ",", "self", "::", "$", "masks", "[", "$", "type", "]", ")", ";", "}" ]
Converts name to class @param string $name @param integer $type @return string @throws InvalidArgumentException
[ "Converts", "name", "to", "class" ]
a63b39f38a790fec7e852c8ef1e4c31653e689f7
https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Convention.php#L102-L110
14,266
LIN3S/WPFoundation
src/LIN3S/WPFoundation/Configuration/Assets/Assets.php
Assets.addScript
protected function addScript( $name, $from = AssetsInterface::ASSETS_JS, array $dependencies = ['jquery'], $version = '1.0.0', $inFooter = true, $ajaxUrl = null ) { wp_enqueue_script($name, $this->path($from, $name), $dependencies, $version, $inFooter); if (null !== $ajaxUrl) { $this->registerAjaxUrls($name, $ajaxUrl); } return $this; }
php
protected function addScript( $name, $from = AssetsInterface::ASSETS_JS, array $dependencies = ['jquery'], $version = '1.0.0', $inFooter = true, $ajaxUrl = null ) { wp_enqueue_script($name, $this->path($from, $name), $dependencies, $version, $inFooter); if (null !== $ajaxUrl) { $this->registerAjaxUrls($name, $ajaxUrl); } return $this; }
[ "protected", "function", "addScript", "(", "$", "name", ",", "$", "from", "=", "AssetsInterface", "::", "ASSETS_JS", ",", "array", "$", "dependencies", "=", "[", "'jquery'", "]", ",", "$", "version", "=", "'1.0.0'", ",", "$", "inFooter", "=", "true", ",", "$", "ajaxUrl", "=", "null", ")", "{", "wp_enqueue_script", "(", "$", "name", ",", "$", "this", "->", "path", "(", "$", "from", ",", "$", "name", ")", ",", "$", "dependencies", ",", "$", "version", ",", "$", "inFooter", ")", ";", "if", "(", "null", "!==", "$", "ajaxUrl", ")", "{", "$", "this", "->", "registerAjaxUrls", "(", "$", "name", ",", "$", "ajaxUrl", ")", ";", "}", "return", "$", "this", ";", "}" ]
Method that wraps the WordPress internal "wp_enqueue_script" simplifying the process adding some common default values. @param string $name The name of asset @param string $from The from location, by default is the JS files default location @param array $dependencies Array which contains the dependencies of the given asset @param string $version The version, by default is "1.0.0" @param bool $inFooter Checks if the asset is going to be in the footer or not @param array|string|null $ajaxUrl The ajax url to expose in JS files @return $this Self class instance
[ "Method", "that", "wraps", "the", "WordPress", "internal", "wp_enqueue_script", "simplifying", "the", "process", "adding", "some", "common", "default", "values", "." ]
4f5674b0544b770809f1ffa7bd7d8fdfe013e4bf
https://github.com/LIN3S/WPFoundation/blob/4f5674b0544b770809f1ffa7bd7d8fdfe013e4bf/src/LIN3S/WPFoundation/Configuration/Assets/Assets.php#L73-L88
14,267
LIN3S/WPFoundation
src/LIN3S/WPFoundation/Configuration/Assets/Assets.php
Assets.addStylesheet
protected function addStylesheet( $name, $from = AssetsInterface::CSS, array $dependencies = [], $version = '1.0.0', $media = 'all' ) { wp_enqueue_style($name, $this->path($from, $name, 'css'), $dependencies, $version, $media); return $this; }
php
protected function addStylesheet( $name, $from = AssetsInterface::CSS, array $dependencies = [], $version = '1.0.0', $media = 'all' ) { wp_enqueue_style($name, $this->path($from, $name, 'css'), $dependencies, $version, $media); return $this; }
[ "protected", "function", "addStylesheet", "(", "$", "name", ",", "$", "from", "=", "AssetsInterface", "::", "CSS", ",", "array", "$", "dependencies", "=", "[", "]", ",", "$", "version", "=", "'1.0.0'", ",", "$", "media", "=", "'all'", ")", "{", "wp_enqueue_style", "(", "$", "name", ",", "$", "this", "->", "path", "(", "$", "from", ",", "$", "name", ",", "'css'", ")", ",", "$", "dependencies", ",", "$", "version", ",", "$", "media", ")", ";", "return", "$", "this", ";", "}" ]
Method that wraps the WordPress internal "wp_enqueue_style" simplifying the process adding some common default values. @param string $name The name of asset @param string $from The from location, by default is the CSS files default location @param array $dependencies Array which contains the dependencies of the given asset, by default is empty @param string $version The version, by default is "1.0.0" @param string $media The media, by default is "all" @return $this Self class instance
[ "Method", "that", "wraps", "the", "WordPress", "internal", "wp_enqueue_style", "simplifying", "the", "process", "adding", "some", "common", "default", "values", "." ]
4f5674b0544b770809f1ffa7bd7d8fdfe013e4bf
https://github.com/LIN3S/WPFoundation/blob/4f5674b0544b770809f1ffa7bd7d8fdfe013e4bf/src/LIN3S/WPFoundation/Configuration/Assets/Assets.php#L102-L112
14,268
LIN3S/WPFoundation
src/LIN3S/WPFoundation/Configuration/Assets/Assets.php
Assets.registerAjaxUrls
protected function registerAjaxUrls($name, $ajaxUrl) { if (false === is_array($ajaxUrl)) { $ajaxUrl = [$ajaxUrl]; } foreach ($ajaxUrl as $url) { wp_localize_script($name, $url, [ 'ajaxUrl' => admin_url('admin-ajax.php'), ]); } }
php
protected function registerAjaxUrls($name, $ajaxUrl) { if (false === is_array($ajaxUrl)) { $ajaxUrl = [$ajaxUrl]; } foreach ($ajaxUrl as $url) { wp_localize_script($name, $url, [ 'ajaxUrl' => admin_url('admin-ajax.php'), ]); } }
[ "protected", "function", "registerAjaxUrls", "(", "$", "name", ",", "$", "ajaxUrl", ")", "{", "if", "(", "false", "===", "is_array", "(", "$", "ajaxUrl", ")", ")", "{", "$", "ajaxUrl", "=", "[", "$", "ajaxUrl", "]", ";", "}", "foreach", "(", "$", "ajaxUrl", "as", "$", "url", ")", "{", "wp_localize_script", "(", "$", "name", ",", "$", "url", ",", "[", "'ajaxUrl'", "=>", "admin_url", "(", "'admin-ajax.php'", ")", ",", "]", ")", ";", "}", "}" ]
Registers the ajax urls inside given JS filename. @param string $name The script file name @param string $ajaxUrl The name that is going to expose in JS file as ajaxUrl Usage example with name="subscribe" and ajaxUrl="subscribeAjax": // subscribe.js $.ajax({ url: subscribeAjax.ajaxUrl, method: 'GET', data: { action: 'ajax-action-registered-in-your-php-file', } }).done(function (response) { (...) });
[ "Registers", "the", "ajax", "urls", "inside", "given", "JS", "filename", "." ]
4f5674b0544b770809f1ffa7bd7d8fdfe013e4bf
https://github.com/LIN3S/WPFoundation/blob/4f5674b0544b770809f1ffa7bd7d8fdfe013e4bf/src/LIN3S/WPFoundation/Configuration/Assets/Assets.php#L134-L144
14,269
cauditor/php-analyzer
src/Analyzers/PDepend/Analyzer.php
Analyzer.pdepend
protected function pdepend($path) { $jsonGenerator = new JsonGenerator(); $jsonGenerator->setLogFile($path.DIRECTORY_SEPARATOR.$this->json); $application = new Application(); // overwrite default config to ensure that cache files are stored in // different folders per build $config = $application->getConfiguration(); $config->cache->driver = 'file'; $config->cache->location = $path.DIRECTORY_SEPARATOR.$this->pdepend; $engine = $application->getEngine(); $engine->addReportGenerator($jsonGenerator); $engine->addDirectory($this->config['path']); // exclude directories are evaluated relative to where pdepend is being // run from, not what it is running on $converter = new PathConverter($this->config['path'], getcwd()); $exclude = array_map(array($converter, 'convert'), $this->config['exclude_folders']); $filter = new ExcludePathFilter($exclude); $engine->addFileFilter($filter); try { $engine->analyze(); } catch (\Exception $e) { throw new Exception('Unable to generate pdepend metrics.'); } }
php
protected function pdepend($path) { $jsonGenerator = new JsonGenerator(); $jsonGenerator->setLogFile($path.DIRECTORY_SEPARATOR.$this->json); $application = new Application(); // overwrite default config to ensure that cache files are stored in // different folders per build $config = $application->getConfiguration(); $config->cache->driver = 'file'; $config->cache->location = $path.DIRECTORY_SEPARATOR.$this->pdepend; $engine = $application->getEngine(); $engine->addReportGenerator($jsonGenerator); $engine->addDirectory($this->config['path']); // exclude directories are evaluated relative to where pdepend is being // run from, not what it is running on $converter = new PathConverter($this->config['path'], getcwd()); $exclude = array_map(array($converter, 'convert'), $this->config['exclude_folders']); $filter = new ExcludePathFilter($exclude); $engine->addFileFilter($filter); try { $engine->analyze(); } catch (\Exception $e) { throw new Exception('Unable to generate pdepend metrics.'); } }
[ "protected", "function", "pdepend", "(", "$", "path", ")", "{", "$", "jsonGenerator", "=", "new", "JsonGenerator", "(", ")", ";", "$", "jsonGenerator", "->", "setLogFile", "(", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "json", ")", ";", "$", "application", "=", "new", "Application", "(", ")", ";", "// overwrite default config to ensure that cache files are stored in", "// different folders per build", "$", "config", "=", "$", "application", "->", "getConfiguration", "(", ")", ";", "$", "config", "->", "cache", "->", "driver", "=", "'file'", ";", "$", "config", "->", "cache", "->", "location", "=", "$", "path", ".", "DIRECTORY_SEPARATOR", ".", "$", "this", "->", "pdepend", ";", "$", "engine", "=", "$", "application", "->", "getEngine", "(", ")", ";", "$", "engine", "->", "addReportGenerator", "(", "$", "jsonGenerator", ")", ";", "$", "engine", "->", "addDirectory", "(", "$", "this", "->", "config", "[", "'path'", "]", ")", ";", "// exclude directories are evaluated relative to where pdepend is being", "// run from, not what it is running on", "$", "converter", "=", "new", "PathConverter", "(", "$", "this", "->", "config", "[", "'path'", "]", ",", "getcwd", "(", ")", ")", ";", "$", "exclude", "=", "array_map", "(", "array", "(", "$", "converter", ",", "'convert'", ")", ",", "$", "this", "->", "config", "[", "'exclude_folders'", "]", ")", ";", "$", "filter", "=", "new", "ExcludePathFilter", "(", "$", "exclude", ")", ";", "$", "engine", "->", "addFileFilter", "(", "$", "filter", ")", ";", "try", "{", "$", "engine", "->", "analyze", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "Exception", "(", "'Unable to generate pdepend metrics.'", ")", ";", "}", "}" ]
Runs pdepend to generate the metrics. @param string $path @throws Exception
[ "Runs", "pdepend", "to", "generate", "the", "metrics", "." ]
0d86686d64d01e6aaed433898841894fa3ce1101
https://github.com/cauditor/php-analyzer/blob/0d86686d64d01e6aaed433898841894fa3ce1101/src/Analyzers/PDepend/Analyzer.php#L81-L111
14,270
joomla-projects/jorobo
src/Tasks/Deploy/Package.php
Package.createComponentZip
public function createComponentZip() { $comZip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $tmp_path = '/dist/tmp/cbuild'; if (file_exists(JPATH_BASE . $tmp_path)) { $this->_deleteDir(JPATH_BASE . $tmp_path); } // Improve, should been a whitelist instead of a hardcoded copy $this->_mkdir(JPATH_BASE . $tmp_path); $this->_copyDir($this->current . '/administrator', JPATH_BASE . $tmp_path . '/administrator'); $this->_remove(JPATH_BASE . $tmp_path . '/administrator/manifests'); $this->_copyDir($this->current . '/language', JPATH_BASE . $tmp_path . '/language'); $this->_copyDir($this->current . '/components', JPATH_BASE . $tmp_path . '/components'); if (file_exists($this->current . '/media')) { $this->_copyDir($this->current . '/media', JPATH_BASE . $tmp_path . '/media'); } $comZip->open(JPATH_BASE . '/dist/zips/com_' . $this->getExtensionName() . '.zip', \ZipArchive::CREATE); // Process the files to zip $this->addFiles($comZip, JPATH_BASE . $tmp_path); $comZip->addFile($this->current . "/" . $this->getExtensionName() . ".xml", $this->getExtensionName() . ".xml"); $comZip->addFile($this->current . "/administrator/components/com_" . $this->getExtensionName() . "/script.php", "script.php"); // Close the zip archive $comZip->close(); }
php
public function createComponentZip() { $comZip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $tmp_path = '/dist/tmp/cbuild'; if (file_exists(JPATH_BASE . $tmp_path)) { $this->_deleteDir(JPATH_BASE . $tmp_path); } // Improve, should been a whitelist instead of a hardcoded copy $this->_mkdir(JPATH_BASE . $tmp_path); $this->_copyDir($this->current . '/administrator', JPATH_BASE . $tmp_path . '/administrator'); $this->_remove(JPATH_BASE . $tmp_path . '/administrator/manifests'); $this->_copyDir($this->current . '/language', JPATH_BASE . $tmp_path . '/language'); $this->_copyDir($this->current . '/components', JPATH_BASE . $tmp_path . '/components'); if (file_exists($this->current . '/media')) { $this->_copyDir($this->current . '/media', JPATH_BASE . $tmp_path . '/media'); } $comZip->open(JPATH_BASE . '/dist/zips/com_' . $this->getExtensionName() . '.zip', \ZipArchive::CREATE); // Process the files to zip $this->addFiles($comZip, JPATH_BASE . $tmp_path); $comZip->addFile($this->current . "/" . $this->getExtensionName() . ".xml", $this->getExtensionName() . ".xml"); $comZip->addFile($this->current . "/administrator/components/com_" . $this->getExtensionName() . "/script.php", "script.php"); // Close the zip archive $comZip->close(); }
[ "public", "function", "createComponentZip", "(", ")", "{", "$", "comZip", "=", "new", "\\", "ZipArchive", "(", "JPATH_BASE", ".", "\"/dist\"", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "$", "tmp_path", "=", "'/dist/tmp/cbuild'", ";", "if", "(", "file_exists", "(", "JPATH_BASE", ".", "$", "tmp_path", ")", ")", "{", "$", "this", "->", "_deleteDir", "(", "JPATH_BASE", ".", "$", "tmp_path", ")", ";", "}", "// Improve, should been a whitelist instead of a hardcoded copy", "$", "this", "->", "_mkdir", "(", "JPATH_BASE", ".", "$", "tmp_path", ")", ";", "$", "this", "->", "_copyDir", "(", "$", "this", "->", "current", ".", "'/administrator'", ",", "JPATH_BASE", ".", "$", "tmp_path", ".", "'/administrator'", ")", ";", "$", "this", "->", "_remove", "(", "JPATH_BASE", ".", "$", "tmp_path", ".", "'/administrator/manifests'", ")", ";", "$", "this", "->", "_copyDir", "(", "$", "this", "->", "current", ".", "'/language'", ",", "JPATH_BASE", ".", "$", "tmp_path", ".", "'/language'", ")", ";", "$", "this", "->", "_copyDir", "(", "$", "this", "->", "current", ".", "'/components'", ",", "JPATH_BASE", ".", "$", "tmp_path", ".", "'/components'", ")", ";", "if", "(", "file_exists", "(", "$", "this", "->", "current", ".", "'/media'", ")", ")", "{", "$", "this", "->", "_copyDir", "(", "$", "this", "->", "current", ".", "'/media'", ",", "JPATH_BASE", ".", "$", "tmp_path", ".", "'/media'", ")", ";", "}", "$", "comZip", "->", "open", "(", "JPATH_BASE", ".", "'/dist/zips/com_'", ".", "$", "this", "->", "getExtensionName", "(", ")", ".", "'.zip'", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "// Process the files to zip", "$", "this", "->", "addFiles", "(", "$", "comZip", ",", "JPATH_BASE", ".", "$", "tmp_path", ")", ";", "$", "comZip", "->", "addFile", "(", "$", "this", "->", "current", ".", "\"/\"", ".", "$", "this", "->", "getExtensionName", "(", ")", ".", "\".xml\"", ",", "$", "this", "->", "getExtensionName", "(", ")", ".", "\".xml\"", ")", ";", "$", "comZip", "->", "addFile", "(", "$", "this", "->", "current", ".", "\"/administrator/components/com_\"", ".", "$", "this", "->", "getExtensionName", "(", ")", ".", "\"/script.php\"", ",", "\"script.php\"", ")", ";", "// Close the zip archive", "$", "comZip", "->", "close", "(", ")", ";", "}" ]
Create a installable zip file for a component @TODO implement possibility for multiple components (without duplicate content) @return void @since 1.0
[ "Create", "a", "installable", "zip", "file", "for", "a", "component" ]
e72dd0ed15f387739f67cacdbc2c0bd1b427f317
https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Deploy/Package.php#L261-L295
14,271
joomla-projects/jorobo
src/Tasks/Deploy/Package.php
Package.createLibraryZips
public function createLibraryZips() { $path = $this->current . "/libraries"; // Get every module $hdl = opendir($path); while ($lib = readdir($hdl)) { // Only folders $p = $path . "/" . $lib; if (substr($lib, 0, 1) == '.') { continue; } // Workaround for libraries without lib_ if (substr($lib, 0, 3) != "lib") { $lib = 'lib_' . $lib; } if (!is_file($p)) { $this->say("Packaging Library " . $lib); // Package file $zip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $zip->open(JPATH_BASE . '/dist/zips/' . $lib . '.zip', \ZipArchive::CREATE); $this->say("Library " . $p); // Process the files to zip $this->addFiles($zip, $p); // Close the zip archive $zip->close(); } } closedir($hdl); }
php
public function createLibraryZips() { $path = $this->current . "/libraries"; // Get every module $hdl = opendir($path); while ($lib = readdir($hdl)) { // Only folders $p = $path . "/" . $lib; if (substr($lib, 0, 1) == '.') { continue; } // Workaround for libraries without lib_ if (substr($lib, 0, 3) != "lib") { $lib = 'lib_' . $lib; } if (!is_file($p)) { $this->say("Packaging Library " . $lib); // Package file $zip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $zip->open(JPATH_BASE . '/dist/zips/' . $lib . '.zip', \ZipArchive::CREATE); $this->say("Library " . $p); // Process the files to zip $this->addFiles($zip, $p); // Close the zip archive $zip->close(); } } closedir($hdl); }
[ "public", "function", "createLibraryZips", "(", ")", "{", "$", "path", "=", "$", "this", "->", "current", ".", "\"/libraries\"", ";", "// Get every module", "$", "hdl", "=", "opendir", "(", "$", "path", ")", ";", "while", "(", "$", "lib", "=", "readdir", "(", "$", "hdl", ")", ")", "{", "// Only folders", "$", "p", "=", "$", "path", ".", "\"/\"", ".", "$", "lib", ";", "if", "(", "substr", "(", "$", "lib", ",", "0", ",", "1", ")", "==", "'.'", ")", "{", "continue", ";", "}", "// Workaround for libraries without lib_", "if", "(", "substr", "(", "$", "lib", ",", "0", ",", "3", ")", "!=", "\"lib\"", ")", "{", "$", "lib", "=", "'lib_'", ".", "$", "lib", ";", "}", "if", "(", "!", "is_file", "(", "$", "p", ")", ")", "{", "$", "this", "->", "say", "(", "\"Packaging Library \"", ".", "$", "lib", ")", ";", "// Package file", "$", "zip", "=", "new", "\\", "ZipArchive", "(", "JPATH_BASE", ".", "\"/dist\"", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "$", "zip", "->", "open", "(", "JPATH_BASE", ".", "'/dist/zips/'", ".", "$", "lib", ".", "'.zip'", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "$", "this", "->", "say", "(", "\"Library \"", ".", "$", "p", ")", ";", "// Process the files to zip", "$", "this", "->", "addFiles", "(", "$", "zip", ",", "$", "p", ")", ";", "// Close the zip archive", "$", "zip", "->", "close", "(", ")", ";", "}", "}", "closedir", "(", "$", "hdl", ")", ";", "}" ]
Create zips for libraries @return void @since 1.0
[ "Create", "zips", "for", "libraries" ]
e72dd0ed15f387739f67cacdbc2c0bd1b427f317
https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Deploy/Package.php#L304-L347
14,272
joomla-projects/jorobo
src/Tasks/Deploy/Package.php
Package.createModuleZips
public function createModuleZips() { $path = $this->current . "/modules"; // Get every module $hdl = opendir($path); while ($entry = readdir($hdl)) { // Only folders $p = $path . "/" . $entry; if (substr($entry, 0, 1) == '.') { continue; } if (!is_file($p)) { $this->say("Packaging Module " . $entry); // Package file $zip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $zip->open(JPATH_BASE . '/dist/zips/' . $entry . '.zip', \ZipArchive::CREATE); $this->say("Module " . $p); // Process the files to zip $this->addFiles($zip, $p); // Close the zip archive $zip->close(); } } closedir($hdl); }
php
public function createModuleZips() { $path = $this->current . "/modules"; // Get every module $hdl = opendir($path); while ($entry = readdir($hdl)) { // Only folders $p = $path . "/" . $entry; if (substr($entry, 0, 1) == '.') { continue; } if (!is_file($p)) { $this->say("Packaging Module " . $entry); // Package file $zip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $zip->open(JPATH_BASE . '/dist/zips/' . $entry . '.zip', \ZipArchive::CREATE); $this->say("Module " . $p); // Process the files to zip $this->addFiles($zip, $p); // Close the zip archive $zip->close(); } } closedir($hdl); }
[ "public", "function", "createModuleZips", "(", ")", "{", "$", "path", "=", "$", "this", "->", "current", ".", "\"/modules\"", ";", "// Get every module", "$", "hdl", "=", "opendir", "(", "$", "path", ")", ";", "while", "(", "$", "entry", "=", "readdir", "(", "$", "hdl", ")", ")", "{", "// Only folders", "$", "p", "=", "$", "path", ".", "\"/\"", ".", "$", "entry", ";", "if", "(", "substr", "(", "$", "entry", ",", "0", ",", "1", ")", "==", "'.'", ")", "{", "continue", ";", "}", "if", "(", "!", "is_file", "(", "$", "p", ")", ")", "{", "$", "this", "->", "say", "(", "\"Packaging Module \"", ".", "$", "entry", ")", ";", "// Package file", "$", "zip", "=", "new", "\\", "ZipArchive", "(", "JPATH_BASE", ".", "\"/dist\"", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "$", "zip", "->", "open", "(", "JPATH_BASE", ".", "'/dist/zips/'", ".", "$", "entry", ".", "'.zip'", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "$", "this", "->", "say", "(", "\"Module \"", ".", "$", "p", ")", ";", "// Process the files to zip", "$", "this", "->", "addFiles", "(", "$", "zip", ",", "$", "p", ")", ";", "// Close the zip archive", "$", "zip", "->", "close", "(", ")", ";", "}", "}", "closedir", "(", "$", "hdl", ")", ";", "}" ]
Create zips for modules @return void @since 1.0
[ "Create", "zips", "for", "modules" ]
e72dd0ed15f387739f67cacdbc2c0bd1b427f317
https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Deploy/Package.php#L356-L393
14,273
joomla-projects/jorobo
src/Tasks/Deploy/Package.php
Package.createPluginZips
public function createPluginZips() { $path = $this->current . "/plugins"; // Get every plugin $hdl = opendir($path); while ($entry = readdir($hdl)) { // Only folders $p = $path . "/" . $entry; if (substr($entry, 0, 1) == '.') { continue; } if (!is_file($p)) { // Plugin type folder $type = $entry; $hdl2 = opendir($p); while ($plugin = readdir($hdl2)) { if (substr($plugin, 0, 1) == '.') { continue; } // Only folders $p2 = $path . "/" . $type . "/" . $plugin; if (!is_file($p2)) { $plg = "plg_" . $type . "_" . $plugin; $this->say("Packaging Plugin " . $plg); // Package file $zip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $zip->open(JPATH_BASE . '/dist/zips/' . $plg . '.zip', \ZipArchive::CREATE); // Process the files to zip $this->addFiles($zip, $p2); // Close the zip archive $zip->close(); } } closedir($hdl2); } } closedir($hdl); }
php
public function createPluginZips() { $path = $this->current . "/plugins"; // Get every plugin $hdl = opendir($path); while ($entry = readdir($hdl)) { // Only folders $p = $path . "/" . $entry; if (substr($entry, 0, 1) == '.') { continue; } if (!is_file($p)) { // Plugin type folder $type = $entry; $hdl2 = opendir($p); while ($plugin = readdir($hdl2)) { if (substr($plugin, 0, 1) == '.') { continue; } // Only folders $p2 = $path . "/" . $type . "/" . $plugin; if (!is_file($p2)) { $plg = "plg_" . $type . "_" . $plugin; $this->say("Packaging Plugin " . $plg); // Package file $zip = new \ZipArchive(JPATH_BASE . "/dist", \ZipArchive::CREATE); $zip->open(JPATH_BASE . '/dist/zips/' . $plg . '.zip', \ZipArchive::CREATE); // Process the files to zip $this->addFiles($zip, $p2); // Close the zip archive $zip->close(); } } closedir($hdl2); } } closedir($hdl); }
[ "public", "function", "createPluginZips", "(", ")", "{", "$", "path", "=", "$", "this", "->", "current", ".", "\"/plugins\"", ";", "// Get every plugin", "$", "hdl", "=", "opendir", "(", "$", "path", ")", ";", "while", "(", "$", "entry", "=", "readdir", "(", "$", "hdl", ")", ")", "{", "// Only folders", "$", "p", "=", "$", "path", ".", "\"/\"", ".", "$", "entry", ";", "if", "(", "substr", "(", "$", "entry", ",", "0", ",", "1", ")", "==", "'.'", ")", "{", "continue", ";", "}", "if", "(", "!", "is_file", "(", "$", "p", ")", ")", "{", "// Plugin type folder", "$", "type", "=", "$", "entry", ";", "$", "hdl2", "=", "opendir", "(", "$", "p", ")", ";", "while", "(", "$", "plugin", "=", "readdir", "(", "$", "hdl2", ")", ")", "{", "if", "(", "substr", "(", "$", "plugin", ",", "0", ",", "1", ")", "==", "'.'", ")", "{", "continue", ";", "}", "// Only folders", "$", "p2", "=", "$", "path", ".", "\"/\"", ".", "$", "type", ".", "\"/\"", ".", "$", "plugin", ";", "if", "(", "!", "is_file", "(", "$", "p2", ")", ")", "{", "$", "plg", "=", "\"plg_\"", ".", "$", "type", ".", "\"_\"", ".", "$", "plugin", ";", "$", "this", "->", "say", "(", "\"Packaging Plugin \"", ".", "$", "plg", ")", ";", "// Package file", "$", "zip", "=", "new", "\\", "ZipArchive", "(", "JPATH_BASE", ".", "\"/dist\"", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "$", "zip", "->", "open", "(", "JPATH_BASE", ".", "'/dist/zips/'", ".", "$", "plg", ".", "'.zip'", ",", "\\", "ZipArchive", "::", "CREATE", ")", ";", "// Process the files to zip", "$", "this", "->", "addFiles", "(", "$", "zip", ",", "$", "p2", ")", ";", "// Close the zip archive", "$", "zip", "->", "close", "(", ")", ";", "}", "}", "closedir", "(", "$", "hdl2", ")", ";", "}", "}", "closedir", "(", "$", "hdl", ")", ";", "}" ]
Create zips for plugins @return void @since 1.0
[ "Create", "zips", "for", "plugins" ]
e72dd0ed15f387739f67cacdbc2c0bd1b427f317
https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/Deploy/Package.php#L402-L460
14,274
PandaPlatform/framework
src/Panda/Localization/Translator.php
Translator.translate
public function translate($key, $package = 'default', $locale = '', $default = null) { // Normalize locale to current if the given is empty $defaultLocale = Locale::getDefault(); $locale = $locale ?: Locale::get(); $locale = $locale ?: $defaultLocale; // Get locale fallback $translation = null; $fallbackList = LocaleHelper::getLocaleFallbackList($locale, $defaultLocale); foreach ($fallbackList as $locale) { $translation = ($translation ?: $this->processor->get($key, $locale, $package, null)); if (!is_null($translation)) { break; } } // Check final translation if (is_null($default) && $translation === $default) { throw new Exception('The translation for [' . $package . ']->[' . $key . '] is not found in any locale [' . implode(', ', $fallbackList) . '].'); } return $translation ?: $default; }
php
public function translate($key, $package = 'default', $locale = '', $default = null) { // Normalize locale to current if the given is empty $defaultLocale = Locale::getDefault(); $locale = $locale ?: Locale::get(); $locale = $locale ?: $defaultLocale; // Get locale fallback $translation = null; $fallbackList = LocaleHelper::getLocaleFallbackList($locale, $defaultLocale); foreach ($fallbackList as $locale) { $translation = ($translation ?: $this->processor->get($key, $locale, $package, null)); if (!is_null($translation)) { break; } } // Check final translation if (is_null($default) && $translation === $default) { throw new Exception('The translation for [' . $package . ']->[' . $key . '] is not found in any locale [' . implode(', ', $fallbackList) . '].'); } return $translation ?: $default; }
[ "public", "function", "translate", "(", "$", "key", ",", "$", "package", "=", "'default'", ",", "$", "locale", "=", "''", ",", "$", "default", "=", "null", ")", "{", "// Normalize locale to current if the given is empty", "$", "defaultLocale", "=", "Locale", "::", "getDefault", "(", ")", ";", "$", "locale", "=", "$", "locale", "?", ":", "Locale", "::", "get", "(", ")", ";", "$", "locale", "=", "$", "locale", "?", ":", "$", "defaultLocale", ";", "// Get locale fallback", "$", "translation", "=", "null", ";", "$", "fallbackList", "=", "LocaleHelper", "::", "getLocaleFallbackList", "(", "$", "locale", ",", "$", "defaultLocale", ")", ";", "foreach", "(", "$", "fallbackList", "as", "$", "locale", ")", "{", "$", "translation", "=", "(", "$", "translation", "?", ":", "$", "this", "->", "processor", "->", "get", "(", "$", "key", ",", "$", "locale", ",", "$", "package", ",", "null", ")", ")", ";", "if", "(", "!", "is_null", "(", "$", "translation", ")", ")", "{", "break", ";", "}", "}", "// Check final translation", "if", "(", "is_null", "(", "$", "default", ")", "&&", "$", "translation", "===", "$", "default", ")", "{", "throw", "new", "Exception", "(", "'The translation for ['", ".", "$", "package", ".", "']->['", ".", "$", "key", ".", "'] is not found in any locale ['", ".", "implode", "(", "', '", ",", "$", "fallbackList", ")", ".", "'].'", ")", ";", "}", "return", "$", "translation", "?", ":", "$", "default", ";", "}" ]
Get a translation value. If there is no value for the given locale, it tries to fallback to default locale. If the default value is null and no translation is found, it throws Exception. @param string $key @param string $package @param string $locale @param mixed $default @return string @throws Exception
[ "Get", "a", "translation", "value", ".", "If", "there", "is", "no", "value", "for", "the", "given", "locale", "it", "tries", "to", "fallback", "to", "default", "locale", ".", "If", "the", "default", "value", "is", "null", "and", "no", "translation", "is", "found", "it", "throws", "Exception", "." ]
a78cf051b379896b5a4d5df620988e37a0e632f5
https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Localization/Translator.php#L53-L76
14,275
ipunkt/social-auth
src/Ipunkt/SocialAuth/Profile/CompositeProfile.php
CompositeProfile.getValue
protected function getValue($field) { $value = null; $readField = 'get'.$field; foreach($this->readProfiles as $profile) { $value = $profile->$readField(); if($value !== null) { $this->setValue($field, $value); break; } } return $value; }
php
protected function getValue($field) { $value = null; $readField = 'get'.$field; foreach($this->readProfiles as $profile) { $value = $profile->$readField(); if($value !== null) { $this->setValue($field, $value); break; } } return $value; }
[ "protected", "function", "getValue", "(", "$", "field", ")", "{", "$", "value", "=", "null", ";", "$", "readField", "=", "'get'", ".", "$", "field", ";", "foreach", "(", "$", "this", "->", "readProfiles", "as", "$", "profile", ")", "{", "$", "value", "=", "$", "profile", "->", "$", "readField", "(", ")", ";", "if", "(", "$", "value", "!==", "null", ")", "{", "$", "this", "->", "setValue", "(", "$", "field", ",", "$", "value", ")", ";", "break", ";", "}", "}", "return", "$", "value", ";", "}" ]
Searches all profiles for the given value @param $field @return mixed
[ "Searches", "all", "profiles", "for", "the", "given", "value" ]
28723a8e449612789a2cd7d21137996c48b62229
https://github.com/ipunkt/social-auth/blob/28723a8e449612789a2cd7d21137996c48b62229/src/Ipunkt/SocialAuth/Profile/CompositeProfile.php#L42-L57
14,276
markwatkinson/luminous
src/Luminous/Caches/FileSystemCache.php
FileSystemCache.purgeRecurse
private function purgeRecurse($dir) { $base = $dir . '/'; $time = time(); if (substr($dir, 0, strlen($this->dir)) !== $this->dir) { // uh oh, we somehow tried to escape from the cache directory assert(0); return; } foreach (scandir($dir) as $f) { $fn = $base . $f; if ($f[0] === '.') { continue; } if (is_dir($fn)) { $this->purgeRecurse($fn); } else { $update = filemtime($fn); if ($time - $update > $this->timeout) { unlink($fn); } } } }
php
private function purgeRecurse($dir) { $base = $dir . '/'; $time = time(); if (substr($dir, 0, strlen($this->dir)) !== $this->dir) { // uh oh, we somehow tried to escape from the cache directory assert(0); return; } foreach (scandir($dir) as $f) { $fn = $base . $f; if ($f[0] === '.') { continue; } if (is_dir($fn)) { $this->purgeRecurse($fn); } else { $update = filemtime($fn); if ($time - $update > $this->timeout) { unlink($fn); } } } }
[ "private", "function", "purgeRecurse", "(", "$", "dir", ")", "{", "$", "base", "=", "$", "dir", ".", "'/'", ";", "$", "time", "=", "time", "(", ")", ";", "if", "(", "substr", "(", "$", "dir", ",", "0", ",", "strlen", "(", "$", "this", "->", "dir", ")", ")", "!==", "$", "this", "->", "dir", ")", "{", "// uh oh, we somehow tried to escape from the cache directory", "assert", "(", "0", ")", ";", "return", ";", "}", "foreach", "(", "scandir", "(", "$", "dir", ")", "as", "$", "f", ")", "{", "$", "fn", "=", "$", "base", ".", "$", "f", ";", "if", "(", "$", "f", "[", "0", "]", "===", "'.'", ")", "{", "continue", ";", "}", "if", "(", "is_dir", "(", "$", "fn", ")", ")", "{", "$", "this", "->", "purgeRecurse", "(", "$", "fn", ")", ";", "}", "else", "{", "$", "update", "=", "filemtime", "(", "$", "fn", ")", ";", "if", "(", "$", "time", "-", "$", "update", ">", "$", "this", "->", "timeout", ")", "{", "unlink", "(", "$", "fn", ")", ";", "}", "}", "}", "}" ]
Purges the contents of a directory recursively
[ "Purges", "the", "contents", "of", "a", "directory", "recursively" ]
4adc18f414534abe986133d6d38e8e9787d32e69
https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Caches/FileSystemCache.php#L119-L144
14,277
opus-online/yii2-giimodel
Generator.php
Generator.generateClassName
protected function generateClassName($tableName, $short = false) { $ns = null; if (list($prefix, $ns) = $this->tablePrefixMatches($tableName)) { $tableName = substr($tableName, strlen($prefix)); } $className = parent::generateClassName($tableName); if (null !== $ns && $short === false) { $className = '\\' . trim($this->ns . '\\' . $ns, '\\') . '\\' . $className; } return $className; }
php
protected function generateClassName($tableName, $short = false) { $ns = null; if (list($prefix, $ns) = $this->tablePrefixMatches($tableName)) { $tableName = substr($tableName, strlen($prefix)); } $className = parent::generateClassName($tableName); if (null !== $ns && $short === false) { $className = '\\' . trim($this->ns . '\\' . $ns, '\\') . '\\' . $className; } return $className; }
[ "protected", "function", "generateClassName", "(", "$", "tableName", ",", "$", "short", "=", "false", ")", "{", "$", "ns", "=", "null", ";", "if", "(", "list", "(", "$", "prefix", ",", "$", "ns", ")", "=", "$", "this", "->", "tablePrefixMatches", "(", "$", "tableName", ")", ")", "{", "$", "tableName", "=", "substr", "(", "$", "tableName", ",", "strlen", "(", "$", "prefix", ")", ")", ";", "}", "$", "className", "=", "parent", "::", "generateClassName", "(", "$", "tableName", ")", ";", "if", "(", "null", "!==", "$", "ns", "&&", "$", "short", "===", "false", ")", "{", "$", "className", "=", "'\\\\'", ".", "trim", "(", "$", "this", "->", "ns", ".", "'\\\\'", ".", "$", "ns", ",", "'\\\\'", ")", ".", "'\\\\'", ".", "$", "className", ";", "}", "return", "$", "className", ";", "}" ]
Generates a class name with namespace prefix from the specified table name. @param string $tableName the table name (which may contain schema prefix) @param bool $short @return string the generated class name
[ "Generates", "a", "class", "name", "with", "namespace", "prefix", "from", "the", "specified", "table", "name", "." ]
85303396a5e5b540cb38138f4b6af2e6f19d0487
https://github.com/opus-online/yii2-giimodel/blob/85303396a5e5b540cb38138f4b6af2e6f19d0487/Generator.php#L258-L270
14,278
dpolac/dictionary
Dictionary.php
Dictionary.fromPairs
public static function fromPairs($array) { if (!is_array($array) && !($array instanceof \Traversable)) { throw new \InvalidArgumentException(sprintf( 'Dictionary::fromPairs() argument must be array or Traversable, ' . 'but is "%s".', gettype($array) )); } $result = new Dictionary(); foreach ($array as $pair) { if (!is_array($pair) || !isset($pair[0]) || !isset($pair[1])) { throw new \InvalidArgumentException( 'Each element of array or Traversable passed to Dictionary::FromPairs()' . ' must be two-elements array.' ); } $result[$pair[0]] = $pair[1]; } return $result; }
php
public static function fromPairs($array) { if (!is_array($array) && !($array instanceof \Traversable)) { throw new \InvalidArgumentException(sprintf( 'Dictionary::fromPairs() argument must be array or Traversable, ' . 'but is "%s".', gettype($array) )); } $result = new Dictionary(); foreach ($array as $pair) { if (!is_array($pair) || !isset($pair[0]) || !isset($pair[1])) { throw new \InvalidArgumentException( 'Each element of array or Traversable passed to Dictionary::FromPairs()' . ' must be two-elements array.' ); } $result[$pair[0]] = $pair[1]; } return $result; }
[ "public", "static", "function", "fromPairs", "(", "$", "array", ")", "{", "if", "(", "!", "is_array", "(", "$", "array", ")", "&&", "!", "(", "$", "array", "instanceof", "\\", "Traversable", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Dictionary::fromPairs() argument must be array or Traversable, '", ".", "'but is \"%s\".'", ",", "gettype", "(", "$", "array", ")", ")", ")", ";", "}", "$", "result", "=", "new", "Dictionary", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "pair", ")", "{", "if", "(", "!", "is_array", "(", "$", "pair", ")", "||", "!", "isset", "(", "$", "pair", "[", "0", "]", ")", "||", "!", "isset", "(", "$", "pair", "[", "1", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Each element of array or Traversable passed to Dictionary::FromPairs()'", ".", "' must be two-elements array.'", ")", ";", "}", "$", "result", "[", "$", "pair", "[", "0", "]", "]", "=", "$", "pair", "[", "1", "]", ";", "}", "return", "$", "result", ";", "}" ]
Create new Dictionary from array of key-value pairs. @param $array array Array of pairs. Each pair must be 2-element array. @return Dictionary
[ "Create", "new", "Dictionary", "from", "array", "of", "key", "-", "value", "pairs", "." ]
7078d8bfe47cfcb11882140f5dbd7c106c1906e6
https://github.com/dpolac/dictionary/blob/7078d8bfe47cfcb11882140f5dbd7c106c1906e6/Dictionary.php#L137-L158
14,279
dpolac/dictionary
Dictionary.php
Dictionary.fromArray
public static function fromArray($array) { if (!is_array($array) && !($array instanceof \Traversable)) { throw new \InvalidArgumentException(sprintf( 'Dictionary::fromArray() argument must be array or Traversable, ' . 'but is "%s".', gettype($array) )); } $result = new Dictionary(); foreach ($array as $key => $value) { $result[$key] = $value; } return $result; }
php
public static function fromArray($array) { if (!is_array($array) && !($array instanceof \Traversable)) { throw new \InvalidArgumentException(sprintf( 'Dictionary::fromArray() argument must be array or Traversable, ' . 'but is "%s".', gettype($array) )); } $result = new Dictionary(); foreach ($array as $key => $value) { $result[$key] = $value; } return $result; }
[ "public", "static", "function", "fromArray", "(", "$", "array", ")", "{", "if", "(", "!", "is_array", "(", "$", "array", ")", "&&", "!", "(", "$", "array", "instanceof", "\\", "Traversable", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Dictionary::fromArray() argument must be array or Traversable, '", ".", "'but is \"%s\".'", ",", "gettype", "(", "$", "array", ")", ")", ")", ";", "}", "$", "result", "=", "new", "Dictionary", "(", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "result", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "$", "result", ";", "}" ]
Create new Dictionary from standard PHP array. @param $array array Array to create Dictionary from. @return Dictionary
[ "Create", "new", "Dictionary", "from", "standard", "PHP", "array", "." ]
7078d8bfe47cfcb11882140f5dbd7c106c1906e6
https://github.com/dpolac/dictionary/blob/7078d8bfe47cfcb11882140f5dbd7c106c1906e6/Dictionary.php#L166-L180
14,280
dpolac/dictionary
Dictionary.php
Dictionary.toPairs
public function toPairs() { $result = []; foreach ($this as $key => $value) { $result[] = [$key, $value]; } return $result; }
php
public function toPairs() { $result = []; foreach ($this as $key => $value) { $result[] = [$key, $value]; } return $result; }
[ "public", "function", "toPairs", "(", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "result", "[", "]", "=", "[", "$", "key", ",", "$", "value", "]", ";", "}", "return", "$", "result", ";", "}" ]
Get array of all key-value pairs in dictionary. @return array Array of pairs. Each pair is 2-element array.
[ "Get", "array", "of", "all", "key", "-", "value", "pairs", "in", "dictionary", "." ]
7078d8bfe47cfcb11882140f5dbd7c106c1906e6
https://github.com/dpolac/dictionary/blob/7078d8bfe47cfcb11882140f5dbd7c106c1906e6/Dictionary.php#L187-L194
14,281
dpolac/dictionary
Dictionary.php
Dictionary.sortBy
public function sortBy($callback = null, $direction = 'ASC') { if (!is_callable($callback)) { if (is_null($callback) or is_string($callback) && 'values' === strtolower($callback)) { $callback = function ($value, $key) { return $value; }; } else if (is_string($callback) && 'keys' === strtolower($callback)) { $callback = function ($value, $key) { return $key; }; } else { throw new \InvalidArgumentException(sprintf( 'Dictionary::sort() argument must be "keys", "values" or callable, ' . 'but is "%s".', gettype($callback) )); } } if ($direction !== SORT_ASC && $direction !== SORT_DESC) { if (is_string($direction)) { switch (strtolower($direction)) { case 'asc': $direction = SORT_ASC; break; case 'desc': $direction = SORT_DESC; break; default: throw new \InvalidArgumentException(sprintf( 'Direction must be "asc" or "desc", but is "%s".', $direction)); } } else { throw new \InvalidArgumentException(sprintf( 'Direction must be string "asc" or "desc", but is "%s".', gettype($direction))); } } $order = []; foreach ($this as $key => $value) { $order[] = $callback($value, $key); } array_multisort($order, $direction, SORT_REGULAR, $this->data, $this->keys); return $this; //to allow chaining }
php
public function sortBy($callback = null, $direction = 'ASC') { if (!is_callable($callback)) { if (is_null($callback) or is_string($callback) && 'values' === strtolower($callback)) { $callback = function ($value, $key) { return $value; }; } else if (is_string($callback) && 'keys' === strtolower($callback)) { $callback = function ($value, $key) { return $key; }; } else { throw new \InvalidArgumentException(sprintf( 'Dictionary::sort() argument must be "keys", "values" or callable, ' . 'but is "%s".', gettype($callback) )); } } if ($direction !== SORT_ASC && $direction !== SORT_DESC) { if (is_string($direction)) { switch (strtolower($direction)) { case 'asc': $direction = SORT_ASC; break; case 'desc': $direction = SORT_DESC; break; default: throw new \InvalidArgumentException(sprintf( 'Direction must be "asc" or "desc", but is "%s".', $direction)); } } else { throw new \InvalidArgumentException(sprintf( 'Direction must be string "asc" or "desc", but is "%s".', gettype($direction))); } } $order = []; foreach ($this as $key => $value) { $order[] = $callback($value, $key); } array_multisort($order, $direction, SORT_REGULAR, $this->data, $this->keys); return $this; //to allow chaining }
[ "public", "function", "sortBy", "(", "$", "callback", "=", "null", ",", "$", "direction", "=", "'ASC'", ")", "{", "if", "(", "!", "is_callable", "(", "$", "callback", ")", ")", "{", "if", "(", "is_null", "(", "$", "callback", ")", "or", "is_string", "(", "$", "callback", ")", "&&", "'values'", "===", "strtolower", "(", "$", "callback", ")", ")", "{", "$", "callback", "=", "function", "(", "$", "value", ",", "$", "key", ")", "{", "return", "$", "value", ";", "}", ";", "}", "else", "if", "(", "is_string", "(", "$", "callback", ")", "&&", "'keys'", "===", "strtolower", "(", "$", "callback", ")", ")", "{", "$", "callback", "=", "function", "(", "$", "value", ",", "$", "key", ")", "{", "return", "$", "key", ";", "}", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Dictionary::sort() argument must be \"keys\", \"values\" or callable, '", ".", "'but is \"%s\".'", ",", "gettype", "(", "$", "callback", ")", ")", ")", ";", "}", "}", "if", "(", "$", "direction", "!==", "SORT_ASC", "&&", "$", "direction", "!==", "SORT_DESC", ")", "{", "if", "(", "is_string", "(", "$", "direction", ")", ")", "{", "switch", "(", "strtolower", "(", "$", "direction", ")", ")", "{", "case", "'asc'", ":", "$", "direction", "=", "SORT_ASC", ";", "break", ";", "case", "'desc'", ":", "$", "direction", "=", "SORT_DESC", ";", "break", ";", "default", ":", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Direction must be \"asc\" or \"desc\", but is \"%s\".'", ",", "$", "direction", ")", ")", ";", "}", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "sprintf", "(", "'Direction must be string \"asc\" or \"desc\", but is \"%s\".'", ",", "gettype", "(", "$", "direction", ")", ")", ")", ";", "}", "}", "$", "order", "=", "[", "]", ";", "foreach", "(", "$", "this", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "order", "[", "]", "=", "$", "callback", "(", "$", "value", ",", "$", "key", ")", ";", "}", "array_multisort", "(", "$", "order", ",", "$", "direction", ",", "SORT_REGULAR", ",", "$", "this", "->", "data", ",", "$", "this", "->", "keys", ")", ";", "return", "$", "this", ";", "//to allow chaining", "}" ]
Sort Dictionary by values returned by callback. @param string|callable $callback Callback returning value for each Dictionary's element. If argument is a string "values" or "keys", it will be sorted by Dictionary's values or keys. @param string $direction Sorting direction. "ASC" or "DESC". @return $this
[ "Sort", "Dictionary", "by", "values", "returned", "by", "callback", "." ]
7078d8bfe47cfcb11882140f5dbd7c106c1906e6
https://github.com/dpolac/dictionary/blob/7078d8bfe47cfcb11882140f5dbd7c106c1906e6/Dictionary.php#L225-L267
14,282
terdia/legato-framework
src/Routing/RouteDispatcher.php
RouteDispatcher.handle
private function handle($handler, $parameters) { if ($handler instanceof \Closure) { $this->app->execute($handler, $parameters); } else { list($controller, $action) = explode('@', $handler); $class = $this->app->construct($controller); $this->app->execute([$class, $action], $parameters); } }
php
private function handle($handler, $parameters) { if ($handler instanceof \Closure) { $this->app->execute($handler, $parameters); } else { list($controller, $action) = explode('@', $handler); $class = $this->app->construct($controller); $this->app->execute([$class, $action], $parameters); } }
[ "private", "function", "handle", "(", "$", "handler", ",", "$", "parameters", ")", "{", "if", "(", "$", "handler", "instanceof", "\\", "Closure", ")", "{", "$", "this", "->", "app", "->", "execute", "(", "$", "handler", ",", "$", "parameters", ")", ";", "}", "else", "{", "list", "(", "$", "controller", ",", "$", "action", ")", "=", "explode", "(", "'@'", ",", "$", "handler", ")", ";", "$", "class", "=", "$", "this", "->", "app", "->", "construct", "(", "$", "controller", ")", ";", "$", "this", "->", "app", "->", "execute", "(", "[", "$", "class", ",", "$", "action", "]", ",", "$", "parameters", ")", ";", "}", "}" ]
Handler for route found, support Closure and Controller methods. @param $handler @param $parameters
[ "Handler", "for", "route", "found", "support", "Closure", "and", "Controller", "methods", "." ]
44057c1c3c6f3e9643e9fade51bd417860fafda8
https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Routing/RouteDispatcher.php#L52-L62
14,283
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.createFromConfig
public static function createFromConfig(array $config) { $fields = []; foreach ($config as $name => $field) { $fields[$name] = Fields::create($name, $field); } return new static($fields); }
php
public static function createFromConfig(array $config) { $fields = []; foreach ($config as $name => $field) { $fields[$name] = Fields::create($name, $field); } return new static($fields); }
[ "public", "static", "function", "createFromConfig", "(", "array", "$", "config", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "config", "as", "$", "name", "=>", "$", "field", ")", "{", "$", "fields", "[", "$", "name", "]", "=", "Fields", "::", "create", "(", "$", "name", ",", "$", "field", ")", ";", "}", "return", "new", "static", "(", "$", "fields", ")", ";", "}" ]
Method to create form fieldset object and fields from config @param array $config @return Fieldset
[ "Method", "to", "create", "form", "fieldset", "object", "and", "fields", "from", "config" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L61-L68
14,284
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.setCurrent
public function setCurrent($i) { $this->current = (int)$i; if (!isset($this->fields[$this->current])) { $this->fields[$this->current] = []; } return $this; }
php
public function setCurrent($i) { $this->current = (int)$i; if (!isset($this->fields[$this->current])) { $this->fields[$this->current] = []; } return $this; }
[ "public", "function", "setCurrent", "(", "$", "i", ")", "{", "$", "this", "->", "current", "=", "(", "int", ")", "$", "i", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "fields", "[", "$", "this", "->", "current", "]", ")", ")", "{", "$", "this", "->", "fields", "[", "$", "this", "->", "current", "]", "=", "[", "]", ";", "}", "return", "$", "this", ";", "}" ]
Method to get current group index @param int $i @return Fieldset
[ "Method", "to", "get", "current", "group", "index" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L86-L93
14,285
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.insertFieldAfter
public function insertFieldAfter($name, Element\AbstractElement $field) { foreach ($this->fields as $i => $group) { $fields = []; foreach ($group as $key => $value) { if ($key == $name) { $fields[$key] = $value; $fields[$field->getName()] = $field; } else { $fields[$key] = $value; } } $this->fields[$i] = $fields; } return $this; }
php
public function insertFieldAfter($name, Element\AbstractElement $field) { foreach ($this->fields as $i => $group) { $fields = []; foreach ($group as $key => $value) { if ($key == $name) { $fields[$key] = $value; $fields[$field->getName()] = $field; } else { $fields[$key] = $value; } } $this->fields[$i] = $fields; } return $this; }
[ "public", "function", "insertFieldAfter", "(", "$", "name", ",", "Element", "\\", "AbstractElement", "$", "field", ")", "{", "foreach", "(", "$", "this", "->", "fields", "as", "$", "i", "=>", "$", "group", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "group", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "==", "$", "name", ")", "{", "$", "fields", "[", "$", "key", "]", "=", "$", "value", ";", "$", "fields", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", ";", "}", "else", "{", "$", "fields", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "$", "this", "->", "fields", "[", "$", "i", "]", "=", "$", "fields", ";", "}", "return", "$", "this", ";", "}" ]
Method to insert a field after another one @param string $name @param Element\AbstractElement $field @return Fieldset
[ "Method", "to", "insert", "a", "field", "after", "another", "one" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L162-L177
14,286
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.count
public function count() { $count = 0; foreach ($this->fields as $group) { $count += count($group); } return $count; }
php
public function count() { $count = 0; foreach ($this->fields as $group) { $count += count($group); } return $count; }
[ "public", "function", "count", "(", ")", "{", "$", "count", "=", "0", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "group", ")", "{", "$", "count", "+=", "count", "(", "$", "group", ")", ";", "}", "return", "$", "count", ";", "}" ]
Method to get the count of elements in the form fieldset @return int
[ "Method", "to", "get", "the", "count", "of", "elements", "in", "the", "form", "fieldset" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L183-L190
14,287
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.hasField
public function hasField($name) { $result = false; foreach ($this->fields as $key => $fields) { if (isset($fields[$name])) { $result = true; break; } } return $result; }
php
public function hasField($name) { $result = false; foreach ($this->fields as $key => $fields) { if (isset($fields[$name])) { $result = true; break; } } return $result; }
[ "public", "function", "hasField", "(", "$", "name", ")", "{", "$", "result", "=", "false", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "key", "=>", "$", "fields", ")", "{", "if", "(", "isset", "(", "$", "fields", "[", "$", "name", "]", ")", ")", "{", "$", "result", "=", "true", ";", "break", ";", "}", "}", "return", "$", "result", ";", "}" ]
Method to determine if the fieldset has a field @param string $name @return boolean
[ "Method", "to", "determine", "if", "the", "fieldset", "has", "a", "field" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L239-L249
14,288
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.getFields
public function getFields($i) { return (isset($this->fields[$i])) ? $this->fields[$i] : null; }
php
public function getFields($i) { return (isset($this->fields[$i])) ? $this->fields[$i] : null; }
[ "public", "function", "getFields", "(", "$", "i", ")", "{", "return", "(", "isset", "(", "$", "this", "->", "fields", "[", "$", "i", "]", ")", ")", "?", "$", "this", "->", "fields", "[", "$", "i", "]", ":", "null", ";", "}" ]
Method to get field element objects in a group @param int $i @return array
[ "Method", "to", "get", "field", "element", "objects", "in", "a", "group" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L272-L275
14,289
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.getAllFields
public function getAllFields() { $fields = []; foreach ($this->fields as $group) { foreach ($group as $field) { $fields[$field->getName()] = $field; } } return $fields; }
php
public function getAllFields() { $fields = []; foreach ($this->fields as $group) { foreach ($group as $field) { $fields[$field->getName()] = $field; } } return $fields; }
[ "public", "function", "getAllFields", "(", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "group", ")", "{", "foreach", "(", "$", "group", "as", "$", "field", ")", "{", "$", "fields", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", ";", "}", "}", "return", "$", "fields", ";", "}" ]
Method to get all field elements @return array
[ "Method", "to", "get", "all", "field", "elements" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L290-L299
14,290
christophe-brachet/aspi-framework
src/Framework/Form/Fieldset.php
Fieldset.prepareForView
public function prepareForView() { $fields = []; foreach ($this->fields as $groups) { foreach ($groups as $field) { if (null !== $field->getLabel()) { $labelFor = $field->getName() . (($field->getNodeName() == 'fieldset') ? '1' : ''); $label = new Child('label', $field->getLabel()); $label->setAttribute('for', $labelFor); if (null !== $field->getLabelAttributes()) { $label->setAttributes($field->getLabelAttributes()); } if ($field->isRequired()) { if ($label->hasAttribute('class')) { $label->setAttribute('class', $label->getAttribute('class') . ' required'); } else { $label->setAttribute('class', 'required'); } } $fields[$field->getName() . '_label'] = $label->render(); } if (null !== $field->getHint()) { $hint = new Child('span', $field->getHint()); if (null !== $field->getHintAttributes()) { $hint->setAttributes($field->getHintAttributes()); } $fields[$field->getName() . '_hint'] = $hint->render(); } if ($field->hasErrors()) { $fields[$field->getName() . '_errors'] = $field->getErrors(); } $fields[$field->getName()] = $field->render(); } } return $fields; }
php
public function prepareForView() { $fields = []; foreach ($this->fields as $groups) { foreach ($groups as $field) { if (null !== $field->getLabel()) { $labelFor = $field->getName() . (($field->getNodeName() == 'fieldset') ? '1' : ''); $label = new Child('label', $field->getLabel()); $label->setAttribute('for', $labelFor); if (null !== $field->getLabelAttributes()) { $label->setAttributes($field->getLabelAttributes()); } if ($field->isRequired()) { if ($label->hasAttribute('class')) { $label->setAttribute('class', $label->getAttribute('class') . ' required'); } else { $label->setAttribute('class', 'required'); } } $fields[$field->getName() . '_label'] = $label->render(); } if (null !== $field->getHint()) { $hint = new Child('span', $field->getHint()); if (null !== $field->getHintAttributes()) { $hint->setAttributes($field->getHintAttributes()); } $fields[$field->getName() . '_hint'] = $hint->render(); } if ($field->hasErrors()) { $fields[$field->getName() . '_errors'] = $field->getErrors(); } $fields[$field->getName()] = $field->render(); } } return $fields; }
[ "public", "function", "prepareForView", "(", ")", "{", "$", "fields", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "fields", "as", "$", "groups", ")", "{", "foreach", "(", "$", "groups", "as", "$", "field", ")", "{", "if", "(", "null", "!==", "$", "field", "->", "getLabel", "(", ")", ")", "{", "$", "labelFor", "=", "$", "field", "->", "getName", "(", ")", ".", "(", "(", "$", "field", "->", "getNodeName", "(", ")", "==", "'fieldset'", ")", "?", "'1'", ":", "''", ")", ";", "$", "label", "=", "new", "Child", "(", "'label'", ",", "$", "field", "->", "getLabel", "(", ")", ")", ";", "$", "label", "->", "setAttribute", "(", "'for'", ",", "$", "labelFor", ")", ";", "if", "(", "null", "!==", "$", "field", "->", "getLabelAttributes", "(", ")", ")", "{", "$", "label", "->", "setAttributes", "(", "$", "field", "->", "getLabelAttributes", "(", ")", ")", ";", "}", "if", "(", "$", "field", "->", "isRequired", "(", ")", ")", "{", "if", "(", "$", "label", "->", "hasAttribute", "(", "'class'", ")", ")", "{", "$", "label", "->", "setAttribute", "(", "'class'", ",", "$", "label", "->", "getAttribute", "(", "'class'", ")", ".", "' required'", ")", ";", "}", "else", "{", "$", "label", "->", "setAttribute", "(", "'class'", ",", "'required'", ")", ";", "}", "}", "$", "fields", "[", "$", "field", "->", "getName", "(", ")", ".", "'_label'", "]", "=", "$", "label", "->", "render", "(", ")", ";", "}", "if", "(", "null", "!==", "$", "field", "->", "getHint", "(", ")", ")", "{", "$", "hint", "=", "new", "Child", "(", "'span'", ",", "$", "field", "->", "getHint", "(", ")", ")", ";", "if", "(", "null", "!==", "$", "field", "->", "getHintAttributes", "(", ")", ")", "{", "$", "hint", "->", "setAttributes", "(", "$", "field", "->", "getHintAttributes", "(", ")", ")", ";", "}", "$", "fields", "[", "$", "field", "->", "getName", "(", ")", ".", "'_hint'", "]", "=", "$", "hint", "->", "render", "(", ")", ";", "}", "if", "(", "$", "field", "->", "hasErrors", "(", ")", ")", "{", "$", "fields", "[", "$", "field", "->", "getName", "(", ")", ".", "'_errors'", "]", "=", "$", "field", "->", "getErrors", "(", ")", ";", "}", "$", "fields", "[", "$", "field", "->", "getName", "(", ")", "]", "=", "$", "field", "->", "render", "(", ")", ";", "}", "}", "return", "$", "fields", ";", "}" ]
Prepare fieldset elements for rendering with a view @return array
[ "Prepare", "fieldset", "elements", "for", "rendering", "with", "a", "view" ]
17a36c8a8582e0b8d8bff7087590c09a9bd4af1e
https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Fieldset.php#L529-L564
14,291
taskforcedev/laravel-support
src/Helpers/User.php
User.getUserModel
public function getUserModel() { /* Check the app's auth config, first */ $model = Config::get('auth.model'); if (class_exists($model)) { return $model; } /* That didn't work, so let's try our fallback. First get the namespace */ $ns = $this->getAppNamespace(); if ($ns) { /* Try laravel default convention (models in the app folder). */ $model = $ns . 'User'; if (class_exists($model)) { return $model; } /* Try secondary convention of having a models directory. */ $model = $ns . 'Models\User'; if (class_exists($model)) { return $model; } } return false; }
php
public function getUserModel() { /* Check the app's auth config, first */ $model = Config::get('auth.model'); if (class_exists($model)) { return $model; } /* That didn't work, so let's try our fallback. First get the namespace */ $ns = $this->getAppNamespace(); if ($ns) { /* Try laravel default convention (models in the app folder). */ $model = $ns . 'User'; if (class_exists($model)) { return $model; } /* Try secondary convention of having a models directory. */ $model = $ns . 'Models\User'; if (class_exists($model)) { return $model; } } return false; }
[ "public", "function", "getUserModel", "(", ")", "{", "/* Check the app's auth config, first */", "$", "model", "=", "Config", "::", "get", "(", "'auth.model'", ")", ";", "if", "(", "class_exists", "(", "$", "model", ")", ")", "{", "return", "$", "model", ";", "}", "/* That didn't work, so let's try our fallback. First get the namespace */", "$", "ns", "=", "$", "this", "->", "getAppNamespace", "(", ")", ";", "if", "(", "$", "ns", ")", "{", "/* Try laravel default convention (models in the app folder). */", "$", "model", "=", "$", "ns", ".", "'User'", ";", "if", "(", "class_exists", "(", "$", "model", ")", ")", "{", "return", "$", "model", ";", "}", "/* Try secondary convention of having a models directory. */", "$", "model", "=", "$", "ns", ".", "'Models\\User'", ";", "if", "(", "class_exists", "(", "$", "model", ")", ")", "{", "return", "$", "model", ";", "}", "}", "return", "false", ";", "}" ]
Gets the user model if found. @return bool|string
[ "Gets", "the", "user", "model", "if", "found", "." ]
fdfa90ca10ffd57bc6f7aca20d2f3db7dc259221
https://github.com/taskforcedev/laravel-support/blob/fdfa90ca10ffd57bc6f7aca20d2f3db7dc259221/src/Helpers/User.php#L15-L37
14,292
taskforcedev/laravel-support
src/Helpers/User.php
User.createGuest
public function createGuest() { /* Get the namespace */ $model = $this->getUserModel(); if ($model) { $guest = new $model(); $guest->name = 'Guest'; $guest->email = '[email protected]'; } else { $guest = (object)['name' => 'Guest', 'email' => '[email protected]']; } return $guest; }
php
public function createGuest() { /* Get the namespace */ $model = $this->getUserModel(); if ($model) { $guest = new $model(); $guest->name = 'Guest'; $guest->email = '[email protected]'; } else { $guest = (object)['name' => 'Guest', 'email' => '[email protected]']; } return $guest; }
[ "public", "function", "createGuest", "(", ")", "{", "/* Get the namespace */", "$", "model", "=", "$", "this", "->", "getUserModel", "(", ")", ";", "if", "(", "$", "model", ")", "{", "$", "guest", "=", "new", "$", "model", "(", ")", ";", "$", "guest", "->", "name", "=", "'Guest'", ";", "$", "guest", "->", "email", "=", "'[email protected]'", ";", "}", "else", "{", "$", "guest", "=", "(", "object", ")", "[", "'name'", "=>", "'Guest'", ",", "'email'", "=>", "'[email protected]'", "]", ";", "}", "return", "$", "guest", ";", "}" ]
Return an instance of a guest user, uses user model if exists. @return object
[ "Return", "an", "instance", "of", "a", "guest", "user", "uses", "user", "model", "if", "exists", "." ]
fdfa90ca10ffd57bc6f7aca20d2f3db7dc259221
https://github.com/taskforcedev/laravel-support/blob/fdfa90ca10ffd57bc6f7aca20d2f3db7dc259221/src/Helpers/User.php#L52-L64
14,293
cbednarski/pharcc
src/cbednarski/Pharcc/Git.php
Git.getVersion
public static function getVersion($path, $strict = false) { $version = 'unknown'; $temp_path = getcwd(); // Git needs the cwd to be inside the repo // proc_open will pick this up automatically chdir($path); // multi-level exit loop do { $descriptorspec = array( 0 => array('pipe', 'r'), // stdin 1 => array('pipe', 'w'), // stdout 2 => array('pipe', 'w'), // stderr ); $process = proc_open('git describe', $descriptorspec, $pipes); $return_value = null; if (is_resource($process)) { $raw_version = stream_get_contents($pipes[1]); $errors = stream_get_contents($pipes[2]); $return_value = proc_close($process); } if ($return_value !== 0) { break; } if (1 === preg_match('/^v?(\d+\.\d+.\d+)(?:\-(\d+)\-[\w\d]+)?$/', $raw_version, $matches)) { if (isset($matches[2])) { if ($strict) { break; } else { $version = $matches[1] . '+' . $matches[2]; } } else { $version = $matches[1]; } } else { break; } } while(false); // Reset the working directory chdir($temp_path); return $version; }
php
public static function getVersion($path, $strict = false) { $version = 'unknown'; $temp_path = getcwd(); // Git needs the cwd to be inside the repo // proc_open will pick this up automatically chdir($path); // multi-level exit loop do { $descriptorspec = array( 0 => array('pipe', 'r'), // stdin 1 => array('pipe', 'w'), // stdout 2 => array('pipe', 'w'), // stderr ); $process = proc_open('git describe', $descriptorspec, $pipes); $return_value = null; if (is_resource($process)) { $raw_version = stream_get_contents($pipes[1]); $errors = stream_get_contents($pipes[2]); $return_value = proc_close($process); } if ($return_value !== 0) { break; } if (1 === preg_match('/^v?(\d+\.\d+.\d+)(?:\-(\d+)\-[\w\d]+)?$/', $raw_version, $matches)) { if (isset($matches[2])) { if ($strict) { break; } else { $version = $matches[1] . '+' . $matches[2]; } } else { $version = $matches[1]; } } else { break; } } while(false); // Reset the working directory chdir($temp_path); return $version; }
[ "public", "static", "function", "getVersion", "(", "$", "path", ",", "$", "strict", "=", "false", ")", "{", "$", "version", "=", "'unknown'", ";", "$", "temp_path", "=", "getcwd", "(", ")", ";", "// Git needs the cwd to be inside the repo", "// proc_open will pick this up automatically", "chdir", "(", "$", "path", ")", ";", "// multi-level exit loop", "do", "{", "$", "descriptorspec", "=", "array", "(", "0", "=>", "array", "(", "'pipe'", ",", "'r'", ")", ",", "// stdin", "1", "=>", "array", "(", "'pipe'", ",", "'w'", ")", ",", "// stdout", "2", "=>", "array", "(", "'pipe'", ",", "'w'", ")", ",", "// stderr", ")", ";", "$", "process", "=", "proc_open", "(", "'git describe'", ",", "$", "descriptorspec", ",", "$", "pipes", ")", ";", "$", "return_value", "=", "null", ";", "if", "(", "is_resource", "(", "$", "process", ")", ")", "{", "$", "raw_version", "=", "stream_get_contents", "(", "$", "pipes", "[", "1", "]", ")", ";", "$", "errors", "=", "stream_get_contents", "(", "$", "pipes", "[", "2", "]", ")", ";", "$", "return_value", "=", "proc_close", "(", "$", "process", ")", ";", "}", "if", "(", "$", "return_value", "!==", "0", ")", "{", "break", ";", "}", "if", "(", "1", "===", "preg_match", "(", "'/^v?(\\d+\\.\\d+.\\d+)(?:\\-(\\d+)\\-[\\w\\d]+)?$/'", ",", "$", "raw_version", ",", "$", "matches", ")", ")", "{", "if", "(", "isset", "(", "$", "matches", "[", "2", "]", ")", ")", "{", "if", "(", "$", "strict", ")", "{", "break", ";", "}", "else", "{", "$", "version", "=", "$", "matches", "[", "1", "]", ".", "'+'", ".", "$", "matches", "[", "2", "]", ";", "}", "}", "else", "{", "$", "version", "=", "$", "matches", "[", "1", "]", ";", "}", "}", "else", "{", "break", ";", "}", "}", "while", "(", "false", ")", ";", "// Reset the working directory", "chdir", "(", "$", "temp_path", ")", ";", "return", "$", "version", ";", "}" ]
Determine the git version based on `git describe` and semver conventions. @see http://semver.org/ @see https://www.kernel.org/pub/software/scm/git/docs/git-describe.html Normally we'll pull a version number like: 1.0.4 Tagged commit 1.0.4+306 Untagged commit on top of a tag If the strict param is true, we will show 'unknown' in the untagged case @param string $path Directory to inspect for git tags @param bool $strict Whether or not we'll allow untagged commits @return string Version number or 'unknown' in a failure case
[ "Determine", "the", "git", "version", "based", "on", "git", "describe", "and", "semver", "conventions", "." ]
562f9d3d13d2856de6a7ca846a83fe70897baaea
https://github.com/cbednarski/pharcc/blob/562f9d3d13d2856de6a7ca846a83fe70897baaea/src/cbednarski/Pharcc/Git.php#L23-L73
14,294
DevGroup-ru/yii2-data-structure-tools
src/behaviors/HasProperties.php
HasProperties.afterFind
public function afterFind() { if ($this->autoFetchProperties === true) { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $owner->ensurePropertyGroupIds(); $models = [&$owner]; PropertiesHelper::fillProperties($models); } return true; }
php
public function afterFind() { if ($this->autoFetchProperties === true) { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $owner->ensurePropertyGroupIds(); $models = [&$owner]; PropertiesHelper::fillProperties($models); } return true; }
[ "public", "function", "afterFind", "(", ")", "{", "if", "(", "$", "this", "->", "autoFetchProperties", "===", "true", ")", "{", "/** @var \\yii\\db\\ActiveRecord|\\DevGroup\\DataStructure\\traits\\PropertiesTrait $owner */", "$", "owner", "=", "$", "this", "->", "owner", ";", "$", "owner", "->", "ensurePropertyGroupIds", "(", ")", ";", "$", "models", "=", "[", "&", "$", "owner", "]", ";", "PropertiesHelper", "::", "fillProperties", "(", "$", "models", ")", ";", "}", "return", "true", ";", "}" ]
Performs auto fetching properties if it is turned on @return bool
[ "Performs", "auto", "fetching", "properties", "if", "it", "is", "turned", "on" ]
a5b24d7c0b24d4b0d58cacd91ec7fd876e979097
https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/behaviors/HasProperties.php#L59-L71
14,295
DevGroup-ru/yii2-data-structure-tools
src/behaviors/HasProperties.php
HasProperties.beforeDelete
public function beforeDelete() { // properties assigned to this record /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $event = new HasPropertiesEvent(); $event->model = $owner; HasPropertiesEvent::trigger(self::class, self::EVENT_BEFORE_DELETE, $event); //! @todo add check if this object doesn't has related properties that we wish to delete(lower db queries) $array = [&$owner]; PropertiesHelper::deleteAllProperties($array); unset($array); return true; }
php
public function beforeDelete() { // properties assigned to this record /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $event = new HasPropertiesEvent(); $event->model = $owner; HasPropertiesEvent::trigger(self::class, self::EVENT_BEFORE_DELETE, $event); //! @todo add check if this object doesn't has related properties that we wish to delete(lower db queries) $array = [&$owner]; PropertiesHelper::deleteAllProperties($array); unset($array); return true; }
[ "public", "function", "beforeDelete", "(", ")", "{", "// properties assigned to this record", "/** @var \\yii\\db\\ActiveRecord|\\DevGroup\\DataStructure\\traits\\PropertiesTrait $owner */", "$", "owner", "=", "$", "this", "->", "owner", ";", "$", "event", "=", "new", "HasPropertiesEvent", "(", ")", ";", "$", "event", "->", "model", "=", "$", "owner", ";", "HasPropertiesEvent", "::", "trigger", "(", "self", "::", "class", ",", "self", "::", "EVENT_BEFORE_DELETE", ",", "$", "event", ")", ";", "//! @todo add check if this object doesn't has related properties that we wish to delete(lower db queries)", "$", "array", "=", "[", "&", "$", "owner", "]", ";", "PropertiesHelper", "::", "deleteAllProperties", "(", "$", "array", ")", ";", "unset", "(", "$", "array", ")", ";", "return", "true", ";", "}" ]
Deletes related properties from database @return bool
[ "Deletes", "related", "properties", "from", "database" ]
a5b24d7c0b24d4b0d58cacd91ec7fd876e979097
https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/behaviors/HasProperties.php#L77-L91
14,296
DevGroup-ru/yii2-data-structure-tools
src/behaviors/HasProperties.php
HasProperties.hasPropertyKey
public function hasPropertyKey($key) { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $owner->ensurePropertiesAttributes(); return in_array($key, $owner->propertiesAttributes); }
php
public function hasPropertyKey($key) { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $owner->ensurePropertiesAttributes(); return in_array($key, $owner->propertiesAttributes); }
[ "public", "function", "hasPropertyKey", "(", "$", "key", ")", "{", "/** @var \\yii\\db\\ActiveRecord|\\DevGroup\\DataStructure\\traits\\PropertiesTrait $owner */", "$", "owner", "=", "$", "this", "->", "owner", ";", "$", "owner", "->", "ensurePropertiesAttributes", "(", ")", ";", "return", "in_array", "(", "$", "key", ",", "$", "owner", "->", "propertiesAttributes", ")", ";", "}" ]
Returns if property is binded to model @param string $key @return bool
[ "Returns", "if", "property", "is", "binded", "to", "model" ]
a5b24d7c0b24d4b0d58cacd91ec7fd876e979097
https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/behaviors/HasProperties.php#L98-L104
14,297
DevGroup-ru/yii2-data-structure-tools
src/behaviors/HasProperties.php
HasProperties.afterInsert
public function afterInsert() { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $groups = $owner->propertyGroupIds; $owner->propertyGroupIds = null; $event = new HasPropertiesEvent(); $event->model = $owner; HasPropertiesEvent::trigger(self::class, self::EVENT_AFTER_SAVE, $event); if (count($groups) > 0) { foreach ($groups as $group_id) { /** @var PropertyGroup $group */ $group = PropertyGroup::findOne(['id' => $group_id]); if ($group) { $owner->addPropertyGroup($group); } } } $handlers = PropertyStorageHelper::getHandlersForModel($owner); $models = [&$owner]; foreach ($handlers as $handler) { $handler->modelsInserted($models); } $this->afterSave(); }
php
public function afterInsert() { /** @var \yii\db\ActiveRecord|\DevGroup\DataStructure\traits\PropertiesTrait $owner */ $owner = $this->owner; $groups = $owner->propertyGroupIds; $owner->propertyGroupIds = null; $event = new HasPropertiesEvent(); $event->model = $owner; HasPropertiesEvent::trigger(self::class, self::EVENT_AFTER_SAVE, $event); if (count($groups) > 0) { foreach ($groups as $group_id) { /** @var PropertyGroup $group */ $group = PropertyGroup::findOne(['id' => $group_id]); if ($group) { $owner->addPropertyGroup($group); } } } $handlers = PropertyStorageHelper::getHandlersForModel($owner); $models = [&$owner]; foreach ($handlers as $handler) { $handler->modelsInserted($models); } $this->afterSave(); }
[ "public", "function", "afterInsert", "(", ")", "{", "/** @var \\yii\\db\\ActiveRecord|\\DevGroup\\DataStructure\\traits\\PropertiesTrait $owner */", "$", "owner", "=", "$", "this", "->", "owner", ";", "$", "groups", "=", "$", "owner", "->", "propertyGroupIds", ";", "$", "owner", "->", "propertyGroupIds", "=", "null", ";", "$", "event", "=", "new", "HasPropertiesEvent", "(", ")", ";", "$", "event", "->", "model", "=", "$", "owner", ";", "HasPropertiesEvent", "::", "trigger", "(", "self", "::", "class", ",", "self", "::", "EVENT_AFTER_SAVE", ",", "$", "event", ")", ";", "if", "(", "count", "(", "$", "groups", ")", ">", "0", ")", "{", "foreach", "(", "$", "groups", "as", "$", "group_id", ")", "{", "/** @var PropertyGroup $group */", "$", "group", "=", "PropertyGroup", "::", "findOne", "(", "[", "'id'", "=>", "$", "group_id", "]", ")", ";", "if", "(", "$", "group", ")", "{", "$", "owner", "->", "addPropertyGroup", "(", "$", "group", ")", ";", "}", "}", "}", "$", "handlers", "=", "PropertyStorageHelper", "::", "getHandlersForModel", "(", "$", "owner", ")", ";", "$", "models", "=", "[", "&", "$", "owner", "]", ";", "foreach", "(", "$", "handlers", "as", "$", "handler", ")", "{", "$", "handler", "->", "modelsInserted", "(", "$", "models", ")", ";", "}", "$", "this", "->", "afterSave", "(", ")", ";", "}" ]
Performs after insert stuff
[ "Performs", "after", "insert", "stuff" ]
a5b24d7c0b24d4b0d58cacd91ec7fd876e979097
https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/behaviors/HasProperties.php#L194-L219
14,298
dphn/ScContent
src/ScContent/Controller/Back/ContentManagerController.php
ContentManagerController.indexAction
public function indexAction() { $optionsProvider = $this->getOptionsProvider(); if ($this->getRequest()->isPost()) { $event = $this->request->getPost('suboperation'); if (! empty($event)) { $events = $this->getEventManager(); $params = $this->request->getPost(); $result = $events->trigger($event, $this, $params); if ($result->last() instanceof Response) { return $result->last(); } } } $lists = $this->getContentListProvider(); $view = new ViewModel([ 'optionsProvider' => $optionsProvider, 'contentListsProvider' => $lists ]); $flashMessenger = $this->flashMessenger(); if ($flashMessenger->hasMessages()) { $view->messages = $flashMessenger->getMessages(); } return $view; }
php
public function indexAction() { $optionsProvider = $this->getOptionsProvider(); if ($this->getRequest()->isPost()) { $event = $this->request->getPost('suboperation'); if (! empty($event)) { $events = $this->getEventManager(); $params = $this->request->getPost(); $result = $events->trigger($event, $this, $params); if ($result->last() instanceof Response) { return $result->last(); } } } $lists = $this->getContentListProvider(); $view = new ViewModel([ 'optionsProvider' => $optionsProvider, 'contentListsProvider' => $lists ]); $flashMessenger = $this->flashMessenger(); if ($flashMessenger->hasMessages()) { $view->messages = $flashMessenger->getMessages(); } return $view; }
[ "public", "function", "indexAction", "(", ")", "{", "$", "optionsProvider", "=", "$", "this", "->", "getOptionsProvider", "(", ")", ";", "if", "(", "$", "this", "->", "getRequest", "(", ")", "->", "isPost", "(", ")", ")", "{", "$", "event", "=", "$", "this", "->", "request", "->", "getPost", "(", "'suboperation'", ")", ";", "if", "(", "!", "empty", "(", "$", "event", ")", ")", "{", "$", "events", "=", "$", "this", "->", "getEventManager", "(", ")", ";", "$", "params", "=", "$", "this", "->", "request", "->", "getPost", "(", ")", ";", "$", "result", "=", "$", "events", "->", "trigger", "(", "$", "event", ",", "$", "this", ",", "$", "params", ")", ";", "if", "(", "$", "result", "->", "last", "(", ")", "instanceof", "Response", ")", "{", "return", "$", "result", "->", "last", "(", ")", ";", "}", "}", "}", "$", "lists", "=", "$", "this", "->", "getContentListProvider", "(", ")", ";", "$", "view", "=", "new", "ViewModel", "(", "[", "'optionsProvider'", "=>", "$", "optionsProvider", ",", "'contentListsProvider'", "=>", "$", "lists", "]", ")", ";", "$", "flashMessenger", "=", "$", "this", "->", "flashMessenger", "(", ")", ";", "if", "(", "$", "flashMessenger", "->", "hasMessages", "(", ")", ")", "{", "$", "view", "->", "messages", "=", "$", "flashMessenger", "->", "getMessages", "(", ")", ";", "}", "return", "$", "view", ";", "}" ]
Show content list. @return \Zend\Stdlib\ResponseInterface|\Zend\View\Model\ViewModel
[ "Show", "content", "list", "." ]
9dd5732490c45fd788b96cedf7b3c7adfacb30d2
https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Back/ContentManagerController.php#L45-L72
14,299
dphn/ScContent
src/ScContent/Controller/Back/ContentManagerController.php
ContentManagerController.searchAction
public function searchAction() { $optionsProvider = $this->getOptionsProvider(); $pane = $this->params()->fromRoute('pane'); if (! $pane || ! $optionsProvider->hasIdentifier($pane)) { $pane = 'first'; } $options = $optionsProvider->getOptions($pane, 'search'); $search = $optionsProvider->getSearchProxy($pane); $form = $this->getSearchForm(); $form->setAttribute( 'action', $this->url()->fromRoute( 'sc-admin/content-search', ['pane' => $pane] ) ); $form->bind($search); if ($this->getRequest()->isPost()) { $post = $this->params()->fromPost(); if (array_key_exists('clean', $post)) { $search->clean(); } else { $form->setData($post); } if ($form->isValid()) { $options->setSearchOptions( $form->getData(ContentSearchForm::VALUES_AS_ARRAY) ); $optionsProvider->save($options->getName()); } } $list = $this->getContentListProvider()->getList($pane); return new ViewModel([ 'options' => $options, 'list' => $list, 'pane' => $pane, 'form' => $form, ]); }
php
public function searchAction() { $optionsProvider = $this->getOptionsProvider(); $pane = $this->params()->fromRoute('pane'); if (! $pane || ! $optionsProvider->hasIdentifier($pane)) { $pane = 'first'; } $options = $optionsProvider->getOptions($pane, 'search'); $search = $optionsProvider->getSearchProxy($pane); $form = $this->getSearchForm(); $form->setAttribute( 'action', $this->url()->fromRoute( 'sc-admin/content-search', ['pane' => $pane] ) ); $form->bind($search); if ($this->getRequest()->isPost()) { $post = $this->params()->fromPost(); if (array_key_exists('clean', $post)) { $search->clean(); } else { $form->setData($post); } if ($form->isValid()) { $options->setSearchOptions( $form->getData(ContentSearchForm::VALUES_AS_ARRAY) ); $optionsProvider->save($options->getName()); } } $list = $this->getContentListProvider()->getList($pane); return new ViewModel([ 'options' => $options, 'list' => $list, 'pane' => $pane, 'form' => $form, ]); }
[ "public", "function", "searchAction", "(", ")", "{", "$", "optionsProvider", "=", "$", "this", "->", "getOptionsProvider", "(", ")", ";", "$", "pane", "=", "$", "this", "->", "params", "(", ")", "->", "fromRoute", "(", "'pane'", ")", ";", "if", "(", "!", "$", "pane", "||", "!", "$", "optionsProvider", "->", "hasIdentifier", "(", "$", "pane", ")", ")", "{", "$", "pane", "=", "'first'", ";", "}", "$", "options", "=", "$", "optionsProvider", "->", "getOptions", "(", "$", "pane", ",", "'search'", ")", ";", "$", "search", "=", "$", "optionsProvider", "->", "getSearchProxy", "(", "$", "pane", ")", ";", "$", "form", "=", "$", "this", "->", "getSearchForm", "(", ")", ";", "$", "form", "->", "setAttribute", "(", "'action'", ",", "$", "this", "->", "url", "(", ")", "->", "fromRoute", "(", "'sc-admin/content-search'", ",", "[", "'pane'", "=>", "$", "pane", "]", ")", ")", ";", "$", "form", "->", "bind", "(", "$", "search", ")", ";", "if", "(", "$", "this", "->", "getRequest", "(", ")", "->", "isPost", "(", ")", ")", "{", "$", "post", "=", "$", "this", "->", "params", "(", ")", "->", "fromPost", "(", ")", ";", "if", "(", "array_key_exists", "(", "'clean'", ",", "$", "post", ")", ")", "{", "$", "search", "->", "clean", "(", ")", ";", "}", "else", "{", "$", "form", "->", "setData", "(", "$", "post", ")", ";", "}", "if", "(", "$", "form", "->", "isValid", "(", ")", ")", "{", "$", "options", "->", "setSearchOptions", "(", "$", "form", "->", "getData", "(", "ContentSearchForm", "::", "VALUES_AS_ARRAY", ")", ")", ";", "$", "optionsProvider", "->", "save", "(", "$", "options", "->", "getName", "(", ")", ")", ";", "}", "}", "$", "list", "=", "$", "this", "->", "getContentListProvider", "(", ")", "->", "getList", "(", "$", "pane", ")", ";", "return", "new", "ViewModel", "(", "[", "'options'", "=>", "$", "options", ",", "'list'", "=>", "$", "list", ",", "'pane'", "=>", "$", "pane", ",", "'form'", "=>", "$", "form", ",", "]", ")", ";", "}" ]
Show search options. @return \Zend\View\Model\ViewModel
[ "Show", "search", "options", "." ]
9dd5732490c45fd788b96cedf7b3c7adfacb30d2
https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Back/ContentManagerController.php#L79-L121