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
sequence
docstring
stringlengths
3
47.2k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
91
247
11,300
ARCANESOFT/Core
src/CoreServiceProvider.php
CoreServiceProvider.registerArcanesoftDatabase
private function registerArcanesoftDatabase() { // Keep it or using a real DBMS ? $connection = $this->config()->get('core.database.default', 'sqlite'); $this->config()->set( 'database.connections.arcanesoft', $this->config()->get("core.database.connections.{$connection}") ); }
php
private function registerArcanesoftDatabase() { // Keep it or using a real DBMS ? $connection = $this->config()->get('core.database.default', 'sqlite'); $this->config()->set( 'database.connections.arcanesoft', $this->config()->get("core.database.connections.{$connection}") ); }
[ "private", "function", "registerArcanesoftDatabase", "(", ")", "{", "// Keep it or using a real DBMS ?", "$", "connection", "=", "$", "this", "->", "config", "(", ")", "->", "get", "(", "'core.database.default'", ",", "'sqlite'", ")", ";", "$", "this", "->", "config", "(", ")", "->", "set", "(", "'database.connections.arcanesoft'", ",", "$", "this", "->", "config", "(", ")", "->", "get", "(", "\"core.database.connections.{$connection}\"", ")", ")", ";", "}" ]
Register Foundation database.
[ "Register", "Foundation", "database", "." ]
d0798074d47785cf0a768f51d82c0315363213be
https://github.com/ARCANESOFT/Core/blob/d0798074d47785cf0a768f51d82c0315363213be/src/CoreServiceProvider.php#L84-L93
11,301
tenside/core
src/Config/TensideJsonConfig.php
TensideJsonConfig.addCommandLineArgument
public function addCommandLineArgument($argument) { $args = (array) $this->getPhpCliArguments(); $this->setPhpCliArguments(array_merge($args, [$argument])); return $this; }
php
public function addCommandLineArgument($argument) { $args = (array) $this->getPhpCliArguments(); $this->setPhpCliArguments(array_merge($args, [$argument])); return $this; }
[ "public", "function", "addCommandLineArgument", "(", "$", "argument", ")", "{", "$", "args", "=", "(", "array", ")", "$", "this", "->", "getPhpCliArguments", "(", ")", ";", "$", "this", "->", "setPhpCliArguments", "(", "array_merge", "(", "$", "args", ",", "[", "$", "argument", "]", ")", ")", ";", "return", "$", "this", ";", "}" ]
Add a command line argument. @param string $argument The argument to add. @return TensideJsonConfig
[ "Add", "a", "command", "line", "argument", "." ]
56422fa8cdecf03cb431bb6654c2942ade39bf7b
https://github.com/tenside/core/blob/56422fa8cdecf03cb431bb6654c2942ade39bf7b/src/Config/TensideJsonConfig.php#L132-L138
11,302
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.fromFloat
public static function fromFloat($float_value, $precision = null) { if ($precision === null) { $precision = static::$PRECISION; } // left of decimal point $rounded_float = intval(round($float_value)); $big_integer_int = (new BigInt($rounded_float))->multiply(self::precisionUnitsAsBigInt(1, $precision)); // right of decimal point $rounded_decimal = intval(round(floatval($float_value - $rounded_float) * pow(10, $precision))); $big_integer_decimal = new BigInt($rounded_decimal); // add the integer value and the decimal value return new static($big_integer_int->add($big_integer_decimal), $precision); }
php
public static function fromFloat($float_value, $precision = null) { if ($precision === null) { $precision = static::$PRECISION; } // left of decimal point $rounded_float = intval(round($float_value)); $big_integer_int = (new BigInt($rounded_float))->multiply(self::precisionUnitsAsBigInt(1, $precision)); // right of decimal point $rounded_decimal = intval(round(floatval($float_value - $rounded_float) * pow(10, $precision))); $big_integer_decimal = new BigInt($rounded_decimal); // add the integer value and the decimal value return new static($big_integer_int->add($big_integer_decimal), $precision); }
[ "public", "static", "function", "fromFloat", "(", "$", "float_value", ",", "$", "precision", "=", "null", ")", "{", "if", "(", "$", "precision", "===", "null", ")", "{", "$", "precision", "=", "static", "::", "$", "PRECISION", ";", "}", "// left of decimal point", "$", "rounded_float", "=", "intval", "(", "round", "(", "$", "float_value", ")", ")", ";", "$", "big_integer_int", "=", "(", "new", "BigInt", "(", "$", "rounded_float", ")", ")", "->", "multiply", "(", "self", "::", "precisionUnitsAsBigInt", "(", "1", ",", "$", "precision", ")", ")", ";", "// right of decimal point", "$", "rounded_decimal", "=", "intval", "(", "round", "(", "floatval", "(", "$", "float_value", "-", "$", "rounded_float", ")", "*", "pow", "(", "10", ",", "$", "precision", ")", ")", ")", ";", "$", "big_integer_decimal", "=", "new", "BigInt", "(", "$", "rounded_decimal", ")", ";", "// add the integer value and the decimal value", "return", "new", "static", "(", "$", "big_integer_int", "->", "add", "(", "$", "big_integer_decimal", ")", ",", "$", "precision", ")", ";", "}" ]
Creates a new quantity from a float value @param float $float_value The amount as a float @param integer $precision Number of decimal places of precision @return CryptoQuantity The new CryptoQuantity object
[ "Creates", "a", "new", "quantity", "from", "a", "float", "value" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L26-L42
11,303
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.fromCryptoQuantity
public static function fromCryptoQuantity(CryptoQuantity $source_quantity, $precision = null) { if ($precision === null) { $precision = static::$PRECISION; } $round_up = false; $source_precision = $source_quantity->getPrecision(); $precision_delta = $precision - $source_precision; if ($precision_delta > 0) { // add zeros $satoshis_string = $source_quantity->getSatoshisString().str_repeat('0', $precision_delta); } else if ($precision_delta < 0) { // remove digits and check for rounding // (divide by 10e{$precision_delta}) $satoshis_string = $source_quantity->getSatoshisString(); $round_digit = substr($satoshis_string, $precision_delta, 1); $satoshis_string = substr($satoshis_string, 0, $precision_delta); $round_up = ($round_digit >= 5); } else { return clone $source_quantity; } $new_quantity = static::fromSatoshis($satoshis_string, $precision); if ($round_up) { $new_quantity = $new_quantity->add(new BigInt(1)); } return $new_quantity; }
php
public static function fromCryptoQuantity(CryptoQuantity $source_quantity, $precision = null) { if ($precision === null) { $precision = static::$PRECISION; } $round_up = false; $source_precision = $source_quantity->getPrecision(); $precision_delta = $precision - $source_precision; if ($precision_delta > 0) { // add zeros $satoshis_string = $source_quantity->getSatoshisString().str_repeat('0', $precision_delta); } else if ($precision_delta < 0) { // remove digits and check for rounding // (divide by 10e{$precision_delta}) $satoshis_string = $source_quantity->getSatoshisString(); $round_digit = substr($satoshis_string, $precision_delta, 1); $satoshis_string = substr($satoshis_string, 0, $precision_delta); $round_up = ($round_digit >= 5); } else { return clone $source_quantity; } $new_quantity = static::fromSatoshis($satoshis_string, $precision); if ($round_up) { $new_quantity = $new_quantity->add(new BigInt(1)); } return $new_quantity; }
[ "public", "static", "function", "fromCryptoQuantity", "(", "CryptoQuantity", "$", "source_quantity", ",", "$", "precision", "=", "null", ")", "{", "if", "(", "$", "precision", "===", "null", ")", "{", "$", "precision", "=", "static", "::", "$", "PRECISION", ";", "}", "$", "round_up", "=", "false", ";", "$", "source_precision", "=", "$", "source_quantity", "->", "getPrecision", "(", ")", ";", "$", "precision_delta", "=", "$", "precision", "-", "$", "source_precision", ";", "if", "(", "$", "precision_delta", ">", "0", ")", "{", "// add zeros", "$", "satoshis_string", "=", "$", "source_quantity", "->", "getSatoshisString", "(", ")", ".", "str_repeat", "(", "'0'", ",", "$", "precision_delta", ")", ";", "}", "else", "if", "(", "$", "precision_delta", "<", "0", ")", "{", "// remove digits and check for rounding", "// (divide by 10e{$precision_delta})", "$", "satoshis_string", "=", "$", "source_quantity", "->", "getSatoshisString", "(", ")", ";", "$", "round_digit", "=", "substr", "(", "$", "satoshis_string", ",", "$", "precision_delta", ",", "1", ")", ";", "$", "satoshis_string", "=", "substr", "(", "$", "satoshis_string", ",", "0", ",", "$", "precision_delta", ")", ";", "$", "round_up", "=", "(", "$", "round_digit", ">=", "5", ")", ";", "}", "else", "{", "return", "clone", "$", "source_quantity", ";", "}", "$", "new_quantity", "=", "static", "::", "fromSatoshis", "(", "$", "satoshis_string", ",", "$", "precision", ")", ";", "if", "(", "$", "round_up", ")", "{", "$", "new_quantity", "=", "$", "new_quantity", "->", "add", "(", "new", "BigInt", "(", "1", ")", ")", ";", "}", "return", "$", "new_quantity", ";", "}" ]
Creates an asset quantity from another cryptoquantity and adjusts the precision This will round if the new precision is smaller than the previous precision @param Math_BigInteger $big_integer The amount as a big integer object @param integer $precision Number of decimal places of precision @return CryptoQuantity The new CryptoQuantity object
[ "Creates", "an", "asset", "quantity", "from", "another", "cryptoquantity", "and", "adjusts", "the", "precision", "This", "will", "round", "if", "the", "new", "precision", "is", "smaller", "than", "the", "previous", "precision" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L103-L131
11,304
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.unserialize
public static function unserialize($serialized_quantity) { if (is_array($serialized_quantity)) { $json_array = $serialized_quantity; } else if (is_object($serialized_quantity)) { $json_array = json_decode(json_encode($serialized_quantity), true); } else { $json_array = json_decode($serialized_quantity, true); } if (!is_array($json_array)) { throw new Exception("Invalid serialized quantity", 1); } return static::fromSatoshis($json_array['value'], $json_array['precision']); }
php
public static function unserialize($serialized_quantity) { if (is_array($serialized_quantity)) { $json_array = $serialized_quantity; } else if (is_object($serialized_quantity)) { $json_array = json_decode(json_encode($serialized_quantity), true); } else { $json_array = json_decode($serialized_quantity, true); } if (!is_array($json_array)) { throw new Exception("Invalid serialized quantity", 1); } return static::fromSatoshis($json_array['value'], $json_array['precision']); }
[ "public", "static", "function", "unserialize", "(", "$", "serialized_quantity", ")", "{", "if", "(", "is_array", "(", "$", "serialized_quantity", ")", ")", "{", "$", "json_array", "=", "$", "serialized_quantity", ";", "}", "else", "if", "(", "is_object", "(", "$", "serialized_quantity", ")", ")", "{", "$", "json_array", "=", "json_decode", "(", "json_encode", "(", "$", "serialized_quantity", ")", ",", "true", ")", ";", "}", "else", "{", "$", "json_array", "=", "json_decode", "(", "$", "serialized_quantity", ",", "true", ")", ";", "}", "if", "(", "!", "is_array", "(", "$", "json_array", ")", ")", "{", "throw", "new", "Exception", "(", "\"Invalid serialized quantity\"", ",", "1", ")", ";", "}", "return", "static", "::", "fromSatoshis", "(", "$", "json_array", "[", "'value'", "]", ",", "$", "json_array", "[", "'precision'", "]", ")", ";", "}" ]
Unserialize a quantity object @param array $serialized_quantity Serialized quantity data @return CryptoQuantity The quantity class
[ "Unserialize", "a", "quantity", "object" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L139-L152
11,305
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.getFloatValue
public function getFloatValue() { list($quotient, $remainder) = $this->big_integer->divide(self::precisionUnitsAsBigInt(1, $this->precision)); return floatval($quotient->toString()) + floatval($remainder->toString() / pow(10, $this->precision)); }
php
public function getFloatValue() { list($quotient, $remainder) = $this->big_integer->divide(self::precisionUnitsAsBigInt(1, $this->precision)); return floatval($quotient->toString()) + floatval($remainder->toString() / pow(10, $this->precision)); }
[ "public", "function", "getFloatValue", "(", ")", "{", "list", "(", "$", "quotient", ",", "$", "remainder", ")", "=", "$", "this", "->", "big_integer", "->", "divide", "(", "self", "::", "precisionUnitsAsBigInt", "(", "1", ",", "$", "this", "->", "precision", ")", ")", ";", "return", "floatval", "(", "$", "quotient", "->", "toString", "(", ")", ")", "+", "floatval", "(", "$", "remainder", "->", "toString", "(", ")", "/", "pow", "(", "10", ",", "$", "this", "->", "precision", ")", ")", ";", "}" ]
Gets the amount as a float @return float A float representation of the value
[ "Gets", "the", "amount", "as", "a", "float" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L189-L193
11,306
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.gt
public function gt($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) > 0); }
php
public function gt($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) > 0); }
[ "public", "function", "gt", "(", "$", "other", ")", "{", "if", "(", "!", "(", "$", "other", "instanceof", "self", ")", ")", "{", "$", "other", "=", "new", "BigInt", "(", "$", "other", ")", ";", "}", "return", "(", "$", "this", "->", "compare", "(", "$", "other", ")", ">", "0", ")", ";", "}" ]
Returns true if greater than @param CryptoQuantity|int $other quantity to compare to @return boolean
[ "Returns", "true", "if", "greater", "than" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L210-L216
11,307
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.gte
public function gte($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) >= 0); }
php
public function gte($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) >= 0); }
[ "public", "function", "gte", "(", "$", "other", ")", "{", "if", "(", "!", "(", "$", "other", "instanceof", "self", ")", ")", "{", "$", "other", "=", "new", "BigInt", "(", "$", "other", ")", ";", "}", "return", "(", "$", "this", "->", "compare", "(", "$", "other", ")", ">=", "0", ")", ";", "}" ]
Returns true if greater than or equal to @param CryptoQuantity|int $other quantity to compare to @return boolean
[ "Returns", "true", "if", "greater", "than", "or", "equal", "to" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L223-L229
11,308
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.lt
public function lt($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) < 0); }
php
public function lt($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) < 0); }
[ "public", "function", "lt", "(", "$", "other", ")", "{", "if", "(", "!", "(", "$", "other", "instanceof", "self", ")", ")", "{", "$", "other", "=", "new", "BigInt", "(", "$", "other", ")", ";", "}", "return", "(", "$", "this", "->", "compare", "(", "$", "other", ")", "<", "0", ")", ";", "}" ]
Returns true if less than @param CryptoQuantity|int $other quantity to compare to @return boolean
[ "Returns", "true", "if", "less", "than" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L236-L242
11,309
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.lte
public function lte($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) <= 0); }
php
public function lte($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) <= 0); }
[ "public", "function", "lte", "(", "$", "other", ")", "{", "if", "(", "!", "(", "$", "other", "instanceof", "self", ")", ")", "{", "$", "other", "=", "new", "BigInt", "(", "$", "other", ")", ";", "}", "return", "(", "$", "this", "->", "compare", "(", "$", "other", ")", "<=", "0", ")", ";", "}" ]
Returns true if less than or equal to @param CryptoQuantity|int $other quantity to compare to @return boolean
[ "Returns", "true", "if", "less", "than", "or", "equal", "to" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L249-L255
11,310
tokenly/crypto-quantity
src/CryptoQuantity.php
CryptoQuantity.equals
public function equals($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) === 0); }
php
public function equals($other) { if (!($other instanceof self)) { $other = new BigInt($other); } return ($this->compare($other) === 0); }
[ "public", "function", "equals", "(", "$", "other", ")", "{", "if", "(", "!", "(", "$", "other", "instanceof", "self", ")", ")", "{", "$", "other", "=", "new", "BigInt", "(", "$", "other", ")", ";", "}", "return", "(", "$", "this", "->", "compare", "(", "$", "other", ")", "===", "0", ")", ";", "}" ]
Returns true if exactly equal to @param CryptoQuantity|int $other quantity to compare to @return boolean
[ "Returns", "true", "if", "exactly", "equal", "to" ]
81b7412b55c3cae1732de55d8e5118d17fb59900
https://github.com/tokenly/crypto-quantity/blob/81b7412b55c3cae1732de55d8e5118d17fb59900/src/CryptoQuantity.php#L271-L277
11,311
coolms/common
src/Form/Element/LocaleSelect.php
LocaleSelect.getLocaleList
public function getLocaleList() { if (null === $this->localeList) { $this->setLocaleList(LocaleUtils::getNamedList(Locale::getDefault())); } return $this->localeList; }
php
public function getLocaleList() { if (null === $this->localeList) { $this->setLocaleList(LocaleUtils::getNamedList(Locale::getDefault())); } return $this->localeList; }
[ "public", "function", "getLocaleList", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "localeList", ")", "{", "$", "this", "->", "setLocaleList", "(", "LocaleUtils", "::", "getNamedList", "(", "Locale", "::", "getDefault", "(", ")", ")", ")", ";", "}", "return", "$", "this", "->", "localeList", ";", "}" ]
Return the locale list for checking allowed locales Lazy loads one if none set @return array
[ "Return", "the", "locale", "list", "for", "checking", "allowed", "locales" ]
3572993cdcdb2898cdde396a2f1de9864b193660
https://github.com/coolms/common/blob/3572993cdcdb2898cdde396a2f1de9864b193660/src/Form/Element/LocaleSelect.php#L196-L203
11,312
jasny/application-env
src/ApplicationEnv.php
ApplicationEnv.is
public function is(string $env): bool { return $this->env === $env || str_starts_with($this->env, "$env."); }
php
public function is(string $env): bool { return $this->env === $env || str_starts_with($this->env, "$env."); }
[ "public", "function", "is", "(", "string", "$", "env", ")", ":", "bool", "{", "return", "$", "this", "->", "env", "===", "$", "env", "||", "str_starts_with", "(", "$", "this", "->", "env", ",", "\"$env.\"", ")", ";", "}" ]
Check if environment matches or is a parent. @param string $env @return bool
[ "Check", "if", "environment", "matches", "or", "is", "a", "parent", "." ]
b4780f6ee81cc3826b2e9acfe207d68a42848a75
https://github.com/jasny/application-env/blob/b4780f6ee81cc3826b2e9acfe207d68a42848a75/src/ApplicationEnv.php#L45-L48
11,313
jasny/application-env
src/ApplicationEnv.php
ApplicationEnv.getLevels
public function getLevels(int $from = 1, ?int $to = null, ?callable $callback = null): array { $parts = explode('.', $this->env); $n = isset($to) ? min(count($parts), $to) : count($parts); $levels = []; for ($i = $from; $i <= $n; $i++) { $level = join('.', array_slice($parts, 0, $i)); $levels[] = isset($callback) ? $callback($level) : $level; } return $levels; }
php
public function getLevels(int $from = 1, ?int $to = null, ?callable $callback = null): array { $parts = explode('.', $this->env); $n = isset($to) ? min(count($parts), $to) : count($parts); $levels = []; for ($i = $from; $i <= $n; $i++) { $level = join('.', array_slice($parts, 0, $i)); $levels[] = isset($callback) ? $callback($level) : $level; } return $levels; }
[ "public", "function", "getLevels", "(", "int", "$", "from", "=", "1", ",", "?", "int", "$", "to", "=", "null", ",", "?", "callable", "$", "callback", "=", "null", ")", ":", "array", "{", "$", "parts", "=", "explode", "(", "'.'", ",", "$", "this", "->", "env", ")", ";", "$", "n", "=", "isset", "(", "$", "to", ")", "?", "min", "(", "count", "(", "$", "parts", ")", ",", "$", "to", ")", ":", "count", "(", "$", "parts", ")", ";", "$", "levels", "=", "[", "]", ";", "for", "(", "$", "i", "=", "$", "from", ";", "$", "i", "<=", "$", "n", ";", "$", "i", "++", ")", "{", "$", "level", "=", "join", "(", "'.'", ",", "array_slice", "(", "$", "parts", ",", "0", ",", "$", "i", ")", ")", ";", "$", "levels", "[", "]", "=", "isset", "(", "$", "callback", ")", "?", "$", "callback", "(", "$", "level", ")", ":", "$", "level", ";", "}", "return", "$", "levels", ";", "}" ]
Traverse through each level of the application env. @param int $from @param int|null $to @param callable|null $callback @return array
[ "Traverse", "through", "each", "level", "of", "the", "application", "env", "." ]
b4780f6ee81cc3826b2e9acfe207d68a42848a75
https://github.com/jasny/application-env/blob/b4780f6ee81cc3826b2e9acfe207d68a42848a75/src/ApplicationEnv.php#L58-L71
11,314
adrianyg7/Acl
src/Policies/AclPolicy.php
AclPolicy.defineAbilities
public function defineAbilities() { $this->gate->before(function ($user, $ability) { if ($user->isSuperuser()) return true; }); foreach ($this->getPermissions() as $permission) { $this->gate->define($permission->name, function ($user) use ($permission) { return $user->hasPermission($permission->name); }); } }
php
public function defineAbilities() { $this->gate->before(function ($user, $ability) { if ($user->isSuperuser()) return true; }); foreach ($this->getPermissions() as $permission) { $this->gate->define($permission->name, function ($user) use ($permission) { return $user->hasPermission($permission->name); }); } }
[ "public", "function", "defineAbilities", "(", ")", "{", "$", "this", "->", "gate", "->", "before", "(", "function", "(", "$", "user", ",", "$", "ability", ")", "{", "if", "(", "$", "user", "->", "isSuperuser", "(", ")", ")", "return", "true", ";", "}", ")", ";", "foreach", "(", "$", "this", "->", "getPermissions", "(", ")", "as", "$", "permission", ")", "{", "$", "this", "->", "gate", "->", "define", "(", "$", "permission", "->", "name", ",", "function", "(", "$", "user", ")", "use", "(", "$", "permission", ")", "{", "return", "$", "user", "->", "hasPermission", "(", "$", "permission", "->", "name", ")", ";", "}", ")", ";", "}", "}" ]
Defines the Abilities for the application. @return void
[ "Defines", "the", "Abilities", "for", "the", "application", "." ]
b3d69199405ca7406b33991884f6bb2e6f85f4e5
https://github.com/adrianyg7/Acl/blob/b3d69199405ca7406b33991884f6bb2e6f85f4e5/src/Policies/AclPolicy.php#L83-L94
11,315
adrianyg7/Acl
src/Policies/AclPolicy.php
AclPolicy.passesAuthorization
public function passesAuthorization() { if ( ! $this->hasToBeAuthorized() ) return true; return $this->gate->allows($this->route->getName()); }
php
public function passesAuthorization() { if ( ! $this->hasToBeAuthorized() ) return true; return $this->gate->allows($this->route->getName()); }
[ "public", "function", "passesAuthorization", "(", ")", "{", "if", "(", "!", "$", "this", "->", "hasToBeAuthorized", "(", ")", ")", "return", "true", ";", "return", "$", "this", "->", "gate", "->", "allows", "(", "$", "this", "->", "route", "->", "getName", "(", ")", ")", ";", "}" ]
Authorizes a given route. @param Route $route @return bool
[ "Authorizes", "a", "given", "route", "." ]
b3d69199405ca7406b33991884f6bb2e6f85f4e5
https://github.com/adrianyg7/Acl/blob/b3d69199405ca7406b33991884f6bb2e6f85f4e5/src/Policies/AclPolicy.php#L114-L119
11,316
adrianyg7/Acl
src/Policies/AclPolicy.php
AclPolicy.hasToBeAuthorized
protected function hasToBeAuthorized() { if ( in_array($this->route->getName(), self::$except) ) return false; return (bool) $this->route->getName(); }
php
protected function hasToBeAuthorized() { if ( in_array($this->route->getName(), self::$except) ) return false; return (bool) $this->route->getName(); }
[ "protected", "function", "hasToBeAuthorized", "(", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "route", "->", "getName", "(", ")", ",", "self", "::", "$", "except", ")", ")", "return", "false", ";", "return", "(", "bool", ")", "$", "this", "->", "route", "->", "getName", "(", ")", ";", "}" ]
Determines if routes has to be authorized. @return bool
[ "Determines", "if", "routes", "has", "to", "be", "authorized", "." ]
b3d69199405ca7406b33991884f6bb2e6f85f4e5
https://github.com/adrianyg7/Acl/blob/b3d69199405ca7406b33991884f6bb2e6f85f4e5/src/Policies/AclPolicy.php#L126-L131
11,317
jmpantoja/planb-utils
src/DS/Stack/Stack.php
Stack.typed
public static function typed(string $type, iterable $input = []): Stack { $resolver = Resolver::typed($type); return new static($input, $resolver); }
php
public static function typed(string $type, iterable $input = []): Stack { $resolver = Resolver::typed($type); return new static($input, $resolver); }
[ "public", "static", "function", "typed", "(", "string", "$", "type", ",", "iterable", "$", "input", "=", "[", "]", ")", ":", "Stack", "{", "$", "resolver", "=", "Resolver", "::", "typed", "(", "$", "type", ")", ";", "return", "new", "static", "(", "$", "input", ",", "$", "resolver", ")", ";", "}" ]
Stack named constructor. @param string $type @param mixed[] $input @return \PlanB\DS\Stack\Stack
[ "Stack", "named", "constructor", "." ]
d17fbced4a285275928f8428ee56e269eb851690
https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/DS/Stack/Stack.php#L53-L58
11,318
nachonerd/silex-markdown-provider
src/Extensions/Markdown.php
Markdown.parseFile
public function parseFile($fileToParse) { $filename = $this->mdPath.$fileToParse; if (file_exists($filename)) { return $this->parse(file_get_contents($filename)); } throw new \NachoNerd\Silex\Markdown\Exceptions\FileNotFound( sprintf("File %s Not Found", $filename), 1 ); }
php
public function parseFile($fileToParse) { $filename = $this->mdPath.$fileToParse; if (file_exists($filename)) { return $this->parse(file_get_contents($filename)); } throw new \NachoNerd\Silex\Markdown\Exceptions\FileNotFound( sprintf("File %s Not Found", $filename), 1 ); }
[ "public", "function", "parseFile", "(", "$", "fileToParse", ")", "{", "$", "filename", "=", "$", "this", "->", "mdPath", ".", "$", "fileToParse", ";", "if", "(", "file_exists", "(", "$", "filename", ")", ")", "{", "return", "$", "this", "->", "parse", "(", "file_get_contents", "(", "$", "filename", ")", ")", ";", "}", "throw", "new", "\\", "NachoNerd", "\\", "Silex", "\\", "Markdown", "\\", "Exceptions", "\\", "FileNotFound", "(", "sprintf", "(", "\"File %s Not Found\"", ",", "$", "filename", ")", ",", "1", ")", ";", "}" ]
Parses the given file @param string $fileToParse File Name To Parse @return string @throws \NachoNerd\Silex\Markdown\Exceptions\FileNotFound
[ "Parses", "the", "given", "file" ]
a2e4528aecfb683766463f6e3e25b27b336c0952
https://github.com/nachonerd/silex-markdown-provider/blob/a2e4528aecfb683766463f6e3e25b27b336c0952/src/Extensions/Markdown.php#L138-L149
11,319
nachonerd/silex-markdown-provider
src/Extensions/Markdown.php
Markdown.getAllFiles
public function getAllFiles() { $finder = new Finder(); return $finder->files()->name($this->filter)->in($this->mdPath); }
php
public function getAllFiles() { $finder = new Finder(); return $finder->files()->name($this->filter)->in($this->mdPath); }
[ "public", "function", "getAllFiles", "(", ")", "{", "$", "finder", "=", "new", "Finder", "(", ")", ";", "return", "$", "finder", "->", "files", "(", ")", "->", "name", "(", "$", "this", "->", "filter", ")", "->", "in", "(", "$", "this", "->", "mdPath", ")", ";", "}" ]
Give All Files in directory given using filer given @return Symfony\Component\Finder\Finder
[ "Give", "All", "Files", "in", "directory", "given", "using", "filer", "given" ]
a2e4528aecfb683766463f6e3e25b27b336c0952
https://github.com/nachonerd/silex-markdown-provider/blob/a2e4528aecfb683766463f6e3e25b27b336c0952/src/Extensions/Markdown.php#L156-L160
11,320
nachonerd/silex-markdown-provider
src/Extensions/Markdown.php
Markdown.getNLastFiles
public function getNLastFiles($n) { $finder = new Finder(); $finder->files()->name( $this->filter )->in( $this->mdPath )->sortByModifiedTimeDesc(); return $finder->getNFirst($n); }
php
public function getNLastFiles($n) { $finder = new Finder(); $finder->files()->name( $this->filter )->in( $this->mdPath )->sortByModifiedTimeDesc(); return $finder->getNFirst($n); }
[ "public", "function", "getNLastFiles", "(", "$", "n", ")", "{", "$", "finder", "=", "new", "Finder", "(", ")", ";", "$", "finder", "->", "files", "(", ")", "->", "name", "(", "$", "this", "->", "filter", ")", "->", "in", "(", "$", "this", "->", "mdPath", ")", "->", "sortByModifiedTimeDesc", "(", ")", ";", "return", "$", "finder", "->", "getNFirst", "(", "$", "n", ")", ";", "}" ]
Give N Last Files in directory given using filer given @param integer $n Umpteenth Number @return Symfony\Component\Finder\Finder
[ "Give", "N", "Last", "Files", "in", "directory", "given", "using", "filer", "given" ]
a2e4528aecfb683766463f6e3e25b27b336c0952
https://github.com/nachonerd/silex-markdown-provider/blob/a2e4528aecfb683766463f6e3e25b27b336c0952/src/Extensions/Markdown.php#L169-L178
11,321
flowcode/AmulenShopBundle
src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php
AdminWarehouseController.transactionsAction
public function transactionsAction(Request $request) { $em = $this->getDoctrine()->getManager(); $changeLogFilter = $this->createForm(StockChangeLogFilterType::class, null, array( 'action' => $this->generateUrl('admin_warehouse_transactions'), 'method' => 'GET', )); $changeLogFilter->handleRequest($request); $filter = array(); $filter['product'] = $changeLogFilter->get('product')->getData(); $filter['warehouse'] = $changeLogFilter->get('warehouse')->getData(); $qb = $em->getRepository(StockChangeLog::class)->findAllFilteredQB($filter); $qb->addOrderBy('scl.id', "DESC"); $paginator = $this->get('knp_paginator')->paginate($qb, $request->query->get('page', 1), 20); return array( 'form_filter' => $changeLogFilter->createView(), 'paginator' => $paginator, ); }
php
public function transactionsAction(Request $request) { $em = $this->getDoctrine()->getManager(); $changeLogFilter = $this->createForm(StockChangeLogFilterType::class, null, array( 'action' => $this->generateUrl('admin_warehouse_transactions'), 'method' => 'GET', )); $changeLogFilter->handleRequest($request); $filter = array(); $filter['product'] = $changeLogFilter->get('product')->getData(); $filter['warehouse'] = $changeLogFilter->get('warehouse')->getData(); $qb = $em->getRepository(StockChangeLog::class)->findAllFilteredQB($filter); $qb->addOrderBy('scl.id', "DESC"); $paginator = $this->get('knp_paginator')->paginate($qb, $request->query->get('page', 1), 20); return array( 'form_filter' => $changeLogFilter->createView(), 'paginator' => $paginator, ); }
[ "public", "function", "transactionsAction", "(", "Request", "$", "request", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "changeLogFilter", "=", "$", "this", "->", "createForm", "(", "StockChangeLogFilterType", "::", "class", ",", "null", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'admin_warehouse_transactions'", ")", ",", "'method'", "=>", "'GET'", ",", ")", ")", ";", "$", "changeLogFilter", "->", "handleRequest", "(", "$", "request", ")", ";", "$", "filter", "=", "array", "(", ")", ";", "$", "filter", "[", "'product'", "]", "=", "$", "changeLogFilter", "->", "get", "(", "'product'", ")", "->", "getData", "(", ")", ";", "$", "filter", "[", "'warehouse'", "]", "=", "$", "changeLogFilter", "->", "get", "(", "'warehouse'", ")", "->", "getData", "(", ")", ";", "$", "qb", "=", "$", "em", "->", "getRepository", "(", "StockChangeLog", "::", "class", ")", "->", "findAllFilteredQB", "(", "$", "filter", ")", ";", "$", "qb", "->", "addOrderBy", "(", "'scl.id'", ",", "\"DESC\"", ")", ";", "$", "paginator", "=", "$", "this", "->", "get", "(", "'knp_paginator'", ")", "->", "paginate", "(", "$", "qb", ",", "$", "request", "->", "query", "->", "get", "(", "'page'", ",", "1", ")", ",", "20", ")", ";", "return", "array", "(", "'form_filter'", "=>", "$", "changeLogFilter", "->", "createView", "(", ")", ",", "'paginator'", "=>", "$", "paginator", ",", ")", ";", "}" ]
Lists all Warehouse entities. @Route("/transactions", name="admin_warehouse_transactions") @Method("GET") @Template()
[ "Lists", "all", "Warehouse", "entities", "." ]
500aaf4364be3c42fca69ecd10a449da03993814
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php#L50-L73
11,322
flowcode/AmulenShopBundle
src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php
AdminWarehouseController.showAction
public function showAction(Warehouse $warehouse) { $editForm = $this->createForm(WarehouseType::class, $warehouse, array( 'action' => $this->generateUrl('admin_warehouse_update', array('id' => $warehouse->getid())), 'method' => 'PUT', )); $deleteForm = $this->createDeleteForm($warehouse->getId(), 'admin_warehouse_update'); return array( 'warehouse' => $warehouse, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), ); }
php
public function showAction(Warehouse $warehouse) { $editForm = $this->createForm(WarehouseType::class, $warehouse, array( 'action' => $this->generateUrl('admin_warehouse_update', array('id' => $warehouse->getid())), 'method' => 'PUT', )); $deleteForm = $this->createDeleteForm($warehouse->getId(), 'admin_warehouse_update'); return array( 'warehouse' => $warehouse, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), ); }
[ "public", "function", "showAction", "(", "Warehouse", "$", "warehouse", ")", "{", "$", "editForm", "=", "$", "this", "->", "createForm", "(", "WarehouseType", "::", "class", ",", "$", "warehouse", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'admin_warehouse_update'", ",", "array", "(", "'id'", "=>", "$", "warehouse", "->", "getid", "(", ")", ")", ")", ",", "'method'", "=>", "'PUT'", ",", ")", ")", ";", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "warehouse", "->", "getId", "(", ")", ",", "'admin_warehouse_update'", ")", ";", "return", "array", "(", "'warehouse'", "=>", "$", "warehouse", ",", "'edit_form'", "=>", "$", "editForm", "->", "createView", "(", ")", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Finds and displays a Warehouse entity. @Route("/{id}/show", name="admin_warehouse_show", requirements={"id"="\d+"}) @Method("GET") @Template()
[ "Finds", "and", "displays", "a", "Warehouse", "entity", "." ]
500aaf4364be3c42fca69ecd10a449da03993814
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php#L82-L97
11,323
flowcode/AmulenShopBundle
src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php
AdminWarehouseController.newAction
public function newAction() { $warehouse = new Warehouse(); $form = $this->createForm(WarehouseType::class, $warehouse); return array( 'warehouse' => $warehouse, 'form' => $form->createView(), ); }
php
public function newAction() { $warehouse = new Warehouse(); $form = $this->createForm(WarehouseType::class, $warehouse); return array( 'warehouse' => $warehouse, 'form' => $form->createView(), ); }
[ "public", "function", "newAction", "(", ")", "{", "$", "warehouse", "=", "new", "Warehouse", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createForm", "(", "WarehouseType", "::", "class", ",", "$", "warehouse", ")", ";", "return", "array", "(", "'warehouse'", "=>", "$", "warehouse", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Displays a form to create a new Warehouse entity. @Route("/new", name="admin_warehouse_new") @Method("GET") @Template()
[ "Displays", "a", "form", "to", "create", "a", "new", "Warehouse", "entity", "." ]
500aaf4364be3c42fca69ecd10a449da03993814
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php#L106-L115
11,324
flowcode/AmulenShopBundle
src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php
AdminWarehouseController.createAction
public function createAction(Request $request) { $warehouse = new Warehouse(); $form = $this->createForm(WarehouseType::class, $warehouse); if ($form->handleRequest($request)->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($warehouse); $em->flush(); return $this->redirect($this->generateUrl('admin_warehouse_show', array('id' => $warehouse->getId()))); } return array( 'warehouse' => $warehouse, 'form' => $form->createView(), ); }
php
public function createAction(Request $request) { $warehouse = new Warehouse(); $form = $this->createForm(WarehouseType::class, $warehouse); if ($form->handleRequest($request)->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($warehouse); $em->flush(); return $this->redirect($this->generateUrl('admin_warehouse_show', array('id' => $warehouse->getId()))); } return array( 'warehouse' => $warehouse, 'form' => $form->createView(), ); }
[ "public", "function", "createAction", "(", "Request", "$", "request", ")", "{", "$", "warehouse", "=", "new", "Warehouse", "(", ")", ";", "$", "form", "=", "$", "this", "->", "createForm", "(", "WarehouseType", "::", "class", ",", "$", "warehouse", ")", ";", "if", "(", "$", "form", "->", "handleRequest", "(", "$", "request", ")", "->", "isValid", "(", ")", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "em", "->", "persist", "(", "$", "warehouse", ")", ";", "$", "em", "->", "flush", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'admin_warehouse_show'", ",", "array", "(", "'id'", "=>", "$", "warehouse", "->", "getId", "(", ")", ")", ")", ")", ";", "}", "return", "array", "(", "'warehouse'", "=>", "$", "warehouse", ",", "'form'", "=>", "$", "form", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Creates a new Warehouse entity. @Route("/create", name="admin_warehouse_create") @Method("POST") @Template("FlowcodeShopBundle:AdminWarehouse:new.html.twig")
[ "Creates", "a", "new", "Warehouse", "entity", "." ]
500aaf4364be3c42fca69ecd10a449da03993814
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php#L124-L140
11,325
flowcode/AmulenShopBundle
src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php
AdminWarehouseController.updateAction
public function updateAction(Warehouse $warehouse, Request $request) { $editForm = $this->createForm(new WarehouseType(), $warehouse, array( 'action' => $this->generateUrl('admin_warehouse_update', array('id' => $warehouse->getid())), 'method' => 'PUT', )); if ($editForm->handleRequest($request)->isValid()) { $this->getDoctrine()->getManager()->flush(); return $this->redirect($this->generateUrl('admin_warehouse_show', array('id' => $warehouse->getId()))); } $deleteForm = $this->createDeleteForm($warehouse->getId(), 'admin_warehouse_delete'); return array( 'warehouse' => $warehouse, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), ); }
php
public function updateAction(Warehouse $warehouse, Request $request) { $editForm = $this->createForm(new WarehouseType(), $warehouse, array( 'action' => $this->generateUrl('admin_warehouse_update', array('id' => $warehouse->getid())), 'method' => 'PUT', )); if ($editForm->handleRequest($request)->isValid()) { $this->getDoctrine()->getManager()->flush(); return $this->redirect($this->generateUrl('admin_warehouse_show', array('id' => $warehouse->getId()))); } $deleteForm = $this->createDeleteForm($warehouse->getId(), 'admin_warehouse_delete'); return array( 'warehouse' => $warehouse, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), ); }
[ "public", "function", "updateAction", "(", "Warehouse", "$", "warehouse", ",", "Request", "$", "request", ")", "{", "$", "editForm", "=", "$", "this", "->", "createForm", "(", "new", "WarehouseType", "(", ")", ",", "$", "warehouse", ",", "array", "(", "'action'", "=>", "$", "this", "->", "generateUrl", "(", "'admin_warehouse_update'", ",", "array", "(", "'id'", "=>", "$", "warehouse", "->", "getid", "(", ")", ")", ")", ",", "'method'", "=>", "'PUT'", ",", ")", ")", ";", "if", "(", "$", "editForm", "->", "handleRequest", "(", "$", "request", ")", "->", "isValid", "(", ")", ")", "{", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", "->", "flush", "(", ")", ";", "return", "$", "this", "->", "redirect", "(", "$", "this", "->", "generateUrl", "(", "'admin_warehouse_show'", ",", "array", "(", "'id'", "=>", "$", "warehouse", "->", "getId", "(", ")", ")", ")", ")", ";", "}", "$", "deleteForm", "=", "$", "this", "->", "createDeleteForm", "(", "$", "warehouse", "->", "getId", "(", ")", ",", "'admin_warehouse_delete'", ")", ";", "return", "array", "(", "'warehouse'", "=>", "$", "warehouse", ",", "'edit_form'", "=>", "$", "editForm", "->", "createView", "(", ")", ",", "'delete_form'", "=>", "$", "deleteForm", "->", "createView", "(", ")", ",", ")", ";", "}" ]
Edits an existing Warehouse entity. @Route("/{id}/update", name="admin_warehouse_update", requirements={"id"="\d+"}) @Method("PUT") @Template("FlowcodeShopBundle:AdminWarehouse:edit.html.twig")
[ "Edits", "an", "existing", "Warehouse", "entity", "." ]
500aaf4364be3c42fca69ecd10a449da03993814
https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/AdminWarehouseController.php#L171-L189
11,326
ArcanSecurity/skeerel-php
Skeerel/Util/Enum.php
Enum.equals
final public function equals(Enum $enum = null) { return $enum !== null && $this->getValue() === $enum->getValue() && \get_called_class() === \get_class($enum); }
php
final public function equals(Enum $enum = null) { return $enum !== null && $this->getValue() === $enum->getValue() && \get_called_class() === \get_class($enum); }
[ "final", "public", "function", "equals", "(", "Enum", "$", "enum", "=", "null", ")", "{", "return", "$", "enum", "!==", "null", "&&", "$", "this", "->", "getValue", "(", ")", "===", "$", "enum", "->", "getValue", "(", ")", "&&", "\\", "get_called_class", "(", ")", "===", "\\", "get_class", "(", "$", "enum", ")", ";", "}" ]
Compares one Enum with another. This method is final, for more information read https://github.com/myclabs/php-enum/issues/4 @return bool True if Enums are equal, false if not equal
[ "Compares", "one", "Enum", "with", "another", "." ]
67718734f31599e80e3cac1c4dec54f3836bb652
https://github.com/ArcanSecurity/skeerel-php/blob/67718734f31599e80e3cac1c4dec54f3836bb652/Skeerel/Util/Enum.php#L81-L84
11,327
ArcanSecurity/skeerel-php
Skeerel/Util/Enum.php
Enum.fromKey
public static function fromKey($name) { foreach (static::values() as $key => $enumInstance) { if ($enumInstance->getKey() === $name) { return $enumInstance; } } return null; }
php
public static function fromKey($name) { foreach (static::values() as $key => $enumInstance) { if ($enumInstance->getKey() === $name) { return $enumInstance; } } return null; }
[ "public", "static", "function", "fromKey", "(", "$", "name", ")", "{", "foreach", "(", "static", "::", "values", "(", ")", "as", "$", "key", "=>", "$", "enumInstance", ")", "{", "if", "(", "$", "enumInstance", "->", "getKey", "(", ")", "===", "$", "name", ")", "{", "return", "$", "enumInstance", ";", "}", "}", "return", "null", ";", "}" ]
Returns Enum by key @return static
[ "Returns", "Enum", "by", "key" ]
67718734f31599e80e3cac1c4dec54f3836bb652
https://github.com/ArcanSecurity/skeerel-php/blob/67718734f31599e80e3cac1c4dec54f3836bb652/Skeerel/Util/Enum.php#L246-L255
11,328
JoshuaEstes/Daedalus
src/Daedalus/Configuration/TaskConfiguration.php
TaskConfiguration.addTasksNode
protected function addTasksNode() { $builder = new TreeBuilder(); $node = $builder->root('tasks'); $node ->isRequired() ->requiresAtLeastOneElement() ->useAttributeAsKey('task') ->prototype('array') ->children() ->scalarNode('description')->defaultNull()->end() ->arrayNode('requires') ->useAttributeAsKey('task') ->prototype('scalar')->end() ->end() ->append($this->addCommandsNode()) ->end() ->end(); return $node; }
php
protected function addTasksNode() { $builder = new TreeBuilder(); $node = $builder->root('tasks'); $node ->isRequired() ->requiresAtLeastOneElement() ->useAttributeAsKey('task') ->prototype('array') ->children() ->scalarNode('description')->defaultNull()->end() ->arrayNode('requires') ->useAttributeAsKey('task') ->prototype('scalar')->end() ->end() ->append($this->addCommandsNode()) ->end() ->end(); return $node; }
[ "protected", "function", "addTasksNode", "(", ")", "{", "$", "builder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "node", "=", "$", "builder", "->", "root", "(", "'tasks'", ")", ";", "$", "node", "->", "isRequired", "(", ")", "->", "requiresAtLeastOneElement", "(", ")", "->", "useAttributeAsKey", "(", "'task'", ")", "->", "prototype", "(", "'array'", ")", "->", "children", "(", ")", "->", "scalarNode", "(", "'description'", ")", "->", "defaultNull", "(", ")", "->", "end", "(", ")", "->", "arrayNode", "(", "'requires'", ")", "->", "useAttributeAsKey", "(", "'task'", ")", "->", "prototype", "(", "'scalar'", ")", "->", "end", "(", ")", "->", "end", "(", ")", "->", "append", "(", "$", "this", "->", "addCommandsNode", "(", ")", ")", "->", "end", "(", ")", "->", "end", "(", ")", ";", "return", "$", "node", ";", "}" ]
Returns the tasks node
[ "Returns", "the", "tasks", "node" ]
4c898c41433242e46b30d45ebe03fdc91512b444
https://github.com/JoshuaEstes/Daedalus/blob/4c898c41433242e46b30d45ebe03fdc91512b444/src/Daedalus/Configuration/TaskConfiguration.php#L30-L51
11,329
JoshuaEstes/Daedalus
src/Daedalus/Configuration/TaskConfiguration.php
TaskConfiguration.addArgumentsNode
protected function addArgumentsNode() { $builder = new TreeBuilder(); $node = $builder->root('arguments'); $node ->prototype('variable') ->end(); return $node; }
php
protected function addArgumentsNode() { $builder = new TreeBuilder(); $node = $builder->root('arguments'); $node ->prototype('variable') ->end(); return $node; }
[ "protected", "function", "addArgumentsNode", "(", ")", "{", "$", "builder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "node", "=", "$", "builder", "->", "root", "(", "'arguments'", ")", ";", "$", "node", "->", "prototype", "(", "'variable'", ")", "->", "end", "(", ")", ";", "return", "$", "node", ";", "}" ]
Arguments that are passed to a command
[ "Arguments", "that", "are", "passed", "to", "a", "command" ]
4c898c41433242e46b30d45ebe03fdc91512b444
https://github.com/JoshuaEstes/Daedalus/blob/4c898c41433242e46b30d45ebe03fdc91512b444/src/Daedalus/Configuration/TaskConfiguration.php#L79-L89
11,330
JoshuaEstes/Daedalus
src/Daedalus/Configuration/TaskConfiguration.php
TaskConfiguration.addOptionsNode
protected function addOptionsNode() { $builder = new TreeBuilder(); $node = $builder->root('options'); $node ->prototype('variable') ->end(); return $node; }
php
protected function addOptionsNode() { $builder = new TreeBuilder(); $node = $builder->root('options'); $node ->prototype('variable') ->end(); return $node; }
[ "protected", "function", "addOptionsNode", "(", ")", "{", "$", "builder", "=", "new", "TreeBuilder", "(", ")", ";", "$", "node", "=", "$", "builder", "->", "root", "(", "'options'", ")", ";", "$", "node", "->", "prototype", "(", "'variable'", ")", "->", "end", "(", ")", ";", "return", "$", "node", ";", "}" ]
Options that are passed to a command
[ "Options", "that", "are", "passed", "to", "a", "command" ]
4c898c41433242e46b30d45ebe03fdc91512b444
https://github.com/JoshuaEstes/Daedalus/blob/4c898c41433242e46b30d45ebe03fdc91512b444/src/Daedalus/Configuration/TaskConfiguration.php#L94-L104
11,331
Sowapps/orpheus-publisher
src/Publisher/Transaction/TransactionOperationSet.php
TransactionOperationSet.validateOperations
protected function validateOperations() { $errors = 0; foreach( $this->operations as $operation ) { $operation->setTransactionOperationSet($this); $operation->validate($errors); } }
php
protected function validateOperations() { $errors = 0; foreach( $this->operations as $operation ) { $operation->setTransactionOperationSet($this); $operation->validate($errors); } }
[ "protected", "function", "validateOperations", "(", ")", "{", "$", "errors", "=", "0", ";", "foreach", "(", "$", "this", "->", "operations", "as", "$", "operation", ")", "{", "$", "operation", "->", "setTransactionOperationSet", "(", "$", "this", ")", ";", "$", "operation", "->", "validate", "(", "$", "errors", ")", ";", "}", "}" ]
Validate operations, before applying
[ "Validate", "operations", "before", "applying" ]
e33508538a0aa6f7491d724ca1cb09893203bfba
https://github.com/Sowapps/orpheus-publisher/blob/e33508538a0aa6f7491d724ca1cb09893203bfba/src/Publisher/Transaction/TransactionOperationSet.php#L78-L84
11,332
Sowapps/orpheus-publisher
src/Publisher/Transaction/TransactionOperationSet.php
TransactionOperationSet.runOperations
protected function runOperations() { foreach( $this->operations as $operation ) { $operation->setTransactionOperationSet($this); $operation->runIfValid(); } }
php
protected function runOperations() { foreach( $this->operations as $operation ) { $operation->setTransactionOperationSet($this); $operation->runIfValid(); } }
[ "protected", "function", "runOperations", "(", ")", "{", "foreach", "(", "$", "this", "->", "operations", "as", "$", "operation", ")", "{", "$", "operation", "->", "setTransactionOperationSet", "(", "$", "this", ")", ";", "$", "operation", "->", "runIfValid", "(", ")", ";", "}", "}" ]
Run operation, these will be applied into DBMS
[ "Run", "operation", "these", "will", "be", "applied", "into", "DBMS" ]
e33508538a0aa6f7491d724ca1cb09893203bfba
https://github.com/Sowapps/orpheus-publisher/blob/e33508538a0aa6f7491d724ca1cb09893203bfba/src/Publisher/Transaction/TransactionOperationSet.php#L89-L94
11,333
emaphp/eMapper
lib/eMapper/Result/Mapper/ArrayMapper.php
ArrayMapper.mapResult
public function mapResult(ResultIterator $result, $resultType = ArrayType::BOTH) { //check numer of rows returned if ($result->countRows() == 0) return null; //get result column types $this->columnTypes = $result->getColumnTypes($resultType); //validate result map (if any) if (isset($this->resultMap)) $this->buildTypeHandlerList(); //map row return $this->map($result->fetchArray($resultType)); }
php
public function mapResult(ResultIterator $result, $resultType = ArrayType::BOTH) { //check numer of rows returned if ($result->countRows() == 0) return null; //get result column types $this->columnTypes = $result->getColumnTypes($resultType); //validate result map (if any) if (isset($this->resultMap)) $this->buildTypeHandlerList(); //map row return $this->map($result->fetchArray($resultType)); }
[ "public", "function", "mapResult", "(", "ResultIterator", "$", "result", ",", "$", "resultType", "=", "ArrayType", "::", "BOTH", ")", "{", "//check numer of rows returned", "if", "(", "$", "result", "->", "countRows", "(", ")", "==", "0", ")", "return", "null", ";", "//get result column types", "$", "this", "->", "columnTypes", "=", "$", "result", "->", "getColumnTypes", "(", "$", "resultType", ")", ";", "//validate result map (if any)", "if", "(", "isset", "(", "$", "this", "->", "resultMap", ")", ")", "$", "this", "->", "buildTypeHandlerList", "(", ")", ";", "//map row", "return", "$", "this", "->", "map", "(", "$", "result", "->", "fetchArray", "(", "$", "resultType", ")", ")", ";", "}" ]
Returns a mapped array from a mysqli_result object @param \eMapper\Engine\Generic\Result\ResultIterator $result @param int $resultType
[ "Returns", "a", "mapped", "array", "from", "a", "mysqli_result", "object" ]
df7100e601d2a1363d07028a786b6ceb22271829
https://github.com/emaphp/eMapper/blob/df7100e601d2a1363d07028a786b6ceb22271829/lib/eMapper/Result/Mapper/ArrayMapper.php#L42-L56
11,334
DripsPHP/Debugger
src/Handler.php
Handler.handleError
public static function handleError($errno, $errstr, $errfile, $errline, $errcontext, $isException = false) { $error = array( 'number' => $errno, 'desc' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'isException' => $isException, ); $handled = false; if ($isException) { $handled = static::call(get_class($errcontext), $handled); } if (!$handled) { static::$errors[] = $error; } }
php
public static function handleError($errno, $errstr, $errfile, $errline, $errcontext, $isException = false) { $error = array( 'number' => $errno, 'desc' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'isException' => $isException, ); $handled = false; if ($isException) { $handled = static::call(get_class($errcontext), $handled); } if (!$handled) { static::$errors[] = $error; } }
[ "public", "static", "function", "handleError", "(", "$", "errno", ",", "$", "errstr", ",", "$", "errfile", ",", "$", "errline", ",", "$", "errcontext", ",", "$", "isException", "=", "false", ")", "{", "$", "error", "=", "array", "(", "'number'", "=>", "$", "errno", ",", "'desc'", "=>", "$", "errstr", ",", "'file'", "=>", "$", "errfile", ",", "'line'", "=>", "$", "errline", ",", "'context'", "=>", "$", "errcontext", ",", "'isException'", "=>", "$", "isException", ",", ")", ";", "$", "handled", "=", "false", ";", "if", "(", "$", "isException", ")", "{", "$", "handled", "=", "static", "::", "call", "(", "get_class", "(", "$", "errcontext", ")", ",", "$", "handled", ")", ";", "}", "if", "(", "!", "$", "handled", ")", "{", "static", "::", "$", "errors", "[", "]", "=", "$", "error", ";", "}", "}" ]
Dient zum Handeln von PHP-Fehlern @param int $errno @param string $errstr @param string $errfile @param int $errline @param mixed $errcontext @param bool $isException
[ "Dient", "zum", "Handeln", "von", "PHP", "-", "Fehlern" ]
750c133ef62861007b63c7fe07f6b32c53c6e96c
https://github.com/DripsPHP/Debugger/blob/750c133ef62861007b63c7fe07f6b32c53c6e96c/src/Handler.php#L40-L57
11,335
DripsPHP/Debugger
src/Handler.php
Handler.handleException
public static function handleException($exception) { static::handleError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception, true); }
php
public static function handleException($exception) { static::handleError($exception->getCode(), $exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception, true); }
[ "public", "static", "function", "handleException", "(", "$", "exception", ")", "{", "static", "::", "handleError", "(", "$", "exception", "->", "getCode", "(", ")", ",", "$", "exception", "->", "getMessage", "(", ")", ",", "$", "exception", "->", "getFile", "(", ")", ",", "$", "exception", "->", "getLine", "(", ")", ",", "$", "exception", ",", "true", ")", ";", "}" ]
Dient zum Handeln von Exceptions @param Exception $exception
[ "Dient", "zum", "Handeln", "von", "Exceptions" ]
750c133ef62861007b63c7fe07f6b32c53c6e96c
https://github.com/DripsPHP/Debugger/blob/750c133ef62861007b63c7fe07f6b32c53c6e96c/src/Handler.php#L64-L67
11,336
popy-dev/popy-calendar
src/Formatter/SymbolFormatter/Chain.php
Chain.addFormatter
public function addFormatter(SymbolFormatterInterface $formatter) { if ($formatter instanceof self) { // Reducing recursivity $this->addFormatters($formatter->formatters); } else { $this->formatters[] = $formatter; } return $this; }
php
public function addFormatter(SymbolFormatterInterface $formatter) { if ($formatter instanceof self) { // Reducing recursivity $this->addFormatters($formatter->formatters); } else { $this->formatters[] = $formatter; } return $this; }
[ "public", "function", "addFormatter", "(", "SymbolFormatterInterface", "$", "formatter", ")", "{", "if", "(", "$", "formatter", "instanceof", "self", ")", "{", "// Reducing recursivity", "$", "this", "->", "addFormatters", "(", "$", "formatter", "->", "formatters", ")", ";", "}", "else", "{", "$", "this", "->", "formatters", "[", "]", "=", "$", "formatter", ";", "}", "return", "$", "this", ";", "}" ]
Adds a formatter to the chain. @param SymbolFormatterInterface $formatter
[ "Adds", "a", "formatter", "to", "the", "chain", "." ]
989048be18451c813cfce926229c6aaddd1b0639
https://github.com/popy-dev/popy-calendar/blob/989048be18451c813cfce926229c6aaddd1b0639/src/Formatter/SymbolFormatter/Chain.php#L38-L48
11,337
osflab/view
Helper/Addon/MvcUrl.php
MvcUrl.setMvcUrl
public function setMvcUrl($controller = null, $action = null, array $params = []) { $this->mvcUrl = [ 'controller' => trim($controller), 'action' => trim($action), 'params' => $params ]; return $this; }
php
public function setMvcUrl($controller = null, $action = null, array $params = []) { $this->mvcUrl = [ 'controller' => trim($controller), 'action' => trim($action), 'params' => $params ]; return $this; }
[ "public", "function", "setMvcUrl", "(", "$", "controller", "=", "null", ",", "$", "action", "=", "null", ",", "array", "$", "params", "=", "[", "]", ")", "{", "$", "this", "->", "mvcUrl", "=", "[", "'controller'", "=>", "trim", "(", "$", "controller", ")", ",", "'action'", "=>", "trim", "(", "$", "action", ")", ",", "'params'", "=>", "$", "params", "]", ";", "return", "$", "this", ";", "}" ]
Define the MVC parameters of the url @param string $controller @param string $action @param array $params @return $this
[ "Define", "the", "MVC", "parameters", "of", "the", "url" ]
e06601013e8ec86dc2055e000e58dffd963c78e2
https://github.com/osflab/view/blob/e06601013e8ec86dc2055e000e58dffd963c78e2/Helper/Addon/MvcUrl.php#L38-L46
11,338
osflab/view
Helper/Addon/MvcUrl.php
MvcUrl.setMvcParam
public function setMvcParam(string $paramName, $value = null) { $value = $value === null ? null : trim($value); switch ($paramName) { case 'controller' : case 'action' : $this->mvcUrl[$paramName] = $value; break; default : $this->mvcUrl['params'][$paramName] = $value; break; } return $this; }
php
public function setMvcParam(string $paramName, $value = null) { $value = $value === null ? null : trim($value); switch ($paramName) { case 'controller' : case 'action' : $this->mvcUrl[$paramName] = $value; break; default : $this->mvcUrl['params'][$paramName] = $value; break; } return $this; }
[ "public", "function", "setMvcParam", "(", "string", "$", "paramName", ",", "$", "value", "=", "null", ")", "{", "$", "value", "=", "$", "value", "===", "null", "?", "null", ":", "trim", "(", "$", "value", ")", ";", "switch", "(", "$", "paramName", ")", "{", "case", "'controller'", ":", "case", "'action'", ":", "$", "this", "->", "mvcUrl", "[", "$", "paramName", "]", "=", "$", "value", ";", "break", ";", "default", ":", "$", "this", "->", "mvcUrl", "[", "'params'", "]", "[", "$", "paramName", "]", "=", "$", "value", ";", "break", ";", "}", "return", "$", "this", ";", "}" ]
Define a MVC parameter individually @param string $paramName @param string $value @return $this
[ "Define", "a", "MVC", "parameter", "individually" ]
e06601013e8ec86dc2055e000e58dffd963c78e2
https://github.com/osflab/view/blob/e06601013e8ec86dc2055e000e58dffd963c78e2/Helper/Addon/MvcUrl.php#L54-L67
11,339
jivoo/http
src/Router.php
Router.addScheme
public function addScheme(Route\Scheme $scheme) { foreach ($scheme->getPrefixes() as $prefix) { $this->schemePrefixes[$prefix] = $scheme; } foreach ($scheme->getKeys() as $key) { $this->schemeKeys[$key] = $scheme; } }
php
public function addScheme(Route\Scheme $scheme) { foreach ($scheme->getPrefixes() as $prefix) { $this->schemePrefixes[$prefix] = $scheme; } foreach ($scheme->getKeys() as $key) { $this->schemeKeys[$key] = $scheme; } }
[ "public", "function", "addScheme", "(", "Route", "\\", "Scheme", "$", "scheme", ")", "{", "foreach", "(", "$", "scheme", "->", "getPrefixes", "(", ")", "as", "$", "prefix", ")", "{", "$", "this", "->", "schemePrefixes", "[", "$", "prefix", "]", "=", "$", "scheme", ";", "}", "foreach", "(", "$", "scheme", "->", "getKeys", "(", ")", "as", "$", "key", ")", "{", "$", "this", "->", "schemeKeys", "[", "$", "key", "]", "=", "$", "scheme", ";", "}", "}" ]
Add a route scheme. @param \Jivoo\Http\Route\Scheme $scheme Scheme.
[ "Add", "a", "route", "scheme", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L84-L92
11,340
jivoo/http
src/Router.php
Router.addPath
public function addPath($route, array $pattern, $arity, $priority = 5) { $route = $this->validate($route); $key = $route->__toString() . '[' . $arity . ']'; if (isset($this->paths[$key])) { if ($priority < $this->paths[$key]['priority']) { return; } } $this->paths[$key] = [ 'pattern' => $pattern, 'priority' => $priority ]; }
php
public function addPath($route, array $pattern, $arity, $priority = 5) { $route = $this->validate($route); $key = $route->__toString() . '[' . $arity . ']'; if (isset($this->paths[$key])) { if ($priority < $this->paths[$key]['priority']) { return; } } $this->paths[$key] = [ 'pattern' => $pattern, 'priority' => $priority ]; }
[ "public", "function", "addPath", "(", "$", "route", ",", "array", "$", "pattern", ",", "$", "arity", ",", "$", "priority", "=", "5", ")", "{", "$", "route", "=", "$", "this", "->", "validate", "(", "$", "route", ")", ";", "$", "key", "=", "$", "route", "->", "__toString", "(", ")", ".", "'['", ".", "$", "arity", ".", "']'", ";", "if", "(", "isset", "(", "$", "this", "->", "paths", "[", "$", "key", "]", ")", ")", "{", "if", "(", "$", "priority", "<", "$", "this", "->", "paths", "[", "$", "key", "]", "[", "'priority'", "]", ")", "{", "return", ";", "}", "}", "$", "this", "->", "paths", "[", "$", "key", "]", "=", "[", "'pattern'", "=>", "$", "pattern", ",", "'priority'", "=>", "$", "priority", "]", ";", "}" ]
Add a path for a route. @param string|array|Route|HasRoute $route A route. @param string[] $pattern Path pattern. @param int|string $arity Pattern arity, i.e. number of variables. '*' for variadic. @param int $priority Path priority.
[ "Add", "a", "path", "for", "a", "route", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L329-L342
11,341
jivoo/http
src/Router.php
Router.getPathValidated
public function getPathValidated(Route\Route $route) { $parameters = $route->getParameters(); if (count($parameters)) { $arity = '[' . count($parameters) . ']'; } else { $arity = '[0]'; } $key = $route->withoutAttributes()->__toString(); $pattern = null; if (isset($this->paths[$key . $arity])) { $pattern = $this->paths[$key . $arity]['pattern']; } elseif (isset($this->paths[$key . '[*]'])) { $pattern = $this->paths[$key . '[*]']['pattern']; } $path = $route->getPath($pattern); if (! isset($path)) { throw new Route\RouteException('Could not find path for: ' . $key . $arity); } return $path; }
php
public function getPathValidated(Route\Route $route) { $parameters = $route->getParameters(); if (count($parameters)) { $arity = '[' . count($parameters) . ']'; } else { $arity = '[0]'; } $key = $route->withoutAttributes()->__toString(); $pattern = null; if (isset($this->paths[$key . $arity])) { $pattern = $this->paths[$key . $arity]['pattern']; } elseif (isset($this->paths[$key . '[*]'])) { $pattern = $this->paths[$key . '[*]']['pattern']; } $path = $route->getPath($pattern); if (! isset($path)) { throw new Route\RouteException('Could not find path for: ' . $key . $arity); } return $path; }
[ "public", "function", "getPathValidated", "(", "Route", "\\", "Route", "$", "route", ")", "{", "$", "parameters", "=", "$", "route", "->", "getParameters", "(", ")", ";", "if", "(", "count", "(", "$", "parameters", ")", ")", "{", "$", "arity", "=", "'['", ".", "count", "(", "$", "parameters", ")", ".", "']'", ";", "}", "else", "{", "$", "arity", "=", "'[0]'", ";", "}", "$", "key", "=", "$", "route", "->", "withoutAttributes", "(", ")", "->", "__toString", "(", ")", ";", "$", "pattern", "=", "null", ";", "if", "(", "isset", "(", "$", "this", "->", "paths", "[", "$", "key", ".", "$", "arity", "]", ")", ")", "{", "$", "pattern", "=", "$", "this", "->", "paths", "[", "$", "key", ".", "$", "arity", "]", "[", "'pattern'", "]", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "paths", "[", "$", "key", ".", "'[*]'", "]", ")", ")", "{", "$", "pattern", "=", "$", "this", "->", "paths", "[", "$", "key", ".", "'[*]'", "]", "[", "'pattern'", "]", ";", "}", "$", "path", "=", "$", "route", "->", "getPath", "(", "$", "pattern", ")", ";", "if", "(", "!", "isset", "(", "$", "path", ")", ")", "{", "throw", "new", "Route", "\\", "RouteException", "(", "'Could not find path for: '", ".", "$", "key", ".", "$", "arity", ")", ";", "}", "return", "$", "path", ";", "}" ]
Get path for a validated route. @param \Jivoo\Http\Route\Route $route Validated route. @return string[]|string Path array or absolute path string. @throws Route\RouteException If the a path could not be found for the route.
[ "Get", "path", "for", "a", "validated", "route", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L352-L372
11,342
jivoo/http
src/Router.php
Router.getUri
public function getUri($route, $full = false) { $route = $this->validate($route); $path = $this->getPathValidated($route); if (is_string($path)) { return new Message\Uri($path); } if ($full) { $uri = $this->request->getUri()->withPath($this->request->pathToString($path)); } else { $uri = new Message\Uri($this->request->pathToString($path)); } $uri = $uri->withQuery($this->buildQuery($route->getQuery())) ->withFragment($route->getFragment()); return $uri; }
php
public function getUri($route, $full = false) { $route = $this->validate($route); $path = $this->getPathValidated($route); if (is_string($path)) { return new Message\Uri($path); } if ($full) { $uri = $this->request->getUri()->withPath($this->request->pathToString($path)); } else { $uri = new Message\Uri($this->request->pathToString($path)); } $uri = $uri->withQuery($this->buildQuery($route->getQuery())) ->withFragment($route->getFragment()); return $uri; }
[ "public", "function", "getUri", "(", "$", "route", ",", "$", "full", "=", "false", ")", "{", "$", "route", "=", "$", "this", "->", "validate", "(", "$", "route", ")", ";", "$", "path", "=", "$", "this", "->", "getPathValidated", "(", "$", "route", ")", ";", "if", "(", "is_string", "(", "$", "path", ")", ")", "{", "return", "new", "Message", "\\", "Uri", "(", "$", "path", ")", ";", "}", "if", "(", "$", "full", ")", "{", "$", "uri", "=", "$", "this", "->", "request", "->", "getUri", "(", ")", "->", "withPath", "(", "$", "this", "->", "request", "->", "pathToString", "(", "$", "path", ")", ")", ";", "}", "else", "{", "$", "uri", "=", "new", "Message", "\\", "Uri", "(", "$", "this", "->", "request", "->", "pathToString", "(", "$", "path", ")", ")", ";", "}", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "$", "this", "->", "buildQuery", "(", "$", "route", "->", "getQuery", "(", ")", ")", ")", "->", "withFragment", "(", "$", "route", "->", "getFragment", "(", ")", ")", ";", "return", "$", "uri", ";", "}" ]
Get URI for a route. @param string|array|Route|HasRoute $route A route. @return Message\Uri Uri.
[ "Get", "URI", "for", "a", "route", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L392-L407
11,343
jivoo/http
src/Router.php
Router.applyPattern
public function applyPattern(array $pattern, array $path) { $length = count($pattern); if ($length == 0 and count($path) > 0) { return null; } if ($length < count($path) and $pattern[$length - 1] != '**' and $pattern[$length - 1] != ':*') { return null; } $parameters = []; foreach ($pattern as $j => $part) { if ($part == '**' or $part == ':*') { $parameters = array_merge( $parameters, array_slice($path, $j) ); break; } elseif (! isset($path[$j])) { return null; } if ($path[$j] == $part) { continue; } if ($part == '*') { $parameters[] = $path[$j]; continue; } if (isset($part[0]) and $part[0] == ':') { $var = substr($part, 1); if (is_numeric($var)) { $parameters[(int)$var] = $path[$j]; } else { $parameters[$var] = $path[$j]; } continue; } return null; } return $parameters; }
php
public function applyPattern(array $pattern, array $path) { $length = count($pattern); if ($length == 0 and count($path) > 0) { return null; } if ($length < count($path) and $pattern[$length - 1] != '**' and $pattern[$length - 1] != ':*') { return null; } $parameters = []; foreach ($pattern as $j => $part) { if ($part == '**' or $part == ':*') { $parameters = array_merge( $parameters, array_slice($path, $j) ); break; } elseif (! isset($path[$j])) { return null; } if ($path[$j] == $part) { continue; } if ($part == '*') { $parameters[] = $path[$j]; continue; } if (isset($part[0]) and $part[0] == ':') { $var = substr($part, 1); if (is_numeric($var)) { $parameters[(int)$var] = $path[$j]; } else { $parameters[$var] = $path[$j]; } continue; } return null; } return $parameters; }
[ "public", "function", "applyPattern", "(", "array", "$", "pattern", ",", "array", "$", "path", ")", "{", "$", "length", "=", "count", "(", "$", "pattern", ")", ";", "if", "(", "$", "length", "==", "0", "and", "count", "(", "$", "path", ")", ">", "0", ")", "{", "return", "null", ";", "}", "if", "(", "$", "length", "<", "count", "(", "$", "path", ")", "and", "$", "pattern", "[", "$", "length", "-", "1", "]", "!=", "'**'", "and", "$", "pattern", "[", "$", "length", "-", "1", "]", "!=", "':*'", ")", "{", "return", "null", ";", "}", "$", "parameters", "=", "[", "]", ";", "foreach", "(", "$", "pattern", "as", "$", "j", "=>", "$", "part", ")", "{", "if", "(", "$", "part", "==", "'**'", "or", "$", "part", "==", "':*'", ")", "{", "$", "parameters", "=", "array_merge", "(", "$", "parameters", ",", "array_slice", "(", "$", "path", ",", "$", "j", ")", ")", ";", "break", ";", "}", "elseif", "(", "!", "isset", "(", "$", "path", "[", "$", "j", "]", ")", ")", "{", "return", "null", ";", "}", "if", "(", "$", "path", "[", "$", "j", "]", "==", "$", "part", ")", "{", "continue", ";", "}", "if", "(", "$", "part", "==", "'*'", ")", "{", "$", "parameters", "[", "]", "=", "$", "path", "[", "$", "j", "]", ";", "continue", ";", "}", "if", "(", "isset", "(", "$", "part", "[", "0", "]", ")", "and", "$", "part", "[", "0", "]", "==", "':'", ")", "{", "$", "var", "=", "substr", "(", "$", "part", ",", "1", ")", ";", "if", "(", "is_numeric", "(", "$", "var", ")", ")", "{", "$", "parameters", "[", "(", "int", ")", "$", "var", "]", "=", "$", "path", "[", "$", "j", "]", ";", "}", "else", "{", "$", "parameters", "[", "$", "var", "]", "=", "$", "path", "[", "$", "j", "]", ";", "}", "continue", ";", "}", "return", "null", ";", "}", "return", "$", "parameters", ";", "}" ]
Apply a path pattern to a path. @param string[] $pattern Path pattern. @param string[] $path Path. @return string[]|null An array of path parameters or null if not a match.
[ "Apply", "a", "path", "pattern", "to", "a", "path", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L416-L456
11,344
jivoo/http
src/Router.php
Router.findMatch
public function findMatch(array $path, $method) { usort($this->patterns, ['Jivoo\Utilities', 'prioritySorter']); foreach ($this->patterns as $pattern) { if ($pattern['method'] != 'ANY' and $pattern['method'] != $method) { continue; } $parameters = $this->applyPattern($pattern['pattern'], $path); if (isset($parameters)) { return $pattern['route']->withParameters($parameters); } } return null; }
php
public function findMatch(array $path, $method) { usort($this->patterns, ['Jivoo\Utilities', 'prioritySorter']); foreach ($this->patterns as $pattern) { if ($pattern['method'] != 'ANY' and $pattern['method'] != $method) { continue; } $parameters = $this->applyPattern($pattern['pattern'], $path); if (isset($parameters)) { return $pattern['route']->withParameters($parameters); } } return null; }
[ "public", "function", "findMatch", "(", "array", "$", "path", ",", "$", "method", ")", "{", "usort", "(", "$", "this", "->", "patterns", ",", "[", "'Jivoo\\Utilities'", ",", "'prioritySorter'", "]", ")", ";", "foreach", "(", "$", "this", "->", "patterns", "as", "$", "pattern", ")", "{", "if", "(", "$", "pattern", "[", "'method'", "]", "!=", "'ANY'", "and", "$", "pattern", "[", "'method'", "]", "!=", "$", "method", ")", "{", "continue", ";", "}", "$", "parameters", "=", "$", "this", "->", "applyPattern", "(", "$", "pattern", "[", "'pattern'", "]", ",", "$", "path", ")", ";", "if", "(", "isset", "(", "$", "parameters", ")", ")", "{", "return", "$", "pattern", "[", "'route'", "]", "->", "withParameters", "(", "$", "parameters", ")", ";", "}", "}", "return", "null", ";", "}" ]
Find a route for a path. @param string[] $path Path array. @param string $method Request method. @return Route|null A route or null if none found.
[ "Find", "a", "route", "for", "a", "path", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L465-L478
11,345
jivoo/http
src/Router.php
Router.redirectPath
public function redirectPath($path, array $query = [], $fragment = '', $permanent = false, $rewrite = false) { $location = new Message\Uri($this->request->pathToString($path, $rewrite)); $location = $location->withQuery($this->buildQuery($query)) ->withFragment($fragment); return Message\Response::redirect($location, $permanent); }
php
public function redirectPath($path, array $query = [], $fragment = '', $permanent = false, $rewrite = false) { $location = new Message\Uri($this->request->pathToString($path, $rewrite)); $location = $location->withQuery($this->buildQuery($query)) ->withFragment($fragment); return Message\Response::redirect($location, $permanent); }
[ "public", "function", "redirectPath", "(", "$", "path", ",", "array", "$", "query", "=", "[", "]", ",", "$", "fragment", "=", "''", ",", "$", "permanent", "=", "false", ",", "$", "rewrite", "=", "false", ")", "{", "$", "location", "=", "new", "Message", "\\", "Uri", "(", "$", "this", "->", "request", "->", "pathToString", "(", "$", "path", ",", "$", "rewrite", ")", ")", ";", "$", "location", "=", "$", "location", "->", "withQuery", "(", "$", "this", "->", "buildQuery", "(", "$", "query", ")", ")", "->", "withFragment", "(", "$", "fragment", ")", ";", "return", "Message", "\\", "Response", "::", "redirect", "(", "$", "location", ",", "$", "permanent", ")", ";", "}" ]
Create a path redirect. @param string|string[] $path Path array. @param array $query Query. @param string $fragment Fragment. @param bool $permanent Whether redirect is permanent. @param bool $rewrite Whether to force removal of script name from path. @return ResponseInterface A redirect response.
[ "Create", "a", "path", "redirect", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L522-L528
11,346
jivoo/http
src/Router.php
Router.redirect
public function redirect($route, $permanent = false) { $route = $this->validate($route); return $this->redirectPath($this->getPath($route), $route->getQuery(), $route->getFragment(), $permanent); }
php
public function redirect($route, $permanent = false) { $route = $this->validate($route); return $this->redirectPath($this->getPath($route), $route->getQuery(), $route->getFragment(), $permanent); }
[ "public", "function", "redirect", "(", "$", "route", ",", "$", "permanent", "=", "false", ")", "{", "$", "route", "=", "$", "this", "->", "validate", "(", "$", "route", ")", ";", "return", "$", "this", "->", "redirectPath", "(", "$", "this", "->", "getPath", "(", "$", "route", ")", ",", "$", "route", "->", "getQuery", "(", ")", ",", "$", "route", "->", "getFragment", "(", ")", ",", "$", "permanent", ")", ";", "}" ]
Create a route redirect. @param string|array|Route|HasRoute $route A route. @param bool $permanent Whether redirect is permanent. @return ResponseInterface A redirect response.
[ "Create", "a", "route", "redirect", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L537-L541
11,347
jivoo/http
src/Router.php
Router.refresh
public function refresh($query = null, $fragment = '') { if (! isset($query)) { $query = $this->request->query; } return $this->redirectPath($this->request->path, $query, $fragment); }
php
public function refresh($query = null, $fragment = '') { if (! isset($query)) { $query = $this->request->query; } return $this->redirectPath($this->request->path, $query, $fragment); }
[ "public", "function", "refresh", "(", "$", "query", "=", "null", ",", "$", "fragment", "=", "''", ")", "{", "if", "(", "!", "isset", "(", "$", "query", ")", ")", "{", "$", "query", "=", "$", "this", "->", "request", "->", "query", ";", "}", "return", "$", "this", "->", "redirectPath", "(", "$", "this", "->", "request", "->", "path", ",", "$", "query", ",", "$", "fragment", ")", ";", "}" ]
Create a refresh response. @param array $query Optional new query parameters. @param string $fragment Optional fragment. @return ResponseInterface A refresh response.
[ "Create", "a", "refresh", "response", "." ]
3c1d8dba66978bc91fc2b324dd941e5da3b253bc
https://github.com/jivoo/http/blob/3c1d8dba66978bc91fc2b324dd941e5da3b253bc/src/Router.php#L560-L566
11,348
Puzzlout/FrameworkMvcLegacy
src/Security/AuthenticationManager.php
AuthenticationManager.authenticate
public function authenticate(IUser $user) { //set role $this->app->user->setAttribute(SessionKeys::UserRole, $user->getRole()); //store user in session $this->app->user->setAttribute(SessionKeys::UserConnected, $user); }
php
public function authenticate(IUser $user) { //set role $this->app->user->setAttribute(SessionKeys::UserRole, $user->getRole()); //store user in session $this->app->user->setAttribute(SessionKeys::UserConnected, $user); }
[ "public", "function", "authenticate", "(", "IUser", "$", "user", ")", "{", "//set role", "$", "this", "->", "app", "->", "user", "->", "setAttribute", "(", "SessionKeys", "::", "UserRole", ",", "$", "user", "->", "getRole", "(", ")", ")", ";", "//store user in session", "$", "this", "->", "app", "->", "user", "->", "setAttribute", "(", "SessionKeys", "::", "UserConnected", ",", "$", "user", ")", ";", "}" ]
Authenticates a user from the given object. @param \Puzzlout\Framework\Interfaces\IUser $user User object holding all the values necessary to connect the user.
[ "Authenticates", "a", "user", "from", "the", "given", "object", "." ]
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Security/AuthenticationManager.php#L26-L31
11,349
Puzzlout/FrameworkMvcLegacy
src/Security/AuthenticationManager.php
AuthenticationManager.HashUserPassword
public function HashUserPassword(\Puzzlout\Framework\BO\F_user $user) { $user->setF_user_salt($user->F_user_password_is_hashed() ? $user->F_user_salt() : \Puzzlout\Framework\Utility\UUID::v4()); $user->setF_user_password($this->app->security()->HashValue($user->F_user_salt(), $user->F_user_password())); $user->setF_user_password_is_hashed(1); return $user; }
php
public function HashUserPassword(\Puzzlout\Framework\BO\F_user $user) { $user->setF_user_salt($user->F_user_password_is_hashed() ? $user->F_user_salt() : \Puzzlout\Framework\Utility\UUID::v4()); $user->setF_user_password($this->app->security()->HashValue($user->F_user_salt(), $user->F_user_password())); $user->setF_user_password_is_hashed(1); return $user; }
[ "public", "function", "HashUserPassword", "(", "\\", "Puzzlout", "\\", "Framework", "\\", "BO", "\\", "F_user", "$", "user", ")", "{", "$", "user", "->", "setF_user_salt", "(", "$", "user", "->", "F_user_password_is_hashed", "(", ")", "?", "$", "user", "->", "F_user_salt", "(", ")", ":", "\\", "Puzzlout", "\\", "Framework", "\\", "Utility", "\\", "UUID", "::", "v4", "(", ")", ")", ";", "$", "user", "->", "setF_user_password", "(", "$", "this", "->", "app", "->", "security", "(", ")", "->", "HashValue", "(", "$", "user", "->", "F_user_salt", "(", ")", ",", "$", "user", "->", "F_user_password", "(", ")", ")", ")", ";", "$", "user", "->", "setF_user_password_is_hashed", "(", "1", ")", ";", "return", "$", "user", ";", "}" ]
Retrieve the hash of the user password. @param \Puzzlout\Framework\BO\F_user $user @return \Puzzlout\Framework\BO\F_user
[ "Retrieve", "the", "hash", "of", "the", "user", "password", "." ]
14e0fc5b16978cbd209f552ee9c649f66a0dfc6e
https://github.com/Puzzlout/FrameworkMvcLegacy/blob/14e0fc5b16978cbd209f552ee9c649f66a0dfc6e/src/Security/AuthenticationManager.php#L47-L52
11,350
thecodingmachine/utils.package-builder
src/Mouf/Utils/PackageBuilder/Export/ExportService.php
ExportService.getAllAnonymousInstancesList
public function getAllAnonymousInstancesList(SplObjectStorage $instances) { $anonymousInstances = new SplObjectStorage(); foreach ($instances as $instance) { $anonymousInstances->addAll($this->getAnonymousAttachedInstances($instance)); } return $anonymousInstances; }
php
public function getAllAnonymousInstancesList(SplObjectStorage $instances) { $anonymousInstances = new SplObjectStorage(); foreach ($instances as $instance) { $anonymousInstances->addAll($this->getAnonymousAttachedInstances($instance)); } return $anonymousInstances; }
[ "public", "function", "getAllAnonymousInstancesList", "(", "SplObjectStorage", "$", "instances", ")", "{", "$", "anonymousInstances", "=", "new", "SplObjectStorage", "(", ")", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "anonymousInstances", "->", "addAll", "(", "$", "this", "->", "getAnonymousAttachedInstances", "(", "$", "instance", ")", ")", ";", "}", "return", "$", "anonymousInstances", ";", "}" ]
This function will browse all instances passed in parameter and will return all anonymous instances bound to those objects. @param SplObjectStorage $instances An object storage of MoufInstanceDescriptor @return \SplObjectStorage
[ "This", "function", "will", "browse", "all", "instances", "passed", "in", "parameter", "and", "will", "return", "all", "anonymous", "instances", "bound", "to", "those", "objects", "." ]
14a82a1a0e0fda503e6152d65900623cd73f6202
https://github.com/thecodingmachine/utils.package-builder/blob/14a82a1a0e0fda503e6152d65900623cd73f6202/src/Mouf/Utils/PackageBuilder/Export/ExportService.php#L122-L131
11,351
zerospam/sdk-framework
src/Client/OAuthClient.php
OAuthClient.registerMiddleware
public function registerMiddleware(IMiddleware $middleware): IOAuthClient { $middleware->setClient($this); foreach ($middleware::statusCode() as $statusCode) { $this->postRequestMiddlewares[$statusCode][] = $middleware; } return $this; }
php
public function registerMiddleware(IMiddleware $middleware): IOAuthClient { $middleware->setClient($this); foreach ($middleware::statusCode() as $statusCode) { $this->postRequestMiddlewares[$statusCode][] = $middleware; } return $this; }
[ "public", "function", "registerMiddleware", "(", "IMiddleware", "$", "middleware", ")", ":", "IOAuthClient", "{", "$", "middleware", "->", "setClient", "(", "$", "this", ")", ";", "foreach", "(", "$", "middleware", "::", "statusCode", "(", ")", "as", "$", "statusCode", ")", "{", "$", "this", "->", "postRequestMiddlewares", "[", "$", "statusCode", "]", "[", "]", "=", "$", "middleware", ";", "}", "return", "$", "this", ";", "}" ]
Register the given middleware. @param \ZEROSPAM\Framework\SDK\Client\Middleware\IMiddleware $middleware @return IOAuthClient
[ "Register", "the", "given", "middleware", "." ]
6780b81584619cb177d5d5e14fd7e87a9d8e48fd
https://github.com/zerospam/sdk-framework/blob/6780b81584619cb177d5d5e14fd7e87a9d8e48fd/src/Client/OAuthClient.php#L110-L118
11,352
zerospam/sdk-framework
src/Client/OAuthClient.php
OAuthClient.registerPreRequestMiddleware
public function registerPreRequestMiddleware(IPreRequestMiddleware $middleware): IOAuthClient { $this->preRequestMiddlewares[get_class($middleware)] = $middleware; return $this; }
php
public function registerPreRequestMiddleware(IPreRequestMiddleware $middleware): IOAuthClient { $this->preRequestMiddlewares[get_class($middleware)] = $middleware; return $this; }
[ "public", "function", "registerPreRequestMiddleware", "(", "IPreRequestMiddleware", "$", "middleware", ")", ":", "IOAuthClient", "{", "$", "this", "->", "preRequestMiddlewares", "[", "get_class", "(", "$", "middleware", ")", "]", "=", "$", "middleware", ";", "return", "$", "this", ";", "}" ]
Register a pre request middleware @param IPreRequestMiddleware $middleware @return IOAuthClient
[ "Register", "a", "pre", "request", "middleware" ]
6780b81584619cb177d5d5e14fd7e87a9d8e48fd
https://github.com/zerospam/sdk-framework/blob/6780b81584619cb177d5d5e14fd7e87a9d8e48fd/src/Client/OAuthClient.php#L127-L132
11,353
zerospam/sdk-framework
src/Client/OAuthClient.php
OAuthClient.registerRefreshTokenMiddleware
public function registerRefreshTokenMiddleware(IRefreshTokenMiddleware $middleware): IOAuthClient { $middleware->setClient($this); $this->refreshTokenMiddlewares[get_class($middleware)] = $middleware; return $this; }
php
public function registerRefreshTokenMiddleware(IRefreshTokenMiddleware $middleware): IOAuthClient { $middleware->setClient($this); $this->refreshTokenMiddlewares[get_class($middleware)] = $middleware; return $this; }
[ "public", "function", "registerRefreshTokenMiddleware", "(", "IRefreshTokenMiddleware", "$", "middleware", ")", ":", "IOAuthClient", "{", "$", "middleware", "->", "setClient", "(", "$", "this", ")", ";", "$", "this", "->", "refreshTokenMiddlewares", "[", "get_class", "(", "$", "middleware", ")", "]", "=", "$", "middleware", ";", "return", "$", "this", ";", "}" ]
Register a middleware to take care of refresh token @param IRefreshTokenMiddleware $middleware @return IOAuthClient
[ "Register", "a", "middleware", "to", "take", "care", "of", "refresh", "token" ]
6780b81584619cb177d5d5e14fd7e87a9d8e48fd
https://github.com/zerospam/sdk-framework/blob/6780b81584619cb177d5d5e14fd7e87a9d8e48fd/src/Client/OAuthClient.php#L141-L147
11,354
zerospam/sdk-framework
src/Client/OAuthClient.php
OAuthClient.unregisterMiddleware
public function unregisterMiddleware(IMiddleware $middleware): IOAuthClient { $middlewareClass = get_class($middleware); foreach ($middleware::statusCode() as $statusCode) { if (!isset($this->postRequestMiddlewares[$statusCode])) { continue; } $result = array_filter( $this->postRequestMiddlewares[$statusCode], function (IMiddleware $currMiddleware) use ($middlewareClass) { return get_class($currMiddleware) != $middlewareClass; } ); if (empty($result)) { unset($this->postRequestMiddlewares[$statusCode]); } else { $this->postRequestMiddlewares[$statusCode] = $result; } } return $this; }
php
public function unregisterMiddleware(IMiddleware $middleware): IOAuthClient { $middlewareClass = get_class($middleware); foreach ($middleware::statusCode() as $statusCode) { if (!isset($this->postRequestMiddlewares[$statusCode])) { continue; } $result = array_filter( $this->postRequestMiddlewares[$statusCode], function (IMiddleware $currMiddleware) use ($middlewareClass) { return get_class($currMiddleware) != $middlewareClass; } ); if (empty($result)) { unset($this->postRequestMiddlewares[$statusCode]); } else { $this->postRequestMiddlewares[$statusCode] = $result; } } return $this; }
[ "public", "function", "unregisterMiddleware", "(", "IMiddleware", "$", "middleware", ")", ":", "IOAuthClient", "{", "$", "middlewareClass", "=", "get_class", "(", "$", "middleware", ")", ";", "foreach", "(", "$", "middleware", "::", "statusCode", "(", ")", "as", "$", "statusCode", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "postRequestMiddlewares", "[", "$", "statusCode", "]", ")", ")", "{", "continue", ";", "}", "$", "result", "=", "array_filter", "(", "$", "this", "->", "postRequestMiddlewares", "[", "$", "statusCode", "]", ",", "function", "(", "IMiddleware", "$", "currMiddleware", ")", "use", "(", "$", "middlewareClass", ")", "{", "return", "get_class", "(", "$", "currMiddleware", ")", "!=", "$", "middlewareClass", ";", "}", ")", ";", "if", "(", "empty", "(", "$", "result", ")", ")", "{", "unset", "(", "$", "this", "->", "postRequestMiddlewares", "[", "$", "statusCode", "]", ")", ";", "}", "else", "{", "$", "this", "->", "postRequestMiddlewares", "[", "$", "statusCode", "]", "=", "$", "result", ";", "}", "}", "return", "$", "this", ";", "}" ]
Unregister the middleware. In fact, all middleware having the same class @param \ZEROSPAM\Framework\SDK\Client\Middleware\IMiddleware $middleware @return IOAuthClient
[ "Unregister", "the", "middleware", "." ]
6780b81584619cb177d5d5e14fd7e87a9d8e48fd
https://github.com/zerospam/sdk-framework/blob/6780b81584619cb177d5d5e14fd7e87a9d8e48fd/src/Client/OAuthClient.php#L158-L180
11,355
zerospam/sdk-framework
src/Client/OAuthClient.php
OAuthClient.processThrottleData
private function processThrottleData(ResponseInterface $response) { if (empty($rateLimit = $response->getHeader('X-RateLimit-Limit'))) { return; } if (empty($remaining = $response->getHeader('X-RateLimit-Remaining'))) { return; } if (!empty($reset = $response->getHeader('X-RateLimit-Reset'))) { $this->rateLimit->setEndOfThrottle(intval($reset[0])); } else { $this->rateLimit->setEndOfThrottle(null); } $this->rateLimit->setMaxPerMinute(intval($rateLimit[0]))->setRemaining(intval($remaining[0])); }
php
private function processThrottleData(ResponseInterface $response) { if (empty($rateLimit = $response->getHeader('X-RateLimit-Limit'))) { return; } if (empty($remaining = $response->getHeader('X-RateLimit-Remaining'))) { return; } if (!empty($reset = $response->getHeader('X-RateLimit-Reset'))) { $this->rateLimit->setEndOfThrottle(intval($reset[0])); } else { $this->rateLimit->setEndOfThrottle(null); } $this->rateLimit->setMaxPerMinute(intval($rateLimit[0]))->setRemaining(intval($remaining[0])); }
[ "private", "function", "processThrottleData", "(", "ResponseInterface", "$", "response", ")", "{", "if", "(", "empty", "(", "$", "rateLimit", "=", "$", "response", "->", "getHeader", "(", "'X-RateLimit-Limit'", ")", ")", ")", "{", "return", ";", "}", "if", "(", "empty", "(", "$", "remaining", "=", "$", "response", "->", "getHeader", "(", "'X-RateLimit-Remaining'", ")", ")", ")", "{", "return", ";", "}", "if", "(", "!", "empty", "(", "$", "reset", "=", "$", "response", "->", "getHeader", "(", "'X-RateLimit-Reset'", ")", ")", ")", "{", "$", "this", "->", "rateLimit", "->", "setEndOfThrottle", "(", "intval", "(", "$", "reset", "[", "0", "]", ")", ")", ";", "}", "else", "{", "$", "this", "->", "rateLimit", "->", "setEndOfThrottle", "(", "null", ")", ";", "}", "$", "this", "->", "rateLimit", "->", "setMaxPerMinute", "(", "intval", "(", "$", "rateLimit", "[", "0", "]", ")", ")", "->", "setRemaining", "(", "intval", "(", "$", "remaining", "[", "0", "]", ")", ")", ";", "}" ]
Process the rate limit. @param ResponseInterface $response
[ "Process", "the", "rate", "limit", "." ]
6780b81584619cb177d5d5e14fd7e87a9d8e48fd
https://github.com/zerospam/sdk-framework/blob/6780b81584619cb177d5d5e14fd7e87a9d8e48fd/src/Client/OAuthClient.php#L342-L359
11,356
BitWeb/stdlib
src/BitWeb/Stdlib/StringUtil.php
StringUtil.stringLinesLimiter
public static function stringLinesLimiter($string, $linesLimit, $removeEmptyLines = false, $stringLengthLimit = 189, $lineStringLengthLimit = 63) { $lines = explode(PHP_EOL, $string); if ($removeEmptyLines) { for ($i = 0; $i < count($lines); $i++) { $element = trim(self::replaceNewlines($lines[$i], '')); if ($element == '') { unset($lines[$i]); } } } $stringLinesArray = array(); $count = $linesLimit; $charactersLeft = $stringLengthLimit; foreach ($lines as &$line) { $line = self::replaceNewlines($line, ''); if (strlen($line) >= ($count * $lineStringLengthLimit)) { $stringLinesArray[] = self::subString($line, $count * $lineStringLengthLimit); break; } $count = $count - 1; if (count($lines) > $linesLimit && $count < 1) { $stringLinesArray[] = $line . '...'; } else { $stringLinesArray[] = $line; } if ($count < 1) { break; } } $string = implode(PHP_EOL, $stringLinesArray); return $string; }
php
public static function stringLinesLimiter($string, $linesLimit, $removeEmptyLines = false, $stringLengthLimit = 189, $lineStringLengthLimit = 63) { $lines = explode(PHP_EOL, $string); if ($removeEmptyLines) { for ($i = 0; $i < count($lines); $i++) { $element = trim(self::replaceNewlines($lines[$i], '')); if ($element == '') { unset($lines[$i]); } } } $stringLinesArray = array(); $count = $linesLimit; $charactersLeft = $stringLengthLimit; foreach ($lines as &$line) { $line = self::replaceNewlines($line, ''); if (strlen($line) >= ($count * $lineStringLengthLimit)) { $stringLinesArray[] = self::subString($line, $count * $lineStringLengthLimit); break; } $count = $count - 1; if (count($lines) > $linesLimit && $count < 1) { $stringLinesArray[] = $line . '...'; } else { $stringLinesArray[] = $line; } if ($count < 1) { break; } } $string = implode(PHP_EOL, $stringLinesArray); return $string; }
[ "public", "static", "function", "stringLinesLimiter", "(", "$", "string", ",", "$", "linesLimit", ",", "$", "removeEmptyLines", "=", "false", ",", "$", "stringLengthLimit", "=", "189", ",", "$", "lineStringLengthLimit", "=", "63", ")", "{", "$", "lines", "=", "explode", "(", "PHP_EOL", ",", "$", "string", ")", ";", "if", "(", "$", "removeEmptyLines", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "lines", ")", ";", "$", "i", "++", ")", "{", "$", "element", "=", "trim", "(", "self", "::", "replaceNewlines", "(", "$", "lines", "[", "$", "i", "]", ",", "''", ")", ")", ";", "if", "(", "$", "element", "==", "''", ")", "{", "unset", "(", "$", "lines", "[", "$", "i", "]", ")", ";", "}", "}", "}", "$", "stringLinesArray", "=", "array", "(", ")", ";", "$", "count", "=", "$", "linesLimit", ";", "$", "charactersLeft", "=", "$", "stringLengthLimit", ";", "foreach", "(", "$", "lines", "as", "&", "$", "line", ")", "{", "$", "line", "=", "self", "::", "replaceNewlines", "(", "$", "line", ",", "''", ")", ";", "if", "(", "strlen", "(", "$", "line", ")", ">=", "(", "$", "count", "*", "$", "lineStringLengthLimit", ")", ")", "{", "$", "stringLinesArray", "[", "]", "=", "self", "::", "subString", "(", "$", "line", ",", "$", "count", "*", "$", "lineStringLengthLimit", ")", ";", "break", ";", "}", "$", "count", "=", "$", "count", "-", "1", ";", "if", "(", "count", "(", "$", "lines", ")", ">", "$", "linesLimit", "&&", "$", "count", "<", "1", ")", "{", "$", "stringLinesArray", "[", "]", "=", "$", "line", ".", "'...'", ";", "}", "else", "{", "$", "stringLinesArray", "[", "]", "=", "$", "line", ";", "}", "if", "(", "$", "count", "<", "1", ")", "{", "break", ";", "}", "}", "$", "string", "=", "implode", "(", "PHP_EOL", ",", "$", "stringLinesArray", ")", ";", "return", "$", "string", ";", "}" ]
Limits string to number of lines, adds "..." to the end @param string $string @param int $limit
[ "Limits", "string", "to", "number", "of", "lines", "adds", "...", "to", "the", "end" ]
e90ac0d25ebb50e6088f14911181cc2c74e9c176
https://github.com/BitWeb/stdlib/blob/e90ac0d25ebb50e6088f14911181cc2c74e9c176/src/BitWeb/Stdlib/StringUtil.php#L148-L184
11,357
PaymentSuite/PaymillBundle
Services/PaymillManager.php
PaymillManager.processPayment
public function processPayment(PaymillMethod $paymentMethod, $amount) { /// first check that amounts are the same $paymentBridgeAmount = intval($this->paymentBridge->getAmount()); /** * If both amounts are different, execute Exception */ if ($amount != $paymentBridgeAmount) { throw new PaymentAmountsNotMatchException(sprintf( 'Amounts differ. Requested: [%s] but in PaymentBridge: [%s].', $amount, $paymentBridgeAmount ) ); } /** * At this point, order must be created given a card, and placed in PaymentBridge * * So, $this->paymentBridge->getOrder() must return an object */ $this->paymentEventDispatcher->notifyPaymentOrderLoad($this->paymentBridge, $paymentMethod); /** * Order Not found Exception must be thrown just here */ if (!$this->paymentBridge->getOrder()) { throw new PaymentOrderNotFoundException(); } /** * Order exists right here */ $this->paymentEventDispatcher->notifyPaymentOrderCreated($this->paymentBridge, $paymentMethod); /** * Validate the order in the module * params for paymill interaction */ $extraData = $this->paymentBridge->getExtraData(); $params = array( 'amount' => $paymentBridgeAmount, 'currency' => $this->paymentBridge->getCurrency(), 'token' => $paymentMethod->getApiToken(), 'description' => $extraData['order_description'], ); try { $transaction = $this ->paymillTransactionWrapper ->create($params['amount'], $params['currency'], $params['token'], $params['description']); } catch (PaymillException $e) { /** * create 'failed' transaction */ $transaction = new Transaction(); $transaction->setStatus('failed'); $transaction->setDescription($e->getCode() . ' ' . $e->getMessage()); } $this->processTransaction($transaction, $paymentMethod); return $this; }
php
public function processPayment(PaymillMethod $paymentMethod, $amount) { /// first check that amounts are the same $paymentBridgeAmount = intval($this->paymentBridge->getAmount()); /** * If both amounts are different, execute Exception */ if ($amount != $paymentBridgeAmount) { throw new PaymentAmountsNotMatchException(sprintf( 'Amounts differ. Requested: [%s] but in PaymentBridge: [%s].', $amount, $paymentBridgeAmount ) ); } /** * At this point, order must be created given a card, and placed in PaymentBridge * * So, $this->paymentBridge->getOrder() must return an object */ $this->paymentEventDispatcher->notifyPaymentOrderLoad($this->paymentBridge, $paymentMethod); /** * Order Not found Exception must be thrown just here */ if (!$this->paymentBridge->getOrder()) { throw new PaymentOrderNotFoundException(); } /** * Order exists right here */ $this->paymentEventDispatcher->notifyPaymentOrderCreated($this->paymentBridge, $paymentMethod); /** * Validate the order in the module * params for paymill interaction */ $extraData = $this->paymentBridge->getExtraData(); $params = array( 'amount' => $paymentBridgeAmount, 'currency' => $this->paymentBridge->getCurrency(), 'token' => $paymentMethod->getApiToken(), 'description' => $extraData['order_description'], ); try { $transaction = $this ->paymillTransactionWrapper ->create($params['amount'], $params['currency'], $params['token'], $params['description']); } catch (PaymillException $e) { /** * create 'failed' transaction */ $transaction = new Transaction(); $transaction->setStatus('failed'); $transaction->setDescription($e->getCode() . ' ' . $e->getMessage()); } $this->processTransaction($transaction, $paymentMethod); return $this; }
[ "public", "function", "processPayment", "(", "PaymillMethod", "$", "paymentMethod", ",", "$", "amount", ")", "{", "/// first check that amounts are the same", "$", "paymentBridgeAmount", "=", "intval", "(", "$", "this", "->", "paymentBridge", "->", "getAmount", "(", ")", ")", ";", "/**\n * If both amounts are different, execute Exception\n */", "if", "(", "$", "amount", "!=", "$", "paymentBridgeAmount", ")", "{", "throw", "new", "PaymentAmountsNotMatchException", "(", "sprintf", "(", "'Amounts differ. Requested: [%s] but in PaymentBridge: [%s].'", ",", "$", "amount", ",", "$", "paymentBridgeAmount", ")", ")", ";", "}", "/**\n * At this point, order must be created given a card, and placed in PaymentBridge\n *\n * So, $this->paymentBridge->getOrder() must return an object\n */", "$", "this", "->", "paymentEventDispatcher", "->", "notifyPaymentOrderLoad", "(", "$", "this", "->", "paymentBridge", ",", "$", "paymentMethod", ")", ";", "/**\n * Order Not found Exception must be thrown just here\n */", "if", "(", "!", "$", "this", "->", "paymentBridge", "->", "getOrder", "(", ")", ")", "{", "throw", "new", "PaymentOrderNotFoundException", "(", ")", ";", "}", "/**\n * Order exists right here\n */", "$", "this", "->", "paymentEventDispatcher", "->", "notifyPaymentOrderCreated", "(", "$", "this", "->", "paymentBridge", ",", "$", "paymentMethod", ")", ";", "/**\n * Validate the order in the module\n * params for paymill interaction\n */", "$", "extraData", "=", "$", "this", "->", "paymentBridge", "->", "getExtraData", "(", ")", ";", "$", "params", "=", "array", "(", "'amount'", "=>", "$", "paymentBridgeAmount", ",", "'currency'", "=>", "$", "this", "->", "paymentBridge", "->", "getCurrency", "(", ")", ",", "'token'", "=>", "$", "paymentMethod", "->", "getApiToken", "(", ")", ",", "'description'", "=>", "$", "extraData", "[", "'order_description'", "]", ",", ")", ";", "try", "{", "$", "transaction", "=", "$", "this", "->", "paymillTransactionWrapper", "->", "create", "(", "$", "params", "[", "'amount'", "]", ",", "$", "params", "[", "'currency'", "]", ",", "$", "params", "[", "'token'", "]", ",", "$", "params", "[", "'description'", "]", ")", ";", "}", "catch", "(", "PaymillException", "$", "e", ")", "{", "/**\n * create 'failed' transaction\n */", "$", "transaction", "=", "new", "Transaction", "(", ")", ";", "$", "transaction", "->", "setStatus", "(", "'failed'", ")", ";", "$", "transaction", "->", "setDescription", "(", "$", "e", "->", "getCode", "(", ")", ".", "' '", ".", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "$", "this", "->", "processTransaction", "(", "$", "transaction", ",", "$", "paymentMethod", ")", ";", "return", "$", "this", ";", "}" ]
Tries to process a payment through Paymill @param PaymillMethod $paymentMethod Payment method @param integer $amount Amount @return PaymillManager Self object @throws PaymentAmountsNotMatchException @throws PaymentOrderNotFoundException @throws PaymentException
[ "Tries", "to", "process", "a", "payment", "through", "Paymill" ]
78aa85daaab8cf08e4971b10d86abd429ac7f6cd
https://github.com/PaymentSuite/PaymillBundle/blob/78aa85daaab8cf08e4971b10d86abd429ac7f6cd/Services/PaymillManager.php#L83-L149
11,358
PaymentSuite/PaymillBundle
Services/PaymillManager.php
PaymillManager.processTransaction
private function processTransaction(Transaction $transaction, PaymillMethod $paymentMethod) { /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); /** * when a transaction is successful, it is marked as 'closed' */ $transactionStatus = $transaction->getStatus(); if (empty($transactionStatus) || $transactionStatus != 'closed') { /** * Payment paid failed * * Paid process has ended failed */ $paymentMethod->setTransaction($transaction); $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } /** * Adding to PaymentMethod transaction information * * This information is only available in PaymentOrderSuccess event */ $paymentMethod ->setTransactionId($transaction->getId()) ->setTransactionStatus($transactionStatus) ->setTransaction($transaction); /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); return $this; }
php
private function processTransaction(Transaction $transaction, PaymillMethod $paymentMethod) { /** * Payment paid done * * Paid process has ended ( No matters result ) */ $this->paymentEventDispatcher->notifyPaymentOrderDone($this->paymentBridge, $paymentMethod); /** * when a transaction is successful, it is marked as 'closed' */ $transactionStatus = $transaction->getStatus(); if (empty($transactionStatus) || $transactionStatus != 'closed') { /** * Payment paid failed * * Paid process has ended failed */ $paymentMethod->setTransaction($transaction); $this->paymentEventDispatcher->notifyPaymentOrderFail($this->paymentBridge, $paymentMethod); throw new PaymentException(); } /** * Adding to PaymentMethod transaction information * * This information is only available in PaymentOrderSuccess event */ $paymentMethod ->setTransactionId($transaction->getId()) ->setTransactionStatus($transactionStatus) ->setTransaction($transaction); /** * Payment paid successfully * * Paid process has ended successfully */ $this->paymentEventDispatcher->notifyPaymentOrderSuccess($this->paymentBridge, $paymentMethod); return $this; }
[ "private", "function", "processTransaction", "(", "Transaction", "$", "transaction", ",", "PaymillMethod", "$", "paymentMethod", ")", "{", "/**\n * Payment paid done\n *\n * Paid process has ended ( No matters result )\n */", "$", "this", "->", "paymentEventDispatcher", "->", "notifyPaymentOrderDone", "(", "$", "this", "->", "paymentBridge", ",", "$", "paymentMethod", ")", ";", "/**\n * when a transaction is successful, it is marked as 'closed'\n */", "$", "transactionStatus", "=", "$", "transaction", "->", "getStatus", "(", ")", ";", "if", "(", "empty", "(", "$", "transactionStatus", ")", "||", "$", "transactionStatus", "!=", "'closed'", ")", "{", "/**\n * Payment paid failed\n *\n * Paid process has ended failed\n */", "$", "paymentMethod", "->", "setTransaction", "(", "$", "transaction", ")", ";", "$", "this", "->", "paymentEventDispatcher", "->", "notifyPaymentOrderFail", "(", "$", "this", "->", "paymentBridge", ",", "$", "paymentMethod", ")", ";", "throw", "new", "PaymentException", "(", ")", ";", "}", "/**\n * Adding to PaymentMethod transaction information\n *\n * This information is only available in PaymentOrderSuccess event\n */", "$", "paymentMethod", "->", "setTransactionId", "(", "$", "transaction", "->", "getId", "(", ")", ")", "->", "setTransactionStatus", "(", "$", "transactionStatus", ")", "->", "setTransaction", "(", "$", "transaction", ")", ";", "/**\n * Payment paid successfully\n *\n * Paid process has ended successfully\n */", "$", "this", "->", "paymentEventDispatcher", "->", "notifyPaymentOrderSuccess", "(", "$", "this", "->", "paymentBridge", ",", "$", "paymentMethod", ")", ";", "return", "$", "this", ";", "}" ]
Given a paymillTransaction response, as an array, prform desired operations @param Transaction $transaction Transaction @param PaymillMethod $paymentMethod Payment method @return PaymillManager Self object @throws PaymentException
[ "Given", "a", "paymillTransaction", "response", "as", "an", "array", "prform", "desired", "operations" ]
78aa85daaab8cf08e4971b10d86abd429ac7f6cd
https://github.com/PaymentSuite/PaymillBundle/blob/78aa85daaab8cf08e4971b10d86abd429ac7f6cd/Services/PaymillManager.php#L161-L205
11,359
antwebes/ChateaClientBundle
Manager/FactoryManager.php
FactoryManager.get
static public function get($apiManager, $name) { if(!array_key_exists($name,self::$managerMap)){ throw new \InvalidArgumentException('Error in Factory Manager. This manager ['.$name.']is not supported'); } $className = self::$managerMap[$name]; return self::factory($apiManager, $className); }
php
static public function get($apiManager, $name) { if(!array_key_exists($name,self::$managerMap)){ throw new \InvalidArgumentException('Error in Factory Manager. This manager ['.$name.']is not supported'); } $className = self::$managerMap[$name]; return self::factory($apiManager, $className); }
[ "static", "public", "function", "get", "(", "$", "apiManager", ",", "$", "name", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "self", "::", "$", "managerMap", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Error in Factory Manager. This manager ['", ".", "$", "name", ".", "']is not supported'", ")", ";", "}", "$", "className", "=", "self", "::", "$", "managerMap", "[", "$", "name", "]", ";", "return", "self", "::", "factory", "(", "$", "apiManager", ",", "$", "className", ")", ";", "}" ]
get or create manager
[ "get", "or", "create", "manager" ]
a4deb5f966b6ddcf817068e859787e32d399acf6
https://github.com/antwebes/ChateaClientBundle/blob/a4deb5f966b6ddcf817068e859787e32d399acf6/Manager/FactoryManager.php#L29-L36
11,360
bearframework/emails-addon
classes/Emails/Email/Content.php
Content.add
public function add(string $content, string $mimeType = null, $encoding = null): void { $contentPart = $this->make(); $contentPart->content = $content; if ($mimeType !== null) { $contentPart->mimeType = $mimeType; } if ($encoding !== null) { $contentPart->encoding = $encoding; } $this->set($contentPart); }
php
public function add(string $content, string $mimeType = null, $encoding = null): void { $contentPart = $this->make(); $contentPart->content = $content; if ($mimeType !== null) { $contentPart->mimeType = $mimeType; } if ($encoding !== null) { $contentPart->encoding = $encoding; } $this->set($contentPart); }
[ "public", "function", "add", "(", "string", "$", "content", ",", "string", "$", "mimeType", "=", "null", ",", "$", "encoding", "=", "null", ")", ":", "void", "{", "$", "contentPart", "=", "$", "this", "->", "make", "(", ")", ";", "$", "contentPart", "->", "content", "=", "$", "content", ";", "if", "(", "$", "mimeType", "!==", "null", ")", "{", "$", "contentPart", "->", "mimeType", "=", "$", "mimeType", ";", "}", "if", "(", "$", "encoding", "!==", "null", ")", "{", "$", "contentPart", "->", "encoding", "=", "$", "encoding", ";", "}", "$", "this", "->", "set", "(", "$", "contentPart", ")", ";", "}" ]
Add a content part. @param string $content The value of content part. @param string|null $mimeType The mime type of the content part. @param string|null $encoding The encoding of the content part.
[ "Add", "a", "content", "part", "." ]
43a68c47e2b1d231dc69a324249ff5f6827201ca
https://github.com/bearframework/emails-addon/blob/43a68c47e2b1d231dc69a324249ff5f6827201ca/classes/Emails/Email/Content.php#L35-L46
11,361
kuria/phpunit-extras
src/Traits/ClockTrait.php
ClockTrait.atTime
static function atTime($now, callable $callback) { // store time if already overridden if (Clock::isOverridden()) { $previousOverride = Clock::microtime(); } else { $previousOverride = null; } try { // override time Clock::override($now); // invoke callback return $callback(); } finally { // restore previous state if ($previousOverride === null) { // no previous override - resume Clock::resume(); } else { // restore previous override Clock::override($previousOverride); } } }
php
static function atTime($now, callable $callback) { // store time if already overridden if (Clock::isOverridden()) { $previousOverride = Clock::microtime(); } else { $previousOverride = null; } try { // override time Clock::override($now); // invoke callback return $callback(); } finally { // restore previous state if ($previousOverride === null) { // no previous override - resume Clock::resume(); } else { // restore previous override Clock::override($previousOverride); } } }
[ "static", "function", "atTime", "(", "$", "now", ",", "callable", "$", "callback", ")", "{", "// store time if already overridden", "if", "(", "Clock", "::", "isOverridden", "(", ")", ")", "{", "$", "previousOverride", "=", "Clock", "::", "microtime", "(", ")", ";", "}", "else", "{", "$", "previousOverride", "=", "null", ";", "}", "try", "{", "// override time", "Clock", "::", "override", "(", "$", "now", ")", ";", "// invoke callback", "return", "$", "callback", "(", ")", ";", "}", "finally", "{", "// restore previous state", "if", "(", "$", "previousOverride", "===", "null", ")", "{", "// no previous override - resume", "Clock", "::", "resume", "(", ")", ";", "}", "else", "{", "// restore previous override", "Clock", "::", "override", "(", "$", "previousOverride", ")", ";", "}", "}", "}" ]
Override current time for the duration of the callback @param \DateTimeInterface|int|float $now @param callable $callback callback to invoke @return mixed return value of the callback
[ "Override", "current", "time", "for", "the", "duration", "of", "the", "callback" ]
fca02d4d6af28d98d312a0830d876293397ce611
https://github.com/kuria/phpunit-extras/blob/fca02d4d6af28d98d312a0830d876293397ce611/src/Traits/ClockTrait.php#L23-L48
11,362
Holdlang/annotationscanner
src/Helpers/ClassInformationFromFile.php
ClassInformationFromFile.getNamespace
public static function getNamespace($tokens) { $count = count($tokens); $i = 0; $namespace = ''; $namespace_ok = false; while ($i < $count) { $token = $tokens[$i]; if (is_array($token) && $token[0] === T_NAMESPACE) { // Found namespace declaration while (++$i < $count) { if ($tokens[$i] === ';') { $namespace_ok = true; $namespace = trim($namespace); break; } $namespace .= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i]; } break; } $i++; } if (!$namespace_ok) { return null; } else { return $namespace; } }
php
public static function getNamespace($tokens) { $count = count($tokens); $i = 0; $namespace = ''; $namespace_ok = false; while ($i < $count) { $token = $tokens[$i]; if (is_array($token) && $token[0] === T_NAMESPACE) { // Found namespace declaration while (++$i < $count) { if ($tokens[$i] === ';') { $namespace_ok = true; $namespace = trim($namespace); break; } $namespace .= is_array($tokens[$i]) ? $tokens[$i][1] : $tokens[$i]; } break; } $i++; } if (!$namespace_ok) { return null; } else { return $namespace; } }
[ "public", "static", "function", "getNamespace", "(", "$", "tokens", ")", "{", "$", "count", "=", "count", "(", "$", "tokens", ")", ";", "$", "i", "=", "0", ";", "$", "namespace", "=", "''", ";", "$", "namespace_ok", "=", "false", ";", "while", "(", "$", "i", "<", "$", "count", ")", "{", "$", "token", "=", "$", "tokens", "[", "$", "i", "]", ";", "if", "(", "is_array", "(", "$", "token", ")", "&&", "$", "token", "[", "0", "]", "===", "T_NAMESPACE", ")", "{", "// Found namespace declaration", "while", "(", "++", "$", "i", "<", "$", "count", ")", "{", "if", "(", "$", "tokens", "[", "$", "i", "]", "===", "';'", ")", "{", "$", "namespace_ok", "=", "true", ";", "$", "namespace", "=", "trim", "(", "$", "namespace", ")", ";", "break", ";", "}", "$", "namespace", ".=", "is_array", "(", "$", "tokens", "[", "$", "i", "]", ")", "?", "$", "tokens", "[", "$", "i", "]", "[", "1", "]", ":", "$", "tokens", "[", "$", "i", "]", ";", "}", "break", ";", "}", "$", "i", "++", ";", "}", "if", "(", "!", "$", "namespace_ok", ")", "{", "return", "null", ";", "}", "else", "{", "return", "$", "namespace", ";", "}", "}" ]
Look for the namespace declaration. @param $tokens @return null|string
[ "Look", "for", "the", "namespace", "declaration", "." ]
7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6
https://github.com/Holdlang/annotationscanner/blob/7420b8ae1ab4d8bf9e76a448ea3ea749d6a934c6/src/Helpers/ClassInformationFromFile.php#L56-L83
11,363
binsoul/net-http-message-message
src/ServerRequest.php
ServerRequest.withAttributes
public function withAttributes(array $attributes): self { $result = clone $this; $result->attributes = new ParameterCollection($attributes); return $result; }
php
public function withAttributes(array $attributes): self { $result = clone $this; $result->attributes = new ParameterCollection($attributes); return $result; }
[ "public", "function", "withAttributes", "(", "array", "$", "attributes", ")", ":", "self", "{", "$", "result", "=", "clone", "$", "this", ";", "$", "result", "->", "attributes", "=", "new", "ParameterCollection", "(", "$", "attributes", ")", ";", "return", "$", "result", ";", "}" ]
Returns a new instance with the specified attributes. @param mixed $attributes attributes of the new instance @return self
[ "Returns", "a", "new", "instance", "with", "the", "specified", "attributes", "." ]
b367ecdfda28570f849fc7e0723125a951d915a7
https://github.com/binsoul/net-http-message-message/blob/b367ecdfda28570f849fc7e0723125a951d915a7/src/ServerRequest.php#L159-L165
11,364
ilya-dev/exo
source/Exo/Filesystem.php
Filesystem.overwrite
public function overwrite($file, $content) { $written = file_put_contents($file, $content); // If $content is not empty // but nothing was written to $file // throw an exception. if ($content and ! $written) { throw new RuntimeException( "Unable to write to {$file}." ); } }
php
public function overwrite($file, $content) { $written = file_put_contents($file, $content); // If $content is not empty // but nothing was written to $file // throw an exception. if ($content and ! $written) { throw new RuntimeException( "Unable to write to {$file}." ); } }
[ "public", "function", "overwrite", "(", "$", "file", ",", "$", "content", ")", "{", "$", "written", "=", "file_put_contents", "(", "$", "file", ",", "$", "content", ")", ";", "// If $content is not empty", "// but nothing was written to $file", "// throw an exception.", "if", "(", "$", "content", "and", "!", "$", "written", ")", "{", "throw", "new", "RuntimeException", "(", "\"Unable to write to {$file}.\"", ")", ";", "}", "}" ]
Overwrite a file. @throws RuntimeException @param string $file @param string $content @return void
[ "Overwrite", "a", "file", "." ]
89960a0116513c3172f107041bc9b9fa80ba8e54
https://github.com/ilya-dev/exo/blob/89960a0116513c3172f107041bc9b9fa80ba8e54/source/Exo/Filesystem.php#L34-L47
11,365
konservs/brilliant.framework
libraries/MVC/BView.php
BView.breadcrumbs_add
public function breadcrumbs_add($url, $name, $active = true, $class = '', $children = array()) { if (!isset($this->controller)) { return false; } $this->controller->breadcrumbs[] = (object)array('url' => $url, 'name' => $name, 'active' => $active, 'class' => $class, 'children' => $children); return true; }
php
public function breadcrumbs_add($url, $name, $active = true, $class = '', $children = array()) { if (!isset($this->controller)) { return false; } $this->controller->breadcrumbs[] = (object)array('url' => $url, 'name' => $name, 'active' => $active, 'class' => $class, 'children' => $children); return true; }
[ "public", "function", "breadcrumbs_add", "(", "$", "url", ",", "$", "name", ",", "$", "active", "=", "true", ",", "$", "class", "=", "''", ",", "$", "children", "=", "array", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "controller", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "controller", "->", "breadcrumbs", "[", "]", "=", "(", "object", ")", "array", "(", "'url'", "=>", "$", "url", ",", "'name'", "=>", "$", "name", ",", "'active'", "=>", "$", "active", ",", "'class'", "=>", "$", "class", ",", "'children'", "=>", "$", "children", ")", ";", "return", "true", ";", "}" ]
Add breadcrumbs element. @param $url @param $name @param bool $active @param string $class @param array $children @return bool
[ "Add", "breadcrumbs", "element", "." ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/MVC/BView.php#L255-L261
11,366
konservs/brilliant.framework
libraries/MVC/BView.php
BView.breadcrumbs_add_userdashboard
public function breadcrumbs_add_userdashboard() { $brouter = BRouter::getInstance(); return $this->breadcrumbs_add('//' . $brouter->generateurl('users', BLang::$langcode, array('view' => 'dashboard')), BLang::_('USERS_DASHBOARD_HEADING'), true); }
php
public function breadcrumbs_add_userdashboard() { $brouter = BRouter::getInstance(); return $this->breadcrumbs_add('//' . $brouter->generateurl('users', BLang::$langcode, array('view' => 'dashboard')), BLang::_('USERS_DASHBOARD_HEADING'), true); }
[ "public", "function", "breadcrumbs_add_userdashboard", "(", ")", "{", "$", "brouter", "=", "BRouter", "::", "getInstance", "(", ")", ";", "return", "$", "this", "->", "breadcrumbs_add", "(", "'//'", ".", "$", "brouter", "->", "generateurl", "(", "'users'", ",", "BLang", "::", "$", "langcode", ",", "array", "(", "'view'", "=>", "'dashboard'", ")", ")", ",", "BLang", "::", "_", "(", "'USERS_DASHBOARD_HEADING'", ")", ",", "true", ")", ";", "}" ]
Add breadcrumbs user dashboard
[ "Add", "breadcrumbs", "user", "dashboard" ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/MVC/BView.php#L275-L278
11,367
konservs/brilliant.framework
libraries/MVC/BView.php
BView.breadcrumbs_add_region
public function breadcrumbs_add_region($id) { bimport('regions.general'); $bregions = BRegions::getInstance(); $regions = $bregions->regions_get_all(); $reg = $bregions->region_get($id); if (empty($reg)) { return false; } $brouter = BRouter::getInstance(); $url = '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'region', 'id' => $id)); $children = array(); foreach ($regions as $r) { $children[$r->id] = (object)array('active' => true, 'url' => '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'region', 'id' => $r->id)), 'name' => $r->getname()); } $name = $reg->getname(); return $this->breadcrumbs_add($url, $name, true, 'region', $children); }
php
public function breadcrumbs_add_region($id) { bimport('regions.general'); $bregions = BRegions::getInstance(); $regions = $bregions->regions_get_all(); $reg = $bregions->region_get($id); if (empty($reg)) { return false; } $brouter = BRouter::getInstance(); $url = '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'region', 'id' => $id)); $children = array(); foreach ($regions as $r) { $children[$r->id] = (object)array('active' => true, 'url' => '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'region', 'id' => $r->id)), 'name' => $r->getname()); } $name = $reg->getname(); return $this->breadcrumbs_add($url, $name, true, 'region', $children); }
[ "public", "function", "breadcrumbs_add_region", "(", "$", "id", ")", "{", "bimport", "(", "'regions.general'", ")", ";", "$", "bregions", "=", "BRegions", "::", "getInstance", "(", ")", ";", "$", "regions", "=", "$", "bregions", "->", "regions_get_all", "(", ")", ";", "$", "reg", "=", "$", "bregions", "->", "region_get", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "reg", ")", ")", "{", "return", "false", ";", "}", "$", "brouter", "=", "BRouter", "::", "getInstance", "(", ")", ";", "$", "url", "=", "'//'", ".", "$", "brouter", "->", "generateURL", "(", "'regions'", ",", "BLang", "::", "$", "langcode", ",", "array", "(", "'view'", "=>", "'region'", ",", "'id'", "=>", "$", "id", ")", ")", ";", "$", "children", "=", "array", "(", ")", ";", "foreach", "(", "$", "regions", "as", "$", "r", ")", "{", "$", "children", "[", "$", "r", "->", "id", "]", "=", "(", "object", ")", "array", "(", "'active'", "=>", "true", ",", "'url'", "=>", "'//'", ".", "$", "brouter", "->", "generateURL", "(", "'regions'", ",", "BLang", "::", "$", "langcode", ",", "array", "(", "'view'", "=>", "'region'", ",", "'id'", "=>", "$", "r", "->", "id", ")", ")", ",", "'name'", "=>", "$", "r", "->", "getname", "(", ")", ")", ";", "}", "$", "name", "=", "$", "reg", "->", "getname", "(", ")", ";", "return", "$", "this", "->", "breadcrumbs_add", "(", "$", "url", ",", "$", "name", ",", "true", ",", "'region'", ",", "$", "children", ")", ";", "}" ]
Add region breadcrumbs element @param $id @return bool
[ "Add", "region", "breadcrumbs", "element" ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/MVC/BView.php#L305-L321
11,368
konservs/brilliant.framework
libraries/MVC/BView.php
BView.breadcrumbs_add_city
public function breadcrumbs_add_city($id) { bimport('regions.general'); $bregions = BRegions::getInstance(); $city = $bregions->city_get($id); if (empty($city)) { return false; } $region = $city->getregion(); if (empty($region)) { return false; } $subcities = $region->cities_get_all(); // $brouter = BRouter::getInstance(); $url = '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'city', 'id' => $id)); $name = $city->getname(); if (!empty($subcities)) { $children = array(); foreach ($subcities as $c) { $children[$c->id] = (object)array('active' => true, 'url' => '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'city', 'id' => $c->id)), 'name' => $c->getname()); } return $this->breadcrumbs_add($url, $name, true, 'city', $children); } return $this->breadcrumbs_add($url, $name, true, 'city'); }
php
public function breadcrumbs_add_city($id) { bimport('regions.general'); $bregions = BRegions::getInstance(); $city = $bregions->city_get($id); if (empty($city)) { return false; } $region = $city->getregion(); if (empty($region)) { return false; } $subcities = $region->cities_get_all(); // $brouter = BRouter::getInstance(); $url = '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'city', 'id' => $id)); $name = $city->getname(); if (!empty($subcities)) { $children = array(); foreach ($subcities as $c) { $children[$c->id] = (object)array('active' => true, 'url' => '//' . $brouter->generateURL('regions', BLang::$langcode, array('view' => 'city', 'id' => $c->id)), 'name' => $c->getname()); } return $this->breadcrumbs_add($url, $name, true, 'city', $children); } return $this->breadcrumbs_add($url, $name, true, 'city'); }
[ "public", "function", "breadcrumbs_add_city", "(", "$", "id", ")", "{", "bimport", "(", "'regions.general'", ")", ";", "$", "bregions", "=", "BRegions", "::", "getInstance", "(", ")", ";", "$", "city", "=", "$", "bregions", "->", "city_get", "(", "$", "id", ")", ";", "if", "(", "empty", "(", "$", "city", ")", ")", "{", "return", "false", ";", "}", "$", "region", "=", "$", "city", "->", "getregion", "(", ")", ";", "if", "(", "empty", "(", "$", "region", ")", ")", "{", "return", "false", ";", "}", "$", "subcities", "=", "$", "region", "->", "cities_get_all", "(", ")", ";", "//", "$", "brouter", "=", "BRouter", "::", "getInstance", "(", ")", ";", "$", "url", "=", "'//'", ".", "$", "brouter", "->", "generateURL", "(", "'regions'", ",", "BLang", "::", "$", "langcode", ",", "array", "(", "'view'", "=>", "'city'", ",", "'id'", "=>", "$", "id", ")", ")", ";", "$", "name", "=", "$", "city", "->", "getname", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "subcities", ")", ")", "{", "$", "children", "=", "array", "(", ")", ";", "foreach", "(", "$", "subcities", "as", "$", "c", ")", "{", "$", "children", "[", "$", "c", "->", "id", "]", "=", "(", "object", ")", "array", "(", "'active'", "=>", "true", ",", "'url'", "=>", "'//'", ".", "$", "brouter", "->", "generateURL", "(", "'regions'", ",", "BLang", "::", "$", "langcode", ",", "array", "(", "'view'", "=>", "'city'", ",", "'id'", "=>", "$", "c", "->", "id", ")", ")", ",", "'name'", "=>", "$", "c", "->", "getname", "(", ")", ")", ";", "}", "return", "$", "this", "->", "breadcrumbs_add", "(", "$", "url", ",", "$", "name", ",", "true", ",", "'city'", ",", "$", "children", ")", ";", "}", "return", "$", "this", "->", "breadcrumbs_add", "(", "$", "url", ",", "$", "name", ",", "true", ",", "'city'", ")", ";", "}" ]
Add city breadcrumbs element @param $id @return bool
[ "Add", "city", "breadcrumbs", "element" ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/MVC/BView.php#L407-L431
11,369
konservs/brilliant.framework
libraries/MVC/BView.php
BView.templateLoad
public function templateLoad($subName = '', $absolute = false) { $this->addPathes(); $suffix = BBrowserUseragent::getDeviceSuffix(); // if ($absolute) { $fNames = array($subName . $suffix . '.php', $subName . '.d.php'); } else { if (!empty($subName)) { $subName = '.' . $subName; } $fNames = array($this->componentname . '.' . $this->viewname . $subName . $suffix . '.php', $this->componentname . '.' . $this->viewname . $subName . '.d.php', $this->componentname . '.' . $this->viewname . $suffix . '.php', $this->componentname . '.' . $this->viewname . '.d.php'); } $filename = ''; $subfname = ''; foreach ($this->paths as $fp) { if (!empty($filename)) { break; } foreach ($fNames as $fn) { if (DEBUG_MODE) { BLog::addToLog('[View] try to load template:' . $fp . $fn); } if (file_exists($fp . $fn)) { $filename = $fp . $fn; $subfname = $fn; break; } } } if (empty($filename)) { return ''; } //Rendering template file into string... ob_start(); include $filename; $html = ob_get_clean(); if (DEBUG_MODE) { $tp = \Brilliant\HTTP\BRequest::GetInt('tp'); if ($tp) { $html = '<div style="font-size: 10px; color: #ccc;">' . $subfname . '</div>' . $html; } } return $html; }
php
public function templateLoad($subName = '', $absolute = false) { $this->addPathes(); $suffix = BBrowserUseragent::getDeviceSuffix(); // if ($absolute) { $fNames = array($subName . $suffix . '.php', $subName . '.d.php'); } else { if (!empty($subName)) { $subName = '.' . $subName; } $fNames = array($this->componentname . '.' . $this->viewname . $subName . $suffix . '.php', $this->componentname . '.' . $this->viewname . $subName . '.d.php', $this->componentname . '.' . $this->viewname . $suffix . '.php', $this->componentname . '.' . $this->viewname . '.d.php'); } $filename = ''; $subfname = ''; foreach ($this->paths as $fp) { if (!empty($filename)) { break; } foreach ($fNames as $fn) { if (DEBUG_MODE) { BLog::addToLog('[View] try to load template:' . $fp . $fn); } if (file_exists($fp . $fn)) { $filename = $fp . $fn; $subfname = $fn; break; } } } if (empty($filename)) { return ''; } //Rendering template file into string... ob_start(); include $filename; $html = ob_get_clean(); if (DEBUG_MODE) { $tp = \Brilliant\HTTP\BRequest::GetInt('tp'); if ($tp) { $html = '<div style="font-size: 10px; color: #ccc;">' . $subfname . '</div>' . $html; } } return $html; }
[ "public", "function", "templateLoad", "(", "$", "subName", "=", "''", ",", "$", "absolute", "=", "false", ")", "{", "$", "this", "->", "addPathes", "(", ")", ";", "$", "suffix", "=", "BBrowserUseragent", "::", "getDeviceSuffix", "(", ")", ";", "//", "if", "(", "$", "absolute", ")", "{", "$", "fNames", "=", "array", "(", "$", "subName", ".", "$", "suffix", ".", "'.php'", ",", "$", "subName", ".", "'.d.php'", ")", ";", "}", "else", "{", "if", "(", "!", "empty", "(", "$", "subName", ")", ")", "{", "$", "subName", "=", "'.'", ".", "$", "subName", ";", "}", "$", "fNames", "=", "array", "(", "$", "this", "->", "componentname", ".", "'.'", ".", "$", "this", "->", "viewname", ".", "$", "subName", ".", "$", "suffix", ".", "'.php'", ",", "$", "this", "->", "componentname", ".", "'.'", ".", "$", "this", "->", "viewname", ".", "$", "subName", ".", "'.d.php'", ",", "$", "this", "->", "componentname", ".", "'.'", ".", "$", "this", "->", "viewname", ".", "$", "suffix", ".", "'.php'", ",", "$", "this", "->", "componentname", ".", "'.'", ".", "$", "this", "->", "viewname", ".", "'.d.php'", ")", ";", "}", "$", "filename", "=", "''", ";", "$", "subfname", "=", "''", ";", "foreach", "(", "$", "this", "->", "paths", "as", "$", "fp", ")", "{", "if", "(", "!", "empty", "(", "$", "filename", ")", ")", "{", "break", ";", "}", "foreach", "(", "$", "fNames", "as", "$", "fn", ")", "{", "if", "(", "DEBUG_MODE", ")", "{", "BLog", "::", "addToLog", "(", "'[View] try to load template:'", ".", "$", "fp", ".", "$", "fn", ")", ";", "}", "if", "(", "file_exists", "(", "$", "fp", ".", "$", "fn", ")", ")", "{", "$", "filename", "=", "$", "fp", ".", "$", "fn", ";", "$", "subfname", "=", "$", "fn", ";", "break", ";", "}", "}", "}", "if", "(", "empty", "(", "$", "filename", ")", ")", "{", "return", "''", ";", "}", "//Rendering template file into string...", "ob_start", "(", ")", ";", "include", "$", "filename", ";", "$", "html", "=", "ob_get_clean", "(", ")", ";", "if", "(", "DEBUG_MODE", ")", "{", "$", "tp", "=", "\\", "Brilliant", "\\", "HTTP", "\\", "BRequest", "::", "GetInt", "(", "'tp'", ")", ";", "if", "(", "$", "tp", ")", "{", "$", "html", "=", "'<div style=\"font-size: 10px; color: #ccc;\">'", ".", "$", "subfname", ".", "'</div>'", ".", "$", "html", ";", "}", "}", "return", "$", "html", ";", "}" ]
Rendering layout into string @param string $subName sub name, if absolute or template name ('users.login') if not. @param bool $absolute true means absolute name @return string
[ "Rendering", "layout", "into", "string" ]
95f03f1917f746fee98bea8a906ba0588c87762d
https://github.com/konservs/brilliant.framework/blob/95f03f1917f746fee98bea8a906ba0588c87762d/libraries/MVC/BView.php#L524-L567
11,370
Silvestra/Silvestra
src/Silvestra/Component/Sitemap/Render/XmlRender.php
XmlRender.renderSitemap
public function renderSitemap(array $entries) { $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; $data .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL; foreach ($entries as $entry) { $data .= ' <url>' . PHP_EOL; $data .= ' <loc>' . $entry->getLoc() . '</loc>' . PHP_EOL; if (null !== $entry->getLastMod()) { $data .= ' <lastmod>' . $entry->getLastMod() . '</lastmod>' . PHP_EOL; } if (null !== $entry->getChangeFreq()) { $data .= ' <changefreq>' . $entry->getChangeFreq() . '</changefreq>' . PHP_EOL; } if (null !== $entry->getPriority()) { $data .= ' <priority>' . $entry->getPriority() . '</priority>' . PHP_EOL; } $data .= ' </url>' . PHP_EOL; } $data .= '</urlset>' . PHP_EOL; return $data; }
php
public function renderSitemap(array $entries) { $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; $data .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL; foreach ($entries as $entry) { $data .= ' <url>' . PHP_EOL; $data .= ' <loc>' . $entry->getLoc() . '</loc>' . PHP_EOL; if (null !== $entry->getLastMod()) { $data .= ' <lastmod>' . $entry->getLastMod() . '</lastmod>' . PHP_EOL; } if (null !== $entry->getChangeFreq()) { $data .= ' <changefreq>' . $entry->getChangeFreq() . '</changefreq>' . PHP_EOL; } if (null !== $entry->getPriority()) { $data .= ' <priority>' . $entry->getPriority() . '</priority>' . PHP_EOL; } $data .= ' </url>' . PHP_EOL; } $data .= '</urlset>' . PHP_EOL; return $data; }
[ "public", "function", "renderSitemap", "(", "array", "$", "entries", ")", "{", "$", "data", "=", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", ".", "PHP_EOL", ";", "$", "data", ".=", "'<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">'", ".", "PHP_EOL", ";", "foreach", "(", "$", "entries", "as", "$", "entry", ")", "{", "$", "data", ".=", "' <url>'", ".", "PHP_EOL", ";", "$", "data", ".=", "' <loc>'", ".", "$", "entry", "->", "getLoc", "(", ")", ".", "'</loc>'", ".", "PHP_EOL", ";", "if", "(", "null", "!==", "$", "entry", "->", "getLastMod", "(", ")", ")", "{", "$", "data", ".=", "' <lastmod>'", ".", "$", "entry", "->", "getLastMod", "(", ")", ".", "'</lastmod>'", ".", "PHP_EOL", ";", "}", "if", "(", "null", "!==", "$", "entry", "->", "getChangeFreq", "(", ")", ")", "{", "$", "data", ".=", "' <changefreq>'", ".", "$", "entry", "->", "getChangeFreq", "(", ")", ".", "'</changefreq>'", ".", "PHP_EOL", ";", "}", "if", "(", "null", "!==", "$", "entry", "->", "getPriority", "(", ")", ")", "{", "$", "data", ".=", "' <priority>'", ".", "$", "entry", "->", "getPriority", "(", ")", ".", "'</priority>'", ".", "PHP_EOL", ";", "}", "$", "data", ".=", "' </url>'", ".", "PHP_EOL", ";", "}", "$", "data", ".=", "'</urlset>'", ".", "PHP_EOL", ";", "return", "$", "data", ";", "}" ]
Render sitemap xml. @param array|UrlEntryInterface[] $entries @return string
[ "Render", "sitemap", "xml", "." ]
b7367601b01495ae3c492b42042f804dee13ab06
https://github.com/Silvestra/Silvestra/blob/b7367601b01495ae3c492b42042f804dee13ab06/src/Silvestra/Component/Sitemap/Render/XmlRender.php#L32-L54
11,371
Silvestra/Silvestra
src/Silvestra/Component/Sitemap/Render/XmlRender.php
XmlRender.renderSitemapIndex
public function renderSitemapIndex(array $entries) { $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; $data .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL; foreach ($entries as $entry) { $data .= ' <sitemap>' . PHP_EOL; $data .= ' <loc>' . $entry->getLoc() . '</loc>' . PHP_EOL; $data .= ' <lastmod>' . $entry->getLastMod() . '</lastmod>' . PHP_EOL; $data .= ' </sitemap>' . PHP_EOL; } $data .= '</sitemapindex>' . PHP_EOL; return $data; }
php
public function renderSitemapIndex(array $entries) { $data = '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL; $data .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">' . PHP_EOL; foreach ($entries as $entry) { $data .= ' <sitemap>' . PHP_EOL; $data .= ' <loc>' . $entry->getLoc() . '</loc>' . PHP_EOL; $data .= ' <lastmod>' . $entry->getLastMod() . '</lastmod>' . PHP_EOL; $data .= ' </sitemap>' . PHP_EOL; } $data .= '</sitemapindex>' . PHP_EOL; return $data; }
[ "public", "function", "renderSitemapIndex", "(", "array", "$", "entries", ")", "{", "$", "data", "=", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", ".", "PHP_EOL", ";", "$", "data", ".=", "'<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">'", ".", "PHP_EOL", ";", "foreach", "(", "$", "entries", "as", "$", "entry", ")", "{", "$", "data", ".=", "' <sitemap>'", ".", "PHP_EOL", ";", "$", "data", ".=", "' <loc>'", ".", "$", "entry", "->", "getLoc", "(", ")", ".", "'</loc>'", ".", "PHP_EOL", ";", "$", "data", ".=", "' <lastmod>'", ".", "$", "entry", "->", "getLastMod", "(", ")", ".", "'</lastmod>'", ".", "PHP_EOL", ";", "$", "data", ".=", "' </sitemap>'", ".", "PHP_EOL", ";", "}", "$", "data", ".=", "'</sitemapindex>'", ".", "PHP_EOL", ";", "return", "$", "data", ";", "}" ]
Render sitemap index xml. @param array|SitemapEntryInterface[] $entries @return string
[ "Render", "sitemap", "index", "xml", "." ]
b7367601b01495ae3c492b42042f804dee13ab06
https://github.com/Silvestra/Silvestra/blob/b7367601b01495ae3c492b42042f804dee13ab06/src/Silvestra/Component/Sitemap/Render/XmlRender.php#L63-L77
11,372
mdzzohrabi/azera-annotation
Annotation.php
Annotation.readClass
public static function readClass( $class , $annotation = null ) { $ref = $class instanceof ReflectionClass ? $class : new ReflectionClass( $class ); return $annotation ? static::reader()->getClassAnnotation( $ref , $annotation ) : static::reader()->getClassAnnotations( $ref ); }
php
public static function readClass( $class , $annotation = null ) { $ref = $class instanceof ReflectionClass ? $class : new ReflectionClass( $class ); return $annotation ? static::reader()->getClassAnnotation( $ref , $annotation ) : static::reader()->getClassAnnotations( $ref ); }
[ "public", "static", "function", "readClass", "(", "$", "class", ",", "$", "annotation", "=", "null", ")", "{", "$", "ref", "=", "$", "class", "instanceof", "ReflectionClass", "?", "$", "class", ":", "new", "ReflectionClass", "(", "$", "class", ")", ";", "return", "$", "annotation", "?", "static", "::", "reader", "(", ")", "->", "getClassAnnotation", "(", "$", "ref", ",", "$", "annotation", ")", ":", "static", "::", "reader", "(", ")", "->", "getClassAnnotations", "(", "$", "ref", ")", ";", "}" ]
Retreive class annotations @param string $class Class @param string $annotation Specified annotation name @return mixed
[ "Retreive", "class", "annotations" ]
dbf8b66941ff76d69e22ffe61ec93c648cd0aea6
https://github.com/mdzzohrabi/azera-annotation/blob/dbf8b66941ff76d69e22ffe61ec93c648cd0aea6/Annotation.php#L74-L80
11,373
Vovan-VE/array-dumper
src/helpers/StringHelper.php
StringHelper.isUtf8String
public static function isUtf8String(string $string): bool { // Keep calm. Just `mb_check_encoding($string, 'UTF-8')` sucks // PCRE `/u` is about 10 times faster. // https://3v4l.org/XYQ2A if (false !== \preg_match('/\\G/u', $string)) { return true; } if (\PREG_BAD_UTF8_ERROR === \preg_last_error()) { return false; } throw new \LogicException('Another unexpected failure happened with PCRE'); }
php
public static function isUtf8String(string $string): bool { // Keep calm. Just `mb_check_encoding($string, 'UTF-8')` sucks // PCRE `/u` is about 10 times faster. // https://3v4l.org/XYQ2A if (false !== \preg_match('/\\G/u', $string)) { return true; } if (\PREG_BAD_UTF8_ERROR === \preg_last_error()) { return false; } throw new \LogicException('Another unexpected failure happened with PCRE'); }
[ "public", "static", "function", "isUtf8String", "(", "string", "$", "string", ")", ":", "bool", "{", "// Keep calm. Just `mb_check_encoding($string, 'UTF-8')` sucks", "// PCRE `/u` is about 10 times faster.", "// https://3v4l.org/XYQ2A", "if", "(", "false", "!==", "\\", "preg_match", "(", "'/\\\\G/u'", ",", "$", "string", ")", ")", "{", "return", "true", ";", "}", "if", "(", "\\", "PREG_BAD_UTF8_ERROR", "===", "\\", "preg_last_error", "(", ")", ")", "{", "return", "false", ";", "}", "throw", "new", "\\", "LogicException", "(", "'Another unexpected failure happened with PCRE'", ")", ";", "}" ]
Checks if a string is valid UTF-8 string @param string $string Input string to test @return bool Whether the input string is valid UTF-8 data
[ "Checks", "if", "a", "string", "is", "valid", "UTF", "-", "8", "string" ]
63fe868a7539cdf020851dae7fe1248bd014a1ef
https://github.com/Vovan-VE/array-dumper/blob/63fe868a7539cdf020851dae7fe1248bd014a1ef/src/helpers/StringHelper.php#L15-L28
11,374
Vovan-VE/array-dumper
src/helpers/StringHelper.php
StringHelper.dumpString
public static function dumpString(string $value): string { if ('' === $value) { return "''"; } // non UTF-8 string will encode "\xFF" and require <"> if (!self::isUtf8String($value)) { return '"' . \preg_replace_callback( // --------------------------------------------------- // 0x80 .. 0x7FF => C2 80 ... DF BF // --------------------------------------------------- // 0x800 .. 0xFFF => E0 A0 80 ... E0 BF BF // 0x1000 .. 0xFFFF => E1 80 80 ... EF BF BF // --------------------------------------------------- // 0x10000 .. 0x3FFFF => F0 90 80 80 ... F0 BF BF BF // 0x40000 .. 0xFFFFF => F1 80 80 80 ... F3 BF BF BF // 0x100000 .. 0x10FFFF => F4 80 80 80 ... F4 8F BF BF // " \x22 // $ \x24 // \ \x5C '/ \\G (?: [\\x20\\x21\\x23\\x25-\\x5B\\x5D-\\x7E]++ | [\\xC2-\\xDF] [\\x80-\\xBF] | \\xE0 [\\xA0-\\xBF] [\\x80-\\xBF] | [\\xE1-\\xEF] [\\x80-\\xBF]{2} | \\xF0 [\\x90-\\xBF] [\\x80-\\xBF]{2} | [\\xF1-\\xF3] [\\x80-\\xBF]{3} | \\xF4 [\\x80-\\x8F] [\\x80-\\xBF]{2} )*+ \\K (?: ( ["$\\\\] ) | ( . ) ) /xs', /** @uses _escapeStringCallback() */ \Closure::fromCallable([__CLASS__, '_escapeStringCallback']), $value ) . '"'; } // valid UTF-8 string with control ASCII characters // also will encode "\xFF" and require <">, but regexp is much simple if (\preg_match('/[\\x00-\\x1F\\x7F]/', $value)) { return '"' . \preg_replace_callback( '/(["$\\\\])|([\\x00-\\x1F\\x7F])/', /** @uses _escapeStringCallback() */ \Closure::fromCallable([__CLASS__, '_escapeStringCallback']), $value ) . '"'; } return \var_export($value, true); }
php
public static function dumpString(string $value): string { if ('' === $value) { return "''"; } // non UTF-8 string will encode "\xFF" and require <"> if (!self::isUtf8String($value)) { return '"' . \preg_replace_callback( // --------------------------------------------------- // 0x80 .. 0x7FF => C2 80 ... DF BF // --------------------------------------------------- // 0x800 .. 0xFFF => E0 A0 80 ... E0 BF BF // 0x1000 .. 0xFFFF => E1 80 80 ... EF BF BF // --------------------------------------------------- // 0x10000 .. 0x3FFFF => F0 90 80 80 ... F0 BF BF BF // 0x40000 .. 0xFFFFF => F1 80 80 80 ... F3 BF BF BF // 0x100000 .. 0x10FFFF => F4 80 80 80 ... F4 8F BF BF // " \x22 // $ \x24 // \ \x5C '/ \\G (?: [\\x20\\x21\\x23\\x25-\\x5B\\x5D-\\x7E]++ | [\\xC2-\\xDF] [\\x80-\\xBF] | \\xE0 [\\xA0-\\xBF] [\\x80-\\xBF] | [\\xE1-\\xEF] [\\x80-\\xBF]{2} | \\xF0 [\\x90-\\xBF] [\\x80-\\xBF]{2} | [\\xF1-\\xF3] [\\x80-\\xBF]{3} | \\xF4 [\\x80-\\x8F] [\\x80-\\xBF]{2} )*+ \\K (?: ( ["$\\\\] ) | ( . ) ) /xs', /** @uses _escapeStringCallback() */ \Closure::fromCallable([__CLASS__, '_escapeStringCallback']), $value ) . '"'; } // valid UTF-8 string with control ASCII characters // also will encode "\xFF" and require <">, but regexp is much simple if (\preg_match('/[\\x00-\\x1F\\x7F]/', $value)) { return '"' . \preg_replace_callback( '/(["$\\\\])|([\\x00-\\x1F\\x7F])/', /** @uses _escapeStringCallback() */ \Closure::fromCallable([__CLASS__, '_escapeStringCallback']), $value ) . '"'; } return \var_export($value, true); }
[ "public", "static", "function", "dumpString", "(", "string", "$", "value", ")", ":", "string", "{", "if", "(", "''", "===", "$", "value", ")", "{", "return", "\"''\"", ";", "}", "// non UTF-8 string will encode \"\\xFF\" and require <\">", "if", "(", "!", "self", "::", "isUtf8String", "(", "$", "value", ")", ")", "{", "return", "'\"'", ".", "\\", "preg_replace_callback", "(", "// ---------------------------------------------------", "// 0x80 .. 0x7FF => C2 80 ... DF BF", "// ---------------------------------------------------", "// 0x800 .. 0xFFF => E0 A0 80 ... E0 BF BF", "// 0x1000 .. 0xFFFF => E1 80 80 ... EF BF BF", "// ---------------------------------------------------", "// 0x10000 .. 0x3FFFF => F0 90 80 80 ... F0 BF BF BF", "// 0x40000 .. 0xFFFFF => F1 80 80 80 ... F3 BF BF BF", "// 0x100000 .. 0x10FFFF => F4 80 80 80 ... F4 8F BF BF", "// \" \\x22", "// $ \\x24", "// \\ \\x5C", "'/\n \\\\G\n (?:\n [\\\\x20\\\\x21\\\\x23\\\\x25-\\\\x5B\\\\x5D-\\\\x7E]++\n | [\\\\xC2-\\\\xDF] [\\\\x80-\\\\xBF]\n | \\\\xE0 [\\\\xA0-\\\\xBF] [\\\\x80-\\\\xBF]\n | [\\\\xE1-\\\\xEF] [\\\\x80-\\\\xBF]{2}\n | \\\\xF0 [\\\\x90-\\\\xBF] [\\\\x80-\\\\xBF]{2}\n | [\\\\xF1-\\\\xF3] [\\\\x80-\\\\xBF]{3}\n | \\\\xF4 [\\\\x80-\\\\x8F] [\\\\x80-\\\\xBF]{2}\n )*+\n \\\\K\n (?:\n ( [\"$\\\\\\\\] )\n |\n ( . )\n )\n /xs'", ",", "/** @uses _escapeStringCallback() */", "\\", "Closure", "::", "fromCallable", "(", "[", "__CLASS__", ",", "'_escapeStringCallback'", "]", ")", ",", "$", "value", ")", ".", "'\"'", ";", "}", "// valid UTF-8 string with control ASCII characters", "// also will encode \"\\xFF\" and require <\">, but regexp is much simple", "if", "(", "\\", "preg_match", "(", "'/[\\\\x00-\\\\x1F\\\\x7F]/'", ",", "$", "value", ")", ")", "{", "return", "'\"'", ".", "\\", "preg_replace_callback", "(", "'/([\"$\\\\\\\\])|([\\\\x00-\\\\x1F\\\\x7F])/'", ",", "/** @uses _escapeStringCallback() */", "\\", "Closure", "::", "fromCallable", "(", "[", "__CLASS__", ",", "'_escapeStringCallback'", "]", ")", ",", "$", "value", ")", ".", "'\"'", ";", "}", "return", "\\", "var_export", "(", "$", "value", ",", "true", ")", ";", "}" ]
Dump string to PHP string literal @param string $value Input string @return string PHP code of string literal. Doing `eval()` of this code will return a string identical `===` to input string.
[ "Dump", "string", "to", "PHP", "string", "literal" ]
63fe868a7539cdf020851dae7fe1248bd014a1ef
https://github.com/Vovan-VE/array-dumper/blob/63fe868a7539cdf020851dae7fe1248bd014a1ef/src/helpers/StringHelper.php#L46-L104
11,375
Vovan-VE/array-dumper
src/helpers/StringHelper.php
StringHelper._escapeStringCallback
private static function _escapeStringCallback(array $match): string { if (isset($match[2])) { return self::ESCAPE_SPECIALS[$match[2]] ?? \sprintf('\\x%02X', \ord($match[2])); } return '\\' . $match[1]; }
php
private static function _escapeStringCallback(array $match): string { if (isset($match[2])) { return self::ESCAPE_SPECIALS[$match[2]] ?? \sprintf('\\x%02X', \ord($match[2])); } return '\\' . $match[1]; }
[ "private", "static", "function", "_escapeStringCallback", "(", "array", "$", "match", ")", ":", "string", "{", "if", "(", "isset", "(", "$", "match", "[", "2", "]", ")", ")", "{", "return", "self", "::", "ESCAPE_SPECIALS", "[", "$", "match", "[", "2", "]", "]", "??", "\\", "sprintf", "(", "'\\\\x%02X'", ",", "\\", "ord", "(", "$", "match", "[", "2", "]", ")", ")", ";", "}", "return", "'\\\\'", ".", "$", "match", "[", "1", "]", ";", "}" ]
Internal callback to escape characters @param array $match A match from `preg_replace_callback()` @return string
[ "Internal", "callback", "to", "escape", "characters" ]
63fe868a7539cdf020851dae7fe1248bd014a1ef
https://github.com/Vovan-VE/array-dumper/blob/63fe868a7539cdf020851dae7fe1248bd014a1ef/src/helpers/StringHelper.php#L118-L125
11,376
fabsgc/framework
Core/Collection/Collection.php
Collection.delete
public function delete($key) { unset($this->_datas[$key]); $this->_datas = array_values($this->_datas); }
php
public function delete($key) { unset($this->_datas[$key]); $this->_datas = array_values($this->_datas); }
[ "public", "function", "delete", "(", "$", "key", ")", "{", "unset", "(", "$", "this", "->", "_datas", "[", "$", "key", "]", ")", ";", "$", "this", "->", "_datas", "=", "array_values", "(", "$", "this", "->", "_datas", ")", ";", "}" ]
Delete one element from the collection @access public @param $key mixed @return void @since 3.0 @package Gcs\Framework\Core\Collecion
[ "Delete", "one", "element", "from", "the", "collection" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Collection/Collection.php#L100-L103
11,377
fabsgc/framework
Core/Collection/Collection.php
Collection.deleteRange
public function deleteRange($key, $length) { $badKeys = []; for ($i = $key; $i < $key + $length; $i++) { array_push($badKeys, $i); } $this->_datas = array_diff_key($this->_datas, array_flip($badKeys)); $this->_datas = array_values($this->_datas); }
php
public function deleteRange($key, $length) { $badKeys = []; for ($i = $key; $i < $key + $length; $i++) { array_push($badKeys, $i); } $this->_datas = array_diff_key($this->_datas, array_flip($badKeys)); $this->_datas = array_values($this->_datas); }
[ "public", "function", "deleteRange", "(", "$", "key", ",", "$", "length", ")", "{", "$", "badKeys", "=", "[", "]", ";", "for", "(", "$", "i", "=", "$", "key", ";", "$", "i", "<", "$", "key", "+", "$", "length", ";", "$", "i", "++", ")", "{", "array_push", "(", "$", "badKeys", ",", "$", "i", ")", ";", "}", "$", "this", "->", "_datas", "=", "array_diff_key", "(", "$", "this", "->", "_datas", ",", "array_flip", "(", "$", "badKeys", ")", ")", ";", "$", "this", "->", "_datas", "=", "array_values", "(", "$", "this", "->", "_datas", ")", ";", "}" ]
Delete between 2 keys @access public @param $key int @param $length int @return void @since 3.0 @package Gcs\Framework\Core\Collecion
[ "Delete", "between", "2", "keys" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Collection/Collection.php#L115-L124
11,378
fabsgc/framework
Core/Collection/Collection.php
Collection.getRange
public function getRange($key, $length) { $badKeys = []; for ($i = 0; $i < $key; $i++) { array_push($badKeys, $i); } for ($i = $key + $length; $i < count($this->_datas); $i++) { array_push($badKeys, $i); } return array_diff_key($this->_datas, array_flip($badKeys)); }
php
public function getRange($key, $length) { $badKeys = []; for ($i = 0; $i < $key; $i++) { array_push($badKeys, $i); } for ($i = $key + $length; $i < count($this->_datas); $i++) { array_push($badKeys, $i); } return array_diff_key($this->_datas, array_flip($badKeys)); }
[ "public", "function", "getRange", "(", "$", "key", ",", "$", "length", ")", "{", "$", "badKeys", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "key", ";", "$", "i", "++", ")", "{", "array_push", "(", "$", "badKeys", ",", "$", "i", ")", ";", "}", "for", "(", "$", "i", "=", "$", "key", "+", "$", "length", ";", "$", "i", "<", "count", "(", "$", "this", "->", "_datas", ")", ";", "$", "i", "++", ")", "{", "array_push", "(", "$", "badKeys", ",", "$", "i", ")", ";", "}", "return", "array_diff_key", "(", "$", "this", "->", "_datas", ",", "array_flip", "(", "$", "badKeys", ")", ")", ";", "}" ]
Get between 2 keys @access public @param $key int @param $length int @return array @since 3.0 @package Gcs\Framework\Core\Collecion
[ "Get", "between", "2", "keys" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Collection/Collection.php#L136-L148
11,379
fabsgc/framework
Core/Collection/Collection.php
Collection.filter
public function filter($closure) { $collection = new Collection(); foreach ($this->_datas as $data) { if ($closure($data)) { $collection->add($data); } } return $collection; }
php
public function filter($closure) { $collection = new Collection(); foreach ($this->_datas as $data) { if ($closure($data)) { $collection->add($data); } } return $collection; }
[ "public", "function", "filter", "(", "$", "closure", ")", "{", "$", "collection", "=", "new", "Collection", "(", ")", ";", "foreach", "(", "$", "this", "->", "_datas", "as", "$", "data", ")", "{", "if", "(", "$", "closure", "(", "$", "data", ")", ")", "{", "$", "collection", "->", "add", "(", "$", "data", ")", ";", "}", "}", "return", "$", "collection", ";", "}" ]
Filter the collection with a closure @access public @param $closure callable @return Collection @since 3.0 @package Gcs\Framework\Core\Collecion
[ "Filter", "the", "collection", "with", "a", "closure" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Collection/Collection.php#L159-L169
11,380
fabsgc/framework
Core/Collection/Collection.php
Collection.add
public function add($data) { if (!array_search($data, $this->_datas, true) && is_object($data)) { $data = clone $data; } if (is_array($data)) { $this->_datas = array_merge($this->_datas, $data); } else { if (get_class($data) != 'Gcs\Framework\Core\Collection\Collection') { array_push($this->_datas, $data); } else { array_merge($this->_datas, $data->data()); } } }
php
public function add($data) { if (!array_search($data, $this->_datas, true) && is_object($data)) { $data = clone $data; } if (is_array($data)) { $this->_datas = array_merge($this->_datas, $data); } else { if (get_class($data) != 'Gcs\Framework\Core\Collection\Collection') { array_push($this->_datas, $data); } else { array_merge($this->_datas, $data->data()); } } }
[ "public", "function", "add", "(", "$", "data", ")", "{", "if", "(", "!", "array_search", "(", "$", "data", ",", "$", "this", "->", "_datas", ",", "true", ")", "&&", "is_object", "(", "$", "data", ")", ")", "{", "$", "data", "=", "clone", "$", "data", ";", "}", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "this", "->", "_datas", "=", "array_merge", "(", "$", "this", "->", "_datas", ",", "$", "data", ")", ";", "}", "else", "{", "if", "(", "get_class", "(", "$", "data", ")", "!=", "'Gcs\\Framework\\Core\\Collection\\Collection'", ")", "{", "array_push", "(", "$", "this", "->", "_datas", ",", "$", "data", ")", ";", "}", "else", "{", "array_merge", "(", "$", "this", "->", "_datas", ",", "$", "data", "->", "data", "(", ")", ")", ";", "}", "}", "}" ]
Add elements to the collection @access public @param $data mixed array[], Collection @return void @since 3.0 @package Gcs\Framework\Core\Collecion
[ "Add", "elements", "to", "the", "collection" ]
45e58182aba6a3c6381970a1fd3c17662cff2168
https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Collection/Collection.php#L180-L196
11,381
eix/core
src/php/main/Eix/Core/Responders/Http.php
Http.getResponse
final public function getResponse() { if (empty($this->response)) { $httpMethod = $this->getRequest() ? strtoupper($this->getRequest()->getMethod()) : 'GET' ; if ($this->isHttpMethodSupported($httpMethod)) { $functionName = $this->getFunctionName($httpMethod); Logger::get()->debug("Running responder method '$functionName'..."); // If the responder is a restricted one... if ($this instanceof \Eix\Core\Responders\Restricted) { // ... ensure the user is allowed to use that function. Users::getCurrent()->checkAuthorisation($this, $functionName); } // The response is the result of executing the appropriate // responder function. $this->response = $this->$functionName(); } else { throw new \Eix\Services\Net\Http\MethodNotAllowedException("This responder does not support {$httpMethod} requests."); } } return $this->response; }
php
final public function getResponse() { if (empty($this->response)) { $httpMethod = $this->getRequest() ? strtoupper($this->getRequest()->getMethod()) : 'GET' ; if ($this->isHttpMethodSupported($httpMethod)) { $functionName = $this->getFunctionName($httpMethod); Logger::get()->debug("Running responder method '$functionName'..."); // If the responder is a restricted one... if ($this instanceof \Eix\Core\Responders\Restricted) { // ... ensure the user is allowed to use that function. Users::getCurrent()->checkAuthorisation($this, $functionName); } // The response is the result of executing the appropriate // responder function. $this->response = $this->$functionName(); } else { throw new \Eix\Services\Net\Http\MethodNotAllowedException("This responder does not support {$httpMethod} requests."); } } return $this->response; }
[ "final", "public", "function", "getResponse", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "response", ")", ")", "{", "$", "httpMethod", "=", "$", "this", "->", "getRequest", "(", ")", "?", "strtoupper", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getMethod", "(", ")", ")", ":", "'GET'", ";", "if", "(", "$", "this", "->", "isHttpMethodSupported", "(", "$", "httpMethod", ")", ")", "{", "$", "functionName", "=", "$", "this", "->", "getFunctionName", "(", "$", "httpMethod", ")", ";", "Logger", "::", "get", "(", ")", "->", "debug", "(", "\"Running responder method '$functionName'...\"", ")", ";", "// If the responder is a restricted one...", "if", "(", "$", "this", "instanceof", "\\", "Eix", "\\", "Core", "\\", "Responders", "\\", "Restricted", ")", "{", "// ... ensure the user is allowed to use that function.", "Users", "::", "getCurrent", "(", ")", "->", "checkAuthorisation", "(", "$", "this", ",", "$", "functionName", ")", ";", "}", "// The response is the result of executing the appropriate", "// responder function.", "$", "this", "->", "response", "=", "$", "this", "->", "$", "functionName", "(", ")", ";", "}", "else", "{", "throw", "new", "\\", "Eix", "\\", "Services", "\\", "Net", "\\", "Http", "\\", "MethodNotAllowedException", "(", "\"This responder does not support {$httpMethod} requests.\"", ")", ";", "}", "}", "return", "$", "this", "->", "response", ";", "}" ]
The default behaviour consists of executing a function named after the HTTP method and the eventual action contained in the request, to produce a Response object. @return \Eix\Core\Response @throws \Eix\Core\Exception
[ "The", "default", "behaviour", "consists", "of", "executing", "a", "function", "named", "after", "the", "HTTP", "method", "and", "the", "eventual", "action", "contained", "in", "the", "request", "to", "produce", "a", "Response", "object", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Responders/Http.php#L54-L80
11,382
eix/core
src/php/main/Eix/Core/Responders/Http.php
Http.getFunctionName
private function getFunctionName($httpMethod) { if ($this->getRequest()) { $functionName = null; // Prefix starts with 'http'. $functionPrefix = 'http'; // The HTTP method is then appended. $functionPrefix .= ucfirst(strtolower($httpMethod)); // If an action has been captured in the URI, append it too. $action = $this->getRequest()->getParameter('action'); if ($action) { $functionPrefix .= ucfirst($action); // If there is an action, check whether the function is likely // to exist. if (!$this->isBaseFunctionAvailable($functionPrefix)) { throw new \Eix\Services\Net\Http\NotFoundException( "This responder does not have any methods starting with {$functionPrefix}." ); } } $found = false; $acceptedContentTypes = $this->getRequest()->getAcceptedContentTypes(); // Append a token to the function name, based on the requested content foreach ($acceptedContentTypes as $contentType => $quality) { try { $contentTypeToken = \Eix\Core\Requests\Http::getContentTypeToken($contentType); // Append the token for the response's expected content type. $functionName = $functionPrefix . 'For' . $contentTypeToken; Logger::get()->debug("Trying {$functionName} for {$contentType}..."); // Check whether a method with that name exists. if (method_exists($this, $functionName)) { return $functionName; } } catch (\InvalidArgumentException $exception) { // This content type is invalid, keep on checking. } } // Although a base method exists, it does not for this content type, // so that's a 406. throw new \Eix\Services\Net\Http\NotAcceptableException( "This responder cannot serve content type {$contentType}." ); } else { // If there is no request, return the generic responder method. return 'httpGetForAll'; } }
php
private function getFunctionName($httpMethod) { if ($this->getRequest()) { $functionName = null; // Prefix starts with 'http'. $functionPrefix = 'http'; // The HTTP method is then appended. $functionPrefix .= ucfirst(strtolower($httpMethod)); // If an action has been captured in the URI, append it too. $action = $this->getRequest()->getParameter('action'); if ($action) { $functionPrefix .= ucfirst($action); // If there is an action, check whether the function is likely // to exist. if (!$this->isBaseFunctionAvailable($functionPrefix)) { throw new \Eix\Services\Net\Http\NotFoundException( "This responder does not have any methods starting with {$functionPrefix}." ); } } $found = false; $acceptedContentTypes = $this->getRequest()->getAcceptedContentTypes(); // Append a token to the function name, based on the requested content foreach ($acceptedContentTypes as $contentType => $quality) { try { $contentTypeToken = \Eix\Core\Requests\Http::getContentTypeToken($contentType); // Append the token for the response's expected content type. $functionName = $functionPrefix . 'For' . $contentTypeToken; Logger::get()->debug("Trying {$functionName} for {$contentType}..."); // Check whether a method with that name exists. if (method_exists($this, $functionName)) { return $functionName; } } catch (\InvalidArgumentException $exception) { // This content type is invalid, keep on checking. } } // Although a base method exists, it does not for this content type, // so that's a 406. throw new \Eix\Services\Net\Http\NotAcceptableException( "This responder cannot serve content type {$contentType}." ); } else { // If there is no request, return the generic responder method. return 'httpGetForAll'; } }
[ "private", "function", "getFunctionName", "(", "$", "httpMethod", ")", "{", "if", "(", "$", "this", "->", "getRequest", "(", ")", ")", "{", "$", "functionName", "=", "null", ";", "// Prefix starts with 'http'.", "$", "functionPrefix", "=", "'http'", ";", "// The HTTP method is then appended.", "$", "functionPrefix", ".=", "ucfirst", "(", "strtolower", "(", "$", "httpMethod", ")", ")", ";", "// If an action has been captured in the URI, append it too.", "$", "action", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getParameter", "(", "'action'", ")", ";", "if", "(", "$", "action", ")", "{", "$", "functionPrefix", ".=", "ucfirst", "(", "$", "action", ")", ";", "// If there is an action, check whether the function is likely", "// to exist.", "if", "(", "!", "$", "this", "->", "isBaseFunctionAvailable", "(", "$", "functionPrefix", ")", ")", "{", "throw", "new", "\\", "Eix", "\\", "Services", "\\", "Net", "\\", "Http", "\\", "NotFoundException", "(", "\"This responder does not have any methods starting with {$functionPrefix}.\"", ")", ";", "}", "}", "$", "found", "=", "false", ";", "$", "acceptedContentTypes", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getAcceptedContentTypes", "(", ")", ";", "// Append a token to the function name, based on the requested content", "foreach", "(", "$", "acceptedContentTypes", "as", "$", "contentType", "=>", "$", "quality", ")", "{", "try", "{", "$", "contentTypeToken", "=", "\\", "Eix", "\\", "Core", "\\", "Requests", "\\", "Http", "::", "getContentTypeToken", "(", "$", "contentType", ")", ";", "// Append the token for the response's expected content type.", "$", "functionName", "=", "$", "functionPrefix", ".", "'For'", ".", "$", "contentTypeToken", ";", "Logger", "::", "get", "(", ")", "->", "debug", "(", "\"Trying {$functionName} for {$contentType}...\"", ")", ";", "// Check whether a method with that name exists.", "if", "(", "method_exists", "(", "$", "this", ",", "$", "functionName", ")", ")", "{", "return", "$", "functionName", ";", "}", "}", "catch", "(", "\\", "InvalidArgumentException", "$", "exception", ")", "{", "// This content type is invalid, keep on checking.", "}", "}", "// Although a base method exists, it does not for this content type,", "// so that's a 406.", "throw", "new", "\\", "Eix", "\\", "Services", "\\", "Net", "\\", "Http", "\\", "NotAcceptableException", "(", "\"This responder cannot serve content type {$contentType}.\"", ")", ";", "}", "else", "{", "// If there is no request, return the generic responder method.", "return", "'httpGetForAll'", ";", "}", "}" ]
Returns a function name that represents the method and response's expected content type. e.g. httpGetForHtml represents a GET request expecting HTML back. e.g. httpPostForJson represents a POST request expecting JSON back. e.g. httpPutForAll represents a PUT request expecting whatever back.
[ "Returns", "a", "function", "name", "that", "represents", "the", "method", "and", "response", "s", "expected", "content", "type", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Responders/Http.php#L90-L138
11,383
eix/core
src/php/main/Eix/Core/Responders/Http.php
Http.isHttpMethodSupported
private function isHttpMethodSupported($requestMethod) { $requestMethodName = 'http' . ucfirst(strtolower($requestMethod)); foreach (get_class_methods($this) as $methodName) { if (strpos($methodName, $requestMethodName) === 0) { return true; } } return false; }
php
private function isHttpMethodSupported($requestMethod) { $requestMethodName = 'http' . ucfirst(strtolower($requestMethod)); foreach (get_class_methods($this) as $methodName) { if (strpos($methodName, $requestMethodName) === 0) { return true; } } return false; }
[ "private", "function", "isHttpMethodSupported", "(", "$", "requestMethod", ")", "{", "$", "requestMethodName", "=", "'http'", ".", "ucfirst", "(", "strtolower", "(", "$", "requestMethod", ")", ")", ";", "foreach", "(", "get_class_methods", "(", "$", "this", ")", "as", "$", "methodName", ")", "{", "if", "(", "strpos", "(", "$", "methodName", ",", "$", "requestMethodName", ")", "===", "0", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check whether there is at least one function that implements the requested HTTP method.
[ "Check", "whether", "there", "is", "at", "least", "one", "function", "that", "implements", "the", "requested", "HTTP", "method", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Responders/Http.php#L144-L154
11,384
eix/core
src/php/main/Eix/Core/Responders/Http.php
Http.isBaseFunctionAvailable
private function isBaseFunctionAvailable($functionName) { foreach (get_class_methods($this) as $responderMethodName) { if (strpos($responderMethodName, $functionName) === 0) { return true; } } return false; }
php
private function isBaseFunctionAvailable($functionName) { foreach (get_class_methods($this) as $responderMethodName) { if (strpos($responderMethodName, $functionName) === 0) { return true; } } return false; }
[ "private", "function", "isBaseFunctionAvailable", "(", "$", "functionName", ")", "{", "foreach", "(", "get_class_methods", "(", "$", "this", ")", "as", "$", "responderMethodName", ")", "{", "if", "(", "strpos", "(", "$", "responderMethodName", ",", "$", "functionName", ")", "===", "0", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check whether there is at least one function that implements the requested HTTP method and an eventual action.
[ "Check", "whether", "there", "is", "at", "least", "one", "function", "that", "implements", "the", "requested", "HTTP", "method", "and", "an", "eventual", "action", "." ]
a5b4c09cc168221e85804fdfeb78e519a0415466
https://github.com/eix/core/blob/a5b4c09cc168221e85804fdfeb78e519a0415466/src/php/main/Eix/Core/Responders/Http.php#L160-L169
11,385
tekkla/core-html
Core/Html/Bootstrap/Navbar/LinkElement.php
LinkElement.isAjax
public function isAjax($ajax=null) { if (isset($ajax)) { $this->ajax = (bool) $ajax; return $this; } else { return $this->ajax; } }
php
public function isAjax($ajax=null) { if (isset($ajax)) { $this->ajax = (bool) $ajax; return $this; } else { return $this->ajax; } }
[ "public", "function", "isAjax", "(", "$", "ajax", "=", "null", ")", "{", "if", "(", "isset", "(", "$", "ajax", ")", ")", "{", "$", "this", "->", "ajax", "=", "(", "bool", ")", "$", "ajax", ";", "return", "$", "this", ";", "}", "else", "{", "return", "$", "this", "->", "ajax", ";", "}", "}" ]
Sets or gets ajax flag. @param string $ajax @return <boolean>, <\Core\Html\Bootstrap\Navbar\LinkElement>
[ "Sets", "or", "gets", "ajax", "flag", "." ]
00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3
https://github.com/tekkla/core-html/blob/00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3/Core/Html/Bootstrap/Navbar/LinkElement.php#L97-L106
11,386
sirgrimorum/crudgenerator
src/CrudGeneratorCommands.php
CrudGeneratorCommands.sendalert
public function sendalert() { $alertaClass = $this->console->ask("Notification Class?"); if (class_exists($alertaClass)) { $email = $this->console->anticipate("User email?", ['[email protected]']); if ($toUser = \App\User::where("email", "=", $email)->first()) { $message = $this->console->ask("Message?"); /* $options = array( 'cluster' => 'us2', 'encrypted' => true ); $pusher = new Pusher( 'adf503a8756876656ec6', 'b21a0ee639fbb893e41d', '481076', $options ); */ $data = []; $data['message'] = $message; /* $result = $pusher->trigger('my-channel', 'my-event', $data, null, true); $this->console->line(print_r($result, true)); */ $tiempo = $this->console->ask("Send in? (Just a number,next you will select seconds, minutes, etc.)"); if (!is_int((int) $tiempo)) { $tiempo = $this->console->ask("Send in? HAS TO BE AN INTEGER NUMBER"); } if (is_int((int) $tiempo)) { $unidad = $this->console->choice('...', ['seconds', 'minutes', 'hours', 'days'], 0); switch ($unidad) { case 'seconds': $when = now()->addSeconds($tiempo); break; case 'minutes': $when = now()->addMinutes($tiempo); break; case 'hours': $when = now()->addHours($tiempo); break; case 'days': $when = now()->addDays($tiempo); break; default: $when = now()->addMinutes($tiempo); break; } $toUser->notify((new $alertaClass($data)) ->delay($when) ); $this->console->info("Listo!"); } else { $this->console->error("Paila!"); } } else { $this->console->error("User not found"); } } else { $this->console->error("Class not found"); } }
php
public function sendalert() { $alertaClass = $this->console->ask("Notification Class?"); if (class_exists($alertaClass)) { $email = $this->console->anticipate("User email?", ['[email protected]']); if ($toUser = \App\User::where("email", "=", $email)->first()) { $message = $this->console->ask("Message?"); /* $options = array( 'cluster' => 'us2', 'encrypted' => true ); $pusher = new Pusher( 'adf503a8756876656ec6', 'b21a0ee639fbb893e41d', '481076', $options ); */ $data = []; $data['message'] = $message; /* $result = $pusher->trigger('my-channel', 'my-event', $data, null, true); $this->console->line(print_r($result, true)); */ $tiempo = $this->console->ask("Send in? (Just a number,next you will select seconds, minutes, etc.)"); if (!is_int((int) $tiempo)) { $tiempo = $this->console->ask("Send in? HAS TO BE AN INTEGER NUMBER"); } if (is_int((int) $tiempo)) { $unidad = $this->console->choice('...', ['seconds', 'minutes', 'hours', 'days'], 0); switch ($unidad) { case 'seconds': $when = now()->addSeconds($tiempo); break; case 'minutes': $when = now()->addMinutes($tiempo); break; case 'hours': $when = now()->addHours($tiempo); break; case 'days': $when = now()->addDays($tiempo); break; default: $when = now()->addMinutes($tiempo); break; } $toUser->notify((new $alertaClass($data)) ->delay($when) ); $this->console->info("Listo!"); } else { $this->console->error("Paila!"); } } else { $this->console->error("User not found"); } } else { $this->console->error("Class not found"); } }
[ "public", "function", "sendalert", "(", ")", "{", "$", "alertaClass", "=", "$", "this", "->", "console", "->", "ask", "(", "\"Notification Class?\"", ")", ";", "if", "(", "class_exists", "(", "$", "alertaClass", ")", ")", "{", "$", "email", "=", "$", "this", "->", "console", "->", "anticipate", "(", "\"User email?\"", ",", "[", "'[email protected]'", "]", ")", ";", "if", "(", "$", "toUser", "=", "\\", "App", "\\", "User", "::", "where", "(", "\"email\"", ",", "\"=\"", ",", "$", "email", ")", "->", "first", "(", ")", ")", "{", "$", "message", "=", "$", "this", "->", "console", "->", "ask", "(", "\"Message?\"", ")", ";", "/* $options = array(\n 'cluster' => 'us2',\n 'encrypted' => true\n );\n $pusher = new Pusher(\n 'adf503a8756876656ec6', 'b21a0ee639fbb893e41d', '481076', $options\n );\n */", "$", "data", "=", "[", "]", ";", "$", "data", "[", "'message'", "]", "=", "$", "message", ";", "/* $result = $pusher->trigger('my-channel', 'my-event', $data, null, true);\n $this->console->line(print_r($result, true)); */", "$", "tiempo", "=", "$", "this", "->", "console", "->", "ask", "(", "\"Send in? (Just a number,next you will select seconds, minutes, etc.)\"", ")", ";", "if", "(", "!", "is_int", "(", "(", "int", ")", "$", "tiempo", ")", ")", "{", "$", "tiempo", "=", "$", "this", "->", "console", "->", "ask", "(", "\"Send in? HAS TO BE AN INTEGER NUMBER\"", ")", ";", "}", "if", "(", "is_int", "(", "(", "int", ")", "$", "tiempo", ")", ")", "{", "$", "unidad", "=", "$", "this", "->", "console", "->", "choice", "(", "'...'", ",", "[", "'seconds'", ",", "'minutes'", ",", "'hours'", ",", "'days'", "]", ",", "0", ")", ";", "switch", "(", "$", "unidad", ")", "{", "case", "'seconds'", ":", "$", "when", "=", "now", "(", ")", "->", "addSeconds", "(", "$", "tiempo", ")", ";", "break", ";", "case", "'minutes'", ":", "$", "when", "=", "now", "(", ")", "->", "addMinutes", "(", "$", "tiempo", ")", ";", "break", ";", "case", "'hours'", ":", "$", "when", "=", "now", "(", ")", "->", "addHours", "(", "$", "tiempo", ")", ";", "break", ";", "case", "'days'", ":", "$", "when", "=", "now", "(", ")", "->", "addDays", "(", "$", "tiempo", ")", ";", "break", ";", "default", ":", "$", "when", "=", "now", "(", ")", "->", "addMinutes", "(", "$", "tiempo", ")", ";", "break", ";", "}", "$", "toUser", "->", "notify", "(", "(", "new", "$", "alertaClass", "(", "$", "data", ")", ")", "->", "delay", "(", "$", "when", ")", ")", ";", "$", "this", "->", "console", "->", "info", "(", "\"Listo!\"", ")", ";", "}", "else", "{", "$", "this", "->", "console", "->", "error", "(", "\"Paila!\"", ")", ";", "}", "}", "else", "{", "$", "this", "->", "console", "->", "error", "(", "\"User not found\"", ")", ";", "}", "}", "else", "{", "$", "this", "->", "console", "->", "error", "(", "\"Class not found\"", ")", ";", "}", "}" ]
Broadcast an alert to a user
[ "Broadcast", "an", "alert", "to", "a", "user" ]
4431e9991a705689be50c4367776dc611bffb863
https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/CrudGeneratorCommands.php#L16-L70
11,387
sirgrimorum/crudgenerator
src/CrudGeneratorCommands.php
CrudGeneratorCommands.createmodel
public function createmodel($table) { $this->console->line("Preparing model attributes"); $bar = $this->console->output->createProgressBar(4); $options = $this->console->options('path'); //$modelName = $singular = substr($table, 0, strlen($table) - 1); $modelName = $singular = str_singular($table); if ($options['path'] != "") { $path = $options['path']; } else { $path = "app/" . ucfirst($modelName); } $path = str_replace("//", "/", str_replace(["\\", " "], ["/", ""], $path)); $AuxclassName = explode("/", str_replace(".php", "", $path)); $className = ""; $justPath = ""; $prefijoPath = "/"; $prefijo = ""; $fileName = ""; $nameSpace = ""; foreach ($AuxclassName as $indice => $pedazo) { if ($indice == count($AuxclassName) - 1) { $nameSpace = $className; $fileName = str_finish(ucfirst($pedazo), ".php"); $modelName = strtolower($pedazo); } else { $justPath .=$prefijoPath . $pedazo; $prefijoPath = "/"; } $className .= $prefijo . ucfirst($pedazo); $prefijo = "\\"; } $path = str_finish($path, ".php"); $bar->advance(); $this->console->line("Loading details from {$table} table"); $config = CrudGenerator::getModelDetailsFromDb($table); $config["modelo"] = $config["model"] = $modelName; $config["nameSpace"] = $nameSpace; $bar->advance(); $this->console->info("Details loaded!"); //$this->console->line(print_r($config, true)); $bar->advance(); $confirm = $this->console->choice("Do you wisth to continue and save the model to '{$path}' with the className '{$className}'?", ['yes', 'no'], 0); if ($confirm == 'yes') { $this->console->line("Saving Model for {$modelName} in {$path} with className '{$className}'"); if (CrudGenerator::saveResource("sirgrimorum::templates.model", false, base_path($justPath), $fileName, $config)) { $this->console->info("Model file saved!"); $bar->finish(); } else { $this->console->error("Something went wrong and the model file could not be saved"); $bar->finish(); } } else { $bar->finish(); } }
php
public function createmodel($table) { $this->console->line("Preparing model attributes"); $bar = $this->console->output->createProgressBar(4); $options = $this->console->options('path'); //$modelName = $singular = substr($table, 0, strlen($table) - 1); $modelName = $singular = str_singular($table); if ($options['path'] != "") { $path = $options['path']; } else { $path = "app/" . ucfirst($modelName); } $path = str_replace("//", "/", str_replace(["\\", " "], ["/", ""], $path)); $AuxclassName = explode("/", str_replace(".php", "", $path)); $className = ""; $justPath = ""; $prefijoPath = "/"; $prefijo = ""; $fileName = ""; $nameSpace = ""; foreach ($AuxclassName as $indice => $pedazo) { if ($indice == count($AuxclassName) - 1) { $nameSpace = $className; $fileName = str_finish(ucfirst($pedazo), ".php"); $modelName = strtolower($pedazo); } else { $justPath .=$prefijoPath . $pedazo; $prefijoPath = "/"; } $className .= $prefijo . ucfirst($pedazo); $prefijo = "\\"; } $path = str_finish($path, ".php"); $bar->advance(); $this->console->line("Loading details from {$table} table"); $config = CrudGenerator::getModelDetailsFromDb($table); $config["modelo"] = $config["model"] = $modelName; $config["nameSpace"] = $nameSpace; $bar->advance(); $this->console->info("Details loaded!"); //$this->console->line(print_r($config, true)); $bar->advance(); $confirm = $this->console->choice("Do you wisth to continue and save the model to '{$path}' with the className '{$className}'?", ['yes', 'no'], 0); if ($confirm == 'yes') { $this->console->line("Saving Model for {$modelName} in {$path} with className '{$className}'"); if (CrudGenerator::saveResource("sirgrimorum::templates.model", false, base_path($justPath), $fileName, $config)) { $this->console->info("Model file saved!"); $bar->finish(); } else { $this->console->error("Something went wrong and the model file could not be saved"); $bar->finish(); } } else { $bar->finish(); } }
[ "public", "function", "createmodel", "(", "$", "table", ")", "{", "$", "this", "->", "console", "->", "line", "(", "\"Preparing model attributes\"", ")", ";", "$", "bar", "=", "$", "this", "->", "console", "->", "output", "->", "createProgressBar", "(", "4", ")", ";", "$", "options", "=", "$", "this", "->", "console", "->", "options", "(", "'path'", ")", ";", "//$modelName = $singular = substr($table, 0, strlen($table) - 1);", "$", "modelName", "=", "$", "singular", "=", "str_singular", "(", "$", "table", ")", ";", "if", "(", "$", "options", "[", "'path'", "]", "!=", "\"\"", ")", "{", "$", "path", "=", "$", "options", "[", "'path'", "]", ";", "}", "else", "{", "$", "path", "=", "\"app/\"", ".", "ucfirst", "(", "$", "modelName", ")", ";", "}", "$", "path", "=", "str_replace", "(", "\"//\"", ",", "\"/\"", ",", "str_replace", "(", "[", "\"\\\\\"", ",", "\" \"", "]", ",", "[", "\"/\"", ",", "\"\"", "]", ",", "$", "path", ")", ")", ";", "$", "AuxclassName", "=", "explode", "(", "\"/\"", ",", "str_replace", "(", "\".php\"", ",", "\"\"", ",", "$", "path", ")", ")", ";", "$", "className", "=", "\"\"", ";", "$", "justPath", "=", "\"\"", ";", "$", "prefijoPath", "=", "\"/\"", ";", "$", "prefijo", "=", "\"\"", ";", "$", "fileName", "=", "\"\"", ";", "$", "nameSpace", "=", "\"\"", ";", "foreach", "(", "$", "AuxclassName", "as", "$", "indice", "=>", "$", "pedazo", ")", "{", "if", "(", "$", "indice", "==", "count", "(", "$", "AuxclassName", ")", "-", "1", ")", "{", "$", "nameSpace", "=", "$", "className", ";", "$", "fileName", "=", "str_finish", "(", "ucfirst", "(", "$", "pedazo", ")", ",", "\".php\"", ")", ";", "$", "modelName", "=", "strtolower", "(", "$", "pedazo", ")", ";", "}", "else", "{", "$", "justPath", ".=", "$", "prefijoPath", ".", "$", "pedazo", ";", "$", "prefijoPath", "=", "\"/\"", ";", "}", "$", "className", ".=", "$", "prefijo", ".", "ucfirst", "(", "$", "pedazo", ")", ";", "$", "prefijo", "=", "\"\\\\\"", ";", "}", "$", "path", "=", "str_finish", "(", "$", "path", ",", "\".php\"", ")", ";", "$", "bar", "->", "advance", "(", ")", ";", "$", "this", "->", "console", "->", "line", "(", "\"Loading details from {$table} table\"", ")", ";", "$", "config", "=", "CrudGenerator", "::", "getModelDetailsFromDb", "(", "$", "table", ")", ";", "$", "config", "[", "\"modelo\"", "]", "=", "$", "config", "[", "\"model\"", "]", "=", "$", "modelName", ";", "$", "config", "[", "\"nameSpace\"", "]", "=", "$", "nameSpace", ";", "$", "bar", "->", "advance", "(", ")", ";", "$", "this", "->", "console", "->", "info", "(", "\"Details loaded!\"", ")", ";", "//$this->console->line(print_r($config, true));", "$", "bar", "->", "advance", "(", ")", ";", "$", "confirm", "=", "$", "this", "->", "console", "->", "choice", "(", "\"Do you wisth to continue and save the model to '{$path}' with the className '{$className}'?\"", ",", "[", "'yes'", ",", "'no'", "]", ",", "0", ")", ";", "if", "(", "$", "confirm", "==", "'yes'", ")", "{", "$", "this", "->", "console", "->", "line", "(", "\"Saving Model for {$modelName} in {$path} with className '{$className}'\"", ")", ";", "if", "(", "CrudGenerator", "::", "saveResource", "(", "\"sirgrimorum::templates.model\"", ",", "false", ",", "base_path", "(", "$", "justPath", ")", ",", "$", "fileName", ",", "$", "config", ")", ")", "{", "$", "this", "->", "console", "->", "info", "(", "\"Model file saved!\"", ")", ";", "$", "bar", "->", "finish", "(", ")", ";", "}", "else", "{", "$", "this", "->", "console", "->", "error", "(", "\"Something went wrong and the model file could not be saved\"", ")", ";", "$", "bar", "->", "finish", "(", ")", ";", "}", "}", "else", "{", "$", "bar", "->", "finish", "(", ")", ";", "}", "}" ]
Create a Model file based on a database table @param string $table Table name
[ "Create", "a", "Model", "file", "based", "on", "a", "database", "table" ]
4431e9991a705689be50c4367776dc611bffb863
https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/CrudGeneratorCommands.php#L76-L130
11,388
sirgrimorum/crudgenerator
src/CrudGeneratorCommands.php
CrudGeneratorCommands.createlang
public function createlang($model) { $this->console->line("Preparing model attributes"); $bar = $this->console->output->createProgressBar(5); $options = $this->console->options('path'); if ($options['path'] != "") { $path = $options['path']; } else { $path = "lang/vendor/crudgenerator/" . config("app.locale"); } $path = str_replace("//", "/", str_replace(["\\", " "], ["/", ""], $path)); $filename = str_finish(strtolower($model), ".php"); $bar->advance(); $this->console->line("Loading config array for {$model}"); $config = CrudGenerator::getConfig($model, false); $bar->advance(); $this->console->info("Config loaded!"); //$this->console->line(print_r($config, true)); $bar->advance(); $this->console->line("Saving Lang file for {$model} in {$path} with filename '{$filename}'"); if (CrudGenerator::saveResource("sirgrimorum::templates.lang", false, resource_path($path), $filename, $config)) { $this->console->info("Model Lang file saved!"); } else { $this->console->error("Something went wrong and the model lang file could not be saved"); } $bar->advance(); $confirm = $this->console->choice("Do you wisth to create a Lang File for the model in es?", ['yes', 'no'], 0); if ($confirm == 'yes') { $path = "lang/vendor/crudgenerator/es"; $filename = str_finish(strtolower($model), ".php"); $this->console->line("Saving Lang file for {$model} in {$path} with filename '{$filename}'"); if (CrudGenerator::saveResource("sirgrimorum::templates.langes", false, resource_path($path), $filename, $config)) { $this->console->info("Model Lang file saved!"); $bar->finish(); } else { $this->console->error("Something went wrong and the model lang file could not be saved"); $bar->finish(); } } $bar->finish(); }
php
public function createlang($model) { $this->console->line("Preparing model attributes"); $bar = $this->console->output->createProgressBar(5); $options = $this->console->options('path'); if ($options['path'] != "") { $path = $options['path']; } else { $path = "lang/vendor/crudgenerator/" . config("app.locale"); } $path = str_replace("//", "/", str_replace(["\\", " "], ["/", ""], $path)); $filename = str_finish(strtolower($model), ".php"); $bar->advance(); $this->console->line("Loading config array for {$model}"); $config = CrudGenerator::getConfig($model, false); $bar->advance(); $this->console->info("Config loaded!"); //$this->console->line(print_r($config, true)); $bar->advance(); $this->console->line("Saving Lang file for {$model} in {$path} with filename '{$filename}'"); if (CrudGenerator::saveResource("sirgrimorum::templates.lang", false, resource_path($path), $filename, $config)) { $this->console->info("Model Lang file saved!"); } else { $this->console->error("Something went wrong and the model lang file could not be saved"); } $bar->advance(); $confirm = $this->console->choice("Do you wisth to create a Lang File for the model in es?", ['yes', 'no'], 0); if ($confirm == 'yes') { $path = "lang/vendor/crudgenerator/es"; $filename = str_finish(strtolower($model), ".php"); $this->console->line("Saving Lang file for {$model} in {$path} with filename '{$filename}'"); if (CrudGenerator::saveResource("sirgrimorum::templates.langes", false, resource_path($path), $filename, $config)) { $this->console->info("Model Lang file saved!"); $bar->finish(); } else { $this->console->error("Something went wrong and the model lang file could not be saved"); $bar->finish(); } } $bar->finish(); }
[ "public", "function", "createlang", "(", "$", "model", ")", "{", "$", "this", "->", "console", "->", "line", "(", "\"Preparing model attributes\"", ")", ";", "$", "bar", "=", "$", "this", "->", "console", "->", "output", "->", "createProgressBar", "(", "5", ")", ";", "$", "options", "=", "$", "this", "->", "console", "->", "options", "(", "'path'", ")", ";", "if", "(", "$", "options", "[", "'path'", "]", "!=", "\"\"", ")", "{", "$", "path", "=", "$", "options", "[", "'path'", "]", ";", "}", "else", "{", "$", "path", "=", "\"lang/vendor/crudgenerator/\"", ".", "config", "(", "\"app.locale\"", ")", ";", "}", "$", "path", "=", "str_replace", "(", "\"//\"", ",", "\"/\"", ",", "str_replace", "(", "[", "\"\\\\\"", ",", "\" \"", "]", ",", "[", "\"/\"", ",", "\"\"", "]", ",", "$", "path", ")", ")", ";", "$", "filename", "=", "str_finish", "(", "strtolower", "(", "$", "model", ")", ",", "\".php\"", ")", ";", "$", "bar", "->", "advance", "(", ")", ";", "$", "this", "->", "console", "->", "line", "(", "\"Loading config array for {$model}\"", ")", ";", "$", "config", "=", "CrudGenerator", "::", "getConfig", "(", "$", "model", ",", "false", ")", ";", "$", "bar", "->", "advance", "(", ")", ";", "$", "this", "->", "console", "->", "info", "(", "\"Config loaded!\"", ")", ";", "//$this->console->line(print_r($config, true));", "$", "bar", "->", "advance", "(", ")", ";", "$", "this", "->", "console", "->", "line", "(", "\"Saving Lang file for {$model} in {$path} with filename '{$filename}'\"", ")", ";", "if", "(", "CrudGenerator", "::", "saveResource", "(", "\"sirgrimorum::templates.lang\"", ",", "false", ",", "resource_path", "(", "$", "path", ")", ",", "$", "filename", ",", "$", "config", ")", ")", "{", "$", "this", "->", "console", "->", "info", "(", "\"Model Lang file saved!\"", ")", ";", "}", "else", "{", "$", "this", "->", "console", "->", "error", "(", "\"Something went wrong and the model lang file could not be saved\"", ")", ";", "}", "$", "bar", "->", "advance", "(", ")", ";", "$", "confirm", "=", "$", "this", "->", "console", "->", "choice", "(", "\"Do you wisth to create a Lang File for the model in es?\"", ",", "[", "'yes'", ",", "'no'", "]", ",", "0", ")", ";", "if", "(", "$", "confirm", "==", "'yes'", ")", "{", "$", "path", "=", "\"lang/vendor/crudgenerator/es\"", ";", "$", "filename", "=", "str_finish", "(", "strtolower", "(", "$", "model", ")", ",", "\".php\"", ")", ";", "$", "this", "->", "console", "->", "line", "(", "\"Saving Lang file for {$model} in {$path} with filename '{$filename}'\"", ")", ";", "if", "(", "CrudGenerator", "::", "saveResource", "(", "\"sirgrimorum::templates.langes\"", ",", "false", ",", "resource_path", "(", "$", "path", ")", ",", "$", "filename", ",", "$", "config", ")", ")", "{", "$", "this", "->", "console", "->", "info", "(", "\"Model Lang file saved!\"", ")", ";", "$", "bar", "->", "finish", "(", ")", ";", "}", "else", "{", "$", "this", "->", "console", "->", "error", "(", "\"Something went wrong and the model lang file could not be saved\"", ")", ";", "$", "bar", "->", "finish", "(", ")", ";", "}", "}", "$", "bar", "->", "finish", "(", ")", ";", "}" ]
Create a Model Lang file from config array @param string $model the model name in lowercase
[ "Create", "a", "Model", "Lang", "file", "from", "config", "array" ]
4431e9991a705689be50c4367776dc611bffb863
https://github.com/sirgrimorum/crudgenerator/blob/4431e9991a705689be50c4367776dc611bffb863/src/CrudGeneratorCommands.php#L136-L175
11,389
tekkla/core-html
Core/Html/Controls/UiButton.php
UiButton.setIcon
public function setIcon($icon) { $this->icon = $this->factory->create('Fontawesome\Icon'); $this->icon->setIcon($icon); return $this; }
php
public function setIcon($icon) { $this->icon = $this->factory->create('Fontawesome\Icon'); $this->icon->setIcon($icon); return $this; }
[ "public", "function", "setIcon", "(", "$", "icon", ")", "{", "$", "this", "->", "icon", "=", "$", "this", "->", "factory", "->", "create", "(", "'Fontawesome\\Icon'", ")", ";", "$", "this", "->", "icon", "->", "setIcon", "(", "$", "icon", ")", ";", "return", "$", "this", ";", "}" ]
Set an icon from fontawesome icon. Use only the name without the leading "fa-" @param string $icon @return \Core\Html\controls\UiButton
[ "Set", "an", "icon", "from", "fontawesome", "icon", ".", "Use", "only", "the", "name", "without", "the", "leading", "fa", "-" ]
00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3
https://github.com/tekkla/core-html/blob/00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3/Core/Html/Controls/UiButton.php#L148-L154
11,390
tekkla/core-html
Core/Html/Controls/UiButton.php
UiButton.build
public function build() { if ($this->mode == 'ajax') { $this->data['ajax'] = 'link'; } // Set text and set icon means we have a button of type imagebutton if ($this->text && $this->icon) { $this->type = 'imgbutton'; } // icon/image if ($this->type == 'icon') { $this->css['icon'] = 'icon'; $this->icon->noStack(); $this->inner = $this->icon->build(); } // textbutton if ($this->type == 'button') { $this->inner = '<span class="button-text">' . $this->text . '</span>'; } // simple link if ($this->type == 'link') { $this->css['link'] = 'link'; $this->inner = '<span class="link-text">' . $this->text . '</span>'; } // imgbutton if ($this->type == 'imgbutton') { $this->icon->noStack(); $this->inner = $this->icon->build() . ' ' . $this->text; } // Do we need to set the default button css code for a non link? if ($this->type != 'link') { $this->css['btn'] = 'btn'; $check = [ 'btn-primary', 'btn-success', 'btn-warning', 'btn-info', 'btn-default' ]; if ($this->checkCss($check) == false) { $this->addCss('btn-default'); } } return parent::build(); }
php
public function build() { if ($this->mode == 'ajax') { $this->data['ajax'] = 'link'; } // Set text and set icon means we have a button of type imagebutton if ($this->text && $this->icon) { $this->type = 'imgbutton'; } // icon/image if ($this->type == 'icon') { $this->css['icon'] = 'icon'; $this->icon->noStack(); $this->inner = $this->icon->build(); } // textbutton if ($this->type == 'button') { $this->inner = '<span class="button-text">' . $this->text . '</span>'; } // simple link if ($this->type == 'link') { $this->css['link'] = 'link'; $this->inner = '<span class="link-text">' . $this->text . '</span>'; } // imgbutton if ($this->type == 'imgbutton') { $this->icon->noStack(); $this->inner = $this->icon->build() . ' ' . $this->text; } // Do we need to set the default button css code for a non link? if ($this->type != 'link') { $this->css['btn'] = 'btn'; $check = [ 'btn-primary', 'btn-success', 'btn-warning', 'btn-info', 'btn-default' ]; if ($this->checkCss($check) == false) { $this->addCss('btn-default'); } } return parent::build(); }
[ "public", "function", "build", "(", ")", "{", "if", "(", "$", "this", "->", "mode", "==", "'ajax'", ")", "{", "$", "this", "->", "data", "[", "'ajax'", "]", "=", "'link'", ";", "}", "// Set text and set icon means we have a button of type imagebutton", "if", "(", "$", "this", "->", "text", "&&", "$", "this", "->", "icon", ")", "{", "$", "this", "->", "type", "=", "'imgbutton'", ";", "}", "// icon/image", "if", "(", "$", "this", "->", "type", "==", "'icon'", ")", "{", "$", "this", "->", "css", "[", "'icon'", "]", "=", "'icon'", ";", "$", "this", "->", "icon", "->", "noStack", "(", ")", ";", "$", "this", "->", "inner", "=", "$", "this", "->", "icon", "->", "build", "(", ")", ";", "}", "// textbutton", "if", "(", "$", "this", "->", "type", "==", "'button'", ")", "{", "$", "this", "->", "inner", "=", "'<span class=\"button-text\">'", ".", "$", "this", "->", "text", ".", "'</span>'", ";", "}", "// simple link", "if", "(", "$", "this", "->", "type", "==", "'link'", ")", "{", "$", "this", "->", "css", "[", "'link'", "]", "=", "'link'", ";", "$", "this", "->", "inner", "=", "'<span class=\"link-text\">'", ".", "$", "this", "->", "text", ".", "'</span>'", ";", "}", "// imgbutton", "if", "(", "$", "this", "->", "type", "==", "'imgbutton'", ")", "{", "$", "this", "->", "icon", "->", "noStack", "(", ")", ";", "$", "this", "->", "inner", "=", "$", "this", "->", "icon", "->", "build", "(", ")", ".", "' '", ".", "$", "this", "->", "text", ";", "}", "// Do we need to set the default button css code for a non link?", "if", "(", "$", "this", "->", "type", "!=", "'link'", ")", "{", "$", "this", "->", "css", "[", "'btn'", "]", "=", "'btn'", ";", "$", "check", "=", "[", "'btn-primary'", ",", "'btn-success'", ",", "'btn-warning'", ",", "'btn-info'", ",", "'btn-default'", "]", ";", "if", "(", "$", "this", "->", "checkCss", "(", "$", "check", ")", "==", "false", ")", "{", "$", "this", "->", "addCss", "(", "'btn-default'", ")", ";", "}", "}", "return", "parent", "::", "build", "(", ")", ";", "}" ]
Builds and returns button html code @param string $wrapper @throws Error @return string
[ "Builds", "and", "returns", "button", "html", "code" ]
00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3
https://github.com/tekkla/core-html/blob/00bf3fa8e060e8aadf1c341f6e3c548c7a76cfd3/Core/Html/Controls/UiButton.php#L241-L295
11,391
diatem-net/jin-com
src/Com/WebService/WSServer.php
WsServer.buildService
public function buildService() { require_once($this->classFile); $wsdl = $this->generateWsdl(); if (isset($_GET['wsdl'])) { print $wsdl; } else { $file = 'data://text/plain;base64,'. base64_encode($wsdl); $server = new \SoapServer($file); $server->setClass($this->className); $functions = get_class_methods($this->className); foreach ($functions as $function) { $server->addFunction($function); } $server->handle(); } }
php
public function buildService() { require_once($this->classFile); $wsdl = $this->generateWsdl(); if (isset($_GET['wsdl'])) { print $wsdl; } else { $file = 'data://text/plain;base64,'. base64_encode($wsdl); $server = new \SoapServer($file); $server->setClass($this->className); $functions = get_class_methods($this->className); foreach ($functions as $function) { $server->addFunction($function); } $server->handle(); } }
[ "public", "function", "buildService", "(", ")", "{", "require_once", "(", "$", "this", "->", "classFile", ")", ";", "$", "wsdl", "=", "$", "this", "->", "generateWsdl", "(", ")", ";", "if", "(", "isset", "(", "$", "_GET", "[", "'wsdl'", "]", ")", ")", "{", "print", "$", "wsdl", ";", "}", "else", "{", "$", "file", "=", "'data://text/plain;base64,'", ".", "base64_encode", "(", "$", "wsdl", ")", ";", "$", "server", "=", "new", "\\", "SoapServer", "(", "$", "file", ")", ";", "$", "server", "->", "setClass", "(", "$", "this", "->", "className", ")", ";", "$", "functions", "=", "get_class_methods", "(", "$", "this", "->", "className", ")", ";", "foreach", "(", "$", "functions", "as", "$", "function", ")", "{", "$", "server", "->", "addFunction", "(", "$", "function", ")", ";", "}", "$", "server", "->", "handle", "(", ")", ";", "}", "}" ]
Construction du service @return void
[ "Construction", "du", "service" ]
7449f555676cc058130377d74c845ff91b6b286f
https://github.com/diatem-net/jin-com/blob/7449f555676cc058130377d74c845ff91b6b286f/src/Com/WebService/WSServer.php#L59-L76
11,392
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.getById
public function getById($id, $col = null) { $id = (int) $id; $model = $this->getCacheItem($id); if (!$model) { $model = $this->getMapper()->getById($id, $col); if ($this->useCache) { $this->setCacheItem($id, $model); } } return $model; }
php
public function getById($id, $col = null) { $id = (int) $id; $model = $this->getCacheItem($id); if (!$model) { $model = $this->getMapper()->getById($id, $col); if ($this->useCache) { $this->setCacheItem($id, $model); } } return $model; }
[ "public", "function", "getById", "(", "$", "id", ",", "$", "col", "=", "null", ")", "{", "$", "id", "=", "(", "int", ")", "$", "id", ";", "$", "model", "=", "$", "this", "->", "getCacheItem", "(", "$", "id", ")", ";", "if", "(", "!", "$", "model", ")", "{", "$", "model", "=", "$", "this", "->", "getMapper", "(", ")", "->", "getById", "(", "$", "id", ",", "$", "col", ")", ";", "if", "(", "$", "this", "->", "useCache", ")", "{", "$", "this", "->", "setCacheItem", "(", "$", "id", ",", "$", "model", ")", ";", "}", "}", "return", "$", "model", ";", "}" ]
return one or more records from database by id @param $id @param null $col @return array|mixed|ModelInterface
[ "return", "one", "or", "more", "records", "from", "database", "by", "id" ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L59-L73
11,393
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.search
public function search(array $post) { $sort = (isset($post['sort'])) ? $post['sort'] : ''; unset($post['sort'], $post['count'], $post['offset'], $post['page']); $searches = []; foreach ($post as $key => $value) { $searches[] = [ 'searchString' => $value, 'columns' => explode('-', $key), ]; } $models = $this->getMapper()->search($searches, $sort); return $models; }
php
public function search(array $post) { $sort = (isset($post['sort'])) ? $post['sort'] : ''; unset($post['sort'], $post['count'], $post['offset'], $post['page']); $searches = []; foreach ($post as $key => $value) { $searches[] = [ 'searchString' => $value, 'columns' => explode('-', $key), ]; } $models = $this->getMapper()->search($searches, $sort); return $models; }
[ "public", "function", "search", "(", "array", "$", "post", ")", "{", "$", "sort", "=", "(", "isset", "(", "$", "post", "[", "'sort'", "]", ")", ")", "?", "$", "post", "[", "'sort'", "]", ":", "''", ";", "unset", "(", "$", "post", "[", "'sort'", "]", ",", "$", "post", "[", "'count'", "]", ",", "$", "post", "[", "'offset'", "]", ",", "$", "post", "[", "'page'", "]", ")", ";", "$", "searches", "=", "[", "]", ";", "foreach", "(", "$", "post", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "searches", "[", "]", "=", "[", "'searchString'", "=>", "$", "value", ",", "'columns'", "=>", "explode", "(", "'-'", ",", "$", "key", ")", ",", "]", ";", "}", "$", "models", "=", "$", "this", "->", "getMapper", "(", ")", "->", "search", "(", "$", "searches", ",", "$", "sort", ")", ";", "return", "$", "models", ";", "}" ]
basic search on database @param array $post @return ResultSet|Paginator|HydratingResultSet
[ "basic", "search", "on", "database" ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L93-L110
11,394
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.add
public function add(array $post, Form $form = null) { $model = $this->getModel(); $form = ($form instanceof Form) ? $form->setData($post) : $this->prepareForm($model, $post, true, true); $argv = compact('post', 'form'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_ADD, $this, $argv); if (!$form->isValid()) { return $form; } $saved = $this->save($form->getData()); $argv = compact('post', 'form', 'saved'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_ADD, $this, $argv); return $saved; }
php
public function add(array $post, Form $form = null) { $model = $this->getModel(); $form = ($form instanceof Form) ? $form->setData($post) : $this->prepareForm($model, $post, true, true); $argv = compact('post', 'form'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_ADD, $this, $argv); if (!$form->isValid()) { return $form; } $saved = $this->save($form->getData()); $argv = compact('post', 'form', 'saved'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_ADD, $this, $argv); return $saved; }
[ "public", "function", "add", "(", "array", "$", "post", ",", "Form", "$", "form", "=", "null", ")", "{", "$", "model", "=", "$", "this", "->", "getModel", "(", ")", ";", "$", "form", "=", "(", "$", "form", "instanceof", "Form", ")", "?", "$", "form", "->", "setData", "(", "$", "post", ")", ":", "$", "this", "->", "prepareForm", "(", "$", "model", ",", "$", "post", ",", "true", ",", "true", ")", ";", "$", "argv", "=", "compact", "(", "'post'", ",", "'form'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_PRE_ADD", ",", "$", "this", ",", "$", "argv", ")", ";", "if", "(", "!", "$", "form", "->", "isValid", "(", ")", ")", "{", "return", "$", "form", ";", "}", "$", "saved", "=", "$", "this", "->", "save", "(", "$", "form", "->", "getData", "(", ")", ")", ";", "$", "argv", "=", "compact", "(", "'post'", ",", "'form'", ",", "'saved'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_POST_ADD", ",", "$", "this", ",", "$", "argv", ")", ";", "return", "$", "saved", ";", "}" ]
prepare and return form @param array $post @param Form $form @return int|Form @throws ServiceException
[ "prepare", "and", "return", "form" ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L120-L142
11,395
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.edit
public function edit(ModelInterface $model, array $post, Form $form = null) { $form = ($form instanceof Form) ? $form->setData($post) : $this->prepareForm($model, $post, true, true); $argv = compact('model', 'post', 'form'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_EDIT, $this, $argv); if (!$form->isValid()) { return $form; } $saved = $this->save($form->getData()); $argv = compact('model', 'post', 'form', 'saved'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_EDIT, $this, $argv); $eventSaved = (isset($argv['result'])) ? $argv['result'] : false; return (!$saved && !$eventSaved) ? false : true; }
php
public function edit(ModelInterface $model, array $post, Form $form = null) { $form = ($form instanceof Form) ? $form->setData($post) : $this->prepareForm($model, $post, true, true); $argv = compact('model', 'post', 'form'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_EDIT, $this, $argv); if (!$form->isValid()) { return $form; } $saved = $this->save($form->getData()); $argv = compact('model', 'post', 'form', 'saved'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_EDIT, $this, $argv); $eventSaved = (isset($argv['result'])) ? $argv['result'] : false; return (!$saved && !$eventSaved) ? false : true; }
[ "public", "function", "edit", "(", "ModelInterface", "$", "model", ",", "array", "$", "post", ",", "Form", "$", "form", "=", "null", ")", "{", "$", "form", "=", "(", "$", "form", "instanceof", "Form", ")", "?", "$", "form", "->", "setData", "(", "$", "post", ")", ":", "$", "this", "->", "prepareForm", "(", "$", "model", ",", "$", "post", ",", "true", ",", "true", ")", ";", "$", "argv", "=", "compact", "(", "'model'", ",", "'post'", ",", "'form'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_PRE_EDIT", ",", "$", "this", ",", "$", "argv", ")", ";", "if", "(", "!", "$", "form", "->", "isValid", "(", ")", ")", "{", "return", "$", "form", ";", "}", "$", "saved", "=", "$", "this", "->", "save", "(", "$", "form", "->", "getData", "(", ")", ")", ";", "$", "argv", "=", "compact", "(", "'model'", ",", "'post'", ",", "'form'", ",", "'saved'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_POST_EDIT", ",", "$", "this", ",", "$", "argv", ")", ";", "$", "eventSaved", "=", "(", "isset", "(", "$", "argv", "[", "'result'", "]", ")", ")", "?", "$", "argv", "[", "'result'", "]", ":", "false", ";", "return", "(", "!", "$", "saved", "&&", "!", "$", "eventSaved", ")", "?", "false", ":", "true", ";", "}" ]
prepare data to be updated and saved into database. @param ModelInterface $model @param array $post @param Form $form @return Form|int results from self::save() @throws ServiceException
[ "prepare", "data", "to", "be", "updated", "and", "saved", "into", "database", "." ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L153-L176
11,396
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.save
public function save($data) { $argv = compact('data'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_SAVE, $this, $argv); $data = $argv['data']; if ($data instanceof ModelInterface) { $data = $this->getHydrator()->extract($data); } $pk = $this->getMapper()->getPrimaryKey(); $id = $data[$pk]; unset($data[$pk]); if (0 === $id || null === $id || '' === $id) { $result = $this->getMapper()->insert($data); $this->clearCacheTags(); } else { if ($this->getById($id)) { $result = $this->getMapper()->update($data, [$pk => $id]); } else { throw new ServiceException('ID ' . $id . ' does not exist'); } $this->removeCacheItem($id); } $argv = compact('data', 'result'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_SAVE, $this, $argv); return $result; }
php
public function save($data) { $argv = compact('data'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_SAVE, $this, $argv); $data = $argv['data']; if ($data instanceof ModelInterface) { $data = $this->getHydrator()->extract($data); } $pk = $this->getMapper()->getPrimaryKey(); $id = $data[$pk]; unset($data[$pk]); if (0 === $id || null === $id || '' === $id) { $result = $this->getMapper()->insert($data); $this->clearCacheTags(); } else { if ($this->getById($id)) { $result = $this->getMapper()->update($data, [$pk => $id]); } else { throw new ServiceException('ID ' . $id . ' does not exist'); } $this->removeCacheItem($id); } $argv = compact('data', 'result'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_SAVE, $this, $argv); return $result; }
[ "public", "function", "save", "(", "$", "data", ")", "{", "$", "argv", "=", "compact", "(", "'data'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_PRE_SAVE", ",", "$", "this", ",", "$", "argv", ")", ";", "$", "data", "=", "$", "argv", "[", "'data'", "]", ";", "if", "(", "$", "data", "instanceof", "ModelInterface", ")", "{", "$", "data", "=", "$", "this", "->", "getHydrator", "(", ")", "->", "extract", "(", "$", "data", ")", ";", "}", "$", "pk", "=", "$", "this", "->", "getMapper", "(", ")", "->", "getPrimaryKey", "(", ")", ";", "$", "id", "=", "$", "data", "[", "$", "pk", "]", ";", "unset", "(", "$", "data", "[", "$", "pk", "]", ")", ";", "if", "(", "0", "===", "$", "id", "||", "null", "===", "$", "id", "||", "''", "===", "$", "id", ")", "{", "$", "result", "=", "$", "this", "->", "getMapper", "(", ")", "->", "insert", "(", "$", "data", ")", ";", "$", "this", "->", "clearCacheTags", "(", ")", ";", "}", "else", "{", "if", "(", "$", "this", "->", "getById", "(", "$", "id", ")", ")", "{", "$", "result", "=", "$", "this", "->", "getMapper", "(", ")", "->", "update", "(", "$", "data", ",", "[", "$", "pk", "=>", "$", "id", "]", ")", ";", "}", "else", "{", "throw", "new", "ServiceException", "(", "'ID '", ".", "$", "id", ".", "' does not exist'", ")", ";", "}", "$", "this", "->", "removeCacheItem", "(", "$", "id", ")", ";", "}", "$", "argv", "=", "compact", "(", "'data'", ",", "'result'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_POST_SAVE", ",", "$", "this", ",", "$", "argv", ")", ";", "return", "$", "result", ";", "}" ]
updates a row if id is supplied else insert a new row @param array|ModelInterface $data @throws ServiceException @return int $results number of rows affected or insertId
[ "updates", "a", "row", "if", "id", "is", "supplied", "else", "insert", "a", "new", "row" ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L185-L221
11,397
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.delete
public function delete($id) { $model = $this->getById($id); $argv = compact('id', 'model'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_DELETE, $this, $argv); $result = $this->getMapper()->delete([ $this->getMapper()->getPrimaryKey() => $id ]); if ($result) { $this->removeCacheItem($id); $argv = compact('id', 'model', 'result'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_DELETE, $this, $argv); } return $result; }
php
public function delete($id) { $model = $this->getById($id); $argv = compact('id', 'model'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_PRE_DELETE, $this, $argv); $result = $this->getMapper()->delete([ $this->getMapper()->getPrimaryKey() => $id ]); if ($result) { $this->removeCacheItem($id); $argv = compact('id', 'model', 'result'); $argv = $this->prepareEventArguments($argv); $this->getEventManager()->trigger(self::EVENT_POST_DELETE, $this, $argv); } return $result; }
[ "public", "function", "delete", "(", "$", "id", ")", "{", "$", "model", "=", "$", "this", "->", "getById", "(", "$", "id", ")", ";", "$", "argv", "=", "compact", "(", "'id'", ",", "'model'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_PRE_DELETE", ",", "$", "this", ",", "$", "argv", ")", ";", "$", "result", "=", "$", "this", "->", "getMapper", "(", ")", "->", "delete", "(", "[", "$", "this", "->", "getMapper", "(", ")", "->", "getPrimaryKey", "(", ")", "=>", "$", "id", "]", ")", ";", "if", "(", "$", "result", ")", "{", "$", "this", "->", "removeCacheItem", "(", "$", "id", ")", ";", "$", "argv", "=", "compact", "(", "'id'", ",", "'model'", ",", "'result'", ")", ";", "$", "argv", "=", "$", "this", "->", "prepareEventArguments", "(", "$", "argv", ")", ";", "$", "this", "->", "getEventManager", "(", ")", "->", "trigger", "(", "self", "::", "EVENT_POST_DELETE", ",", "$", "this", ",", "$", "argv", ")", ";", "}", "return", "$", "result", ";", "}" ]
delete row from database @param int $id @return int $result number of rows affected
[ "delete", "row", "from", "database" ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L229-L250
11,398
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.getMapper
public function getMapper($mapperClass = null, array $options = []) { $mapperClass = $mapperClass ?? $this->mapper ?? $this->serviceAlias; if (!array_key_exists($mapperClass, $this->mappers)) { $this->setMapper($mapperClass, $options); } return $this->mappers[$mapperClass]; }
php
public function getMapper($mapperClass = null, array $options = []) { $mapperClass = $mapperClass ?? $this->mapper ?? $this->serviceAlias; if (!array_key_exists($mapperClass, $this->mappers)) { $this->setMapper($mapperClass, $options); } return $this->mappers[$mapperClass]; }
[ "public", "function", "getMapper", "(", "$", "mapperClass", "=", "null", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "mapperClass", "=", "$", "mapperClass", "??", "$", "this", "->", "mapper", "??", "$", "this", "->", "serviceAlias", ";", "if", "(", "!", "array_key_exists", "(", "$", "mapperClass", ",", "$", "this", "->", "mappers", ")", ")", "{", "$", "this", "->", "setMapper", "(", "$", "mapperClass", ",", "$", "options", ")", ";", "}", "return", "$", "this", "->", "mappers", "[", "$", "mapperClass", "]", ";", "}" ]
gets the mapper class for this service @param null|string $mapperClass @param array $options @return MapperInterface
[ "gets", "the", "mapper", "class", "for", "this", "service" ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L259-L268
11,399
uthando-cms/uthando-common
src/UthandoCommon/Service/AbstractMapperService.php
AbstractMapperService.setMapper
public function setMapper($mapperClass, array $options = []) { $sl = $this->getServiceLocator(); $mapperManager = $sl->get(MapperManager::class); $defaultOptions = [ 'model' => $this->model ?? $this->serviceAlias, 'hydrator' => $this->hydrator ?? $this->serviceAlias, ]; $options = array_merge($defaultOptions, $options); $mapper = $mapperManager->get($mapperClass, $options); $this->mappers[$mapperClass] = $mapper; return $this; }
php
public function setMapper($mapperClass, array $options = []) { $sl = $this->getServiceLocator(); $mapperManager = $sl->get(MapperManager::class); $defaultOptions = [ 'model' => $this->model ?? $this->serviceAlias, 'hydrator' => $this->hydrator ?? $this->serviceAlias, ]; $options = array_merge($defaultOptions, $options); $mapper = $mapperManager->get($mapperClass, $options); $this->mappers[$mapperClass] = $mapper; return $this; }
[ "public", "function", "setMapper", "(", "$", "mapperClass", ",", "array", "$", "options", "=", "[", "]", ")", "{", "$", "sl", "=", "$", "this", "->", "getServiceLocator", "(", ")", ";", "$", "mapperManager", "=", "$", "sl", "->", "get", "(", "MapperManager", "::", "class", ")", ";", "$", "defaultOptions", "=", "[", "'model'", "=>", "$", "this", "->", "model", "??", "$", "this", "->", "serviceAlias", ",", "'hydrator'", "=>", "$", "this", "->", "hydrator", "??", "$", "this", "->", "serviceAlias", ",", "]", ";", "$", "options", "=", "array_merge", "(", "$", "defaultOptions", ",", "$", "options", ")", ";", "$", "mapper", "=", "$", "mapperManager", "->", "get", "(", "$", "mapperClass", ",", "$", "options", ")", ";", "$", "this", "->", "mappers", "[", "$", "mapperClass", "]", "=", "$", "mapper", ";", "return", "$", "this", ";", "}" ]
Sets mapper in mapper array for reuse. @param string $mapperClass @param array $options @return $this
[ "Sets", "mapper", "in", "mapper", "array", "for", "reuse", "." ]
feb915da5d26b60f536282e1bc3ad5c22e53f485
https://github.com/uthando-cms/uthando-common/blob/feb915da5d26b60f536282e1bc3ad5c22e53f485/src/UthandoCommon/Service/AbstractMapperService.php#L277-L293