repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
stripe/stripe-php
lib/Util/Util.php
Util.secureCompare
public static function secureCompare($a, $b) { if (self::$isHashEqualsAvailable === null) { self::$isHashEqualsAvailable = function_exists('hash_equals'); } if (self::$isHashEqualsAvailable) { return hash_equals($a, $b); } else { if (strlen($a) != strlen($b)) { return false; } $result = 0; for ($i = 0; $i < strlen($a); $i++) { $result |= ord($a[$i]) ^ ord($b[$i]); } return ($result == 0); } }
php
public static function secureCompare($a, $b) { if (self::$isHashEqualsAvailable === null) { self::$isHashEqualsAvailable = function_exists('hash_equals'); } if (self::$isHashEqualsAvailable) { return hash_equals($a, $b); } else { if (strlen($a) != strlen($b)) { return false; } $result = 0; for ($i = 0; $i < strlen($a); $i++) { $result |= ord($a[$i]) ^ ord($b[$i]); } return ($result == 0); } }
[ "public", "static", "function", "secureCompare", "(", "$", "a", ",", "$", "b", ")", "{", "if", "(", "self", "::", "$", "isHashEqualsAvailable", "===", "null", ")", "{", "self", "::", "$", "isHashEqualsAvailable", "=", "function_exists", "(", "'hash_equals'", ")", ";", "}", "if", "(", "self", "::", "$", "isHashEqualsAvailable", ")", "{", "return", "hash_equals", "(", "$", "a", ",", "$", "b", ")", ";", "}", "else", "{", "if", "(", "strlen", "(", "$", "a", ")", "!=", "strlen", "(", "$", "b", ")", ")", "{", "return", "false", ";", "}", "$", "result", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "strlen", "(", "$", "a", ")", ";", "$", "i", "++", ")", "{", "$", "result", "|=", "ord", "(", "$", "a", "[", "$", "i", "]", ")", "^", "ord", "(", "$", "b", "[", "$", "i", "]", ")", ";", "}", "return", "(", "$", "result", "==", "0", ")", ";", "}", "}" ]
Compares two strings for equality. The time taken is independent of the number of characters that match. @param string $a one of the strings to compare. @param string $b the other string to compare. @return bool true if the strings are equal, false otherwise.
[ "Compares", "two", "strings", "for", "equality", ".", "The", "time", "taken", "is", "independent", "of", "the", "number", "of", "characters", "that", "match", "." ]
8f74cbe130f962d96d4ba92e75a44396a40cf41a
https://github.com/stripe/stripe-php/blob/8f74cbe130f962d96d4ba92e75a44396a40cf41a/lib/Util/Util.php#L201-L220
train
stripe/stripe-php
lib/Util/Util.php
Util.objectsToIds
public static function objectsToIds($h) { if ($h instanceof \Stripe\ApiResource) { return $h->id; } elseif (static::isList($h)) { $results = []; foreach ($h as $v) { array_push($results, static::objectsToIds($v)); } return $results; } elseif (is_array($h)) { $results = []; foreach ($h as $k => $v) { if (is_null($v)) { continue; } $results[$k] = static::objectsToIds($v); } return $results; } else { return $h; } }
php
public static function objectsToIds($h) { if ($h instanceof \Stripe\ApiResource) { return $h->id; } elseif (static::isList($h)) { $results = []; foreach ($h as $v) { array_push($results, static::objectsToIds($v)); } return $results; } elseif (is_array($h)) { $results = []; foreach ($h as $k => $v) { if (is_null($v)) { continue; } $results[$k] = static::objectsToIds($v); } return $results; } else { return $h; } }
[ "public", "static", "function", "objectsToIds", "(", "$", "h", ")", "{", "if", "(", "$", "h", "instanceof", "\\", "Stripe", "\\", "ApiResource", ")", "{", "return", "$", "h", "->", "id", ";", "}", "elseif", "(", "static", "::", "isList", "(", "$", "h", ")", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "h", "as", "$", "v", ")", "{", "array_push", "(", "$", "results", ",", "static", "::", "objectsToIds", "(", "$", "v", ")", ")", ";", "}", "return", "$", "results", ";", "}", "elseif", "(", "is_array", "(", "$", "h", ")", ")", "{", "$", "results", "=", "[", "]", ";", "foreach", "(", "$", "h", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "is_null", "(", "$", "v", ")", ")", "{", "continue", ";", "}", "$", "results", "[", "$", "k", "]", "=", "static", "::", "objectsToIds", "(", "$", "v", ")", ";", "}", "return", "$", "results", ";", "}", "else", "{", "return", "$", "h", ";", "}", "}" ]
Recursively goes through an array of parameters. If a parameter is an instance of ApiResource, then it is replaced by the resource's ID. Also clears out null values. @param mixed $h @return mixed
[ "Recursively", "goes", "through", "an", "array", "of", "parameters", ".", "If", "a", "parameter", "is", "an", "instance", "of", "ApiResource", "then", "it", "is", "replaced", "by", "the", "resource", "s", "ID", ".", "Also", "clears", "out", "null", "values", "." ]
8f74cbe130f962d96d4ba92e75a44396a40cf41a
https://github.com/stripe/stripe-php/blob/8f74cbe130f962d96d4ba92e75a44396a40cf41a/lib/Util/Util.php#L230-L252
train
stripe/stripe-php
lib/OAuth.php
OAuth.authorizeUrl
public static function authorizeUrl($params = null, $opts = null) { $params = $params ?: []; $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase; $params['client_id'] = self::_getClientId($params); if (!array_key_exists('response_type', $params)) { $params['response_type'] = 'code'; } $query = Util\Util::encodeParameters($params); return $base . '/oauth/authorize?' . $query; }
php
public static function authorizeUrl($params = null, $opts = null) { $params = $params ?: []; $base = ($opts && array_key_exists('connect_base', $opts)) ? $opts['connect_base'] : Stripe::$connectBase; $params['client_id'] = self::_getClientId($params); if (!array_key_exists('response_type', $params)) { $params['response_type'] = 'code'; } $query = Util\Util::encodeParameters($params); return $base . '/oauth/authorize?' . $query; }
[ "public", "static", "function", "authorizeUrl", "(", "$", "params", "=", "null", ",", "$", "opts", "=", "null", ")", "{", "$", "params", "=", "$", "params", "?", ":", "[", "]", ";", "$", "base", "=", "(", "$", "opts", "&&", "array_key_exists", "(", "'connect_base'", ",", "$", "opts", ")", ")", "?", "$", "opts", "[", "'connect_base'", "]", ":", "Stripe", "::", "$", "connectBase", ";", "$", "params", "[", "'client_id'", "]", "=", "self", "::", "_getClientId", "(", "$", "params", ")", ";", "if", "(", "!", "array_key_exists", "(", "'response_type'", ",", "$", "params", ")", ")", "{", "$", "params", "[", "'response_type'", "]", "=", "'code'", ";", "}", "$", "query", "=", "Util", "\\", "Util", "::", "encodeParameters", "(", "$", "params", ")", ";", "return", "$", "base", ".", "'/oauth/authorize?'", ".", "$", "query", ";", "}" ]
Generates a URL to Stripe's OAuth form. @param array|null $params @param array|null $opts @return string The URL to Stripe's OAuth form.
[ "Generates", "a", "URL", "to", "Stripe", "s", "OAuth", "form", "." ]
8f74cbe130f962d96d4ba92e75a44396a40cf41a
https://github.com/stripe/stripe-php/blob/8f74cbe130f962d96d4ba92e75a44396a40cf41a/lib/OAuth.php#L15-L28
train
stripe/stripe-php
lib/Util/RequestOptions.php
RequestOptions.discardNonPersistentHeaders
public function discardNonPersistentHeaders() { foreach ($this->headers as $k => $v) { if (!in_array($k, self::$HEADERS_TO_PERSIST)) { unset($this->headers[$k]); } } }
php
public function discardNonPersistentHeaders() { foreach ($this->headers as $k => $v) { if (!in_array($k, self::$HEADERS_TO_PERSIST)) { unset($this->headers[$k]); } } }
[ "public", "function", "discardNonPersistentHeaders", "(", ")", "{", "foreach", "(", "$", "this", "->", "headers", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "!", "in_array", "(", "$", "k", ",", "self", "::", "$", "HEADERS_TO_PERSIST", ")", ")", "{", "unset", "(", "$", "this", "->", "headers", "[", "$", "k", "]", ")", ";", "}", "}", "}" ]
Discards all headers that we don't want to persist across requests.
[ "Discards", "all", "headers", "that", "we", "don", "t", "want", "to", "persist", "across", "requests", "." ]
8f74cbe130f962d96d4ba92e75a44396a40cf41a
https://github.com/stripe/stripe-php/blob/8f74cbe130f962d96d4ba92e75a44396a40cf41a/lib/Util/RequestOptions.php#L51-L58
train
stripe/stripe-php
lib/Util/RandomGenerator.php
RandomGenerator.uuid
public function uuid() { $arr = array_values(unpack('N1a/n4b/N1c', openssl_random_pseudo_bytes(16))); $arr[2] = ($arr[2] & 0x0fff) | 0x4000; $arr[3] = ($arr[3] & 0x3fff) | 0x8000; return vsprintf('%08x-%04x-%04x-%04x-%04x%08x', $arr); }
php
public function uuid() { $arr = array_values(unpack('N1a/n4b/N1c', openssl_random_pseudo_bytes(16))); $arr[2] = ($arr[2] & 0x0fff) | 0x4000; $arr[3] = ($arr[3] & 0x3fff) | 0x8000; return vsprintf('%08x-%04x-%04x-%04x-%04x%08x', $arr); }
[ "public", "function", "uuid", "(", ")", "{", "$", "arr", "=", "array_values", "(", "unpack", "(", "'N1a/n4b/N1c'", ",", "openssl_random_pseudo_bytes", "(", "16", ")", ")", ")", ";", "$", "arr", "[", "2", "]", "=", "(", "$", "arr", "[", "2", "]", "&", "0x0fff", ")", "|", "0x4000", ";", "$", "arr", "[", "3", "]", "=", "(", "$", "arr", "[", "3", "]", "&", "0x3fff", ")", "|", "0x8000", ";", "return", "vsprintf", "(", "'%08x-%04x-%04x-%04x-%04x%08x'", ",", "$", "arr", ")", ";", "}" ]
Returns a v4 UUID. @return string
[ "Returns", "a", "v4", "UUID", "." ]
8f74cbe130f962d96d4ba92e75a44396a40cf41a
https://github.com/stripe/stripe-php/blob/8f74cbe130f962d96d4ba92e75a44396a40cf41a/lib/Util/RandomGenerator.php#L27-L33
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.scopeSearch
public function scopeSearch(Builder $q, $search, $threshold = null, $entireText = false, $entireTextOnly = false) { return $this->scopeSearchRestricted($q, $search, null, $threshold, $entireText, $entireTextOnly); }
php
public function scopeSearch(Builder $q, $search, $threshold = null, $entireText = false, $entireTextOnly = false) { return $this->scopeSearchRestricted($q, $search, null, $threshold, $entireText, $entireTextOnly); }
[ "public", "function", "scopeSearch", "(", "Builder", "$", "q", ",", "$", "search", ",", "$", "threshold", "=", "null", ",", "$", "entireText", "=", "false", ",", "$", "entireTextOnly", "=", "false", ")", "{", "return", "$", "this", "->", "scopeSearchRestricted", "(", "$", "q", ",", "$", "search", ",", "null", ",", "$", "threshold", ",", "$", "entireText", ",", "$", "entireTextOnly", ")", ";", "}" ]
Creates the search scope. @param \Illuminate\Database\Eloquent\Builder $q @param string $search @param float|null $threshold @param boolean $entireText @param boolean $entireTextOnly @return \Illuminate\Database\Eloquent\Builder
[ "Creates", "the", "search", "scope", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L33-L36
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.getColumns
protected function getColumns() { if (array_key_exists('columns', $this->searchable)) { $driver = $this->getDatabaseDriver(); $prefix = Config::get("database.connections.$driver.prefix"); $columns = []; foreach($this->searchable['columns'] as $column => $priority){ $columns[$prefix . $column] = $priority; } return $columns; } else { return DB::connection()->getSchemaBuilder()->getColumnListing($this->table); } }
php
protected function getColumns() { if (array_key_exists('columns', $this->searchable)) { $driver = $this->getDatabaseDriver(); $prefix = Config::get("database.connections.$driver.prefix"); $columns = []; foreach($this->searchable['columns'] as $column => $priority){ $columns[$prefix . $column] = $priority; } return $columns; } else { return DB::connection()->getSchemaBuilder()->getColumnListing($this->table); } }
[ "protected", "function", "getColumns", "(", ")", "{", "if", "(", "array_key_exists", "(", "'columns'", ",", "$", "this", "->", "searchable", ")", ")", "{", "$", "driver", "=", "$", "this", "->", "getDatabaseDriver", "(", ")", ";", "$", "prefix", "=", "Config", "::", "get", "(", "\"database.connections.$driver.prefix\"", ")", ";", "$", "columns", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "searchable", "[", "'columns'", "]", "as", "$", "column", "=>", "$", "priority", ")", "{", "$", "columns", "[", "$", "prefix", ".", "$", "column", "]", "=", "$", "priority", ";", "}", "return", "$", "columns", ";", "}", "else", "{", "return", "DB", "::", "connection", "(", ")", "->", "getSchemaBuilder", "(", ")", "->", "getColumnListing", "(", "$", "this", "->", "table", ")", ";", "}", "}" ]
Returns the search columns. @return array
[ "Returns", "the", "search", "columns", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L121-L134
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.makeJoins
protected function makeJoins(Builder $query) { foreach ($this->getJoins() as $table => $keys) { $query->leftJoin($table, function ($join) use ($keys) { $join->on($keys[0], '=', $keys[1]); if (array_key_exists(2, $keys) && array_key_exists(3, $keys)) { $join->whereRaw($keys[2] . ' = "' . $keys[3] . '"'); } }); } }
php
protected function makeJoins(Builder $query) { foreach ($this->getJoins() as $table => $keys) { $query->leftJoin($table, function ($join) use ($keys) { $join->on($keys[0], '=', $keys[1]); if (array_key_exists(2, $keys) && array_key_exists(3, $keys)) { $join->whereRaw($keys[2] . ' = "' . $keys[3] . '"'); } }); } }
[ "protected", "function", "makeJoins", "(", "Builder", "$", "query", ")", "{", "foreach", "(", "$", "this", "->", "getJoins", "(", ")", "as", "$", "table", "=>", "$", "keys", ")", "{", "$", "query", "->", "leftJoin", "(", "$", "table", ",", "function", "(", "$", "join", ")", "use", "(", "$", "keys", ")", "{", "$", "join", "->", "on", "(", "$", "keys", "[", "0", "]", ",", "'='", ",", "$", "keys", "[", "1", "]", ")", ";", "if", "(", "array_key_exists", "(", "2", ",", "$", "keys", ")", "&&", "array_key_exists", "(", "3", ",", "$", "keys", ")", ")", "{", "$", "join", "->", "whereRaw", "(", "$", "keys", "[", "2", "]", ".", "' = \"'", ".", "$", "keys", "[", "3", "]", ".", "'\"'", ")", ";", "}", "}", ")", ";", "}", "}" ]
Adds the sql joins to the query. @param \Illuminate\Database\Eloquent\Builder $query
[ "Adds", "the", "sql", "joins", "to", "the", "query", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L175-L185
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.makeGroupBy
protected function makeGroupBy(Builder $query) { if ($groupBy = $this->getGroupBy()) { $query->groupBy($groupBy); } else { $driver = $this->getDatabaseDriver(); if ($driver == 'sqlsrv') { $columns = $this->getTableColumns(); } else { $columns = $this->getTable() . '.' .$this->primaryKey; } $query->groupBy($columns); $joins = array_keys(($this->getJoins())); foreach ($this->getColumns() as $column => $relevance) { array_map(function ($join) use ($column, $query) { if (Str::contains($column, $join)) { $query->groupBy($column); } }, $joins); } } }
php
protected function makeGroupBy(Builder $query) { if ($groupBy = $this->getGroupBy()) { $query->groupBy($groupBy); } else { $driver = $this->getDatabaseDriver(); if ($driver == 'sqlsrv') { $columns = $this->getTableColumns(); } else { $columns = $this->getTable() . '.' .$this->primaryKey; } $query->groupBy($columns); $joins = array_keys(($this->getJoins())); foreach ($this->getColumns() as $column => $relevance) { array_map(function ($join) use ($column, $query) { if (Str::contains($column, $join)) { $query->groupBy($column); } }, $joins); } } }
[ "protected", "function", "makeGroupBy", "(", "Builder", "$", "query", ")", "{", "if", "(", "$", "groupBy", "=", "$", "this", "->", "getGroupBy", "(", ")", ")", "{", "$", "query", "->", "groupBy", "(", "$", "groupBy", ")", ";", "}", "else", "{", "$", "driver", "=", "$", "this", "->", "getDatabaseDriver", "(", ")", ";", "if", "(", "$", "driver", "==", "'sqlsrv'", ")", "{", "$", "columns", "=", "$", "this", "->", "getTableColumns", "(", ")", ";", "}", "else", "{", "$", "columns", "=", "$", "this", "->", "getTable", "(", ")", ".", "'.'", ".", "$", "this", "->", "primaryKey", ";", "}", "$", "query", "->", "groupBy", "(", "$", "columns", ")", ";", "$", "joins", "=", "array_keys", "(", "(", "$", "this", "->", "getJoins", "(", ")", ")", ")", ";", "foreach", "(", "$", "this", "->", "getColumns", "(", ")", "as", "$", "column", "=>", "$", "relevance", ")", "{", "array_map", "(", "function", "(", "$", "join", ")", "use", "(", "$", "column", ",", "$", "query", ")", "{", "if", "(", "Str", "::", "contains", "(", "$", "column", ",", "$", "join", ")", ")", "{", "$", "query", "->", "groupBy", "(", "$", "column", ")", ";", "}", "}", ",", "$", "joins", ")", ";", "}", "}", "}" ]
Makes the query not repeat the results. @param \Illuminate\Database\Eloquent\Builder $query
[ "Makes", "the", "query", "not", "repeat", "the", "results", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L192-L217
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.getSearchQueriesForColumn
protected function getSearchQueriesForColumn(Builder $query, $column, $relevance, array $words) { $queries = []; $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 15); $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 5, '', '%'); $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 1, '%', '%'); return $queries; }
php
protected function getSearchQueriesForColumn(Builder $query, $column, $relevance, array $words) { $queries = []; $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 15); $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 5, '', '%'); $queries[] = $this->getSearchQuery($query, $column, $relevance, $words, 1, '%', '%'); return $queries; }
[ "protected", "function", "getSearchQueriesForColumn", "(", "Builder", "$", "query", ",", "$", "column", ",", "$", "relevance", ",", "array", "$", "words", ")", "{", "$", "queries", "=", "[", "]", ";", "$", "queries", "[", "]", "=", "$", "this", "->", "getSearchQuery", "(", "$", "query", ",", "$", "column", ",", "$", "relevance", ",", "$", "words", ",", "15", ")", ";", "$", "queries", "[", "]", "=", "$", "this", "->", "getSearchQuery", "(", "$", "query", ",", "$", "column", ",", "$", "relevance", ",", "$", "words", ",", "5", ",", "''", ",", "'%'", ")", ";", "$", "queries", "[", "]", "=", "$", "this", "->", "getSearchQuery", "(", "$", "query", ",", "$", "column", ",", "$", "relevance", ",", "$", "words", ",", "1", ",", "'%'", ",", "'%'", ")", ";", "return", "$", "queries", ";", "}" ]
Returns the search queries for the specified column. @param \Illuminate\Database\Eloquent\Builder $query @param string $column @param float $relevance @param array $words @return array
[ "Returns", "the", "search", "queries", "for", "the", "specified", "column", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L265-L274
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.getSearchQuery
protected function getSearchQuery(Builder $query, $column, $relevance, array $words, $relevance_multiplier, $pre_word = '', $post_word = '') { $like_comparator = $this->getDatabaseDriver() == 'pgsql' ? 'ILIKE' : 'LIKE'; $cases = []; foreach ($words as $word) { $cases[] = $this->getCaseCompare($column, $like_comparator, $relevance * $relevance_multiplier); $this->search_bindings[] = $pre_word . $word . $post_word; } return implode(' + ', $cases); }
php
protected function getSearchQuery(Builder $query, $column, $relevance, array $words, $relevance_multiplier, $pre_word = '', $post_word = '') { $like_comparator = $this->getDatabaseDriver() == 'pgsql' ? 'ILIKE' : 'LIKE'; $cases = []; foreach ($words as $word) { $cases[] = $this->getCaseCompare($column, $like_comparator, $relevance * $relevance_multiplier); $this->search_bindings[] = $pre_word . $word . $post_word; } return implode(' + ', $cases); }
[ "protected", "function", "getSearchQuery", "(", "Builder", "$", "query", ",", "$", "column", ",", "$", "relevance", ",", "array", "$", "words", ",", "$", "relevance_multiplier", ",", "$", "pre_word", "=", "''", ",", "$", "post_word", "=", "''", ")", "{", "$", "like_comparator", "=", "$", "this", "->", "getDatabaseDriver", "(", ")", "==", "'pgsql'", "?", "'ILIKE'", ":", "'LIKE'", ";", "$", "cases", "=", "[", "]", ";", "foreach", "(", "$", "words", "as", "$", "word", ")", "{", "$", "cases", "[", "]", "=", "$", "this", "->", "getCaseCompare", "(", "$", "column", ",", "$", "like_comparator", ",", "$", "relevance", "*", "$", "relevance_multiplier", ")", ";", "$", "this", "->", "search_bindings", "[", "]", "=", "$", "pre_word", ".", "$", "word", ".", "$", "post_word", ";", "}", "return", "implode", "(", "' + '", ",", "$", "cases", ")", ";", "}" ]
Returns the sql string for the given parameters. @param \Illuminate\Database\Eloquent\Builder $query @param string $column @param string $relevance @param array $words @param string $compare @param float $relevance_multiplier @param string $pre_word @param string $post_word @return string
[ "Returns", "the", "sql", "string", "for", "the", "given", "parameters", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L289-L301
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.getCaseCompare
protected function getCaseCompare($column, $compare, $relevance) { if($this->getDatabaseDriver() == 'pgsql') { $field = "LOWER(" . $column . ") " . $compare . " ?"; return '(case when ' . $field . ' then ' . $relevance . ' else 0 end)'; } $column = str_replace('.', '`.`', $column); $field = "LOWER(`" . $column . "`) " . $compare . " ?"; return '(case when ' . $field . ' then ' . $relevance . ' else 0 end)'; }
php
protected function getCaseCompare($column, $compare, $relevance) { if($this->getDatabaseDriver() == 'pgsql') { $field = "LOWER(" . $column . ") " . $compare . " ?"; return '(case when ' . $field . ' then ' . $relevance . ' else 0 end)'; } $column = str_replace('.', '`.`', $column); $field = "LOWER(`" . $column . "`) " . $compare . " ?"; return '(case when ' . $field . ' then ' . $relevance . ' else 0 end)'; }
[ "protected", "function", "getCaseCompare", "(", "$", "column", ",", "$", "compare", ",", "$", "relevance", ")", "{", "if", "(", "$", "this", "->", "getDatabaseDriver", "(", ")", "==", "'pgsql'", ")", "{", "$", "field", "=", "\"LOWER(\"", ".", "$", "column", ".", "\") \"", ".", "$", "compare", ".", "\" ?\"", ";", "return", "'(case when '", ".", "$", "field", ".", "' then '", ".", "$", "relevance", ".", "' else 0 end)'", ";", "}", "$", "column", "=", "str_replace", "(", "'.'", ",", "'`.`'", ",", "$", "column", ")", ";", "$", "field", "=", "\"LOWER(`\"", ".", "$", "column", ".", "\"`) \"", ".", "$", "compare", ".", "\" ?\"", ";", "return", "'(case when '", ".", "$", "field", ".", "' then '", ".", "$", "relevance", ".", "' else 0 end)'", ";", "}" ]
Returns the comparison string. @param string $column @param string $compare @param float $relevance @return string
[ "Returns", "the", "comparison", "string", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L311-L320
train
nicolaslopezj/searchable
src/SearchableTrait.php
SearchableTrait.mergeQueries
protected function mergeQueries(Builder $clone, Builder $original) { $tableName = DB::connection($this->connection)->getTablePrefix() . $this->getTable(); if ($this->getDatabaseDriver() == 'pgsql') { $original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as {$tableName}")); } else { $original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as `{$tableName}`")); } // First create a new array merging bindings $mergedBindings = array_merge_recursive( $clone->getBindings(), $original->getBindings() ); // Then apply bindings WITHOUT global scopes which are already included. If not, there is a strange behaviour // with some scope's bindings remaning $original->withoutGlobalScopes()->setBindings($mergedBindings); }
php
protected function mergeQueries(Builder $clone, Builder $original) { $tableName = DB::connection($this->connection)->getTablePrefix() . $this->getTable(); if ($this->getDatabaseDriver() == 'pgsql') { $original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as {$tableName}")); } else { $original->from(DB::connection($this->connection)->raw("({$clone->toSql()}) as `{$tableName}`")); } // First create a new array merging bindings $mergedBindings = array_merge_recursive( $clone->getBindings(), $original->getBindings() ); // Then apply bindings WITHOUT global scopes which are already included. If not, there is a strange behaviour // with some scope's bindings remaning $original->withoutGlobalScopes()->setBindings($mergedBindings); }
[ "protected", "function", "mergeQueries", "(", "Builder", "$", "clone", ",", "Builder", "$", "original", ")", "{", "$", "tableName", "=", "DB", "::", "connection", "(", "$", "this", "->", "connection", ")", "->", "getTablePrefix", "(", ")", ".", "$", "this", "->", "getTable", "(", ")", ";", "if", "(", "$", "this", "->", "getDatabaseDriver", "(", ")", "==", "'pgsql'", ")", "{", "$", "original", "->", "from", "(", "DB", "::", "connection", "(", "$", "this", "->", "connection", ")", "->", "raw", "(", "\"({$clone->toSql()}) as {$tableName}\"", ")", ")", ";", "}", "else", "{", "$", "original", "->", "from", "(", "DB", "::", "connection", "(", "$", "this", "->", "connection", ")", "->", "raw", "(", "\"({$clone->toSql()}) as `{$tableName}`\"", ")", ")", ";", "}", "// First create a new array merging bindings", "$", "mergedBindings", "=", "array_merge_recursive", "(", "$", "clone", "->", "getBindings", "(", ")", ",", "$", "original", "->", "getBindings", "(", ")", ")", ";", "// Then apply bindings WITHOUT global scopes which are already included. If not, there is a strange behaviour", "// with some scope's bindings remaning", "$", "original", "->", "withoutGlobalScopes", "(", ")", "->", "setBindings", "(", "$", "mergedBindings", ")", ";", "}" ]
Merge our cloned query builder with the original one. @param \Illuminate\Database\Eloquent\Builder $clone @param \Illuminate\Database\Eloquent\Builder $original
[ "Merge", "our", "cloned", "query", "builder", "with", "the", "original", "one", "." ]
69dfeb12ae283067288e4bc412235b1f3f13dcf4
https://github.com/nicolaslopezj/searchable/blob/69dfeb12ae283067288e4bc412235b1f3f13dcf4/src/SearchableTrait.php#L328-L345
train
Eleirbag89/TelegramBotPHP
Telegram.php
Telegram.setWebhook
public function setWebhook($url, $certificate = '') { if ($certificate == '') { $requestBody = ['url' => $url]; } else { $requestBody = ['url' => $url, 'certificate' => "@$certificate"]; } return $this->endpoint('setWebhook', $requestBody, true); }
php
public function setWebhook($url, $certificate = '') { if ($certificate == '') { $requestBody = ['url' => $url]; } else { $requestBody = ['url' => $url, 'certificate' => "@$certificate"]; } return $this->endpoint('setWebhook', $requestBody, true); }
[ "public", "function", "setWebhook", "(", "$", "url", ",", "$", "certificate", "=", "''", ")", "{", "if", "(", "$", "certificate", "==", "''", ")", "{", "$", "requestBody", "=", "[", "'url'", "=>", "$", "url", "]", ";", "}", "else", "{", "$", "requestBody", "=", "[", "'url'", "=>", "$", "url", ",", "'certificate'", "=>", "\"@$certificate\"", "]", ";", "}", "return", "$", "this", "->", "endpoint", "(", "'setWebhook'", ",", "$", "requestBody", ",", "true", ")", ";", "}" ]
Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. \param $url String HTTPS url to send updates to. Use an empty string to remove webhook integration \param $certificate InputFile Upload your public key certificate so that the root certificate in use can be checked \return the JSON Telegram's reply.
[ "Use", "this", "method", "to", "specify", "a", "url", "and", "receive", "incoming", "updates", "via", "an", "outgoing", "webhook", ".", "Whenever", "there", "is", "an", "update", "for", "the", "bot", "we", "will", "send", "an", "HTTPS", "POST", "request", "to", "the", "specified", "url", "containing", "a", "JSON", "-", "serialized", "Update", ".", "In", "case", "of", "an", "unsuccessful", "request", "we", "will", "give", "up", "after", "a", "reasonable", "amount", "of", "attempts", "." ]
19ee63772ff3e13c57142b04a5e71e8bf34236bc
https://github.com/Eleirbag89/TelegramBotPHP/blob/19ee63772ff3e13c57142b04a5e71e8bf34236bc/Telegram.php#L1703-L1712
train
Eleirbag89/TelegramBotPHP
Telegram.php
Telegram.ChatID
public function ChatID() { $type = $this->getUpdateType(); if ($type == self::CALLBACK_QUERY) { return @$this->data['callback_query']['message']['chat']['id']; } if ($type == self::CHANNEL_POST) { return @$this->data['channel_post']['chat']['id']; } if ($type == self::EDITED_MESSAGE) { return @$this->data['edited_message']['chat']['id']; } if ($type == self::INLINE_QUERY) { return @$this->data['inline_query']['from']['id']; } return $this->data['message']['chat']['id']; }
php
public function ChatID() { $type = $this->getUpdateType(); if ($type == self::CALLBACK_QUERY) { return @$this->data['callback_query']['message']['chat']['id']; } if ($type == self::CHANNEL_POST) { return @$this->data['channel_post']['chat']['id']; } if ($type == self::EDITED_MESSAGE) { return @$this->data['edited_message']['chat']['id']; } if ($type == self::INLINE_QUERY) { return @$this->data['inline_query']['from']['id']; } return $this->data['message']['chat']['id']; }
[ "public", "function", "ChatID", "(", ")", "{", "$", "type", "=", "$", "this", "->", "getUpdateType", "(", ")", ";", "if", "(", "$", "type", "==", "self", "::", "CALLBACK_QUERY", ")", "{", "return", "@", "$", "this", "->", "data", "[", "'callback_query'", "]", "[", "'message'", "]", "[", "'chat'", "]", "[", "'id'", "]", ";", "}", "if", "(", "$", "type", "==", "self", "::", "CHANNEL_POST", ")", "{", "return", "@", "$", "this", "->", "data", "[", "'channel_post'", "]", "[", "'chat'", "]", "[", "'id'", "]", ";", "}", "if", "(", "$", "type", "==", "self", "::", "EDITED_MESSAGE", ")", "{", "return", "@", "$", "this", "->", "data", "[", "'edited_message'", "]", "[", "'chat'", "]", "[", "'id'", "]", ";", "}", "if", "(", "$", "type", "==", "self", "::", "INLINE_QUERY", ")", "{", "return", "@", "$", "this", "->", "data", "[", "'inline_query'", "]", "[", "'from'", "]", "[", "'id'", "]", ";", "}", "return", "$", "this", "->", "data", "[", "'message'", "]", "[", "'chat'", "]", "[", "'id'", "]", ";", "}" ]
\return the String users's chat_id.
[ "\\", "return", "the", "String", "users", "s", "chat_id", "." ]
19ee63772ff3e13c57142b04a5e71e8bf34236bc
https://github.com/Eleirbag89/TelegramBotPHP/blob/19ee63772ff3e13c57142b04a5e71e8bf34236bc/Telegram.php#L1778-L1795
train
Eleirbag89/TelegramBotPHP
Telegram.php
Telegram.getUpdateType
public function getUpdateType() { $update = $this->data; if (isset($update['inline_query'])) { return self::INLINE_QUERY; } if (isset($update['callback_query'])) { return self::CALLBACK_QUERY; } if (isset($update['edited_message'])) { return self::EDITED_MESSAGE; } if (isset($update['message']['text'])) { return self::MESSAGE; } if (isset($update['message']['photo'])) { return self::PHOTO; } if (isset($update['message']['video'])) { return self::VIDEO; } if (isset($update['message']['audio'])) { return self::AUDIO; } if (isset($update['message']['voice'])) { return self::VOICE; } if (isset($update['message']['contact'])) { return self::CONTACT; } if (isset($update['message']['location'])) { return self::LOCATION; } if (isset($update['message']['reply_to_message'])) { return self::REPLY; } if (isset($update['message']['animation'])) { return self::ANIMATION; } if (isset($update['message']['document'])) { return self::DOCUMENT; } if (isset($update['channel_post'])) { return self::CHANNEL_POST; } return false; }
php
public function getUpdateType() { $update = $this->data; if (isset($update['inline_query'])) { return self::INLINE_QUERY; } if (isset($update['callback_query'])) { return self::CALLBACK_QUERY; } if (isset($update['edited_message'])) { return self::EDITED_MESSAGE; } if (isset($update['message']['text'])) { return self::MESSAGE; } if (isset($update['message']['photo'])) { return self::PHOTO; } if (isset($update['message']['video'])) { return self::VIDEO; } if (isset($update['message']['audio'])) { return self::AUDIO; } if (isset($update['message']['voice'])) { return self::VOICE; } if (isset($update['message']['contact'])) { return self::CONTACT; } if (isset($update['message']['location'])) { return self::LOCATION; } if (isset($update['message']['reply_to_message'])) { return self::REPLY; } if (isset($update['message']['animation'])) { return self::ANIMATION; } if (isset($update['message']['document'])) { return self::DOCUMENT; } if (isset($update['channel_post'])) { return self::CHANNEL_POST; } return false; }
[ "public", "function", "getUpdateType", "(", ")", "{", "$", "update", "=", "$", "this", "->", "data", ";", "if", "(", "isset", "(", "$", "update", "[", "'inline_query'", "]", ")", ")", "{", "return", "self", "::", "INLINE_QUERY", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'callback_query'", "]", ")", ")", "{", "return", "self", "::", "CALLBACK_QUERY", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'edited_message'", "]", ")", ")", "{", "return", "self", "::", "EDITED_MESSAGE", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'text'", "]", ")", ")", "{", "return", "self", "::", "MESSAGE", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'photo'", "]", ")", ")", "{", "return", "self", "::", "PHOTO", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'video'", "]", ")", ")", "{", "return", "self", "::", "VIDEO", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'audio'", "]", ")", ")", "{", "return", "self", "::", "AUDIO", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'voice'", "]", ")", ")", "{", "return", "self", "::", "VOICE", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'contact'", "]", ")", ")", "{", "return", "self", "::", "CONTACT", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'location'", "]", ")", ")", "{", "return", "self", "::", "LOCATION", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'reply_to_message'", "]", ")", ")", "{", "return", "self", "::", "REPLY", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'animation'", "]", ")", ")", "{", "return", "self", "::", "ANIMATION", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'message'", "]", "[", "'document'", "]", ")", ")", "{", "return", "self", "::", "DOCUMENT", ";", "}", "if", "(", "isset", "(", "$", "update", "[", "'channel_post'", "]", ")", ")", "{", "return", "self", "::", "CHANNEL_POST", ";", "}", "return", "false", ";", "}" ]
Return current update type `False` on failure. @return bool|string
[ "Return", "current", "update", "type", "False", "on", "failure", "." ]
19ee63772ff3e13c57142b04a5e71e8bf34236bc
https://github.com/Eleirbag89/TelegramBotPHP/blob/19ee63772ff3e13c57142b04a5e71e8bf34236bc/Telegram.php#L3097-L3144
train
unicodeveloper/laravel-paystack
src/TransRef.php
TransRef.getPool
private static function getPool($type = 'alnum') { switch ($type) { case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'hexdec': $pool = '0123456789abcdef'; break; case 'numeric': $pool = '0123456789'; break; case 'nozero': $pool = '123456789'; break; case 'distinct': $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; break; default: $pool = (string) $type; break; } return $pool; }
php
private static function getPool($type = 'alnum') { switch ($type) { case 'alnum': $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'alpha': $pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case 'hexdec': $pool = '0123456789abcdef'; break; case 'numeric': $pool = '0123456789'; break; case 'nozero': $pool = '123456789'; break; case 'distinct': $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; break; default: $pool = (string) $type; break; } return $pool; }
[ "private", "static", "function", "getPool", "(", "$", "type", "=", "'alnum'", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "'alnum'", ":", "$", "pool", "=", "'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'", ";", "break", ";", "case", "'alpha'", ":", "$", "pool", "=", "'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'", ";", "break", ";", "case", "'hexdec'", ":", "$", "pool", "=", "'0123456789abcdef'", ";", "break", ";", "case", "'numeric'", ":", "$", "pool", "=", "'0123456789'", ";", "break", ";", "case", "'nozero'", ":", "$", "pool", "=", "'123456789'", ";", "break", ";", "case", "'distinct'", ":", "$", "pool", "=", "'2345679ACDEFHJKLMNPRSTUVWXYZ'", ";", "break", ";", "default", ":", "$", "pool", "=", "(", "string", ")", "$", "type", ";", "break", ";", "}", "return", "$", "pool", ";", "}" ]
Get the pool to use based on the type of prefix hash @param string $type @return string
[ "Get", "the", "pool", "to", "use", "based", "on", "the", "type", "of", "prefix", "hash" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/TransRef.php#L23-L50
train
unicodeveloper/laravel-paystack
src/TransRef.php
TransRef.getHashedToken
public static function getHashedToken($length = 25) { $token = ""; $max = strlen(static::getPool()); for ($i = 0; $i < $length; $i++) { $token .= static::getPool()[static::secureCrypt(0, $max)]; } return $token; }
php
public static function getHashedToken($length = 25) { $token = ""; $max = strlen(static::getPool()); for ($i = 0; $i < $length; $i++) { $token .= static::getPool()[static::secureCrypt(0, $max)]; } return $token; }
[ "public", "static", "function", "getHashedToken", "(", "$", "length", "=", "25", ")", "{", "$", "token", "=", "\"\"", ";", "$", "max", "=", "strlen", "(", "static", "::", "getPool", "(", ")", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "length", ";", "$", "i", "++", ")", "{", "$", "token", ".=", "static", "::", "getPool", "(", ")", "[", "static", "::", "secureCrypt", "(", "0", ",", "$", "max", ")", "]", ";", "}", "return", "$", "token", ";", "}" ]
Finally, generate a hashed token @param integer $length @return string
[ "Finally", "generate", "a", "hashed", "token" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/TransRef.php#L83-L92
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.setRequestOptions
private function setRequestOptions() { $authBearer = 'Bearer '. $this->secretKey; $this->client = new Client( [ 'base_uri' => $this->baseUrl, 'headers' => [ 'Authorization' => $authBearer, 'Content-Type' => 'application/json', 'Accept' => 'application/json' ] ] ); }
php
private function setRequestOptions() { $authBearer = 'Bearer '. $this->secretKey; $this->client = new Client( [ 'base_uri' => $this->baseUrl, 'headers' => [ 'Authorization' => $authBearer, 'Content-Type' => 'application/json', 'Accept' => 'application/json' ] ] ); }
[ "private", "function", "setRequestOptions", "(", ")", "{", "$", "authBearer", "=", "'Bearer '", ".", "$", "this", "->", "secretKey", ";", "$", "this", "->", "client", "=", "new", "Client", "(", "[", "'base_uri'", "=>", "$", "this", "->", "baseUrl", ",", "'headers'", "=>", "[", "'Authorization'", "=>", "$", "authBearer", ",", "'Content-Type'", "=>", "'application/json'", ",", "'Accept'", "=>", "'application/json'", "]", "]", ")", ";", "}" ]
Set options for making the Client request
[ "Set", "options", "for", "making", "the", "Client", "request" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L87-L101
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.getAuthorizationResponse
public function getAuthorizationResponse($data) { $this->makePaymentRequest($data); $this->url = $this->getResponse()['data']['authorization_url']; return $this->getResponse(); }
php
public function getAuthorizationResponse($data) { $this->makePaymentRequest($data); $this->url = $this->getResponse()['data']['authorization_url']; return $this->getResponse(); }
[ "public", "function", "getAuthorizationResponse", "(", "$", "data", ")", "{", "$", "this", "->", "makePaymentRequest", "(", "$", "data", ")", ";", "$", "this", "->", "url", "=", "$", "this", "->", "getResponse", "(", ")", "[", "'data'", "]", "[", "'authorization_url'", "]", ";", "return", "$", "this", "->", "getResponse", "(", ")", ";", "}" ]
Get the authorization callback response In situations where Laravel serves as an backend for a detached UI, the api cannot redirect and might need to take different actions based on the success or not of the transaction @return array
[ "Get", "the", "authorization", "callback", "response", "In", "situations", "where", "Laravel", "serves", "as", "an", "backend", "for", "a", "detached", "UI", "the", "api", "cannot", "redirect", "and", "might", "need", "to", "take", "different", "actions", "based", "on", "the", "success", "or", "not", "of", "the", "transaction" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L189-L196
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.verifyTransactionAtGateway
private function verifyTransactionAtGateway() { $transactionRef = request()->query('trxref'); $relativeUrl = "/transaction/verify/{$transactionRef}"; $this->response = $this->client->get($this->baseUrl . $relativeUrl, []); }
php
private function verifyTransactionAtGateway() { $transactionRef = request()->query('trxref'); $relativeUrl = "/transaction/verify/{$transactionRef}"; $this->response = $this->client->get($this->baseUrl . $relativeUrl, []); }
[ "private", "function", "verifyTransactionAtGateway", "(", ")", "{", "$", "transactionRef", "=", "request", "(", ")", "->", "query", "(", "'trxref'", ")", ";", "$", "relativeUrl", "=", "\"/transaction/verify/{$transactionRef}\"", ";", "$", "this", "->", "response", "=", "$", "this", "->", "client", "->", "get", "(", "$", "this", "->", "baseUrl", ".", "$", "relativeUrl", ",", "[", "]", ")", ";", "}" ]
Hit Paystack Gateway to Verify that the transaction is valid
[ "Hit", "Paystack", "Gateway", "to", "Verify", "that", "the", "transaction", "is", "valid" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L201-L208
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.isTransactionVerificationValid
public function isTransactionVerificationValid() { $this->verifyTransactionAtGateway(); $result = $this->getResponse()['message']; switch ($result) { case self::VS: $validate = true; break; case self::ITF: $validate = false; break; default: $validate = false; break; } return $validate; }
php
public function isTransactionVerificationValid() { $this->verifyTransactionAtGateway(); $result = $this->getResponse()['message']; switch ($result) { case self::VS: $validate = true; break; case self::ITF: $validate = false; break; default: $validate = false; break; } return $validate; }
[ "public", "function", "isTransactionVerificationValid", "(", ")", "{", "$", "this", "->", "verifyTransactionAtGateway", "(", ")", ";", "$", "result", "=", "$", "this", "->", "getResponse", "(", ")", "[", "'message'", "]", ";", "switch", "(", "$", "result", ")", "{", "case", "self", "::", "VS", ":", "$", "validate", "=", "true", ";", "break", ";", "case", "self", "::", "ITF", ":", "$", "validate", "=", "false", ";", "break", ";", "default", ":", "$", "validate", "=", "false", ";", "break", ";", "}", "return", "$", "validate", ";", "}" ]
True or false condition whether the transaction is verified @return boolean
[ "True", "or", "false", "condition", "whether", "the", "transaction", "is", "verified" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L214-L233
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.createPlan
public function createPlan() { $data = [ "name" => request()->name, "description" => request()->desc, "amount" => intval(request()->amount), "interval" => request()->interval, "send_invoices" => request()->send_invoices, "send_sms" => request()->send_sms, "currency" => request()->currency, ]; $this->setRequestOptions(); $this->setHttpResponse("/plan", 'POST', $data); }
php
public function createPlan() { $data = [ "name" => request()->name, "description" => request()->desc, "amount" => intval(request()->amount), "interval" => request()->interval, "send_invoices" => request()->send_invoices, "send_sms" => request()->send_sms, "currency" => request()->currency, ]; $this->setRequestOptions(); $this->setHttpResponse("/plan", 'POST', $data); }
[ "public", "function", "createPlan", "(", ")", "{", "$", "data", "=", "[", "\"name\"", "=>", "request", "(", ")", "->", "name", ",", "\"description\"", "=>", "request", "(", ")", "->", "desc", ",", "\"amount\"", "=>", "intval", "(", "request", "(", ")", "->", "amount", ")", ",", "\"interval\"", "=>", "request", "(", ")", "->", "interval", ",", "\"send_invoices\"", "=>", "request", "(", ")", "->", "send_invoices", ",", "\"send_sms\"", "=>", "request", "(", ")", "->", "send_sms", ",", "\"currency\"", "=>", "request", "(", ")", "->", "currency", ",", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "$", "this", "->", "setHttpResponse", "(", "\"/plan\"", ",", "'POST'", ",", "$", "data", ")", ";", "}" ]
Create a plan
[ "Create", "a", "plan" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L329-L345
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.updatePlan
public function updatePlan($plan_code) { $data = [ "name" => request()->name, "description" => request()->desc, "amount" => intval(request()->amount), "interval" => request()->interval, "send_invoices" => request()->send_invoices, "send_sms" => request()->send_sms, "currency" => request()->currency, ]; $this->setRequestOptions(); return $this->setHttpResponse('/plan/' . $plan_code, 'PUT', $data)->getResponse(); }
php
public function updatePlan($plan_code) { $data = [ "name" => request()->name, "description" => request()->desc, "amount" => intval(request()->amount), "interval" => request()->interval, "send_invoices" => request()->send_invoices, "send_sms" => request()->send_sms, "currency" => request()->currency, ]; $this->setRequestOptions(); return $this->setHttpResponse('/plan/' . $plan_code, 'PUT', $data)->getResponse(); }
[ "public", "function", "updatePlan", "(", "$", "plan_code", ")", "{", "$", "data", "=", "[", "\"name\"", "=>", "request", "(", ")", "->", "name", ",", "\"description\"", "=>", "request", "(", ")", "->", "desc", ",", "\"amount\"", "=>", "intval", "(", "request", "(", ")", "->", "amount", ")", ",", "\"interval\"", "=>", "request", "(", ")", "->", "interval", ",", "\"send_invoices\"", "=>", "request", "(", ")", "->", "send_invoices", ",", "\"send_sms\"", "=>", "request", "(", ")", "->", "send_sms", ",", "\"currency\"", "=>", "request", "(", ")", "->", "currency", ",", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "return", "$", "this", "->", "setHttpResponse", "(", "'/plan/'", ".", "$", "plan_code", ",", "'PUT'", ",", "$", "data", ")", "->", "getResponse", "(", ")", ";", "}" ]
Update any plan's details based on its id or code @param $plan_code @return array
[ "Update", "any", "plan", "s", "details", "based", "on", "its", "id", "or", "code" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L363-L377
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.updateCustomer
public function updateCustomer($customer_id) { $data = [ "email" => request()->email, "first_name" => request()->fname, "last_name" => request()->lname, "phone" => request()->phone, "metadata" => request()->additional_info /* key => value pairs array */ ]; $this->setRequestOptions(); return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse(); }
php
public function updateCustomer($customer_id) { $data = [ "email" => request()->email, "first_name" => request()->fname, "last_name" => request()->lname, "phone" => request()->phone, "metadata" => request()->additional_info /* key => value pairs array */ ]; $this->setRequestOptions(); return $this->setHttpResponse('/customer/'. $customer_id, 'PUT', $data)->getResponse(); }
[ "public", "function", "updateCustomer", "(", "$", "customer_id", ")", "{", "$", "data", "=", "[", "\"email\"", "=>", "request", "(", ")", "->", "email", ",", "\"first_name\"", "=>", "request", "(", ")", "->", "fname", ",", "\"last_name\"", "=>", "request", "(", ")", "->", "lname", ",", "\"phone\"", "=>", "request", "(", ")", "->", "phone", ",", "\"metadata\"", "=>", "request", "(", ")", "->", "additional_info", "/* key => value pairs array */", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "return", "$", "this", "->", "setHttpResponse", "(", "'/customer/'", ".", "$", "customer_id", ",", "'PUT'", ",", "$", "data", ")", "->", "getResponse", "(", ")", ";", "}" ]
Update a customer's details based on their id or code @param $customer_id @return array
[ "Update", "a", "customer", "s", "details", "based", "on", "their", "id", "or", "code" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L413-L426
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.exportTransactions
public function exportTransactions() { $data = [ "from" => request()->from, "to" => request()->to, 'settled' => request()->settled ]; $this->setRequestOptions(); return $this->setHttpResponse('/transaction/export', 'GET', $data)->getResponse(); }
php
public function exportTransactions() { $data = [ "from" => request()->from, "to" => request()->to, 'settled' => request()->settled ]; $this->setRequestOptions(); return $this->setHttpResponse('/transaction/export', 'GET', $data)->getResponse(); }
[ "public", "function", "exportTransactions", "(", ")", "{", "$", "data", "=", "[", "\"from\"", "=>", "request", "(", ")", "->", "from", ",", "\"to\"", "=>", "request", "(", ")", "->", "to", ",", "'settled'", "=>", "request", "(", ")", "->", "settled", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "return", "$", "this", "->", "setHttpResponse", "(", "'/transaction/export'", ",", "'GET'", ",", "$", "data", ")", "->", "getResponse", "(", ")", ";", "}" ]
Export transactions in .CSV @return array
[ "Export", "transactions", "in", ".", "CSV" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L432-L442
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.createSubscription
public function createSubscription() { $data = [ "customer" => request()->customer, //Customer email or code "plan" => request()->plan, "authorization" => request()->authorization_code ]; $this->setRequestOptions(); $this->setHttpResponse('/subscription', 'POST', $data); }
php
public function createSubscription() { $data = [ "customer" => request()->customer, //Customer email or code "plan" => request()->plan, "authorization" => request()->authorization_code ]; $this->setRequestOptions(); $this->setHttpResponse('/subscription', 'POST', $data); }
[ "public", "function", "createSubscription", "(", ")", "{", "$", "data", "=", "[", "\"customer\"", "=>", "request", "(", ")", "->", "customer", ",", "//Customer email or code", "\"plan\"", "=>", "request", "(", ")", "->", "plan", ",", "\"authorization\"", "=>", "request", "(", ")", "->", "authorization_code", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "$", "this", "->", "setHttpResponse", "(", "'/subscription'", ",", "'POST'", ",", "$", "data", ")", ";", "}" ]
Create a subscription to a plan from a customer.
[ "Create", "a", "subscription", "to", "a", "plan", "from", "a", "customer", "." ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L447-L457
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.enableSubscription
public function enableSubscription() { $data = [ "code" => request()->code, "token" => request()->token, ]; $this->setRequestOptions(); return $this->setHttpResponse('/subscription/enable', 'POST', $data)->getResponse(); }
php
public function enableSubscription() { $data = [ "code" => request()->code, "token" => request()->token, ]; $this->setRequestOptions(); return $this->setHttpResponse('/subscription/enable', 'POST', $data)->getResponse(); }
[ "public", "function", "enableSubscription", "(", ")", "{", "$", "data", "=", "[", "\"code\"", "=>", "request", "(", ")", "->", "code", ",", "\"token\"", "=>", "request", "(", ")", "->", "token", ",", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "return", "$", "this", "->", "setHttpResponse", "(", "'/subscription/enable'", ",", "'POST'", ",", "$", "data", ")", "->", "getResponse", "(", ")", ";", "}" ]
Enable a subscription using the subscription code and token @return array
[ "Enable", "a", "subscription", "using", "the", "subscription", "code", "and", "token" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L501-L510
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.createPage
public function createPage() { $data = [ "name" => request()->name, "description" => request()->description, "amount" => request()->amount ]; $this->setRequestOptions(); $this->setHttpResponse('/page', 'POST', $data); }
php
public function createPage() { $data = [ "name" => request()->name, "description" => request()->description, "amount" => request()->amount ]; $this->setRequestOptions(); $this->setHttpResponse('/page', 'POST', $data); }
[ "public", "function", "createPage", "(", ")", "{", "$", "data", "=", "[", "\"name\"", "=>", "request", "(", ")", "->", "name", ",", "\"description\"", "=>", "request", "(", ")", "->", "description", ",", "\"amount\"", "=>", "request", "(", ")", "->", "amount", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "$", "this", "->", "setHttpResponse", "(", "'/page'", ",", "'POST'", ",", "$", "data", ")", ";", "}" ]
Create pages you can share with users using the returned slug
[ "Create", "pages", "you", "can", "share", "with", "users", "using", "the", "returned", "slug" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L541-L551
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.updatePage
public function updatePage($page_id) { $data = [ "name" => request()->name, "description" => request()->description, "amount" => request()->amount ]; $this->setRequestOptions(); return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse(); }
php
public function updatePage($page_id) { $data = [ "name" => request()->name, "description" => request()->description, "amount" => request()->amount ]; $this->setRequestOptions(); return $this->setHttpResponse('/page/'.$page_id, 'PUT', $data)->getResponse(); }
[ "public", "function", "updatePage", "(", "$", "page_id", ")", "{", "$", "data", "=", "[", "\"name\"", "=>", "request", "(", ")", "->", "name", ",", "\"description\"", "=>", "request", "(", ")", "->", "description", ",", "\"amount\"", "=>", "request", "(", ")", "->", "amount", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "return", "$", "this", "->", "setHttpResponse", "(", "'/page/'", ".", "$", "page_id", ",", "'PUT'", ",", "$", "data", ")", "->", "getResponse", "(", ")", ";", "}" ]
Update the details about a particular page @param $page_id @return array
[ "Update", "the", "details", "about", "a", "particular", "page" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L579-L589
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.listSubAccounts
public function listSubAccounts($per_page,$page){ $this->setRequestOptions(); return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse(); }
php
public function listSubAccounts($per_page,$page){ $this->setRequestOptions(); return $this->setHttpResponse("/subaccount/?perPage=".(int) $per_page."&page=".(int) $page,"GET")->getResponse(); }
[ "public", "function", "listSubAccounts", "(", "$", "per_page", ",", "$", "page", ")", "{", "$", "this", "->", "setRequestOptions", "(", ")", ";", "return", "$", "this", "->", "setHttpResponse", "(", "\"/subaccount/?perPage=\"", ".", "(", "int", ")", "$", "per_page", ".", "\"&page=\"", ".", "(", "int", ")", "$", "page", ",", "\"GET\"", ")", "->", "getResponse", "(", ")", ";", "}" ]
Lists all the subaccounts associated with the account @param $per_page - Specifies how many records to retrieve per page , $page - SPecifies exactly what page to retrieve @return array
[ "Lists", "all", "the", "subaccounts", "associated", "with", "the", "account" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L632-L637
train
unicodeveloper/laravel-paystack
src/Paystack.php
Paystack.updateSubAccount
public function updateSubAccount($subaccount_code){ $data = [ "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, "account_number" => request()->account_number, "percentage_charge" => request()->percentage_charge, "description" => request()->description, "primary_contact_email" => request()->primary_contact_email, "primary_contact_name" => request()->primary_contact_name, "primary_contact_phone" => request()->primary_contact_phone, "metadata" => request()->metadata, 'settlement_schedule' => request()->settlement_schedule ]; $this->setRequestOptions(); return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse(); }
php
public function updateSubAccount($subaccount_code){ $data = [ "business_name" => request()->business_name, "settlement_bank" => request()->settlement_bank, "account_number" => request()->account_number, "percentage_charge" => request()->percentage_charge, "description" => request()->description, "primary_contact_email" => request()->primary_contact_email, "primary_contact_name" => request()->primary_contact_name, "primary_contact_phone" => request()->primary_contact_phone, "metadata" => request()->metadata, 'settlement_schedule' => request()->settlement_schedule ]; $this->setRequestOptions(); return $this->setHttpResponse("/subaccount/{$subaccount_code}", "PUT", array_filter($data))->getResponse(); }
[ "public", "function", "updateSubAccount", "(", "$", "subaccount_code", ")", "{", "$", "data", "=", "[", "\"business_name\"", "=>", "request", "(", ")", "->", "business_name", ",", "\"settlement_bank\"", "=>", "request", "(", ")", "->", "settlement_bank", ",", "\"account_number\"", "=>", "request", "(", ")", "->", "account_number", ",", "\"percentage_charge\"", "=>", "request", "(", ")", "->", "percentage_charge", ",", "\"description\"", "=>", "request", "(", ")", "->", "description", ",", "\"primary_contact_email\"", "=>", "request", "(", ")", "->", "primary_contact_email", ",", "\"primary_contact_name\"", "=>", "request", "(", ")", "->", "primary_contact_name", ",", "\"primary_contact_phone\"", "=>", "request", "(", ")", "->", "primary_contact_phone", ",", "\"metadata\"", "=>", "request", "(", ")", "->", "metadata", ",", "'settlement_schedule'", "=>", "request", "(", ")", "->", "settlement_schedule", "]", ";", "$", "this", "->", "setRequestOptions", "(", ")", ";", "return", "$", "this", "->", "setHttpResponse", "(", "\"/subaccount/{$subaccount_code}\"", ",", "\"PUT\"", ",", "array_filter", "(", "$", "data", ")", ")", "->", "getResponse", "(", ")", ";", "}" ]
Updates a subaccount to be used for split payments . Required params are business_name , settlement_bank , account_number , percentage_charge @param subaccount code @return array
[ "Updates", "a", "subaccount", "to", "be", "used", "for", "split", "payments", ".", "Required", "params", "are", "business_name", "settlement_bank", "account_number", "percentage_charge" ]
1150bf5f1be5cb765d1221fbc4489d27283538b1
https://github.com/unicodeveloper/laravel-paystack/blob/1150bf5f1be5cb765d1221fbc4489d27283538b1/src/Paystack.php#L646-L663
train
phpro/grumphp
src/Console/Helper/PathsHelper.php
PathsHelper.getAsciiContent
public function getAsciiContent(string $resource): string { $file = $this->config->getAsciiContentPath($resource); // Disabled: if (null === $file) { return ''; } // Specified by user: if ($this->fileSystem->exists($file)) { return $this->fileSystem->readFromFileInfo(new SplFileInfo($file)); } // Embedded ASCII art: $embeddedFile = $this->getAsciiPath().$file; if ($this->fileSystem->exists($embeddedFile)) { return $this->fileSystem->readFromFileInfo(new SplFileInfo($embeddedFile)); } // Error: return sprintf('ASCII file %s could not be found.', $file); }
php
public function getAsciiContent(string $resource): string { $file = $this->config->getAsciiContentPath($resource); // Disabled: if (null === $file) { return ''; } // Specified by user: if ($this->fileSystem->exists($file)) { return $this->fileSystem->readFromFileInfo(new SplFileInfo($file)); } // Embedded ASCII art: $embeddedFile = $this->getAsciiPath().$file; if ($this->fileSystem->exists($embeddedFile)) { return $this->fileSystem->readFromFileInfo(new SplFileInfo($embeddedFile)); } // Error: return sprintf('ASCII file %s could not be found.', $file); }
[ "public", "function", "getAsciiContent", "(", "string", "$", "resource", ")", ":", "string", "{", "$", "file", "=", "$", "this", "->", "config", "->", "getAsciiContentPath", "(", "$", "resource", ")", ";", "// Disabled:", "if", "(", "null", "===", "$", "file", ")", "{", "return", "''", ";", "}", "// Specified by user:", "if", "(", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "file", ")", ")", "{", "return", "$", "this", "->", "fileSystem", "->", "readFromFileInfo", "(", "new", "SplFileInfo", "(", "$", "file", ")", ")", ";", "}", "// Embedded ASCII art:", "$", "embeddedFile", "=", "$", "this", "->", "getAsciiPath", "(", ")", ".", "$", "file", ";", "if", "(", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "embeddedFile", ")", ")", "{", "return", "$", "this", "->", "fileSystem", "->", "readFromFileInfo", "(", "new", "SplFileInfo", "(", "$", "embeddedFile", ")", ")", ";", "}", "// Error:", "return", "sprintf", "(", "'ASCII file %s could not be found.'", ",", "$", "file", ")", ";", "}" ]
Load an ascii image.
[ "Load", "an", "ascii", "image", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Helper/PathsHelper.php#L83-L105
train
phpro/grumphp
src/Console/Helper/PathsHelper.php
PathsHelper.getGitDir
public function getGitDir(): string { $gitDir = $this->config->getGitDir(); if (!$this->fileSystem->exists($gitDir)) { throw new RuntimeException('The configured GIT directory could not be found.'); } return $this->getRelativePath($gitDir); }
php
public function getGitDir(): string { $gitDir = $this->config->getGitDir(); if (!$this->fileSystem->exists($gitDir)) { throw new RuntimeException('The configured GIT directory could not be found.'); } return $this->getRelativePath($gitDir); }
[ "public", "function", "getGitDir", "(", ")", ":", "string", "{", "$", "gitDir", "=", "$", "this", "->", "config", "->", "getGitDir", "(", ")", ";", "if", "(", "!", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "gitDir", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'The configured GIT directory could not be found.'", ")", ";", "}", "return", "$", "this", "->", "getRelativePath", "(", "$", "gitDir", ")", ";", "}" ]
Find the relative git directory.
[ "Find", "the", "relative", "git", "directory", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Helper/PathsHelper.php#L119-L127
train
phpro/grumphp
src/Console/Helper/PathsHelper.php
PathsHelper.getGitHookExecutionPath
public function getGitHookExecutionPath(): string { $gitPath = $this->getGitDir(); return $this->fileSystem->makePathRelative($this->getWorkingDir(), $this->getAbsolutePath($gitPath)); }
php
public function getGitHookExecutionPath(): string { $gitPath = $this->getGitDir(); return $this->fileSystem->makePathRelative($this->getWorkingDir(), $this->getAbsolutePath($gitPath)); }
[ "public", "function", "getGitHookExecutionPath", "(", ")", ":", "string", "{", "$", "gitPath", "=", "$", "this", "->", "getGitDir", "(", ")", ";", "return", "$", "this", "->", "fileSystem", "->", "makePathRelative", "(", "$", "this", "->", "getWorkingDir", "(", ")", ",", "$", "this", "->", "getAbsolutePath", "(", "$", "gitPath", ")", ")", ";", "}" ]
Gets the path from where the command needs to be executed in the GIT hook.
[ "Gets", "the", "path", "from", "where", "the", "command", "needs", "to", "be", "executed", "in", "the", "GIT", "hook", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Helper/PathsHelper.php#L132-L137
train
phpro/grumphp
src/Console/Helper/PathsHelper.php
PathsHelper.getGitHooksDir
public function getGitHooksDir(): string { $gitPath = $this->getGitDir(); $absoluteGitPath = $this->getAbsolutePath($gitPath); $gitRepoPath = $absoluteGitPath.'/.git'; if (is_file($gitRepoPath)) { $fileContent = $this->fileSystem->readFromFileInfo(new SplFileInfo($gitRepoPath)); if (preg_match('/gitdir:\s+(\S+)/', $fileContent, $matches)) { $relativePath = $this->getRelativePath($matches[1]); return $this->getRelativePath($gitPath.$relativePath.'/hooks/'); } } return $gitPath.'.git/hooks/'; }
php
public function getGitHooksDir(): string { $gitPath = $this->getGitDir(); $absoluteGitPath = $this->getAbsolutePath($gitPath); $gitRepoPath = $absoluteGitPath.'/.git'; if (is_file($gitRepoPath)) { $fileContent = $this->fileSystem->readFromFileInfo(new SplFileInfo($gitRepoPath)); if (preg_match('/gitdir:\s+(\S+)/', $fileContent, $matches)) { $relativePath = $this->getRelativePath($matches[1]); return $this->getRelativePath($gitPath.$relativePath.'/hooks/'); } } return $gitPath.'.git/hooks/'; }
[ "public", "function", "getGitHooksDir", "(", ")", ":", "string", "{", "$", "gitPath", "=", "$", "this", "->", "getGitDir", "(", ")", ";", "$", "absoluteGitPath", "=", "$", "this", "->", "getAbsolutePath", "(", "$", "gitPath", ")", ";", "$", "gitRepoPath", "=", "$", "absoluteGitPath", ".", "'/.git'", ";", "if", "(", "is_file", "(", "$", "gitRepoPath", ")", ")", "{", "$", "fileContent", "=", "$", "this", "->", "fileSystem", "->", "readFromFileInfo", "(", "new", "SplFileInfo", "(", "$", "gitRepoPath", ")", ")", ";", "if", "(", "preg_match", "(", "'/gitdir:\\s+(\\S+)/'", ",", "$", "fileContent", ",", "$", "matches", ")", ")", "{", "$", "relativePath", "=", "$", "this", "->", "getRelativePath", "(", "$", "matches", "[", "1", "]", ")", ";", "return", "$", "this", "->", "getRelativePath", "(", "$", "gitPath", ".", "$", "relativePath", ".", "'/hooks/'", ")", ";", "}", "}", "return", "$", "gitPath", ".", "'.git/hooks/'", ";", "}" ]
Returns the directory where the git hooks are installed.
[ "Returns", "the", "directory", "where", "the", "git", "hooks", "are", "installed", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Helper/PathsHelper.php#L142-L157
train
phpro/grumphp
src/Console/Helper/PathsHelper.php
PathsHelper.getBinDir
public function getBinDir(): string { $binDir = $this->config->getBinDir(); if (!$this->fileSystem->exists($binDir)) { throw new RuntimeException('The configured BIN directory could not be found.'); } return $this->getRelativePath($binDir); }
php
public function getBinDir(): string { $binDir = $this->config->getBinDir(); if (!$this->fileSystem->exists($binDir)) { throw new RuntimeException('The configured BIN directory could not be found.'); } return $this->getRelativePath($binDir); }
[ "public", "function", "getBinDir", "(", ")", ":", "string", "{", "$", "binDir", "=", "$", "this", "->", "config", "->", "getBinDir", "(", ")", ";", "if", "(", "!", "$", "this", "->", "fileSystem", "->", "exists", "(", "$", "binDir", ")", ")", "{", "throw", "new", "RuntimeException", "(", "'The configured BIN directory could not be found.'", ")", ";", "}", "return", "$", "this", "->", "getRelativePath", "(", "$", "binDir", ")", ";", "}" ]
Find the relative bin directory.
[ "Find", "the", "relative", "bin", "directory", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Helper/PathsHelper.php#L170-L178
train
phpro/grumphp
src/Console/Helper/PathsHelper.php
PathsHelper.getRelativeProjectPath
public function getRelativeProjectPath(string $path): string { $realPath = $this->getAbsolutePath($path); $gitPath = $this->getAbsolutePath($this->getGitDir()); if (0 !== strpos($realPath, $gitPath)) { return $realPath; } return rtrim($this->getRelativePath($realPath), '\\/'); }
php
public function getRelativeProjectPath(string $path): string { $realPath = $this->getAbsolutePath($path); $gitPath = $this->getAbsolutePath($this->getGitDir()); if (0 !== strpos($realPath, $gitPath)) { return $realPath; } return rtrim($this->getRelativePath($realPath), '\\/'); }
[ "public", "function", "getRelativeProjectPath", "(", "string", "$", "path", ")", ":", "string", "{", "$", "realPath", "=", "$", "this", "->", "getAbsolutePath", "(", "$", "path", ")", ";", "$", "gitPath", "=", "$", "this", "->", "getAbsolutePath", "(", "$", "this", "->", "getGitDir", "(", ")", ")", ";", "if", "(", "0", "!==", "strpos", "(", "$", "realPath", ",", "$", "gitPath", ")", ")", "{", "return", "$", "realPath", ";", "}", "return", "rtrim", "(", "$", "this", "->", "getRelativePath", "(", "$", "realPath", ")", ",", "'\\\\/'", ")", ";", "}" ]
This method will return a relative path to a file of directory if it lives in the current project. When the file is not located in the current project, the absolute path to the file is returned. @throws FileNotFoundException
[ "This", "method", "will", "return", "a", "relative", "path", "to", "a", "file", "of", "directory", "if", "it", "lives", "in", "the", "current", "project", ".", "When", "the", "file", "is", "not", "located", "in", "the", "current", "project", "the", "absolute", "path", "to", "the", "file", "is", "returned", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Helper/PathsHelper.php#L206-L216
train
phpro/grumphp
src/Util/Str.php
Str.containsOneOf
public static function containsOneOf($haystack, array $needles) { foreach ($needles as $needle) { if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { return true; } } return false; }
php
public static function containsOneOf($haystack, array $needles) { foreach ($needles as $needle) { if ($needle !== '' && mb_strpos($haystack, $needle) !== false) { return true; } } return false; }
[ "public", "static", "function", "containsOneOf", "(", "$", "haystack", ",", "array", "$", "needles", ")", "{", "foreach", "(", "$", "needles", "as", "$", "needle", ")", "{", "if", "(", "$", "needle", "!==", "''", "&&", "mb_strpos", "(", "$", "haystack", ",", "$", "needle", ")", "!==", "false", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
String contains one of the provided needles @param string $haystack @param array $needles @return bool
[ "String", "contains", "one", "of", "the", "provided", "needles" ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Util/Str.php#L14-L23
train
phpro/grumphp
src/Collection/ProcessArgumentsCollection.php
ProcessArgumentsCollection.addArgumentArrayWithSeparatedValue
public function addArgumentArrayWithSeparatedValue(string $argument, array $values) { foreach ($values as $value) { $this->add(sprintf($argument, $value)); $this->add($value); } }
php
public function addArgumentArrayWithSeparatedValue(string $argument, array $values) { foreach ($values as $value) { $this->add(sprintf($argument, $value)); $this->add($value); } }
[ "public", "function", "addArgumentArrayWithSeparatedValue", "(", "string", "$", "argument", ",", "array", "$", "values", ")", "{", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "$", "this", "->", "add", "(", "sprintf", "(", "$", "argument", ",", "$", "value", ")", ")", ";", "$", "this", "->", "add", "(", "$", "value", ")", ";", "}", "}" ]
Some CLI tools prefer to split the argument and the value.
[ "Some", "CLI", "tools", "prefer", "to", "split", "the", "argument", "and", "the", "value", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Collection/ProcessArgumentsCollection.php#L58-L64
train
phpro/grumphp
src/Configuration/Compiler/PhpParserCompilerPass.php
PhpParserCompilerPass.process
public function process(ContainerBuilder $container) { $traverserConfigurator = $container->findDefinition('grumphp.parser.php.configurator.traverser'); foreach ($container->findTaggedServiceIds(self::TAG) as $id => $tags) { $definition = $container->findDefinition($id); $this->markServiceAsPrototype($definition); foreach ($tags as $tag) { $alias = array_key_exists('alias', $tag) ? $tag['alias'] : $id; $traverserConfigurator->addMethodCall('registerVisitorId', [$alias, $id]); } } }
php
public function process(ContainerBuilder $container) { $traverserConfigurator = $container->findDefinition('grumphp.parser.php.configurator.traverser'); foreach ($container->findTaggedServiceIds(self::TAG) as $id => $tags) { $definition = $container->findDefinition($id); $this->markServiceAsPrototype($definition); foreach ($tags as $tag) { $alias = array_key_exists('alias', $tag) ? $tag['alias'] : $id; $traverserConfigurator->addMethodCall('registerVisitorId', [$alias, $id]); } } }
[ "public", "function", "process", "(", "ContainerBuilder", "$", "container", ")", "{", "$", "traverserConfigurator", "=", "$", "container", "->", "findDefinition", "(", "'grumphp.parser.php.configurator.traverser'", ")", ";", "foreach", "(", "$", "container", "->", "findTaggedServiceIds", "(", "self", "::", "TAG", ")", "as", "$", "id", "=>", "$", "tags", ")", "{", "$", "definition", "=", "$", "container", "->", "findDefinition", "(", "$", "id", ")", ";", "$", "this", "->", "markServiceAsPrototype", "(", "$", "definition", ")", ";", "foreach", "(", "$", "tags", "as", "$", "tag", ")", "{", "$", "alias", "=", "array_key_exists", "(", "'alias'", ",", "$", "tag", ")", "?", "$", "tag", "[", "'alias'", "]", ":", "$", "id", ";", "$", "traverserConfigurator", "->", "addMethodCall", "(", "'registerVisitorId'", ",", "[", "$", "alias", ",", "$", "id", "]", ")", ";", "}", "}", "}" ]
Sets the visitors as non shared services. This will make sure that the state of the visitor won't need to be reset after an iteration of the traverser. All visitor Ids are registered in the traverser configurator. The configurator will be used to apply the configured visitors to the traverser. @throws \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
[ "Sets", "the", "visitors", "as", "non", "shared", "services", ".", "This", "will", "make", "sure", "that", "the", "state", "of", "the", "visitor", "won", "t", "need", "to", "be", "reset", "after", "an", "iteration", "of", "the", "traverser", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Configuration/Compiler/PhpParserCompilerPass.php#L27-L38
train
phpro/grumphp
src/Configuration/Compiler/PhpParserCompilerPass.php
PhpParserCompilerPass.markServiceAsPrototype
public function markServiceAsPrototype(Definition $definition) { if (method_exists($definition, 'setShared')) { $definition->setShared(false); return; } if (method_exists($definition, 'setScope')) { $definition->setScope('prototype'); return; } throw new RuntimeException('The visitor could not be marked as unshared'); }
php
public function markServiceAsPrototype(Definition $definition) { if (method_exists($definition, 'setShared')) { $definition->setShared(false); return; } if (method_exists($definition, 'setScope')) { $definition->setScope('prototype'); return; } throw new RuntimeException('The visitor could not be marked as unshared'); }
[ "public", "function", "markServiceAsPrototype", "(", "Definition", "$", "definition", ")", "{", "if", "(", "method_exists", "(", "$", "definition", ",", "'setShared'", ")", ")", "{", "$", "definition", "->", "setShared", "(", "false", ")", ";", "return", ";", "}", "if", "(", "method_exists", "(", "$", "definition", ",", "'setScope'", ")", ")", "{", "$", "definition", "->", "setScope", "(", "'prototype'", ")", ";", "return", ";", "}", "throw", "new", "RuntimeException", "(", "'The visitor could not be marked as unshared'", ")", ";", "}" ]
This method can be used to make the service shared cross-version. From Symfony 2.8 the setShared method was available. The 2.7 version is the LTS, so we still need to support it. @see http://symfony.com/blog/new-in-symfony-3-1-customizable-yaml-parsing-and-dumping @throws \GrumPHP\Exception\RuntimeException
[ "This", "method", "can", "be", "used", "to", "make", "the", "service", "shared", "cross", "-", "version", ".", "From", "Symfony", "2", ".", "8", "the", "setShared", "method", "was", "available", ".", "The", "2", ".", "7", "version", "is", "the", "LTS", "so", "we", "still", "need", "to", "support", "it", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Configuration/Compiler/PhpParserCompilerPass.php#L49-L64
train
phpro/grumphp
src/Composer/GrumPHPPlugin.php
GrumPHPPlugin.postPackageInstall
public function postPackageInstall(PackageEvent $event) { /** @var InstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // Schedule init when command is completed $this->configureScheduled = true; $this->initScheduled = true; }
php
public function postPackageInstall(PackageEvent $event) { /** @var InstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // Schedule init when command is completed $this->configureScheduled = true; $this->initScheduled = true; }
[ "public", "function", "postPackageInstall", "(", "PackageEvent", "$", "event", ")", "{", "/** @var InstallOperation $operation */", "$", "operation", "=", "$", "event", "->", "getOperation", "(", ")", ";", "$", "package", "=", "$", "operation", "->", "getPackage", "(", ")", ";", "if", "(", "!", "$", "this", "->", "guardIsGrumPhpPackage", "(", "$", "package", ")", ")", "{", "return", ";", "}", "// Schedule init when command is completed", "$", "this", "->", "configureScheduled", "=", "true", ";", "$", "this", "->", "initScheduled", "=", "true", ";", "}" ]
When this package is updated, the git hook is also initialized.
[ "When", "this", "package", "is", "updated", "the", "git", "hook", "is", "also", "initialized", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Composer/GrumPHPPlugin.php#L79-L92
train
phpro/grumphp
src/Composer/GrumPHPPlugin.php
GrumPHPPlugin.postPackageUpdate
public function postPackageUpdate(PackageEvent $event) { /** @var UpdateOperation $operation */ $operation = $event->getOperation(); $package = $operation->getTargetPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // Schedule init when command is completed $this->initScheduled = true; }
php
public function postPackageUpdate(PackageEvent $event) { /** @var UpdateOperation $operation */ $operation = $event->getOperation(); $package = $operation->getTargetPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // Schedule init when command is completed $this->initScheduled = true; }
[ "public", "function", "postPackageUpdate", "(", "PackageEvent", "$", "event", ")", "{", "/** @var UpdateOperation $operation */", "$", "operation", "=", "$", "event", "->", "getOperation", "(", ")", ";", "$", "package", "=", "$", "operation", "->", "getTargetPackage", "(", ")", ";", "if", "(", "!", "$", "this", "->", "guardIsGrumPhpPackage", "(", "$", "package", ")", ")", "{", "return", ";", "}", "// Schedule init when command is completed", "$", "this", "->", "initScheduled", "=", "true", ";", "}" ]
When this package is updated, the git hook is also updated.
[ "When", "this", "package", "is", "updated", "the", "git", "hook", "is", "also", "updated", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Composer/GrumPHPPlugin.php#L97-L109
train
phpro/grumphp
src/Composer/GrumPHPPlugin.php
GrumPHPPlugin.prePackageUninstall
public function prePackageUninstall(PackageEvent $event) { /** @var UninstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // First remove the hook, before everything is deleted! $this->deInitGitHook(); }
php
public function prePackageUninstall(PackageEvent $event) { /** @var UninstallOperation $operation */ $operation = $event->getOperation(); $package = $operation->getPackage(); if (!$this->guardIsGrumPhpPackage($package)) { return; } // First remove the hook, before everything is deleted! $this->deInitGitHook(); }
[ "public", "function", "prePackageUninstall", "(", "PackageEvent", "$", "event", ")", "{", "/** @var UninstallOperation $operation */", "$", "operation", "=", "$", "event", "->", "getOperation", "(", ")", ";", "$", "package", "=", "$", "operation", "->", "getPackage", "(", ")", ";", "if", "(", "!", "$", "this", "->", "guardIsGrumPhpPackage", "(", "$", "package", ")", ")", "{", "return", ";", "}", "// First remove the hook, before everything is deleted!", "$", "this", "->", "deInitGitHook", "(", ")", ";", "}" ]
When this package is uninstalled, the generated git hooks need to be removed.
[ "When", "this", "package", "is", "uninstalled", "the", "generated", "git", "hooks", "need", "to", "be", "removed", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Composer/GrumPHPPlugin.php#L114-L126
train
phpro/grumphp
src/Console/Command/Git/InitCommand.php
InitCommand.useExoticConfigFile
protected function useExoticConfigFile() { try { $configPath = $this->paths()->getAbsolutePath($this->input->getOption('config')); if ($configPath !== $this->paths()->getDefaultConfigPath()) { return $this->paths()->getRelativeProjectPath($configPath); } } catch (FileNotFoundException $e) { // no config file should be set. } return null; }
php
protected function useExoticConfigFile() { try { $configPath = $this->paths()->getAbsolutePath($this->input->getOption('config')); if ($configPath !== $this->paths()->getDefaultConfigPath()) { return $this->paths()->getRelativeProjectPath($configPath); } } catch (FileNotFoundException $e) { // no config file should be set. } return null; }
[ "protected", "function", "useExoticConfigFile", "(", ")", "{", "try", "{", "$", "configPath", "=", "$", "this", "->", "paths", "(", ")", "->", "getAbsolutePath", "(", "$", "this", "->", "input", "->", "getOption", "(", "'config'", ")", ")", ";", "if", "(", "$", "configPath", "!==", "$", "this", "->", "paths", "(", ")", "->", "getDefaultConfigPath", "(", ")", ")", "{", "return", "$", "this", "->", "paths", "(", ")", "->", "getRelativeProjectPath", "(", "$", "configPath", ")", ";", "}", "}", "catch", "(", "FileNotFoundException", "$", "e", ")", "{", "// no config file should be set.", "}", "return", "null", ";", "}" ]
This method will tell you which exotic configuration file should be used. @return null|string
[ "This", "method", "will", "tell", "you", "which", "exotic", "configuration", "file", "should", "be", "used", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Command/Git/InitCommand.php#L149-L161
train
phpro/grumphp
src/Composer/DevelopmentIntegrator.php
DevelopmentIntegrator.integrate
public static function integrate(Event $event) { $filesystem = new Filesystem(); $composerBinDir = $event->getComposer()->getConfig()->get('bin-dir'); $executable = getcwd().'/bin/grumphp'; $composerExecutable = $composerBinDir.'/grumphp'; $filesystem->copy( self::noramlizePath($executable), self::noramlizePath($composerExecutable) ); $commandlineArgs = ProcessArgumentsCollection::forExecutable($composerExecutable); $commandlineArgs->add('git:init'); $process = ProcessFactory::fromArguments($commandlineArgs); $process->run(); if (!$process->isSuccessful()) { $event->getIO()->write( '<fg=red>GrumPHP can not sniff your commits. Did you specify the correct git-dir?</fg=red>' ); $event->getIO()->write('<fg=red>'.$process->getErrorOutput().'</fg=red>'); return; } $event->getIO()->write('<fg=yellow>'.$process->getOutput().'</fg=yellow>'); }
php
public static function integrate(Event $event) { $filesystem = new Filesystem(); $composerBinDir = $event->getComposer()->getConfig()->get('bin-dir'); $executable = getcwd().'/bin/grumphp'; $composerExecutable = $composerBinDir.'/grumphp'; $filesystem->copy( self::noramlizePath($executable), self::noramlizePath($composerExecutable) ); $commandlineArgs = ProcessArgumentsCollection::forExecutable($composerExecutable); $commandlineArgs->add('git:init'); $process = ProcessFactory::fromArguments($commandlineArgs); $process->run(); if (!$process->isSuccessful()) { $event->getIO()->write( '<fg=red>GrumPHP can not sniff your commits. Did you specify the correct git-dir?</fg=red>' ); $event->getIO()->write('<fg=red>'.$process->getErrorOutput().'</fg=red>'); return; } $event->getIO()->write('<fg=yellow>'.$process->getOutput().'</fg=yellow>'); }
[ "public", "static", "function", "integrate", "(", "Event", "$", "event", ")", "{", "$", "filesystem", "=", "new", "Filesystem", "(", ")", ";", "$", "composerBinDir", "=", "$", "event", "->", "getComposer", "(", ")", "->", "getConfig", "(", ")", "->", "get", "(", "'bin-dir'", ")", ";", "$", "executable", "=", "getcwd", "(", ")", ".", "'/bin/grumphp'", ";", "$", "composerExecutable", "=", "$", "composerBinDir", ".", "'/grumphp'", ";", "$", "filesystem", "->", "copy", "(", "self", "::", "noramlizePath", "(", "$", "executable", ")", ",", "self", "::", "noramlizePath", "(", "$", "composerExecutable", ")", ")", ";", "$", "commandlineArgs", "=", "ProcessArgumentsCollection", "::", "forExecutable", "(", "$", "composerExecutable", ")", ";", "$", "commandlineArgs", "->", "add", "(", "'git:init'", ")", ";", "$", "process", "=", "ProcessFactory", "::", "fromArguments", "(", "$", "commandlineArgs", ")", ";", "$", "process", "->", "run", "(", ")", ";", "if", "(", "!", "$", "process", "->", "isSuccessful", "(", ")", ")", "{", "$", "event", "->", "getIO", "(", ")", "->", "write", "(", "'<fg=red>GrumPHP can not sniff your commits. Did you specify the correct git-dir?</fg=red>'", ")", ";", "$", "event", "->", "getIO", "(", ")", "->", "write", "(", "'<fg=red>'", ".", "$", "process", "->", "getErrorOutput", "(", ")", ".", "'</fg=red>'", ")", ";", "return", ";", "}", "$", "event", "->", "getIO", "(", ")", "->", "write", "(", "'<fg=yellow>'", ".", "$", "process", "->", "getOutput", "(", ")", ".", "'</fg=yellow>'", ")", ";", "}" ]
This method makes sure that GrumPHP registers itself during development.
[ "This", "method", "makes", "sure", "that", "GrumPHP", "registers", "itself", "during", "development", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Composer/DevelopmentIntegrator.php#L17-L44
train
phpro/grumphp
src/Configuration/GrumPHP.php
GrumPHP.getAsciiContentPath
public function getAsciiContentPath(string $resource) { if (null === $this->container->getParameter('ascii')) { return null; } $paths = $this->container->getParameter('ascii'); if (!array_key_exists($resource, $paths)) { return null; } // Deal with multiple ascii files by returning one at random. if (\is_array($paths[$resource])) { shuffle($paths[$resource]); return reset($paths[$resource]); } return $paths[$resource]; }
php
public function getAsciiContentPath(string $resource) { if (null === $this->container->getParameter('ascii')) { return null; } $paths = $this->container->getParameter('ascii'); if (!array_key_exists($resource, $paths)) { return null; } // Deal with multiple ascii files by returning one at random. if (\is_array($paths[$resource])) { shuffle($paths[$resource]); return reset($paths[$resource]); } return $paths[$resource]; }
[ "public", "function", "getAsciiContentPath", "(", "string", "$", "resource", ")", "{", "if", "(", "null", "===", "$", "this", "->", "container", "->", "getParameter", "(", "'ascii'", ")", ")", "{", "return", "null", ";", "}", "$", "paths", "=", "$", "this", "->", "container", "->", "getParameter", "(", "'ascii'", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "resource", ",", "$", "paths", ")", ")", "{", "return", "null", ";", "}", "// Deal with multiple ascii files by returning one at random.", "if", "(", "\\", "is_array", "(", "$", "paths", "[", "$", "resource", "]", ")", ")", "{", "shuffle", "(", "$", "paths", "[", "$", "resource", "]", ")", ";", "return", "reset", "(", "$", "paths", "[", "$", "resource", "]", ")", ";", "}", "return", "$", "paths", "[", "$", "resource", "]", ";", "}" ]
Get ascii content path from grumphp.yml file. @return string|null
[ "Get", "ascii", "content", "path", "from", "grumphp", ".", "yml", "file", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Configuration/GrumPHP.php#L138-L156
train
phpro/grumphp
src/Console/Application.php
Application.updateUserConfigPath
private function updateUserConfigPath(string $configPath): string { if ($configPath !== $this->getDefaultConfigPath()) { $configPath = getcwd().DIRECTORY_SEPARATOR.$configPath; } return $configPath; }
php
private function updateUserConfigPath(string $configPath): string { if ($configPath !== $this->getDefaultConfigPath()) { $configPath = getcwd().DIRECTORY_SEPARATOR.$configPath; } return $configPath; }
[ "private", "function", "updateUserConfigPath", "(", "string", "$", "configPath", ")", ":", "string", "{", "if", "(", "$", "configPath", "!==", "$", "this", "->", "getDefaultConfigPath", "(", ")", ")", "{", "$", "configPath", "=", "getcwd", "(", ")", ".", "DIRECTORY_SEPARATOR", ".", "$", "configPath", ";", "}", "return", "$", "configPath", ";", "}" ]
Prefixes the cwd to the path given by the user.
[ "Prefixes", "the", "cwd", "to", "the", "path", "given", "by", "the", "user", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Application.php#L202-L209
train
phpro/grumphp
src/Task/Git/CommitMessage.php
CommitMessage.getSubjectLine
private function getSubjectLine($context) { $commitMessage = $context->getCommitMessage(); $lines = $this->getCommitMessageLinesWithoutComments($commitMessage); return (string) $lines[0]; }
php
private function getSubjectLine($context) { $commitMessage = $context->getCommitMessage(); $lines = $this->getCommitMessageLinesWithoutComments($commitMessage); return (string) $lines[0]; }
[ "private", "function", "getSubjectLine", "(", "$", "context", ")", "{", "$", "commitMessage", "=", "$", "context", "->", "getCommitMessage", "(", ")", ";", "$", "lines", "=", "$", "this", "->", "getCommitMessageLinesWithoutComments", "(", "$", "commitMessage", ")", ";", "return", "(", "string", ")", "$", "lines", "[", "0", "]", ";", "}" ]
Gets a clean subject line from the commit message @param $context @return string
[ "Gets", "a", "clean", "subject", "line", "from", "the", "commit", "message" ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Task/Git/CommitMessage.php#L361-L366
train
phpro/grumphp
src/Event/Subscriber/StashUnstagedChangesSubscriber.php
StashUnstagedChangesSubscriber.doSaveStash
private function doSaveStash() { $pending = $this->repository->getWorkingCopy()->getDiffPending(); if (!\count($pending->getFiles())) { return; } try { $this->io->write(['<fg=yellow>Detected unstaged changes... Stashing them!</fg=yellow>']); $this->repository->run('stash', ['save', '--quiet', '--keep-index', uniqid('grumphp')]); } catch (Exception $e) { // No worries ... $this->io->write([sprintf('<fg=red>Failed stashing changes: %s</fg=red>', $e->getMessage())]); return; } $this->stashIsApplied = true; $this->registerShutdownHandler(); }
php
private function doSaveStash() { $pending = $this->repository->getWorkingCopy()->getDiffPending(); if (!\count($pending->getFiles())) { return; } try { $this->io->write(['<fg=yellow>Detected unstaged changes... Stashing them!</fg=yellow>']); $this->repository->run('stash', ['save', '--quiet', '--keep-index', uniqid('grumphp')]); } catch (Exception $e) { // No worries ... $this->io->write([sprintf('<fg=red>Failed stashing changes: %s</fg=red>', $e->getMessage())]); return; } $this->stashIsApplied = true; $this->registerShutdownHandler(); }
[ "private", "function", "doSaveStash", "(", ")", "{", "$", "pending", "=", "$", "this", "->", "repository", "->", "getWorkingCopy", "(", ")", "->", "getDiffPending", "(", ")", ";", "if", "(", "!", "\\", "count", "(", "$", "pending", "->", "getFiles", "(", ")", ")", ")", "{", "return", ";", "}", "try", "{", "$", "this", "->", "io", "->", "write", "(", "[", "'<fg=yellow>Detected unstaged changes... Stashing them!</fg=yellow>'", "]", ")", ";", "$", "this", "->", "repository", "->", "run", "(", "'stash'", ",", "[", "'save'", ",", "'--quiet'", ",", "'--keep-index'", ",", "uniqid", "(", "'grumphp'", ")", "]", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "// No worries ...", "$", "this", "->", "io", "->", "write", "(", "[", "sprintf", "(", "'<fg=red>Failed stashing changes: %s</fg=red>'", ",", "$", "e", "->", "getMessage", "(", ")", ")", "]", ")", ";", "return", ";", "}", "$", "this", "->", "stashIsApplied", "=", "true", ";", "$", "this", "->", "registerShutdownHandler", "(", ")", ";", "}" ]
Check if there is a pending diff and stash the changes. @reurn void
[ "Check", "if", "there", "is", "a", "pending", "diff", "and", "stash", "the", "changes", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Event/Subscriber/StashUnstagedChangesSubscriber.php#L108-L127
train
phpro/grumphp
src/Event/Subscriber/StashUnstagedChangesSubscriber.php
StashUnstagedChangesSubscriber.registerShutdownHandler
private function registerShutdownHandler() { if ($this->shutdownFunctionRegistered) { return; } $subscriber = $this; register_shutdown_function(function () use ($subscriber) { if (!$error = error_get_last()) { return; } // Don't fail on non-blcoking errors! if (\in_array($error['type'], [E_DEPRECATED, E_USER_DEPRECATED, E_CORE_WARNING, E_CORE_ERROR], true)) { return; } $subscriber->handleErrors(); }); $this->shutdownFunctionRegistered = true; }
php
private function registerShutdownHandler() { if ($this->shutdownFunctionRegistered) { return; } $subscriber = $this; register_shutdown_function(function () use ($subscriber) { if (!$error = error_get_last()) { return; } // Don't fail on non-blcoking errors! if (\in_array($error['type'], [E_DEPRECATED, E_USER_DEPRECATED, E_CORE_WARNING, E_CORE_ERROR], true)) { return; } $subscriber->handleErrors(); }); $this->shutdownFunctionRegistered = true; }
[ "private", "function", "registerShutdownHandler", "(", ")", "{", "if", "(", "$", "this", "->", "shutdownFunctionRegistered", ")", "{", "return", ";", "}", "$", "subscriber", "=", "$", "this", ";", "register_shutdown_function", "(", "function", "(", ")", "use", "(", "$", "subscriber", ")", "{", "if", "(", "!", "$", "error", "=", "error_get_last", "(", ")", ")", "{", "return", ";", "}", "// Don't fail on non-blcoking errors!", "if", "(", "\\", "in_array", "(", "$", "error", "[", "'type'", "]", ",", "[", "E_DEPRECATED", ",", "E_USER_DEPRECATED", ",", "E_CORE_WARNING", ",", "E_CORE_ERROR", "]", ",", "true", ")", ")", "{", "return", ";", "}", "$", "subscriber", "->", "handleErrors", "(", ")", ";", "}", ")", ";", "$", "this", "->", "shutdownFunctionRegistered", "=", "true", ";", "}" ]
Make sure to fetch errors and pop the stash before crashing.
[ "Make", "sure", "to", "fetch", "errors", "and", "pop", "the", "stash", "before", "crashing", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Event/Subscriber/StashUnstagedChangesSubscriber.php#L158-L179
train
phpro/grumphp
src/Linter/Yaml/YamlLinter.php
YamlLinter.supportsFlags
public static function supportsFlags(): bool { $rc = new ReflectionClass(Yaml::class); $method = $rc->getMethod('parse'); $params = $method->getParameters(); return 'flags' === $params[1]->getName(); }
php
public static function supportsFlags(): bool { $rc = new ReflectionClass(Yaml::class); $method = $rc->getMethod('parse'); $params = $method->getParameters(); return 'flags' === $params[1]->getName(); }
[ "public", "static", "function", "supportsFlags", "(", ")", ":", "bool", "{", "$", "rc", "=", "new", "ReflectionClass", "(", "Yaml", "::", "class", ")", ";", "$", "method", "=", "$", "rc", "->", "getMethod", "(", "'parse'", ")", ";", "$", "params", "=", "$", "method", "->", "getParameters", "(", ")", ";", "return", "'flags'", "===", "$", "params", "[", "1", "]", "->", "getName", "(", ")", ";", "}" ]
This method can be used to determine the Symfony Linter version. If this method returns true, you are using Symfony YAML > 3.1. @see http://symfony.com/blog/new-in-symfony-3-1-customizable-yaml-parsing-and-dumping
[ "This", "method", "can", "be", "used", "to", "determine", "the", "Symfony", "Linter", "version", ".", "If", "this", "method", "returns", "true", "you", "are", "using", "Symfony", "YAML", ">", "3", ".", "1", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Linter/Yaml/YamlLinter.php#L80-L87
train
phpro/grumphp
src/Collection/TasksCollection.php
TasksCollection.sortByPriority
public function sortByPriority(GrumPHP $grumPHP): self { $priorityQueue = new SplPriorityQueue(); $stableSortIndex = PHP_INT_MAX; foreach ($this->getIterator() as $task) { $metadata = $grumPHP->getTaskMetadata($task->getName()); $priorityQueue->insert($task, [$metadata['priority'], $stableSortIndex--]); } return new self(array_values(iterator_to_array($priorityQueue))); }
php
public function sortByPriority(GrumPHP $grumPHP): self { $priorityQueue = new SplPriorityQueue(); $stableSortIndex = PHP_INT_MAX; foreach ($this->getIterator() as $task) { $metadata = $grumPHP->getTaskMetadata($task->getName()); $priorityQueue->insert($task, [$metadata['priority'], $stableSortIndex--]); } return new self(array_values(iterator_to_array($priorityQueue))); }
[ "public", "function", "sortByPriority", "(", "GrumPHP", "$", "grumPHP", ")", ":", "self", "{", "$", "priorityQueue", "=", "new", "SplPriorityQueue", "(", ")", ";", "$", "stableSortIndex", "=", "PHP_INT_MAX", ";", "foreach", "(", "$", "this", "->", "getIterator", "(", ")", "as", "$", "task", ")", "{", "$", "metadata", "=", "$", "grumPHP", "->", "getTaskMetadata", "(", "$", "task", "->", "getName", "(", ")", ")", ";", "$", "priorityQueue", "->", "insert", "(", "$", "task", ",", "[", "$", "metadata", "[", "'priority'", "]", ",", "$", "stableSortIndex", "--", "]", ")", ";", "}", "return", "new", "self", "(", "array_values", "(", "iterator_to_array", "(", "$", "priorityQueue", ")", ")", ")", ";", "}" ]
This method sorts the tasks by highest priority first.
[ "This", "method", "sorts", "the", "tasks", "by", "highest", "priority", "first", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Collection/TasksCollection.php#L40-L50
train
phpro/grumphp
src/Util/Composer.php
Composer.ensureProjectBinDirInSystemPath
public static function ensureProjectBinDirInSystemPath(string $binDir) { $pathStr = 'PATH'; if (!isset($_SERVER[$pathStr]) && isset($_SERVER['Path'])) { $pathStr = 'Path'; } if (!is_dir($binDir)) { return; } // add the bin dir to the PATH to make local binaries of deps usable in scripts $binDir = realpath($binDir); $hasBindDirInPath = preg_match( '{(^|'.PATH_SEPARATOR.')'.preg_quote($binDir).'($|'.PATH_SEPARATOR.')}', $_SERVER[$pathStr] ); if (!$hasBindDirInPath && isset($_SERVER[$pathStr])) { $_SERVER[$pathStr] = $binDir.PATH_SEPARATOR.getenv($pathStr); putenv($pathStr.'='.$_SERVER[$pathStr]); } }
php
public static function ensureProjectBinDirInSystemPath(string $binDir) { $pathStr = 'PATH'; if (!isset($_SERVER[$pathStr]) && isset($_SERVER['Path'])) { $pathStr = 'Path'; } if (!is_dir($binDir)) { return; } // add the bin dir to the PATH to make local binaries of deps usable in scripts $binDir = realpath($binDir); $hasBindDirInPath = preg_match( '{(^|'.PATH_SEPARATOR.')'.preg_quote($binDir).'($|'.PATH_SEPARATOR.')}', $_SERVER[$pathStr] ); if (!$hasBindDirInPath && isset($_SERVER[$pathStr])) { $_SERVER[$pathStr] = $binDir.PATH_SEPARATOR.getenv($pathStr); putenv($pathStr.'='.$_SERVER[$pathStr]); } }
[ "public", "static", "function", "ensureProjectBinDirInSystemPath", "(", "string", "$", "binDir", ")", "{", "$", "pathStr", "=", "'PATH'", ";", "if", "(", "!", "isset", "(", "$", "_SERVER", "[", "$", "pathStr", "]", ")", "&&", "isset", "(", "$", "_SERVER", "[", "'Path'", "]", ")", ")", "{", "$", "pathStr", "=", "'Path'", ";", "}", "if", "(", "!", "is_dir", "(", "$", "binDir", ")", ")", "{", "return", ";", "}", "// add the bin dir to the PATH to make local binaries of deps usable in scripts", "$", "binDir", "=", "realpath", "(", "$", "binDir", ")", ";", "$", "hasBindDirInPath", "=", "preg_match", "(", "'{(^|'", ".", "PATH_SEPARATOR", ".", "')'", ".", "preg_quote", "(", "$", "binDir", ")", ".", "'($|'", ".", "PATH_SEPARATOR", ".", "')}'", ",", "$", "_SERVER", "[", "$", "pathStr", "]", ")", ";", "if", "(", "!", "$", "hasBindDirInPath", "&&", "isset", "(", "$", "_SERVER", "[", "$", "pathStr", "]", ")", ")", "{", "$", "_SERVER", "[", "$", "pathStr", "]", "=", "$", "binDir", ".", "PATH_SEPARATOR", ".", "getenv", "(", "$", "pathStr", ")", ";", "putenv", "(", "$", "pathStr", ".", "'='", ".", "$", "_SERVER", "[", "$", "pathStr", "]", ")", ";", "}", "}" ]
Composer contains some logic to prepend the current bin dir to the system PATH. To make sure this application works the same in CLI and Composer modus, we'll have to ensure that the bin path is always prefixed. @see https://github.com/composer/composer/blob/1.1/src/Composer/EventDispatcher/EventDispatcher.php#L147-L160
[ "Composer", "contains", "some", "logic", "to", "prepend", "the", "current", "bin", "dir", "to", "the", "system", "PATH", ".", "To", "make", "sure", "this", "application", "works", "the", "same", "in", "CLI", "and", "Composer", "modus", "we", "ll", "have", "to", "ensure", "that", "the", "bin", "path", "is", "always", "prefixed", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Util/Composer.php#L57-L79
train
phpro/grumphp
src/Collection/FilesCollection.php
FilesCollection.paths
public function paths(array $patterns): self { $filter = new Iterator\PathFilterIterator($this->getIterator(), $patterns, []); return new self(iterator_to_array($filter)); }
php
public function paths(array $patterns): self { $filter = new Iterator\PathFilterIterator($this->getIterator(), $patterns, []); return new self(iterator_to_array($filter)); }
[ "public", "function", "paths", "(", "array", "$", "patterns", ")", ":", "self", "{", "$", "filter", "=", "new", "Iterator", "\\", "PathFilterIterator", "(", "$", "this", "->", "getIterator", "(", ")", ",", "$", "patterns", ",", "[", "]", ")", ";", "return", "new", "self", "(", "iterator_to_array", "(", "$", "filter", ")", ")", ";", "}" ]
Filter by paths. $collection->paths(['/^spec\/','/^src\/'])
[ "Filter", "by", "paths", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Collection/FilesCollection.php#L80-L85
train
phpro/grumphp
src/Collection/FilesCollection.php
FilesCollection.notPaths
public function notPaths(array $pattern): self { $filter = new Iterator\PathFilterIterator($this->getIterator(), [], $pattern); return new self(iterator_to_array($filter)); }
php
public function notPaths(array $pattern): self { $filter = new Iterator\PathFilterIterator($this->getIterator(), [], $pattern); return new self(iterator_to_array($filter)); }
[ "public", "function", "notPaths", "(", "array", "$", "pattern", ")", ":", "self", "{", "$", "filter", "=", "new", "Iterator", "\\", "PathFilterIterator", "(", "$", "this", "->", "getIterator", "(", ")", ",", "[", "]", ",", "$", "pattern", ")", ";", "return", "new", "self", "(", "iterator_to_array", "(", "$", "filter", ")", ")", ";", "}" ]
Adds rules that filenames must not match. You can use patterns (delimited with / sign) or simple strings. $collection->notPaths(['/^spec\/','/^src\/'])
[ "Adds", "rules", "that", "filenames", "must", "not", "match", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Collection/FilesCollection.php#L106-L111
train
phpro/grumphp
src/Collection/FilesCollection.php
FilesCollection.filter
public function filter(Closure $closure): self { $filter = new Iterator\CustomFilterIterator($this->getIterator(), [$closure]); return new self(iterator_to_array($filter)); }
php
public function filter(Closure $closure): self { $filter = new Iterator\CustomFilterIterator($this->getIterator(), [$closure]); return new self(iterator_to_array($filter)); }
[ "public", "function", "filter", "(", "Closure", "$", "closure", ")", ":", "self", "{", "$", "filter", "=", "new", "Iterator", "\\", "CustomFilterIterator", "(", "$", "this", "->", "getIterator", "(", ")", ",", "[", "$", "closure", "]", ")", ";", "return", "new", "self", "(", "iterator_to_array", "(", "$", "filter", ")", ")", ";", "}" ]
Filters the iterator with an anonymous function. The anonymous function receives a \SplFileInfo and must return false to remove files. @see CustomFilterIterator
[ "Filters", "the", "iterator", "with", "an", "anonymous", "function", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Collection/FilesCollection.php#L173-L178
train
phpro/grumphp
src/Console/Command/ConfigureCommand.php
ConfigureCommand.buildConfiguration
protected function buildConfiguration(InputInterface $input, OutputInterface $output): array { /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $questionString = $this->createQuestionString( 'Do you want to create a grumphp.yml file?', 'Yes' ); $question = new ConfirmationQuestion($questionString, true); if (!$helper->ask($input, $output, $question)) { return []; } // Search for git_dir $default = $this->guessGitDir(); $questionString = $this->createQuestionString('In which folder is GIT initialized?', $default); $question = new Question($questionString, $default); $question->setValidator([$this, 'pathValidator']); $gitDir = $helper->ask($input, $output, $question); // Search for bin_dir $default = $this->guessBinDir(); $questionString = $this->createQuestionString('Where can we find the executables?', $default); $question = new Question($questionString, $default); $question->setValidator([$this, 'pathValidator']); $binDir = $helper->ask($input, $output, $question); // Search tasks $tasks = []; if ($input->isInteractive()) { $question = new ChoiceQuestion( 'Which tasks do you want to run?', $this->getAvailableTasks($this->config) ); $question->setMultiselect(true); $tasks = (array) $helper->ask($input, $output, $question); } // Build configuration return [ 'parameters' => [ 'git_dir' => $gitDir, 'bin_dir' => $binDir, 'tasks' => array_map(function ($task) { return null; }, array_flip($tasks)), ], ]; }
php
protected function buildConfiguration(InputInterface $input, OutputInterface $output): array { /** @var QuestionHelper $helper */ $helper = $this->getHelper('question'); $questionString = $this->createQuestionString( 'Do you want to create a grumphp.yml file?', 'Yes' ); $question = new ConfirmationQuestion($questionString, true); if (!$helper->ask($input, $output, $question)) { return []; } // Search for git_dir $default = $this->guessGitDir(); $questionString = $this->createQuestionString('In which folder is GIT initialized?', $default); $question = new Question($questionString, $default); $question->setValidator([$this, 'pathValidator']); $gitDir = $helper->ask($input, $output, $question); // Search for bin_dir $default = $this->guessBinDir(); $questionString = $this->createQuestionString('Where can we find the executables?', $default); $question = new Question($questionString, $default); $question->setValidator([$this, 'pathValidator']); $binDir = $helper->ask($input, $output, $question); // Search tasks $tasks = []; if ($input->isInteractive()) { $question = new ChoiceQuestion( 'Which tasks do you want to run?', $this->getAvailableTasks($this->config) ); $question->setMultiselect(true); $tasks = (array) $helper->ask($input, $output, $question); } // Build configuration return [ 'parameters' => [ 'git_dir' => $gitDir, 'bin_dir' => $binDir, 'tasks' => array_map(function ($task) { return null; }, array_flip($tasks)), ], ]; }
[ "protected", "function", "buildConfiguration", "(", "InputInterface", "$", "input", ",", "OutputInterface", "$", "output", ")", ":", "array", "{", "/** @var QuestionHelper $helper */", "$", "helper", "=", "$", "this", "->", "getHelper", "(", "'question'", ")", ";", "$", "questionString", "=", "$", "this", "->", "createQuestionString", "(", "'Do you want to create a grumphp.yml file?'", ",", "'Yes'", ")", ";", "$", "question", "=", "new", "ConfirmationQuestion", "(", "$", "questionString", ",", "true", ")", ";", "if", "(", "!", "$", "helper", "->", "ask", "(", "$", "input", ",", "$", "output", ",", "$", "question", ")", ")", "{", "return", "[", "]", ";", "}", "// Search for git_dir", "$", "default", "=", "$", "this", "->", "guessGitDir", "(", ")", ";", "$", "questionString", "=", "$", "this", "->", "createQuestionString", "(", "'In which folder is GIT initialized?'", ",", "$", "default", ")", ";", "$", "question", "=", "new", "Question", "(", "$", "questionString", ",", "$", "default", ")", ";", "$", "question", "->", "setValidator", "(", "[", "$", "this", ",", "'pathValidator'", "]", ")", ";", "$", "gitDir", "=", "$", "helper", "->", "ask", "(", "$", "input", ",", "$", "output", ",", "$", "question", ")", ";", "// Search for bin_dir", "$", "default", "=", "$", "this", "->", "guessBinDir", "(", ")", ";", "$", "questionString", "=", "$", "this", "->", "createQuestionString", "(", "'Where can we find the executables?'", ",", "$", "default", ")", ";", "$", "question", "=", "new", "Question", "(", "$", "questionString", ",", "$", "default", ")", ";", "$", "question", "->", "setValidator", "(", "[", "$", "this", ",", "'pathValidator'", "]", ")", ";", "$", "binDir", "=", "$", "helper", "->", "ask", "(", "$", "input", ",", "$", "output", ",", "$", "question", ")", ";", "// Search tasks", "$", "tasks", "=", "[", "]", ";", "if", "(", "$", "input", "->", "isInteractive", "(", ")", ")", "{", "$", "question", "=", "new", "ChoiceQuestion", "(", "'Which tasks do you want to run?'", ",", "$", "this", "->", "getAvailableTasks", "(", "$", "this", "->", "config", ")", ")", ";", "$", "question", "->", "setMultiselect", "(", "true", ")", ";", "$", "tasks", "=", "(", "array", ")", "$", "helper", "->", "ask", "(", "$", "input", ",", "$", "output", ",", "$", "question", ")", ";", "}", "// Build configuration", "return", "[", "'parameters'", "=>", "[", "'git_dir'", "=>", "$", "gitDir", ",", "'bin_dir'", "=>", "$", "binDir", ",", "'tasks'", "=>", "array_map", "(", "function", "(", "$", "task", ")", "{", "return", "null", ";", "}", ",", "array_flip", "(", "$", "tasks", ")", ")", ",", "]", ",", "]", ";", "}" ]
This method will ask the developer for it's input and will result in a configuration array.
[ "This", "method", "will", "ask", "the", "developer", "for", "it", "s", "input", "and", "will", "result", "in", "a", "configuration", "array", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Command/ConfigureCommand.php#L113-L162
train
phpro/grumphp
src/Console/Command/ConfigureCommand.php
ConfigureCommand.guessBinDir
protected function guessBinDir(): string { $defaultBinDir = $this->config->getBinDir(); if (!$this->composer()->hasConfiguration()) { return $defaultBinDir; } $config = $this->composer()->getConfiguration(); if (!$config->has('bin-dir')) { return $defaultBinDir; } return $config->get('bin-dir', Config::RELATIVE_PATHS); }
php
protected function guessBinDir(): string { $defaultBinDir = $this->config->getBinDir(); if (!$this->composer()->hasConfiguration()) { return $defaultBinDir; } $config = $this->composer()->getConfiguration(); if (!$config->has('bin-dir')) { return $defaultBinDir; } return $config->get('bin-dir', Config::RELATIVE_PATHS); }
[ "protected", "function", "guessBinDir", "(", ")", ":", "string", "{", "$", "defaultBinDir", "=", "$", "this", "->", "config", "->", "getBinDir", "(", ")", ";", "if", "(", "!", "$", "this", "->", "composer", "(", ")", "->", "hasConfiguration", "(", ")", ")", "{", "return", "$", "defaultBinDir", ";", "}", "$", "config", "=", "$", "this", "->", "composer", "(", ")", "->", "getConfiguration", "(", ")", ";", "if", "(", "!", "$", "config", "->", "has", "(", "'bin-dir'", ")", ")", "{", "return", "$", "defaultBinDir", ";", "}", "return", "$", "config", "->", "get", "(", "'bin-dir'", ",", "Config", "::", "RELATIVE_PATHS", ")", ";", "}" ]
Make a guess to the bin dir.
[ "Make", "a", "guess", "to", "the", "bin", "dir", "." ]
362a7394a3f766c374b9062b6d393dd0d61ca87a
https://github.com/phpro/grumphp/blob/362a7394a3f766c374b9062b6d393dd0d61ca87a/src/Console/Command/ConfigureCommand.php#L189-L202
train
overtrue/pinyin
src/Pinyin.php
Pinyin.convert
public function convert($string, $option = PINYIN_DEFAULT) { $pinyin = $this->romanize($string, $option); return $this->splitWords($pinyin, $option); }
php
public function convert($string, $option = PINYIN_DEFAULT) { $pinyin = $this->romanize($string, $option); return $this->splitWords($pinyin, $option); }
[ "public", "function", "convert", "(", "$", "string", ",", "$", "option", "=", "PINYIN_DEFAULT", ")", "{", "$", "pinyin", "=", "$", "this", "->", "romanize", "(", "$", "string", ",", "$", "option", ")", ";", "return", "$", "this", "->", "splitWords", "(", "$", "pinyin", ",", "$", "option", ")", ";", "}" ]
Convert string to pinyin. @param string $string @param int $option @return array
[ "Convert", "string", "to", "pinyin", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L76-L81
train
overtrue/pinyin
src/Pinyin.php
Pinyin.permalink
public function permalink($string, $delimiter = '-', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, '-'); } if (!in_array($delimiter, array('_', '-', '.', ''), true)) { throw new InvalidArgumentException("Delimiter must be one of: '_', '-', '', '.'."); } return implode($delimiter, $this->convert($string, $option | \PINYIN_KEEP_NUMBER | \PINYIN_KEEP_ENGLISH)); }
php
public function permalink($string, $delimiter = '-', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, '-'); } if (!in_array($delimiter, array('_', '-', '.', ''), true)) { throw new InvalidArgumentException("Delimiter must be one of: '_', '-', '', '.'."); } return implode($delimiter, $this->convert($string, $option | \PINYIN_KEEP_NUMBER | \PINYIN_KEEP_ENGLISH)); }
[ "public", "function", "permalink", "(", "$", "string", ",", "$", "delimiter", "=", "'-'", ",", "$", "option", "=", "PINYIN_DEFAULT", ")", "{", "if", "(", "\\", "is_int", "(", "$", "delimiter", ")", ")", "{", "list", "(", "$", "option", ",", "$", "delimiter", ")", "=", "array", "(", "$", "delimiter", ",", "'-'", ")", ";", "}", "if", "(", "!", "in_array", "(", "$", "delimiter", ",", "array", "(", "'_'", ",", "'-'", ",", "'.'", ",", "''", ")", ",", "true", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "\"Delimiter must be one of: '_', '-', '', '.'.\"", ")", ";", "}", "return", "implode", "(", "$", "delimiter", ",", "$", "this", "->", "convert", "(", "$", "string", ",", "$", "option", "|", "\\", "PINYIN_KEEP_NUMBER", "|", "\\", "PINYIN_KEEP_ENGLISH", ")", ")", ";", "}" ]
Return a pinyin permalink from string. @param string $string @param string $delimiter @param int $option @return string
[ "Return", "a", "pinyin", "permalink", "from", "string", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L107-L118
train
overtrue/pinyin
src/Pinyin.php
Pinyin.abbr
public function abbr($string, $delimiter = '', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ''); } return implode($delimiter, array_map(function ($pinyin) { return \is_numeric($pinyin) ? $pinyin : mb_substr($pinyin, 0, 1); }, $this->convert($string, $option))); }
php
public function abbr($string, $delimiter = '', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ''); } return implode($delimiter, array_map(function ($pinyin) { return \is_numeric($pinyin) ? $pinyin : mb_substr($pinyin, 0, 1); }, $this->convert($string, $option))); }
[ "public", "function", "abbr", "(", "$", "string", ",", "$", "delimiter", "=", "''", ",", "$", "option", "=", "PINYIN_DEFAULT", ")", "{", "if", "(", "\\", "is_int", "(", "$", "delimiter", ")", ")", "{", "list", "(", "$", "option", ",", "$", "delimiter", ")", "=", "array", "(", "$", "delimiter", ",", "''", ")", ";", "}", "return", "implode", "(", "$", "delimiter", ",", "array_map", "(", "function", "(", "$", "pinyin", ")", "{", "return", "\\", "is_numeric", "(", "$", "pinyin", ")", "?", "$", "pinyin", ":", "mb_substr", "(", "$", "pinyin", ",", "0", ",", "1", ")", ";", "}", ",", "$", "this", "->", "convert", "(", "$", "string", ",", "$", "option", ")", ")", ")", ";", "}" ]
Return first letters. @param string $string @param string $delimiter @param int $option @return string
[ "Return", "first", "letters", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L129-L138
train
overtrue/pinyin
src/Pinyin.php
Pinyin.phrase
public function phrase($string, $delimiter = ' ', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ' '); } return implode($delimiter, $this->convert($string, $option)); }
php
public function phrase($string, $delimiter = ' ', $option = PINYIN_DEFAULT) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ' '); } return implode($delimiter, $this->convert($string, $option)); }
[ "public", "function", "phrase", "(", "$", "string", ",", "$", "delimiter", "=", "' '", ",", "$", "option", "=", "PINYIN_DEFAULT", ")", "{", "if", "(", "\\", "is_int", "(", "$", "delimiter", ")", ")", "{", "list", "(", "$", "option", ",", "$", "delimiter", ")", "=", "array", "(", "$", "delimiter", ",", "' '", ")", ";", "}", "return", "implode", "(", "$", "delimiter", ",", "$", "this", "->", "convert", "(", "$", "string", ",", "$", "option", ")", ")", ";", "}" ]
Chinese phrase to pinyin. @param string $string @param string $delimiter @param int $option @return string
[ "Chinese", "phrase", "to", "pinyin", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L149-L156
train
overtrue/pinyin
src/Pinyin.php
Pinyin.sentence
public function sentence($string, $delimiter = ' ', $option = \PINYIN_NO_TONE) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ' '); } return implode($delimiter, $this->convert($string, $option | \PINYIN_KEEP_PUNCTUATION | \PINYIN_KEEP_ENGLISH | \PINYIN_KEEP_NUMBER)); }
php
public function sentence($string, $delimiter = ' ', $option = \PINYIN_NO_TONE) { if (\is_int($delimiter)) { list($option, $delimiter) = array($delimiter, ' '); } return implode($delimiter, $this->convert($string, $option | \PINYIN_KEEP_PUNCTUATION | \PINYIN_KEEP_ENGLISH | \PINYIN_KEEP_NUMBER)); }
[ "public", "function", "sentence", "(", "$", "string", ",", "$", "delimiter", "=", "' '", ",", "$", "option", "=", "\\", "PINYIN_NO_TONE", ")", "{", "if", "(", "\\", "is_int", "(", "$", "delimiter", ")", ")", "{", "list", "(", "$", "option", ",", "$", "delimiter", ")", "=", "array", "(", "$", "delimiter", ",", "' '", ")", ";", "}", "return", "implode", "(", "$", "delimiter", ",", "$", "this", "->", "convert", "(", "$", "string", ",", "$", "option", "|", "\\", "PINYIN_KEEP_PUNCTUATION", "|", "\\", "PINYIN_KEEP_ENGLISH", "|", "\\", "PINYIN_KEEP_NUMBER", ")", ")", ";", "}" ]
Chinese to pinyin sentence. @param string $string @param string $delimiter @param int $option @return string
[ "Chinese", "to", "pinyin", "sentence", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L167-L174
train
overtrue/pinyin
src/Pinyin.php
Pinyin.getLoader
public function getLoader() { if (!($this->loader instanceof DictLoaderInterface)) { $dataDir = dirname(__DIR__).'/data/'; $loaderName = $this->loader; $this->loader = new $loaderName($dataDir); } return $this->loader; }
php
public function getLoader() { if (!($this->loader instanceof DictLoaderInterface)) { $dataDir = dirname(__DIR__).'/data/'; $loaderName = $this->loader; $this->loader = new $loaderName($dataDir); } return $this->loader; }
[ "public", "function", "getLoader", "(", ")", "{", "if", "(", "!", "(", "$", "this", "->", "loader", "instanceof", "DictLoaderInterface", ")", ")", "{", "$", "dataDir", "=", "dirname", "(", "__DIR__", ")", ".", "'/data/'", ";", "$", "loaderName", "=", "$", "this", "->", "loader", ";", "$", "this", "->", "loader", "=", "new", "$", "loaderName", "(", "$", "dataDir", ")", ";", "}", "return", "$", "this", "->", "loader", ";", "}" ]
Return dict loader,. @return \Overtrue\Pinyin\DictLoaderInterface
[ "Return", "dict", "loader", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L195-L205
train
overtrue/pinyin
src/Pinyin.php
Pinyin.romanize
protected function romanize($string, $option = \PINYIN_DEFAULT) { $string = $this->prepare($string, $option); $dictLoader = $this->getLoader(); if ($this->hasOption($option, \PINYIN_NAME)) { $string = $this->convertSurname($string, $dictLoader); } $dictLoader->map(function ($dictionary) use (&$string) { $string = strtr($string, $dictionary); }); return $string; }
php
protected function romanize($string, $option = \PINYIN_DEFAULT) { $string = $this->prepare($string, $option); $dictLoader = $this->getLoader(); if ($this->hasOption($option, \PINYIN_NAME)) { $string = $this->convertSurname($string, $dictLoader); } $dictLoader->map(function ($dictionary) use (&$string) { $string = strtr($string, $dictionary); }); return $string; }
[ "protected", "function", "romanize", "(", "$", "string", ",", "$", "option", "=", "\\", "PINYIN_DEFAULT", ")", "{", "$", "string", "=", "$", "this", "->", "prepare", "(", "$", "string", ",", "$", "option", ")", ";", "$", "dictLoader", "=", "$", "this", "->", "getLoader", "(", ")", ";", "if", "(", "$", "this", "->", "hasOption", "(", "$", "option", ",", "\\", "PINYIN_NAME", ")", ")", "{", "$", "string", "=", "$", "this", "->", "convertSurname", "(", "$", "string", ",", "$", "dictLoader", ")", ";", "}", "$", "dictLoader", "->", "map", "(", "function", "(", "$", "dictionary", ")", "use", "(", "&", "$", "string", ")", "{", "$", "string", "=", "strtr", "(", "$", "string", ",", "$", "dictionary", ")", ";", "}", ")", ";", "return", "$", "string", ";", "}" ]
Convert Chinese to pinyin. @param string $string @param int $option @return string
[ "Convert", "Chinese", "to", "pinyin", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L215-L230
train
overtrue/pinyin
src/Pinyin.php
Pinyin.convertSurname
protected function convertSurname($string, $dictLoader) { $dictLoader->mapSurname(function ($dictionary) use (&$string) { foreach ($dictionary as $surname => $pinyin) { if (0 === strpos($string, $surname)) { $string = $pinyin.mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8'); break; } } }); return $string; }
php
protected function convertSurname($string, $dictLoader) { $dictLoader->mapSurname(function ($dictionary) use (&$string) { foreach ($dictionary as $surname => $pinyin) { if (0 === strpos($string, $surname)) { $string = $pinyin.mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8'); break; } } }); return $string; }
[ "protected", "function", "convertSurname", "(", "$", "string", ",", "$", "dictLoader", ")", "{", "$", "dictLoader", "->", "mapSurname", "(", "function", "(", "$", "dictionary", ")", "use", "(", "&", "$", "string", ")", "{", "foreach", "(", "$", "dictionary", "as", "$", "surname", "=>", "$", "pinyin", ")", "{", "if", "(", "0", "===", "strpos", "(", "$", "string", ",", "$", "surname", ")", ")", "{", "$", "string", "=", "$", "pinyin", ".", "mb_substr", "(", "$", "string", ",", "mb_strlen", "(", "$", "surname", ",", "'UTF-8'", ")", ",", "mb_strlen", "(", "$", "string", ",", "'UTF-8'", ")", "-", "1", ",", "'UTF-8'", ")", ";", "break", ";", "}", "}", "}", ")", ";", "return", "$", "string", ";", "}" ]
Convert Chinese Surname to pinyin. @param string $string @param \Overtrue\Pinyin\DictLoaderInterface $dictLoader @return string
[ "Convert", "Chinese", "Surname", "to", "pinyin", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L240-L253
train
overtrue/pinyin
src/Pinyin.php
Pinyin.splitWords
protected function splitWords($pinyin, $option) { $split = array_filter(preg_split('/\s+/i', $pinyin)); if (!$this->hasOption($option, PINYIN_TONE)) { foreach ($split as $index => $pinyin) { $split[$index] = $this->formatTone($pinyin, $option); } } return array_values($split); }
php
protected function splitWords($pinyin, $option) { $split = array_filter(preg_split('/\s+/i', $pinyin)); if (!$this->hasOption($option, PINYIN_TONE)) { foreach ($split as $index => $pinyin) { $split[$index] = $this->formatTone($pinyin, $option); } } return array_values($split); }
[ "protected", "function", "splitWords", "(", "$", "pinyin", ",", "$", "option", ")", "{", "$", "split", "=", "array_filter", "(", "preg_split", "(", "'/\\s+/i'", ",", "$", "pinyin", ")", ")", ";", "if", "(", "!", "$", "this", "->", "hasOption", "(", "$", "option", ",", "PINYIN_TONE", ")", ")", "{", "foreach", "(", "$", "split", "as", "$", "index", "=>", "$", "pinyin", ")", "{", "$", "split", "[", "$", "index", "]", "=", "$", "this", "->", "formatTone", "(", "$", "pinyin", ",", "$", "option", ")", ";", "}", "}", "return", "array_values", "(", "$", "split", ")", ";", "}" ]
Split pinyin string to words. @param string $pinyin @param string $option @return array
[ "Split", "pinyin", "string", "to", "words", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L263-L274
train
overtrue/pinyin
src/Pinyin.php
Pinyin.prepare
protected function prepare($string, $option = \PINYIN_DEFAULT) { $string = preg_replace_callback('~[a-z0-9_-]+~i', function ($matches) { return "\t".$matches[0]; }, $string); $regex = array('\p{Han}', '\p{Z}', '\p{M}', "\t"); if ($this->hasOption($option, \PINYIN_KEEP_NUMBER)) { \array_push($regex, '\p{N}'); } if ($this->hasOption($option, \PINYIN_KEEP_ENGLISH)) { \array_push($regex, 'a-zA-Z'); } if ($this->hasOption($option, \PINYIN_KEEP_PUNCTUATION)) { $punctuations = array_merge($this->punctuations, array("\t" => ' ', ' ' => ' ')); $string = trim(str_replace(array_keys($punctuations), $punctuations, $string)); \array_push($regex, preg_quote(implode(array_merge(array_keys($this->punctuations), $this->punctuations)), '~')); } return preg_replace(\sprintf('~[^%s]~u', implode($regex)), '', $string); }
php
protected function prepare($string, $option = \PINYIN_DEFAULT) { $string = preg_replace_callback('~[a-z0-9_-]+~i', function ($matches) { return "\t".$matches[0]; }, $string); $regex = array('\p{Han}', '\p{Z}', '\p{M}', "\t"); if ($this->hasOption($option, \PINYIN_KEEP_NUMBER)) { \array_push($regex, '\p{N}'); } if ($this->hasOption($option, \PINYIN_KEEP_ENGLISH)) { \array_push($regex, 'a-zA-Z'); } if ($this->hasOption($option, \PINYIN_KEEP_PUNCTUATION)) { $punctuations = array_merge($this->punctuations, array("\t" => ' ', ' ' => ' ')); $string = trim(str_replace(array_keys($punctuations), $punctuations, $string)); \array_push($regex, preg_quote(implode(array_merge(array_keys($this->punctuations), $this->punctuations)), '~')); } return preg_replace(\sprintf('~[^%s]~u', implode($regex)), '', $string); }
[ "protected", "function", "prepare", "(", "$", "string", ",", "$", "option", "=", "\\", "PINYIN_DEFAULT", ")", "{", "$", "string", "=", "preg_replace_callback", "(", "'~[a-z0-9_-]+~i'", ",", "function", "(", "$", "matches", ")", "{", "return", "\"\\t\"", ".", "$", "matches", "[", "0", "]", ";", "}", ",", "$", "string", ")", ";", "$", "regex", "=", "array", "(", "'\\p{Han}'", ",", "'\\p{Z}'", ",", "'\\p{M}'", ",", "\"\\t\"", ")", ";", "if", "(", "$", "this", "->", "hasOption", "(", "$", "option", ",", "\\", "PINYIN_KEEP_NUMBER", ")", ")", "{", "\\", "array_push", "(", "$", "regex", ",", "'\\p{N}'", ")", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "$", "option", ",", "\\", "PINYIN_KEEP_ENGLISH", ")", ")", "{", "\\", "array_push", "(", "$", "regex", ",", "'a-zA-Z'", ")", ";", "}", "if", "(", "$", "this", "->", "hasOption", "(", "$", "option", ",", "\\", "PINYIN_KEEP_PUNCTUATION", ")", ")", "{", "$", "punctuations", "=", "array_merge", "(", "$", "this", "->", "punctuations", ",", "array", "(", "\"\\t\"", "=>", "' '", ",", "' '", "=>", "' '", ")", ")", ";", "$", "string", "=", "trim", "(", "str_replace", "(", "array_keys", "(", "$", "punctuations", ")", ",", "$", "punctuations", ",", "$", "string", ")", ")", ";", "\\", "array_push", "(", "$", "regex", ",", "preg_quote", "(", "implode", "(", "array_merge", "(", "array_keys", "(", "$", "this", "->", "punctuations", ")", ",", "$", "this", "->", "punctuations", ")", ")", ",", "'~'", ")", ")", ";", "}", "return", "preg_replace", "(", "\\", "sprintf", "(", "'~[^%s]~u'", ",", "implode", "(", "$", "regex", ")", ")", ",", "''", ",", "$", "string", ")", ";", "}" ]
Pre-process. @param string $string @param int $option @return string
[ "Pre", "-", "process", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/Pinyin.php#L295-L319
train
overtrue/pinyin
src/GeneratorFileDictLoader.php
GeneratorFileDictLoader.getGenerator
protected function getGenerator(array $handles) { foreach ($handles as $handle) { $handle->seek(0); while (false === $handle->eof()) { $string = str_replace(['\'', ' ', PHP_EOL, ','], '', $handle->fgets()); if (false === strpos($string, '=>')) { continue; } list($string, $pinyin) = explode('=>', $string); yield $string => $pinyin; } } }
php
protected function getGenerator(array $handles) { foreach ($handles as $handle) { $handle->seek(0); while (false === $handle->eof()) { $string = str_replace(['\'', ' ', PHP_EOL, ','], '', $handle->fgets()); if (false === strpos($string, '=>')) { continue; } list($string, $pinyin) = explode('=>', $string); yield $string => $pinyin; } } }
[ "protected", "function", "getGenerator", "(", "array", "$", "handles", ")", "{", "foreach", "(", "$", "handles", "as", "$", "handle", ")", "{", "$", "handle", "->", "seek", "(", "0", ")", ";", "while", "(", "false", "===", "$", "handle", "->", "eof", "(", ")", ")", "{", "$", "string", "=", "str_replace", "(", "[", "'\\''", ",", "' '", ",", "PHP_EOL", ",", "','", "]", ",", "''", ",", "$", "handle", "->", "fgets", "(", ")", ")", ";", "if", "(", "false", "===", "strpos", "(", "$", "string", ",", "'=>'", ")", ")", "{", "continue", ";", "}", "list", "(", "$", "string", ",", "$", "pinyin", ")", "=", "explode", "(", "'=>'", ",", "$", "string", ")", ";", "yield", "$", "string", "=>", "$", "pinyin", ";", "}", "}", "}" ]
get Generator syntax. @param array $handles SplFileObjects @return Generator
[ "get", "Generator", "syntax", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/GeneratorFileDictLoader.php#L89-L105
train
overtrue/pinyin
src/GeneratorFileDictLoader.php
GeneratorFileDictLoader.traversing
protected function traversing(Generator $generator, Closure $callback) { foreach ($generator as $string => $pinyin) { $callback([$string => $pinyin]); } }
php
protected function traversing(Generator $generator, Closure $callback) { foreach ($generator as $string => $pinyin) { $callback([$string => $pinyin]); } }
[ "protected", "function", "traversing", "(", "Generator", "$", "generator", ",", "Closure", "$", "callback", ")", "{", "foreach", "(", "$", "generator", "as", "$", "string", "=>", "$", "pinyin", ")", "{", "$", "callback", "(", "[", "$", "string", "=>", "$", "pinyin", "]", ")", ";", "}", "}" ]
Traverse the stream. @param Generator $generator @param Closure $callback @author Seven Du <shiweidu@outlook.com>
[ "Traverse", "the", "stream", "." ]
a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5
https://github.com/overtrue/pinyin/blob/a6b1f1ecd65b5a8f79460708d1b31d4dfe0ab9c5/src/GeneratorFileDictLoader.php#L115-L120
train
spipu/html2pdf
src/Parsing/TagParser.php
TagParser.extractTagAttributes
public function extractTagAttributes($code) { $param = array(); $regexes = array( '([a-zA-Z0-9_]+)=([^"\'\s>]+)', // read the parameters : name=value '([a-zA-Z0-9_]+)=["]([^"]*)["]', // read the parameters : name="value" "([a-zA-Z0-9_]+)=[']([^']*)[']" // read the parameters : name='value' ); foreach ($regexes as $regex) { preg_match_all('/'.$regex.'/is', $code, $match); $amountMatch = count($match[0]); for ($k = 0; $k < $amountMatch; $k++) { $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); } } return $param; }
php
public function extractTagAttributes($code) { $param = array(); $regexes = array( '([a-zA-Z0-9_]+)=([^"\'\s>]+)', // read the parameters : name=value '([a-zA-Z0-9_]+)=["]([^"]*)["]', // read the parameters : name="value" "([a-zA-Z0-9_]+)=[']([^']*)[']" // read the parameters : name='value' ); foreach ($regexes as $regex) { preg_match_all('/'.$regex.'/is', $code, $match); $amountMatch = count($match[0]); for ($k = 0; $k < $amountMatch; $k++) { $param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); } } return $param; }
[ "public", "function", "extractTagAttributes", "(", "$", "code", ")", "{", "$", "param", "=", "array", "(", ")", ";", "$", "regexes", "=", "array", "(", "'([a-zA-Z0-9_]+)=([^\"\\'\\s>]+)'", ",", "// read the parameters : name=value", "'([a-zA-Z0-9_]+)=[\"]([^\"]*)[\"]'", ",", "// read the parameters : name=\"value\"", "\"([a-zA-Z0-9_]+)=[']([^']*)[']\"", "// read the parameters : name='value'", ")", ";", "foreach", "(", "$", "regexes", "as", "$", "regex", ")", "{", "preg_match_all", "(", "'/'", ".", "$", "regex", ".", "'/is'", ",", "$", "code", ",", "$", "match", ")", ";", "$", "amountMatch", "=", "count", "(", "$", "match", "[", "0", "]", ")", ";", "for", "(", "$", "k", "=", "0", ";", "$", "k", "<", "$", "amountMatch", ";", "$", "k", "++", ")", "{", "$", "param", "[", "trim", "(", "strtolower", "(", "$", "match", "[", "1", "]", "[", "$", "k", "]", ")", ")", "]", "=", "trim", "(", "$", "match", "[", "2", "]", "[", "$", "k", "]", ")", ";", "}", "}", "return", "$", "param", ";", "}" ]
Extract the list of attribute => value inside an HTML tag @param string $code The full HTML tag to parse @return array
[ "Extract", "the", "list", "of", "attribute", "=", ">", "value", "inside", "an", "HTML", "tag" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/TagParser.php#L208-L226
train
spipu/html2pdf
src/Parsing/Css.php
Css.getOldValues
public function getOldValues() { return isset($this->table[count($this->table)-1]) ? $this->table[count($this->table)-1] : $this->value; }
php
public function getOldValues() { return isset($this->table[count($this->table)-1]) ? $this->table[count($this->table)-1] : $this->value; }
[ "public", "function", "getOldValues", "(", ")", "{", "return", "isset", "(", "$", "this", "->", "table", "[", "count", "(", "$", "this", "->", "table", ")", "-", "1", "]", ")", "?", "$", "this", "->", "table", "[", "count", "(", "$", "this", "->", "table", ")", "-", "1", "]", ":", "$", "this", "->", "value", ";", "}" ]
Get the vales of the parent, if exist @return array CSS values
[ "Get", "the", "vales", "of", "the", "parent", "if", "exist" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L88-L91
train
spipu/html2pdf
src/Parsing/Css.php
Css.setDefaultFont
public function setDefaultFont($default = null) { $old = $this->defaultFont; $this->defaultFont = $default; if ($default) { $this->value['font-family'] = $default; } return $old; }
php
public function setDefaultFont($default = null) { $old = $this->defaultFont; $this->defaultFont = $default; if ($default) { $this->value['font-family'] = $default; } return $old; }
[ "public", "function", "setDefaultFont", "(", "$", "default", "=", "null", ")", "{", "$", "old", "=", "$", "this", "->", "defaultFont", ";", "$", "this", "->", "defaultFont", "=", "$", "default", ";", "if", "(", "$", "default", ")", "{", "$", "this", "->", "value", "[", "'font-family'", "]", "=", "$", "default", ";", "}", "return", "$", "old", ";", "}" ]
Define the Default Font to use, if the font does not exist, or if no font asked @param string default font-family. If null : Arial for no font asked, and error fot ont does not exist @return string old default font-family
[ "Define", "the", "Default", "Font", "to", "use", "if", "the", "font", "does", "not", "exist", "or", "if", "no", "font", "asked" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L100-L108
train
spipu/html2pdf
src/Parsing/Css.php
Css.setPosition
public function setPosition() { // get the current position $currentX = $this->pdf->GetX(); $currentY = $this->pdf->GetY(); // save it $this->value['xc'] = $currentX; $this->value['yc'] = $currentY; if ($this->value['position'] === 'relative' || $this->value['position'] === 'absolute') { if ($this->value['right'] !== null) { $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width']; if ($this->value['margin']['r']) { $x-= $this->value['margin']['r']; } } else { $x = $this->value['left']; if ($this->value['margin']['l']) { $x+= $this->value['margin']['l']; } } if ($this->value['bottom'] !== null) { $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height']; if ($this->value['margin']['b']) { $y-= $this->value['margin']['b']; } } else { $y = $this->value['top']; if ($this->value['margin']['t']) { $y+= $this->value['margin']['t']; } } if ($this->value['position'] === 'relative') { $this->value['x'] = $currentX + $x; $this->value['y'] = $currentY + $y; } else { $this->value['x'] = $this->getLastAbsoluteX()+$x; $this->value['y'] = $this->getLastAbsoluteY()+$y; } } else { $this->value['x'] = $currentX; $this->value['y'] = $currentY; if ($this->value['margin']['l']) { $this->value['x']+= $this->value['margin']['l']; } if ($this->value['margin']['t']) { $this->value['y']+= $this->value['margin']['t']; } } // save the new position $this->pdf->SetXY($this->value['x'], $this->value['y']); }
php
public function setPosition() { // get the current position $currentX = $this->pdf->GetX(); $currentY = $this->pdf->GetY(); // save it $this->value['xc'] = $currentX; $this->value['yc'] = $currentY; if ($this->value['position'] === 'relative' || $this->value['position'] === 'absolute') { if ($this->value['right'] !== null) { $x = $this->getLastWidth(true) - $this->value['right'] - $this->value['width']; if ($this->value['margin']['r']) { $x-= $this->value['margin']['r']; } } else { $x = $this->value['left']; if ($this->value['margin']['l']) { $x+= $this->value['margin']['l']; } } if ($this->value['bottom'] !== null) { $y = $this->getLastHeight(true) - $this->value['bottom'] - $this->value['height']; if ($this->value['margin']['b']) { $y-= $this->value['margin']['b']; } } else { $y = $this->value['top']; if ($this->value['margin']['t']) { $y+= $this->value['margin']['t']; } } if ($this->value['position'] === 'relative') { $this->value['x'] = $currentX + $x; $this->value['y'] = $currentY + $y; } else { $this->value['x'] = $this->getLastAbsoluteX()+$x; $this->value['y'] = $this->getLastAbsoluteY()+$y; } } else { $this->value['x'] = $currentX; $this->value['y'] = $currentY; if ($this->value['margin']['l']) { $this->value['x']+= $this->value['margin']['l']; } if ($this->value['margin']['t']) { $this->value['y']+= $this->value['margin']['t']; } } // save the new position $this->pdf->SetXY($this->value['x'], $this->value['y']); }
[ "public", "function", "setPosition", "(", ")", "{", "// get the current position", "$", "currentX", "=", "$", "this", "->", "pdf", "->", "GetX", "(", ")", ";", "$", "currentY", "=", "$", "this", "->", "pdf", "->", "GetY", "(", ")", ";", "// save it", "$", "this", "->", "value", "[", "'xc'", "]", "=", "$", "currentX", ";", "$", "this", "->", "value", "[", "'yc'", "]", "=", "$", "currentY", ";", "if", "(", "$", "this", "->", "value", "[", "'position'", "]", "===", "'relative'", "||", "$", "this", "->", "value", "[", "'position'", "]", "===", "'absolute'", ")", "{", "if", "(", "$", "this", "->", "value", "[", "'right'", "]", "!==", "null", ")", "{", "$", "x", "=", "$", "this", "->", "getLastWidth", "(", "true", ")", "-", "$", "this", "->", "value", "[", "'right'", "]", "-", "$", "this", "->", "value", "[", "'width'", "]", ";", "if", "(", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'r'", "]", ")", "{", "$", "x", "-=", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'r'", "]", ";", "}", "}", "else", "{", "$", "x", "=", "$", "this", "->", "value", "[", "'left'", "]", ";", "if", "(", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'l'", "]", ")", "{", "$", "x", "+=", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'l'", "]", ";", "}", "}", "if", "(", "$", "this", "->", "value", "[", "'bottom'", "]", "!==", "null", ")", "{", "$", "y", "=", "$", "this", "->", "getLastHeight", "(", "true", ")", "-", "$", "this", "->", "value", "[", "'bottom'", "]", "-", "$", "this", "->", "value", "[", "'height'", "]", ";", "if", "(", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'b'", "]", ")", "{", "$", "y", "-=", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'b'", "]", ";", "}", "}", "else", "{", "$", "y", "=", "$", "this", "->", "value", "[", "'top'", "]", ";", "if", "(", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'t'", "]", ")", "{", "$", "y", "+=", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'t'", "]", ";", "}", "}", "if", "(", "$", "this", "->", "value", "[", "'position'", "]", "===", "'relative'", ")", "{", "$", "this", "->", "value", "[", "'x'", "]", "=", "$", "currentX", "+", "$", "x", ";", "$", "this", "->", "value", "[", "'y'", "]", "=", "$", "currentY", "+", "$", "y", ";", "}", "else", "{", "$", "this", "->", "value", "[", "'x'", "]", "=", "$", "this", "->", "getLastAbsoluteX", "(", ")", "+", "$", "x", ";", "$", "this", "->", "value", "[", "'y'", "]", "=", "$", "this", "->", "getLastAbsoluteY", "(", ")", "+", "$", "y", ";", "}", "}", "else", "{", "$", "this", "->", "value", "[", "'x'", "]", "=", "$", "currentX", ";", "$", "this", "->", "value", "[", "'y'", "]", "=", "$", "currentY", ";", "if", "(", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'l'", "]", ")", "{", "$", "this", "->", "value", "[", "'x'", "]", "+=", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'l'", "]", ";", "}", "if", "(", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'t'", "]", ")", "{", "$", "this", "->", "value", "[", "'y'", "]", "+=", "$", "this", "->", "value", "[", "'margin'", "]", "[", "'t'", "]", ";", "}", "}", "// save the new position", "$", "this", "->", "pdf", "->", "SetXY", "(", "$", "this", "->", "value", "[", "'x'", "]", ",", "$", "this", "->", "value", "[", "'y'", "]", ")", ";", "}" ]
Set the New position for the current Tag @return void
[ "Set", "the", "New", "position", "for", "the", "current", "Tag" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L419-L474
train
spipu/html2pdf
src/Parsing/Css.php
Css.getLastHeight
public function getLastHeight($mode = false) { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['height']) { $h = $this->table[$k]['height']; if ($mode) { $h+= $this->table[$k]['border']['t']['width'] + $this->table[$k]['padding']['t'] + 0.02; $h+= $this->table[$k]['border']['b']['width'] + $this->table[$k]['padding']['b'] + 0.02; } return $h; } } return $this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin(); }
php
public function getLastHeight($mode = false) { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['height']) { $h = $this->table[$k]['height']; if ($mode) { $h+= $this->table[$k]['border']['t']['width'] + $this->table[$k]['padding']['t'] + 0.02; $h+= $this->table[$k]['border']['b']['width'] + $this->table[$k]['padding']['b'] + 0.02; } return $h; } } return $this->pdf->getH() - $this->pdf->gettMargin() - $this->pdf->getbMargin(); }
[ "public", "function", "getLastHeight", "(", "$", "mode", "=", "false", ")", "{", "for", "(", "$", "k", "=", "count", "(", "$", "this", "->", "table", ")", "-", "1", ";", "$", "k", ">=", "0", ";", "$", "k", "--", ")", "{", "if", "(", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'height'", "]", ")", "{", "$", "h", "=", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'height'", "]", ";", "if", "(", "$", "mode", ")", "{", "$", "h", "+=", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'border'", "]", "[", "'t'", "]", "[", "'width'", "]", "+", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'padding'", "]", "[", "'t'", "]", "+", "0.02", ";", "$", "h", "+=", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'border'", "]", "[", "'b'", "]", "[", "'width'", "]", "+", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'padding'", "]", "[", "'b'", "]", "+", "0.02", ";", "}", "return", "$", "h", ";", "}", "}", "return", "$", "this", "->", "pdf", "->", "getH", "(", ")", "-", "$", "this", "->", "pdf", "->", "gettMargin", "(", ")", "-", "$", "this", "->", "pdf", "->", "getbMargin", "(", ")", ";", "}" ]
Get the height of the parent @param boolean $mode true => adding padding and border @return float height in mm
[ "Get", "the", "height", "of", "the", "parent" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L1335-L1348
train
spipu/html2pdf
src/Parsing/Css.php
Css.getLastValue
public function getLastValue($key) { $nb = count($this->table); if ($nb>0) { return $this->table[$nb-1][$key]; } else { return null; } }
php
public function getLastValue($key) { $nb = count($this->table); if ($nb>0) { return $this->table[$nb-1][$key]; } else { return null; } }
[ "public", "function", "getLastValue", "(", "$", "key", ")", "{", "$", "nb", "=", "count", "(", "$", "this", "->", "table", ")", ";", "if", "(", "$", "nb", ">", "0", ")", "{", "return", "$", "this", "->", "table", "[", "$", "nb", "-", "1", "]", "[", "$", "key", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get the last value for a specific key @param string $key @return mixed
[ "Get", "the", "last", "value", "for", "a", "specific", "key" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L1373-L1381
train
spipu/html2pdf
src/Parsing/Css.php
Css.getLastAbsoluteX
protected function getLastAbsoluteX() { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['x'] && $this->table[$k]['position']) { return $this->table[$k]['x']; } } return $this->pdf->getlMargin(); }
php
protected function getLastAbsoluteX() { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['x'] && $this->table[$k]['position']) { return $this->table[$k]['x']; } } return $this->pdf->getlMargin(); }
[ "protected", "function", "getLastAbsoluteX", "(", ")", "{", "for", "(", "$", "k", "=", "count", "(", "$", "this", "->", "table", ")", "-", "1", ";", "$", "k", ">=", "0", ";", "$", "k", "--", ")", "{", "if", "(", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'x'", "]", "&&", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'position'", "]", ")", "{", "return", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'x'", "]", ";", "}", "}", "return", "$", "this", "->", "pdf", "->", "getlMargin", "(", ")", ";", "}" ]
Get the last absolute X @return float x
[ "Get", "the", "last", "absolute", "X" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L1388-L1396
train
spipu/html2pdf
src/Parsing/Css.php
Css.getLastAbsoluteY
protected function getLastAbsoluteY() { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['y'] && $this->table[$k]['position']) { return $this->table[$k]['y']; } } return $this->pdf->gettMargin(); }
php
protected function getLastAbsoluteY() { for ($k=count($this->table)-1; $k>=0; $k--) { if ($this->table[$k]['y'] && $this->table[$k]['position']) { return $this->table[$k]['y']; } } return $this->pdf->gettMargin(); }
[ "protected", "function", "getLastAbsoluteY", "(", ")", "{", "for", "(", "$", "k", "=", "count", "(", "$", "this", "->", "table", ")", "-", "1", ";", "$", "k", ">=", "0", ";", "$", "k", "--", ")", "{", "if", "(", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'y'", "]", "&&", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'position'", "]", ")", "{", "return", "$", "this", "->", "table", "[", "$", "k", "]", "[", "'y'", "]", ";", "}", "}", "return", "$", "this", "->", "pdf", "->", "gettMargin", "(", ")", ";", "}" ]
Get the last absolute Y @return float y
[ "Get", "the", "last", "absolute", "Y" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L1403-L1411
train
spipu/html2pdf
src/Parsing/Css.php
Css.duplicateBorder
protected function duplicateBorder(&$val) { // 1 value => L => RTB if (count($val) == 1) { $val[1] = $val[0]; $val[2] = $val[0]; $val[3] = $val[0]; // 2 values => L => R & T => B } elseif (count($val) == 2) { $val[2] = $val[0]; $val[3] = $val[1]; // 3 values => T => B } elseif (count($val) == 3) { $val[3] = $val[1]; } }
php
protected function duplicateBorder(&$val) { // 1 value => L => RTB if (count($val) == 1) { $val[1] = $val[0]; $val[2] = $val[0]; $val[3] = $val[0]; // 2 values => L => R & T => B } elseif (count($val) == 2) { $val[2] = $val[0]; $val[3] = $val[1]; // 3 values => T => B } elseif (count($val) == 3) { $val[3] = $val[1]; } }
[ "protected", "function", "duplicateBorder", "(", "&", "$", "val", ")", "{", "// 1 value => L => RTB", "if", "(", "count", "(", "$", "val", ")", "==", "1", ")", "{", "$", "val", "[", "1", "]", "=", "$", "val", "[", "0", "]", ";", "$", "val", "[", "2", "]", "=", "$", "val", "[", "0", "]", ";", "$", "val", "[", "3", "]", "=", "$", "val", "[", "0", "]", ";", "// 2 values => L => R & T => B", "}", "elseif", "(", "count", "(", "$", "val", ")", "==", "2", ")", "{", "$", "val", "[", "2", "]", "=", "$", "val", "[", "0", "]", ";", "$", "val", "[", "3", "]", "=", "$", "val", "[", "1", "]", ";", "// 3 values => T => B", "}", "elseif", "(", "count", "(", "$", "val", ")", "==", "3", ")", "{", "$", "val", "[", "3", "]", "=", "$", "val", "[", "1", "]", ";", "}", "}" ]
Duplicate the borders if needed @param &array $val @return void
[ "Duplicate", "the", "borders", "if", "needed" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L1571-L1586
train
spipu/html2pdf
src/Parsing/Css.php
Css.analyseStyle
protected function analyseStyle($code) { // clean the spaces $code = preg_replace('/[\s]+/', ' ', $code); // remove the comments $code = preg_replace('/\/\*.*?\*\//s', '', $code); // split each CSS code "selector { value }" preg_match_all('/([^{}]+){([^}]*)}/isU', $code, $match); // for each CSS code $amountMatch = count($match[0]); for ($k = 0; $k < $amountMatch; $k++) { // selectors $names = strtolower(trim($match[1][$k])); // css style $styles = trim($match[2][$k]); // explode each value $styles = explode(';', $styles); // parse each value $css = array(); foreach ($styles as $style) { $tmp = explode(':', $style); if (count($tmp) > 1) { $cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp); $css[trim(strtolower($cod))] = trim($tmp); } } // explode the names $names = explode(',', $names); // save the values for each names foreach ($names as $name) { // clean the name $name = trim($name); // if a selector with something like :hover => continue if (strpos($name, ':') !== false) { continue; } // save the value if (!isset($this->css[$name])) { $this->css[$name] = $css; } else { $this->css[$name] = array_merge($this->css[$name], $css); } } } // get he list of the keys $this->cssKeys = array_flip(array_keys($this->css)); }
php
protected function analyseStyle($code) { // clean the spaces $code = preg_replace('/[\s]+/', ' ', $code); // remove the comments $code = preg_replace('/\/\*.*?\*\//s', '', $code); // split each CSS code "selector { value }" preg_match_all('/([^{}]+){([^}]*)}/isU', $code, $match); // for each CSS code $amountMatch = count($match[0]); for ($k = 0; $k < $amountMatch; $k++) { // selectors $names = strtolower(trim($match[1][$k])); // css style $styles = trim($match[2][$k]); // explode each value $styles = explode(';', $styles); // parse each value $css = array(); foreach ($styles as $style) { $tmp = explode(':', $style); if (count($tmp) > 1) { $cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp); $css[trim(strtolower($cod))] = trim($tmp); } } // explode the names $names = explode(',', $names); // save the values for each names foreach ($names as $name) { // clean the name $name = trim($name); // if a selector with something like :hover => continue if (strpos($name, ':') !== false) { continue; } // save the value if (!isset($this->css[$name])) { $this->css[$name] = $css; } else { $this->css[$name] = array_merge($this->css[$name], $css); } } } // get he list of the keys $this->cssKeys = array_flip(array_keys($this->css)); }
[ "protected", "function", "analyseStyle", "(", "$", "code", ")", "{", "// clean the spaces", "$", "code", "=", "preg_replace", "(", "'/[\\s]+/'", ",", "' '", ",", "$", "code", ")", ";", "// remove the comments", "$", "code", "=", "preg_replace", "(", "'/\\/\\*.*?\\*\\//s'", ",", "''", ",", "$", "code", ")", ";", "// split each CSS code \"selector { value }\"", "preg_match_all", "(", "'/([^{}]+){([^}]*)}/isU'", ",", "$", "code", ",", "$", "match", ")", ";", "// for each CSS code", "$", "amountMatch", "=", "count", "(", "$", "match", "[", "0", "]", ")", ";", "for", "(", "$", "k", "=", "0", ";", "$", "k", "<", "$", "amountMatch", ";", "$", "k", "++", ")", "{", "// selectors", "$", "names", "=", "strtolower", "(", "trim", "(", "$", "match", "[", "1", "]", "[", "$", "k", "]", ")", ")", ";", "// css style", "$", "styles", "=", "trim", "(", "$", "match", "[", "2", "]", "[", "$", "k", "]", ")", ";", "// explode each value", "$", "styles", "=", "explode", "(", "';'", ",", "$", "styles", ")", ";", "// parse each value", "$", "css", "=", "array", "(", ")", ";", "foreach", "(", "$", "styles", "as", "$", "style", ")", "{", "$", "tmp", "=", "explode", "(", "':'", ",", "$", "style", ")", ";", "if", "(", "count", "(", "$", "tmp", ")", ">", "1", ")", "{", "$", "cod", "=", "$", "tmp", "[", "0", "]", ";", "unset", "(", "$", "tmp", "[", "0", "]", ")", ";", "$", "tmp", "=", "implode", "(", "':'", ",", "$", "tmp", ")", ";", "$", "css", "[", "trim", "(", "strtolower", "(", "$", "cod", ")", ")", "]", "=", "trim", "(", "$", "tmp", ")", ";", "}", "}", "// explode the names", "$", "names", "=", "explode", "(", "','", ",", "$", "names", ")", ";", "// save the values for each names", "foreach", "(", "$", "names", "as", "$", "name", ")", "{", "// clean the name", "$", "name", "=", "trim", "(", "$", "name", ")", ";", "// if a selector with something like :hover => continue", "if", "(", "strpos", "(", "$", "name", ",", "':'", ")", "!==", "false", ")", "{", "continue", ";", "}", "// save the value", "if", "(", "!", "isset", "(", "$", "this", "->", "css", "[", "$", "name", "]", ")", ")", "{", "$", "this", "->", "css", "[", "$", "name", "]", "=", "$", "css", ";", "}", "else", "{", "$", "this", "->", "css", "[", "$", "name", "]", "=", "array_merge", "(", "$", "this", "->", "css", "[", "$", "name", "]", ",", "$", "css", ")", ";", "}", "}", "}", "// get he list of the keys", "$", "this", "->", "cssKeys", "=", "array_flip", "(", "array_keys", "(", "$", "this", "->", "css", ")", ")", ";", "}" ]
Read a css content @param &string $code @return void
[ "Read", "a", "css", "content" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Parsing/Css.php#L1596-L1657
train
spipu/html2pdf
src/Tag/AbstractSvgTag.php
AbstractSvgTag.openSvg
protected function openSvg($properties) { if (!$this->svgDrawer->isDrawing()) { $e = new HtmlParsingException('The asked ['.$this->getName().'] tag is not in a [DRAW] tag'); $e->setInvalidTag($this->getName()); throw $e; } $transform = null; if (array_key_exists('transform', $properties)) { $transform = $this->svgDrawer->prepareTransform($properties['transform']); } $this->pdf->doTransform($transform); $this->parsingCss->save(); }
php
protected function openSvg($properties) { if (!$this->svgDrawer->isDrawing()) { $e = new HtmlParsingException('The asked ['.$this->getName().'] tag is not in a [DRAW] tag'); $e->setInvalidTag($this->getName()); throw $e; } $transform = null; if (array_key_exists('transform', $properties)) { $transform = $this->svgDrawer->prepareTransform($properties['transform']); } $this->pdf->doTransform($transform); $this->parsingCss->save(); }
[ "protected", "function", "openSvg", "(", "$", "properties", ")", "{", "if", "(", "!", "$", "this", "->", "svgDrawer", "->", "isDrawing", "(", ")", ")", "{", "$", "e", "=", "new", "HtmlParsingException", "(", "'The asked ['", ".", "$", "this", "->", "getName", "(", ")", ".", "'] tag is not in a [DRAW] tag'", ")", ";", "$", "e", "->", "setInvalidTag", "(", "$", "this", "->", "getName", "(", ")", ")", ";", "throw", "$", "e", ";", "}", "$", "transform", "=", "null", ";", "if", "(", "array_key_exists", "(", "'transform'", ",", "$", "properties", ")", ")", "{", "$", "transform", "=", "$", "this", "->", "svgDrawer", "->", "prepareTransform", "(", "$", "properties", "[", "'transform'", "]", ")", ";", "}", "$", "this", "->", "pdf", "->", "doTransform", "(", "$", "transform", ")", ";", "$", "this", "->", "parsingCss", "->", "save", "(", ")", ";", "}" ]
Open the SVG tag @param array $properties @throws HtmlParsingException
[ "Open", "the", "SVG", "tag" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Tag/AbstractSvgTag.php#L65-L80
train
spipu/html2pdf
src/Tag/AbstractHtmlTag.php
AbstractHtmlTag.open
public function open($properties) { $this->parsingCss->save(); $this->overrideStyles(); $this->parsingCss->analyse($this->getName(), $properties); $this->parsingCss->setPosition(); $this->parsingCss->fontSet(); return true; }
php
public function open($properties) { $this->parsingCss->save(); $this->overrideStyles(); $this->parsingCss->analyse($this->getName(), $properties); $this->parsingCss->setPosition(); $this->parsingCss->fontSet(); return true; }
[ "public", "function", "open", "(", "$", "properties", ")", "{", "$", "this", "->", "parsingCss", "->", "save", "(", ")", ";", "$", "this", "->", "overrideStyles", "(", ")", ";", "$", "this", "->", "parsingCss", "->", "analyse", "(", "$", "this", "->", "getName", "(", ")", ",", "$", "properties", ")", ";", "$", "this", "->", "parsingCss", "->", "setPosition", "(", ")", ";", "$", "this", "->", "parsingCss", "->", "fontSet", "(", ")", ";", "return", "true", ";", "}" ]
Open the HTML tag @param array $properties properties of the HTML tag @return boolean
[ "Open", "the", "HTML", "tag" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Tag/AbstractHtmlTag.php#L27-L36
train
spipu/html2pdf
src/Debug/Debug.php
Debug.displayLine
protected function displayLine($name, $timeTotal, $timeStep, $memoryUsage, $memoryPeak) { $output = str_pad($name, 30, ' ', STR_PAD_RIGHT). str_pad($timeTotal, 12, ' ', STR_PAD_LEFT). str_pad($timeStep, 12, ' ', STR_PAD_LEFT). str_pad($memoryUsage, 15, ' ', STR_PAD_LEFT). str_pad($memoryPeak, 15, ' ', STR_PAD_LEFT); if ($this->htmlOutput) { $output = '<pre style="padding:0; margin:0">'.$output.'</pre>'; } echo $output."\n"; }
php
protected function displayLine($name, $timeTotal, $timeStep, $memoryUsage, $memoryPeak) { $output = str_pad($name, 30, ' ', STR_PAD_RIGHT). str_pad($timeTotal, 12, ' ', STR_PAD_LEFT). str_pad($timeStep, 12, ' ', STR_PAD_LEFT). str_pad($memoryUsage, 15, ' ', STR_PAD_LEFT). str_pad($memoryPeak, 15, ' ', STR_PAD_LEFT); if ($this->htmlOutput) { $output = '<pre style="padding:0; margin:0">'.$output.'</pre>'; } echo $output."\n"; }
[ "protected", "function", "displayLine", "(", "$", "name", ",", "$", "timeTotal", ",", "$", "timeStep", ",", "$", "memoryUsage", ",", "$", "memoryPeak", ")", "{", "$", "output", "=", "str_pad", "(", "$", "name", ",", "30", ",", "' '", ",", "STR_PAD_RIGHT", ")", ".", "str_pad", "(", "$", "timeTotal", ",", "12", ",", "' '", ",", "STR_PAD_LEFT", ")", ".", "str_pad", "(", "$", "timeStep", ",", "12", ",", "' '", ",", "STR_PAD_LEFT", ")", ".", "str_pad", "(", "$", "memoryUsage", ",", "15", ",", "' '", ",", "STR_PAD_LEFT", ")", ".", "str_pad", "(", "$", "memoryPeak", ",", "15", ",", "' '", ",", "STR_PAD_LEFT", ")", ";", "if", "(", "$", "this", "->", "htmlOutput", ")", "{", "$", "output", "=", "'<pre style=\"padding:0; margin:0\">'", ".", "$", "output", ".", "'</pre>'", ";", "}", "echo", "$", "output", ".", "\"\\n\"", ";", "}" ]
display a debug line @param string $name @param string $timeTotal @param string $timeStep @param string $memoryUsage @param string $memoryPeak @return void
[ "display", "a", "debug", "line" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Debug/Debug.php#L61-L75
train
spipu/html2pdf
src/Debug/Debug.php
Debug.start
public function start() { $time = microtime(true); $this->startTime = $time; $this->lastTime = $time; $this->displayLine('step', 'time', 'delta', 'memory', 'peak'); $this->addStep('Init debug'); return $this; }
php
public function start() { $time = microtime(true); $this->startTime = $time; $this->lastTime = $time; $this->displayLine('step', 'time', 'delta', 'memory', 'peak'); $this->addStep('Init debug'); return $this; }
[ "public", "function", "start", "(", ")", "{", "$", "time", "=", "microtime", "(", "true", ")", ";", "$", "this", "->", "startTime", "=", "$", "time", ";", "$", "this", "->", "lastTime", "=", "$", "time", ";", "$", "this", "->", "displayLine", "(", "'step'", ",", "'time'", ",", "'delta'", ",", "'memory'", ",", "'peak'", ")", ";", "$", "this", "->", "addStep", "(", "'Init debug'", ")", ";", "return", "$", "this", ";", "}" ]
Start the debugger @return Debug
[ "Start", "the", "debugger" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Debug/Debug.php#L82-L93
train
spipu/html2pdf
src/Debug/Debug.php
Debug.addStep
public function addStep($name, $level = null) { // if true : UP if ($level === true) { $this->level++; } $time = microtime(true); $usage = memory_get_usage(); $peak = memory_get_peak_usage(); $type = ($level === true ? ' Begin' : ($level === false ? ' End' : '')); $this->displayLine( str_repeat(' ', $this->level) . $name . $type, number_format(($time - $this->startTime)*1000, 1, '.', ' ').' ms', number_format(($time - $this->lastTime)*1000, 1, '.', ' ').' ms', number_format($usage/1024, 1, '.', ' ').' Ko', number_format($peak/1024, 1, '.', ' ').' Ko' ); $this->lastTime = $time; // it false : DOWN if ($level === false) { $this->level--; } return $this; }
php
public function addStep($name, $level = null) { // if true : UP if ($level === true) { $this->level++; } $time = microtime(true); $usage = memory_get_usage(); $peak = memory_get_peak_usage(); $type = ($level === true ? ' Begin' : ($level === false ? ' End' : '')); $this->displayLine( str_repeat(' ', $this->level) . $name . $type, number_format(($time - $this->startTime)*1000, 1, '.', ' ').' ms', number_format(($time - $this->lastTime)*1000, 1, '.', ' ').' ms', number_format($usage/1024, 1, '.', ' ').' Ko', number_format($peak/1024, 1, '.', ' ').' Ko' ); $this->lastTime = $time; // it false : DOWN if ($level === false) { $this->level--; } return $this; }
[ "public", "function", "addStep", "(", "$", "name", ",", "$", "level", "=", "null", ")", "{", "// if true : UP", "if", "(", "$", "level", "===", "true", ")", "{", "$", "this", "->", "level", "++", ";", "}", "$", "time", "=", "microtime", "(", "true", ")", ";", "$", "usage", "=", "memory_get_usage", "(", ")", ";", "$", "peak", "=", "memory_get_peak_usage", "(", ")", ";", "$", "type", "=", "(", "$", "level", "===", "true", "?", "' Begin'", ":", "(", "$", "level", "===", "false", "?", "' End'", ":", "''", ")", ")", ";", "$", "this", "->", "displayLine", "(", "str_repeat", "(", "' '", ",", "$", "this", "->", "level", ")", ".", "$", "name", ".", "$", "type", ",", "number_format", "(", "(", "$", "time", "-", "$", "this", "->", "startTime", ")", "*", "1000", ",", "1", ",", "'.'", ",", "' '", ")", ".", "' ms'", ",", "number_format", "(", "(", "$", "time", "-", "$", "this", "->", "lastTime", ")", "*", "1000", ",", "1", ",", "'.'", ",", "' '", ")", ".", "' ms'", ",", "number_format", "(", "$", "usage", "/", "1024", ",", "1", ",", "'.'", ",", "' '", ")", ".", "' Ko'", ",", "number_format", "(", "$", "peak", "/", "1024", ",", "1", ",", "'.'", ",", "' '", ")", ".", "' Ko'", ")", ";", "$", "this", "->", "lastTime", "=", "$", "time", ";", "// it false : DOWN", "if", "(", "$", "level", "===", "false", ")", "{", "$", "this", "->", "level", "--", ";", "}", "return", "$", "this", ";", "}" ]
add a debug step @param string $name step name @param boolean $level (true=up, false=down, null=nothing to do) @return Debug
[ "add", "a", "debug", "step" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Debug/Debug.php#L114-L142
train
spipu/html2pdf
src/CssConverter.php
CssConverter.convertBackground
public function convertBackground($css, &$value) { // is there a image ? $text = '/url\(([^)]*)\)/isU'; if (preg_match($text, $css, $match)) { // get the image $value['image'] = $this->convertBackgroundImage($match[0]); // remove if from the css properties $css = preg_replace($text, '', $css); $css = preg_replace('/[\s]+/', ' ', $css); } // protect some spaces $css = preg_replace('/,[\s]+/', ',', $css); // explode the values $css = explode(' ', $css); // background position to parse $pos = ''; // foreach value foreach ($css as $val) { // try to parse the value as a color $ok = false; $color = $this->convertToColor($val, $ok); // if ok => it is a color if ($ok) { $value['color'] = $color; // else if transparent => no coloàr } elseif ($val === 'transparent') { $value['color'] = null; // else } else { // try to parse the value as a repeat $repeat = $this->convertBackgroundRepeat($val); // if ok => it is repeat if ($repeat) { $value['repeat'] = $repeat; // else => it could only be a position } else { $pos.= ($pos ? ' ' : '').$val; } } } // if we have a position to parse if ($pos) { // try to read it $pos = $this->convertBackgroundPosition($pos, $ok); if ($ok) { $value['position'] = $pos; } } }
php
public function convertBackground($css, &$value) { // is there a image ? $text = '/url\(([^)]*)\)/isU'; if (preg_match($text, $css, $match)) { // get the image $value['image'] = $this->convertBackgroundImage($match[0]); // remove if from the css properties $css = preg_replace($text, '', $css); $css = preg_replace('/[\s]+/', ' ', $css); } // protect some spaces $css = preg_replace('/,[\s]+/', ',', $css); // explode the values $css = explode(' ', $css); // background position to parse $pos = ''; // foreach value foreach ($css as $val) { // try to parse the value as a color $ok = false; $color = $this->convertToColor($val, $ok); // if ok => it is a color if ($ok) { $value['color'] = $color; // else if transparent => no coloàr } elseif ($val === 'transparent') { $value['color'] = null; // else } else { // try to parse the value as a repeat $repeat = $this->convertBackgroundRepeat($val); // if ok => it is repeat if ($repeat) { $value['repeat'] = $repeat; // else => it could only be a position } else { $pos.= ($pos ? ' ' : '').$val; } } } // if we have a position to parse if ($pos) { // try to read it $pos = $this->convertBackgroundPosition($pos, $ok); if ($ok) { $value['position'] = $pos; } } }
[ "public", "function", "convertBackground", "(", "$", "css", ",", "&", "$", "value", ")", "{", "// is there a image ?", "$", "text", "=", "'/url\\(([^)]*)\\)/isU'", ";", "if", "(", "preg_match", "(", "$", "text", ",", "$", "css", ",", "$", "match", ")", ")", "{", "// get the image", "$", "value", "[", "'image'", "]", "=", "$", "this", "->", "convertBackgroundImage", "(", "$", "match", "[", "0", "]", ")", ";", "// remove if from the css properties", "$", "css", "=", "preg_replace", "(", "$", "text", ",", "''", ",", "$", "css", ")", ";", "$", "css", "=", "preg_replace", "(", "'/[\\s]+/'", ",", "' '", ",", "$", "css", ")", ";", "}", "// protect some spaces", "$", "css", "=", "preg_replace", "(", "'/,[\\s]+/'", ",", "','", ",", "$", "css", ")", ";", "// explode the values", "$", "css", "=", "explode", "(", "' '", ",", "$", "css", ")", ";", "// background position to parse", "$", "pos", "=", "''", ";", "// foreach value", "foreach", "(", "$", "css", "as", "$", "val", ")", "{", "// try to parse the value as a color", "$", "ok", "=", "false", ";", "$", "color", "=", "$", "this", "->", "convertToColor", "(", "$", "val", ",", "$", "ok", ")", ";", "// if ok => it is a color", "if", "(", "$", "ok", ")", "{", "$", "value", "[", "'color'", "]", "=", "$", "color", ";", "// else if transparent => no coloàr", "}", "elseif", "(", "$", "val", "===", "'transparent'", ")", "{", "$", "value", "[", "'color'", "]", "=", "null", ";", "// else", "}", "else", "{", "// try to parse the value as a repeat", "$", "repeat", "=", "$", "this", "->", "convertBackgroundRepeat", "(", "$", "val", ")", ";", "// if ok => it is repeat", "if", "(", "$", "repeat", ")", "{", "$", "value", "[", "'repeat'", "]", "=", "$", "repeat", ";", "// else => it could only be a position", "}", "else", "{", "$", "pos", ".=", "(", "$", "pos", "?", "' '", ":", "''", ")", ".", "$", "val", ";", "}", "}", "}", "// if we have a position to parse", "if", "(", "$", "pos", ")", "{", "// try to read it", "$", "pos", "=", "$", "this", "->", "convertBackgroundPosition", "(", "$", "pos", ",", "$", "ok", ")", ";", "if", "(", "$", "ok", ")", "{", "$", "value", "[", "'position'", "]", "=", "$", "pos", ";", "}", "}", "}" ]
Analyse a background @param string $css css background properties @param &array $value parsed values (by reference, because, ther is a legacy of the parent CSS properties) @return void
[ "Analyse", "a", "background" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/CssConverter.php#L214-L271
train
spipu/html2pdf
src/CssConverter.php
CssConverter.convertBackgroundColor
public function convertBackgroundColor($css) { $res = null; if ($css === 'transparent') { return null; } return $this->convertToColor($css, $res); }
php
public function convertBackgroundColor($css) { $res = null; if ($css === 'transparent') { return null; } return $this->convertToColor($css, $res); }
[ "public", "function", "convertBackgroundColor", "(", "$", "css", ")", "{", "$", "res", "=", "null", ";", "if", "(", "$", "css", "===", "'transparent'", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "convertToColor", "(", "$", "css", ",", "$", "res", ")", ";", "}" ]
Parse a background color @param string $css @return string|null $value
[ "Parse", "a", "background", "color" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/CssConverter.php#L280-L288
train
spipu/html2pdf
src/CssConverter.php
CssConverter.convertBackgroundRepeat
public function convertBackgroundRepeat($css) { switch ($css) { case 'repeat': return array(true, true); case 'repeat-x': return array(true, false); case 'repeat-y': return array(false, true); case 'no-repeat': return array(false, false); } return null; }
php
public function convertBackgroundRepeat($css) { switch ($css) { case 'repeat': return array(true, true); case 'repeat-x': return array(true, false); case 'repeat-y': return array(false, true); case 'no-repeat': return array(false, false); } return null; }
[ "public", "function", "convertBackgroundRepeat", "(", "$", "css", ")", "{", "switch", "(", "$", "css", ")", "{", "case", "'repeat'", ":", "return", "array", "(", "true", ",", "true", ")", ";", "case", "'repeat-x'", ":", "return", "array", "(", "true", ",", "false", ")", ";", "case", "'repeat-y'", ":", "return", "array", "(", "false", ",", "true", ")", ";", "case", "'no-repeat'", ":", "return", "array", "(", "false", ",", "false", ")", ";", "}", "return", "null", ";", "}" ]
Parse a background repeat @param string $css @return array|null background repeat as array
[ "Parse", "a", "background", "repeat" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/CssConverter.php#L391-L404
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.loadExtensions
protected function loadExtensions() { if ($this->extensionsLoaded) { return; } foreach ($this->extensions as $extension) { foreach ($extension->getTags() as $tag) { if (!$tag instanceof TagInterface) { throw new Html2PdfException('The ExtensionInterface::getTags() method must return an array of TagInterface.'); } $this->addTagObject($tag); } } $this->extensionsLoaded = true; }
php
protected function loadExtensions() { if ($this->extensionsLoaded) { return; } foreach ($this->extensions as $extension) { foreach ($extension->getTags() as $tag) { if (!$tag instanceof TagInterface) { throw new Html2PdfException('The ExtensionInterface::getTags() method must return an array of TagInterface.'); } $this->addTagObject($tag); } } $this->extensionsLoaded = true; }
[ "protected", "function", "loadExtensions", "(", ")", "{", "if", "(", "$", "this", "->", "extensionsLoaded", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "extensions", "as", "$", "extension", ")", "{", "foreach", "(", "$", "extension", "->", "getTags", "(", ")", "as", "$", "tag", ")", "{", "if", "(", "!", "$", "tag", "instanceof", "TagInterface", ")", "{", "throw", "new", "Html2PdfException", "(", "'The ExtensionInterface::getTags() method must return an array of TagInterface.'", ")", ";", "}", "$", "this", "->", "addTagObject", "(", "$", "tag", ")", ";", "}", "}", "$", "this", "->", "extensionsLoaded", "=", "true", ";", "}" ]
Initialize the registered extensions @throws Html2PdfException
[ "Initialize", "the", "registered", "extensions" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L320-L335
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.addTagObject
protected function addTagObject(TagInterface $tagObject) { $tagName = strtolower($tagObject->getName()); $this->tagObjects[$tagName] = $tagObject; }
php
protected function addTagObject(TagInterface $tagObject) { $tagName = strtolower($tagObject->getName()); $this->tagObjects[$tagName] = $tagObject; }
[ "protected", "function", "addTagObject", "(", "TagInterface", "$", "tagObject", ")", "{", "$", "tagName", "=", "strtolower", "(", "$", "tagObject", "->", "getName", "(", ")", ")", ";", "$", "this", "->", "tagObjects", "[", "$", "tagName", "]", "=", "$", "tagObject", ";", "}" ]
register a tag object @param TagInterface $tagObject the object
[ "register", "a", "tag", "object" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L342-L346
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.getTagObject
protected function getTagObject($tagName) { if (!$this->extensionsLoaded) { $this->loadExtensions(); } if (!array_key_exists($tagName, $this->tagObjects)) { return null; } $tagObject = $this->tagObjects[$tagName]; $tagObject->setParsingCssObject($this->parsingCss); $tagObject->setCssConverterObject($this->cssConverter); $tagObject->setPdfObject($this->pdf); if (!is_null($this->debug)) { $tagObject->setDebugObject($this->debug); } return $tagObject; }
php
protected function getTagObject($tagName) { if (!$this->extensionsLoaded) { $this->loadExtensions(); } if (!array_key_exists($tagName, $this->tagObjects)) { return null; } $tagObject = $this->tagObjects[$tagName]; $tagObject->setParsingCssObject($this->parsingCss); $tagObject->setCssConverterObject($this->cssConverter); $tagObject->setPdfObject($this->pdf); if (!is_null($this->debug)) { $tagObject->setDebugObject($this->debug); } return $tagObject; }
[ "protected", "function", "getTagObject", "(", "$", "tagName", ")", "{", "if", "(", "!", "$", "this", "->", "extensionsLoaded", ")", "{", "$", "this", "->", "loadExtensions", "(", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "tagName", ",", "$", "this", "->", "tagObjects", ")", ")", "{", "return", "null", ";", "}", "$", "tagObject", "=", "$", "this", "->", "tagObjects", "[", "$", "tagName", "]", ";", "$", "tagObject", "->", "setParsingCssObject", "(", "$", "this", "->", "parsingCss", ")", ";", "$", "tagObject", "->", "setCssConverterObject", "(", "$", "this", "->", "cssConverter", ")", ";", "$", "tagObject", "->", "setPdfObject", "(", "$", "this", "->", "pdf", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "debug", ")", ")", "{", "$", "tagObject", "->", "setDebugObject", "(", "$", "this", "->", "debug", ")", ";", "}", "return", "$", "tagObject", ";", "}" ]
get the tag object from a tag name @param string $tagName tag name to load @return TagInterface|null
[ "get", "the", "tag", "object", "from", "a", "tag", "name" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L355-L374
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.setModeDebug
public function setModeDebug(DebugInterface $debugObject = null) { if (is_null($debugObject)) { $this->debug = new Debug(); } else { $this->debug = $debugObject; } $this->debug->start(); return $this; }
php
public function setModeDebug(DebugInterface $debugObject = null) { if (is_null($debugObject)) { $this->debug = new Debug(); } else { $this->debug = $debugObject; } $this->debug->start(); return $this; }
[ "public", "function", "setModeDebug", "(", "DebugInterface", "$", "debugObject", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "debugObject", ")", ")", "{", "$", "this", "->", "debug", "=", "new", "Debug", "(", ")", ";", "}", "else", "{", "$", "this", "->", "debug", "=", "$", "debugObject", ";", "}", "$", "this", "->", "debug", "->", "start", "(", ")", ";", "return", "$", "this", ";", "}" ]
set the debug mode to On @param DebugInterface $debugObject @return Html2Pdf $this
[ "set", "the", "debug", "mode", "to", "On" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L383-L393
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.addFont
public function addFont($family, $style = '', $file = '') { $this->pdf->AddFont($family, $style, $file); return $this; }
php
public function addFont($family, $style = '', $file = '') { $this->pdf->AddFont($family, $style, $file); return $this; }
[ "public", "function", "addFont", "(", "$", "family", ",", "$", "style", "=", "''", ",", "$", "file", "=", "''", ")", "{", "$", "this", "->", "pdf", "->", "AddFont", "(", "$", "family", ",", "$", "style", ",", "$", "file", ")", ";", "return", "$", "this", ";", "}" ]
add a font, see TCPDF function addFont @access public @param string $family Font family. The name can be chosen arbitrarily. If it is a standard family name, it will override the corresponding font. @param string $style Font style. Possible values are (case insensitive):<ul><li>empty string: regular (default)</li><li>B: bold</li><li>I: italic</li><li>BI or IB: bold italic</li></ul> @param string $file The font definition file. By default, the name is built from the family and style, in lower case with no spaces. @return Html2Pdf $this @see TCPDF::addFont
[ "add", "a", "font", "see", "TCPDF", "function", "addFont" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L462-L467
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.createIndex
public function createIndex( $titre = 'Index', $sizeTitle = 20, $sizeBookmark = 15, $bookmarkTitle = true, $displayPage = true, $onPage = null, $fontName = null, $marginTop = null ) { if ($fontName === null) { $fontName = 'helvetica'; } $oldPage = $this->_INDEX_NewPage($onPage); if ($marginTop !== null) { $marginTop = $this->cssConverter->convertToMM($marginTop); $this->pdf->SetY($this->pdf->GetY() + $marginTop); } $this->pdf->createIndex($this, $titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName); if ($oldPage) { $this->pdf->setPage($oldPage); } }
php
public function createIndex( $titre = 'Index', $sizeTitle = 20, $sizeBookmark = 15, $bookmarkTitle = true, $displayPage = true, $onPage = null, $fontName = null, $marginTop = null ) { if ($fontName === null) { $fontName = 'helvetica'; } $oldPage = $this->_INDEX_NewPage($onPage); if ($marginTop !== null) { $marginTop = $this->cssConverter->convertToMM($marginTop); $this->pdf->SetY($this->pdf->GetY() + $marginTop); } $this->pdf->createIndex($this, $titre, $sizeTitle, $sizeBookmark, $bookmarkTitle, $displayPage, $onPage, $fontName); if ($oldPage) { $this->pdf->setPage($oldPage); } }
[ "public", "function", "createIndex", "(", "$", "titre", "=", "'Index'", ",", "$", "sizeTitle", "=", "20", ",", "$", "sizeBookmark", "=", "15", ",", "$", "bookmarkTitle", "=", "true", ",", "$", "displayPage", "=", "true", ",", "$", "onPage", "=", "null", ",", "$", "fontName", "=", "null", ",", "$", "marginTop", "=", "null", ")", "{", "if", "(", "$", "fontName", "===", "null", ")", "{", "$", "fontName", "=", "'helvetica'", ";", "}", "$", "oldPage", "=", "$", "this", "->", "_INDEX_NewPage", "(", "$", "onPage", ")", ";", "if", "(", "$", "marginTop", "!==", "null", ")", "{", "$", "marginTop", "=", "$", "this", "->", "cssConverter", "->", "convertToMM", "(", "$", "marginTop", ")", ";", "$", "this", "->", "pdf", "->", "SetY", "(", "$", "this", "->", "pdf", "->", "GetY", "(", ")", "+", "$", "marginTop", ")", ";", "}", "$", "this", "->", "pdf", "->", "createIndex", "(", "$", "this", ",", "$", "titre", ",", "$", "sizeTitle", ",", "$", "sizeBookmark", ",", "$", "bookmarkTitle", ",", "$", "displayPage", ",", "$", "onPage", ",", "$", "fontName", ")", ";", "if", "(", "$", "oldPage", ")", "{", "$", "this", "->", "pdf", "->", "setPage", "(", "$", "oldPage", ")", ";", "}", "}" ]
display a automatic index, from the bookmarks @access public @param string $titre index title @param int $sizeTitle font size of the index title, in mm @param int $sizeBookmark font size of the index, in mm @param boolean $bookmarkTitle add a bookmark for the index, at his beginning @param boolean $displayPage display the page numbers @param int $onPage if null : at the end of the document on a new page, else on the $onPage page @param string $fontName font name to use @param string $marginTop margin top to use on the index page @return null
[ "display", "a", "automatic", "index", "from", "the", "bookmarks" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L483-L508
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.writeHTML
public function writeHTML($html) { $html = $this->parsingHtml->prepareHtml($html); $html = $this->parsingCss->extractStyle($html); $this->parsingHtml->parse($this->lexer->tokenize($html)); $this->_makeHTMLcode(); return $this; }
php
public function writeHTML($html) { $html = $this->parsingHtml->prepareHtml($html); $html = $this->parsingCss->extractStyle($html); $this->parsingHtml->parse($this->lexer->tokenize($html)); $this->_makeHTMLcode(); return $this; }
[ "public", "function", "writeHTML", "(", "$", "html", ")", "{", "$", "html", "=", "$", "this", "->", "parsingHtml", "->", "prepareHtml", "(", "$", "html", ")", ";", "$", "html", "=", "$", "this", "->", "parsingCss", "->", "extractStyle", "(", "$", "html", ")", ";", "$", "this", "->", "parsingHtml", "->", "parse", "(", "$", "this", "->", "lexer", "->", "tokenize", "(", "$", "html", ")", ")", ";", "$", "this", "->", "_makeHTMLcode", "(", ")", ";", "return", "$", "this", ";", "}" ]
convert HTML to PDF @param string $html @return Html2Pdf
[ "convert", "HTML", "to", "PDF" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L590-L598
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.previewHTML
public function previewHTML($html) { $html = $this->parsingHtml->prepareHtml($html); $html = preg_replace('/<page([^>]*)>/isU', '<hr>Page : $1<hr><div$1>', $html); $html = preg_replace('/<page_header([^>]*)>/isU', '<hr>Page Header : $1<hr><div$1>', $html); $html = preg_replace('/<page_footer([^>]*)>/isU', '<hr>Page Footer : $1<hr><div$1>', $html); $html = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $html); $html = preg_replace('/<\/page_header([^>]*)>/isU', '</div><hr>', $html); $html = preg_replace('/<\/page_footer([^>]*)>/isU', '</div><hr>', $html); $html = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $html); $html = preg_replace('/<\/bookmark([^>]*)>/isU', '', $html); $html = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $html); $html = preg_replace('/<\/barcode([^>]*)>/isU', '', $html); $html = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $html); $html = preg_replace('/<\/qrcode([^>]*)>/isU', '', $html); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>HTML View</title> <meta http-equiv="Content-Type" content="text/html; charset='.$this->_encoding.'" > </head> <body style="padding: 10px; font-size: 10pt;font-family: Verdana;"> '.$html.' </body> </html>'; }
php
public function previewHTML($html) { $html = $this->parsingHtml->prepareHtml($html); $html = preg_replace('/<page([^>]*)>/isU', '<hr>Page : $1<hr><div$1>', $html); $html = preg_replace('/<page_header([^>]*)>/isU', '<hr>Page Header : $1<hr><div$1>', $html); $html = preg_replace('/<page_footer([^>]*)>/isU', '<hr>Page Footer : $1<hr><div$1>', $html); $html = preg_replace('/<\/page([^>]*)>/isU', '</div><hr>', $html); $html = preg_replace('/<\/page_header([^>]*)>/isU', '</div><hr>', $html); $html = preg_replace('/<\/page_footer([^>]*)>/isU', '</div><hr>', $html); $html = preg_replace('/<bookmark([^>]*)>/isU', '<hr>bookmark : $1<hr>', $html); $html = preg_replace('/<\/bookmark([^>]*)>/isU', '', $html); $html = preg_replace('/<barcode([^>]*)>/isU', '<hr>barcode : $1<hr>', $html); $html = preg_replace('/<\/barcode([^>]*)>/isU', '', $html); $html = preg_replace('/<qrcode([^>]*)>/isU', '<hr>qrcode : $1<hr>', $html); $html = preg_replace('/<\/qrcode([^>]*)>/isU', '', $html); echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>HTML View</title> <meta http-equiv="Content-Type" content="text/html; charset='.$this->_encoding.'" > </head> <body style="padding: 10px; font-size: 10pt;font-family: Verdana;"> '.$html.' </body> </html>'; }
[ "public", "function", "previewHTML", "(", "$", "html", ")", "{", "$", "html", "=", "$", "this", "->", "parsingHtml", "->", "prepareHtml", "(", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<page([^>]*)>/isU'", ",", "'<hr>Page : $1<hr><div$1>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<page_header([^>]*)>/isU'", ",", "'<hr>Page Header : $1<hr><div$1>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<page_footer([^>]*)>/isU'", ",", "'<hr>Page Footer : $1<hr><div$1>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<\\/page([^>]*)>/isU'", ",", "'</div><hr>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<\\/page_header([^>]*)>/isU'", ",", "'</div><hr>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<\\/page_footer([^>]*)>/isU'", ",", "'</div><hr>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<bookmark([^>]*)>/isU'", ",", "'<hr>bookmark : $1<hr>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<\\/bookmark([^>]*)>/isU'", ",", "''", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<barcode([^>]*)>/isU'", ",", "'<hr>barcode : $1<hr>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<\\/barcode([^>]*)>/isU'", ",", "''", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<qrcode([^>]*)>/isU'", ",", "'<hr>qrcode : $1<hr>'", ",", "$", "html", ")", ";", "$", "html", "=", "preg_replace", "(", "'/<\\/qrcode([^>]*)>/isU'", ",", "''", ",", "$", "html", ")", ";", "echo", "'<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<html>\n <head>\n <title>HTML View</title>\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset='", ".", "$", "this", "->", "_encoding", ".", "'\" >\n </head>\n <body style=\"padding: 10px; font-size: 10pt;font-family: Verdana;\">\n '", ".", "$", "html", ".", "'\n </body>\n</html>'", ";", "}" ]
Preview the HTML before conversion @param string $html @return void
[ "Preview", "the", "HTML", "before", "conversion" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L608-L638
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.initSubHtml
public function initSubHtml($format, $orientation, $marge, $page, $defLIST, $myLastPageGroup, $myLastPageGroupNb) { $this->_isSubPart = true; $this->parsingCss->setOnlyLeft(); $this->_setNewPage($format, $orientation, null, null, ($myLastPageGroup !== null)); $this->_saveMargin(0, 0, $marge); $this->_defList = $defLIST; $this->_page = $page; $this->pdf->setMyLastPageGroup($myLastPageGroup); $this->pdf->setMyLastPageGroupNb($myLastPageGroupNb); $this->pdf->SetXY(0, 0); $this->parsingCss->fontSet(); }
php
public function initSubHtml($format, $orientation, $marge, $page, $defLIST, $myLastPageGroup, $myLastPageGroupNb) { $this->_isSubPart = true; $this->parsingCss->setOnlyLeft(); $this->_setNewPage($format, $orientation, null, null, ($myLastPageGroup !== null)); $this->_saveMargin(0, 0, $marge); $this->_defList = $defLIST; $this->_page = $page; $this->pdf->setMyLastPageGroup($myLastPageGroup); $this->pdf->setMyLastPageGroupNb($myLastPageGroupNb); $this->pdf->SetXY(0, 0); $this->parsingCss->fontSet(); }
[ "public", "function", "initSubHtml", "(", "$", "format", ",", "$", "orientation", ",", "$", "marge", ",", "$", "page", ",", "$", "defLIST", ",", "$", "myLastPageGroup", ",", "$", "myLastPageGroupNb", ")", "{", "$", "this", "->", "_isSubPart", "=", "true", ";", "$", "this", "->", "parsingCss", "->", "setOnlyLeft", "(", ")", ";", "$", "this", "->", "_setNewPage", "(", "$", "format", ",", "$", "orientation", ",", "null", ",", "null", ",", "(", "$", "myLastPageGroup", "!==", "null", ")", ")", ";", "$", "this", "->", "_saveMargin", "(", "0", ",", "0", ",", "$", "marge", ")", ";", "$", "this", "->", "_defList", "=", "$", "defLIST", ";", "$", "this", "->", "_page", "=", "$", "page", ";", "$", "this", "->", "pdf", "->", "setMyLastPageGroup", "(", "$", "myLastPageGroup", ")", ";", "$", "this", "->", "pdf", "->", "setMyLastPageGroupNb", "(", "$", "myLastPageGroupNb", ")", ";", "$", "this", "->", "pdf", "->", "SetXY", "(", "0", ",", "0", ")", ";", "$", "this", "->", "parsingCss", "->", "fontSet", "(", ")", ";", "}" ]
init a sub Html2Pdf. do not use it directly. Only the method createSubHTML must use it @access public @param string $format @param string $orientation @param array $marge @param integer $page @param array $defLIST @param integer $myLastPageGroup @param integer $myLastPageGroupNb
[ "init", "a", "sub", "Html2Pdf", ".", "do", "not", "use", "it", "directly", ".", "Only", "the", "method", "createSubHTML", "must", "use", "it" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L652-L668
train
spipu/html2pdf
src/Html2Pdf.php
Html2Pdf.setDefaultMargins
protected function setDefaultMargins($margins) { if (!is_array($margins)) { $margins = array($margins, $margins, $margins, $margins); } if (!isset($margins[2])) { $margins[2] = $margins[0]; } if (!isset($margins[3])) { $margins[3] = 8; } $this->_defaultLeft = $this->cssConverter->convertToMM($margins[0].'mm'); $this->_defaultTop = $this->cssConverter->convertToMM($margins[1].'mm'); $this->_defaultRight = $this->cssConverter->convertToMM($margins[2].'mm'); $this->_defaultBottom = $this->cssConverter->convertToMM($margins[3].'mm'); }
php
protected function setDefaultMargins($margins) { if (!is_array($margins)) { $margins = array($margins, $margins, $margins, $margins); } if (!isset($margins[2])) { $margins[2] = $margins[0]; } if (!isset($margins[3])) { $margins[3] = 8; } $this->_defaultLeft = $this->cssConverter->convertToMM($margins[0].'mm'); $this->_defaultTop = $this->cssConverter->convertToMM($margins[1].'mm'); $this->_defaultRight = $this->cssConverter->convertToMM($margins[2].'mm'); $this->_defaultBottom = $this->cssConverter->convertToMM($margins[3].'mm'); }
[ "protected", "function", "setDefaultMargins", "(", "$", "margins", ")", "{", "if", "(", "!", "is_array", "(", "$", "margins", ")", ")", "{", "$", "margins", "=", "array", "(", "$", "margins", ",", "$", "margins", ",", "$", "margins", ",", "$", "margins", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "margins", "[", "2", "]", ")", ")", "{", "$", "margins", "[", "2", "]", "=", "$", "margins", "[", "0", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "margins", "[", "3", "]", ")", ")", "{", "$", "margins", "[", "3", "]", "=", "8", ";", "}", "$", "this", "->", "_defaultLeft", "=", "$", "this", "->", "cssConverter", "->", "convertToMM", "(", "$", "margins", "[", "0", "]", ".", "'mm'", ")", ";", "$", "this", "->", "_defaultTop", "=", "$", "this", "->", "cssConverter", "->", "convertToMM", "(", "$", "margins", "[", "1", "]", ".", "'mm'", ")", ";", "$", "this", "->", "_defaultRight", "=", "$", "this", "->", "cssConverter", "->", "convertToMM", "(", "$", "margins", "[", "2", "]", ".", "'mm'", ")", ";", "$", "this", "->", "_defaultBottom", "=", "$", "this", "->", "cssConverter", "->", "convertToMM", "(", "$", "margins", "[", "3", "]", ".", "'mm'", ")", ";", "}" ]
set the default margins of the page @param array|int $margins (mm, left top right bottom)
[ "set", "the", "default", "margins", "of", "the", "page" ]
83c9bd942e8520681808b70584e01d17157335ba
https://github.com/spipu/html2pdf/blob/83c9bd942e8520681808b70584e01d17157335ba/src/Html2Pdf.php#L675-L692
train