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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
miknatr/grace-dbal
lib/Grace/DBAL/QueryLogger.php
QueryLogger.stopQuery
public function stopQuery() { $this->queries[$this->counter]['time'] = (time() + microtime(true) - $this->timer); $this->counter++; $this->timer = 0; }
php
public function stopQuery() { $this->queries[$this->counter]['time'] = (time() + microtime(true) - $this->timer); $this->counter++; $this->timer = 0; }
[ "public", "function", "stopQuery", "(", ")", "{", "$", "this", "->", "queries", "[", "$", "this", "->", "counter", "]", "[", "'time'", "]", "=", "(", "time", "(", ")", "+", "microtime", "(", "true", ")", "-", "$", "this", "->", "timer", ")", ";", "$", "this", "->", "counter", "++", ";", "$", "this", "->", "timer", "=", "0", ";", "}" ]
Stops timer and logs query information
[ "Stops", "timer", "and", "logs", "query", "information" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/DBAL/QueryLogger.php#L36-L41
train
miknatr/grace-dbal
lib/Grace/DBAL/QueryLogger.php
QueryLogger.startConnection
public function startConnection($queryString) { $this->connections[$this->counterConnections] = array('query' => $queryString); $this->timer = time() + microtime(true); }
php
public function startConnection($queryString) { $this->connections[$this->counterConnections] = array('query' => $queryString); $this->timer = time() + microtime(true); }
[ "public", "function", "startConnection", "(", "$", "queryString", ")", "{", "$", "this", "->", "connections", "[", "$", "this", "->", "counterConnections", "]", "=", "array", "(", "'query'", "=>", "$", "queryString", ")", ";", "$", "this", "->", "timer", "=", "time", "(", ")", "+", "microtime", "(", "true", ")", ";", "}" ]
Start timer for connection @param string $queryString sql query string
[ "Start", "timer", "for", "connection" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/DBAL/QueryLogger.php#L59-L63
train
miknatr/grace-dbal
lib/Grace/DBAL/QueryLogger.php
QueryLogger.stopConnection
public function stopConnection() { $this->connections[$this->counterConnections]['time'] = (time() + microtime(true) - $this->timer); $this->counterConnections++; $this->timer = 0; }
php
public function stopConnection() { $this->connections[$this->counterConnections]['time'] = (time() + microtime(true) - $this->timer); $this->counterConnections++; $this->timer = 0; }
[ "public", "function", "stopConnection", "(", ")", "{", "$", "this", "->", "connections", "[", "$", "this", "->", "counterConnections", "]", "[", "'time'", "]", "=", "(", "time", "(", ")", "+", "microtime", "(", "true", ")", "-", "$", "this", "->", "timer", ")", ";", "$", "this", "->", "counterConnections", "++", ";", "$", "this", "->", "timer", "=", "0", ";", "}" ]
Stops timer and logs connection information
[ "Stops", "timer", "and", "logs", "connection", "information" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/DBAL/QueryLogger.php#L67-L72
train
miknatr/grace-dbal
lib/Grace/DBAL/QueryLogger.php
QueryLogger.reset
public function reset() { $this->timer = 0; $this->counter = 0; $this->counterConnections = 0; $this->queries = array(); $this->connections = array(); }
php
public function reset() { $this->timer = 0; $this->counter = 0; $this->counterConnections = 0; $this->queries = array(); $this->connections = array(); }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "timer", "=", "0", ";", "$", "this", "->", "counter", "=", "0", ";", "$", "this", "->", "counterConnections", "=", "0", ";", "$", "this", "->", "queries", "=", "array", "(", ")", ";", "$", "this", "->", "connections", "=", "array", "(", ")", ";", "}" ]
Clear all logged data
[ "Clear", "all", "logged", "data" ]
b05e03040568631dc6c77477c0eaed6e60db4ba2
https://github.com/miknatr/grace-dbal/blob/b05e03040568631dc6c77477c0eaed6e60db4ba2/lib/Grace/DBAL/QueryLogger.php#L84-L91
train
stevenliebregt/crispysystem
src/View/SmartyView.php
SmartyView.with
public function with(array $data) : SmartyView { foreach ($data as $k => $v) { $this->smarty->assign($k, $v); } return $this; }
php
public function with(array $data) : SmartyView { foreach ($data as $k => $v) { $this->smarty->assign($k, $v); } return $this; }
[ "public", "function", "with", "(", "array", "$", "data", ")", ":", "SmartyView", "{", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "v", ")", "{", "$", "this", "->", "smarty", "->", "assign", "(", "$", "k", ",", "$", "v", ")", ";", "}", "return", "$", "this", ";", "}" ]
Assigns data to Smarty @param array $data @return SmartyView @since 1.0.0
[ "Assigns", "data", "to", "Smarty" ]
06547dae100dae1023a93ec903f2d2abacce9aec
https://github.com/stevenliebregt/crispysystem/blob/06547dae100dae1023a93ec903f2d2abacce9aec/src/View/SmartyView.php#L109-L116
train
nicodevs/laito
src/Laito/Session/Session.php
Session.login
public function login($username, $password, $data) { // Verify the password against the stored hash if (!password_verify($password, $this->getStoredPassword($username))) { throw new \Exception('Incorrect username or password', 401); } // Create token return $this->app->tokens->create($data); }
php
public function login($username, $password, $data) { // Verify the password against the stored hash if (!password_verify($password, $this->getStoredPassword($username))) { throw new \Exception('Incorrect username or password', 401); } // Create token return $this->app->tokens->create($data); }
[ "public", "function", "login", "(", "$", "username", ",", "$", "password", ",", "$", "data", ")", "{", "// Verify the password against the stored hash", "if", "(", "!", "password_verify", "(", "$", "password", ",", "$", "this", "->", "getStoredPassword", "(", "$", "username", ")", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "'Incorrect username or password'", ",", "401", ")", ";", "}", "// Create token", "return", "$", "this", "->", "app", "->", "tokens", "->", "create", "(", "$", "data", ")", ";", "}" ]
Attempts to start a session @param string $username Username to login @param string $password Password @param array $data Data to store in the session @return array|bool Session data or false
[ "Attempts", "to", "start", "a", "session" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Session/Session.php#L31-L40
train
nicodevs/laito
src/Laito/Session/Session.php
Session.getField
public function getField($field, $token = null) { $session = $this->app->tokens->get($token); return ($session && isset($session[$field]))? $session[$field] : null; }
php
public function getField($field, $token = null) { $session = $this->app->tokens->get($token); return ($session && isset($session[$field]))? $session[$field] : null; }
[ "public", "function", "getField", "(", "$", "field", ",", "$", "token", "=", "null", ")", "{", "$", "session", "=", "$", "this", "->", "app", "->", "tokens", "->", "get", "(", "$", "token", ")", ";", "return", "(", "$", "session", "&&", "isset", "(", "$", "session", "[", "$", "field", "]", ")", ")", "?", "$", "session", "[", "$", "field", "]", ":", "null", ";", "}" ]
Gets a session field @param string $field Field name @param string $token Token hash @return array|bool Session data or false
[ "Gets", "a", "session", "field" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Session/Session.php#L71-L75
train
nicodevs/laito
src/Laito/Session/Session.php
Session.update
public function update($token = null, $data = []) { return $this->app->tokens->update($token, $data); }
php
public function update($token = null, $data = []) { return $this->app->tokens->update($token, $data); }
[ "public", "function", "update", "(", "$", "token", "=", "null", ",", "$", "data", "=", "[", "]", ")", "{", "return", "$", "this", "->", "app", "->", "tokens", "->", "update", "(", "$", "token", ",", "$", "data", ")", ";", "}" ]
Updates a session @param string $token Token hash @param array $data Data to store @return array|bool Session data or false
[ "Updates", "a", "session" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Session/Session.php#L84-L87
train
nicodevs/laito
src/Laito/Session/Session.php
Session.getStoredPassword
private function getStoredPassword($username) { // Get table object $db = $this->app->db->reset()->table($this->table); // Find user by username column $user = $db->select($this->passwordColumn)->limit(1)->where($this->usernameColumn, $username)->getOne(); // Abort if the user or the password column do not exist if (!is_array($user) || !isset($user[$this->passwordColumn])) { return false; } // Return password column return $user[$this->passwordColumn]; }
php
private function getStoredPassword($username) { // Get table object $db = $this->app->db->reset()->table($this->table); // Find user by username column $user = $db->select($this->passwordColumn)->limit(1)->where($this->usernameColumn, $username)->getOne(); // Abort if the user or the password column do not exist if (!is_array($user) || !isset($user[$this->passwordColumn])) { return false; } // Return password column return $user[$this->passwordColumn]; }
[ "private", "function", "getStoredPassword", "(", "$", "username", ")", "{", "// Get table object", "$", "db", "=", "$", "this", "->", "app", "->", "db", "->", "reset", "(", ")", "->", "table", "(", "$", "this", "->", "table", ")", ";", "// Find user by username column", "$", "user", "=", "$", "db", "->", "select", "(", "$", "this", "->", "passwordColumn", ")", "->", "limit", "(", "1", ")", "->", "where", "(", "$", "this", "->", "usernameColumn", ",", "$", "username", ")", "->", "getOne", "(", ")", ";", "// Abort if the user or the password column do not exist", "if", "(", "!", "is_array", "(", "$", "user", ")", "||", "!", "isset", "(", "$", "user", "[", "$", "this", "->", "passwordColumn", "]", ")", ")", "{", "return", "false", ";", "}", "// Return password column", "return", "$", "user", "[", "$", "this", "->", "passwordColumn", "]", ";", "}" ]
Gets an stored password for a user @param string $username Username @return mixed User password, of false if the user does not exist
[ "Gets", "an", "stored", "password", "for", "a", "user" ]
d2d28abfcbf981c4decfec28ce94f8849600e9fe
https://github.com/nicodevs/laito/blob/d2d28abfcbf981c4decfec28ce94f8849600e9fe/src/Laito/Session/Session.php#L106-L121
train
rafrsr/generic-api
src/ApiRequestBuilder.php
ApiRequestBuilder.withJsonBody
public function withJsonBody($data, SerializationContext $context = null) { if (is_string($data)) { $json = $data; } else { $json = SerializerBuilder::create()->build()->serialize($data, 'json', $context); } $this->withBody($json); return $this; }
php
public function withJsonBody($data, SerializationContext $context = null) { if (is_string($data)) { $json = $data; } else { $json = SerializerBuilder::create()->build()->serialize($data, 'json', $context); } $this->withBody($json); return $this; }
[ "public", "function", "withJsonBody", "(", "$", "data", ",", "SerializationContext", "$", "context", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "$", "json", "=", "$", "data", ";", "}", "else", "{", "$", "json", "=", "SerializerBuilder", "::", "create", "(", ")", "->", "build", "(", ")", "->", "serialize", "(", "$", "data", ",", "'json'", ",", "$", "context", ")", ";", "}", "$", "this", "->", "withBody", "(", "$", "json", ")", ";", "return", "$", "this", ";", "}" ]
Create json with given data using serialization @param $data @param SerializationContext|null $context @return $this
[ "Create", "json", "with", "given", "data", "using", "serialization" ]
2572d3dcc32e03914cf710f0229d72e1c09ea65b
https://github.com/rafrsr/generic-api/blob/2572d3dcc32e03914cf710f0229d72e1c09ea65b/src/ApiRequestBuilder.php#L282-L292
train
rafrsr/generic-api
src/ApiRequestBuilder.php
ApiRequestBuilder.withXMLBody
public function withXMLBody($data, SerializationContext $context = null) { if (is_string($data)) { $xml = $data; } else { $xml = SerializerBuilder::create()->build()->serialize($data, 'xml', $context); } $this->addHeader('Content-Type', 'text/xml; charset=utf-8'); $this->withBody($xml); return $this; }
php
public function withXMLBody($data, SerializationContext $context = null) { if (is_string($data)) { $xml = $data; } else { $xml = SerializerBuilder::create()->build()->serialize($data, 'xml', $context); } $this->addHeader('Content-Type', 'text/xml; charset=utf-8'); $this->withBody($xml); return $this; }
[ "public", "function", "withXMLBody", "(", "$", "data", ",", "SerializationContext", "$", "context", "=", "null", ")", "{", "if", "(", "is_string", "(", "$", "data", ")", ")", "{", "$", "xml", "=", "$", "data", ";", "}", "else", "{", "$", "xml", "=", "SerializerBuilder", "::", "create", "(", ")", "->", "build", "(", ")", "->", "serialize", "(", "$", "data", ",", "'xml'", ",", "$", "context", ")", ";", "}", "$", "this", "->", "addHeader", "(", "'Content-Type'", ",", "'text/xml; charset=utf-8'", ")", ";", "$", "this", "->", "withBody", "(", "$", "xml", ")", ";", "return", "$", "this", ";", "}" ]
Create xml with given data using serialization @param $data @param SerializationContext|null $context @return $this
[ "Create", "xml", "with", "given", "data", "using", "serialization" ]
2572d3dcc32e03914cf710f0229d72e1c09ea65b
https://github.com/rafrsr/generic-api/blob/2572d3dcc32e03914cf710f0229d72e1c09ea65b/src/ApiRequestBuilder.php#L302-L313
train
RedCirclePL/ConsoleProcessManagerBundle
EventListener/CommandListener.php
CommandListener.onConsoleCommand
public function onConsoleCommand(ConsoleCommandEvent $event) { if (!$this->processRepository->createSchemaIfNotExists()) { throw new Exception('Cannot create schema for ConsoleProcessManagerBundle'); } $argv = $_SERVER['argv']; unset($argv[0]); $command = implode(' ', $argv); if (!$process = $this->processRepository->findOneByCommand($command)) { $commandName = $event->getCommand()->getName(); $process = $this->processRepository->createProcess($commandName, $command); } $call = new Call(); $call->setStatus(Call::STATUS_STARTED); $call->setConsolePid($this->getPid()); $this->processRepository->addCallToProcess($process, $call); $process->setLastCall($call); $this->processRepository->update($process); $_REQUEST['call_id'] = $call->getId(); }
php
public function onConsoleCommand(ConsoleCommandEvent $event) { if (!$this->processRepository->createSchemaIfNotExists()) { throw new Exception('Cannot create schema for ConsoleProcessManagerBundle'); } $argv = $_SERVER['argv']; unset($argv[0]); $command = implode(' ', $argv); if (!$process = $this->processRepository->findOneByCommand($command)) { $commandName = $event->getCommand()->getName(); $process = $this->processRepository->createProcess($commandName, $command); } $call = new Call(); $call->setStatus(Call::STATUS_STARTED); $call->setConsolePid($this->getPid()); $this->processRepository->addCallToProcess($process, $call); $process->setLastCall($call); $this->processRepository->update($process); $_REQUEST['call_id'] = $call->getId(); }
[ "public", "function", "onConsoleCommand", "(", "ConsoleCommandEvent", "$", "event", ")", "{", "if", "(", "!", "$", "this", "->", "processRepository", "->", "createSchemaIfNotExists", "(", ")", ")", "{", "throw", "new", "Exception", "(", "'Cannot create schema for ConsoleProcessManagerBundle'", ")", ";", "}", "$", "argv", "=", "$", "_SERVER", "[", "'argv'", "]", ";", "unset", "(", "$", "argv", "[", "0", "]", ")", ";", "$", "command", "=", "implode", "(", "' '", ",", "$", "argv", ")", ";", "if", "(", "!", "$", "process", "=", "$", "this", "->", "processRepository", "->", "findOneByCommand", "(", "$", "command", ")", ")", "{", "$", "commandName", "=", "$", "event", "->", "getCommand", "(", ")", "->", "getName", "(", ")", ";", "$", "process", "=", "$", "this", "->", "processRepository", "->", "createProcess", "(", "$", "commandName", ",", "$", "command", ")", ";", "}", "$", "call", "=", "new", "Call", "(", ")", ";", "$", "call", "->", "setStatus", "(", "Call", "::", "STATUS_STARTED", ")", ";", "$", "call", "->", "setConsolePid", "(", "$", "this", "->", "getPid", "(", ")", ")", ";", "$", "this", "->", "processRepository", "->", "addCallToProcess", "(", "$", "process", ",", "$", "call", ")", ";", "$", "process", "->", "setLastCall", "(", "$", "call", ")", ";", "$", "this", "->", "processRepository", "->", "update", "(", "$", "process", ")", ";", "$", "_REQUEST", "[", "'call_id'", "]", "=", "$", "call", "->", "getId", "(", ")", ";", "}" ]
Run on console command start @param ConsoleCommandEvent $event @throws Exception
[ "Run", "on", "console", "command", "start" ]
76b17924d3b7faf81f81f5fdaa96555200dee66b
https://github.com/RedCirclePL/ConsoleProcessManagerBundle/blob/76b17924d3b7faf81f81f5fdaa96555200dee66b/EventListener/CommandListener.php#L46-L71
train
RedCirclePL/ConsoleProcessManagerBundle
EventListener/CommandListener.php
CommandListener.onConsoleException
public function onConsoleException(ConsoleExceptionEvent $event) { $call = $this->callRepository->find($_REQUEST['call_id']); $call->setStatus(Call::STATUS_FAILED) ->setOutput($event->getException()); $this->callRepository->update($call); $this->registerError($call); }
php
public function onConsoleException(ConsoleExceptionEvent $event) { $call = $this->callRepository->find($_REQUEST['call_id']); $call->setStatus(Call::STATUS_FAILED) ->setOutput($event->getException()); $this->callRepository->update($call); $this->registerError($call); }
[ "public", "function", "onConsoleException", "(", "ConsoleExceptionEvent", "$", "event", ")", "{", "$", "call", "=", "$", "this", "->", "callRepository", "->", "find", "(", "$", "_REQUEST", "[", "'call_id'", "]", ")", ";", "$", "call", "->", "setStatus", "(", "Call", "::", "STATUS_FAILED", ")", "->", "setOutput", "(", "$", "event", "->", "getException", "(", ")", ")", ";", "$", "this", "->", "callRepository", "->", "update", "(", "$", "call", ")", ";", "$", "this", "->", "registerError", "(", "$", "call", ")", ";", "}" ]
Run on console command exception @param ConsoleExceptionEvent $event
[ "Run", "on", "console", "command", "exception" ]
76b17924d3b7faf81f81f5fdaa96555200dee66b
https://github.com/RedCirclePL/ConsoleProcessManagerBundle/blob/76b17924d3b7faf81f81f5fdaa96555200dee66b/EventListener/CommandListener.php#L78-L88
train
RedCirclePL/ConsoleProcessManagerBundle
EventListener/CommandListener.php
CommandListener.onConsoleTerminate
public function onConsoleTerminate(ConsoleTerminateEvent $event) { $call = $this->callRepository->find($_REQUEST['call_id']); if (!$call->getStatus()) { $call->setStatus(Call::STATUS_SUCCESS); } if ($event->getExitCode()) { $call->setStatus(Call::STATUS_ABORTED); $call->setOutput(sprintf('Command finished with exit code: %s', $event->getExitCode())); $this->registerError($call); } $call->setFinishedAt(new \DateTime()); $call->setExecutionTime($call->getExecutionTime()); $this->callRepository->update($call); $this->processRepository->countAvgExecutionTime($call->getProcess(), $call->getExecutionTime()); $this->processRepository->update($call->getProcess()); }
php
public function onConsoleTerminate(ConsoleTerminateEvent $event) { $call = $this->callRepository->find($_REQUEST['call_id']); if (!$call->getStatus()) { $call->setStatus(Call::STATUS_SUCCESS); } if ($event->getExitCode()) { $call->setStatus(Call::STATUS_ABORTED); $call->setOutput(sprintf('Command finished with exit code: %s', $event->getExitCode())); $this->registerError($call); } $call->setFinishedAt(new \DateTime()); $call->setExecutionTime($call->getExecutionTime()); $this->callRepository->update($call); $this->processRepository->countAvgExecutionTime($call->getProcess(), $call->getExecutionTime()); $this->processRepository->update($call->getProcess()); }
[ "public", "function", "onConsoleTerminate", "(", "ConsoleTerminateEvent", "$", "event", ")", "{", "$", "call", "=", "$", "this", "->", "callRepository", "->", "find", "(", "$", "_REQUEST", "[", "'call_id'", "]", ")", ";", "if", "(", "!", "$", "call", "->", "getStatus", "(", ")", ")", "{", "$", "call", "->", "setStatus", "(", "Call", "::", "STATUS_SUCCESS", ")", ";", "}", "if", "(", "$", "event", "->", "getExitCode", "(", ")", ")", "{", "$", "call", "->", "setStatus", "(", "Call", "::", "STATUS_ABORTED", ")", ";", "$", "call", "->", "setOutput", "(", "sprintf", "(", "'Command finished with exit code: %s'", ",", "$", "event", "->", "getExitCode", "(", ")", ")", ")", ";", "$", "this", "->", "registerError", "(", "$", "call", ")", ";", "}", "$", "call", "->", "setFinishedAt", "(", "new", "\\", "DateTime", "(", ")", ")", ";", "$", "call", "->", "setExecutionTime", "(", "$", "call", "->", "getExecutionTime", "(", ")", ")", ";", "$", "this", "->", "callRepository", "->", "update", "(", "$", "call", ")", ";", "$", "this", "->", "processRepository", "->", "countAvgExecutionTime", "(", "$", "call", "->", "getProcess", "(", ")", ",", "$", "call", "->", "getExecutionTime", "(", ")", ")", ";", "$", "this", "->", "processRepository", "->", "update", "(", "$", "call", "->", "getProcess", "(", ")", ")", ";", "}" ]
Run on console command ends @param ConsoleTerminateEvent $event
[ "Run", "on", "console", "command", "ends" ]
76b17924d3b7faf81f81f5fdaa96555200dee66b
https://github.com/RedCirclePL/ConsoleProcessManagerBundle/blob/76b17924d3b7faf81f81f5fdaa96555200dee66b/EventListener/CommandListener.php#L95-L116
train
mtils/cmsable
src/Cmsable/Resource/ResourceBus.php
ResourceBus.getEventBus
public function getEventBus() { if ($this->eventBus) { return $this->eventBus; } if (isset(static::$staticEventBus) && static::$staticEventBus) { return static::$staticEventBus; } if (!$this->eventBus) { $this->eventBus = Bus::instance(); } return $this->eventBus; }
php
public function getEventBus() { if ($this->eventBus) { return $this->eventBus; } if (isset(static::$staticEventBus) && static::$staticEventBus) { return static::$staticEventBus; } if (!$this->eventBus) { $this->eventBus = Bus::instance(); } return $this->eventBus; }
[ "public", "function", "getEventBus", "(", ")", "{", "if", "(", "$", "this", "->", "eventBus", ")", "{", "return", "$", "this", "->", "eventBus", ";", "}", "if", "(", "isset", "(", "static", "::", "$", "staticEventBus", ")", "&&", "static", "::", "$", "staticEventBus", ")", "{", "return", "static", "::", "$", "staticEventBus", ";", "}", "if", "(", "!", "$", "this", "->", "eventBus", ")", "{", "$", "this", "->", "eventBus", "=", "Bus", "::", "instance", "(", ")", ";", "}", "return", "$", "this", "->", "eventBus", ";", "}" ]
Return the single instance of resource bus @return BusContract
[ "Return", "the", "single", "instance", "of", "resource", "bus" ]
03ae84ee3c7d46146f2a1cf687e5c29d6de4286d
https://github.com/mtils/cmsable/blob/03ae84ee3c7d46146f2a1cf687e5c29d6de4286d/src/Cmsable/Resource/ResourceBus.php#L28-L42
train
Arcesilas/dot-array
src/DotArray.php
DotArray.get
public function get(string $key, $default = null) { if (array_key_exists($key, $this->input)) { return $this->input[$key]; } elseif (array_key_exists($key, $this->cache)) { return $this->cache[$key]; } // No dot, then not nested keys. We already tried that key and were not lucky. if (false === strpos($key, '.')) { return $this->default($default); } try { $return = $this->find($this->input, $key); } catch (\Exception $e) { $return = $this->default($default); } return $return; }
php
public function get(string $key, $default = null) { if (array_key_exists($key, $this->input)) { return $this->input[$key]; } elseif (array_key_exists($key, $this->cache)) { return $this->cache[$key]; } // No dot, then not nested keys. We already tried that key and were not lucky. if (false === strpos($key, '.')) { return $this->default($default); } try { $return = $this->find($this->input, $key); } catch (\Exception $e) { $return = $this->default($default); } return $return; }
[ "public", "function", "get", "(", "string", "$", "key", ",", "$", "default", "=", "null", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "input", ")", ")", "{", "return", "$", "this", "->", "input", "[", "$", "key", "]", ";", "}", "elseif", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "cache", ")", ")", "{", "return", "$", "this", "->", "cache", "[", "$", "key", "]", ";", "}", "// No dot, then not nested keys. We already tried that key and were not lucky.", "if", "(", "false", "===", "strpos", "(", "$", "key", ",", "'.'", ")", ")", "{", "return", "$", "this", "->", "default", "(", "$", "default", ")", ";", "}", "try", "{", "$", "return", "=", "$", "this", "->", "find", "(", "$", "this", "->", "input", ",", "$", "key", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "return", "=", "$", "this", "->", "default", "(", "$", "default", ")", ";", "}", "return", "$", "return", ";", "}" ]
Returns an item using dot notation @method get @param string $key @param mixed $default @return mixed
[ "Returns", "an", "item", "using", "dot", "notation" ]
89839a56c71cb472a8df7d7d1d3b90d68bf31f97
https://github.com/Arcesilas/dot-array/blob/89839a56c71cb472a8df7d7d1d3b90d68bf31f97/src/DotArray.php#L80-L99
train
Arcesilas/dot-array
src/DotArray.php
DotArray.has
public function has(string $key) { if (array_key_exists($key, $this->input)) { return true; } try { $this->find($this->input, $key); return true; } catch (\Exception $e) { return false; } }
php
public function has(string $key) { if (array_key_exists($key, $this->input)) { return true; } try { $this->find($this->input, $key); return true; } catch (\Exception $e) { return false; } }
[ "public", "function", "has", "(", "string", "$", "key", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "input", ")", ")", "{", "return", "true", ";", "}", "try", "{", "$", "this", "->", "find", "(", "$", "this", "->", "input", ",", "$", "key", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "return", "false", ";", "}", "}" ]
Checks whether the dotted key exists @method has @param string $key @return boolean
[ "Checks", "whether", "the", "dotted", "key", "exists" ]
89839a56c71cb472a8df7d7d1d3b90d68bf31f97
https://github.com/Arcesilas/dot-array/blob/89839a56c71cb472a8df7d7d1d3b90d68bf31f97/src/DotArray.php#L107-L119
train
Arcesilas/dot-array
src/DotArray.php
DotArray.find
protected function find(array $array, string $key) { $item = $array; foreach (explode('.', $key) as $segment) { if (is_array($item) && array_key_exists($segment, $item)) { $item = $item[$segment]; } else { throw new \Exception(); } } $this->cache[$key] = &$item; return $item; }
php
protected function find(array $array, string $key) { $item = $array; foreach (explode('.', $key) as $segment) { if (is_array($item) && array_key_exists($segment, $item)) { $item = $item[$segment]; } else { throw new \Exception(); } } $this->cache[$key] = &$item; return $item; }
[ "protected", "function", "find", "(", "array", "$", "array", ",", "string", "$", "key", ")", "{", "$", "item", "=", "$", "array", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "key", ")", "as", "$", "segment", ")", "{", "if", "(", "is_array", "(", "$", "item", ")", "&&", "array_key_exists", "(", "$", "segment", ",", "$", "item", ")", ")", "{", "$", "item", "=", "$", "item", "[", "$", "segment", "]", ";", "}", "else", "{", "throw", "new", "\\", "Exception", "(", ")", ";", "}", "}", "$", "this", "->", "cache", "[", "$", "key", "]", "=", "&", "$", "item", ";", "return", "$", "item", ";", "}" ]
Find a value with its dotted key in an array @param array $array @param string $key @return mixed @throws \Exception if the key is not found
[ "Find", "a", "value", "with", "its", "dotted", "key", "in", "an", "array" ]
89839a56c71cb472a8df7d7d1d3b90d68bf31f97
https://github.com/Arcesilas/dot-array/blob/89839a56c71cb472a8df7d7d1d3b90d68bf31f97/src/DotArray.php#L128-L143
train
Arcesilas/dot-array
src/DotArray.php
DotArray.set
public function set(string $key, $value) { $array = &$this->input; $keys = explode('.', $key); while (count($keys) > 1) { $k = array_shift($keys); if (!isset($array[$k]) || ! is_array($array[$k])) { $array[$k] = []; } $array = &$array[$k]; } $array[array_shift($keys)] = $value; $this->cache[$key] = &$value; }
php
public function set(string $key, $value) { $array = &$this->input; $keys = explode('.', $key); while (count($keys) > 1) { $k = array_shift($keys); if (!isset($array[$k]) || ! is_array($array[$k])) { $array[$k] = []; } $array = &$array[$k]; } $array[array_shift($keys)] = $value; $this->cache[$key] = &$value; }
[ "public", "function", "set", "(", "string", "$", "key", ",", "$", "value", ")", "{", "$", "array", "=", "&", "$", "this", "->", "input", ";", "$", "keys", "=", "explode", "(", "'.'", ",", "$", "key", ")", ";", "while", "(", "count", "(", "$", "keys", ")", ">", "1", ")", "{", "$", "k", "=", "array_shift", "(", "$", "keys", ")", ";", "if", "(", "!", "isset", "(", "$", "array", "[", "$", "k", "]", ")", "||", "!", "is_array", "(", "$", "array", "[", "$", "k", "]", ")", ")", "{", "$", "array", "[", "$", "k", "]", "=", "[", "]", ";", "}", "$", "array", "=", "&", "$", "array", "[", "$", "k", "]", ";", "}", "$", "array", "[", "array_shift", "(", "$", "keys", ")", "]", "=", "$", "value", ";", "$", "this", "->", "cache", "[", "$", "key", "]", "=", "&", "$", "value", ";", "}" ]
Sets a value using dot notation @param string $key @param mixed $value
[ "Sets", "a", "value", "using", "dot", "notation" ]
89839a56c71cb472a8df7d7d1d3b90d68bf31f97
https://github.com/Arcesilas/dot-array/blob/89839a56c71cb472a8df7d7d1d3b90d68bf31f97/src/DotArray.php#L150-L165
train
Arcesilas/dot-array
src/DotArray.php
DotArray.unset
public function unset(string $key) { if (array_key_exists($key, $this->input)) { unset($this->input[$key]); unset($this->cache[$key]); } $item = &$this->input; foreach (explode('.', $key) as $segment) { if (! isset($item[$segment])) { return; } if (! is_array($item[$segment])) { unset($item[$segment]); break; } $item = &$item[$segment]; } unset($this->cache[$key]); }
php
public function unset(string $key) { if (array_key_exists($key, $this->input)) { unset($this->input[$key]); unset($this->cache[$key]); } $item = &$this->input; foreach (explode('.', $key) as $segment) { if (! isset($item[$segment])) { return; } if (! is_array($item[$segment])) { unset($item[$segment]); break; } $item = &$item[$segment]; } unset($this->cache[$key]); }
[ "public", "function", "unset", "(", "string", "$", "key", ")", "{", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "input", ")", ")", "{", "unset", "(", "$", "this", "->", "input", "[", "$", "key", "]", ")", ";", "unset", "(", "$", "this", "->", "cache", "[", "$", "key", "]", ")", ";", "}", "$", "item", "=", "&", "$", "this", "->", "input", ";", "foreach", "(", "explode", "(", "'.'", ",", "$", "key", ")", "as", "$", "segment", ")", "{", "if", "(", "!", "isset", "(", "$", "item", "[", "$", "segment", "]", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_array", "(", "$", "item", "[", "$", "segment", "]", ")", ")", "{", "unset", "(", "$", "item", "[", "$", "segment", "]", ")", ";", "break", ";", "}", "$", "item", "=", "&", "$", "item", "[", "$", "segment", "]", ";", "}", "unset", "(", "$", "this", "->", "cache", "[", "$", "key", "]", ")", ";", "}" ]
Unsets a dotted key @param string $key
[ "Unsets", "a", "dotted", "key" ]
89839a56c71cb472a8df7d7d1d3b90d68bf31f97
https://github.com/Arcesilas/dot-array/blob/89839a56c71cb472a8df7d7d1d3b90d68bf31f97/src/DotArray.php#L171-L192
train
Arcesilas/dot-array
src/DotArray.php
DotArray.import
public function import($input) { if (false !== ($array = $this->getImportableArray($input))) { $this->input = array_replace_recursive($this->input, $array); $this->cache = []; } }
php
public function import($input) { if (false !== ($array = $this->getImportableArray($input))) { $this->input = array_replace_recursive($this->input, $array); $this->cache = []; } }
[ "public", "function", "import", "(", "$", "input", ")", "{", "if", "(", "false", "!==", "(", "$", "array", "=", "$", "this", "->", "getImportableArray", "(", "$", "input", ")", ")", ")", "{", "$", "this", "->", "input", "=", "array_replace_recursive", "(", "$", "this", "->", "input", ",", "$", "array", ")", ";", "$", "this", "->", "cache", "=", "[", "]", ";", "}", "}" ]
Import an array, ArrayAccess @method import @param mixed $input
[ "Import", "an", "array", "ArrayAccess" ]
89839a56c71cb472a8df7d7d1d3b90d68bf31f97
https://github.com/Arcesilas/dot-array/blob/89839a56c71cb472a8df7d7d1d3b90d68bf31f97/src/DotArray.php#L199-L205
train
ciims/ciims-modules-api
components/ApiController.php
ApiController.createAction
public function createAction($actionID) { if ($actionID==='') $actionID=$this->defaultAction; if (Yii::app()->request->getRequestType() != 'GET' && $actionID != 'error') $actionID .= Yii::app()->request->getRequestType(); if (method_exists($this,'action'.$actionID) && strcasecmp($actionID,'s')) // we have actions method return new ApiInlineAction($this,$actionID); else { $action=$this->createActionFromMap($this->actions(),$actionID,$actionID); if ($action!==null && !method_exists($action,'run')) throw new CException(Yii::t('yii', 'Action class {class} must implement the "run" method.', array('{class}'=>get_class($action)))); return $action; } }
php
public function createAction($actionID) { if ($actionID==='') $actionID=$this->defaultAction; if (Yii::app()->request->getRequestType() != 'GET' && $actionID != 'error') $actionID .= Yii::app()->request->getRequestType(); if (method_exists($this,'action'.$actionID) && strcasecmp($actionID,'s')) // we have actions method return new ApiInlineAction($this,$actionID); else { $action=$this->createActionFromMap($this->actions(),$actionID,$actionID); if ($action!==null && !method_exists($action,'run')) throw new CException(Yii::t('yii', 'Action class {class} must implement the "run" method.', array('{class}'=>get_class($action)))); return $action; } }
[ "public", "function", "createAction", "(", "$", "actionID", ")", "{", "if", "(", "$", "actionID", "===", "''", ")", "$", "actionID", "=", "$", "this", "->", "defaultAction", ";", "if", "(", "Yii", "::", "app", "(", ")", "->", "request", "->", "getRequestType", "(", ")", "!=", "'GET'", "&&", "$", "actionID", "!=", "'error'", ")", "$", "actionID", ".=", "Yii", "::", "app", "(", ")", "->", "request", "->", "getRequestType", "(", ")", ";", "if", "(", "method_exists", "(", "$", "this", ",", "'action'", ".", "$", "actionID", ")", "&&", "strcasecmp", "(", "$", "actionID", ",", "'s'", ")", ")", "// we have actions method\r", "return", "new", "ApiInlineAction", "(", "$", "this", ",", "$", "actionID", ")", ";", "else", "{", "$", "action", "=", "$", "this", "->", "createActionFromMap", "(", "$", "this", "->", "actions", "(", ")", ",", "$", "actionID", ",", "$", "actionID", ")", ";", "if", "(", "$", "action", "!==", "null", "&&", "!", "method_exists", "(", "$", "action", ",", "'run'", ")", ")", "throw", "new", "CException", "(", "Yii", "::", "t", "(", "'yii'", ",", "'Action class {class} must implement the \"run\" method.'", ",", "array", "(", "'{class}'", "=>", "get_class", "(", "$", "action", ")", ")", ")", ")", ";", "return", "$", "action", ";", "}", "}" ]
Method overload allows clearer separation of controller actions in relation to REQUEST_TYPE GET actions will be routed to action$actionID Other actions will be routed to action$actionIDREQUEST_TYPE @param $actionID string The string name of the action that we want to run @return CInlineAction @see CController::createAction($actionID)
[ "Method", "overload", "allows", "clearer", "separation", "of", "controller", "actions", "in", "relation", "to", "REQUEST_TYPE" ]
4351855328da0b112ac27bde7e7e07e212be8689
https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/components/ApiController.php#L115-L133
train
ciims/ciims-modules-api
components/ApiController.php
ApiController.beforeAction
public function beforeAction($action) { try { @Yii::app()->newRelic->setTransactionName($this->id, $action->id); } catch (Exception $e) {} // Ignore errors if NewRelic isn't installed/configured properly // Force SSL for secure areas if enabled from the dashboard if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false)) $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri); // If content was sent as application/x-www-form-urlencoded, use it. Otherwise, assume raw JSON was sent and convert it into // the $_POST variable for ease of use if (Yii::app()->request->rawBody != "" && empty($_POST)) { // IF the rawBody is malformed, throw an HTTP 500 error. Use json_encode so that we can get json_last_error $_POST = json_decode(Yii::app()->request->rawBody); if (json_last_error() != JSON_ERROR_NONE) { header('HTTP/1.1 400 Bad Request'); $this->status = 400; $this->message = Yii::t('Api.main', 'Request payload not properly formed JSON.'); return null; } $_POST = CJSON::decode(Yii::app()->request->rawBody); } return true; }
php
public function beforeAction($action) { try { @Yii::app()->newRelic->setTransactionName($this->id, $action->id); } catch (Exception $e) {} // Ignore errors if NewRelic isn't installed/configured properly // Force SSL for secure areas if enabled from the dashboard if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false)) $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri); // If content was sent as application/x-www-form-urlencoded, use it. Otherwise, assume raw JSON was sent and convert it into // the $_POST variable for ease of use if (Yii::app()->request->rawBody != "" && empty($_POST)) { // IF the rawBody is malformed, throw an HTTP 500 error. Use json_encode so that we can get json_last_error $_POST = json_decode(Yii::app()->request->rawBody); if (json_last_error() != JSON_ERROR_NONE) { header('HTTP/1.1 400 Bad Request'); $this->status = 400; $this->message = Yii::t('Api.main', 'Request payload not properly formed JSON.'); return null; } $_POST = CJSON::decode(Yii::app()->request->rawBody); } return true; }
[ "public", "function", "beforeAction", "(", "$", "action", ")", "{", "try", "{", "@", "Yii", "::", "app", "(", ")", "->", "newRelic", "->", "setTransactionName", "(", "$", "this", "->", "id", ",", "$", "action", "->", "id", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "}", "// Ignore errors if NewRelic isn't installed/configured properly\r", "// Force SSL for secure areas if enabled from the dashboard\r", "if", "(", "!", "Yii", "::", "app", "(", ")", "->", "getRequest", "(", ")", "->", "isSecureConnection", "&&", "Cii", "::", "getConfig", "(", "'forceSecureSSL'", ",", "false", ")", ")", "$", "this", "->", "redirect", "(", "'https://'", ".", "Yii", "::", "app", "(", ")", "->", "getRequest", "(", ")", "->", "serverName", ".", "Yii", "::", "app", "(", ")", "->", "getRequest", "(", ")", "->", "requestUri", ")", ";", "// If content was sent as application/x-www-form-urlencoded, use it. Otherwise, assume raw JSON was sent and convert it into\r", "// the $_POST variable for ease of use\r", "if", "(", "Yii", "::", "app", "(", ")", "->", "request", "->", "rawBody", "!=", "\"\"", "&&", "empty", "(", "$", "_POST", ")", ")", "{", "// IF the rawBody is malformed, throw an HTTP 500 error. Use json_encode so that we can get json_last_error\r", "$", "_POST", "=", "json_decode", "(", "Yii", "::", "app", "(", ")", "->", "request", "->", "rawBody", ")", ";", "if", "(", "json_last_error", "(", ")", "!=", "JSON_ERROR_NONE", ")", "{", "header", "(", "'HTTP/1.1 400 Bad Request'", ")", ";", "$", "this", "->", "status", "=", "400", ";", "$", "this", "->", "message", "=", "Yii", "::", "t", "(", "'Api.main'", ",", "'Request payload not properly formed JSON.'", ")", ";", "return", "null", ";", "}", "$", "_POST", "=", "CJSON", "::", "decode", "(", "Yii", "::", "app", "(", ")", "->", "request", "->", "rawBody", ")", ";", "}", "return", "true", ";", "}" ]
BeforeAction, validates that there is a valid response body @param CAction $action The action we want to run
[ "BeforeAction", "validates", "that", "there", "is", "a", "valid", "response", "body" ]
4351855328da0b112ac27bde7e7e07e212be8689
https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/components/ApiController.php#L139-L167
train
ciims/ciims-modules-api
components/ApiController.php
ApiController.actionError
public function actionError() { $response = array(); $this->message = Yii::t('Api.Controller', 'An unexpected error occured.'); if ($error=Yii::app()->errorHandler->error) { $this->status = $error['code']; $this->message = $error['message']; if (YII_DEBUG) $response = $error; } return $this->renderOutput($response); }
php
public function actionError() { $response = array(); $this->message = Yii::t('Api.Controller', 'An unexpected error occured.'); if ($error=Yii::app()->errorHandler->error) { $this->status = $error['code']; $this->message = $error['message']; if (YII_DEBUG) $response = $error; } return $this->renderOutput($response); }
[ "public", "function", "actionError", "(", ")", "{", "$", "response", "=", "array", "(", ")", ";", "$", "this", "->", "message", "=", "Yii", "::", "t", "(", "'Api.Controller'", ",", "'An unexpected error occured.'", ")", ";", "if", "(", "$", "error", "=", "Yii", "::", "app", "(", ")", "->", "errorHandler", "->", "error", ")", "{", "$", "this", "->", "status", "=", "$", "error", "[", "'code'", "]", ";", "$", "this", "->", "message", "=", "$", "error", "[", "'message'", "]", ";", "if", "(", "YII_DEBUG", ")", "$", "response", "=", "$", "error", ";", "}", "return", "$", "this", "->", "renderOutput", "(", "$", "response", ")", ";", "}" ]
Default Error Handler. Yii automatically magics the response when renderOutput is called. This just updates the necessary components for us
[ "Default", "Error", "Handler", ".", "Yii", "automatically", "magics", "the", "response", "when", "renderOutput", "is", "called", ".", "This", "just", "updates", "the", "necessary", "components", "for", "us" ]
4351855328da0b112ac27bde7e7e07e212be8689
https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/components/ApiController.php#L173-L187
train
ciims/ciims-modules-api
components/ApiController.php
ApiController.renderOutput
public function renderOutput($response = array(), $status=NULL, $message=NULL) { http_response_code( $status != NULL ? $status : $this->status ); header('Content-Type: application/json'); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: x-auth-token, x-auth-email"); header('Access-Control-Allow-Methods: PUT, PATCH, DELETE, POST, GET, OPTIONS'); // Back-convert the string to a boolean if ($response === 'false') $response = false; echo CJSON::encode(array( 'status' => $status != NULL ? $status : $this->status, 'message' => $message != NULL ? $message : ($this->message == NULL ? Yii::t('Api.main', 'Your request was successfully fulfilled') : $this->message), 'response' => $response )); Yii::app()->end(); }
php
public function renderOutput($response = array(), $status=NULL, $message=NULL) { http_response_code( $status != NULL ? $status : $this->status ); header('Content-Type: application/json'); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Headers: x-auth-token, x-auth-email"); header('Access-Control-Allow-Methods: PUT, PATCH, DELETE, POST, GET, OPTIONS'); // Back-convert the string to a boolean if ($response === 'false') $response = false; echo CJSON::encode(array( 'status' => $status != NULL ? $status : $this->status, 'message' => $message != NULL ? $message : ($this->message == NULL ? Yii::t('Api.main', 'Your request was successfully fulfilled') : $this->message), 'response' => $response )); Yii::app()->end(); }
[ "public", "function", "renderOutput", "(", "$", "response", "=", "array", "(", ")", ",", "$", "status", "=", "NULL", ",", "$", "message", "=", "NULL", ")", "{", "http_response_code", "(", "$", "status", "!=", "NULL", "?", "$", "status", ":", "$", "this", "->", "status", ")", ";", "header", "(", "'Content-Type: application/json'", ")", ";", "header", "(", "\"Access-Control-Allow-Origin: *\"", ")", ";", "header", "(", "\"Access-Control-Allow-Headers: x-auth-token, x-auth-email\"", ")", ";", "header", "(", "'Access-Control-Allow-Methods: PUT, PATCH, DELETE, POST, GET, OPTIONS'", ")", ";", "// Back-convert the string to a boolean\r", "if", "(", "$", "response", "===", "'false'", ")", "$", "response", "=", "false", ";", "echo", "CJSON", "::", "encode", "(", "array", "(", "'status'", "=>", "$", "status", "!=", "NULL", "?", "$", "status", ":", "$", "this", "->", "status", ",", "'message'", "=>", "$", "message", "!=", "NULL", "?", "$", "message", ":", "(", "$", "this", "->", "message", "==", "NULL", "?", "Yii", "::", "t", "(", "'Api.main'", ",", "'Your request was successfully fulfilled'", ")", ":", "$", "this", "->", "message", ")", ",", "'response'", "=>", "$", "response", ")", ")", ";", "Yii", "::", "app", "(", ")", "->", "end", "(", ")", ";", "}" ]
Outputs the data as JSON @param boolean|null $response the response data
[ "Outputs", "the", "data", "as", "JSON" ]
4351855328da0b112ac27bde7e7e07e212be8689
https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/components/ApiController.php#L235-L253
train
ciims/ciims-modules-api
components/ApiController.php
ApiController.returnError
public function returnError($status, $message = NULL, $response) { header('HTTP/1.1 '. $status); $this->status = $status; if ($message === NULL) $this->message = Yii::t('Api.main', 'Failed to set model attributes.'); else $this->message = $message; // This is a special condition in Yii. We need to convert it back if ($response == false) return 'false'; return $response; }
php
public function returnError($status, $message = NULL, $response) { header('HTTP/1.1 '. $status); $this->status = $status; if ($message === NULL) $this->message = Yii::t('Api.main', 'Failed to set model attributes.'); else $this->message = $message; // This is a special condition in Yii. We need to convert it back if ($response == false) return 'false'; return $response; }
[ "public", "function", "returnError", "(", "$", "status", ",", "$", "message", "=", "NULL", ",", "$", "response", ")", "{", "header", "(", "'HTTP/1.1 '", ".", "$", "status", ")", ";", "$", "this", "->", "status", "=", "$", "status", ";", "if", "(", "$", "message", "===", "NULL", ")", "$", "this", "->", "message", "=", "Yii", "::", "t", "(", "'Api.main'", ",", "'Failed to set model attributes.'", ")", ";", "else", "$", "this", "->", "message", "=", "$", "message", ";", "// This is a special condition in Yii. We need to convert it back\r", "if", "(", "$", "response", "==", "false", ")", "return", "'false'", ";", "return", "$", "response", ";", "}" ]
Performs an error dump with the given status code @param int $status The HTTP Status Code @param string $message The error message @param array $response The error response @return array
[ "Performs", "an", "error", "dump", "with", "the", "given", "status", "code" ]
4351855328da0b112ac27bde7e7e07e212be8689
https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/components/ApiController.php#L262-L277
train
ciims/ciims-modules-api
components/ApiController.php
ApiController.getRole
protected function getRole($role) { if (!isset($this->user)) return false; if (isset($this->user->role)) return $this->user->role->hasPermission($role); return false; }
php
protected function getRole($role) { if (!isset($this->user)) return false; if (isset($this->user->role)) return $this->user->role->hasPermission($role); return false; }
[ "protected", "function", "getRole", "(", "$", "role", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "user", ")", ")", "return", "false", ";", "if", "(", "isset", "(", "$", "this", "->", "user", "->", "role", ")", ")", "return", "$", "this", "->", "user", "->", "role", "->", "hasPermission", "(", "$", "role", ")", ";", "return", "false", ";", "}" ]
Helper function to get the user's role @param integer $role the user's role' @return boolean
[ "Helper", "function", "to", "get", "the", "user", "s", "role" ]
4351855328da0b112ac27bde7e7e07e212be8689
https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/components/ApiController.php#L284-L293
train
stubbles/stubbles-reflect
src/main/php/annotation/Annotation.php
Annotation.getValueByName
public function getValueByName(string $name, $default = null) { if (isset($this->values[$name])) { return $this->parseType($this->values[$name]); } return $default; }
php
public function getValueByName(string $name, $default = null) { if (isset($this->values[$name])) { return $this->parseType($this->values[$name]); } return $default; }
[ "public", "function", "getValueByName", "(", "string", "$", "name", ",", "$", "default", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "values", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "parseType", "(", "$", "this", "->", "values", "[", "$", "name", "]", ")", ";", "}", "return", "$", "default", ";", "}" ]
returns a value by its name Returns null if a value with given name does not exist or is not set. @api @param string $name @param mixed $default optional value to return if value not set @return mixed @since 1.7.0
[ "returns", "a", "value", "by", "its", "name" ]
ab48f9b8692293ef0d276b52619625dbb8869c97
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/Annotation.php#L125-L132
train
stubbles/stubbles-reflect
src/main/php/annotation/Annotation.php
Annotation.parseType
private function parseType(string $value) { if ((substr($value, 0, 1) === '"' && substr($value, -1) === '"') || (substr($value, 0, 1) === "'" && substr($value, -1) === "'")) { return substr($value, 1, strlen($value) - 2); } return Parse::toType($value); }
php
private function parseType(string $value) { if ((substr($value, 0, 1) === '"' && substr($value, -1) === '"') || (substr($value, 0, 1) === "'" && substr($value, -1) === "'")) { return substr($value, 1, strlen($value) - 2); } return Parse::toType($value); }
[ "private", "function", "parseType", "(", "string", "$", "value", ")", "{", "if", "(", "(", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "===", "'\"'", "&&", "substr", "(", "$", "value", ",", "-", "1", ")", "===", "'\"'", ")", "||", "(", "substr", "(", "$", "value", ",", "0", ",", "1", ")", "===", "\"'\"", "&&", "substr", "(", "$", "value", ",", "-", "1", ")", "===", "\"'\"", ")", ")", "{", "return", "substr", "(", "$", "value", ",", "1", ",", "strlen", "(", "$", "value", ")", "-", "2", ")", ";", "}", "return", "Parse", "::", "toType", "(", "$", "value", ")", ";", "}" ]
parses value to correct type @param string $value @return mixed
[ "parses", "value", "to", "correct", "type" ]
ab48f9b8692293ef0d276b52619625dbb8869c97
https://github.com/stubbles/stubbles-reflect/blob/ab48f9b8692293ef0d276b52619625dbb8869c97/src/main/php/annotation/Annotation.php#L231-L238
train
redkite-labs/ThemeEngineBundle
Core/Rendering/DependencyInjection/BaseExtension.php
BaseExtension.loadConfigurationRecursive
protected function loadConfigurationRecursive(ContainerBuilder $container, array $configuration) { foreach ($configuration as $values) { $loader = new XmlFileLoader($container, new FileLocator($values['path'])); foreach ($values['configFiles'] as $configFile) { $loader->load($configFile); } if (array_key_exists('configuration', $values)) { $this->loadConfigurationRecursive($container, $values['configuration']); } } }
php
protected function loadConfigurationRecursive(ContainerBuilder $container, array $configuration) { foreach ($configuration as $values) { $loader = new XmlFileLoader($container, new FileLocator($values['path'])); foreach ($values['configFiles'] as $configFile) { $loader->load($configFile); } if (array_key_exists('configuration', $values)) { $this->loadConfigurationRecursive($container, $values['configuration']); } } }
[ "protected", "function", "loadConfigurationRecursive", "(", "ContainerBuilder", "$", "container", ",", "array", "$", "configuration", ")", "{", "foreach", "(", "$", "configuration", "as", "$", "values", ")", "{", "$", "loader", "=", "new", "XmlFileLoader", "(", "$", "container", ",", "new", "FileLocator", "(", "$", "values", "[", "'path'", "]", ")", ")", ";", "foreach", "(", "$", "values", "[", "'configFiles'", "]", "as", "$", "configFile", ")", "{", "$", "loader", "->", "load", "(", "$", "configFile", ")", ";", "}", "if", "(", "array_key_exists", "(", "'configuration'", ",", "$", "values", ")", ")", "{", "$", "this", "->", "loadConfigurationRecursive", "(", "$", "container", ",", "$", "values", "[", "'configuration'", "]", ")", ";", "}", "}", "}" ]
Loads the them configuration recursively @param \Symfony\Component\DependencyInjection\ContainerBuilder $container @param array $configuration
[ "Loads", "the", "them", "configuration", "recursively" ]
427409110f2d4f8f39d8802c17d5dd4115cbdf2b
https://github.com/redkite-labs/ThemeEngineBundle/blob/427409110f2d4f8f39d8802c17d5dd4115cbdf2b/Core/Rendering/DependencyInjection/BaseExtension.php#L67-L78
train
ekyna/PaymentBundle
DependencyInjection/Configuration.php
Configuration.addPoolsSection
private function addPoolsSection(ArrayNodeDefinition $node) { $node ->children() ->arrayNode('pools') ->addDefaultsIfNotSet() ->children() ->arrayNode('method') ->addDefaultsIfNotSet() ->children() ->variableNode('templates')->defaultValue([ '_form.html' => 'EkynaPaymentBundle:Admin/Method:_form.html', 'show.html' => 'EkynaPaymentBundle:Admin/Method:show.html', 'new.html' => 'EkynaPaymentBundle:Admin/Method:new.html', ])->end() ->scalarNode('parent')->end() ->scalarNode('entity')->defaultValue('Ekyna\Bundle\PaymentBundle\Entity\Method')->end() ->scalarNode('controller')->defaultValue('Ekyna\Bundle\PaymentBundle\Controller\Admin\MethodController')->end() ->scalarNode('operator')->end() ->scalarNode('repository')->defaultValue('Ekyna\Bundle\PaymentBundle\Entity\MethodRepository')->end() ->scalarNode('form')->defaultValue('Ekyna\Bundle\PaymentBundle\Form\Type\MethodType')->end() ->scalarNode('table')->defaultValue('Ekyna\Bundle\PaymentBundle\Table\Type\MethodType')->end() ->scalarNode('event')->end() ->end() ->end() ->end() ->end() ->end() ; }
php
private function addPoolsSection(ArrayNodeDefinition $node) { $node ->children() ->arrayNode('pools') ->addDefaultsIfNotSet() ->children() ->arrayNode('method') ->addDefaultsIfNotSet() ->children() ->variableNode('templates')->defaultValue([ '_form.html' => 'EkynaPaymentBundle:Admin/Method:_form.html', 'show.html' => 'EkynaPaymentBundle:Admin/Method:show.html', 'new.html' => 'EkynaPaymentBundle:Admin/Method:new.html', ])->end() ->scalarNode('parent')->end() ->scalarNode('entity')->defaultValue('Ekyna\Bundle\PaymentBundle\Entity\Method')->end() ->scalarNode('controller')->defaultValue('Ekyna\Bundle\PaymentBundle\Controller\Admin\MethodController')->end() ->scalarNode('operator')->end() ->scalarNode('repository')->defaultValue('Ekyna\Bundle\PaymentBundle\Entity\MethodRepository')->end() ->scalarNode('form')->defaultValue('Ekyna\Bundle\PaymentBundle\Form\Type\MethodType')->end() ->scalarNode('table')->defaultValue('Ekyna\Bundle\PaymentBundle\Table\Type\MethodType')->end() ->scalarNode('event')->end() ->end() ->end() ->end() ->end() ->end() ; }
[ "private", "function", "addPoolsSection", "(", "ArrayNodeDefinition", "$", "node", ")", "{", "$", "node", "->", "children", "(", ")", "->", "arrayNode", "(", "'pools'", ")", "->", "addDefaultsIfNotSet", "(", ")", "->", "children", "(", ")", "->", "arrayNode", "(", "'method'", ")", "->", "addDefaultsIfNotSet", "(", ")", "->", "children", "(", ")", "->", "variableNode", "(", "'templates'", ")", "->", "defaultValue", "(", "[", "'_form.html'", "=>", "'EkynaPaymentBundle:Admin/Method:_form.html'", ",", "'show.html'", "=>", "'EkynaPaymentBundle:Admin/Method:show.html'", ",", "'new.html'", "=>", "'EkynaPaymentBundle:Admin/Method:new.html'", ",", "]", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'parent'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'entity'", ")", "->", "defaultValue", "(", "'Ekyna\\Bundle\\PaymentBundle\\Entity\\Method'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'controller'", ")", "->", "defaultValue", "(", "'Ekyna\\Bundle\\PaymentBundle\\Controller\\Admin\\MethodController'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'operator'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'repository'", ")", "->", "defaultValue", "(", "'Ekyna\\Bundle\\PaymentBundle\\Entity\\MethodRepository'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'form'", ")", "->", "defaultValue", "(", "'Ekyna\\Bundle\\PaymentBundle\\Form\\Type\\MethodType'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'table'", ")", "->", "defaultValue", "(", "'Ekyna\\Bundle\\PaymentBundle\\Table\\Type\\MethodType'", ")", "->", "end", "(", ")", "->", "scalarNode", "(", "'event'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "end", "(", ")", ";", "}" ]
Adds admin pool sections. @param ArrayNodeDefinition $node
[ "Adds", "admin", "pool", "sections", "." ]
1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1
https://github.com/ekyna/PaymentBundle/blob/1b4f4103b28e3a4f8dbfac2cbd872d728238f4d1/DependencyInjection/Configuration.php#L34-L63
train
byjg/authuser
src/UsersDBDataset.php
UsersDBDataset.getIterator
public function getIterator(IteratorFilter $filter = null) { if (is_null($filter)) { $filter = new IteratorFilter(); } $param = []; $formatter = new IteratorFilterSqlFormatter(); $sql = $formatter->getFilter($filter->getRawFilters(), $param); $query = Query::getInstance() ->table($this->getUserDefinition()->table()) ->where($sql, $param); return $this->userRepository->getByQuery($query); }
php
public function getIterator(IteratorFilter $filter = null) { if (is_null($filter)) { $filter = new IteratorFilter(); } $param = []; $formatter = new IteratorFilterSqlFormatter(); $sql = $formatter->getFilter($filter->getRawFilters(), $param); $query = Query::getInstance() ->table($this->getUserDefinition()->table()) ->where($sql, $param); return $this->userRepository->getByQuery($query); }
[ "public", "function", "getIterator", "(", "IteratorFilter", "$", "filter", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "filter", ")", ")", "{", "$", "filter", "=", "new", "IteratorFilter", "(", ")", ";", "}", "$", "param", "=", "[", "]", ";", "$", "formatter", "=", "new", "IteratorFilterSqlFormatter", "(", ")", ";", "$", "sql", "=", "$", "formatter", "->", "getFilter", "(", "$", "filter", "->", "getRawFilters", "(", ")", ",", "$", "param", ")", ";", "$", "query", "=", "Query", "::", "getInstance", "(", ")", "->", "table", "(", "$", "this", "->", "getUserDefinition", "(", ")", "->", "table", "(", ")", ")", "->", "where", "(", "$", "sql", ",", "$", "param", ")", ";", "return", "$", "this", "->", "userRepository", "->", "getByQuery", "(", "$", "query", ")", ";", "}" ]
Get the users database information based on a filter. @param IteratorFilter $filter Filter to find user @return UserModel[] @throws \ByJG\MicroOrm\Exception\InvalidArgumentException @throws \ByJG\Serializer\Exception\InvalidArgumentException
[ "Get", "the", "users", "database", "information", "based", "on", "a", "filter", "." ]
2ca520e921e559257d14dd933c746a1df28eaf9f
https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersDBDataset.php#L134-L149
train
byjg/authuser
src/UsersDBDataset.php
UsersDBDataset.removeByLoginField
public function removeByLoginField($login) { $user = $this->getByLoginField($login); if ($user !== null) { return $this->removeUserById($user->getUserid()); } return false; }
php
public function removeByLoginField($login) { $user = $this->getByLoginField($login); if ($user !== null) { return $this->removeUserById($user->getUserid()); } return false; }
[ "public", "function", "removeByLoginField", "(", "$", "login", ")", "{", "$", "user", "=", "$", "this", "->", "getByLoginField", "(", "$", "login", ")", ";", "if", "(", "$", "user", "!==", "null", ")", "{", "return", "$", "this", "->", "removeUserById", "(", "$", "user", "->", "getUserid", "(", ")", ")", ";", "}", "return", "false", ";", "}" ]
Remove the user based on his user login. @param string $login @return bool @throws \Exception
[ "Remove", "the", "user", "based", "on", "his", "user", "login", "." ]
2ca520e921e559257d14dd933c746a1df28eaf9f
https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersDBDataset.php#L181-L190
train
byjg/authuser
src/UsersDBDataset.php
UsersDBDataset.removeUserById
public function removeUserById($userId) { $updtableProperties = Updatable::getInstance() ->table($this->getUserPropertiesDefinition()->table()) ->where( "{$this->getUserPropertiesDefinition()->getUserid()} = :id", [ "id" => $userId ] ); $this->propertiesRepository->deleteByQuery($updtableProperties); $this->userRepository->delete($userId); return true; }
php
public function removeUserById($userId) { $updtableProperties = Updatable::getInstance() ->table($this->getUserPropertiesDefinition()->table()) ->where( "{$this->getUserPropertiesDefinition()->getUserid()} = :id", [ "id" => $userId ] ); $this->propertiesRepository->deleteByQuery($updtableProperties); $this->userRepository->delete($userId); return true; }
[ "public", "function", "removeUserById", "(", "$", "userId", ")", "{", "$", "updtableProperties", "=", "Updatable", "::", "getInstance", "(", ")", "->", "table", "(", "$", "this", "->", "getUserPropertiesDefinition", "(", ")", "->", "table", "(", ")", ")", "->", "where", "(", "\"{$this->getUserPropertiesDefinition()->getUserid()} = :id\"", ",", "[", "\"id\"", "=>", "$", "userId", "]", ")", ";", "$", "this", "->", "propertiesRepository", "->", "deleteByQuery", "(", "$", "updtableProperties", ")", ";", "$", "this", "->", "userRepository", "->", "delete", "(", "$", "userId", ")", ";", "return", "true", ";", "}" ]
Remove the user based on his user id. @param mixed $userId @return bool @throws \Exception
[ "Remove", "the", "user", "based", "on", "his", "user", "id", "." ]
2ca520e921e559257d14dd933c746a1df28eaf9f
https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersDBDataset.php#L199-L214
train
byjg/authuser
src/UsersDBDataset.php
UsersDBDataset.removeProperty
public function removeProperty($userId, $propertyName, $value = null) { $user = $this->getById($userId); if ($user !== null) { $updateable = Updatable::getInstance() ->table($this->getUserPropertiesDefinition()->table()) ->where("{$this->getUserPropertiesDefinition()->getUserid()} = :id", ["id" => $userId]) ->where("{$this->getUserPropertiesDefinition()->getName()} = :name", ["name" => $propertyName]); if (!empty($value)) { $updateable->where("{$this->getUserPropertiesDefinition()->getValue()} = :value", ["value" => $value]); } $this->propertiesRepository->deleteByQuery($updateable); return true; } return false; }
php
public function removeProperty($userId, $propertyName, $value = null) { $user = $this->getById($userId); if ($user !== null) { $updateable = Updatable::getInstance() ->table($this->getUserPropertiesDefinition()->table()) ->where("{$this->getUserPropertiesDefinition()->getUserid()} = :id", ["id" => $userId]) ->where("{$this->getUserPropertiesDefinition()->getName()} = :name", ["name" => $propertyName]); if (!empty($value)) { $updateable->where("{$this->getUserPropertiesDefinition()->getValue()} = :value", ["value" => $value]); } $this->propertiesRepository->deleteByQuery($updateable); return true; } return false; }
[ "public", "function", "removeProperty", "(", "$", "userId", ",", "$", "propertyName", ",", "$", "value", "=", "null", ")", "{", "$", "user", "=", "$", "this", "->", "getById", "(", "$", "userId", ")", ";", "if", "(", "$", "user", "!==", "null", ")", "{", "$", "updateable", "=", "Updatable", "::", "getInstance", "(", ")", "->", "table", "(", "$", "this", "->", "getUserPropertiesDefinition", "(", ")", "->", "table", "(", ")", ")", "->", "where", "(", "\"{$this->getUserPropertiesDefinition()->getUserid()} = :id\"", ",", "[", "\"id\"", "=>", "$", "userId", "]", ")", "->", "where", "(", "\"{$this->getUserPropertiesDefinition()->getName()} = :name\"", ",", "[", "\"name\"", "=>", "$", "propertyName", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "updateable", "->", "where", "(", "\"{$this->getUserPropertiesDefinition()->getValue()} = :value\"", ",", "[", "\"value\"", "=>", "$", "value", "]", ")", ";", "}", "$", "this", "->", "propertiesRepository", "->", "deleteByQuery", "(", "$", "updateable", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
Remove a specific site from user Return True or false @param int $userId User Id @param string $propertyName Property name @param string $value Property value with a site @return bool @throws \ByJG\MicroOrm\Exception\InvalidArgumentException @throws \ByJG\Serializer\Exception\InvalidArgumentException
[ "Remove", "a", "specific", "site", "from", "user", "Return", "True", "or", "false" ]
2ca520e921e559257d14dd933c746a1df28eaf9f
https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersDBDataset.php#L254-L274
train
byjg/authuser
src/UsersDBDataset.php
UsersDBDataset.setPropertiesInUser
protected function setPropertiesInUser(UserModel $userRow) { $query = Query::getInstance() ->table($this->getUserPropertiesDefinition()->table()) ->where("{$this->getUserPropertiesDefinition()->getUserid()} = :id", ['id' =>$userRow->getUserid()]); $userRow->setProperties($this->propertiesRepository->getByQuery($query)); }
php
protected function setPropertiesInUser(UserModel $userRow) { $query = Query::getInstance() ->table($this->getUserPropertiesDefinition()->table()) ->where("{$this->getUserPropertiesDefinition()->getUserid()} = :id", ['id' =>$userRow->getUserid()]); $userRow->setProperties($this->propertiesRepository->getByQuery($query)); }
[ "protected", "function", "setPropertiesInUser", "(", "UserModel", "$", "userRow", ")", "{", "$", "query", "=", "Query", "::", "getInstance", "(", ")", "->", "table", "(", "$", "this", "->", "getUserPropertiesDefinition", "(", ")", "->", "table", "(", ")", ")", "->", "where", "(", "\"{$this->getUserPropertiesDefinition()->getUserid()} = :id\"", ",", "[", "'id'", "=>", "$", "userRow", "->", "getUserid", "(", ")", "]", ")", ";", "$", "userRow", "->", "setProperties", "(", "$", "this", "->", "propertiesRepository", "->", "getByQuery", "(", "$", "query", ")", ")", ";", "}" ]
Return all property's fields from this user @param UserModel $userRow @throws \ByJG\MicroOrm\Exception\InvalidArgumentException @throws \ByJG\Serializer\Exception\InvalidArgumentException
[ "Return", "all", "property", "s", "fields", "from", "this", "user" ]
2ca520e921e559257d14dd933c746a1df28eaf9f
https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersDBDataset.php#L307-L313
train
ptlis/grep-db
src/Search/Search.php
Search.searchServer
public function searchServer( Connection $connection, string $searchTerm ): \Generator { $serverMetadata = (new MetadataFactory())->getServerMetadata($connection); foreach ($serverMetadata->getAllDatabaseMetadata() as $databaseMetadata) { $resultList = $this->searchDatabase( $connection, $databaseMetadata->getDatabaseName(), $searchTerm ); foreach ($resultList as $result) { yield $result; } } }
php
public function searchServer( Connection $connection, string $searchTerm ): \Generator { $serverMetadata = (new MetadataFactory())->getServerMetadata($connection); foreach ($serverMetadata->getAllDatabaseMetadata() as $databaseMetadata) { $resultList = $this->searchDatabase( $connection, $databaseMetadata->getDatabaseName(), $searchTerm ); foreach ($resultList as $result) { yield $result; } } }
[ "public", "function", "searchServer", "(", "Connection", "$", "connection", ",", "string", "$", "searchTerm", ")", ":", "\\", "Generator", "{", "$", "serverMetadata", "=", "(", "new", "MetadataFactory", "(", ")", ")", "->", "getServerMetadata", "(", "$", "connection", ")", ";", "foreach", "(", "$", "serverMetadata", "->", "getAllDatabaseMetadata", "(", ")", "as", "$", "databaseMetadata", ")", "{", "$", "resultList", "=", "$", "this", "->", "searchDatabase", "(", "$", "connection", ",", "$", "databaseMetadata", "->", "getDatabaseName", "(", ")", ",", "$", "searchTerm", ")", ";", "foreach", "(", "$", "resultList", "as", "$", "result", ")", "{", "yield", "$", "result", ";", "}", "}", "}" ]
Performs a search across databases on a server. @param Connection $connection @param string $searchTerm @return \Generator|RowSearchResult[]
[ "Performs", "a", "search", "across", "databases", "on", "a", "server", "." ]
7abff68982d426690d0515ccd7adc7a2e3d72a3f
https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Search/Search.php#L28-L45
train
ptlis/grep-db
src/Search/Search.php
Search.searchDatabase
public function searchDatabase( Connection $connection, string $databaseName, string $searchTerm ): \Generator { $databaseMetadata = (new MetadataFactory())->getDatabaseMetadata($connection, $databaseName); foreach ($databaseMetadata->getAllTableMetadata() as $tableMetadata) { $resultList = $this->searchTable( $connection, $tableMetadata->getDatabaseName(), $tableMetadata->getTableName(), $searchTerm ); foreach ($resultList as $result) { yield $result; } } }
php
public function searchDatabase( Connection $connection, string $databaseName, string $searchTerm ): \Generator { $databaseMetadata = (new MetadataFactory())->getDatabaseMetadata($connection, $databaseName); foreach ($databaseMetadata->getAllTableMetadata() as $tableMetadata) { $resultList = $this->searchTable( $connection, $tableMetadata->getDatabaseName(), $tableMetadata->getTableName(), $searchTerm ); foreach ($resultList as $result) { yield $result; } } }
[ "public", "function", "searchDatabase", "(", "Connection", "$", "connection", ",", "string", "$", "databaseName", ",", "string", "$", "searchTerm", ")", ":", "\\", "Generator", "{", "$", "databaseMetadata", "=", "(", "new", "MetadataFactory", "(", ")", ")", "->", "getDatabaseMetadata", "(", "$", "connection", ",", "$", "databaseName", ")", ";", "foreach", "(", "$", "databaseMetadata", "->", "getAllTableMetadata", "(", ")", "as", "$", "tableMetadata", ")", "{", "$", "resultList", "=", "$", "this", "->", "searchTable", "(", "$", "connection", ",", "$", "tableMetadata", "->", "getDatabaseName", "(", ")", ",", "$", "tableMetadata", "->", "getTableName", "(", ")", ",", "$", "searchTerm", ")", ";", "foreach", "(", "$", "resultList", "as", "$", "result", ")", "{", "yield", "$", "result", ";", "}", "}", "}" ]
Performs a search across tables in a database. @param Connection $connection @param string $databaseName @param string $searchTerm @return \Generator|RowSearchResult[]
[ "Performs", "a", "search", "across", "tables", "in", "a", "database", "." ]
7abff68982d426690d0515ccd7adc7a2e3d72a3f
https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Search/Search.php#L55-L74
train
ptlis/grep-db
src/Search/Search.php
Search.searchTable
public function searchTable( Connection $connection, string $databaseName, string $tableName, string $searchTerm ): \Generator { $tableMetadata = (new MetadataFactory())->getTableMetadata($connection, $databaseName, $tableName); if (!$tableMetadata->hasStringTypeColumn()) { return; } $rowResultList = (new StringMatchTableSearchStrategy())->getMatches( $connection, $tableMetadata, $searchTerm ); // Yield batch tracking rows returned foreach ($rowResultList as $rowResult) { yield $rowResult; } }
php
public function searchTable( Connection $connection, string $databaseName, string $tableName, string $searchTerm ): \Generator { $tableMetadata = (new MetadataFactory())->getTableMetadata($connection, $databaseName, $tableName); if (!$tableMetadata->hasStringTypeColumn()) { return; } $rowResultList = (new StringMatchTableSearchStrategy())->getMatches( $connection, $tableMetadata, $searchTerm ); // Yield batch tracking rows returned foreach ($rowResultList as $rowResult) { yield $rowResult; } }
[ "public", "function", "searchTable", "(", "Connection", "$", "connection", ",", "string", "$", "databaseName", ",", "string", "$", "tableName", ",", "string", "$", "searchTerm", ")", ":", "\\", "Generator", "{", "$", "tableMetadata", "=", "(", "new", "MetadataFactory", "(", ")", ")", "->", "getTableMetadata", "(", "$", "connection", ",", "$", "databaseName", ",", "$", "tableName", ")", ";", "if", "(", "!", "$", "tableMetadata", "->", "hasStringTypeColumn", "(", ")", ")", "{", "return", ";", "}", "$", "rowResultList", "=", "(", "new", "StringMatchTableSearchStrategy", "(", ")", ")", "->", "getMatches", "(", "$", "connection", ",", "$", "tableMetadata", ",", "$", "searchTerm", ")", ";", "// Yield batch tracking rows returned", "foreach", "(", "$", "rowResultList", "as", "$", "rowResult", ")", "{", "yield", "$", "rowResult", ";", "}", "}" ]
Performs a search on the provided table. @param Connection $connection @param string $databaseName @param string $tableName @param string $searchTerm @return \Generator|RowSearchResult[]
[ "Performs", "a", "search", "on", "the", "provided", "table", "." ]
7abff68982d426690d0515ccd7adc7a2e3d72a3f
https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Search/Search.php#L85-L107
train
zenodorus-tools/filesystem
src/Filesystem.php
Filesystem.slash
public static function slash(string ...$sections) { $count = count($sections); // If we only got a single section, return it. if (1 === $count) { return $sections[0]; } // Somehow we got NO sections, so return null. elseif (0 >= $count || empty($sections)) { return null; } // Only two sections; concatenated and return! elseif (2 === $count) { $compiled = sprintf( "%s%s%s", trim($sections[0]), DIRECTORY_SEPARATOR, trim($sections[1]) ); // Check for double-slashes return preg_replace( '/\\\\{2,}|\/{2,}/', DIRECTORY_SEPARATOR, $compiled ); } // Multiple sections, so let's get recursive! else { $append = array_shift($sections); $prepend = array_shift($sections); $compiled = static::slash($append, $prepend); return static::slashAr(array_merge([$compiled], $sections)); } }
php
public static function slash(string ...$sections) { $count = count($sections); // If we only got a single section, return it. if (1 === $count) { return $sections[0]; } // Somehow we got NO sections, so return null. elseif (0 >= $count || empty($sections)) { return null; } // Only two sections; concatenated and return! elseif (2 === $count) { $compiled = sprintf( "%s%s%s", trim($sections[0]), DIRECTORY_SEPARATOR, trim($sections[1]) ); // Check for double-slashes return preg_replace( '/\\\\{2,}|\/{2,}/', DIRECTORY_SEPARATOR, $compiled ); } // Multiple sections, so let's get recursive! else { $append = array_shift($sections); $prepend = array_shift($sections); $compiled = static::slash($append, $prepend); return static::slashAr(array_merge([$compiled], $sections)); } }
[ "public", "static", "function", "slash", "(", "string", "...", "$", "sections", ")", "{", "$", "count", "=", "count", "(", "$", "sections", ")", ";", "// If we only got a single section, return it.", "if", "(", "1", "===", "$", "count", ")", "{", "return", "$", "sections", "[", "0", "]", ";", "}", "// Somehow we got NO sections, so return null.", "elseif", "(", "0", ">=", "$", "count", "||", "empty", "(", "$", "sections", ")", ")", "{", "return", "null", ";", "}", "// Only two sections; concatenated and return!", "elseif", "(", "2", "===", "$", "count", ")", "{", "$", "compiled", "=", "sprintf", "(", "\"%s%s%s\"", ",", "trim", "(", "$", "sections", "[", "0", "]", ")", ",", "DIRECTORY_SEPARATOR", ",", "trim", "(", "$", "sections", "[", "1", "]", ")", ")", ";", "// Check for double-slashes", "return", "preg_replace", "(", "'/\\\\\\\\{2,}|\\/{2,}/'", ",", "DIRECTORY_SEPARATOR", ",", "$", "compiled", ")", ";", "}", "// Multiple sections, so let's get recursive!", "else", "{", "$", "append", "=", "array_shift", "(", "$", "sections", ")", ";", "$", "prepend", "=", "array_shift", "(", "$", "sections", ")", ";", "$", "compiled", "=", "static", "::", "slash", "(", "$", "append", ",", "$", "prepend", ")", ";", "return", "static", "::", "slashAr", "(", "array_merge", "(", "[", "$", "compiled", "]", ",", "$", "sections", ")", ")", ";", "}", "}" ]
Combine strings with a directory separator. Accepts any number of strings. This is purely string manipulation: Although this function will likely be used for paths, it does no path validation of any sort. @param string[] ...$sections All strings you wish to concatenate. @return string
[ "Combine", "strings", "with", "a", "directory", "separator", "." ]
210d098fa9cc7f261d68402667763497cba1fba0
https://github.com/zenodorus-tools/filesystem/blob/210d098fa9cc7f261d68402667763497cba1fba0/src/Filesystem.php#L16-L48
train
zenodorus-tools/filesystem
src/Filesystem.php
Filesystem.resolve
public static function resolve(string $path, bool $absolute = false) { $path = static::normalize($path); if (strpos($path, DIRECTORY_SEPARATOR) === 0) { // This was an absolute string, so keep it that way. $absolute = true; } /** @noinspection SpellCheckingInspection */ $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen'); $absolutes = array(); foreach ($parts as $part) { if ('.' == $part) { continue; } if ('..' == $part) { array_pop($absolutes); } else { $absolutes[] = $part; } } $newPath = implode(DIRECTORY_SEPARATOR, $absolutes); if ($absolute === true) { $newPath = sprintf("%s%s", DIRECTORY_SEPARATOR, $newPath); } return $newPath; }
php
public static function resolve(string $path, bool $absolute = false) { $path = static::normalize($path); if (strpos($path, DIRECTORY_SEPARATOR) === 0) { // This was an absolute string, so keep it that way. $absolute = true; } /** @noinspection SpellCheckingInspection */ $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen'); $absolutes = array(); foreach ($parts as $part) { if ('.' == $part) { continue; } if ('..' == $part) { array_pop($absolutes); } else { $absolutes[] = $part; } } $newPath = implode(DIRECTORY_SEPARATOR, $absolutes); if ($absolute === true) { $newPath = sprintf("%s%s", DIRECTORY_SEPARATOR, $newPath); } return $newPath; }
[ "public", "static", "function", "resolve", "(", "string", "$", "path", ",", "bool", "$", "absolute", "=", "false", ")", "{", "$", "path", "=", "static", "::", "normalize", "(", "$", "path", ")", ";", "if", "(", "strpos", "(", "$", "path", ",", "DIRECTORY_SEPARATOR", ")", "===", "0", ")", "{", "// This was an absolute string, so keep it that way.", "$", "absolute", "=", "true", ";", "}", "/** @noinspection SpellCheckingInspection */", "$", "parts", "=", "array_filter", "(", "explode", "(", "DIRECTORY_SEPARATOR", ",", "$", "path", ")", ",", "'strlen'", ")", ";", "$", "absolutes", "=", "array", "(", ")", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{", "if", "(", "'.'", "==", "$", "part", ")", "{", "continue", ";", "}", "if", "(", "'..'", "==", "$", "part", ")", "{", "array_pop", "(", "$", "absolutes", ")", ";", "}", "else", "{", "$", "absolutes", "[", "]", "=", "$", "part", ";", "}", "}", "$", "newPath", "=", "implode", "(", "DIRECTORY_SEPARATOR", ",", "$", "absolutes", ")", ";", "if", "(", "$", "absolute", "===", "true", ")", "{", "$", "newPath", "=", "sprintf", "(", "\"%s%s\"", ",", "DIRECTORY_SEPARATOR", ",", "$", "newPath", ")", ";", "}", "return", "$", "newPath", ";", "}" ]
Naively resolve paths. This attempts to discern the correct directory path from something that contains relative indicators (i.e. `../`). It does not touch the actual filesystem, so do not assume that these paths are accurate, or that they even exist. Notably, this means that you can use this to deal with symlinks (Specifically you can look at their locations without resolving their targets.) @link http://www.php.net/manual/en/function.realpath.php#84012 @param string $path @param boolean $absolute Set to `true` to prepend a directory separator. @return string
[ "Naively", "resolve", "paths", "." ]
210d098fa9cc7f261d68402667763497cba1fba0
https://github.com/zenodorus-tools/filesystem/blob/210d098fa9cc7f261d68402667763497cba1fba0/src/Filesystem.php#L94-L121
train
zenodorus-tools/filesystem
src/Filesystem.php
Filesystem.resolveReal
public static function resolveReal(string $path, string $workingDir = null) { if (null === $workingDir /** * Path includes full (absolute) path, which doesn't need * working directory. */ && file_exists($real = Filesystem::resolve($path))) { return $real; } elseif (null !== $workingDir) { /** * ...Otherwise, add $workingDir before trying to find it. */ $fullPath = Filesystem::slash($workingDir, $path); $real = Filesystem::resolve($fullPath); return file_exists($real) ? $real : null; } return null; }
php
public static function resolveReal(string $path, string $workingDir = null) { if (null === $workingDir /** * Path includes full (absolute) path, which doesn't need * working directory. */ && file_exists($real = Filesystem::resolve($path))) { return $real; } elseif (null !== $workingDir) { /** * ...Otherwise, add $workingDir before trying to find it. */ $fullPath = Filesystem::slash($workingDir, $path); $real = Filesystem::resolve($fullPath); return file_exists($real) ? $real : null; } return null; }
[ "public", "static", "function", "resolveReal", "(", "string", "$", "path", ",", "string", "$", "workingDir", "=", "null", ")", "{", "if", "(", "null", "===", "$", "workingDir", "/**\n * Path includes full (absolute) path, which doesn't need\n * working directory.\n */", "&&", "file_exists", "(", "$", "real", "=", "Filesystem", "::", "resolve", "(", "$", "path", ")", ")", ")", "{", "return", "$", "real", ";", "}", "elseif", "(", "null", "!==", "$", "workingDir", ")", "{", "/**\n * ...Otherwise, add $workingDir before trying to find it.\n */", "$", "fullPath", "=", "Filesystem", "::", "slash", "(", "$", "workingDir", ",", "$", "path", ")", ";", "$", "real", "=", "Filesystem", "::", "resolve", "(", "$", "fullPath", ")", ";", "return", "file_exists", "(", "$", "real", ")", "?", "$", "real", ":", "null", ";", "}", "return", "null", ";", "}" ]
Resolve paths to real locations. A wrapper for `Filesystem::resolve()` that returns real paths. It will fully evaluate symbolic links, so they will return their targets. If a directory/file does not exist, this method returns `null`. In certain situations, this may return `null` for files that are, technically accessible (see php.net documentation for `file_exists()`). This will always return an absolute path. @see https://secure.php.net/manual/en/function.file-exists.php @param string $path @param string|null $workingDir The directory to use as the base. @return bool|string Real path if it exists, bool false otherwise.
[ "Resolve", "paths", "to", "real", "locations", "." ]
210d098fa9cc7f261d68402667763497cba1fba0
https://github.com/zenodorus-tools/filesystem/blob/210d098fa9cc7f261d68402667763497cba1fba0/src/Filesystem.php#L142-L161
train
zenodorus-tools/filesystem
src/Filesystem.php
Filesystem.recursiveRemove
public static function recursiveRemove(string $dir, bool $complete = true) { $di = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); $ri = new \RecursiveIteratorIterator($di, \RecursiveIteratorIterator::CHILD_FIRST); foreach ($ri as $file) { $file->isDir() ? rmdir($file) : unlink($file); } if ($complete) { rmdir($dir); } return true; }
php
public static function recursiveRemove(string $dir, bool $complete = true) { $di = new \RecursiveDirectoryIterator($dir, \FilesystemIterator::SKIP_DOTS); $ri = new \RecursiveIteratorIterator($di, \RecursiveIteratorIterator::CHILD_FIRST); foreach ($ri as $file) { $file->isDir() ? rmdir($file) : unlink($file); } if ($complete) { rmdir($dir); } return true; }
[ "public", "static", "function", "recursiveRemove", "(", "string", "$", "dir", ",", "bool", "$", "complete", "=", "true", ")", "{", "$", "di", "=", "new", "\\", "RecursiveDirectoryIterator", "(", "$", "dir", ",", "\\", "FilesystemIterator", "::", "SKIP_DOTS", ")", ";", "$", "ri", "=", "new", "\\", "RecursiveIteratorIterator", "(", "$", "di", ",", "\\", "RecursiveIteratorIterator", "::", "CHILD_FIRST", ")", ";", "foreach", "(", "$", "ri", "as", "$", "file", ")", "{", "$", "file", "->", "isDir", "(", ")", "?", "rmdir", "(", "$", "file", ")", ":", "unlink", "(", "$", "file", ")", ";", "}", "if", "(", "$", "complete", ")", "{", "rmdir", "(", "$", "dir", ")", ";", "}", "return", "true", ";", "}" ]
Removes all files and directories in a directory. BE CAREFUL! By default, this includes directory specified in `$dir`. Pass `false` to the second argument to disable this behavior and leave `$dir` in place. @see https://stackoverflow.com/a/24563703 @param string $dir @param boolean $complete @return boolean
[ "Removes", "all", "files", "and", "directories", "in", "a", "directory", ".", "BE", "CAREFUL!" ]
210d098fa9cc7f261d68402667763497cba1fba0
https://github.com/zenodorus-tools/filesystem/blob/210d098fa9cc7f261d68402667763497cba1fba0/src/Filesystem.php#L175-L186
train
spyrit/PropelDatagridBundle
Datagrid/PropelDatagrid.php
PropelDatagrid.getPaginationPath
public function getPaginationPath($route, $page, $extraParams = array()) { $params = array( $this->getActionParameterName() => $this->getPageActionParameterName(), $this->getDatagridParameterName() => $this->getName(), $this->getPageParameterName() => $page, ); return $this->container->get('router')->generate($route, array_merge($params, $extraParams)); }
php
public function getPaginationPath($route, $page, $extraParams = array()) { $params = array( $this->getActionParameterName() => $this->getPageActionParameterName(), $this->getDatagridParameterName() => $this->getName(), $this->getPageParameterName() => $page, ); return $this->container->get('router')->generate($route, array_merge($params, $extraParams)); }
[ "public", "function", "getPaginationPath", "(", "$", "route", ",", "$", "page", ",", "$", "extraParams", "=", "array", "(", ")", ")", "{", "$", "params", "=", "array", "(", "$", "this", "->", "getActionParameterName", "(", ")", "=>", "$", "this", "->", "getPageActionParameterName", "(", ")", ",", "$", "this", "->", "getDatagridParameterName", "(", ")", "=>", "$", "this", "->", "getName", "(", ")", ",", "$", "this", "->", "getPageParameterName", "(", ")", "=>", "$", "page", ",", ")", ";", "return", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "generate", "(", "$", "route", ",", "array_merge", "(", "$", "params", ",", "$", "extraParams", ")", ")", ";", "}" ]
Generate pagination route @param type $route @param type $extraParams @return type
[ "Generate", "pagination", "route" ]
2c12ad90e8e6f44dc106a4512225c1ec68871076
https://github.com/spyrit/PropelDatagridBundle/blob/2c12ad90e8e6f44dc106a4512225c1ec68871076/Datagrid/PropelDatagrid.php#L462-L470
train
spyrit/PropelDatagridBundle
Datagrid/PropelDatagrid.php
PropelDatagrid.getResetPath
public function getResetPath($route, $extraParams = array()) { $params = array( $this->getActionParameterName() => $this->getResetActionParameterName(), $this->getDatagridParameterName() => $this->getName(), ); return $this->container->get('router')->generate($route, array_merge($params, $extraParams)); }
php
public function getResetPath($route, $extraParams = array()) { $params = array( $this->getActionParameterName() => $this->getResetActionParameterName(), $this->getDatagridParameterName() => $this->getName(), ); return $this->container->get('router')->generate($route, array_merge($params, $extraParams)); }
[ "public", "function", "getResetPath", "(", "$", "route", ",", "$", "extraParams", "=", "array", "(", ")", ")", "{", "$", "params", "=", "array", "(", "$", "this", "->", "getActionParameterName", "(", ")", "=>", "$", "this", "->", "getResetActionParameterName", "(", ")", ",", "$", "this", "->", "getDatagridParameterName", "(", ")", "=>", "$", "this", "->", "getName", "(", ")", ",", ")", ";", "return", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "generate", "(", "$", "route", ",", "array_merge", "(", "$", "params", ",", "$", "extraParams", ")", ")", ";", "}" ]
Generate reset route for the button view @param type $route @param type $extraParams @return type
[ "Generate", "reset", "route", "for", "the", "button", "view" ]
2c12ad90e8e6f44dc106a4512225c1ec68871076
https://github.com/spyrit/PropelDatagridBundle/blob/2c12ad90e8e6f44dc106a4512225c1ec68871076/Datagrid/PropelDatagrid.php#L478-L485
train
spyrit/PropelDatagridBundle
Datagrid/PropelDatagrid.php
PropelDatagrid.getSortPath
public function getSortPath($route, $column, $order, $extraParams = array()) { $params = array( $this->getActionParameterName() => $this->getSortActionParameterName(), $this->getDatagridParameterName() => $this->getName(), $this->getSortColumnParameterName() => $column, $this->getSortOrderParameterName() => $order, ); return $this->container->get('router')->generate($route, array_merge($params, $extraParams)); }
php
public function getSortPath($route, $column, $order, $extraParams = array()) { $params = array( $this->getActionParameterName() => $this->getSortActionParameterName(), $this->getDatagridParameterName() => $this->getName(), $this->getSortColumnParameterName() => $column, $this->getSortOrderParameterName() => $order, ); return $this->container->get('router')->generate($route, array_merge($params, $extraParams)); }
[ "public", "function", "getSortPath", "(", "$", "route", ",", "$", "column", ",", "$", "order", ",", "$", "extraParams", "=", "array", "(", ")", ")", "{", "$", "params", "=", "array", "(", "$", "this", "->", "getActionParameterName", "(", ")", "=>", "$", "this", "->", "getSortActionParameterName", "(", ")", ",", "$", "this", "->", "getDatagridParameterName", "(", ")", "=>", "$", "this", "->", "getName", "(", ")", ",", "$", "this", "->", "getSortColumnParameterName", "(", ")", "=>", "$", "column", ",", "$", "this", "->", "getSortOrderParameterName", "(", ")", "=>", "$", "order", ",", ")", ";", "return", "$", "this", "->", "container", "->", "get", "(", "'router'", ")", "->", "generate", "(", "$", "route", ",", "array_merge", "(", "$", "params", ",", "$", "extraParams", ")", ")", ";", "}" ]
Generate sorting route for a given column to be displayed in view @todo Remove the order parameter and ask to the datagrid to guess it ? @param type $route @param type $column @param type $order @param type $extraParams @return type
[ "Generate", "sorting", "route", "for", "a", "given", "column", "to", "be", "displayed", "in", "view" ]
2c12ad90e8e6f44dc106a4512225c1ec68871076
https://github.com/spyrit/PropelDatagridBundle/blob/2c12ad90e8e6f44dc106a4512225c1ec68871076/Datagrid/PropelDatagrid.php#L496-L505
train
shrink0r/php-schema
src/Property/ScalarProperty.php
ScalarProperty.validate
public function validate($value) { return is_scalar($value) ? Ok::unit() : Error::unit([ Error::NON_SCALAR ]); }
php
public function validate($value) { return is_scalar($value) ? Ok::unit() : Error::unit([ Error::NON_SCALAR ]); }
[ "public", "function", "validate", "(", "$", "value", ")", "{", "return", "is_scalar", "(", "$", "value", ")", "?", "Ok", "::", "unit", "(", ")", ":", "Error", "::", "unit", "(", "[", "Error", "::", "NON_SCALAR", "]", ")", ";", "}" ]
Tells if a given value is a valid scalar. @param mixed $value @return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned.
[ "Tells", "if", "a", "given", "value", "is", "a", "valid", "scalar", "." ]
94293fe897af376dd9d05962e2c516079409dd29
https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/ScalarProperty.php#L18-L21
train
OxfordInfoLabs/kinikit-core
src/Validation/FieldValidators/LengthFieldValidator.php
LengthFieldValidator.validateObjectFieldValue
public function validateObjectFieldValue($value, $fieldName, $targetObject, &$validatorParams, $validatorKey) { if (sizeof($validatorParams) < ($this->mode == self::MODE_RANGE ? 2 : 1)) { throw new MisconfiguredValidatorException($validatorKey, $fieldName, $targetObject); } if (!$value) return true; switch ($this->mode) { case self::MODE_MIN: return strlen($value) >= $validatorParams[0]; case self::MODE_MAX: return strlen($value) <= $validatorParams[0]; case self::MODE_RANGE: return strlen($value) <= $validatorParams[1] && strlen($value) >= $validatorParams[0]; } }
php
public function validateObjectFieldValue($value, $fieldName, $targetObject, &$validatorParams, $validatorKey) { if (sizeof($validatorParams) < ($this->mode == self::MODE_RANGE ? 2 : 1)) { throw new MisconfiguredValidatorException($validatorKey, $fieldName, $targetObject); } if (!$value) return true; switch ($this->mode) { case self::MODE_MIN: return strlen($value) >= $validatorParams[0]; case self::MODE_MAX: return strlen($value) <= $validatorParams[0]; case self::MODE_RANGE: return strlen($value) <= $validatorParams[1] && strlen($value) >= $validatorParams[0]; } }
[ "public", "function", "validateObjectFieldValue", "(", "$", "value", ",", "$", "fieldName", ",", "$", "targetObject", ",", "&", "$", "validatorParams", ",", "$", "validatorKey", ")", "{", "if", "(", "sizeof", "(", "$", "validatorParams", ")", "<", "(", "$", "this", "->", "mode", "==", "self", "::", "MODE_RANGE", "?", "2", ":", "1", ")", ")", "{", "throw", "new", "MisconfiguredValidatorException", "(", "$", "validatorKey", ",", "$", "fieldName", ",", "$", "targetObject", ")", ";", "}", "if", "(", "!", "$", "value", ")", "return", "true", ";", "switch", "(", "$", "this", "->", "mode", ")", "{", "case", "self", "::", "MODE_MIN", ":", "return", "strlen", "(", "$", "value", ")", ">=", "$", "validatorParams", "[", "0", "]", ";", "case", "self", "::", "MODE_MAX", ":", "return", "strlen", "(", "$", "value", ")", "<=", "$", "validatorParams", "[", "0", "]", ";", "case", "self", "::", "MODE_RANGE", ":", "return", "strlen", "(", "$", "value", ")", "<=", "$", "validatorParams", "[", "1", "]", "&&", "strlen", "(", "$", "value", ")", ">=", "$", "validatorParams", "[", "0", "]", ";", "}", "}" ]
Validate a range object @param string $value @param $fieldName @param SerialisableObject $targetObject @param array $validatorParams @param $validatorKey @return bool|mixed @throws MisconfiguredValidatorException
[ "Validate", "a", "range", "object" ]
edc1b2e6ffabd595c4c7d322279b3dd1e59ef359
https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Validation/FieldValidators/LengthFieldValidator.php#L39-L56
train
jbouzekri/SculpinTagCloudBundle
Component/Manager/TagCloudManager.php
TagCloudManager.applyStrategies
protected function applyStrategies(\Jb\Bundle\TagCloudBundle\Model\TagCloud $tagCloud) { foreach ($this->strategies as $strategy) { $strategy->process($tagCloud); } }
php
protected function applyStrategies(\Jb\Bundle\TagCloudBundle\Model\TagCloud $tagCloud) { foreach ($this->strategies as $strategy) { $strategy->process($tagCloud); } }
[ "protected", "function", "applyStrategies", "(", "\\", "Jb", "\\", "Bundle", "\\", "TagCloudBundle", "\\", "Model", "\\", "TagCloud", "$", "tagCloud", ")", "{", "foreach", "(", "$", "this", "->", "strategies", "as", "$", "strategy", ")", "{", "$", "strategy", "->", "process", "(", "$", "tagCloud", ")", ";", "}", "}" ]
Apply all registered strategies @param \Jb\Bundle\TagCloudBundle\Model\TagCloud $tagCloud
[ "Apply", "all", "registered", "strategies" ]
936cf34ce60cb8fb4774931b1841fc775a3e9208
https://github.com/jbouzekri/SculpinTagCloudBundle/blob/936cf34ce60cb8fb4774931b1841fc775a3e9208/Component/Manager/TagCloudManager.php#L107-L112
train
Th3Mouk/CMSPageBundle
Migration/BlocksMigration.php
BlocksMigration.migrateCkeditorBlocks
public function migrateCkeditorBlocks() { $legacyBlocks = $this->getLegacyCkeditorBlocks(); foreach ($legacyBlocks as $legacyBlock) { $legacyBlock->setType('cms.block.ckeditor'); $settings = $legacyBlock->getSettings(); if (isset($settings['contenu'])) { $settings['content'] = $settings['contenu']; unset($settings['contenu']); } $legacyBlock->setSettings($settings); $this->blockManager->save($legacyBlock); } }
php
public function migrateCkeditorBlocks() { $legacyBlocks = $this->getLegacyCkeditorBlocks(); foreach ($legacyBlocks as $legacyBlock) { $legacyBlock->setType('cms.block.ckeditor'); $settings = $legacyBlock->getSettings(); if (isset($settings['contenu'])) { $settings['content'] = $settings['contenu']; unset($settings['contenu']); } $legacyBlock->setSettings($settings); $this->blockManager->save($legacyBlock); } }
[ "public", "function", "migrateCkeditorBlocks", "(", ")", "{", "$", "legacyBlocks", "=", "$", "this", "->", "getLegacyCkeditorBlocks", "(", ")", ";", "foreach", "(", "$", "legacyBlocks", "as", "$", "legacyBlock", ")", "{", "$", "legacyBlock", "->", "setType", "(", "'cms.block.ckeditor'", ")", ";", "$", "settings", "=", "$", "legacyBlock", "->", "getSettings", "(", ")", ";", "if", "(", "isset", "(", "$", "settings", "[", "'contenu'", "]", ")", ")", "{", "$", "settings", "[", "'content'", "]", "=", "$", "settings", "[", "'contenu'", "]", ";", "unset", "(", "$", "settings", "[", "'contenu'", "]", ")", ";", "}", "$", "legacyBlock", "->", "setSettings", "(", "$", "settings", ")", ";", "$", "this", "->", "blockManager", "->", "save", "(", "$", "legacyBlock", ")", ";", "}", "}" ]
Function of migration of included blocks.
[ "Function", "of", "migration", "of", "included", "blocks", "." ]
c78667ae6969f5947263dcde625e0541f9064774
https://github.com/Th3Mouk/CMSPageBundle/blob/c78667ae6969f5947263dcde625e0541f9064774/Migration/BlocksMigration.php#L34-L52
train
Facebook-Anonymous-Publisher/shortener
src/Drivers/Hashids.php
Hashids.exists
protected function exists($url) { $shortener = Shortener::where('hash', hash('sha512', $url))->first(); if (is_null($shortener)) { return false; } return route('shortener.show', [ 'url' => $this->hashids->encode($shortener->getKey()), ]); }
php
protected function exists($url) { $shortener = Shortener::where('hash', hash('sha512', $url))->first(); if (is_null($shortener)) { return false; } return route('shortener.show', [ 'url' => $this->hashids->encode($shortener->getKey()), ]); }
[ "protected", "function", "exists", "(", "$", "url", ")", "{", "$", "shortener", "=", "Shortener", "::", "where", "(", "'hash'", ",", "hash", "(", "'sha512'", ",", "$", "url", ")", ")", "->", "first", "(", ")", ";", "if", "(", "is_null", "(", "$", "shortener", ")", ")", "{", "return", "false", ";", "}", "return", "route", "(", "'shortener.show'", ",", "[", "'url'", "=>", "$", "this", "->", "hashids", "->", "encode", "(", "$", "shortener", "->", "getKey", "(", ")", ")", ",", "]", ")", ";", "}" ]
Returns shorten url if exists, or false. @param $url @return string
[ "Returns", "shorten", "url", "if", "exists", "or", "false", "." ]
3b2e49d9cdd96758d35cf57a7a27659d2b6682aa
https://github.com/Facebook-Anonymous-Publisher/shortener/blob/3b2e49d9cdd96758d35cf57a7a27659d2b6682aa/src/Drivers/Hashids.php#L53-L64
train
Facebook-Anonymous-Publisher/shortener
src/Drivers/Hashids.php
Hashids.decode
public function decode($short) { $ids = $this->hashids->decode($short); if (empty($ids)) { throw new \InvalidArgumentException; } return Shortener::findOrFail(reset($ids))->getAttribute('url'); }
php
public function decode($short) { $ids = $this->hashids->decode($short); if (empty($ids)) { throw new \InvalidArgumentException; } return Shortener::findOrFail(reset($ids))->getAttribute('url'); }
[ "public", "function", "decode", "(", "$", "short", ")", "{", "$", "ids", "=", "$", "this", "->", "hashids", "->", "decode", "(", "$", "short", ")", ";", "if", "(", "empty", "(", "$", "ids", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", ";", "}", "return", "Shortener", "::", "findOrFail", "(", "reset", "(", "$", "ids", ")", ")", "->", "getAttribute", "(", "'url'", ")", ";", "}" ]
Get the origin url. @param string $short @return string
[ "Get", "the", "origin", "url", "." ]
3b2e49d9cdd96758d35cf57a7a27659d2b6682aa
https://github.com/Facebook-Anonymous-Publisher/shortener/blob/3b2e49d9cdd96758d35cf57a7a27659d2b6682aa/src/Drivers/Hashids.php#L73-L82
train
ARCANESOFT/SEO
src/Helpers/SeoChecker.php
SeoChecker.label
public static function label($status) { $statuses = [ SeoChecker::STATUS_DANGER => 'danger', SeoChecker::STATUS_GOOD => 'success', SeoChecker::STATUS_WARNING => 'warning', ]; return Arr::get($statuses, $status, 'default'); }
php
public static function label($status) { $statuses = [ SeoChecker::STATUS_DANGER => 'danger', SeoChecker::STATUS_GOOD => 'success', SeoChecker::STATUS_WARNING => 'warning', ]; return Arr::get($statuses, $status, 'default'); }
[ "public", "static", "function", "label", "(", "$", "status", ")", "{", "$", "statuses", "=", "[", "SeoChecker", "::", "STATUS_DANGER", "=>", "'danger'", ",", "SeoChecker", "::", "STATUS_GOOD", "=>", "'success'", ",", "SeoChecker", "::", "STATUS_WARNING", "=>", "'warning'", ",", "]", ";", "return", "Arr", "::", "get", "(", "$", "statuses", ",", "$", "status", ",", "'default'", ")", ";", "}" ]
Get the label class for the given status. @param string $status @return string
[ "Get", "the", "label", "class", "for", "the", "given", "status", "." ]
ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2
https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Helpers/SeoChecker.php#L61-L70
train
ARCANESOFT/SEO
src/Helpers/SeoChecker.php
SeoChecker.check
protected static function check($value, $min, $max) { $length = strlen($value); if ($length < $min) return self::STATUS_WARNING; if ($min <= $length && $length <= $max) return self::STATUS_GOOD; return self::STATUS_DANGER; }
php
protected static function check($value, $min, $max) { $length = strlen($value); if ($length < $min) return self::STATUS_WARNING; if ($min <= $length && $length <= $max) return self::STATUS_GOOD; return self::STATUS_DANGER; }
[ "protected", "static", "function", "check", "(", "$", "value", ",", "$", "min", ",", "$", "max", ")", "{", "$", "length", "=", "strlen", "(", "$", "value", ")", ";", "if", "(", "$", "length", "<", "$", "min", ")", "return", "self", "::", "STATUS_WARNING", ";", "if", "(", "$", "min", "<=", "$", "length", "&&", "$", "length", "<=", "$", "max", ")", "return", "self", "::", "STATUS_GOOD", ";", "return", "self", "::", "STATUS_DANGER", ";", "}" ]
Check the value with min & max length. @param string $value @param int $min @param int $max @return string
[ "Check", "the", "value", "with", "min", "&", "max", "length", "." ]
ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2
https://github.com/ARCANESOFT/SEO/blob/ce6d6135d55e8b2fd43cf7923839b4791b7c7ad2/src/Helpers/SeoChecker.php#L86-L97
train
PatrolServer/patrolsdk-php
lib/Server.php
Server.save
public function save() { if ($this->id) { throw new Exception('Can\'t save this server because it is already stored'); } $server = $this->_post('servers', $this->dirty_values); $this->mergeValues($server); }
php
public function save() { if ($this->id) { throw new Exception('Can\'t save this server because it is already stored'); } $server = $this->_post('servers', $this->dirty_values); $this->mergeValues($server); }
[ "public", "function", "save", "(", ")", "{", "if", "(", "$", "this", "->", "id", ")", "{", "throw", "new", "Exception", "(", "'Can\\'t save this server because it is already stored'", ")", ";", "}", "$", "server", "=", "$", "this", "->", "_post", "(", "'servers'", ",", "$", "this", "->", "dirty_values", ")", ";", "$", "this", "->", "mergeValues", "(", "$", "server", ")", ";", "}" ]
Saves a server
[ "Saves", "a", "server" ]
2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2
https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/Server.php#L41-L48
train
PatrolServer/patrolsdk-php
lib/Server.php
Server.verify
public function verify($token = null) { if (!$token) { $data = $this->requestVerificationToken(); $token = $data['token']; } return $this->_post('servers/' . $this->id . '/verify', ['token' => $token]); }
php
public function verify($token = null) { if (!$token) { $data = $this->requestVerificationToken(); $token = $data['token']; } return $this->_post('servers/' . $this->id . '/verify', ['token' => $token]); }
[ "public", "function", "verify", "(", "$", "token", "=", "null", ")", "{", "if", "(", "!", "$", "token", ")", "{", "$", "data", "=", "$", "this", "->", "requestVerificationToken", "(", ")", ";", "$", "token", "=", "$", "data", "[", "'token'", "]", ";", "}", "return", "$", "this", "->", "_post", "(", "'servers/'", ".", "$", "this", "->", "id", ".", "'/verify'", ",", "[", "'token'", "=>", "$", "token", "]", ")", ";", "}" ]
Verifies the server with the verification token
[ "Verifies", "the", "server", "with", "the", "verification", "token" ]
2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2
https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/Server.php#L64-L71
train
PatrolServer/patrolsdk-php
lib/Server.php
Server.allSoftware
public function allSoftware($scopes = []) { if (!$this->id) { throw new Exception("The server has no ID, can\'t get software"); } $software = new Software($this->patrol); $software->defaults([ 'server_id' => $this->id ]); return $software->all($scopes); }
php
public function allSoftware($scopes = []) { if (!$this->id) { throw new Exception("The server has no ID, can\'t get software"); } $software = new Software($this->patrol); $software->defaults([ 'server_id' => $this->id ]); return $software->all($scopes); }
[ "public", "function", "allSoftware", "(", "$", "scopes", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "id", ")", "{", "throw", "new", "Exception", "(", "\"The server has no ID, can\\'t get software\"", ")", ";", "}", "$", "software", "=", "new", "Software", "(", "$", "this", "->", "patrol", ")", ";", "$", "software", "->", "defaults", "(", "[", "'server_id'", "=>", "$", "this", "->", "id", "]", ")", ";", "return", "$", "software", "->", "all", "(", "$", "scopes", ")", ";", "}" ]
Gets all installed software from this server @param array $scopes optional @return array List of PatrolSdk\Software
[ "Gets", "all", "installed", "software", "from", "this", "server" ]
2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2
https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/Server.php#L92-L104
train
PatrolServer/patrolsdk-php
lib/Server.php
Server.software
public function software($id, $scopes = []) { if (!$this->id) { throw new Exception("The server has no ID, can\'t get software"); } $software = new Software($this->patrol); $software->defaults([ 'server_id' => $this->id ]); return $software->find($id, $scopes); }
php
public function software($id, $scopes = []) { if (!$this->id) { throw new Exception("The server has no ID, can\'t get software"); } $software = new Software($this->patrol); $software->defaults([ 'server_id' => $this->id ]); return $software->find($id, $scopes); }
[ "public", "function", "software", "(", "$", "id", ",", "$", "scopes", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "id", ")", "{", "throw", "new", "Exception", "(", "\"The server has no ID, can\\'t get software\"", ")", ";", "}", "$", "software", "=", "new", "Software", "(", "$", "this", "->", "patrol", ")", ";", "$", "software", "->", "defaults", "(", "[", "'server_id'", "=>", "$", "this", "->", "id", "]", ")", ";", "return", "$", "software", "->", "find", "(", "$", "id", ",", "$", "scopes", ")", ";", "}" ]
Gets a single installed software from this server @param integer $id @param array $scopes optional @return Software
[ "Gets", "a", "single", "installed", "software", "from", "this", "server" ]
2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2
https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/Server.php#L114-L126
train
PatrolServer/patrolsdk-php
lib/Server.php
Server.buckets
public function buckets() { if (!$this->id) { throw new Exception("The server has no ID, can\'t get buckets"); } $bucket = new Bucket($this->patrol); $bucket->defaults([ 'server_id' => $this->id ]); return $bucket->all(); }
php
public function buckets() { if (!$this->id) { throw new Exception("The server has no ID, can\'t get buckets"); } $bucket = new Bucket($this->patrol); $bucket->defaults([ 'server_id' => $this->id ]); return $bucket->all(); }
[ "public", "function", "buckets", "(", ")", "{", "if", "(", "!", "$", "this", "->", "id", ")", "{", "throw", "new", "Exception", "(", "\"The server has no ID, can\\'t get buckets\"", ")", ";", "}", "$", "bucket", "=", "new", "Bucket", "(", "$", "this", "->", "patrol", ")", ";", "$", "bucket", "->", "defaults", "(", "[", "'server_id'", "=>", "$", "this", "->", "id", "]", ")", ";", "return", "$", "bucket", "->", "all", "(", ")", ";", "}" ]
Gets all software buckets from this server @return array List of PatrolSdk\Bucket
[ "Gets", "all", "software", "buckets", "from", "this", "server" ]
2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2
https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/Server.php#L133-L145
train
PatrolServer/patrolsdk-php
lib/Server.php
Server.bucket
public function bucket($key = null) { if (!$this->id) { throw new Exception("The server has no ID, can\'t get buckets"); } $bucket = new Bucket($this->patrol); $bucket->defaults([ 'server_id' => $this->id ]); if (is_null($key)) { return $bucket; } try { return $bucket->find($key); } catch (Exception $ex) { if ($ex->getMessage() === "Bucket does not exist") { $bucket->key = $key; return $bucket; } } return null; }
php
public function bucket($key = null) { if (!$this->id) { throw new Exception("The server has no ID, can\'t get buckets"); } $bucket = new Bucket($this->patrol); $bucket->defaults([ 'server_id' => $this->id ]); if (is_null($key)) { return $bucket; } try { return $bucket->find($key); } catch (Exception $ex) { if ($ex->getMessage() === "Bucket does not exist") { $bucket->key = $key; return $bucket; } } return null; }
[ "public", "function", "bucket", "(", "$", "key", "=", "null", ")", "{", "if", "(", "!", "$", "this", "->", "id", ")", "{", "throw", "new", "Exception", "(", "\"The server has no ID, can\\'t get buckets\"", ")", ";", "}", "$", "bucket", "=", "new", "Bucket", "(", "$", "this", "->", "patrol", ")", ";", "$", "bucket", "->", "defaults", "(", "[", "'server_id'", "=>", "$", "this", "->", "id", "]", ")", ";", "if", "(", "is_null", "(", "$", "key", ")", ")", "{", "return", "$", "bucket", ";", "}", "try", "{", "return", "$", "bucket", "->", "find", "(", "$", "key", ")", ";", "}", "catch", "(", "Exception", "$", "ex", ")", "{", "if", "(", "$", "ex", "->", "getMessage", "(", ")", "===", "\"Bucket does not exist\"", ")", "{", "$", "bucket", "->", "key", "=", "$", "key", ";", "return", "$", "bucket", ";", "}", "}", "return", "null", ";", "}" ]
Gets a single software bucket If no key is set, an empty Bucket object will be returned which will act as a repository @param string $key optional @return Bucket
[ "Gets", "a", "single", "software", "bucket", "If", "no", "key", "is", "set", "an", "empty", "Bucket", "object", "will", "be", "returned", "which", "will", "act", "as", "a", "repository" ]
2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2
https://github.com/PatrolServer/patrolsdk-php/blob/2451f0d2ba2bb5bc3d7e47cfc110f7f272620db2/lib/Server.php#L155-L180
train
UWEnrollmentManagement/Secure-Upload
src/Cipher.php
Cipher.cleanFilename
public static function cleanFilename($filename) { return preg_replace( '/[^A-Za-z0-9_\-]/', '_', htmlentities(pathinfo($filename, PATHINFO_FILENAME)) ) . '.' . preg_replace( '/[^A-Za-z0-9_\-]/', '_', htmlentities(pathinfo($filename, PATHINFO_EXTENSION)) ); }
php
public static function cleanFilename($filename) { return preg_replace( '/[^A-Za-z0-9_\-]/', '_', htmlentities(pathinfo($filename, PATHINFO_FILENAME)) ) . '.' . preg_replace( '/[^A-Za-z0-9_\-]/', '_', htmlentities(pathinfo($filename, PATHINFO_EXTENSION)) ); }
[ "public", "static", "function", "cleanFilename", "(", "$", "filename", ")", "{", "return", "preg_replace", "(", "'/[^A-Za-z0-9_\\-]/'", ",", "'_'", ",", "htmlentities", "(", "pathinfo", "(", "$", "filename", ",", "PATHINFO_FILENAME", ")", ")", ")", ".", "'.'", ".", "preg_replace", "(", "'/[^A-Za-z0-9_\\-]/'", ",", "'_'", ",", "htmlentities", "(", "pathinfo", "(", "$", "filename", ",", "PATHINFO_EXTENSION", ")", ")", ")", ";", "}" ]
White list scrub of file name. @param string $filename A filename to be cleaned of potentially troublesome characters. @return string
[ "White", "list", "scrub", "of", "file", "name", "." ]
153e1f59224d9311585be464e22bd53ed7e1fb01
https://github.com/UWEnrollmentManagement/Secure-Upload/blob/153e1f59224d9311585be464e22bd53ed7e1fb01/src/Cipher.php#L19-L30
train
UWEnrollmentManagement/Secure-Upload
src/Cipher.php
Cipher.encrypt
public static function encrypt($name, $location, $destination, $publicKeyLocation) { /** @var resource $publicKey */ $publicKey = openssl_get_publickey(file_get_contents($publicKeyLocation)); /** @var string $data */ $data = file_get_contents($location); /** @var string $info */ $info = json_encode(['name' => $name]); openssl_seal(gzcompress($data), $encryptedData, $dataKeys, [$publicKey]); openssl_seal(gzcompress($info), $encryptedInfo, $infoKeys, [$publicKey]); /** @var string $hash */ $hash = md5($encryptedData); file_put_contents("$destination/$hash.data", $encryptedData); file_put_contents("$destination/$hash.info", $encryptedInfo); file_put_contents("$destination/$hash.data.key", $dataKeys[0]); file_put_contents("$destination/$hash.info.key", $infoKeys[0]); openssl_free_key($publicKey); return "$destination/$hash.data"; }
php
public static function encrypt($name, $location, $destination, $publicKeyLocation) { /** @var resource $publicKey */ $publicKey = openssl_get_publickey(file_get_contents($publicKeyLocation)); /** @var string $data */ $data = file_get_contents($location); /** @var string $info */ $info = json_encode(['name' => $name]); openssl_seal(gzcompress($data), $encryptedData, $dataKeys, [$publicKey]); openssl_seal(gzcompress($info), $encryptedInfo, $infoKeys, [$publicKey]); /** @var string $hash */ $hash = md5($encryptedData); file_put_contents("$destination/$hash.data", $encryptedData); file_put_contents("$destination/$hash.info", $encryptedInfo); file_put_contents("$destination/$hash.data.key", $dataKeys[0]); file_put_contents("$destination/$hash.info.key", $infoKeys[0]); openssl_free_key($publicKey); return "$destination/$hash.data"; }
[ "public", "static", "function", "encrypt", "(", "$", "name", ",", "$", "location", ",", "$", "destination", ",", "$", "publicKeyLocation", ")", "{", "/** @var resource $publicKey */", "$", "publicKey", "=", "openssl_get_publickey", "(", "file_get_contents", "(", "$", "publicKeyLocation", ")", ")", ";", "/** @var string $data */", "$", "data", "=", "file_get_contents", "(", "$", "location", ")", ";", "/** @var string $info */", "$", "info", "=", "json_encode", "(", "[", "'name'", "=>", "$", "name", "]", ")", ";", "openssl_seal", "(", "gzcompress", "(", "$", "data", ")", ",", "$", "encryptedData", ",", "$", "dataKeys", ",", "[", "$", "publicKey", "]", ")", ";", "openssl_seal", "(", "gzcompress", "(", "$", "info", ")", ",", "$", "encryptedInfo", ",", "$", "infoKeys", ",", "[", "$", "publicKey", "]", ")", ";", "/** @var string $hash */", "$", "hash", "=", "md5", "(", "$", "encryptedData", ")", ";", "file_put_contents", "(", "\"$destination/$hash.data\"", ",", "$", "encryptedData", ")", ";", "file_put_contents", "(", "\"$destination/$hash.info\"", ",", "$", "encryptedInfo", ")", ";", "file_put_contents", "(", "\"$destination/$hash.data.key\"", ",", "$", "dataKeys", "[", "0", "]", ")", ";", "file_put_contents", "(", "\"$destination/$hash.info.key\"", ",", "$", "infoKeys", "[", "0", "]", ")", ";", "openssl_free_key", "(", "$", "publicKey", ")", ";", "return", "\"$destination/$hash.data\"", ";", "}" ]
Encrypt a specified file. @param string $name The name that the file shall have when it's decrypted. @param string $location The current location of the file. @param string $destination The folder into which you wish to encrypt the file. @param string $publicKeyLocation The location of the public key to encrypt to. @return string The path of the newly encrypted file.
[ "Encrypt", "a", "specified", "file", "." ]
153e1f59224d9311585be464e22bd53ed7e1fb01
https://github.com/UWEnrollmentManagement/Secure-Upload/blob/153e1f59224d9311585be464e22bd53ed7e1fb01/src/Cipher.php#L41-L66
train
Panigale/laravel5-Points
src/Traits/GetPointEvent.php
GetPointEvent.getPointEvent
public function getPointEvent($typeId = null) { $this->buildQuery(); $query = $this->eventQuery; if(! is_null($typeId)){ $query->where('point_event_type_id' ,$typeId); } return $this->doQuery(); }
php
public function getPointEvent($typeId = null) { $this->buildQuery(); $query = $this->eventQuery; if(! is_null($typeId)){ $query->where('point_event_type_id' ,$typeId); } return $this->doQuery(); }
[ "public", "function", "getPointEvent", "(", "$", "typeId", "=", "null", ")", "{", "$", "this", "->", "buildQuery", "(", ")", ";", "$", "query", "=", "$", "this", "->", "eventQuery", ";", "if", "(", "!", "is_null", "(", "$", "typeId", ")", ")", "{", "$", "query", "->", "where", "(", "'point_event_type_id'", ",", "$", "typeId", ")", ";", "}", "return", "$", "this", "->", "doQuery", "(", ")", ";", "}" ]
get user point event @return \Illuminate\Database\Eloquent\Collection|static[]
[ "get", "user", "point", "event" ]
6fb559d91694a336f5a11d8408348a85395b4ff3
https://github.com/Panigale/laravel5-Points/blob/6fb559d91694a336f5a11d8408348a85395b4ff3/src/Traits/GetPointEvent.php#L40-L50
train
Panigale/laravel5-Points
src/Traits/GetPointEvent.php
GetPointEvent.getPointEventByType
public function getPointEventByType($isIncrease = true) { $query = PointEventType::select('id'); $isIncrease ? $query->where('is_increase' ,$isIncrease) : $query->where('is_deduction'); $eventType = $query->get(); $this->eventQuery = PointEvent::with('activities') ->whereIn('point_event_type_id' ,$eventType->toArray()); return $this->doQuery(); }
php
public function getPointEventByType($isIncrease = true) { $query = PointEventType::select('id'); $isIncrease ? $query->where('is_increase' ,$isIncrease) : $query->where('is_deduction'); $eventType = $query->get(); $this->eventQuery = PointEvent::with('activities') ->whereIn('point_event_type_id' ,$eventType->toArray()); return $this->doQuery(); }
[ "public", "function", "getPointEventByType", "(", "$", "isIncrease", "=", "true", ")", "{", "$", "query", "=", "PointEventType", "::", "select", "(", "'id'", ")", ";", "$", "isIncrease", "?", "$", "query", "->", "where", "(", "'is_increase'", ",", "$", "isIncrease", ")", ":", "$", "query", "->", "where", "(", "'is_deduction'", ")", ";", "$", "eventType", "=", "$", "query", "->", "get", "(", ")", ";", "$", "this", "->", "eventQuery", "=", "PointEvent", "::", "with", "(", "'activities'", ")", "->", "whereIn", "(", "'point_event_type_id'", ",", "$", "eventType", "->", "toArray", "(", ")", ")", ";", "return", "$", "this", "->", "doQuery", "(", ")", ";", "}" ]
get point event by type @param bool $isIncrease @return \Illuminate\Database\Eloquent\Collection|static[]
[ "get", "point", "event", "by", "type" ]
6fb559d91694a336f5a11d8408348a85395b4ff3
https://github.com/Panigale/laravel5-Points/blob/6fb559d91694a336f5a11d8408348a85395b4ff3/src/Traits/GetPointEvent.php#L58-L69
train
erenmustafaozdal/laravel-modules-base
src/Validators/BaseValidator.php
BaseValidator.validateElfinder
public function validateElfinder($attribute, $value, $parameters, $validator) { if( ! File::exists($value) ) { return false; } if(count($parameters)>0) { return in_array( File::extension($value),$parameters ); } return true; }
php
public function validateElfinder($attribute, $value, $parameters, $validator) { if( ! File::exists($value) ) { return false; } if(count($parameters)>0) { return in_array( File::extension($value),$parameters ); } return true; }
[ "public", "function", "validateElfinder", "(", "$", "attribute", ",", "$", "value", ",", "$", "parameters", ",", "$", "validator", ")", "{", "if", "(", "!", "File", "::", "exists", "(", "$", "value", ")", ")", "{", "return", "false", ";", "}", "if", "(", "count", "(", "$", "parameters", ")", ">", "0", ")", "{", "return", "in_array", "(", "File", "::", "extension", "(", "$", "value", ")", ",", "$", "parameters", ")", ";", "}", "return", "true", ";", "}" ]
validator elfinder file @param $attribute @param $value @param $parameters @param $validator @return bool
[ "validator", "elfinder", "file" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Validators/BaseValidator.php#L19-L30
train
erenmustafaozdal/laravel-modules-base
src/Validators/BaseValidator.php
BaseValidator.validateElfinderMax
public function validateElfinderMax($attribute, $value, $parameters, $validator) { $size = $parameters[0] * 1024; // parameters kB to B if ( File::size($value) > $size ) { return false; } return true; }
php
public function validateElfinderMax($attribute, $value, $parameters, $validator) { $size = $parameters[0] * 1024; // parameters kB to B if ( File::size($value) > $size ) { return false; } return true; }
[ "public", "function", "validateElfinderMax", "(", "$", "attribute", ",", "$", "value", ",", "$", "parameters", ",", "$", "validator", ")", "{", "$", "size", "=", "$", "parameters", "[", "0", "]", "*", "1024", ";", "// parameters kB to B\r", "if", "(", "File", "::", "size", "(", "$", "value", ")", ">", "$", "size", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
validator elfinder max size file @param $attribute @param $value @param $parameters @param $validator @return bool
[ "validator", "elfinder", "max", "size", "file" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Validators/BaseValidator.php#L41-L48
train
erenmustafaozdal/laravel-modules-base
src/Validators/BaseValidator.php
BaseValidator.validateVideoLink
public function validateVideoLink($attribute, $value, $parameters, $validator) { return preg_match($this->youtubeRegex, $value) || preg_match($this->vimeoRegex, $value); }
php
public function validateVideoLink($attribute, $value, $parameters, $validator) { return preg_match($this->youtubeRegex, $value) || preg_match($this->vimeoRegex, $value); }
[ "public", "function", "validateVideoLink", "(", "$", "attribute", ",", "$", "value", ",", "$", "parameters", ",", "$", "validator", ")", "{", "return", "preg_match", "(", "$", "this", "->", "youtubeRegex", ",", "$", "value", ")", "||", "preg_match", "(", "$", "this", "->", "vimeoRegex", ",", "$", "value", ")", ";", "}" ]
validator youtube link @param $attribute @param $value @param $parameters @param $validator @param $validator @return bool
[ "validator", "youtube", "link" ]
c26600543817642926bcf16ada84009e00d784e0
https://github.com/erenmustafaozdal/laravel-modules-base/blob/c26600543817642926bcf16ada84009e00d784e0/src/Validators/BaseValidator.php#L104-L107
train
horntell/php-sdk
src/Horntell/Http/Request.php
Request.send
public function send($method, $endpoint, $data = []) { try { $request = $this->client->createRequest($method, $endpoint, ['body' => json_encode($data)]); return new Response($this->client->send($request)); } catch(GuzzleExceptions\RequestException $e) { // pass the exception to a helper method, // which will figure our what kind of // exception to throw return $this->handleError($e); } }
php
public function send($method, $endpoint, $data = []) { try { $request = $this->client->createRequest($method, $endpoint, ['body' => json_encode($data)]); return new Response($this->client->send($request)); } catch(GuzzleExceptions\RequestException $e) { // pass the exception to a helper method, // which will figure our what kind of // exception to throw return $this->handleError($e); } }
[ "public", "function", "send", "(", "$", "method", ",", "$", "endpoint", ",", "$", "data", "=", "[", "]", ")", "{", "try", "{", "$", "request", "=", "$", "this", "->", "client", "->", "createRequest", "(", "$", "method", ",", "$", "endpoint", ",", "[", "'body'", "=>", "json_encode", "(", "$", "data", ")", "]", ")", ";", "return", "new", "Response", "(", "$", "this", "->", "client", "->", "send", "(", "$", "request", ")", ")", ";", "}", "catch", "(", "GuzzleExceptions", "\\", "RequestException", "$", "e", ")", "{", "// pass the exception to a helper method,", "// which will figure our what kind of ", "// exception to throw", "return", "$", "this", "->", "handleError", "(", "$", "e", ")", ";", "}", "}" ]
Wraps HTTP call into a good mould @param string $method @param string $endpoint @param array $data @return Horntell\Http\Response @throws Horntell\Errors\*
[ "Wraps", "HTTP", "call", "into", "a", "good", "mould" ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/src/Horntell/Http/Request.php#L46-L60
train
horntell/php-sdk
src/Horntell/Http/Request.php
Request.handleError
private function handleError($e) { // if there's no response attached to the exception, // we will assume that the request was never sent and // thus will throw a network error if( ! $e->hasResponse()) { throw new Errors\NetworkError; } // if there's a response attached to the exception, // we will figure out which error to throw based on // the HTTP status code of response $response = $e->getResponse(); $body = $response->json(); switch($response->getStatusCode()) { case 400: throw new Errors\InvalidRequestError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 401: throw new Errors\AuthenticationError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 403: throw new Errors\ForbiddenError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 404: throw new Errors\NotFoundError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 500: throw new Errors\ServiceError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; // for backwards compatibility, we will handle other // HTTP status codes too (to keep the SDK working, // even when we send more variants of HTTP status codes // through API) default: return $this->handleUnknownError($e); } }
php
private function handleError($e) { // if there's no response attached to the exception, // we will assume that the request was never sent and // thus will throw a network error if( ! $e->hasResponse()) { throw new Errors\NetworkError; } // if there's a response attached to the exception, // we will figure out which error to throw based on // the HTTP status code of response $response = $e->getResponse(); $body = $response->json(); switch($response->getStatusCode()) { case 400: throw new Errors\InvalidRequestError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 401: throw new Errors\AuthenticationError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 403: throw new Errors\ForbiddenError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 404: throw new Errors\NotFoundError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; case 500: throw new Errors\ServiceError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; // for backwards compatibility, we will handle other // HTTP status codes too (to keep the SDK working, // even when we send more variants of HTTP status codes // through API) default: return $this->handleUnknownError($e); } }
[ "private", "function", "handleError", "(", "$", "e", ")", "{", "// if there's no response attached to the exception,", "// we will assume that the request was never sent and", "// thus will throw a network error", "if", "(", "!", "$", "e", "->", "hasResponse", "(", ")", ")", "{", "throw", "new", "Errors", "\\", "NetworkError", ";", "}", "// if there's a response attached to the exception,", "// we will figure out which error to throw based on", "// the HTTP status code of response", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ";", "$", "body", "=", "$", "response", "->", "json", "(", ")", ";", "switch", "(", "$", "response", "->", "getStatusCode", "(", ")", ")", "{", "case", "400", ":", "throw", "new", "Errors", "\\", "InvalidRequestError", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "break", ";", "case", "401", ":", "throw", "new", "Errors", "\\", "AuthenticationError", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "break", ";", "case", "403", ":", "throw", "new", "Errors", "\\", "ForbiddenError", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "break", ";", "case", "404", ":", "throw", "new", "Errors", "\\", "NotFoundError", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "break", ";", "case", "500", ":", "throw", "new", "Errors", "\\", "ServiceError", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "break", ";", "// for backwards compatibility, we will handle other", "// HTTP status codes too (to keep the SDK working,", "// even when we send more variants of HTTP status codes", "// through API)", "default", ":", "return", "$", "this", "->", "handleUnknownError", "(", "$", "e", ")", ";", "}", "}" ]
Handles the error by throwing proper exception @param GuzzleHttp\Exception\RequestException $e @return null @throws Horntell\Errors\NetworkError If original exception has no response attached to it @throws Horntell\Errors\InvalidRequestException If HTTP Status Code is 400 @throws Horntell\Errors\AuthenticationException If HTTP Status Code is 401 @throws Horntell\Errors\ForbiddenException If HTTP Status Code is 403 @throws Horntell\Errors\NotFoundException If HTTP Status Code is 404 @throws Horntell\Errors\ServiceException If HTTP Status Code is 500
[ "Handles", "the", "error", "by", "throwing", "proper", "exception" ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/src/Horntell/Http/Request.php#L74-L118
train
horntell/php-sdk
src/Horntell/Http/Request.php
Request.handleUnknownError
private function handleUnknownError($e) { $response = $e->getResponse(); $body = $response->json(); // switching on the first number of status code // we are using floor to round off to the lower end // eg. floor(404 / 100) == 4 switch(floor($response->getStatusCode() / 100)) { // client error (4xx) case 4: throw new Errors\InvalidRequestError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; // server error (5xx) case 5: throw new Errors\ServiceError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; // very generic error (if all else fails) default: throw new Errors\Error($body['error']['message'], $body['error']['code'], $body['error']['type']); } }
php
private function handleUnknownError($e) { $response = $e->getResponse(); $body = $response->json(); // switching on the first number of status code // we are using floor to round off to the lower end // eg. floor(404 / 100) == 4 switch(floor($response->getStatusCode() / 100)) { // client error (4xx) case 4: throw new Errors\InvalidRequestError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; // server error (5xx) case 5: throw new Errors\ServiceError($body['error']['message'], $body['error']['code'], $body['error']['type']); break; // very generic error (if all else fails) default: throw new Errors\Error($body['error']['message'], $body['error']['code'], $body['error']['type']); } }
[ "private", "function", "handleUnknownError", "(", "$", "e", ")", "{", "$", "response", "=", "$", "e", "->", "getResponse", "(", ")", ";", "$", "body", "=", "$", "response", "->", "json", "(", ")", ";", "// switching on the first number of status code", "// we are using floor to round off to the lower end", "// eg. floor(404 / 100) == 4", "switch", "(", "floor", "(", "$", "response", "->", "getStatusCode", "(", ")", "/", "100", ")", ")", "{", "// client error (4xx)", "case", "4", ":", "throw", "new", "Errors", "\\", "InvalidRequestError", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "break", ";", "// server error (5xx)", "case", "5", ":", "throw", "new", "Errors", "\\", "ServiceError", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "break", ";", "// very generic error (if all else fails)", "default", ":", "throw", "new", "Errors", "\\", "Error", "(", "$", "body", "[", "'error'", "]", "[", "'message'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'code'", "]", ",", "$", "body", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "}", "}" ]
Handles unknown errors by checking the kind of HTTP status code @param GuzzleHttp\Exception\RequestException $e @return null @throws Horntell\Errors\InvalidRequestError If HTTP Status Code is 4xx @throws Horntell\Errors\ServiceError If HTTP Status Code is 5xx @throws Horntell\Errors\Error If HTTP Status Code is other than 4xx and 5xx
[ "Handles", "unknown", "errors", "by", "checking", "the", "kind", "of", "HTTP", "status", "code" ]
e5205e9396a21b754d5651a8aa5898da5922a1b7
https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/src/Horntell/Http/Request.php#L129-L153
train
pixelpolishers/makedocs
src/MakeDocs/Generator/PageManager.php
PageManager.getSourceFile
public function getSourceFile($page) { $path = realpath($this->generator->getInputDirectory() . '/' . $page . '.xml'); return new SourceFile($page, $path); }
php
public function getSourceFile($page) { $path = realpath($this->generator->getInputDirectory() . '/' . $page . '.xml'); return new SourceFile($page, $path); }
[ "public", "function", "getSourceFile", "(", "$", "page", ")", "{", "$", "path", "=", "realpath", "(", "$", "this", "->", "generator", "->", "getInputDirectory", "(", ")", ".", "'/'", ".", "$", "page", ".", "'.xml'", ")", ";", "return", "new", "SourceFile", "(", "$", "page", ",", "$", "path", ")", ";", "}" ]
Loads a source file. @param string $page The page to load. @return SourceFile
[ "Loads", "a", "source", "file", "." ]
1fa243b52565b5de417ef2dbdfbcae9896b6b483
https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Generator/PageManager.php#L67-L72
train
congraphcms/core
Traits/ValidatorTrait.php
ValidatorTrait.validateParams
protected function validateParams(array &$params, $rules = null, $clean = false) { if( ! is_null($rules) ) { // init laravel validator $validator = $this->newValidator($params, $rules, $clean); $this->setValidator($validator); } $validator = $this->getValidator(); $rules = $validator->getRules(); if ($validator->fails()) { // params did not pass validation rules // add errors to exception $this->getException()->addErrors($validator->errors()->toArray()); return false; } else { // params passed validation rules return true; } }
php
protected function validateParams(array &$params, $rules = null, $clean = false) { if( ! is_null($rules) ) { // init laravel validator $validator = $this->newValidator($params, $rules, $clean); $this->setValidator($validator); } $validator = $this->getValidator(); $rules = $validator->getRules(); if ($validator->fails()) { // params did not pass validation rules // add errors to exception $this->getException()->addErrors($validator->errors()->toArray()); return false; } else { // params passed validation rules return true; } }
[ "protected", "function", "validateParams", "(", "array", "&", "$", "params", ",", "$", "rules", "=", "null", ",", "$", "clean", "=", "false", ")", "{", "if", "(", "!", "is_null", "(", "$", "rules", ")", ")", "{", "// init laravel validator", "$", "validator", "=", "$", "this", "->", "newValidator", "(", "$", "params", ",", "$", "rules", ",", "$", "clean", ")", ";", "$", "this", "->", "setValidator", "(", "$", "validator", ")", ";", "}", "$", "validator", "=", "$", "this", "->", "getValidator", "(", ")", ";", "$", "rules", "=", "$", "validator", "->", "getRules", "(", ")", ";", "if", "(", "$", "validator", "->", "fails", "(", ")", ")", "{", "// params did not pass validation rules", "// add errors to exception", "$", "this", "->", "getException", "(", ")", "->", "addErrors", "(", "$", "validator", "->", "errors", "(", ")", "->", "toArray", "(", ")", ")", ";", "return", "false", ";", "}", "else", "{", "// params passed validation rules", "return", "true", ";", "}", "}" ]
Validate params by given rules @param $params array - input parameters @param $rules array - rules for validator @param $clean boolean - whether to unset params that are not in rules @return boolean
[ "Validate", "params", "by", "given", "rules" ]
d017d3951b446fb2ac93b8fcee120549bb125b17
https://github.com/congraphcms/core/blob/d017d3951b446fb2ac93b8fcee120549bb125b17/Traits/ValidatorTrait.php#L59-L87
train
WellCommerce/ClientBundle
Twig/Extension/ClientAddressFormatterExtension.php
ClientAddressFormatterExtension.formatShippingAddress
public function formatShippingAddress(ClientShippingAddressInterface $address, $lineSeparator = self::LINES_SEPARATOR) { $lines = []; $lines[] = sprintf('%s %s', $address->getFirstName(), $address->getLastName()); if ('' !== $address->getCompanyName()) { $lines[] = $address->getCompanyName(); } $lines[] = $address->getLine1(); $lines[] = $address->getLine2(); $lines[] = sprintf('%s, %s %s', $address->getCountry(), $address->getPostalCode(), $address->getCity()); return implode($lineSeparator, $lines); }
php
public function formatShippingAddress(ClientShippingAddressInterface $address, $lineSeparator = self::LINES_SEPARATOR) { $lines = []; $lines[] = sprintf('%s %s', $address->getFirstName(), $address->getLastName()); if ('' !== $address->getCompanyName()) { $lines[] = $address->getCompanyName(); } $lines[] = $address->getLine1(); $lines[] = $address->getLine2(); $lines[] = sprintf('%s, %s %s', $address->getCountry(), $address->getPostalCode(), $address->getCity()); return implode($lineSeparator, $lines); }
[ "public", "function", "formatShippingAddress", "(", "ClientShippingAddressInterface", "$", "address", ",", "$", "lineSeparator", "=", "self", "::", "LINES_SEPARATOR", ")", "{", "$", "lines", "=", "[", "]", ";", "$", "lines", "[", "]", "=", "sprintf", "(", "'%s %s'", ",", "$", "address", "->", "getFirstName", "(", ")", ",", "$", "address", "->", "getLastName", "(", ")", ")", ";", "if", "(", "''", "!==", "$", "address", "->", "getCompanyName", "(", ")", ")", "{", "$", "lines", "[", "]", "=", "$", "address", "->", "getCompanyName", "(", ")", ";", "}", "$", "lines", "[", "]", "=", "$", "address", "->", "getLine1", "(", ")", ";", "$", "lines", "[", "]", "=", "$", "address", "->", "getLine2", "(", ")", ";", "$", "lines", "[", "]", "=", "sprintf", "(", "'%s, %s %s'", ",", "$", "address", "->", "getCountry", "(", ")", ",", "$", "address", "->", "getPostalCode", "(", ")", ",", "$", "address", "->", "getCity", "(", ")", ")", ";", "return", "implode", "(", "$", "lineSeparator", ",", "$", "lines", ")", ";", "}" ]
Formats the shipping address @param ClientShippingAddressInterface $address @param string $lineSeparator @return string
[ "Formats", "the", "shipping", "address" ]
b19aa5c962e67972f79338d2f341b30fa1ee879e
https://github.com/WellCommerce/ClientBundle/blob/b19aa5c962e67972f79338d2f341b30fa1ee879e/Twig/Extension/ClientAddressFormatterExtension.php#L74-L86
train
WellCommerce/ClientBundle
Twig/Extension/ClientAddressFormatterExtension.php
ClientAddressFormatterExtension.formatContactDetails
public function formatContactDetails(ClientContactDetailsInterface $details, $lineSeparator = self::LINES_SEPARATOR) { $lines = []; $lines[] = sprintf('%s %s', $details->getFirstName(), $details->getLastName()); $lines[] = sprintf('%s %s', $details->getPhone(), $details->getSecondaryPhone()); $lines[] = $details->getEmail(); return implode($lineSeparator, $lines); }
php
public function formatContactDetails(ClientContactDetailsInterface $details, $lineSeparator = self::LINES_SEPARATOR) { $lines = []; $lines[] = sprintf('%s %s', $details->getFirstName(), $details->getLastName()); $lines[] = sprintf('%s %s', $details->getPhone(), $details->getSecondaryPhone()); $lines[] = $details->getEmail(); return implode($lineSeparator, $lines); }
[ "public", "function", "formatContactDetails", "(", "ClientContactDetailsInterface", "$", "details", ",", "$", "lineSeparator", "=", "self", "::", "LINES_SEPARATOR", ")", "{", "$", "lines", "=", "[", "]", ";", "$", "lines", "[", "]", "=", "sprintf", "(", "'%s %s'", ",", "$", "details", "->", "getFirstName", "(", ")", ",", "$", "details", "->", "getLastName", "(", ")", ")", ";", "$", "lines", "[", "]", "=", "sprintf", "(", "'%s %s'", ",", "$", "details", "->", "getPhone", "(", ")", ",", "$", "details", "->", "getSecondaryPhone", "(", ")", ")", ";", "$", "lines", "[", "]", "=", "$", "details", "->", "getEmail", "(", ")", ";", "return", "implode", "(", "$", "lineSeparator", ",", "$", "lines", ")", ";", "}" ]
Formats the contact details @param ClientContactDetailsInterface $details @param string $lineSeparator @return string
[ "Formats", "the", "contact", "details" ]
b19aa5c962e67972f79338d2f341b30fa1ee879e
https://github.com/WellCommerce/ClientBundle/blob/b19aa5c962e67972f79338d2f341b30fa1ee879e/Twig/Extension/ClientAddressFormatterExtension.php#L96-L104
train
raphievila/xtags
src/xTags.php
xTags.frm
public function frm($txt, $att = '', $a = '', $m = '', $e = '') { $attList = array(); if (!empty($a)) { $attList['action'] = $a; } if (!empty($m)) { $attList['method'] = $m; } if (!empty($e)) { $attList['enctype'] = $e; } $newatt = $this->addAttributes($attList, $att); return $this->tag('form', $txt, $newatt); }
php
public function frm($txt, $att = '', $a = '', $m = '', $e = '') { $attList = array(); if (!empty($a)) { $attList['action'] = $a; } if (!empty($m)) { $attList['method'] = $m; } if (!empty($e)) { $attList['enctype'] = $e; } $newatt = $this->addAttributes($attList, $att); return $this->tag('form', $txt, $newatt); }
[ "public", "function", "frm", "(", "$", "txt", ",", "$", "att", "=", "''", ",", "$", "a", "=", "''", ",", "$", "m", "=", "''", ",", "$", "e", "=", "''", ")", "{", "$", "attList", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "a", ")", ")", "{", "$", "attList", "[", "'action'", "]", "=", "$", "a", ";", "}", "if", "(", "!", "empty", "(", "$", "m", ")", ")", "{", "$", "attList", "[", "'method'", "]", "=", "$", "m", ";", "}", "if", "(", "!", "empty", "(", "$", "e", ")", ")", "{", "$", "attList", "[", "'enctype'", "]", "=", "$", "e", ";", "}", "$", "newatt", "=", "$", "this", "->", "addAttributes", "(", "$", "attList", ",", "$", "att", ")", ";", "return", "$", "this", "->", "tag", "(", "'form'", ",", "$", "txt", ",", "$", "newatt", ")", ";", "}" ]
complex tags predefined to simplify coding
[ "complex", "tags", "predefined", "to", "simplify", "coding" ]
cd05cc4d8811662becffb0dd1abce30d8436f2c7
https://github.com/raphievila/xtags/blob/cd05cc4d8811662becffb0dd1abce30d8436f2c7/src/xTags.php#L213-L228
train
TitaPHP/framework
src/TitaPHP/Foundation/Application.php
Application.setConfig
public function setConfig( $param, $value ) { $dn = new DotNotation($this->configs); $dn->set($param, $value); $this->configs = $dn->getValues(); }
php
public function setConfig( $param, $value ) { $dn = new DotNotation($this->configs); $dn->set($param, $value); $this->configs = $dn->getValues(); }
[ "public", "function", "setConfig", "(", "$", "param", ",", "$", "value", ")", "{", "$", "dn", "=", "new", "DotNotation", "(", "$", "this", "->", "configs", ")", ";", "$", "dn", "->", "set", "(", "$", "param", ",", "$", "value", ")", ";", "$", "this", "->", "configs", "=", "$", "dn", "->", "getValues", "(", ")", ";", "}" ]
Set configuration parameter. @param string $param @param string $value @return void
[ "Set", "configuration", "parameter", "." ]
72283a45733a49c1d9c1fc0eba22ff13a802295c
https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Foundation/Application.php#L127-L132
train
TitaPHP/framework
src/TitaPHP/Foundation/Application.php
Application.getConfig
public function getConfig( $param, $defaultValue = null ) { $dn = new DotNotation($this->configs); return $dn->get($param, $defaultValue); }
php
public function getConfig( $param, $defaultValue = null ) { $dn = new DotNotation($this->configs); return $dn->get($param, $defaultValue); }
[ "public", "function", "getConfig", "(", "$", "param", ",", "$", "defaultValue", "=", "null", ")", "{", "$", "dn", "=", "new", "DotNotation", "(", "$", "this", "->", "configs", ")", ";", "return", "$", "dn", "->", "get", "(", "$", "param", ",", "$", "defaultValue", ")", ";", "}" ]
Get Configuration Value. @param string $param @param null $defaultValue @return mixed
[ "Get", "Configuration", "Value", "." ]
72283a45733a49c1d9c1fc0eba22ff13a802295c
https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Foundation/Application.php#L143-L147
train
TitaPHP/framework
src/TitaPHP/Foundation/Application.php
Application.loadProviders
protected function loadProviders($providers) { foreach ((array) $providers as $provider) { $provider = $this->container->get($provider); if (!$provider instanceof ServiceProviderInterface) { $providerName = get_class($provider); throw new \Exception( "$providerName does not implement required \\TitaPHP\\Foundation\\ServiceProviderInterface Interface" ); } $provider->register($this); } }
php
protected function loadProviders($providers) { foreach ((array) $providers as $provider) { $provider = $this->container->get($provider); if (!$provider instanceof ServiceProviderInterface) { $providerName = get_class($provider); throw new \Exception( "$providerName does not implement required \\TitaPHP\\Foundation\\ServiceProviderInterface Interface" ); } $provider->register($this); } }
[ "protected", "function", "loadProviders", "(", "$", "providers", ")", "{", "foreach", "(", "(", "array", ")", "$", "providers", "as", "$", "provider", ")", "{", "$", "provider", "=", "$", "this", "->", "container", "->", "get", "(", "$", "provider", ")", ";", "if", "(", "!", "$", "provider", "instanceof", "ServiceProviderInterface", ")", "{", "$", "providerName", "=", "get_class", "(", "$", "provider", ")", ";", "throw", "new", "\\", "Exception", "(", "\"$providerName does not implement required \\\\TitaPHP\\\\Foundation\\\\ServiceProviderInterface Interface\"", ")", ";", "}", "$", "provider", "->", "register", "(", "$", "this", ")", ";", "}", "}" ]
Register Providers into the Application. @param array $providers @return void @throws \Exception
[ "Register", "Providers", "into", "the", "Application", "." ]
72283a45733a49c1d9c1fc0eba22ff13a802295c
https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Foundation/Application.php#L178-L192
train
TitaPHP/framework
src/TitaPHP/Foundation/Application.php
Application.loadEvents
protected function loadEvents($appEvents) { foreach ((array) $appEvents as $appEventType => $events) { foreach ($events as $event) { $this->eventDispatcher->addListener($appEventType, $this->container->get($event)); } } }
php
protected function loadEvents($appEvents) { foreach ((array) $appEvents as $appEventType => $events) { foreach ($events as $event) { $this->eventDispatcher->addListener($appEventType, $this->container->get($event)); } } }
[ "protected", "function", "loadEvents", "(", "$", "appEvents", ")", "{", "foreach", "(", "(", "array", ")", "$", "appEvents", "as", "$", "appEventType", "=>", "$", "events", ")", "{", "foreach", "(", "$", "events", "as", "$", "event", ")", "{", "$", "this", "->", "eventDispatcher", "->", "addListener", "(", "$", "appEventType", ",", "$", "this", "->", "container", "->", "get", "(", "$", "event", ")", ")", ";", "}", "}", "}" ]
Register Event Listeners. @param array $appEvents @return void
[ "Register", "Event", "Listeners", "." ]
72283a45733a49c1d9c1fc0eba22ff13a802295c
https://github.com/TitaPHP/framework/blob/72283a45733a49c1d9c1fc0eba22ff13a802295c/src/TitaPHP/Foundation/Application.php#L200-L207
train
phossa/phossa-config
src/Phossa/Config/Parameter.php
Parameter.getSuperGlobalValue
protected function getSuperGlobalValue(/*# string */ $name) { $pos = strpos($name, $this->field_splitter); if (false !== $pos) { $pref = substr($name, 0, $pos); $suff = substr($name, $pos + 1); if (isset($GLOBALS[$pref][$suff])) { return $GLOBALS[$pref][$suff]; } } else { $pref = $name; if (isset($GLOBALS[$pref])) { return $GLOBALS[$pref]; } } return null; }
php
protected function getSuperGlobalValue(/*# string */ $name) { $pos = strpos($name, $this->field_splitter); if (false !== $pos) { $pref = substr($name, 0, $pos); $suff = substr($name, $pos + 1); if (isset($GLOBALS[$pref][$suff])) { return $GLOBALS[$pref][$suff]; } } else { $pref = $name; if (isset($GLOBALS[$pref])) { return $GLOBALS[$pref]; } } return null; }
[ "protected", "function", "getSuperGlobalValue", "(", "/*# string */", "$", "name", ")", "{", "$", "pos", "=", "strpos", "(", "$", "name", ",", "$", "this", "->", "field_splitter", ")", ";", "if", "(", "false", "!==", "$", "pos", ")", "{", "$", "pref", "=", "substr", "(", "$", "name", ",", "0", ",", "$", "pos", ")", ";", "$", "suff", "=", "substr", "(", "$", "name", ",", "$", "pos", "+", "1", ")", ";", "if", "(", "isset", "(", "$", "GLOBALS", "[", "$", "pref", "]", "[", "$", "suff", "]", ")", ")", "{", "return", "$", "GLOBALS", "[", "$", "pref", "]", "[", "$", "suff", "]", ";", "}", "}", "else", "{", "$", "pref", "=", "$", "name", ";", "if", "(", "isset", "(", "$", "GLOBALS", "[", "$", "pref", "]", ")", ")", "{", "return", "$", "GLOBALS", "[", "$", "pref", "]", ";", "}", "}", "return", "null", ";", "}" ]
Get super global value @param string $name something like '_SERVER.HTTP_HOST' @return string|array @access protected
[ "Get", "super", "global", "value" ]
fdb90831da06408bb674ab777754e67025604bed
https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Parameter.php#L165-L181
train
phossa/phossa-config
src/Phossa/Config/Parameter.php
Parameter.exceptionIfNotString
protected function exceptionIfNotString($key) { if (!is_string($key)) { throw new InvalidArgumentException( Message::get(Message::CONFIG_KEY_INVALID, $key), Message::CONFIG_KEY_INVALID ); } }
php
protected function exceptionIfNotString($key) { if (!is_string($key)) { throw new InvalidArgumentException( Message::get(Message::CONFIG_KEY_INVALID, $key), Message::CONFIG_KEY_INVALID ); } }
[ "protected", "function", "exceptionIfNotString", "(", "$", "key", ")", "{", "if", "(", "!", "is_string", "(", "$", "key", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "Message", "::", "get", "(", "Message", "::", "CONFIG_KEY_INVALID", ",", "$", "key", ")", ",", "Message", "::", "CONFIG_KEY_INVALID", ")", ";", "}", "}" ]
Throw exception if not a string @param string $key @throws InvalidArgumentException if $key not a string @access public
[ "Throw", "exception", "if", "not", "a", "string" ]
fdb90831da06408bb674ab777754e67025604bed
https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Parameter.php#L190-L198
train
agentmedia/phine-core
src/Core/Logic/Routing/FrontendRouter.php
FrontendRouter.GatherParams
static function GatherParams($url) { $reader = new StringReader($url); $param = ''; $params = array(); $start = false; while (false !== ($ch = $reader->ReadChar())) { if ($ch == '{') { $start = true; } else if ($ch == '}' && $start) { $params[] = $param; $param = ''; $start = false; } else if ($start) { $param .= $ch; } } return $params; }
php
static function GatherParams($url) { $reader = new StringReader($url); $param = ''; $params = array(); $start = false; while (false !== ($ch = $reader->ReadChar())) { if ($ch == '{') { $start = true; } else if ($ch == '}' && $start) { $params[] = $param; $param = ''; $start = false; } else if ($start) { $param .= $ch; } } return $params; }
[ "static", "function", "GatherParams", "(", "$", "url", ")", "{", "$", "reader", "=", "new", "StringReader", "(", "$", "url", ")", ";", "$", "param", "=", "''", ";", "$", "params", "=", "array", "(", ")", ";", "$", "start", "=", "false", ";", "while", "(", "false", "!==", "(", "$", "ch", "=", "$", "reader", "->", "ReadChar", "(", ")", ")", ")", "{", "if", "(", "$", "ch", "==", "'{'", ")", "{", "$", "start", "=", "true", ";", "}", "else", "if", "(", "$", "ch", "==", "'}'", "&&", "$", "start", ")", "{", "$", "params", "[", "]", "=", "$", "param", ";", "$", "param", "=", "''", ";", "$", "start", "=", "false", ";", "}", "else", "if", "(", "$", "start", ")", "{", "$", "param", ".=", "$", "ch", ";", "}", "}", "return", "$", "params", ";", "}" ]
Gathers the obligatory parameters from the url @param string $url The page url @return string[] Array of parameter names
[ "Gathers", "the", "obligatory", "parameters", "from", "the", "url" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Routing/FrontendRouter.php#L26-L46
train
agentmedia/phine-core
src/Core/Logic/Routing/FrontendRouter.php
FrontendRouter.PageUrl
static function PageUrl(Page $page, array $params = array(), $fragment = '') { $siteUrl = $page->GetSite()->GetUrl(); $pageUrl = $page->GetUrl(); if ($pageUrl == 'index.html') { $url = $siteUrl; } else { $url = Path::Combine($siteUrl, $pageUrl); } $oblParams = self::GatherParams($url); $urlObl = self::AttachObligatoryParams($url, $oblParams, $params); $urlAllParams = self::AttachMoreParams($urlObl, $oblParams, $params); return $fragment ? $urlAllParams . '#' . $fragment : $urlAllParams; }
php
static function PageUrl(Page $page, array $params = array(), $fragment = '') { $siteUrl = $page->GetSite()->GetUrl(); $pageUrl = $page->GetUrl(); if ($pageUrl == 'index.html') { $url = $siteUrl; } else { $url = Path::Combine($siteUrl, $pageUrl); } $oblParams = self::GatherParams($url); $urlObl = self::AttachObligatoryParams($url, $oblParams, $params); $urlAllParams = self::AttachMoreParams($urlObl, $oblParams, $params); return $fragment ? $urlAllParams . '#' . $fragment : $urlAllParams; }
[ "static", "function", "PageUrl", "(", "Page", "$", "page", ",", "array", "$", "params", "=", "array", "(", ")", ",", "$", "fragment", "=", "''", ")", "{", "$", "siteUrl", "=", "$", "page", "->", "GetSite", "(", ")", "->", "GetUrl", "(", ")", ";", "$", "pageUrl", "=", "$", "page", "->", "GetUrl", "(", ")", ";", "if", "(", "$", "pageUrl", "==", "'index.html'", ")", "{", "$", "url", "=", "$", "siteUrl", ";", "}", "else", "{", "$", "url", "=", "Path", "::", "Combine", "(", "$", "siteUrl", ",", "$", "pageUrl", ")", ";", "}", "$", "oblParams", "=", "self", "::", "GatherParams", "(", "$", "url", ")", ";", "$", "urlObl", "=", "self", "::", "AttachObligatoryParams", "(", "$", "url", ",", "$", "oblParams", ",", "$", "params", ")", ";", "$", "urlAllParams", "=", "self", "::", "AttachMoreParams", "(", "$", "urlObl", ",", "$", "oblParams", ",", "$", "params", ")", ";", "return", "$", "fragment", "?", "$", "urlAllParams", ".", "'#'", ".", "$", "fragment", ":", "$", "urlAllParams", ";", "}" ]
Returns the url of a page with parameters and fragment @param Page $page The page @param array $params All parameters @return string Return the page url
[ "Returns", "the", "url", "of", "a", "page", "with", "parameters", "and", "fragment" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Routing/FrontendRouter.php#L54-L70
train
agentmedia/phine-core
src/Core/Logic/Routing/FrontendRouter.php
FrontendRouter.Url
static function Url(PageUrl $pageUrl, array $additionalParameters = array()) { $list = new PageParamListProvider($pageUrl); $params = $list->ToArray(); foreach ($additionalParameters as $key => $value) { $params[$key] = $value; } return self::PageUrl($pageUrl->GetPage(), $params, $pageUrl->GetFragment()); }
php
static function Url(PageUrl $pageUrl, array $additionalParameters = array()) { $list = new PageParamListProvider($pageUrl); $params = $list->ToArray(); foreach ($additionalParameters as $key => $value) { $params[$key] = $value; } return self::PageUrl($pageUrl->GetPage(), $params, $pageUrl->GetFragment()); }
[ "static", "function", "Url", "(", "PageUrl", "$", "pageUrl", ",", "array", "$", "additionalParameters", "=", "array", "(", ")", ")", "{", "$", "list", "=", "new", "PageParamListProvider", "(", "$", "pageUrl", ")", ";", "$", "params", "=", "$", "list", "->", "ToArray", "(", ")", ";", "foreach", "(", "$", "additionalParameters", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "params", "[", "$", "key", "]", "=", "$", "value", ";", "}", "return", "self", "::", "PageUrl", "(", "$", "pageUrl", "->", "GetPage", "(", ")", ",", "$", "params", ",", "$", "pageUrl", "->", "GetFragment", "(", ")", ")", ";", "}" ]
Gets the url for a page url entity @param PageUrl $pageUrl The page url as stored in the database @param array $additionalParameters Additional parameters; will override stored parameters with same keys @return string Returns the page url
[ "Gets", "the", "url", "for", "a", "page", "url", "entity" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Routing/FrontendRouter.php#L78-L86
train
agentmedia/phine-core
src/Core/Logic/Routing/FrontendRouter.php
FrontendRouter.AttachObligatoryParams
private static function AttachObligatoryParams($url, array $oblParams, array $params) { foreach ($oblParams as $oblParam) { $value = ''; if (!array_key_exists($oblParam, $params)) { $value = Request::GetData($oblParam); } else { $value = $params[$oblParam]; } if ($value) { $url = str_replace('{' . $oblParam . '}', $value, $url); } } return $url; }
php
private static function AttachObligatoryParams($url, array $oblParams, array $params) { foreach ($oblParams as $oblParam) { $value = ''; if (!array_key_exists($oblParam, $params)) { $value = Request::GetData($oblParam); } else { $value = $params[$oblParam]; } if ($value) { $url = str_replace('{' . $oblParam . '}', $value, $url); } } return $url; }
[ "private", "static", "function", "AttachObligatoryParams", "(", "$", "url", ",", "array", "$", "oblParams", ",", "array", "$", "params", ")", "{", "foreach", "(", "$", "oblParams", "as", "$", "oblParam", ")", "{", "$", "value", "=", "''", ";", "if", "(", "!", "array_key_exists", "(", "$", "oblParam", ",", "$", "params", ")", ")", "{", "$", "value", "=", "Request", "::", "GetData", "(", "$", "oblParam", ")", ";", "}", "else", "{", "$", "value", "=", "$", "params", "[", "$", "oblParam", "]", ";", "}", "if", "(", "$", "value", ")", "{", "$", "url", "=", "str_replace", "(", "'{'", ".", "$", "oblParam", ".", "'}'", ",", "$", "value", ",", "$", "url", ")", ";", "}", "}", "return", "$", "url", ";", "}" ]
Attaches obligatory parameters @param string $url The url pattern as given by the associated page property @param array $oblParams The names of the obligatory parameters @param array $params All given parameters for appending @return string Returns the url with obligatory paramters attached @throws \LogicException Raises an error if an obligatory parameter is missing
[ "Attaches", "obligatory", "parameters" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Routing/FrontendRouter.php#L96-L112
train
agentmedia/phine-core
src/Core/Logic/Routing/FrontendRouter.php
FrontendRouter.AttachMoreParams
private static function AttachMoreParams($url, array $oblParams, array $params) { $moreParams = array(); foreach ($params as $key => $value) { if (!in_array($key, $oblParams)) { $moreParams[$key] = $value; } } if (count($moreParams)) { $url .= '?' . http_build_query($moreParams, null, '&'); } return $url; }
php
private static function AttachMoreParams($url, array $oblParams, array $params) { $moreParams = array(); foreach ($params as $key => $value) { if (!in_array($key, $oblParams)) { $moreParams[$key] = $value; } } if (count($moreParams)) { $url .= '?' . http_build_query($moreParams, null, '&'); } return $url; }
[ "private", "static", "function", "AttachMoreParams", "(", "$", "url", ",", "array", "$", "oblParams", ",", "array", "$", "params", ")", "{", "$", "moreParams", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "oblParams", ")", ")", "{", "$", "moreParams", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "if", "(", "count", "(", "$", "moreParams", ")", ")", "{", "$", "url", ".=", "'?'", ".", "http_build_query", "(", "$", "moreParams", ",", "null", ",", "'&'", ")", ";", "}", "return", "$", "url", ";", "}" ]
Attaches none oblique url paramters @param string $url The url with obligatory parameters already attached @param array $oblParams The names of the obligatory parameters @param array $params All url parameters @return string Returns the url with all paramteters attached
[ "Attaches", "none", "oblique", "url", "paramters" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Routing/FrontendRouter.php#L121-L133
train
agentmedia/phine-core
src/Core/Logic/Routing/FrontendRouter.php
FrontendRouter.Page404
static function Page404(Site $site) { $sql = Access::SqlBuilder(); $tblPage = Page::Schema()->Table(); $where = $sql->Equals($tblPage->Field('Type'), $sql->Value((string) PageType::NotFound())) ->And_($sql->Equals($tblPage->Field('Site'), $sql->Value($site->GetID()))); return Page::Schema()->First($where); }
php
static function Page404(Site $site) { $sql = Access::SqlBuilder(); $tblPage = Page::Schema()->Table(); $where = $sql->Equals($tblPage->Field('Type'), $sql->Value((string) PageType::NotFound())) ->And_($sql->Equals($tblPage->Field('Site'), $sql->Value($site->GetID()))); return Page::Schema()->First($where); }
[ "static", "function", "Page404", "(", "Site", "$", "site", ")", "{", "$", "sql", "=", "Access", "::", "SqlBuilder", "(", ")", ";", "$", "tblPage", "=", "Page", "::", "Schema", "(", ")", "->", "Table", "(", ")", ";", "$", "where", "=", "$", "sql", "->", "Equals", "(", "$", "tblPage", "->", "Field", "(", "'Type'", ")", ",", "$", "sql", "->", "Value", "(", "(", "string", ")", "PageType", "::", "NotFound", "(", ")", ")", ")", "->", "And_", "(", "$", "sql", "->", "Equals", "(", "$", "tblPage", "->", "Field", "(", "'Site'", ")", ",", "$", "sql", "->", "Value", "(", "$", "site", "->", "GetID", "(", ")", ")", ")", ")", ";", "return", "Page", "::", "Schema", "(", ")", "->", "First", "(", "$", "where", ")", ";", "}" ]
Finds the 404 page for a site @param Site $site The site whise 404 page is searched for @return Page The 404 page
[ "Finds", "the", "404", "page", "for", "a", "site" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Routing/FrontendRouter.php#L140-L148
train
phossa/phossa-config
src/Phossa/Config/Reference/ReferenceTrait.php
ReferenceTrait.getPattern
protected function getPattern()/*# : string */ { if (is_null($this->reference_pattern)) { if ('' === $this->reference_start || is_null($this->reference_end)) { $this->reference_pattern = ''; } else { $this->reference_pattern = '~(' . preg_quote($this->reference_start) . '([a-zA-Z_][a-zA-Z0-9._]*+)' . preg_quote($this->reference_end) . ')~'; } } return $this->reference_pattern; }
php
protected function getPattern()/*# : string */ { if (is_null($this->reference_pattern)) { if ('' === $this->reference_start || is_null($this->reference_end)) { $this->reference_pattern = ''; } else { $this->reference_pattern = '~(' . preg_quote($this->reference_start) . '([a-zA-Z_][a-zA-Z0-9._]*+)' . preg_quote($this->reference_end) . ')~'; } } return $this->reference_pattern; }
[ "protected", "function", "getPattern", "(", ")", "/*# : string */", "{", "if", "(", "is_null", "(", "$", "this", "->", "reference_pattern", ")", ")", "{", "if", "(", "''", "===", "$", "this", "->", "reference_start", "||", "is_null", "(", "$", "this", "->", "reference_end", ")", ")", "{", "$", "this", "->", "reference_pattern", "=", "''", ";", "}", "else", "{", "$", "this", "->", "reference_pattern", "=", "'~('", ".", "preg_quote", "(", "$", "this", "->", "reference_start", ")", ".", "'([a-zA-Z_][a-zA-Z0-9._]*+)'", ".", "preg_quote", "(", "$", "this", "->", "reference_end", ")", ".", "')~'", ";", "}", "}", "return", "$", "this", "->", "reference_pattern", ";", "}" ]
Get the reference pattern @return string @access protected
[ "Get", "the", "reference", "pattern" ]
fdb90831da06408bb674ab777754e67025604bed
https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Reference/ReferenceTrait.php#L181-L195
train
phossa/phossa-config
src/Phossa/Config/Reference/ReferenceTrait.php
ReferenceTrait.deReferenceArray
protected function deReferenceArray( array &$dataArray, /*# bool */ $clearCache = false ) { // reference feature disabled if ('' === $this->getPattern()) { return; } // clear old cache if ($clearCache) { $this->loop_detect = []; } try { foreach ($dataArray as $idx => &$data) { // go deeper if is array if (is_array($data)) { $this->dereferenceArray($data); // $data is string } elseif (is_string($data)) { $key = $data; if (isset($this->loop_detect[$key])) { $data = $this->loop_detect[$key]; } else { $data = $this->deReference($data); if (is_array($data)) { $this->dereferenceArray($data); } $this->loop_detect[$key] = $data; } } } } catch (\Exception $e) { throw new LogicException($e->getMessage(), $e->getCode(), $e); } }
php
protected function deReferenceArray( array &$dataArray, /*# bool */ $clearCache = false ) { // reference feature disabled if ('' === $this->getPattern()) { return; } // clear old cache if ($clearCache) { $this->loop_detect = []; } try { foreach ($dataArray as $idx => &$data) { // go deeper if is array if (is_array($data)) { $this->dereferenceArray($data); // $data is string } elseif (is_string($data)) { $key = $data; if (isset($this->loop_detect[$key])) { $data = $this->loop_detect[$key]; } else { $data = $this->deReference($data); if (is_array($data)) { $this->dereferenceArray($data); } $this->loop_detect[$key] = $data; } } } } catch (\Exception $e) { throw new LogicException($e->getMessage(), $e->getCode(), $e); } }
[ "protected", "function", "deReferenceArray", "(", "array", "&", "$", "dataArray", ",", "/*# bool */", "$", "clearCache", "=", "false", ")", "{", "// reference feature disabled", "if", "(", "''", "===", "$", "this", "->", "getPattern", "(", ")", ")", "{", "return", ";", "}", "// clear old cache", "if", "(", "$", "clearCache", ")", "{", "$", "this", "->", "loop_detect", "=", "[", "]", ";", "}", "try", "{", "foreach", "(", "$", "dataArray", "as", "$", "idx", "=>", "&", "$", "data", ")", "{", "// go deeper if is array", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "dereferenceArray", "(", "$", "data", ")", ";", "// $data is string", "}", "elseif", "(", "is_string", "(", "$", "data", ")", ")", "{", "$", "key", "=", "$", "data", ";", "if", "(", "isset", "(", "$", "this", "->", "loop_detect", "[", "$", "key", "]", ")", ")", "{", "$", "data", "=", "$", "this", "->", "loop_detect", "[", "$", "key", "]", ";", "}", "else", "{", "$", "data", "=", "$", "this", "->", "deReference", "(", "$", "data", ")", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "dereferenceArray", "(", "$", "data", ")", ";", "}", "$", "this", "->", "loop_detect", "[", "$", "key", "]", "=", "$", "data", ";", "}", "}", "}", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "LogicException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Derefence all references in an array @param array &$dataArray @param bool $clearCache clear dereference cache @throws LogicException if malformed reference found @access protected
[ "Derefence", "all", "references", "in", "an", "array" ]
fdb90831da06408bb674ab777754e67025604bed
https://github.com/phossa/phossa-config/blob/fdb90831da06408bb674ab777754e67025604bed/src/Phossa/Config/Reference/ReferenceTrait.php#L231-L268
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.BundleFolder
static function BundleFolder($bundleName) { $packageBundles = self::PackageBundles(); if (isset($packageBundles[$bundleName])) { return $packageBundles[$bundleName]; } return Path::Combine(self::AppBundlesFolder(), $bundleName); }
php
static function BundleFolder($bundleName) { $packageBundles = self::PackageBundles(); if (isset($packageBundles[$bundleName])) { return $packageBundles[$bundleName]; } return Path::Combine(self::AppBundlesFolder(), $bundleName); }
[ "static", "function", "BundleFolder", "(", "$", "bundleName", ")", "{", "$", "packageBundles", "=", "self", "::", "PackageBundles", "(", ")", ";", "if", "(", "isset", "(", "$", "packageBundles", "[", "$", "bundleName", "]", ")", ")", "{", "return", "$", "packageBundles", "[", "$", "bundleName", "]", ";", "}", "return", "Path", "::", "Combine", "(", "self", "::", "AppBundlesFolder", "(", ")", ",", "$", "bundleName", ")", ";", "}" ]
Gets the folder for the bundle @param string $bundleName The name of the bundle @return string Returns the bundle directory path
[ "Gets", "the", "folder", "for", "the", "bundle" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L27-L34
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.Modules
static function Modules($bundleName, ModuleLocation $location) { $result = array(); $modulesFolder = Path::Combine(self::BundleFolder($bundleName), 'Modules'); $folder = Path::Combine($modulesFolder, (string)$location); if (!Folder::Exists($folder)) { return $result; } $files = Folder::GetFiles($folder); foreach ($files as $file) { $result[] = Path::RemoveExtension($file); } return $result; }
php
static function Modules($bundleName, ModuleLocation $location) { $result = array(); $modulesFolder = Path::Combine(self::BundleFolder($bundleName), 'Modules'); $folder = Path::Combine($modulesFolder, (string)$location); if (!Folder::Exists($folder)) { return $result; } $files = Folder::GetFiles($folder); foreach ($files as $file) { $result[] = Path::RemoveExtension($file); } return $result; }
[ "static", "function", "Modules", "(", "$", "bundleName", ",", "ModuleLocation", "$", "location", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "modulesFolder", "=", "Path", "::", "Combine", "(", "self", "::", "BundleFolder", "(", "$", "bundleName", ")", ",", "'Modules'", ")", ";", "$", "folder", "=", "Path", "::", "Combine", "(", "$", "modulesFolder", ",", "(", "string", ")", "$", "location", ")", ";", "if", "(", "!", "Folder", "::", "Exists", "(", "$", "folder", ")", ")", "{", "return", "$", "result", ";", "}", "$", "files", "=", "Folder", "::", "GetFiles", "(", "$", "folder", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "result", "[", "]", "=", "Path", "::", "RemoveExtension", "(", "$", "file", ")", ";", "}", "return", "$", "result", ";", "}" ]
Gets all modules in a bundle @param string $bundleName @param ModuleLocation $location Backend or frontend @return string[] Returns the module names
[ "Gets", "all", "modules", "in", "a", "bundle" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L100-L114
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.BundleTranslationsFile
static function BundleTranslationsFile(ModuleBase $module, $lang) { $moduleTransFolder = self::ModuleTranslationsFolder($module); $bundleTransFolder = Path::Directory($moduleTransFolder); $file = Path::Combine($bundleTransFolder, $lang); return Path::AddExtension($file, 'php'); }
php
static function BundleTranslationsFile(ModuleBase $module, $lang) { $moduleTransFolder = self::ModuleTranslationsFolder($module); $bundleTransFolder = Path::Directory($moduleTransFolder); $file = Path::Combine($bundleTransFolder, $lang); return Path::AddExtension($file, 'php'); }
[ "static", "function", "BundleTranslationsFile", "(", "ModuleBase", "$", "module", ",", "$", "lang", ")", "{", "$", "moduleTransFolder", "=", "self", "::", "ModuleTranslationsFolder", "(", "$", "module", ")", ";", "$", "bundleTransFolder", "=", "Path", "::", "Directory", "(", "$", "moduleTransFolder", ")", ";", "$", "file", "=", "Path", "::", "Combine", "(", "$", "bundleTransFolder", ",", "$", "lang", ")", ";", "return", "Path", "::", "AddExtension", "(", "$", "file", ",", "'php'", ")", ";", "}" ]
Gets the bundle translations file @param ModuleBase $module @param string $lang @return string Returns the bundle translations file
[ "Gets", "the", "bundle", "translations", "file" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L182-L188
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.ModuleTranslationsFolder
static function ModuleTranslationsFolder(ModuleBase $module) { $class = new \ReflectionClass($module); $classFile = Str::Replace('\\', '/', $class->getFileName()); return Str::Replace('/Modules/', '/Translations/', Path::RemoveExtension($classFile)); }
php
static function ModuleTranslationsFolder(ModuleBase $module) { $class = new \ReflectionClass($module); $classFile = Str::Replace('\\', '/', $class->getFileName()); return Str::Replace('/Modules/', '/Translations/', Path::RemoveExtension($classFile)); }
[ "static", "function", "ModuleTranslationsFolder", "(", "ModuleBase", "$", "module", ")", "{", "$", "class", "=", "new", "\\", "ReflectionClass", "(", "$", "module", ")", ";", "$", "classFile", "=", "Str", "::", "Replace", "(", "'\\\\'", ",", "'/'", ",", "$", "class", "->", "getFileName", "(", ")", ")", ";", "return", "Str", "::", "Replace", "(", "'/Modules/'", ",", "'/Translations/'", ",", "Path", "::", "RemoveExtension", "(", "$", "classFile", ")", ")", ";", "}" ]
Gets the translations folder for a module @param ModuleBase $module @return string Returns the folder of the module translationss
[ "Gets", "the", "translations", "folder", "for", "a", "module" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L194-L199
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.ModuleTranslationsFile
static function ModuleTranslationsFile(ModuleBase $module, $lang) { $folder = self::ModuleTranslationsFolder($module); $file = Path::Combine($folder, $lang); return Path::AddExtension($file, 'php'); }
php
static function ModuleTranslationsFile(ModuleBase $module, $lang) { $folder = self::ModuleTranslationsFolder($module); $file = Path::Combine($folder, $lang); return Path::AddExtension($file, 'php'); }
[ "static", "function", "ModuleTranslationsFile", "(", "ModuleBase", "$", "module", ",", "$", "lang", ")", "{", "$", "folder", "=", "self", "::", "ModuleTranslationsFolder", "(", "$", "module", ")", ";", "$", "file", "=", "Path", "::", "Combine", "(", "$", "folder", ",", "$", "lang", ")", ";", "return", "Path", "::", "AddExtension", "(", "$", "file", ",", "'php'", ")", ";", "}" ]
Gets the translations file for a module @param ModuleBase $module The module @param string $lang The desired language @return string Returns the file with specific translations for a module
[ "Gets", "the", "translations", "file", "for", "a", "module" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L207-L212
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.ModuleCustomTemplatesFolder
static function ModuleCustomTemplatesFolder(TemplateModule $module) { $parentFolder = Path::Combine(PHINE_PATH, 'App/Phine/ModuleTemplates'); $bundleFolder = Path::Combine($parentFolder, $module->MyBundle()); return Path::Combine($bundleFolder, $module->MyName()); }
php
static function ModuleCustomTemplatesFolder(TemplateModule $module) { $parentFolder = Path::Combine(PHINE_PATH, 'App/Phine/ModuleTemplates'); $bundleFolder = Path::Combine($parentFolder, $module->MyBundle()); return Path::Combine($bundleFolder, $module->MyName()); }
[ "static", "function", "ModuleCustomTemplatesFolder", "(", "TemplateModule", "$", "module", ")", "{", "$", "parentFolder", "=", "Path", "::", "Combine", "(", "PHINE_PATH", ",", "'App/Phine/ModuleTemplates'", ")", ";", "$", "bundleFolder", "=", "Path", "::", "Combine", "(", "$", "parentFolder", ",", "$", "module", "->", "MyBundle", "(", ")", ")", ";", "return", "Path", "::", "Combine", "(", "$", "bundleFolder", ",", "$", "module", "->", "MyName", "(", ")", ")", ";", "}" ]
Gets the folder for @param TemplateModule $module @return string
[ "Gets", "the", "folder", "for" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L220-L225
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.LayoutTemplate
static function LayoutTemplate(Layout $layout) { $folder = Path::Combine(PHINE_PATH, 'App/Phine/LayoutTemplates'); $file = Path::Combine($folder, $layout->GetName()); return Path::AddExtension($file, 'phtml'); }
php
static function LayoutTemplate(Layout $layout) { $folder = Path::Combine(PHINE_PATH, 'App/Phine/LayoutTemplates'); $file = Path::Combine($folder, $layout->GetName()); return Path::AddExtension($file, 'phtml'); }
[ "static", "function", "LayoutTemplate", "(", "Layout", "$", "layout", ")", "{", "$", "folder", "=", "Path", "::", "Combine", "(", "PHINE_PATH", ",", "'App/Phine/LayoutTemplates'", ")", ";", "$", "file", "=", "Path", "::", "Combine", "(", "$", "folder", ",", "$", "layout", "->", "GetName", "(", ")", ")", ";", "return", "Path", "::", "AddExtension", "(", "$", "file", ",", "'phtml'", ")", ";", "}" ]
The template file for a page layout @param Layout $layout The page layout @return string Returns the layout template path
[ "The", "template", "file", "for", "a", "page", "layout" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L232-L237
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.SitemapCacheFile
static function SitemapCacheFile(Site $site) { $cacheFolder = Path::Combine(PHINE_PATH, 'App/Phine/Cache/Sitemap'); $filename = Path::AddExtension($site->GetID(), 'xml'); return Path::Combine($cacheFolder, $filename); }
php
static function SitemapCacheFile(Site $site) { $cacheFolder = Path::Combine(PHINE_PATH, 'App/Phine/Cache/Sitemap'); $filename = Path::AddExtension($site->GetID(), 'xml'); return Path::Combine($cacheFolder, $filename); }
[ "static", "function", "SitemapCacheFile", "(", "Site", "$", "site", ")", "{", "$", "cacheFolder", "=", "Path", "::", "Combine", "(", "PHINE_PATH", ",", "'App/Phine/Cache/Sitemap'", ")", ";", "$", "filename", "=", "Path", "::", "AddExtension", "(", "$", "site", "->", "GetID", "(", ")", ",", "'xml'", ")", ";", "return", "Path", "::", "Combine", "(", "$", "cacheFolder", ",", "$", "filename", ")", ";", "}" ]
The name of the cache file of the @param Site $site The site @return string Returns the full file path of the sitemap cache file
[ "The", "name", "of", "the", "cache", "file", "of", "the" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L337-L342
train
agentmedia/phine-core
src/Core/Logic/Util/PathUtil.php
PathUtil.ContentCacheFile
static function ContentCacheFile(FrontendModule $module) { $file = $module->Content()->GetID(); $cacheKey = $module->CacheKey(); if ($cacheKey) { if (!ctype_alnum($cacheKey)) { throw new \Exception(Trans('Core.CacheKey.Error.NotAlphaNumeric')); } $file .= '-' . $cacheKey; } $cacheFolder = Path::Combine(PHINE_PATH, 'App/Phine/Cache/Content'); return Path::AddExtension(Path::Combine($cacheFolder, $file), 'phtml'); }
php
static function ContentCacheFile(FrontendModule $module) { $file = $module->Content()->GetID(); $cacheKey = $module->CacheKey(); if ($cacheKey) { if (!ctype_alnum($cacheKey)) { throw new \Exception(Trans('Core.CacheKey.Error.NotAlphaNumeric')); } $file .= '-' . $cacheKey; } $cacheFolder = Path::Combine(PHINE_PATH, 'App/Phine/Cache/Content'); return Path::AddExtension(Path::Combine($cacheFolder, $file), 'phtml'); }
[ "static", "function", "ContentCacheFile", "(", "FrontendModule", "$", "module", ")", "{", "$", "file", "=", "$", "module", "->", "Content", "(", ")", "->", "GetID", "(", ")", ";", "$", "cacheKey", "=", "$", "module", "->", "CacheKey", "(", ")", ";", "if", "(", "$", "cacheKey", ")", "{", "if", "(", "!", "ctype_alnum", "(", "$", "cacheKey", ")", ")", "{", "throw", "new", "\\", "Exception", "(", "Trans", "(", "'Core.CacheKey.Error.NotAlphaNumeric'", ")", ")", ";", "}", "$", "file", ".=", "'-'", ".", "$", "cacheKey", ";", "}", "$", "cacheFolder", "=", "Path", "::", "Combine", "(", "PHINE_PATH", ",", "'App/Phine/Cache/Content'", ")", ";", "return", "Path", "::", "AddExtension", "(", "Path", "::", "Combine", "(", "$", "cacheFolder", ",", "$", "file", ")", ",", "'phtml'", ")", ";", "}" ]
The name of the cache file @param FrontendModule $module @return string The name of the cache file, it needn't exist yet @throws \Exception Raises an error in case the cache key is not alphanumeric
[ "The", "name", "of", "the", "cache", "file" ]
38c1be8d03ebffae950d00a96da3c612aff67832
https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Logic/Util/PathUtil.php#L349-L363
train
Kris-Kuiper/sFire-Framework
src/MVC/View.php
View.process
public function process($file) { ob_start(); extract($this -> viewmodel -> getVariables(), EXTR_REFS); include($file); $this -> output = ob_get_clean(); return $this; }
php
public function process($file) { ob_start(); extract($this -> viewmodel -> getVariables(), EXTR_REFS); include($file); $this -> output = ob_get_clean(); return $this; }
[ "public", "function", "process", "(", "$", "file", ")", "{", "ob_start", "(", ")", ";", "extract", "(", "$", "this", "->", "viewmodel", "->", "getVariables", "(", ")", ",", "EXTR_REFS", ")", ";", "include", "(", "$", "file", ")", ";", "$", "this", "->", "output", "=", "ob_get_clean", "(", ")", ";", "return", "$", "this", ";", "}" ]
Converts template code to output string @param string $file @return sFire\MVC\View
[ "Converts", "template", "code", "to", "output", "string" ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/View.php#L74-L82
train
Kris-Kuiper/sFire-Framework
src/MVC/View.php
View.escapeJs
public function escapeJs($string, $encoding = 'utf-8') { $current = Escape :: getEncoding(); Escape :: setEncoding($encoding); $result = Escape :: js($string); Escape :: setEncoding($current); return $result; }
php
public function escapeJs($string, $encoding = 'utf-8') { $current = Escape :: getEncoding(); Escape :: setEncoding($encoding); $result = Escape :: js($string); Escape :: setEncoding($current); return $result; }
[ "public", "function", "escapeJs", "(", "$", "string", ",", "$", "encoding", "=", "'utf-8'", ")", "{", "$", "current", "=", "Escape", "::", "getEncoding", "(", ")", ";", "Escape", "::", "setEncoding", "(", "$", "encoding", ")", ";", "$", "result", "=", "Escape", "::", "js", "(", "$", "string", ")", ";", "Escape", "::", "setEncoding", "(", "$", "current", ")", ";", "return", "$", "result", ";", "}" ]
Escape a string for the Javascript context. @param string $string @return string
[ "Escape", "a", "string", "for", "the", "Javascript", "context", "." ]
deefe1d9d2b40e7326381e8dcd4f01f9aa61885c
https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/View.php#L131-L139
train