repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
mvdbos/vdb-uri | src/VDB/Uri/Uri.php | Uri.equals | public function equals(UriInterface $that, $normalized = false)
{
$thisClone = $this;
$thatClone = $that;
if (false !== $normalized) {
$thisClone = clone $this;
$thatClone = clone $that;
$thisClone->normalize();
$thatClone->normalize();
}
if ($thisClone->getScheme() !== $thatClone->getScheme()) {
return false;
} else {
if ($thisClone->getUsername() !== $thatClone->getUsername()) {
return false;
} else {
if ($thisClone->getPassword() !== $thatClone->getPassword()) {
return false;
} else {
if ($thisClone->getHost() !== $thatClone->getHost()) {
return false;
} else {
if ($thisClone->getPort() !== $thatClone->getPort()) {
return false;
} else {
if ($thisClone->getPath() !== $thatClone->getPath()) {
return false;
} else {
if ($thisClone->getQuery() !== $thatClone->getQuery()) {
return false;
} else {
if ($thisClone->getFragment() !== $thatClone->getFragment()) {
return false;
} else {
return true;
}
}
}
}
}
}
}
}
} | php | public function equals(UriInterface $that, $normalized = false)
{
$thisClone = $this;
$thatClone = $that;
if (false !== $normalized) {
$thisClone = clone $this;
$thatClone = clone $that;
$thisClone->normalize();
$thatClone->normalize();
}
if ($thisClone->getScheme() !== $thatClone->getScheme()) {
return false;
} else {
if ($thisClone->getUsername() !== $thatClone->getUsername()) {
return false;
} else {
if ($thisClone->getPassword() !== $thatClone->getPassword()) {
return false;
} else {
if ($thisClone->getHost() !== $thatClone->getHost()) {
return false;
} else {
if ($thisClone->getPort() !== $thatClone->getPort()) {
return false;
} else {
if ($thisClone->getPath() !== $thatClone->getPath()) {
return false;
} else {
if ($thisClone->getQuery() !== $thatClone->getQuery()) {
return false;
} else {
if ($thisClone->getFragment() !== $thatClone->getFragment()) {
return false;
} else {
return true;
}
}
}
}
}
}
}
}
} | [
"public",
"function",
"equals",
"(",
"UriInterface",
"$",
"that",
",",
"$",
"normalized",
"=",
"false",
")",
"{",
"$",
"thisClone",
"=",
"$",
"this",
";",
"$",
"thatClone",
"=",
"$",
"that",
";",
"if",
"(",
"false",
"!==",
"$",
"normalized",
")",
"{",
"$",
"thisClone",
"=",
"clone",
"$",
"this",
";",
"$",
"thatClone",
"=",
"clone",
"$",
"that",
";",
"$",
"thisClone",
"->",
"normalize",
"(",
")",
";",
"$",
"thatClone",
"->",
"normalize",
"(",
")",
";",
"}",
"if",
"(",
"$",
"thisClone",
"->",
"getScheme",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getScheme",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"thisClone",
"->",
"getUsername",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getUsername",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"thisClone",
"->",
"getPassword",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getPassword",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"thisClone",
"->",
"getHost",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getHost",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"thisClone",
"->",
"getPort",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getPort",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"thisClone",
"->",
"getPath",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getPath",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"thisClone",
"->",
"getQuery",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getQuery",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"thisClone",
"->",
"getFragment",
"(",
")",
"!==",
"$",
"thatClone",
"->",
"getFragment",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}"
]
| Test two URIs for equality. Will return true if and only if all Uri components are identical.
Note: will use the normalized versions of the Uri's to compare
@param UriInterface $that
@param bool $normalized whether the comparison will be done on normalized versions of the URIs.
This does not alter the arguments.
@return bool | [
"Test",
"two",
"URIs",
"for",
"equality",
".",
"Will",
"return",
"true",
"if",
"and",
"only",
"if",
"all",
"Uri",
"components",
"are",
"identical",
".",
"Note",
":",
"will",
"use",
"the",
"normalized",
"versions",
"of",
"the",
"Uri",
"s",
"to",
"compare"
]
| train | https://github.com/mvdbos/vdb-uri/blob/48264d5cd3a61b5166bf62468381cd58405b63ca/src/VDB/Uri/Uri.php#L180-L225 |
mvdbos/vdb-uri | src/VDB/Uri/Uri.php | Uri.normalize | public function normalize()
{
$this->normalizeSchemeCase();
$this->normalizeUsernamePercentageEncoding();
$this->normalizePasswordPercentageEncoding();
$this->normalizeHostCase();
$this->normalizePort();
$this->normalizePathPercentageEncoding();
$this->normalizeDotSegments();
$this->normalizeQueryPercentageEncoding();
$this->normalizeFragmentPercentageEncoding();
return $this;
} | php | public function normalize()
{
$this->normalizeSchemeCase();
$this->normalizeUsernamePercentageEncoding();
$this->normalizePasswordPercentageEncoding();
$this->normalizeHostCase();
$this->normalizePort();
$this->normalizePathPercentageEncoding();
$this->normalizeDotSegments();
$this->normalizeQueryPercentageEncoding();
$this->normalizeFragmentPercentageEncoding();
return $this;
} | [
"public",
"function",
"normalize",
"(",
")",
"{",
"$",
"this",
"->",
"normalizeSchemeCase",
"(",
")",
";",
"$",
"this",
"->",
"normalizeUsernamePercentageEncoding",
"(",
")",
";",
"$",
"this",
"->",
"normalizePasswordPercentageEncoding",
"(",
")",
";",
"$",
"this",
"->",
"normalizeHostCase",
"(",
")",
";",
"$",
"this",
"->",
"normalizePort",
"(",
")",
";",
"$",
"this",
"->",
"normalizePathPercentageEncoding",
"(",
")",
";",
"$",
"this",
"->",
"normalizeDotSegments",
"(",
")",
";",
"$",
"this",
"->",
"normalizeQueryPercentageEncoding",
"(",
")",
";",
"$",
"this",
"->",
"normalizeFragmentPercentageEncoding",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Normalization includes the following:
- dot segements in the path component,
- the port if it matches the default port for the scheme,
- percent encoding and character case where applicable to components, according to RFC 3986.
@return $this|UriInterface | [
"Normalization",
"includes",
"the",
"following",
":",
"-",
"dot",
"segements",
"in",
"the",
"path",
"component",
"-",
"the",
"port",
"if",
"it",
"matches",
"the",
"default",
"port",
"for",
"the",
"scheme",
"-",
"percent",
"encoding",
"and",
"character",
"case",
"where",
"applicable",
"to",
"components",
"according",
"to",
"RFC",
"3986",
"."
]
| train | https://github.com/mvdbos/vdb-uri/blob/48264d5cd3a61b5166bf62468381cd58405b63ca/src/VDB/Uri/Uri.php#L309-L322 |
mvdbos/vdb-uri | src/VDB/Uri/Uri.php | Uri.resolveRelativeReference | private function resolveRelativeReference()
{
if (null !== $this->scheme) {
$this->normalizeDotSegments();
} else {
$this->scheme = $this->baseUri->scheme;
if (null !== $this->authority) {
$this->normalizeDotSegments();
} else {
$this->authority = $this->baseUri->authority;
$this->parseUserInfoHostPort();
if ('' === $this->path) {
$this->path = $this->baseUri->path;
if (null === $this->query) {
$this->query = $this->baseUri->query;
}
} else {
if (0 === strpos($this->path, '/')) {
$this->normalizeDotSegments();
} else {
$this->mergeBasePath();
$this->normalizeDotSegments();
}
}
}
}
} | php | private function resolveRelativeReference()
{
if (null !== $this->scheme) {
$this->normalizeDotSegments();
} else {
$this->scheme = $this->baseUri->scheme;
if (null !== $this->authority) {
$this->normalizeDotSegments();
} else {
$this->authority = $this->baseUri->authority;
$this->parseUserInfoHostPort();
if ('' === $this->path) {
$this->path = $this->baseUri->path;
if (null === $this->query) {
$this->query = $this->baseUri->query;
}
} else {
if (0 === strpos($this->path, '/')) {
$this->normalizeDotSegments();
} else {
$this->mergeBasePath();
$this->normalizeDotSegments();
}
}
}
}
} | [
"private",
"function",
"resolveRelativeReference",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"scheme",
")",
"{",
"$",
"this",
"->",
"normalizeDotSegments",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"scheme",
"=",
"$",
"this",
"->",
"baseUri",
"->",
"scheme",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"authority",
")",
"{",
"$",
"this",
"->",
"normalizeDotSegments",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"authority",
"=",
"$",
"this",
"->",
"baseUri",
"->",
"authority",
";",
"$",
"this",
"->",
"parseUserInfoHostPort",
"(",
")",
";",
"if",
"(",
"''",
"===",
"$",
"this",
"->",
"path",
")",
"{",
"$",
"this",
"->",
"path",
"=",
"$",
"this",
"->",
"baseUri",
"->",
"path",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"query",
")",
"{",
"$",
"this",
"->",
"query",
"=",
"$",
"this",
"->",
"baseUri",
"->",
"query",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"this",
"->",
"path",
",",
"'/'",
")",
")",
"{",
"$",
"this",
"->",
"normalizeDotSegments",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"mergeBasePath",
"(",
")",
";",
"$",
"this",
"->",
"normalizeDotSegments",
"(",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| From RFC 3986 paragraph 4.2
relative-ref = relative-part [ "?" query ] [ "#" fragment ]
relative-part = "//" authority path-abempty
/ path-absolute
/ path-noscheme
/ path-empty
then:
From RFC 3986 paragraph 5.2.2
For each Uri reference (R), the following pseudocode describes an
algorithm for transforming R into its target Uri (T):
-- The Uri reference is parsed into the five Uri components
--
(R.scheme, R.authority, R.path, R.query, R.fragment) = parse(R);
-- A non-strict parser may ignore a scheme in the reference
-- if it is identical to the base Uri's scheme.
--
if ((not strict) and (R.scheme == Base.scheme)) then
undefine(R.scheme);
endif;
if defined(R.scheme) then
T.scheme = R.scheme;
T.authority = R.authority;
T.path = remove_dot_segments(R.path);
T.query = R.query;
else
if defined(R.authority) then
T.authority = R.authority;
T.path = remove_dot_segments(R.path);
T.query = R.query;
else
if (R.path == "") then
T.path = Base.path;
if defined(R.query) then
T.query = R.query;
else
T.query = Base.query;
endif;
else
if (R.path starts-with "/") then
T.path = remove_dot_segments(R.path);
else
T.path = merge(Base.path, R.path);
T.path = remove_dot_segments(T.path);
endif;
T.query = R.query;
endif;
T.authority = Base.authority;
endif;
T.scheme = Base.scheme;
endif;
T.fragment = R.fragment; | [
"From",
"RFC",
"3986",
"paragraph",
"4",
".",
"2"
]
| train | https://github.com/mvdbos/vdb-uri/blob/48264d5cd3a61b5166bf62468381cd58405b63ca/src/VDB/Uri/Uri.php#L538-L564 |
mvdbos/vdb-uri | src/VDB/Uri/Uri.php | Uri.normalizeDotSegments | private function normalizeDotSegments()
{
$input = explode('/', $this->path);
$output = array();
while (!empty($input)) {
if ('..' === $input[0]) {
if (1 === count($input)) {
array_shift($input);
if ('' !== end($output)) {
array_pop($output);
}
array_push($output, '');
} else {
array_shift($input);
if ('' !== end($output)) {
array_pop($output);
}
}
} elseif ('.' === $input[0]) {
if (1 === count($input)) {
array_shift($input);
array_push($output, '');
} else {
array_shift($input);
}
} else {
array_push($output, array_shift($input));
}
}
$this->path = implode('/', $output);
} | php | private function normalizeDotSegments()
{
$input = explode('/', $this->path);
$output = array();
while (!empty($input)) {
if ('..' === $input[0]) {
if (1 === count($input)) {
array_shift($input);
if ('' !== end($output)) {
array_pop($output);
}
array_push($output, '');
} else {
array_shift($input);
if ('' !== end($output)) {
array_pop($output);
}
}
} elseif ('.' === $input[0]) {
if (1 === count($input)) {
array_shift($input);
array_push($output, '');
} else {
array_shift($input);
}
} else {
array_push($output, array_shift($input));
}
}
$this->path = implode('/', $output);
} | [
"private",
"function",
"normalizeDotSegments",
"(",
")",
"{",
"$",
"input",
"=",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"path",
")",
";",
"$",
"output",
"=",
"array",
"(",
")",
";",
"while",
"(",
"!",
"empty",
"(",
"$",
"input",
")",
")",
"{",
"if",
"(",
"'..'",
"===",
"$",
"input",
"[",
"0",
"]",
")",
"{",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"input",
")",
")",
"{",
"array_shift",
"(",
"$",
"input",
")",
";",
"if",
"(",
"''",
"!==",
"end",
"(",
"$",
"output",
")",
")",
"{",
"array_pop",
"(",
"$",
"output",
")",
";",
"}",
"array_push",
"(",
"$",
"output",
",",
"''",
")",
";",
"}",
"else",
"{",
"array_shift",
"(",
"$",
"input",
")",
";",
"if",
"(",
"''",
"!==",
"end",
"(",
"$",
"output",
")",
")",
"{",
"array_pop",
"(",
"$",
"output",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"'.'",
"===",
"$",
"input",
"[",
"0",
"]",
")",
"{",
"if",
"(",
"1",
"===",
"count",
"(",
"$",
"input",
")",
")",
"{",
"array_shift",
"(",
"$",
"input",
")",
";",
"array_push",
"(",
"$",
"output",
",",
"''",
")",
";",
"}",
"else",
"{",
"array_shift",
"(",
"$",
"input",
")",
";",
"}",
"}",
"else",
"{",
"array_push",
"(",
"$",
"output",
",",
"array_shift",
"(",
"$",
"input",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"path",
"=",
"implode",
"(",
"'/'",
",",
"$",
"output",
")",
";",
"}"
]
| From RFC 3986 paragraph 5.2.4
1. The input buffer is initialized with the now-appended path
components and the output buffer is initialized to the empty
string.
2. While the input buffer is not empty, loop as follows:
A. If the input buffer begins with a prefix of "../" or "./",
then remove that prefix from the input buffer; otherwise,
B. if the input buffer begins with a prefix of "/./" or "/.",
where "." is a complete path segment, then replace that
prefix with "/" in the input buffer; otherwise,
C. if the input buffer begins with a prefix of "/../" or "/..",
where ".." is a complete path segment, then replace that
prefix with "/" in the input buffer and remove the last
segment and its preceding "/" (if any) from the output
buffer; otherwise,
D. if the input buffer consists only of "." or "..", then remove
that from the input buffer; otherwise,
E. move the first path segment in the input buffer to the end of
the output buffer, including the initial "/" character (if
any) and any subsequent characters up to, but not including,
the next "/" character or the end of the input buffer.
3. Finally, the output buffer is returned as the result of
remove_dot_segments. | [
"From",
"RFC",
"3986",
"paragraph",
"5",
".",
"2",
".",
"4"
]
| train | https://github.com/mvdbos/vdb-uri/blob/48264d5cd3a61b5166bf62468381cd58405b63ca/src/VDB/Uri/Uri.php#L600-L631 |
mvdbos/vdb-uri | src/VDB/Uri/Uri.php | Uri.mergeBasePath | private function mergeBasePath()
{
if (null !== $this->baseUri->authority && '' === $this->baseUri->path) {
$this->path = '/' . $this->path;
} else {
if (false !== $lastSlashPos = strrpos($this->baseUri->path, '/')) {
$basePath = substr($this->baseUri->path, 0, $lastSlashPos + 1);
$this->path = $basePath . $this->path;
}
}
} | php | private function mergeBasePath()
{
if (null !== $this->baseUri->authority && '' === $this->baseUri->path) {
$this->path = '/' . $this->path;
} else {
if (false !== $lastSlashPos = strrpos($this->baseUri->path, '/')) {
$basePath = substr($this->baseUri->path, 0, $lastSlashPos + 1);
$this->path = $basePath . $this->path;
}
}
} | [
"private",
"function",
"mergeBasePath",
"(",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"baseUri",
"->",
"authority",
"&&",
"''",
"===",
"$",
"this",
"->",
"baseUri",
"->",
"path",
")",
"{",
"$",
"this",
"->",
"path",
"=",
"'/'",
".",
"$",
"this",
"->",
"path",
";",
"}",
"else",
"{",
"if",
"(",
"false",
"!==",
"$",
"lastSlashPos",
"=",
"strrpos",
"(",
"$",
"this",
"->",
"baseUri",
"->",
"path",
",",
"'/'",
")",
")",
"{",
"$",
"basePath",
"=",
"substr",
"(",
"$",
"this",
"->",
"baseUri",
"->",
"path",
",",
"0",
",",
"$",
"lastSlashPos",
"+",
"1",
")",
";",
"$",
"this",
"->",
"path",
"=",
"$",
"basePath",
".",
"$",
"this",
"->",
"path",
";",
"}",
"}",
"}"
]
| From RFC 3986 paragraph 5.2.3 | [
"From",
"RFC",
"3986",
"paragraph",
"5",
".",
"2",
".",
"3"
]
| train | https://github.com/mvdbos/vdb-uri/blob/48264d5cd3a61b5166bf62468381cd58405b63ca/src/VDB/Uri/Uri.php#L636-L646 |
mvdbos/vdb-uri | src/VDB/Uri/Uri.php | Uri.parseUriReference | private function parseUriReference()
{
$this->parseScheme();
$this->parseAuthority();
$this->parsePath();
$this->parseQuery();
$this->parseFragment();
$this->doSchemeSpecificPostProcessing();
if (strlen($this->remaining)) {
throw new ErrorException("Still something left after parsing, shouldn't happen: '$this->remaining'");
}
} | php | private function parseUriReference()
{
$this->parseScheme();
$this->parseAuthority();
$this->parsePath();
$this->parseQuery();
$this->parseFragment();
$this->doSchemeSpecificPostProcessing();
if (strlen($this->remaining)) {
throw new ErrorException("Still something left after parsing, shouldn't happen: '$this->remaining'");
}
} | [
"private",
"function",
"parseUriReference",
"(",
")",
"{",
"$",
"this",
"->",
"parseScheme",
"(",
")",
";",
"$",
"this",
"->",
"parseAuthority",
"(",
")",
";",
"$",
"this",
"->",
"parsePath",
"(",
")",
";",
"$",
"this",
"->",
"parseQuery",
"(",
")",
";",
"$",
"this",
"->",
"parseFragment",
"(",
")",
";",
"$",
"this",
"->",
"doSchemeSpecificPostProcessing",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"remaining",
")",
")",
"{",
"throw",
"new",
"ErrorException",
"(",
"\"Still something left after parsing, shouldn't happen: '$this->remaining'\"",
")",
";",
"}",
"}"
]
| From RFC 3986 paragraph 4.1
Uri-reference = Uri / relative-ref | [
"From",
"RFC",
"3986",
"paragraph",
"4",
".",
"1"
]
| train | https://github.com/mvdbos/vdb-uri/blob/48264d5cd3a61b5166bf62468381cd58405b63ca/src/VDB/Uri/Uri.php#L725-L738 |
digitalkaoz/versioneye-php | src/Output/BaseOutput.php | BaseOutput.printTable | protected function printTable(OutputInterface $output, array $headings, array $keys, $data, \Closure $callback = null)
{
$table = $this->createTable($output);
$table->setHeaders(array_map('trim', $headings));
foreach ($data as $row) {
$rowData = array_merge(array_flip($keys), array_intersect_key($row, array_flip($keys)));
if ($callback) {
$rowData = array_map($callback, array_keys($rowData), $rowData);
}
$table->addRow(array_map('trim', $rowData));
}
$table->render($output);
} | php | protected function printTable(OutputInterface $output, array $headings, array $keys, $data, \Closure $callback = null)
{
$table = $this->createTable($output);
$table->setHeaders(array_map('trim', $headings));
foreach ($data as $row) {
$rowData = array_merge(array_flip($keys), array_intersect_key($row, array_flip($keys)));
if ($callback) {
$rowData = array_map($callback, array_keys($rowData), $rowData);
}
$table->addRow(array_map('trim', $rowData));
}
$table->render($output);
} | [
"protected",
"function",
"printTable",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"headings",
",",
"array",
"$",
"keys",
",",
"$",
"data",
",",
"\\",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"createTable",
"(",
"$",
"output",
")",
";",
"$",
"table",
"->",
"setHeaders",
"(",
"array_map",
"(",
"'trim'",
",",
"$",
"headings",
")",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"row",
")",
"{",
"$",
"rowData",
"=",
"array_merge",
"(",
"array_flip",
"(",
"$",
"keys",
")",
",",
"array_intersect_key",
"(",
"$",
"row",
",",
"array_flip",
"(",
"$",
"keys",
")",
")",
")",
";",
"if",
"(",
"$",
"callback",
")",
"{",
"$",
"rowData",
"=",
"array_map",
"(",
"$",
"callback",
",",
"array_keys",
"(",
"$",
"rowData",
")",
",",
"$",
"rowData",
")",
";",
"}",
"$",
"table",
"->",
"addRow",
"(",
"array_map",
"(",
"'trim'",
",",
"$",
"rowData",
")",
")",
";",
"}",
"$",
"table",
"->",
"render",
"(",
"$",
"output",
")",
";",
"}"
]
| prints a table, values can be modified via $callback.
@param OutputInterface $output
@param string[] $headings
@param string[] $keys
@param array|Pager $data
@param \Closure $callback | [
"prints",
"a",
"table",
"values",
"can",
"be",
"modified",
"via",
"$callback",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/BaseOutput.php#L26-L41 |
digitalkaoz/versioneye-php | src/Output/BaseOutput.php | BaseOutput.printBoolean | protected function printBoolean(OutputInterface $output, $success, $fail, $value, $line = true)
{
if ($value) {
$message = '<info>' . $success . '</info>';
} else {
$message = '<error>' . $fail . '</error>';
}
if (false === $line) {
return $message;
}
$output->writeln($message);
} | php | protected function printBoolean(OutputInterface $output, $success, $fail, $value, $line = true)
{
if ($value) {
$message = '<info>' . $success . '</info>';
} else {
$message = '<error>' . $fail . '</error>';
}
if (false === $line) {
return $message;
}
$output->writeln($message);
} | [
"protected",
"function",
"printBoolean",
"(",
"OutputInterface",
"$",
"output",
",",
"$",
"success",
",",
"$",
"fail",
",",
"$",
"value",
",",
"$",
"line",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"message",
"=",
"'<info>'",
".",
"$",
"success",
".",
"'</info>'",
";",
"}",
"else",
"{",
"$",
"message",
"=",
"'<error>'",
".",
"$",
"fail",
".",
"'</error>'",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"line",
")",
"{",
"return",
"$",
"message",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"$",
"message",
")",
";",
"}"
]
| prints a simple boolean.
@param OutputInterface $output
@param string $success
@param string $fail
@param bool $value
@param bool $line
@return string | [
"prints",
"a",
"simple",
"boolean",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/BaseOutput.php#L54-L67 |
digitalkaoz/versioneye-php | src/Output/BaseOutput.php | BaseOutput.printList | protected function printList(OutputInterface $output, array $headings, array $keys, array $data, \Closure $callback = null)
{
$width = $this->getColumnWidth($headings);
$data = array_merge(array_flip($keys), array_intersect_key($data, array_flip($keys)));
foreach ($headings as $key => $heading) {
$value = array_values($data)[$key];
if ($callback) {
$value = $callback($heading, $value);
}
$value = is_bool($value) ? (true === $value ? 'Yes' : 'No') : $value;
$output->writeln(sprintf('<comment>%s%s</comment> : <info>%s</info>', $heading, str_repeat(' ', $width - strlen($heading)), $value));
}
} | php | protected function printList(OutputInterface $output, array $headings, array $keys, array $data, \Closure $callback = null)
{
$width = $this->getColumnWidth($headings);
$data = array_merge(array_flip($keys), array_intersect_key($data, array_flip($keys)));
foreach ($headings as $key => $heading) {
$value = array_values($data)[$key];
if ($callback) {
$value = $callback($heading, $value);
}
$value = is_bool($value) ? (true === $value ? 'Yes' : 'No') : $value;
$output->writeln(sprintf('<comment>%s%s</comment> : <info>%s</info>', $heading, str_repeat(' ', $width - strlen($heading)), $value));
}
} | [
"protected",
"function",
"printList",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"headings",
",",
"array",
"$",
"keys",
",",
"array",
"$",
"data",
",",
"\\",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"width",
"=",
"$",
"this",
"->",
"getColumnWidth",
"(",
"$",
"headings",
")",
";",
"$",
"data",
"=",
"array_merge",
"(",
"array_flip",
"(",
"$",
"keys",
")",
",",
"array_intersect_key",
"(",
"$",
"data",
",",
"array_flip",
"(",
"$",
"keys",
")",
")",
")",
";",
"foreach",
"(",
"$",
"headings",
"as",
"$",
"key",
"=>",
"$",
"heading",
")",
"{",
"$",
"value",
"=",
"array_values",
"(",
"$",
"data",
")",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"callback",
")",
"{",
"$",
"value",
"=",
"$",
"callback",
"(",
"$",
"heading",
",",
"$",
"value",
")",
";",
"}",
"$",
"value",
"=",
"is_bool",
"(",
"$",
"value",
")",
"?",
"(",
"true",
"===",
"$",
"value",
"?",
"'Yes'",
":",
"'No'",
")",
":",
"$",
"value",
";",
"$",
"output",
"->",
"writeln",
"(",
"sprintf",
"(",
"'<comment>%s%s</comment> : <info>%s</info>'",
",",
"$",
"heading",
",",
"str_repeat",
"(",
"' '",
",",
"$",
"width",
"-",
"strlen",
"(",
"$",
"heading",
")",
")",
",",
"$",
"value",
")",
")",
";",
"}",
"}"
]
| prints a list combined as <comment>Heading</comment> : <info>Value</info>, values can be modified via $callback.
@param OutputInterface $output
@param string[] $headings
@param string[] $keys
@param array $data
@param \Closure $callback | [
"prints",
"a",
"list",
"combined",
"as",
"<comment",
">",
"Heading<",
"/",
"comment",
">",
":",
"<info",
">",
"Value<",
"/",
"info",
">",
"values",
"can",
"be",
"modified",
"via",
"$callback",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/BaseOutput.php#L78-L92 |
digitalkaoz/versioneye-php | src/Output/BaseOutput.php | BaseOutput.printMessage | protected function printMessage(OutputInterface $output, array $response)
{
$this->printBoolean($output, $response['message'], $response['message'], true === $response['success']);
} | php | protected function printMessage(OutputInterface $output, array $response)
{
$this->printBoolean($output, $response['message'], $response['message'], true === $response['success']);
} | [
"protected",
"function",
"printMessage",
"(",
"OutputInterface",
"$",
"output",
",",
"array",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"printBoolean",
"(",
"$",
"output",
",",
"$",
"response",
"[",
"'message'",
"]",
",",
"$",
"response",
"[",
"'message'",
"]",
",",
"true",
"===",
"$",
"response",
"[",
"'success'",
"]",
")",
";",
"}"
]
| prints a simple message.
@param OutputInterface $output
@param array $response | [
"prints",
"a",
"simple",
"message",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/BaseOutput.php#L115-L118 |
digitalkaoz/versioneye-php | src/Output/BaseOutput.php | BaseOutput.getColumnWidth | private function getColumnWidth(array $headings)
{
$width = 0;
foreach ($headings as $heading) {
$width = strlen($heading) > $width ? strlen($heading) : $width;
}
return $width + 5;
} | php | private function getColumnWidth(array $headings)
{
$width = 0;
foreach ($headings as $heading) {
$width = strlen($heading) > $width ? strlen($heading) : $width;
}
return $width + 5;
} | [
"private",
"function",
"getColumnWidth",
"(",
"array",
"$",
"headings",
")",
"{",
"$",
"width",
"=",
"0",
";",
"foreach",
"(",
"$",
"headings",
"as",
"$",
"heading",
")",
"{",
"$",
"width",
"=",
"strlen",
"(",
"$",
"heading",
")",
">",
"$",
"width",
"?",
"strlen",
"(",
"$",
"heading",
")",
":",
"$",
"width",
";",
"}",
"return",
"$",
"width",
"+",
"5",
";",
"}"
]
| calculates the max width of a given set of string.
@param string[] $headings
@return int | [
"calculates",
"the",
"max",
"width",
"of",
"a",
"given",
"set",
"of",
"string",
"."
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/BaseOutput.php#L127-L135 |
digitalkaoz/versioneye-php | src/Output/BaseOutput.php | BaseOutput.createTable | protected function createTable(OutputInterface $output)
{
if (!class_exists('Symfony\Component\Console\Helper\Table')) {
$table = new TableHelper(false);
} else {
$table = new Table($output);
}
return $table;
} | php | protected function createTable(OutputInterface $output)
{
if (!class_exists('Symfony\Component\Console\Helper\Table')) {
$table = new TableHelper(false);
} else {
$table = new Table($output);
}
return $table;
} | [
"protected",
"function",
"createTable",
"(",
"OutputInterface",
"$",
"output",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"'Symfony\\Component\\Console\\Helper\\Table'",
")",
")",
"{",
"$",
"table",
"=",
"new",
"TableHelper",
"(",
"false",
")",
";",
"}",
"else",
"{",
"$",
"table",
"=",
"new",
"Table",
"(",
"$",
"output",
")",
";",
"}",
"return",
"$",
"table",
";",
"}"
]
| @param OutputInterface $output
@return Table|TableHelper | [
"@param",
"OutputInterface",
"$output"
]
| train | https://github.com/digitalkaoz/versioneye-php/blob/7b8eb9cdc83e01138dda0e709c07e3beb6aad136/src/Output/BaseOutput.php#L142-L151 |
orzcc/autometa | src/AutoMeta/AutoMeta.php | AutoMeta.generate | public function generate()
{
$this->loadWebMasterTags();
$title = $this->getTitle();
$description = $this->getDescription();
$keywords = $this->getKeywords();
$metatags = $this->metatags;
$html = [];
if($title):
$html[] = "<title>$title</title>";
endif;
if(!empty($description)):
$html[] = "<meta name=\"description\" content=\"{$description}\" />";
endif;
if (!empty($keywords)):
$keywords = implode(',', $keywords);
$html[] = "<meta name=\"keywords\" content=\"{$keywords}\" />";
endif;
foreach ($metatags as $key => $value):
$name = $value[0];
$content = $value[1];
$html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\" />";
endforeach;
return implode(PHP_EOL, $html);
} | php | public function generate()
{
$this->loadWebMasterTags();
$title = $this->getTitle();
$description = $this->getDescription();
$keywords = $this->getKeywords();
$metatags = $this->metatags;
$html = [];
if($title):
$html[] = "<title>$title</title>";
endif;
if(!empty($description)):
$html[] = "<meta name=\"description\" content=\"{$description}\" />";
endif;
if (!empty($keywords)):
$keywords = implode(',', $keywords);
$html[] = "<meta name=\"keywords\" content=\"{$keywords}\" />";
endif;
foreach ($metatags as $key => $value):
$name = $value[0];
$content = $value[1];
$html[] = "<meta {$name}=\"{$key}\" content=\"{$content}\" />";
endforeach;
return implode(PHP_EOL, $html);
} | [
"public",
"function",
"generate",
"(",
")",
"{",
"$",
"this",
"->",
"loadWebMasterTags",
"(",
")",
";",
"$",
"title",
"=",
"$",
"this",
"->",
"getTitle",
"(",
")",
";",
"$",
"description",
"=",
"$",
"this",
"->",
"getDescription",
"(",
")",
";",
"$",
"keywords",
"=",
"$",
"this",
"->",
"getKeywords",
"(",
")",
";",
"$",
"metatags",
"=",
"$",
"this",
"->",
"metatags",
";",
"$",
"html",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"title",
")",
":",
"$",
"html",
"[",
"]",
"=",
"\"<title>$title</title>\"",
";",
"endif",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"description",
")",
")",
":",
"$",
"html",
"[",
"]",
"=",
"\"<meta name=\\\"description\\\" content=\\\"{$description}\\\" />\"",
";",
"endif",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"keywords",
")",
")",
":",
"$",
"keywords",
"=",
"implode",
"(",
"','",
",",
"$",
"keywords",
")",
";",
"$",
"html",
"[",
"]",
"=",
"\"<meta name=\\\"keywords\\\" content=\\\"{$keywords}\\\" />\"",
";",
"endif",
";",
"foreach",
"(",
"$",
"metatags",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
":",
"$",
"name",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"$",
"content",
"=",
"$",
"value",
"[",
"1",
"]",
";",
"$",
"html",
"[",
"]",
"=",
"\"<meta {$name}=\\\"{$key}\\\" content=\\\"{$content}\\\" />\"",
";",
"endforeach",
";",
"return",
"implode",
"(",
"PHP_EOL",
",",
"$",
"html",
")",
";",
"}"
]
| Generates meta tags
@return string | [
"Generates",
"meta",
"tags"
]
| train | https://github.com/orzcc/autometa/blob/1e3bd93f364e2619c9c20820399735c9fe805c9c/src/AutoMeta/AutoMeta.php#L81-L112 |
orzcc/autometa | src/AutoMeta/AutoMeta.php | AutoMeta.setTitle | public function setTitle($title, $suffix='', $has_suffix=true)
{
// clean title
$title = strip_tags($title);
$suffix = strip_tags($suffix);
// store title session
$this->title_session = $title;
// store title
$this->title = $this->parseTitle($title, $suffix, $has_suffix);
return $this;
} | php | public function setTitle($title, $suffix='', $has_suffix=true)
{
// clean title
$title = strip_tags($title);
$suffix = strip_tags($suffix);
// store title session
$this->title_session = $title;
// store title
$this->title = $this->parseTitle($title, $suffix, $has_suffix);
return $this;
} | [
"public",
"function",
"setTitle",
"(",
"$",
"title",
",",
"$",
"suffix",
"=",
"''",
",",
"$",
"has_suffix",
"=",
"true",
")",
"{",
"// clean title",
"$",
"title",
"=",
"strip_tags",
"(",
"$",
"title",
")",
";",
"$",
"suffix",
"=",
"strip_tags",
"(",
"$",
"suffix",
")",
";",
"// store title session",
"$",
"this",
"->",
"title_session",
"=",
"$",
"title",
";",
"// store title",
"$",
"this",
"->",
"title",
"=",
"$",
"this",
"->",
"parseTitle",
"(",
"$",
"title",
",",
"$",
"suffix",
",",
"$",
"has_suffix",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Sets the title
@param string $title
@param string $suffix
@param boolean $has_suffix
@return MetaTagsContract | [
"Sets",
"the",
"title"
]
| train | https://github.com/orzcc/autometa/blob/1e3bd93f364e2619c9c20820399735c9fe805c9c/src/AutoMeta/AutoMeta.php#L123-L136 |
orzcc/autometa | src/AutoMeta/AutoMeta.php | AutoMeta.setKeywords | public function setKeywords($keywords)
{
if (!is_array($keywords)):
$keywords = explode(', ', $this->keywords);
endif;
// clean keywords
$keywords = array_map('strip_tags', $keywords);
// store keywords
$this->keywords = $keywords;
return $this;
} | php | public function setKeywords($keywords)
{
if (!is_array($keywords)):
$keywords = explode(', ', $this->keywords);
endif;
// clean keywords
$keywords = array_map('strip_tags', $keywords);
// store keywords
$this->keywords = $keywords;
return $this;
} | [
"public",
"function",
"setKeywords",
"(",
"$",
"keywords",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"keywords",
")",
")",
":",
"$",
"keywords",
"=",
"explode",
"(",
"', '",
",",
"$",
"this",
"->",
"keywords",
")",
";",
"endif",
";",
"// clean keywords",
"$",
"keywords",
"=",
"array_map",
"(",
"'strip_tags'",
",",
"$",
"keywords",
")",
";",
"// store keywords",
"$",
"this",
"->",
"keywords",
"=",
"$",
"keywords",
";",
"return",
"$",
"this",
";",
"}"
]
| Sets the list of keywords, you can send an array or string separated with commas
also clears the previously set keywords
@param string|array $keywords
@return MetaTagsContract | [
"Sets",
"the",
"list",
"of",
"keywords",
"you",
"can",
"send",
"an",
"array",
"or",
"string",
"separated",
"with",
"commas",
"also",
"clears",
"the",
"previously",
"set",
"keywords"
]
| train | https://github.com/orzcc/autometa/blob/1e3bd93f364e2619c9c20820399735c9fe805c9c/src/AutoMeta/AutoMeta.php#L174-L188 |
orzcc/autometa | src/AutoMeta/AutoMeta.php | AutoMeta.addKeyword | public function addKeyword($keyword)
{
if (is_array($keyword)):
$this->keywords = array_merge($keyword, $this->keywords);
else:
$this->keywords[] = strip_tags($keyword);
endif;
return $this;
} | php | public function addKeyword($keyword)
{
if (is_array($keyword)):
$this->keywords = array_merge($keyword, $this->keywords);
else:
$this->keywords[] = strip_tags($keyword);
endif;
return $this;
} | [
"public",
"function",
"addKeyword",
"(",
"$",
"keyword",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"keyword",
")",
")",
":",
"$",
"this",
"->",
"keywords",
"=",
"array_merge",
"(",
"$",
"keyword",
",",
"$",
"this",
"->",
"keywords",
")",
";",
"else",
":",
"$",
"this",
"->",
"keywords",
"[",
"]",
"=",
"strip_tags",
"(",
"$",
"keyword",
")",
";",
"endif",
";",
"return",
"$",
"this",
";",
"}"
]
| Add a keyword
@param string|array $keyword
@return MetaTagsContract | [
"Add",
"a",
"keyword"
]
| train | https://github.com/orzcc/autometa/blob/1e3bd93f364e2619c9c20820399735c9fe805c9c/src/AutoMeta/AutoMeta.php#L197-L206 |
orzcc/autometa | src/AutoMeta/AutoMeta.php | AutoMeta.reset | public function reset()
{
$this->description = null;
$this->title_session = null;
$this->metatags = [];
$this->keywords = [];
} | php | public function reset()
{
$this->description = null;
$this->title_session = null;
$this->metatags = [];
$this->keywords = [];
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"description",
"=",
"null",
";",
"$",
"this",
"->",
"title_session",
"=",
"null",
";",
"$",
"this",
"->",
"metatags",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"keywords",
"=",
"[",
"]",
";",
"}"
]
| Reset all data.
@return void | [
"Reset",
"all",
"data",
"."
]
| train | https://github.com/orzcc/autometa/blob/1e3bd93f364e2619c9c20820399735c9fe805c9c/src/AutoMeta/AutoMeta.php#L283-L289 |
orzcc/autometa | src/AutoMeta/AutoMeta.php | AutoMeta.parseTitle | protected function parseTitle($title, $suffix, $has_suffix)
{
if (!$has_suffix):
return $title;
elseif(!empty($suffix)):
return $title . $this->getTitleSeperator() . $suffix;
else:
return $this->config->get('defaults.title') ? $title . $this->getTitleSeperator() . $this->config->get('defaults.title', null) : $title;
endif;
} | php | protected function parseTitle($title, $suffix, $has_suffix)
{
if (!$has_suffix):
return $title;
elseif(!empty($suffix)):
return $title . $this->getTitleSeperator() . $suffix;
else:
return $this->config->get('defaults.title') ? $title . $this->getTitleSeperator() . $this->config->get('defaults.title', null) : $title;
endif;
} | [
"protected",
"function",
"parseTitle",
"(",
"$",
"title",
",",
"$",
"suffix",
",",
"$",
"has_suffix",
")",
"{",
"if",
"(",
"!",
"$",
"has_suffix",
")",
":",
"return",
"$",
"title",
";",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"suffix",
")",
")",
":",
"return",
"$",
"title",
".",
"$",
"this",
"->",
"getTitleSeperator",
"(",
")",
".",
"$",
"suffix",
";",
"else",
":",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'defaults.title'",
")",
"?",
"$",
"title",
".",
"$",
"this",
"->",
"getTitleSeperator",
"(",
")",
".",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"'defaults.title'",
",",
"null",
")",
":",
"$",
"title",
";",
"endif",
";",
"}"
]
| Get parsed title.
@param string $title
@param string @suffix
@return string | [
"Get",
"parsed",
"title",
"."
]
| train | https://github.com/orzcc/autometa/blob/1e3bd93f364e2619c9c20820399735c9fe805c9c/src/AutoMeta/AutoMeta.php#L299-L308 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBOGeneratorBundle/Datatable/Data/DatatableDataManager.php | DatatableDataManager.getDatatable | public function getDatatable(DatatableViewInterface $datatableView)
{
$type = $datatableView->getAjax()->getType();
$entity = $datatableView->getEntity();
if ('GET' === strtoupper($type)) {
$this->parameterBag = $this->request->query;
}
if ('POST' === strtoupper($type)) {
$this->parameterBag = $this->request->request;
}
$params = $this->parameterBag->all();
/**
* @var \Doctrine\ORM\Mapping\ClassMetadata
*/
$metadata = $this->doctrine->getManager()->getClassMetadata($entity);
/**
* @var \Doctrine\ORM\EntityManager
*/
$em = $this->doctrine->getManager();
$datatableQuery = new DatatableQuery($params, $metadata, $em);
$virtualColumns = $datatableView->getColumnBuilder()->getVirtualColumnNames();
$datatableData = new DatatableData($params, $metadata, $em, $this->serializer, $datatableQuery, $virtualColumns);
$datatableData->setLineFormatter($datatableView->getLineFormatter());
return $datatableData;
} | php | public function getDatatable(DatatableViewInterface $datatableView)
{
$type = $datatableView->getAjax()->getType();
$entity = $datatableView->getEntity();
if ('GET' === strtoupper($type)) {
$this->parameterBag = $this->request->query;
}
if ('POST' === strtoupper($type)) {
$this->parameterBag = $this->request->request;
}
$params = $this->parameterBag->all();
/**
* @var \Doctrine\ORM\Mapping\ClassMetadata
*/
$metadata = $this->doctrine->getManager()->getClassMetadata($entity);
/**
* @var \Doctrine\ORM\EntityManager
*/
$em = $this->doctrine->getManager();
$datatableQuery = new DatatableQuery($params, $metadata, $em);
$virtualColumns = $datatableView->getColumnBuilder()->getVirtualColumnNames();
$datatableData = new DatatableData($params, $metadata, $em, $this->serializer, $datatableQuery, $virtualColumns);
$datatableData->setLineFormatter($datatableView->getLineFormatter());
return $datatableData;
} | [
"public",
"function",
"getDatatable",
"(",
"DatatableViewInterface",
"$",
"datatableView",
")",
"{",
"$",
"type",
"=",
"$",
"datatableView",
"->",
"getAjax",
"(",
")",
"->",
"getType",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"datatableView",
"->",
"getEntity",
"(",
")",
";",
"if",
"(",
"'GET'",
"===",
"strtoupper",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"parameterBag",
"=",
"$",
"this",
"->",
"request",
"->",
"query",
";",
"}",
"if",
"(",
"'POST'",
"===",
"strtoupper",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"parameterBag",
"=",
"$",
"this",
"->",
"request",
"->",
"request",
";",
"}",
"$",
"params",
"=",
"$",
"this",
"->",
"parameterBag",
"->",
"all",
"(",
")",
";",
"/**\n * @var \\Doctrine\\ORM\\Mapping\\ClassMetadata\n */",
"$",
"metadata",
"=",
"$",
"this",
"->",
"doctrine",
"->",
"getManager",
"(",
")",
"->",
"getClassMetadata",
"(",
"$",
"entity",
")",
";",
"/**\n * @var \\Doctrine\\ORM\\EntityManager\n */",
"$",
"em",
"=",
"$",
"this",
"->",
"doctrine",
"->",
"getManager",
"(",
")",
";",
"$",
"datatableQuery",
"=",
"new",
"DatatableQuery",
"(",
"$",
"params",
",",
"$",
"metadata",
",",
"$",
"em",
")",
";",
"$",
"virtualColumns",
"=",
"$",
"datatableView",
"->",
"getColumnBuilder",
"(",
")",
"->",
"getVirtualColumnNames",
"(",
")",
";",
"$",
"datatableData",
"=",
"new",
"DatatableData",
"(",
"$",
"params",
",",
"$",
"metadata",
",",
"$",
"em",
",",
"$",
"this",
"->",
"serializer",
",",
"$",
"datatableQuery",
",",
"$",
"virtualColumns",
")",
";",
"$",
"datatableData",
"->",
"setLineFormatter",
"(",
"$",
"datatableView",
"->",
"getLineFormatter",
"(",
")",
")",
";",
"return",
"$",
"datatableData",
";",
"}"
]
| Get Datatable.
@param DatatableViewInterface $datatableView
@return DatatableData | [
"Get",
"Datatable",
"."
]
| train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBOGeneratorBundle/Datatable/Data/DatatableDataManager.php#L80-L111 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.normalize | public function normalize($object, $format = null, array $context = array())
{
$context['depth'] = isset($context['depth']) ? $context['depth']+1 : 0;
if (!isset($context['@references'])) {
$references = array();
$context['@references'] = &$references;
}
if (!isset($context['cache_key'])) {
$context['cache_key'] = md5(serialize($context));
}
$class = get_class($object);
/* @var ClassMetadata $meta */
$context['entityMeta'] = $this->entityMetadataFactory->getMetadataFor($class);
$data = array();
$attributes = $this->getAttributes($object, $format, $context);
foreach ($attributes as $attribute) {
$value = $this->getAttributeValue($object, $attribute, $format, $context);
$data[$attribute] = $this->normalizeProperty($value, $attribute, $format, $context);
}
$hint = $this->getHintFromObject($object);
if ($context['depth'] === 0 and !empty($context['@references'])) {
$ids = $this->getIdentifierFromObject($object);
$id = $this->getIdentifiersAsString($ids);
$objectId = current($hint).'#'.$id;
unset($context['@references'][$objectId]);
ksort($context['@references']);
$data['@references'] = array_filter($context['@references']);
}
return array_merge($hint, $data);
} | php | public function normalize($object, $format = null, array $context = array())
{
$context['depth'] = isset($context['depth']) ? $context['depth']+1 : 0;
if (!isset($context['@references'])) {
$references = array();
$context['@references'] = &$references;
}
if (!isset($context['cache_key'])) {
$context['cache_key'] = md5(serialize($context));
}
$class = get_class($object);
/* @var ClassMetadata $meta */
$context['entityMeta'] = $this->entityMetadataFactory->getMetadataFor($class);
$data = array();
$attributes = $this->getAttributes($object, $format, $context);
foreach ($attributes as $attribute) {
$value = $this->getAttributeValue($object, $attribute, $format, $context);
$data[$attribute] = $this->normalizeProperty($value, $attribute, $format, $context);
}
$hint = $this->getHintFromObject($object);
if ($context['depth'] === 0 and !empty($context['@references'])) {
$ids = $this->getIdentifierFromObject($object);
$id = $this->getIdentifiersAsString($ids);
$objectId = current($hint).'#'.$id;
unset($context['@references'][$objectId]);
ksort($context['@references']);
$data['@references'] = array_filter($context['@references']);
}
return array_merge($hint, $data);
} | [
"public",
"function",
"normalize",
"(",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"context",
"[",
"'depth'",
"]",
"=",
"isset",
"(",
"$",
"context",
"[",
"'depth'",
"]",
")",
"?",
"$",
"context",
"[",
"'depth'",
"]",
"+",
"1",
":",
"0",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"[",
"'@references'",
"]",
")",
")",
"{",
"$",
"references",
"=",
"array",
"(",
")",
";",
"$",
"context",
"[",
"'@references'",
"]",
"=",
"&",
"$",
"references",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"[",
"'cache_key'",
"]",
")",
")",
"{",
"$",
"context",
"[",
"'cache_key'",
"]",
"=",
"md5",
"(",
"serialize",
"(",
"$",
"context",
")",
")",
";",
"}",
"$",
"class",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"/* @var ClassMetadata $meta */",
"$",
"context",
"[",
"'entityMeta'",
"]",
"=",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"$",
"object",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getAttributeValue",
"(",
"$",
"object",
",",
"$",
"attribute",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"$",
"data",
"[",
"$",
"attribute",
"]",
"=",
"$",
"this",
"->",
"normalizeProperty",
"(",
"$",
"value",
",",
"$",
"attribute",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"$",
"hint",
"=",
"$",
"this",
"->",
"getHintFromObject",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"context",
"[",
"'depth'",
"]",
"===",
"0",
"and",
"!",
"empty",
"(",
"$",
"context",
"[",
"'@references'",
"]",
")",
")",
"{",
"$",
"ids",
"=",
"$",
"this",
"->",
"getIdentifierFromObject",
"(",
"$",
"object",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"getIdentifiersAsString",
"(",
"$",
"ids",
")",
";",
"$",
"objectId",
"=",
"current",
"(",
"$",
"hint",
")",
".",
"'#'",
".",
"$",
"id",
";",
"unset",
"(",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
")",
";",
"ksort",
"(",
"$",
"context",
"[",
"'@references'",
"]",
")",
";",
"$",
"data",
"[",
"'@references'",
"]",
"=",
"array_filter",
"(",
"$",
"context",
"[",
"'@references'",
"]",
")",
";",
"}",
"return",
"array_merge",
"(",
"$",
"hint",
",",
"$",
"data",
")",
";",
"}"
]
| @param object $object
@param string $format
@param array $context
@return array | [
"@param",
"object",
"$object",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L51-L92 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.normalizeProperty | protected function normalizeProperty($value, $name, $format = null, array $context = array())
{
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
if ($meta->hasField($name)) {
return $value;
}
if (isset($meta->embeddedClasses[$name])) {
return parent::normalize($value, $format, $context);
}
switch ($meta->associationMappings[$name]['type']) {
case ClassMetadata::ONE_TO_ONE:
case ClassMetadata::MANY_TO_ONE:
return $this->normalizeAssociation($value, $name, $format, $context);
case ClassMetadata::ONE_TO_MANY:
case ClassMetadata::MANY_TO_MANY:
return $this->normalizeCollection($value, $name, $format, $context);
}
} | php | protected function normalizeProperty($value, $name, $format = null, array $context = array())
{
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
if ($meta->hasField($name)) {
return $value;
}
if (isset($meta->embeddedClasses[$name])) {
return parent::normalize($value, $format, $context);
}
switch ($meta->associationMappings[$name]['type']) {
case ClassMetadata::ONE_TO_ONE:
case ClassMetadata::MANY_TO_ONE:
return $this->normalizeAssociation($value, $name, $format, $context);
case ClassMetadata::ONE_TO_MANY:
case ClassMetadata::MANY_TO_MANY:
return $this->normalizeCollection($value, $name, $format, $context);
}
} | [
"protected",
"function",
"normalizeProperty",
"(",
"$",
"value",
",",
"$",
"name",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"/** @var ClassMetadata $meta */",
"$",
"meta",
"=",
"$",
"context",
"[",
"'entityMeta'",
"]",
";",
"if",
"(",
"$",
"meta",
"->",
"hasField",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"embeddedClasses",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"parent",
"::",
"normalize",
"(",
"$",
"value",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"switch",
"(",
"$",
"meta",
"->",
"associationMappings",
"[",
"$",
"name",
"]",
"[",
"'type'",
"]",
")",
"{",
"case",
"ClassMetadata",
"::",
"ONE_TO_ONE",
":",
"case",
"ClassMetadata",
"::",
"MANY_TO_ONE",
":",
"return",
"$",
"this",
"->",
"normalizeAssociation",
"(",
"$",
"value",
",",
"$",
"name",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"case",
"ClassMetadata",
"::",
"ONE_TO_MANY",
":",
"case",
"ClassMetadata",
"::",
"MANY_TO_MANY",
":",
"return",
"$",
"this",
"->",
"normalizeCollection",
"(",
"$",
"value",
",",
"$",
"name",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"}"
]
| @param object $value
@param string $name
@param string $format
@param array $context
@return mixed|object | [
"@param",
"object",
"$value",
"@param",
"string",
"$name",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L102-L124 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.normalizeAssociation | protected function normalizeAssociation($association, $name, $format = null, array $context = array())
{
if ($association === null) {
return;
}
$hint = $this->getHintFromObject($association);
$ids = $this->getIdentifierFromObject($association);
$id = $this->getIdentifiersAsString($ids);
$data = array_merge($hint, $ids);
$objectId = current($hint).'#'.$id;
if (isset($context['@references'][$objectId])) {
return $data;
}
$context['@references'][$objectId] = false;
if ($association instanceof Proxy and !$association->__isInitialized()) {
return $data;
}
$normalized = $this->serializer->normalize($association, $format, $context);
$context['@references'][$objectId] = $normalized;
return $data;
} | php | protected function normalizeAssociation($association, $name, $format = null, array $context = array())
{
if ($association === null) {
return;
}
$hint = $this->getHintFromObject($association);
$ids = $this->getIdentifierFromObject($association);
$id = $this->getIdentifiersAsString($ids);
$data = array_merge($hint, $ids);
$objectId = current($hint).'#'.$id;
if (isset($context['@references'][$objectId])) {
return $data;
}
$context['@references'][$objectId] = false;
if ($association instanceof Proxy and !$association->__isInitialized()) {
return $data;
}
$normalized = $this->serializer->normalize($association, $format, $context);
$context['@references'][$objectId] = $normalized;
return $data;
} | [
"protected",
"function",
"normalizeAssociation",
"(",
"$",
"association",
",",
"$",
"name",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"association",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"hint",
"=",
"$",
"this",
"->",
"getHintFromObject",
"(",
"$",
"association",
")",
";",
"$",
"ids",
"=",
"$",
"this",
"->",
"getIdentifierFromObject",
"(",
"$",
"association",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"getIdentifiersAsString",
"(",
"$",
"ids",
")",
";",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"hint",
",",
"$",
"ids",
")",
";",
"$",
"objectId",
"=",
"current",
"(",
"$",
"hint",
")",
".",
"'#'",
".",
"$",
"id",
";",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
"=",
"false",
";",
"if",
"(",
"$",
"association",
"instanceof",
"Proxy",
"and",
"!",
"$",
"association",
"->",
"__isInitialized",
"(",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"normalized",
"=",
"$",
"this",
"->",
"serializer",
"->",
"normalize",
"(",
"$",
"association",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
"=",
"$",
"normalized",
";",
"return",
"$",
"data",
";",
"}"
]
| @param object $association
@param string $name
@param string $format
@param array $context
@return array | [
"@param",
"object",
"$association",
"@param",
"string",
"$name",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L134-L160 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.normalizeCollection | protected function normalizeCollection($collection, $name, $format = null, array $context = array())
{
if (empty($collection)) {
return array();
}
if ($collection instanceof AbstractLazyCollection and !$collection->isInitialized()) {
return array();
}
$data = array();
foreach ($collection as $key => $element) {
$data[$key] = $this->normalizeAssociation($element, $name, $format, $context);
}
return $data;
} | php | protected function normalizeCollection($collection, $name, $format = null, array $context = array())
{
if (empty($collection)) {
return array();
}
if ($collection instanceof AbstractLazyCollection and !$collection->isInitialized()) {
return array();
}
$data = array();
foreach ($collection as $key => $element) {
$data[$key] = $this->normalizeAssociation($element, $name, $format, $context);
}
return $data;
} | [
"protected",
"function",
"normalizeCollection",
"(",
"$",
"collection",
",",
"$",
"name",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"collection",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"collection",
"instanceof",
"AbstractLazyCollection",
"and",
"!",
"$",
"collection",
"->",
"isInitialized",
"(",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"key",
"=>",
"$",
"element",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"normalizeAssociation",
"(",
"$",
"element",
",",
"$",
"name",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
]
| @param object $collection
@param string $name
@param string $format
@param array $context
@return array | [
"@param",
"object",
"$collection",
"@param",
"string",
"$name",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L170-L186 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.getAttributes | public function getAttributes($objectOrClass, $format = null, array $context)
{
$class = is_object($objectOrClass) ? get_class($objectOrClass) : $objectOrClass;
/** @var ClassMetadata $meta */
$meta = $this->entityMetadataFactory->getMetadataFor($class);
$fields = array_keys($meta->fieldMappings);
$fields = array_filter($fields, function ($name) { return strpos($name, '.') === false; });
$embedded = array_keys($meta->embeddedClasses);
$associations = array_keys($meta->associationMappings);
return array_merge($fields, $embedded, $associations);
} | php | public function getAttributes($objectOrClass, $format = null, array $context)
{
$class = is_object($objectOrClass) ? get_class($objectOrClass) : $objectOrClass;
/** @var ClassMetadata $meta */
$meta = $this->entityMetadataFactory->getMetadataFor($class);
$fields = array_keys($meta->fieldMappings);
$fields = array_filter($fields, function ($name) { return strpos($name, '.') === false; });
$embedded = array_keys($meta->embeddedClasses);
$associations = array_keys($meta->associationMappings);
return array_merge($fields, $embedded, $associations);
} | [
"public",
"function",
"getAttributes",
"(",
"$",
"objectOrClass",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
")",
"{",
"$",
"class",
"=",
"is_object",
"(",
"$",
"objectOrClass",
")",
"?",
"get_class",
"(",
"$",
"objectOrClass",
")",
":",
"$",
"objectOrClass",
";",
"/** @var ClassMetadata $meta */",
"$",
"meta",
"=",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
";",
"$",
"fields",
"=",
"array_keys",
"(",
"$",
"meta",
"->",
"fieldMappings",
")",
";",
"$",
"fields",
"=",
"array_filter",
"(",
"$",
"fields",
",",
"function",
"(",
"$",
"name",
")",
"{",
"return",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
"===",
"false",
";",
"}",
")",
";",
"$",
"embedded",
"=",
"array_keys",
"(",
"$",
"meta",
"->",
"embeddedClasses",
")",
";",
"$",
"associations",
"=",
"array_keys",
"(",
"$",
"meta",
"->",
"associationMappings",
")",
";",
"return",
"array_merge",
"(",
"$",
"fields",
",",
"$",
"embedded",
",",
"$",
"associations",
")",
";",
"}"
]
| @param object|string $objectOrClass
@param string $format
@param array $context
@return array | [
"@param",
"object|string",
"$objectOrClass",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L195-L208 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.supportsNormalization | public function supportsNormalization($data, $format = null)
{
if (!is_object($data)) {
return false;
}
$class = get_class($data);
if (!$this->entityMetadataFactory->hasMetadataFor($class)
or $this->entityMetadataFactory->getMetadataFor($class)->isEmbeddedClass) {
return false;
}
return parent::supportsNormalization($data, $format);
} | php | public function supportsNormalization($data, $format = null)
{
if (!is_object($data)) {
return false;
}
$class = get_class($data);
if (!$this->entityMetadataFactory->hasMetadataFor($class)
or $this->entityMetadataFactory->getMetadataFor($class)->isEmbeddedClass) {
return false;
}
return parent::supportsNormalization($data, $format);
} | [
"public",
"function",
"supportsNormalization",
"(",
"$",
"data",
",",
"$",
"format",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"class",
"=",
"get_class",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"hasMetadataFor",
"(",
"$",
"class",
")",
"or",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
"->",
"isEmbeddedClass",
")",
"{",
"return",
"false",
";",
"}",
"return",
"parent",
"::",
"supportsNormalization",
"(",
"$",
"data",
",",
"$",
"format",
")",
";",
"}"
]
| @param object $data
@param string $format
@return bool | [
"@param",
"object",
"$data",
"@param",
"string",
"$format"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L216-L229 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.denormalize | public function denormalize($data, $class, $format = null, array $context = array())
{
if (isset($data['@references'])) {
$context['@references'] = &$data['@references'];
$ids = $this->getIdentifierFromArray($class, $data);
$objectId = $class.'#'.$this->getIdentifiersAsString($ids);
$context['@references'][$objectId] = $data;
unset($context['@references'][$objectId]['@references']);
}
if (!isset($context['cache_key'])) {
$context['cache_key'] = md5(serialize($context));
}
$class = $class ?: $this->getClassFromArray($data);
$context['entityMeta'] = $this->entityMetadataFactory->getMetadataFor($class);
$rc = new \ReflectionClass($class);
$object = $this->instantiateObject($data, $class, $context, $rc, false);
return $this->hydrateObject($object, $data, $class, $format, $context);
} | php | public function denormalize($data, $class, $format = null, array $context = array())
{
if (isset($data['@references'])) {
$context['@references'] = &$data['@references'];
$ids = $this->getIdentifierFromArray($class, $data);
$objectId = $class.'#'.$this->getIdentifiersAsString($ids);
$context['@references'][$objectId] = $data;
unset($context['@references'][$objectId]['@references']);
}
if (!isset($context['cache_key'])) {
$context['cache_key'] = md5(serialize($context));
}
$class = $class ?: $this->getClassFromArray($data);
$context['entityMeta'] = $this->entityMetadataFactory->getMetadataFor($class);
$rc = new \ReflectionClass($class);
$object = $this->instantiateObject($data, $class, $context, $rc, false);
return $this->hydrateObject($object, $data, $class, $format, $context);
} | [
"public",
"function",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'@references'",
"]",
")",
")",
"{",
"$",
"context",
"[",
"'@references'",
"]",
"=",
"&",
"$",
"data",
"[",
"'@references'",
"]",
";",
"$",
"ids",
"=",
"$",
"this",
"->",
"getIdentifierFromArray",
"(",
"$",
"class",
",",
"$",
"data",
")",
";",
"$",
"objectId",
"=",
"$",
"class",
".",
"'#'",
".",
"$",
"this",
"->",
"getIdentifiersAsString",
"(",
"$",
"ids",
")",
";",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
"=",
"$",
"data",
";",
"unset",
"(",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
"[",
"'@references'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"[",
"'cache_key'",
"]",
")",
")",
"{",
"$",
"context",
"[",
"'cache_key'",
"]",
"=",
"md5",
"(",
"serialize",
"(",
"$",
"context",
")",
")",
";",
"}",
"$",
"class",
"=",
"$",
"class",
"?",
":",
"$",
"this",
"->",
"getClassFromArray",
"(",
"$",
"data",
")",
";",
"$",
"context",
"[",
"'entityMeta'",
"]",
"=",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
";",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"instantiateObject",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"context",
",",
"$",
"rc",
",",
"false",
")",
";",
"return",
"$",
"this",
"->",
"hydrateObject",
"(",
"$",
"object",
",",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}"
]
| @param array $data
@param string $class
@param string $format
@param array $context
@return object | [
"@param",
"array",
"$data",
"@param",
"string",
"$class",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L239-L260 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.hydrateObject | public function hydrateObject($object, $data, $class, $format, $context)
{
$attributes = $this->getAttributes($class, $format, $context);
foreach ($attributes as $attribute) {
$value = isset($data[$attribute]) ? $data[$attribute] : null;
$value = $this->denormalizeProperty($value, null, $attribute, $format, $context);
$this->setAttributeValue($object, $attribute, $value, $format, $context);
}
return $object;
} | php | public function hydrateObject($object, $data, $class, $format, $context)
{
$attributes = $this->getAttributes($class, $format, $context);
foreach ($attributes as $attribute) {
$value = isset($data[$attribute]) ? $data[$attribute] : null;
$value = $this->denormalizeProperty($value, null, $attribute, $format, $context);
$this->setAttributeValue($object, $attribute, $value, $format, $context);
}
return $object;
} | [
"public",
"function",
"hydrateObject",
"(",
"$",
"object",
",",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
",",
"$",
"context",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
"$",
"class",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"data",
"[",
"$",
"attribute",
"]",
")",
"?",
"$",
"data",
"[",
"$",
"attribute",
"]",
":",
"null",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"denormalizeProperty",
"(",
"$",
"value",
",",
"null",
",",
"$",
"attribute",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"$",
"this",
"->",
"setAttributeValue",
"(",
"$",
"object",
",",
"$",
"attribute",
",",
"$",
"value",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
]
| @param object $object
@param array $data
@param string $class
@param string $format
@param array $context
@return object | [
"@param",
"object",
"$object",
"@param",
"array",
"$data",
"@param",
"string",
"$class",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L271-L282 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.denormalizeProperty | protected function denormalizeProperty($value, $class, $name, $format = null, array $context = array())
{
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
if ($meta->hasField($name)) {
return $value;
}
if (isset($meta->embeddedClasses[$name])) {
return parent::denormalize($value, null, $format, $context);
}
if (!isset($meta->associationMappings[$name])) {
return parent::denormalizeProperty($value, $class, $name, $format, $context);
}
switch ($meta->associationMappings[$name]['type']) {
case ClassMetadata::ONE_TO_ONE:
case ClassMetadata::MANY_TO_ONE:
return $this->denormalizeAssociation($value, null, $name, $format, $context);
case ClassMetadata::ONE_TO_MANY:
case ClassMetadata::MANY_TO_MANY:
return $this->denormalizeCollection($value, null, $name, $format, $context);
}
} | php | protected function denormalizeProperty($value, $class, $name, $format = null, array $context = array())
{
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
if ($meta->hasField($name)) {
return $value;
}
if (isset($meta->embeddedClasses[$name])) {
return parent::denormalize($value, null, $format, $context);
}
if (!isset($meta->associationMappings[$name])) {
return parent::denormalizeProperty($value, $class, $name, $format, $context);
}
switch ($meta->associationMappings[$name]['type']) {
case ClassMetadata::ONE_TO_ONE:
case ClassMetadata::MANY_TO_ONE:
return $this->denormalizeAssociation($value, null, $name, $format, $context);
case ClassMetadata::ONE_TO_MANY:
case ClassMetadata::MANY_TO_MANY:
return $this->denormalizeCollection($value, null, $name, $format, $context);
}
} | [
"protected",
"function",
"denormalizeProperty",
"(",
"$",
"value",
",",
"$",
"class",
",",
"$",
"name",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"/** @var ClassMetadata $meta */",
"$",
"meta",
"=",
"$",
"context",
"[",
"'entityMeta'",
"]",
";",
"if",
"(",
"$",
"meta",
"->",
"hasField",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"meta",
"->",
"embeddedClasses",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"parent",
"::",
"denormalize",
"(",
"$",
"value",
",",
"null",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"meta",
"->",
"associationMappings",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"parent",
"::",
"denormalizeProperty",
"(",
"$",
"value",
",",
"$",
"class",
",",
"$",
"name",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"switch",
"(",
"$",
"meta",
"->",
"associationMappings",
"[",
"$",
"name",
"]",
"[",
"'type'",
"]",
")",
"{",
"case",
"ClassMetadata",
"::",
"ONE_TO_ONE",
":",
"case",
"ClassMetadata",
"::",
"MANY_TO_ONE",
":",
"return",
"$",
"this",
"->",
"denormalizeAssociation",
"(",
"$",
"value",
",",
"null",
",",
"$",
"name",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"case",
"ClassMetadata",
"::",
"ONE_TO_MANY",
":",
"case",
"ClassMetadata",
"::",
"MANY_TO_MANY",
":",
"return",
"$",
"this",
"->",
"denormalizeCollection",
"(",
"$",
"value",
",",
"null",
",",
"$",
"name",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"}"
]
| @param mixed $value
@param string $class
@param string $name
@param string $format
@param array $context
@return mixed|object | [
"@param",
"mixed",
"$value",
"@param",
"string",
"$class",
"@param",
"string",
"$name",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L293-L319 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.denormalizeAssociation | protected function denormalizeAssociation($value, $class, $name, $format = null, array $context = array())
{
if (empty($value)) {
return $value;
}
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
$class = $class ?: $meta->associationMappings[$name]['targetEntity'];
$ids = $this->getIdentifierFromArray($class, $value);
$objectId = $class.'#'.$this->getIdentifiersAsString($ids);
if (!isset($context['@references'][$objectId])) {
return null;
}
if ($context['@references'][$objectId] instanceof $class) {
return $context['@references'][$objectId];
}
$value = $context['@references'][$objectId];
$object = $this->instantiateObject($value, $class, $context, new \ReflectionClass($class), false);
$context['@references'][$objectId] = &$object;
$object = $this->hydrateObject($object, $value, $class, $format, $context);
return $object;
} | php | protected function denormalizeAssociation($value, $class, $name, $format = null, array $context = array())
{
if (empty($value)) {
return $value;
}
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
$class = $class ?: $meta->associationMappings[$name]['targetEntity'];
$ids = $this->getIdentifierFromArray($class, $value);
$objectId = $class.'#'.$this->getIdentifiersAsString($ids);
if (!isset($context['@references'][$objectId])) {
return null;
}
if ($context['@references'][$objectId] instanceof $class) {
return $context['@references'][$objectId];
}
$value = $context['@references'][$objectId];
$object = $this->instantiateObject($value, $class, $context, new \ReflectionClass($class), false);
$context['@references'][$objectId] = &$object;
$object = $this->hydrateObject($object, $value, $class, $format, $context);
return $object;
} | [
"protected",
"function",
"denormalizeAssociation",
"(",
"$",
"value",
",",
"$",
"class",
",",
"$",
"name",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
";",
"}",
"/** @var ClassMetadata $meta */",
"$",
"meta",
"=",
"$",
"context",
"[",
"'entityMeta'",
"]",
";",
"$",
"class",
"=",
"$",
"class",
"?",
":",
"$",
"meta",
"->",
"associationMappings",
"[",
"$",
"name",
"]",
"[",
"'targetEntity'",
"]",
";",
"$",
"ids",
"=",
"$",
"this",
"->",
"getIdentifierFromArray",
"(",
"$",
"class",
",",
"$",
"value",
")",
";",
"$",
"objectId",
"=",
"$",
"class",
".",
"'#'",
".",
"$",
"this",
"->",
"getIdentifiersAsString",
"(",
"$",
"ids",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
"instanceof",
"$",
"class",
")",
"{",
"return",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
";",
"}",
"$",
"value",
"=",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"instantiateObject",
"(",
"$",
"value",
",",
"$",
"class",
",",
"$",
"context",
",",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
",",
"false",
")",
";",
"$",
"context",
"[",
"'@references'",
"]",
"[",
"$",
"objectId",
"]",
"=",
"&",
"$",
"object",
";",
"$",
"object",
"=",
"$",
"this",
"->",
"hydrateObject",
"(",
"$",
"object",
",",
"$",
"value",
",",
"$",
"class",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"return",
"$",
"object",
";",
"}"
]
| @param mixed $value
@param string $class
@param string $name
@param string $format
@param array $context
@return mixed|object | [
"@param",
"mixed",
"$value",
"@param",
"string",
"$class",
"@param",
"string",
"$name",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L330-L356 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.denormalizeCollection | protected function denormalizeCollection($collection, $class, $name, $format = null, array $context = array())
{
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
$targetEntity = $meta->associationMappings[$name]['targetEntity'];
$result = array();
foreach ($collection as $key => $element) {
$class = $class ?: $targetEntity;
$result[$key] = $this->denormalizeAssociation($element, $class, $name, $format, $context);
}
return $result;
} | php | protected function denormalizeCollection($collection, $class, $name, $format = null, array $context = array())
{
/** @var ClassMetadata $meta */
$meta = $context['entityMeta'];
$targetEntity = $meta->associationMappings[$name]['targetEntity'];
$result = array();
foreach ($collection as $key => $element) {
$class = $class ?: $targetEntity;
$result[$key] = $this->denormalizeAssociation($element, $class, $name, $format, $context);
}
return $result;
} | [
"protected",
"function",
"denormalizeCollection",
"(",
"$",
"collection",
",",
"$",
"class",
",",
"$",
"name",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"/** @var ClassMetadata $meta */",
"$",
"meta",
"=",
"$",
"context",
"[",
"'entityMeta'",
"]",
";",
"$",
"targetEntity",
"=",
"$",
"meta",
"->",
"associationMappings",
"[",
"$",
"name",
"]",
"[",
"'targetEntity'",
"]",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"key",
"=>",
"$",
"element",
")",
"{",
"$",
"class",
"=",
"$",
"class",
"?",
":",
"$",
"targetEntity",
";",
"$",
"result",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"denormalizeAssociation",
"(",
"$",
"element",
",",
"$",
"class",
",",
"$",
"name",
",",
"$",
"format",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| @param mixed $collection
@param string $class
@param string $name
@param string $format
@param array $context
@return mixed|object | [
"@param",
"mixed",
"$collection",
"@param",
"string",
"$class",
"@param",
"string",
"$name",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L367-L382 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.supportsDenormalization | public function supportsDenormalization($data, $type, $format = null)
{
$class = $type ?: $this->getClassFromArray($data);
if (!$this->entityMetadataFactory->hasMetadataFor($class)
or $this->entityMetadataFactory->getMetadataFor($class)->isEmbeddedClass) {
return false;
}
return parent::supportsDenormalization($data, $type, $format);
} | php | public function supportsDenormalization($data, $type, $format = null)
{
$class = $type ?: $this->getClassFromArray($data);
if (!$this->entityMetadataFactory->hasMetadataFor($class)
or $this->entityMetadataFactory->getMetadataFor($class)->isEmbeddedClass) {
return false;
}
return parent::supportsDenormalization($data, $type, $format);
} | [
"public",
"function",
"supportsDenormalization",
"(",
"$",
"data",
",",
"$",
"type",
",",
"$",
"format",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"$",
"type",
"?",
":",
"$",
"this",
"->",
"getClassFromArray",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"hasMetadataFor",
"(",
"$",
"class",
")",
"or",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
"->",
"isEmbeddedClass",
")",
"{",
"return",
"false",
";",
"}",
"return",
"parent",
"::",
"supportsDenormalization",
"(",
"$",
"data",
",",
"$",
"type",
",",
"$",
"format",
")",
";",
"}"
]
| @param array $data
@param string $type
@param string $format
@return bool | [
"@param",
"array",
"$data",
"@param",
"string",
"$type",
"@param",
"string",
"$format"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L391-L400 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.getIdentifierFromObject | protected function getIdentifierFromObject($object)
{
$class = get_class($object);
$meta = $this->entityMetadataFactory->getMetadataFor($class);
$values = $meta->getIdentifierValues($object);
$values = array_map(
function ($value) {
if (is_object($value)) {
return $this->getIdentifierFromObject($value);
}
return $value;
},
$values
);
return $values;
} | php | protected function getIdentifierFromObject($object)
{
$class = get_class($object);
$meta = $this->entityMetadataFactory->getMetadataFor($class);
$values = $meta->getIdentifierValues($object);
$values = array_map(
function ($value) {
if (is_object($value)) {
return $this->getIdentifierFromObject($value);
}
return $value;
},
$values
);
return $values;
} | [
"protected",
"function",
"getIdentifierFromObject",
"(",
"$",
"object",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"object",
")",
";",
"$",
"meta",
"=",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
";",
"$",
"values",
"=",
"$",
"meta",
"->",
"getIdentifierValues",
"(",
"$",
"object",
")",
";",
"$",
"values",
"=",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getIdentifierFromObject",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}",
",",
"$",
"values",
")",
";",
"return",
"$",
"values",
";",
"}"
]
| @param object $object
@return array | [
"@param",
"object",
"$object"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L417-L435 |
mihai-stancu/serializer | Serializer/Normalizer/DoctrineNormalizer.php | DoctrineNormalizer.getIdentifierFromArray | protected function getIdentifierFromArray($class, $array)
{
$meta = $this->entityMetadataFactory->getMetadataFor($class);
$fields = $meta->getIdentifierFieldNames();
$ids = array();
foreach ($fields as $field) {
if (isset($array[$field])) {
$ids[$field] = $array[$field];
} else {
$tmp = $array;
$parts = explode('.', $field);
foreach ($parts as $part) {
if (isset($tmp[$part])) {
if (is_array($tmp[$part])) {
$tmp = $tmp[$part];
} else {
$ids[$field] = $tmp[$part];
break;
}
}
}
}
}
return $ids;
} | php | protected function getIdentifierFromArray($class, $array)
{
$meta = $this->entityMetadataFactory->getMetadataFor($class);
$fields = $meta->getIdentifierFieldNames();
$ids = array();
foreach ($fields as $field) {
if (isset($array[$field])) {
$ids[$field] = $array[$field];
} else {
$tmp = $array;
$parts = explode('.', $field);
foreach ($parts as $part) {
if (isset($tmp[$part])) {
if (is_array($tmp[$part])) {
$tmp = $tmp[$part];
} else {
$ids[$field] = $tmp[$part];
break;
}
}
}
}
}
return $ids;
} | [
"protected",
"function",
"getIdentifierFromArray",
"(",
"$",
"class",
",",
"$",
"array",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"entityMetadataFactory",
"->",
"getMetadataFor",
"(",
"$",
"class",
")",
";",
"$",
"fields",
"=",
"$",
"meta",
"->",
"getIdentifierFieldNames",
"(",
")",
";",
"$",
"ids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"ids",
"[",
"$",
"field",
"]",
"=",
"$",
"array",
"[",
"$",
"field",
"]",
";",
"}",
"else",
"{",
"$",
"tmp",
"=",
"$",
"array",
";",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"field",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"tmp",
"[",
"$",
"part",
"]",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"tmp",
"[",
"$",
"part",
"]",
")",
")",
"{",
"$",
"tmp",
"=",
"$",
"tmp",
"[",
"$",
"part",
"]",
";",
"}",
"else",
"{",
"$",
"ids",
"[",
"$",
"field",
"]",
"=",
"$",
"tmp",
"[",
"$",
"part",
"]",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"ids",
";",
"}"
]
| @param string $class
@param array $array
@return array | [
"@param",
"string",
"$class",
"@param",
"array",
"$array"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/DoctrineNormalizer.php#L443-L470 |
ClanCats/Core | src/classes/CCShipyard/Class.php | CCShipyard_Class.create | public function create( $name, $extends = null, $implements = null )
{
$this->name = $name;
$this->extends = $extends;
if ( !is_array( $implements ) && !is_null( $implements ) )
{
$implements = array( $implements );
}
$this->implements = $implements;
} | php | public function create( $name, $extends = null, $implements = null )
{
$this->name = $name;
$this->extends = $extends;
if ( !is_array( $implements ) && !is_null( $implements ) )
{
$implements = array( $implements );
}
$this->implements = $implements;
} | [
"public",
"function",
"create",
"(",
"$",
"name",
",",
"$",
"extends",
"=",
"null",
",",
"$",
"implements",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"this",
"->",
"extends",
"=",
"$",
"extends",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"implements",
")",
"&&",
"!",
"is_null",
"(",
"$",
"implements",
")",
")",
"{",
"$",
"implements",
"=",
"array",
"(",
"$",
"implements",
")",
";",
"}",
"$",
"this",
"->",
"implements",
"=",
"$",
"implements",
";",
"}"
]
| Start new class builder
@param string $name
@param string $extends
@param string|array $implements
@return void | [
"Start",
"new",
"class",
"builder"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCShipyard/Class.php#L37-L48 |
ClanCats/Core | src/classes/CCShipyard/Class.php | CCShipyard_Class.add | public function add()
{
$args = func_get_args();
$component = array_shift( $args );
$method = 'build_'.strtolower( $component );
if ( !method_exists( $this, $method ) )
{
throw new CCException( 'CCShipyard_Class invalid component builder "'.$component.'".' );
}
$this->output .= call_user_func_array( array( $this, $method ), $args );
} | php | public function add()
{
$args = func_get_args();
$component = array_shift( $args );
$method = 'build_'.strtolower( $component );
if ( !method_exists( $this, $method ) )
{
throw new CCException( 'CCShipyard_Class invalid component builder "'.$component.'".' );
}
$this->output .= call_user_func_array( array( $this, $method ), $args );
} | [
"public",
"function",
"add",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"component",
"=",
"array_shift",
"(",
"$",
"args",
")",
";",
"$",
"method",
"=",
"'build_'",
".",
"strtolower",
"(",
"$",
"component",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"CCException",
"(",
"'CCShipyard_Class invalid component builder \"'",
".",
"$",
"component",
".",
"'\".'",
")",
";",
"}",
"$",
"this",
"->",
"output",
".=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"method",
")",
",",
"$",
"args",
")",
";",
"}"
]
| Add a component to the class
@param mixed ...
@return void | [
"Add",
"a",
"component",
"to",
"the",
"class"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCShipyard/Class.php#L56-L70 |
ClanCats/Core | src/classes/CCShipyard/Class.php | CCShipyard_Class.build_property | public function build_property( $name, $context = null, $default = null, $comment = null, $export_default = true )
{
if ( is_null( $context ) )
{
$context = 'public';
}
if ( is_null( $comment ) )
{
$comment = ucfirst( $name );
}
if ( $default !== null )
{
$type = gettype( $default );
// integer to int
if ( $type === 'integer' )
{
$type = 'int';
}
// boolean to bool
if ( $type === 'boolean' )
{
$type = 'bool';
}
$comment .= "\n\n@var ".$type;
}
$forge = new \CCForge_Php;
return $forge->property( $context.' $'.$name, $default, $comment, $export_default );
} | php | public function build_property( $name, $context = null, $default = null, $comment = null, $export_default = true )
{
if ( is_null( $context ) )
{
$context = 'public';
}
if ( is_null( $comment ) )
{
$comment = ucfirst( $name );
}
if ( $default !== null )
{
$type = gettype( $default );
// integer to int
if ( $type === 'integer' )
{
$type = 'int';
}
// boolean to bool
if ( $type === 'boolean' )
{
$type = 'bool';
}
$comment .= "\n\n@var ".$type;
}
$forge = new \CCForge_Php;
return $forge->property( $context.' $'.$name, $default, $comment, $export_default );
} | [
"public",
"function",
"build_property",
"(",
"$",
"name",
",",
"$",
"context",
"=",
"null",
",",
"$",
"default",
"=",
"null",
",",
"$",
"comment",
"=",
"null",
",",
"$",
"export_default",
"=",
"true",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"context",
")",
")",
"{",
"$",
"context",
"=",
"'public'",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"comment",
")",
")",
"{",
"$",
"comment",
"=",
"ucfirst",
"(",
"$",
"name",
")",
";",
"}",
"if",
"(",
"$",
"default",
"!==",
"null",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"default",
")",
";",
"// integer to int",
"if",
"(",
"$",
"type",
"===",
"'integer'",
")",
"{",
"$",
"type",
"=",
"'int'",
";",
"}",
"// boolean to bool",
"if",
"(",
"$",
"type",
"===",
"'boolean'",
")",
"{",
"$",
"type",
"=",
"'bool'",
";",
"}",
"$",
"comment",
".=",
"\"\\n\\n@var \"",
".",
"$",
"type",
";",
"}",
"$",
"forge",
"=",
"new",
"\\",
"CCForge_Php",
";",
"return",
"$",
"forge",
"->",
"property",
"(",
"$",
"context",
".",
"' $'",
".",
"$",
"name",
",",
"$",
"default",
",",
"$",
"comment",
",",
"$",
"export_default",
")",
";",
"}"
]
| Builds a new class property
@param string $name
@param string $context
@param mixed $default
@param string $comment
@param bool $export_default | [
"Builds",
"a",
"new",
"class",
"property"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCShipyard/Class.php#L81-L115 |
ClanCats/Core | src/classes/CCShipyard/Class.php | CCShipyard_Class.build_function | public function build_function( $name, $context = null, $content = null, $comment = null )
{
if ( is_null( $context ) )
{
$context = 'public';
}
if ( strpos( $name, '(' ) === false && strpos( $name, '(' ) === false )
{
$name .= '()';
}
if ( is_null( $comment ) )
{
$comment = ucfirst( $name )." function\n\nreturn void";
}
$forge = new \CCForge_Php;
return $forge->closure( $context.' function '.$name, $content, $comment );
} | php | public function build_function( $name, $context = null, $content = null, $comment = null )
{
if ( is_null( $context ) )
{
$context = 'public';
}
if ( strpos( $name, '(' ) === false && strpos( $name, '(' ) === false )
{
$name .= '()';
}
if ( is_null( $comment ) )
{
$comment = ucfirst( $name )." function\n\nreturn void";
}
$forge = new \CCForge_Php;
return $forge->closure( $context.' function '.$name, $content, $comment );
} | [
"public",
"function",
"build_function",
"(",
"$",
"name",
",",
"$",
"context",
"=",
"null",
",",
"$",
"content",
"=",
"null",
",",
"$",
"comment",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"context",
")",
")",
"{",
"$",
"context",
"=",
"'public'",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'('",
")",
"===",
"false",
"&&",
"strpos",
"(",
"$",
"name",
",",
"'('",
")",
"===",
"false",
")",
"{",
"$",
"name",
".=",
"'()'",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"comment",
")",
")",
"{",
"$",
"comment",
"=",
"ucfirst",
"(",
"$",
"name",
")",
".",
"\" function\\n\\nreturn void\"",
";",
"}",
"$",
"forge",
"=",
"new",
"\\",
"CCForge_Php",
";",
"return",
"$",
"forge",
"->",
"closure",
"(",
"$",
"context",
".",
"' function '",
".",
"$",
"name",
",",
"$",
"content",
",",
"$",
"comment",
")",
";",
"}"
]
| Builds a new class property
@param string $name
@param string $context
@param mixed $content
@param string $comment | [
"Builds",
"a",
"new",
"class",
"property"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCShipyard/Class.php#L125-L144 |
ClanCats/Core | src/classes/CCShipyard/Class.php | CCShipyard_Class.file_header | protected function file_header( $title, $data = array() )
{
$conf = \CCConfig::create( 'shipyard' );
$data = CCDataObject::assign( $data );
// Build the authors string
$authors = $data->get( 'authors', $conf->get( 'defaults.authors' ) );
if ( is_array( $authors ) )
{
foreach( $authors as $person )
{
$author_str .= $person['name']." ";
if ( array_key_exists( 'email', $person ) )
{
$author_str .= "<".$person['email'].">";
}
$author_str .= ", ";
}
$author_str = substr( $author_str, 0, -2 );
}
// Finish comment heeader
return "$title\n".
"*\n".
"\n".
"@package ".$data->get( 'package', $conf->get( 'defaults.package' ) )."\n".
"@author ".$author_str."\n".
"@version ".$data->get( 'version', $conf->get( 'defaults.version' ) )."\n".
"@copyright ".$data->get( 'copyright', $conf->get( 'defaults.copyright' ) )."\n";
} | php | protected function file_header( $title, $data = array() )
{
$conf = \CCConfig::create( 'shipyard' );
$data = CCDataObject::assign( $data );
// Build the authors string
$authors = $data->get( 'authors', $conf->get( 'defaults.authors' ) );
if ( is_array( $authors ) )
{
foreach( $authors as $person )
{
$author_str .= $person['name']." ";
if ( array_key_exists( 'email', $person ) )
{
$author_str .= "<".$person['email'].">";
}
$author_str .= ", ";
}
$author_str = substr( $author_str, 0, -2 );
}
// Finish comment heeader
return "$title\n".
"*\n".
"\n".
"@package ".$data->get( 'package', $conf->get( 'defaults.package' ) )."\n".
"@author ".$author_str."\n".
"@version ".$data->get( 'version', $conf->get( 'defaults.version' ) )."\n".
"@copyright ".$data->get( 'copyright', $conf->get( 'defaults.copyright' ) )."\n";
} | [
"protected",
"function",
"file_header",
"(",
"$",
"title",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"conf",
"=",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
";",
"$",
"data",
"=",
"CCDataObject",
"::",
"assign",
"(",
"$",
"data",
")",
";",
"// Build the authors string",
"$",
"authors",
"=",
"$",
"data",
"->",
"get",
"(",
"'authors'",
",",
"$",
"conf",
"->",
"get",
"(",
"'defaults.authors'",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"authors",
")",
")",
"{",
"foreach",
"(",
"$",
"authors",
"as",
"$",
"person",
")",
"{",
"$",
"author_str",
".=",
"$",
"person",
"[",
"'name'",
"]",
".",
"\" \"",
";",
"if",
"(",
"array_key_exists",
"(",
"'email'",
",",
"$",
"person",
")",
")",
"{",
"$",
"author_str",
".=",
"\"<\"",
".",
"$",
"person",
"[",
"'email'",
"]",
".",
"\">\"",
";",
"}",
"$",
"author_str",
".=",
"\", \"",
";",
"}",
"$",
"author_str",
"=",
"substr",
"(",
"$",
"author_str",
",",
"0",
",",
"-",
"2",
")",
";",
"}",
"// Finish comment heeader",
"return",
"\"$title\\n\"",
".",
"\"*\\n\"",
".",
"\"\\n\"",
".",
"\"@package \"",
".",
"$",
"data",
"->",
"get",
"(",
"'package'",
",",
"$",
"conf",
"->",
"get",
"(",
"'defaults.package'",
")",
")",
".",
"\"\\n\"",
".",
"\"@author \"",
".",
"$",
"author_str",
".",
"\"\\n\"",
".",
"\"@version \"",
".",
"$",
"data",
"->",
"get",
"(",
"'version'",
",",
"$",
"conf",
"->",
"get",
"(",
"'defaults.version'",
")",
")",
".",
"\"\\n\"",
".",
"\"@copyright \"",
".",
"$",
"data",
"->",
"get",
"(",
"'copyright'",
",",
"$",
"conf",
"->",
"get",
"(",
"'defaults.copyright'",
")",
")",
".",
"\"\\n\"",
";",
"}"
]
| generates an file header string
@param string $title
@param array $data
@return string | [
"generates",
"an",
"file",
"header",
"string"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCShipyard/Class.php#L163-L193 |
ClanCats/Core | src/classes/CCShipyard/Class.php | CCShipyard_Class.output | public function output()
{
$namespace = null;
$class = $this->name;
extract( \CCConfig::create( 'shipyard' )->defaults );
// get namespace from the param
if ( strpos( $class, '::' ) !== false )
{
list( $namespace, $class ) = explode( '::', $this->name );
// try to get the ship from namespace
if ( $ship = \CCOrbit::ship_by_namespace( $namespace ) )
{
$package = $ship->name;
$version = $ship->version;
$authors = $ship->authors;
}
}
// create forge instance
$forge = new \CCForge_Php( $namespace );
// add header
$forge->comment( $this->file_header( $class, array(
'package' => $package,
'authors' => $authors,
'version' => $version,
'copyright' => $copyright
)));
$class_string = 'class '.$class;
// superclasses
if ( $this->extends )
{
$class_string .= ' extends '.$this->extends;
}
// interface implementations
if ( !empty( $this->implements ) )
{
$class_string .= ' implements '.implode( ', ', $this->implements );
}
// create the closure
$forge->closure( $class_string, $this->output );
return $forge->buffer;
} | php | public function output()
{
$namespace = null;
$class = $this->name;
extract( \CCConfig::create( 'shipyard' )->defaults );
// get namespace from the param
if ( strpos( $class, '::' ) !== false )
{
list( $namespace, $class ) = explode( '::', $this->name );
// try to get the ship from namespace
if ( $ship = \CCOrbit::ship_by_namespace( $namespace ) )
{
$package = $ship->name;
$version = $ship->version;
$authors = $ship->authors;
}
}
// create forge instance
$forge = new \CCForge_Php( $namespace );
// add header
$forge->comment( $this->file_header( $class, array(
'package' => $package,
'authors' => $authors,
'version' => $version,
'copyright' => $copyright
)));
$class_string = 'class '.$class;
// superclasses
if ( $this->extends )
{
$class_string .= ' extends '.$this->extends;
}
// interface implementations
if ( !empty( $this->implements ) )
{
$class_string .= ' implements '.implode( ', ', $this->implements );
}
// create the closure
$forge->closure( $class_string, $this->output );
return $forge->buffer;
} | [
"public",
"function",
"output",
"(",
")",
"{",
"$",
"namespace",
"=",
"null",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"name",
";",
"extract",
"(",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
"->",
"defaults",
")",
";",
"// get namespace from the param",
"if",
"(",
"strpos",
"(",
"$",
"class",
",",
"'::'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"namespace",
",",
"$",
"class",
")",
"=",
"explode",
"(",
"'::'",
",",
"$",
"this",
"->",
"name",
")",
";",
"// try to get the ship from namespace",
"if",
"(",
"$",
"ship",
"=",
"\\",
"CCOrbit",
"::",
"ship_by_namespace",
"(",
"$",
"namespace",
")",
")",
"{",
"$",
"package",
"=",
"$",
"ship",
"->",
"name",
";",
"$",
"version",
"=",
"$",
"ship",
"->",
"version",
";",
"$",
"authors",
"=",
"$",
"ship",
"->",
"authors",
";",
"}",
"}",
"// create forge instance",
"$",
"forge",
"=",
"new",
"\\",
"CCForge_Php",
"(",
"$",
"namespace",
")",
";",
"// add header",
"$",
"forge",
"->",
"comment",
"(",
"$",
"this",
"->",
"file_header",
"(",
"$",
"class",
",",
"array",
"(",
"'package'",
"=>",
"$",
"package",
",",
"'authors'",
"=>",
"$",
"authors",
",",
"'version'",
"=>",
"$",
"version",
",",
"'copyright'",
"=>",
"$",
"copyright",
")",
")",
")",
";",
"$",
"class_string",
"=",
"'class '",
".",
"$",
"class",
";",
"// superclasses",
"if",
"(",
"$",
"this",
"->",
"extends",
")",
"{",
"$",
"class_string",
".=",
"' extends '",
".",
"$",
"this",
"->",
"extends",
";",
"}",
"// interface implementations",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"implements",
")",
")",
"{",
"$",
"class_string",
".=",
"' implements '",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"implements",
")",
";",
"}",
"// create the closure",
"$",
"forge",
"->",
"closure",
"(",
"$",
"class_string",
",",
"$",
"this",
"->",
"output",
")",
";",
"return",
"$",
"forge",
"->",
"buffer",
";",
"}"
]
| Get the current builder output
@return string | [
"Get",
"the",
"current",
"builder",
"output"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCShipyard/Class.php#L200-L250 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Template.php | PHPWord_Template.setValue | public function setValue($search, $replace) {
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${'.$search.'}';
}
$this->_documentXML = str_replace($search, $replace, $this->_documentXML);
} | php | public function setValue($search, $replace) {
if(substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') {
$search = '${'.$search.'}';
}
$this->_documentXML = str_replace($search, $replace, $this->_documentXML);
} | [
"public",
"function",
"setValue",
"(",
"$",
"search",
",",
"$",
"replace",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"search",
",",
"0",
",",
"2",
")",
"!==",
"'${'",
"&&",
"substr",
"(",
"$",
"search",
",",
"-",
"1",
")",
"!==",
"'}'",
")",
"{",
"$",
"search",
"=",
"'${'",
".",
"$",
"search",
".",
"'}'",
";",
"}",
"$",
"this",
"->",
"_documentXML",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"_documentXML",
")",
";",
"}"
]
| Set a Template value
@param mixed $search
@param mixed $replace | [
"Set",
"a",
"Template",
"value"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Template.php#L83-L89 |
webforge-labs/psc-cms | lib/PHPWord/PHPWord/Template.php | PHPWord_Template.save | public function save($strFilename) {
if(file_exists($strFilename)) {
unlink($strFilename);
}
$this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file
if($this->_objZip->close() === false) {
throw new Exception('Could not close zip file.');
}
rename($this->_tempFileName, $strFilename);
} | php | public function save($strFilename) {
if(file_exists($strFilename)) {
unlink($strFilename);
}
$this->_objZip->addFromString('word/document.xml', $this->_documentXML);
// Close zip file
if($this->_objZip->close() === false) {
throw new Exception('Could not close zip file.');
}
rename($this->_tempFileName, $strFilename);
} | [
"public",
"function",
"save",
"(",
"$",
"strFilename",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"strFilename",
")",
")",
"{",
"unlink",
"(",
"$",
"strFilename",
")",
";",
"}",
"$",
"this",
"->",
"_objZip",
"->",
"addFromString",
"(",
"'word/document.xml'",
",",
"$",
"this",
"->",
"_documentXML",
")",
";",
"// Close zip file\r",
"if",
"(",
"$",
"this",
"->",
"_objZip",
"->",
"close",
"(",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Could not close zip file.'",
")",
";",
"}",
"rename",
"(",
"$",
"this",
"->",
"_tempFileName",
",",
"$",
"strFilename",
")",
";",
"}"
]
| Save Template
@param string $strFilename | [
"Save",
"Template"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/PHPWord/PHPWord/Template.php#L96-L109 |
steeffeen/FancyManiaLinks | FML/Stylesheet/Style3d.php | Style3d.render | public function render(\DOMDocument $domDocument)
{
$style3dXml = $domDocument->createElement("style3d");
$this->checkId();
if ($this->styleId) {
$style3dXml->setAttribute("id", $this->styleId);
}
if ($this->model) {
$style3dXml->setAttribute("model", $this->model);
}
if ($this->thickness) {
$style3dXml->setAttribute("thickness", $this->thickness);
}
if ($this->color) {
$style3dXml->setAttribute("color", $this->color);
}
if ($this->focusColor) {
$style3dXml->setAttribute("fcolor", $this->focusColor);
}
if ($this->lightColor) {
$style3dXml->setAttribute("lightcolor", $this->lightColor);
}
if ($this->focusLightColor) {
$style3dXml->setAttribute("flightcolor", $this->focusLightColor);
}
if ($this->yOffset) {
$style3dXml->setAttribute("yoffset", $this->yOffset);
}
if ($this->focusYOffset) {
$style3dXml->setAttribute("fyoffset", $this->focusYOffset);
}
if ($this->zOffset) {
$style3dXml->setAttribute("zoffset", $this->zOffset);
}
if ($this->focusZOffset) {
$style3dXml->setAttribute("fzoffset", $this->focusZOffset);
}
return $style3dXml;
} | php | public function render(\DOMDocument $domDocument)
{
$style3dXml = $domDocument->createElement("style3d");
$this->checkId();
if ($this->styleId) {
$style3dXml->setAttribute("id", $this->styleId);
}
if ($this->model) {
$style3dXml->setAttribute("model", $this->model);
}
if ($this->thickness) {
$style3dXml->setAttribute("thickness", $this->thickness);
}
if ($this->color) {
$style3dXml->setAttribute("color", $this->color);
}
if ($this->focusColor) {
$style3dXml->setAttribute("fcolor", $this->focusColor);
}
if ($this->lightColor) {
$style3dXml->setAttribute("lightcolor", $this->lightColor);
}
if ($this->focusLightColor) {
$style3dXml->setAttribute("flightcolor", $this->focusLightColor);
}
if ($this->yOffset) {
$style3dXml->setAttribute("yoffset", $this->yOffset);
}
if ($this->focusYOffset) {
$style3dXml->setAttribute("fyoffset", $this->focusYOffset);
}
if ($this->zOffset) {
$style3dXml->setAttribute("zoffset", $this->zOffset);
}
if ($this->focusZOffset) {
$style3dXml->setAttribute("fzoffset", $this->focusZOffset);
}
return $style3dXml;
} | [
"public",
"function",
"render",
"(",
"\\",
"DOMDocument",
"$",
"domDocument",
")",
"{",
"$",
"style3dXml",
"=",
"$",
"domDocument",
"->",
"createElement",
"(",
"\"style3d\"",
")",
";",
"$",
"this",
"->",
"checkId",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"styleId",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"id\"",
",",
"$",
"this",
"->",
"styleId",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"model",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"model\"",
",",
"$",
"this",
"->",
"model",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"thickness",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"thickness\"",
",",
"$",
"this",
"->",
"thickness",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"color",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"color\"",
",",
"$",
"this",
"->",
"color",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"focusColor",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"fcolor\"",
",",
"$",
"this",
"->",
"focusColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lightColor",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"lightcolor\"",
",",
"$",
"this",
"->",
"lightColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"focusLightColor",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"flightcolor\"",
",",
"$",
"this",
"->",
"focusLightColor",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"yOffset",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"yoffset\"",
",",
"$",
"this",
"->",
"yOffset",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"focusYOffset",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"fyoffset\"",
",",
"$",
"this",
"->",
"focusYOffset",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"zOffset",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"zoffset\"",
",",
"$",
"this",
"->",
"zOffset",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"focusZOffset",
")",
"{",
"$",
"style3dXml",
"->",
"setAttribute",
"(",
"\"fzoffset\"",
",",
"$",
"this",
"->",
"focusZOffset",
")",
";",
"}",
"return",
"$",
"style3dXml",
";",
"}"
]
| Render the Style3d
@param \DOMDocument $domDocument DOMDocument for which the Style3d should be rendered
@return \DOMElement | [
"Render",
"the",
"Style3d"
]
| train | https://github.com/steeffeen/FancyManiaLinks/blob/227b0759306f0a3c75873ba50276e4163a93bfa6/FML/Stylesheet/Style3d.php#L394-L432 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.ExpectRetrievedValueIsString | public static function ExpectRetrievedValueIsString(
string $property,
$value,
string $class_name
) : string {
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'string');
return $value;
} | php | public static function ExpectRetrievedValueIsString(
string $property,
$value,
string $class_name
) : string {
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'string');
return $value;
} | [
"public",
"static",
"function",
"ExpectRetrievedValueIsString",
"(",
"string",
"$",
"property",
",",
"$",
"value",
",",
"string",
"$",
"class_name",
")",
":",
"string",
"{",
"/**\n * @psalm-var T\n */",
"$",
"value",
"=",
"static",
"::",
"MaybeThrowIfNotType",
"(",
"$",
"property",
",",
"$",
"value",
",",
"$",
"class_name",
",",
"'string'",
")",
";",
"return",
"$",
"value",
";",
"}"
]
| @template T as string
@param scalar|array|object|null $value
@psalm-param class-string<DaftObject> $class_name | [
"@template",
"T",
"as",
"string"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L130-L141 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.ExpectRetrievedValueIsArray | public static function ExpectRetrievedValueIsArray(
string $property,
$value,
string $class_name
) : array {
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'array');
return $value;
} | php | public static function ExpectRetrievedValueIsArray(
string $property,
$value,
string $class_name
) : array {
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'array');
return $value;
} | [
"public",
"static",
"function",
"ExpectRetrievedValueIsArray",
"(",
"string",
"$",
"property",
",",
"$",
"value",
",",
"string",
"$",
"class_name",
")",
":",
"array",
"{",
"/**\n * @psalm-var T\n */",
"$",
"value",
"=",
"static",
"::",
"MaybeThrowIfNotType",
"(",
"$",
"property",
",",
"$",
"value",
",",
"$",
"class_name",
",",
"'array'",
")",
";",
"return",
"$",
"value",
";",
"}"
]
| @template T as array
@param scalar|array|object|null $value
@psalm-param class-string<DaftObject> $class_name | [
"@template",
"T",
"as",
"array"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L150-L161 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.ExpectRetrievedValueIsIntish | public static function ExpectRetrievedValueIsIntish(
string $property,
$value,
string $class_name
) : int {
if (is_string($value) && ctype_digit($value)) {
$value = (int) $value;
}
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'integer');
return $value;
} | php | public static function ExpectRetrievedValueIsIntish(
string $property,
$value,
string $class_name
) : int {
if (is_string($value) && ctype_digit($value)) {
$value = (int) $value;
}
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'integer');
return $value;
} | [
"public",
"static",
"function",
"ExpectRetrievedValueIsIntish",
"(",
"string",
"$",
"property",
",",
"$",
"value",
",",
"string",
"$",
"class_name",
")",
":",
"int",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"ctype_digit",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"int",
")",
"$",
"value",
";",
"}",
"/**\n * @psalm-var T\n */",
"$",
"value",
"=",
"static",
"::",
"MaybeThrowIfNotType",
"(",
"$",
"property",
",",
"$",
"value",
",",
"$",
"class_name",
",",
"'integer'",
")",
";",
"return",
"$",
"value",
";",
"}"
]
| @template T as int
@param scalar|array|object|null $value
@psalm-param class-string<DaftObject> $class_name | [
"@template",
"T",
"as",
"int"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L170-L185 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.ExpectRetrievedValueIsFloatish | public static function ExpectRetrievedValueIsFloatish(
string $property,
$value,
string $class_name
) : float {
if (is_string($value) && is_numeric($value)) {
$value = (float) $value;
}
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'double');
return $value;
} | php | public static function ExpectRetrievedValueIsFloatish(
string $property,
$value,
string $class_name
) : float {
if (is_string($value) && is_numeric($value)) {
$value = (float) $value;
}
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'double');
return $value;
} | [
"public",
"static",
"function",
"ExpectRetrievedValueIsFloatish",
"(",
"string",
"$",
"property",
",",
"$",
"value",
",",
"string",
"$",
"class_name",
")",
":",
"float",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"}",
"/**\n * @psalm-var T\n */",
"$",
"value",
"=",
"static",
"::",
"MaybeThrowIfNotType",
"(",
"$",
"property",
",",
"$",
"value",
",",
"$",
"class_name",
",",
"'double'",
")",
";",
"return",
"$",
"value",
";",
"}"
]
| @template T as float
@param scalar|array|object|null $value
@psalm-param class-string<DaftObject> $class_name | [
"@template",
"T",
"as",
"float"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L194-L209 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.ExpectRetrievedValueIsBoolish | public static function ExpectRetrievedValueIsBoolish(
string $property,
$value,
string $class_name
) : bool {
if ('1' === $value || 1 === $value) {
return true;
} elseif ('0' === $value || 0 === $value) {
return false;
}
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'boolean');
return $value;
} | php | public static function ExpectRetrievedValueIsBoolish(
string $property,
$value,
string $class_name
) : bool {
if ('1' === $value || 1 === $value) {
return true;
} elseif ('0' === $value || 0 === $value) {
return false;
}
/**
* @psalm-var T
*/
$value = static::MaybeThrowIfNotType($property, $value, $class_name, 'boolean');
return $value;
} | [
"public",
"static",
"function",
"ExpectRetrievedValueIsBoolish",
"(",
"string",
"$",
"property",
",",
"$",
"value",
",",
"string",
"$",
"class_name",
")",
":",
"bool",
"{",
"if",
"(",
"'1'",
"===",
"$",
"value",
"||",
"1",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"elseif",
"(",
"'0'",
"===",
"$",
"value",
"||",
"0",
"===",
"$",
"value",
")",
"{",
"return",
"false",
";",
"}",
"/**\n * @psalm-var T\n */",
"$",
"value",
"=",
"static",
"::",
"MaybeThrowIfNotType",
"(",
"$",
"property",
",",
"$",
"value",
",",
"$",
"class_name",
",",
"'boolean'",
")",
";",
"return",
"$",
"value",
";",
"}"
]
| @template T as bool
@param scalar|array|object|null $value
@psalm-param class-string<DaftObject> $class_name | [
"@template",
"T",
"as",
"bool"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L218-L235 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.MaybeThrowOnNudge | public static function MaybeThrowOnNudge(
string $class_name,
string $property,
$value
) : void {
if (
! in_array(
$property,
$class_name::DaftObjectProperties(),
DefinitionAssistant::IN_ARRAY_STRICT_MODE
)
) {
throw Exceptions\Factory::UndefinedPropertyException($class_name, $property);
} elseif (
true === is_null($value) &&
! in_array(
$property,
$class_name::DaftObjectNullableProperties(),
DefinitionAssistant::IN_ARRAY_STRICT_MODE
)
) {
throw Exceptions\Factory::PropertyNotNullableException($class_name, $property);
}
} | php | public static function MaybeThrowOnNudge(
string $class_name,
string $property,
$value
) : void {
if (
! in_array(
$property,
$class_name::DaftObjectProperties(),
DefinitionAssistant::IN_ARRAY_STRICT_MODE
)
) {
throw Exceptions\Factory::UndefinedPropertyException($class_name, $property);
} elseif (
true === is_null($value) &&
! in_array(
$property,
$class_name::DaftObjectNullableProperties(),
DefinitionAssistant::IN_ARRAY_STRICT_MODE
)
) {
throw Exceptions\Factory::PropertyNotNullableException($class_name, $property);
}
} | [
"public",
"static",
"function",
"MaybeThrowOnNudge",
"(",
"string",
"$",
"class_name",
",",
"string",
"$",
"property",
",",
"$",
"value",
")",
":",
"void",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"property",
",",
"$",
"class_name",
"::",
"DaftObjectProperties",
"(",
")",
",",
"DefinitionAssistant",
"::",
"IN_ARRAY_STRICT_MODE",
")",
")",
"{",
"throw",
"Exceptions",
"\\",
"Factory",
"::",
"UndefinedPropertyException",
"(",
"$",
"class_name",
",",
"$",
"property",
")",
";",
"}",
"elseif",
"(",
"true",
"===",
"is_null",
"(",
"$",
"value",
")",
"&&",
"!",
"in_array",
"(",
"$",
"property",
",",
"$",
"class_name",
"::",
"DaftObjectNullableProperties",
"(",
")",
",",
"DefinitionAssistant",
"::",
"IN_ARRAY_STRICT_MODE",
")",
")",
"{",
"throw",
"Exceptions",
"\\",
"Factory",
"::",
"PropertyNotNullableException",
"(",
"$",
"class_name",
",",
"$",
"property",
")",
";",
"}",
"}"
]
| @psalm-param class-string<DaftObject> $class_name
@param scalar|array|object|null $value | [
"@psalm",
"-",
"param",
"class",
"-",
"string<DaftObject",
">",
"$class_name"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L242-L265 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.MaybeThrowIfNotType | protected static function MaybeThrowIfNotType(
string $property,
$value,
string $class_name,
string $type
) {
if ($type !== gettype($value)) {
throw Exceptions\Factory::PropertyValueNotOfExpectedTypeException(
$class_name,
$property,
$type
);
}
/**
* @var T
*/
$value = $value;
return $value;
} | php | protected static function MaybeThrowIfNotType(
string $property,
$value,
string $class_name,
string $type
) {
if ($type !== gettype($value)) {
throw Exceptions\Factory::PropertyValueNotOfExpectedTypeException(
$class_name,
$property,
$type
);
}
/**
* @var T
*/
$value = $value;
return $value;
} | [
"protected",
"static",
"function",
"MaybeThrowIfNotType",
"(",
"string",
"$",
"property",
",",
"$",
"value",
",",
"string",
"$",
"class_name",
",",
"string",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"!==",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"Exceptions",
"\\",
"Factory",
"::",
"PropertyValueNotOfExpectedTypeException",
"(",
"$",
"class_name",
",",
"$",
"property",
",",
"$",
"type",
")",
";",
"}",
"/**\n * @var T\n */",
"$",
"value",
"=",
"$",
"value",
";",
"return",
"$",
"value",
";",
"}"
]
| @template T
@param scalar|array|object|null $value
@psalm-return T
@return mixed | [
"@template",
"T"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L276-L296 |
SignpostMarv/daft-object | src/TypeUtilities.php | TypeUtilities.CachePublicGettersAndSettersProperties | protected static function CachePublicGettersAndSettersProperties(string $class) : void
{
if (
is_a($class, AbstractDaftObject::class, true) &&
DefinitionAssistant::IsTypeUnregistered($class)
) {
/**
* @psalm-var class-string<T>
*/
$class = DefinitionAssistant::RegisterAbstractDaftObjectType($class);
}
foreach (
DefinitionAssistant::ObtainExpectedProperties($class) as $prop
) {
static::CachePublicGettersAndSettersProperty($class, $prop);
}
} | php | protected static function CachePublicGettersAndSettersProperties(string $class) : void
{
if (
is_a($class, AbstractDaftObject::class, true) &&
DefinitionAssistant::IsTypeUnregistered($class)
) {
/**
* @psalm-var class-string<T>
*/
$class = DefinitionAssistant::RegisterAbstractDaftObjectType($class);
}
foreach (
DefinitionAssistant::ObtainExpectedProperties($class) as $prop
) {
static::CachePublicGettersAndSettersProperty($class, $prop);
}
} | [
"protected",
"static",
"function",
"CachePublicGettersAndSettersProperties",
"(",
"string",
"$",
"class",
")",
":",
"void",
"{",
"if",
"(",
"is_a",
"(",
"$",
"class",
",",
"AbstractDaftObject",
"::",
"class",
",",
"true",
")",
"&&",
"DefinitionAssistant",
"::",
"IsTypeUnregistered",
"(",
"$",
"class",
")",
")",
"{",
"/**\n * @psalm-var class-string<T>\n */",
"$",
"class",
"=",
"DefinitionAssistant",
"::",
"RegisterAbstractDaftObjectType",
"(",
"$",
"class",
")",
";",
"}",
"foreach",
"(",
"DefinitionAssistant",
"::",
"ObtainExpectedProperties",
"(",
"$",
"class",
")",
"as",
"$",
"prop",
")",
"{",
"static",
"::",
"CachePublicGettersAndSettersProperty",
"(",
"$",
"class",
",",
"$",
"prop",
")",
";",
"}",
"}"
]
| @template T as DaftObject
@psalm-param class-string<T> $class | [
"@template",
"T",
"as",
"DaftObject"
]
| train | https://github.com/SignpostMarv/daft-object/blob/514886592b64986cc637040045f098335e27c037/src/TypeUtilities.php#L303-L320 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setIo($input, $output);
$outputFile = $input->getOption('generate');
$output->writeln("<info>Generating your {$outputFile}...</info>");
$output->writeln("<comment>{$this->banner}\n</comment>");
$generated['source'] = $this->setupSources();
$generated['build'] = $this->setupBuild();
$generated['deploy'] = $this->setupDeploy();
$generated['gulp'] = $this->setupGulp();
$generated['serve'] = $this->setupServe($generated);
$yaml = $this->createYaml($generated);
if ($input->getOption('dry-run')) {
$output->writeln("\n<info>Ready to write config file</info>");
$output->writeln($yaml);
if ( ! $this->confirm("Write the above configuration to <path>{$outputFile}</path>?")) {
return $output->writeln('<error>Aborted!</error>');
}
}
if ( ! $this->files->put($outputFile, $yaml)) {
return $output->writeln('<error>Failed to save config file.</error>');
}
$output->writeln("<info>Success! <path>{$outputFile}</path> written.</info>");
if ( ! empty($generated['source']['git.url'])) {
$output->writeln("Try a <comment>steak pull</comment> next to fetch your sources...");
} else {
$output->writeln("Try <comment>steak serve</comment> to start building your site...");
}
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setIo($input, $output);
$outputFile = $input->getOption('generate');
$output->writeln("<info>Generating your {$outputFile}...</info>");
$output->writeln("<comment>{$this->banner}\n</comment>");
$generated['source'] = $this->setupSources();
$generated['build'] = $this->setupBuild();
$generated['deploy'] = $this->setupDeploy();
$generated['gulp'] = $this->setupGulp();
$generated['serve'] = $this->setupServe($generated);
$yaml = $this->createYaml($generated);
if ($input->getOption('dry-run')) {
$output->writeln("\n<info>Ready to write config file</info>");
$output->writeln($yaml);
if ( ! $this->confirm("Write the above configuration to <path>{$outputFile}</path>?")) {
return $output->writeln('<error>Aborted!</error>');
}
}
if ( ! $this->files->put($outputFile, $yaml)) {
return $output->writeln('<error>Failed to save config file.</error>');
}
$output->writeln("<info>Success! <path>{$outputFile}</path> written.</info>");
if ( ! empty($generated['source']['git.url'])) {
$output->writeln("Try a <comment>steak pull</comment> next to fetch your sources...");
} else {
$output->writeln("Try <comment>steak serve</comment> to start building your site...");
}
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"this",
"->",
"setIo",
"(",
"$",
"input",
",",
"$",
"output",
")",
";",
"$",
"outputFile",
"=",
"$",
"input",
"->",
"getOption",
"(",
"'generate'",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"\"<info>Generating your {$outputFile}...</info>\"",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"\"<comment>{$this->banner}\\n</comment>\"",
")",
";",
"$",
"generated",
"[",
"'source'",
"]",
"=",
"$",
"this",
"->",
"setupSources",
"(",
")",
";",
"$",
"generated",
"[",
"'build'",
"]",
"=",
"$",
"this",
"->",
"setupBuild",
"(",
")",
";",
"$",
"generated",
"[",
"'deploy'",
"]",
"=",
"$",
"this",
"->",
"setupDeploy",
"(",
")",
";",
"$",
"generated",
"[",
"'gulp'",
"]",
"=",
"$",
"this",
"->",
"setupGulp",
"(",
")",
";",
"$",
"generated",
"[",
"'serve'",
"]",
"=",
"$",
"this",
"->",
"setupServe",
"(",
"$",
"generated",
")",
";",
"$",
"yaml",
"=",
"$",
"this",
"->",
"createYaml",
"(",
"$",
"generated",
")",
";",
"if",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'dry-run'",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"\"\\n<info>Ready to write config file</info>\"",
")",
";",
"$",
"output",
"->",
"writeln",
"(",
"$",
"yaml",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"confirm",
"(",
"\"Write the above configuration to <path>{$outputFile}</path>?\"",
")",
")",
"{",
"return",
"$",
"output",
"->",
"writeln",
"(",
"'<error>Aborted!</error>'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"put",
"(",
"$",
"outputFile",
",",
"$",
"yaml",
")",
")",
"{",
"return",
"$",
"output",
"->",
"writeln",
"(",
"'<error>Failed to save config file.</error>'",
")",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"\"<info>Success! <path>{$outputFile}</path> written.</info>\"",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"generated",
"[",
"'source'",
"]",
"[",
"'git.url'",
"]",
")",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"\"Try a <comment>steak pull</comment> next to fetch your sources...\"",
")",
";",
"}",
"else",
"{",
"$",
"output",
"->",
"writeln",
"(",
"\"Try <comment>steak serve</comment> to start building your site...\"",
")",
";",
"}",
"}"
]
| Execute the command.
@param InputInterface $input
@param OutputInterface $output
@return void | [
"Execute",
"the",
"command",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L89-L127 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.setupSources | protected function setupSources()
{
/** @var Repository $config */
$config = $this->container['config'];
$cwd = getcwd();
$source = [];
$this->output->writeln("Working directory is <path>{$cwd}</path>");
$this->title('Sources');
if ($this->isGitRepo('.')) {
$this->output->writeln("It looks your project already has a git repository.\n");
if ($this->confirm('Would you like to store your steak sources in a <b>separate</b> repo/branch?', false)) {
$source['git.directory'] = $this->ask(
"Where should we check out the site sources <b>repository</b>?",
$config->get('source.directory', 'steak')
);
// @todo if the sources repo already exists, try reading values from there instead of config?
$source['git.url'] = $this->ask(
"Enter the source repository URL:",
$config->get('source.git.url', $this->getPushUrl('.'))
);
$source['git.branch'] = $this->ask(
"Specify the branch to use:",
$config->get('source.git.branch', 'gh-pages-src')
);
} else { // not using a separate source vcs
$this->output->writeln([
" Okay, no problem, just commit your steak sources as part of your standard workflow.",
" The <comment>steak pull</comment> command will have no effect.",
""
]);
$source['directory'] = $this->ask(
"Where are the <b>source files</b> kept?",
$config->get('source.directory', 'source')
);
}
} else { // not running inside a git repo
$this->output->writeln("working directory not under git", OutputInterface::VERBOSITY_VERBOSE);
if ($this->confirm('Would you like to store your steak sources in a git repo?')) {
$source['directory'] = $this->ask(
"Where should we check out the site sources <b>repository</b>?",
$config->get('source.directory', 'steak')
);
$source['git.url'] = $this->ask(
"Enter the source repository URL:",
$config->get('source.git.url'),
$this->valueRequiredValidator()
);
$source['git.branch'] = $this->ask(
"Specify the branch to use:",
$config->get('source.git.branch', 'master')
);
} else {
$this->output->writeln(" Okay, no git.");
$source['directory'] = $this->ask(
"Where to put the steak <b>source files</b>?",
$config->get('source.directory', 'sources')
);
}
}
return $source;
} | php | protected function setupSources()
{
/** @var Repository $config */
$config = $this->container['config'];
$cwd = getcwd();
$source = [];
$this->output->writeln("Working directory is <path>{$cwd}</path>");
$this->title('Sources');
if ($this->isGitRepo('.')) {
$this->output->writeln("It looks your project already has a git repository.\n");
if ($this->confirm('Would you like to store your steak sources in a <b>separate</b> repo/branch?', false)) {
$source['git.directory'] = $this->ask(
"Where should we check out the site sources <b>repository</b>?",
$config->get('source.directory', 'steak')
);
// @todo if the sources repo already exists, try reading values from there instead of config?
$source['git.url'] = $this->ask(
"Enter the source repository URL:",
$config->get('source.git.url', $this->getPushUrl('.'))
);
$source['git.branch'] = $this->ask(
"Specify the branch to use:",
$config->get('source.git.branch', 'gh-pages-src')
);
} else { // not using a separate source vcs
$this->output->writeln([
" Okay, no problem, just commit your steak sources as part of your standard workflow.",
" The <comment>steak pull</comment> command will have no effect.",
""
]);
$source['directory'] = $this->ask(
"Where are the <b>source files</b> kept?",
$config->get('source.directory', 'source')
);
}
} else { // not running inside a git repo
$this->output->writeln("working directory not under git", OutputInterface::VERBOSITY_VERBOSE);
if ($this->confirm('Would you like to store your steak sources in a git repo?')) {
$source['directory'] = $this->ask(
"Where should we check out the site sources <b>repository</b>?",
$config->get('source.directory', 'steak')
);
$source['git.url'] = $this->ask(
"Enter the source repository URL:",
$config->get('source.git.url'),
$this->valueRequiredValidator()
);
$source['git.branch'] = $this->ask(
"Specify the branch to use:",
$config->get('source.git.branch', 'master')
);
} else {
$this->output->writeln(" Okay, no git.");
$source['directory'] = $this->ask(
"Where to put the steak <b>source files</b>?",
$config->get('source.directory', 'sources')
);
}
}
return $source;
} | [
"protected",
"function",
"setupSources",
"(",
")",
"{",
"/** @var Repository $config */",
"$",
"config",
"=",
"$",
"this",
"->",
"container",
"[",
"'config'",
"]",
";",
"$",
"cwd",
"=",
"getcwd",
"(",
")",
";",
"$",
"source",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"Working directory is <path>{$cwd}</path>\"",
")",
";",
"$",
"this",
"->",
"title",
"(",
"'Sources'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isGitRepo",
"(",
"'.'",
")",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"It looks your project already has a git repository.\\n\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"confirm",
"(",
"'Would you like to store your steak sources in a <b>separate</b> repo/branch?'",
",",
"false",
")",
")",
"{",
"$",
"source",
"[",
"'git.directory'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Where should we check out the site sources <b>repository</b>?\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.directory'",
",",
"'steak'",
")",
")",
";",
"// @todo if the sources repo already exists, try reading values from there instead of config?",
"$",
"source",
"[",
"'git.url'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Enter the source repository URL:\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.git.url'",
",",
"$",
"this",
"->",
"getPushUrl",
"(",
"'.'",
")",
")",
")",
";",
"$",
"source",
"[",
"'git.branch'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Specify the branch to use:\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.git.branch'",
",",
"'gh-pages-src'",
")",
")",
";",
"}",
"else",
"{",
"// not using a separate source vcs",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"[",
"\" Okay, no problem, just commit your steak sources as part of your standard workflow.\"",
",",
"\" The <comment>steak pull</comment> command will have no effect.\"",
",",
"\"\"",
"]",
")",
";",
"$",
"source",
"[",
"'directory'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Where are the <b>source files</b> kept?\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.directory'",
",",
"'source'",
")",
")",
";",
"}",
"}",
"else",
"{",
"// not running inside a git repo",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"working directory not under git\"",
",",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
";",
"if",
"(",
"$",
"this",
"->",
"confirm",
"(",
"'Would you like to store your steak sources in a git repo?'",
")",
")",
"{",
"$",
"source",
"[",
"'directory'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Where should we check out the site sources <b>repository</b>?\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.directory'",
",",
"'steak'",
")",
")",
";",
"$",
"source",
"[",
"'git.url'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Enter the source repository URL:\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.git.url'",
")",
",",
"$",
"this",
"->",
"valueRequiredValidator",
"(",
")",
")",
";",
"$",
"source",
"[",
"'git.branch'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Specify the branch to use:\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.git.branch'",
",",
"'master'",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\" Okay, no git.\"",
")",
";",
"$",
"source",
"[",
"'directory'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Where to put the steak <b>source files</b>?\"",
",",
"$",
"config",
"->",
"get",
"(",
"'source.directory'",
",",
"'sources'",
")",
")",
";",
"}",
"}",
"return",
"$",
"source",
";",
"}"
]
| Get the config values related to steak sources.
@return array | [
"Get",
"the",
"config",
"values",
"related",
"to",
"steak",
"sources",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L134-L212 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.setupBuild | protected function setupBuild()
{
/** @var Repository $config */
$config = $this->container['config'];
$build = [];
$this->title('Build');
$build['directory'] = $this->ask("Where should we put the generated site files?", $config['build.directory']);
return $build;
} | php | protected function setupBuild()
{
/** @var Repository $config */
$config = $this->container['config'];
$build = [];
$this->title('Build');
$build['directory'] = $this->ask("Where should we put the generated site files?", $config['build.directory']);
return $build;
} | [
"protected",
"function",
"setupBuild",
"(",
")",
"{",
"/** @var Repository $config */",
"$",
"config",
"=",
"$",
"this",
"->",
"container",
"[",
"'config'",
"]",
";",
"$",
"build",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"title",
"(",
"'Build'",
")",
";",
"$",
"build",
"[",
"'directory'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Where should we put the generated site files?\"",
",",
"$",
"config",
"[",
"'build.directory'",
"]",
")",
";",
"return",
"$",
"build",
";",
"}"
]
| Get the config values related to the build process.
@return array | [
"Get",
"the",
"config",
"values",
"related",
"to",
"the",
"build",
"process",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L219-L231 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.setupDeploy | protected function setupDeploy()
{
/** @var Repository $config */
$config = $this->container['config'];
$this->title('Deployment via Git');
$deploy = [];
if ($this->confirm('Push the generated static site to a git repository?')) {
$deploy['git.url'] = $this->ask(
"Specify a destination repository for the <path>steak deploy</path> command to use:",
$config->get('deploy.git.url', $this->getPushUrl('.')),
$this->valueRequiredValidator()
);
$deploy['git.branch'] = $this->ask(
"Specify the branch to use:",
$config->get('deploy.git.branch', 'gh-pages')
);
} else {
$this->output->writeln([
" Okay, no problem, steak will not attempt deployments.",
" The <comment>steak deploy</comment> command will have no effect.",
]);
}
return $deploy;
} | php | protected function setupDeploy()
{
/** @var Repository $config */
$config = $this->container['config'];
$this->title('Deployment via Git');
$deploy = [];
if ($this->confirm('Push the generated static site to a git repository?')) {
$deploy['git.url'] = $this->ask(
"Specify a destination repository for the <path>steak deploy</path> command to use:",
$config->get('deploy.git.url', $this->getPushUrl('.')),
$this->valueRequiredValidator()
);
$deploy['git.branch'] = $this->ask(
"Specify the branch to use:",
$config->get('deploy.git.branch', 'gh-pages')
);
} else {
$this->output->writeln([
" Okay, no problem, steak will not attempt deployments.",
" The <comment>steak deploy</comment> command will have no effect.",
]);
}
return $deploy;
} | [
"protected",
"function",
"setupDeploy",
"(",
")",
"{",
"/** @var Repository $config */",
"$",
"config",
"=",
"$",
"this",
"->",
"container",
"[",
"'config'",
"]",
";",
"$",
"this",
"->",
"title",
"(",
"'Deployment via Git'",
")",
";",
"$",
"deploy",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"confirm",
"(",
"'Push the generated static site to a git repository?'",
")",
")",
"{",
"$",
"deploy",
"[",
"'git.url'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Specify a destination repository for the <path>steak deploy</path> command to use:\"",
",",
"$",
"config",
"->",
"get",
"(",
"'deploy.git.url'",
",",
"$",
"this",
"->",
"getPushUrl",
"(",
"'.'",
")",
")",
",",
"$",
"this",
"->",
"valueRequiredValidator",
"(",
")",
")",
";",
"$",
"deploy",
"[",
"'git.branch'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Specify the branch to use:\"",
",",
"$",
"config",
"->",
"get",
"(",
"'deploy.git.branch'",
",",
"'gh-pages'",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"[",
"\" Okay, no problem, steak will not attempt deployments.\"",
",",
"\" The <comment>steak deploy</comment> command will have no effect.\"",
",",
"]",
")",
";",
"}",
"return",
"$",
"deploy",
";",
"}"
]
| Get the config values related to deployment.
@return array | [
"Get",
"the",
"config",
"values",
"related",
"to",
"deployment",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L238-L270 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.setupGulp | protected function setupGulp()
{
/** @var Repository $config */
$config = $this->container['config'];
$this->title('Gulp');
$gulp = [];
$this->output->writeln([
"steak uses the gulp taskrunner to:",
" 1. publish non-PHP files from your source directory to the build directory with <comment>steak:publish</comment>",
" 2. run the local development server and rebuild the site on change with <comment>steak:serve</comment>",
]);
$gulp['file'] = $this->ask("Which gulpfile should steak use?", $config['gulp.file']);
return $gulp;
} | php | protected function setupGulp()
{
/** @var Repository $config */
$config = $this->container['config'];
$this->title('Gulp');
$gulp = [];
$this->output->writeln([
"steak uses the gulp taskrunner to:",
" 1. publish non-PHP files from your source directory to the build directory with <comment>steak:publish</comment>",
" 2. run the local development server and rebuild the site on change with <comment>steak:serve</comment>",
]);
$gulp['file'] = $this->ask("Which gulpfile should steak use?", $config['gulp.file']);
return $gulp;
} | [
"protected",
"function",
"setupGulp",
"(",
")",
"{",
"/** @var Repository $config */",
"$",
"config",
"=",
"$",
"this",
"->",
"container",
"[",
"'config'",
"]",
";",
"$",
"this",
"->",
"title",
"(",
"'Gulp'",
")",
";",
"$",
"gulp",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"[",
"\"steak uses the gulp taskrunner to:\"",
",",
"\" 1. publish non-PHP files from your source directory to the build directory with <comment>steak:publish</comment>\"",
",",
"\" 2. run the local development server and rebuild the site on change with <comment>steak:serve</comment>\"",
",",
"]",
")",
";",
"$",
"gulp",
"[",
"'file'",
"]",
"=",
"$",
"this",
"->",
"ask",
"(",
"\"Which gulpfile should steak use?\"",
",",
"$",
"config",
"[",
"'gulp.file'",
"]",
")",
";",
"return",
"$",
"gulp",
";",
"}"
]
| Get the config values related to gulp.
@return array | [
"Get",
"the",
"config",
"values",
"related",
"to",
"gulp",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L277-L295 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.setupServe | protected function setupServe(array $newConfig)
{
$newConfig = array_dot($newConfig);
if (array_get($newConfig, 'deploy.git.branch') != 'gh-pages') {
return [];
}
$this->title('Local development server');
$this->output->writeln([
"When you publish to github pages, your site is available from username.github.io/projectname",
"To help avoid problems with relative URLs, use a matching subdirectory for the local server.",
"",
]);
return [
'subdirectory' => $this->ask(
"Subdirectory to use for the <comment>steak serve</comment> command?",
$this->git->parseRepositoryName(array_get($newConfig, 'deploy.git.url'))
)
];
} | php | protected function setupServe(array $newConfig)
{
$newConfig = array_dot($newConfig);
if (array_get($newConfig, 'deploy.git.branch') != 'gh-pages') {
return [];
}
$this->title('Local development server');
$this->output->writeln([
"When you publish to github pages, your site is available from username.github.io/projectname",
"To help avoid problems with relative URLs, use a matching subdirectory for the local server.",
"",
]);
return [
'subdirectory' => $this->ask(
"Subdirectory to use for the <comment>steak serve</comment> command?",
$this->git->parseRepositoryName(array_get($newConfig, 'deploy.git.url'))
)
];
} | [
"protected",
"function",
"setupServe",
"(",
"array",
"$",
"newConfig",
")",
"{",
"$",
"newConfig",
"=",
"array_dot",
"(",
"$",
"newConfig",
")",
";",
"if",
"(",
"array_get",
"(",
"$",
"newConfig",
",",
"'deploy.git.branch'",
")",
"!=",
"'gh-pages'",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"title",
"(",
"'Local development server'",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"[",
"\"When you publish to github pages, your site is available from username.github.io/projectname\"",
",",
"\"To help avoid problems with relative URLs, use a matching subdirectory for the local server.\"",
",",
"\"\"",
",",
"]",
")",
";",
"return",
"[",
"'subdirectory'",
"=>",
"$",
"this",
"->",
"ask",
"(",
"\"Subdirectory to use for the <comment>steak serve</comment> command?\"",
",",
"$",
"this",
"->",
"git",
"->",
"parseRepositoryName",
"(",
"array_get",
"(",
"$",
"newConfig",
",",
"'deploy.git.url'",
")",
")",
")",
"]",
";",
"}"
]
| Get the config values related to the development server.
@param array $newConfig
@return array | [
"Get",
"the",
"config",
"values",
"related",
"to",
"the",
"development",
"server",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L303-L325 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.ask | protected function ask($question, $default = null, Closure $validator = null)
{
if ($default) {
$question .= " [$default]";
}
$question = new Question($question . "\n > ", $default);
if ($validator) {
$question->setValidator($validator);
}
return trim($this->getHelper('question')->ask($this->input, $this->output, $question));
} | php | protected function ask($question, $default = null, Closure $validator = null)
{
if ($default) {
$question .= " [$default]";
}
$question = new Question($question . "\n > ", $default);
if ($validator) {
$question->setValidator($validator);
}
return trim($this->getHelper('question')->ask($this->input, $this->output, $question));
} | [
"protected",
"function",
"ask",
"(",
"$",
"question",
",",
"$",
"default",
"=",
"null",
",",
"Closure",
"$",
"validator",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"default",
")",
"{",
"$",
"question",
".=",
"\" [$default]\"",
";",
"}",
"$",
"question",
"=",
"new",
"Question",
"(",
"$",
"question",
".",
"\"\\n > \"",
",",
"$",
"default",
")",
";",
"if",
"(",
"$",
"validator",
")",
"{",
"$",
"question",
"->",
"setValidator",
"(",
"$",
"validator",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"this",
"->",
"getHelper",
"(",
"'question'",
")",
"->",
"ask",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"this",
"->",
"output",
",",
"$",
"question",
")",
")",
";",
"}"
]
| Ask a question.
@param string $question
@param null|string $default
@param Closure $validator
@return string | [
"Ask",
"a",
"question",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L336-L349 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.confirm | protected function confirm($text, $default = true)
{
$choices = $default ? 'Yn' : 'yN';
$confirm = new ConfirmationQuestion("$text [$choices] ", $default);
return $this->getHelper('question')->ask($this->input, $this->output, $confirm);
} | php | protected function confirm($text, $default = true)
{
$choices = $default ? 'Yn' : 'yN';
$confirm = new ConfirmationQuestion("$text [$choices] ", $default);
return $this->getHelper('question')->ask($this->input, $this->output, $confirm);
} | [
"protected",
"function",
"confirm",
"(",
"$",
"text",
",",
"$",
"default",
"=",
"true",
")",
"{",
"$",
"choices",
"=",
"$",
"default",
"?",
"'Yn'",
":",
"'yN'",
";",
"$",
"confirm",
"=",
"new",
"ConfirmationQuestion",
"(",
"\"$text [$choices] \"",
",",
"$",
"default",
")",
";",
"return",
"$",
"this",
"->",
"getHelper",
"(",
"'question'",
")",
"->",
"ask",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"this",
"->",
"output",
",",
"$",
"confirm",
")",
";",
"}"
]
| Ask for user confirmation.
@param string $text
@param bool $default
@return bool | [
"Ask",
"for",
"user",
"confirmation",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L358-L364 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.select | protected function select($text, $choices, $default = null)
{
$question = new ChoiceQuestion($text, $choices, $default);
return $this->getHelper('question')->ask($this->input, $this->output, $question);
} | php | protected function select($text, $choices, $default = null)
{
$question = new ChoiceQuestion($text, $choices, $default);
return $this->getHelper('question')->ask($this->input, $this->output, $question);
} | [
"protected",
"function",
"select",
"(",
"$",
"text",
",",
"$",
"choices",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"question",
"=",
"new",
"ChoiceQuestion",
"(",
"$",
"text",
",",
"$",
"choices",
",",
"$",
"default",
")",
";",
"return",
"$",
"this",
"->",
"getHelper",
"(",
"'question'",
")",
"->",
"ask",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"this",
"->",
"output",
",",
"$",
"question",
")",
";",
"}"
]
| Ask user to choose from a list of options.
@param string $text
@param array $choices
@param mixed $default
@return mixed | [
"Ask",
"user",
"to",
"choose",
"from",
"a",
"list",
"of",
"options",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L374-L379 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.getPushUrl | protected function getPushUrl($dir, $throws = false)
{
try {
$remotes = $this->git->workingCopy($dir)->remote('show', 'origin', '-n')->getOutput();
if (preg_match('!Push\s*URL:\s*([^\s#]+)!', $remotes, $matches)) {
return $matches[1];
}
} catch (GitException $exception) {
if ($throws) {
throw $exception;
}
}
return null;
} | php | protected function getPushUrl($dir, $throws = false)
{
try {
$remotes = $this->git->workingCopy($dir)->remote('show', 'origin', '-n')->getOutput();
if (preg_match('!Push\s*URL:\s*([^\s#]+)!', $remotes, $matches)) {
return $matches[1];
}
} catch (GitException $exception) {
if ($throws) {
throw $exception;
}
}
return null;
} | [
"protected",
"function",
"getPushUrl",
"(",
"$",
"dir",
",",
"$",
"throws",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"remotes",
"=",
"$",
"this",
"->",
"git",
"->",
"workingCopy",
"(",
"$",
"dir",
")",
"->",
"remote",
"(",
"'show'",
",",
"'origin'",
",",
"'-n'",
")",
"->",
"getOutput",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'!Push\\s*URL:\\s*([^\\s#]+)!'",
",",
"$",
"remotes",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
"catch",
"(",
"GitException",
"$",
"exception",
")",
"{",
"if",
"(",
"$",
"throws",
")",
"{",
"throw",
"$",
"exception",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Get the origin's push URL.
@param string $dir
@param bool $throws
@return null|string | [
"Get",
"the",
"origin",
"s",
"push",
"URL",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L399-L414 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.createYaml | protected function createYaml(array $config)
{
$nested = [];
array_walk(array_dot($config), function ($value, $key) use (&$nested) {
array_set($nested, $key, $value);
});
return $this->yaml->dump($nested, 4);
} | php | protected function createYaml(array $config)
{
$nested = [];
array_walk(array_dot($config), function ($value, $key) use (&$nested) {
array_set($nested, $key, $value);
});
return $this->yaml->dump($nested, 4);
} | [
"protected",
"function",
"createYaml",
"(",
"array",
"$",
"config",
")",
"{",
"$",
"nested",
"=",
"[",
"]",
";",
"array_walk",
"(",
"array_dot",
"(",
"$",
"config",
")",
",",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"&",
"$",
"nested",
")",
"{",
"array_set",
"(",
"$",
"nested",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"yaml",
"->",
"dump",
"(",
"$",
"nested",
",",
"4",
")",
";",
"}"
]
| Create a YML string from a dotted array.
@param array $config
@return string | [
"Create",
"a",
"YML",
"string",
"from",
"a",
"dotted",
"array",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L422-L431 |
parsnick/steak | src/Console/InitCommand.php | InitCommand.dirExists | protected function dirExists($dir)
{
if ($this->files->exists($dir)) {
if ( ! $this->files->isDirectory($dir)) {
throw new RuntimeException("The given directory [$dir] is not a directory.");
}
return true;
}
return false;
} | php | protected function dirExists($dir)
{
if ($this->files->exists($dir)) {
if ( ! $this->files->isDirectory($dir)) {
throw new RuntimeException("The given directory [$dir] is not a directory.");
}
return true;
}
return false;
} | [
"protected",
"function",
"dirExists",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"files",
"->",
"isDirectory",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The given directory [$dir] is not a directory.\"",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Check if a directory exists.
@param string $dir
@return bool | [
"Check",
"if",
"a",
"directory",
"exists",
"."
]
| train | https://github.com/parsnick/steak/blob/461869189a640938438187330f6c50aca97c5ccc/src/Console/InitCommand.php#L440-L452 |
koriym/Koriym.QueryLocator | src/QueryLocator.php | QueryLocator.get | public function get(string $queryName) : string
{
$sqlFile = sprintf(
'%s/%s.sql',
$this->sqlDir,
$queryName
);
return trim($this->getFileContents($sqlFile));
} | php | public function get(string $queryName) : string
{
$sqlFile = sprintf(
'%s/%s.sql',
$this->sqlDir,
$queryName
);
return trim($this->getFileContents($sqlFile));
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"queryName",
")",
":",
"string",
"{",
"$",
"sqlFile",
"=",
"sprintf",
"(",
"'%s/%s.sql'",
",",
"$",
"this",
"->",
"sqlDir",
",",
"$",
"queryName",
")",
";",
"return",
"trim",
"(",
"$",
"this",
"->",
"getFileContents",
"(",
"$",
"sqlFile",
")",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/koriym/Koriym.QueryLocator/blob/4e9b9ecfdd99c4850e39e88204a597af503c3823/src/QueryLocator.php#L27-L36 |
koriym/Koriym.QueryLocator | src/QueryLocator.php | QueryLocator.rewriteCountQuery | private function rewriteCountQuery(string $sql) : string
{
if (preg_match('/^\s*SELECT\s+\bDISTINCT\b/is', $sql) || preg_match('/\s+GROUP\s+BY\s+/is', $sql)) {
throw new CountQueryException($sql);
}
$openParenthesis = '(?:\()';
$closeParenthesis = '(?:\))';
$subQueryInSelect = $openParenthesis . '.*\bFROM\b.*' . $closeParenthesis;
$pattern = '/(?:.*' . $subQueryInSelect . '.*)\bFROM\b\s+/Uims';
if (preg_match($pattern, $sql)) {
throw new CountQueryException($sql);
}
$subQueryWithLimitOrder = $openParenthesis . '.*\b(LIMIT|ORDER)\b.*' . $closeParenthesis;
$pattern = '/.*\bFROM\b.*(?:.*' . $subQueryWithLimitOrder . '.*).*/Uims';
if (preg_match($pattern, $sql)) {
throw new CountQueryException($sql);
}
$queryCount = preg_replace('/(?:.*)\bFROM\b\s+/Uims', 'SELECT COUNT(*) FROM ', $sql, 1);
if (! is_string($queryCount)) {
throw new CountQueryException($sql);
}
list($queryCount) = preg_split('/\s+ORDER\s+BY\s+/is', $queryCount);
if (! is_string($queryCount)) {
throw new CountQueryException($sql);
}
list($queryCount) = preg_split('/\bLIMIT\b/is', $queryCount);
if (! is_string($queryCount)) {
throw new CountQueryException($sql);
}
return trim($queryCount);
} | php | private function rewriteCountQuery(string $sql) : string
{
if (preg_match('/^\s*SELECT\s+\bDISTINCT\b/is', $sql) || preg_match('/\s+GROUP\s+BY\s+/is', $sql)) {
throw new CountQueryException($sql);
}
$openParenthesis = '(?:\()';
$closeParenthesis = '(?:\))';
$subQueryInSelect = $openParenthesis . '.*\bFROM\b.*' . $closeParenthesis;
$pattern = '/(?:.*' . $subQueryInSelect . '.*)\bFROM\b\s+/Uims';
if (preg_match($pattern, $sql)) {
throw new CountQueryException($sql);
}
$subQueryWithLimitOrder = $openParenthesis . '.*\b(LIMIT|ORDER)\b.*' . $closeParenthesis;
$pattern = '/.*\bFROM\b.*(?:.*' . $subQueryWithLimitOrder . '.*).*/Uims';
if (preg_match($pattern, $sql)) {
throw new CountQueryException($sql);
}
$queryCount = preg_replace('/(?:.*)\bFROM\b\s+/Uims', 'SELECT COUNT(*) FROM ', $sql, 1);
if (! is_string($queryCount)) {
throw new CountQueryException($sql);
}
list($queryCount) = preg_split('/\s+ORDER\s+BY\s+/is', $queryCount);
if (! is_string($queryCount)) {
throw new CountQueryException($sql);
}
list($queryCount) = preg_split('/\bLIMIT\b/is', $queryCount);
if (! is_string($queryCount)) {
throw new CountQueryException($sql);
}
return trim($queryCount);
} | [
"private",
"function",
"rewriteCountQuery",
"(",
"string",
"$",
"sql",
")",
":",
"string",
"{",
"if",
"(",
"preg_match",
"(",
"'/^\\s*SELECT\\s+\\bDISTINCT\\b/is'",
",",
"$",
"sql",
")",
"||",
"preg_match",
"(",
"'/\\s+GROUP\\s+BY\\s+/is'",
",",
"$",
"sql",
")",
")",
"{",
"throw",
"new",
"CountQueryException",
"(",
"$",
"sql",
")",
";",
"}",
"$",
"openParenthesis",
"=",
"'(?:\\()'",
";",
"$",
"closeParenthesis",
"=",
"'(?:\\))'",
";",
"$",
"subQueryInSelect",
"=",
"$",
"openParenthesis",
".",
"'.*\\bFROM\\b.*'",
".",
"$",
"closeParenthesis",
";",
"$",
"pattern",
"=",
"'/(?:.*'",
".",
"$",
"subQueryInSelect",
".",
"'.*)\\bFROM\\b\\s+/Uims'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"sql",
")",
")",
"{",
"throw",
"new",
"CountQueryException",
"(",
"$",
"sql",
")",
";",
"}",
"$",
"subQueryWithLimitOrder",
"=",
"$",
"openParenthesis",
".",
"'.*\\b(LIMIT|ORDER)\\b.*'",
".",
"$",
"closeParenthesis",
";",
"$",
"pattern",
"=",
"'/.*\\bFROM\\b.*(?:.*'",
".",
"$",
"subQueryWithLimitOrder",
".",
"'.*).*/Uims'",
";",
"if",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"sql",
")",
")",
"{",
"throw",
"new",
"CountQueryException",
"(",
"$",
"sql",
")",
";",
"}",
"$",
"queryCount",
"=",
"preg_replace",
"(",
"'/(?:.*)\\bFROM\\b\\s+/Uims'",
",",
"'SELECT COUNT(*) FROM '",
",",
"$",
"sql",
",",
"1",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"queryCount",
")",
")",
"{",
"throw",
"new",
"CountQueryException",
"(",
"$",
"sql",
")",
";",
"}",
"list",
"(",
"$",
"queryCount",
")",
"=",
"preg_split",
"(",
"'/\\s+ORDER\\s+BY\\s+/is'",
",",
"$",
"queryCount",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"queryCount",
")",
")",
"{",
"throw",
"new",
"CountQueryException",
"(",
"$",
"sql",
")",
";",
"}",
"list",
"(",
"$",
"queryCount",
")",
"=",
"preg_split",
"(",
"'/\\bLIMIT\\b/is'",
",",
"$",
"queryCount",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"queryCount",
")",
")",
"{",
"throw",
"new",
"CountQueryException",
"(",
"$",
"sql",
")",
";",
"}",
"return",
"trim",
"(",
"$",
"queryCount",
")",
";",
"}"
]
| Return count query
@see https://github.com/pear/Pager/blob/master/examples/Pager_Wrapper.php
Taken from pear/pager and modified.
tested at https://github.com/pear/Pager/blob/80c0e31c8b94f913cfbdeccbe83b63822f42a2f8/tests/pager_wrapper_test.php#L19
@codeCoverageIgnore | [
"Return",
"count",
"query"
]
| train | https://github.com/koriym/Koriym.QueryLocator/blob/4e9b9ecfdd99c4850e39e88204a597af503c3823/src/QueryLocator.php#L86-L117 |
ondrakoupil/tools | src/Url.php | Url.builder | static function builder($params, $originalUrl, $clear=false, $clearArrays=true, $keepEntities = array()) {
$origParams=array();
if (!$clear) {
$query=parse_url($originalUrl,PHP_URL_QUERY);
if ($query) {
parse_str($query, $origParams);
}
if (!$origParams) {
$origParams=array();
}
}
if ($clearArrays) {
$finalParams=array_merge($origParams,$params);
} else {
$finalParams=array_replace_recursive($origParams,$params);
}
foreach($finalParams as $i=>$r) {
if ($r===null) unset($finalParams[$i]);
}
$casti=array();
foreach($finalParams as $i=>$p) {
if (is_array($p)) {
foreach($p as $pi=>$pp) {
$casti[]=$i."[".urlencode($pi)."]=".urlencode($pp);
}
} else {
$casti[]=$i."=".urlencode($p);
}
}
if (Strings::strpos($originalUrl,"?")!==false) {
$zaklad=Strings::substr($originalUrl,0,Strings::strpos($originalUrl,"?"));
} else {
$zaklad=$originalUrl;
}
$vrat=$zaklad;
if ($casti) $vrat.="?".implode("&",$casti);
if ($keepEntities) {
foreach(Arrays::arrayize($keepEntities) as $ent) {
$entEncoded = urlencode($ent);
$vrat = str_replace($entEncoded, $ent, $vrat);
}
}
return $vrat;
} | php | static function builder($params, $originalUrl, $clear=false, $clearArrays=true, $keepEntities = array()) {
$origParams=array();
if (!$clear) {
$query=parse_url($originalUrl,PHP_URL_QUERY);
if ($query) {
parse_str($query, $origParams);
}
if (!$origParams) {
$origParams=array();
}
}
if ($clearArrays) {
$finalParams=array_merge($origParams,$params);
} else {
$finalParams=array_replace_recursive($origParams,$params);
}
foreach($finalParams as $i=>$r) {
if ($r===null) unset($finalParams[$i]);
}
$casti=array();
foreach($finalParams as $i=>$p) {
if (is_array($p)) {
foreach($p as $pi=>$pp) {
$casti[]=$i."[".urlencode($pi)."]=".urlencode($pp);
}
} else {
$casti[]=$i."=".urlencode($p);
}
}
if (Strings::strpos($originalUrl,"?")!==false) {
$zaklad=Strings::substr($originalUrl,0,Strings::strpos($originalUrl,"?"));
} else {
$zaklad=$originalUrl;
}
$vrat=$zaklad;
if ($casti) $vrat.="?".implode("&",$casti);
if ($keepEntities) {
foreach(Arrays::arrayize($keepEntities) as $ent) {
$entEncoded = urlencode($ent);
$vrat = str_replace($entEncoded, $ent, $vrat);
}
}
return $vrat;
} | [
"static",
"function",
"builder",
"(",
"$",
"params",
",",
"$",
"originalUrl",
",",
"$",
"clear",
"=",
"false",
",",
"$",
"clearArrays",
"=",
"true",
",",
"$",
"keepEntities",
"=",
"array",
"(",
")",
")",
"{",
"$",
"origParams",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"clear",
")",
"{",
"$",
"query",
"=",
"parse_url",
"(",
"$",
"originalUrl",
",",
"PHP_URL_QUERY",
")",
";",
"if",
"(",
"$",
"query",
")",
"{",
"parse_str",
"(",
"$",
"query",
",",
"$",
"origParams",
")",
";",
"}",
"if",
"(",
"!",
"$",
"origParams",
")",
"{",
"$",
"origParams",
"=",
"array",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"clearArrays",
")",
"{",
"$",
"finalParams",
"=",
"array_merge",
"(",
"$",
"origParams",
",",
"$",
"params",
")",
";",
"}",
"else",
"{",
"$",
"finalParams",
"=",
"array_replace_recursive",
"(",
"$",
"origParams",
",",
"$",
"params",
")",
";",
"}",
"foreach",
"(",
"$",
"finalParams",
"as",
"$",
"i",
"=>",
"$",
"r",
")",
"{",
"if",
"(",
"$",
"r",
"===",
"null",
")",
"unset",
"(",
"$",
"finalParams",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"casti",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"finalParams",
"as",
"$",
"i",
"=>",
"$",
"p",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"p",
")",
")",
"{",
"foreach",
"(",
"$",
"p",
"as",
"$",
"pi",
"=>",
"$",
"pp",
")",
"{",
"$",
"casti",
"[",
"]",
"=",
"$",
"i",
".",
"\"[\"",
".",
"urlencode",
"(",
"$",
"pi",
")",
".",
"\"]=\"",
".",
"urlencode",
"(",
"$",
"pp",
")",
";",
"}",
"}",
"else",
"{",
"$",
"casti",
"[",
"]",
"=",
"$",
"i",
".",
"\"=\"",
".",
"urlencode",
"(",
"$",
"p",
")",
";",
"}",
"}",
"if",
"(",
"Strings",
"::",
"strpos",
"(",
"$",
"originalUrl",
",",
"\"?\"",
")",
"!==",
"false",
")",
"{",
"$",
"zaklad",
"=",
"Strings",
"::",
"substr",
"(",
"$",
"originalUrl",
",",
"0",
",",
"Strings",
"::",
"strpos",
"(",
"$",
"originalUrl",
",",
"\"?\"",
")",
")",
";",
"}",
"else",
"{",
"$",
"zaklad",
"=",
"$",
"originalUrl",
";",
"}",
"$",
"vrat",
"=",
"$",
"zaklad",
";",
"if",
"(",
"$",
"casti",
")",
"$",
"vrat",
".=",
"\"?\"",
".",
"implode",
"(",
"\"&\"",
",",
"$",
"casti",
")",
";",
"if",
"(",
"$",
"keepEntities",
")",
"{",
"foreach",
"(",
"Arrays",
"::",
"arrayize",
"(",
"$",
"keepEntities",
")",
"as",
"$",
"ent",
")",
"{",
"$",
"entEncoded",
"=",
"urlencode",
"(",
"$",
"ent",
")",
";",
"$",
"vrat",
"=",
"str_replace",
"(",
"$",
"entEncoded",
",",
"$",
"ent",
",",
"$",
"vrat",
")",
";",
"}",
"}",
"return",
"$",
"vrat",
";",
"}"
]
| Pomůcka pro sestavení adresy s GET parametry.
@param array $params Asociativní pole [název-parametru] => hodnota-parametru. Null pro odstranění daného parametru, byl-li tam.
Hodnota může být array, pak se automaticky převede na několik samostatných parametrů ve tvaru název-parametru[]
@param string $originalUrl Původní adresa
@param bool $clear True = všechny GET parametry z $original URL vyhodit a pouze přidávat ty z $params
@param bool $clearArrays Jak se má chovat, když v $originalUrl je nějaký parametr - pole (s [] na konci) a v $params také.
False = sloučit obě pole. True = smazat to z $originalUrl a nechat jen hodnoty z $params.
@param array $keepEntities Array entit, které se nemají enkódovat (např. %id%)
@return string | [
"Pomůcka",
"pro",
"sestavení",
"adresy",
"s",
"GET",
"parametry",
"."
]
| train | https://github.com/ondrakoupil/tools/blob/7ecbe3652e379802fbaabf4fe8f27b96dcbadb22/src/Url.php#L18-L69 |
simple-php-mvc/simple-php-mvc | src/MVC/Sessions/Session.php | Session.set | public function set($name, $value)
{
if (!$this->has($name)) {
$this->vars[$name] = $value;
} else {
return false;
}
} | php | public function set($name, $value)
{
if (!$this->has($name)) {
$this->vars[$name] = $value;
} else {
return false;
}
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"vars",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Set var session
@access public
@param string $name
@param mixed $value
@return bool | [
"Set",
"var",
"session"
]
| train | https://github.com/simple-php-mvc/simple-php-mvc/blob/e319eb09d29afad6993acb4a7e35f32a87dd0841/src/MVC/Sessions/Session.php#L111-L118 |
dms-org/package.blog | src/Domain/Services/Comment/BlogArticleCommentingService.php | BlogArticleCommentingService.postComment | public function postComment(int $blogArticleId, string $authorName, EmailAddress $authorEmail, string $comment): BlogArticleComment
{
$blogArticle = $this->blogArticleRepo->get($blogArticleId);
$comment = $blogArticle->postComment($authorName, $authorEmail, $comment, $this->clock);
$this->blogArticleRepo->save($blogArticle);
return $comment;
} | php | public function postComment(int $blogArticleId, string $authorName, EmailAddress $authorEmail, string $comment): BlogArticleComment
{
$blogArticle = $this->blogArticleRepo->get($blogArticleId);
$comment = $blogArticle->postComment($authorName, $authorEmail, $comment, $this->clock);
$this->blogArticleRepo->save($blogArticle);
return $comment;
} | [
"public",
"function",
"postComment",
"(",
"int",
"$",
"blogArticleId",
",",
"string",
"$",
"authorName",
",",
"EmailAddress",
"$",
"authorEmail",
",",
"string",
"$",
"comment",
")",
":",
"BlogArticleComment",
"{",
"$",
"blogArticle",
"=",
"$",
"this",
"->",
"blogArticleRepo",
"->",
"get",
"(",
"$",
"blogArticleId",
")",
";",
"$",
"comment",
"=",
"$",
"blogArticle",
"->",
"postComment",
"(",
"$",
"authorName",
",",
"$",
"authorEmail",
",",
"$",
"comment",
",",
"$",
"this",
"->",
"clock",
")",
";",
"$",
"this",
"->",
"blogArticleRepo",
"->",
"save",
"(",
"$",
"blogArticle",
")",
";",
"return",
"$",
"comment",
";",
"}"
]
| @param int $blogArticleId
@param string $authorName
@param EmailAddress $authorEmail
@param string $comment
@return BlogArticleComment | [
"@param",
"int",
"$blogArticleId",
"@param",
"string",
"$authorName",
"@param",
"EmailAddress",
"$authorEmail",
"@param",
"string",
"$comment"
]
| train | https://github.com/dms-org/package.blog/blob/1500f6fad20d81289a0dfa617fc1c54699f01e16/src/Domain/Services/Comment/BlogArticleCommentingService.php#L45-L54 |
nyeholt/silverstripe-external-content | thirdparty/Zend/Validate/File/WordCount.php | Zend_Validate_File_WordCount.isValid | public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
$content = file_get_contents($value);
$this->_count = str_word_count($content);
if (($this->_max !== null) && ($this->_count > $this->_max)) {
return $this->_throw($file, self::TOO_MUCH);
}
if (($this->_min !== null) && ($this->_count < $this->_min)) {
return $this->_throw($file, self::TOO_LESS);
}
return true;
} | php | public function isValid($value, $file = null)
{
// Is file readable ?
require_once 'Zend/Loader.php';
if (!Zend_Loader::isReadable($value)) {
return $this->_throw($file, self::NOT_FOUND);
}
$content = file_get_contents($value);
$this->_count = str_word_count($content);
if (($this->_max !== null) && ($this->_count > $this->_max)) {
return $this->_throw($file, self::TOO_MUCH);
}
if (($this->_min !== null) && ($this->_count < $this->_min)) {
return $this->_throw($file, self::TOO_LESS);
}
return true;
} | [
"public",
"function",
"isValid",
"(",
"$",
"value",
",",
"$",
"file",
"=",
"null",
")",
"{",
"// Is file readable ?",
"require_once",
"'Zend/Loader.php'",
";",
"if",
"(",
"!",
"Zend_Loader",
"::",
"isReadable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_throw",
"(",
"$",
"file",
",",
"self",
"::",
"NOT_FOUND",
")",
";",
"}",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"_count",
"=",
"str_word_count",
"(",
"$",
"content",
")",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"_max",
"!==",
"null",
")",
"&&",
"(",
"$",
"this",
"->",
"_count",
">",
"$",
"this",
"->",
"_max",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_throw",
"(",
"$",
"file",
",",
"self",
"::",
"TOO_MUCH",
")",
";",
"}",
"if",
"(",
"(",
"$",
"this",
"->",
"_min",
"!==",
"null",
")",
"&&",
"(",
"$",
"this",
"->",
"_count",
"<",
"$",
"this",
"->",
"_min",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_throw",
"(",
"$",
"file",
",",
"self",
"::",
"TOO_LESS",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Defined by Zend_Validate_Interface
Returns true if and only if the counted words are at least min and
not bigger than max (when max is not null).
@param string $value Filename to check for word count
@param array $file File data from Zend_File_Transfer
@return boolean | [
"Defined",
"by",
"Zend_Validate_Interface"
]
| train | https://github.com/nyeholt/silverstripe-external-content/blob/1c6da8c56ef717225ff904e1522aff94ed051601/thirdparty/Zend/Validate/File/WordCount.php#L64-L83 |
xinix-technology/norm | src/Norm/Cursor/PDOCursor.php | PDOCursor.count | public function count($foundOnly = false)
{
$data = array();
$sql = $this->connection->getDialect()->grammarCount($this, $foundOnly, $data);
$statement = $this->connection->getRaw()->prepare($sql);
$statement->execute($data);
$count = $statement->fetch(PDO::FETCH_OBJ)->c;
return intval($count);
} | php | public function count($foundOnly = false)
{
$data = array();
$sql = $this->connection->getDialect()->grammarCount($this, $foundOnly, $data);
$statement = $this->connection->getRaw()->prepare($sql);
$statement->execute($data);
$count = $statement->fetch(PDO::FETCH_OBJ)->c;
return intval($count);
} | [
"public",
"function",
"count",
"(",
"$",
"foundOnly",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"connection",
"->",
"getDialect",
"(",
")",
"->",
"grammarCount",
"(",
"$",
"this",
",",
"$",
"foundOnly",
",",
"$",
"data",
")",
";",
"$",
"statement",
"=",
"$",
"this",
"->",
"connection",
"->",
"getRaw",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"statement",
"->",
"execute",
"(",
"$",
"data",
")",
";",
"$",
"count",
"=",
"$",
"statement",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_OBJ",
")",
"->",
"c",
";",
"return",
"intval",
"(",
"$",
"count",
")",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/PDOCursor.php#L41-L53 |
xinix-technology/norm | src/Norm/Cursor/PDOCursor.php | PDOCursor.next | public function next()
{
// Try to get the next element in our data buffer.
$this->next = each($this->buffer);
// Past the end of the data buffer
if (false === $this->next) {
// Fetch the next row of data
$row = $this->getStatement()->fetch(PDO::FETCH_ASSOC);
// Fetch successful
if ($row) {
// Add row to data buffer
$this->buffer[] = $row;
}
$this->next = each($this->buffer);
}
} | php | public function next()
{
// Try to get the next element in our data buffer.
$this->next = each($this->buffer);
// Past the end of the data buffer
if (false === $this->next) {
// Fetch the next row of data
$row = $this->getStatement()->fetch(PDO::FETCH_ASSOC);
// Fetch successful
if ($row) {
// Add row to data buffer
$this->buffer[] = $row;
}
$this->next = each($this->buffer);
}
} | [
"public",
"function",
"next",
"(",
")",
"{",
"// Try to get the next element in our data buffer.",
"$",
"this",
"->",
"next",
"=",
"each",
"(",
"$",
"this",
"->",
"buffer",
")",
";",
"// Past the end of the data buffer",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"next",
")",
"{",
"// Fetch the next row of data",
"$",
"row",
"=",
"$",
"this",
"->",
"getStatement",
"(",
")",
"->",
"fetch",
"(",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"// Fetch successful",
"if",
"(",
"$",
"row",
")",
"{",
"// Add row to data buffer",
"$",
"this",
"->",
"buffer",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"$",
"this",
"->",
"next",
"=",
"each",
"(",
"$",
"this",
"->",
"buffer",
")",
";",
"}",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/PDOCursor.php#L82-L100 |
xinix-technology/norm | src/Norm/Cursor/PDOCursor.php | PDOCursor.getStatement | public function getStatement($type = null)
{
if (is_null($this->statement)) {
$this->buffer = array();
$this->next = false;
$sql = "SELECT * FROM {$this->connection->getDialect()->grammarEscape($this->collection->getName())}";
$wheres = array();
$data = array();
foreach ($this->criteria as $key => $value) {
$wheres[] = $a= $this->connection->getDialect()->grammarExpression(
$key,
$value,
$this->collection,
$data
);
}
if (!empty($wheres)) {
$sql .= ' WHERE '.implode(' AND ', $wheres);
}
if (isset($this->sorts)) {
$sorts = array();
foreach ($this->sorts as $key => $value) {
if ($value == 1) {
$op = ' ASC';
} else {
$op = ' DESC';
}
$sorts[] = $this->connection->getDialect()->grammarEscape($key).$op;
}
if (!empty($sorts)) {
$sql .= ' ORDER BY '.implode(',', $sorts);
}
}
if (isset($this->limit) || isset($this->skip)) {
$sql .= ' LIMIT '.($this->limit ?: -1).' OFFSET '.($this->skip ?: 0);
}
$this->statement = $this->connection->getRaw()->prepare($sql);
$this->statement->execute($data);
}
return $this->statement;
} | php | public function getStatement($type = null)
{
if (is_null($this->statement)) {
$this->buffer = array();
$this->next = false;
$sql = "SELECT * FROM {$this->connection->getDialect()->grammarEscape($this->collection->getName())}";
$wheres = array();
$data = array();
foreach ($this->criteria as $key => $value) {
$wheres[] = $a= $this->connection->getDialect()->grammarExpression(
$key,
$value,
$this->collection,
$data
);
}
if (!empty($wheres)) {
$sql .= ' WHERE '.implode(' AND ', $wheres);
}
if (isset($this->sorts)) {
$sorts = array();
foreach ($this->sorts as $key => $value) {
if ($value == 1) {
$op = ' ASC';
} else {
$op = ' DESC';
}
$sorts[] = $this->connection->getDialect()->grammarEscape($key).$op;
}
if (!empty($sorts)) {
$sql .= ' ORDER BY '.implode(',', $sorts);
}
}
if (isset($this->limit) || isset($this->skip)) {
$sql .= ' LIMIT '.($this->limit ?: -1).' OFFSET '.($this->skip ?: 0);
}
$this->statement = $this->connection->getRaw()->prepare($sql);
$this->statement->execute($data);
}
return $this->statement;
} | [
"public",
"function",
"getStatement",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"statement",
")",
")",
"{",
"$",
"this",
"->",
"buffer",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"next",
"=",
"false",
";",
"$",
"sql",
"=",
"\"SELECT * FROM {$this->connection->getDialect()->grammarEscape($this->collection->getName())}\"",
";",
"$",
"wheres",
"=",
"array",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"criteria",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"wheres",
"[",
"]",
"=",
"$",
"a",
"=",
"$",
"this",
"->",
"connection",
"->",
"getDialect",
"(",
")",
"->",
"grammarExpression",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"this",
"->",
"collection",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"wheres",
")",
")",
"{",
"$",
"sql",
".=",
"' WHERE '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"wheres",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"sorts",
")",
")",
"{",
"$",
"sorts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"sorts",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"1",
")",
"{",
"$",
"op",
"=",
"' ASC'",
";",
"}",
"else",
"{",
"$",
"op",
"=",
"' DESC'",
";",
"}",
"$",
"sorts",
"[",
"]",
"=",
"$",
"this",
"->",
"connection",
"->",
"getDialect",
"(",
")",
"->",
"grammarEscape",
"(",
"$",
"key",
")",
".",
"$",
"op",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"sorts",
")",
")",
"{",
"$",
"sql",
".=",
"' ORDER BY '",
".",
"implode",
"(",
"','",
",",
"$",
"sorts",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"limit",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"skip",
")",
")",
"{",
"$",
"sql",
".=",
"' LIMIT '",
".",
"(",
"$",
"this",
"->",
"limit",
"?",
":",
"-",
"1",
")",
".",
"' OFFSET '",
".",
"(",
"$",
"this",
"->",
"skip",
"?",
":",
"0",
")",
";",
"}",
"$",
"this",
"->",
"statement",
"=",
"$",
"this",
"->",
"connection",
"->",
"getRaw",
"(",
")",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"statement",
"->",
"execute",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"this",
"->",
"statement",
";",
"}"
]
| Get query statement of current cursor.
@param mixed $type
@return \PDOStatement | [
"Get",
"query",
"statement",
"of",
"current",
"cursor",
"."
]
| train | https://github.com/xinix-technology/norm/blob/c357f7d3a75d05324dd84b8f6a968a094c53d603/src/Norm/Cursor/PDOCursor.php#L135-L188 |
ClanCats/Core | src/console/shipyard.php | shipyard.action_class | public function action_class( $params )
{
$options = \CCDataObject::assign( $params );
$name = $options->get( 0, null );
// get name if we dont have one
while( !$name )
{
$name = $this->read( 'Please enter the class name: ' );
}
// try to resolve the path
if ( !$path = \CCPath::classes( str_replace( '_', '/', $name ), EXT ) )
{
$this->error( 'Could not resolve the path. Check if the namespace is registered.' ); return;
}
// create the class
$class = \CCShipyard::create( 'class', $name, $options->get( 'extends', null ), explode( ',', $options->get( 'implements', null ) ) );
// add static init
if ( !$options->get( 'no-init', false ) )
{
$class->add( 'function', '_init', 'public static', '//', "static class initialisation\n@return void" );
}
// check for overwrite
if ( file_exists( $path ) )
{
if ( !$this->confirm( "The class already exists. Do you wish to overwrite it?", true ) )
{
return;
}
}
// write file
\CCFile::write( $path, $class->output() );
} | php | public function action_class( $params )
{
$options = \CCDataObject::assign( $params );
$name = $options->get( 0, null );
// get name if we dont have one
while( !$name )
{
$name = $this->read( 'Please enter the class name: ' );
}
// try to resolve the path
if ( !$path = \CCPath::classes( str_replace( '_', '/', $name ), EXT ) )
{
$this->error( 'Could not resolve the path. Check if the namespace is registered.' ); return;
}
// create the class
$class = \CCShipyard::create( 'class', $name, $options->get( 'extends', null ), explode( ',', $options->get( 'implements', null ) ) );
// add static init
if ( !$options->get( 'no-init', false ) )
{
$class->add( 'function', '_init', 'public static', '//', "static class initialisation\n@return void" );
}
// check for overwrite
if ( file_exists( $path ) )
{
if ( !$this->confirm( "The class already exists. Do you wish to overwrite it?", true ) )
{
return;
}
}
// write file
\CCFile::write( $path, $class->output() );
} | [
"public",
"function",
"action_class",
"(",
"$",
"params",
")",
"{",
"$",
"options",
"=",
"\\",
"CCDataObject",
"::",
"assign",
"(",
"$",
"params",
")",
";",
"$",
"name",
"=",
"$",
"options",
"->",
"get",
"(",
"0",
",",
"null",
")",
";",
"// get name if we dont have one",
"while",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"read",
"(",
"'Please enter the class name: '",
")",
";",
"}",
"// try to resolve the path",
"if",
"(",
"!",
"$",
"path",
"=",
"\\",
"CCPath",
"::",
"classes",
"(",
"str_replace",
"(",
"'_'",
",",
"'/'",
",",
"$",
"name",
")",
",",
"EXT",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Could not resolve the path. Check if the namespace is registered.'",
")",
";",
"return",
";",
"}",
"// create the class",
"$",
"class",
"=",
"\\",
"CCShipyard",
"::",
"create",
"(",
"'class'",
",",
"$",
"name",
",",
"$",
"options",
"->",
"get",
"(",
"'extends'",
",",
"null",
")",
",",
"explode",
"(",
"','",
",",
"$",
"options",
"->",
"get",
"(",
"'implements'",
",",
"null",
")",
")",
")",
";",
"// add static init",
"if",
"(",
"!",
"$",
"options",
"->",
"get",
"(",
"'no-init'",
",",
"false",
")",
")",
"{",
"$",
"class",
"->",
"add",
"(",
"'function'",
",",
"'_init'",
",",
"'public static'",
",",
"'//'",
",",
"\"static class initialisation\\n@return void\"",
")",
";",
"}",
"// check for overwrite",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"confirm",
"(",
"\"The class already exists. Do you wish to overwrite it?\"",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"}",
"// write file",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"path",
",",
"$",
"class",
"->",
"output",
"(",
")",
")",
";",
"}"
]
| generate an class
exmample:
run shipyard::class <class>
run shipyard::class <namespace>::<class>
@param array $params
@return void | [
"generate",
"an",
"class"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/shipyard.php#L88-L126 |
ClanCats/Core | src/console/shipyard.php | shipyard.action_model | public function action_model( $params )
{
$options = \CCDataObject::assign( $params );
// params
$name = $options->get( 0, null );
$table = $options->get( 1, null );
// get name if we dont have one
while( !$name )
{
$name = $this->read( 'Please enter the class name: ' );
}
// get table if we dont have one
while( !$table )
{
$table = $this->read( 'Please enter the table name: ' );
}
// resolve the path
if ( !$path = \CCPath::classes( str_replace( '_', '/', $name ), EXT ) )
{
$this->error( 'Could not resolve the path. Check if the namespace is registered.' ); return;
}
// create the class
$model = \CCShipyard::create( 'dbmodel', $name, $table );
// auto timestamps
$model->timestamps( $options->get( 'timestamps', false ) );
// check before
if ( file_exists( $path ) )
{
if ( !CCCli::confirm( "The class already exists. Do you wish to overwrite it?", true ) )
{
return;
}
}
// write file
\CCFile::write( $path, $model->output() );
} | php | public function action_model( $params )
{
$options = \CCDataObject::assign( $params );
// params
$name = $options->get( 0, null );
$table = $options->get( 1, null );
// get name if we dont have one
while( !$name )
{
$name = $this->read( 'Please enter the class name: ' );
}
// get table if we dont have one
while( !$table )
{
$table = $this->read( 'Please enter the table name: ' );
}
// resolve the path
if ( !$path = \CCPath::classes( str_replace( '_', '/', $name ), EXT ) )
{
$this->error( 'Could not resolve the path. Check if the namespace is registered.' ); return;
}
// create the class
$model = \CCShipyard::create( 'dbmodel', $name, $table );
// auto timestamps
$model->timestamps( $options->get( 'timestamps', false ) );
// check before
if ( file_exists( $path ) )
{
if ( !CCCli::confirm( "The class already exists. Do you wish to overwrite it?", true ) )
{
return;
}
}
// write file
\CCFile::write( $path, $model->output() );
} | [
"public",
"function",
"action_model",
"(",
"$",
"params",
")",
"{",
"$",
"options",
"=",
"\\",
"CCDataObject",
"::",
"assign",
"(",
"$",
"params",
")",
";",
"// params",
"$",
"name",
"=",
"$",
"options",
"->",
"get",
"(",
"0",
",",
"null",
")",
";",
"$",
"table",
"=",
"$",
"options",
"->",
"get",
"(",
"1",
",",
"null",
")",
";",
"// get name if we dont have one",
"while",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"read",
"(",
"'Please enter the class name: '",
")",
";",
"}",
"// get table if we dont have one",
"while",
"(",
"!",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"read",
"(",
"'Please enter the table name: '",
")",
";",
"}",
"// resolve the path",
"if",
"(",
"!",
"$",
"path",
"=",
"\\",
"CCPath",
"::",
"classes",
"(",
"str_replace",
"(",
"'_'",
",",
"'/'",
",",
"$",
"name",
")",
",",
"EXT",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Could not resolve the path. Check if the namespace is registered.'",
")",
";",
"return",
";",
"}",
"// create the class",
"$",
"model",
"=",
"\\",
"CCShipyard",
"::",
"create",
"(",
"'dbmodel'",
",",
"$",
"name",
",",
"$",
"table",
")",
";",
"// auto timestamps",
"$",
"model",
"->",
"timestamps",
"(",
"$",
"options",
"->",
"get",
"(",
"'timestamps'",
",",
"false",
")",
")",
";",
"// check before",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"CCCli",
"::",
"confirm",
"(",
"\"The class already exists. Do you wish to overwrite it?\"",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"}",
"// write file",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"path",
",",
"$",
"model",
"->",
"output",
"(",
")",
")",
";",
"}"
]
| generate a model class
exmample:
run shipyard::model <class>
run shipyard::model <class> <table>
run shipyard::model <namespace>::<class>
@param array $params
@return void | [
"generate",
"a",
"model",
"class"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/shipyard.php#L139-L182 |
ClanCats/Core | src/console/shipyard.php | shipyard.action_controller | public function action_controller( $params )
{
$options = \CCDataObject::assign( $params );
$name = $options->get( 0, null );
$parent = $options->get( 1, null );
// get name if we dont have one
while( !$name )
{
$name = $this->read( 'Please enter the controller name: ' );
}
// fix controller suffix
if ( substr( $name, ( strlen( 'Controller' ) * -1 ) ) != 'Controller' )
{
$name .= 'Controller';
}
// try to resolve the path
if ( !$path = \CCPath::controllers( str_replace( '_', '/', $name ), EXT ) )
{
$this->error( 'Could not resolve the path. Check if the namespace is registered.' ); return;
}
// parent
if ( is_null( $parent ) )
{
$parent = '\\CCController';
}
// view controller
if ( $options->get( 'view', false ) )
{
$parent = '\\CCViewController';
}
// create the class
$class = \CCShipyard::create( 'class', $name, $parent );
// get the actions
$actions = array( 'index' );
if ( $options->get( 'actions', false ) )
{
$actions = array_merge( $actions, explode( ',', $options->get( 'actions' ) ) );
}
foreach( $actions as $action )
{
$action = trim( $action );
$class->add( 'function', 'action_'.$action, 'protected', 'echo "'.$name.' '.$action.' action";', ucfirst($action)." action\n@return void|CCResponse" );
$class->add( 'line', 2 );
}
// add static init
if ( !$options->get( 'no-events', false ) )
{
$class->add( 'function', 'wake', 'protected', '//', "Controller wake\n@return void|CCResponse" );
$class->add( 'line', 2 );
$class->add( 'function', 'sleep', 'protected', '//', "Controller wake\n@return void" );
}
// check for overwrite
if ( file_exists( $path ) )
{
if ( !$this->confirm( "The class already exists. Do you wish to overwrite it?", true ) )
{
return;
}
}
// write file
\CCFile::write( $path, $class->output() );
} | php | public function action_controller( $params )
{
$options = \CCDataObject::assign( $params );
$name = $options->get( 0, null );
$parent = $options->get( 1, null );
// get name if we dont have one
while( !$name )
{
$name = $this->read( 'Please enter the controller name: ' );
}
// fix controller suffix
if ( substr( $name, ( strlen( 'Controller' ) * -1 ) ) != 'Controller' )
{
$name .= 'Controller';
}
// try to resolve the path
if ( !$path = \CCPath::controllers( str_replace( '_', '/', $name ), EXT ) )
{
$this->error( 'Could not resolve the path. Check if the namespace is registered.' ); return;
}
// parent
if ( is_null( $parent ) )
{
$parent = '\\CCController';
}
// view controller
if ( $options->get( 'view', false ) )
{
$parent = '\\CCViewController';
}
// create the class
$class = \CCShipyard::create( 'class', $name, $parent );
// get the actions
$actions = array( 'index' );
if ( $options->get( 'actions', false ) )
{
$actions = array_merge( $actions, explode( ',', $options->get( 'actions' ) ) );
}
foreach( $actions as $action )
{
$action = trim( $action );
$class->add( 'function', 'action_'.$action, 'protected', 'echo "'.$name.' '.$action.' action";', ucfirst($action)." action\n@return void|CCResponse" );
$class->add( 'line', 2 );
}
// add static init
if ( !$options->get( 'no-events', false ) )
{
$class->add( 'function', 'wake', 'protected', '//', "Controller wake\n@return void|CCResponse" );
$class->add( 'line', 2 );
$class->add( 'function', 'sleep', 'protected', '//', "Controller wake\n@return void" );
}
// check for overwrite
if ( file_exists( $path ) )
{
if ( !$this->confirm( "The class already exists. Do you wish to overwrite it?", true ) )
{
return;
}
}
// write file
\CCFile::write( $path, $class->output() );
} | [
"public",
"function",
"action_controller",
"(",
"$",
"params",
")",
"{",
"$",
"options",
"=",
"\\",
"CCDataObject",
"::",
"assign",
"(",
"$",
"params",
")",
";",
"$",
"name",
"=",
"$",
"options",
"->",
"get",
"(",
"0",
",",
"null",
")",
";",
"$",
"parent",
"=",
"$",
"options",
"->",
"get",
"(",
"1",
",",
"null",
")",
";",
"// get name if we dont have one",
"while",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"read",
"(",
"'Please enter the controller name: '",
")",
";",
"}",
"// fix controller suffix",
"if",
"(",
"substr",
"(",
"$",
"name",
",",
"(",
"strlen",
"(",
"'Controller'",
")",
"*",
"-",
"1",
")",
")",
"!=",
"'Controller'",
")",
"{",
"$",
"name",
".=",
"'Controller'",
";",
"}",
"// try to resolve the path",
"if",
"(",
"!",
"$",
"path",
"=",
"\\",
"CCPath",
"::",
"controllers",
"(",
"str_replace",
"(",
"'_'",
",",
"'/'",
",",
"$",
"name",
")",
",",
"EXT",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"'Could not resolve the path. Check if the namespace is registered.'",
")",
";",
"return",
";",
"}",
"// parent",
"if",
"(",
"is_null",
"(",
"$",
"parent",
")",
")",
"{",
"$",
"parent",
"=",
"'\\\\CCController'",
";",
"}",
"// view controller",
"if",
"(",
"$",
"options",
"->",
"get",
"(",
"'view'",
",",
"false",
")",
")",
"{",
"$",
"parent",
"=",
"'\\\\CCViewController'",
";",
"}",
"// create the class",
"$",
"class",
"=",
"\\",
"CCShipyard",
"::",
"create",
"(",
"'class'",
",",
"$",
"name",
",",
"$",
"parent",
")",
";",
"// get the actions",
"$",
"actions",
"=",
"array",
"(",
"'index'",
")",
";",
"if",
"(",
"$",
"options",
"->",
"get",
"(",
"'actions'",
",",
"false",
")",
")",
"{",
"$",
"actions",
"=",
"array_merge",
"(",
"$",
"actions",
",",
"explode",
"(",
"','",
",",
"$",
"options",
"->",
"get",
"(",
"'actions'",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"action",
")",
"{",
"$",
"action",
"=",
"trim",
"(",
"$",
"action",
")",
";",
"$",
"class",
"->",
"add",
"(",
"'function'",
",",
"'action_'",
".",
"$",
"action",
",",
"'protected'",
",",
"'echo \"'",
".",
"$",
"name",
".",
"' '",
".",
"$",
"action",
".",
"' action\";'",
",",
"ucfirst",
"(",
"$",
"action",
")",
".",
"\" action\\n@return void|CCResponse\"",
")",
";",
"$",
"class",
"->",
"add",
"(",
"'line'",
",",
"2",
")",
";",
"}",
"// add static init",
"if",
"(",
"!",
"$",
"options",
"->",
"get",
"(",
"'no-events'",
",",
"false",
")",
")",
"{",
"$",
"class",
"->",
"add",
"(",
"'function'",
",",
"'wake'",
",",
"'protected'",
",",
"'//'",
",",
"\"Controller wake\\n@return void|CCResponse\"",
")",
";",
"$",
"class",
"->",
"add",
"(",
"'line'",
",",
"2",
")",
";",
"$",
"class",
"->",
"add",
"(",
"'function'",
",",
"'sleep'",
",",
"'protected'",
",",
"'//'",
",",
"\"Controller wake\\n@return void\"",
")",
";",
"}",
"// check for overwrite",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"confirm",
"(",
"\"The class already exists. Do you wish to overwrite it?\"",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"}",
"// write file",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"path",
",",
"$",
"class",
"->",
"output",
"(",
")",
")",
";",
"}"
]
| generate an controller
exmample:
run shipyard::controller <controller>
run shipyard::controller <controller> <parent_class>
run shipyard::controller <namespace>::<controller>
@param array $params
@return void | [
"generate",
"an",
"controller"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/shipyard.php#L195-L270 |
ClanCats/Core | src/console/shipyard.php | shipyard.action_ship | public function action_ship( $params )
{
$options = \CCDataObject::assign( $params );
$name = $options->get( 0, null );
$namespace = $options->get( 1, null );
// get name if we dont have one
while( !$name )
{
$name = CCCli::read( 'Please enter the ship name: ' );
}
// set namespace
if ( !$namespace )
{
$namespace = $name;
}
// no namespace?
if ( $params['no-namespace'] )
{
$namespace = false;
}
// custom target
$target = $options->get( 'target', ORBITPATH );
if ( substr( $target, 0, 1 ) !== '/' )
{
$target = CCFPATH.$target;
}
if ( substr( $target, -1 ) !== '/' )
{
$target .= '/';
}
$target .= $name.'/';
// check if the module is in our orbit path
if ( is_dir( $target ) )
{
if ( !CCCli::confirm( "there is already a ship with this name. do you want to overwrite?", true ) )
{
return;
}
}
// create the blueprint
$defaults = \CCConfig::create( 'shipyard' );
$blueprint = array(
'name' => $name,
'version' => $defaults->get( 'defaults.version' ),
'description' => $defaults->get( 'defaults.description' ),
'homepage' => $defaults->get( 'defaults.homepage' ),
'keywords' => $defaults->get( 'defaults.keywords' ),
'license' => $defaults->get( 'defaults.license' ),
'authors' => $defaults->get( 'defaults.authors' ),
'namespace' => $namespace,
);
// create file
\CCJson::write( $target.'blueprint.json', $blueprint, true );
$ship = \CCOrbit_Ship::blueprint( $blueprint, $target );
// create event files
if ( $namespace )
{
// create forge instance
$forge = new \CCForge_Php( $namespace );
// add header
$forge->comment( $this->make_comment_header( $ship->name.' ship', array(
'package' => $ship->name,
'authors' => $ship->authors,
'version' => $ship->version,
'copyright' => \CCConfig::create( 'shipyard' )->get( 'defaults.copyright' ),
)));
// add class
$forge->closure( 'class Ship extends \CCOrbit_Ship', function() {
$forge = new \CCForge_Php;
// add init function
echo $forge->closure( 'public function wake()', '// Do stuff',
"initialize the ship\n\n".
"@return void"
);
echo $forge->line(2);
// add init function
echo $forge->closure( 'public function install()', '// Do stuff',
"install the ship\n\n".
"@return void"
);
echo $forge->line(2);
// add init function
echo $forge->closure( 'public function unsintall()', '// Do stuff',
"uninstall the ship\n\n".
"@return void"
);
});
\CCFile::write( $target.CCDIR_CLASS.'Ship'.EXT, $forge );
} else {
// create forge instance
$forge = new \CCForge_Php();
// add header
$forge->comment( $this->make_comment_header( $ship->name, array(
'package' => $ship->name,
'authors' => $ship->authors,
'version' => $ship->version,
'copyright' => \CCConfig::create( 'shipyard' )->get( 'defaults.copyright' ),
)));
\CCFile::write( $target.'shipyard/wake'.EXT, $forge );
\CCFile::write( $target.'shipyard/install'.EXT, $forge );
\CCFile::write( $target.'shipyard/uninstall'.EXT, $forge );
}
// sucess
CCCli::line( "'".$name."' succesfully created under: ".$target, 'green' );
} | php | public function action_ship( $params )
{
$options = \CCDataObject::assign( $params );
$name = $options->get( 0, null );
$namespace = $options->get( 1, null );
// get name if we dont have one
while( !$name )
{
$name = CCCli::read( 'Please enter the ship name: ' );
}
// set namespace
if ( !$namespace )
{
$namespace = $name;
}
// no namespace?
if ( $params['no-namespace'] )
{
$namespace = false;
}
// custom target
$target = $options->get( 'target', ORBITPATH );
if ( substr( $target, 0, 1 ) !== '/' )
{
$target = CCFPATH.$target;
}
if ( substr( $target, -1 ) !== '/' )
{
$target .= '/';
}
$target .= $name.'/';
// check if the module is in our orbit path
if ( is_dir( $target ) )
{
if ( !CCCli::confirm( "there is already a ship with this name. do you want to overwrite?", true ) )
{
return;
}
}
// create the blueprint
$defaults = \CCConfig::create( 'shipyard' );
$blueprint = array(
'name' => $name,
'version' => $defaults->get( 'defaults.version' ),
'description' => $defaults->get( 'defaults.description' ),
'homepage' => $defaults->get( 'defaults.homepage' ),
'keywords' => $defaults->get( 'defaults.keywords' ),
'license' => $defaults->get( 'defaults.license' ),
'authors' => $defaults->get( 'defaults.authors' ),
'namespace' => $namespace,
);
// create file
\CCJson::write( $target.'blueprint.json', $blueprint, true );
$ship = \CCOrbit_Ship::blueprint( $blueprint, $target );
// create event files
if ( $namespace )
{
// create forge instance
$forge = new \CCForge_Php( $namespace );
// add header
$forge->comment( $this->make_comment_header( $ship->name.' ship', array(
'package' => $ship->name,
'authors' => $ship->authors,
'version' => $ship->version,
'copyright' => \CCConfig::create( 'shipyard' )->get( 'defaults.copyright' ),
)));
// add class
$forge->closure( 'class Ship extends \CCOrbit_Ship', function() {
$forge = new \CCForge_Php;
// add init function
echo $forge->closure( 'public function wake()', '// Do stuff',
"initialize the ship\n\n".
"@return void"
);
echo $forge->line(2);
// add init function
echo $forge->closure( 'public function install()', '// Do stuff',
"install the ship\n\n".
"@return void"
);
echo $forge->line(2);
// add init function
echo $forge->closure( 'public function unsintall()', '// Do stuff',
"uninstall the ship\n\n".
"@return void"
);
});
\CCFile::write( $target.CCDIR_CLASS.'Ship'.EXT, $forge );
} else {
// create forge instance
$forge = new \CCForge_Php();
// add header
$forge->comment( $this->make_comment_header( $ship->name, array(
'package' => $ship->name,
'authors' => $ship->authors,
'version' => $ship->version,
'copyright' => \CCConfig::create( 'shipyard' )->get( 'defaults.copyright' ),
)));
\CCFile::write( $target.'shipyard/wake'.EXT, $forge );
\CCFile::write( $target.'shipyard/install'.EXT, $forge );
\CCFile::write( $target.'shipyard/uninstall'.EXT, $forge );
}
// sucess
CCCli::line( "'".$name."' succesfully created under: ".$target, 'green' );
} | [
"public",
"function",
"action_ship",
"(",
"$",
"params",
")",
"{",
"$",
"options",
"=",
"\\",
"CCDataObject",
"::",
"assign",
"(",
"$",
"params",
")",
";",
"$",
"name",
"=",
"$",
"options",
"->",
"get",
"(",
"0",
",",
"null",
")",
";",
"$",
"namespace",
"=",
"$",
"options",
"->",
"get",
"(",
"1",
",",
"null",
")",
";",
"// get name if we dont have one",
"while",
"(",
"!",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"CCCli",
"::",
"read",
"(",
"'Please enter the ship name: '",
")",
";",
"}",
"// set namespace ",
"if",
"(",
"!",
"$",
"namespace",
")",
"{",
"$",
"namespace",
"=",
"$",
"name",
";",
"}",
"// no namespace?",
"if",
"(",
"$",
"params",
"[",
"'no-namespace'",
"]",
")",
"{",
"$",
"namespace",
"=",
"false",
";",
"}",
"// custom target",
"$",
"target",
"=",
"$",
"options",
"->",
"get",
"(",
"'target'",
",",
"ORBITPATH",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"target",
",",
"0",
",",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"target",
"=",
"CCFPATH",
".",
"$",
"target",
";",
"}",
"if",
"(",
"substr",
"(",
"$",
"target",
",",
"-",
"1",
")",
"!==",
"'/'",
")",
"{",
"$",
"target",
".=",
"'/'",
";",
"}",
"$",
"target",
".=",
"$",
"name",
".",
"'/'",
";",
"// check if the module is in our orbit path",
"if",
"(",
"is_dir",
"(",
"$",
"target",
")",
")",
"{",
"if",
"(",
"!",
"CCCli",
"::",
"confirm",
"(",
"\"there is already a ship with this name. do you want to overwrite?\"",
",",
"true",
")",
")",
"{",
"return",
";",
"}",
"}",
"// create the blueprint",
"$",
"defaults",
"=",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
";",
"$",
"blueprint",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"name",
",",
"'version'",
"=>",
"$",
"defaults",
"->",
"get",
"(",
"'defaults.version'",
")",
",",
"'description'",
"=>",
"$",
"defaults",
"->",
"get",
"(",
"'defaults.description'",
")",
",",
"'homepage'",
"=>",
"$",
"defaults",
"->",
"get",
"(",
"'defaults.homepage'",
")",
",",
"'keywords'",
"=>",
"$",
"defaults",
"->",
"get",
"(",
"'defaults.keywords'",
")",
",",
"'license'",
"=>",
"$",
"defaults",
"->",
"get",
"(",
"'defaults.license'",
")",
",",
"'authors'",
"=>",
"$",
"defaults",
"->",
"get",
"(",
"'defaults.authors'",
")",
",",
"'namespace'",
"=>",
"$",
"namespace",
",",
")",
";",
"// create file",
"\\",
"CCJson",
"::",
"write",
"(",
"$",
"target",
".",
"'blueprint.json'",
",",
"$",
"blueprint",
",",
"true",
")",
";",
"$",
"ship",
"=",
"\\",
"CCOrbit_Ship",
"::",
"blueprint",
"(",
"$",
"blueprint",
",",
"$",
"target",
")",
";",
"// create event files",
"if",
"(",
"$",
"namespace",
")",
"{",
"// create forge instance",
"$",
"forge",
"=",
"new",
"\\",
"CCForge_Php",
"(",
"$",
"namespace",
")",
";",
"// add header",
"$",
"forge",
"->",
"comment",
"(",
"$",
"this",
"->",
"make_comment_header",
"(",
"$",
"ship",
"->",
"name",
".",
"' ship'",
",",
"array",
"(",
"'package'",
"=>",
"$",
"ship",
"->",
"name",
",",
"'authors'",
"=>",
"$",
"ship",
"->",
"authors",
",",
"'version'",
"=>",
"$",
"ship",
"->",
"version",
",",
"'copyright'",
"=>",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
"->",
"get",
"(",
"'defaults.copyright'",
")",
",",
")",
")",
")",
";",
"// add class",
"$",
"forge",
"->",
"closure",
"(",
"'class Ship extends \\CCOrbit_Ship'",
",",
"function",
"(",
")",
"{",
"$",
"forge",
"=",
"new",
"\\",
"CCForge_Php",
";",
"// add init function",
"echo",
"$",
"forge",
"->",
"closure",
"(",
"'public function wake()'",
",",
"'// Do stuff'",
",",
"\"initialize the ship\\n\\n\"",
".",
"\"@return void\"",
")",
";",
"echo",
"$",
"forge",
"->",
"line",
"(",
"2",
")",
";",
"// add init function",
"echo",
"$",
"forge",
"->",
"closure",
"(",
"'public function install()'",
",",
"'// Do stuff'",
",",
"\"install the ship\\n\\n\"",
".",
"\"@return void\"",
")",
";",
"echo",
"$",
"forge",
"->",
"line",
"(",
"2",
")",
";",
"// add init function",
"echo",
"$",
"forge",
"->",
"closure",
"(",
"'public function unsintall()'",
",",
"'// Do stuff'",
",",
"\"uninstall the ship\\n\\n\"",
".",
"\"@return void\"",
")",
";",
"}",
")",
";",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"target",
".",
"CCDIR_CLASS",
".",
"'Ship'",
".",
"EXT",
",",
"$",
"forge",
")",
";",
"}",
"else",
"{",
"// create forge instance",
"$",
"forge",
"=",
"new",
"\\",
"CCForge_Php",
"(",
")",
";",
"// add header",
"$",
"forge",
"->",
"comment",
"(",
"$",
"this",
"->",
"make_comment_header",
"(",
"$",
"ship",
"->",
"name",
",",
"array",
"(",
"'package'",
"=>",
"$",
"ship",
"->",
"name",
",",
"'authors'",
"=>",
"$",
"ship",
"->",
"authors",
",",
"'version'",
"=>",
"$",
"ship",
"->",
"version",
",",
"'copyright'",
"=>",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
"->",
"get",
"(",
"'defaults.copyright'",
")",
",",
")",
")",
")",
";",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"target",
".",
"'shipyard/wake'",
".",
"EXT",
",",
"$",
"forge",
")",
";",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"target",
".",
"'shipyard/install'",
".",
"EXT",
",",
"$",
"forge",
")",
";",
"\\",
"CCFile",
"::",
"write",
"(",
"$",
"target",
".",
"'shipyard/uninstall'",
".",
"EXT",
",",
"$",
"forge",
")",
";",
"}",
"// sucess",
"CCCli",
"::",
"line",
"(",
"\"'\"",
".",
"$",
"name",
".",
"\"' succesfully created under: \"",
".",
"$",
"target",
",",
"'green'",
")",
";",
"}"
]
| generate ships
exmample:
run shipyard::ship <name>
run shipyard::ship <name> <namespace>
run shipyard::ship <name> --no-namespace
@param array $params
@return void | [
"generate",
"ships"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/shipyard.php#L283-L417 |
ClanCats/Core | src/console/shipyard.php | shipyard.make_comment_header | public function make_comment_header( $title, $data = array() ) {
// get author
$authors = \CCArr::get( 'authors', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.authors' ) );
// author
if ( is_array( $authors ) )
{
foreach( $authors as $person )
{
$author_str .= $person['name']." ";
if ( array_key_exists( 'email', $person ) )
{
$author_str .= "<".$person['email'].">";
}
$author_str .= ", ";
}
$author_str = substr( $author_str, 0, -2 );
}
return "$title\n".
"*\n".
"\n".
"@package ".\CCArr::get( 'package', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.package' ) )."\n".
"@author ".$author_str."\n".
"@version ".\CCArr::get( 'version', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.version' ) )."\n".
"@copyright ".\CCArr::get( 'copyright', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.copyright' ) )."\n";
} | php | public function make_comment_header( $title, $data = array() ) {
// get author
$authors = \CCArr::get( 'authors', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.authors' ) );
// author
if ( is_array( $authors ) )
{
foreach( $authors as $person )
{
$author_str .= $person['name']." ";
if ( array_key_exists( 'email', $person ) )
{
$author_str .= "<".$person['email'].">";
}
$author_str .= ", ";
}
$author_str = substr( $author_str, 0, -2 );
}
return "$title\n".
"*\n".
"\n".
"@package ".\CCArr::get( 'package', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.package' ) )."\n".
"@author ".$author_str."\n".
"@version ".\CCArr::get( 'version', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.version' ) )."\n".
"@copyright ".\CCArr::get( 'copyright', $data, \CCConfig::create( 'shipyard' )->get( 'defaults.copyright' ) )."\n";
} | [
"public",
"function",
"make_comment_header",
"(",
"$",
"title",
",",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"// get author",
"$",
"authors",
"=",
"\\",
"CCArr",
"::",
"get",
"(",
"'authors'",
",",
"$",
"data",
",",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
"->",
"get",
"(",
"'defaults.authors'",
")",
")",
";",
"// author",
"if",
"(",
"is_array",
"(",
"$",
"authors",
")",
")",
"{",
"foreach",
"(",
"$",
"authors",
"as",
"$",
"person",
")",
"{",
"$",
"author_str",
".=",
"$",
"person",
"[",
"'name'",
"]",
".",
"\" \"",
";",
"if",
"(",
"array_key_exists",
"(",
"'email'",
",",
"$",
"person",
")",
")",
"{",
"$",
"author_str",
".=",
"\"<\"",
".",
"$",
"person",
"[",
"'email'",
"]",
".",
"\">\"",
";",
"}",
"$",
"author_str",
".=",
"\", \"",
";",
"}",
"$",
"author_str",
"=",
"substr",
"(",
"$",
"author_str",
",",
"0",
",",
"-",
"2",
")",
";",
"}",
"return",
"\"$title\\n\"",
".",
"\"*\\n\"",
".",
"\"\\n\"",
".",
"\"@package \"",
".",
"\\",
"CCArr",
"::",
"get",
"(",
"'package'",
",",
"$",
"data",
",",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
"->",
"get",
"(",
"'defaults.package'",
")",
")",
".",
"\"\\n\"",
".",
"\"@author \"",
".",
"$",
"author_str",
".",
"\"\\n\"",
".",
"\"@version \"",
".",
"\\",
"CCArr",
"::",
"get",
"(",
"'version'",
",",
"$",
"data",
",",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
"->",
"get",
"(",
"'defaults.version'",
")",
")",
".",
"\"\\n\"",
".",
"\"@copyright \"",
".",
"\\",
"CCArr",
"::",
"get",
"(",
"'copyright'",
",",
"$",
"data",
",",
"\\",
"CCConfig",
"::",
"create",
"(",
"'shipyard'",
")",
"->",
"get",
"(",
"'defaults.copyright'",
")",
")",
".",
"\"\\n\"",
";",
"}"
]
| generates an file header string
@param string $title
@param array $data
@return string | [
"generates",
"an",
"file",
"header",
"string"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/console/shipyard.php#L426-L453 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBORuntimeBundle/Form/DataTransformer/EntityToIdTransformer.php | EntityToIdTransformer.transform | public function transform($item)
{
if (null === $item) {
return '';
}
$getter = 'get'.ucfirst($this->primaryKey);
if ($this->multiple && (is_array($item) || $item instanceof \Traversable)) {
$result = [];
foreach ($item as $it) {
if (method_exists($it, $getter)) {
$result[] = $it->$getter();
} elseif (method_exists($it, 'getId')) {
$result[] = $it->getId();
}
}
return implode($this->glue, $result);
}
if (method_exists($item, $getter)) {
return $item->$getter();
}
if (method_exists($item, 'getId')) {
return $item->getId();
}
return '';
} | php | public function transform($item)
{
if (null === $item) {
return '';
}
$getter = 'get'.ucfirst($this->primaryKey);
if ($this->multiple && (is_array($item) || $item instanceof \Traversable)) {
$result = [];
foreach ($item as $it) {
if (method_exists($it, $getter)) {
$result[] = $it->$getter();
} elseif (method_exists($it, 'getId')) {
$result[] = $it->getId();
}
}
return implode($this->glue, $result);
}
if (method_exists($item, $getter)) {
return $item->$getter();
}
if (method_exists($item, 'getId')) {
return $item->getId();
}
return '';
} | [
"public",
"function",
"transform",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"item",
")",
"{",
"return",
"''",
";",
"}",
"$",
"getter",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"this",
"->",
"primaryKey",
")",
";",
"if",
"(",
"$",
"this",
"->",
"multiple",
"&&",
"(",
"is_array",
"(",
"$",
"item",
")",
"||",
"$",
"item",
"instanceof",
"\\",
"Traversable",
")",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"item",
"as",
"$",
"it",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"it",
",",
"$",
"getter",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"it",
"->",
"$",
"getter",
"(",
")",
";",
"}",
"elseif",
"(",
"method_exists",
"(",
"$",
"it",
",",
"'getId'",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"it",
"->",
"getId",
"(",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"$",
"this",
"->",
"glue",
",",
"$",
"result",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"item",
",",
"$",
"getter",
")",
")",
"{",
"return",
"$",
"item",
"->",
"$",
"getter",
"(",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"item",
",",
"'getId'",
")",
")",
"{",
"return",
"$",
"item",
"->",
"getId",
"(",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Transforms an object (issue) to a string (number).
@param object|array|null $item
@return string | [
"Transforms",
"an",
"object",
"(",
"issue",
")",
"to",
"a",
"string",
"(",
"number",
")",
"."
]
| train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBORuntimeBundle/Form/DataTransformer/EntityToIdTransformer.php#L71-L100 |
Sedona-Solutions/sedona-sbo | src/Sedona/SBORuntimeBundle/Form/DataTransformer/EntityToIdTransformer.php | EntityToIdTransformer.reverseTransform | public function reverseTransform($key)
{
if (!$key) {
return;
}
if ($this->multiple) {
$keys = explode($this->glue, $key);
$items = $this->om
->getRepository($this->class)
->findBy(array($this->primaryKey => $keys))
;
if (count($keys) != count($items)) {
throw new TransformationFailedException(sprintf("Can't find all items in %s this keys", $key));
}
return $items;
}
$item = $this->om
->getRepository($this->class)
->findOneBy(array($this->primaryKey => $key))
;
if (null === $item) {
throw new TransformationFailedException(sprintf("Can't find the %s item", $key));
}
return $item;
} | php | public function reverseTransform($key)
{
if (!$key) {
return;
}
if ($this->multiple) {
$keys = explode($this->glue, $key);
$items = $this->om
->getRepository($this->class)
->findBy(array($this->primaryKey => $keys))
;
if (count($keys) != count($items)) {
throw new TransformationFailedException(sprintf("Can't find all items in %s this keys", $key));
}
return $items;
}
$item = $this->om
->getRepository($this->class)
->findOneBy(array($this->primaryKey => $key))
;
if (null === $item) {
throw new TransformationFailedException(sprintf("Can't find the %s item", $key));
}
return $item;
} | [
"public",
"function",
"reverseTransform",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"key",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"multiple",
")",
"{",
"$",
"keys",
"=",
"explode",
"(",
"$",
"this",
"->",
"glue",
",",
"$",
"key",
")",
";",
"$",
"items",
"=",
"$",
"this",
"->",
"om",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"class",
")",
"->",
"findBy",
"(",
"array",
"(",
"$",
"this",
"->",
"primaryKey",
"=>",
"$",
"keys",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"keys",
")",
"!=",
"count",
"(",
"$",
"items",
")",
")",
"{",
"throw",
"new",
"TransformationFailedException",
"(",
"sprintf",
"(",
"\"Can't find all items in %s this keys\"",
",",
"$",
"key",
")",
")",
";",
"}",
"return",
"$",
"items",
";",
"}",
"$",
"item",
"=",
"$",
"this",
"->",
"om",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"class",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"$",
"this",
"->",
"primaryKey",
"=>",
"$",
"key",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"item",
")",
"{",
"throw",
"new",
"TransformationFailedException",
"(",
"sprintf",
"(",
"\"Can't find the %s item\"",
",",
"$",
"key",
")",
")",
";",
"}",
"return",
"$",
"item",
";",
"}"
]
| Transforms a string (number) to an object (issue).
@param string $number
@return object|array|null
@throws TransformationFailedException if object (issue) is not found. | [
"Transforms",
"a",
"string",
"(",
"number",
")",
"to",
"an",
"object",
"(",
"issue",
")",
"."
]
| train | https://github.com/Sedona-Solutions/sedona-sbo/blob/8548be4170d191cb1a3e263577aaaab49f04d5ce/src/Sedona/SBORuntimeBundle/Form/DataTransformer/EntityToIdTransformer.php#L111-L141 |
drsdre/yii2-xmlsoccer | Client.php | Client.init | public function init()
{
if (empty($this->serviceUrl)) {
throw new InvalidConfigException("service_url cannot be empty. Please configure.");
}
if (empty($this->apiKey)) {
throw new InvalidConfigException("api_key cannot be empty. Please configure.");
}
if ($this->cache) {
// If class was specified as name, try to instantiate on application
if (is_string($this->cache) && Yii::$app->has($this->cache)) {
$this->cache = Yii::$app->get($this->cache);
} elseif (is_array($this->cache)) {
$this->cache = Yii::createObject($this->cache);
}
} elseif ($this->cache !== false && isset(Yii::$app->cache)) {
$this->cache = Yii::$app->cache;
}
$this->_client = new \yii\httpclient\Client([
'baseUrl' => $this->serviceUrl,
'requestConfig' => [
'method' => 'POST',
'data' => [
'ApiKey' => $this->apiKey
]
],
'responseConfig' => [
'format' => \yii\httpclient\Client::FORMAT_XML
]
]);
if ($this->requestIp) {
$validator = new IpValidator([
'ipv6' => true,
'ipv4' => true,
'subnet' => false,
'expandIPv6' => true
]);
if ($validator->validate($this->requestIp)) {
ArrayHelper::setValue($this->_client->requestConfig, 'options.bindto', $this->requestIp);
}
}
$result = $this->checkApiKey();
if (!is_array($result) || empty($result) || strpos($result[0], 'not accepted') !== false) {
throw new InvalidConfigException(
"Api Key seems to be invalid: {$result[0]}",
Exception::E_API_INVALID_PARAMETER
);
}
} | php | public function init()
{
if (empty($this->serviceUrl)) {
throw new InvalidConfigException("service_url cannot be empty. Please configure.");
}
if (empty($this->apiKey)) {
throw new InvalidConfigException("api_key cannot be empty. Please configure.");
}
if ($this->cache) {
// If class was specified as name, try to instantiate on application
if (is_string($this->cache) && Yii::$app->has($this->cache)) {
$this->cache = Yii::$app->get($this->cache);
} elseif (is_array($this->cache)) {
$this->cache = Yii::createObject($this->cache);
}
} elseif ($this->cache !== false && isset(Yii::$app->cache)) {
$this->cache = Yii::$app->cache;
}
$this->_client = new \yii\httpclient\Client([
'baseUrl' => $this->serviceUrl,
'requestConfig' => [
'method' => 'POST',
'data' => [
'ApiKey' => $this->apiKey
]
],
'responseConfig' => [
'format' => \yii\httpclient\Client::FORMAT_XML
]
]);
if ($this->requestIp) {
$validator = new IpValidator([
'ipv6' => true,
'ipv4' => true,
'subnet' => false,
'expandIPv6' => true
]);
if ($validator->validate($this->requestIp)) {
ArrayHelper::setValue($this->_client->requestConfig, 'options.bindto', $this->requestIp);
}
}
$result = $this->checkApiKey();
if (!is_array($result) || empty($result) || strpos($result[0], 'not accepted') !== false) {
throw new InvalidConfigException(
"Api Key seems to be invalid: {$result[0]}",
Exception::E_API_INVALID_PARAMETER
);
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"serviceUrl",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"service_url cannot be empty. Please configure.\"",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"apiKey",
")",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"api_key cannot be empty. Please configure.\"",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cache",
")",
"{",
"// If class was specified as name, try to instantiate on application",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"cache",
")",
"&&",
"Yii",
"::",
"$",
"app",
"->",
"has",
"(",
"$",
"this",
"->",
"cache",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"Yii",
"::",
"$",
"app",
"->",
"get",
"(",
"$",
"this",
"->",
"cache",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"this",
"->",
"cache",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"Yii",
"::",
"createObject",
"(",
"$",
"this",
"->",
"cache",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"this",
"->",
"cache",
"!==",
"false",
"&&",
"isset",
"(",
"Yii",
"::",
"$",
"app",
"->",
"cache",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"=",
"Yii",
"::",
"$",
"app",
"->",
"cache",
";",
"}",
"$",
"this",
"->",
"_client",
"=",
"new",
"\\",
"yii",
"\\",
"httpclient",
"\\",
"Client",
"(",
"[",
"'baseUrl'",
"=>",
"$",
"this",
"->",
"serviceUrl",
",",
"'requestConfig'",
"=>",
"[",
"'method'",
"=>",
"'POST'",
",",
"'data'",
"=>",
"[",
"'ApiKey'",
"=>",
"$",
"this",
"->",
"apiKey",
"]",
"]",
",",
"'responseConfig'",
"=>",
"[",
"'format'",
"=>",
"\\",
"yii",
"\\",
"httpclient",
"\\",
"Client",
"::",
"FORMAT_XML",
"]",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"requestIp",
")",
"{",
"$",
"validator",
"=",
"new",
"IpValidator",
"(",
"[",
"'ipv6'",
"=>",
"true",
",",
"'ipv4'",
"=>",
"true",
",",
"'subnet'",
"=>",
"false",
",",
"'expandIPv6'",
"=>",
"true",
"]",
")",
";",
"if",
"(",
"$",
"validator",
"->",
"validate",
"(",
"$",
"this",
"->",
"requestIp",
")",
")",
"{",
"ArrayHelper",
"::",
"setValue",
"(",
"$",
"this",
"->",
"_client",
"->",
"requestConfig",
",",
"'options.bindto'",
",",
"$",
"this",
"->",
"requestIp",
")",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"checkApiKey",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"result",
")",
"||",
"empty",
"(",
"$",
"result",
")",
"||",
"strpos",
"(",
"$",
"result",
"[",
"0",
"]",
",",
"'not accepted'",
")",
"!==",
"false",
")",
"{",
"throw",
"new",
"InvalidConfigException",
"(",
"\"Api Key seems to be invalid: {$result[0]}\"",
",",
"Exception",
"::",
"E_API_INVALID_PARAMETER",
")",
";",
"}",
"}"
]
| Initialize component
@throws InvalidConfigException | [
"Initialize",
"component"
]
| train | https://github.com/drsdre/yii2-xmlsoccer/blob/a746edee6269ed0791bac6c6165a946adc30d994/Client.php#L114-L164 |
drsdre/yii2-xmlsoccer | Client.php | Client.getMethodArguments | protected function getMethodArguments($methodName)
{
if (!empty($this->_magicMethodArgumentNames)) {
return ArrayHelper::getValue($this->_magicMethodArgumentNames, $methodName, []);
}
try {
$reflectionClass = new \ReflectionClass($this);
$comment = $reflectionClass->getDocComment();
$lines = preg_split('/[\r\n]/', $comment);
$regexp = '#\s*\*\s*@method ((?:.*) )?([a-zA-Z_]+)\(((?:[\\a-zA-Z]+\s+)?\$(?:[a-zA-Z_]+),?\s*)*\)#';
foreach ($lines as $line) {
$matches = [];
if (preg_match($regexp, $line, $matches)) {
@list($null, $returnType, $method, $argumentString) = $matches;
if (is_null($argumentString)) {
$arguments = [];
} else {
$arguments = array_map('trim', explode(',', $argumentString));
foreach ($arguments as $k => $argument) {
if (empty($argument)) {
continue;
}
if (strpos($argument, ' ') !== false) {
$tmp = explode(' ', $argument);
$arguments[$k] = ['name' => ltrim($tmp[1], '$'), 'type' => $tmp[0]];
} else {
$arguments[$k] = ['name' => ltrim($argument, '$'), 'type' => 'mixed'];
}
}
}
$this->_magicMethodArgumentNames[$method] = $arguments;
}
}
} catch (\ReflectionException $e) {
}
return ArrayHelper::getValue($this->_magicMethodArgumentNames, $methodName, []);
} | php | protected function getMethodArguments($methodName)
{
if (!empty($this->_magicMethodArgumentNames)) {
return ArrayHelper::getValue($this->_magicMethodArgumentNames, $methodName, []);
}
try {
$reflectionClass = new \ReflectionClass($this);
$comment = $reflectionClass->getDocComment();
$lines = preg_split('/[\r\n]/', $comment);
$regexp = '#\s*\*\s*@method ((?:.*) )?([a-zA-Z_]+)\(((?:[\\a-zA-Z]+\s+)?\$(?:[a-zA-Z_]+),?\s*)*\)#';
foreach ($lines as $line) {
$matches = [];
if (preg_match($regexp, $line, $matches)) {
@list($null, $returnType, $method, $argumentString) = $matches;
if (is_null($argumentString)) {
$arguments = [];
} else {
$arguments = array_map('trim', explode(',', $argumentString));
foreach ($arguments as $k => $argument) {
if (empty($argument)) {
continue;
}
if (strpos($argument, ' ') !== false) {
$tmp = explode(' ', $argument);
$arguments[$k] = ['name' => ltrim($tmp[1], '$'), 'type' => $tmp[0]];
} else {
$arguments[$k] = ['name' => ltrim($argument, '$'), 'type' => 'mixed'];
}
}
}
$this->_magicMethodArgumentNames[$method] = $arguments;
}
}
} catch (\ReflectionException $e) {
}
return ArrayHelper::getValue($this->_magicMethodArgumentNames, $methodName, []);
} | [
"protected",
"function",
"getMethodArguments",
"(",
"$",
"methodName",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_magicMethodArgumentNames",
")",
")",
"{",
"return",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"this",
"->",
"_magicMethodArgumentNames",
",",
"$",
"methodName",
",",
"[",
"]",
")",
";",
"}",
"try",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"$",
"comment",
"=",
"$",
"reflectionClass",
"->",
"getDocComment",
"(",
")",
";",
"$",
"lines",
"=",
"preg_split",
"(",
"'/[\\r\\n]/'",
",",
"$",
"comment",
")",
";",
"$",
"regexp",
"=",
"'#\\s*\\*\\s*@method ((?:.*) )?([a-zA-Z_]+)\\(((?:[\\\\a-zA-Z]+\\s+)?\\$(?:[a-zA-Z_]+),?\\s*)*\\)#'",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"matches",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match",
"(",
"$",
"regexp",
",",
"$",
"line",
",",
"$",
"matches",
")",
")",
"{",
"@",
"list",
"(",
"$",
"null",
",",
"$",
"returnType",
",",
"$",
"method",
",",
"$",
"argumentString",
")",
"=",
"$",
"matches",
";",
"if",
"(",
"is_null",
"(",
"$",
"argumentString",
")",
")",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"$",
"arguments",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"argumentString",
")",
")",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"k",
"=>",
"$",
"argument",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"argument",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"argument",
",",
"' '",
")",
"!==",
"false",
")",
"{",
"$",
"tmp",
"=",
"explode",
"(",
"' '",
",",
"$",
"argument",
")",
";",
"$",
"arguments",
"[",
"$",
"k",
"]",
"=",
"[",
"'name'",
"=>",
"ltrim",
"(",
"$",
"tmp",
"[",
"1",
"]",
",",
"'$'",
")",
",",
"'type'",
"=>",
"$",
"tmp",
"[",
"0",
"]",
"]",
";",
"}",
"else",
"{",
"$",
"arguments",
"[",
"$",
"k",
"]",
"=",
"[",
"'name'",
"=>",
"ltrim",
"(",
"$",
"argument",
",",
"'$'",
")",
",",
"'type'",
"=>",
"'mixed'",
"]",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"_magicMethodArgumentNames",
"[",
"$",
"method",
"]",
"=",
"$",
"arguments",
";",
"}",
"}",
"}",
"catch",
"(",
"\\",
"ReflectionException",
"$",
"e",
")",
"{",
"}",
"return",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"this",
"->",
"_magicMethodArgumentNames",
",",
"$",
"methodName",
",",
"[",
"]",
")",
";",
"}"
]
| Get argument names and positions and data types from phpdoc class comment
@param string $methodName method to get arguments from
@return mixed | [
"Get",
"argument",
"names",
"and",
"positions",
"and",
"data",
"types",
"from",
"phpdoc",
"class",
"comment"
]
| train | https://github.com/drsdre/yii2-xmlsoccer/blob/a746edee6269ed0791bac6c6165a946adc30d994/Client.php#L269-L310 |
ClanCats/Core | src/bundles/Mail/PHPMailer/class.pop3.php | POP3.authorise | public function authorise($host, $port = false, $tval = false, $username = '', $password = '', $debug_level = 0)
{
$this->host = $host;
// If no port value provided, use default
if ($port === false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
}
// If no timeout value provided, use default
if ($tval === false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Reset the error log
$this->errors = array();
// connect
$result = $this->connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->login($this->username, $this->password);
if ($login_result) {
$this->disconnect();
return true;
}
}
// We need to disconnect regardless of whether the login succeeded
$this->disconnect();
return false;
} | php | public function authorise($host, $port = false, $tval = false, $username = '', $password = '', $debug_level = 0)
{
$this->host = $host;
// If no port value provided, use default
if ($port === false) {
$this->port = $this->POP3_PORT;
} else {
$this->port = $port;
}
// If no timeout value provided, use default
if ($tval === false) {
$this->tval = $this->POP3_TIMEOUT;
} else {
$this->tval = $tval;
}
$this->do_debug = $debug_level;
$this->username = $username;
$this->password = $password;
// Reset the error log
$this->errors = array();
// connect
$result = $this->connect($this->host, $this->port, $this->tval);
if ($result) {
$login_result = $this->login($this->username, $this->password);
if ($login_result) {
$this->disconnect();
return true;
}
}
// We need to disconnect regardless of whether the login succeeded
$this->disconnect();
return false;
} | [
"public",
"function",
"authorise",
"(",
"$",
"host",
",",
"$",
"port",
"=",
"false",
",",
"$",
"tval",
"=",
"false",
",",
"$",
"username",
"=",
"''",
",",
"$",
"password",
"=",
"''",
",",
"$",
"debug_level",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"host",
"=",
"$",
"host",
";",
"// If no port value provided, use default",
"if",
"(",
"$",
"port",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"port",
"=",
"$",
"this",
"->",
"POP3_PORT",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"port",
"=",
"$",
"port",
";",
"}",
"// If no timeout value provided, use default",
"if",
"(",
"$",
"tval",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"tval",
"=",
"$",
"this",
"->",
"POP3_TIMEOUT",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"tval",
"=",
"$",
"tval",
";",
"}",
"$",
"this",
"->",
"do_debug",
"=",
"$",
"debug_level",
";",
"$",
"this",
"->",
"username",
"=",
"$",
"username",
";",
"$",
"this",
"->",
"password",
"=",
"$",
"password",
";",
"// Reset the error log",
"$",
"this",
"->",
"errors",
"=",
"array",
"(",
")",
";",
"// connect",
"$",
"result",
"=",
"$",
"this",
"->",
"connect",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
",",
"$",
"this",
"->",
"tval",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"login_result",
"=",
"$",
"this",
"->",
"login",
"(",
"$",
"this",
"->",
"username",
",",
"$",
"this",
"->",
"password",
")",
";",
"if",
"(",
"$",
"login_result",
")",
"{",
"$",
"this",
"->",
"disconnect",
"(",
")",
";",
"return",
"true",
";",
"}",
"}",
"// We need to disconnect regardless of whether the login succeeded",
"$",
"this",
"->",
"disconnect",
"(",
")",
";",
"return",
"false",
";",
"}"
]
| Authenticate with a POP3 server.
A connect, login, disconnect sequence
appropriate for POP-before SMTP authorisation.
@access public
@param string $host
@param integer|boolean $port
@param integer|boolean $tval
@param string $username
@param string $password
@param integer $debug_level
@return boolean | [
"Authenticate",
"with",
"a",
"POP3",
"server",
".",
"A",
"connect",
"login",
"disconnect",
"sequence",
"appropriate",
"for",
"POP",
"-",
"before",
"SMTP",
"authorisation",
"."
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/bundles/Mail/PHPMailer/class.pop3.php#L165-L197 |
fond-of/spryker-brand | src/FondOfSpryker/Client/Brand/Dependency/Client/BrandToZedRequestClientBridge.php | BrandToZedRequestClientBridge.call | public function call($url, TransferInterface $object, $requestOptions = null): TransferInterface
{
return $this->zedRequestClient->call($url, $object, $requestOptions);
} | php | public function call($url, TransferInterface $object, $requestOptions = null): TransferInterface
{
return $this->zedRequestClient->call($url, $object, $requestOptions);
} | [
"public",
"function",
"call",
"(",
"$",
"url",
",",
"TransferInterface",
"$",
"object",
",",
"$",
"requestOptions",
"=",
"null",
")",
":",
"TransferInterface",
"{",
"return",
"$",
"this",
"->",
"zedRequestClient",
"->",
"call",
"(",
"$",
"url",
",",
"$",
"object",
",",
"$",
"requestOptions",
")",
";",
"}"
]
| @param string $url
@param \Spryker\Shared\Kernel\Transfer\TransferInterface $object
@param array|null $requestOptions
@return \Spryker\Shared\Kernel\Transfer\TransferInterface | [
"@param",
"string",
"$url",
"@param",
"\\",
"Spryker",
"\\",
"Shared",
"\\",
"Kernel",
"\\",
"Transfer",
"\\",
"TransferInterface",
"$object",
"@param",
"array|null",
"$requestOptions"
]
| train | https://github.com/fond-of/spryker-brand/blob/0ae25c381649b70845016606de9cf4e7dfdccffa/src/FondOfSpryker/Client/Brand/Dependency/Client/BrandToZedRequestClientBridge.php#L29-L32 |
andrelohmann/silverstripe-geolocation | code/models/fieldtypes/PostCodeLocation.php | PostCodeLocation.scaffoldFormField | public function scaffoldFormField($title = null) {
$field = new PostCodeLocationField($this->name);
$field->setLocale($this->getLocale());
return $field;
} | php | public function scaffoldFormField($title = null) {
$field = new PostCodeLocationField($this->name);
$field->setLocale($this->getLocale());
return $field;
} | [
"public",
"function",
"scaffoldFormField",
"(",
"$",
"title",
"=",
"null",
")",
"{",
"$",
"field",
"=",
"new",
"PostCodeLocationField",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"field",
"->",
"setLocale",
"(",
"$",
"this",
"->",
"getLocale",
"(",
")",
")",
";",
"return",
"$",
"field",
";",
"}"
]
| Returns a CompositeField instance used as a default
for form scaffolding.
Used by {@link SearchContext}, {@link ModelAdmin}, {@link DataObject::scaffoldFormFields()}
@param string $title Optional. Localized title of the generated instance
@return FormField | [
"Returns",
"a",
"CompositeField",
"instance",
"used",
"as",
"a",
"default",
"for",
"form",
"scaffolding",
"."
]
| train | https://github.com/andrelohmann/silverstripe-geolocation/blob/124062008d8fa25b631bf5bb69b2ca79b53ef81b/code/models/fieldtypes/PostCodeLocation.php#L243-L248 |
SachaMorard/phalcon-console | Library/Phalcon/Script/Color.php | Color.isSupportedShell | public static function isSupportedShell()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
}
return defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT);
} | php | public static function isSupportedShell()
{
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
return false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM');
}
return defined('STDOUT') && function_exists('posix_isatty') && posix_isatty(STDOUT);
} | [
"public",
"static",
"function",
"isSupportedShell",
"(",
")",
"{",
"if",
"(",
"strtoupper",
"(",
"substr",
"(",
"PHP_OS",
",",
"0",
",",
"3",
")",
")",
"===",
"'WIN'",
")",
"{",
"return",
"false",
"!==",
"getenv",
"(",
"'ANSICON'",
")",
"||",
"'ON'",
"===",
"getenv",
"(",
"'ConEmuANSI'",
")",
"||",
"'xterm'",
"===",
"getenv",
"(",
"'TERM'",
")",
";",
"}",
"return",
"defined",
"(",
"'STDOUT'",
")",
"&&",
"function_exists",
"(",
"'posix_isatty'",
")",
"&&",
"posix_isatty",
"(",
"STDOUT",
")",
";",
"}"
]
| Identify if console supports colors
@return boolean | [
"Identify",
"if",
"console",
"supports",
"colors"
]
| train | https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Script/Color.php#L124-L131 |
SachaMorard/phalcon-console | Library/Phalcon/Script/Color.php | Color.colorize | public static function colorize($string, $fg = null, $at = null, $bg = null)
{
// Shell not supported, exit early
if (!static::isSupportedShell()) {
return $string;
}
$colored = '';
// Check if given foreground color is supported
if (isset(static::$_fg[$fg])) {
$colored .= "\033[" . static::$_fg[$fg] . "m";
}
// Check if given background color is supported
if (isset(static::$_bg[$bg])) {
$colored .= "\033[" . static::$_bg[$bg] . "m";
}
// Check if given attribute is supported
if (isset(static::$_at[$at])) {
$colored .= "\033[" . static::$_at[$at] . "m";
}
// Add string and end coloring
$colored .= $string . "\033[0m";
return $colored;
} | php | public static function colorize($string, $fg = null, $at = null, $bg = null)
{
// Shell not supported, exit early
if (!static::isSupportedShell()) {
return $string;
}
$colored = '';
// Check if given foreground color is supported
if (isset(static::$_fg[$fg])) {
$colored .= "\033[" . static::$_fg[$fg] . "m";
}
// Check if given background color is supported
if (isset(static::$_bg[$bg])) {
$colored .= "\033[" . static::$_bg[$bg] . "m";
}
// Check if given attribute is supported
if (isset(static::$_at[$at])) {
$colored .= "\033[" . static::$_at[$at] . "m";
}
// Add string and end coloring
$colored .= $string . "\033[0m";
return $colored;
} | [
"public",
"static",
"function",
"colorize",
"(",
"$",
"string",
",",
"$",
"fg",
"=",
"null",
",",
"$",
"at",
"=",
"null",
",",
"$",
"bg",
"=",
"null",
")",
"{",
"// Shell not supported, exit early",
"if",
"(",
"!",
"static",
"::",
"isSupportedShell",
"(",
")",
")",
"{",
"return",
"$",
"string",
";",
"}",
"$",
"colored",
"=",
"''",
";",
"// Check if given foreground color is supported",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_fg",
"[",
"$",
"fg",
"]",
")",
")",
"{",
"$",
"colored",
".=",
"\"\\033[\"",
".",
"static",
"::",
"$",
"_fg",
"[",
"$",
"fg",
"]",
".",
"\"m\"",
";",
"}",
"// Check if given background color is supported",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_bg",
"[",
"$",
"bg",
"]",
")",
")",
"{",
"$",
"colored",
".=",
"\"\\033[\"",
".",
"static",
"::",
"$",
"_bg",
"[",
"$",
"bg",
"]",
".",
"\"m\"",
";",
"}",
"// Check if given attribute is supported",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_at",
"[",
"$",
"at",
"]",
")",
")",
"{",
"$",
"colored",
".=",
"\"\\033[\"",
".",
"static",
"::",
"$",
"_at",
"[",
"$",
"at",
"]",
".",
"\"m\"",
";",
"}",
"// Add string and end coloring",
"$",
"colored",
".=",
"$",
"string",
".",
"\"\\033[0m\"",
";",
"return",
"$",
"colored",
";",
"}"
]
| Colorizes the string using provided colors.
@static
@param $string
@param null|integer $fg
@param null|integer $at
@param null|integer $bg
@return string | [
"Colorizes",
"the",
"string",
"using",
"provided",
"colors",
"."
]
| train | https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Script/Color.php#L144-L172 |
SachaMorard/phalcon-console | Library/Phalcon/Script/Color.php | Color.error | public static function error($msg)
{
$msg = 'Error: ' . $msg;
$space = strlen($msg) + 4;
$out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
$out .= static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
return $out;
} | php | public static function error($msg)
{
$msg = 'Error: ' . $msg;
$space = strlen($msg) + 4;
$out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
$out .= static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_RED) . PHP_EOL;
return $out;
} | [
"public",
"static",
"function",
"error",
"(",
"$",
"msg",
")",
"{",
"$",
"msg",
"=",
"'Error: '",
".",
"$",
"msg",
";",
"$",
"space",
"=",
"strlen",
"(",
"$",
"msg",
")",
"+",
"4",
";",
"$",
"out",
"=",
"static",
"::",
"colorize",
"(",
"str_pad",
"(",
"' '",
",",
"$",
"space",
")",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_RED",
")",
".",
"PHP_EOL",
";",
"$",
"out",
".=",
"static",
"::",
"colorize",
"(",
"' '",
".",
"$",
"msg",
".",
"' '",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_RED",
")",
".",
"PHP_EOL",
";",
"$",
"out",
".=",
"static",
"::",
"colorize",
"(",
"str_pad",
"(",
"' '",
",",
"$",
"space",
")",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_RED",
")",
".",
"PHP_EOL",
";",
"return",
"$",
"out",
";",
"}"
]
| Color style for error messages.
@static
@param $msg
@return string | [
"Color",
"style",
"for",
"error",
"messages",
"."
]
| train | https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Script/Color.php#L186-L195 |
SachaMorard/phalcon-console | Library/Phalcon/Script/Color.php | Color.success | public static function success($msg)
{
$msg = 'Success: ' . $msg;
$space = strlen($msg) + 4;
$out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_GREEN) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_GREEN) . PHP_EOL;
$out .= static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_GREEN) . PHP_EOL;
return $out;
} | php | public static function success($msg)
{
$msg = 'Success: ' . $msg;
$space = strlen($msg) + 4;
$out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_GREEN) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_GREEN) . PHP_EOL;
$out .= static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_GREEN) . PHP_EOL;
return $out;
} | [
"public",
"static",
"function",
"success",
"(",
"$",
"msg",
")",
"{",
"$",
"msg",
"=",
"'Success: '",
".",
"$",
"msg",
";",
"$",
"space",
"=",
"strlen",
"(",
"$",
"msg",
")",
"+",
"4",
";",
"$",
"out",
"=",
"static",
"::",
"colorize",
"(",
"str_pad",
"(",
"' '",
",",
"$",
"space",
")",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_GREEN",
")",
".",
"PHP_EOL",
";",
"$",
"out",
".=",
"static",
"::",
"colorize",
"(",
"' '",
".",
"$",
"msg",
".",
"' '",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_GREEN",
")",
".",
"PHP_EOL",
";",
"$",
"out",
".=",
"static",
"::",
"colorize",
"(",
"str_pad",
"(",
"' '",
",",
"$",
"space",
")",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_GREEN",
")",
".",
"PHP_EOL",
";",
"return",
"$",
"out",
";",
"}"
]
| Color style for success messages.
@static
@param $msg
@return string | [
"Color",
"style",
"for",
"success",
"messages",
"."
]
| train | https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Script/Color.php#L204-L213 |
SachaMorard/phalcon-console | Library/Phalcon/Script/Color.php | Color.info | public static function info($msg)
{
$msg = 'Info: ' . $msg;
$space = strlen($msg) + 4;
$out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_BLUE) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_BLUE) . PHP_EOL;
$out .= static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_BLUE) . PHP_EOL;
return $out;
} | php | public static function info($msg)
{
$msg = 'Info: ' . $msg;
$space = strlen($msg) + 4;
$out = static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_BLUE) . PHP_EOL;
$out .= static::colorize(' ' . $msg . ' ', Color::FG_WHITE, Color::AT_BOLD, Color::BG_BLUE) . PHP_EOL;
$out .= static::colorize(str_pad(' ', $space), Color::FG_WHITE, Color::AT_BOLD, Color::BG_BLUE) . PHP_EOL;
return $out;
} | [
"public",
"static",
"function",
"info",
"(",
"$",
"msg",
")",
"{",
"$",
"msg",
"=",
"'Info: '",
".",
"$",
"msg",
";",
"$",
"space",
"=",
"strlen",
"(",
"$",
"msg",
")",
"+",
"4",
";",
"$",
"out",
"=",
"static",
"::",
"colorize",
"(",
"str_pad",
"(",
"' '",
",",
"$",
"space",
")",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_BLUE",
")",
".",
"PHP_EOL",
";",
"$",
"out",
".=",
"static",
"::",
"colorize",
"(",
"' '",
".",
"$",
"msg",
".",
"' '",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_BLUE",
")",
".",
"PHP_EOL",
";",
"$",
"out",
".=",
"static",
"::",
"colorize",
"(",
"str_pad",
"(",
"' '",
",",
"$",
"space",
")",
",",
"Color",
"::",
"FG_WHITE",
",",
"Color",
"::",
"AT_BOLD",
",",
"Color",
"::",
"BG_BLUE",
")",
".",
"PHP_EOL",
";",
"return",
"$",
"out",
";",
"}"
]
| Color style for info messages.
@static
@param $msg
@return string | [
"Color",
"style",
"for",
"info",
"messages",
"."
]
| train | https://github.com/SachaMorard/phalcon-console/blob/a7922e4c488ea19bc0ecce793e6f01cf9cf3c0c3/Library/Phalcon/Script/Color.php#L222-L231 |
lmammino/e-foundation | src/Address/Model/Country.php | Country.setProvinces | public function setProvinces(Collection $provinces)
{
foreach ($provinces as $province) {
$this->addProvince($province);
}
return $this;
} | php | public function setProvinces(Collection $provinces)
{
foreach ($provinces as $province) {
$this->addProvince($province);
}
return $this;
} | [
"public",
"function",
"setProvinces",
"(",
"Collection",
"$",
"provinces",
")",
"{",
"foreach",
"(",
"$",
"provinces",
"as",
"$",
"province",
")",
"{",
"$",
"this",
"->",
"addProvince",
"(",
"$",
"province",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Address/Model/Country.php#L89-L96 |
lmammino/e-foundation | src/Address/Model/Country.php | Country.addProvince | public function addProvince(ProvinceInterface $province)
{
if (!$this->hasProvince($province)) {
$province->setCountry($this);
$this->provinces->add($province);
}
return $this;
} | php | public function addProvince(ProvinceInterface $province)
{
if (!$this->hasProvince($province)) {
$province->setCountry($this);
$this->provinces->add($province);
}
return $this;
} | [
"public",
"function",
"addProvince",
"(",
"ProvinceInterface",
"$",
"province",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProvince",
"(",
"$",
"province",
")",
")",
"{",
"$",
"province",
"->",
"setCountry",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"provinces",
"->",
"add",
"(",
"$",
"province",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Address/Model/Country.php#L101-L109 |
uthando-cms/uthando-dompdf | src/UthandoDomPdf/Service/DomPdfFactory.php | DomPdfFactory.createService | public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var DomPdfOptions $config */
$config = $serviceLocator->get(DomPdfOptions::class);
$options = $config->toArray();
return new Dompdf($options);
} | php | public function createService(ServiceLocatorInterface $serviceLocator)
{
/* @var DomPdfOptions $config */
$config = $serviceLocator->get(DomPdfOptions::class);
$options = $config->toArray();
return new Dompdf($options);
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"/* @var DomPdfOptions $config */",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"get",
"(",
"DomPdfOptions",
"::",
"class",
")",
";",
"$",
"options",
"=",
"$",
"config",
"->",
"toArray",
"(",
")",
";",
"return",
"new",
"Dompdf",
"(",
"$",
"options",
")",
";",
"}"
]
| Creates an instance of Dompdf.
@param ServiceLocatorInterface $serviceLocator
@return Dompdf | [
"Creates",
"an",
"instance",
"of",
"Dompdf",
"."
]
| train | https://github.com/uthando-cms/uthando-dompdf/blob/60a750058c2db9ed167476192b20c7f544c32007/src/UthandoDomPdf/Service/DomPdfFactory.php#L31-L38 |
phpmob/changmin | src/PhpMob/ChangMinBundle/Form/Type/TaxonChoiceType.php | TaxonChoiceType.buildView | public function buildView(FormView $view, FormInterface $form, array $options)
{
$rootLevel = 0;
/** @var ChoiceView $choice */
foreach ($view->vars['choices'] as $i => $choice) {
$dash = '— ';
if (0 === $i) {
$rootLevel = $choice->data->getLevel();
}
if (preg_match("/^$dash/", $choice->label)) {
continue;
}
$level = $choice->data->getLevel() - $rootLevel;
$choice->label = @str_repeat($dash, $level).$choice->label;
}
} | php | public function buildView(FormView $view, FormInterface $form, array $options)
{
$rootLevel = 0;
/** @var ChoiceView $choice */
foreach ($view->vars['choices'] as $i => $choice) {
$dash = '— ';
if (0 === $i) {
$rootLevel = $choice->data->getLevel();
}
if (preg_match("/^$dash/", $choice->label)) {
continue;
}
$level = $choice->data->getLevel() - $rootLevel;
$choice->label = @str_repeat($dash, $level).$choice->label;
}
} | [
"public",
"function",
"buildView",
"(",
"FormView",
"$",
"view",
",",
"FormInterface",
"$",
"form",
",",
"array",
"$",
"options",
")",
"{",
"$",
"rootLevel",
"=",
"0",
";",
"/** @var ChoiceView $choice */",
"foreach",
"(",
"$",
"view",
"->",
"vars",
"[",
"'choices'",
"]",
"as",
"$",
"i",
"=>",
"$",
"choice",
")",
"{",
"$",
"dash",
"=",
"'— ';",
"",
"if",
"(",
"0",
"===",
"$",
"i",
")",
"{",
"$",
"rootLevel",
"=",
"$",
"choice",
"->",
"data",
"->",
"getLevel",
"(",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"\"/^$dash/\"",
",",
"$",
"choice",
"->",
"label",
")",
")",
"{",
"continue",
";",
"}",
"$",
"level",
"=",
"$",
"choice",
"->",
"data",
"->",
"getLevel",
"(",
")",
"-",
"$",
"rootLevel",
";",
"$",
"choice",
"->",
"label",
"=",
"@",
"str_repeat",
"(",
"$",
"dash",
",",
"$",
"level",
")",
".",
"$",
"choice",
"->",
"label",
";",
"}",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Form/Type/TaxonChoiceType.php#L45-L64 |
phpmob/changmin | src/PhpMob/ChangMinBundle/Form/Type/TaxonChoiceType.php | TaxonChoiceType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'choices' => function (Options $options) {
return $this->getTaxons($options['root'], $options['filter']);
},
'choice_value' => 'id',
'choice_label' => 'name',
'choice_translation_domain' => false,
'root' => null,
'root_code' => null,
'filter' => null,
])
->setAllowedTypes('root', [TaxonInterface::class, 'string', 'null'])
->setAllowedTypes('root_code', ['string', 'null'])
->setAllowedTypes('filter', ['callable', 'null'])
->setNormalizer('root', function (Options $options, $value) {
if ($value instanceof TaxonInterface) {
return $value->getCode();
}
return $value ?: $options['root_code'];
})
;
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'choices' => function (Options $options) {
return $this->getTaxons($options['root'], $options['filter']);
},
'choice_value' => 'id',
'choice_label' => 'name',
'choice_translation_domain' => false,
'root' => null,
'root_code' => null,
'filter' => null,
])
->setAllowedTypes('root', [TaxonInterface::class, 'string', 'null'])
->setAllowedTypes('root_code', ['string', 'null'])
->setAllowedTypes('filter', ['callable', 'null'])
->setNormalizer('root', function (Options $options, $value) {
if ($value instanceof TaxonInterface) {
return $value->getCode();
}
return $value ?: $options['root_code'];
})
;
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'choices'",
"=>",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"this",
"->",
"getTaxons",
"(",
"$",
"options",
"[",
"'root'",
"]",
",",
"$",
"options",
"[",
"'filter'",
"]",
")",
";",
"}",
",",
"'choice_value'",
"=>",
"'id'",
",",
"'choice_label'",
"=>",
"'name'",
",",
"'choice_translation_domain'",
"=>",
"false",
",",
"'root'",
"=>",
"null",
",",
"'root_code'",
"=>",
"null",
",",
"'filter'",
"=>",
"null",
",",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'root'",
",",
"[",
"TaxonInterface",
"::",
"class",
",",
"'string'",
",",
"'null'",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'root_code'",
",",
"[",
"'string'",
",",
"'null'",
"]",
")",
"->",
"setAllowedTypes",
"(",
"'filter'",
",",
"[",
"'callable'",
",",
"'null'",
"]",
")",
"->",
"setNormalizer",
"(",
"'root'",
",",
"function",
"(",
"Options",
"$",
"options",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"TaxonInterface",
")",
"{",
"return",
"$",
"value",
"->",
"getCode",
"(",
")",
";",
"}",
"return",
"$",
"value",
"?",
":",
"$",
"options",
"[",
"'root_code'",
"]",
";",
"}",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Form/Type/TaxonChoiceType.php#L77-L102 |
phpmob/changmin | src/PhpMob/ChangMinBundle/Form/Type/TaxonChoiceType.php | TaxonChoiceType.getTaxons | private function getTaxons($rootCode = null, $filter = null)
{
$taxons = $this->taxonRepository->findNodesTreeSorted($rootCode);
if (null !== $filter) {
$taxons = array_filter($taxons, $filter);
}
return $taxons;
} | php | private function getTaxons($rootCode = null, $filter = null)
{
$taxons = $this->taxonRepository->findNodesTreeSorted($rootCode);
if (null !== $filter) {
$taxons = array_filter($taxons, $filter);
}
return $taxons;
} | [
"private",
"function",
"getTaxons",
"(",
"$",
"rootCode",
"=",
"null",
",",
"$",
"filter",
"=",
"null",
")",
"{",
"$",
"taxons",
"=",
"$",
"this",
"->",
"taxonRepository",
"->",
"findNodesTreeSorted",
"(",
"$",
"rootCode",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"filter",
")",
"{",
"$",
"taxons",
"=",
"array_filter",
"(",
"$",
"taxons",
",",
"$",
"filter",
")",
";",
"}",
"return",
"$",
"taxons",
";",
"}"
]
| @param string|null $rootCode
@param callable|null $filter
@return TaxonInterface[] | [
"@param",
"string|null",
"$rootCode",
"@param",
"callable|null",
"$filter"
]
| train | https://github.com/phpmob/changmin/blob/bfebb1561229094d1c138574abab75f2f1d17d66/src/PhpMob/ChangMinBundle/Form/Type/TaxonChoiceType.php#L110-L119 |
spiral-modules/scaffolder | source/Scaffolder/Commands/Database/DocumentCommand.php | DocumentCommand.perform | public function perform()
{
/** @var DocumentDeclaration $declaration */
$declaration = $this->createDeclaration();
foreach ($this->option('field') as $field) {
if (strpos($field, ':') === false) {
throw new ScaffolderException("Field definition must in 'name:type' form");
}
list($name, $type) = explode(':', $field);
$declaration->addField($name, $type);
}
$declaration->setCollection((string)$this->option('collection'));
$declaration->setDatabase((string)$this->option('database'));
$this->writeDeclaration($declaration->normalizeDeclaration());
if ($this->option('source')) {
$this->writeDeclaration(
$this->sourceDeclaration(
$this->argument('name'),
'document',
$this->getNamespace() . '\\' . $this->getClass()
),
'source'
);
}
} | php | public function perform()
{
/** @var DocumentDeclaration $declaration */
$declaration = $this->createDeclaration();
foreach ($this->option('field') as $field) {
if (strpos($field, ':') === false) {
throw new ScaffolderException("Field definition must in 'name:type' form");
}
list($name, $type) = explode(':', $field);
$declaration->addField($name, $type);
}
$declaration->setCollection((string)$this->option('collection'));
$declaration->setDatabase((string)$this->option('database'));
$this->writeDeclaration($declaration->normalizeDeclaration());
if ($this->option('source')) {
$this->writeDeclaration(
$this->sourceDeclaration(
$this->argument('name'),
'document',
$this->getNamespace() . '\\' . $this->getClass()
),
'source'
);
}
} | [
"public",
"function",
"perform",
"(",
")",
"{",
"/** @var DocumentDeclaration $declaration */",
"$",
"declaration",
"=",
"$",
"this",
"->",
"createDeclaration",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"option",
"(",
"'field'",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"field",
",",
"':'",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"ScaffolderException",
"(",
"\"Field definition must in 'name:type' form\"",
")",
";",
"}",
"list",
"(",
"$",
"name",
",",
"$",
"type",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"field",
")",
";",
"$",
"declaration",
"->",
"addField",
"(",
"$",
"name",
",",
"$",
"type",
")",
";",
"}",
"$",
"declaration",
"->",
"setCollection",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"option",
"(",
"'collection'",
")",
")",
";",
"$",
"declaration",
"->",
"setDatabase",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"option",
"(",
"'database'",
")",
")",
";",
"$",
"this",
"->",
"writeDeclaration",
"(",
"$",
"declaration",
"->",
"normalizeDeclaration",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'source'",
")",
")",
"{",
"$",
"this",
"->",
"writeDeclaration",
"(",
"$",
"this",
"->",
"sourceDeclaration",
"(",
"$",
"this",
"->",
"argument",
"(",
"'name'",
")",
",",
"'document'",
",",
"$",
"this",
"->",
"getNamespace",
"(",
")",
".",
"'\\\\'",
".",
"$",
"this",
"->",
"getClass",
"(",
")",
")",
",",
"'source'",
")",
";",
"}",
"}"
]
| Create controller declaration. | [
"Create",
"controller",
"declaration",
"."
]
| train | https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Commands/Database/DocumentCommand.php#L36-L65 |
spiral-modules/scaffolder | source/Scaffolder/Commands/Database/DocumentCommand.php | DocumentCommand.defineOptions | protected function defineOptions(): array
{
return [
[
'field',
'f',
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Add field in a format "name:type"'
],
[
'collection',
't',
InputOption::VALUE_OPTIONAL,
'Associated collection'
],
[
'database',
'db',
InputOption::VALUE_OPTIONAL,
'Associated database'
],
[
'comment',
'c',
InputOption::VALUE_OPTIONAL,
'Optional comment to add as class header'
],
[
'source',
's',
InputOption::VALUE_NONE,
'Create source/repository class'
]
];
} | php | protected function defineOptions(): array
{
return [
[
'field',
'f',
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
'Add field in a format "name:type"'
],
[
'collection',
't',
InputOption::VALUE_OPTIONAL,
'Associated collection'
],
[
'database',
'db',
InputOption::VALUE_OPTIONAL,
'Associated database'
],
[
'comment',
'c',
InputOption::VALUE_OPTIONAL,
'Optional comment to add as class header'
],
[
'source',
's',
InputOption::VALUE_NONE,
'Create source/repository class'
]
];
} | [
"protected",
"function",
"defineOptions",
"(",
")",
":",
"array",
"{",
"return",
"[",
"[",
"'field'",
",",
"'f'",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
"|",
"InputOption",
"::",
"VALUE_IS_ARRAY",
",",
"'Add field in a format \"name:type\"'",
"]",
",",
"[",
"'collection'",
",",
"'t'",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Associated collection'",
"]",
",",
"[",
"'database'",
",",
"'db'",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Associated database'",
"]",
",",
"[",
"'comment'",
",",
"'c'",
",",
"InputOption",
"::",
"VALUE_OPTIONAL",
",",
"'Optional comment to add as class header'",
"]",
",",
"[",
"'source'",
",",
"'s'",
",",
"InputOption",
"::",
"VALUE_NONE",
",",
"'Create source/repository class'",
"]",
"]",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/spiral-modules/scaffolder/blob/9be9dd0da6e4b02232db24e797fe5c288afbbddf/source/Scaffolder/Commands/Database/DocumentCommand.php#L70-L104 |
meccado/acl-admin-control-panel | src/Http/Controllers/Admin/RoleController.php | RoleController.store | public function store(Request $request)
{
$this->roles->create($request->only('name', 'label'));
return \Redirect::route('admin.roles.index', [
])->withMessage(trans('acl::role.roles-controller-successfully_created'));
} | php | public function store(Request $request)
{
$this->roles->create($request->only('name', 'label'));
return \Redirect::route('admin.roles.index', [
])->withMessage(trans('acl::role.roles-controller-successfully_created'));
} | [
"public",
"function",
"store",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"roles",
"->",
"create",
"(",
"$",
"request",
"->",
"only",
"(",
"'name'",
",",
"'label'",
")",
")",
";",
"return",
"\\",
"Redirect",
"::",
"route",
"(",
"'admin.roles.index'",
",",
"[",
"]",
")",
"->",
"withMessage",
"(",
"trans",
"(",
"'acl::role.roles-controller-successfully_created'",
")",
")",
";",
"}"
]
| Store a newly created resource in storage.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\RedirectResponse | [
"Store",
"a",
"newly",
"created",
"resource",
"in",
"storage",
"."
]
| train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/RoleController.php#L56-L61 |
meccado/acl-admin-control-panel | src/Http/Controllers/Admin/RoleController.php | RoleController.show | public function show($id)
{
$role = Role::with('permissions')->findOrFail($id);
return \View::make('admin.roles.show', compact('role'));
} | php | public function show($id)
{
$role = Role::with('permissions')->findOrFail($id);
return \View::make('admin.roles.show', compact('role'));
} | [
"public",
"function",
"show",
"(",
"$",
"id",
")",
"{",
"$",
"role",
"=",
"Role",
"::",
"with",
"(",
"'permissions'",
")",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"return",
"\\",
"View",
"::",
"make",
"(",
"'admin.roles.show'",
",",
"compact",
"(",
"'role'",
")",
")",
";",
"}"
]
| Display the specified resource.
@param int $id
@return \Illuminate\View\View | [
"Display",
"the",
"specified",
"resource",
"."
]
| train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/RoleController.php#L69-L73 |
meccado/acl-admin-control-panel | src/Http/Controllers/Admin/RoleController.php | RoleController.edit | public function edit($id)
{
$role = $this->roles->findOrFail($id);
return \View::make('admin.roles.edit', [
'role' => $role,
'title' => 'edit',
]);
} | php | public function edit($id)
{
$role = $this->roles->findOrFail($id);
return \View::make('admin.roles.edit', [
'role' => $role,
'title' => 'edit',
]);
} | [
"public",
"function",
"edit",
"(",
"$",
"id",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"roles",
"->",
"findOrFail",
"(",
"$",
"id",
")",
";",
"return",
"\\",
"View",
"::",
"make",
"(",
"'admin.roles.edit'",
",",
"[",
"'role'",
"=>",
"$",
"role",
",",
"'title'",
"=>",
"'edit'",
",",
"]",
")",
";",
"}"
]
| Show the form for editing the specified resource.
@param int $id
@return \Illuminate\View\View | [
"Show",
"the",
"form",
"for",
"editing",
"the",
"specified",
"resource",
"."
]
| train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/RoleController.php#L81-L88 |
meccado/acl-admin-control-panel | src/Http/Controllers/Admin/RoleController.php | RoleController.update | public function update(Request $request, $id)
{
$this->roles->findOrFail($id)->update($request->only('name', 'label'));
return \Redirect::route('admin.roles.index', [
])->withMessage(trans('acl::role.roles-controller-successfully_updated'));
} | php | public function update(Request $request, $id)
{
$this->roles->findOrFail($id)->update($request->only('name', 'label'));
return \Redirect::route('admin.roles.index', [
])->withMessage(trans('acl::role.roles-controller-successfully_updated'));
} | [
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"roles",
"->",
"findOrFail",
"(",
"$",
"id",
")",
"->",
"update",
"(",
"$",
"request",
"->",
"only",
"(",
"'name'",
",",
"'label'",
")",
")",
";",
"return",
"\\",
"Redirect",
"::",
"route",
"(",
"'admin.roles.index'",
",",
"[",
"]",
")",
"->",
"withMessage",
"(",
"trans",
"(",
"'acl::role.roles-controller-successfully_updated'",
")",
")",
";",
"}"
]
| Update the specified resource in storage.
@param \Illuminate\Http\Request $request
@param int $id
@return \Illuminate\Http\RedirectResponse | [
"Update",
"the",
"specified",
"resource",
"in",
"storage",
"."
]
| train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Admin/RoleController.php#L97-L102 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.