repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/File.php
File.create
public static function create($path) { $file = new static($path); if (! is_dir(dirname($path))) { mkdir(dirname($path), 0755, true); } if (! $file->exists()) { touch($path); } return $file; }
php
public static function create($path) { $file = new static($path); if (! is_dir(dirname($path))) { mkdir(dirname($path), 0755, true); } if (! $file->exists()) { touch($path); } return $file; }
[ "public", "static", "function", "create", "(", "$", "path", ")", "{", "$", "file", "=", "new", "static", "(", "$", "path", ")", ";", "if", "(", "!", "is_dir", "(", "dirname", "(", "$", "path", ")", ")", ")", "{", "mkdir", "(", "dirname", "(", "...
Create a new instance, including the file and parent directories. @param $path @return static
[ "Create", "a", "new", "instance", "including", "the", "file", "and", "parent", "directories", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/File.php#L89-L102
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/File.php
File.set
public function set($key, $value, $quote = '') { $this->lines->updateOrAdd(new KeyValue($key, $value, $quote)); return $this; }
php
public function set($key, $value, $quote = '') { $this->lines->updateOrAdd(new KeyValue($key, $value, $quote)); return $this; }
[ "public", "function", "set", "(", "$", "key", ",", "$", "value", ",", "$", "quote", "=", "''", ")", "{", "$", "this", "->", "lines", "->", "updateOrAdd", "(", "new", "KeyValue", "(", "$", "key", ",", "$", "value", ",", "$", "quote", ")", ")", "...
Set a variable definition. @param $key @param $value @param string $quote @return $this
[ "Set", "a", "variable", "definition", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/File.php#L195-L200
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/File.php
File.remove
public function remove($key) { $linesBefore = $this->lineCount(); $this->lines->removeDefinition($key); return $linesBefore - $this->lineCount(); }
php
public function remove($key) { $linesBefore = $this->lineCount(); $this->lines->removeDefinition($key); return $linesBefore - $this->lineCount(); }
[ "public", "function", "remove", "(", "$", "key", ")", "{", "$", "linesBefore", "=", "$", "this", "->", "lineCount", "(", ")", ";", "$", "this", "->", "lines", "->", "removeDefinition", "(", "$", "key", ")", ";", "return", "$", "linesBefore", "-", "$"...
Remove a variable definition. @param $key @return int Lines removed
[ "Remove", "a", "variable", "definition", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/File.php#L209-L216
aaemnnosttv/wp-cli-dotenv-command
features/bootstrap/Process.php
Process.run
public function run() { $cwd = $this->cwd; $descriptors = array( 0 => STDIN, 1 => array( 'pipe', 'w' ), 2 => array( 'pipe', 'w' ), ); $proc = proc_open( $this->command, $descriptors, $pipes, $cwd, $this->env ); $stdout = stream_get_contents( $pipes[1] ); fclose( $pipes[1] ); $stderr = stream_get_contents( $pipes[2] ); fclose( $pipes[2] ); return new ProcessRun( array( 'stdout' => $stdout, 'stderr' => $stderr, 'return_code' => proc_close( $proc ), 'command' => $this->command, 'cwd' => $cwd, 'env' => $this->env ) ); }
php
public function run() { $cwd = $this->cwd; $descriptors = array( 0 => STDIN, 1 => array( 'pipe', 'w' ), 2 => array( 'pipe', 'w' ), ); $proc = proc_open( $this->command, $descriptors, $pipes, $cwd, $this->env ); $stdout = stream_get_contents( $pipes[1] ); fclose( $pipes[1] ); $stderr = stream_get_contents( $pipes[2] ); fclose( $pipes[2] ); return new ProcessRun( array( 'stdout' => $stdout, 'stderr' => $stderr, 'return_code' => proc_close( $proc ), 'command' => $this->command, 'cwd' => $cwd, 'env' => $this->env ) ); }
[ "public", "function", "run", "(", ")", "{", "$", "cwd", "=", "$", "this", "->", "cwd", ";", "$", "descriptors", "=", "array", "(", "0", "=>", "STDIN", ",", "1", "=>", "array", "(", "'pipe'", ",", "'w'", ")", ",", "2", "=>", "array", "(", "'pipe...
Run the command. @return ProcessRun
[ "Run", "the", "command", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/features/bootstrap/Process.php#L34-L59
aaemnnosttv/wp-cli-dotenv-command
features/bootstrap/Process.php
Process.run_check
public function run_check() { $r = $this->run(); if ( $r->return_code || !empty( $r->STDERR ) ) { throw new \RuntimeException( $r ); } return $r; }
php
public function run_check() { $r = $this->run(); if ( $r->return_code || !empty( $r->STDERR ) ) { throw new \RuntimeException( $r ); } return $r; }
[ "public", "function", "run_check", "(", ")", "{", "$", "r", "=", "$", "this", "->", "run", "(", ")", ";", "if", "(", "$", "r", "->", "return_code", "||", "!", "empty", "(", "$", "r", "->", "STDERR", ")", ")", "{", "throw", "new", "\\", "Runtime...
Run the command, but throw an Exception on error. @return ProcessRun
[ "Run", "the", "command", "but", "throw", "an", "Exception", "on", "error", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/features/bootstrap/Process.php#L66-L74
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/Line.php
Line.value_raw
public function value_raw() { if (! strlen($this->text)) { return $this->text; } $pieces = explode('=', $this->text, 2); $pieces = array_map('trim', $pieces); return end($pieces); }
php
public function value_raw() { if (! strlen($this->text)) { return $this->text; } $pieces = explode('=', $this->text, 2); $pieces = array_map('trim', $pieces); return end($pieces); }
[ "public", "function", "value_raw", "(", ")", "{", "if", "(", "!", "strlen", "(", "$", "this", "->", "text", ")", ")", "{", "return", "$", "this", "->", "text", ";", "}", "$", "pieces", "=", "explode", "(", "'='", ",", "$", "this", "->", "text", ...
Get the raw, uncleaned value. @return mixed|null|string
[ "Get", "the", "raw", "uncleaned", "value", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/Line.php#L46-L56
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/Line.php
Line.isPair
public function isPair() { if (0 === strpos(trim($this->text), '#')) { return false; } $pieces = explode('=', $this->text, 2); $pieces = array_map('trim', $pieces); return 2 === count($pieces); }
php
public function isPair() { if (0 === strpos(trim($this->text), '#')) { return false; } $pieces = explode('=', $this->text, 2); $pieces = array_map('trim', $pieces); return 2 === count($pieces); }
[ "public", "function", "isPair", "(", ")", "{", "if", "(", "0", "===", "strpos", "(", "trim", "(", "$", "this", "->", "text", ")", ",", "'#'", ")", ")", "{", "return", "false", ";", "}", "$", "pieces", "=", "explode", "(", "'='", ",", "$", "this...
Whether or not the text is a key=value pair. @return bool
[ "Whether", "or", "not", "the", "text", "is", "a", "key", "=", "value", "pair", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/Line.php#L73-L83
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/Line.php
Line.parse_raw
public static function parse_raw($text) { $line = new static($text); if (! $line->isPair()) { return $line; } return new KeyValue($line->key(), $line->value(), $line->quote()); }
php
public static function parse_raw($text) { $line = new static($text); if (! $line->isPair()) { return $line; } return new KeyValue($line->key(), $line->value(), $line->quote()); }
[ "public", "static", "function", "parse_raw", "(", "$", "text", ")", "{", "$", "line", "=", "new", "static", "(", "$", "text", ")", ";", "if", "(", "!", "$", "line", "->", "isPair", "(", ")", ")", "{", "return", "$", "line", ";", "}", "return", ...
@param string $text @return LineInterface
[ "@param", "string", "$text" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/Line.php#L98-L107
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/Line.php
Line.wraps_value
public static function wraps_value($char, $value) { return substr((string) $value, 0, 1) == $char && substr((string) $value, -1, 1) == $char; }
php
public static function wraps_value($char, $value) { return substr((string) $value, 0, 1) == $char && substr((string) $value, -1, 1) == $char; }
[ "public", "static", "function", "wraps_value", "(", "$", "char", ",", "$", "value", ")", "{", "return", "substr", "(", "(", "string", ")", "$", "value", ",", "0", ",", "1", ")", "==", "$", "char", "&&", "substr", "(", "(", "string", ")", "$", "va...
Check if the given character wraps the value. @param $char @param $value @return bool
[ "Check", "if", "the", "given", "character", "wraps", "the", "value", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/Line.php#L117-L121
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/Line.php
Line.wrapping_quote_for
public static function wrapping_quote_for($string) { return Collection::make(["'", '"']) ->first(function ($key, $quote) use ($string) { return static::wraps_value($quote, $string); }, ''); }
php
public static function wrapping_quote_for($string) { return Collection::make(["'", '"']) ->first(function ($key, $quote) use ($string) { return static::wraps_value($quote, $string); }, ''); }
[ "public", "static", "function", "wrapping_quote_for", "(", "$", "string", ")", "{", "return", "Collection", "::", "make", "(", "[", "\"'\"", ",", "'\"'", "]", ")", "->", "first", "(", "function", "(", "$", "key", ",", "$", "quote", ")", "use", "(", "...
@param $string @return string
[ "@param", "$string" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/Line.php#L128-L134
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/Line.php
Line.clean_quotes
public static function clean_quotes($string) { if (static::wrapping_quote_for($string)) { $string = substr($string, 1); // remove first character $string = substr($string, 0, -1); // remove last } return $string; }
php
public static function clean_quotes($string) { if (static::wrapping_quote_for($string)) { $string = substr($string, 1); // remove first character $string = substr($string, 0, -1); // remove last } return $string; }
[ "public", "static", "function", "clean_quotes", "(", "$", "string", ")", "{", "if", "(", "static", "::", "wrapping_quote_for", "(", "$", "string", ")", ")", "{", "$", "string", "=", "substr", "(", "$", "string", ",", "1", ")", ";", "// remove first chara...
Trim surrounding quotes from a string @param $string @return string
[ "Trim", "surrounding", "quotes", "from", "a", "string" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/Line.php#L143-L151
aaemnnosttv/wp-cli-dotenv-command
features/bootstrap/FeatureContext.php
FeatureContext.get_process_env_variables
private static function get_process_env_variables() { // Ensure we're using the expected `wp` binary $bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . "/../../bin" ); $env = array( 'PATH' => $bin_dir . ':' . getenv( 'PATH' ), 'BEHAT_RUN' => 1 ); if ( $config_path = getenv( 'WP_CLI_CONFIG_PATH' ) ) { $env['WP_CLI_CONFIG_PATH'] = $config_path; } return $env; }
php
private static function get_process_env_variables() { // Ensure we're using the expected `wp` binary $bin_dir = getenv( 'WP_CLI_BIN_DIR' ) ?: realpath( __DIR__ . "/../../bin" ); $env = array( 'PATH' => $bin_dir . ':' . getenv( 'PATH' ), 'BEHAT_RUN' => 1 ); if ( $config_path = getenv( 'WP_CLI_CONFIG_PATH' ) ) { $env['WP_CLI_CONFIG_PATH'] = $config_path; } return $env; }
[ "private", "static", "function", "get_process_env_variables", "(", ")", "{", "// Ensure we're using the expected `wp` binary", "$", "bin_dir", "=", "getenv", "(", "'WP_CLI_BIN_DIR'", ")", "?", ":", "realpath", "(", "__DIR__", ".", "\"/../../bin\"", ")", ";", "$", "e...
Get the environment variables required for launched `wp` processes @beforeSuite
[ "Get", "the", "environment", "variables", "required", "for", "launched", "wp", "processes" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/features/bootstrap/FeatureContext.php#L43-L54
aaemnnosttv/wp-cli-dotenv-command
features/bootstrap/FeatureContext.php
FeatureContext.cache_wp_files
private static function cache_wp_files() { self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test core-download-cache'; if ( is_readable( self::$cache_dir . '/wp-config-sample.php' ) ) return; $cmd = Utils\esc_cmd( 'wp core download --force --path=%s', self::$cache_dir ); Process::create( $cmd, null, self::get_process_env_variables() )->run_check(); }
php
private static function cache_wp_files() { self::$cache_dir = sys_get_temp_dir() . '/wp-cli-test core-download-cache'; if ( is_readable( self::$cache_dir . '/wp-config-sample.php' ) ) return; $cmd = Utils\esc_cmd( 'wp core download --force --path=%s', self::$cache_dir ); Process::create( $cmd, null, self::get_process_env_variables() )->run_check(); }
[ "private", "static", "function", "cache_wp_files", "(", ")", "{", "self", "::", "$", "cache_dir", "=", "sys_get_temp_dir", "(", ")", ".", "'/wp-cli-test core-download-cache'", ";", "if", "(", "is_readable", "(", "self", "::", "$", "cache_dir", ".", "'/wp-config-...
Ideally, we'd cache at the HTTP layer for more reliable tests
[ "Ideally", "we", "d", "cache", "at", "the", "HTTP", "layer", "for", "more", "reliable", "tests" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/features/bootstrap/FeatureContext.php#L58-L66
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/SaltsCommand.php
SaltsCommand.generate
public function generate($_, $assoc_args) { $this->init_args(func_get_args()); $updated = $this->update_salts($this->get_flag('force') ?: $this->salts_are_placeholders()); if (! $this->env->save()) { WP_CLI::error('Failed to update salts.'); } $skipped = $updated->pluck('skipped')->filter(); $set = $this->salts->count() - $skipped->count(); if ($set === count($this->salts)) { WP_CLI::success('Salts generated.'); } elseif ($set) { WP_CLI::success("$set salts set."); } if (! $skipped->isEmpty()) { WP_CLI::line('Some keys were already defined in the environment file.'); WP_CLI::line("Use 'dotenv salts regenerate' to update them."); } }
php
public function generate($_, $assoc_args) { $this->init_args(func_get_args()); $updated = $this->update_salts($this->get_flag('force') ?: $this->salts_are_placeholders()); if (! $this->env->save()) { WP_CLI::error('Failed to update salts.'); } $skipped = $updated->pluck('skipped')->filter(); $set = $this->salts->count() - $skipped->count(); if ($set === count($this->salts)) { WP_CLI::success('Salts generated.'); } elseif ($set) { WP_CLI::success("$set salts set."); } if (! $skipped->isEmpty()) { WP_CLI::line('Some keys were already defined in the environment file.'); WP_CLI::line("Use 'dotenv salts regenerate' to update them."); } }
[ "public", "function", "generate", "(", "$", "_", ",", "$", "assoc_args", ")", "{", "$", "this", "->", "init_args", "(", "func_get_args", "(", ")", ")", ";", "$", "updated", "=", "$", "this", "->", "update_salts", "(", "$", "this", "->", "get_flag", "...
Fetch some fresh salts and add them to the environment file if they do not already exist. [--file=<path-to-dotenv>] : Path to the environment file. Default: '.env' [--force] : Overwrite any existing salts in the environment file. @when before_wp_load @param $_ @param $assoc_args
[ "Fetch", "some", "fresh", "salts", "and", "add", "them", "to", "the", "environment", "file", "if", "they", "do", "not", "already", "exist", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/SaltsCommand.php#L42-L65
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/SaltsCommand.php
SaltsCommand.regenerate
public function regenerate($_, $assoc_args) { $this->init_args(func_get_args()); $this->update_salts(true); if (! $this->env->save()) { WP_CLI::error('Failed to update salts.'); } WP_CLI::success('Salts regenerated.'); }
php
public function regenerate($_, $assoc_args) { $this->init_args(func_get_args()); $this->update_salts(true); if (! $this->env->save()) { WP_CLI::error('Failed to update salts.'); } WP_CLI::success('Salts regenerated.'); }
[ "public", "function", "regenerate", "(", "$", "_", ",", "$", "assoc_args", ")", "{", "$", "this", "->", "init_args", "(", "func_get_args", "(", ")", ")", ";", "$", "this", "->", "update_salts", "(", "true", ")", ";", "if", "(", "!", "$", "this", "-...
Regenerate salts for the environment file. [--file=<path-to-dotenv>] : Path to the environment file. Default: '.env' @when before_wp_load @param $_ @param $assoc_args
[ "Regenerate", "salts", "for", "the", "environment", "file", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/SaltsCommand.php#L78-L89
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/SaltsCommand.php
SaltsCommand.salts_are_placeholders
protected function salts_are_placeholders() { return $this->env->dictionary() // salts are stored as a list [key, value] ->only($this->salts->pluck(0)->all()) // strip the env down to just the salts ->values() ->unique() ->count() === 1; // 1 unique means they are all the same }
php
protected function salts_are_placeholders() { return $this->env->dictionary() // salts are stored as a list [key, value] ->only($this->salts->pluck(0)->all()) // strip the env down to just the salts ->values() ->unique() ->count() === 1; // 1 unique means they are all the same }
[ "protected", "function", "salts_are_placeholders", "(", ")", "{", "return", "$", "this", "->", "env", "->", "dictionary", "(", ")", "// salts are stored as a list [key, value]", "->", "only", "(", "$", "this", "->", "salts", "->", "pluck", "(", "0", ")", "->",...
Perform a simple check to see if all defined salts are using a placeholder. @return bool
[ "Perform", "a", "simple", "check", "to", "see", "if", "all", "defined", "salts", "are", "using", "a", "placeholder", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/SaltsCommand.php#L95-L103
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/SaltsCommand.php
SaltsCommand.update_salts
protected function update_salts($force = false) { return $this->salts->map(function ($salt) use ($force) { list($key, $value) = $salt; if (! $force && $this->env->hasKey($key)) { WP_CLI::line("The '$key' already exists, skipping."); $salt['skipped'] = true; return $salt; } $this->env->set($key, $value, "'"); return $salt; }); }
php
protected function update_salts($force = false) { return $this->salts->map(function ($salt) use ($force) { list($key, $value) = $salt; if (! $force && $this->env->hasKey($key)) { WP_CLI::line("The '$key' already exists, skipping."); $salt['skipped'] = true; return $salt; } $this->env->set($key, $value, "'"); return $salt; }); }
[ "protected", "function", "update_salts", "(", "$", "force", "=", "false", ")", "{", "return", "$", "this", "->", "salts", "->", "map", "(", "function", "(", "$", "salt", ")", "use", "(", "$", "force", ")", "{", "list", "(", "$", "key", ",", "$", ...
Update salts in the environment file. @param bool $force Whether or not to force update any existing values @return Collection
[ "Update", "salts", "in", "the", "environment", "file", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/SaltsCommand.php#L112-L127
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/SaltsCommand.php
SaltsCommand.init_args
protected function init_args($args) { parent::init_args($args); $this->env = $this->get_env_for_write_or_fail(); $api = new Salts(); try { $this->salts = $api->collect(); } catch (Exception $e) { WP_CLI::error($e->getMessage()); } }
php
protected function init_args($args) { parent::init_args($args); $this->env = $this->get_env_for_write_or_fail(); $api = new Salts(); try { $this->salts = $api->collect(); } catch (Exception $e) { WP_CLI::error($e->getMessage()); } }
[ "protected", "function", "init_args", "(", "$", "args", ")", "{", "parent", "::", "init_args", "(", "$", "args", ")", ";", "$", "this", "->", "env", "=", "$", "this", "->", "get_env_for_write_or_fail", "(", ")", ";", "$", "api", "=", "new", "Salts", ...
Initialize properties for the command. @param array $args
[ "Initialize", "properties", "for", "the", "command", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/SaltsCommand.php#L134-L146
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/FileLines.php
FileLines.updateOrAdd
public function updateOrAdd(LineInterface $line) { $key = $line->key(); $index = $this->search(function (LineInterface $line) use ($key) { return $line->key() == $key; }); if ($index > -1) { $this->put($index, $line); } else { $this->add($line); } }
php
public function updateOrAdd(LineInterface $line) { $key = $line->key(); $index = $this->search(function (LineInterface $line) use ($key) { return $line->key() == $key; }); if ($index > -1) { $this->put($index, $line); } else { $this->add($line); } }
[ "public", "function", "updateOrAdd", "(", "LineInterface", "$", "line", ")", "{", "$", "key", "=", "$", "line", "->", "key", "(", ")", ";", "$", "index", "=", "$", "this", "->", "search", "(", "function", "(", "LineInterface", "$", "line", ")", "use"...
Update the line by key, or add it if there is no existing line for the same key. @param LineInterface $line
[ "Update", "the", "line", "by", "key", "or", "add", "it", "if", "there", "is", "no", "existing", "line", "for", "the", "same", "key", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/FileLines.php#L73-L86
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/FileLines.php
FileLines.hasDefinition
public function hasDefinition($varName) { return $this->contains(function ($index, LineInterface $line) use ($varName) { return $line->key() == $varName; }); }
php
public function hasDefinition($varName) { return $this->contains(function ($index, LineInterface $line) use ($varName) { return $line->key() == $varName; }); }
[ "public", "function", "hasDefinition", "(", "$", "varName", ")", "{", "return", "$", "this", "->", "contains", "(", "function", "(", "$", "index", ",", "LineInterface", "$", "line", ")", "use", "(", "$", "varName", ")", "{", "return", "$", "line", "->"...
Check if the collection has a definition for the given variable name. @param $varName @return bool
[ "Check", "if", "the", "collection", "has", "a", "definition", "for", "the", "given", "variable", "name", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/FileLines.php#L95-L100
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/FileLines.php
FileLines.removeDefinition
public function removeDefinition($varName) { $this->items = $this->reject(function (LineInterface $line) use ($varName) { return $line->key() == $varName; })->all(); return $this; }
php
public function removeDefinition($varName) { $this->items = $this->reject(function (LineInterface $line) use ($varName) { return $line->key() == $varName; })->all(); return $this; }
[ "public", "function", "removeDefinition", "(", "$", "varName", ")", "{", "$", "this", "->", "items", "=", "$", "this", "->", "reject", "(", "function", "(", "LineInterface", "$", "line", ")", "use", "(", "$", "varName", ")", "{", "return", "$", "line",...
Remove the definition by the variable name. @param string $varName @return $this
[ "Remove", "the", "definition", "by", "the", "variable", "name", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/FileLines.php#L109-L116
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/FileLines.php
FileLines.toDictionary
public function toDictionary() { return $this->pairs()->reduce(function (Collection $pairs, LineInterface $line) { $pairs[ $line->key() ] = $line->value(); return $pairs; }, new Collection); }
php
public function toDictionary() { return $this->pairs()->reduce(function (Collection $pairs, LineInterface $line) { $pairs[ $line->key() ] = $line->value(); return $pairs; }, new Collection); }
[ "public", "function", "toDictionary", "(", ")", "{", "return", "$", "this", "->", "pairs", "(", ")", "->", "reduce", "(", "function", "(", "Collection", "$", "pairs", ",", "LineInterface", "$", "line", ")", "{", "$", "pairs", "[", "$", "line", "->", ...
Get the lines as key => value. @return Collection
[ "Get", "the", "lines", "as", "key", "=", ">", "value", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/FileLines.php#L147-L154
aaemnnosttv/wp-cli-dotenv-command
src/Dotenv/FileLines.php
FileLines.whereKeysLike
public function whereKeysLike($patterns) { if (! $patterns instanceof Collection) { $patterns = new Collection((array) $patterns); } /* @var Collection $patterns */ if ($patterns->filter()->isEmpty()) { return new static($this->all()); } /** * Return a subset of pairs that match any of the given patterns. */ return $this->pairs()->filter(function (LineInterface $line) use ($patterns) { return $patterns->contains(function ($index, $pattern) use ($line) { return fnmatch($pattern, $line->key()); }); }); }
php
public function whereKeysLike($patterns) { if (! $patterns instanceof Collection) { $patterns = new Collection((array) $patterns); } /* @var Collection $patterns */ if ($patterns->filter()->isEmpty()) { return new static($this->all()); } /** * Return a subset of pairs that match any of the given patterns. */ return $this->pairs()->filter(function (LineInterface $line) use ($patterns) { return $patterns->contains(function ($index, $pattern) use ($line) { return fnmatch($pattern, $line->key()); }); }); }
[ "public", "function", "whereKeysLike", "(", "$", "patterns", ")", "{", "if", "(", "!", "$", "patterns", "instanceof", "Collection", ")", "{", "$", "patterns", "=", "new", "Collection", "(", "(", "array", ")", "$", "patterns", ")", ";", "}", "/* @var Coll...
Get a subset of lines where the key matches at least one of the given glob-style patterns. @param string|array|Collection $patterns @return static
[ "Get", "a", "subset", "of", "lines", "where", "the", "key", "matches", "at", "least", "one", "of", "the", "given", "glob", "-", "style", "patterns", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/Dotenv/FileLines.php#L163-L183
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/DotenvCommand.php
DotenvCommand.init
public function init($_, $assoc_args) { $this->init_args(func_get_args()); $path = $this->resolve_file_path(); if (file_exists($path) && ! $this->get_flag('force')) { WP_CLI::error("Environment file already exists at: $path"); return; } $env = File::create($path); if (! $env->exists()) { WP_CLI::error('Failed to create environment file at: ' . $env->path()); return; } if ($this->args->template) { $this->init_from_template($env, $this->args->template); } if ($this->get_flag('with-salts')) { WP_CLI::run_command(['dotenv', 'salts', 'generate'], ['file' => $env->path()]); } WP_CLI::success("$path created."); }
php
public function init($_, $assoc_args) { $this->init_args(func_get_args()); $path = $this->resolve_file_path(); if (file_exists($path) && ! $this->get_flag('force')) { WP_CLI::error("Environment file already exists at: $path"); return; } $env = File::create($path); if (! $env->exists()) { WP_CLI::error('Failed to create environment file at: ' . $env->path()); return; } if ($this->args->template) { $this->init_from_template($env, $this->args->template); } if ($this->get_flag('with-salts')) { WP_CLI::run_command(['dotenv', 'salts', 'generate'], ['file' => $env->path()]); } WP_CLI::success("$path created."); }
[ "public", "function", "init", "(", "$", "_", ",", "$", "assoc_args", ")", "{", "$", "this", "->", "init_args", "(", "func_get_args", "(", ")", ")", ";", "$", "path", "=", "$", "this", "->", "resolve_file_path", "(", ")", ";", "if", "(", "file_exists"...
Initialize the environment file. [--file=<path-to-dotenv>] : Path to the environment file. Default: '.env' [--with-salts] : Additionally, generate and define keys for salts [--template=<template-name>] : Path to a template to use to interactively set values [--interactive] : Set new values from the template interactively with prompts for each key-value pair [--force] : Overwrite existing destination file if it exists @when before_wp_load @param $_ @param $assoc_args
[ "Initialize", "the", "environment", "file", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/DotenvCommand.php#L37-L65
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/DotenvCommand.php
DotenvCommand.set
public function set($_, $assoc_args) { $this->init_args(func_get_args()); list($key, $value) = $_; $env = $this->get_env_for_write_or_fail(); $env->set($key, $value, $this->quote()); $env->save(); WP_CLI::success("'$key' set."); }
php
public function set($_, $assoc_args) { $this->init_args(func_get_args()); list($key, $value) = $_; $env = $this->get_env_for_write_or_fail(); $env->set($key, $value, $this->quote()); $env->save(); WP_CLI::success("'$key' set."); }
[ "public", "function", "set", "(", "$", "_", ",", "$", "assoc_args", ")", "{", "$", "this", "->", "init_args", "(", "func_get_args", "(", ")", ")", ";", "list", "(", "$", "key", ",", "$", "value", ")", "=", "$", "_", ";", "$", "env", "=", "$", ...
Set a value in the environment file for a given key. Updates an existing value or creates a new entry. <key> : The var key <value> : the value to set. [--file=<path-to-dotenv>] : Path to the environment file. Default: '.env' [--quote-single] : Wrap the value with single quotes. [--quote-double] : Wrap the value with double quotes. @when before_wp_load @param $_ @param $assoc_args
[ "Set", "a", "value", "in", "the", "environment", "file", "for", "a", "given", "key", ".", "Updates", "an", "existing", "value", "or", "creates", "a", "new", "entry", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/DotenvCommand.php#L130-L140
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/DotenvCommand.php
DotenvCommand.get
public function get($_, $assoc_args) { $this->init_args(func_get_args()); list($key) = $_; $env = $this->get_env_for_read_or_fail(); if (is_null($value = $env->get($key))) { WP_CLI::error("Key '$key' not found."); } WP_CLI::line($value); }
php
public function get($_, $assoc_args) { $this->init_args(func_get_args()); list($key) = $_; $env = $this->get_env_for_read_or_fail(); if (is_null($value = $env->get($key))) { WP_CLI::error("Key '$key' not found."); } WP_CLI::line($value); }
[ "public", "function", "get", "(", "$", "_", ",", "$", "assoc_args", ")", "{", "$", "this", "->", "init_args", "(", "func_get_args", "(", ")", ")", ";", "list", "(", "$", "key", ")", "=", "$", "_", ";", "$", "env", "=", "$", "this", "->", "get_e...
Get the value for a given key from the environment file <key> : The variable name to retrieve the value for. [--file=<path-to-dotenv>] : Path to the environment file. Default: '.env' @when before_wp_load @param $_ @param $assoc_args
[ "Get", "the", "value", "for", "a", "given", "key", "from", "the", "environment", "file" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/DotenvCommand.php#L174-L186
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/DotenvCommand.php
DotenvCommand.delete
public function delete($_, $assoc_args) { $this->init_args(func_get_args()); $env = $this->get_env_for_write_or_fail(); foreach ($_ as $key) { if ($result = $env->remove($key)) { WP_CLI::success("Removed '$key'"); } else { WP_CLI::warning("No line found for key: '$key'"); } } $env->save(); }
php
public function delete($_, $assoc_args) { $this->init_args(func_get_args()); $env = $this->get_env_for_write_or_fail(); foreach ($_ as $key) { if ($result = $env->remove($key)) { WP_CLI::success("Removed '$key'"); } else { WP_CLI::warning("No line found for key: '$key'"); } } $env->save(); }
[ "public", "function", "delete", "(", "$", "_", ",", "$", "assoc_args", ")", "{", "$", "this", "->", "init_args", "(", "func_get_args", "(", ")", ")", ";", "$", "env", "=", "$", "this", "->", "get_env_for_write_or_fail", "(", ")", ";", "foreach", "(", ...
Delete a definition from the environment file <key>... : One or more keys to remove from the environment file. [--file=<path-to-dotenv>] : Path to the environment file. Default: '.env' @when before_wp_load @param $_ @param $assoc_args
[ "Delete", "a", "definition", "from", "the", "environment", "file" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/DotenvCommand.php#L202-L216
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/DotenvCommand.php
DotenvCommand._list
public function _list($patterns, $assoc_args) { $this->init_args(func_get_args()); $env = $this->get_env_for_read_or_fail(); $items = $env->dictionaryWithKeysMatching($patterns) ->map(function ($value, $key) { return (object) compact('key', 'value'); }); $args = $this->args->toArray(); // var required - passed by reference $formatter = new Formatter($args, $this->fields()); $formatter->display_items($items->all()); }
php
public function _list($patterns, $assoc_args) { $this->init_args(func_get_args()); $env = $this->get_env_for_read_or_fail(); $items = $env->dictionaryWithKeysMatching($patterns) ->map(function ($value, $key) { return (object) compact('key', 'value'); }); $args = $this->args->toArray(); // var required - passed by reference $formatter = new Formatter($args, $this->fields()); $formatter->display_items($items->all()); }
[ "public", "function", "_list", "(", "$", "patterns", ",", "$", "assoc_args", ")", "{", "$", "this", "->", "init_args", "(", "func_get_args", "(", ")", ")", ";", "$", "env", "=", "$", "this", "->", "get_env_for_read_or_fail", "(", ")", ";", "$", "items"...
List the defined variables from the environment file [<pattern>...] : Key names or glob-style patterns to match. [--format=<format>] : Accepted values: table, csv, json, count. Default: table [--file=<path-to-dotenv>] : Path to the environment file. Default: '.env' @subcommand list @when before_wp_load @param array $patterns Glob-style patterns to match against env keys @param array $assoc_args
[ "List", "the", "defined", "variables", "from", "the", "environment", "file" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/DotenvCommand.php#L237-L250
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/DotenvCommand.php
DotenvCommand.fields
protected function fields() { return is_string($this->args->fields) ? explode(',', $this->args->fields) : $this->args->fields; }
php
protected function fields() { return is_string($this->args->fields) ? explode(',', $this->args->fields) : $this->args->fields; }
[ "protected", "function", "fields", "(", ")", "{", "return", "is_string", "(", "$", "this", "->", "args", "->", "fields", ")", "?", "explode", "(", "','", ",", "$", "this", "->", "args", "->", "fields", ")", ":", "$", "this", "->", "args", "->", "fi...
Get the fields to display as passed in the arguments. Multiple keys can be passed in the cli arguments as a comma-separated list. This converts those to an array, if passed. @return array
[ "Get", "the", "fields", "to", "display", "as", "passed", "in", "the", "arguments", "." ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/DotenvCommand.php#L260-L265
aaemnnosttv/wp-cli-dotenv-command
src/WP_CLI/DotenvCommand.php
DotenvCommand.prompt_all
protected function prompt_all(File $env) { $env->dictionary()->each(function ($value, $key) use ($env) { $env->set($key, $this->prompt($key, $value)); }); $env->save(); }
php
protected function prompt_all(File $env) { $env->dictionary()->each(function ($value, $key) use ($env) { $env->set($key, $this->prompt($key, $value)); }); $env->save(); }
[ "protected", "function", "prompt_all", "(", "File", "$", "env", ")", "{", "$", "env", "->", "dictionary", "(", ")", "->", "each", "(", "function", "(", "$", "value", ",", "$", "key", ")", "use", "(", "$", "env", ")", "{", "$", "env", "->", "set",...
Iterate over each line and prompt for a new value @param File $env @return int
[ "Iterate", "over", "each", "line", "and", "prompt", "for", "a", "new", "value" ]
train
https://github.com/aaemnnosttv/wp-cli-dotenv-command/blob/1a779dd3645ed49bf1e48b3b35d3b9c8af90fc2c/src/WP_CLI/DotenvCommand.php#L274-L281
K-Phoen/rulerz
src/Executor/Polyfill/FilterBasedSatisfaction.php
FilterBasedSatisfaction.satisfies
public function satisfies($target, array $parameters, array $operators, ExecutionContext $context): bool { return count($this->filter($target, $parameters, $operators, $context)) !== 0; }
php
public function satisfies($target, array $parameters, array $operators, ExecutionContext $context): bool { return count($this->filter($target, $parameters, $operators, $context)) !== 0; }
[ "public", "function", "satisfies", "(", "$", "target", ",", "array", "$", "parameters", ",", "array", "$", "operators", ",", "ExecutionContext", "$", "context", ")", ":", "bool", "{", "return", "count", "(", "$", "this", "->", "filter", "(", "$", "target...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Executor/Polyfill/FilterBasedSatisfaction.php#L19-L22
K-Phoen/rulerz
src/Target/AbstractCompilationTarget.php
AbstractCompilationTarget.compile
public function compile(Model\Rule $rule, Context $compilationContext): Model\Executor { $visitor = $this->createVisitor($compilationContext); $compiledCode = $visitor->visit($rule); return new Model\Executor( $this->getExecutorTraits(), $compiledCode, $visitor->getCompilationData() ); }
php
public function compile(Model\Rule $rule, Context $compilationContext): Model\Executor { $visitor = $this->createVisitor($compilationContext); $compiledCode = $visitor->visit($rule); return new Model\Executor( $this->getExecutorTraits(), $compiledCode, $visitor->getCompilationData() ); }
[ "public", "function", "compile", "(", "Model", "\\", "Rule", "$", "rule", ",", "Context", "$", "compilationContext", ")", ":", "Model", "\\", "Executor", "{", "$", "visitor", "=", "$", "this", "->", "createVisitor", "(", "$", "compilationContext", ")", ";"...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/AbstractCompilationTarget.php#L46-L56
K-Phoen/rulerz
src/Target/AbstractCompilationTarget.php
AbstractCompilationTarget.defineOperator
public function defineOperator(string $name, callable $transformer): void { $this->customOperators->defineOperator($name, $transformer); }
php
public function defineOperator(string $name, callable $transformer): void { $this->customOperators->defineOperator($name, $transformer); }
[ "public", "function", "defineOperator", "(", "string", "$", "name", ",", "callable", "$", "transformer", ")", ":", "void", "{", "$", "this", "->", "customOperators", "->", "defineOperator", "(", "$", "name", ",", "$", "transformer", ")", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/AbstractCompilationTarget.php#L69-L72
K-Phoen/rulerz
src/Target/AbstractCompilationTarget.php
AbstractCompilationTarget.defineInlineOperator
public function defineInlineOperator(string $name, callable $transformer): void { $this->customOperators->defineInlineOperator($name, $transformer); }
php
public function defineInlineOperator(string $name, callable $transformer): void { $this->customOperators->defineInlineOperator($name, $transformer); }
[ "public", "function", "defineInlineOperator", "(", "string", "$", "name", ",", "callable", "$", "transformer", ")", ":", "void", "{", "$", "this", "->", "customOperators", "->", "defineInlineOperator", "(", "$", "name", ",", "$", "transformer", ")", ";", "}"...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/AbstractCompilationTarget.php#L77-L80
K-Phoen/rulerz
src/Compiler/FileEvaluator.php
FileEvaluator.evaluate
public function evaluate(string $ruleIdentifier, callable $compiler): void { $fileName = $this->directory.DIRECTORY_SEPARATOR.'rulerz_executor_'.$ruleIdentifier; if (!$this->fs->has($fileName)) { $this->fs->write($fileName, '<?php'."\n".$compiler()); } require $fileName; }
php
public function evaluate(string $ruleIdentifier, callable $compiler): void { $fileName = $this->directory.DIRECTORY_SEPARATOR.'rulerz_executor_'.$ruleIdentifier; if (!$this->fs->has($fileName)) { $this->fs->write($fileName, '<?php'."\n".$compiler()); } require $fileName; }
[ "public", "function", "evaluate", "(", "string", "$", "ruleIdentifier", ",", "callable", "$", "compiler", ")", ":", "void", "{", "$", "fileName", "=", "$", "this", "->", "directory", ".", "DIRECTORY_SEPARATOR", ".", "'rulerz_executor_'", ".", "$", "ruleIdentif...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Compiler/FileEvaluator.php#L27-L36
K-Phoen/rulerz
src/Context/ExecutionContext.php
ExecutionContext.offsetGet
public function offsetGet($key) { if (!array_key_exists($key, $this->data)) { throw new \RuntimeException(sprintf('Identifier "%s" does not exist in the context.', $key)); } return $this->data[$key]; }
php
public function offsetGet($key) { if (!array_key_exists($key, $this->data)) { throw new \RuntimeException(sprintf('Identifier "%s" does not exist in the context.', $key)); } return $this->data[$key]; }
[ "public", "function", "offsetGet", "(", "$", "key", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "data", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "sprintf", "(", "'Identifier \"%s\" does not ex...
Get a data. @param string $key Key. @return mixed
[ "Get", "a", "data", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Context/ExecutionContext.php#L38-L45
K-Phoen/rulerz
src/Target/GenericElasticsearchVisitor.php
GenericElasticsearchVisitor.visitAccess
public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $dimensions = $element->getDimensions(); // nested path if (!empty($dimensions)) { return $this->flattenAccessPath($element); } return $element->getId(); }
php
public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $dimensions = $element->getDimensions(); // nested path if (!empty($dimensions)) { return $this->flattenAccessPath($element); } return $element->getId(); }
[ "public", "function", "visitAccess", "(", "AST", "\\", "Bag", "\\", "Context", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "$", "dimensions", "=", "$", "element", "->", "getDimensions", "(", ")", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/GenericElasticsearchVisitor.php#L21-L31
K-Phoen/rulerz
src/Executor/ArrayTarget/FilterTrait.php
FilterTrait.filter
public function filter($target, array $parameters, array $operators, ExecutionContext $context) { return IteratorTools::fromGenerator(function () use ($target, $parameters, $operators) { foreach ($target as $row) { $targetRow = is_array($row) ? $row : new ObjectContext($row); if ($this->execute($targetRow, $operators, $parameters)) { yield $row; } } }); }
php
public function filter($target, array $parameters, array $operators, ExecutionContext $context) { return IteratorTools::fromGenerator(function () use ($target, $parameters, $operators) { foreach ($target as $row) { $targetRow = is_array($row) ? $row : new ObjectContext($row); if ($this->execute($targetRow, $operators, $parameters)) { yield $row; } } }); }
[ "public", "function", "filter", "(", "$", "target", ",", "array", "$", "parameters", ",", "array", "$", "operators", ",", "ExecutionContext", "$", "context", ")", "{", "return", "IteratorTools", "::", "fromGenerator", "(", "function", "(", ")", "use", "(", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Executor/ArrayTarget/FilterTrait.php#L26-L37
K-Phoen/rulerz
src/Context/ObjectContext.php
ObjectContext.offsetGet
public function offsetGet($id) { $value = $this->accessor->getValue($this->object, $id); if (is_scalar($value) || $value === null) { return $value; } return new static($value); }
php
public function offsetGet($id) { $value = $this->accessor->getValue($this->object, $id); if (is_scalar($value) || $value === null) { return $value; } return new static($value); }
[ "public", "function", "offsetGet", "(", "$", "id", ")", "{", "$", "value", "=", "$", "this", "->", "accessor", "->", "getValue", "(", "$", "this", "->", "object", ",", "$", "id", ")", ";", "if", "(", "is_scalar", "(", "$", "value", ")", "||", "$"...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Context/ObjectContext.php#L43-L52
K-Phoen/rulerz
src/Model/Parameter.php
Parameter.accept
public function accept(Visitor\Visit $visitor, &$handle = null, $eldnah = null) { return $visitor->visit($this, $handle, $eldnah); }
php
public function accept(Visitor\Visit $visitor, &$handle = null, $eldnah = null) { return $visitor->visit($this, $handle, $eldnah); }
[ "public", "function", "accept", "(", "Visitor", "\\", "Visit", "$", "visitor", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "return", "$", "visitor", "->", "visit", "(", "$", "this", ",", "$", "handle", ",", "$",...
Accept a visitor. @param \Hoa\Visitor\Visit $visitor Visitor. @param mixed &$handle Handle (reference). @param mixed $eldnah Handle (no reference). @return mixed
[ "Accept", "a", "visitor", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Model/Parameter.php#L37-L40
K-Phoen/rulerz
src/Result/IteratorTools.php
IteratorTools.ensureTraversable
public static function ensureTraversable($items): \Traversable { if ($items instanceof \Traversable) { return $items; } if (is_array($items)) { return self::fromArray($items); } throw new \InvalidArgumentException('Un-handled argument of type: '.get_class($items)); }
php
public static function ensureTraversable($items): \Traversable { if ($items instanceof \Traversable) { return $items; } if (is_array($items)) { return self::fromArray($items); } throw new \InvalidArgumentException('Un-handled argument of type: '.get_class($items)); }
[ "public", "static", "function", "ensureTraversable", "(", "$", "items", ")", ":", "\\", "Traversable", "{", "if", "(", "$", "items", "instanceof", "\\", "Traversable", ")", "{", "return", "$", "items", ";", "}", "if", "(", "is_array", "(", "$", "items", ...
Ensures that the given items are \Traversable. Usage: ``` IteratorTools::ensureTraversable([1, 2, 3]); IteratorTools::ensureTraversable(new \ArrayIterator([1, 2, 3])); ``` @param mixed $items @throws \InvalidArgumentException
[ "Ensures", "that", "the", "given", "items", "are", "\\", "Traversable", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Result/IteratorTools.php#L28-L39
K-Phoen/rulerz
src/RulerZ.php
RulerZ.filter
public function filter($target, string $rule, array $parameters = [], array $executionContext = []) { $targetCompiler = $this->findTargetCompiler($target, CompilationTarget::MODE_FILTER); $compilationContext = $targetCompiler->createCompilationContext($target); $executor = $this->compiler->compile($rule, $targetCompiler, $compilationContext); return $executor->filter($target, $parameters, $targetCompiler->getOperators()->getOperators(), new ExecutionContext($executionContext)); }
php
public function filter($target, string $rule, array $parameters = [], array $executionContext = []) { $targetCompiler = $this->findTargetCompiler($target, CompilationTarget::MODE_FILTER); $compilationContext = $targetCompiler->createCompilationContext($target); $executor = $this->compiler->compile($rule, $targetCompiler, $compilationContext); return $executor->filter($target, $parameters, $targetCompiler->getOperators()->getOperators(), new ExecutionContext($executionContext)); }
[ "public", "function", "filter", "(", "$", "target", ",", "string", "$", "rule", ",", "array", "$", "parameters", "=", "[", "]", ",", "array", "$", "executionContext", "=", "[", "]", ")", "{", "$", "targetCompiler", "=", "$", "this", "->", "findTargetCo...
Filters a target using the given rule and parameters. The target compiler to use is determined at runtime using the registered ones. @param mixed $target The target to filter. @param string $rule The rule to apply. @param array $parameters The parameters used in the rule. @param array $executionContext The execution context. @return \Traversable The filtered target. @throws TargetUnsupportedException
[ "Filters", "a", "target", "using", "the", "given", "rule", "and", "parameters", ".", "The", "target", "compiler", "to", "use", "is", "determined", "at", "runtime", "using", "the", "registered", "ones", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/RulerZ.php#L82-L89
K-Phoen/rulerz
src/RulerZ.php
RulerZ.filterSpec
public function filterSpec($target, Specification $spec, array $executionContext = []) { return $this->filter($target, $spec->getRule(), $spec->getParameters(), $executionContext); }
php
public function filterSpec($target, Specification $spec, array $executionContext = []) { return $this->filter($target, $spec->getRule(), $spec->getParameters(), $executionContext); }
[ "public", "function", "filterSpec", "(", "$", "target", ",", "Specification", "$", "spec", ",", "array", "$", "executionContext", "=", "[", "]", ")", "{", "return", "$", "this", "->", "filter", "(", "$", "target", ",", "$", "spec", "->", "getRule", "("...
Filters a target using the given specification. The targetCompiler to use is determined at runtime using the registered ones. @param mixed $target The target to filter. @param Specification $spec The specification to apply. @param array $executionContext The execution context. @return mixed The filtered target. @throws TargetUnsupportedException
[ "Filters", "a", "target", "using", "the", "given", "specification", ".", "The", "targetCompiler", "to", "use", "is", "determined", "at", "runtime", "using", "the", "registered", "ones", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/RulerZ.php#L103-L106
K-Phoen/rulerz
src/RulerZ.php
RulerZ.applyFilterSpec
public function applyFilterSpec($target, Specification $spec, array $executionContext = []) { return $this->applyFilter($target, $spec->getRule(), $spec->getParameters(), $executionContext); }
php
public function applyFilterSpec($target, Specification $spec, array $executionContext = []) { return $this->applyFilter($target, $spec->getRule(), $spec->getParameters(), $executionContext); }
[ "public", "function", "applyFilterSpec", "(", "$", "target", ",", "Specification", "$", "spec", ",", "array", "$", "executionContext", "=", "[", "]", ")", "{", "return", "$", "this", "->", "applyFilter", "(", "$", "target", ",", "$", "spec", "->", "getRu...
Apply the filters on a target using the given specification. The targetCompiler to use is determined at runtime using the registered ones. @param mixed $target The target to filter. @param Specification $spec The specification to apply. @param array $executionContext The execution context. @return mixed @throws TargetUnsupportedException
[ "Apply", "the", "filters", "on", "a", "target", "using", "the", "given", "specification", ".", "The", "targetCompiler", "to", "use", "is", "determined", "at", "runtime", "using", "the", "registered", "ones", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/RulerZ.php#L120-L123
K-Phoen/rulerz
src/RulerZ.php
RulerZ.satisfies
public function satisfies($target, string $rule, array $parameters = [], array $executionContext = []): bool { $targetCompiler = $this->findTargetCompiler($target, CompilationTarget::MODE_SATISFIES); $compilationContext = $targetCompiler->createCompilationContext($target); $executor = $this->compiler->compile($rule, $targetCompiler, $compilationContext); return $executor->satisfies($target, $parameters, $targetCompiler->getOperators()->getOperators(), new ExecutionContext($executionContext)); }
php
public function satisfies($target, string $rule, array $parameters = [], array $executionContext = []): bool { $targetCompiler = $this->findTargetCompiler($target, CompilationTarget::MODE_SATISFIES); $compilationContext = $targetCompiler->createCompilationContext($target); $executor = $this->compiler->compile($rule, $targetCompiler, $compilationContext); return $executor->satisfies($target, $parameters, $targetCompiler->getOperators()->getOperators(), new ExecutionContext($executionContext)); }
[ "public", "function", "satisfies", "(", "$", "target", ",", "string", "$", "rule", ",", "array", "$", "parameters", "=", "[", "]", ",", "array", "$", "executionContext", "=", "[", "]", ")", ":", "bool", "{", "$", "targetCompiler", "=", "$", "this", "...
Tells if a target satisfies the given rule and parameters. The target compiler to use is determined at runtime using the registered ones. @param mixed $target The target. @param string $rule The rule to test. @param array $parameters The parameters used in the rule. @param array $executionContext The execution context. @throws TargetUnsupportedException
[ "Tells", "if", "a", "target", "satisfies", "the", "given", "rule", "and", "parameters", ".", "The", "target", "compiler", "to", "use", "is", "determined", "at", "runtime", "using", "the", "registered", "ones", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/RulerZ.php#L136-L143
K-Phoen/rulerz
src/RulerZ.php
RulerZ.satisfiesSpec
public function satisfiesSpec($target, Specification $spec, array $executionContext = []): bool { return $this->satisfies($target, $spec->getRule(), $spec->getParameters(), $executionContext); }
php
public function satisfiesSpec($target, Specification $spec, array $executionContext = []): bool { return $this->satisfies($target, $spec->getRule(), $spec->getParameters(), $executionContext); }
[ "public", "function", "satisfiesSpec", "(", "$", "target", ",", "Specification", "$", "spec", ",", "array", "$", "executionContext", "=", "[", "]", ")", ":", "bool", "{", "return", "$", "this", "->", "satisfies", "(", "$", "target", ",", "$", "spec", "...
Tells if a target satisfies the given specification. The target compiler to use is determined at runtime using the registered ones. @param mixed $target The target. @param Specification $spec The specification to use. @param array $executionContext The execution context. @throws TargetUnsupportedException
[ "Tells", "if", "a", "target", "satisfies", "the", "given", "specification", ".", "The", "target", "compiler", "to", "use", "is", "determined", "at", "runtime", "using", "the", "registered", "ones", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/RulerZ.php#L155-L158
K-Phoen/rulerz
src/RulerZ.php
RulerZ.findTargetCompiler
private function findTargetCompiler($target, $mode): CompilationTarget { /** @var CompilationTarget $targetCompiler */ foreach ($this->compilationTargets as $targetCompiler) { if ($targetCompiler->supports($target, $mode)) { return $targetCompiler; } } throw new TargetUnsupportedException('The given target is not supported.'); }
php
private function findTargetCompiler($target, $mode): CompilationTarget { /** @var CompilationTarget $targetCompiler */ foreach ($this->compilationTargets as $targetCompiler) { if ($targetCompiler->supports($target, $mode)) { return $targetCompiler; } } throw new TargetUnsupportedException('The given target is not supported.'); }
[ "private", "function", "findTargetCompiler", "(", "$", "target", ",", "$", "mode", ")", ":", "CompilationTarget", "{", "/** @var CompilationTarget $targetCompiler */", "foreach", "(", "$", "this", "->", "compilationTargets", "as", "$", "targetCompiler", ")", "{", "i...
Finds a target compiler supporting the given target. @param mixed $target The target to filter. @param string $mode The execution mode (MODE_FILTER or MODE_SATISFIES). @throws TargetUnsupportedException
[ "Finds", "a", "target", "compiler", "supporting", "the", "given", "target", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/RulerZ.php#L168-L178
K-Phoen/rulerz
src/Target/Operators/Definitions.php
Definitions.defineOperator
public function defineOperator(string $operator, callable $transformer): void { unset($this->inlineOperators[$operator]); $this->operators[$operator] = $transformer; }
php
public function defineOperator(string $operator, callable $transformer): void { unset($this->inlineOperators[$operator]); $this->operators[$operator] = $transformer; }
[ "public", "function", "defineOperator", "(", "string", "$", "operator", ",", "callable", "$", "transformer", ")", ":", "void", "{", "unset", "(", "$", "this", "->", "inlineOperators", "[", "$", "operator", "]", ")", ";", "$", "this", "->", "operators", "...
Define an operator. @param string $operator The operator's name. @param callable $transformer Callable.
[ "Define", "an", "operator", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/Operators/Definitions.php#L67-L71
K-Phoen/rulerz
src/Target/Operators/Definitions.php
Definitions.getOperator
protected function getOperator(string $operator): callable { if (!$this->hasOperator($operator)) { throw new OperatorNotFoundException($operator, sprintf('Operator "%s" does not exist.', $operator)); } return $this->operators[$operator]; }
php
protected function getOperator(string $operator): callable { if (!$this->hasOperator($operator)) { throw new OperatorNotFoundException($operator, sprintf('Operator "%s" does not exist.', $operator)); } return $this->operators[$operator]; }
[ "protected", "function", "getOperator", "(", "string", "$", "operator", ")", ":", "callable", "{", "if", "(", "!", "$", "this", "->", "hasOperator", "(", "$", "operator", ")", ")", "{", "throw", "new", "OperatorNotFoundException", "(", "$", "operator", ","...
Get an operator. @param string $operator The operator's name. @throws OperatorNotFoundException
[ "Get", "an", "operator", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/Operators/Definitions.php#L80-L87
K-Phoen/rulerz
src/Target/Operators/Definitions.php
Definitions.getInlineOperator
public function getInlineOperator(string $operator): callable { if (!$this->hasInlineOperator($operator)) { throw new OperatorNotFoundException($operator, sprintf('Inline operator "%s" does not exist.', $operator)); } return $this->inlineOperators[$operator]; }
php
public function getInlineOperator(string $operator): callable { if (!$this->hasInlineOperator($operator)) { throw new OperatorNotFoundException($operator, sprintf('Inline operator "%s" does not exist.', $operator)); } return $this->inlineOperators[$operator]; }
[ "public", "function", "getInlineOperator", "(", "string", "$", "operator", ")", ":", "callable", "{", "if", "(", "!", "$", "this", "->", "hasInlineOperator", "(", "$", "operator", ")", ")", "{", "throw", "new", "OperatorNotFoundException", "(", "$", "operato...
Gets an inline-able operator. @param string $operator The operator's name. @throws OperatorNotFoundException
[ "Gets", "an", "inline", "-", "able", "operator", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/Operators/Definitions.php#L106-L113
K-Phoen/rulerz
src/Target/Operators/Definitions.php
Definitions.defineInlineOperator
public function defineInlineOperator(string $operator, callable $transformer) { unset($this->operators[$operator]); $this->inlineOperators[$operator] = $transformer; }
php
public function defineInlineOperator(string $operator, callable $transformer) { unset($this->operators[$operator]); $this->inlineOperators[$operator] = $transformer; }
[ "public", "function", "defineInlineOperator", "(", "string", "$", "operator", ",", "callable", "$", "transformer", ")", "{", "unset", "(", "$", "this", "->", "operators", "[", "$", "operator", "]", ")", ";", "$", "this", "->", "inlineOperators", "[", "$", ...
Set an inline-able operator. @param string $operator The operator's name. @param callable $transformer Callable.
[ "Set", "an", "inline", "-", "able", "operator", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/Operators/Definitions.php#L143-L147
K-Phoen/rulerz
src/Visitor/Visitor.php
Visitor.visit
public function visit(VisitorElement $element, &$handle = null, $eldnah = null) { if ($element instanceof Model\Rule) { return $this->visitModel($element, $handle, $eldnah); } if ($element instanceof AST\Operator) { return $this->visitOperator($element, $handle, $eldnah); } if ($element instanceof AST\Bag\Scalar) { return $this->visitScalar($element, $handle, $eldnah); } if ($element instanceof AST\Bag\RulerArray) { return $this->visitArray($element, $handle, $eldnah); } if ($element instanceof AST\Bag\Context) { return $this->visitAccess($element, $handle, $eldnah); } if ($element instanceof Model\Parameter) { return $this->visitParameter($element, $handle, $eldnah); } throw new \LogicException(sprintf('Element of type "%s" not handled', get_class($element))); }
php
public function visit(VisitorElement $element, &$handle = null, $eldnah = null) { if ($element instanceof Model\Rule) { return $this->visitModel($element, $handle, $eldnah); } if ($element instanceof AST\Operator) { return $this->visitOperator($element, $handle, $eldnah); } if ($element instanceof AST\Bag\Scalar) { return $this->visitScalar($element, $handle, $eldnah); } if ($element instanceof AST\Bag\RulerArray) { return $this->visitArray($element, $handle, $eldnah); } if ($element instanceof AST\Bag\Context) { return $this->visitAccess($element, $handle, $eldnah); } if ($element instanceof Model\Parameter) { return $this->visitParameter($element, $handle, $eldnah); } throw new \LogicException(sprintf('Element of type "%s" not handled', get_class($element))); }
[ "public", "function", "visit", "(", "VisitorElement", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "if", "(", "$", "element", "instanceof", "Model", "\\", "Rule", ")", "{", "return", "$", "this", "-...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/Visitor.php#L18-L45
K-Phoen/rulerz
src/Visitor/Visitor.php
Visitor.visitModel
public function visitModel(AST\Model $element, &$handle = null, $eldnah = null) { return $element->getExpression()->accept($this, $handle, $eldnah); }
php
public function visitModel(AST\Model $element, &$handle = null, $eldnah = null) { return $element->getExpression()->accept($this, $handle, $eldnah); }
[ "public", "function", "visitModel", "(", "AST", "\\", "Model", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "return", "$", "element", "->", "getExpression", "(", ")", "->", "accept", "(", "$", "this...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/Visitor.php#L57-L60
K-Phoen/rulerz
src/Visitor/Visitor.php
Visitor.visitArray
public function visitArray(AST\Bag\RulerArray $element, &$handle = null, $eldnah = null) { return array_map(function ($item) use (&$handle, $eldnah) { return $item->accept($this, $handle, $eldnah); }, $element->getArray()); }
php
public function visitArray(AST\Bag\RulerArray $element, &$handle = null, $eldnah = null) { return array_map(function ($item) use (&$handle, $eldnah) { return $item->accept($this, $handle, $eldnah); }, $element->getArray()); }
[ "public", "function", "visitArray", "(", "AST", "\\", "Bag", "\\", "RulerArray", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "return", "array_map", "(", "function", "(", "$", "item", ")", "use", "(...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/Visitor.php#L72-L77
K-Phoen/rulerz
src/Visitor/Visitor.php
Visitor.visitOperator
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { // visit the arguments array_map(function ($argument) use (&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); }
php
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { // visit the arguments array_map(function ($argument) use (&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); }
[ "public", "function", "visitOperator", "(", "AST", "\\", "Operator", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "// visit the arguments", "array_map", "(", "function", "(", "$", "argument", ")", "use", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/Visitor.php#L82-L88
K-Phoen/rulerz
src/Target/GenericVisitor.php
GenericVisitor.visitScalar
public function visitScalar(AST\Bag\Scalar $element, &$handle = null, $eldnah = null) { return var_export($element->getValue(), true); }
php
public function visitScalar(AST\Bag\Scalar $element, &$handle = null, $eldnah = null) { return var_export($element->getValue(), true); }
[ "public", "function", "visitScalar", "(", "AST", "\\", "Bag", "\\", "Scalar", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "return", "var_export", "(", "$", "element", "->", "getValue", "(", ")", ",...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/GenericVisitor.php#L83-L86
K-Phoen/rulerz
src/Target/GenericVisitor.php
GenericVisitor.visitOperator
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { $operatorName = $element->getName(); // the operator does not exist at all, throw an error before doing anything else. if (!$this->operators->hasInlineOperator($operatorName) && !$this->operators->hasOperator($operatorName)) { throw new OperatorNotFoundException($operatorName, sprintf('Operator "%s" does not exist.', $operatorName)); } // expand the arguments $arguments = array_map(function ($argument) use (&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); // and either inline the operator call if ($this->operators->hasInlineOperator($operatorName)) { $callable = $this->operators->getInlineOperator($operatorName); return call_user_func_array($callable, $arguments); } $inlinedArguments = empty($arguments) ? '' : ', '.implode(', ', $arguments); // or defer it. return sprintf('call_user_func($operators["%s"]%s)', $operatorName, $inlinedArguments); }
php
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { $operatorName = $element->getName(); // the operator does not exist at all, throw an error before doing anything else. if (!$this->operators->hasInlineOperator($operatorName) && !$this->operators->hasOperator($operatorName)) { throw new OperatorNotFoundException($operatorName, sprintf('Operator "%s" does not exist.', $operatorName)); } // expand the arguments $arguments = array_map(function ($argument) use (&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); // and either inline the operator call if ($this->operators->hasInlineOperator($operatorName)) { $callable = $this->operators->getInlineOperator($operatorName); return call_user_func_array($callable, $arguments); } $inlinedArguments = empty($arguments) ? '' : ', '.implode(', ', $arguments); // or defer it. return sprintf('call_user_func($operators["%s"]%s)', $operatorName, $inlinedArguments); }
[ "public", "function", "visitOperator", "(", "AST", "\\", "Operator", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "$", "operatorName", "=", "$", "element", "->", "getName", "(", ")", ";", "// the oper...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/GenericVisitor.php#L101-L126
K-Phoen/rulerz
src/Executor/ArrayTarget/SatisfiesTrait.php
SatisfiesTrait.satisfies
public function satisfies($target, array $parameters, array $operators, ExecutionContext $context): bool { $wrappedTarget = is_array($target) ? $target : new ObjectContext($target); return $this->execute($wrappedTarget, $operators, $parameters); }
php
public function satisfies($target, array $parameters, array $operators, ExecutionContext $context): bool { $wrappedTarget = is_array($target) ? $target : new ObjectContext($target); return $this->execute($wrappedTarget, $operators, $parameters); }
[ "public", "function", "satisfies", "(", "$", "target", ",", "array", "$", "parameters", ",", "array", "$", "operators", ",", "ExecutionContext", "$", "context", ")", ":", "bool", "{", "$", "wrappedTarget", "=", "is_array", "(", "$", "target", ")", "?", "...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Executor/ArrayTarget/SatisfiesTrait.php#L17-L22
K-Phoen/rulerz
src/Target/Native/NativeVisitor.php
NativeVisitor.visitAccess
public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $flattenedDimensions = [ sprintf('["%s"]', $element->getId()), ]; foreach ($element->getDimensions() as $dimension) { $flattenedDimensions[] = sprintf('["%s"]', $dimension[AST\Bag\Context::ACCESS_VALUE]); } return sprintf('$this->unwrapArgument($target%s)', implode('', $flattenedDimensions)); }
php
public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $flattenedDimensions = [ sprintf('["%s"]', $element->getId()), ]; foreach ($element->getDimensions() as $dimension) { $flattenedDimensions[] = sprintf('["%s"]', $dimension[AST\Bag\Context::ACCESS_VALUE]); } return sprintf('$this->unwrapArgument($target%s)', implode('', $flattenedDimensions)); }
[ "public", "function", "visitAccess", "(", "AST", "\\", "Bag", "\\", "Context", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "$", "flattenedDimensions", "=", "[", "sprintf", "(", "'[\"%s\"]'", ",", "$"...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/Native/NativeVisitor.php#L17-L28
K-Phoen/rulerz
src/Target/GenericSqlVisitor.php
GenericSqlVisitor.visitModel
public function visitModel(AST\Model $element, &$handle = null, $eldnah = null) { $sql = parent::visitModel($element, $handle, $eldnah); return '"'.$sql.'"'; }
php
public function visitModel(AST\Model $element, &$handle = null, $eldnah = null) { $sql = parent::visitModel($element, $handle, $eldnah); return '"'.$sql.'"'; }
[ "public", "function", "visitModel", "(", "AST", "\\", "Model", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "$", "sql", "=", "parent", "::", "visitModel", "(", "$", "element", ",", "$", "handle", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/GenericSqlVisitor.php#L47-L52
K-Phoen/rulerz
src/Target/GenericSqlVisitor.php
GenericSqlVisitor.visitArray
public function visitArray(AST\Bag\RulerArray $element, &$handle = null, $eldnah = null) { $array = parent::visitArray($element, $handle, $eldnah); return sprintf('(%s)', implode(', ', $array)); }
php
public function visitArray(AST\Bag\RulerArray $element, &$handle = null, $eldnah = null) { $array = parent::visitArray($element, $handle, $eldnah); return sprintf('(%s)', implode(', ', $array)); }
[ "public", "function", "visitArray", "(", "AST", "\\", "Bag", "\\", "RulerArray", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "$", "array", "=", "parent", "::", "visitArray", "(", "$", "element", ",...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/GenericSqlVisitor.php#L74-L79
K-Phoen/rulerz
src/Target/GenericSqlVisitor.php
GenericSqlVisitor.visitOperator
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { try { return parent::visitOperator($element, $handle, $eldnah); } catch (OperatorNotFoundException $e) { if (!$this->allowStarOperator) { throw $e; } } $arguments = array_map(function ($argument) use (&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); return sprintf('%s(%s)', $element->getName(), implode(', ', $arguments)); }
php
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { try { return parent::visitOperator($element, $handle, $eldnah); } catch (OperatorNotFoundException $e) { if (!$this->allowStarOperator) { throw $e; } } $arguments = array_map(function ($argument) use (&$handle, $eldnah) { return $argument->accept($this, $handle, $eldnah); }, $element->getArguments()); return sprintf('%s(%s)', $element->getName(), implode(', ', $arguments)); }
[ "public", "function", "visitOperator", "(", "AST", "\\", "Operator", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "try", "{", "return", "parent", "::", "visitOperator", "(", "$", "element", ",", "$", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/GenericSqlVisitor.php#L84-L99
K-Phoen/rulerz
src/Spec/Composite.php
Composite.getRule
public function getRule(): string { return implode(sprintf(' %s ', $this->operator), array_map(function (Specification $specification) { return sprintf('(%s)', $specification->getRule()); }, $this->specifications)); }
php
public function getRule(): string { return implode(sprintf(' %s ', $this->operator), array_map(function (Specification $specification) { return sprintf('(%s)', $specification->getRule()); }, $this->specifications)); }
[ "public", "function", "getRule", "(", ")", ":", "string", "{", "return", "implode", "(", "sprintf", "(", "' %s '", ",", "$", "this", "->", "operator", ")", ",", "array_map", "(", "function", "(", "Specification", "$", "specification", ")", "{", "return", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Spec/Composite.php#L51-L56
K-Phoen/rulerz
src/Spec/Composite.php
Composite.getParameters
public function getParameters(): array { $parametersCount = 0; $parametersList = array_map(function (Specification $specification) use (&$parametersCount) { $parametersCount += count($specification->getParameters()); return $specification->getParameters(); }, $this->specifications); $mergedParameters = array_merge([], ...$parametersList); // error handling in case of overriden parameters if ($parametersCount !== count($mergedParameters)) { $overridenParameters = $this->searchOverridenParameters($parametersList); $specificationsTypes = array_map(function (Specification $spec) { return get_class($spec); }, $this->specifications); throw new ParameterOverridenException(sprintf( 'Looks like some parameters were overriden (%s) while combining specifications of types %s'."\n". 'More information on how to solve this can be found here: https://github.com/K-Phoen/rulerz/issues/3', implode(', ', $overridenParameters), implode(', ', $specificationsTypes) )); } return $mergedParameters; }
php
public function getParameters(): array { $parametersCount = 0; $parametersList = array_map(function (Specification $specification) use (&$parametersCount) { $parametersCount += count($specification->getParameters()); return $specification->getParameters(); }, $this->specifications); $mergedParameters = array_merge([], ...$parametersList); // error handling in case of overriden parameters if ($parametersCount !== count($mergedParameters)) { $overridenParameters = $this->searchOverridenParameters($parametersList); $specificationsTypes = array_map(function (Specification $spec) { return get_class($spec); }, $this->specifications); throw new ParameterOverridenException(sprintf( 'Looks like some parameters were overriden (%s) while combining specifications of types %s'."\n". 'More information on how to solve this can be found here: https://github.com/K-Phoen/rulerz/issues/3', implode(', ', $overridenParameters), implode(', ', $specificationsTypes) )); } return $mergedParameters; }
[ "public", "function", "getParameters", "(", ")", ":", "array", "{", "$", "parametersCount", "=", "0", ";", "$", "parametersList", "=", "array_map", "(", "function", "(", "Specification", "$", "specification", ")", "use", "(", "&", "$", "parametersCount", ")"...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Spec/Composite.php#L61-L89
K-Phoen/rulerz
src/Spec/Composite.php
Composite.searchOverridenParameters
private function searchOverridenParameters(array $parametersList): array { $parametersUsageCount = []; foreach ($parametersList as $list) { foreach ($list as $parameter => $_value) { if (!isset($parametersUsageCount[$parameter])) { $parametersUsageCount[$parameter] = 0; } $parametersUsageCount[$parameter] += 1; } } $overriddenParameters = array_filter($parametersUsageCount, function ($count) { return $count > 1; }); return array_keys($overriddenParameters); }
php
private function searchOverridenParameters(array $parametersList): array { $parametersUsageCount = []; foreach ($parametersList as $list) { foreach ($list as $parameter => $_value) { if (!isset($parametersUsageCount[$parameter])) { $parametersUsageCount[$parameter] = 0; } $parametersUsageCount[$parameter] += 1; } } $overriddenParameters = array_filter($parametersUsageCount, function ($count) { return $count > 1; }); return array_keys($overriddenParameters); }
[ "private", "function", "searchOverridenParameters", "(", "array", "$", "parametersList", ")", ":", "array", "{", "$", "parametersUsageCount", "=", "[", "]", ";", "foreach", "(", "$", "parametersList", "as", "$", "list", ")", "{", "foreach", "(", "$", "list",...
Search the parameters that were overridden during the parameters-merge phase. @return array Names of the overridden parameters.
[ "Search", "the", "parameters", "that", "were", "overridden", "during", "the", "parameters", "-", "merge", "phase", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Spec/Composite.php#L96-L115
K-Phoen/rulerz
src/Visitor/OperatorCollectorVisitor.php
OperatorCollectorVisitor.visitOperator
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { parent::visitOperator($element, $handle, $eldnah); $this->operators[] = $element; }
php
public function visitOperator(AST\Operator $element, &$handle = null, $eldnah = null) { parent::visitOperator($element, $handle, $eldnah); $this->operators[] = $element; }
[ "public", "function", "visitOperator", "(", "AST", "\\", "Operator", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "parent", "::", "visitOperator", "(", "$", "element", ",", "$", "handle", ",", "$", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/OperatorCollectorVisitor.php#L39-L44
K-Phoen/rulerz
src/Parser/Parser.php
Parser.parse
public function parse($rule) { if ($this->parser === null) { $this->parser = Compiler\Llk::load( new File\Read(__DIR__.'/../Grammar.pp') ); } $this->nextParameterIndex = 0; return $this->visit($this->parser->parse($rule)); }
php
public function parse($rule) { if ($this->parser === null) { $this->parser = Compiler\Llk::load( new File\Read(__DIR__.'/../Grammar.pp') ); } $this->nextParameterIndex = 0; return $this->visit($this->parser->parse($rule)); }
[ "public", "function", "parse", "(", "$", "rule", ")", "{", "if", "(", "$", "this", "->", "parser", "===", "null", ")", "{", "$", "this", "->", "parser", "=", "Compiler", "\\", "Llk", "::", "load", "(", "new", "File", "\\", "Read", "(", "__DIR__", ...
Parses the rule into an equivalent AST. @param string $rule The rule represented as a string. @return \RulerZ\Model\Rule
[ "Parses", "the", "rule", "into", "an", "equivalent", "AST", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Parser/Parser.php#L59-L70
K-Phoen/rulerz
src/Parser/Parser.php
Parser.visit
public function visit(Visitor\Element $element, &$handle = null, $eldnah = null) { /** @var \Hoa\Compiler\Llk\TreeNode $element */ $id = $element->getId(); $variable = false !== $eldnah; switch ($id) { case '#expression': $this->root = new Model\Rule(); $this->root->expression = $element->getChild(0)->accept( $this, $handle, $eldnah ); return $this->root; case '#operation': $children = $element->getChildren(); $left = $children[0]->accept($this, $handle, $eldnah); $right = $children[2]->accept($this, $handle, $eldnah); $name = $children[1]->accept($this, $handle, false); return $this->root->_operator( $name, [$left, $right], false ); case '#variable_access': $children = $element->getChildren(); $name = $children[0]->accept($this, $handle, $eldnah); array_shift($children); foreach ($children as $child) { $_child = $child->accept($this, $handle, $eldnah); switch ($child->getId()) { case '#attribute_access': $name->attribute($_child); break; } } return $name; case '#attribute_access': return $element->getChild(0)->accept($this, $handle, false); case '#array_declaration': $out = []; foreach ($element->getChildren() as $child) { $out[] = $child->accept($this, $handle, $eldnah); } return $out; case '#function_call': $children = $element->getChildren(); $name = $children[0]->accept($this, $handle, false); array_shift($children); $arguments = []; foreach ($children as $child) { $arguments[] = $child->accept($this, $handle, $eldnah); } return $this->root->_operator( $name, $arguments, true ); case '#and': case '#or': case '#xor': $name = substr($id, 1); $children = $element->getChildren(); $left = $children[0]->accept($this, $handle, $eldnah); $right = $children[1]->accept($this, $handle, $eldnah); return $this->root->operation($name, [$left, $right]); case '#not': return $this->root->operation( 'not', [$element->getChild(0)->accept($this, $handle, $eldnah)] ); case 'token': $token = $element->getValueToken(); $value = $element->getValueValue(); switch ($token) { case 'identifier': return true === $variable ? $this->root->variable($value) : $value; case 'named_parameter': return new Model\Parameter(substr($value, 1)); case 'positional_parameter': $index = $this->nextParameterIndex++; return new Model\Parameter($index); case 'true': return true; case 'false': return false; case 'null': return null; case 'float': return (float) $value; case 'integer': return (int) $value; case 'string': return str_replace( '\\'.$value[0], $value[0], substr($value, 1, -1) ); default: throw new Ruler\Exception\Interpreter('Token %s is unknown.', 0, $token); } default: throw new Ruler\Exception\Interpreter('Element %s is unknown.', 1, $id); } }
php
public function visit(Visitor\Element $element, &$handle = null, $eldnah = null) { /** @var \Hoa\Compiler\Llk\TreeNode $element */ $id = $element->getId(); $variable = false !== $eldnah; switch ($id) { case '#expression': $this->root = new Model\Rule(); $this->root->expression = $element->getChild(0)->accept( $this, $handle, $eldnah ); return $this->root; case '#operation': $children = $element->getChildren(); $left = $children[0]->accept($this, $handle, $eldnah); $right = $children[2]->accept($this, $handle, $eldnah); $name = $children[1]->accept($this, $handle, false); return $this->root->_operator( $name, [$left, $right], false ); case '#variable_access': $children = $element->getChildren(); $name = $children[0]->accept($this, $handle, $eldnah); array_shift($children); foreach ($children as $child) { $_child = $child->accept($this, $handle, $eldnah); switch ($child->getId()) { case '#attribute_access': $name->attribute($_child); break; } } return $name; case '#attribute_access': return $element->getChild(0)->accept($this, $handle, false); case '#array_declaration': $out = []; foreach ($element->getChildren() as $child) { $out[] = $child->accept($this, $handle, $eldnah); } return $out; case '#function_call': $children = $element->getChildren(); $name = $children[0]->accept($this, $handle, false); array_shift($children); $arguments = []; foreach ($children as $child) { $arguments[] = $child->accept($this, $handle, $eldnah); } return $this->root->_operator( $name, $arguments, true ); case '#and': case '#or': case '#xor': $name = substr($id, 1); $children = $element->getChildren(); $left = $children[0]->accept($this, $handle, $eldnah); $right = $children[1]->accept($this, $handle, $eldnah); return $this->root->operation($name, [$left, $right]); case '#not': return $this->root->operation( 'not', [$element->getChild(0)->accept($this, $handle, $eldnah)] ); case 'token': $token = $element->getValueToken(); $value = $element->getValueValue(); switch ($token) { case 'identifier': return true === $variable ? $this->root->variable($value) : $value; case 'named_parameter': return new Model\Parameter(substr($value, 1)); case 'positional_parameter': $index = $this->nextParameterIndex++; return new Model\Parameter($index); case 'true': return true; case 'false': return false; case 'null': return null; case 'float': return (float) $value; case 'integer': return (int) $value; case 'string': return str_replace( '\\'.$value[0], $value[0], substr($value, 1, -1) ); default: throw new Ruler\Exception\Interpreter('Token %s is unknown.', 0, $token); } default: throw new Ruler\Exception\Interpreter('Element %s is unknown.', 1, $id); } }
[ "public", "function", "visit", "(", "Visitor", "\\", "Element", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "/** @var \\Hoa\\Compiler\\Llk\\TreeNode $element */", "$", "id", "=", "$", "element", "->", "get...
Visit an element. @param \Hoa\Visitor\Element $element Element to visit. @param mixed &$handle Handle (reference). @param mixed $eldnah Handle (not reference). @return \RulerZ\Model\Rule @throws \Hoa\Ruler\Exception\Interpreter
[ "Visit", "an", "element", "." ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Parser/Parser.php#L83-L221
K-Phoen/rulerz
src/Visitor/AccessCollectorVisitor.php
AccessCollectorVisitor.visitAccess
public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $this->accesses[] = $element; }
php
public function visitAccess(AST\Bag\Context $element, &$handle = null, $eldnah = null) { $this->accesses[] = $element; }
[ "public", "function", "visitAccess", "(", "AST", "\\", "Bag", "\\", "Context", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "$", "this", "->", "accesses", "[", "]", "=", "$", "element", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/AccessCollectorVisitor.php#L29-L32
K-Phoen/rulerz
src/Target/Native/Native.php
Native.supports
public function supports($target, string $mode): bool { if ($mode === self::MODE_APPLY_FILTER) { return false; } // we can filter a collection if ($mode === self::MODE_FILTER) { return is_array($target) || $target instanceof \Traversable; } // and we know how to handle arrays and objects return is_array($target) || is_object($target); }
php
public function supports($target, string $mode): bool { if ($mode === self::MODE_APPLY_FILTER) { return false; } // we can filter a collection if ($mode === self::MODE_FILTER) { return is_array($target) || $target instanceof \Traversable; } // and we know how to handle arrays and objects return is_array($target) || is_object($target); }
[ "public", "function", "supports", "(", "$", "target", ",", "string", "$", "mode", ")", ":", "bool", "{", "if", "(", "$", "mode", "===", "self", "::", "MODE_APPLY_FILTER", ")", "{", "return", "false", ";", "}", "// we can filter a collection", "if", "(", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Target/Native/Native.php#L19-L32
K-Phoen/rulerz
src/Visitor/ParameterCollectorVisitor.php
ParameterCollectorVisitor.visitParameter
public function visitParameter(Model\Parameter $element, &$handle = null, $eldnah = null) { $this->parameters[$element->getName()] = $element; }
php
public function visitParameter(Model\Parameter $element, &$handle = null, $eldnah = null) { $this->parameters[$element->getName()] = $element; }
[ "public", "function", "visitParameter", "(", "Model", "\\", "Parameter", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "$", "this", "->", "parameters", "[", "$", "element", "->", "getName", "(", ")", ...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/ParameterCollectorVisitor.php#L30-L33
K-Phoen/rulerz
src/Visitor/ParameterCollectorVisitor.php
ParameterCollectorVisitor.visitModel
public function visitModel(AST\Model $element, &$handle = null, $eldnah = null) { parent::visitModel($element, $handle, $eldnah); return $this->parameters; }
php
public function visitModel(AST\Model $element, &$handle = null, $eldnah = null) { parent::visitModel($element, $handle, $eldnah); return $this->parameters; }
[ "public", "function", "visitModel", "(", "AST", "\\", "Model", "$", "element", ",", "&", "$", "handle", "=", "null", ",", "$", "eldnah", "=", "null", ")", "{", "parent", "::", "visitModel", "(", "$", "element", ",", "$", "handle", ",", "$", "eldnah",...
{@inheritdoc}
[ "{" ]
train
https://github.com/K-Phoen/rulerz/blob/5c26c4f99636e4e7e464f1b28c8054b059347534/src/Visitor/ParameterCollectorVisitor.php#L38-L43
podio-community/podio-php
models/PodioItemCollection.php
PodioItemCollection.offsetSet
public function offsetSet($offset, $value) { if (!is_a($value, 'PodioItem')) { throw new PodioDataIntegrityError("Objects in PodioItemCollection must be of class PodioItem"); } parent::offsetSet($offset, $value); }
php
public function offsetSet($offset, $value) { if (!is_a($value, 'PodioItem')) { throw new PodioDataIntegrityError("Objects in PodioItemCollection must be of class PodioItem"); } parent::offsetSet($offset, $value); }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "if", "(", "!", "is_a", "(", "$", "value", ",", "'PodioItem'", ")", ")", "{", "throw", "new", "PodioDataIntegrityError", "(", "\"Objects in PodioItemCollection must be of class P...
Array access
[ "Array", "access" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioItemCollection.php#L19-L24
podio-community/podio-php
lib/Podio.php
Podio.set_debug
public static function set_debug($toggle, $output = "stdout") { if ($toggle) { self::$debug = $output; } else { self::$debug = false; } }
php
public static function set_debug($toggle, $output = "stdout") { if ($toggle) { self::$debug = $output; } else { self::$debug = false; } }
[ "public", "static", "function", "set_debug", "(", "$", "toggle", ",", "$", "output", "=", "\"stdout\"", ")", "{", "if", "(", "$", "toggle", ")", "{", "self", "::", "$", "debug", "=", "$", "output", ";", "}", "else", "{", "self", "::", "$", "debug",...
Set debug config @param $toggle True to enable debugging. False to disable @param $output Output mode. Can be "stdout" or "file". Default is "stdout"
[ "Set", "debug", "config" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/lib/Podio.php#L423-L430
podio-community/podio-php
models/PodioAppFieldCollection.php
PodioAppFieldCollection.offsetSet
public function offsetSet($offset, $field) { if (!is_a($field, 'PodioAppField')) { throw new PodioDataIntegrityError("Objects in PodioAppFieldCollection must be of class PodioAppField"); } parent::offsetSet($offset, $field); }
php
public function offsetSet($offset, $field) { if (!is_a($field, 'PodioAppField')) { throw new PodioDataIntegrityError("Objects in PodioAppFieldCollection must be of class PodioAppField"); } parent::offsetSet($offset, $field); }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "field", ")", "{", "if", "(", "!", "is_a", "(", "$", "field", ",", "'PodioAppField'", ")", ")", "{", "throw", "new", "PodioDataIntegrityError", "(", "\"Objects in PodioAppFieldCollection must be of...
Array access. Add field to collection.
[ "Array", "access", ".", "Add", "field", "to", "collection", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioAppFieldCollection.php#L29-L36
podio-community/podio-php
models/PodioFile.php
PodioFile.get_raw
public function get_raw($size = null) { return Podio::get($this->get_download_link($size), array(), array('file_download' => true))->body; }
php
public function get_raw($size = null) { return Podio::get($this->get_download_link($size), array(), array('file_download' => true))->body; }
[ "public", "function", "get_raw", "(", "$", "size", "=", "null", ")", "{", "return", "Podio", "::", "get", "(", "$", "this", "->", "get_download_link", "(", "$", "size", ")", ",", "array", "(", ")", ",", "array", "(", "'file_download'", "=>", "true", ...
Returns the raw bytes of a file. Beware: This is not a static method. It can only be used after you have a PodioFile object.
[ "Returns", "the", "raw", "bytes", "of", "a", "file", ".", "Beware", ":", "This", "is", "not", "a", "static", "method", ".", "It", "can", "only", "be", "used", "after", "you", "have", "a", "PodioFile", "object", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioFile.php#L35-L37
podio-community/podio-php
models/PodioFile.php
PodioFile.get_raw_as_resource
public function get_raw_as_resource($size = null) { return Podio::get($this->get_download_link($size), array(), array('file_download' => true, 'return_raw_as_resource_only' => true)); }
php
public function get_raw_as_resource($size = null) { return Podio::get($this->get_download_link($size), array(), array('file_download' => true, 'return_raw_as_resource_only' => true)); }
[ "public", "function", "get_raw_as_resource", "(", "$", "size", "=", "null", ")", "{", "return", "Podio", "::", "get", "(", "$", "this", "->", "get_download_link", "(", "$", "size", ")", ",", "array", "(", ")", ",", "array", "(", "'file_download'", "=>", ...
Returns the raw bytes of a file. Beware: This is not a static method. It can only be used after you have a PodioFile object. In contrast to get_raw this method does use minimal memory (the result is stored in php://temp) @return resource pointing at start of body (use fseek($resource, 0) to get headers as well)
[ "Returns", "the", "raw", "bytes", "of", "a", "file", ".", "Beware", ":", "This", "is", "not", "a", "static", "method", ".", "It", "can", "only", "be", "used", "after", "you", "have", "a", "PodioFile", "object", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioFile.php#L46-L48
podio-community/podio-php
models/PodioItem.php
PodioItem.save
public function save($options = array()) { $json_attributes = $this->as_json_without_readonly_fields(); if ($this->id) { return self::update($this->id, $json_attributes, $options); } else { if ($this->app && $this->app->id) { $new = self::create($this->app->id, $json_attributes, $options); $this->item_id = $new->item_id; return $this; } else { throw new PodioMissingRelationshipError('{"error_description":"Item is missing relationship to app"}', null, null); } } }
php
public function save($options = array()) { $json_attributes = $this->as_json_without_readonly_fields(); if ($this->id) { return self::update($this->id, $json_attributes, $options); } else { if ($this->app && $this->app->id) { $new = self::create($this->app->id, $json_attributes, $options); $this->item_id = $new->item_id; return $this; } else { throw new PodioMissingRelationshipError('{"error_description":"Item is missing relationship to app"}', null, null); } } }
[ "public", "function", "save", "(", "$", "options", "=", "array", "(", ")", ")", "{", "$", "json_attributes", "=", "$", "this", "->", "as_json_without_readonly_fields", "(", ")", ";", "if", "(", "$", "this", "->", "id", ")", "{", "return", "self", "::",...
Create or updates an item
[ "Create", "or", "updates", "an", "item" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioItem.php#L62-L78
podio-community/podio-php
models/PodioItem.php
PodioItem.as_json_without_readonly_fields
public function as_json_without_readonly_fields() { $readonly_fields = $this->fields->readonly_fields()->external_ids(); $json_attributes = $this->as_json(false); foreach ($this->fields->readonly_fields()->external_ids() as $external_id) { if (isset($json_attributes['fields'][$external_id])) { unset($json_attributes['fields'][$external_id]); } } return $json_attributes; }
php
public function as_json_without_readonly_fields() { $readonly_fields = $this->fields->readonly_fields()->external_ids(); $json_attributes = $this->as_json(false); foreach ($this->fields->readonly_fields()->external_ids() as $external_id) { if (isset($json_attributes['fields'][$external_id])) { unset($json_attributes['fields'][$external_id]); } } return $json_attributes; }
[ "public", "function", "as_json_without_readonly_fields", "(", ")", "{", "$", "readonly_fields", "=", "$", "this", "->", "fields", "->", "readonly_fields", "(", ")", "->", "external_ids", "(", ")", ";", "$", "json_attributes", "=", "$", "this", "->", "as_json",...
Return json representation without readonly fields. Used for saving items.
[ "Return", "json", "representation", "without", "readonly", "fields", ".", "Used", "for", "saving", "items", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioItem.php#L83-L92
podio-community/podio-php
lib/PodioObject.php
PodioObject.property
public function property($name, $type, $options = array()) { if (!$this->has_property($name)) { $this->__properties[$name] = array('type' => $type, 'options' => $options); } }
php
public function property($name, $type, $options = array()) { if (!$this->has_property($name)) { $this->__properties[$name] = array('type' => $type, 'options' => $options); } }
[ "public", "function", "property", "(", "$", "name", ",", "$", "type", ",", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "$", "this", "->", "has_property", "(", "$", "name", ")", ")", "{", "$", "this", "->", "__properties", "[...
Define a property on this object
[ "Define", "a", "property", "on", "this", "object" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/lib/PodioObject.php#L253-L257
podio-community/podio-php
models/PodioTask.php
PodioTask.save
public function save() { if ($this->id) { return self::update($this->id, $this); } else { $new = self::create($this); $this->task_id = $new->task_id; return $this; } }
php
public function save() { if ($this->id) { return self::update($this->id, $this); } else { $new = self::create($this); $this->task_id = $new->task_id; return $this; } }
[ "public", "function", "save", "(", ")", "{", "if", "(", "$", "this", "->", "id", ")", "{", "return", "self", "::", "update", "(", "$", "this", "->", "id", ",", "$", "this", ")", ";", "}", "else", "{", "$", "new", "=", "self", "::", "create", ...
Creates or updates a task
[ "Creates", "or", "updates", "a", "task" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioTask.php#L41-L50
podio-community/podio-php
lib/PodioCollection.php
PodioCollection.offsetSet
public function offsetSet($offset, $value) { if (!is_a($value, 'PodioObject')) { throw new PodioDataIntegrityError("Objects in PodioCollection must be of class PodioObject"); } // If the collection has a relationship with a parent, add it to the item as well. $relationship = $this->relationship(); if ($relationship) { $value->add_relationship($relationship['instance'], $relationship['property']); } if (is_null($offset)) { $this->__items[] = $value; } else { $this->__items[$offset] = $value; } }
php
public function offsetSet($offset, $value) { if (!is_a($value, 'PodioObject')) { throw new PodioDataIntegrityError("Objects in PodioCollection must be of class PodioObject"); } // If the collection has a relationship with a parent, add it to the item as well. $relationship = $this->relationship(); if ($relationship) { $value->add_relationship($relationship['instance'], $relationship['property']); } if (is_null($offset)) { $this->__items[] = $value; } else { $this->__items[$offset] = $value; } }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "value", ")", "{", "if", "(", "!", "is_a", "(", "$", "value", ",", "'PodioObject'", ")", ")", "{", "throw", "new", "PodioDataIntegrityError", "(", "\"Objects in PodioCollection must be of class Pod...
Array access. Set item by offset, automatically adding relationship.
[ "Array", "access", ".", "Set", "item", "by", "offset", "automatically", "adding", "relationship", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/lib/PodioCollection.php#L48-L65
podio-community/podio-php
lib/PodioCollection.php
PodioCollection.offsetGet
public function offsetGet($offset) { return isset($this->__items[$offset]) ? $this->__items[$offset] : null; }
php
public function offsetGet($offset) { return isset($this->__items[$offset]) ? $this->__items[$offset] : null; }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "return", "isset", "(", "$", "this", "->", "__items", "[", "$", "offset", "]", ")", "?", "$", "this", "->", "__items", "[", "$", "offset", "]", ":", "null", ";", "}" ]
Array access. Get.
[ "Array", "access", ".", "Get", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/lib/PodioCollection.php#L84-L86
podio-community/podio-php
lib/PodioCollection.php
PodioCollection.add_relationship
public function add_relationship($instance, $property = 'fields') { $this->__belongs_to = array('property' => $property, 'instance' => $instance); // Add relationship to all individual fields as well. foreach ($this as $item) { if ($item->has_property($property)) { $item->add_relationship($instance, $property); } } }
php
public function add_relationship($instance, $property = 'fields') { $this->__belongs_to = array('property' => $property, 'instance' => $instance); // Add relationship to all individual fields as well. foreach ($this as $item) { if ($item->has_property($property)) { $item->add_relationship($instance, $property); } } }
[ "public", "function", "add_relationship", "(", "$", "instance", ",", "$", "property", "=", "'fields'", ")", "{", "$", "this", "->", "__belongs_to", "=", "array", "(", "'property'", "=>", "$", "property", ",", "'instance'", "=>", "$", "instance", ")", ";", ...
Add a new relationship to a parent object. Will also add relationship to all individual objects in the collection.
[ "Add", "a", "new", "relationship", "to", "a", "parent", "object", ".", "Will", "also", "add", "relationship", "to", "all", "individual", "objects", "in", "the", "collection", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/lib/PodioCollection.php#L113-L122
podio-community/podio-php
lib/PodioCollection.php
PodioCollection.get
public function get($id_or_external_id) { $key = is_int($id_or_external_id) ? 'id' : 'external_id'; foreach ($this as $item) { if ($item->{$key} === $id_or_external_id) { return $item; } } return null; }
php
public function get($id_or_external_id) { $key = is_int($id_or_external_id) ? 'id' : 'external_id'; foreach ($this as $item) { if ($item->{$key} === $id_or_external_id) { return $item; } } return null; }
[ "public", "function", "get", "(", "$", "id_or_external_id", ")", "{", "$", "key", "=", "is_int", "(", "$", "id_or_external_id", ")", "?", "'id'", ":", "'external_id'", ";", "foreach", "(", "$", "this", "as", "$", "item", ")", "{", "if", "(", "$", "it...
Get object in the collection by id or external_id.
[ "Get", "object", "in", "the", "collection", "by", "id", "or", "external_id", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/lib/PodioCollection.php#L127-L135
podio-community/podio-php
lib/PodioCollection.php
PodioCollection.remove
public function remove($id_or_external_id) { if (count($this) === 0) { return true; } $this->_set_items(array_filter($this->_get_items(), function($item) use ($id_or_external_id) { return !($item->id == $id_or_external_id || $item->external_id == $id_or_external_id); })); }
php
public function remove($id_or_external_id) { if (count($this) === 0) { return true; } $this->_set_items(array_filter($this->_get_items(), function($item) use ($id_or_external_id) { return !($item->id == $id_or_external_id || $item->external_id == $id_or_external_id); })); }
[ "public", "function", "remove", "(", "$", "id_or_external_id", ")", "{", "if", "(", "count", "(", "$", "this", ")", "===", "0", ")", "{", "return", "true", ";", "}", "$", "this", "->", "_set_items", "(", "array_filter", "(", "$", "this", "->", "_get_...
Remove object from collection by id or external_id.
[ "Remove", "object", "from", "collection", "by", "id", "or", "external_id", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/lib/PodioCollection.php#L140-L147
podio-community/podio-php
models/PodioFieldCollection.php
PodioFieldCollection.offsetSet
public function offsetSet($offset, $field) { // Allow you to set external id in the array offset. // E.g. $collection['external_id'] = $field; if (is_string($offset)) { $field->external_id = $offset; $offset = null; } if (!$field->id && !$field->external_id) { throw new PodioDataIntegrityError('Field must have id or external_id set.'); } // Remove any existing field with this id $this->remove($field->id ? $field->id : $field->external_id); // Add to internal storage parent::offsetSet($offset, $field); }
php
public function offsetSet($offset, $field) { // Allow you to set external id in the array offset. // E.g. $collection['external_id'] = $field; if (is_string($offset)) { $field->external_id = $offset; $offset = null; } if (!$field->id && !$field->external_id) { throw new PodioDataIntegrityError('Field must have id or external_id set.'); } // Remove any existing field with this id $this->remove($field->id ? $field->id : $field->external_id); // Add to internal storage parent::offsetSet($offset, $field); }
[ "public", "function", "offsetSet", "(", "$", "offset", ",", "$", "field", ")", "{", "// Allow you to set external id in the array offset.", "// E.g. $collection['external_id'] = $field;", "if", "(", "is_string", "(", "$", "offset", ")", ")", "{", "$", "field", "->", ...
Array access. Set fiels using external id or offset.
[ "Array", "access", ".", "Set", "fiels", "using", "external", "id", "or", "offset", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioFieldCollection.php#L21-L39
podio-community/podio-php
models/PodioFieldCollection.php
PodioFieldCollection.offsetExists
public function offsetExists($offset) { if (is_string($offset)) { return $this->get($offset) ? true : false; } return parent::offsetExists($offset); }
php
public function offsetExists($offset) { if (is_string($offset)) { return $this->get($offset) ? true : false; } return parent::offsetExists($offset); }
[ "public", "function", "offsetExists", "(", "$", "offset", ")", "{", "if", "(", "is_string", "(", "$", "offset", ")", ")", "{", "return", "$", "this", "->", "get", "(", "$", "offset", ")", "?", "true", ":", "false", ";", "}", "return", "parent", "::...
Array access. Check for existence using external_id or offset.
[ "Array", "access", ".", "Check", "for", "existence", "using", "external_id", "or", "offset", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioFieldCollection.php#L44-L49
podio-community/podio-php
models/PodioFieldCollection.php
PodioFieldCollection.offsetUnset
public function offsetUnset($offset) { if (is_string($offset)) { $this->remove($offset); } else { parent::offsetUnset($offset); } }
php
public function offsetUnset($offset) { if (is_string($offset)) { $this->remove($offset); } else { parent::offsetUnset($offset); } }
[ "public", "function", "offsetUnset", "(", "$", "offset", ")", "{", "if", "(", "is_string", "(", "$", "offset", ")", ")", "{", "$", "this", "->", "remove", "(", "$", "offset", ")", ";", "}", "else", "{", "parent", "::", "offsetUnset", "(", "$", "off...
Array access. Unset field using external)id or offset.
[ "Array", "access", ".", "Unset", "field", "using", "external", ")", "id", "or", "offset", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioFieldCollection.php#L54-L61
podio-community/podio-php
models/PodioFieldCollection.php
PodioFieldCollection.offsetGet
public function offsetGet($offset) { if (is_string($offset)) { return $this->get($offset); } return parent::offsetGet($offset); }
php
public function offsetGet($offset) { if (is_string($offset)) { return $this->get($offset); } return parent::offsetGet($offset); }
[ "public", "function", "offsetGet", "(", "$", "offset", ")", "{", "if", "(", "is_string", "(", "$", "offset", ")", ")", "{", "return", "$", "this", "->", "get", "(", "$", "offset", ")", ";", "}", "return", "parent", "::", "offsetGet", "(", "$", "off...
Array access. Get field using external_id or offset.
[ "Array", "access", ".", "Get", "field", "using", "external_id", "or", "offset", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioFieldCollection.php#L66-L71
podio-community/podio-php
models/PodioFieldCollection.php
PodioFieldCollection.readonly_fields
public function readonly_fields() { $fields = new PodioFieldCollection(array()); foreach ($this->_get_items() as $field) { if ($field->type === 'calculation') { $fields[] = $field; } } return $fields; }
php
public function readonly_fields() { $fields = new PodioFieldCollection(array()); foreach ($this->_get_items() as $field) { if ($field->type === 'calculation') { $fields[] = $field; } } return $fields; }
[ "public", "function", "readonly_fields", "(", ")", "{", "$", "fields", "=", "new", "PodioFieldCollection", "(", "array", "(", ")", ")", ";", "foreach", "(", "$", "this", "->", "_get_items", "(", ")", "as", "$", "field", ")", "{", "if", "(", "$", "fie...
Returns all readonly fields
[ "Returns", "all", "readonly", "fields" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioFieldCollection.php#L85-L93
podio-community/podio-php
models/PodioItemField.php
PodioItemField.save
public function save($options = array()) { $relationship = $this->relationship(); if (!$relationship) { throw new PodioMissingRelationshipError('{"error_description":"Field is missing relationship to item"}', null, null); } if (!$this->id && !$this->external_id) { throw new PodioDataIntegrityError('Field must have id or external_id set.'); } $attributes = $this->as_json(false); return self::update($relationship['instance']->id, $this->id ? $this->id : $this->external_id, $attributes, $options); }
php
public function save($options = array()) { $relationship = $this->relationship(); if (!$relationship) { throw new PodioMissingRelationshipError('{"error_description":"Field is missing relationship to item"}', null, null); } if (!$this->id && !$this->external_id) { throw new PodioDataIntegrityError('Field must have id or external_id set.'); } $attributes = $this->as_json(false); return self::update($relationship['instance']->id, $this->id ? $this->id : $this->external_id, $attributes, $options); }
[ "public", "function", "save", "(", "$", "options", "=", "array", "(", ")", ")", "{", "$", "relationship", "=", "$", "this", "->", "relationship", "(", ")", ";", "if", "(", "!", "$", "relationship", ")", "{", "throw", "new", "PodioMissingRelationshipError...
Saves the value of the field
[ "Saves", "the", "value", "of", "the", "field" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioItemField.php#L23-L33
podio-community/podio-php
models/PodioItemField.php
PodioItemField.as_json
public function as_json($encoded = true) { $result = $this->api_friendly_values(); return $encoded ? json_encode($result) : $result; }
php
public function as_json($encoded = true) { $result = $this->api_friendly_values(); return $encoded ? json_encode($result) : $result; }
[ "public", "function", "as_json", "(", "$", "encoded", "=", "true", ")", "{", "$", "result", "=", "$", "this", "->", "api_friendly_values", "(", ")", ";", "return", "$", "encoded", "?", "json_encode", "(", "$", "result", ")", ":", "$", "result", ";", ...
Overwrites normal as_json to use api_friendly_values
[ "Overwrites", "normal", "as_json", "to", "use", "api_friendly_values" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioItemField.php#L45-L48
podio-community/podio-php
models/PodioItemField.php
PodioDateItemField.same_day
public function same_day() { if (!$this->values || ($this->start && !$this->end)) { return true; } if ($this->start->format('Y-m-d') == $this->end->format('Y-m-d')) { return true; } return false; }
php
public function same_day() { if (!$this->values || ($this->start && !$this->end)) { return true; } if ($this->start->format('Y-m-d') == $this->end->format('Y-m-d')) { return true; } return false; }
[ "public", "function", "same_day", "(", ")", "{", "if", "(", "!", "$", "this", "->", "values", "||", "(", "$", "this", "->", "start", "&&", "!", "$", "this", "->", "end", ")", ")", "{", "return", "true", ";", "}", "if", "(", "$", "this", "->", ...
True if start and end are on the same day.
[ "True", "if", "start", "and", "end", "are", "on", "the", "same", "day", "." ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioItemField.php#L420-L429
podio-community/podio-php
models/PodioItemField.php
PodioDateItemField.all_day
public function all_day() { if (!$this->values) { return false; } if (($this->start->format('H:i:s') == '00:00:00' && (!$this->end || ($this->end && $this->end->format('H:i:s') == '00:00:00')))) { return true; } return false; }
php
public function all_day() { if (!$this->values) { return false; } if (($this->start->format('H:i:s') == '00:00:00' && (!$this->end || ($this->end && $this->end->format('H:i:s') == '00:00:00')))) { return true; } return false; }
[ "public", "function", "all_day", "(", ")", "{", "if", "(", "!", "$", "this", "->", "values", ")", "{", "return", "false", ";", "}", "if", "(", "(", "$", "this", "->", "start", "->", "format", "(", "'H:i:s'", ")", "==", "'00:00:00'", "&&", "(", "!...
True if this is an allday event (has no time component on both start and end)
[ "True", "if", "this", "is", "an", "allday", "event", "(", "has", "no", "time", "component", "on", "both", "start", "and", "end", ")" ]
train
https://github.com/podio-community/podio-php/blob/663fd4dc2233b6dc7711b80d0473f01cb0e937ce/models/PodioItemField.php#L434-L442
mautic/api-library
lib/Auth/BasicAuth.php
BasicAuth.setup
public function setup($userName, $password) { // we MUST have the username and password. No Blanks allowed! // // remove blanks else Empty doesn't work $userName = trim($userName); $password = trim($password); if (empty($userName) || empty($password)) { //Throw exception if the required parameters were not found $this->log('parameters did not include username and/or password'); throw new RequiredParameterMissingException('One or more required parameters was not supplied. Both userName and password required!'); } $this->userName = $userName; $this->password = $password; }
php
public function setup($userName, $password) { // we MUST have the username and password. No Blanks allowed! // // remove blanks else Empty doesn't work $userName = trim($userName); $password = trim($password); if (empty($userName) || empty($password)) { //Throw exception if the required parameters were not found $this->log('parameters did not include username and/or password'); throw new RequiredParameterMissingException('One or more required parameters was not supplied. Both userName and password required!'); } $this->userName = $userName; $this->password = $password; }
[ "public", "function", "setup", "(", "$", "userName", ",", "$", "password", ")", "{", "// we MUST have the username and password. No Blanks allowed!", "//", "// remove blanks else Empty doesn't work", "$", "userName", "=", "trim", "(", "$", "userName", ")", ";", "$", "...
@param string $userName The username to use for Authentication *Required* @param string $password The Password to use *Required* @throws RequiredParameterMissingException
[ "@param", "string", "$userName", "The", "username", "to", "use", "for", "Authentication", "*", "Required", "*", "@param", "string", "$password", "The", "Password", "to", "use", "*", "Required", "*" ]
train
https://github.com/mautic/api-library/blob/54c035bb87051250c2226b46b1b07e28aece1c39/lib/Auth/BasicAuth.php#L91-L106
mautic/api-library
lib/Auth/BasicAuth.php
BasicAuth.prepareRequest
protected function prepareRequest($url, array $headers, array $parameters, $method, array $settings) { //Set Basic Auth parameters/headers $headers = array_merge($headers, array($this->buildAuthorizationHeader(), 'Expect:')); return array($headers, $parameters); }
php
protected function prepareRequest($url, array $headers, array $parameters, $method, array $settings) { //Set Basic Auth parameters/headers $headers = array_merge($headers, array($this->buildAuthorizationHeader(), 'Expect:')); return array($headers, $parameters); }
[ "protected", "function", "prepareRequest", "(", "$", "url", ",", "array", "$", "headers", ",", "array", "$", "parameters", ",", "$", "method", ",", "array", "$", "settings", ")", "{", "//Set Basic Auth parameters/headers", "$", "headers", "=", "array_merge", "...
@param $url @param array $headers @param array $parameters @param $method @param array $settings @return array
[ "@param", "$url", "@param", "array", "$headers", "@param", "array", "$parameters", "@param", "$method", "@param", "array", "$settings" ]
train
https://github.com/mautic/api-library/blob/54c035bb87051250c2226b46b1b07e28aece1c39/lib/Auth/BasicAuth.php#L117-L123
mautic/api-library
lib/Api/Emails.php
Emails.sendToContact
public function sendToContact($id, $contactId, $parameters = array()) { return $this->makeRequest($this->endpoint.'/'.$id.'/contact/'.$contactId.'/send', $parameters, 'POST'); }
php
public function sendToContact($id, $contactId, $parameters = array()) { return $this->makeRequest($this->endpoint.'/'.$id.'/contact/'.$contactId.'/send', $parameters, 'POST'); }
[ "public", "function", "sendToContact", "(", "$", "id", ",", "$", "contactId", ",", "$", "parameters", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "makeRequest", "(", "$", "this", "->", "endpoint", ".", "'/'", ".", "$", "id", ".", ...
Send email to a specific contact @param int $id @param int $contactId @return array|mixed
[ "Send", "email", "to", "a", "specific", "contact" ]
train
https://github.com/mautic/api-library/blob/54c035bb87051250c2226b46b1b07e28aece1c39/lib/Api/Emails.php#L74-L77
mautic/api-library
lib/Api/Api.php
Api.setBaseUrl
public function setBaseUrl($url) { if (substr($url, -1) != '/') { $url .= '/'; } if (substr($url,-4,4) != 'api/') { $url .= 'api/'; } $this->baseUrl = $url; return $this; }
php
public function setBaseUrl($url) { if (substr($url, -1) != '/') { $url .= '/'; } if (substr($url,-4,4) != 'api/') { $url .= 'api/'; } $this->baseUrl = $url; return $this; }
[ "public", "function", "setBaseUrl", "(", "$", "url", ")", "{", "if", "(", "substr", "(", "$", "url", ",", "-", "1", ")", "!=", "'/'", ")", "{", "$", "url", ".=", "'/'", ";", "}", "if", "(", "substr", "(", "$", "url", ",", "-", "4", ",", "4"...
Set the base URL for API endpoints @param string $url @return $this
[ "Set", "the", "base", "URL", "for", "API", "endpoints" ]
train
https://github.com/mautic/api-library/blob/54c035bb87051250c2226b46b1b07e28aece1c39/lib/Api/Api.php#L185-L198
mautic/api-library
lib/Api/Api.php
Api.makeRequest
public function makeRequest($endpoint, array $parameters = array(), $method = 'GET') { $response = array(); // Validate if this endpoint has a BC url $bcEndpoint = null; if (!$this->bcAttempt) { if (!empty($this->bcRegexEndpoints)) { foreach ($this->bcRegexEndpoints as $regex => $bc) { if (preg_match('@'.$regex.'@', $endpoint)) { $this->bcAttempt = true; $bcEndpoint = preg_replace('@'.$regex.'@', $bc, $endpoint); break; } } } } $url = $this->baseUrl.$endpoint; // Don't make the call if we're unit testing a BC endpoint if (!$bcEndpoint || !$this->bcTesting || ($bcEndpoint && $this->bcTesting && $this->bcAttempt)) { // Hack for unit testing to ensure this isn't being called due to a bad regex if ($this->bcTesting && !$this->bcAttempt) { $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); if (!is_array($this->bcTesting)) { $this->bcTesting = array($this->bcTesting); } // The method is not catching the BC endpoint so fail the test if (in_array($bt[1]['function'], $this->bcTesting)) { throw new \Exception($endpoint.' not matched in '.var_export($this->bcRegexEndpoints, true)); } } $this->bcAttempt = false; if (strpos($url, 'http') === false) { $error = array( 'code' => 500, 'message' => sprintf( 'URL is incomplete. Please use %s, set the base URL as the third argument to $MauticApi->newApi(), or make $endpoint a complete URL.', __CLASS__.'setBaseUrl()' ) ); } else { try { $settings = []; if (method_exists($this, 'getTemporaryFilePath')) { $settings['temporaryFilePath'] = $this->getTemporaryFilePath(); } $response = $this->auth->makeRequest($url, $parameters, $method, $settings); $this->getLogger()->debug('API Response', array('response' => $response)); if (!is_array($response)) { $this->getLogger()->warning($response); //assume an error $error = array( 'code' => 500, 'message' => $response ); } // @deprecated support for 2.6.0 to be removed in 3.0 if (!isset($response['errors']) && isset($response['error']) && isset($response['error_description'])) { $message = $response['error'].': '.$response['error_description']; $this->getLogger()->warning($message); $error = array( 'code' => 403, 'message' => $message ); } } catch (\Exception $e) { $this->getLogger()->error('Failed connecting to Mautic API: '.$e->getMessage(), array('trace' => $e->getTraceAsString())); $error = array( 'code' => $e->getCode(), 'message' => $e->getMessage() ); } } if (!empty($error)) { return array( 'errors' => array($error), // @deprecated 2.6.0 to be removed 3.0 'error' => $error ); } elseif (!empty($response['errors'])) { $this->getLogger()->error('Mautic API returned errors: '.var_export($response['errors'], true)); } // @deprecated 2.6.0 BC error handling // @todo remove in 3.0 if (isset($response['error']) && !isset($response['errors'])) { if (isset($response['error_description'])) { // BC Oauth2 error $response['errors'] = array( array( 'message' => $response['error_description'], 'type' => $response['error'] ) ); } elseif (isset($response['message'])) { $response['errors'] = array( $response['error'] ); } } // Ensure a code is present in the error array if (!empty($response['errors'])) { $info = $this->auth->getResponseInfo(); foreach ($response['errors'] as $key => $error) { if (!isset($response['errors'][$key]['code'])) { $response['errors'][$key]['code'] = $info['http_code']; } } } } // Check for a 404 code and a BC URL then try again if applicable if ($bcEndpoint && ($this->bcTesting || (!empty($response['errors'][0]['code']) && (int) $response['errors'][0]['code'] === 404))) { $this->bcAttempt = true; return $this->makeRequest($bcEndpoint, $parameters, $method); } return $response; }
php
public function makeRequest($endpoint, array $parameters = array(), $method = 'GET') { $response = array(); // Validate if this endpoint has a BC url $bcEndpoint = null; if (!$this->bcAttempt) { if (!empty($this->bcRegexEndpoints)) { foreach ($this->bcRegexEndpoints as $regex => $bc) { if (preg_match('@'.$regex.'@', $endpoint)) { $this->bcAttempt = true; $bcEndpoint = preg_replace('@'.$regex.'@', $bc, $endpoint); break; } } } } $url = $this->baseUrl.$endpoint; // Don't make the call if we're unit testing a BC endpoint if (!$bcEndpoint || !$this->bcTesting || ($bcEndpoint && $this->bcTesting && $this->bcAttempt)) { // Hack for unit testing to ensure this isn't being called due to a bad regex if ($this->bcTesting && !$this->bcAttempt) { $bt = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2); if (!is_array($this->bcTesting)) { $this->bcTesting = array($this->bcTesting); } // The method is not catching the BC endpoint so fail the test if (in_array($bt[1]['function'], $this->bcTesting)) { throw new \Exception($endpoint.' not matched in '.var_export($this->bcRegexEndpoints, true)); } } $this->bcAttempt = false; if (strpos($url, 'http') === false) { $error = array( 'code' => 500, 'message' => sprintf( 'URL is incomplete. Please use %s, set the base URL as the third argument to $MauticApi->newApi(), or make $endpoint a complete URL.', __CLASS__.'setBaseUrl()' ) ); } else { try { $settings = []; if (method_exists($this, 'getTemporaryFilePath')) { $settings['temporaryFilePath'] = $this->getTemporaryFilePath(); } $response = $this->auth->makeRequest($url, $parameters, $method, $settings); $this->getLogger()->debug('API Response', array('response' => $response)); if (!is_array($response)) { $this->getLogger()->warning($response); //assume an error $error = array( 'code' => 500, 'message' => $response ); } // @deprecated support for 2.6.0 to be removed in 3.0 if (!isset($response['errors']) && isset($response['error']) && isset($response['error_description'])) { $message = $response['error'].': '.$response['error_description']; $this->getLogger()->warning($message); $error = array( 'code' => 403, 'message' => $message ); } } catch (\Exception $e) { $this->getLogger()->error('Failed connecting to Mautic API: '.$e->getMessage(), array('trace' => $e->getTraceAsString())); $error = array( 'code' => $e->getCode(), 'message' => $e->getMessage() ); } } if (!empty($error)) { return array( 'errors' => array($error), // @deprecated 2.6.0 to be removed 3.0 'error' => $error ); } elseif (!empty($response['errors'])) { $this->getLogger()->error('Mautic API returned errors: '.var_export($response['errors'], true)); } // @deprecated 2.6.0 BC error handling // @todo remove in 3.0 if (isset($response['error']) && !isset($response['errors'])) { if (isset($response['error_description'])) { // BC Oauth2 error $response['errors'] = array( array( 'message' => $response['error_description'], 'type' => $response['error'] ) ); } elseif (isset($response['message'])) { $response['errors'] = array( $response['error'] ); } } // Ensure a code is present in the error array if (!empty($response['errors'])) { $info = $this->auth->getResponseInfo(); foreach ($response['errors'] as $key => $error) { if (!isset($response['errors'][$key]['code'])) { $response['errors'][$key]['code'] = $info['http_code']; } } } } // Check for a 404 code and a BC URL then try again if applicable if ($bcEndpoint && ($this->bcTesting || (!empty($response['errors'][0]['code']) && (int) $response['errors'][0]['code'] === 404))) { $this->bcAttempt = true; return $this->makeRequest($bcEndpoint, $parameters, $method); } return $response; }
[ "public", "function", "makeRequest", "(", "$", "endpoint", ",", "array", "$", "parameters", "=", "array", "(", ")", ",", "$", "method", "=", "'GET'", ")", "{", "$", "response", "=", "array", "(", ")", ";", "// Validate if this endpoint has a BC url", "$", ...
Make the API request @param $endpoint @param array $parameters @param string $method @return array @throws \Exception
[ "Make", "the", "API", "request" ]
train
https://github.com/mautic/api-library/blob/54c035bb87051250c2226b46b1b07e28aece1c39/lib/Api/Api.php#L210-L343