repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
steos/php-quickcheck | src/QCheck/Generator.php | Generator.oneOf | public static function oneOf()
{
$generators = self::getArgs(func_get_args());
$num = count($generators);
if ($num < 2) {
throw new \InvalidArgumentException();
}
return self::choose(0, $num - 1)
->bind(function ($index) use ($generators) {
return $generators[$index];
});
} | php | public static function oneOf()
{
$generators = self::getArgs(func_get_args());
$num = count($generators);
if ($num < 2) {
throw new \InvalidArgumentException();
}
return self::choose(0, $num - 1)
->bind(function ($index) use ($generators) {
return $generators[$index];
});
} | [
"public",
"static",
"function",
"oneOf",
"(",
")",
"{",
"$",
"generators",
"=",
"self",
"::",
"getArgs",
"(",
"func_get_args",
"(",
")",
")",
";",
"$",
"num",
"=",
"count",
"(",
"$",
"generators",
")",
";",
"if",
"(",
"$",
"num",
"<",
"2",
")",
"... | creates a new generator that randomly chooses a value from the list
of provided generators. Shrinks toward earlier generators as well as shrinking
the generated value itself.
Accepts either a variadic number of args or a single array of generators.
Example:
Gen::oneOf(Gen::booleans(), Gen::ints())
Gen::oneOf([Gen::booleans(), Gen::ints()])
@return Generator | [
"creates",
"a",
"new",
"generator",
"that",
"randomly",
"chooses",
"a",
"value",
"from",
"the",
"list",
"of",
"provided",
"generators",
".",
"Shrinks",
"toward",
"earlier",
"generators",
"as",
"well",
"as",
"shrinking",
"the",
"generated",
"value",
"itself",
"... | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L473-L484 | train |
steos/php-quickcheck | src/QCheck/Generator.php | Generator.elements | public static function elements()
{
$coll = self::getArgs(func_get_args());
if (empty($coll)) {
throw new \InvalidArgumentException();
}
return self::choose(0, count($coll) - 1)
->bindGen(function (RoseTree $rose) use ($coll) {
return self::pureGen($rose->fmap(
function ($index) use ($coll) {
return $coll[$index];
}
));
});
} | php | public static function elements()
{
$coll = self::getArgs(func_get_args());
if (empty($coll)) {
throw new \InvalidArgumentException();
}
return self::choose(0, count($coll) - 1)
->bindGen(function (RoseTree $rose) use ($coll) {
return self::pureGen($rose->fmap(
function ($index) use ($coll) {
return $coll[$index];
}
));
});
} | [
"public",
"static",
"function",
"elements",
"(",
")",
"{",
"$",
"coll",
"=",
"self",
"::",
"getArgs",
"(",
"func_get_args",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"coll",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
... | creates a generator that randomly chooses from the specified values
Accepts either a variadic number of args or a single array of values.
Example:
Gen::elements('foo', 'bar', 'baz')
Gen::elements(['foo', 'bar', 'baz'])
@return Generator | [
"creates",
"a",
"generator",
"that",
"randomly",
"chooses",
"from",
"the",
"specified",
"values"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L497-L511 | train |
steos/php-quickcheck | src/QCheck/Generator.php | Generator.frequency | public static function frequency()
{
$args = func_get_args();
$argc = count($args);
if ($argc < 2 || $argc % 2 != 0) {
throw new \InvalidArgumentException();
}
$total = array_sum(FP::realize(FP::takeNth(2, $args)));
$pairs = FP::realize(FP::partition(2, $args));
return self::choose(1, $total)->bindGen(
function (RoseTree $rose) use ($pairs) {
$n = $rose->getRoot();
foreach ($pairs as $pair) {
list($chance, $gen) = $pair;
if ($n <= $chance) {
return $gen;
}
$n = $n - $chance;
}
}
);
} | php | public static function frequency()
{
$args = func_get_args();
$argc = count($args);
if ($argc < 2 || $argc % 2 != 0) {
throw new \InvalidArgumentException();
}
$total = array_sum(FP::realize(FP::takeNth(2, $args)));
$pairs = FP::realize(FP::partition(2, $args));
return self::choose(1, $total)->bindGen(
function (RoseTree $rose) use ($pairs) {
$n = $rose->getRoot();
foreach ($pairs as $pair) {
list($chance, $gen) = $pair;
if ($n <= $chance) {
return $gen;
}
$n = $n - $chance;
}
}
);
} | [
"public",
"static",
"function",
"frequency",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"argc",
"=",
"count",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"argc",
"<",
"2",
"||",
"$",
"argc",
"%",
"2",
"!=",
"0",
")",
... | creates a generator that produces values from specified generators based on
likelihoods. The likelihood of a generator being chosen is its likelihood divided
by the sum of all likelihoods.
Example:
Gen::frequency(
5, Gen::ints(),
3, Gen::booleans(),
2, Gen::alphaStrings()
)
@return Generator | [
"creates",
"a",
"generator",
"that",
"produces",
"values",
"from",
"specified",
"generators",
"based",
"on",
"likelihoods",
".",
"The",
"likelihood",
"of",
"a",
"generator",
"being",
"chosen",
"is",
"its",
"likelihood",
"divided",
"by",
"the",
"sum",
"of",
"al... | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L624-L645 | train |
cartalyst/converter | src/Laravel/ConverterServiceProvider.php | ConverterServiceProvider.registerExchangers | protected function registerExchangers()
{
$this->app->singleton('converter.native.exchanger', function ($app) {
return new NativeExchanger;
});
$this->app->singleton('converter.openexchangerates.exchanger', function ($app) {
$config = $app['config']->get('cartalyst.converter');
$appId = array_get($config, 'exchangers.openexchangerates.app_id');
$expires = array_get($config, 'expires');
$exchanger = new OpenExchangeRatesExchanger($app['cache']);
$exchanger->setAppId($appId);
$exchanger->setExpires($expires);
return $exchanger;
});
$this->app->singleton('converter.exchanger', function ($app) {
$default = $app['config']->get('cartalyst.converter.exchangers.default');
return $app["converter.{$default}.exchanger"];
});
} | php | protected function registerExchangers()
{
$this->app->singleton('converter.native.exchanger', function ($app) {
return new NativeExchanger;
});
$this->app->singleton('converter.openexchangerates.exchanger', function ($app) {
$config = $app['config']->get('cartalyst.converter');
$appId = array_get($config, 'exchangers.openexchangerates.app_id');
$expires = array_get($config, 'expires');
$exchanger = new OpenExchangeRatesExchanger($app['cache']);
$exchanger->setAppId($appId);
$exchanger->setExpires($expires);
return $exchanger;
});
$this->app->singleton('converter.exchanger', function ($app) {
$default = $app['config']->get('cartalyst.converter.exchangers.default');
return $app["converter.{$default}.exchanger"];
});
} | [
"protected",
"function",
"registerExchangers",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'converter.native.exchanger'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"NativeExchanger",
";",
"}",
")",
";",
"$",
"this",
... | Register all the available exchangers.
@return void | [
"Register",
"all",
"the",
"available",
"exchangers",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Laravel/ConverterServiceProvider.php#L63-L88 | train |
cartalyst/converter | src/Laravel/ConverterServiceProvider.php | ConverterServiceProvider.registerConverter | protected function registerConverter()
{
$this->app->singleton('converter', function ($app) {
$measurements = $app['config']->get('cartalyst.converter.measurements');
$converter = new Converter($app['converter.exchanger']);
$converter->setMeasurements($measurements);
return $converter;
});
} | php | protected function registerConverter()
{
$this->app->singleton('converter', function ($app) {
$measurements = $app['config']->get('cartalyst.converter.measurements');
$converter = new Converter($app['converter.exchanger']);
$converter->setMeasurements($measurements);
return $converter;
});
} | [
"protected",
"function",
"registerConverter",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'converter'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"measurements",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'ca... | Register the Converter.
@return void | [
"Register",
"the",
"Converter",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Laravel/ConverterServiceProvider.php#L95-L105 | train |
steos/php-quickcheck | src/QCheck/Annotation.php | Annotation.getReflection | public static function getReflection(callable $f)
{
if (is_string($f)) {
if (strpos($f, '::', 1) !== false) {
return new \ReflectionMethod($f);
} else {
return new \ReflectionFunction($f);
}
} elseif (is_array($f) && count($f) == 2) {
return new \ReflectionMethod($f[0], $f[1]);
} elseif ($f instanceof \Closure) {
return new \ReflectionFunction($f);
} elseif (is_object($f) && method_exists($f, '__invoke')) {
return new \ReflectionMethod($f, '__invoke');
}
// if the tests above are exhaustive, we should never hit the next line.
throw new AnnotationException("Unable to determine callable type.");
} | php | public static function getReflection(callable $f)
{
if (is_string($f)) {
if (strpos($f, '::', 1) !== false) {
return new \ReflectionMethod($f);
} else {
return new \ReflectionFunction($f);
}
} elseif (is_array($f) && count($f) == 2) {
return new \ReflectionMethod($f[0], $f[1]);
} elseif ($f instanceof \Closure) {
return new \ReflectionFunction($f);
} elseif (is_object($f) && method_exists($f, '__invoke')) {
return new \ReflectionMethod($f, '__invoke');
}
// if the tests above are exhaustive, we should never hit the next line.
throw new AnnotationException("Unable to determine callable type.");
} | [
"public",
"static",
"function",
"getReflection",
"(",
"callable",
"$",
"f",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"f",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"f",
",",
"'::'",
",",
"1",
")",
"!==",
"false",
")",
"{",
"return",
"new",... | Return the correct reflection class for the given callable.
@param callable $f
@throws AnnotationException
@return \ReflectionFunction|\ReflectionMethod | [
"Return",
"the",
"correct",
"reflection",
"class",
"for",
"the",
"given",
"callable",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Annotation.php#L33-L50 | train |
steos/php-quickcheck | src/QCheck/Annotation.php | Annotation.types | public static function types(callable $f)
{
$ref = self::getReflection($f);
$docs = $ref->getDocComment();
$proto = $ref->getParameters();
preg_match_all('/@param\s+(?P<type>.*?)\s+\$(?P<name>.*?)\s+/', $docs, $docs, PREG_SET_ORDER);
$params = array();
foreach ($proto as $p) {
$name = $p->getName();
$type = null;
foreach ($docs as $k => $d) {
if ($d['name'] === $name) {
$type = $d['type'];
unset($docs[$k]);
break;
}
}
if (is_null($type)) {
throw new MissingTypeAnnotationException("Cannot determine type for $name.");
}
if (count(explode('|', $type)) > 1) {
throw new AmbiguousTypeAnnotationException("Ambiguous type for $name : $type");
}
$params[$name] = $type;
}
return $params;
} | php | public static function types(callable $f)
{
$ref = self::getReflection($f);
$docs = $ref->getDocComment();
$proto = $ref->getParameters();
preg_match_all('/@param\s+(?P<type>.*?)\s+\$(?P<name>.*?)\s+/', $docs, $docs, PREG_SET_ORDER);
$params = array();
foreach ($proto as $p) {
$name = $p->getName();
$type = null;
foreach ($docs as $k => $d) {
if ($d['name'] === $name) {
$type = $d['type'];
unset($docs[$k]);
break;
}
}
if (is_null($type)) {
throw new MissingTypeAnnotationException("Cannot determine type for $name.");
}
if (count(explode('|', $type)) > 1) {
throw new AmbiguousTypeAnnotationException("Ambiguous type for $name : $type");
}
$params[$name] = $type;
}
return $params;
} | [
"public",
"static",
"function",
"types",
"(",
"callable",
"$",
"f",
")",
"{",
"$",
"ref",
"=",
"self",
"::",
"getReflection",
"(",
"$",
"f",
")",
";",
"$",
"docs",
"=",
"$",
"ref",
"->",
"getDocComment",
"(",
")",
";",
"$",
"proto",
"=",
"$",
"re... | Return the types for the given callable.
@param callable $f
@throws AnnotationException
@return array | [
"Return",
"the",
"types",
"for",
"the",
"given",
"callable",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Annotation.php#L59-L89 | train |
steos/php-quickcheck | src/QCheck/Annotation.php | Annotation.register | public static function register($type, Generator $generator)
{
if (array_key_exists($type, self::$generators)) {
throw new DuplicateGeneratorException("A generator is already registred for $type.");
}
self::$generators[$type] = $generator;
} | php | public static function register($type, Generator $generator)
{
if (array_key_exists($type, self::$generators)) {
throw new DuplicateGeneratorException("A generator is already registred for $type.");
}
self::$generators[$type] = $generator;
} | [
"public",
"static",
"function",
"register",
"(",
"$",
"type",
",",
"Generator",
"$",
"generator",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"self",
"::",
"$",
"generators",
")",
")",
"{",
"throw",
"new",
"DuplicateGeneratorException",
... | Associate a generator to a given type.
@param string $type
@param Generator $generator Tĥe generator associated with the type
@throws DuplicateGeneratorException | [
"Associate",
"a",
"generator",
"to",
"a",
"given",
"type",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Annotation.php#L98-L105 | train |
cartalyst/converter | src/Exchangers/OpenExchangeRatesExchanger.php | OpenExchangeRatesExchanger.get | public function get($code)
{
$rates = $this->getRates();
$code = strtoupper($code);
if (empty($rates[$code])) {
throw new Exception;
}
return $rates[$code];
} | php | public function get($code)
{
$rates = $this->getRates();
$code = strtoupper($code);
if (empty($rates[$code])) {
throw new Exception;
}
return $rates[$code];
} | [
"public",
"function",
"get",
"(",
"$",
"code",
")",
"{",
"$",
"rates",
"=",
"$",
"this",
"->",
"getRates",
"(",
")",
";",
"$",
"code",
"=",
"strtoupper",
"(",
"$",
"code",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rates",
"[",
"$",
"code",
"]",
... | Return the exchange rate for the provided currency code.
@param string $code
@return float
@throws \Exception | [
"Return",
"the",
"exchange",
"rate",
"for",
"the",
"provided",
"currency",
"code",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Exchangers/OpenExchangeRatesExchanger.php#L102-L113 | train |
cartalyst/converter | src/Exchangers/OpenExchangeRatesExchanger.php | OpenExchangeRatesExchanger.setRates | public function setRates()
{
// Avoid instance issues
$self = $this;
// Cache the currencies
return $this->rates = $this->cache->remember('currencies', $this->getExpires(), function () use ($self) {
if (! $appId = $self->getAppId()) {
throw new Exception('OpenExchangeRates.org requires an app key.');
}
$client = new Client([ 'base_url' => $self->getUrl() ]);
$data = $client->get("latest.json?app_id={$appId}")->json();
return $data['rates'];
});
} | php | public function setRates()
{
// Avoid instance issues
$self = $this;
// Cache the currencies
return $this->rates = $this->cache->remember('currencies', $this->getExpires(), function () use ($self) {
if (! $appId = $self->getAppId()) {
throw new Exception('OpenExchangeRates.org requires an app key.');
}
$client = new Client([ 'base_url' => $self->getUrl() ]);
$data = $client->get("latest.json?app_id={$appId}")->json();
return $data['rates'];
});
} | [
"public",
"function",
"setRates",
"(",
")",
"{",
"// Avoid instance issues",
"$",
"self",
"=",
"$",
"this",
";",
"// Cache the currencies",
"return",
"$",
"this",
"->",
"rates",
"=",
"$",
"this",
"->",
"cache",
"->",
"remember",
"(",
"'currencies'",
",",
"$"... | Downloads the latest exchange rates file from openexchangerates.org
@return object | [
"Downloads",
"the",
"latest",
"exchange",
"rates",
"file",
"from",
"openexchangerates",
".",
"org"
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Exchangers/OpenExchangeRatesExchanger.php#L173-L190 | train |
steos/php-quickcheck | src/QCheck/FP.php | FP.reduce | public static function reduce(callable $f, $xs, $initial = null)
{
if (is_array($xs)) {
$initial = $initial !== null ? $initial : array_shift($xs);
return array_reduce($xs, $f, $initial);
}
if ($xs instanceof \Iterator) {
$xs->rewind();
if (!$xs->valid()) {
return $initial;
}
$acc = $initial;
if ($acc === null) {
$acc = $xs->current();
$xs->next();
}
for (; $xs->valid(); $xs->next()) {
$acc = call_user_func($f, $acc, $xs->current());
}
return $acc;
}
throw new \InvalidArgumentException();
} | php | public static function reduce(callable $f, $xs, $initial = null)
{
if (is_array($xs)) {
$initial = $initial !== null ? $initial : array_shift($xs);
return array_reduce($xs, $f, $initial);
}
if ($xs instanceof \Iterator) {
$xs->rewind();
if (!$xs->valid()) {
return $initial;
}
$acc = $initial;
if ($acc === null) {
$acc = $xs->current();
$xs->next();
}
for (; $xs->valid(); $xs->next()) {
$acc = call_user_func($f, $acc, $xs->current());
}
return $acc;
}
throw new \InvalidArgumentException();
} | [
"public",
"static",
"function",
"reduce",
"(",
"callable",
"$",
"f",
",",
"$",
"xs",
",",
"$",
"initial",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"xs",
")",
")",
"{",
"$",
"initial",
"=",
"$",
"initial",
"!==",
"null",
"?",
"$",
... | Reduce any iterable collection using the callback. In case
of an array, array_reduce is used.
@param callable $f
@param $xs
@param null $initial
@return mixed|null
@throws \InvalidArgumentException | [
"Reduce",
"any",
"iterable",
"collection",
"using",
"the",
"callback",
".",
"In",
"case",
"of",
"an",
"array",
"array_reduce",
"is",
"used",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L37-L59 | train |
steos/php-quickcheck | src/QCheck/FP.php | FP.comp | public static function comp(callable $f, callable $g)
{
return function () use ($f, $g) {
return call_user_func($f, call_user_func_array($g, func_get_args()));
};
} | php | public static function comp(callable $f, callable $g)
{
return function () use ($f, $g) {
return call_user_func($f, call_user_func_array($g, func_get_args()));
};
} | [
"public",
"static",
"function",
"comp",
"(",
"callable",
"$",
"f",
",",
"callable",
"$",
"g",
")",
"{",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"f",
",",
"$",
"g",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"f",
",",
"call_user_func_arr... | Compose the two functions
@param callable $f
@param callable $g
@return callable | [
"Compose",
"the",
"two",
"functions"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L68-L73 | train |
steos/php-quickcheck | src/QCheck/FP.php | FP.filter | public static function filter(callable $f, $coll)
{
foreach ($coll as $x) {
if (call_user_func($f, $x)) {
yield $x;
}
}
} | php | public static function filter(callable $f, $coll)
{
foreach ($coll as $x) {
if (call_user_func($f, $x)) {
yield $x;
}
}
} | [
"public",
"static",
"function",
"filter",
"(",
"callable",
"$",
"f",
",",
"$",
"coll",
")",
"{",
"foreach",
"(",
"$",
"coll",
"as",
"$",
"x",
")",
"{",
"if",
"(",
"call_user_func",
"(",
"$",
"f",
",",
"$",
"x",
")",
")",
"{",
"yield",
"$",
"x",... | Filter the given iterable collection using the callback in a
lazy way.
@param callable $f
@param $coll
@return \Generator | [
"Filter",
"the",
"given",
"iterable",
"collection",
"using",
"the",
"callback",
"in",
"a",
"lazy",
"way",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L98-L105 | train |
steos/php-quickcheck | src/QCheck/FP.php | FP.iterator | public static function iterator($xs)
{
if (is_array($xs)) {
return new \ArrayIterator($xs);
}
if (!$xs instanceof \Iterator) {
throw new \InvalidArgumentException();
}
return $xs;
} | php | public static function iterator($xs)
{
if (is_array($xs)) {
return new \ArrayIterator($xs);
}
if (!$xs instanceof \Iterator) {
throw new \InvalidArgumentException();
}
return $xs;
} | [
"public",
"static",
"function",
"iterator",
"(",
"$",
"xs",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"xs",
")",
")",
"{",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"xs",
")",
";",
"}",
"if",
"(",
"!",
"$",
"xs",
"instanceof",
"\\",
"Ite... | Return an iterator for the given collection if
possible.
@param $xs
@return \ArrayIterator
@throws \InvalidArgumentException | [
"Return",
"an",
"iterator",
"for",
"the",
"given",
"collection",
"if",
"possible",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L322-L331 | train |
steos/php-quickcheck | src/QCheck/FP.php | FP.takeNth | public static function takeNth($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid(); $coll->valid() && $coll->next()) {
yield $coll->current();
for ($i = 0; $i < $n - 1 && $coll->valid(); ++$i) {
$coll->next();
}
}
} | php | public static function takeNth($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid(); $coll->valid() && $coll->next()) {
yield $coll->current();
for ($i = 0; $i < $n - 1 && $coll->valid(); ++$i) {
$coll->next();
}
}
} | [
"public",
"static",
"function",
"takeNth",
"(",
"$",
"n",
",",
"$",
"coll",
")",
"{",
"$",
"coll",
"=",
"self",
"::",
"iterator",
"(",
"$",
"coll",
")",
";",
"for",
"(",
"$",
"coll",
"->",
"rewind",
"(",
")",
";",
"$",
"coll",
"->",
"valid",
"(... | Return every Nth elements in the given collection in a lazy
fashion.
@param int $n
@param $coll
@return \Generator | [
"Return",
"every",
"Nth",
"elements",
"in",
"the",
"given",
"collection",
"in",
"a",
"lazy",
"fashion",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L341-L350 | train |
steos/php-quickcheck | src/QCheck/FP.php | FP.partition | public static function partition($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid();) {
$partition = [];
for ($i = 0; $i < $n && $coll->valid(); ++$i, $coll->next()) {
$partition[] = $coll->current();
}
yield $partition;
}
} | php | public static function partition($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid();) {
$partition = [];
for ($i = 0; $i < $n && $coll->valid(); ++$i, $coll->next()) {
$partition[] = $coll->current();
}
yield $partition;
}
} | [
"public",
"static",
"function",
"partition",
"(",
"$",
"n",
",",
"$",
"coll",
")",
"{",
"$",
"coll",
"=",
"self",
"::",
"iterator",
"(",
"$",
"coll",
")",
";",
"for",
"(",
"$",
"coll",
"->",
"rewind",
"(",
")",
";",
"$",
"coll",
"->",
"valid",
... | Return the given collection partitioned in n sized segments
in a lazy fashion.
@param int $n
@param $coll
@return \Generator | [
"Return",
"the",
"given",
"collection",
"partitioned",
"in",
"n",
"sized",
"segments",
"in",
"a",
"lazy",
"fashion",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L360-L370 | train |
lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.process | public function process(Query $query, $rows)
{
$meta = [
'hasPrevious' => false,
'previousCursor' => null,
'hasNext' => false,
'nextCursor' => null,
];
if ($this->shouldLtrim($query, $rows)) {
$type = $query->direction()->forward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, (int)$query->exclusive())
);
$rows = $this->slice($rows, 1);
}
if ($this->shouldRtrim($query, $rows)) {
$type = $query->direction()->backward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, $query->limit() - $query->exclusive())
);
$rows = $this->slice($rows, 0, $query->limit());
}
// If we are not using UNION ALL, boolean values are not defined.
if (!$query->selectOrUnionAll() instanceof UnionAll) {
$meta[$query->direction()->forward() ? 'hasPrevious' : 'hasNext'] = null;
}
return $this->invokeFormatter($this->shouldReverse($query) ? $this->reverse($rows) : $rows, $meta, $query);
} | php | public function process(Query $query, $rows)
{
$meta = [
'hasPrevious' => false,
'previousCursor' => null,
'hasNext' => false,
'nextCursor' => null,
];
if ($this->shouldLtrim($query, $rows)) {
$type = $query->direction()->forward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, (int)$query->exclusive())
);
$rows = $this->slice($rows, 1);
}
if ($this->shouldRtrim($query, $rows)) {
$type = $query->direction()->backward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, $query->limit() - $query->exclusive())
);
$rows = $this->slice($rows, 0, $query->limit());
}
// If we are not using UNION ALL, boolean values are not defined.
if (!$query->selectOrUnionAll() instanceof UnionAll) {
$meta[$query->direction()->forward() ? 'hasPrevious' : 'hasNext'] = null;
}
return $this->invokeFormatter($this->shouldReverse($query) ? $this->reverse($rows) : $rows, $meta, $query);
} | [
"public",
"function",
"process",
"(",
"Query",
"$",
"query",
",",
"$",
"rows",
")",
"{",
"$",
"meta",
"=",
"[",
"'hasPrevious'",
"=>",
"false",
",",
"'previousCursor'",
"=>",
"null",
",",
"'hasNext'",
"=>",
"false",
",",
"'nextCursor'",
"=>",
"null",
","... | Get result.
@param Query $query
@param mixed $rows
@return mixed | [
"Get",
"result",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L72-L106 | train |
lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.invokeFormatter | protected function invokeFormatter($rows, array $meta, Query $query)
{
$formatter = $this->formatter ?: static::$defaultFormatter ?: [$this, 'defaultFormat'];
return $formatter($rows, $meta, $query);
} | php | protected function invokeFormatter($rows, array $meta, Query $query)
{
$formatter = $this->formatter ?: static::$defaultFormatter ?: [$this, 'defaultFormat'];
return $formatter($rows, $meta, $query);
} | [
"protected",
"function",
"invokeFormatter",
"(",
"$",
"rows",
",",
"array",
"$",
"meta",
",",
"Query",
"$",
"query",
")",
"{",
"$",
"formatter",
"=",
"$",
"this",
"->",
"formatter",
"?",
":",
"static",
"::",
"$",
"defaultFormatter",
"?",
":",
"[",
"$",... | Invoke formatter.
@param mixed $rows
@param array $meta
@param Query $query
@return mixed | [
"Invoke",
"formatter",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L116-L120 | train |
lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.validateFormatter | protected static function validateFormatter($formatter)
{
if (is_subclass_of($formatter, Formatter::class)) {
return [is_string($formatter) ? new $formatter() : $formatter, 'format'];
}
if (is_callable($formatter)) {
return $formatter;
}
throw new InvalidArgumentException('Formatter must be an instanceof ' . Formatter::class . ' or callable.');
} | php | protected static function validateFormatter($formatter)
{
if (is_subclass_of($formatter, Formatter::class)) {
return [is_string($formatter) ? new $formatter() : $formatter, 'format'];
}
if (is_callable($formatter)) {
return $formatter;
}
throw new InvalidArgumentException('Formatter must be an instanceof ' . Formatter::class . ' or callable.');
} | [
"protected",
"static",
"function",
"validateFormatter",
"(",
"$",
"formatter",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"formatter",
",",
"Formatter",
"::",
"class",
")",
")",
"{",
"return",
"[",
"is_string",
"(",
"$",
"formatter",
")",
"?",
"new",... | Validate formatter and return in normalized form.
@param mixed $formatter
@return callable | [
"Validate",
"formatter",
"and",
"return",
"in",
"normalized",
"form",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L128-L137 | train |
lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.shouldLtrim | protected function shouldLtrim(Query $query, $rows)
{
$first = $this->offset($rows, 0);
$selectOrUnionAll = $query->selectOrUnionAll();
// If we are not using UNION ALL or the elements are empty...
if (!$selectOrUnionAll instanceof UnionAll || !$first) {
return false;
}
foreach ($selectOrUnionAll->supportQuery()->orders() as $order) {
// Retrieve values
$field = $this->field($first, $order->column());
$cursor = $query->cursor()->get($order->column());
// Compare the first row and the cursor
if (!$diff = $this->compareField($field, $cursor)) {
continue;
}
//
// Drop the first row if ...
//
//
// - the support query is descending && $field < $cursor
//
// --------------------> Main query, ascending
// [4, <5>, 6, 7, 8, 9, 10]
// <----- Support query, descending
//
// ----> Support query, descending
// [10, 9, 8, 7, 6, <5>, 4]
// <--------------------- Main query, ascending
//
//
// - the support query is ascending && $field > $cursor
//
// -----> Support query, ascending
// [4, 5, 6, 7, 8, <9>, 10]
// <-------------------- Main query, descending
//
// --------------------> Main query, descending
// [10, <9>, 8, 7, 6, 5, 4]
// <---- Support query, ascending
//
return $diff === ($order->descending() ? -1 : 1);
}
// If the first row and the cursor are identical, we should drop the first row only if exclusive.
return $query->exclusive();
} | php | protected function shouldLtrim(Query $query, $rows)
{
$first = $this->offset($rows, 0);
$selectOrUnionAll = $query->selectOrUnionAll();
// If we are not using UNION ALL or the elements are empty...
if (!$selectOrUnionAll instanceof UnionAll || !$first) {
return false;
}
foreach ($selectOrUnionAll->supportQuery()->orders() as $order) {
// Retrieve values
$field = $this->field($first, $order->column());
$cursor = $query->cursor()->get($order->column());
// Compare the first row and the cursor
if (!$diff = $this->compareField($field, $cursor)) {
continue;
}
//
// Drop the first row if ...
//
//
// - the support query is descending && $field < $cursor
//
// --------------------> Main query, ascending
// [4, <5>, 6, 7, 8, 9, 10]
// <----- Support query, descending
//
// ----> Support query, descending
// [10, 9, 8, 7, 6, <5>, 4]
// <--------------------- Main query, ascending
//
//
// - the support query is ascending && $field > $cursor
//
// -----> Support query, ascending
// [4, 5, 6, 7, 8, <9>, 10]
// <-------------------- Main query, descending
//
// --------------------> Main query, descending
// [10, <9>, 8, 7, 6, 5, 4]
// <---- Support query, ascending
//
return $diff === ($order->descending() ? -1 : 1);
}
// If the first row and the cursor are identical, we should drop the first row only if exclusive.
return $query->exclusive();
} | [
"protected",
"function",
"shouldLtrim",
"(",
"Query",
"$",
"query",
",",
"$",
"rows",
")",
"{",
"$",
"first",
"=",
"$",
"this",
"->",
"offset",
"(",
"$",
"rows",
",",
"0",
")",
";",
"$",
"selectOrUnionAll",
"=",
"$",
"query",
"->",
"selectOrUnionAll",
... | Determine if the first row should be dropped.
@param Query $query
@param mixed $rows
@return bool | [
"Determine",
"if",
"the",
"first",
"row",
"should",
"be",
"dropped",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L170-L222 | train |
lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.makeCursor | protected function makeCursor(Query $query, $row)
{
$fields = [];
foreach ($query->orders() as $order) {
$fields[$order->column()] = $this->field($row, $order->column());
}
return $fields;
} | php | protected function makeCursor(Query $query, $row)
{
$fields = [];
foreach ($query->orders() as $order) {
$fields[$order->column()] = $this->field($row, $order->column());
}
return $fields;
} | [
"protected",
"function",
"makeCursor",
"(",
"Query",
"$",
"query",
",",
"$",
"row",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"orders",
"(",
")",
"as",
"$",
"order",
")",
"{",
"$",
"fields",
"[",
"$",
"order... | Make a cursor from the specific row.
@param Query $query
@param mixed $row
@return int[]|string[] | [
"Make",
"a",
"cursor",
"from",
"the",
"specific",
"row",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L243-L250 | train |
lampager/lampager | src/ArrayProcessor.php | ArrayProcessor.field | protected function field($row, $column)
{
return is_object($row) && !$row instanceof \ArrayAccess ? $row->$column : $row[$column];
} | php | protected function field($row, $column)
{
return is_object($row) && !$row instanceof \ArrayAccess ? $row->$column : $row[$column];
} | [
"protected",
"function",
"field",
"(",
"$",
"row",
",",
"$",
"column",
")",
"{",
"return",
"is_object",
"(",
"$",
"row",
")",
"&&",
"!",
"$",
"row",
"instanceof",
"\\",
"ArrayAccess",
"?",
"$",
"row",
"->",
"$",
"column",
":",
"$",
"row",
"[",
"$",... | Return comparable value from a row.
@param mixed $row
@param string $column
@return int|string | [
"Return",
"comparable",
"value",
"from",
"a",
"row",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/ArrayProcessor.php#L14-L17 | train |
lampager/lampager | src/Concerns/HasProcessor.php | HasProcessor.validateProcessor | protected static function validateProcessor($processor)
{
if (!is_subclass_of($processor, AbstractProcessor::class)) {
throw new InvalidArgumentException('Processor must be an instanceof ' . AbstractProcessor::class);
}
return is_string($processor) ? new $processor() : $processor;
} | php | protected static function validateProcessor($processor)
{
if (!is_subclass_of($processor, AbstractProcessor::class)) {
throw new InvalidArgumentException('Processor must be an instanceof ' . AbstractProcessor::class);
}
return is_string($processor) ? new $processor() : $processor;
} | [
"protected",
"static",
"function",
"validateProcessor",
"(",
"$",
"processor",
")",
"{",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"processor",
",",
"AbstractProcessor",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Processor... | Validate processor and return in normalized form.
@param mixed $processor
@return AbstractProcessor | [
"Validate",
"processor",
"and",
"return",
"in",
"normalized",
"form",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Concerns/HasProcessor.php#L70-L76 | train |
lampager/lampager | src/Paginator.php | Paginator.orderBy | public function orderBy($column, $order = Order::ASC)
{
$this->orders[] = [$column, $order];
return $this;
} | php | public function orderBy($column, $order = Order::ASC)
{
$this->orders[] = [$column, $order];
return $this;
} | [
"public",
"function",
"orderBy",
"(",
"$",
"column",
",",
"$",
"order",
"=",
"Order",
"::",
"ASC",
")",
"{",
"$",
"this",
"->",
"orders",
"[",
"]",
"=",
"[",
"$",
"column",
",",
"$",
"order",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add cursor parameter name for ORDER BY statement.
IMPORTANT: Last parameter MUST be a primary key
e.g. $factory->orderBy('created_at')->orderBy('id') // <--- PRIMARY KEY
@param string $column
@param null|string $order
@return $this | [
"Add",
"cursor",
"parameter",
"name",
"for",
"ORDER",
"BY",
"statement",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Paginator.php#L54-L58 | train |
lampager/lampager | src/Paginator.php | Paginator.fromArray | public function fromArray(array $options)
{
static $configurables = [
'limit',
'forward',
'backward',
'exclusive',
'inclusive',
'seekable',
'unseekable',
];
if (isset($options['orders'])) {
foreach ($options['orders'] as $order) {
$this->orderBy(...$order);
}
}
foreach (array_intersect_key($options, array_flip($configurables)) as $key => $value) {
$this->$key($value);
}
return $this;
} | php | public function fromArray(array $options)
{
static $configurables = [
'limit',
'forward',
'backward',
'exclusive',
'inclusive',
'seekable',
'unseekable',
];
if (isset($options['orders'])) {
foreach ($options['orders'] as $order) {
$this->orderBy(...$order);
}
}
foreach (array_intersect_key($options, array_flip($configurables)) as $key => $value) {
$this->$key($value);
}
return $this;
} | [
"public",
"function",
"fromArray",
"(",
"array",
"$",
"options",
")",
"{",
"static",
"$",
"configurables",
"=",
"[",
"'limit'",
",",
"'forward'",
",",
"'backward'",
",",
"'exclusive'",
",",
"'inclusive'",
",",
"'seekable'",
",",
"'unseekable'",
",",
"]",
";"... | Define options from an associative array.
@param (bool|int|string[][])[] $options
@return $this | [
"Define",
"options",
"from",
"an",
"associative",
"array",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Paginator.php#L172-L195 | train |
lampager/lampager | src/Paginator.php | Paginator.configure | public function configure($cursor = [])
{
return Query::create($this->orders, $cursor, $this->limit, $this->backward, $this->exclusive, $this->seekable, $this->builder);
} | php | public function configure($cursor = [])
{
return Query::create($this->orders, $cursor, $this->limit, $this->backward, $this->exclusive, $this->seekable, $this->builder);
} | [
"public",
"function",
"configure",
"(",
"$",
"cursor",
"=",
"[",
"]",
")",
"{",
"return",
"Query",
"::",
"create",
"(",
"$",
"this",
"->",
"orders",
",",
"$",
"cursor",
",",
"$",
"this",
"->",
"limit",
",",
"$",
"this",
"->",
"backward",
",",
"$",
... | Build Query instance.
@param Cursor|int[]|string[] $cursor
@return Query | [
"Build",
"Query",
"instance",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Paginator.php#L203-L206 | train |
fgheorghe/php3d-stl | src/STLFacetNormal.php | STLFacetNormal.fromString | public static function fromString(string $stlFacetNormalString) : STLFacetNormal
{
$class = new self();
preg_match("/facet normal +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlFacetNormalString, $matches);
$class->setCoordinatesArray(array((float)$matches[1], (float)$matches[2], (float)$matches[3]));
$lines = explode("\n", $stlFacetNormalString);
$vertex = "";
for ($i = 1; $i < count($lines) - 1; $i++) {
$vertex .= $lines[$i];
}
$class->setVertex(STLVertex::fromString($vertex));
return $class;
} | php | public static function fromString(string $stlFacetNormalString) : STLFacetNormal
{
$class = new self();
preg_match("/facet normal +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlFacetNormalString, $matches);
$class->setCoordinatesArray(array((float)$matches[1], (float)$matches[2], (float)$matches[3]));
$lines = explode("\n", $stlFacetNormalString);
$vertex = "";
for ($i = 1; $i < count($lines) - 1; $i++) {
$vertex .= $lines[$i];
}
$class->setVertex(STLVertex::fromString($vertex));
return $class;
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"stlFacetNormalString",
")",
":",
"STLFacetNormal",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"preg_match",
"(",
"\"/facet normal +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\d*) +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\... | Class constructor from an STL facet normal string.
Example facet normal string:
facet normal 0.5651193 -0.07131607 0.8219211
outerloop
vertex -71.74323 47.70205 4.666243
vertex -72.13071 47.70205 4.932664
vertex -72.1506 47.2273 4.905148
endloop
endfacet
@param string $stlFacetNormalString
@return STLFacetNormal | [
"Class",
"constructor",
"from",
"an",
"STL",
"facet",
"normal",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLFacetNormal.php#L86-L102 | train |
fgheorghe/php3d-stl | src/STLFacetNormal.php | STLFacetNormal.fromArray | public static function fromArray(array $stlFacetNormalArray) : STLFacetNormal
{
$class = new self();
$class->setCoordinatesArray($stlFacetNormalArray["coordinates"]);
$class->setVertex(STLVertex::fromArray($stlFacetNormalArray["vertex"]));
return $class;
} | php | public static function fromArray(array $stlFacetNormalArray) : STLFacetNormal
{
$class = new self();
$class->setCoordinatesArray($stlFacetNormalArray["coordinates"]);
$class->setVertex(STLVertex::fromArray($stlFacetNormalArray["vertex"]));
return $class;
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"stlFacetNormalArray",
")",
":",
"STLFacetNormal",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"$",
"class",
"->",
"setCoordinatesArray",
"(",
"$",
"stlFacetNormalArray",
"[",
"\"coordin... | Class constructor from an STL facet normal array.
Example facet normal array:
array(
"coordinates" => array(0.5651193, -0.07131607, 0.8219211),
"vertex" => array(
array(
-71.74323, 47.70205, 4.666243
),
array(
-72.13071, 47.70205, 4.932664
),
array(
-72.1506, 47.2273, 4.905148
)
)
)
@param array $stlFacetNormalArray
@return STLFacetNormal | [
"Class",
"constructor",
"from",
"an",
"STL",
"facet",
"normal",
"array",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLFacetNormal.php#L126-L132 | train |
fgheorghe/php3d-stl | src/STLFacetNormal.php | STLFacetNormal.toString | public function toString() : string
{
$string = "facet normal " . implode(" ", $this->getCoordinatesArray()) . "\n";
$string .= $this->getVertex()->toString() . "\n";
$string .= "endfacet";
return $string;
} | php | public function toString() : string
{
$string = "facet normal " . implode(" ", $this->getCoordinatesArray()) . "\n";
$string .= $this->getVertex()->toString() . "\n";
$string .= "endfacet";
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
":",
"string",
"{",
"$",
"string",
"=",
"\"facet normal \"",
".",
"implode",
"(",
"\" \"",
",",
"$",
"this",
"->",
"getCoordinatesArray",
"(",
")",
")",
".",
"\"\\n\"",
";",
"$",
"string",
".=",
"$",
"this",
... | Returns facet as string.
@return string | [
"Returns",
"facet",
"as",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLFacetNormal.php#L152-L158 | train |
fgheorghe/php3d-stl | src/STLSplit.php | STLSplit.split | public function split() : array
{
$stlArray = $this->getStl()->toArray();
$facets = $stlArray["facets"];
$objArray = array();
$vertex = $facets[0];
unset($facets[0]);
$current = 0;
$objArray[$current] = array($vertex);
while (count($facets) != 0) {
$this->findNeighbour(
$vertex,
$objArray[$current],
$facets
);
$vertex = array_pop($facets);
$current++;
if ($vertex) {
$objArray[$current] = array($vertex);
}
}
$stlObjects = array();
foreach ($objArray as $key => $object) {
$stlObjects[] = STL::fromArray(array(
"name" => $this->getStl()->getSolidName() . $key,
"facets" => $object
));
}
return $stlObjects;
} | php | public function split() : array
{
$stlArray = $this->getStl()->toArray();
$facets = $stlArray["facets"];
$objArray = array();
$vertex = $facets[0];
unset($facets[0]);
$current = 0;
$objArray[$current] = array($vertex);
while (count($facets) != 0) {
$this->findNeighbour(
$vertex,
$objArray[$current],
$facets
);
$vertex = array_pop($facets);
$current++;
if ($vertex) {
$objArray[$current] = array($vertex);
}
}
$stlObjects = array();
foreach ($objArray as $key => $object) {
$stlObjects[] = STL::fromArray(array(
"name" => $this->getStl()->getSolidName() . $key,
"facets" => $object
));
}
return $stlObjects;
} | [
"public",
"function",
"split",
"(",
")",
":",
"array",
"{",
"$",
"stlArray",
"=",
"$",
"this",
"->",
"getStl",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"facets",
"=",
"$",
"stlArray",
"[",
"\"facets\"",
"]",
";",
"$",
"objArray",
"=",
"array"... | Splits an STL object and returns the new 3D objects in an array of STL files.
@return array | [
"Splits",
"an",
"STL",
"object",
"and",
"returns",
"the",
"new",
"3D",
"objects",
"in",
"an",
"array",
"of",
"STL",
"files",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLSplit.php#L55-L88 | train |
fgheorghe/php3d-stl | src/STLSplit.php | STLSplit.findNeighbour | private function findNeighbour(array $facet, array &$object, array &$facets)
{
foreach ($facets as $key => $_facet) {
for ($i = 0; $i < 3; $i++) {
if (in_array($_facet["vertex"][$i], $facet["vertex"])) {
unset($facets[$key]);
$object[] = $_facet;
$this->findNeighbour(
$_facet,
$object,
$facets
);
}
continue 2;
}
}
} | php | private function findNeighbour(array $facet, array &$object, array &$facets)
{
foreach ($facets as $key => $_facet) {
for ($i = 0; $i < 3; $i++) {
if (in_array($_facet["vertex"][$i], $facet["vertex"])) {
unset($facets[$key]);
$object[] = $_facet;
$this->findNeighbour(
$_facet,
$object,
$facets
);
}
continue 2;
}
}
} | [
"private",
"function",
"findNeighbour",
"(",
"array",
"$",
"facet",
",",
"array",
"&",
"$",
"object",
",",
"array",
"&",
"$",
"facets",
")",
"{",
"foreach",
"(",
"$",
"facets",
"as",
"$",
"key",
"=>",
"$",
"_facet",
")",
"{",
"for",
"(",
"$",
"i",
... | Finds the neighbouring facets of a facet.
@param array $facet
@param array $object
@param array $facets | [
"Finds",
"the",
"neighbouring",
"facets",
"of",
"a",
"facet",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLSplit.php#L97-L113 | train |
fgheorghe/php3d-stl | src/STLVertex.php | STLVertex.fromString | public static function fromString(string $stlVertexString) : STLVertex
{
$class = new self();
preg_match_all("/vertex +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlVertexString, $matches);
$coordinates = array(
array((float)$matches[1][0], (float)$matches[2][0], (float)$matches[3][0]),
array((float)$matches[1][1], (float)$matches[2][1], (float)$matches[3][1]),
array((float)$matches[1][2], (float)$matches[2][2], (float)$matches[3][2])
);
$class->setCoordinatesArray($coordinates);
return $class;
} | php | public static function fromString(string $stlVertexString) : STLVertex
{
$class = new self();
preg_match_all("/vertex +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlVertexString, $matches);
$coordinates = array(
array((float)$matches[1][0], (float)$matches[2][0], (float)$matches[3][0]),
array((float)$matches[1][1], (float)$matches[2][1], (float)$matches[3][1]),
array((float)$matches[1][2], (float)$matches[2][2], (float)$matches[3][2])
);
$class->setCoordinatesArray($coordinates);
return $class;
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"stlVertexString",
")",
":",
"STLVertex",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"preg_match_all",
"(",
"\"/vertex +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\d*) +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\d*) +(\\-*\\... | Class constructor from an STL vertex string.
Example vertex string:
outerloop
vertex -71.74323 47.70205 4.666243
vertex -72.13071 47.70205 4.932664
vertex -72.1506 47.2273 4.905148
endloop
@param string $stlVertexString
@return STLVertex | [
"Class",
"constructor",
"from",
"an",
"STL",
"vertex",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLVertex.php#L60-L76 | train |
fgheorghe/php3d-stl | src/STLVertex.php | STLVertex.toString | public function toString() : string
{
$coordinates = $this->getCoordinatesArray();
$string = "outerloop\n";
foreach ($coordinates as $coordinate) {
$string .= " vertex " . implode(" ", $coordinate) . "\n";
}
$string .= "endloop";
return $string;
} | php | public function toString() : string
{
$coordinates = $this->getCoordinatesArray();
$string = "outerloop\n";
foreach ($coordinates as $coordinate) {
$string .= " vertex " . implode(" ", $coordinate) . "\n";
}
$string .= "endloop";
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
":",
"string",
"{",
"$",
"coordinates",
"=",
"$",
"this",
"->",
"getCoordinatesArray",
"(",
")",
";",
"$",
"string",
"=",
"\"outerloop\\n\"",
";",
"foreach",
"(",
"$",
"coordinates",
"as",
"$",
"coordinate",
")",... | Returns a vertex outerloop.
@return string | [
"Returns",
"a",
"vertex",
"outerloop",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLVertex.php#L120-L130 | train |
fgheorghe/php3d-stl | src/STL.php | STL.fromString | public static function fromString(string $stlFileContentString) : STL
{
$class = new self();
// Extract name.
$lines = explode("\n", $stlFileContentString);
preg_match("/solid (.+)/", $lines[0], $matches);
$class->setSolidName($matches[1]);
// Extract facets.
foreach ($lines as $line) {
if (preg_match("/facet normal (.+)/", $line)) {
// Get this line and the following, making a block of facets.
$string = next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$class->addFacetNormal(STLFacetNormal::fromString($string));
}
}
return $class;
} | php | public static function fromString(string $stlFileContentString) : STL
{
$class = new self();
// Extract name.
$lines = explode("\n", $stlFileContentString);
preg_match("/solid (.+)/", $lines[0], $matches);
$class->setSolidName($matches[1]);
// Extract facets.
foreach ($lines as $line) {
if (preg_match("/facet normal (.+)/", $line)) {
// Get this line and the following, making a block of facets.
$string = next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$class->addFacetNormal(STLFacetNormal::fromString($string));
}
}
return $class;
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"stlFileContentString",
")",
":",
"STL",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"// Extract name.",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"stlFileContentString... | Class constructor from an STL string.
Example STL file string: see STLTest $stlFileString property.
@param string $stlFileContentString
@return STL | [
"Class",
"constructor",
"from",
"an",
"STL",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L60-L85 | train |
fgheorghe/php3d-stl | src/STL.php | STL.fromArray | public static function fromArray(array $stlFileArray) : STL
{
$class = new self();
$class->setSolidName($stlFileArray["name"]);
foreach ($stlFileArray["facets"] as $facet) {
$class->addFacetNormal(STLFacetNormal::fromArray($facet));
}
return $class;
} | php | public static function fromArray(array $stlFileArray) : STL
{
$class = new self();
$class->setSolidName($stlFileArray["name"]);
foreach ($stlFileArray["facets"] as $facet) {
$class->addFacetNormal(STLFacetNormal::fromArray($facet));
}
return $class;
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"stlFileArray",
")",
":",
"STL",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"$",
"class",
"->",
"setSolidName",
"(",
"$",
"stlFileArray",
"[",
"\"name\"",
"]",
")",
";",
"foreac... | Class constructor from an STL array.
Example STL file array: see STLTest $stlFileArray property.
@param array $stlFileArray
@return STL | [
"Class",
"constructor",
"from",
"an",
"STL",
"array",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L95-L105 | train |
fgheorghe/php3d-stl | src/STL.php | STL.setFacetNormal | public function setFacetNormal(int $position, STLFacetNormal $facetNormal) : STL
{
$this->facets[$position] = $facetNormal;
return $this;
} | php | public function setFacetNormal(int $position, STLFacetNormal $facetNormal) : STL
{
$this->facets[$position] = $facetNormal;
return $this;
} | [
"public",
"function",
"setFacetNormal",
"(",
"int",
"$",
"position",
",",
"STLFacetNormal",
"$",
"facetNormal",
")",
":",
"STL",
"{",
"$",
"this",
"->",
"facets",
"[",
"$",
"position",
"]",
"=",
"$",
"facetNormal",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a facet normal at a given position.
@param int $position
@param STLFacetNormal $facetNormal
@return STL | [
"Sets",
"a",
"facet",
"normal",
"at",
"a",
"given",
"position",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L147-L151 | train |
fgheorghe/php3d-stl | src/STL.php | STL.deleteFacetNormal | public function deleteFacetNormal(int $position) : STL
{
$facets = $this->facets;
unset($facets[$position]);
$this->facets = array_values($facets);
return $this;
} | php | public function deleteFacetNormal(int $position) : STL
{
$facets = $this->facets;
unset($facets[$position]);
$this->facets = array_values($facets);
return $this;
} | [
"public",
"function",
"deleteFacetNormal",
"(",
"int",
"$",
"position",
")",
":",
"STL",
"{",
"$",
"facets",
"=",
"$",
"this",
"->",
"facets",
";",
"unset",
"(",
"$",
"facets",
"[",
"$",
"position",
"]",
")",
";",
"$",
"this",
"->",
"facets",
"=",
... | Deletes a facet normal at a given position.
@param int $position
@return STL | [
"Deletes",
"a",
"facet",
"normal",
"at",
"a",
"given",
"position",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L159-L165 | train |
fgheorghe/php3d-stl | src/STL.php | STL.toArray | public function toArray() : array
{
$facets = array();
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$facets[] = $this->getFacetNormal($i)->toArray();
}
return array(
"name" => $this->getSolidName(),
"facets" => $facets
);
} | php | public function toArray() : array
{
$facets = array();
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$facets[] = $this->getFacetNormal($i)->toArray();
}
return array(
"name" => $this->getSolidName(),
"facets" => $facets
);
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"facets",
"=",
"array",
"(",
")",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"getFacetNormalCount",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"coun... | Converts STL back to array.
@return array | [
"Converts",
"STL",
"back",
"to",
"array",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L172-L185 | train |
fgheorghe/php3d-stl | src/STL.php | STL.toString | public function toString() : string
{
$string = "solid " . $this->getSolidName() . "\n";
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$string .= $this->getFacetNormal($i)->toString() . "\n";
}
$string .= "endsolid";
return $string;
} | php | public function toString() : string
{
$string = "solid " . $this->getSolidName() . "\n";
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$string .= $this->getFacetNormal($i)->toString() . "\n";
}
$string .= "endsolid";
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
":",
"string",
"{",
"$",
"string",
"=",
"\"solid \"",
".",
"$",
"this",
"->",
"getSolidName",
"(",
")",
".",
"\"\\n\"",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"getFacetNormalCount",
"(",
")",
";",
"for",
... | Converts STL back to string.
@return string | [
"Converts",
"STL",
"back",
"to",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L192-L205 | train |
ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.save | public function save($file, $data, $ttl)
{
$cacheHash = $this->getCacheHash($file);
if($this->fs->write($this->getMetaFilePath($file), json_encode($data))) {
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($ttl)
$cache->set($cacheHash, $data, $ttl);
elseif ($cache->exists($cacheHash))
$cache->clear($cacheHash);
}
$this->data = $data;
return true;
} else return false;
} | php | public function save($file, $data, $ttl)
{
$cacheHash = $this->getCacheHash($file);
if($this->fs->write($this->getMetaFilePath($file), json_encode($data))) {
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($ttl)
$cache->set($cacheHash, $data, $ttl);
elseif ($cache->exists($cacheHash))
$cache->clear($cacheHash);
}
$this->data = $data;
return true;
} else return false;
} | [
"public",
"function",
"save",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"ttl",
")",
"{",
"$",
"cacheHash",
"=",
"$",
"this",
"->",
"getCacheHash",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"write",
"(",
"$",
"thi... | save meta data
@param $file
@param $data
@param $ttl
@return bool | [
"save",
"meta",
"data"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L44-L58 | train |
ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.load | public function load($file,$ttl)
{
$cache = \Cache::instance();
$cacheHash = $this->getCacheHash($file);
if ($this->f3->get('CACHE') && $ttl && ($cached = $cache->exists(
$cacheHash, $content)) && $cached + $ttl > microtime(TRUE)
) {
$this->data = $content;
} elseif ($this->fs->exists($metaFile = $this->getMetaFilePath($file))) {
$this->data = json_decode($this->fs->read($metaFile), true);
if ($this->f3->get('CACHE') && $ttl)
$cache->set($cacheHash, $this->data, $ttl);
}
return $this->data;
} | php | public function load($file,$ttl)
{
$cache = \Cache::instance();
$cacheHash = $this->getCacheHash($file);
if ($this->f3->get('CACHE') && $ttl && ($cached = $cache->exists(
$cacheHash, $content)) && $cached + $ttl > microtime(TRUE)
) {
$this->data = $content;
} elseif ($this->fs->exists($metaFile = $this->getMetaFilePath($file))) {
$this->data = json_decode($this->fs->read($metaFile), true);
if ($this->f3->get('CACHE') && $ttl)
$cache->set($cacheHash, $this->data, $ttl);
}
return $this->data;
} | [
"public",
"function",
"load",
"(",
"$",
"file",
",",
"$",
"ttl",
")",
"{",
"$",
"cache",
"=",
"\\",
"Cache",
"::",
"instance",
"(",
")",
";",
"$",
"cacheHash",
"=",
"$",
"this",
"->",
"getCacheHash",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
... | return meta data
@param $file
@param $ttl
@return mixed | [
"return",
"meta",
"data"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L66-L80 | train |
ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.delete | public function delete($file)
{
$metaFile = $this->getMetaFilePath($file);
if ($this->fs->exists($metaFile))
$this->fs->delete($metaFile);
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($file)))
$cache->clear($cacheHash);
}
} | php | public function delete($file)
{
$metaFile = $this->getMetaFilePath($file);
if ($this->fs->exists($metaFile))
$this->fs->delete($metaFile);
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($file)))
$cache->clear($cacheHash);
}
} | [
"public",
"function",
"delete",
"(",
"$",
"file",
")",
"{",
"$",
"metaFile",
"=",
"$",
"this",
"->",
"getMetaFilePath",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"metaFile",
")",
")",
"$",
"this",
"... | delete meta record
@param $file | [
"delete",
"meta",
"record"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L86-L96 | train |
ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.move | public function move($current,$new)
{
$metaFile = $this->getMetaFilePath($current);
if ($this->fs->exists($metaFile)) {
$this->fs->move($metaFile,$this->getMetaFilePath($new));
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($current)))
$cache->clear($cacheHash);
}
}
} | php | public function move($current,$new)
{
$metaFile = $this->getMetaFilePath($current);
if ($this->fs->exists($metaFile)) {
$this->fs->move($metaFile,$this->getMetaFilePath($new));
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($current)))
$cache->clear($cacheHash);
}
}
} | [
"public",
"function",
"move",
"(",
"$",
"current",
",",
"$",
"new",
")",
"{",
"$",
"metaFile",
"=",
"$",
"this",
"->",
"getMetaFilePath",
"(",
"$",
"current",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"metaFile",
")",
... | rename meta file
@param $current
@param $new | [
"rename",
"meta",
"file"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L103-L114 | train |
ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.getMetaFilePath | protected function getMetaFilePath($file)
{
$parts = pathinfo($file);
$metaFilename = sprintf($this->metaFileMask, $parts['basename']);
return str_replace($parts['basename'], $metaFilename, $file);
} | php | protected function getMetaFilePath($file)
{
$parts = pathinfo($file);
$metaFilename = sprintf($this->metaFileMask, $parts['basename']);
return str_replace($parts['basename'], $metaFilename, $file);
} | [
"protected",
"function",
"getMetaFilePath",
"(",
"$",
"file",
")",
"{",
"$",
"parts",
"=",
"pathinfo",
"(",
"$",
"file",
")",
";",
"$",
"metaFilename",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"metaFileMask",
",",
"$",
"parts",
"[",
"'basename'",
"]",
"... | compute meta file path
@param string $file
@return mixed | [
"compute",
"meta",
"file",
"path"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L121-L126 | train |
ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.getCacheHash | protected function getCacheHash($file)
{
$fs_class = explode('\\', get_class($this->fs));
return $this->f3->hash($this->f3->stringify($file)).
'.'.strtolower(array_pop($fs_class)).'.meta';
} | php | protected function getCacheHash($file)
{
$fs_class = explode('\\', get_class($this->fs));
return $this->f3->hash($this->f3->stringify($file)).
'.'.strtolower(array_pop($fs_class)).'.meta';
} | [
"protected",
"function",
"getCacheHash",
"(",
"$",
"file",
")",
"{",
"$",
"fs_class",
"=",
"explode",
"(",
"'\\\\'",
",",
"get_class",
"(",
"$",
"this",
"->",
"fs",
")",
")",
";",
"return",
"$",
"this",
"->",
"f3",
"->",
"hash",
"(",
"$",
"this",
"... | return cache key
@param $file
@return string | [
"return",
"cache",
"key"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L133-L138 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.setAuthToken | public function setAuthToken($token, $secret) {
$this->authToken = $token;
$this->authSecret = $secret;
$this->f3->set('SESSION.dropbox.authToken', $this->authToken);
$this->f3->set('SESSION.dropbox.authSecret', $this->authSecret);
} | php | public function setAuthToken($token, $secret) {
$this->authToken = $token;
$this->authSecret = $secret;
$this->f3->set('SESSION.dropbox.authToken', $this->authToken);
$this->f3->set('SESSION.dropbox.authSecret', $this->authSecret);
} | [
"public",
"function",
"setAuthToken",
"(",
"$",
"token",
",",
"$",
"secret",
")",
"{",
"$",
"this",
"->",
"authToken",
"=",
"$",
"token",
";",
"$",
"this",
"->",
"authSecret",
"=",
"$",
"secret",
";",
"$",
"this",
"->",
"f3",
"->",
"set",
"(",
"'SE... | set auth tokens
@param $token
@param $secret | [
"set",
"auth",
"tokens"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L70-L75 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.login | public function login($callback_url=NULL) {
if (!$this->f3->exists('GET.oauth_token')) {
$tokens = $this->requestToken();
$this->setAuthToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
if(is_null($callback_url))
$callback_url = $this->f3->get('SCHEME').'://'.$this->f3->get('HOST').
$this->f3->get('URI');
$this->authorize($callback_url);
} else {
return $this->accessToken();
}
} | php | public function login($callback_url=NULL) {
if (!$this->f3->exists('GET.oauth_token')) {
$tokens = $this->requestToken();
$this->setAuthToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
if(is_null($callback_url))
$callback_url = $this->f3->get('SCHEME').'://'.$this->f3->get('HOST').
$this->f3->get('URI');
$this->authorize($callback_url);
} else {
return $this->accessToken();
}
} | [
"public",
"function",
"login",
"(",
"$",
"callback_url",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"f3",
"->",
"exists",
"(",
"'GET.oauth_token'",
")",
")",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"requestToken",
"(",
")",
";",
... | perform external authorisation, return access token
@param null $callback_url
@return array|bool | [
"perform",
"external",
"authorisation",
"return",
"access",
"token"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L82-L93 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.doOAuthCall | protected function doOAuthCall($url, $method, $params=null,
$type=NULL, $file=NULL, $content=NULL) {
if(is_null($params)) $params = array();
$method = strtoupper($method);
$options = array('method' => $method);
if ($method == 'GET') {
if($file)
$url .= $type.'/'.$file;
$url .= '?'.http_build_query($this->authParams + $params);
}
elseif ($method == 'POST') {
$params = $this->authParams + $params + array('root' => $type);
$options['content'] = http_build_query($params);
}
elseif ($method == 'PUT') {
$url .= $type.'/'.$file.'?'.http_build_query($this->authParams + $params);
$options['content'] = $content;
$options['header'] = array('Content-Type: application/octet-stream');
}
else {
trigger_error(sprintf(self::E_METHODNOTSUPPORTED,$method));
return false;
}
return $this->web->request($url, $options);
} | php | protected function doOAuthCall($url, $method, $params=null,
$type=NULL, $file=NULL, $content=NULL) {
if(is_null($params)) $params = array();
$method = strtoupper($method);
$options = array('method' => $method);
if ($method == 'GET') {
if($file)
$url .= $type.'/'.$file;
$url .= '?'.http_build_query($this->authParams + $params);
}
elseif ($method == 'POST') {
$params = $this->authParams + $params + array('root' => $type);
$options['content'] = http_build_query($params);
}
elseif ($method == 'PUT') {
$url .= $type.'/'.$file.'?'.http_build_query($this->authParams + $params);
$options['content'] = $content;
$options['header'] = array('Content-Type: application/octet-stream');
}
else {
trigger_error(sprintf(self::E_METHODNOTSUPPORTED,$method));
return false;
}
return $this->web->request($url, $options);
} | [
"protected",
"function",
"doOAuthCall",
"(",
"$",
"url",
",",
"$",
"method",
",",
"$",
"params",
"=",
"null",
",",
"$",
"type",
"=",
"NULL",
",",
"$",
"file",
"=",
"NULL",
",",
"$",
"content",
"=",
"NULL",
")",
"{",
"if",
"(",
"is_null",
"(",
"$"... | perform a signed oauth request
@param string $url request url
@param string $method method type
@param array $params additional params
@param null $type storage type [sandbox|dropbox]
@param null $file full file pathname
@param null $content file content
@return bool | [
"perform",
"a",
"signed",
"oauth",
"request"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L160-L184 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.getAccountInfo | public function getAccountInfo() {
$url = 'https://api.dropbox.com/1/account/info';
$result = $this->doOAuthCall($url,'POST');
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR,$result_body['error']));
return false;
}
} | php | public function getAccountInfo() {
$url = 'https://api.dropbox.com/1/account/info';
$result = $this->doOAuthCall($url,'POST');
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR,$result_body['error']));
return false;
}
} | [
"public",
"function",
"getAccountInfo",
"(",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/account/info'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url",
",",
"'POST'",
")",
";",
"$",
"result_body",
"=",
"json_decode",
"... | gather user account information
@return bool|mixed | [
"gather",
"user",
"account",
"information"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L190-L200 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.read | public function read($file, $rev=NUll, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files/';
$params = array();
if ($rev) $params['rev'] = $rev;
$result = $this->doOAuthCall($url,'GET',$params, $type, $file);
// if file not found, response is json, otherwise just file contents
if(!in_array('HTTP/1.1 404 Not Found', $result['headers']))
return $result['body'];
else {
$result_body = json_decode($result['body'], true);
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function read($file, $rev=NUll, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files/';
$params = array();
if ($rev) $params['rev'] = $rev;
$result = $this->doOAuthCall($url,'GET',$params, $type, $file);
// if file not found, response is json, otherwise just file contents
if(!in_array('HTTP/1.1 404 Not Found', $result['headers']))
return $result['body'];
else {
$result_body = json_decode($result['body'], true);
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"read",
"(",
"$",
"file",
",",
"$",
"rev",
"=",
"NUll",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api-content.dropbox.com/1/files/'",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
... | return file content
@param $file
@param null $rev
@param string $type
@return mixed | [
"return",
"file",
"content"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L209-L223 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.exists | public function exists($file, $hidden=false, $rev=NULL, $type='sandbox')
{
return $this->metadata($file, false, true, $hidden, $rev, $type);
} | php | public function exists($file, $hidden=false, $rev=NULL, $type='sandbox')
{
return $this->metadata($file, false, true, $hidden, $rev, $type);
} | [
"public",
"function",
"exists",
"(",
"$",
"file",
",",
"$",
"hidden",
"=",
"false",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"return",
"$",
"this",
"->",
"metadata",
"(",
"$",
"file",
",",
"false",
",",
"true",
... | determine if the file exists
@param $file
@param bool $hidden
@param null $rev
@param string $type
@return mixed | [
"determine",
"if",
"the",
"file",
"exists"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L233-L236 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.listDir | public function listDir($dir='/', $filter=NULL, $hidden=false, $rev=NUll, $type='sandbox')
{
$result = $this->metadata($dir, true, false, $hidden, $rev, $type);
$return = array();
foreach ($result['contents'] as $item) {
$exp = explode('/', $item['path']);
$ext = explode('.', $name = end($exp));
if (!$filter || preg_match($filter, $name))
$return[$name] = array(
'path' => $item['path'],
'filename' => $name,
'extension' => (count($ext) > 1) ? array_pop($ext) : null,
'basename' => implode('.', $ext),
'mtime'=>strtotime($item['modified']),
'size' => $item['bytes'],
'type' => $item['is_dir'] ? 'dir' : 'file',
);
}
return $return;
} | php | public function listDir($dir='/', $filter=NULL, $hidden=false, $rev=NUll, $type='sandbox')
{
$result = $this->metadata($dir, true, false, $hidden, $rev, $type);
$return = array();
foreach ($result['contents'] as $item) {
$exp = explode('/', $item['path']);
$ext = explode('.', $name = end($exp));
if (!$filter || preg_match($filter, $name))
$return[$name] = array(
'path' => $item['path'],
'filename' => $name,
'extension' => (count($ext) > 1) ? array_pop($ext) : null,
'basename' => implode('.', $ext),
'mtime'=>strtotime($item['modified']),
'size' => $item['bytes'],
'type' => $item['is_dir'] ? 'dir' : 'file',
);
}
return $return;
} | [
"public",
"function",
"listDir",
"(",
"$",
"dir",
"=",
"'/'",
",",
"$",
"filter",
"=",
"NULL",
",",
"$",
"hidden",
"=",
"false",
",",
"$",
"rev",
"=",
"NUll",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
... | list directory contents
@param string $dir
@param string $filter
@param bool $hidden
@param null $rev
@param string $type
@return bool|mixed | [
"list",
"directory",
"contents"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L247-L266 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.fileInfo | public function fileInfo($file, $rev=NUll, $type='sandbox')
{
return $this->metadata($file,false,false,true,$rev,$type);
} | php | public function fileInfo($file, $rev=NUll, $type='sandbox')
{
return $this->metadata($file,false,false,true,$rev,$type);
} | [
"public",
"function",
"fileInfo",
"(",
"$",
"file",
",",
"$",
"rev",
"=",
"NUll",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"return",
"$",
"this",
"->",
"metadata",
"(",
"$",
"file",
",",
"false",
",",
"false",
",",
"true",
",",
"$",
"rev",
"... | get file information
@param $file
@param null $rev
@param string $type
@return bool|mixed | [
"get",
"file",
"information"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L275-L278 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.metadata | public function metadata($file, $list=true, $existCheck=false,
$hidden=false, $rev=NULL, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/metadata/';
$params = array();
$params['list'] = $list;
if ($rev) $params['rev'] = $rev;
if ($list) $params['include_deleted'] = 'false';
$result = $this->doOAuthCall($url, 'GET', $params, $type,$file);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
if($existCheck) {
if(array_key_exists('is_deleted',$result_body) && $result_body['is_deleted'])
return ($hidden) ? true : false;
else return true;
}
else return $result_body;
} else {
if($existCheck) return false;
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function metadata($file, $list=true, $existCheck=false,
$hidden=false, $rev=NULL, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/metadata/';
$params = array();
$params['list'] = $list;
if ($rev) $params['rev'] = $rev;
if ($list) $params['include_deleted'] = 'false';
$result = $this->doOAuthCall($url, 'GET', $params, $type,$file);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
if($existCheck) {
if(array_key_exists('is_deleted',$result_body) && $result_body['is_deleted'])
return ($hidden) ? true : false;
else return true;
}
else return $result_body;
} else {
if($existCheck) return false;
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"metadata",
"(",
"$",
"file",
",",
"$",
"list",
"=",
"true",
",",
"$",
"existCheck",
"=",
"false",
",",
"$",
"hidden",
"=",
"false",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"="... | perform meta request
@param string $file full file pathname
@param bool $list include file list, if $file is a dir
@param bool $existCheck return bool instead of json or error
@param bool $hidden include deleted files
@param null $rev select file version
@param string $type storage type [sandbox|dropbox]
@return bool|mixed | [
"perform",
"meta",
"request"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L290-L312 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.write | public function write($file, $content, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files_put/';
$result = $this->doOAuthCall($url,'PUT',null,$type,$file,$content);
$result_body = json_decode($result['body'],true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function write($file, $content, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files_put/';
$result = $this->doOAuthCall($url,'PUT',null,$type,$file,$content);
$result_body = json_decode($result['body'],true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"write",
"(",
"$",
"file",
",",
"$",
"content",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api-content.dropbox.com/1/files_put/'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url... | write file content
@param $file file path
@param $content file content
@param string $type sandbox or dropbox
@return mixed | [
"write",
"file",
"content"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L321-L332 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.delete | public function delete($file, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/delete';
$result = $this->doOAuthCall($url,'POST',array('path' => $file),$type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function delete($file, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/delete';
$result = $this->doOAuthCall($url,'POST',array('path' => $file),$type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"delete",
"(",
"$",
"file",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/fileops/delete'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url",
",",
"'POST'",
",",
... | delete a file or dir
@param $file
@param string $type
@return mixed | [
"delete",
"a",
"file",
"or",
"dir"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L340-L351 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.move | public function move($from, $to, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/move';
$params = array('from_path' => $from,'to_path'=>$to);
$result = $this->doOAuthCall($url, 'POST', $params, $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function move($from, $to, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/move';
$params = array('from_path' => $from,'to_path'=>$to);
$result = $this->doOAuthCall($url, 'POST', $params, $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"move",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/fileops/move'",
";",
"$",
"params",
"=",
"array",
"(",
"'from_path'",
"=>",
"$",
"from",
",",
"'to_... | rename a file or directory
@param $from
@param $to
@param string $type
@return mixed | [
"rename",
"a",
"file",
"or",
"directory"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L360-L372 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.modified | public function modified($file, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($file, false, false, true, $rev, $type);
return strtotime($result['modified']);
} | php | public function modified($file, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($file, false, false, true, $rev, $type);
return strtotime($result['modified']);
} | [
"public",
"function",
"modified",
"(",
"$",
"file",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"metadata",
"(",
"$",
"file",
",",
"false",
",",
"false",
",",
"true",
",",
"$"... | get last modified date
@param $file
@param null $rev
@param string $type
@return mixed | [
"get",
"last",
"modified",
"date"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L381-L385 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.isDir | public function isDir($dir, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($dir, false, true, false, $rev, $type);
return (bool)$result;
} | php | public function isDir($dir, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($dir, false, true, false, $rev, $type);
return (bool)$result;
} | [
"public",
"function",
"isDir",
"(",
"$",
"dir",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"metadata",
"(",
"$",
"dir",
",",
"false",
",",
"true",
",",
"false",
",",
"$",
"... | return whether the item is a directory
@param $dir
@param null $rev
@param string $type
@return mixed | [
"return",
"whether",
"the",
"item",
"is",
"a",
"directory"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L407-L411 | train |
ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.createDir | public function createDir($dir, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/create_folder';
$result = $this->doOAuthCall($url, 'POST', array('path'=>$dir), $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function createDir($dir, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/create_folder';
$result = $this->doOAuthCall($url, 'POST', array('path'=>$dir), $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"createDir",
"(",
"$",
"dir",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/fileops/create_folder'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url",
",",
"'POST'",... | create new directory
@param $dir
@param string $type
@return mixed | [
"create",
"new",
"directory"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L419-L430 | train |
ikkez/f3-fal | lib/fal.php | FAL.instance | static public function instance() {
$f3 = \Base::instance();
$dir = $f3->split($f3->get('UI'));
$localFS = new \FAL\LocalFS($dir[0]);
return new self($localFS);
} | php | static public function instance() {
$f3 = \Base::instance();
$dir = $f3->split($f3->get('UI'));
$localFS = new \FAL\LocalFS($dir[0]);
return new self($localFS);
} | [
"static",
"public",
"function",
"instance",
"(",
")",
"{",
"$",
"f3",
"=",
"\\",
"Base",
"::",
"instance",
"(",
")",
";",
"$",
"dir",
"=",
"$",
"f3",
"->",
"split",
"(",
"$",
"f3",
"->",
"get",
"(",
"'UI'",
")",
")",
";",
"$",
"localFS",
"=",
... | create FAL on local filesystem as prefab default
@return mixed | [
"create",
"FAL",
"on",
"local",
"filesystem",
"as",
"prefab",
"default"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L57-L62 | train |
ikkez/f3-fal | lib/fal.php | FAL.load | public function load($file,$ttl = 0)
{
$this->reset();
$cache = \Cache::instance();
$this->file = $file;
$this->changed = false;
$this->ttl = $ttl;
$cacheHash = $this->getCacheHash($file);
if ($this->f3->get('CACHE') && $ttl && ($cached = $cache->exists(
$cacheHash,$content)) && $cached[0] + $ttl > microtime(TRUE)
) {
// load from cache
$this->content = $content;
$this->meta = $this->metaHandle->load($file,$ttl);
} elseif ($this->fs->exists($file)) {
// load from FS
$this->meta = $this->metaHandle->load($file,$ttl);
// if caching is on, save content to cache backend, otherwise it gets lazy loaded
if ($this->f3->get('CACHE') && $ttl) {
$this->content = $this->fs->read($file);
$cache->set($cacheHash, $this->content, $ttl);
}
}
} | php | public function load($file,$ttl = 0)
{
$this->reset();
$cache = \Cache::instance();
$this->file = $file;
$this->changed = false;
$this->ttl = $ttl;
$cacheHash = $this->getCacheHash($file);
if ($this->f3->get('CACHE') && $ttl && ($cached = $cache->exists(
$cacheHash,$content)) && $cached[0] + $ttl > microtime(TRUE)
) {
// load from cache
$this->content = $content;
$this->meta = $this->metaHandle->load($file,$ttl);
} elseif ($this->fs->exists($file)) {
// load from FS
$this->meta = $this->metaHandle->load($file,$ttl);
// if caching is on, save content to cache backend, otherwise it gets lazy loaded
if ($this->f3->get('CACHE') && $ttl) {
$this->content = $this->fs->read($file);
$cache->set($cacheHash, $this->content, $ttl);
}
}
} | [
"public",
"function",
"load",
"(",
"$",
"file",
",",
"$",
"ttl",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"cache",
"=",
"\\",
"Cache",
"::",
"instance",
"(",
")",
";",
"$",
"this",
"->",
"file",
"=",
"$",
"file",
";... | loads a file and it's meta data
@param string $file
@param int $ttl | [
"loads",
"a",
"file",
"and",
"it",
"s",
"meta",
"data"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L102-L125 | train |
ikkez/f3-fal | lib/fal.php | FAL.delete | public function delete($file = null)
{
$file = $file ?: $this->file;
if ($this->fs->exists($file))
$this->fs->delete($file);
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if($cache->exists($cacheHash = $this->getCacheHash($file)))
$cache->clear($cacheHash);
}
$this->metaHandle->delete($file);
} | php | public function delete($file = null)
{
$file = $file ?: $this->file;
if ($this->fs->exists($file))
$this->fs->delete($file);
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if($cache->exists($cacheHash = $this->getCacheHash($file)))
$cache->clear($cacheHash);
}
$this->metaHandle->delete($file);
} | [
"public",
"function",
"delete",
"(",
"$",
"file",
"=",
"null",
")",
"{",
"$",
"file",
"=",
"$",
"file",
"?",
":",
"$",
"this",
"->",
"file",
";",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"file",
")",
")",
"$",
"this",
"->... | delete a file and it's meta data
@param null $file | [
"delete",
"a",
"file",
"and",
"it",
"s",
"meta",
"data"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L146-L157 | train |
ikkez/f3-fal | lib/fal.php | FAL.& | public function &get($key)
{
$out = ($this->exists($key)) ? $this->meta[$key] : false;
return $out;
} | php | public function &get($key)
{
$out = ($this->exists($key)) ? $this->meta[$key] : false;
return $out;
} | [
"public",
"function",
"&",
"get",
"(",
"$",
"key",
")",
"{",
"$",
"out",
"=",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"key",
")",
")",
"?",
"$",
"this",
"->",
"meta",
"[",
"$",
"key",
"]",
":",
"false",
";",
"return",
"$",
"out",
";",
"... | get meta data field
@param $key
@return bool | [
"get",
"meta",
"data",
"field"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L182-L186 | train |
ikkez/f3-fal | lib/fal.php | FAL.exists | public function exists($key)
{
if(empty($this->meta)) return false;
return array_key_exists($key, $this->meta);
} | php | public function exists($key)
{
if(empty($this->meta)) return false;
return array_key_exists($key, $this->meta);
} | [
"public",
"function",
"exists",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"meta",
")",
")",
"return",
"false",
";",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"meta",
")",
";",
"}"
] | check whether meta field exists
@param $key
@return bool | [
"check",
"whether",
"meta",
"field",
"exists"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L204-L208 | train |
ikkez/f3-fal | lib/fal.php | FAL.reset | public function reset()
{
$this->meta = false;
$this->file = false;
$this->content = false;
$this->changed = false;
$this->ttl = 0;
$this->cacheHash = null;
} | php | public function reset()
{
$this->meta = false;
$this->file = false;
$this->content = false;
$this->changed = false;
$this->ttl = 0;
$this->cacheHash = null;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"meta",
"=",
"false",
";",
"$",
"this",
"->",
"file",
"=",
"false",
";",
"$",
"this",
"->",
"content",
"=",
"false",
";",
"$",
"this",
"->",
"changed",
"=",
"false",
";",
"$",
"this... | free the layer of loaded data | [
"free",
"the",
"layer",
"of",
"loaded",
"data"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L222-L230 | train |
ikkez/f3-fal | lib/fal.php | FAL.getContent | public function getContent()
{
if(!empty($this->content))
return $this->content;
elseif ($this->fs->exists($this->file)) {
$this->content = $this->fs->read($this->file);
return $this->content;
} else
return false;
} | php | public function getContent()
{
if(!empty($this->content))
return $this->content;
elseif ($this->fs->exists($this->file)) {
$this->content = $this->fs->read($this->file);
return $this->content;
} else
return false;
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"content",
")",
")",
"return",
"$",
"this",
"->",
"content",
";",
"elseif",
"(",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"this",
"->",
... | lazy load file contents
@return mixed|bool | [
"lazy",
"load",
"file",
"contents"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L236-L245 | train |
ikkez/f3-fal | lib/fal.php | FAL.getFileStream | public function getFileStream() {
$stream = new \FAL\FileStream();
$pt = $stream->getProtocolName();
file_put_contents($path = $pt.'://'.$this->file,$this->getContent());
return $path;
} | php | public function getFileStream() {
$stream = new \FAL\FileStream();
$pt = $stream->getProtocolName();
file_put_contents($path = $pt.'://'.$this->file,$this->getContent());
return $path;
} | [
"public",
"function",
"getFileStream",
"(",
")",
"{",
"$",
"stream",
"=",
"new",
"\\",
"FAL",
"\\",
"FileStream",
"(",
")",
";",
"$",
"pt",
"=",
"$",
"stream",
"->",
"getProtocolName",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"path",
"=",
"$",
"... | return file stream path
@return string | [
"return",
"file",
"stream",
"path"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal.php#L261-L266 | train |
raoul2000/yii2-bootswatch-asset | BootswatchAsset.php | BootswatchAsset.init | public function init()
{
if ( self::$theme != null) {
if ( ! is_string(self::$theme) ) {
throw new InvalidConfigException('No theme Bootswatch configured : set BootswatchAsset::$theme to the theme name you want to use');
}
$this->css = [
strtolower(self::$theme).'/bootstrap'.( YII_ENV_DEV ? '.css' : '.min.css' )
];
// optimized asset publication : only publish bootswatch theme folders and font folder.
$this->publishOptions['beforeCopy'] = function ($from, $to) {
if ( is_dir($from)) {
$name = pathinfo($from,PATHINFO_BASENAME);
return ! in_array($name, ['2','api','assets','bower_components','tests','help','global','default']);
} else {
$ext = pathinfo($from,PATHINFO_EXTENSION);
return in_array($ext,['css','eot','svg','ttf','woff','woff2']);
}
};
}
parent::init();
} | php | public function init()
{
if ( self::$theme != null) {
if ( ! is_string(self::$theme) ) {
throw new InvalidConfigException('No theme Bootswatch configured : set BootswatchAsset::$theme to the theme name you want to use');
}
$this->css = [
strtolower(self::$theme).'/bootstrap'.( YII_ENV_DEV ? '.css' : '.min.css' )
];
// optimized asset publication : only publish bootswatch theme folders and font folder.
$this->publishOptions['beforeCopy'] = function ($from, $to) {
if ( is_dir($from)) {
$name = pathinfo($from,PATHINFO_BASENAME);
return ! in_array($name, ['2','api','assets','bower_components','tests','help','global','default']);
} else {
$ext = pathinfo($from,PATHINFO_EXTENSION);
return in_array($ext,['css','eot','svg','ttf','woff','woff2']);
}
};
}
parent::init();
} | [
"public",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"theme",
"!=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"self",
"::",
"$",
"theme",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"'No theme Bootswatc... | Initialize the class properties depending on the current active theme.
When debug mode is disabled, the minified version of the css is used.
@see \yii\web\AssetBundle::init() | [
"Initialize",
"the",
"class",
"properties",
"depending",
"on",
"the",
"current",
"active",
"theme",
"."
] | 39d89d94d892c0162334a5927a308f781e075da1 | https://github.com/raoul2000/yii2-bootswatch-asset/blob/39d89d94d892c0162334a5927a308f781e075da1/BootswatchAsset.php#L36-L59 | train |
raoul2000/yii2-bootswatch-asset | BootswatchAsset.php | BootswatchAsset.isSupportedTheme | static function isSupportedTheme($theme)
{
if (! is_string($theme) || empty($theme)) {
throw new InvalidCallException('Invalid theme value : empty or null value');
}
return file_exists(Yii::getAlias(BootswatchAsset::VENDOR_ALIAS . '/' . strtolower($theme) . '/bootstrap.min.css'));
} | php | static function isSupportedTheme($theme)
{
if (! is_string($theme) || empty($theme)) {
throw new InvalidCallException('Invalid theme value : empty or null value');
}
return file_exists(Yii::getAlias(BootswatchAsset::VENDOR_ALIAS . '/' . strtolower($theme) . '/bootstrap.min.css'));
} | [
"static",
"function",
"isSupportedTheme",
"(",
"$",
"theme",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"theme",
")",
"||",
"empty",
"(",
"$",
"theme",
")",
")",
"{",
"throw",
"new",
"InvalidCallException",
"(",
"'Invalid theme value : empty or null valu... | Chekcs if a theme is a valid bootswatch theme.
This basic method assumes the $theme name passed as argument is an existing
subfolder of the vendor alias folder (@vendor/thomaspark/bootswatch) that contains
the file 'bootstrap.min.css'. If this condition is not true, the theme is invalid.
@param string $theme the theme name to test
@return boolean TRUE if $theme is a valid bootswatch theme, FALSE otherwise | [
"Chekcs",
"if",
"a",
"theme",
"is",
"a",
"valid",
"bootswatch",
"theme",
"."
] | 39d89d94d892c0162334a5927a308f781e075da1 | https://github.com/raoul2000/yii2-bootswatch-asset/blob/39d89d94d892c0162334a5927a308f781e075da1/BootswatchAsset.php#L71-L77 | train |
gpslab/domain-event | src/Aggregator/AggregateEventsRaiseInSelfTrait.php | AggregateEventsRaiseInSelfTrait.eventHandlerName | protected function eventHandlerName(Event $event)
{
$class = get_class($event);
if ('Event' === substr($class, -5)) {
$class = substr($class, 0, -5);
}
$class = str_replace('_', '\\', $class); // convert names for classes not in namespace
$parts = explode('\\', $class);
return 'on'.end($parts);
} | php | protected function eventHandlerName(Event $event)
{
$class = get_class($event);
if ('Event' === substr($class, -5)) {
$class = substr($class, 0, -5);
}
$class = str_replace('_', '\\', $class); // convert names for classes not in namespace
$parts = explode('\\', $class);
return 'on'.end($parts);
} | [
"protected",
"function",
"eventHandlerName",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"event",
")",
";",
"if",
"(",
"'Event'",
"===",
"substr",
"(",
"$",
"class",
",",
"-",
"5",
")",
")",
"{",
"$",
"class",
"=... | Get handler method name from event.
Override this method if you want to change algorithm to generate the handler method name.
@param Event $event
@return string | [
"Get",
"handler",
"method",
"name",
"from",
"event",
"."
] | 3db48d8f4b85c8da14aa2ff113fe79aa021394b4 | https://github.com/gpslab/domain-event/blob/3db48d8f4b85c8da14aa2ff113fe79aa021394b4/src/Aggregator/AggregateEventsRaiseInSelfTrait.php#L63-L75 | train |
tavo1987/ec-validador-cedula-ruc | src/ValidadorEc.php | ValidadorEc.validarRucSociedadPrivada | public function validarRucSociedadPrivada($numero = '')
{
// fuerzo parametro de entrada a string
$numero = (string) $numero;
// borro por si acaso errores de llamadas anteriores.
$this->setError('');
// validaciones
try {
$this->validarInicial($numero, '13');
$this->validarCodigoProvincia(substr($numero, 0, 2));
$this->validarTercerDigito($numero[2], 'ruc_privada');
$this->validarCodigoEstablecimiento(substr($numero, 10, 3));
$this->algoritmoModulo11(substr($numero, 0, 9), $numero[9], 'ruc_privada');
} catch (Exception $e) {
$this->setError($e->getMessage());
return false;
}
return true;
} | php | public function validarRucSociedadPrivada($numero = '')
{
// fuerzo parametro de entrada a string
$numero = (string) $numero;
// borro por si acaso errores de llamadas anteriores.
$this->setError('');
// validaciones
try {
$this->validarInicial($numero, '13');
$this->validarCodigoProvincia(substr($numero, 0, 2));
$this->validarTercerDigito($numero[2], 'ruc_privada');
$this->validarCodigoEstablecimiento(substr($numero, 10, 3));
$this->algoritmoModulo11(substr($numero, 0, 9), $numero[9], 'ruc_privada');
} catch (Exception $e) {
$this->setError($e->getMessage());
return false;
}
return true;
} | [
"public",
"function",
"validarRucSociedadPrivada",
"(",
"$",
"numero",
"=",
"''",
")",
"{",
"// fuerzo parametro de entrada a string",
"$",
"numero",
"=",
"(",
"string",
")",
"$",
"numero",
";",
"// borro por si acaso errores de llamadas anteriores.",
"$",
"this",
"->",... | Validar RUC sociedad privada.
@param string $numero Número de RUC sociedad privada
@return bool | [
"Validar",
"RUC",
"sociedad",
"privada",
"."
] | 379b50bc5dfda20d935df2bdd3c0de94e4fc024e | https://github.com/tavo1987/ec-validador-cedula-ruc/blob/379b50bc5dfda20d935df2bdd3c0de94e4fc024e/src/ValidadorEc.php#L96-L118 | train |
gpslab/domain-event | src/Bus/ListenerLocatedEventBus.php | ListenerLocatedEventBus.publish | public function publish(Event $event)
{
foreach ($this->locator->listenersOfEvent($event) as $listener) {
call_user_func($listener, $event);
}
} | php | public function publish(Event $event)
{
foreach ($this->locator->listenersOfEvent($event) as $listener) {
call_user_func($listener, $event);
}
} | [
"public",
"function",
"publish",
"(",
"Event",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"locator",
"->",
"listenersOfEvent",
"(",
"$",
"event",
")",
"as",
"$",
"listener",
")",
"{",
"call_user_func",
"(",
"$",
"listener",
",",
"$",
"e... | Publishes the event to every listener that wants to.
@param Event $event | [
"Publishes",
"the",
"event",
"to",
"every",
"listener",
"that",
"wants",
"to",
"."
] | 3db48d8f4b85c8da14aa2ff113fe79aa021394b4 | https://github.com/gpslab/domain-event/blob/3db48d8f4b85c8da14aa2ff113fe79aa021394b4/src/Bus/ListenerLocatedEventBus.php#L36-L41 | train |
gpslab/domain-event | src/Queue/Subscribe/PredisSubscribeEventQueue.php | PredisSubscribeEventQueue.subscribe | public function subscribe(callable $handler)
{
$this->handlers[] = $handler;
// laze subscribe
if (!$this->subscribed) {
$this->client->subscribe($this->queue_name, function ($message) {
$this->handle($message);
});
$this->subscribed = true;
}
} | php | public function subscribe(callable $handler)
{
$this->handlers[] = $handler;
// laze subscribe
if (!$this->subscribed) {
$this->client->subscribe($this->queue_name, function ($message) {
$this->handle($message);
});
$this->subscribed = true;
}
} | [
"public",
"function",
"subscribe",
"(",
"callable",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"handlers",
"[",
"]",
"=",
"$",
"handler",
";",
"// laze subscribe",
"if",
"(",
"!",
"$",
"this",
"->",
"subscribed",
")",
"{",
"$",
"this",
"->",
"client"... | Subscribe on event queue.
@param callable $handler | [
"Subscribe",
"on",
"event",
"queue",
"."
] | 3db48d8f4b85c8da14aa2ff113fe79aa021394b4 | https://github.com/gpslab/domain-event/blob/3db48d8f4b85c8da14aa2ff113fe79aa021394b4/src/Queue/Subscribe/PredisSubscribeEventQueue.php#L88-L99 | train |
gpslab/domain-event | src/Queue/Subscribe/PredisSubscribeEventQueue.php | PredisSubscribeEventQueue.unsubscribe | public function unsubscribe(callable $handler)
{
$index = array_search($handler, $this->handlers);
if ($index === false) {
return false;
}
unset($this->handlers[$index]);
return true;
} | php | public function unsubscribe(callable $handler)
{
$index = array_search($handler, $this->handlers);
if ($index === false) {
return false;
}
unset($this->handlers[$index]);
return true;
} | [
"public",
"function",
"unsubscribe",
"(",
"callable",
"$",
"handler",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"handler",
",",
"$",
"this",
"->",
"handlers",
")",
";",
"if",
"(",
"$",
"index",
"===",
"false",
")",
"{",
"return",
"false",
... | Unsubscribe on event queue.
@param callable $handler
@return bool | [
"Unsubscribe",
"on",
"event",
"queue",
"."
] | 3db48d8f4b85c8da14aa2ff113fe79aa021394b4 | https://github.com/gpslab/domain-event/blob/3db48d8f4b85c8da14aa2ff113fe79aa021394b4/src/Queue/Subscribe/PredisSubscribeEventQueue.php#L108-L119 | train |
sjaakp/yii2-illustrated-behavior | Illustration.php | Illustration.deleteFiles | public function deleteFiles() {
$fileName = $this->_model->{$this->attribute};
if (! empty($fileName)) {
$size = $this->cropSize;
if ($this->sizeSteps && $size > 0) {
$minSize = $size >> ($this->sizeSteps - 1);
while ($size >= $minSize) {
$path = $this->imgBaseDir . DIRECTORY_SEPARATOR . $size . DIRECTORY_SEPARATOR . $fileName;
if (file_exists($path)) unlink($path);
$size >>= 1;
}
}
else {
$path = $this->imgBaseDir . DIRECTORY_SEPARATOR . $fileName;
if (file_exists($path)) unlink($path);
}
$this->_model->{$this->attribute} = null;
if (! is_numeric($this->aspectRatio)) $this->_model->{$this->aspectRatio} = null;
}
} | php | public function deleteFiles() {
$fileName = $this->_model->{$this->attribute};
if (! empty($fileName)) {
$size = $this->cropSize;
if ($this->sizeSteps && $size > 0) {
$minSize = $size >> ($this->sizeSteps - 1);
while ($size >= $minSize) {
$path = $this->imgBaseDir . DIRECTORY_SEPARATOR . $size . DIRECTORY_SEPARATOR . $fileName;
if (file_exists($path)) unlink($path);
$size >>= 1;
}
}
else {
$path = $this->imgBaseDir . DIRECTORY_SEPARATOR . $fileName;
if (file_exists($path)) unlink($path);
}
$this->_model->{$this->attribute} = null;
if (! is_numeric($this->aspectRatio)) $this->_model->{$this->aspectRatio} = null;
}
} | [
"public",
"function",
"deleteFiles",
"(",
")",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"_model",
"->",
"{",
"$",
"this",
"->",
"attribute",
"}",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fileName",
")",
")",
"{",
"$",
"size",
"=",
"$",
"this... | Delete image files and clear imgAttribute | [
"Delete",
"image",
"files",
"and",
"clear",
"imgAttribute"
] | 940d93fd84d008bacd4a0716c773e442a6299724 | https://github.com/sjaakp/yii2-illustrated-behavior/blob/940d93fd84d008bacd4a0716c773e442a6299724/Illustration.php#L237-L259 | train |
jralph/Twig-Markdown | src/Node.php | Node.compile | public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this)
->write('ob_start();' . PHP_EOL)
->subcompile($this->getNode('value'))
->write('$content = ob_get_clean();' . PHP_EOL)
->write('preg_match("/^\s*/", $content, $matches);' . PHP_EOL)
->write('$lines = explode("\n", $content);'.PHP_EOL)
->write('$content = preg_replace(\'/^\' . $matches[0]. \'/\', "", $lines);' . PHP_EOL)
->write('$content = implode("\n", $content);' . PHP_EOL)
->write('echo $this->env->getTags()["markdown"]
->getMarkdown()
->parse($content);
'.PHP_EOL);
} | php | public function compile(Twig_Compiler $compiler)
{
$compiler->addDebugInfo($this)
->write('ob_start();' . PHP_EOL)
->subcompile($this->getNode('value'))
->write('$content = ob_get_clean();' . PHP_EOL)
->write('preg_match("/^\s*/", $content, $matches);' . PHP_EOL)
->write('$lines = explode("\n", $content);'.PHP_EOL)
->write('$content = preg_replace(\'/^\' . $matches[0]. \'/\', "", $lines);' . PHP_EOL)
->write('$content = implode("\n", $content);' . PHP_EOL)
->write('echo $this->env->getTags()["markdown"]
->getMarkdown()
->parse($content);
'.PHP_EOL);
} | [
"public",
"function",
"compile",
"(",
"Twig_Compiler",
"$",
"compiler",
")",
"{",
"$",
"compiler",
"->",
"addDebugInfo",
"(",
"$",
"this",
")",
"->",
"write",
"(",
"'ob_start();'",
".",
"PHP_EOL",
")",
"->",
"subcompile",
"(",
"$",
"this",
"->",
"getNode",... | Compile the provided markdown into html.
@param Twig_Compiler $compiler
@return void | [
"Compile",
"the",
"provided",
"markdown",
"into",
"html",
"."
] | 3f4bb7cfdbde05712fc861c4d96ff8f5e47501fd | https://github.com/jralph/Twig-Markdown/blob/3f4bb7cfdbde05712fc861c4d96ff8f5e47501fd/src/Node.php#L25-L39 | train |
jralph/Twig-Markdown | src/TokenParser.php | TokenParser.parse | public function parse(Twig_Token $token)
{
$line = $token->getLine();
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(function(Twig_Token $token)
{
return $token->test('endmarkdown');
}, true);
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
return new Node($body, $line, $this->getTag());
} | php | public function parse(Twig_Token $token)
{
$line = $token->getLine();
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
$body = $this->parser->subparse(function(Twig_Token $token)
{
return $token->test('endmarkdown');
}, true);
$this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE);
return new Node($body, $line, $this->getTag());
} | [
"public",
"function",
"parse",
"(",
"Twig_Token",
"$",
"token",
")",
"{",
"$",
"line",
"=",
"$",
"token",
"->",
"getLine",
"(",
")",
";",
"$",
"this",
"->",
"parser",
"->",
"getStream",
"(",
")",
"->",
"expect",
"(",
"Twig_Token",
"::",
"BLOCK_END_TYPE... | Parse the twig tag.
@param Twig_Token $token
@return Node | [
"Parse",
"the",
"twig",
"tag",
"."
] | 3f4bb7cfdbde05712fc861c4d96ff8f5e47501fd | https://github.com/jralph/Twig-Markdown/blob/3f4bb7cfdbde05712fc861c4d96ff8f5e47501fd/src/TokenParser.php#L27-L41 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.getResponseStructure | public function getResponseStructure($success = false, $payload = null, $message = '', $debug = null)
{
if (isset($debug)) {
$data = [
'success' => $success,
'message' => $message,
'payload' => $payload,
'debug' => $debug
];
} else {
$data = [
'success' => $success,
'message' => $message,
'payload' => $payload
];
}
return $data;
} | php | public function getResponseStructure($success = false, $payload = null, $message = '', $debug = null)
{
if (isset($debug)) {
$data = [
'success' => $success,
'message' => $message,
'payload' => $payload,
'debug' => $debug
];
} else {
$data = [
'success' => $success,
'message' => $message,
'payload' => $payload
];
}
return $data;
} | [
"public",
"function",
"getResponseStructure",
"(",
"$",
"success",
"=",
"false",
",",
"$",
"payload",
"=",
"null",
",",
"$",
"message",
"=",
"''",
",",
"$",
"debug",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"debug",
")",
")",
"{",
"$",
... | create API structure.
@param boolean $success
@param null $payload
@param string $message
@param null $debug
@return object | [
"create",
"API",
"structure",
"."
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L99-L116 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondWithData | public function respondWithData(array $data)
{
$responseData = $this->getResponseStructure(true, $data, '');
$response = new JsonResponse($responseData, $this->getStatusCode(), $this->getHeaders());
return $response;
} | php | public function respondWithData(array $data)
{
$responseData = $this->getResponseStructure(true, $data, '');
$response = new JsonResponse($responseData, $this->getStatusCode(), $this->getHeaders());
return $response;
} | [
"public",
"function",
"respondWithData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"responseData",
"=",
"$",
"this",
"->",
"getResponseStructure",
"(",
"true",
",",
"$",
"data",
",",
"''",
")",
";",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
"$",
... | Responds with data
@param array $data
@return JsonResponse | [
"Responds",
"with",
"data"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L125-L131 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondWithMessage | public function respondWithMessage($message = "Ok")
{
$data = $this->getResponseStructure(true, null, $message);
return $this->respond($data);
} | php | public function respondWithMessage($message = "Ok")
{
$data = $this->getResponseStructure(true, null, $message);
return $this->respond($data);
} | [
"public",
"function",
"respondWithMessage",
"(",
"$",
"message",
"=",
"\"Ok\"",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getResponseStructure",
"(",
"true",
",",
"null",
",",
"$",
"message",
")",
";",
"return",
"$",
"this",
"->",
"respond",
"(",
... | Use this for responding with messages.
@param string $message
@return JsonResponse | [
"Use",
"this",
"for",
"responding",
"with",
"messages",
"."
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L140-L145 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondWithMessageAndPayload | public function respondWithMessageAndPayload($payload = null, $message = "Ok")
{
$data = $this->getResponseStructure(true, $payload, $message);
$reponse = $this->respond($data);
return $reponse;
} | php | public function respondWithMessageAndPayload($payload = null, $message = "Ok")
{
$data = $this->getResponseStructure(true, $payload, $message);
$reponse = $this->respond($data);
return $reponse;
} | [
"public",
"function",
"respondWithMessageAndPayload",
"(",
"$",
"payload",
"=",
"null",
",",
"$",
"message",
"=",
"\"Ok\"",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getResponseStructure",
"(",
"true",
",",
"$",
"payload",
",",
"$",
"message",
")",
... | Use this for responding with messages and payload.
@param null $payload
@param string $message
@return JsonResponse | [
"Use",
"this",
"for",
"responding",
"with",
"messages",
"and",
"payload",
"."
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L155-L160 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondWithError | public function respondWithError($message = "Error", $e = null, $data = null)
{
$response = null;
if (\App::environment('local', 'staging') && isset($e)) {
$debug_message = $e;
$data = $this->getResponseStructure(false, $data, $message, $debug_message);
} else {
$data = $this->getResponseStructure(false, $data, $message);
}
$response = $this->respond($data);
return $response;
} | php | public function respondWithError($message = "Error", $e = null, $data = null)
{
$response = null;
if (\App::environment('local', 'staging') && isset($e)) {
$debug_message = $e;
$data = $this->getResponseStructure(false, $data, $message, $debug_message);
} else {
$data = $this->getResponseStructure(false, $data, $message);
}
$response = $this->respond($data);
return $response;
} | [
"public",
"function",
"respondWithError",
"(",
"$",
"message",
"=",
"\"Error\"",
",",
"$",
"e",
"=",
"null",
",",
"$",
"data",
"=",
"null",
")",
"{",
"$",
"response",
"=",
"null",
";",
"if",
"(",
"\\",
"App",
"::",
"environment",
"(",
"'local'",
",",... | Responds with error
@param string $message
@param null $e
@param null $data
@return JsonResponse|null | [
"Responds",
"with",
"error"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L171-L184 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondCreatedWithPayload | public function respondCreatedWithPayload($payload = null, $message = "Created")
{
$reponse = $this->setStatusCode(ResponseHTTP::HTTP_CREATED)
->respondWithMessageAndPayload($payload, $message);
return $reponse;
} | php | public function respondCreatedWithPayload($payload = null, $message = "Created")
{
$reponse = $this->setStatusCode(ResponseHTTP::HTTP_CREATED)
->respondWithMessageAndPayload($payload, $message);
return $reponse;
} | [
"public",
"function",
"respondCreatedWithPayload",
"(",
"$",
"payload",
"=",
"null",
",",
"$",
"message",
"=",
"\"Created\"",
")",
"{",
"$",
"reponse",
"=",
"$",
"this",
"->",
"setStatusCode",
"(",
"ResponseHTTP",
"::",
"HTTP_CREATED",
")",
"->",
"respondWithM... | Respond created with the payload
@param null $payload
@param string $message
@return mixed | [
"Respond",
"created",
"with",
"the",
"payload"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L221-L227 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondUpdatedWithPayload | public function respondUpdatedWithPayload($payload = null, $message = "Updated")
{
$reponse = $this->setStatusCode(ResponseHTTP::HTTP_ACCEPTED)
->respondWithMessageAndPayload($payload, $message);
return $reponse;
} | php | public function respondUpdatedWithPayload($payload = null, $message = "Updated")
{
$reponse = $this->setStatusCode(ResponseHTTP::HTTP_ACCEPTED)
->respondWithMessageAndPayload($payload, $message);
return $reponse;
} | [
"public",
"function",
"respondUpdatedWithPayload",
"(",
"$",
"payload",
"=",
"null",
",",
"$",
"message",
"=",
"\"Updated\"",
")",
"{",
"$",
"reponse",
"=",
"$",
"this",
"->",
"setStatusCode",
"(",
"ResponseHTTP",
"::",
"HTTP_ACCEPTED",
")",
"->",
"respondWith... | Respond is updated wih payload
@param null $payload
@param string $message
@return mixed | [
"Respond",
"is",
"updated",
"wih",
"payload"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L251-L256 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondValidationError | public function respondValidationError($message = "Validation Error", $data = null)
{
return $this->setStatusCode(ResponseHTTP::HTTP_UNPROCESSABLE_ENTITY)
->respondWithError($message, null, $data);
} | php | public function respondValidationError($message = "Validation Error", $data = null)
{
return $this->setStatusCode(ResponseHTTP::HTTP_UNPROCESSABLE_ENTITY)
->respondWithError($message, null, $data);
} | [
"public",
"function",
"respondValidationError",
"(",
"$",
"message",
"=",
"\"Validation Error\"",
",",
"$",
"data",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"setStatusCode",
"(",
"ResponseHTTP",
"::",
"HTTP_UNPROCESSABLE_ENTITY",
")",
"->",
"respondWith... | Use this when response validation error
@param string $message
@param null $data
@return mixed | [
"Use",
"this",
"when",
"response",
"validation",
"error"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L334-L338 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondResourceConflictWithData | public function respondResourceConflictWithData(
$payload = null,
$message = "Resource Already Exists",
$responseCode = ResponseHTTP::HTTP_CONFLICT
) {
return $this->setStatusCode($responseCode)
->respondWithMessageAndPayload($payload, $message);
} | php | public function respondResourceConflictWithData(
$payload = null,
$message = "Resource Already Exists",
$responseCode = ResponseHTTP::HTTP_CONFLICT
) {
return $this->setStatusCode($responseCode)
->respondWithMessageAndPayload($payload, $message);
} | [
"public",
"function",
"respondResourceConflictWithData",
"(",
"$",
"payload",
"=",
"null",
",",
"$",
"message",
"=",
"\"Resource Already Exists\"",
",",
"$",
"responseCode",
"=",
"ResponseHTTP",
"::",
"HTTP_CONFLICT",
")",
"{",
"return",
"$",
"this",
"->",
"setSta... | Used when response resource conflict with data
@param null $payload
@param string $message
@param int $responseCode
@return mixed | [
"Used",
"when",
"response",
"resource",
"conflict",
"with",
"data"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L417-L424 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.respondWithFile | public function respondWithFile($file, $mime)
{
return (new \Illuminate\Http\Response($file, ResponseHTTP::HTTP_OK))
->header('Content-Type', $mime);
} | php | public function respondWithFile($file, $mime)
{
return (new \Illuminate\Http\Response($file, ResponseHTTP::HTTP_OK))
->header('Content-Type', $mime);
} | [
"public",
"function",
"respondWithFile",
"(",
"$",
"file",
",",
"$",
"mime",
")",
"{",
"return",
"(",
"new",
"\\",
"Illuminate",
"\\",
"Http",
"\\",
"Response",
"(",
"$",
"file",
",",
"ResponseHTTP",
"::",
"HTTP_OK",
")",
")",
"->",
"header",
"(",
"'Co... | Response with file
@param \Illuminate\Contracts\Filesystem\Filesystem $file
@param $mime
@return mixed | [
"Response",
"with",
"file"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L434-L439 | train |
dharmvijay/laravel-api-response | src/APIResponse.php | APIResponse.handleAndResponseException | public function handleAndResponseException(\Exception $ex)
{
$response = '';
switch (true) {
case $ex instanceof \Illuminate\Database\Eloquent\ModelNotFoundException:
$response = $this->respondNotFound('Record not found');
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
$response = $this->respondNotFound("Not found");
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException:
$response = $this->respondForbidden("Access denied");
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
$response = $this->respondBadRequest("Bad request");
break;
case $ex instanceof BadMethodCallException:
$response = $this->respondBadRequest("Bad method Call");
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException:
$response = $this->respondForbidden("Method not found");
break;
case $ex instanceof \Illuminate\Database\QueryException:
$response = $this->respondValidationError("Some thing went wrong with your query", [$ex->getMessage()]);
break;
case $ex instanceof \Illuminate\Http\Exceptions\HttpResponseException:
$response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
break;
case $ex instanceof \Illuminate\Auth\AuthenticationException:
$response = $this->respondUnauthorized("Unauthorized request");
break;
case $ex instanceof \Illuminate\Validation\ValidationException:
$response = $this->respondValidationError("In valid request", [$ex->getMessage()]);
break;
case $ex instanceof NotAcceptableHttpException:
$response = $this->respondUnauthorized("Unauthorized request");
break;
case $ex instanceof \Illuminate\Validation\UnauthorizedException:
$response = $this->respondUnauthorized("Unauthorized request", [$ex->getMessage()]);
break;
case $ex instanceof \Exception:
$response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
break;
}
return $response;
} | php | public function handleAndResponseException(\Exception $ex)
{
$response = '';
switch (true) {
case $ex instanceof \Illuminate\Database\Eloquent\ModelNotFoundException:
$response = $this->respondNotFound('Record not found');
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException:
$response = $this->respondNotFound("Not found");
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException:
$response = $this->respondForbidden("Access denied");
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\BadRequestHttpException:
$response = $this->respondBadRequest("Bad request");
break;
case $ex instanceof BadMethodCallException:
$response = $this->respondBadRequest("Bad method Call");
break;
case $ex instanceof \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException:
$response = $this->respondForbidden("Method not found");
break;
case $ex instanceof \Illuminate\Database\QueryException:
$response = $this->respondValidationError("Some thing went wrong with your query", [$ex->getMessage()]);
break;
case $ex instanceof \Illuminate\Http\Exceptions\HttpResponseException:
$response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
break;
case $ex instanceof \Illuminate\Auth\AuthenticationException:
$response = $this->respondUnauthorized("Unauthorized request");
break;
case $ex instanceof \Illuminate\Validation\ValidationException:
$response = $this->respondValidationError("In valid request", [$ex->getMessage()]);
break;
case $ex instanceof NotAcceptableHttpException:
$response = $this->respondUnauthorized("Unauthorized request");
break;
case $ex instanceof \Illuminate\Validation\UnauthorizedException:
$response = $this->respondUnauthorized("Unauthorized request", [$ex->getMessage()]);
break;
case $ex instanceof \Exception:
$response = $this->respondInternalError("Something went wrong with our system", [$ex->getMessage()]);
break;
}
return $response;
} | [
"public",
"function",
"handleAndResponseException",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"$",
"response",
"=",
"''",
";",
"switch",
"(",
"true",
")",
"{",
"case",
"$",
"ex",
"instanceof",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\"... | handle all type of exceptions
@param \Exception $ex
@return mixed|string | [
"handle",
"all",
"type",
"of",
"exceptions"
] | f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1 | https://github.com/dharmvijay/laravel-api-response/blob/f51ded129bd50fbd33f627d1d9a6dd4d5031bdc1/src/APIResponse.php#L502-L548 | train |
simplito/bn-php | lib/BN.php | BN.iuor | public function iuor(BN $num) {
$this->bi = $this->bi->binaryOr($num->bi);
return $this;
} | php | public function iuor(BN $num) {
$this->bi = $this->bi->binaryOr($num->bi);
return $this;
} | [
"public",
"function",
"iuor",
"(",
"BN",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"bi",
"=",
"$",
"this",
"->",
"bi",
"->",
"binaryOr",
"(",
"$",
"num",
"->",
"bi",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Or `num` with `this` in-place | [
"Or",
"num",
"with",
"this",
"in",
"-",
"place"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L159-L162 | train |
simplito/bn-php | lib/BN.php | BN._or | public function _or(BN $num) {
if( $this->ucmp($num) > 0 )
return $this->_clone()->ior($num);
return $num->_clone()->ior($this);
} | php | public function _or(BN $num) {
if( $this->ucmp($num) > 0 )
return $this->_clone()->ior($num);
return $num->_clone()->ior($this);
} | [
"public",
"function",
"_or",
"(",
"BN",
"$",
"num",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ucmp",
"(",
"$",
"num",
")",
">",
"0",
")",
"return",
"$",
"this",
"->",
"_clone",
"(",
")",
"->",
"ior",
"(",
"$",
"num",
")",
";",
"return",
"$",
... | Or `num` with `this` | [
"Or",
"num",
"with",
"this"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L170-L174 | train |
simplito/bn-php | lib/BN.php | BN.iuand | public function iuand(BN $num) {
$this->bi = $this->bi->binaryAnd($num->bi);
return $this;
} | php | public function iuand(BN $num) {
$this->bi = $this->bi->binaryAnd($num->bi);
return $this;
} | [
"public",
"function",
"iuand",
"(",
"BN",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"bi",
"=",
"$",
"this",
"->",
"bi",
"->",
"binaryAnd",
"(",
"$",
"num",
"->",
"bi",
")",
";",
"return",
"$",
"this",
";",
"}"
] | And `num` with `this` in-place | [
"And",
"num",
"with",
"this",
"in",
"-",
"place"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L183-L186 | train |
simplito/bn-php | lib/BN.php | BN._and | public function _and(BN $num) {
if( $this->ucmp($num) > 0 )
return $this->_clone()->iand($num);
return $num->_clone()->iand($this);
} | php | public function _and(BN $num) {
if( $this->ucmp($num) > 0 )
return $this->_clone()->iand($num);
return $num->_clone()->iand($this);
} | [
"public",
"function",
"_and",
"(",
"BN",
"$",
"num",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ucmp",
"(",
"$",
"num",
")",
">",
"0",
")",
"return",
"$",
"this",
"->",
"_clone",
"(",
")",
"->",
"iand",
"(",
"$",
"num",
")",
";",
"return",
"$",... | And `num` with `this` | [
"And",
"num",
"with",
"this"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L194-L198 | train |
simplito/bn-php | lib/BN.php | BN.iuxor | public function iuxor(BN $num) {
$this->bi = $this->bi->binaryXor($num->bi);
return $this;
} | php | public function iuxor(BN $num) {
$this->bi = $this->bi->binaryXor($num->bi);
return $this;
} | [
"public",
"function",
"iuxor",
"(",
"BN",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"bi",
"=",
"$",
"this",
"->",
"bi",
"->",
"binaryXor",
"(",
"$",
"num",
"->",
"bi",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Xor `num` with `this` in-place | [
"Xor",
"num",
"with",
"this",
"in",
"-",
"place"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L207-L210 | train |
simplito/bn-php | lib/BN.php | BN._xor | public function _xor(BN $num) {
if( $this->ucmp($num) > 0 )
return $this->_clone()->ixor($num);
return $num->_clone()->ixor($this);
} | php | public function _xor(BN $num) {
if( $this->ucmp($num) > 0 )
return $this->_clone()->ixor($num);
return $num->_clone()->ixor($this);
} | [
"public",
"function",
"_xor",
"(",
"BN",
"$",
"num",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ucmp",
"(",
"$",
"num",
")",
">",
"0",
")",
"return",
"$",
"this",
"->",
"_clone",
"(",
")",
"->",
"ixor",
"(",
"$",
"num",
")",
";",
"return",
"$",... | Xor `num` with `this` | [
"Xor",
"num",
"with",
"this"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L218-L222 | train |
simplito/bn-php | lib/BN.php | BN.inotn | public function inotn($width)
{
assert(is_integer($width) && $width >= 0);
$neg = false;
if( $this->isNeg() )
{
$this->negi();
$neg = true;
}
for($i = 0; $i < $width; $i++)
$this->bi = $this->bi->setbit($i, !$this->bi->testbit($i));
return $neg ? $this->negi() : $this;
} | php | public function inotn($width)
{
assert(is_integer($width) && $width >= 0);
$neg = false;
if( $this->isNeg() )
{
$this->negi();
$neg = true;
}
for($i = 0; $i < $width; $i++)
$this->bi = $this->bi->setbit($i, !$this->bi->testbit($i));
return $neg ? $this->negi() : $this;
} | [
"public",
"function",
"inotn",
"(",
"$",
"width",
")",
"{",
"assert",
"(",
"is_integer",
"(",
"$",
"width",
")",
"&&",
"$",
"width",
">=",
"0",
")",
";",
"$",
"neg",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"isNeg",
"(",
")",
")",
"{",
... | Not ``this`` with ``width`` bitwidth | [
"Not",
"this",
"with",
"width",
"bitwidth"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L231-L245 | train |
simplito/bn-php | lib/BN.php | BN.setn | public function setn($bit, $val) {
assert(is_integer($bit) && $bit > 0);
$this->bi = $this->bi->setbit($bit, !!$val);
return $this;
} | php | public function setn($bit, $val) {
assert(is_integer($bit) && $bit > 0);
$this->bi = $this->bi->setbit($bit, !!$val);
return $this;
} | [
"public",
"function",
"setn",
"(",
"$",
"bit",
",",
"$",
"val",
")",
"{",
"assert",
"(",
"is_integer",
"(",
"$",
"bit",
")",
"&&",
"$",
"bit",
">",
"0",
")",
";",
"$",
"this",
"->",
"bi",
"=",
"$",
"this",
"->",
"bi",
"->",
"setbit",
"(",
"$"... | Set `bit` of `this` | [
"Set",
"bit",
"of",
"this"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L252-L256 | train |
simplito/bn-php | lib/BN.php | BN.iadd | public function iadd(BN $num) {
$this->bi = $this->bi->add($num->bi);
return $this;
} | php | public function iadd(BN $num) {
$this->bi = $this->bi->add($num->bi);
return $this;
} | [
"public",
"function",
"iadd",
"(",
"BN",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"bi",
"=",
"$",
"this",
"->",
"bi",
"->",
"add",
"(",
"$",
"num",
"->",
"bi",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add `num` to `this` in-place | [
"Add",
"num",
"to",
"this",
"in",
"-",
"place"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L259-L262 | train |
simplito/bn-php | lib/BN.php | BN.isub | public function isub(BN $num) {
$this->bi = $this->bi->sub($num->bi);
return $this;
} | php | public function isub(BN $num) {
$this->bi = $this->bi->sub($num->bi);
return $this;
} | [
"public",
"function",
"isub",
"(",
"BN",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"bi",
"=",
"$",
"this",
"->",
"bi",
"->",
"sub",
"(",
"$",
"num",
"->",
"bi",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Subtract `num` from `this` in-place | [
"Subtract",
"num",
"from",
"this",
"in",
"-",
"place"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L270-L273 | train |
simplito/bn-php | lib/BN.php | BN.imul | public function imul(BN $num) {
$this->bi = $this->bi->mul($num->bi);
return $this;
} | php | public function imul(BN $num) {
$this->bi = $this->bi->mul($num->bi);
return $this;
} | [
"public",
"function",
"imul",
"(",
"BN",
"$",
"num",
")",
"{",
"$",
"this",
"->",
"bi",
"=",
"$",
"this",
"->",
"bi",
"->",
"mul",
"(",
"$",
"num",
"->",
"bi",
")",
";",
"return",
"$",
"this",
";",
"}"
] | In-place Multiplication | [
"In",
"-",
"place",
"Multiplication"
] | e852fcd27e4acbc32459606d7606e45a85e42465 | https://github.com/simplito/bn-php/blob/e852fcd27e4acbc32459606d7606e45a85e42465/lib/BN.php#L286-L289 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.