id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
229,900
clickalicious/rng
src/Generator.php
Generator.checkRequirements
protected function checkRequirements($mode) { if (true !== in_array($mode, self::$validModes, true)) { throw new Exception( sprintf('Mode "%s" not supported. Supported: "%s"', $mode, var_export(self::$validModes, true)) ); } switch ($mode) { case self::MODE_OPEN_SSL: case self::MODE_PHP_DEFAULT: case self::MODE_PHP_MERSENNE_TWISTER: default: // Intentionally omitted cause not required - listed here for code quality and readability break; } return true; }
php
protected function checkRequirements($mode) { if (true !== in_array($mode, self::$validModes, true)) { throw new Exception( sprintf('Mode "%s" not supported. Supported: "%s"', $mode, var_export(self::$validModes, true)) ); } switch ($mode) { case self::MODE_OPEN_SSL: case self::MODE_PHP_DEFAULT: case self::MODE_PHP_MERSENNE_TWISTER: default: // Intentionally omitted cause not required - listed here for code quality and readability break; } return true; }
[ "protected", "function", "checkRequirements", "(", "$", "mode", ")", "{", "if", "(", "true", "!==", "in_array", "(", "$", "mode", ",", "self", "::", "$", "validModes", ",", "true", ")", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'Mode \"%s\" not supported. Supported: \"%s\"'", ",", "$", "mode", ",", "var_export", "(", "self", "::", "$", "validModes", ",", "true", ")", ")", ")", ";", "}", "switch", "(", "$", "mode", ")", "{", "case", "self", "::", "MODE_OPEN_SSL", ":", "case", "self", "::", "MODE_PHP_DEFAULT", ":", "case", "self", "::", "MODE_PHP_MERSENNE_TWISTER", ":", "default", ":", "// Intentionally omitted cause not required - listed here for code quality and readability", "break", ";", "}", "return", "true", ";", "}" ]
Checks if requirements for mode are fulfilled. @param int $mode The mode to check requirements for @author Benjamin Carl <opensource@clickalicious.de> @return bool TRUE on success, otherwise FALSE @throws \Clickalicious\Rng\Exception
[ "Checks", "if", "requirements", "for", "mode", "are", "fulfilled", "." ]
9ee48ac4c5a9000e5776559715d027228a015bf9
https://github.com/clickalicious/rng/blob/9ee48ac4c5a9000e5776559715d027228a015bf9/src/Generator.php#L373-L391
229,901
clickalicious/rng
src/Generator.php
Generator.setSeed
public function setSeed($seed) { if (is_int($seed) !== true) { throw new Exception( sprintf('The type of the seed value "%s" need to be int. You passed a(n) "%s".', $seed, gettype($seed)) ); } // We need to call different methods depending on chosen source switch ($this->getMode()) { case self::MODE_PHP_MERSENNE_TWISTER: mt_srand($seed); break; case self::MODE_PHP_DEFAULT: srand($seed); break; case self::MODE_OPEN_SSL: default: // Intentionally left blank break; } $this->seed = $seed; }
php
public function setSeed($seed) { if (is_int($seed) !== true) { throw new Exception( sprintf('The type of the seed value "%s" need to be int. You passed a(n) "%s".', $seed, gettype($seed)) ); } // We need to call different methods depending on chosen source switch ($this->getMode()) { case self::MODE_PHP_MERSENNE_TWISTER: mt_srand($seed); break; case self::MODE_PHP_DEFAULT: srand($seed); break; case self::MODE_OPEN_SSL: default: // Intentionally left blank break; } $this->seed = $seed; }
[ "public", "function", "setSeed", "(", "$", "seed", ")", "{", "if", "(", "is_int", "(", "$", "seed", ")", "!==", "true", ")", "{", "throw", "new", "Exception", "(", "sprintf", "(", "'The type of the seed value \"%s\" need to be int. You passed a(n) \"%s\".'", ",", "$", "seed", ",", "gettype", "(", "$", "seed", ")", ")", ")", ";", "}", "// We need to call different methods depending on chosen source", "switch", "(", "$", "this", "->", "getMode", "(", ")", ")", "{", "case", "self", "::", "MODE_PHP_MERSENNE_TWISTER", ":", "mt_srand", "(", "$", "seed", ")", ";", "break", ";", "case", "self", "::", "MODE_PHP_DEFAULT", ":", "srand", "(", "$", "seed", ")", ";", "break", ";", "case", "self", "::", "MODE_OPEN_SSL", ":", "default", ":", "// Intentionally left blank", "break", ";", "}", "$", "this", "->", "seed", "=", "$", "seed", ";", "}" ]
Setter for seed. @param int $seed The seed value @author Benjamin Carl <opensource@clickalicious.de> @throws \Clickalicious\Rng\Exception
[ "Setter", "for", "seed", "." ]
9ee48ac4c5a9000e5776559715d027228a015bf9
https://github.com/clickalicious/rng/blob/9ee48ac4c5a9000e5776559715d027228a015bf9/src/Generator.php#L447-L473
229,902
Iandenh/cakephp-sendgrid
src/Mailer/Transport/SendgridTransport.php
SendgridTransport._send
protected function _send($message) { $options = [ 'headers' => ['Authorization' => 'Bearer ' . $this->getConfig('api_key')] ]; $response = $this->http->post('/api/mail.send.json', $message, $options); if ($response->getStatusCode() !== 200) { throw new SendgridEmailException(sprintf( 'SendGrid error %s %s: %s', $response->getStatusCode(), $response->getReasonPhrase(), implode('; ', $response->json['errors']) )); } return $response->json; }
php
protected function _send($message) { $options = [ 'headers' => ['Authorization' => 'Bearer ' . $this->getConfig('api_key')] ]; $response = $this->http->post('/api/mail.send.json', $message, $options); if ($response->getStatusCode() !== 200) { throw new SendgridEmailException(sprintf( 'SendGrid error %s %s: %s', $response->getStatusCode(), $response->getReasonPhrase(), implode('; ', $response->json['errors']) )); } return $response->json; }
[ "protected", "function", "_send", "(", "$", "message", ")", "{", "$", "options", "=", "[", "'headers'", "=>", "[", "'Authorization'", "=>", "'Bearer '", ".", "$", "this", "->", "getConfig", "(", "'api_key'", ")", "]", "]", ";", "$", "response", "=", "$", "this", "->", "http", "->", "post", "(", "'/api/mail.send.json'", ",", "$", "message", ",", "$", "options", ")", ";", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "!==", "200", ")", "{", "throw", "new", "SendgridEmailException", "(", "sprintf", "(", "'SendGrid error %s %s: %s'", ",", "$", "response", "->", "getStatusCode", "(", ")", ",", "$", "response", "->", "getReasonPhrase", "(", ")", ",", "implode", "(", "'; '", ",", "$", "response", "->", "json", "[", "'errors'", "]", ")", ")", ")", ";", "}", "return", "$", "response", "->", "json", ";", "}" ]
Send normal email @param array $message The Message Array @return array Returns an array with the results from the SendGrid API @throws \SendgridEmail\Mailer\Exception\SendgridEmailException
[ "Send", "normal", "email" ]
491571517ff538653780b5c723bf9c9198f2f68c
https://github.com/Iandenh/cakephp-sendgrid/blob/491571517ff538653780b5c723bf9c9198f2f68c/src/Mailer/Transport/SendgridTransport.php#L97-L113
229,903
Iandenh/cakephp-sendgrid
src/Mailer/Transport/SendgridTransport.php
SendgridTransport._attachments
protected function _attachments(Email $email, array $message = []) { foreach ($email->getAttachments() as $filename => $attach) { $content = isset($attach['data']) ? base64_decode($attach['data']) : file_get_contents($attach['file']); $message['files'][$filename] = $content; if (isset($attach['contentId'])) { $message['content'][$filename] = $attach['contentId']; } } return $message; }
php
protected function _attachments(Email $email, array $message = []) { foreach ($email->getAttachments() as $filename => $attach) { $content = isset($attach['data']) ? base64_decode($attach['data']) : file_get_contents($attach['file']); $message['files'][$filename] = $content; if (isset($attach['contentId'])) { $message['content'][$filename] = $attach['contentId']; } } return $message; }
[ "protected", "function", "_attachments", "(", "Email", "$", "email", ",", "array", "$", "message", "=", "[", "]", ")", "{", "foreach", "(", "$", "email", "->", "getAttachments", "(", ")", "as", "$", "filename", "=>", "$", "attach", ")", "{", "$", "content", "=", "isset", "(", "$", "attach", "[", "'data'", "]", ")", "?", "base64_decode", "(", "$", "attach", "[", "'data'", "]", ")", ":", "file_get_contents", "(", "$", "attach", "[", "'file'", "]", ")", ";", "$", "message", "[", "'files'", "]", "[", "$", "filename", "]", "=", "$", "content", ";", "if", "(", "isset", "(", "$", "attach", "[", "'contentId'", "]", ")", ")", "{", "$", "message", "[", "'content'", "]", "[", "$", "filename", "]", "=", "$", "attach", "[", "'contentId'", "]", ";", "}", "}", "return", "$", "message", ";", "}" ]
Format the attachments @param \Cake\Mailer\Email $email Email instance. @param array $message A message array. @return array Message
[ "Format", "the", "attachments" ]
491571517ff538653780b5c723bf9c9198f2f68c
https://github.com/Iandenh/cakephp-sendgrid/blob/491571517ff538653780b5c723bf9c9198f2f68c/src/Mailer/Transport/SendgridTransport.php#L122-L133
229,904
Webiny/Framework
src/Webiny/Component/Rest/Parser/MethodParser.php
MethodParser.getHeader
private function getHeader(ConfigObject $annotations) { // headers status code depends on the request method type, unless it's forced on the class or method $successStatus = $annotations->get('header.status.success', false); if (!$successStatus) { $successStatus = $this->classDefaults->get('header.status.success', false); if (!$successStatus) { $method = strtolower($annotations->get('method', $this->classDefaults->get('method', 'get'))); if ($method == 'post') { $successStatus = 201; } else { $successStatus = 200; } } } return [ 'cache' => [ 'expires' => $annotations->get('header.cache.expires', $this->classDefaults->get('header.cache.expires', 0)) ], 'status' => [ 'success' => $successStatus, 'error' => $annotations->get('header.status.error', $this->classDefaults->get('header.status.error', 404)), 'errorMessage' => $annotations->get('header.status.errorMessage', $this->classDefaults->get('header.status.errorMessage', '')) ] ]; }
php
private function getHeader(ConfigObject $annotations) { // headers status code depends on the request method type, unless it's forced on the class or method $successStatus = $annotations->get('header.status.success', false); if (!$successStatus) { $successStatus = $this->classDefaults->get('header.status.success', false); if (!$successStatus) { $method = strtolower($annotations->get('method', $this->classDefaults->get('method', 'get'))); if ($method == 'post') { $successStatus = 201; } else { $successStatus = 200; } } } return [ 'cache' => [ 'expires' => $annotations->get('header.cache.expires', $this->classDefaults->get('header.cache.expires', 0)) ], 'status' => [ 'success' => $successStatus, 'error' => $annotations->get('header.status.error', $this->classDefaults->get('header.status.error', 404)), 'errorMessage' => $annotations->get('header.status.errorMessage', $this->classDefaults->get('header.status.errorMessage', '')) ] ]; }
[ "private", "function", "getHeader", "(", "ConfigObject", "$", "annotations", ")", "{", "// headers status code depends on the request method type, unless it's forced on the class or method", "$", "successStatus", "=", "$", "annotations", "->", "get", "(", "'header.status.success'", ",", "false", ")", ";", "if", "(", "!", "$", "successStatus", ")", "{", "$", "successStatus", "=", "$", "this", "->", "classDefaults", "->", "get", "(", "'header.status.success'", ",", "false", ")", ";", "if", "(", "!", "$", "successStatus", ")", "{", "$", "method", "=", "strtolower", "(", "$", "annotations", "->", "get", "(", "'method'", ",", "$", "this", "->", "classDefaults", "->", "get", "(", "'method'", ",", "'get'", ")", ")", ")", ";", "if", "(", "$", "method", "==", "'post'", ")", "{", "$", "successStatus", "=", "201", ";", "}", "else", "{", "$", "successStatus", "=", "200", ";", "}", "}", "}", "return", "[", "'cache'", "=>", "[", "'expires'", "=>", "$", "annotations", "->", "get", "(", "'header.cache.expires'", ",", "$", "this", "->", "classDefaults", "->", "get", "(", "'header.cache.expires'", ",", "0", ")", ")", "]", ",", "'status'", "=>", "[", "'success'", "=>", "$", "successStatus", ",", "'error'", "=>", "$", "annotations", "->", "get", "(", "'header.status.error'", ",", "$", "this", "->", "classDefaults", "->", "get", "(", "'header.status.error'", ",", "404", ")", ")", ",", "'errorMessage'", "=>", "$", "annotations", "->", "get", "(", "'header.status.errorMessage'", ",", "$", "this", "->", "classDefaults", "->", "get", "(", "'header.status.errorMessage'", ",", "''", ")", ")", "]", "]", ";", "}" ]
Extracts http header information from method annotations. @param ConfigObject $annotations Method annotations. @return array
[ "Extracts", "http", "header", "information", "from", "method", "annotations", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/MethodParser.php#L203-L233
229,905
Webiny/Framework
src/Webiny/Component/Rest/Parser/MethodParser.php
MethodParser.buildUrlPatternStandard
private function buildUrlPatternStandard($methodName, array $parameters) { $url = $methodName; if ($this->normalize) { $url = PathTransformations::methodNameToUrl($methodName); } foreach ($parameters as $p) { $matchType = $p->matchPattern; $url = $url . '/' . $matchType; } return $url . '/'; }
php
private function buildUrlPatternStandard($methodName, array $parameters) { $url = $methodName; if ($this->normalize) { $url = PathTransformations::methodNameToUrl($methodName); } foreach ($parameters as $p) { $matchType = $p->matchPattern; $url = $url . '/' . $matchType; } return $url . '/'; }
[ "private", "function", "buildUrlPatternStandard", "(", "$", "methodName", ",", "array", "$", "parameters", ")", "{", "$", "url", "=", "$", "methodName", ";", "if", "(", "$", "this", "->", "normalize", ")", "{", "$", "url", "=", "PathTransformations", "::", "methodNameToUrl", "(", "$", "methodName", ")", ";", "}", "foreach", "(", "$", "parameters", "as", "$", "p", ")", "{", "$", "matchType", "=", "$", "p", "->", "matchPattern", ";", "$", "url", "=", "$", "url", ".", "'/'", ".", "$", "matchType", ";", "}", "return", "$", "url", ".", "'/'", ";", "}" ]
Builds the url match pattern for each of the method inside the api. @param string $methodName Method name. @param array $parameters List of the ParsedParameter instances. @return string The url pattern.
[ "Builds", "the", "url", "match", "pattern", "for", "each", "of", "the", "method", "inside", "the", "api", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/MethodParser.php#L255-L268
229,906
Webiny/Framework
src/Webiny/Component/Rest/Parser/MethodParser.php
MethodParser.buildUrlPatternFromPattern
private function buildUrlPatternFromPattern($pattern, array $parameters) { foreach ($parameters as $p) { $pattern = str_replace('{' . $p->name . '}', $p->matchPattern, $pattern, $rcount); if ($rcount < 1) { throw new RestException(sprintf('Missing parameter "%s" for "%s" method in the rest.url definition.', $p->name, $this->method->getName())); } } return rtrim($pattern, '/') . '/'; }
php
private function buildUrlPatternFromPattern($pattern, array $parameters) { foreach ($parameters as $p) { $pattern = str_replace('{' . $p->name . '}', $p->matchPattern, $pattern, $rcount); if ($rcount < 1) { throw new RestException(sprintf('Missing parameter "%s" for "%s" method in the rest.url definition.', $p->name, $this->method->getName())); } } return rtrim($pattern, '/') . '/'; }
[ "private", "function", "buildUrlPatternFromPattern", "(", "$", "pattern", ",", "array", "$", "parameters", ")", "{", "foreach", "(", "$", "parameters", "as", "$", "p", ")", "{", "$", "pattern", "=", "str_replace", "(", "'{'", ".", "$", "p", "->", "name", ".", "'}'", ",", "$", "p", "->", "matchPattern", ",", "$", "pattern", ",", "$", "rcount", ")", ";", "if", "(", "$", "rcount", "<", "1", ")", "{", "throw", "new", "RestException", "(", "sprintf", "(", "'Missing parameter \"%s\" for \"%s\" method in the rest.url definition.'", ",", "$", "p", "->", "name", ",", "$", "this", "->", "method", "->", "getName", "(", ")", ")", ")", ";", "}", "}", "return", "rtrim", "(", "$", "pattern", ",", "'/'", ")", ".", "'/'", ";", "}" ]
Builds the url pattern using the `rest.url` definition from method phpDoc. @param string $pattern Defined `rest.url` pattern. @param array $parameters List of method parameters. @return string @throws RestException
[ "Builds", "the", "url", "pattern", "using", "the", "rest", ".", "url", "definition", "from", "method", "phpDoc", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Rest/Parser/MethodParser.php#L279-L290
229,907
Webiny/Framework
src/Webiny/Component/Cache/Storage/Couchbase.php
Couchbase.getInstance
public static function getInstance($user, $password, $bucket, $host) { return \Webiny\Component\Cache\Bridge\Couchbase::getInstance($user, $password, $bucket, $host); }
php
public static function getInstance($user, $password, $bucket, $host) { return \Webiny\Component\Cache\Bridge\Couchbase::getInstance($user, $password, $bucket, $host); }
[ "public", "static", "function", "getInstance", "(", "$", "user", ",", "$", "password", ",", "$", "bucket", ",", "$", "host", ")", "{", "return", "\\", "Webiny", "\\", "Component", "\\", "Cache", "\\", "Bridge", "\\", "Couchbase", "::", "getInstance", "(", "$", "user", ",", "$", "password", ",", "$", "bucket", ",", "$", "host", ")", ";", "}" ]
Get an instance of Couchbase cache storage. @param string $user Couchbase username. @param string $password Couchbase password. @param string $bucket Couchbase bucket. @param string $host Couchbase host (with port number). @return CacheStorageInterface
[ "Get", "an", "instance", "of", "Couchbase", "cache", "storage", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Cache/Storage/Couchbase.php#L29-L32
229,908
juliangut/slim-doctrine
src/ManagerBuilder.php
ManagerBuilder.loadSettings
public function loadSettings(array $settings) { $relationalManagerKey = $this->getOption(static::RELATIONAL_MANAGER_KEY); if (array_key_exists($relationalManagerKey, $settings)) { $this->registerEntityManagers((array) $settings[$relationalManagerKey]); } $mongoDBManagerKey = $this->getOption(static::MONGODB_MANAGER_KEY); if (array_key_exists($mongoDBManagerKey, $settings)) { $this->registerMongoDBDocumentManagers((array) $settings[$mongoDBManagerKey]); } $couchDBManagerKey = $this->getOption(static::COUCHDB_MANAGER_KEY); if (array_key_exists($couchDBManagerKey, $settings)) { $this->registerCouchDBDocumentManagers((array) $settings[$couchDBManagerKey]); } return $this; }
php
public function loadSettings(array $settings) { $relationalManagerKey = $this->getOption(static::RELATIONAL_MANAGER_KEY); if (array_key_exists($relationalManagerKey, $settings)) { $this->registerEntityManagers((array) $settings[$relationalManagerKey]); } $mongoDBManagerKey = $this->getOption(static::MONGODB_MANAGER_KEY); if (array_key_exists($mongoDBManagerKey, $settings)) { $this->registerMongoDBDocumentManagers((array) $settings[$mongoDBManagerKey]); } $couchDBManagerKey = $this->getOption(static::COUCHDB_MANAGER_KEY); if (array_key_exists($couchDBManagerKey, $settings)) { $this->registerCouchDBDocumentManagers((array) $settings[$couchDBManagerKey]); } return $this; }
[ "public", "function", "loadSettings", "(", "array", "$", "settings", ")", "{", "$", "relationalManagerKey", "=", "$", "this", "->", "getOption", "(", "static", "::", "RELATIONAL_MANAGER_KEY", ")", ";", "if", "(", "array_key_exists", "(", "$", "relationalManagerKey", ",", "$", "settings", ")", ")", "{", "$", "this", "->", "registerEntityManagers", "(", "(", "array", ")", "$", "settings", "[", "$", "relationalManagerKey", "]", ")", ";", "}", "$", "mongoDBManagerKey", "=", "$", "this", "->", "getOption", "(", "static", "::", "MONGODB_MANAGER_KEY", ")", ";", "if", "(", "array_key_exists", "(", "$", "mongoDBManagerKey", ",", "$", "settings", ")", ")", "{", "$", "this", "->", "registerMongoDBDocumentManagers", "(", "(", "array", ")", "$", "settings", "[", "$", "mongoDBManagerKey", "]", ")", ";", "}", "$", "couchDBManagerKey", "=", "$", "this", "->", "getOption", "(", "static", "::", "COUCHDB_MANAGER_KEY", ")", ";", "if", "(", "array_key_exists", "(", "$", "couchDBManagerKey", ",", "$", "settings", ")", ")", "{", "$", "this", "->", "registerCouchDBDocumentManagers", "(", "(", "array", ")", "$", "settings", "[", "$", "couchDBManagerKey", "]", ")", ";", "}", "return", "$", "this", ";", "}" ]
Load Doctrine managers from settings array. @param array $settings @throws \RuntimeException @return $this
[ "Load", "Doctrine", "managers", "from", "settings", "array", "." ]
1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3
https://github.com/juliangut/slim-doctrine/blob/1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3/src/ManagerBuilder.php#L88-L106
229,909
juliangut/slim-doctrine
src/ManagerBuilder.php
ManagerBuilder.registerEntityManagers
protected function registerEntityManagers(array $settings) { if (array_key_exists('connection', $settings)) { $settings = [$settings]; } foreach ($settings as $name => $config) { if (!is_string($name)) { $name = $this->getOption(static::RELATIONAL_MANAGER_NAME); } $this->addBuilder(new RelationalBuilder($config, $name)); } }
php
protected function registerEntityManagers(array $settings) { if (array_key_exists('connection', $settings)) { $settings = [$settings]; } foreach ($settings as $name => $config) { if (!is_string($name)) { $name = $this->getOption(static::RELATIONAL_MANAGER_NAME); } $this->addBuilder(new RelationalBuilder($config, $name)); } }
[ "protected", "function", "registerEntityManagers", "(", "array", "$", "settings", ")", "{", "if", "(", "array_key_exists", "(", "'connection'", ",", "$", "settings", ")", ")", "{", "$", "settings", "=", "[", "$", "settings", "]", ";", "}", "foreach", "(", "$", "settings", "as", "$", "name", "=>", "$", "config", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "$", "name", "=", "$", "this", "->", "getOption", "(", "static", "::", "RELATIONAL_MANAGER_NAME", ")", ";", "}", "$", "this", "->", "addBuilder", "(", "new", "RelationalBuilder", "(", "$", "config", ",", "$", "name", ")", ")", ";", "}", "}" ]
Register ORM entity managers. @param array $settings @throws \RuntimeException
[ "Register", "ORM", "entity", "managers", "." ]
1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3
https://github.com/juliangut/slim-doctrine/blob/1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3/src/ManagerBuilder.php#L115-L128
229,910
juliangut/slim-doctrine
src/ManagerBuilder.php
ManagerBuilder.registerMongoDBDocumentManagers
protected function registerMongoDBDocumentManagers(array $settings) { if (array_key_exists('connection', $settings)) { $settings = [$settings]; } foreach ($settings as $name => $config) { if (!is_string($name)) { $name = $this->getOption(static::MONGODB_MANAGER_NAME); } $this->addBuilder(new MongoDBBuilder($config, $name)); } }
php
protected function registerMongoDBDocumentManagers(array $settings) { if (array_key_exists('connection', $settings)) { $settings = [$settings]; } foreach ($settings as $name => $config) { if (!is_string($name)) { $name = $this->getOption(static::MONGODB_MANAGER_NAME); } $this->addBuilder(new MongoDBBuilder($config, $name)); } }
[ "protected", "function", "registerMongoDBDocumentManagers", "(", "array", "$", "settings", ")", "{", "if", "(", "array_key_exists", "(", "'connection'", ",", "$", "settings", ")", ")", "{", "$", "settings", "=", "[", "$", "settings", "]", ";", "}", "foreach", "(", "$", "settings", "as", "$", "name", "=>", "$", "config", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "$", "name", "=", "$", "this", "->", "getOption", "(", "static", "::", "MONGODB_MANAGER_NAME", ")", ";", "}", "$", "this", "->", "addBuilder", "(", "new", "MongoDBBuilder", "(", "$", "config", ",", "$", "name", ")", ")", ";", "}", "}" ]
Register MongoDB ODM document managers. @param array $settings @throws \RuntimeException
[ "Register", "MongoDB", "ODM", "document", "managers", "." ]
1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3
https://github.com/juliangut/slim-doctrine/blob/1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3/src/ManagerBuilder.php#L137-L150
229,911
juliangut/slim-doctrine
src/ManagerBuilder.php
ManagerBuilder.registerCouchDBDocumentManagers
protected function registerCouchDBDocumentManagers(array $settings) { if (array_key_exists('connection', $settings)) { $settings = [$settings]; } foreach ($settings as $name => $config) { if (!is_string($name)) { $name = $this->getOption(static::COUCHDB_MANAGER_NAME); } $this->addBuilder(new CouchDBBuilder($config, $name)); } }
php
protected function registerCouchDBDocumentManagers(array $settings) { if (array_key_exists('connection', $settings)) { $settings = [$settings]; } foreach ($settings as $name => $config) { if (!is_string($name)) { $name = $this->getOption(static::COUCHDB_MANAGER_NAME); } $this->addBuilder(new CouchDBBuilder($config, $name)); } }
[ "protected", "function", "registerCouchDBDocumentManagers", "(", "array", "$", "settings", ")", "{", "if", "(", "array_key_exists", "(", "'connection'", ",", "$", "settings", ")", ")", "{", "$", "settings", "=", "[", "$", "settings", "]", ";", "}", "foreach", "(", "$", "settings", "as", "$", "name", "=>", "$", "config", ")", "{", "if", "(", "!", "is_string", "(", "$", "name", ")", ")", "{", "$", "name", "=", "$", "this", "->", "getOption", "(", "static", "::", "COUCHDB_MANAGER_NAME", ")", ";", "}", "$", "this", "->", "addBuilder", "(", "new", "CouchDBBuilder", "(", "$", "config", ",", "$", "name", ")", ")", ";", "}", "}" ]
Register CouchDB ODM document managers. @param array $settings @throws \RuntimeException
[ "Register", "CouchDB", "ODM", "document", "managers", "." ]
1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3
https://github.com/juliangut/slim-doctrine/blob/1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3/src/ManagerBuilder.php#L159-L172
229,912
juliangut/slim-doctrine
src/ManagerBuilder.php
ManagerBuilder.getManagers
public function getManagers() { $managers = array_map( function (Builder $builder) { return $builder->getManager(); }, $this->builders ); $this->registerGlobalAnnotationLoader(); return $managers; }
php
public function getManagers() { $managers = array_map( function (Builder $builder) { return $builder->getManager(); }, $this->builders ); $this->registerGlobalAnnotationLoader(); return $managers; }
[ "public", "function", "getManagers", "(", ")", "{", "$", "managers", "=", "array_map", "(", "function", "(", "Builder", "$", "builder", ")", "{", "return", "$", "builder", "->", "getManager", "(", ")", ";", "}", ",", "$", "this", "->", "builders", ")", ";", "$", "this", "->", "registerGlobalAnnotationLoader", "(", ")", ";", "return", "$", "managers", ";", "}" ]
Get registered builder's managers. @return \Doctrine\Common\Persistence\ObjectManager[]
[ "Get", "registered", "builder", "s", "managers", "." ]
1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3
https://github.com/juliangut/slim-doctrine/blob/1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3/src/ManagerBuilder.php#L179-L191
229,913
juliangut/slim-doctrine
src/ManagerBuilder.php
ManagerBuilder.getManager
public function getManager($name) { $builder = $this->getBuilder($name); if (!$builder instanceof Builder) { throw new \RuntimeException(sprintf('"%s" is not a registered manager', $name)); } $manager = $builder->getManager(); $this->registerGlobalAnnotationLoader(); return $manager; }
php
public function getManager($name) { $builder = $this->getBuilder($name); if (!$builder instanceof Builder) { throw new \RuntimeException(sprintf('"%s" is not a registered manager', $name)); } $manager = $builder->getManager(); $this->registerGlobalAnnotationLoader(); return $manager; }
[ "public", "function", "getManager", "(", "$", "name", ")", "{", "$", "builder", "=", "$", "this", "->", "getBuilder", "(", "$", "name", ")", ";", "if", "(", "!", "$", "builder", "instanceof", "Builder", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'\"%s\" is not a registered manager'", ",", "$", "name", ")", ")", ";", "}", "$", "manager", "=", "$", "builder", "->", "getManager", "(", ")", ";", "$", "this", "->", "registerGlobalAnnotationLoader", "(", ")", ";", "return", "$", "manager", ";", "}" ]
Get registered builder's manager. @param string $name @throws \RuntimeException @return \Doctrine\Common\Persistence\ObjectManager
[ "Get", "registered", "builder", "s", "manager", "." ]
1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3
https://github.com/juliangut/slim-doctrine/blob/1a7a24f445e9eb4d4223f5f851e2beb7305c0ab3/src/ManagerBuilder.php#L202-L214
229,914
deanblackborough/zf3-view-helpers
src/Bootstrap4ProgressBarMultiple.php
Bootstrap4ProgressBarMultiple.bgStyles
private function bgStyles(array $colors) : void { if (count($colors) !== count($this->values)) { throw new Exception('Number of progress bar colours needs to match the number or progress bar values'); } foreach ($colors as $color) { if (in_array($color, $this->supported_bg_styles) === true) { $this->bg_colors[] = $color; } } }
php
private function bgStyles(array $colors) : void { if (count($colors) !== count($this->values)) { throw new Exception('Number of progress bar colours needs to match the number or progress bar values'); } foreach ($colors as $color) { if (in_array($color, $this->supported_bg_styles) === true) { $this->bg_colors[] = $color; } } }
[ "private", "function", "bgStyles", "(", "array", "$", "colors", ")", ":", "void", "{", "if", "(", "count", "(", "$", "colors", ")", "!==", "count", "(", "$", "this", "->", "values", ")", ")", "{", "throw", "new", "Exception", "(", "'Number of progress bar colours needs to match the number or progress bar values'", ")", ";", "}", "foreach", "(", "$", "colors", "as", "$", "color", ")", "{", "if", "(", "in_array", "(", "$", "color", ",", "$", "this", "->", "supported_bg_styles", ")", "===", "true", ")", "{", "$", "this", "->", "bg_colors", "[", "]", "=", "$", "color", ";", "}", "}", "}" ]
Set the background colour for each of the progress bars, values need to be one of the following, primary, secondary, success, danger, warning, info, light, dark or white @param array $colors @throws Exception
[ "Set", "the", "background", "colour", "for", "each", "of", "the", "progress", "bars", "values", "need", "to", "be", "one", "of", "the", "following", "primary", "secondary", "success", "danger", "warning", "info", "light", "dark", "or", "white" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4ProgressBarMultiple.php#L83-L94
229,915
deanblackborough/zf3-view-helpers
src/Bootstrap4ProgressBarMultiple.php
Bootstrap4ProgressBarMultiple.styles
private function styles(int $value) : string { $styles = ''; if ($value > 0) { $styles .= ' width: ' . $value . '%;'; } if ($this->height !== null && $this->height > 0) { $styles .= ' height:' . $this->height . 'px;'; } return $styles; }
php
private function styles(int $value) : string { $styles = ''; if ($value > 0) { $styles .= ' width: ' . $value . '%;'; } if ($this->height !== null && $this->height > 0) { $styles .= ' height:' . $this->height . 'px;'; } return $styles; }
[ "private", "function", "styles", "(", "int", "$", "value", ")", ":", "string", "{", "$", "styles", "=", "''", ";", "if", "(", "$", "value", ">", "0", ")", "{", "$", "styles", ".=", "' width: '", ".", "$", "value", ".", "'%;'", ";", "}", "if", "(", "$", "this", "->", "height", "!==", "null", "&&", "$", "this", "->", "height", ">", "0", ")", "{", "$", "styles", ".=", "' height:'", ".", "$", "this", "->", "height", ".", "'px;'", ";", "}", "return", "$", "styles", ";", "}" ]
Generate the style attributes for the progress bar @param integer $value @return string
[ "Generate", "the", "style", "attributes", "for", "the", "progress", "bar" ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap4ProgressBarMultiple.php#L194-L207
229,916
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/OldApiParser.php
OldApiParser.parsePoint
static function parsePoint($source) { $point = new Point; if (isset($source['time'])) { $point->setTime(new \DateTime($source['time'])); } if (isset($source['lat'])) { $point->setLatitude($source['lat']); } if (isset($source['lng'])) { $point->setLongitude($source['lng']); } if (isset($source['alt'])) { $point->setAltitude($source['alt']); } if (isset($source['dist'])) { $point->setDistance($source['dist']); } if (isset($source['speed'])) { $point->setSpeed($source['speed']); } if (isset($source['duration'])) { $point->setDuration($source['duration']); } if (isset($source['hr'])) { $point->setHeartRate($source['hr']); } if (isset($source['inst'])) { $point->setInstruction($source['inst']); } return $point; }
php
static function parsePoint($source) { $point = new Point; if (isset($source['time'])) { $point->setTime(new \DateTime($source['time'])); } if (isset($source['lat'])) { $point->setLatitude($source['lat']); } if (isset($source['lng'])) { $point->setLongitude($source['lng']); } if (isset($source['alt'])) { $point->setAltitude($source['alt']); } if (isset($source['dist'])) { $point->setDistance($source['dist']); } if (isset($source['speed'])) { $point->setSpeed($source['speed']); } if (isset($source['duration'])) { $point->setDuration($source['duration']); } if (isset($source['hr'])) { $point->setHeartRate($source['hr']); } if (isset($source['inst'])) { $point->setInstruction($source['inst']); } return $point; }
[ "static", "function", "parsePoint", "(", "$", "source", ")", "{", "$", "point", "=", "new", "Point", ";", "if", "(", "isset", "(", "$", "source", "[", "'time'", "]", ")", ")", "{", "$", "point", "->", "setTime", "(", "new", "\\", "DateTime", "(", "$", "source", "[", "'time'", "]", ")", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'lat'", "]", ")", ")", "{", "$", "point", "->", "setLatitude", "(", "$", "source", "[", "'lat'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'lng'", "]", ")", ")", "{", "$", "point", "->", "setLongitude", "(", "$", "source", "[", "'lng'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'alt'", "]", ")", ")", "{", "$", "point", "->", "setAltitude", "(", "$", "source", "[", "'alt'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'dist'", "]", ")", ")", "{", "$", "point", "->", "setDistance", "(", "$", "source", "[", "'dist'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'speed'", "]", ")", ")", "{", "$", "point", "->", "setSpeed", "(", "$", "source", "[", "'speed'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'duration'", "]", ")", ")", "{", "$", "point", "->", "setDuration", "(", "$", "source", "[", "'duration'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'hr'", "]", ")", ")", "{", "$", "point", "->", "setHeartRate", "(", "$", "source", "[", "'hr'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'inst'", "]", ")", ")", "{", "$", "point", "->", "setInstruction", "(", "$", "source", "[", "'inst'", "]", ")", ";", "}", "return", "$", "point", ";", "}" ]
Parse point data from old Endomondo API. @param $source array @return Point
[ "Parse", "point", "data", "from", "old", "Endomondo", "API", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/OldApiParser.php#L13-L54
229,917
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/OldApiParser.php
OldApiParser.parseWorkout
static function parseWorkout($source) { $workout = new Workout(); $workout ->setSource($source) ->setTypeId($source['sport']) ->setDuration($source['duration']) ->setStart(new \DateTime($source['start_time'])) ->setMapPrivacy($source['privacy_map']) ->setWorkoutPrivacy($source['privacy_workout']); if ($source['id']) { $workout->setId($source['id']); } if ($source['calories']) { $workout->setCalories($source['calories']); } if ($source['distance']) { $workout->setDistance($source['distance']); } if (isset($source['points'])) { $points = []; foreach ($source['points'] as $point) { $points[] = OldApiParser::parsePoint($point); } $workout->setPoints($points); } if (isset($source['heart_rate_avg'])) { $workout->setAvgHeartRate($source['heart_rate_avg']); } if (isset($source['heart_rate_max'])) { $workout->setMaxHeartRate($source['heart_rate_max']); } if (isset($source['notes'])) { $workout->setNotes($source['notes']); } return $workout; }
php
static function parseWorkout($source) { $workout = new Workout(); $workout ->setSource($source) ->setTypeId($source['sport']) ->setDuration($source['duration']) ->setStart(new \DateTime($source['start_time'])) ->setMapPrivacy($source['privacy_map']) ->setWorkoutPrivacy($source['privacy_workout']); if ($source['id']) { $workout->setId($source['id']); } if ($source['calories']) { $workout->setCalories($source['calories']); } if ($source['distance']) { $workout->setDistance($source['distance']); } if (isset($source['points'])) { $points = []; foreach ($source['points'] as $point) { $points[] = OldApiParser::parsePoint($point); } $workout->setPoints($points); } if (isset($source['heart_rate_avg'])) { $workout->setAvgHeartRate($source['heart_rate_avg']); } if (isset($source['heart_rate_max'])) { $workout->setMaxHeartRate($source['heart_rate_max']); } if (isset($source['notes'])) { $workout->setNotes($source['notes']); } return $workout; }
[ "static", "function", "parseWorkout", "(", "$", "source", ")", "{", "$", "workout", "=", "new", "Workout", "(", ")", ";", "$", "workout", "->", "setSource", "(", "$", "source", ")", "->", "setTypeId", "(", "$", "source", "[", "'sport'", "]", ")", "->", "setDuration", "(", "$", "source", "[", "'duration'", "]", ")", "->", "setStart", "(", "new", "\\", "DateTime", "(", "$", "source", "[", "'start_time'", "]", ")", ")", "->", "setMapPrivacy", "(", "$", "source", "[", "'privacy_map'", "]", ")", "->", "setWorkoutPrivacy", "(", "$", "source", "[", "'privacy_workout'", "]", ")", ";", "if", "(", "$", "source", "[", "'id'", "]", ")", "{", "$", "workout", "->", "setId", "(", "$", "source", "[", "'id'", "]", ")", ";", "}", "if", "(", "$", "source", "[", "'calories'", "]", ")", "{", "$", "workout", "->", "setCalories", "(", "$", "source", "[", "'calories'", "]", ")", ";", "}", "if", "(", "$", "source", "[", "'distance'", "]", ")", "{", "$", "workout", "->", "setDistance", "(", "$", "source", "[", "'distance'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'points'", "]", ")", ")", "{", "$", "points", "=", "[", "]", ";", "foreach", "(", "$", "source", "[", "'points'", "]", "as", "$", "point", ")", "{", "$", "points", "[", "]", "=", "OldApiParser", "::", "parsePoint", "(", "$", "point", ")", ";", "}", "$", "workout", "->", "setPoints", "(", "$", "points", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'heart_rate_avg'", "]", ")", ")", "{", "$", "workout", "->", "setAvgHeartRate", "(", "$", "source", "[", "'heart_rate_avg'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'heart_rate_max'", "]", ")", ")", "{", "$", "workout", "->", "setMaxHeartRate", "(", "$", "source", "[", "'heart_rate_max'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "source", "[", "'notes'", "]", ")", ")", "{", "$", "workout", "->", "setNotes", "(", "$", "source", "[", "'notes'", "]", ")", ";", "}", "return", "$", "workout", ";", "}" ]
Get Endomondo workout from old API @param $source array @return Workout
[ "Get", "Endomondo", "workout", "from", "old", "API" ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/OldApiParser.php#L62-L107
229,918
alexandresalome/php-webdriver
src/WebDriver/Behat/AbstractWebDriverContext.php
AbstractWebDriverContext.tryRepeating
public function tryRepeating(\Closure $closure, $time = null) { if (null === $time) { $time = $this->timeout; } $last = null; $count = 0; do { $count++; try { return $closure($this->getBrowser()); } catch (\Exception $e) { $last = $e; } $wait = min(1000, $time); $time -= $wait; usleep($wait*1000); } while ($time > 0); throw new \RuntimeException(sprintf('Repeatedly failed, %s time: %s', $count, $last->getMessage()), 0, $last); }
php
public function tryRepeating(\Closure $closure, $time = null) { if (null === $time) { $time = $this->timeout; } $last = null; $count = 0; do { $count++; try { return $closure($this->getBrowser()); } catch (\Exception $e) { $last = $e; } $wait = min(1000, $time); $time -= $wait; usleep($wait*1000); } while ($time > 0); throw new \RuntimeException(sprintf('Repeatedly failed, %s time: %s', $count, $last->getMessage()), 0, $last); }
[ "public", "function", "tryRepeating", "(", "\\", "Closure", "$", "closure", ",", "$", "time", "=", "null", ")", "{", "if", "(", "null", "===", "$", "time", ")", "{", "$", "time", "=", "$", "this", "->", "timeout", ";", "}", "$", "last", "=", "null", ";", "$", "count", "=", "0", ";", "do", "{", "$", "count", "++", ";", "try", "{", "return", "$", "closure", "(", "$", "this", "->", "getBrowser", "(", ")", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "last", "=", "$", "e", ";", "}", "$", "wait", "=", "min", "(", "1000", ",", "$", "time", ")", ";", "$", "time", "-=", "$", "wait", ";", "usleep", "(", "$", "wait", "*", "1000", ")", ";", "}", "while", "(", "$", "time", ">", "0", ")", ";", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Repeatedly failed, %s time: %s'", ",", "$", "count", ",", "$", "last", "->", "getMessage", "(", ")", ")", ",", "0", ",", "$", "last", ")", ";", "}" ]
Try repeating a statement until it stops throwing exception. It's used for operations having a fail-tolerated risk. @return mixed return value of closure
[ "Try", "repeating", "a", "statement", "until", "it", "stops", "throwing", "exception", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Behat/AbstractWebDriverContext.php#L43-L66
229,919
alexandresalome/php-webdriver
src/WebDriver/Behat/AbstractWebDriverContext.php
AbstractWebDriverContext.getElements
public function getElements(By $by, Element $element = null) { try { $obj = null === $element ? $this->getBrowser() : $element; return $obj->elements($by); } catch (ExceptionInterface $e) { throw new \RuntimeException(sprintf('Error while searching for element "%s" : %s (visible text: "%s").', $by->toString(), $e->getMessage(), $this->getBrowser()->getText())); } }
php
public function getElements(By $by, Element $element = null) { try { $obj = null === $element ? $this->getBrowser() : $element; return $obj->elements($by); } catch (ExceptionInterface $e) { throw new \RuntimeException(sprintf('Error while searching for element "%s" : %s (visible text: "%s").', $by->toString(), $e->getMessage(), $this->getBrowser()->getText())); } }
[ "public", "function", "getElements", "(", "By", "$", "by", ",", "Element", "$", "element", "=", "null", ")", "{", "try", "{", "$", "obj", "=", "null", "===", "$", "element", "?", "$", "this", "->", "getBrowser", "(", ")", ":", "$", "element", ";", "return", "$", "obj", "->", "elements", "(", "$", "by", ")", ";", "}", "catch", "(", "ExceptionInterface", "$", "e", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Error while searching for element \"%s\" : %s (visible text: \"%s\").'", ",", "$", "by", "->", "toString", "(", ")", ",", "$", "e", "->", "getMessage", "(", ")", ",", "$", "this", "->", "getBrowser", "(", ")", "->", "getText", "(", ")", ")", ")", ";", "}", "}" ]
Proxy to browser, catch errors to display body on error. @return array
[ "Proxy", "to", "browser", "catch", "errors", "to", "display", "body", "on", "error", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Behat/AbstractWebDriverContext.php#L89-L98
229,920
alexandresalome/php-webdriver
src/WebDriver/Behat/AbstractWebDriverContext.php
AbstractWebDriverContext.parseSelector
protected function parseSelector($text) { if (0 === strpos($text, 'id=')) { return By::id(substr($text, 3)); } if (0 === strpos($text, 'xpath=')) { return By::xpath(substr($text, 6)); } if (0 === strpos($text, 'css=')) { return By::css(substr($text, 4)); } if (0 === strpos($text, 'name=')) { return By::name(substr($text, 5)); } if (0 === strpos($text, 'class=')) { return By::className(substr($text, 6)); } return $text; }
php
protected function parseSelector($text) { if (0 === strpos($text, 'id=')) { return By::id(substr($text, 3)); } if (0 === strpos($text, 'xpath=')) { return By::xpath(substr($text, 6)); } if (0 === strpos($text, 'css=')) { return By::css(substr($text, 4)); } if (0 === strpos($text, 'name=')) { return By::name(substr($text, 5)); } if (0 === strpos($text, 'class=')) { return By::className(substr($text, 6)); } return $text; }
[ "protected", "function", "parseSelector", "(", "$", "text", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "text", ",", "'id='", ")", ")", "{", "return", "By", "::", "id", "(", "substr", "(", "$", "text", ",", "3", ")", ")", ";", "}", "if", "(", "0", "===", "strpos", "(", "$", "text", ",", "'xpath='", ")", ")", "{", "return", "By", "::", "xpath", "(", "substr", "(", "$", "text", ",", "6", ")", ")", ";", "}", "if", "(", "0", "===", "strpos", "(", "$", "text", ",", "'css='", ")", ")", "{", "return", "By", "::", "css", "(", "substr", "(", "$", "text", ",", "4", ")", ")", ";", "}", "if", "(", "0", "===", "strpos", "(", "$", "text", ",", "'name='", ")", ")", "{", "return", "By", "::", "name", "(", "substr", "(", "$", "text", ",", "5", ")", ")", ";", "}", "if", "(", "0", "===", "strpos", "(", "$", "text", ",", "'class='", ")", ")", "{", "return", "By", "::", "className", "(", "substr", "(", "$", "text", ",", "6", ")", ")", ";", "}", "return", "$", "text", ";", "}" ]
Converts a text selector to a By object. Tries to find magic expressions (css=#foo, xpath=//div[@id="foo"], id=foo, name=q, class=active). @return By|string returns a By instance when magic matched, the string otherwise
[ "Converts", "a", "text", "selector", "to", "a", "By", "object", "." ]
ba187e7b13979e1db5001b7bfbe82d07c8e2e39d
https://github.com/alexandresalome/php-webdriver/blob/ba187e7b13979e1db5001b7bfbe82d07c8e2e39d/src/WebDriver/Behat/AbstractWebDriverContext.php#L132-L155
229,921
ZenMagick/ZenCart
includes/modules/payment/paypal.php
paypal.before_process
function before_process() { global $order_total_modules; list($this->transaction_amount, $this->transaction_currency) = $_SESSION['paypal_transaction_info']; unset($_SESSION['paypal_transaction_info']); if (isset($_GET['referer']) && $_GET['referer'] == 'paypal') { $this->notify('NOTIFY_PAYMENT_PAYPAL_RETURN_TO_STORE'); if (defined('MODULE_PAYMENT_PAYPAL_PDTTOKEN') && MODULE_PAYMENT_PAYPAL_PDTTOKEN != '' && isset($_GET['tx']) && $_GET['tx'] != '') { $pdtStatus = $this->_getPDTresults($this->transaction_amount, $this->transaction_currency, $_GET['tx']); } else { $pdtStatus = false; } if ($pdtStatus == false) { $_SESSION['cart']->reset(true); unset($_SESSION['sendto']); unset($_SESSION['billto']); unset($_SESSION['shipping']); unset($_SESSION['payment']); unset($_SESSION['comments']); unset($_SESSION['cot_gv']); $order_total_modules->clear_posts();//ICW ADDED FOR CREDIT CLASS SYSTEM zen_redirect(zen_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL')); } else { // PDT was good, so delete IPN session from PayPal table -- housekeeping. global $db; $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'"); unset($_SESSION['ppipn_key_to_remove']); $_SESSION['paypal_transaction_PDT_passed'] = true; return true; } } else { $this->notify('NOTIFY_PAYMENT_PAYPAL_CANCELLED_DURING_CHECKOUT'); zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); } }
php
function before_process() { global $order_total_modules; list($this->transaction_amount, $this->transaction_currency) = $_SESSION['paypal_transaction_info']; unset($_SESSION['paypal_transaction_info']); if (isset($_GET['referer']) && $_GET['referer'] == 'paypal') { $this->notify('NOTIFY_PAYMENT_PAYPAL_RETURN_TO_STORE'); if (defined('MODULE_PAYMENT_PAYPAL_PDTTOKEN') && MODULE_PAYMENT_PAYPAL_PDTTOKEN != '' && isset($_GET['tx']) && $_GET['tx'] != '') { $pdtStatus = $this->_getPDTresults($this->transaction_amount, $this->transaction_currency, $_GET['tx']); } else { $pdtStatus = false; } if ($pdtStatus == false) { $_SESSION['cart']->reset(true); unset($_SESSION['sendto']); unset($_SESSION['billto']); unset($_SESSION['shipping']); unset($_SESSION['payment']); unset($_SESSION['comments']); unset($_SESSION['cot_gv']); $order_total_modules->clear_posts();//ICW ADDED FOR CREDIT CLASS SYSTEM zen_redirect(zen_href_link(FILENAME_CHECKOUT_SUCCESS, '', 'SSL')); } else { // PDT was good, so delete IPN session from PayPal table -- housekeeping. global $db; $db->Execute("delete from " . TABLE_PAYPAL_SESSION . " where session_id = '" . zen_db_input($_SESSION['ppipn_key_to_remove']) . "'"); unset($_SESSION['ppipn_key_to_remove']); $_SESSION['paypal_transaction_PDT_passed'] = true; return true; } } else { $this->notify('NOTIFY_PAYMENT_PAYPAL_CANCELLED_DURING_CHECKOUT'); zen_redirect(zen_href_link(FILENAME_CHECKOUT_PAYMENT, '', 'SSL')); } }
[ "function", "before_process", "(", ")", "{", "global", "$", "order_total_modules", ";", "list", "(", "$", "this", "->", "transaction_amount", ",", "$", "this", "->", "transaction_currency", ")", "=", "$", "_SESSION", "[", "'paypal_transaction_info'", "]", ";", "unset", "(", "$", "_SESSION", "[", "'paypal_transaction_info'", "]", ")", ";", "if", "(", "isset", "(", "$", "_GET", "[", "'referer'", "]", ")", "&&", "$", "_GET", "[", "'referer'", "]", "==", "'paypal'", ")", "{", "$", "this", "->", "notify", "(", "'NOTIFY_PAYMENT_PAYPAL_RETURN_TO_STORE'", ")", ";", "if", "(", "defined", "(", "'MODULE_PAYMENT_PAYPAL_PDTTOKEN'", ")", "&&", "MODULE_PAYMENT_PAYPAL_PDTTOKEN", "!=", "''", "&&", "isset", "(", "$", "_GET", "[", "'tx'", "]", ")", "&&", "$", "_GET", "[", "'tx'", "]", "!=", "''", ")", "{", "$", "pdtStatus", "=", "$", "this", "->", "_getPDTresults", "(", "$", "this", "->", "transaction_amount", ",", "$", "this", "->", "transaction_currency", ",", "$", "_GET", "[", "'tx'", "]", ")", ";", "}", "else", "{", "$", "pdtStatus", "=", "false", ";", "}", "if", "(", "$", "pdtStatus", "==", "false", ")", "{", "$", "_SESSION", "[", "'cart'", "]", "->", "reset", "(", "true", ")", ";", "unset", "(", "$", "_SESSION", "[", "'sendto'", "]", ")", ";", "unset", "(", "$", "_SESSION", "[", "'billto'", "]", ")", ";", "unset", "(", "$", "_SESSION", "[", "'shipping'", "]", ")", ";", "unset", "(", "$", "_SESSION", "[", "'payment'", "]", ")", ";", "unset", "(", "$", "_SESSION", "[", "'comments'", "]", ")", ";", "unset", "(", "$", "_SESSION", "[", "'cot_gv'", "]", ")", ";", "$", "order_total_modules", "->", "clear_posts", "(", ")", ";", "//ICW ADDED FOR CREDIT CLASS SYSTEM", "zen_redirect", "(", "zen_href_link", "(", "FILENAME_CHECKOUT_SUCCESS", ",", "''", ",", "'SSL'", ")", ")", ";", "}", "else", "{", "// PDT was good, so delete IPN session from PayPal table -- housekeeping.", "global", "$", "db", ";", "$", "db", "->", "Execute", "(", "\"delete from \"", ".", "TABLE_PAYPAL_SESSION", ".", "\" where session_id = '\"", ".", "zen_db_input", "(", "$", "_SESSION", "[", "'ppipn_key_to_remove'", "]", ")", ".", "\"'\"", ")", ";", "unset", "(", "$", "_SESSION", "[", "'ppipn_key_to_remove'", "]", ")", ";", "$", "_SESSION", "[", "'paypal_transaction_PDT_passed'", "]", "=", "true", ";", "return", "true", ";", "}", "}", "else", "{", "$", "this", "->", "notify", "(", "'NOTIFY_PAYMENT_PAYPAL_CANCELLED_DURING_CHECKOUT'", ")", ";", "zen_redirect", "(", "zen_href_link", "(", "FILENAME_CHECKOUT_PAYMENT", ",", "''", ",", "'SSL'", ")", ")", ";", "}", "}" ]
Store transaction info to the order and process any results that come back from the payment gateway
[ "Store", "transaction", "info", "to", "the", "order", "and", "process", "any", "results", "that", "come", "back", "from", "the", "payment", "gateway" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/paypal.php#L326-L359
229,922
ZenMagick/ZenCart
includes/modules/payment/paypal.php
paypal.check
function check() { global $db; if (IS_ADMIN_FLAG === true) { global $sniffer; if ($sniffer->field_exists(TABLE_PAYPAL, 'zen_order_id')) $db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE COLUMN zen_order_id order_id int(11) NOT NULL default '0'"); } if (!isset($this->_check)) { $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_STATUS'"); $this->_check = $check_query->RecordCount(); } return $this->_check; }
php
function check() { global $db; if (IS_ADMIN_FLAG === true) { global $sniffer; if ($sniffer->field_exists(TABLE_PAYPAL, 'zen_order_id')) $db->Execute("ALTER TABLE " . TABLE_PAYPAL . " CHANGE COLUMN zen_order_id order_id int(11) NOT NULL default '0'"); } if (!isset($this->_check)) { $check_query = $db->Execute("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_PAYMENT_PAYPAL_STATUS'"); $this->_check = $check_query->RecordCount(); } return $this->_check; }
[ "function", "check", "(", ")", "{", "global", "$", "db", ";", "if", "(", "IS_ADMIN_FLAG", "===", "true", ")", "{", "global", "$", "sniffer", ";", "if", "(", "$", "sniffer", "->", "field_exists", "(", "TABLE_PAYPAL", ",", "'zen_order_id'", ")", ")", "$", "db", "->", "Execute", "(", "\"ALTER TABLE \"", ".", "TABLE_PAYPAL", ".", "\" CHANGE COLUMN zen_order_id order_id int(11) NOT NULL default '0'\"", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_check", ")", ")", "{", "$", "check_query", "=", "$", "db", "->", "Execute", "(", "\"select configuration_value from \"", ".", "TABLE_CONFIGURATION", ".", "\" where configuration_key = 'MODULE_PAYMENT_PAYPAL_STATUS'\"", ")", ";", "$", "this", "->", "_check", "=", "$", "check_query", "->", "RecordCount", "(", ")", ";", "}", "return", "$", "this", "->", "_check", ";", "}" ]
Check to see whether module is installed @return boolean
[ "Check", "to", "see", "whether", "module", "is", "installed" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/paypal.php#L465-L476
229,923
ikkez/f3-events
lib/event.php
Event.on
public function on($key,$func,$priority=10,$options=array()) { $call = $options ? array($func,$options) : $func; if ($e = &$this->f3->ref($this->ekey.$key)) $e[$priority][] = $call; else $e = array($priority=>array($call)); krsort($e); }
php
public function on($key,$func,$priority=10,$options=array()) { $call = $options ? array($func,$options) : $func; if ($e = &$this->f3->ref($this->ekey.$key)) $e[$priority][] = $call; else $e = array($priority=>array($call)); krsort($e); }
[ "public", "function", "on", "(", "$", "key", ",", "$", "func", ",", "$", "priority", "=", "10", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "call", "=", "$", "options", "?", "array", "(", "$", "func", ",", "$", "options", ")", ":", "$", "func", ";", "if", "(", "$", "e", "=", "&", "$", "this", "->", "f3", "->", "ref", "(", "$", "this", "->", "ekey", ".", "$", "key", ")", ")", "$", "e", "[", "$", "priority", "]", "[", "]", "=", "$", "call", ";", "else", "$", "e", "=", "array", "(", "$", "priority", "=>", "array", "(", "$", "call", ")", ")", ";", "krsort", "(", "$", "e", ")", ";", "}" ]
add a listener to an event. It can catch the event dispatched by broadcast and emit. @param $key @param $func @param int $priority @param array $options
[ "add", "a", "listener", "to", "an", "event", ".", "It", "can", "catch", "the", "event", "dispatched", "by", "broadcast", "and", "emit", "." ]
4dab051ad68ec93efa8ac42045579afc440189c3
https://github.com/ikkez/f3-events/blob/4dab051ad68ec93efa8ac42045579afc440189c3/lib/event.php#L43-L50
229,924
ikkez/f3-events
lib/event.php
Event.unwatch
public function unwatch($obj) { $this->f3->clear('EVENTS_local.'.$this->f3->hash(spl_object_hash($obj))); }
php
public function unwatch($obj) { $this->f3->clear('EVENTS_local.'.$this->f3->hash(spl_object_hash($obj))); }
[ "public", "function", "unwatch", "(", "$", "obj", ")", "{", "$", "this", "->", "f3", "->", "clear", "(", "'EVENTS_local.'", ".", "$", "this", "->", "f3", "->", "hash", "(", "spl_object_hash", "(", "$", "obj", ")", ")", ")", ";", "}" ]
drop the watching sensor for an object @param $obj
[ "drop", "the", "watching", "sensor", "for", "an", "object" ]
4dab051ad68ec93efa8ac42045579afc440189c3
https://github.com/ikkez/f3-events/blob/4dab051ad68ec93efa8ac42045579afc440189c3/lib/event.php#L175-L177
229,925
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/ArrayObject/ArrayObject.php
ArrayObject.last
public function last() { $arr = $this->val(); $last = end($arr); return StdObjectWrapper::returnStdObject($last); }
php
public function last() { $arr = $this->val(); $last = end($arr); return StdObjectWrapper::returnStdObject($last); }
[ "public", "function", "last", "(", ")", "{", "$", "arr", "=", "$", "this", "->", "val", "(", ")", ";", "$", "last", "=", "end", "(", "$", "arr", ")", ";", "return", "StdObjectWrapper", "::", "returnStdObject", "(", "$", "last", ")", ";", "}" ]
Get the last element in the array. If the element is array, ArrayObject is returned, else StringObject is returned. @return StringObject|ArrayObject|StdObjectWrapper The last element in the array.
[ "Get", "the", "last", "element", "in", "the", "array", ".", "If", "the", "element", "is", "array", "ArrayObject", "is", "returned", "else", "StringObject", "is", "returned", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/ArrayObject/ArrayObject.php#L107-L113
229,926
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/ArrayObject/ArrayObject.php
ArrayObject.first
public function first() { $arr = $this->val(); $first = reset($arr); return StdObjectWrapper::returnStdObject($first); }
php
public function first() { $arr = $this->val(); $first = reset($arr); return StdObjectWrapper::returnStdObject($first); }
[ "public", "function", "first", "(", ")", "{", "$", "arr", "=", "$", "this", "->", "val", "(", ")", ";", "$", "first", "=", "reset", "(", "$", "arr", ")", ";", "return", "StdObjectWrapper", "::", "returnStdObject", "(", "$", "first", ")", ";", "}" ]
Get the first element in the array. If the element is array, ArrayObject is returned, else StringObject is returned. @return StringObject|ArrayObject|StdObjectWrapper The first element in the array.
[ "Get", "the", "first", "element", "in", "the", "array", ".", "If", "the", "element", "is", "array", "ArrayObject", "is", "returned", "else", "StringObject", "is", "returned", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/ArrayObject/ArrayObject.php#L121-L127
229,927
Webiny/Framework
src/Webiny/Component/Http/HttpTrait.php
HttpTrait.httpRedirect
protected static function httpRedirect($url, $headers = [], $redirectCode = 301) { $url = new UrlObject($url); $headers['Location'] = $url->val(); $response = new Response('', $redirectCode, $headers); $response->sendHeaders(); }
php
protected static function httpRedirect($url, $headers = [], $redirectCode = 301) { $url = new UrlObject($url); $headers['Location'] = $url->val(); $response = new Response('', $redirectCode, $headers); $response->sendHeaders(); }
[ "protected", "static", "function", "httpRedirect", "(", "$", "url", ",", "$", "headers", "=", "[", "]", ",", "$", "redirectCode", "=", "301", ")", "{", "$", "url", "=", "new", "UrlObject", "(", "$", "url", ")", ";", "$", "headers", "[", "'Location'", "]", "=", "$", "url", "->", "val", "(", ")", ";", "$", "response", "=", "new", "Response", "(", "''", ",", "$", "redirectCode", ",", "$", "headers", ")", ";", "$", "response", "->", "sendHeaders", "(", ")", ";", "}" ]
Redirect the request to the given url. @param string|UrlObject $url @param string|int|array $headers Headers that you wish to send with your request. @param int $redirectCode
[ "Redirect", "the", "request", "to", "the", "given", "url", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Http/HttpTrait.php#L71-L78
229,928
ZenMagick/ZenCart
includes/modules/payment/authorizenet_aim.php
authorizenet_aim.tableCheckup
function tableCheckup() { global $db, $sniffer; $fieldOkay1 = (method_exists($sniffer, 'field_type')) ? $sniffer->field_type(TABLE_AUTHORIZENET, 'transaction_id', 'bigint(20)', true) : -1; if ($fieldOkay1 !== true) { $db->Execute("ALTER TABLE " . TABLE_AUTHORIZENET . " CHANGE transaction_id transaction_id bigint(20) default NULL"); } }
php
function tableCheckup() { global $db, $sniffer; $fieldOkay1 = (method_exists($sniffer, 'field_type')) ? $sniffer->field_type(TABLE_AUTHORIZENET, 'transaction_id', 'bigint(20)', true) : -1; if ($fieldOkay1 !== true) { $db->Execute("ALTER TABLE " . TABLE_AUTHORIZENET . " CHANGE transaction_id transaction_id bigint(20) default NULL"); } }
[ "function", "tableCheckup", "(", ")", "{", "global", "$", "db", ",", "$", "sniffer", ";", "$", "fieldOkay1", "=", "(", "method_exists", "(", "$", "sniffer", ",", "'field_type'", ")", ")", "?", "$", "sniffer", "->", "field_type", "(", "TABLE_AUTHORIZENET", ",", "'transaction_id'", ",", "'bigint(20)'", ",", "true", ")", ":", "-", "1", ";", "if", "(", "$", "fieldOkay1", "!==", "true", ")", "{", "$", "db", "->", "Execute", "(", "\"ALTER TABLE \"", ".", "TABLE_AUTHORIZENET", ".", "\" CHANGE transaction_id transaction_id bigint(20) default NULL\"", ")", ";", "}", "}" ]
Check and fix table structure if appropriate
[ "Check", "and", "fix", "table", "structure", "if", "appropriate" ]
00438ebc0faee786489aab4a6d70fc0d0c1461c7
https://github.com/ZenMagick/ZenCart/blob/00438ebc0faee786489aab4a6d70fc0d0c1461c7/includes/modules/payment/authorizenet_aim.php#L674-L680
229,929
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php
ManipulatorTrait.setScheme
public function setScheme($scheme) { // validate scheme try { $scheme = new StringObject($scheme); } catch (\Exception $e) { throw new UrlObjectException($e->getMessage()); } if (!$scheme->endsWith('://')) { $scheme->val($scheme->val() . '://'); } // set the scheme $this->scheme = $scheme->trimRight('://')->val(); $this->rebuildUrl(); return $this; }
php
public function setScheme($scheme) { // validate scheme try { $scheme = new StringObject($scheme); } catch (\Exception $e) { throw new UrlObjectException($e->getMessage()); } if (!$scheme->endsWith('://')) { $scheme->val($scheme->val() . '://'); } // set the scheme $this->scheme = $scheme->trimRight('://')->val(); $this->rebuildUrl(); return $this; }
[ "public", "function", "setScheme", "(", "$", "scheme", ")", "{", "// validate scheme", "try", "{", "$", "scheme", "=", "new", "StringObject", "(", "$", "scheme", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "UrlObjectException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "!", "$", "scheme", "->", "endsWith", "(", "'://'", ")", ")", "{", "$", "scheme", "->", "val", "(", "$", "scheme", "->", "val", "(", ")", ".", "'://'", ")", ";", "}", "// set the scheme", "$", "this", "->", "scheme", "=", "$", "scheme", "->", "trimRight", "(", "'://'", ")", "->", "val", "(", ")", ";", "$", "this", "->", "rebuildUrl", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set url scheme. @param StringObject|string $scheme - Scheme must end with '://'. Example 'http://'. @throws UrlObjectException @return $this
[ "Set", "url", "scheme", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php#L32-L50
229,930
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php
ManipulatorTrait.setHost
public function setHost($host) { try { $host = new StringObject($host); } catch (\Exception $e) { throw new UrlObjectException($e->getMessage()); } $this->host = $host->stripTrailingSlash()->trim()->val(); $this->rebuildUrl(); return $this; }
php
public function setHost($host) { try { $host = new StringObject($host); } catch (\Exception $e) { throw new UrlObjectException($e->getMessage()); } $this->host = $host->stripTrailingSlash()->trim()->val(); $this->rebuildUrl(); return $this; }
[ "public", "function", "setHost", "(", "$", "host", ")", "{", "try", "{", "$", "host", "=", "new", "StringObject", "(", "$", "host", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "UrlObjectException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "$", "this", "->", "host", "=", "$", "host", "->", "stripTrailingSlash", "(", ")", "->", "trim", "(", ")", "->", "val", "(", ")", ";", "$", "this", "->", "rebuildUrl", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set url host. @param StringObject|string $host Url host. @throws UrlObjectException @return $this
[ "Set", "url", "host", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php#L60-L73
229,931
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php
ManipulatorTrait.setPort
public function setPort($port) { $this->port = StdObjectWrapper::toString($port); $this->rebuildUrl(); return $this; }
php
public function setPort($port) { $this->port = StdObjectWrapper::toString($port); $this->rebuildUrl(); return $this; }
[ "public", "function", "setPort", "(", "$", "port", ")", "{", "$", "this", "->", "port", "=", "StdObjectWrapper", "::", "toString", "(", "$", "port", ")", ";", "$", "this", "->", "rebuildUrl", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set url port. @param StringObject|string $port Url port. @return $this
[ "Set", "url", "port", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php#L82-L88
229,932
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php
ManipulatorTrait.setPath
public function setPath($path) { try { $path = new StringObject($path); } catch (\Exception $e) { throw new UrlObjectException($e->getMessage()); } if ($path != '') { $path->trimLeft('/'); $this->path = '/' . $path->val(); } else { $this->path = $path->val(); } $this->rebuildUrl(); return $this; }
php
public function setPath($path) { try { $path = new StringObject($path); } catch (\Exception $e) { throw new UrlObjectException($e->getMessage()); } if ($path != '') { $path->trimLeft('/'); $this->path = '/' . $path->val(); } else { $this->path = $path->val(); } $this->rebuildUrl(); return $this; }
[ "public", "function", "setPath", "(", "$", "path", ")", "{", "try", "{", "$", "path", "=", "new", "StringObject", "(", "$", "path", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "UrlObjectException", "(", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "if", "(", "$", "path", "!=", "''", ")", "{", "$", "path", "->", "trimLeft", "(", "'/'", ")", ";", "$", "this", "->", "path", "=", "'/'", ".", "$", "path", "->", "val", "(", ")", ";", "}", "else", "{", "$", "this", "->", "path", "=", "$", "path", "->", "val", "(", ")", ";", "}", "$", "this", "->", "rebuildUrl", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set url path. @param StringObject|string $path Url path. @throws UrlObjectException @return $this
[ "Set", "url", "path", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php#L98-L116
229,933
Webiny/Framework
src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php
ManipulatorTrait.setQuery
public function setQuery($query, $append = false) { if ($this->isStdObject($query)) { $query = $query->val(); } if ($append && $this->query != '') { if ($this->isString($this->query)) { $currentQuery = new StringObject($this->query); $currentQuery = $currentQuery->parseString(); } else { $currentQuery = new ArrayObject($this->query); } if ($this->isStdObject($query)) { if (StdObjectWrapper::isArrayObject($append)) { $query = $query->val(); } else { if (StdObjectWrapper::isStringObject($query)) { $query = $query->parseString()->val(); } else { throw new UrlObjectException(UrlObjectException::MSG_INVALID_ARG, [ '$query', 'StringObject|ArrayObject|string|array' ] ); } } } else { if ($this->isString($query)) { $query = new StringObject($query); $query = $query->parseString()->val(); } } $currentQuery->merge($query); $query = $currentQuery->val(); } $this->query = $query; $this->rebuildUrl(); return $this; }
php
public function setQuery($query, $append = false) { if ($this->isStdObject($query)) { $query = $query->val(); } if ($append && $this->query != '') { if ($this->isString($this->query)) { $currentQuery = new StringObject($this->query); $currentQuery = $currentQuery->parseString(); } else { $currentQuery = new ArrayObject($this->query); } if ($this->isStdObject($query)) { if (StdObjectWrapper::isArrayObject($append)) { $query = $query->val(); } else { if (StdObjectWrapper::isStringObject($query)) { $query = $query->parseString()->val(); } else { throw new UrlObjectException(UrlObjectException::MSG_INVALID_ARG, [ '$query', 'StringObject|ArrayObject|string|array' ] ); } } } else { if ($this->isString($query)) { $query = new StringObject($query); $query = $query->parseString()->val(); } } $currentQuery->merge($query); $query = $currentQuery->val(); } $this->query = $query; $this->rebuildUrl(); return $this; }
[ "public", "function", "setQuery", "(", "$", "query", ",", "$", "append", "=", "false", ")", "{", "if", "(", "$", "this", "->", "isStdObject", "(", "$", "query", ")", ")", "{", "$", "query", "=", "$", "query", "->", "val", "(", ")", ";", "}", "if", "(", "$", "append", "&&", "$", "this", "->", "query", "!=", "''", ")", "{", "if", "(", "$", "this", "->", "isString", "(", "$", "this", "->", "query", ")", ")", "{", "$", "currentQuery", "=", "new", "StringObject", "(", "$", "this", "->", "query", ")", ";", "$", "currentQuery", "=", "$", "currentQuery", "->", "parseString", "(", ")", ";", "}", "else", "{", "$", "currentQuery", "=", "new", "ArrayObject", "(", "$", "this", "->", "query", ")", ";", "}", "if", "(", "$", "this", "->", "isStdObject", "(", "$", "query", ")", ")", "{", "if", "(", "StdObjectWrapper", "::", "isArrayObject", "(", "$", "append", ")", ")", "{", "$", "query", "=", "$", "query", "->", "val", "(", ")", ";", "}", "else", "{", "if", "(", "StdObjectWrapper", "::", "isStringObject", "(", "$", "query", ")", ")", "{", "$", "query", "=", "$", "query", "->", "parseString", "(", ")", "->", "val", "(", ")", ";", "}", "else", "{", "throw", "new", "UrlObjectException", "(", "UrlObjectException", "::", "MSG_INVALID_ARG", ",", "[", "'$query'", ",", "'StringObject|ArrayObject|string|array'", "]", ")", ";", "}", "}", "}", "else", "{", "if", "(", "$", "this", "->", "isString", "(", "$", "query", ")", ")", "{", "$", "query", "=", "new", "StringObject", "(", "$", "query", ")", ";", "$", "query", "=", "$", "query", "->", "parseString", "(", ")", "->", "val", "(", ")", ";", "}", "}", "$", "currentQuery", "->", "merge", "(", "$", "query", ")", ";", "$", "query", "=", "$", "currentQuery", "->", "val", "(", ")", ";", "}", "$", "this", "->", "query", "=", "$", "query", ";", "$", "this", "->", "rebuildUrl", "(", ")", ";", "return", "$", "this", ";", "}" ]
Set url query param. @param StringObject|ArrayObject|string|array $query Query params. @param bool $append Do you want to append or overwrite current query param. In case when you are appending values, the values from $query, that already exist in the current query, will be overwritten by the ones inside the $query. @throws UrlObjectException @return $this
[ "Set", "url", "query", "param", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/StdLib/StdObject/UrlObject/ManipulatorTrait.php#L130-L174
229,934
Webiny/Framework
src/Webiny/Component/Security/Security.php
Security.firewall
public function firewall($firewallKey = '') { // initialize firewall if (isset($this->firewalls[$firewallKey])) { $fw = $this->firewalls[$firewallKey]; } else { if ($firewallKey == '') { $firewall = $this->getConfig()->Firewalls[0]; if (empty($firewall)) { throw new SecurityException("There are no firewalls defined inside your configuration."); } } else { $firewall = $this->getConfig()->Firewalls->get($firewallKey, false); if (!$firewall) { throw new SecurityException("Firewall '" . $firewallKey . "' is not defined under Security.Firewalls."); } } $fw = new Firewall($firewallKey, $firewall, $this->getFirewallUserProviders($firewallKey), $this->getFirewallEncoder($firewallKey)); $this->firewalls[$firewallKey] = $fw; } return $fw; }
php
public function firewall($firewallKey = '') { // initialize firewall if (isset($this->firewalls[$firewallKey])) { $fw = $this->firewalls[$firewallKey]; } else { if ($firewallKey == '') { $firewall = $this->getConfig()->Firewalls[0]; if (empty($firewall)) { throw new SecurityException("There are no firewalls defined inside your configuration."); } } else { $firewall = $this->getConfig()->Firewalls->get($firewallKey, false); if (!$firewall) { throw new SecurityException("Firewall '" . $firewallKey . "' is not defined under Security.Firewalls."); } } $fw = new Firewall($firewallKey, $firewall, $this->getFirewallUserProviders($firewallKey), $this->getFirewallEncoder($firewallKey)); $this->firewalls[$firewallKey] = $fw; } return $fw; }
[ "public", "function", "firewall", "(", "$", "firewallKey", "=", "''", ")", "{", "// initialize firewall", "if", "(", "isset", "(", "$", "this", "->", "firewalls", "[", "$", "firewallKey", "]", ")", ")", "{", "$", "fw", "=", "$", "this", "->", "firewalls", "[", "$", "firewallKey", "]", ";", "}", "else", "{", "if", "(", "$", "firewallKey", "==", "''", ")", "{", "$", "firewall", "=", "$", "this", "->", "getConfig", "(", ")", "->", "Firewalls", "[", "0", "]", ";", "if", "(", "empty", "(", "$", "firewall", ")", ")", "{", "throw", "new", "SecurityException", "(", "\"There are no firewalls defined inside your configuration.\"", ")", ";", "}", "}", "else", "{", "$", "firewall", "=", "$", "this", "->", "getConfig", "(", ")", "->", "Firewalls", "->", "get", "(", "$", "firewallKey", ",", "false", ")", ";", "if", "(", "!", "$", "firewall", ")", "{", "throw", "new", "SecurityException", "(", "\"Firewall '\"", ".", "$", "firewallKey", ".", "\"' is not defined under Security.Firewalls.\"", ")", ";", "}", "}", "$", "fw", "=", "new", "Firewall", "(", "$", "firewallKey", ",", "$", "firewall", ",", "$", "this", "->", "getFirewallUserProviders", "(", "$", "firewallKey", ")", ",", "$", "this", "->", "getFirewallEncoder", "(", "$", "firewallKey", ")", ")", ";", "$", "this", "->", "firewalls", "[", "$", "firewallKey", "]", "=", "$", "fw", ";", "}", "return", "$", "fw", ";", "}" ]
Initializes the security layer for a specific firewall. @param string $firewallKey Name of the firewall you wish to return. If you don't pass the name param, the first firewall from your configuration will be used. @throws SecurityException @return Firewall
[ "Initializes", "the", "security", "layer", "for", "a", "specific", "firewall", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Security.php#L71-L98
229,935
Webiny/Framework
src/Webiny/Component/Security/Security.php
Security.getFirewallEncoder
private function getFirewallEncoder($firewallKey) { // get the encoder name $encoderName = $this->getFirewallConfig($firewallKey)->get('Encoder', 'Crypt'); if (!$encoderName) { $encoderName = 'Plain'; } // check if the encoder is defined in the global config $encoderConfig = $this->getConfig()->get('Encoders.' . $encoderName, false); // get the driver & params $driver = false; $params = null; if ($encoderConfig) { $driver = $encoderConfig->get('Driver', false); $params = $encoderConfig->get('Params', null, true); } // get the driver class name if (!$driver && isset(self::$encoders[$encoderName])) { // use built-in driver $driver = self::$encoders[$encoderName]; } else { if (isset(self::$encoders[$driver])) { // driver defined as short-name built-in driver $driver = self::$encoders[$driver]; } else { if (!$driver) { throw new SecurityException('Invalid "Driver" param for "' . $encoderName . '" encoder.'); } } } // create encoder instance return new Encoder($driver, $params); }
php
private function getFirewallEncoder($firewallKey) { // get the encoder name $encoderName = $this->getFirewallConfig($firewallKey)->get('Encoder', 'Crypt'); if (!$encoderName) { $encoderName = 'Plain'; } // check if the encoder is defined in the global config $encoderConfig = $this->getConfig()->get('Encoders.' . $encoderName, false); // get the driver & params $driver = false; $params = null; if ($encoderConfig) { $driver = $encoderConfig->get('Driver', false); $params = $encoderConfig->get('Params', null, true); } // get the driver class name if (!$driver && isset(self::$encoders[$encoderName])) { // use built-in driver $driver = self::$encoders[$encoderName]; } else { if (isset(self::$encoders[$driver])) { // driver defined as short-name built-in driver $driver = self::$encoders[$driver]; } else { if (!$driver) { throw new SecurityException('Invalid "Driver" param for "' . $encoderName . '" encoder.'); } } } // create encoder instance return new Encoder($driver, $params); }
[ "private", "function", "getFirewallEncoder", "(", "$", "firewallKey", ")", "{", "// get the encoder name", "$", "encoderName", "=", "$", "this", "->", "getFirewallConfig", "(", "$", "firewallKey", ")", "->", "get", "(", "'Encoder'", ",", "'Crypt'", ")", ";", "if", "(", "!", "$", "encoderName", ")", "{", "$", "encoderName", "=", "'Plain'", ";", "}", "// check if the encoder is defined in the global config", "$", "encoderConfig", "=", "$", "this", "->", "getConfig", "(", ")", "->", "get", "(", "'Encoders.'", ".", "$", "encoderName", ",", "false", ")", ";", "// get the driver & params", "$", "driver", "=", "false", ";", "$", "params", "=", "null", ";", "if", "(", "$", "encoderConfig", ")", "{", "$", "driver", "=", "$", "encoderConfig", "->", "get", "(", "'Driver'", ",", "false", ")", ";", "$", "params", "=", "$", "encoderConfig", "->", "get", "(", "'Params'", ",", "null", ",", "true", ")", ";", "}", "// get the driver class name", "if", "(", "!", "$", "driver", "&&", "isset", "(", "self", "::", "$", "encoders", "[", "$", "encoderName", "]", ")", ")", "{", "// use built-in driver", "$", "driver", "=", "self", "::", "$", "encoders", "[", "$", "encoderName", "]", ";", "}", "else", "{", "if", "(", "isset", "(", "self", "::", "$", "encoders", "[", "$", "driver", "]", ")", ")", "{", "// driver defined as short-name built-in driver", "$", "driver", "=", "self", "::", "$", "encoders", "[", "$", "driver", "]", ";", "}", "else", "{", "if", "(", "!", "$", "driver", ")", "{", "throw", "new", "SecurityException", "(", "'Invalid \"Driver\" param for \"'", ".", "$", "encoderName", ".", "'\" encoder.'", ")", ";", "}", "}", "}", "// create encoder instance", "return", "new", "Encoder", "(", "$", "driver", ",", "$", "params", ")", ";", "}" ]
Returns the encoder instance for the given firewall. @param string $firewallKey Firewall name. @return Encoder @throws SecurityException
[ "Returns", "the", "encoder", "instance", "for", "the", "given", "firewall", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Security.php#L174-L208
229,936
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Image.php
Image.send
public function send() { // Set some defaults $extension = null; $returnImage = $this->_absoluteImagePath; // If the GD extension is not available if (!extension_loaded('gd') && (!function_exists('dl') || !dl('gd.so'))) { $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::GD_UNAVAILABLE_MSG, \Tollwerk\Squeezr\Exception::GD_UNAVAILABLE); // If the cache directory doesn't exist or is not writable: Error } elseif ((!@is_dir($this->_absoluteCacheImageDir) && !@mkdir($this->_absoluteCacheImageDir, 0777, true)) || !@is_writable($this->_absoluteCacheImageDir) ) { $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::INVALID_TARGET_CACHE_DIRECTORY_MSG, \Tollwerk\Squeezr\Exception::INVALID_TARGET_CACHE_DIRECTORY); // If the squeezr screen cookie is not available or invalid } elseif (empty($_COOKIE['squeezr_screen']) || !preg_match("%^(\d+)x(\d+)\@(\d+(?:\.\d+)?)$%", $_COOKIE['squeezr_screen'], $squeezr) ) { $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::MISSING_METRICS_COOKIE_MSG, \Tollwerk\Squeezr\Exception::MISSING_METRICS_COOKIE); // Copy & resample original image } else { $errors = array(); $returnImage = $this->squeeze($this->_absoluteImagePath, $this->_absoluteCacheImagePath, SQUEEZR_BREAKPOINT, $errors); foreach ($errors as $errNo => $errMsg) { $this->_addErrorHeader(sprintf($errMsg, $this->_relativeImagePath), $errNo); } } // Send the image along with it's HTTP headers $extension = ($extension === null) ? pathinfo($returnImage, PATHINFO_EXTENSION) : $extension; $this->_sendFile($returnImage, 'image/'.((strtolower($extension) == 'jpg') ? 'jpeg' : strtolower($extension)), true); exit; }
php
public function send() { // Set some defaults $extension = null; $returnImage = $this->_absoluteImagePath; // If the GD extension is not available if (!extension_loaded('gd') && (!function_exists('dl') || !dl('gd.so'))) { $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::GD_UNAVAILABLE_MSG, \Tollwerk\Squeezr\Exception::GD_UNAVAILABLE); // If the cache directory doesn't exist or is not writable: Error } elseif ((!@is_dir($this->_absoluteCacheImageDir) && !@mkdir($this->_absoluteCacheImageDir, 0777, true)) || !@is_writable($this->_absoluteCacheImageDir) ) { $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::INVALID_TARGET_CACHE_DIRECTORY_MSG, \Tollwerk\Squeezr\Exception::INVALID_TARGET_CACHE_DIRECTORY); // If the squeezr screen cookie is not available or invalid } elseif (empty($_COOKIE['squeezr_screen']) || !preg_match("%^(\d+)x(\d+)\@(\d+(?:\.\d+)?)$%", $_COOKIE['squeezr_screen'], $squeezr) ) { $this->_addErrorHeader(\Tollwerk\Squeezr\Exception::MISSING_METRICS_COOKIE_MSG, \Tollwerk\Squeezr\Exception::MISSING_METRICS_COOKIE); // Copy & resample original image } else { $errors = array(); $returnImage = $this->squeeze($this->_absoluteImagePath, $this->_absoluteCacheImagePath, SQUEEZR_BREAKPOINT, $errors); foreach ($errors as $errNo => $errMsg) { $this->_addErrorHeader(sprintf($errMsg, $this->_relativeImagePath), $errNo); } } // Send the image along with it's HTTP headers $extension = ($extension === null) ? pathinfo($returnImage, PATHINFO_EXTENSION) : $extension; $this->_sendFile($returnImage, 'image/'.((strtolower($extension) == 'jpg') ? 'jpeg' : strtolower($extension)), true); exit; }
[ "public", "function", "send", "(", ")", "{", "// Set some defaults", "$", "extension", "=", "null", ";", "$", "returnImage", "=", "$", "this", "->", "_absoluteImagePath", ";", "// If the GD extension is not available", "if", "(", "!", "extension_loaded", "(", "'gd'", ")", "&&", "(", "!", "function_exists", "(", "'dl'", ")", "||", "!", "dl", "(", "'gd.so'", ")", ")", ")", "{", "$", "this", "->", "_addErrorHeader", "(", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "GD_UNAVAILABLE_MSG", ",", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "GD_UNAVAILABLE", ")", ";", "// If the cache directory doesn't exist or is not writable: Error", "}", "elseif", "(", "(", "!", "@", "is_dir", "(", "$", "this", "->", "_absoluteCacheImageDir", ")", "&&", "!", "@", "mkdir", "(", "$", "this", "->", "_absoluteCacheImageDir", ",", "0777", ",", "true", ")", ")", "||", "!", "@", "is_writable", "(", "$", "this", "->", "_absoluteCacheImageDir", ")", ")", "{", "$", "this", "->", "_addErrorHeader", "(", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "INVALID_TARGET_CACHE_DIRECTORY_MSG", ",", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "INVALID_TARGET_CACHE_DIRECTORY", ")", ";", "// If the squeezr screen cookie is not available or invalid", "}", "elseif", "(", "empty", "(", "$", "_COOKIE", "[", "'squeezr_screen'", "]", ")", "||", "!", "preg_match", "(", "\"%^(\\d+)x(\\d+)\\@(\\d+(?:\\.\\d+)?)$%\"", ",", "$", "_COOKIE", "[", "'squeezr_screen'", "]", ",", "$", "squeezr", ")", ")", "{", "$", "this", "->", "_addErrorHeader", "(", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "MISSING_METRICS_COOKIE_MSG", ",", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "MISSING_METRICS_COOKIE", ")", ";", "// Copy & resample original image", "}", "else", "{", "$", "errors", "=", "array", "(", ")", ";", "$", "returnImage", "=", "$", "this", "->", "squeeze", "(", "$", "this", "->", "_absoluteImagePath", ",", "$", "this", "->", "_absoluteCacheImagePath", ",", "SQUEEZR_BREAKPOINT", ",", "$", "errors", ")", ";", "foreach", "(", "$", "errors", "as", "$", "errNo", "=>", "$", "errMsg", ")", "{", "$", "this", "->", "_addErrorHeader", "(", "sprintf", "(", "$", "errMsg", ",", "$", "this", "->", "_relativeImagePath", ")", ",", "$", "errNo", ")", ";", "}", "}", "// Send the image along with it's HTTP headers", "$", "extension", "=", "(", "$", "extension", "===", "null", ")", "?", "pathinfo", "(", "$", "returnImage", ",", "PATHINFO_EXTENSION", ")", ":", "$", "extension", ";", "$", "this", "->", "_sendFile", "(", "$", "returnImage", ",", "'image/'", ".", "(", "(", "strtolower", "(", "$", "extension", ")", "==", "'jpg'", ")", "?", "'jpeg'", ":", "strtolower", "(", "$", "extension", ")", ")", ",", "true", ")", ";", "exit", ";", "}" ]
Send the cached and possibly downsampled image @return void
[ "Send", "the", "cached", "and", "possibly", "downsampled", "image" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Image.php#L92-L133
229,937
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Image.php
Image.squeeze
public static function squeeze($source, $target, $breakpoint = SQUEEZR_BREAKPOINT, array &$errors = array()) { $returnImage = null; // Determine the image dimensions list($width, $height, $type) = getImageSize($source); // Determine the target width (considering the breakpoint) $targetWidth = intval($breakpoint); // If the image image has to be downsampled at all if ($width > $targetWidth) { // Prepare basic target parameters $targetHeight = round($targetWidth * $height / $width); switch ($type) { case IMAGETYPE_PNG: $saved = self::_downscalePng($source, $width, $height, $target, $targetWidth, $targetHeight); break; case IMAGETYPE_JPEG: $saved = self::_downscaleJpeg($source, $width, $height, $target, $targetWidth, $targetHeight); break; case IMAGETYPE_GIF: $saved = self::_downscaleGif($source, $width, $height, $target, $targetWidth, $targetHeight); break; default: $saved = false; } // If target image could be created: Send it if ($saved && @file_exists($target)) { $returnImage = $target; // Else: Error } else { $errors[\Tollwerk\Squeezr\Exception::FAILED_DOWNSAMPLE_CACHE] = \Tollwerk\Squeezr\Exception::FAILED_DOWNSAMPLE_CACHE_MSG; } // Else: No downsampling necessary, try to cache a copy of the original image to avoid subsequent squeeze attempts } elseif (!@symlink($source, $target) && (SQUEEZR_IMAGE_COPY_UNDERSIZED ? !@copy($source, $target) : true)) { $errors[\Tollwerk\Squeezr\Exception::FAILED_COPY_CACHE] = \Tollwerk\Squeezr\Exception::FAILED_COPY_CACHE_MSG; // Else: Return target image } else { $returnImage = $target; } return $returnImage; }
php
public static function squeeze($source, $target, $breakpoint = SQUEEZR_BREAKPOINT, array &$errors = array()) { $returnImage = null; // Determine the image dimensions list($width, $height, $type) = getImageSize($source); // Determine the target width (considering the breakpoint) $targetWidth = intval($breakpoint); // If the image image has to be downsampled at all if ($width > $targetWidth) { // Prepare basic target parameters $targetHeight = round($targetWidth * $height / $width); switch ($type) { case IMAGETYPE_PNG: $saved = self::_downscalePng($source, $width, $height, $target, $targetWidth, $targetHeight); break; case IMAGETYPE_JPEG: $saved = self::_downscaleJpeg($source, $width, $height, $target, $targetWidth, $targetHeight); break; case IMAGETYPE_GIF: $saved = self::_downscaleGif($source, $width, $height, $target, $targetWidth, $targetHeight); break; default: $saved = false; } // If target image could be created: Send it if ($saved && @file_exists($target)) { $returnImage = $target; // Else: Error } else { $errors[\Tollwerk\Squeezr\Exception::FAILED_DOWNSAMPLE_CACHE] = \Tollwerk\Squeezr\Exception::FAILED_DOWNSAMPLE_CACHE_MSG; } // Else: No downsampling necessary, try to cache a copy of the original image to avoid subsequent squeeze attempts } elseif (!@symlink($source, $target) && (SQUEEZR_IMAGE_COPY_UNDERSIZED ? !@copy($source, $target) : true)) { $errors[\Tollwerk\Squeezr\Exception::FAILED_COPY_CACHE] = \Tollwerk\Squeezr\Exception::FAILED_COPY_CACHE_MSG; // Else: Return target image } else { $returnImage = $target; } return $returnImage; }
[ "public", "static", "function", "squeeze", "(", "$", "source", ",", "$", "target", ",", "$", "breakpoint", "=", "SQUEEZR_BREAKPOINT", ",", "array", "&", "$", "errors", "=", "array", "(", ")", ")", "{", "$", "returnImage", "=", "null", ";", "// Determine the image dimensions", "list", "(", "$", "width", ",", "$", "height", ",", "$", "type", ")", "=", "getImageSize", "(", "$", "source", ")", ";", "// Determine the target width (considering the breakpoint)", "$", "targetWidth", "=", "intval", "(", "$", "breakpoint", ")", ";", "// If the image image has to be downsampled at all", "if", "(", "$", "width", ">", "$", "targetWidth", ")", "{", "// Prepare basic target parameters", "$", "targetHeight", "=", "round", "(", "$", "targetWidth", "*", "$", "height", "/", "$", "width", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "IMAGETYPE_PNG", ":", "$", "saved", "=", "self", "::", "_downscalePng", "(", "$", "source", ",", "$", "width", ",", "$", "height", ",", "$", "target", ",", "$", "targetWidth", ",", "$", "targetHeight", ")", ";", "break", ";", "case", "IMAGETYPE_JPEG", ":", "$", "saved", "=", "self", "::", "_downscaleJpeg", "(", "$", "source", ",", "$", "width", ",", "$", "height", ",", "$", "target", ",", "$", "targetWidth", ",", "$", "targetHeight", ")", ";", "break", ";", "case", "IMAGETYPE_GIF", ":", "$", "saved", "=", "self", "::", "_downscaleGif", "(", "$", "source", ",", "$", "width", ",", "$", "height", ",", "$", "target", ",", "$", "targetWidth", ",", "$", "targetHeight", ")", ";", "break", ";", "default", ":", "$", "saved", "=", "false", ";", "}", "// If target image could be created: Send it", "if", "(", "$", "saved", "&&", "@", "file_exists", "(", "$", "target", ")", ")", "{", "$", "returnImage", "=", "$", "target", ";", "// Else: Error", "}", "else", "{", "$", "errors", "[", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "FAILED_DOWNSAMPLE_CACHE", "]", "=", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "FAILED_DOWNSAMPLE_CACHE_MSG", ";", "}", "// Else: No downsampling necessary, try to cache a copy of the original image to avoid subsequent squeeze attempts", "}", "elseif", "(", "!", "@", "symlink", "(", "$", "source", ",", "$", "target", ")", "&&", "(", "SQUEEZR_IMAGE_COPY_UNDERSIZED", "?", "!", "@", "copy", "(", "$", "source", ",", "$", "target", ")", ":", "true", ")", ")", "{", "$", "errors", "[", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "FAILED_COPY_CACHE", "]", "=", "\\", "Tollwerk", "\\", "Squeezr", "\\", "Exception", "::", "FAILED_COPY_CACHE_MSG", ";", "// Else: Return target image", "}", "else", "{", "$", "returnImage", "=", "$", "target", ";", "}", "return", "$", "returnImage", ";", "}" ]
Squeeze a particular source file @param string $source Source file @param string $target Target file @param string $breakpoint Breakpoint @param array $errors Errors @return string Result file path @link http://www.idux.com/2011/02/27/what-are-index-and-alpha-transparency/
[ "Squeeze", "a", "particular", "source", "file" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Image.php#L190-L239
229,938
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Image.php
Image._downscaleJpeg
protected static function _downscaleJpeg($source, $width, $height, $target, $targetWidth, $targetHeight) { $sourceImage = @imagecreatefromjpeg($source); $targetImage = imagecreatetruecolor($targetWidth, $targetHeight); // Enable interlacing for progressive JPEGs imageinterlace($targetImage, true); // Resize, resample and sharpen the image imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height); self::_sharpenImage($targetImage, $width, $targetWidth); // Save the target JPEG image $saved = imagejpeg($targetImage, $target, min(100, max(1, intval(SQUEEZR_IMAGE_JPEG_QUALITY)))); // Destroy the source image descriptor imagedestroy($sourceImage); // Destroy the target image descriptor imagedestroy($targetImage); return $saved; }
php
protected static function _downscaleJpeg($source, $width, $height, $target, $targetWidth, $targetHeight) { $sourceImage = @imagecreatefromjpeg($source); $targetImage = imagecreatetruecolor($targetWidth, $targetHeight); // Enable interlacing for progressive JPEGs imageinterlace($targetImage, true); // Resize, resample and sharpen the image imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height); self::_sharpenImage($targetImage, $width, $targetWidth); // Save the target JPEG image $saved = imagejpeg($targetImage, $target, min(100, max(1, intval(SQUEEZR_IMAGE_JPEG_QUALITY)))); // Destroy the source image descriptor imagedestroy($sourceImage); // Destroy the target image descriptor imagedestroy($targetImage); return $saved; }
[ "protected", "static", "function", "_downscaleJpeg", "(", "$", "source", ",", "$", "width", ",", "$", "height", ",", "$", "target", ",", "$", "targetWidth", ",", "$", "targetHeight", ")", "{", "$", "sourceImage", "=", "@", "imagecreatefromjpeg", "(", "$", "source", ")", ";", "$", "targetImage", "=", "imagecreatetruecolor", "(", "$", "targetWidth", ",", "$", "targetHeight", ")", ";", "// Enable interlacing for progressive JPEGs", "imageinterlace", "(", "$", "targetImage", ",", "true", ")", ";", "// Resize, resample and sharpen the image", "imagecopyresampled", "(", "$", "targetImage", ",", "$", "sourceImage", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "targetWidth", ",", "$", "targetHeight", ",", "$", "width", ",", "$", "height", ")", ";", "self", "::", "_sharpenImage", "(", "$", "targetImage", ",", "$", "width", ",", "$", "targetWidth", ")", ";", "// Save the target JPEG image", "$", "saved", "=", "imagejpeg", "(", "$", "targetImage", ",", "$", "target", ",", "min", "(", "100", ",", "max", "(", "1", ",", "intval", "(", "SQUEEZR_IMAGE_JPEG_QUALITY", ")", ")", ")", ")", ";", "// Destroy the source image descriptor", "imagedestroy", "(", "$", "sourceImage", ")", ";", "// Destroy the target image descriptor", "imagedestroy", "(", "$", "targetImage", ")", ";", "return", "$", "saved", ";", "}" ]
Downscale a JPEG image @param string $source Source image path @param int $width Source image width @param int $height Source image height @param string $target Target image path @param int $targetWidth Target image width @param int $targetHeight Target image height @return boolean Downscaled image has been saved
[ "Downscale", "a", "JPEG", "image" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Image.php#L371-L393
229,939
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Image.php
Image._downscaleGif
protected static function _downscaleGif($source, $width, $height, $target, $targetWidth, $targetHeight) { $sourceImage = @imagecreatefromgif($source); $targetImage = imagecreatetruecolor($targetWidth, $targetHeight); // Determine the transparent color $sourceTransparentIndex = imagecolortransparent($sourceImage); $sourceTransparentColor = ($sourceTransparentIndex >= 0) ? imagecolorsforindex($sourceImage, $sourceTransparentIndex) : null; // Allocate transparency for the target image if needed if ($sourceTransparentColor !== null) { $targetTransparentColor = imagecolorallocate($targetImage, $sourceTransparentColor['red'], $sourceTransparentColor['green'], $sourceTransparentColor['blue']); $targetTransparentIndex = imagecolortransparent($targetImage, $targetTransparentColor); imageFill($targetImage, 0, 0, $targetTransparentIndex); } // Resize & resample the image (no sharpening) imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height); // Save the target GIF image $saved = imagegif($targetImage, $target); // Destroy the source image descriptor imagedestroy($sourceImage); // Destroy the target image descriptor imagedestroy($targetImage); return $saved; }
php
protected static function _downscaleGif($source, $width, $height, $target, $targetWidth, $targetHeight) { $sourceImage = @imagecreatefromgif($source); $targetImage = imagecreatetruecolor($targetWidth, $targetHeight); // Determine the transparent color $sourceTransparentIndex = imagecolortransparent($sourceImage); $sourceTransparentColor = ($sourceTransparentIndex >= 0) ? imagecolorsforindex($sourceImage, $sourceTransparentIndex) : null; // Allocate transparency for the target image if needed if ($sourceTransparentColor !== null) { $targetTransparentColor = imagecolorallocate($targetImage, $sourceTransparentColor['red'], $sourceTransparentColor['green'], $sourceTransparentColor['blue']); $targetTransparentIndex = imagecolortransparent($targetImage, $targetTransparentColor); imageFill($targetImage, 0, 0, $targetTransparentIndex); } // Resize & resample the image (no sharpening) imagecopyresampled($targetImage, $sourceImage, 0, 0, 0, 0, $targetWidth, $targetHeight, $width, $height); // Save the target GIF image $saved = imagegif($targetImage, $target); // Destroy the source image descriptor imagedestroy($sourceImage); // Destroy the target image descriptor imagedestroy($targetImage); return $saved; }
[ "protected", "static", "function", "_downscaleGif", "(", "$", "source", ",", "$", "width", ",", "$", "height", ",", "$", "target", ",", "$", "targetWidth", ",", "$", "targetHeight", ")", "{", "$", "sourceImage", "=", "@", "imagecreatefromgif", "(", "$", "source", ")", ";", "$", "targetImage", "=", "imagecreatetruecolor", "(", "$", "targetWidth", ",", "$", "targetHeight", ")", ";", "// Determine the transparent color", "$", "sourceTransparentIndex", "=", "imagecolortransparent", "(", "$", "sourceImage", ")", ";", "$", "sourceTransparentColor", "=", "(", "$", "sourceTransparentIndex", ">=", "0", ")", "?", "imagecolorsforindex", "(", "$", "sourceImage", ",", "$", "sourceTransparentIndex", ")", ":", "null", ";", "// Allocate transparency for the target image if needed", "if", "(", "$", "sourceTransparentColor", "!==", "null", ")", "{", "$", "targetTransparentColor", "=", "imagecolorallocate", "(", "$", "targetImage", ",", "$", "sourceTransparentColor", "[", "'red'", "]", ",", "$", "sourceTransparentColor", "[", "'green'", "]", ",", "$", "sourceTransparentColor", "[", "'blue'", "]", ")", ";", "$", "targetTransparentIndex", "=", "imagecolortransparent", "(", "$", "targetImage", ",", "$", "targetTransparentColor", ")", ";", "imageFill", "(", "$", "targetImage", ",", "0", ",", "0", ",", "$", "targetTransparentIndex", ")", ";", "}", "// Resize & resample the image (no sharpening)", "imagecopyresampled", "(", "$", "targetImage", ",", "$", "sourceImage", ",", "0", ",", "0", ",", "0", ",", "0", ",", "$", "targetWidth", ",", "$", "targetHeight", ",", "$", "width", ",", "$", "height", ")", ";", "// Save the target GIF image", "$", "saved", "=", "imagegif", "(", "$", "targetImage", ",", "$", "target", ")", ";", "// Destroy the source image descriptor", "imagedestroy", "(", "$", "sourceImage", ")", ";", "// Destroy the target image descriptor", "imagedestroy", "(", "$", "targetImage", ")", ";", "return", "$", "saved", ";", "}" ]
Downscale a GIF image @param string $source Source image path @param int $width Source image width @param int $height Source image height @param string $target Target image path @param int $targetWidth Target image width @param int $targetHeight Target image height @return boolean Downscaled image has been saved
[ "Downscale", "a", "GIF", "image" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Image.php#L406-L437
229,940
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Image.php
Image._sharpenImage
protected static function _sharpenImage($image, $width, $targetWidth) { // Sharpen image if possible and requested if (!!SQUEEZR_IMAGE_SHARPEN && function_exists('imageconvolution')) { $intFinal = $targetWidth * (750.0 / $width); $intA = 52; $intB = -0.27810650887573124; $intC = .00047337278106508946; $intRes = $intA + $intB * $intFinal + $intC * $intFinal * $intFinal; $intSharpness = max(round($intRes), 0); $arrMatrix = array( array(-1, -2, -1), array(-2, $intSharpness + 12, -2), array(-1, -2, -1) ); imageconvolution($image, $arrMatrix, $intSharpness, 0); } }
php
protected static function _sharpenImage($image, $width, $targetWidth) { // Sharpen image if possible and requested if (!!SQUEEZR_IMAGE_SHARPEN && function_exists('imageconvolution')) { $intFinal = $targetWidth * (750.0 / $width); $intA = 52; $intB = -0.27810650887573124; $intC = .00047337278106508946; $intRes = $intA + $intB * $intFinal + $intC * $intFinal * $intFinal; $intSharpness = max(round($intRes), 0); $arrMatrix = array( array(-1, -2, -1), array(-2, $intSharpness + 12, -2), array(-1, -2, -1) ); imageconvolution($image, $arrMatrix, $intSharpness, 0); } }
[ "protected", "static", "function", "_sharpenImage", "(", "$", "image", ",", "$", "width", ",", "$", "targetWidth", ")", "{", "// Sharpen image if possible and requested", "if", "(", "!", "!", "SQUEEZR_IMAGE_SHARPEN", "&&", "function_exists", "(", "'imageconvolution'", ")", ")", "{", "$", "intFinal", "=", "$", "targetWidth", "*", "(", "750.0", "/", "$", "width", ")", ";", "$", "intA", "=", "52", ";", "$", "intB", "=", "-", "0.27810650887573124", ";", "$", "intC", "=", ".00047337278106508946", ";", "$", "intRes", "=", "$", "intA", "+", "$", "intB", "*", "$", "intFinal", "+", "$", "intC", "*", "$", "intFinal", "*", "$", "intFinal", ";", "$", "intSharpness", "=", "max", "(", "round", "(", "$", "intRes", ")", ",", "0", ")", ";", "$", "arrMatrix", "=", "array", "(", "array", "(", "-", "1", ",", "-", "2", ",", "-", "1", ")", ",", "array", "(", "-", "2", ",", "$", "intSharpness", "+", "12", ",", "-", "2", ")", ",", "array", "(", "-", "1", ",", "-", "2", ",", "-", "1", ")", ")", ";", "imageconvolution", "(", "$", "image", ",", "$", "arrMatrix", ",", "$", "intSharpness", ",", "0", ")", ";", "}", "}" ]
Sharpen an image @param resource $image Image resource @param int $width Original image width @param int $targetWidth Downsampled image width @return void
[ "Sharpen", "an", "image" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Image.php#L447-L465
229,941
jkphl/squeezr
squeezr/lib/Tollwerk/Squeezr/Image.php
Image._enableTranparency
protected static function _enableTranparency($image, array $transparentColor = null) { if ($transparentColor === null) { $transparentColor = array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127); } $targetTransparent = imagecolorallocatealpha($image, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue'], $transparentColor['alpha']); imagecolortransparent($image, $targetTransparent); imageFill($image, 0, 0, $targetTransparent); imagealphablending($image, false); imagesavealpha($image, true); }
php
protected static function _enableTranparency($image, array $transparentColor = null) { if ($transparentColor === null) { $transparentColor = array('red' => 0, 'green' => 0, 'blue' => 0, 'alpha' => 127); } $targetTransparent = imagecolorallocatealpha($image, $transparentColor['red'], $transparentColor['green'], $transparentColor['blue'], $transparentColor['alpha']); imagecolortransparent($image, $targetTransparent); imageFill($image, 0, 0, $targetTransparent); imagealphablending($image, false); imagesavealpha($image, true); }
[ "protected", "static", "function", "_enableTranparency", "(", "$", "image", ",", "array", "$", "transparentColor", "=", "null", ")", "{", "if", "(", "$", "transparentColor", "===", "null", ")", "{", "$", "transparentColor", "=", "array", "(", "'red'", "=>", "0", ",", "'green'", "=>", "0", ",", "'blue'", "=>", "0", ",", "'alpha'", "=>", "127", ")", ";", "}", "$", "targetTransparent", "=", "imagecolorallocatealpha", "(", "$", "image", ",", "$", "transparentColor", "[", "'red'", "]", ",", "$", "transparentColor", "[", "'green'", "]", ",", "$", "transparentColor", "[", "'blue'", "]", ",", "$", "transparentColor", "[", "'alpha'", "]", ")", ";", "imagecolortransparent", "(", "$", "image", ",", "$", "targetTransparent", ")", ";", "imageFill", "(", "$", "image", ",", "0", ",", "0", ",", "$", "targetTransparent", ")", ";", "imagealphablending", "(", "$", "image", ",", "false", ")", ";", "imagesavealpha", "(", "$", "image", ",", "true", ")", ";", "}" ]
Enable transparency on an image resource @param resource $image Image resource @param array $transparentColor Transparent color @return void
[ "Enable", "transparency", "on", "an", "image", "resource" ]
9aed77dcdca889a532a81630498fa51ad63138b7
https://github.com/jkphl/squeezr/blob/9aed77dcdca889a532a81630498fa51ad63138b7/squeezr/lib/Tollwerk/Squeezr/Image.php#L474-L485
229,942
beeyev/yandex-translate
src/Translate.php
Translate.detectLanguage
public function detectLanguage($text, $hint = null) { if (is_array($hint)) { $hint = implode(',', $hint); } $callResult = $this->makeCall( 'detect', array( 'text' => $text, 'hint' => $hint ) ); return $callResult['lang']; }
php
public function detectLanguage($text, $hint = null) { if (is_array($hint)) { $hint = implode(',', $hint); } $callResult = $this->makeCall( 'detect', array( 'text' => $text, 'hint' => $hint ) ); return $callResult['lang']; }
[ "public", "function", "detectLanguage", "(", "$", "text", ",", "$", "hint", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "hint", ")", ")", "{", "$", "hint", "=", "implode", "(", "','", ",", "$", "hint", ")", ";", "}", "$", "callResult", "=", "$", "this", "->", "makeCall", "(", "'detect'", ",", "array", "(", "'text'", "=>", "$", "text", ",", "'hint'", "=>", "$", "hint", ")", ")", ";", "return", "$", "callResult", "[", "'lang'", "]", ";", "}" ]
Detects the language of the specified text. @link https://tech.yandex.com/translate/doc/dg/reference/detect-docpage/ @param string $text The text to detect the language for. @param string $hint Optional parameter. List of the most possible languages, separator is comma. @return string
[ "Detects", "the", "language", "of", "the", "specified", "text", "." ]
4530d765de91d7c0bb53f9b43cf4ed1d170fe8cd
https://github.com/beeyev/yandex-translate/blob/4530d765de91d7c0bb53f9b43cf4ed1d170fe8cd/src/Translate.php#L119-L133
229,943
beeyev/yandex-translate
src/Translate.php
Translate.translate
public function translate($text, $language, $format = 'plain', $options = null) { /* html code autodetection i will appreciate if smb tell me a beetter way to detect html code in a string */ if ($format == 'auto') { if (is_array($text)) { $textD = implode('', $text); } else { $textD = $text; } $format = $textD == strip_tags($textD) ? 'plain' : 'html'; } $callResult = $this->makeCall( 'translate', array( 'text' => $text, 'lang' => $language, 'format' => $format, ) ); return new TranslationResponse($callResult, $text); }
php
public function translate($text, $language, $format = 'plain', $options = null) { /* html code autodetection i will appreciate if smb tell me a beetter way to detect html code in a string */ if ($format == 'auto') { if (is_array($text)) { $textD = implode('', $text); } else { $textD = $text; } $format = $textD == strip_tags($textD) ? 'plain' : 'html'; } $callResult = $this->makeCall( 'translate', array( 'text' => $text, 'lang' => $language, 'format' => $format, ) ); return new TranslationResponse($callResult, $text); }
[ "public", "function", "translate", "(", "$", "text", ",", "$", "language", ",", "$", "format", "=", "'plain'", ",", "$", "options", "=", "null", ")", "{", "/*\n html code autodetection\n i will appreciate if smb tell me a beetter way\n to detect html code in a string\n */", "if", "(", "$", "format", "==", "'auto'", ")", "{", "if", "(", "is_array", "(", "$", "text", ")", ")", "{", "$", "textD", "=", "implode", "(", "''", ",", "$", "text", ")", ";", "}", "else", "{", "$", "textD", "=", "$", "text", ";", "}", "$", "format", "=", "$", "textD", "==", "strip_tags", "(", "$", "textD", ")", "?", "'plain'", ":", "'html'", ";", "}", "$", "callResult", "=", "$", "this", "->", "makeCall", "(", "'translate'", ",", "array", "(", "'text'", "=>", "$", "text", ",", "'lang'", "=>", "$", "language", ",", "'format'", "=>", "$", "format", ",", ")", ")", ";", "return", "new", "TranslationResponse", "(", "$", "callResult", ",", "$", "text", ")", ";", "}" ]
Translates text to the specified language. @link https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/ @param string|array $text The text to translate. @param string $language The translation direction. @param "plain"|"html"|"auto" $format If input text contains html code @param int $options Read more on the website @return object
[ "Translates", "text", "to", "the", "specified", "language", "." ]
4530d765de91d7c0bb53f9b43cf4ed1d170fe8cd
https://github.com/beeyev/yandex-translate/blob/4530d765de91d7c0bb53f9b43cf4ed1d170fe8cd/src/Translate.php#L147-L172
229,944
beeyev/yandex-translate
src/Translate.php
Translate.makeCall
protected function makeCall($uri, array $requestParameters) { $requestParameters['key'] = $this->getApiKey(); $text = ''; if (isset($requestParameters['text']) && is_array($requestParameters['text'])) { $text = '&text=' . implode('&text=', $requestParameters['text']); unset($requestParameters['text']); } $requestParameters = http_build_query($requestParameters) . $text; $curlOptions = array( CURLOPT_URL => self::API_URL . $uri, CURLOPT_POSTFIELDS => $requestParameters, CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 20, CURLOPT_TIMEOUT => 60, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CUSTOMREQUEST => 'POST', ); $ch = curl_init(); curl_setopt_array($ch, $curlOptions); $callResult = curl_exec($ch); if (!$callResult) { throw new TranslateException('Error: makeCall() - cURL error: ' . curl_error($ch)); } curl_close($ch); $callResult = json_decode($callResult, true); if (isset($callResult['code']) && $callResult['code'] > 200) { throw new TranslateException('API error: ' .$callResult['message'], $callResult['code']); } return $callResult; }
php
protected function makeCall($uri, array $requestParameters) { $requestParameters['key'] = $this->getApiKey(); $text = ''; if (isset($requestParameters['text']) && is_array($requestParameters['text'])) { $text = '&text=' . implode('&text=', $requestParameters['text']); unset($requestParameters['text']); } $requestParameters = http_build_query($requestParameters) . $text; $curlOptions = array( CURLOPT_URL => self::API_URL . $uri, CURLOPT_POSTFIELDS => $requestParameters, CURLOPT_RETURNTRANSFER => true, CURLOPT_CONNECTTIMEOUT => 20, CURLOPT_TIMEOUT => 60, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_CUSTOMREQUEST => 'POST', ); $ch = curl_init(); curl_setopt_array($ch, $curlOptions); $callResult = curl_exec($ch); if (!$callResult) { throw new TranslateException('Error: makeCall() - cURL error: ' . curl_error($ch)); } curl_close($ch); $callResult = json_decode($callResult, true); if (isset($callResult['code']) && $callResult['code'] > 200) { throw new TranslateException('API error: ' .$callResult['message'], $callResult['code']); } return $callResult; }
[ "protected", "function", "makeCall", "(", "$", "uri", ",", "array", "$", "requestParameters", ")", "{", "$", "requestParameters", "[", "'key'", "]", "=", "$", "this", "->", "getApiKey", "(", ")", ";", "$", "text", "=", "''", ";", "if", "(", "isset", "(", "$", "requestParameters", "[", "'text'", "]", ")", "&&", "is_array", "(", "$", "requestParameters", "[", "'text'", "]", ")", ")", "{", "$", "text", "=", "'&text='", ".", "implode", "(", "'&text='", ",", "$", "requestParameters", "[", "'text'", "]", ")", ";", "unset", "(", "$", "requestParameters", "[", "'text'", "]", ")", ";", "}", "$", "requestParameters", "=", "http_build_query", "(", "$", "requestParameters", ")", ".", "$", "text", ";", "$", "curlOptions", "=", "array", "(", "CURLOPT_URL", "=>", "self", "::", "API_URL", ".", "$", "uri", ",", "CURLOPT_POSTFIELDS", "=>", "$", "requestParameters", ",", "CURLOPT_RETURNTRANSFER", "=>", "true", ",", "CURLOPT_CONNECTTIMEOUT", "=>", "20", ",", "CURLOPT_TIMEOUT", "=>", "60", ",", "CURLOPT_SSL_VERIFYPEER", "=>", "false", ",", "CURLOPT_CUSTOMREQUEST", "=>", "'POST'", ",", ")", ";", "$", "ch", "=", "curl_init", "(", ")", ";", "curl_setopt_array", "(", "$", "ch", ",", "$", "curlOptions", ")", ";", "$", "callResult", "=", "curl_exec", "(", "$", "ch", ")", ";", "if", "(", "!", "$", "callResult", ")", "{", "throw", "new", "TranslateException", "(", "'Error: makeCall() - cURL error: '", ".", "curl_error", "(", "$", "ch", ")", ")", ";", "}", "curl_close", "(", "$", "ch", ")", ";", "$", "callResult", "=", "json_decode", "(", "$", "callResult", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "callResult", "[", "'code'", "]", ")", "&&", "$", "callResult", "[", "'code'", "]", ">", "200", ")", "{", "throw", "new", "TranslateException", "(", "'API error: '", ".", "$", "callResult", "[", "'message'", "]", ",", "$", "callResult", "[", "'code'", "]", ")", ";", "}", "return", "$", "callResult", ";", "}" ]
Makes call to an API server @param string $uri API method @param array $requestParameters API parameters @throws TranslateException When curl error has occurred @throws TranslateException When curl error has occurred @throws TranslateException When API server returns error @return array
[ "Makes", "call", "to", "an", "API", "server" ]
4530d765de91d7c0bb53f9b43cf4ed1d170fe8cd
https://github.com/beeyev/yandex-translate/blob/4530d765de91d7c0bb53f9b43cf4ed1d170fe8cd/src/Translate.php#L186-L224
229,945
milesj/admin
Controller/CrudController.php
CrudController.index
public function index() { if ($this->overrideAction('index')) { return; } $this->paginate = array_merge(array( 'limit' => 25, 'order' => array($this->Model->alias . '.' . $this->Model->displayField => 'ASC'), 'contain' => array_keys($this->Model->belongsTo) ), $this->Model->admin['paginate']); $this->AdminToolbar->setBelongsToData($this->Model); // Filters if (!empty($this->request->params['named'])) { $this->paginate['conditions'] = $this->AdminToolbar->parseFilterConditions($this->Model, $this->request->params['named']); } // Batch delete if ($this->request->is('post')) { if (!$this->Model->admin['batchProcess']) { throw new ForbiddenException(__d('admin', 'Batch Access Protected')); } $action = $this->request->data[$this->Model->alias]['batch_action']; $items = $this->request->data[$this->Model->alias]['items']; $processed = array(); foreach ($items as $id) { if (!$id) { continue; } if ($action === 'delete_item') { if ($this->Model->delete($id, true)) { $processed[] = $id; } } else { if (call_user_func(array($this->Model, $action), $id)) { $processed[] = $id; } } } $count = count($processed); if ($count > 0) { $this->AdminToolbar->logAction(ActionLog::BATCH_DELETE, $this->Model, '', sprintf('Processed IDs: %s', implode(', ', $processed))); $this->AdminToolbar->setFlashMessage(__d('admin', '%s %s have been processed', array($count, mb_strtolower($this->Model->pluralName)))); $this->request->data[$this->Model->alias] = array(); } } $this->set('results', $this->paginate($this->Model)); $this->overrideView('index'); }
php
public function index() { if ($this->overrideAction('index')) { return; } $this->paginate = array_merge(array( 'limit' => 25, 'order' => array($this->Model->alias . '.' . $this->Model->displayField => 'ASC'), 'contain' => array_keys($this->Model->belongsTo) ), $this->Model->admin['paginate']); $this->AdminToolbar->setBelongsToData($this->Model); // Filters if (!empty($this->request->params['named'])) { $this->paginate['conditions'] = $this->AdminToolbar->parseFilterConditions($this->Model, $this->request->params['named']); } // Batch delete if ($this->request->is('post')) { if (!$this->Model->admin['batchProcess']) { throw new ForbiddenException(__d('admin', 'Batch Access Protected')); } $action = $this->request->data[$this->Model->alias]['batch_action']; $items = $this->request->data[$this->Model->alias]['items']; $processed = array(); foreach ($items as $id) { if (!$id) { continue; } if ($action === 'delete_item') { if ($this->Model->delete($id, true)) { $processed[] = $id; } } else { if (call_user_func(array($this->Model, $action), $id)) { $processed[] = $id; } } } $count = count($processed); if ($count > 0) { $this->AdminToolbar->logAction(ActionLog::BATCH_DELETE, $this->Model, '', sprintf('Processed IDs: %s', implode(', ', $processed))); $this->AdminToolbar->setFlashMessage(__d('admin', '%s %s have been processed', array($count, mb_strtolower($this->Model->pluralName)))); $this->request->data[$this->Model->alias] = array(); } } $this->set('results', $this->paginate($this->Model)); $this->overrideView('index'); }
[ "public", "function", "index", "(", ")", "{", "if", "(", "$", "this", "->", "overrideAction", "(", "'index'", ")", ")", "{", "return", ";", "}", "$", "this", "->", "paginate", "=", "array_merge", "(", "array", "(", "'limit'", "=>", "25", ",", "'order'", "=>", "array", "(", "$", "this", "->", "Model", "->", "alias", ".", "'.'", ".", "$", "this", "->", "Model", "->", "displayField", "=>", "'ASC'", ")", ",", "'contain'", "=>", "array_keys", "(", "$", "this", "->", "Model", "->", "belongsTo", ")", ")", ",", "$", "this", "->", "Model", "->", "admin", "[", "'paginate'", "]", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setBelongsToData", "(", "$", "this", "->", "Model", ")", ";", "// Filters", "if", "(", "!", "empty", "(", "$", "this", "->", "request", "->", "params", "[", "'named'", "]", ")", ")", "{", "$", "this", "->", "paginate", "[", "'conditions'", "]", "=", "$", "this", "->", "AdminToolbar", "->", "parseFilterConditions", "(", "$", "this", "->", "Model", ",", "$", "this", "->", "request", "->", "params", "[", "'named'", "]", ")", ";", "}", "// Batch delete", "if", "(", "$", "this", "->", "request", "->", "is", "(", "'post'", ")", ")", "{", "if", "(", "!", "$", "this", "->", "Model", "->", "admin", "[", "'batchProcess'", "]", ")", "{", "throw", "new", "ForbiddenException", "(", "__d", "(", "'admin'", ",", "'Batch Access Protected'", ")", ")", ";", "}", "$", "action", "=", "$", "this", "->", "request", "->", "data", "[", "$", "this", "->", "Model", "->", "alias", "]", "[", "'batch_action'", "]", ";", "$", "items", "=", "$", "this", "->", "request", "->", "data", "[", "$", "this", "->", "Model", "->", "alias", "]", "[", "'items'", "]", ";", "$", "processed", "=", "array", "(", ")", ";", "foreach", "(", "$", "items", "as", "$", "id", ")", "{", "if", "(", "!", "$", "id", ")", "{", "continue", ";", "}", "if", "(", "$", "action", "===", "'delete_item'", ")", "{", "if", "(", "$", "this", "->", "Model", "->", "delete", "(", "$", "id", ",", "true", ")", ")", "{", "$", "processed", "[", "]", "=", "$", "id", ";", "}", "}", "else", "{", "if", "(", "call_user_func", "(", "array", "(", "$", "this", "->", "Model", ",", "$", "action", ")", ",", "$", "id", ")", ")", "{", "$", "processed", "[", "]", "=", "$", "id", ";", "}", "}", "}", "$", "count", "=", "count", "(", "$", "processed", ")", ";", "if", "(", "$", "count", ">", "0", ")", "{", "$", "this", "->", "AdminToolbar", "->", "logAction", "(", "ActionLog", "::", "BATCH_DELETE", ",", "$", "this", "->", "Model", ",", "''", ",", "sprintf", "(", "'Processed IDs: %s'", ",", "implode", "(", "', '", ",", "$", "processed", ")", ")", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'%s %s have been processed'", ",", "array", "(", "$", "count", ",", "mb_strtolower", "(", "$", "this", "->", "Model", "->", "pluralName", ")", ")", ")", ")", ";", "$", "this", "->", "request", "->", "data", "[", "$", "this", "->", "Model", "->", "alias", "]", "=", "array", "(", ")", ";", "}", "}", "$", "this", "->", "set", "(", "'results'", ",", "$", "this", "->", "paginate", "(", "$", "this", "->", "Model", ")", ")", ";", "$", "this", "->", "overrideView", "(", "'index'", ")", ";", "}" ]
List out and paginate all the records in the model.
[ "List", "out", "and", "paginate", "all", "the", "records", "in", "the", "model", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L13-L69
229,946
milesj/admin
Controller/CrudController.php
CrudController.read
public function read($id) { if ($this->overrideAction('read', $id)) { return; } $this->Model->id = $id; $result = $this->AdminToolbar->getRecordById($this->Model, $id); if (!$result) { throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName)); } $this->Model->set($result); $this->AdminToolbar->logAction(ActionLog::READ, $this->Model, $id); $this->AdminToolbar->setAssociationCounts($this->Model); $this->set('result', $result); $this->overrideView('read'); }
php
public function read($id) { if ($this->overrideAction('read', $id)) { return; } $this->Model->id = $id; $result = $this->AdminToolbar->getRecordById($this->Model, $id); if (!$result) { throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName)); } $this->Model->set($result); $this->AdminToolbar->logAction(ActionLog::READ, $this->Model, $id); $this->AdminToolbar->setAssociationCounts($this->Model); $this->set('result', $result); $this->overrideView('read'); }
[ "public", "function", "read", "(", "$", "id", ")", "{", "if", "(", "$", "this", "->", "overrideAction", "(", "'read'", ",", "$", "id", ")", ")", "{", "return", ";", "}", "$", "this", "->", "Model", "->", "id", "=", "$", "id", ";", "$", "result", "=", "$", "this", "->", "AdminToolbar", "->", "getRecordById", "(", "$", "this", "->", "Model", ",", "$", "id", ")", ";", "if", "(", "!", "$", "result", ")", "{", "throw", "new", "NotFoundException", "(", "__d", "(", "'admin'", ",", "'%s Not Found'", ",", "$", "this", "->", "Model", "->", "singularName", ")", ")", ";", "}", "$", "this", "->", "Model", "->", "set", "(", "$", "result", ")", ";", "$", "this", "->", "AdminToolbar", "->", "logAction", "(", "ActionLog", "::", "READ", ",", "$", "this", "->", "Model", ",", "$", "id", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setAssociationCounts", "(", "$", "this", "->", "Model", ")", ";", "$", "this", "->", "set", "(", "'result'", ",", "$", "result", ")", ";", "$", "this", "->", "overrideView", "(", "'read'", ")", ";", "}" ]
Read a record and associated records. @param int $id @throws NotFoundException
[ "Read", "a", "record", "and", "associated", "records", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L107-L127
229,947
milesj/admin
Controller/CrudController.php
CrudController.delete
public function delete($id) { if (!$this->Model->admin['deletable']) { throw new ForbiddenException(__d('admin', 'Delete Access Protected')); } if ($this->overrideAction('delete', $id)) { return; } $this->Model->id = $id; $result = $this->AdminToolbar->getRecordById($this->Model, $id); if (!$result) { throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName)); } if ($this->request->is('post')) { if ($this->Model->delete($id, true)) { $this->AdminToolbar->logAction(ActionLog::DELETE, $this->Model, $id); $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully deleted %s with ID %s', array(mb_strtolower($this->Model->singularName), $id))); $this->AdminToolbar->redirectAfter($this->Model); } else { $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to delete %s with ID %s', array(mb_strtolower($this->Model->singularName), $id)), 'is-error'); } } $this->set('result', $result); $this->overrideView('delete'); }
php
public function delete($id) { if (!$this->Model->admin['deletable']) { throw new ForbiddenException(__d('admin', 'Delete Access Protected')); } if ($this->overrideAction('delete', $id)) { return; } $this->Model->id = $id; $result = $this->AdminToolbar->getRecordById($this->Model, $id); if (!$result) { throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName)); } if ($this->request->is('post')) { if ($this->Model->delete($id, true)) { $this->AdminToolbar->logAction(ActionLog::DELETE, $this->Model, $id); $this->AdminToolbar->setFlashMessage(__d('admin', 'Successfully deleted %s with ID %s', array(mb_strtolower($this->Model->singularName), $id))); $this->AdminToolbar->redirectAfter($this->Model); } else { $this->AdminToolbar->setFlashMessage(__d('admin', 'Failed to delete %s with ID %s', array(mb_strtolower($this->Model->singularName), $id)), 'is-error'); } } $this->set('result', $result); $this->overrideView('delete'); }
[ "public", "function", "delete", "(", "$", "id", ")", "{", "if", "(", "!", "$", "this", "->", "Model", "->", "admin", "[", "'deletable'", "]", ")", "{", "throw", "new", "ForbiddenException", "(", "__d", "(", "'admin'", ",", "'Delete Access Protected'", ")", ")", ";", "}", "if", "(", "$", "this", "->", "overrideAction", "(", "'delete'", ",", "$", "id", ")", ")", "{", "return", ";", "}", "$", "this", "->", "Model", "->", "id", "=", "$", "id", ";", "$", "result", "=", "$", "this", "->", "AdminToolbar", "->", "getRecordById", "(", "$", "this", "->", "Model", ",", "$", "id", ")", ";", "if", "(", "!", "$", "result", ")", "{", "throw", "new", "NotFoundException", "(", "__d", "(", "'admin'", ",", "'%s Not Found'", ",", "$", "this", "->", "Model", "->", "singularName", ")", ")", ";", "}", "if", "(", "$", "this", "->", "request", "->", "is", "(", "'post'", ")", ")", "{", "if", "(", "$", "this", "->", "Model", "->", "delete", "(", "$", "id", ",", "true", ")", ")", "{", "$", "this", "->", "AdminToolbar", "->", "logAction", "(", "ActionLog", "::", "DELETE", ",", "$", "this", "->", "Model", ",", "$", "id", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'Successfully deleted %s with ID %s'", ",", "array", "(", "mb_strtolower", "(", "$", "this", "->", "Model", "->", "singularName", ")", ",", "$", "id", ")", ")", ")", ";", "$", "this", "->", "AdminToolbar", "->", "redirectAfter", "(", "$", "this", "->", "Model", ")", ";", "}", "else", "{", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'Failed to delete %s with ID %s'", ",", "array", "(", "mb_strtolower", "(", "$", "this", "->", "Model", "->", "singularName", ")", ",", "$", "id", ")", ")", ",", "'is-error'", ")", ";", "}", "}", "$", "this", "->", "set", "(", "'result'", ",", "$", "result", ")", ";", "$", "this", "->", "overrideView", "(", "'delete'", ")", ";", "}" ]
Delete a record and all associated records after delete confirmation. @param int $id @throws NotFoundException @throws ForbiddenException
[ "Delete", "a", "record", "and", "all", "associated", "records", "after", "delete", "confirmation", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L184-L215
229,948
milesj/admin
Controller/CrudController.php
CrudController.type_ahead
public function type_ahead() { if ($response = $this->overrideAction('type_ahead')) { return; } $this->viewClass = 'Json'; $this->layout = 'ajax'; if (empty($this->request->query['term'])) { throw new BadRequestException(__d('admin', 'Missing Query')); } $this->set('results', $this->AdminToolbar->searchTypeAhead($this->Model, $this->request->query)); $this->set('_serialize', 'results'); }
php
public function type_ahead() { if ($response = $this->overrideAction('type_ahead')) { return; } $this->viewClass = 'Json'; $this->layout = 'ajax'; if (empty($this->request->query['term'])) { throw new BadRequestException(__d('admin', 'Missing Query')); } $this->set('results', $this->AdminToolbar->searchTypeAhead($this->Model, $this->request->query)); $this->set('_serialize', 'results'); }
[ "public", "function", "type_ahead", "(", ")", "{", "if", "(", "$", "response", "=", "$", "this", "->", "overrideAction", "(", "'type_ahead'", ")", ")", "{", "return", ";", "}", "$", "this", "->", "viewClass", "=", "'Json'", ";", "$", "this", "->", "layout", "=", "'ajax'", ";", "if", "(", "empty", "(", "$", "this", "->", "request", "->", "query", "[", "'term'", "]", ")", ")", "{", "throw", "new", "BadRequestException", "(", "__d", "(", "'admin'", ",", "'Missing Query'", ")", ")", ";", "}", "$", "this", "->", "set", "(", "'results'", ",", "$", "this", "->", "AdminToolbar", "->", "searchTypeAhead", "(", "$", "this", "->", "Model", ",", "$", "this", "->", "request", "->", "query", ")", ")", ";", "$", "this", "->", "set", "(", "'_serialize'", ",", "'results'", ")", ";", "}" ]
Query the model for a list of records that match the term. @throws BadRequestException
[ "Query", "the", "model", "for", "a", "list", "of", "records", "that", "match", "the", "term", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L222-L236
229,949
milesj/admin
Controller/CrudController.php
CrudController.process_model
public function process_model($id, $method) { $model = $this->Model; $record = $this->AdminToolbar->getRecordById($model, $id); if (!$record) { throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName)); } if ($model->hasMethod($method)) { $model->{$method}($id); $this->AdminToolbar->logAction(ActionLog::PROCESS, $model, $id, __d('admin', 'Triggered %s.%s() process', array($model->alias, $method))); $this->AdminToolbar->setFlashMessage(__d('admin', 'Processed %s.%s() for ID %s', array($model->alias, $method, $id))); } else { $this->AdminToolbar->setFlashMessage(__d('admin', '%s does not allow this process', $model->singularName), 'is-error'); } $this->redirect($this->referer()); }
php
public function process_model($id, $method) { $model = $this->Model; $record = $this->AdminToolbar->getRecordById($model, $id); if (!$record) { throw new NotFoundException(__d('admin', '%s Not Found', $this->Model->singularName)); } if ($model->hasMethod($method)) { $model->{$method}($id); $this->AdminToolbar->logAction(ActionLog::PROCESS, $model, $id, __d('admin', 'Triggered %s.%s() process', array($model->alias, $method))); $this->AdminToolbar->setFlashMessage(__d('admin', 'Processed %s.%s() for ID %s', array($model->alias, $method, $id))); } else { $this->AdminToolbar->setFlashMessage(__d('admin', '%s does not allow this process', $model->singularName), 'is-error'); } $this->redirect($this->referer()); }
[ "public", "function", "process_model", "(", "$", "id", ",", "$", "method", ")", "{", "$", "model", "=", "$", "this", "->", "Model", ";", "$", "record", "=", "$", "this", "->", "AdminToolbar", "->", "getRecordById", "(", "$", "model", ",", "$", "id", ")", ";", "if", "(", "!", "$", "record", ")", "{", "throw", "new", "NotFoundException", "(", "__d", "(", "'admin'", ",", "'%s Not Found'", ",", "$", "this", "->", "Model", "->", "singularName", ")", ")", ";", "}", "if", "(", "$", "model", "->", "hasMethod", "(", "$", "method", ")", ")", "{", "$", "model", "->", "{", "$", "method", "}", "(", "$", "id", ")", ";", "$", "this", "->", "AdminToolbar", "->", "logAction", "(", "ActionLog", "::", "PROCESS", ",", "$", "model", ",", "$", "id", ",", "__d", "(", "'admin'", ",", "'Triggered %s.%s() process'", ",", "array", "(", "$", "model", "->", "alias", ",", "$", "method", ")", ")", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'Processed %s.%s() for ID %s'", ",", "array", "(", "$", "model", "->", "alias", ",", "$", "method", ",", "$", "id", ")", ")", ")", ";", "}", "else", "{", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'%s does not allow this process'", ",", "$", "model", "->", "singularName", ")", ",", "'is-error'", ")", ";", "}", "$", "this", "->", "redirect", "(", "$", "this", "->", "referer", "(", ")", ")", ";", "}" ]
Trigger a callback method on the model. @param int $id @param string $method @throws NotFoundException
[ "Trigger", "a", "callback", "method", "on", "the", "model", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L245-L264
229,950
milesj/admin
Controller/CrudController.php
CrudController.process_behavior
public function process_behavior($behavior, $method) { $behavior = Inflector::camelize($behavior); $model = $this->Model; if ($model->Behaviors->loaded($behavior) && $model->hasMethod($method)) { $model->Behaviors->{$behavior}->{$method}($model); $this->AdminToolbar->logAction(ActionLog::PROCESS, $model, '', __d('admin', 'Triggered %s.%s() process', array($behavior, $method))); $this->AdminToolbar->setFlashMessage(__d('admin', 'Processed %s.%s() for %s', array($behavior, $method, mb_strtolower($model->pluralName)))); } else { $this->AdminToolbar->setFlashMessage(__d('admin', '%s does not allow this process', $model->singularName), 'is-error'); } $this->redirect($this->referer()); }
php
public function process_behavior($behavior, $method) { $behavior = Inflector::camelize($behavior); $model = $this->Model; if ($model->Behaviors->loaded($behavior) && $model->hasMethod($method)) { $model->Behaviors->{$behavior}->{$method}($model); $this->AdminToolbar->logAction(ActionLog::PROCESS, $model, '', __d('admin', 'Triggered %s.%s() process', array($behavior, $method))); $this->AdminToolbar->setFlashMessage(__d('admin', 'Processed %s.%s() for %s', array($behavior, $method, mb_strtolower($model->pluralName)))); } else { $this->AdminToolbar->setFlashMessage(__d('admin', '%s does not allow this process', $model->singularName), 'is-error'); } $this->redirect($this->referer()); }
[ "public", "function", "process_behavior", "(", "$", "behavior", ",", "$", "method", ")", "{", "$", "behavior", "=", "Inflector", "::", "camelize", "(", "$", "behavior", ")", ";", "$", "model", "=", "$", "this", "->", "Model", ";", "if", "(", "$", "model", "->", "Behaviors", "->", "loaded", "(", "$", "behavior", ")", "&&", "$", "model", "->", "hasMethod", "(", "$", "method", ")", ")", "{", "$", "model", "->", "Behaviors", "->", "{", "$", "behavior", "}", "->", "{", "$", "method", "}", "(", "$", "model", ")", ";", "$", "this", "->", "AdminToolbar", "->", "logAction", "(", "ActionLog", "::", "PROCESS", ",", "$", "model", ",", "''", ",", "__d", "(", "'admin'", ",", "'Triggered %s.%s() process'", ",", "array", "(", "$", "behavior", ",", "$", "method", ")", ")", ")", ";", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'Processed %s.%s() for %s'", ",", "array", "(", "$", "behavior", ",", "$", "method", ",", "mb_strtolower", "(", "$", "model", "->", "pluralName", ")", ")", ")", ")", ";", "}", "else", "{", "$", "this", "->", "AdminToolbar", "->", "setFlashMessage", "(", "__d", "(", "'admin'", ",", "'%s does not allow this process'", ",", "$", "model", "->", "singularName", ")", ",", "'is-error'", ")", ";", "}", "$", "this", "->", "redirect", "(", "$", "this", "->", "referer", "(", ")", ")", ";", "}" ]
Trigger a callback method on the behavior. @param string $behavior @param string $method
[ "Trigger", "a", "callback", "method", "on", "the", "behavior", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L272-L287
229,951
milesj/admin
Controller/CrudController.php
CrudController.overrideAction
protected function overrideAction($action, $id = null) { $overrides = Configure::read('Admin.actionOverrides'); $model = $this->Model->qualifiedName; if (empty($overrides[$model][$action])) { return false; } $url = (array) $overrides[$model][$action]; $url[] = $id; $response = $this->requestAction($url, array( 'autoRender' => true, 'bare' => false, 'return' => true, 'override' => true, 'data' => $this->request->data )); $this->autoRender = false; $this->response->body($response); return true; }
php
protected function overrideAction($action, $id = null) { $overrides = Configure::read('Admin.actionOverrides'); $model = $this->Model->qualifiedName; if (empty($overrides[$model][$action])) { return false; } $url = (array) $overrides[$model][$action]; $url[] = $id; $response = $this->requestAction($url, array( 'autoRender' => true, 'bare' => false, 'return' => true, 'override' => true, 'data' => $this->request->data )); $this->autoRender = false; $this->response->body($response); return true; }
[ "protected", "function", "overrideAction", "(", "$", "action", ",", "$", "id", "=", "null", ")", "{", "$", "overrides", "=", "Configure", "::", "read", "(", "'Admin.actionOverrides'", ")", ";", "$", "model", "=", "$", "this", "->", "Model", "->", "qualifiedName", ";", "if", "(", "empty", "(", "$", "overrides", "[", "$", "model", "]", "[", "$", "action", "]", ")", ")", "{", "return", "false", ";", "}", "$", "url", "=", "(", "array", ")", "$", "overrides", "[", "$", "model", "]", "[", "$", "action", "]", ";", "$", "url", "[", "]", "=", "$", "id", ";", "$", "response", "=", "$", "this", "->", "requestAction", "(", "$", "url", ",", "array", "(", "'autoRender'", "=>", "true", ",", "'bare'", "=>", "false", ",", "'return'", "=>", "true", ",", "'override'", "=>", "true", ",", "'data'", "=>", "$", "this", "->", "request", "->", "data", ")", ")", ";", "$", "this", "->", "autoRender", "=", "false", ";", "$", "this", "->", "response", "->", "body", "(", "$", "response", ")", ";", "return", "true", ";", "}" ]
Override a CRUD action with an external Controller's action. Request the custom action and set its response. @param string $action @param int $id @return bool
[ "Override", "a", "CRUD", "action", "with", "an", "external", "Controller", "s", "action", ".", "Request", "the", "custom", "action", "and", "set", "its", "response", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L369-L392
229,952
milesj/admin
Controller/CrudController.php
CrudController.overrideView
protected function overrideView($action) { $overrides = Configure::read('Admin.viewOverrides'); $model = $this->Model->qualifiedName; $view = in_array($action, array('create', 'update')) ? 'form' : $action; if (empty($overrides[$model][$action])) { $this->render($view); return; } $override = $overrides[$model][$action] + array( 'action' => $view, 'controller' => $this->name, 'plugin' => null ); // View settings $this->view = $override['action']; $this->viewPath = Inflector::camelize($override['controller']); $this->plugin = Inflector::camelize($override['plugin']); // Override $this->request->params['override'] = true; $this->render(); }
php
protected function overrideView($action) { $overrides = Configure::read('Admin.viewOverrides'); $model = $this->Model->qualifiedName; $view = in_array($action, array('create', 'update')) ? 'form' : $action; if (empty($overrides[$model][$action])) { $this->render($view); return; } $override = $overrides[$model][$action] + array( 'action' => $view, 'controller' => $this->name, 'plugin' => null ); // View settings $this->view = $override['action']; $this->viewPath = Inflector::camelize($override['controller']); $this->plugin = Inflector::camelize($override['plugin']); // Override $this->request->params['override'] = true; $this->render(); }
[ "protected", "function", "overrideView", "(", "$", "action", ")", "{", "$", "overrides", "=", "Configure", "::", "read", "(", "'Admin.viewOverrides'", ")", ";", "$", "model", "=", "$", "this", "->", "Model", "->", "qualifiedName", ";", "$", "view", "=", "in_array", "(", "$", "action", ",", "array", "(", "'create'", ",", "'update'", ")", ")", "?", "'form'", ":", "$", "action", ";", "if", "(", "empty", "(", "$", "overrides", "[", "$", "model", "]", "[", "$", "action", "]", ")", ")", "{", "$", "this", "->", "render", "(", "$", "view", ")", ";", "return", ";", "}", "$", "override", "=", "$", "overrides", "[", "$", "model", "]", "[", "$", "action", "]", "+", "array", "(", "'action'", "=>", "$", "view", ",", "'controller'", "=>", "$", "this", "->", "name", ",", "'plugin'", "=>", "null", ")", ";", "// View settings", "$", "this", "->", "view", "=", "$", "override", "[", "'action'", "]", ";", "$", "this", "->", "viewPath", "=", "Inflector", "::", "camelize", "(", "$", "override", "[", "'controller'", "]", ")", ";", "$", "this", "->", "plugin", "=", "Inflector", "::", "camelize", "(", "$", "override", "[", "'plugin'", "]", ")", ";", "// Override", "$", "this", "->", "request", "->", "params", "[", "'override'", "]", "=", "true", ";", "$", "this", "->", "render", "(", ")", ";", "}" ]
Override a CRUD view with an external view template. @param string $action @return bool
[ "Override", "a", "CRUD", "view", "with", "an", "external", "view", "template", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Controller/CrudController.php#L400-L425
229,953
addiks/phpsql
src/Addiks/PHPSQL/Value/Value.php
Value.factory
public static function factory($value) { if ($value instanceof self) { $value = $value->getValue(); } $value = static::filter($value); if (!is_scalar($value)) { throw new ErrorException("A value object must be created from a scalar value!"); } $classname = get_called_class(); if (!isset(self::$instances[$classname])) { self::$instances[$classname] = array(); } // lazy load the value-object if (!isset(self::$instances[$classname][$value])) { if (func_num_args()>1) { // construct value-object with more then the pure scalar value // (not really correct in terms of value-objects, but sometimes needed) $arguments = func_get_args(); $reflection = new \ReflectionClass($classname); self::$instances[$classname][$value] = $reflection->newInstanceArgs($arguments); } else { self::$instances[$classname][$value] = new static($value); } } return self::$instances[$classname][$value]; }
php
public static function factory($value) { if ($value instanceof self) { $value = $value->getValue(); } $value = static::filter($value); if (!is_scalar($value)) { throw new ErrorException("A value object must be created from a scalar value!"); } $classname = get_called_class(); if (!isset(self::$instances[$classname])) { self::$instances[$classname] = array(); } // lazy load the value-object if (!isset(self::$instances[$classname][$value])) { if (func_num_args()>1) { // construct value-object with more then the pure scalar value // (not really correct in terms of value-objects, but sometimes needed) $arguments = func_get_args(); $reflection = new \ReflectionClass($classname); self::$instances[$classname][$value] = $reflection->newInstanceArgs($arguments); } else { self::$instances[$classname][$value] = new static($value); } } return self::$instances[$classname][$value]; }
[ "public", "static", "function", "factory", "(", "$", "value", ")", "{", "if", "(", "$", "value", "instanceof", "self", ")", "{", "$", "value", "=", "$", "value", "->", "getValue", "(", ")", ";", "}", "$", "value", "=", "static", "::", "filter", "(", "$", "value", ")", ";", "if", "(", "!", "is_scalar", "(", "$", "value", ")", ")", "{", "throw", "new", "ErrorException", "(", "\"A value object must be created from a scalar value!\"", ")", ";", "}", "$", "classname", "=", "get_called_class", "(", ")", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "classname", "]", ")", ")", "{", "self", "::", "$", "instances", "[", "$", "classname", "]", "=", "array", "(", ")", ";", "}", "// lazy load the value-object", "if", "(", "!", "isset", "(", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "value", "]", ")", ")", "{", "if", "(", "func_num_args", "(", ")", ">", "1", ")", "{", "// construct value-object with more then the pure scalar value", "// (not really correct in terms of value-objects, but sometimes needed)", "$", "arguments", "=", "func_get_args", "(", ")", ";", "$", "reflection", "=", "new", "\\", "ReflectionClass", "(", "$", "classname", ")", ";", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "value", "]", "=", "$", "reflection", "->", "newInstanceArgs", "(", "$", "arguments", ")", ";", "}", "else", "{", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "value", "]", "=", "new", "static", "(", "$", "value", ")", ";", "}", "}", "return", "self", "::", "$", "instances", "[", "$", "classname", "]", "[", "$", "value", "]", ";", "}" ]
Creates a new value object. If the value is invalid, an invalid-argument-exception is thrown. @see self::validate() @param scalar $value @throws InvalidArgumentException
[ "Creates", "a", "new", "value", "object", "." ]
28dae64ffc2123f39f801a50ab53bfe29890cbd9
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Value/Value.php#L68-L102
229,954
geosocio/http-serializer
src/Loader/GroupLoader.php
GroupLoader.getGroups
protected function getGroups(array $annotations) :? array { if (empty($annotations)) { return []; } return array_values(array_unique(array_reduce($annotations, function ($carry, $annotation) { return array_merge($carry, $annotation->getGroups()); }, []))); }
php
protected function getGroups(array $annotations) :? array { if (empty($annotations)) { return []; } return array_values(array_unique(array_reduce($annotations, function ($carry, $annotation) { return array_merge($carry, $annotation->getGroups()); }, []))); }
[ "protected", "function", "getGroups", "(", "array", "$", "annotations", ")", ":", "?", "array", "{", "if", "(", "empty", "(", "$", "annotations", ")", ")", "{", "return", "[", "]", ";", "}", "return", "array_values", "(", "array_unique", "(", "array_reduce", "(", "$", "annotations", ",", "function", "(", "$", "carry", ",", "$", "annotation", ")", "{", "return", "array_merge", "(", "$", "carry", ",", "$", "annotation", "->", "getGroups", "(", ")", ")", ";", "}", ",", "[", "]", ")", ")", ")", ";", "}" ]
Gets the groups from annotations. @param array $annotations @return array|null
[ "Gets", "the", "groups", "from", "annotations", "." ]
aa7f9c6b2e39d147d3e53ee13e0cafce11f5fc42
https://github.com/geosocio/http-serializer/blob/aa7f9c6b2e39d147d3e53ee13e0cafce11f5fc42/src/Loader/GroupLoader.php#L45-L54
229,955
geosocio/http-serializer
src/Loader/GroupLoader.php
GroupLoader.getAnnotations
protected function getAnnotations(Request $request) : array { $controller = $this->resolver->getController($request); if (!$controller) { return []; } [$class, $name] = $controller; return $this->reader->getMethodAnnotations(new \ReflectionMethod($class, $name)); }
php
protected function getAnnotations(Request $request) : array { $controller = $this->resolver->getController($request); if (!$controller) { return []; } [$class, $name] = $controller; return $this->reader->getMethodAnnotations(new \ReflectionMethod($class, $name)); }
[ "protected", "function", "getAnnotations", "(", "Request", "$", "request", ")", ":", "array", "{", "$", "controller", "=", "$", "this", "->", "resolver", "->", "getController", "(", "$", "request", ")", ";", "if", "(", "!", "$", "controller", ")", "{", "return", "[", "]", ";", "}", "[", "$", "class", ",", "$", "name", "]", "=", "$", "controller", ";", "return", "$", "this", "->", "reader", "->", "getMethodAnnotations", "(", "new", "\\", "ReflectionMethod", "(", "$", "class", ",", "$", "name", ")", ")", ";", "}" ]
Gets the group annotations from the request @param Request $request @return array|null
[ "Gets", "the", "group", "annotations", "from", "the", "request" ]
aa7f9c6b2e39d147d3e53ee13e0cafce11f5fc42
https://github.com/geosocio/http-serializer/blob/aa7f9c6b2e39d147d3e53ee13e0cafce11f5fc42/src/Loader/GroupLoader.php#L63-L73
229,956
stefanzweifel/ScreeenlyClient
src/Wnx/ScreeenlyClient/Screenshot.php
Screenshot.capture
public function capture($url) { $this->setUrl($url); $client = new Client(); $response = $client->post($this->apiUrl, ['form_params' => [ 'key' => $this->key, 'url' => $url, 'width' => $this->width, 'height' => $this->height ] ]); $responseJson = $response->getBody(); $responseArray = json_decode($responseJson); $this->response = $responseArray; return $this; }
php
public function capture($url) { $this->setUrl($url); $client = new Client(); $response = $client->post($this->apiUrl, ['form_params' => [ 'key' => $this->key, 'url' => $url, 'width' => $this->width, 'height' => $this->height ] ]); $responseJson = $response->getBody(); $responseArray = json_decode($responseJson); $this->response = $responseArray; return $this; }
[ "public", "function", "capture", "(", "$", "url", ")", "{", "$", "this", "->", "setUrl", "(", "$", "url", ")", ";", "$", "client", "=", "new", "Client", "(", ")", ";", "$", "response", "=", "$", "client", "->", "post", "(", "$", "this", "->", "apiUrl", ",", "[", "'form_params'", "=>", "[", "'key'", "=>", "$", "this", "->", "key", ",", "'url'", "=>", "$", "url", ",", "'width'", "=>", "$", "this", "->", "width", ",", "'height'", "=>", "$", "this", "->", "height", "]", "]", ")", ";", "$", "responseJson", "=", "$", "response", "->", "getBody", "(", ")", ";", "$", "responseArray", "=", "json_decode", "(", "$", "responseJson", ")", ";", "$", "this", "->", "response", "=", "$", "responseArray", ";", "return", "$", "this", ";", "}" ]
Do API Request and store response @param string $url @return object
[ "Do", "API", "Request", "and", "store", "response" ]
854600b75da0eaa283f6f89407c8f3bcd8f80e21
https://github.com/stefanzweifel/ScreeenlyClient/blob/854600b75da0eaa283f6f89407c8f3bcd8f80e21/src/Wnx/ScreeenlyClient/Screenshot.php#L68-L88
229,957
stefanzweifel/ScreeenlyClient
src/Wnx/ScreeenlyClient/Screenshot.php
Screenshot.store
public function store($storagePath = '', $filename = '') { $path = $this->getPath(); $pathinfo = pathinfo($path); $data = file_get_contents($path); // Use Original Filename if no specific filename is set if (empty($filename)) { $filename = $pathinfo['filename'] . '.jpg'; } file_put_contents($storagePath . $filename, $data); $this->setLocalStoragePath($storagePath); $this->setLocalFilename($filename); return $storagePath . $filename; }
php
public function store($storagePath = '', $filename = '') { $path = $this->getPath(); $pathinfo = pathinfo($path); $data = file_get_contents($path); // Use Original Filename if no specific filename is set if (empty($filename)) { $filename = $pathinfo['filename'] . '.jpg'; } file_put_contents($storagePath . $filename, $data); $this->setLocalStoragePath($storagePath); $this->setLocalFilename($filename); return $storagePath . $filename; }
[ "public", "function", "store", "(", "$", "storagePath", "=", "''", ",", "$", "filename", "=", "''", ")", "{", "$", "path", "=", "$", "this", "->", "getPath", "(", ")", ";", "$", "pathinfo", "=", "pathinfo", "(", "$", "path", ")", ";", "$", "data", "=", "file_get_contents", "(", "$", "path", ")", ";", "// Use Original Filename if no specific filename is set", "if", "(", "empty", "(", "$", "filename", ")", ")", "{", "$", "filename", "=", "$", "pathinfo", "[", "'filename'", "]", ".", "'.jpg'", ";", "}", "file_put_contents", "(", "$", "storagePath", ".", "$", "filename", ",", "$", "data", ")", ";", "$", "this", "->", "setLocalStoragePath", "(", "$", "storagePath", ")", ";", "$", "this", "->", "setLocalFilename", "(", "$", "filename", ")", ";", "return", "$", "storagePath", ".", "$", "filename", ";", "}" ]
Store Screenshot no disk @param string $storagePath @param string $filename @return string Local Storage Path
[ "Store", "Screenshot", "no", "disk" ]
854600b75da0eaa283f6f89407c8f3bcd8f80e21
https://github.com/stefanzweifel/ScreeenlyClient/blob/854600b75da0eaa283f6f89407c8f3bcd8f80e21/src/Wnx/ScreeenlyClient/Screenshot.php#L96-L113
229,958
milesj/admin
Model/ItemReport.php
ItemReport.markAs
public function markAs($id, $status, $user_id, $comment = null) { $this->id = $id; return $this->save(array( 'status' => $status, 'resolver_id' => $user_id, 'comment' => $comment )); }
php
public function markAs($id, $status, $user_id, $comment = null) { $this->id = $id; return $this->save(array( 'status' => $status, 'resolver_id' => $user_id, 'comment' => $comment )); }
[ "public", "function", "markAs", "(", "$", "id", ",", "$", "status", ",", "$", "user_id", ",", "$", "comment", "=", "null", ")", "{", "$", "this", "->", "id", "=", "$", "id", ";", "return", "$", "this", "->", "save", "(", "array", "(", "'status'", "=>", "$", "status", ",", "'resolver_id'", "=>", "$", "user_id", ",", "'comment'", "=>", "$", "comment", ")", ")", ";", "}" ]
Mark a report as resolved or invalid. @param int $id @param int $status @param int $user_id @param string $comment @return bool
[ "Mark", "a", "report", "as", "resolved", "or", "invalid", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/ItemReport.php#L101-L109
229,959
milesj/admin
Model/ItemReport.php
ItemReport.reportItem
public function reportItem($query) { $conditions = $query; $conditions['created >='] = date('Y-m-d H:i:s', strtotime('-7 days')); unset($conditions['type'], $conditions['item'], $conditions['reason'], $conditions['comment']); $count = $this->find('count', array( 'conditions' => $conditions )); if ($count) { return true; } $this->create(); return $this->save($query, false); }
php
public function reportItem($query) { $conditions = $query; $conditions['created >='] = date('Y-m-d H:i:s', strtotime('-7 days')); unset($conditions['type'], $conditions['item'], $conditions['reason'], $conditions['comment']); $count = $this->find('count', array( 'conditions' => $conditions )); if ($count) { return true; } $this->create(); return $this->save($query, false); }
[ "public", "function", "reportItem", "(", "$", "query", ")", "{", "$", "conditions", "=", "$", "query", ";", "$", "conditions", "[", "'created >='", "]", "=", "date", "(", "'Y-m-d H:i:s'", ",", "strtotime", "(", "'-7 days'", ")", ")", ";", "unset", "(", "$", "conditions", "[", "'type'", "]", ",", "$", "conditions", "[", "'item'", "]", ",", "$", "conditions", "[", "'reason'", "]", ",", "$", "conditions", "[", "'comment'", "]", ")", ";", "$", "count", "=", "$", "this", "->", "find", "(", "'count'", ",", "array", "(", "'conditions'", "=>", "$", "conditions", ")", ")", ";", "if", "(", "$", "count", ")", "{", "return", "true", ";", "}", "$", "this", "->", "create", "(", ")", ";", "return", "$", "this", "->", "save", "(", "$", "query", ",", "false", ")", ";", "}" ]
Log a unique report only once every 7 days. @param array $query @return bool
[ "Log", "a", "unique", "report", "only", "once", "every", "7", "days", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/ItemReport.php#L117-L134
229,960
milesj/admin
Model/ItemReport.php
ItemReport.beforeSave
public function beforeSave($options = array()) { if (isset($this->data[$this->alias]['model'])) { list($plugin, $model) = Admin::parseName($this->data[$this->alias]['model']); if ($plugin === Configure::read('Admin.coreName')) { $this->data[$this->alias]['model'] = $model; } } return true; }
php
public function beforeSave($options = array()) { if (isset($this->data[$this->alias]['model'])) { list($plugin, $model) = Admin::parseName($this->data[$this->alias]['model']); if ($plugin === Configure::read('Admin.coreName')) { $this->data[$this->alias]['model'] = $model; } } return true; }
[ "public", "function", "beforeSave", "(", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "this", "->", "alias", "]", "[", "'model'", "]", ")", ")", "{", "list", "(", "$", "plugin", ",", "$", "model", ")", "=", "Admin", "::", "parseName", "(", "$", "this", "->", "data", "[", "$", "this", "->", "alias", "]", "[", "'model'", "]", ")", ";", "if", "(", "$", "plugin", "===", "Configure", "::", "read", "(", "'Admin.coreName'", ")", ")", "{", "$", "this", "->", "data", "[", "$", "this", "->", "alias", "]", "[", "'model'", "]", "=", "$", "model", ";", "}", "}", "return", "true", ";", "}" ]
Remove core plugin from models. @param array $options @return bool
[ "Remove", "core", "plugin", "from", "models", "." ]
e5e93823d1eb4415f05a3191f653eb50c296d2c6
https://github.com/milesj/admin/blob/e5e93823d1eb4415f05a3191f653eb50c296d2c6/Model/ItemReport.php#L142-L152
229,961
khepin/KhepinYamlFixturesBundle
Loader/YamlLoader.php
YamlLoader.loadFixtureFiles
protected function loadFixtureFiles() { foreach ($this->bundles as $bundle) { $file = '*'; if (strpos($bundle, '/')) { list($bundle, $file) = explode('/', $bundle); } $path = $this->kernel->locateResource('@' . $bundle); $files = glob($path . $this->directory . '/'.$file.'.yml'); $this->fixture_files = array_unique(array_merge($this->fixture_files, $files)); } }
php
protected function loadFixtureFiles() { foreach ($this->bundles as $bundle) { $file = '*'; if (strpos($bundle, '/')) { list($bundle, $file) = explode('/', $bundle); } $path = $this->kernel->locateResource('@' . $bundle); $files = glob($path . $this->directory . '/'.$file.'.yml'); $this->fixture_files = array_unique(array_merge($this->fixture_files, $files)); } }
[ "protected", "function", "loadFixtureFiles", "(", ")", "{", "foreach", "(", "$", "this", "->", "bundles", "as", "$", "bundle", ")", "{", "$", "file", "=", "'*'", ";", "if", "(", "strpos", "(", "$", "bundle", ",", "'/'", ")", ")", "{", "list", "(", "$", "bundle", ",", "$", "file", ")", "=", "explode", "(", "'/'", ",", "$", "bundle", ")", ";", "}", "$", "path", "=", "$", "this", "->", "kernel", "->", "locateResource", "(", "'@'", ".", "$", "bundle", ")", ";", "$", "files", "=", "glob", "(", "$", "path", ".", "$", "this", "->", "directory", ".", "'/'", ".", "$", "file", ".", "'.yml'", ")", ";", "$", "this", "->", "fixture_files", "=", "array_unique", "(", "array_merge", "(", "$", "this", "->", "fixture_files", ",", "$", "files", ")", ")", ";", "}", "}" ]
Gets all fixtures files
[ "Gets", "all", "fixtures", "files" ]
4f1947b03809421057e7b8a3553ccaa93423d192
https://github.com/khepin/KhepinYamlFixturesBundle/blob/4f1947b03809421057e7b8a3553ccaa93423d192/Loader/YamlLoader.php#L87-L98
229,962
khepin/KhepinYamlFixturesBundle
Loader/YamlLoader.php
YamlLoader.loadFixtures
public function loadFixtures() { $this->loadFixtureFiles(); foreach ($this->fixture_files as $file) { $fixture_data = Yaml::parse(file_get_contents($file)); // if nothing is specified, we use doctrine orm for persistence $persistence = isset($fixture_data['persistence']) ? $fixture_data['persistence'] : 'orm'; $persister = $this->getPersister($persistence); $manager = $persister->getManagerForClass($fixture_data['model']); $fixture = $this->getFixtureClass($persistence); $fixture = new $fixture($fixture_data, $this, $file); $fixture->load($manager, func_get_args()); } if (!is_null($this->acl_manager)) { foreach ($this->fixture_files as $file) { $fixture = new YamlAclFixture($file, $this); $fixture->load($this->acl_manager, func_get_args()); } } }
php
public function loadFixtures() { $this->loadFixtureFiles(); foreach ($this->fixture_files as $file) { $fixture_data = Yaml::parse(file_get_contents($file)); // if nothing is specified, we use doctrine orm for persistence $persistence = isset($fixture_data['persistence']) ? $fixture_data['persistence'] : 'orm'; $persister = $this->getPersister($persistence); $manager = $persister->getManagerForClass($fixture_data['model']); $fixture = $this->getFixtureClass($persistence); $fixture = new $fixture($fixture_data, $this, $file); $fixture->load($manager, func_get_args()); } if (!is_null($this->acl_manager)) { foreach ($this->fixture_files as $file) { $fixture = new YamlAclFixture($file, $this); $fixture->load($this->acl_manager, func_get_args()); } } }
[ "public", "function", "loadFixtures", "(", ")", "{", "$", "this", "->", "loadFixtureFiles", "(", ")", ";", "foreach", "(", "$", "this", "->", "fixture_files", "as", "$", "file", ")", "{", "$", "fixture_data", "=", "Yaml", "::", "parse", "(", "file_get_contents", "(", "$", "file", ")", ")", ";", "// if nothing is specified, we use doctrine orm for persistence", "$", "persistence", "=", "isset", "(", "$", "fixture_data", "[", "'persistence'", "]", ")", "?", "$", "fixture_data", "[", "'persistence'", "]", ":", "'orm'", ";", "$", "persister", "=", "$", "this", "->", "getPersister", "(", "$", "persistence", ")", ";", "$", "manager", "=", "$", "persister", "->", "getManagerForClass", "(", "$", "fixture_data", "[", "'model'", "]", ")", ";", "$", "fixture", "=", "$", "this", "->", "getFixtureClass", "(", "$", "persistence", ")", ";", "$", "fixture", "=", "new", "$", "fixture", "(", "$", "fixture_data", ",", "$", "this", ",", "$", "file", ")", ";", "$", "fixture", "->", "load", "(", "$", "manager", ",", "func_get_args", "(", ")", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "this", "->", "acl_manager", ")", ")", "{", "foreach", "(", "$", "this", "->", "fixture_files", "as", "$", "file", ")", "{", "$", "fixture", "=", "new", "YamlAclFixture", "(", "$", "file", ",", "$", "this", ")", ";", "$", "fixture", "->", "load", "(", "$", "this", "->", "acl_manager", ",", "func_get_args", "(", ")", ")", ";", "}", "}", "}" ]
Loads the fixtures file by file and saves them to the database
[ "Loads", "the", "fixtures", "file", "by", "file", "and", "saves", "them", "to", "the", "database" ]
4f1947b03809421057e7b8a3553ccaa93423d192
https://github.com/khepin/KhepinYamlFixturesBundle/blob/4f1947b03809421057e7b8a3553ccaa93423d192/Loader/YamlLoader.php#L103-L125
229,963
khepin/KhepinYamlFixturesBundle
Loader/YamlLoader.php
YamlLoader.purgeDatabase
public function purgeDatabase($persistence, $databaseName = null, $withTruncate = false) { $purgetools = array( 'orm' => array( 'purger' => 'Doctrine\Common\DataFixtures\Purger\ORMPurger', 'executor' => 'Doctrine\Common\DataFixtures\Executor\ORMExecutor', ), 'mongodb' => array( 'purger' => 'Doctrine\Common\DataFixtures\Purger\MongoDBPurger', 'executor' => 'Doctrine\Common\DataFixtures\Executor\MongoDBExecutor', ) ); // Retrieve the correct purger and executor $purge_class = $purgetools[$persistence]['purger']; $executor_class = $purgetools[$persistence]['executor']; // Instanciate purger and executor $persister = $this->getPersister($persistence); $entityManagers = ($databaseName) ? array($persister->getManager($databaseName)) : $persister->getManagers(); foreach ($entityManagers as $entityManager) { $purger = new $purge_class($entityManager); if ($withTruncate && $purger instanceof ORMPurger) { $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE); } $executor = new $executor_class($entityManager, $purger); // purge $executor->purge(); } }
php
public function purgeDatabase($persistence, $databaseName = null, $withTruncate = false) { $purgetools = array( 'orm' => array( 'purger' => 'Doctrine\Common\DataFixtures\Purger\ORMPurger', 'executor' => 'Doctrine\Common\DataFixtures\Executor\ORMExecutor', ), 'mongodb' => array( 'purger' => 'Doctrine\Common\DataFixtures\Purger\MongoDBPurger', 'executor' => 'Doctrine\Common\DataFixtures\Executor\MongoDBExecutor', ) ); // Retrieve the correct purger and executor $purge_class = $purgetools[$persistence]['purger']; $executor_class = $purgetools[$persistence]['executor']; // Instanciate purger and executor $persister = $this->getPersister($persistence); $entityManagers = ($databaseName) ? array($persister->getManager($databaseName)) : $persister->getManagers(); foreach ($entityManagers as $entityManager) { $purger = new $purge_class($entityManager); if ($withTruncate && $purger instanceof ORMPurger) { $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE); } $executor = new $executor_class($entityManager, $purger); // purge $executor->purge(); } }
[ "public", "function", "purgeDatabase", "(", "$", "persistence", ",", "$", "databaseName", "=", "null", ",", "$", "withTruncate", "=", "false", ")", "{", "$", "purgetools", "=", "array", "(", "'orm'", "=>", "array", "(", "'purger'", "=>", "'Doctrine\\Common\\DataFixtures\\Purger\\ORMPurger'", ",", "'executor'", "=>", "'Doctrine\\Common\\DataFixtures\\Executor\\ORMExecutor'", ",", ")", ",", "'mongodb'", "=>", "array", "(", "'purger'", "=>", "'Doctrine\\Common\\DataFixtures\\Purger\\MongoDBPurger'", ",", "'executor'", "=>", "'Doctrine\\Common\\DataFixtures\\Executor\\MongoDBExecutor'", ",", ")", ")", ";", "// Retrieve the correct purger and executor", "$", "purge_class", "=", "$", "purgetools", "[", "$", "persistence", "]", "[", "'purger'", "]", ";", "$", "executor_class", "=", "$", "purgetools", "[", "$", "persistence", "]", "[", "'executor'", "]", ";", "// Instanciate purger and executor", "$", "persister", "=", "$", "this", "->", "getPersister", "(", "$", "persistence", ")", ";", "$", "entityManagers", "=", "(", "$", "databaseName", ")", "?", "array", "(", "$", "persister", "->", "getManager", "(", "$", "databaseName", ")", ")", ":", "$", "persister", "->", "getManagers", "(", ")", ";", "foreach", "(", "$", "entityManagers", "as", "$", "entityManager", ")", "{", "$", "purger", "=", "new", "$", "purge_class", "(", "$", "entityManager", ")", ";", "if", "(", "$", "withTruncate", "&&", "$", "purger", "instanceof", "ORMPurger", ")", "{", "$", "purger", "->", "setPurgeMode", "(", "ORMPurger", "::", "PURGE_MODE_TRUNCATE", ")", ";", "}", "$", "executor", "=", "new", "$", "executor_class", "(", "$", "entityManager", ",", "$", "purger", ")", ";", "// purge", "$", "executor", "->", "purge", "(", ")", ";", "}", "}" ]
Remove all fixtures from the database
[ "Remove", "all", "fixtures", "from", "the", "database" ]
4f1947b03809421057e7b8a3553ccaa93423d192
https://github.com/khepin/KhepinYamlFixturesBundle/blob/4f1947b03809421057e7b8a3553ccaa93423d192/Loader/YamlLoader.php#L130-L161
229,964
Webiny/Framework
src/Webiny/Component/OAuth2/AbstractServer.php
AbstractServer.getUserDetails
public function getUserDetails() { $requestData = $this->getUserDetailsTargetData(); $result = $this->rawRequest($requestData['url'], $requestData['params']); return $this->processUserDetails($result); }
php
public function getUserDetails() { $requestData = $this->getUserDetailsTargetData(); $result = $this->rawRequest($requestData['url'], $requestData['params']); return $this->processUserDetails($result); }
[ "public", "function", "getUserDetails", "(", ")", "{", "$", "requestData", "=", "$", "this", "->", "getUserDetailsTargetData", "(", ")", ";", "$", "result", "=", "$", "this", "->", "rawRequest", "(", "$", "requestData", "[", "'url'", "]", ",", "$", "requestData", "[", "'params'", "]", ")", ";", "return", "$", "this", "->", "processUserDetails", "(", "$", "result", ")", ";", "}" ]
Tries to get user details for the current OAuth2 server. If you wish to get full account details you must use the rawRequest method because this one returns only the standardized response in a form of OAuth2User object. @return OAuth2User
[ "Tries", "to", "get", "user", "details", "for", "the", "current", "OAuth2", "server", ".", "If", "you", "wish", "to", "get", "full", "account", "details", "you", "must", "use", "the", "rawRequest", "method", "because", "this", "one", "returns", "only", "the", "standardized", "response", "in", "a", "form", "of", "OAuth2User", "object", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/AbstractServer.php#L87-L94
229,965
Webiny/Framework
src/Webiny/Component/OAuth2/AbstractServer.php
AbstractServer.rawRequest
private function rawRequest($url, $parameters = []) { $request = new OAuth2Request($this->oauth2); $request->setUrl($url); $request->setParams($parameters); return $request->executeRequest(); }
php
private function rawRequest($url, $parameters = []) { $request = new OAuth2Request($this->oauth2); $request->setUrl($url); $request->setParams($parameters); return $request->executeRequest(); }
[ "private", "function", "rawRequest", "(", "$", "url", ",", "$", "parameters", "=", "[", "]", ")", "{", "$", "request", "=", "new", "OAuth2Request", "(", "$", "this", "->", "oauth2", ")", ";", "$", "request", "->", "setUrl", "(", "$", "url", ")", ";", "$", "request", "->", "setParams", "(", "$", "parameters", ")", ";", "return", "$", "request", "->", "executeRequest", "(", ")", ";", "}" ]
Preforms an raw request on the current OAuth2 server. @param string $url Targeted url. @param array $parameters Query params that will be send along the request. @return array
[ "Preforms", "an", "raw", "request", "on", "the", "current", "OAuth2", "server", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/AbstractServer.php#L104-L112
229,966
decred/decred-php-api
src/Decred/Crypto/DecredNetwork.php
DecredNetwork.extendedKeyBase58Decode
public static function extendedKeyBase58Decode($key) { // The base58-decoded extended key must consist of a serialized payload // plus an additional 4 bytes for the checksum. $decoded = static::base58()->decode($key); if (strlen($decoded) !== 82) { throw new \InvalidArgumentException('Wrong key length.'); } // Split the payload and checksum up and ensure the checksum matches. $payload = substr($decoded, 0, 78); $expected = substr($decoded, -4); // Verify checksum of provided key $network = NetworkFactory::fromExtendedKeyVersion(substr($payload, 0, 4)); $checksum = substr($network->base58Checksum($payload), 0, 4); if ($expected !== $checksum) { throw new \InvalidArgumentException('Wrong checksum on encoding extended key!'); } return $decoded; }
php
public static function extendedKeyBase58Decode($key) { // The base58-decoded extended key must consist of a serialized payload // plus an additional 4 bytes for the checksum. $decoded = static::base58()->decode($key); if (strlen($decoded) !== 82) { throw new \InvalidArgumentException('Wrong key length.'); } // Split the payload and checksum up and ensure the checksum matches. $payload = substr($decoded, 0, 78); $expected = substr($decoded, -4); // Verify checksum of provided key $network = NetworkFactory::fromExtendedKeyVersion(substr($payload, 0, 4)); $checksum = substr($network->base58Checksum($payload), 0, 4); if ($expected !== $checksum) { throw new \InvalidArgumentException('Wrong checksum on encoding extended key!'); } return $decoded; }
[ "public", "static", "function", "extendedKeyBase58Decode", "(", "$", "key", ")", "{", "// The base58-decoded extended key must consist of a serialized payload", "// plus an additional 4 bytes for the checksum.", "$", "decoded", "=", "static", "::", "base58", "(", ")", "->", "decode", "(", "$", "key", ")", ";", "if", "(", "strlen", "(", "$", "decoded", ")", "!==", "82", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Wrong key length.'", ")", ";", "}", "// Split the payload and checksum up and ensure the checksum matches.", "$", "payload", "=", "substr", "(", "$", "decoded", ",", "0", ",", "78", ")", ";", "$", "expected", "=", "substr", "(", "$", "decoded", ",", "-", "4", ")", ";", "// Verify checksum of provided key", "$", "network", "=", "NetworkFactory", "::", "fromExtendedKeyVersion", "(", "substr", "(", "$", "payload", ",", "0", ",", "4", ")", ")", ";", "$", "checksum", "=", "substr", "(", "$", "network", "->", "base58Checksum", "(", "$", "payload", ")", ",", "0", ",", "4", ")", ";", "if", "(", "$", "expected", "!==", "$", "checksum", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Wrong checksum on encoding extended key!'", ")", ";", "}", "return", "$", "decoded", ";", "}" ]
Decode encrypted key and verify the checksum. @param string $key @return string
[ "Decode", "encrypted", "key", "and", "verify", "the", "checksum", "." ]
dafea9ceac918c4c3cd9bc7c436009a95dfb1643
https://github.com/decred/decred-php-api/blob/dafea9ceac918c4c3cd9bc7c436009a95dfb1643/src/Decred/Crypto/DecredNetwork.php#L28-L51
229,967
Webiny/Framework
src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php
AbstractHandler.canHandle
public function canHandle(Record $record) { if ($this->levels->count() < 1) { return true; } return $this->levels->inArray($record->getLevel()); }
php
public function canHandle(Record $record) { if ($this->levels->count() < 1) { return true; } return $this->levels->inArray($record->getLevel()); }
[ "public", "function", "canHandle", "(", "Record", "$", "record", ")", "{", "if", "(", "$", "this", "->", "levels", "->", "count", "(", ")", "<", "1", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "levels", "->", "inArray", "(", "$", "record", "->", "getLevel", "(", ")", ")", ";", "}" ]
Check if this handler can handle the given Record @param Record $record @return bool Boolean telling whether this handler can handle the given Record
[ "Check", "if", "this", "handler", "can", "handle", "the", "given", "Record" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php#L86-L93
229,968
Webiny/Framework
src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php
AbstractHandler.addProcessor
public function addProcessor($callback, $processBufferRecord = false) { if (!is_callable($callback) && !$this->isInstanceOf($callback, ProcessorInterface::class)) { throw new \InvalidArgumentException('Processor must be valid callable or an instance of ' . ProcessorInterface::class); } if ($processBufferRecord) { $this->bufferProcessors->prepend($callback); } else { $this->processors->prepend($callback); } return $this; }
php
public function addProcessor($callback, $processBufferRecord = false) { if (!is_callable($callback) && !$this->isInstanceOf($callback, ProcessorInterface::class)) { throw new \InvalidArgumentException('Processor must be valid callable or an instance of ' . ProcessorInterface::class); } if ($processBufferRecord) { $this->bufferProcessors->prepend($callback); } else { $this->processors->prepend($callback); } return $this; }
[ "public", "function", "addProcessor", "(", "$", "callback", ",", "$", "processBufferRecord", "=", "false", ")", "{", "if", "(", "!", "is_callable", "(", "$", "callback", ")", "&&", "!", "$", "this", "->", "isInstanceOf", "(", "$", "callback", ",", "ProcessorInterface", "::", "class", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Processor must be valid callable or an instance of '", ".", "ProcessorInterface", "::", "class", ")", ";", "}", "if", "(", "$", "processBufferRecord", ")", "{", "$", "this", "->", "bufferProcessors", "->", "prepend", "(", "$", "callback", ")", ";", "}", "else", "{", "$", "this", "->", "processors", "->", "prepend", "(", "$", "callback", ")", ";", "}", "return", "$", "this", ";", "}" ]
Add processor to this handler @param mixed $callback Callable or instance of ProcessorInterface @param bool $processBufferRecord @throws \InvalidArgumentException @return $this
[ "Add", "processor", "to", "this", "handler" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php#L118-L132
229,969
Webiny/Framework
src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php
AbstractHandler.process
public function process(Record $record) { if ($this->buffer) { $this->processRecord($record); $this->records[] = $record; return $this->bubble; } $this->processRecord($record); $this->getFormatter()->formatRecord($record); $this->write($record); return $this->bubble; }
php
public function process(Record $record) { if ($this->buffer) { $this->processRecord($record); $this->records[] = $record; return $this->bubble; } $this->processRecord($record); $this->getFormatter()->formatRecord($record); $this->write($record); return $this->bubble; }
[ "public", "function", "process", "(", "Record", "$", "record", ")", "{", "if", "(", "$", "this", "->", "buffer", ")", "{", "$", "this", "->", "processRecord", "(", "$", "record", ")", ";", "$", "this", "->", "records", "[", "]", "=", "$", "record", ";", "return", "$", "this", "->", "bubble", ";", "}", "$", "this", "->", "processRecord", "(", "$", "record", ")", ";", "$", "this", "->", "getFormatter", "(", ")", "->", "formatRecord", "(", "$", "record", ")", ";", "$", "this", "->", "write", "(", "$", "record", ")", ";", "return", "$", "this", "->", "bubble", ";", "}" ]
Process given record This will pass given record to ProcessorInterface instance, then format the record and output it according to current AbstractHandler instance @param Record $record @return bool Bubble flag (this either continues propagation of the Record to other handlers, or stops the logger from processing this record any further)
[ "Process", "given", "record", "This", "will", "pass", "given", "record", "to", "ProcessorInterface", "instance", "then", "format", "the", "record", "and", "output", "it", "according", "to", "current", "AbstractHandler", "instance" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php#L149-L164
229,970
Webiny/Framework
src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php
AbstractHandler.processRecords
protected function processRecords(array $records) { $record = new Record(); $formatter = $this->getFormatter(); if ($this->isInstanceOf($formatter, FormatterInterface::class)) { $formatter->formatRecords($records, $record); } $this->write($record); return $this->bubble; }
php
protected function processRecords(array $records) { $record = new Record(); $formatter = $this->getFormatter(); if ($this->isInstanceOf($formatter, FormatterInterface::class)) { $formatter->formatRecords($records, $record); } $this->write($record); return $this->bubble; }
[ "protected", "function", "processRecords", "(", "array", "$", "records", ")", "{", "$", "record", "=", "new", "Record", "(", ")", ";", "$", "formatter", "=", "$", "this", "->", "getFormatter", "(", ")", ";", "if", "(", "$", "this", "->", "isInstanceOf", "(", "$", "formatter", ",", "FormatterInterface", "::", "class", ")", ")", "{", "$", "formatter", "->", "formatRecords", "(", "$", "records", ",", "$", "record", ")", ";", "}", "$", "this", "->", "write", "(", "$", "record", ")", ";", "return", "$", "this", "->", "bubble", ";", "}" ]
Process batch of records @param array $records Batch of records to process @return bool Bubble flag (this either continues propagation of the Record to other handlers, or stops the logger from processing this record any further)
[ "Process", "batch", "of", "records" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Logger/Driver/Webiny/Handler/AbstractHandler.php#L192-L203
229,971
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/Loader.php
Loader.getMessage
public static function getMessage($mailer, ConfigObject $config = null) { // Do it this way to avoid merging into the original mailer config $mailerConfig = Mailer::getConfig()->get($mailer)->toArray(); $mailerConfig = new ConfigObject($mailerConfig); if ($config) { $mailerConfig->mergeWith($config); } $lib = self::getLibrary($mailer); /** @var MailerInterface $libInstance */ $libInstance = self::factory($lib, MailerInterface::class); $instance = $libInstance::getMessage($mailerConfig); if (!self::isInstanceOf($instance, MessageInterface::class)) { throw new MailerException(MailerException::MESSAGE_INTERFACE); } return $instance; }
php
public static function getMessage($mailer, ConfigObject $config = null) { // Do it this way to avoid merging into the original mailer config $mailerConfig = Mailer::getConfig()->get($mailer)->toArray(); $mailerConfig = new ConfigObject($mailerConfig); if ($config) { $mailerConfig->mergeWith($config); } $lib = self::getLibrary($mailer); /** @var MailerInterface $libInstance */ $libInstance = self::factory($lib, MailerInterface::class); $instance = $libInstance::getMessage($mailerConfig); if (!self::isInstanceOf($instance, MessageInterface::class)) { throw new MailerException(MailerException::MESSAGE_INTERFACE); } return $instance; }
[ "public", "static", "function", "getMessage", "(", "$", "mailer", ",", "ConfigObject", "$", "config", "=", "null", ")", "{", "// Do it this way to avoid merging into the original mailer config", "$", "mailerConfig", "=", "Mailer", "::", "getConfig", "(", ")", "->", "get", "(", "$", "mailer", ")", "->", "toArray", "(", ")", ";", "$", "mailerConfig", "=", "new", "ConfigObject", "(", "$", "mailerConfig", ")", ";", "if", "(", "$", "config", ")", "{", "$", "mailerConfig", "->", "mergeWith", "(", "$", "config", ")", ";", "}", "$", "lib", "=", "self", "::", "getLibrary", "(", "$", "mailer", ")", ";", "/** @var MailerInterface $libInstance */", "$", "libInstance", "=", "self", "::", "factory", "(", "$", "lib", ",", "MailerInterface", "::", "class", ")", ";", "$", "instance", "=", "$", "libInstance", "::", "getMessage", "(", "$", "mailerConfig", ")", ";", "if", "(", "!", "self", "::", "isInstanceOf", "(", "$", "instance", ",", "MessageInterface", "::", "class", ")", ")", "{", "throw", "new", "MailerException", "(", "MailerException", "::", "MESSAGE_INTERFACE", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Returns an instance of MessageInterface based on current bridge. @param $mailer @param ConfigObject $config @return \Webiny\Component\Mailer\MessageInterface @throws MailerException @throws \Webiny\Component\StdLib\Exception\Exception
[ "Returns", "an", "instance", "of", "MessageInterface", "based", "on", "current", "bridge", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/Loader.php#L43-L62
229,972
Webiny/Framework
src/Webiny/Component/Mailer/Bridge/Loader.php
Loader.getTransport
public static function getTransport($mailer) { $config = Mailer::getConfig()->get($mailer); if (!$config) { throw new MailerException(MailerException::INVALID_CONFIGURATION, [$mailer]); } $lib = self::getLibrary($mailer); /* @var MailerInterface $libInstance */ $libInstance = self::factory($lib, MailerInterface::class); $instance = $libInstance::getTransport($config); if (!self::isInstanceOf($instance, TransportInterface::class)) { throw new MailerException(MailerException::TRANSPORT_INTERFACE); } return $instance; }
php
public static function getTransport($mailer) { $config = Mailer::getConfig()->get($mailer); if (!$config) { throw new MailerException(MailerException::INVALID_CONFIGURATION, [$mailer]); } $lib = self::getLibrary($mailer); /* @var MailerInterface $libInstance */ $libInstance = self::factory($lib, MailerInterface::class); $instance = $libInstance::getTransport($config); if (!self::isInstanceOf($instance, TransportInterface::class)) { throw new MailerException(MailerException::TRANSPORT_INTERFACE); } return $instance; }
[ "public", "static", "function", "getTransport", "(", "$", "mailer", ")", "{", "$", "config", "=", "Mailer", "::", "getConfig", "(", ")", "->", "get", "(", "$", "mailer", ")", ";", "if", "(", "!", "$", "config", ")", "{", "throw", "new", "MailerException", "(", "MailerException", "::", "INVALID_CONFIGURATION", ",", "[", "$", "mailer", "]", ")", ";", "}", "$", "lib", "=", "self", "::", "getLibrary", "(", "$", "mailer", ")", ";", "/* @var MailerInterface $libInstance */", "$", "libInstance", "=", "self", "::", "factory", "(", "$", "lib", ",", "MailerInterface", "::", "class", ")", ";", "$", "instance", "=", "$", "libInstance", "::", "getTransport", "(", "$", "config", ")", ";", "if", "(", "!", "self", "::", "isInstanceOf", "(", "$", "instance", ",", "TransportInterface", "::", "class", ")", ")", "{", "throw", "new", "MailerException", "(", "MailerException", "::", "TRANSPORT_INTERFACE", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Returns an instance of TransportInterface based on current bridge. @param string $mailer @return TransportInterface @throws MailerException @throws \Webiny\Component\StdLib\Exception\Exception
[ "Returns", "an", "instance", "of", "TransportInterface", "based", "on", "current", "bridge", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Mailer/Bridge/Loader.php#L73-L91
229,973
addiks/phpsql
src/Addiks/PHPSQL/Index/IndexSchema.php
IndexSchema.getColumns
public function getColumns() { $rawColumns = substr($this->data, 64, 128); $columnsString = rtrim($rawColumns, "\0"); return explode("\0", $columnsString); }
php
public function getColumns() { $rawColumns = substr($this->data, 64, 128); $columnsString = rtrim($rawColumns, "\0"); return explode("\0", $columnsString); }
[ "public", "function", "getColumns", "(", ")", "{", "$", "rawColumns", "=", "substr", "(", "$", "this", "->", "data", ",", "64", ",", "128", ")", ";", "$", "columnsString", "=", "rtrim", "(", "$", "rawColumns", ",", "\"\\0\"", ")", ";", "return", "explode", "(", "\"\\0\"", ",", "$", "columnsString", ")", ";", "}" ]
Array of column-schema-indexes. @var array
[ "Array", "of", "column", "-", "schema", "-", "indexes", "." ]
28dae64ffc2123f39f801a50ab53bfe29890cbd9
https://github.com/addiks/phpsql/blob/28dae64ffc2123f39f801a50ab53bfe29890cbd9/src/Addiks/PHPSQL/Index/IndexSchema.php#L80-L85
229,974
deanblackborough/zf3-view-helpers
src/Bootstrap3ProgressBar.php
Bootstrap3ProgressBar.color
public function color(string $color): Bootstrap3ProgressBar { if (in_array($color, $this->supported_styles) === true) { $this->color = $color; } return $this; }
php
public function color(string $color): Bootstrap3ProgressBar { if (in_array($color, $this->supported_styles) === true) { $this->color = $color; } return $this; }
[ "public", "function", "color", "(", "string", "$", "color", ")", ":", "Bootstrap3ProgressBar", "{", "if", "(", "in_array", "(", "$", "color", ",", "$", "this", "->", "supported_styles", ")", "===", "true", ")", "{", "$", "this", "->", "color", "=", "$", "color", ";", "}", "return", "$", "this", ";", "}" ]
Set the background color for the progress bar, one of the following, success, info, warning or danger. If an incorrect style is passed in we don't apply the class. @param string $color @return Bootstrap3ProgressBar
[ "Set", "the", "background", "color", "for", "the", "progress", "bar", "one", "of", "the", "following", "success", "info", "warning", "or", "danger", ".", "If", "an", "incorrect", "style", "is", "passed", "in", "we", "don", "t", "apply", "the", "class", "." ]
db8bea4ca62709b2ac8c732aedbb2a5235223f23
https://github.com/deanblackborough/zf3-view-helpers/blob/db8bea4ca62709b2ac8c732aedbb2a5235223f23/src/Bootstrap3ProgressBar.php#L77-L84
229,975
Webiny/Framework
src/Webiny/Component/OAuth2/OAuth2.php
OAuth2.processUrl
private function processUrl($url) { $vars = [ '{CLIENT_ID}' => $this->getClientId(), '{REDIRECT_URI}' => $this->getRedirectURI(), '{SCOPE}' => $this->getScope(), '{STATE}' => $this->getState(), " " => '', "\n" => '', "\r" => '', "\t" => '' ]; $url = str_replace(array_keys($vars), array_values($vars), $url); return $url; }
php
private function processUrl($url) { $vars = [ '{CLIENT_ID}' => $this->getClientId(), '{REDIRECT_URI}' => $this->getRedirectURI(), '{SCOPE}' => $this->getScope(), '{STATE}' => $this->getState(), " " => '', "\n" => '', "\r" => '', "\t" => '' ]; $url = str_replace(array_keys($vars), array_values($vars), $url); return $url; }
[ "private", "function", "processUrl", "(", "$", "url", ")", "{", "$", "vars", "=", "[", "'{CLIENT_ID}'", "=>", "$", "this", "->", "getClientId", "(", ")", ",", "'{REDIRECT_URI}'", "=>", "$", "this", "->", "getRedirectURI", "(", ")", ",", "'{SCOPE}'", "=>", "$", "this", "->", "getScope", "(", ")", ",", "'{STATE}'", "=>", "$", "this", "->", "getState", "(", ")", ",", "\" \"", "=>", "''", ",", "\"\\n\"", "=>", "''", ",", "\"\\r\"", "=>", "''", ",", "\"\\t\"", "=>", "''", "]", ";", "$", "url", "=", "str_replace", "(", "array_keys", "(", "$", "vars", ")", ",", "array_values", "(", "$", "vars", ")", ",", "$", "url", ")", ";", "return", "$", "url", ";", "}" ]
Replaces the url variables with real data. @param string $url Url to process. @return string Processed url.
[ "Replaces", "the", "url", "variables", "with", "real", "data", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/OAuth2/OAuth2.php#L219-L235
229,976
Webiny/Framework
src/Webiny/Component/ServiceManager/ConfigCompiler.php
ConfigCompiler.compile
public function compile() { $this->manageInheritance(); $this->serviceConfig = $this->insertParameters($this->serviceConfig); $this->buildArguments('Arguments'); $this->buildArguments('MethodArguments'); $this->buildCallsArguments(); $this->buildFactoryArgument(); return $this->buildServiceConfig(); }
php
public function compile() { $this->manageInheritance(); $this->serviceConfig = $this->insertParameters($this->serviceConfig); $this->buildArguments('Arguments'); $this->buildArguments('MethodArguments'); $this->buildCallsArguments(); $this->buildFactoryArgument(); return $this->buildServiceConfig(); }
[ "public", "function", "compile", "(", ")", "{", "$", "this", "->", "manageInheritance", "(", ")", ";", "$", "this", "->", "serviceConfig", "=", "$", "this", "->", "insertParameters", "(", "$", "this", "->", "serviceConfig", ")", ";", "$", "this", "->", "buildArguments", "(", "'Arguments'", ")", ";", "$", "this", "->", "buildArguments", "(", "'MethodArguments'", ")", ";", "$", "this", "->", "buildCallsArguments", "(", ")", ";", "$", "this", "->", "buildFactoryArgument", "(", ")", ";", "return", "$", "this", "->", "buildServiceConfig", "(", ")", ";", "}" ]
Compile current config and return a valid ServiceConfig object. That new ServiceConfig will be used to instantiate a service later in the process of creating a service instance. @return ServiceConfig
[ "Compile", "current", "config", "and", "return", "a", "valid", "ServiceConfig", "object", ".", "That", "new", "ServiceConfig", "will", "be", "used", "to", "instantiate", "a", "service", "later", "in", "the", "process", "of", "creating", "a", "service", "instance", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ConfigCompiler.php#L48-L58
229,977
Webiny/Framework
src/Webiny/Component/ServiceManager/ConfigCompiler.php
ConfigCompiler.manageInheritance
private function manageInheritance() { $config = $this->serviceConfig; if ($config->keyExists('Parent')) { $parentServiceName = $this->str($config->key('Parent'))->trimLeft('@')->val(); $parentConfig = ServiceManager::getInstance()->getServiceConfig($parentServiceName)->toArray(true); if (!$parentConfig->keyExists('Abstract')) { throw new ServiceManagerException(ServiceManagerException::SERVICE_IS_NOT_ABSTRACT, [$config->key('Parent')] ); } $config = $this->extendConfig($config, $parentConfig); } // Check if it's a potentially valid service definition if (!$config->keyExists('Class') && !$config->keyExists('Factory')) { throw new ServiceManagerException(ServiceManagerException::SERVICE_CLASS_KEY_NOT_FOUND, [$this->serviceName] ); } $this->serviceConfig = $config; }
php
private function manageInheritance() { $config = $this->serviceConfig; if ($config->keyExists('Parent')) { $parentServiceName = $this->str($config->key('Parent'))->trimLeft('@')->val(); $parentConfig = ServiceManager::getInstance()->getServiceConfig($parentServiceName)->toArray(true); if (!$parentConfig->keyExists('Abstract')) { throw new ServiceManagerException(ServiceManagerException::SERVICE_IS_NOT_ABSTRACT, [$config->key('Parent')] ); } $config = $this->extendConfig($config, $parentConfig); } // Check if it's a potentially valid service definition if (!$config->keyExists('Class') && !$config->keyExists('Factory')) { throw new ServiceManagerException(ServiceManagerException::SERVICE_CLASS_KEY_NOT_FOUND, [$this->serviceName] ); } $this->serviceConfig = $config; }
[ "private", "function", "manageInheritance", "(", ")", "{", "$", "config", "=", "$", "this", "->", "serviceConfig", ";", "if", "(", "$", "config", "->", "keyExists", "(", "'Parent'", ")", ")", "{", "$", "parentServiceName", "=", "$", "this", "->", "str", "(", "$", "config", "->", "key", "(", "'Parent'", ")", ")", "->", "trimLeft", "(", "'@'", ")", "->", "val", "(", ")", ";", "$", "parentConfig", "=", "ServiceManager", "::", "getInstance", "(", ")", "->", "getServiceConfig", "(", "$", "parentServiceName", ")", "->", "toArray", "(", "true", ")", ";", "if", "(", "!", "$", "parentConfig", "->", "keyExists", "(", "'Abstract'", ")", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "SERVICE_IS_NOT_ABSTRACT", ",", "[", "$", "config", "->", "key", "(", "'Parent'", ")", "]", ")", ";", "}", "$", "config", "=", "$", "this", "->", "extendConfig", "(", "$", "config", ",", "$", "parentConfig", ")", ";", "}", "// Check if it's a potentially valid service definition", "if", "(", "!", "$", "config", "->", "keyExists", "(", "'Class'", ")", "&&", "!", "$", "config", "->", "keyExists", "(", "'Factory'", ")", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "SERVICE_CLASS_KEY_NOT_FOUND", ",", "[", "$", "this", "->", "serviceName", "]", ")", ";", "}", "$", "this", "->", "serviceConfig", "=", "$", "config", ";", "}" ]
Check if current service has a parent service and merge its config with parent service config. @throws ServiceManagerException
[ "Check", "if", "current", "service", "has", "a", "parent", "service", "and", "merge", "its", "config", "with", "parent", "service", "config", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ConfigCompiler.php#L65-L87
229,978
Webiny/Framework
src/Webiny/Component/ServiceManager/ConfigCompiler.php
ConfigCompiler.insertParameters
private function insertParameters($config) { foreach ($config as $k => $v) { if ($this->isArray($v)) { $config[$k] = $this->insertParameters($v); } elseif ($this->isString($v)) { $str = $this->str($v)->trim(); if ($str->startsWith('%') && $str->endsWith('%')) { $parameter = $str->trim('%')->val(); if (isset($this->parameters[$parameter])) { $config[$k] = $this->parameters[$parameter]; } else { throw new ServiceManagerException(ServiceManagerException::PARAMETER_NOT_FOUND, [ $parameter, $this->serviceName ] ); } } } } return $config; }
php
private function insertParameters($config) { foreach ($config as $k => $v) { if ($this->isArray($v)) { $config[$k] = $this->insertParameters($v); } elseif ($this->isString($v)) { $str = $this->str($v)->trim(); if ($str->startsWith('%') && $str->endsWith('%')) { $parameter = $str->trim('%')->val(); if (isset($this->parameters[$parameter])) { $config[$k] = $this->parameters[$parameter]; } else { throw new ServiceManagerException(ServiceManagerException::PARAMETER_NOT_FOUND, [ $parameter, $this->serviceName ] ); } } } } return $config; }
[ "private", "function", "insertParameters", "(", "$", "config", ")", "{", "foreach", "(", "$", "config", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "this", "->", "isArray", "(", "$", "v", ")", ")", "{", "$", "config", "[", "$", "k", "]", "=", "$", "this", "->", "insertParameters", "(", "$", "v", ")", ";", "}", "elseif", "(", "$", "this", "->", "isString", "(", "$", "v", ")", ")", "{", "$", "str", "=", "$", "this", "->", "str", "(", "$", "v", ")", "->", "trim", "(", ")", ";", "if", "(", "$", "str", "->", "startsWith", "(", "'%'", ")", "&&", "$", "str", "->", "endsWith", "(", "'%'", ")", ")", "{", "$", "parameter", "=", "$", "str", "->", "trim", "(", "'%'", ")", "->", "val", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "parameters", "[", "$", "parameter", "]", ")", ")", "{", "$", "config", "[", "$", "k", "]", "=", "$", "this", "->", "parameters", "[", "$", "parameter", "]", ";", "}", "else", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "PARAMETER_NOT_FOUND", ",", "[", "$", "parameter", ",", "$", "this", "->", "serviceName", "]", ")", ";", "}", "}", "}", "}", "return", "$", "config", ";", "}" ]
Insert parameters into the config @param ArrayObject $config Target config @return ArrayObject @throws ServiceManagerException
[ "Insert", "parameters", "into", "the", "config" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ConfigCompiler.php#L98-L122
229,979
Webiny/Framework
src/Webiny/Component/ServiceManager/ConfigCompiler.php
ConfigCompiler.buildArguments
private function buildArguments($key) { $newArguments = []; if ($this->serviceConfig->keyExists($key)) { $arguments = $this->serviceConfig->key($key); if (!$this->isArray($arguments)) { throw new ServiceManagerException(ServiceManagerException::INVALID_SERVICE_ARGUMENTS_TYPE, [$this->serviceName] ); } foreach ($arguments as $arg) { $newArguments[] = new Argument($arg); } } $this->serviceConfig->key($key, $newArguments); }
php
private function buildArguments($key) { $newArguments = []; if ($this->serviceConfig->keyExists($key)) { $arguments = $this->serviceConfig->key($key); if (!$this->isArray($arguments)) { throw new ServiceManagerException(ServiceManagerException::INVALID_SERVICE_ARGUMENTS_TYPE, [$this->serviceName] ); } foreach ($arguments as $arg) { $newArguments[] = new Argument($arg); } } $this->serviceConfig->key($key, $newArguments); }
[ "private", "function", "buildArguments", "(", "$", "key", ")", "{", "$", "newArguments", "=", "[", "]", ";", "if", "(", "$", "this", "->", "serviceConfig", "->", "keyExists", "(", "$", "key", ")", ")", "{", "$", "arguments", "=", "$", "this", "->", "serviceConfig", "->", "key", "(", "$", "key", ")", ";", "if", "(", "!", "$", "this", "->", "isArray", "(", "$", "arguments", ")", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "INVALID_SERVICE_ARGUMENTS_TYPE", ",", "[", "$", "this", "->", "serviceName", "]", ")", ";", "}", "foreach", "(", "$", "arguments", "as", "$", "arg", ")", "{", "$", "newArguments", "[", "]", "=", "new", "Argument", "(", "$", "arg", ")", ";", "}", "}", "$", "this", "->", "serviceConfig", "->", "key", "(", "$", "key", ",", "$", "newArguments", ")", ";", "}" ]
Convert simple config arguments into Argument objects @param string $key @throws ServiceManagerException
[ "Convert", "simple", "config", "arguments", "into", "Argument", "objects" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ConfigCompiler.php#L186-L201
229,980
Webiny/Framework
src/Webiny/Component/ServiceManager/ConfigCompiler.php
ConfigCompiler.buildFactoryArgument
private function buildFactoryArgument() { if ($this->serviceConfig->keyExists('Factory')) { $factory = $this->str($this->serviceConfig->key('Factory')); $arguments = $this->serviceConfig->key('Arguments', null, true); // If it's a STATIC method call - unset all arguments if ($this->serviceConfig->key('Static', true, true) && !$factory->startsWith('@')) { $arguments = []; } $factoryArgument = new FactoryArgument($this->serviceConfig->key('Factory'), $arguments, $this->serviceConfig->key('Static') ); $this->serviceConfig->key('Factory', $factoryArgument); } }
php
private function buildFactoryArgument() { if ($this->serviceConfig->keyExists('Factory')) { $factory = $this->str($this->serviceConfig->key('Factory')); $arguments = $this->serviceConfig->key('Arguments', null, true); // If it's a STATIC method call - unset all arguments if ($this->serviceConfig->key('Static', true, true) && !$factory->startsWith('@')) { $arguments = []; } $factoryArgument = new FactoryArgument($this->serviceConfig->key('Factory'), $arguments, $this->serviceConfig->key('Static') ); $this->serviceConfig->key('Factory', $factoryArgument); } }
[ "private", "function", "buildFactoryArgument", "(", ")", "{", "if", "(", "$", "this", "->", "serviceConfig", "->", "keyExists", "(", "'Factory'", ")", ")", "{", "$", "factory", "=", "$", "this", "->", "str", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Factory'", ")", ")", ";", "$", "arguments", "=", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Arguments'", ",", "null", ",", "true", ")", ";", "// If it's a STATIC method call - unset all arguments", "if", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Static'", ",", "true", ",", "true", ")", "&&", "!", "$", "factory", "->", "startsWith", "(", "'@'", ")", ")", "{", "$", "arguments", "=", "[", "]", ";", "}", "$", "factoryArgument", "=", "new", "FactoryArgument", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Factory'", ")", ",", "$", "arguments", ",", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Static'", ")", ")", ";", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Factory'", ",", "$", "factoryArgument", ")", ";", "}", "}" ]
Convert factory service arguments into FactoryArgument objects
[ "Convert", "factory", "service", "arguments", "into", "FactoryArgument", "objects" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ConfigCompiler.php#L206-L220
229,981
Webiny/Framework
src/Webiny/Component/ServiceManager/ConfigCompiler.php
ConfigCompiler.buildCallsArguments
private function buildCallsArguments() { if ($this->serviceConfig->keyExists('Calls')) { $calls = $this->serviceConfig->key('Calls'); foreach ($calls as $callKey => $call) { if ($this->isArray($call[1])) { $newArguments = []; foreach ($call[1] as $arg) { $newArguments[] = new Argument($arg); } $calls[$callKey][1] = $newArguments; } } $this->serviceConfig->key('Calls', $calls); } }
php
private function buildCallsArguments() { if ($this->serviceConfig->keyExists('Calls')) { $calls = $this->serviceConfig->key('Calls'); foreach ($calls as $callKey => $call) { if ($this->isArray($call[1])) { $newArguments = []; foreach ($call[1] as $arg) { $newArguments[] = new Argument($arg); } $calls[$callKey][1] = $newArguments; } } $this->serviceConfig->key('Calls', $calls); } }
[ "private", "function", "buildCallsArguments", "(", ")", "{", "if", "(", "$", "this", "->", "serviceConfig", "->", "keyExists", "(", "'Calls'", ")", ")", "{", "$", "calls", "=", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Calls'", ")", ";", "foreach", "(", "$", "calls", "as", "$", "callKey", "=>", "$", "call", ")", "{", "if", "(", "$", "this", "->", "isArray", "(", "$", "call", "[", "1", "]", ")", ")", "{", "$", "newArguments", "=", "[", "]", ";", "foreach", "(", "$", "call", "[", "1", "]", "as", "$", "arg", ")", "{", "$", "newArguments", "[", "]", "=", "new", "Argument", "(", "$", "arg", ")", ";", "}", "$", "calls", "[", "$", "callKey", "]", "[", "1", "]", "=", "$", "newArguments", ";", "}", "}", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Calls'", ",", "$", "calls", ")", ";", "}", "}" ]
Build arguments for "Calls" methods
[ "Build", "arguments", "for", "Calls", "methods" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ConfigCompiler.php#L225-L240
229,982
Webiny/Framework
src/Webiny/Component/ServiceManager/ConfigCompiler.php
ConfigCompiler.buildServiceConfig
private function buildServiceConfig() { if ($this->serviceConfig->keyExists('Factory') && !$this->serviceConfig->keyExists('Method')) { throw new ServiceManagerException(ServiceManagerException::FACTORY_SERVICE_METHOD_KEY_MISSING, [$this->serviceName] ); } $config = new ServiceConfig(); $config->setClass($this->serviceConfig->key('Class', null, true)); $config->setArguments($this->serviceConfig->key('Arguments', [], true)); $config->setCalls($this->serviceConfig->key('Calls', [], true)); $config->setScope($this->serviceConfig->key('Scope', ServiceScope::CONTAINER, true)); $config->setFactory($this->serviceConfig->key('Factory', null, true)); $config->setMethod($this->serviceConfig->key('Method', null, true)); $config->setMethodArguments($this->serviceConfig->key('MethodArguments')); $config->setStatic($this->serviceConfig->key('Static', true, true)); return $config; }
php
private function buildServiceConfig() { if ($this->serviceConfig->keyExists('Factory') && !$this->serviceConfig->keyExists('Method')) { throw new ServiceManagerException(ServiceManagerException::FACTORY_SERVICE_METHOD_KEY_MISSING, [$this->serviceName] ); } $config = new ServiceConfig(); $config->setClass($this->serviceConfig->key('Class', null, true)); $config->setArguments($this->serviceConfig->key('Arguments', [], true)); $config->setCalls($this->serviceConfig->key('Calls', [], true)); $config->setScope($this->serviceConfig->key('Scope', ServiceScope::CONTAINER, true)); $config->setFactory($this->serviceConfig->key('Factory', null, true)); $config->setMethod($this->serviceConfig->key('Method', null, true)); $config->setMethodArguments($this->serviceConfig->key('MethodArguments')); $config->setStatic($this->serviceConfig->key('Static', true, true)); return $config; }
[ "private", "function", "buildServiceConfig", "(", ")", "{", "if", "(", "$", "this", "->", "serviceConfig", "->", "keyExists", "(", "'Factory'", ")", "&&", "!", "$", "this", "->", "serviceConfig", "->", "keyExists", "(", "'Method'", ")", ")", "{", "throw", "new", "ServiceManagerException", "(", "ServiceManagerException", "::", "FACTORY_SERVICE_METHOD_KEY_MISSING", ",", "[", "$", "this", "->", "serviceName", "]", ")", ";", "}", "$", "config", "=", "new", "ServiceConfig", "(", ")", ";", "$", "config", "->", "setClass", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Class'", ",", "null", ",", "true", ")", ")", ";", "$", "config", "->", "setArguments", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Arguments'", ",", "[", "]", ",", "true", ")", ")", ";", "$", "config", "->", "setCalls", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Calls'", ",", "[", "]", ",", "true", ")", ")", ";", "$", "config", "->", "setScope", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Scope'", ",", "ServiceScope", "::", "CONTAINER", ",", "true", ")", ")", ";", "$", "config", "->", "setFactory", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Factory'", ",", "null", ",", "true", ")", ")", ";", "$", "config", "->", "setMethod", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Method'", ",", "null", ",", "true", ")", ")", ";", "$", "config", "->", "setMethodArguments", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'MethodArguments'", ")", ")", ";", "$", "config", "->", "setStatic", "(", "$", "this", "->", "serviceConfig", "->", "key", "(", "'Static'", ",", "true", ",", "true", ")", ")", ";", "return", "$", "config", ";", "}" ]
Build final ServiceConfig object @return ServiceConfig @throws ServiceManagerException
[ "Build", "final", "ServiceConfig", "object" ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/ServiceManager/ConfigCompiler.php#L249-L268
229,983
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.requestAuthToken
public function requestAuthToken($username, $password) { $response = parent::requestAuthToken($username, $password); $data = $this->decodeResponse($response); if (count($data) === 0) { throw new EndomondoApiOldException('Wrong username or password.'); } $this->setAccessToken($data['authToken']); $this->setUserId($data['userId']); return $data; }
php
public function requestAuthToken($username, $password) { $response = parent::requestAuthToken($username, $password); $data = $this->decodeResponse($response); if (count($data) === 0) { throw new EndomondoApiOldException('Wrong username or password.'); } $this->setAccessToken($data['authToken']); $this->setUserId($data['userId']); return $data; }
[ "public", "function", "requestAuthToken", "(", "$", "username", ",", "$", "password", ")", "{", "$", "response", "=", "parent", "::", "requestAuthToken", "(", "$", "username", ",", "$", "password", ")", ";", "$", "data", "=", "$", "this", "->", "decodeResponse", "(", "$", "response", ")", ";", "if", "(", "count", "(", "$", "data", ")", "===", "0", ")", "{", "throw", "new", "EndomondoApiOldException", "(", "'Wrong username or password.'", ")", ";", "}", "$", "this", "->", "setAccessToken", "(", "$", "data", "[", "'authToken'", "]", ")", ";", "$", "this", "->", "setUserId", "(", "$", "data", "[", "'userId'", "]", ")", ";", "return", "$", "data", ";", "}" ]
Request auth token and other base user information. @param string $username endomondo username @param string $password password for user @return array Data that contain action, authToken, measure, displayName, userId, facebookConnected and secureToken @throws EndomondoApiOldException when credentials are wrong
[ "Request", "auth", "token", "and", "other", "base", "user", "information", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L47-L59
229,984
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.decodeResponse
private function decodeResponse(ResponseInterface $response) { $responseBody = trim((string) $response->getBody()); if ($response->getHeader('Content-Type')[0] === 'text/plain;charset=UTF-8') { $lines = explode("\n", $responseBody); $data = []; // parse endomondo text response foreach ($lines as $line) { $items = explode('=', $line); if (count($items) === 2) { $data[$items[0]] = $items[1]; } } return $data; } $data = json_decode($responseBody, true); if (isset($data['error'])) { throw new EndomondoApiOldException('Api error: ' . $data['error']['type']); } return $data; }
php
private function decodeResponse(ResponseInterface $response) { $responseBody = trim((string) $response->getBody()); if ($response->getHeader('Content-Type')[0] === 'text/plain;charset=UTF-8') { $lines = explode("\n", $responseBody); $data = []; // parse endomondo text response foreach ($lines as $line) { $items = explode('=', $line); if (count($items) === 2) { $data[$items[0]] = $items[1]; } } return $data; } $data = json_decode($responseBody, true); if (isset($data['error'])) { throw new EndomondoApiOldException('Api error: ' . $data['error']['type']); } return $data; }
[ "private", "function", "decodeResponse", "(", "ResponseInterface", "$", "response", ")", "{", "$", "responseBody", "=", "trim", "(", "(", "string", ")", "$", "response", "->", "getBody", "(", ")", ")", ";", "if", "(", "$", "response", "->", "getHeader", "(", "'Content-Type'", ")", "[", "0", "]", "===", "'text/plain;charset=UTF-8'", ")", "{", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "responseBody", ")", ";", "$", "data", "=", "[", "]", ";", "// parse endomondo text response", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "items", "=", "explode", "(", "'='", ",", "$", "line", ")", ";", "if", "(", "count", "(", "$", "items", ")", "===", "2", ")", "{", "$", "data", "[", "$", "items", "[", "0", "]", "]", "=", "$", "items", "[", "1", "]", ";", "}", "}", "return", "$", "data", ";", "}", "$", "data", "=", "json_decode", "(", "$", "responseBody", ",", "true", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "'error'", "]", ")", ")", "{", "throw", "new", "EndomondoApiOldException", "(", "'Api error: '", ".", "$", "data", "[", "'error'", "]", "[", "'type'", "]", ")", ";", "}", "return", "$", "data", ";", "}" ]
Decode response from Endomondo and convert it to array. @param ResponseInterface $response @return array response from endomondo @throws EndomondoApiOldException when request to endomondo fail
[ "Decode", "response", "from", "Endomondo", "and", "convert", "it", "to", "array", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L68-L94
229,985
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.request
public function request($endpoint, $options = [], $body = '') { if ($this->getAcessToken()) { $options['authToken'] = $this->getAcessToken(); } try { return $this->decodeResponse(parent::send($endpoint, $options, gzencode($body))); } catch(ClientException $e) { throw new EndomondoApiOldException($e->getMessage(), $e->getCode(), $e); } }
php
public function request($endpoint, $options = [], $body = '') { if ($this->getAcessToken()) { $options['authToken'] = $this->getAcessToken(); } try { return $this->decodeResponse(parent::send($endpoint, $options, gzencode($body))); } catch(ClientException $e) { throw new EndomondoApiOldException($e->getMessage(), $e->getCode(), $e); } }
[ "public", "function", "request", "(", "$", "endpoint", ",", "$", "options", "=", "[", "]", ",", "$", "body", "=", "''", ")", "{", "if", "(", "$", "this", "->", "getAcessToken", "(", ")", ")", "{", "$", "options", "[", "'authToken'", "]", "=", "$", "this", "->", "getAcessToken", "(", ")", ";", "}", "try", "{", "return", "$", "this", "->", "decodeResponse", "(", "parent", "::", "send", "(", "$", "endpoint", ",", "$", "options", ",", "gzencode", "(", "$", "body", ")", ")", ")", ";", "}", "catch", "(", "ClientException", "$", "e", ")", "{", "throw", "new", "EndomondoApiOldException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "$", "e", "->", "getCode", "(", ")", ",", "$", "e", ")", ";", "}", "}" ]
Request Old Endomondo API. @param string $endpoint @param array $options @param string $body @return array @throws EndomondoApiOldException when api request fail
[ "Request", "Old", "Endomondo", "API", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L105-L116
229,986
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.getWorkout
public function getWorkout($id, $fields = self::DEFAULT_WORKOUT_FIELDS) { return OldApiParser::parseWorkout($this->request(self::GET_WORKOUT_ENDPOINT, [ 'fields' => join($fields, ','), 'workoutId' => $id, ])); }
php
public function getWorkout($id, $fields = self::DEFAULT_WORKOUT_FIELDS) { return OldApiParser::parseWorkout($this->request(self::GET_WORKOUT_ENDPOINT, [ 'fields' => join($fields, ','), 'workoutId' => $id, ])); }
[ "public", "function", "getWorkout", "(", "$", "id", ",", "$", "fields", "=", "self", "::", "DEFAULT_WORKOUT_FIELDS", ")", "{", "return", "OldApiParser", "::", "parseWorkout", "(", "$", "this", "->", "request", "(", "self", "::", "GET_WORKOUT_ENDPOINT", ",", "[", "'fields'", "=>", "join", "(", "$", "fields", ",", "','", ")", ",", "'workoutId'", "=>", "$", "id", ",", "]", ")", ")", ";", "}" ]
Get single Endomondo workout. @param $id string @param array $fields list of requested fields @return Workout
[ "Get", "single", "Endomondo", "workout", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L125-L131
229,987
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.getWorkouts
public function getWorkouts($limit = 10, $fields = self::DEFAULT_WORKOUT_FIELDS) { $workouts = []; $response = $this->request(self::GET_WORKOUTS_ENDPOINT, [ 'fields' => join(',', $fields), 'maxResults' => $limit, ]); foreach ($response['data'] as $workout) { $workouts[] = OldApiParser::parseWorkout($workout); } return $workouts; }
php
public function getWorkouts($limit = 10, $fields = self::DEFAULT_WORKOUT_FIELDS) { $workouts = []; $response = $this->request(self::GET_WORKOUTS_ENDPOINT, [ 'fields' => join(',', $fields), 'maxResults' => $limit, ]); foreach ($response['data'] as $workout) { $workouts[] = OldApiParser::parseWorkout($workout); } return $workouts; }
[ "public", "function", "getWorkouts", "(", "$", "limit", "=", "10", ",", "$", "fields", "=", "self", "::", "DEFAULT_WORKOUT_FIELDS", ")", "{", "$", "workouts", "=", "[", "]", ";", "$", "response", "=", "$", "this", "->", "request", "(", "self", "::", "GET_WORKOUTS_ENDPOINT", ",", "[", "'fields'", "=>", "join", "(", "','", ",", "$", "fields", ")", ",", "'maxResults'", "=>", "$", "limit", ",", "]", ")", ";", "foreach", "(", "$", "response", "[", "'data'", "]", "as", "$", "workout", ")", "{", "$", "workouts", "[", "]", "=", "OldApiParser", "::", "parseWorkout", "(", "$", "workout", ")", ";", "}", "return", "$", "workouts", ";", "}" ]
Get list of last workouts @param int $limit @param array $fields list of requested fields @return Workout[]
[ "Get", "list", "of", "last", "workouts" ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L140-L153
229,988
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.createWorkout
public function createWorkout(Workout $workout) { $response = $this->request(self::CREATE_WORKOUT_ENDPOINT, [ 'workoutId' => '-' . $this->bigRandomNumber(16), 'duration' => $workout->getDuration(), 'sport' => $workout->getTypeId(), 'extendedResponse' => 'true', 'gzip' => 'true', ], $workout->getPointsAsString()); if (!isset($response['workout.id'])) { throw new EndomondoApiOldException('Workout create failed.'); } $workout->setId($response['workout.id']); return $this->updateWorkout($workout); }
php
public function createWorkout(Workout $workout) { $response = $this->request(self::CREATE_WORKOUT_ENDPOINT, [ 'workoutId' => '-' . $this->bigRandomNumber(16), 'duration' => $workout->getDuration(), 'sport' => $workout->getTypeId(), 'extendedResponse' => 'true', 'gzip' => 'true', ], $workout->getPointsAsString()); if (!isset($response['workout.id'])) { throw new EndomondoApiOldException('Workout create failed.'); } $workout->setId($response['workout.id']); return $this->updateWorkout($workout); }
[ "public", "function", "createWorkout", "(", "Workout", "$", "workout", ")", "{", "$", "response", "=", "$", "this", "->", "request", "(", "self", "::", "CREATE_WORKOUT_ENDPOINT", ",", "[", "'workoutId'", "=>", "'-'", ".", "$", "this", "->", "bigRandomNumber", "(", "16", ")", ",", "'duration'", "=>", "$", "workout", "->", "getDuration", "(", ")", ",", "'sport'", "=>", "$", "workout", "->", "getTypeId", "(", ")", ",", "'extendedResponse'", "=>", "'true'", ",", "'gzip'", "=>", "'true'", ",", "]", ",", "$", "workout", "->", "getPointsAsString", "(", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "response", "[", "'workout.id'", "]", ")", ")", "{", "throw", "new", "EndomondoApiOldException", "(", "'Workout create failed.'", ")", ";", "}", "$", "workout", "->", "setId", "(", "$", "response", "[", "'workout.id'", "]", ")", ";", "return", "$", "this", "->", "updateWorkout", "(", "$", "workout", ")", ";", "}" ]
Create Endomondo Workout. @param Workout $workout @return Workout @throws EndomondoApiOldException when it fails to create workout
[ "Create", "Endomondo", "Workout", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L162-L179
229,989
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.updateWorkout
public function updateWorkout(Workout $workout) { if (!$workout->getId()) { throw new EndomondoApiOldException('You cannot edit workout without knowing its ID.'); } $utc = new \DateTimeZone('UTC'); $timeFormat = 'Y-m-d H:i:s \U\T\C'; $data = [ 'duration' => $workout->getDuration(), 'sport' => $workout->getTypeId(), 'distance' => $workout->getDistance(), 'start_time' => $workout->getStart()->setTimezone($utc)->format($timeFormat), 'end_time' => $workout->getEnd()->setTimezone($utc)->format($timeFormat), 'extendedResponse' => 'true', 'gzip' => 'true', ]; if ($workout->getCalories() !== null) { $data['calories'] = $workout->getCalories(); } if ($workout->getNotes() !== null) { $data['notes'] = $workout->getNotes(); } if ($workout->getMapPrivacy() !== null) { $data['privacy_map'] = $workout->getMapPrivacy(); } if ($workout->getWorkoutPrivacy() !== null) { $data['privacy_workout'] = $workout->getWorkoutPrivacy(); } $this->request(self::UPDATE_WORKOUT_ENDPOINT, [ 'workoutId' => $workout->getId(), 'userId' => $this->getUserId(), 'gzip' => 'true', ], json_encode($data)); return $this->getWorkout($workout->getId()); }
php
public function updateWorkout(Workout $workout) { if (!$workout->getId()) { throw new EndomondoApiOldException('You cannot edit workout without knowing its ID.'); } $utc = new \DateTimeZone('UTC'); $timeFormat = 'Y-m-d H:i:s \U\T\C'; $data = [ 'duration' => $workout->getDuration(), 'sport' => $workout->getTypeId(), 'distance' => $workout->getDistance(), 'start_time' => $workout->getStart()->setTimezone($utc)->format($timeFormat), 'end_time' => $workout->getEnd()->setTimezone($utc)->format($timeFormat), 'extendedResponse' => 'true', 'gzip' => 'true', ]; if ($workout->getCalories() !== null) { $data['calories'] = $workout->getCalories(); } if ($workout->getNotes() !== null) { $data['notes'] = $workout->getNotes(); } if ($workout->getMapPrivacy() !== null) { $data['privacy_map'] = $workout->getMapPrivacy(); } if ($workout->getWorkoutPrivacy() !== null) { $data['privacy_workout'] = $workout->getWorkoutPrivacy(); } $this->request(self::UPDATE_WORKOUT_ENDPOINT, [ 'workoutId' => $workout->getId(), 'userId' => $this->getUserId(), 'gzip' => 'true', ], json_encode($data)); return $this->getWorkout($workout->getId()); }
[ "public", "function", "updateWorkout", "(", "Workout", "$", "workout", ")", "{", "if", "(", "!", "$", "workout", "->", "getId", "(", ")", ")", "{", "throw", "new", "EndomondoApiOldException", "(", "'You cannot edit workout without knowing its ID.'", ")", ";", "}", "$", "utc", "=", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ";", "$", "timeFormat", "=", "'Y-m-d H:i:s \\U\\T\\C'", ";", "$", "data", "=", "[", "'duration'", "=>", "$", "workout", "->", "getDuration", "(", ")", ",", "'sport'", "=>", "$", "workout", "->", "getTypeId", "(", ")", ",", "'distance'", "=>", "$", "workout", "->", "getDistance", "(", ")", ",", "'start_time'", "=>", "$", "workout", "->", "getStart", "(", ")", "->", "setTimezone", "(", "$", "utc", ")", "->", "format", "(", "$", "timeFormat", ")", ",", "'end_time'", "=>", "$", "workout", "->", "getEnd", "(", ")", "->", "setTimezone", "(", "$", "utc", ")", "->", "format", "(", "$", "timeFormat", ")", ",", "'extendedResponse'", "=>", "'true'", ",", "'gzip'", "=>", "'true'", ",", "]", ";", "if", "(", "$", "workout", "->", "getCalories", "(", ")", "!==", "null", ")", "{", "$", "data", "[", "'calories'", "]", "=", "$", "workout", "->", "getCalories", "(", ")", ";", "}", "if", "(", "$", "workout", "->", "getNotes", "(", ")", "!==", "null", ")", "{", "$", "data", "[", "'notes'", "]", "=", "$", "workout", "->", "getNotes", "(", ")", ";", "}", "if", "(", "$", "workout", "->", "getMapPrivacy", "(", ")", "!==", "null", ")", "{", "$", "data", "[", "'privacy_map'", "]", "=", "$", "workout", "->", "getMapPrivacy", "(", ")", ";", "}", "if", "(", "$", "workout", "->", "getWorkoutPrivacy", "(", ")", "!==", "null", ")", "{", "$", "data", "[", "'privacy_workout'", "]", "=", "$", "workout", "->", "getWorkoutPrivacy", "(", ")", ";", "}", "$", "this", "->", "request", "(", "self", "::", "UPDATE_WORKOUT_ENDPOINT", ",", "[", "'workoutId'", "=>", "$", "workout", "->", "getId", "(", ")", ",", "'userId'", "=>", "$", "this", "->", "getUserId", "(", ")", ",", "'gzip'", "=>", "'true'", ",", "]", ",", "json_encode", "(", "$", "data", ")", ")", ";", "return", "$", "this", "->", "getWorkout", "(", "$", "workout", "->", "getId", "(", ")", ")", ";", "}" ]
Update existing endomondo Workout. @param Workout $workout @return Workout @throws EndomondoApiOldException when id of workout is not set
[ "Update", "existing", "endomondo", "Workout", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L188-L230
229,990
fabulator/endomondo-api-old
lib/Fabulator/Endomondo/EndomondoApiOld.php
EndomondoApiOld.bigRandomNumber
private function bigRandomNumber($randNumberLength) { $randNumber = null; for ($i = 0; $i < $randNumberLength; $i++) { $randNumber .= rand(0, 9); } return $randNumber; }
php
private function bigRandomNumber($randNumberLength) { $randNumber = null; for ($i = 0; $i < $randNumberLength; $i++) { $randNumber .= rand(0, 9); } return $randNumber; }
[ "private", "function", "bigRandomNumber", "(", "$", "randNumberLength", ")", "{", "$", "randNumber", "=", "null", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "randNumberLength", ";", "$", "i", "++", ")", "{", "$", "randNumber", ".=", "rand", "(", "0", ",", "9", ")", ";", "}", "return", "$", "randNumber", ";", "}" ]
Generate really long number. @param int $randNumberLength @return string
[ "Generate", "really", "long", "number", "." ]
c06871902f23ca9f40a7465cbecaf750a8114fa0
https://github.com/fabulator/endomondo-api-old/blob/c06871902f23ca9f40a7465cbecaf750a8114fa0/lib/Fabulator/Endomondo/EndomondoApiOld.php#L238-L247
229,991
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.initializeEnvironment
public function initializeEnvironment($applicationAbsolutePath) { $this->applicationAbsolutePath = $applicationAbsolutePath; $this->loadApplicationConfig(); $this->registerAppNamespace(); $this->initializeEnvironmentInternal(); $this->initializeComponentConfigurations(); $this->setErrorReporting(); }
php
public function initializeEnvironment($applicationAbsolutePath) { $this->applicationAbsolutePath = $applicationAbsolutePath; $this->loadApplicationConfig(); $this->registerAppNamespace(); $this->initializeEnvironmentInternal(); $this->initializeComponentConfigurations(); $this->setErrorReporting(); }
[ "public", "function", "initializeEnvironment", "(", "$", "applicationAbsolutePath", ")", "{", "$", "this", "->", "applicationAbsolutePath", "=", "$", "applicationAbsolutePath", ";", "$", "this", "->", "loadApplicationConfig", "(", ")", ";", "$", "this", "->", "registerAppNamespace", "(", ")", ";", "$", "this", "->", "initializeEnvironmentInternal", "(", ")", ";", "$", "this", "->", "initializeComponentConfigurations", "(", ")", ";", "$", "this", "->", "setErrorReporting", "(", ")", ";", "}" ]
Initializes the environment and loads all the configurations from it. @param string $applicationAbsolutePath Absolute path to the root of the application. @throws BootstrapException
[ "Initializes", "the", "environment", "and", "loads", "all", "the", "configurations", "from", "it", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L83-L92
229,992
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.getCurrentEnvironmentName
public function getCurrentEnvironmentName() { if (!empty($this->currentEnvironmentName)) { return $this->currentEnvironmentName; } // get current environments $environments = $this->applicationConfig->get('Application.Environments', false); if($environments){ // get current url $currentUrl = $this->str($this->httpRequest()->getCurrentUrl()); // loop over all registered environments in the config, and try to match the current based on the domain foreach ($environments as $eName => $e) { if ($currentUrl->contains($e->Domain)) { $this->currentEnvironmentName = $eName; } } } if (empty($this->currentEnvironmentName)) { $this->currentEnvironmentName = 'Production'; } return $this->currentEnvironmentName; }
php
public function getCurrentEnvironmentName() { if (!empty($this->currentEnvironmentName)) { return $this->currentEnvironmentName; } // get current environments $environments = $this->applicationConfig->get('Application.Environments', false); if($environments){ // get current url $currentUrl = $this->str($this->httpRequest()->getCurrentUrl()); // loop over all registered environments in the config, and try to match the current based on the domain foreach ($environments as $eName => $e) { if ($currentUrl->contains($e->Domain)) { $this->currentEnvironmentName = $eName; } } } if (empty($this->currentEnvironmentName)) { $this->currentEnvironmentName = 'Production'; } return $this->currentEnvironmentName; }
[ "public", "function", "getCurrentEnvironmentName", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "currentEnvironmentName", ")", ")", "{", "return", "$", "this", "->", "currentEnvironmentName", ";", "}", "// get current environments", "$", "environments", "=", "$", "this", "->", "applicationConfig", "->", "get", "(", "'Application.Environments'", ",", "false", ")", ";", "if", "(", "$", "environments", ")", "{", "// get current url", "$", "currentUrl", "=", "$", "this", "->", "str", "(", "$", "this", "->", "httpRequest", "(", ")", "->", "getCurrentUrl", "(", ")", ")", ";", "// loop over all registered environments in the config, and try to match the current based on the domain", "foreach", "(", "$", "environments", "as", "$", "eName", "=>", "$", "e", ")", "{", "if", "(", "$", "currentUrl", "->", "contains", "(", "$", "e", "->", "Domain", ")", ")", "{", "$", "this", "->", "currentEnvironmentName", "=", "$", "eName", ";", "}", "}", "}", "if", "(", "empty", "(", "$", "this", "->", "currentEnvironmentName", ")", ")", "{", "$", "this", "->", "currentEnvironmentName", "=", "'Production'", ";", "}", "return", "$", "this", "->", "currentEnvironmentName", ";", "}" ]
Get the name of the current loaded environment. @return string @throws BootstrapException
[ "Get", "the", "name", "of", "the", "current", "loaded", "environment", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L130-L156
229,993
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.loadApplicationConfig
private function loadApplicationConfig() { // load the config try{ $this->applicationConfig = $this->config()->yaml($this->applicationAbsolutePath . 'App/Config/App.yaml'); }catch (\Exception $e){ throw new BootstrapException('Unable to read app config file: '.$this->applicationAbsolutePath . 'App/Config/App.yaml'); } }
php
private function loadApplicationConfig() { // load the config try{ $this->applicationConfig = $this->config()->yaml($this->applicationAbsolutePath . 'App/Config/App.yaml'); }catch (\Exception $e){ throw new BootstrapException('Unable to read app config file: '.$this->applicationAbsolutePath . 'App/Config/App.yaml'); } }
[ "private", "function", "loadApplicationConfig", "(", ")", "{", "// load the config", "try", "{", "$", "this", "->", "applicationConfig", "=", "$", "this", "->", "config", "(", ")", "->", "yaml", "(", "$", "this", "->", "applicationAbsolutePath", ".", "'App/Config/App.yaml'", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "BootstrapException", "(", "'Unable to read app config file: '", ".", "$", "this", "->", "applicationAbsolutePath", ".", "'App/Config/App.yaml'", ")", ";", "}", "}" ]
Loads application configuration.
[ "Loads", "application", "configuration", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L172-L181
229,994
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.initializeEnvironmentInternal
private function initializeEnvironmentInternal() { // validate the environment $environments = $this->applicationConfig->get('Application.Environments', false); if($environments){ // get the production environment $productionEnv = $environments->get('Production', false); if (!$productionEnv) { throw new BootstrapException('Production environment must always be defined in App/Config/App.yaml'); } } // get the name of the current environment $currentEnvName = $this->getCurrentEnvironmentName(); // load the production environment configs $this->componentConfigs = $this->loadConfigurations('Production'); // check if the current env is different from Production if ($currentEnvName != 'Production') { $currentConfigs = $this->loadConfigurations($currentEnvName); $this->componentConfigs->mergeWith($currentConfigs); } }
php
private function initializeEnvironmentInternal() { // validate the environment $environments = $this->applicationConfig->get('Application.Environments', false); if($environments){ // get the production environment $productionEnv = $environments->get('Production', false); if (!$productionEnv) { throw new BootstrapException('Production environment must always be defined in App/Config/App.yaml'); } } // get the name of the current environment $currentEnvName = $this->getCurrentEnvironmentName(); // load the production environment configs $this->componentConfigs = $this->loadConfigurations('Production'); // check if the current env is different from Production if ($currentEnvName != 'Production') { $currentConfigs = $this->loadConfigurations($currentEnvName); $this->componentConfigs->mergeWith($currentConfigs); } }
[ "private", "function", "initializeEnvironmentInternal", "(", ")", "{", "// validate the environment", "$", "environments", "=", "$", "this", "->", "applicationConfig", "->", "get", "(", "'Application.Environments'", ",", "false", ")", ";", "if", "(", "$", "environments", ")", "{", "// get the production environment", "$", "productionEnv", "=", "$", "environments", "->", "get", "(", "'Production'", ",", "false", ")", ";", "if", "(", "!", "$", "productionEnv", ")", "{", "throw", "new", "BootstrapException", "(", "'Production environment must always be defined in App/Config/App.yaml'", ")", ";", "}", "}", "// get the name of the current environment", "$", "currentEnvName", "=", "$", "this", "->", "getCurrentEnvironmentName", "(", ")", ";", "// load the production environment configs", "$", "this", "->", "componentConfigs", "=", "$", "this", "->", "loadConfigurations", "(", "'Production'", ")", ";", "// check if the current env is different from Production", "if", "(", "$", "currentEnvName", "!=", "'Production'", ")", "{", "$", "currentConfigs", "=", "$", "this", "->", "loadConfigurations", "(", "$", "currentEnvName", ")", ";", "$", "this", "->", "componentConfigs", "->", "mergeWith", "(", "$", "currentConfigs", ")", ";", "}", "}" ]
Initializes current environment. Method detect the current environment and loads all the configurations from it. @throws BootstrapException @throws \Webiny\Component\Config\ConfigException
[ "Initializes", "current", "environment", ".", "Method", "detect", "the", "current", "environment", "and", "loads", "all", "the", "configurations", "from", "it", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L190-L214
229,995
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.setErrorReporting
private function setErrorReporting() { // set error reporting $errorReporting = $this->applicationConfig->get('Application.Environments.' . $this->getCurrentEnvironmentName( ) . '.ErrorReporting', 'off' ); if (strtolower($errorReporting) == 'on') { error_reporting(E_ALL); } else { error_reporting(E_ALL); } }
php
private function setErrorReporting() { // set error reporting $errorReporting = $this->applicationConfig->get('Application.Environments.' . $this->getCurrentEnvironmentName( ) . '.ErrorReporting', 'off' ); if (strtolower($errorReporting) == 'on') { error_reporting(E_ALL); } else { error_reporting(E_ALL); } }
[ "private", "function", "setErrorReporting", "(", ")", "{", "// set error reporting", "$", "errorReporting", "=", "$", "this", "->", "applicationConfig", "->", "get", "(", "'Application.Environments.'", ".", "$", "this", "->", "getCurrentEnvironmentName", "(", ")", ".", "'.ErrorReporting'", ",", "'off'", ")", ";", "if", "(", "strtolower", "(", "$", "errorReporting", ")", "==", "'on'", ")", "{", "error_reporting", "(", "E_ALL", ")", ";", "}", "else", "{", "error_reporting", "(", "E_ALL", ")", ";", "}", "}" ]
Sets the error reporting based on the environment. @throws BootstrapException
[ "Sets", "the", "error", "reporting", "based", "on", "the", "environment", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L221-L232
229,996
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.registerAppNamespace
private function registerAppNamespace() { // get app namespace $namespace = $this->applicationConfig->get('Application.Namespace', false); if (!$namespace) { throw new BootstrapException('Unable to register application namespace. You must define the application namespace in your App.yaml config file.'); } try{ // register the namespace ClassLoader::getInstance()->registerMap([$namespace => $this->applicationAbsolutePath.'App']); }catch (\Exception $e){ throw new BootstrapException('Unable to register application ('.$namespace.' => '.$this->applicationAbsolutePath.'App'.') namespace with ClassLoader.'); } }
php
private function registerAppNamespace() { // get app namespace $namespace = $this->applicationConfig->get('Application.Namespace', false); if (!$namespace) { throw new BootstrapException('Unable to register application namespace. You must define the application namespace in your App.yaml config file.'); } try{ // register the namespace ClassLoader::getInstance()->registerMap([$namespace => $this->applicationAbsolutePath.'App']); }catch (\Exception $e){ throw new BootstrapException('Unable to register application ('.$namespace.' => '.$this->applicationAbsolutePath.'App'.') namespace with ClassLoader.'); } }
[ "private", "function", "registerAppNamespace", "(", ")", "{", "// get app namespace", "$", "namespace", "=", "$", "this", "->", "applicationConfig", "->", "get", "(", "'Application.Namespace'", ",", "false", ")", ";", "if", "(", "!", "$", "namespace", ")", "{", "throw", "new", "BootstrapException", "(", "'Unable to register application namespace. You must define the application namespace in your App.yaml config file.'", ")", ";", "}", "try", "{", "// register the namespace", "ClassLoader", "::", "getInstance", "(", ")", "->", "registerMap", "(", "[", "$", "namespace", "=>", "$", "this", "->", "applicationAbsolutePath", ".", "'App'", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "BootstrapException", "(", "'Unable to register application ('", ".", "$", "namespace", ".", "' => '", ".", "$", "this", "->", "applicationAbsolutePath", ".", "'App'", ".", "') namespace with ClassLoader.'", ")", ";", "}", "}" ]
Registers the application namespace with the ClassLoader component. @throws BootstrapException
[ "Registers", "the", "application", "namespace", "with", "the", "ClassLoader", "component", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L239-L254
229,997
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.initializeComponentConfigurations
private function initializeComponentConfigurations() { foreach ($this->webinyComponents as $c) { $componentConfig = $this->componentConfigs->get($c, false); if ($componentConfig) { $class = 'Webiny\Component\\' . $c . '\\' . $c; $method = 'setConfig'; try { $class::$method($componentConfig); } catch (\Exception $e) { // ignore it ... probably user-based component } } } }
php
private function initializeComponentConfigurations() { foreach ($this->webinyComponents as $c) { $componentConfig = $this->componentConfigs->get($c, false); if ($componentConfig) { $class = 'Webiny\Component\\' . $c . '\\' . $c; $method = 'setConfig'; try { $class::$method($componentConfig); } catch (\Exception $e) { // ignore it ... probably user-based component } } } }
[ "private", "function", "initializeComponentConfigurations", "(", ")", "{", "foreach", "(", "$", "this", "->", "webinyComponents", "as", "$", "c", ")", "{", "$", "componentConfig", "=", "$", "this", "->", "componentConfigs", "->", "get", "(", "$", "c", ",", "false", ")", ";", "if", "(", "$", "componentConfig", ")", "{", "$", "class", "=", "'Webiny\\Component\\\\'", ".", "$", "c", ".", "'\\\\'", ".", "$", "c", ";", "$", "method", "=", "'setConfig'", ";", "try", "{", "$", "class", "::", "$", "method", "(", "$", "componentConfig", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// ignore it ... probably user-based component", "}", "}", "}", "}" ]
Initializes component configurations. Component configurations are all the configurations inside the specific environment. If configuration name matches a Webiny Framework component, then the configuration is automatically assigned to that component.
[ "Initializes", "component", "configurations", ".", "Component", "configurations", "are", "all", "the", "configurations", "inside", "the", "specific", "environment", ".", "If", "configuration", "name", "matches", "a", "Webiny", "Framework", "component", "then", "the", "configuration", "is", "automatically", "assigned", "to", "that", "component", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L262-L276
229,998
Webiny/Framework
src/Webiny/Component/Bootstrap/Environment.php
Environment.loadConfigurations
private function loadConfigurations($environment) { $configs = new ConfigObject([]); $configFolder = $this->applicationAbsolutePath . 'App/Config/' . $environment; $h = scandir($configFolder); foreach ($h as $configFile) { if (strpos($configFile, 'yaml') === false) { continue; } $configs->mergeWith($this->config()->yaml($configFolder . DIRECTORY_SEPARATOR . $configFile)); } return $configs; }
php
private function loadConfigurations($environment) { $configs = new ConfigObject([]); $configFolder = $this->applicationAbsolutePath . 'App/Config/' . $environment; $h = scandir($configFolder); foreach ($h as $configFile) { if (strpos($configFile, 'yaml') === false) { continue; } $configs->mergeWith($this->config()->yaml($configFolder . DIRECTORY_SEPARATOR . $configFile)); } return $configs; }
[ "private", "function", "loadConfigurations", "(", "$", "environment", ")", "{", "$", "configs", "=", "new", "ConfigObject", "(", "[", "]", ")", ";", "$", "configFolder", "=", "$", "this", "->", "applicationAbsolutePath", ".", "'App/Config/'", ".", "$", "environment", ";", "$", "h", "=", "scandir", "(", "$", "configFolder", ")", ";", "foreach", "(", "$", "h", "as", "$", "configFile", ")", "{", "if", "(", "strpos", "(", "$", "configFile", ",", "'yaml'", ")", "===", "false", ")", "{", "continue", ";", "}", "$", "configs", "->", "mergeWith", "(", "$", "this", "->", "config", "(", ")", "->", "yaml", "(", "$", "configFolder", ".", "DIRECTORY_SEPARATOR", ".", "$", "configFile", ")", ")", ";", "}", "return", "$", "configs", ";", "}" ]
Loads all the configurations from a specific environment. @param string $environment Environment name. @return ConfigObject @throws \Webiny\Component\Config\ConfigException
[ "Loads", "all", "the", "configurations", "from", "a", "specific", "environment", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Bootstrap/Environment.php#L286-L301
229,999
Webiny/Framework
src/Webiny/Component/Security/Authorization/AccessControl.php
AccessControl.isUserAllowedAccess
public function isUserAllowedAccess() { $requestedRoles = $this->getRequestedRoles(); // we allow access if there are no requested roles that the user must have if (count($requestedRoles) < 1) { return true; } return $this->getAccessDecision($requestedRoles); }
php
public function isUserAllowedAccess() { $requestedRoles = $this->getRequestedRoles(); // we allow access if there are no requested roles that the user must have if (count($requestedRoles) < 1) { return true; } return $this->getAccessDecision($requestedRoles); }
[ "public", "function", "isUserAllowedAccess", "(", ")", "{", "$", "requestedRoles", "=", "$", "this", "->", "getRequestedRoles", "(", ")", ";", "// we allow access if there are no requested roles that the user must have", "if", "(", "count", "(", "$", "requestedRoles", ")", "<", "1", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "getAccessDecision", "(", "$", "requestedRoles", ")", ";", "}" ]
Checks if current user is allowed access. @return bool
[ "Checks", "if", "current", "user", "is", "allowed", "access", "." ]
2ca7fb238999387e54a1eea8c5cb4735de9022a7
https://github.com/Webiny/Framework/blob/2ca7fb238999387e54a1eea8c5cb4735de9022a7/src/Webiny/Component/Security/Authorization/AccessControl.php#L76-L86