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
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getBuildProperty
protected function getBuildProperty($name) { if ($this->generatorConfig !== null) { return $this->generatorConfig->getBuildProperty($name); } return null; }
php
protected function getBuildProperty($name) { if ($this->generatorConfig !== null) { return $this->generatorConfig->getBuildProperty($name); } return null; }
[ "protected", "function", "getBuildProperty", "(", "$", "name", ")", "{", "if", "(", "$", "this", "->", "generatorConfig", "!==", "null", ")", "{", "return", "$", "this", "->", "generatorConfig", "->", "getBuildProperty", "(", "$", "name", ")", ";", "}", "return", "null", ";", "}" ]
Gets a specific propel (renamed) property from the build. @param string $name @return mixed
[ "Gets", "a", "specific", "propel", "(", "renamed", ")", "property", "from", "the", "build", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L94-L101
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.initialize
protected function initialize() { $this->schemaDomainMap = array(); foreach (PropelTypes::getPropelTypes() as $type) { $this->schemaDomainMap[$type] = new Domain($type); } // BU_* no longer needed, so map these to the DATE/TIMESTAMP domains $this->schemaDomainMap[PropelTypes::BU_DATE] = new Domain(PropelTypes::DATE); $this->schemaDomainMap[PropelTypes::BU_TIMESTAMP] = new Domain(PropelTypes::TIMESTAMP); // Boolean is a bit special, since typically it must be mapped to INT type. $this->schemaDomainMap[PropelTypes::BOOLEAN] = new Domain(PropelTypes::BOOLEAN, "INTEGER"); }
php
protected function initialize() { $this->schemaDomainMap = array(); foreach (PropelTypes::getPropelTypes() as $type) { $this->schemaDomainMap[$type] = new Domain($type); } // BU_* no longer needed, so map these to the DATE/TIMESTAMP domains $this->schemaDomainMap[PropelTypes::BU_DATE] = new Domain(PropelTypes::DATE); $this->schemaDomainMap[PropelTypes::BU_TIMESTAMP] = new Domain(PropelTypes::TIMESTAMP); // Boolean is a bit special, since typically it must be mapped to INT type. $this->schemaDomainMap[PropelTypes::BOOLEAN] = new Domain(PropelTypes::BOOLEAN, "INTEGER"); }
[ "protected", "function", "initialize", "(", ")", "{", "$", "this", "->", "schemaDomainMap", "=", "array", "(", ")", ";", "foreach", "(", "PropelTypes", "::", "getPropelTypes", "(", ")", "as", "$", "type", ")", "{", "$", "this", "->", "schemaDomainMap", "[", "$", "type", "]", "=", "new", "Domain", "(", "$", "type", ")", ";", "}", "// BU_* no longer needed, so map these to the DATE/TIMESTAMP domains", "$", "this", "->", "schemaDomainMap", "[", "PropelTypes", "::", "BU_DATE", "]", "=", "new", "Domain", "(", "PropelTypes", "::", "DATE", ")", ";", "$", "this", "->", "schemaDomainMap", "[", "PropelTypes", "::", "BU_TIMESTAMP", "]", "=", "new", "Domain", "(", "PropelTypes", "::", "TIMESTAMP", ")", ";", "// Boolean is a bit special, since typically it must be mapped to INT type.", "$", "this", "->", "schemaDomainMap", "[", "PropelTypes", "::", "BOOLEAN", "]", "=", "new", "Domain", "(", "PropelTypes", "::", "BOOLEAN", ",", "\"INTEGER\"", ")", ";", "}" ]
Initialize the type -> Domain mapping.
[ "Initialize", "the", "type", "-", ">", "Domain", "mapping", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L106-L118
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getDatabaseType
public function getDatabaseType() { $clazz = get_class($this); $pos = strpos($clazz, 'Platform'); return strtolower(substr($clazz, 0, $pos)); }
php
public function getDatabaseType() { $clazz = get_class($this); $pos = strpos($clazz, 'Platform'); return strtolower(substr($clazz, 0, $pos)); }
[ "public", "function", "getDatabaseType", "(", ")", "{", "$", "clazz", "=", "get_class", "(", "$", "this", ")", ";", "$", "pos", "=", "strpos", "(", "$", "clazz", ",", "'Platform'", ")", ";", "return", "strtolower", "(", "substr", "(", "$", "clazz", ",", "0", ",", "$", "pos", ")", ")", ";", "}" ]
Returns the short name of the database type that this platform represents. For example MysqlPlatform->getDatabaseType() returns 'mysql'. @return string
[ "Returns", "the", "short", "name", "of", "the", "database", "type", "that", "this", "platform", "represents", ".", "For", "example", "MysqlPlatform", "-", ">", "getDatabaseType", "()", "returns", "mysql", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L136-L142
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getDomainForType
public function getDomainForType($propelType) { if (!isset($this->schemaDomainMap[$propelType])) { throw new EngineException("Cannot map unknown Propel type " . var_export($propelType, true) . " to native database type."); } return $this->schemaDomainMap[$propelType]; }
php
public function getDomainForType($propelType) { if (!isset($this->schemaDomainMap[$propelType])) { throw new EngineException("Cannot map unknown Propel type " . var_export($propelType, true) . " to native database type."); } return $this->schemaDomainMap[$propelType]; }
[ "public", "function", "getDomainForType", "(", "$", "propelType", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "schemaDomainMap", "[", "$", "propelType", "]", ")", ")", "{", "throw", "new", "EngineException", "(", "\"Cannot map unknown Propel type \"", ".", "var_export", "(", "$", "propelType", ",", "true", ")", ".", "\" to native database type.\"", ")", ";", "}", "return", "$", "this", "->", "schemaDomainMap", "[", "$", "propelType", "]", ";", "}" ]
Returns the db specific domain for a propelType. @param string $propelType the Propel type name. @return Domain The db specific domain. @throws EngineException
[ "Returns", "the", "db", "specific", "domain", "for", "a", "propelType", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L177-L184
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getSequenceName
public function getSequenceName(Table $table) { static $longNamesMap = array(); $result = null; if ($table->getIdMethod() == IDMethod::NATIVE) { $idMethodParams = $table->getIdMethodParameters(); $maxIdentifierLength = $this->getMaxColumnNameLength(); if (empty($idMethodParams)) { if (strlen($table->getName() . "_SEQ") > $maxIdentifierLength) { if (!isset($longNamesMap[$table->getName()])) { $longNamesMap[$table->getName()] = strval(count($longNamesMap) + 1); } $result = substr($table->getName(), 0, $maxIdentifierLength - strlen("_SEQ_" . $longNamesMap[$table->getName()])) . "_SEQ_" . $longNamesMap[$table->getName()]; } else { $result = substr($table->getName(), 0, $maxIdentifierLength - 4) . "_SEQ"; } } else { $result = substr($idMethodParams[0]->getValue(), 0, $maxIdentifierLength); } } return $result; }
php
public function getSequenceName(Table $table) { static $longNamesMap = array(); $result = null; if ($table->getIdMethod() == IDMethod::NATIVE) { $idMethodParams = $table->getIdMethodParameters(); $maxIdentifierLength = $this->getMaxColumnNameLength(); if (empty($idMethodParams)) { if (strlen($table->getName() . "_SEQ") > $maxIdentifierLength) { if (!isset($longNamesMap[$table->getName()])) { $longNamesMap[$table->getName()] = strval(count($longNamesMap) + 1); } $result = substr($table->getName(), 0, $maxIdentifierLength - strlen("_SEQ_" . $longNamesMap[$table->getName()])) . "_SEQ_" . $longNamesMap[$table->getName()]; } else { $result = substr($table->getName(), 0, $maxIdentifierLength - 4) . "_SEQ"; } } else { $result = substr($idMethodParams[0]->getValue(), 0, $maxIdentifierLength); } } return $result; }
[ "public", "function", "getSequenceName", "(", "Table", "$", "table", ")", "{", "static", "$", "longNamesMap", "=", "array", "(", ")", ";", "$", "result", "=", "null", ";", "if", "(", "$", "table", "->", "getIdMethod", "(", ")", "==", "IDMethod", "::", "NATIVE", ")", "{", "$", "idMethodParams", "=", "$", "table", "->", "getIdMethodParameters", "(", ")", ";", "$", "maxIdentifierLength", "=", "$", "this", "->", "getMaxColumnNameLength", "(", ")", ";", "if", "(", "empty", "(", "$", "idMethodParams", ")", ")", "{", "if", "(", "strlen", "(", "$", "table", "->", "getName", "(", ")", ".", "\"_SEQ\"", ")", ">", "$", "maxIdentifierLength", ")", "{", "if", "(", "!", "isset", "(", "$", "longNamesMap", "[", "$", "table", "->", "getName", "(", ")", "]", ")", ")", "{", "$", "longNamesMap", "[", "$", "table", "->", "getName", "(", ")", "]", "=", "strval", "(", "count", "(", "$", "longNamesMap", ")", "+", "1", ")", ";", "}", "$", "result", "=", "substr", "(", "$", "table", "->", "getName", "(", ")", ",", "0", ",", "$", "maxIdentifierLength", "-", "strlen", "(", "\"_SEQ_\"", ".", "$", "longNamesMap", "[", "$", "table", "->", "getName", "(", ")", "]", ")", ")", ".", "\"_SEQ_\"", ".", "$", "longNamesMap", "[", "$", "table", "->", "getName", "(", ")", "]", ";", "}", "else", "{", "$", "result", "=", "substr", "(", "$", "table", "->", "getName", "(", ")", ",", "0", ",", "$", "maxIdentifierLength", "-", "4", ")", ".", "\"_SEQ\"", ";", "}", "}", "else", "{", "$", "result", "=", "substr", "(", "$", "idMethodParams", "[", "0", "]", "->", "getValue", "(", ")", ",", "0", ",", "$", "maxIdentifierLength", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Gets the name to use for creating a sequence for a table. This will create a new name or use one specified in an id-method-parameter tag, if specified. @param Table $table @return string Sequence name for this table.
[ "Gets", "the", "name", "to", "use", "for", "creating", "a", "sequence", "for", "a", "table", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L213-L235
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getDropPrimaryKeyDDL
public function getDropPrimaryKeyDDL(Table $table) { $pattern = " ALTER TABLE %s DROP CONSTRAINT %s; "; return sprintf($pattern, $this->quoteIdentifier($table->getName()), $this->quoteIdentifier($this->getPrimaryKeyName($table)) ); }
php
public function getDropPrimaryKeyDDL(Table $table) { $pattern = " ALTER TABLE %s DROP CONSTRAINT %s; "; return sprintf($pattern, $this->quoteIdentifier($table->getName()), $this->quoteIdentifier($this->getPrimaryKeyName($table)) ); }
[ "public", "function", "getDropPrimaryKeyDDL", "(", "Table", "$", "table", ")", "{", "$", "pattern", "=", "\"\nALTER TABLE %s DROP CONSTRAINT %s;\n\"", ";", "return", "sprintf", "(", "$", "pattern", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "table", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "this", "->", "getPrimaryKeyName", "(", "$", "table", ")", ")", ")", ";", "}" ]
Builds the DDL SQL to drop the primary key of a table. @param Table $table @return string
[ "Builds", "the", "DDL", "SQL", "to", "drop", "the", "primary", "key", "of", "a", "table", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L452-L462
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getAddPrimaryKeyDDL
public function getAddPrimaryKeyDDL(Table $table) { $pattern = " ALTER TABLE %s ADD %s; "; return sprintf($pattern, $this->quoteIdentifier($table->getName()), $this->getPrimaryKeyDDL($table) ); }
php
public function getAddPrimaryKeyDDL(Table $table) { $pattern = " ALTER TABLE %s ADD %s; "; return sprintf($pattern, $this->quoteIdentifier($table->getName()), $this->getPrimaryKeyDDL($table) ); }
[ "public", "function", "getAddPrimaryKeyDDL", "(", "Table", "$", "table", ")", "{", "$", "pattern", "=", "\"\nALTER TABLE %s ADD %s;\n\"", ";", "return", "sprintf", "(", "$", "pattern", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "table", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "getPrimaryKeyDDL", "(", "$", "table", ")", ")", ";", "}" ]
Builds the DDL SQL to add the primary key of a table. @param Table $table @return string
[ "Builds", "the", "DDL", "SQL", "to", "add", "the", "primary", "key", "of", "a", "table", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L471-L481
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getDropIndexDDL
public function getDropIndexDDL(Index $index) { $pattern = " DROP INDEX %s; "; return sprintf($pattern, $this->quoteIdentifier($index->getName())); }
php
public function getDropIndexDDL(Index $index) { $pattern = " DROP INDEX %s; "; return sprintf($pattern, $this->quoteIdentifier($index->getName())); }
[ "public", "function", "getDropIndexDDL", "(", "Index", "$", "index", ")", "{", "$", "pattern", "=", "\"\nDROP INDEX %s;\n\"", ";", "return", "sprintf", "(", "$", "pattern", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "index", "->", "getName", "(", ")", ")", ")", ";", "}" ]
Builds the DDL SQL to drop an Index. @param Index $index @return string
[ "Builds", "the", "DDL", "SQL", "to", "drop", "an", "Index", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L528-L535
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getIndexDDL
public function getIndexDDL(Index $index) { return sprintf('%sINDEX %s (%s)', $index->getIsUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->getColumnListDDL($index->getColumns())); }
php
public function getIndexDDL(Index $index) { return sprintf('%sINDEX %s (%s)', $index->getIsUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->getColumnListDDL($index->getColumns())); }
[ "public", "function", "getIndexDDL", "(", "Index", "$", "index", ")", "{", "return", "sprintf", "(", "'%sINDEX %s (%s)'", ",", "$", "index", "->", "getIsUnique", "(", ")", "?", "'UNIQUE '", ":", "''", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "index", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "getColumnListDDL", "(", "$", "index", "->", "getColumns", "(", ")", ")", ")", ";", "}" ]
Builds the DDL SQL for an Index object. @param Index $index @return string
[ "Builds", "the", "DDL", "SQL", "for", "an", "Index", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L544-L547
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getDropForeignKeyDDL
public function getDropForeignKeyDDL(ForeignKey $fk) { if ($fk->isSkipSql()) { return; } $pattern = " ALTER TABLE %s DROP CONSTRAINT %s; "; return sprintf($pattern, $this->quoteIdentifier($fk->getTable()->getName()), $this->quoteIdentifier($fk->getName()) ); }
php
public function getDropForeignKeyDDL(ForeignKey $fk) { if ($fk->isSkipSql()) { return; } $pattern = " ALTER TABLE %s DROP CONSTRAINT %s; "; return sprintf($pattern, $this->quoteIdentifier($fk->getTable()->getName()), $this->quoteIdentifier($fk->getName()) ); }
[ "public", "function", "getDropForeignKeyDDL", "(", "ForeignKey", "$", "fk", ")", "{", "if", "(", "$", "fk", "->", "isSkipSql", "(", ")", ")", "{", "return", ";", "}", "$", "pattern", "=", "\"\nALTER TABLE %s DROP CONSTRAINT %s;\n\"", ";", "return", "sprintf", "(", "$", "pattern", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "fk", "->", "getTable", "(", ")", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "fk", "->", "getName", "(", ")", ")", ")", ";", "}" ]
Builds the DDL SQL to drop a foreign key. @param ForeignKey $fk @return string
[ "Builds", "the", "DDL", "SQL", "to", "drop", "a", "foreign", "key", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L607-L620
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getForeignKeyDDL
public function getForeignKeyDDL(ForeignKey $fk) { if ($fk->isSkipSql()) { return; } $pattern = "CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)"; $script = sprintf($pattern, $this->quoteIdentifier($fk->getName()), $this->getColumnListDDL($fk->getLocalColumns()), $this->quoteIdentifier($fk->getForeignTableName()), $this->getColumnListDDL($fk->getForeignColumns()) ); if ($fk->hasOnUpdate()) { $script .= " ON UPDATE " . $fk->getOnUpdate(); } if ($fk->hasOnDelete()) { $script .= " ON DELETE " . $fk->getOnDelete(); } return $script; }
php
public function getForeignKeyDDL(ForeignKey $fk) { if ($fk->isSkipSql()) { return; } $pattern = "CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)"; $script = sprintf($pattern, $this->quoteIdentifier($fk->getName()), $this->getColumnListDDL($fk->getLocalColumns()), $this->quoteIdentifier($fk->getForeignTableName()), $this->getColumnListDDL($fk->getForeignColumns()) ); if ($fk->hasOnUpdate()) { $script .= " ON UPDATE " . $fk->getOnUpdate(); } if ($fk->hasOnDelete()) { $script .= " ON DELETE " . $fk->getOnDelete(); } return $script; }
[ "public", "function", "getForeignKeyDDL", "(", "ForeignKey", "$", "fk", ")", "{", "if", "(", "$", "fk", "->", "isSkipSql", "(", ")", ")", "{", "return", ";", "}", "$", "pattern", "=", "\"CONSTRAINT %s\n FOREIGN KEY (%s)\n REFERENCES %s (%s)\"", ";", "$", "script", "=", "sprintf", "(", "$", "pattern", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "fk", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "getColumnListDDL", "(", "$", "fk", "->", "getLocalColumns", "(", ")", ")", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "fk", "->", "getForeignTableName", "(", ")", ")", ",", "$", "this", "->", "getColumnListDDL", "(", "$", "fk", "->", "getForeignColumns", "(", ")", ")", ")", ";", "if", "(", "$", "fk", "->", "hasOnUpdate", "(", ")", ")", "{", "$", "script", ".=", "\"\n ON UPDATE \"", ".", "$", "fk", "->", "getOnUpdate", "(", ")", ";", "}", "if", "(", "$", "fk", "->", "hasOnDelete", "(", ")", ")", "{", "$", "script", ".=", "\"\n ON DELETE \"", ".", "$", "fk", "->", "getOnDelete", "(", ")", ";", "}", "return", "$", "script", ";", "}" ]
Builds the DDL SQL for a ForeignKey object. @return string
[ "Builds", "the", "DDL", "SQL", "for", "a", "ForeignKey", "object", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L627-L651
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getModifyDatabaseDDL
public function getModifyDatabaseDDL(PropelDatabaseDiff $databaseDiff) { $ret = $this->getBeginDDL(); foreach ($databaseDiff->getRemovedTables() as $table) { $ret .= $this->getDropTableDDL($table); } foreach ($databaseDiff->getRenamedTables() as $fromTableName => $toTableName) { $ret .= $this->getRenameTableDDL($fromTableName, $toTableName); } foreach ($databaseDiff->getAddedTables() as $table) { $ret .= $this->getAddTableDDL($table); $ret .= $this->getAddIndicesDDL($table); } foreach ($databaseDiff->getModifiedTables() as $tableDiff) { $ret .= $this->getModifyTableDDL($tableDiff); } foreach ($databaseDiff->getAddedTables() as $table) { $ret .= $this->getAddForeignKeysDDL($table); } $ret .= $this->getEndDDL(); return $ret; }
php
public function getModifyDatabaseDDL(PropelDatabaseDiff $databaseDiff) { $ret = $this->getBeginDDL(); foreach ($databaseDiff->getRemovedTables() as $table) { $ret .= $this->getDropTableDDL($table); } foreach ($databaseDiff->getRenamedTables() as $fromTableName => $toTableName) { $ret .= $this->getRenameTableDDL($fromTableName, $toTableName); } foreach ($databaseDiff->getAddedTables() as $table) { $ret .= $this->getAddTableDDL($table); $ret .= $this->getAddIndicesDDL($table); } foreach ($databaseDiff->getModifiedTables() as $tableDiff) { $ret .= $this->getModifyTableDDL($tableDiff); } foreach ($databaseDiff->getAddedTables() as $table) { $ret .= $this->getAddForeignKeysDDL($table); } $ret .= $this->getEndDDL(); return $ret; }
[ "public", "function", "getModifyDatabaseDDL", "(", "PropelDatabaseDiff", "$", "databaseDiff", ")", "{", "$", "ret", "=", "$", "this", "->", "getBeginDDL", "(", ")", ";", "foreach", "(", "$", "databaseDiff", "->", "getRemovedTables", "(", ")", "as", "$", "table", ")", "{", "$", "ret", ".=", "$", "this", "->", "getDropTableDDL", "(", "$", "table", ")", ";", "}", "foreach", "(", "$", "databaseDiff", "->", "getRenamedTables", "(", ")", "as", "$", "fromTableName", "=>", "$", "toTableName", ")", "{", "$", "ret", ".=", "$", "this", "->", "getRenameTableDDL", "(", "$", "fromTableName", ",", "$", "toTableName", ")", ";", "}", "foreach", "(", "$", "databaseDiff", "->", "getAddedTables", "(", ")", "as", "$", "table", ")", "{", "$", "ret", ".=", "$", "this", "->", "getAddTableDDL", "(", "$", "table", ")", ";", "$", "ret", ".=", "$", "this", "->", "getAddIndicesDDL", "(", "$", "table", ")", ";", "}", "foreach", "(", "$", "databaseDiff", "->", "getModifiedTables", "(", ")", "as", "$", "tableDiff", ")", "{", "$", "ret", ".=", "$", "this", "->", "getModifyTableDDL", "(", "$", "tableDiff", ")", ";", "}", "foreach", "(", "$", "databaseDiff", "->", "getAddedTables", "(", ")", "as", "$", "table", ")", "{", "$", "ret", ".=", "$", "this", "->", "getAddForeignKeysDDL", "(", "$", "table", ")", ";", "}", "$", "ret", ".=", "$", "this", "->", "getEndDDL", "(", ")", ";", "return", "$", "ret", ";", "}" ]
Builds the DDL SQL to modify a database based on a PropelDatabaseDiff instance @return string
[ "Builds", "the", "DDL", "SQL", "to", "modify", "a", "database", "based", "on", "a", "PropelDatabaseDiff", "instance" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L678-L706
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getModifyTableDDL
public function getModifyTableDDL(PropelTableDiff $tableDiff) { $ret = ''; // drop indices, foreign keys if ($tableDiff->hasModifiedPk()) { $ret .= $this->getDropPrimaryKeyDDL($tableDiff->getFromTable()); } foreach ($tableDiff->getRemovedFks() as $fk) { $ret .= $this->getDropForeignKeyDDL($fk); } foreach ($tableDiff->getModifiedFks() as $fkName => $fkModification) { list($fromFk, $toFk) = $fkModification; $ret .= $this->getDropForeignKeyDDL($fromFk); } foreach ($tableDiff->getRemovedIndices() as $index) { $ret .= $this->getDropIndexDDL($index); } foreach ($tableDiff->getModifiedIndices() as $indexName => $indexModification) { list($fromIndex, $toIndex) = $indexModification; $ret .= $this->getDropIndexDDL($fromIndex); } // alter table structure foreach ($tableDiff->getRenamedColumns() as $columnRenaming) { $ret .= $this->getRenameColumnDDL($columnRenaming[0], $columnRenaming[1]); } if ($modifiedColumns = $tableDiff->getModifiedColumns()) { $ret .= $this->getModifyColumnsDDL($modifiedColumns); } if ($addedColumns = $tableDiff->getAddedColumns()) { $ret .= $this->getAddColumnsDDL($addedColumns); } foreach ($tableDiff->getRemovedColumns() as $column) { $ret .= $this->getRemoveColumnDDL($column); } // add new indices and foreign keys if ($tableDiff->hasModifiedPk()) { $ret .= $this->getAddPrimaryKeyDDL($tableDiff->getToTable()); } foreach ($tableDiff->getModifiedIndices() as $indexName => $indexModification) { list($fromIndex, $toIndex) = $indexModification; $ret .= $this->getAddIndexDDL($toIndex); } foreach ($tableDiff->getAddedIndices() as $index) { $ret .= $this->getAddIndexDDL($index); } foreach ($tableDiff->getModifiedFks() as $fkName => $fkModification) { list($fromFk, $toFk) = $fkModification; $ret .= $this->getAddForeignKeyDDL($toFk); } foreach ($tableDiff->getAddedFks() as $fk) { $ret .= $this->getAddForeignKeyDDL($fk); } return $ret; }
php
public function getModifyTableDDL(PropelTableDiff $tableDiff) { $ret = ''; // drop indices, foreign keys if ($tableDiff->hasModifiedPk()) { $ret .= $this->getDropPrimaryKeyDDL($tableDiff->getFromTable()); } foreach ($tableDiff->getRemovedFks() as $fk) { $ret .= $this->getDropForeignKeyDDL($fk); } foreach ($tableDiff->getModifiedFks() as $fkName => $fkModification) { list($fromFk, $toFk) = $fkModification; $ret .= $this->getDropForeignKeyDDL($fromFk); } foreach ($tableDiff->getRemovedIndices() as $index) { $ret .= $this->getDropIndexDDL($index); } foreach ($tableDiff->getModifiedIndices() as $indexName => $indexModification) { list($fromIndex, $toIndex) = $indexModification; $ret .= $this->getDropIndexDDL($fromIndex); } // alter table structure foreach ($tableDiff->getRenamedColumns() as $columnRenaming) { $ret .= $this->getRenameColumnDDL($columnRenaming[0], $columnRenaming[1]); } if ($modifiedColumns = $tableDiff->getModifiedColumns()) { $ret .= $this->getModifyColumnsDDL($modifiedColumns); } if ($addedColumns = $tableDiff->getAddedColumns()) { $ret .= $this->getAddColumnsDDL($addedColumns); } foreach ($tableDiff->getRemovedColumns() as $column) { $ret .= $this->getRemoveColumnDDL($column); } // add new indices and foreign keys if ($tableDiff->hasModifiedPk()) { $ret .= $this->getAddPrimaryKeyDDL($tableDiff->getToTable()); } foreach ($tableDiff->getModifiedIndices() as $indexName => $indexModification) { list($fromIndex, $toIndex) = $indexModification; $ret .= $this->getAddIndexDDL($toIndex); } foreach ($tableDiff->getAddedIndices() as $index) { $ret .= $this->getAddIndexDDL($index); } foreach ($tableDiff->getModifiedFks() as $fkName => $fkModification) { list($fromFk, $toFk) = $fkModification; $ret .= $this->getAddForeignKeyDDL($toFk); } foreach ($tableDiff->getAddedFks() as $fk) { $ret .= $this->getAddForeignKeyDDL($fk); } return $ret; }
[ "public", "function", "getModifyTableDDL", "(", "PropelTableDiff", "$", "tableDiff", ")", "{", "$", "ret", "=", "''", ";", "// drop indices, foreign keys", "if", "(", "$", "tableDiff", "->", "hasModifiedPk", "(", ")", ")", "{", "$", "ret", ".=", "$", "this", "->", "getDropPrimaryKeyDDL", "(", "$", "tableDiff", "->", "getFromTable", "(", ")", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getRemovedFks", "(", ")", "as", "$", "fk", ")", "{", "$", "ret", ".=", "$", "this", "->", "getDropForeignKeyDDL", "(", "$", "fk", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getModifiedFks", "(", ")", "as", "$", "fkName", "=>", "$", "fkModification", ")", "{", "list", "(", "$", "fromFk", ",", "$", "toFk", ")", "=", "$", "fkModification", ";", "$", "ret", ".=", "$", "this", "->", "getDropForeignKeyDDL", "(", "$", "fromFk", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getRemovedIndices", "(", ")", "as", "$", "index", ")", "{", "$", "ret", ".=", "$", "this", "->", "getDropIndexDDL", "(", "$", "index", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getModifiedIndices", "(", ")", "as", "$", "indexName", "=>", "$", "indexModification", ")", "{", "list", "(", "$", "fromIndex", ",", "$", "toIndex", ")", "=", "$", "indexModification", ";", "$", "ret", ".=", "$", "this", "->", "getDropIndexDDL", "(", "$", "fromIndex", ")", ";", "}", "// alter table structure", "foreach", "(", "$", "tableDiff", "->", "getRenamedColumns", "(", ")", "as", "$", "columnRenaming", ")", "{", "$", "ret", ".=", "$", "this", "->", "getRenameColumnDDL", "(", "$", "columnRenaming", "[", "0", "]", ",", "$", "columnRenaming", "[", "1", "]", ")", ";", "}", "if", "(", "$", "modifiedColumns", "=", "$", "tableDiff", "->", "getModifiedColumns", "(", ")", ")", "{", "$", "ret", ".=", "$", "this", "->", "getModifyColumnsDDL", "(", "$", "modifiedColumns", ")", ";", "}", "if", "(", "$", "addedColumns", "=", "$", "tableDiff", "->", "getAddedColumns", "(", ")", ")", "{", "$", "ret", ".=", "$", "this", "->", "getAddColumnsDDL", "(", "$", "addedColumns", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getRemovedColumns", "(", ")", "as", "$", "column", ")", "{", "$", "ret", ".=", "$", "this", "->", "getRemoveColumnDDL", "(", "$", "column", ")", ";", "}", "// add new indices and foreign keys", "if", "(", "$", "tableDiff", "->", "hasModifiedPk", "(", ")", ")", "{", "$", "ret", ".=", "$", "this", "->", "getAddPrimaryKeyDDL", "(", "$", "tableDiff", "->", "getToTable", "(", ")", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getModifiedIndices", "(", ")", "as", "$", "indexName", "=>", "$", "indexModification", ")", "{", "list", "(", "$", "fromIndex", ",", "$", "toIndex", ")", "=", "$", "indexModification", ";", "$", "ret", ".=", "$", "this", "->", "getAddIndexDDL", "(", "$", "toIndex", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getAddedIndices", "(", ")", "as", "$", "index", ")", "{", "$", "ret", ".=", "$", "this", "->", "getAddIndexDDL", "(", "$", "index", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getModifiedFks", "(", ")", "as", "$", "fkName", "=>", "$", "fkModification", ")", "{", "list", "(", "$", "fromFk", ",", "$", "toFk", ")", "=", "$", "fkModification", ";", "$", "ret", ".=", "$", "this", "->", "getAddForeignKeyDDL", "(", "$", "toFk", ")", ";", "}", "foreach", "(", "$", "tableDiff", "->", "getAddedFks", "(", ")", "as", "$", "fk", ")", "{", "$", "ret", ".=", "$", "this", "->", "getAddForeignKeyDDL", "(", "$", "fk", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Builds the DDL SQL to alter a table based on a PropelTableDiff instance @return string
[ "Builds", "the", "DDL", "SQL", "to", "alter", "a", "table", "based", "on", "a", "PropelTableDiff", "instance" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L731-L788
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getRenameColumnDDL
public function getRenameColumnDDL($fromColumn, $toColumn) { $pattern = " ALTER TABLE %s RENAME COLUMN %s TO %s; "; return sprintf($pattern, $this->quoteIdentifier($fromColumn->getTable()->getName()), $this->quoteIdentifier($fromColumn->getName()), $this->quoteIdentifier($toColumn->getName()) ); }
php
public function getRenameColumnDDL($fromColumn, $toColumn) { $pattern = " ALTER TABLE %s RENAME COLUMN %s TO %s; "; return sprintf($pattern, $this->quoteIdentifier($fromColumn->getTable()->getName()), $this->quoteIdentifier($fromColumn->getName()), $this->quoteIdentifier($toColumn->getName()) ); }
[ "public", "function", "getRenameColumnDDL", "(", "$", "fromColumn", ",", "$", "toColumn", ")", "{", "$", "pattern", "=", "\"\nALTER TABLE %s RENAME COLUMN %s TO %s;\n\"", ";", "return", "sprintf", "(", "$", "pattern", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "fromColumn", "->", "getTable", "(", ")", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "fromColumn", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "toColumn", "->", "getName", "(", ")", ")", ")", ";", "}" ]
Builds the DDL SQL to rename a column @return string
[ "Builds", "the", "DDL", "SQL", "to", "rename", "a", "column" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L913-L924
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getModifyColumnDDL
public function getModifyColumnDDL(PropelColumnDiff $columnDiff) { $toColumn = $columnDiff->getToColumn(); $pattern = " ALTER TABLE %s MODIFY %s; "; return sprintf($pattern, $this->quoteIdentifier($toColumn->getTable()->getName()), $this->getColumnDDL($toColumn) ); }
php
public function getModifyColumnDDL(PropelColumnDiff $columnDiff) { $toColumn = $columnDiff->getToColumn(); $pattern = " ALTER TABLE %s MODIFY %s; "; return sprintf($pattern, $this->quoteIdentifier($toColumn->getTable()->getName()), $this->getColumnDDL($toColumn) ); }
[ "public", "function", "getModifyColumnDDL", "(", "PropelColumnDiff", "$", "columnDiff", ")", "{", "$", "toColumn", "=", "$", "columnDiff", "->", "getToColumn", "(", ")", ";", "$", "pattern", "=", "\"\nALTER TABLE %s MODIFY %s;\n\"", ";", "return", "sprintf", "(", "$", "pattern", ",", "$", "this", "->", "quoteIdentifier", "(", "$", "toColumn", "->", "getTable", "(", ")", "->", "getName", "(", ")", ")", ",", "$", "this", "->", "getColumnDDL", "(", "$", "toColumn", ")", ")", ";", "}" ]
Builds the DDL SQL to modify a column @return string
[ "Builds", "the", "DDL", "SQL", "to", "modify", "a", "column" ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L931-L942
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getBooleanString
public function getBooleanString($b) { $b = ($b === true || strtolower($b) === 'true' || $b === 1 || $b === '1' || strtolower($b) === 'y' || strtolower($b) === 'yes'); return ($b ? '1' : '0'); }
php
public function getBooleanString($b) { $b = ($b === true || strtolower($b) === 'true' || $b === 1 || $b === '1' || strtolower($b) === 'y' || strtolower($b) === 'yes'); return ($b ? '1' : '0'); }
[ "public", "function", "getBooleanString", "(", "$", "b", ")", "{", "$", "b", "=", "(", "$", "b", "===", "true", "||", "strtolower", "(", "$", "b", ")", "===", "'true'", "||", "$", "b", "===", "1", "||", "$", "b", "===", "'1'", "||", "strtolower", "(", "$", "b", ")", "===", "'y'", "||", "strtolower", "(", "$", "b", ")", "===", "'yes'", ")", ";", "return", "(", "$", "b", "?", "'1'", ":", "'0'", ")", ";", "}" ]
Returns the boolean value for the RDBMS. This value should match the boolean value that is set when using Propel's PreparedStatement::setBoolean(). This function is used to set default column values when building SQL. @param mixed $tf A boolean or string representation of boolean ('y', 'true'). @return mixed
[ "Returns", "the", "boolean", "value", "for", "the", "RDBMS", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L1165-L1170
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getColumnBindingPHP
public function getColumnBindingPHP($column, $identifier, $columnValueAccessor, $tab = " ") { $script = ''; $hasValuePreparation = false; if ($column->isTemporalType()) { // nothing special, the internal value was already properly formatted by the setter } elseif ($column->isLobType()) { // we always need to make sure that the stream is rewound, otherwise nothing will // get written to database. $script .= " if (is_resource($columnValueAccessor)) { rewind($columnValueAccessor); }"; } $script .= sprintf( " \$stmt->bindValue(%s, %s, %s);", $identifier, $columnValueAccessor , PropelTypes::getPdoTypeString($column->getType()) ); return preg_replace('/^(.+)/m', $tab . '$1', $script); }
php
public function getColumnBindingPHP($column, $identifier, $columnValueAccessor, $tab = " ") { $script = ''; $hasValuePreparation = false; if ($column->isTemporalType()) { // nothing special, the internal value was already properly formatted by the setter } elseif ($column->isLobType()) { // we always need to make sure that the stream is rewound, otherwise nothing will // get written to database. $script .= " if (is_resource($columnValueAccessor)) { rewind($columnValueAccessor); }"; } $script .= sprintf( " \$stmt->bindValue(%s, %s, %s);", $identifier, $columnValueAccessor , PropelTypes::getPdoTypeString($column->getType()) ); return preg_replace('/^(.+)/m', $tab . '$1', $script); }
[ "public", "function", "getColumnBindingPHP", "(", "$", "column", ",", "$", "identifier", ",", "$", "columnValueAccessor", ",", "$", "tab", "=", "\"\t\t\t\"", ")", "{", "$", "script", "=", "''", ";", "$", "hasValuePreparation", "=", "false", ";", "if", "(", "$", "column", "->", "isTemporalType", "(", ")", ")", "{", "// nothing special, the internal value was already properly formatted by the setter", "}", "elseif", "(", "$", "column", "->", "isLobType", "(", ")", ")", "{", "// we always need to make sure that the stream is rewound, otherwise nothing will", "// get written to database.", "$", "script", ".=", "\"\nif (is_resource($columnValueAccessor)) {\n rewind($columnValueAccessor);\n}\"", ";", "}", "$", "script", ".=", "sprintf", "(", "\"\n\\$stmt->bindValue(%s, %s, %s);\"", ",", "$", "identifier", ",", "$", "columnValueAccessor", ",", "PropelTypes", "::", "getPdoTypeString", "(", "$", "column", "->", "getType", "(", ")", ")", ")", ";", "return", "preg_replace", "(", "'/^(.+)/m'", ",", "$", "tab", ".", "'$1'", ",", "$", "script", ")", ";", "}" ]
Get the PHP snippet for binding a value to a column. Warning: duplicates logic from DBAdapter::bindValue(). Any code modification here must be ported there.
[ "Get", "the", "PHP", "snippet", "for", "binding", "a", "value", "to", "a", "column", ".", "Warning", ":", "duplicates", "logic", "from", "DBAdapter", "::", "bindValue", "()", ".", "Any", "code", "modification", "here", "must", "be", "ported", "there", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L1228-L1252
propelorm/Propel
generator/lib/platform/DefaultPlatform.php
DefaultPlatform.getIdentifierPhp
public function getIdentifierPhp($columnValueMutator, $connectionVariableName = '$con', $sequenceName = '', $tab = " ") { return sprintf( " %s%s = %s->lastInsertId(%s);", $tab, $columnValueMutator, $connectionVariableName, $sequenceName ? ("'" . $sequenceName . "'") : '' ); }
php
public function getIdentifierPhp($columnValueMutator, $connectionVariableName = '$con', $sequenceName = '', $tab = " ") { return sprintf( " %s%s = %s->lastInsertId(%s);", $tab, $columnValueMutator, $connectionVariableName, $sequenceName ? ("'" . $sequenceName . "'") : '' ); }
[ "public", "function", "getIdentifierPhp", "(", "$", "columnValueMutator", ",", "$", "connectionVariableName", "=", "'$con'", ",", "$", "sequenceName", "=", "''", ",", "$", "tab", "=", "\"\t\t\t\"", ")", "{", "return", "sprintf", "(", "\"\n%s%s = %s->lastInsertId(%s);\"", ",", "$", "tab", ",", "$", "columnValueMutator", ",", "$", "connectionVariableName", ",", "$", "sequenceName", "?", "(", "\"'\"", ".", "$", "sequenceName", ".", "\"'\"", ")", ":", "''", ")", ";", "}" ]
Get the PHP snippet for getting a Pk from the database. Warning: duplicates logic from DBAdapter::getId(). Any code modification here must be ported there. Typical output: <code> $this->id = $con->lastInsertId(); </code>
[ "Get", "the", "PHP", "snippet", "for", "getting", "a", "Pk", "from", "the", "database", ".", "Warning", ":", "duplicates", "logic", "from", "DBAdapter", "::", "getId", "()", ".", "Any", "code", "modification", "here", "must", "be", "ported", "there", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/platform/DefaultPlatform.php#L1264-L1274
propelorm/Propel
generator/lib/builder/sql/DataSQLBuilder.php
DataSQLBuilder.buildRowSql
public function buildRowSql(DataRow $row) { $sql = ""; $platform = $this->getPlatform(); $table = $this->getTable(); $sql .= "INSERT INTO " . $this->quoteIdentifier($this->getTable()->getName()) . " ("; // add column names to SQL $colNames = array(); foreach ($row->getColumnValues() as $colValue) { $colNames[] = $this->quoteIdentifier($colValue->getColumn()->getName()); } $sql .= implode(',', $colNames); $sql .= ") VALUES ("; $colVals = array(); foreach ($row->getColumnValues() as $colValue) { $colVals[] = $this->getColumnValueSql($colValue); } $sql .= implode(',', $colVals); $sql .= "); "; return $sql; }
php
public function buildRowSql(DataRow $row) { $sql = ""; $platform = $this->getPlatform(); $table = $this->getTable(); $sql .= "INSERT INTO " . $this->quoteIdentifier($this->getTable()->getName()) . " ("; // add column names to SQL $colNames = array(); foreach ($row->getColumnValues() as $colValue) { $colNames[] = $this->quoteIdentifier($colValue->getColumn()->getName()); } $sql .= implode(',', $colNames); $sql .= ") VALUES ("; $colVals = array(); foreach ($row->getColumnValues() as $colValue) { $colVals[] = $this->getColumnValueSql($colValue); } $sql .= implode(',', $colVals); $sql .= "); "; return $sql; }
[ "public", "function", "buildRowSql", "(", "DataRow", "$", "row", ")", "{", "$", "sql", "=", "\"\"", ";", "$", "platform", "=", "$", "this", "->", "getPlatform", "(", ")", ";", "$", "table", "=", "$", "this", "->", "getTable", "(", ")", ";", "$", "sql", ".=", "\"INSERT INTO \"", ".", "$", "this", "->", "quoteIdentifier", "(", "$", "this", "->", "getTable", "(", ")", "->", "getName", "(", ")", ")", ".", "\" (\"", ";", "// add column names to SQL", "$", "colNames", "=", "array", "(", ")", ";", "foreach", "(", "$", "row", "->", "getColumnValues", "(", ")", "as", "$", "colValue", ")", "{", "$", "colNames", "[", "]", "=", "$", "this", "->", "quoteIdentifier", "(", "$", "colValue", "->", "getColumn", "(", ")", "->", "getName", "(", ")", ")", ";", "}", "$", "sql", ".=", "implode", "(", "','", ",", "$", "colNames", ")", ";", "$", "sql", ".=", "\") VALUES (\"", ";", "$", "colVals", "=", "array", "(", ")", ";", "foreach", "(", "$", "row", "->", "getColumnValues", "(", ")", "as", "$", "colValue", ")", "{", "$", "colVals", "[", "]", "=", "$", "this", "->", "getColumnValueSql", "(", "$", "colValue", ")", ";", "}", "$", "sql", ".=", "implode", "(", "','", ",", "$", "colVals", ")", ";", "$", "sql", ".=", "\");\n\"", ";", "return", "$", "sql", ";", "}" ]
The main method in this class, returns the SQL for INSERTing data into a row. @param DataRow $row The row to process. @return string
[ "The", "main", "method", "in", "this", "class", "returns", "the", "SQL", "for", "INSERTing", "data", "into", "a", "row", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/sql/DataSQLBuilder.php#L80-L108
propelorm/Propel
generator/lib/builder/sql/DataSQLBuilder.php
DataSQLBuilder.getColumnValueSql
protected function getColumnValueSql(ColumnValue $colValue) { $column = $colValue->getColumn(); $method = 'get' . $column->getPhpNative() . 'Sql'; return $this->$method($colValue->getValue()); }
php
protected function getColumnValueSql(ColumnValue $colValue) { $column = $colValue->getColumn(); $method = 'get' . $column->getPhpNative() . 'Sql'; return $this->$method($colValue->getValue()); }
[ "protected", "function", "getColumnValueSql", "(", "ColumnValue", "$", "colValue", ")", "{", "$", "column", "=", "$", "colValue", "->", "getColumn", "(", ")", ";", "$", "method", "=", "'get'", ".", "$", "column", "->", "getPhpNative", "(", ")", ".", "'Sql'", ";", "return", "$", "this", "->", "$", "method", "(", "$", "colValue", "->", "getValue", "(", ")", ")", ";", "}" ]
Gets the property escaped (and quoted) value for a column. @param ColumnValue $colValue @return mixed The proper value to be added to the string.
[ "Gets", "the", "property", "escaped", "(", "and", "quoted", ")", "value", "for", "a", "column", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/sql/DataSQLBuilder.php#L117-L123
propelorm/Propel
generator/lib/builder/sql/DataSQLBuilder.php
DataSQLBuilder.getBlobSql
protected function getBlobSql($blob) { // they took magic __toString() out of PHP5.0.0; this sucks if (is_object($blob)) { return $this->getPlatform()->quote($blob->__toString()); } else { return $this->getPlatform()->quote($blob); } }
php
protected function getBlobSql($blob) { // they took magic __toString() out of PHP5.0.0; this sucks if (is_object($blob)) { return $this->getPlatform()->quote($blob->__toString()); } else { return $this->getPlatform()->quote($blob); } }
[ "protected", "function", "getBlobSql", "(", "$", "blob", ")", "{", "// they took magic __toString() out of PHP5.0.0; this sucks", "if", "(", "is_object", "(", "$", "blob", ")", ")", "{", "return", "$", "this", "->", "getPlatform", "(", ")", "->", "quote", "(", "$", "blob", "->", "__toString", "(", ")", ")", ";", "}", "else", "{", "return", "$", "this", "->", "getPlatform", "(", ")", "->", "quote", "(", "$", "blob", ")", ";", "}", "}" ]
Gets a representation of a BLOB/LONGVARBINARY value suitable for use in a SQL statement. @param mixed $blob Blob object or string data. @return string
[ "Gets", "a", "representation", "of", "a", "BLOB", "/", "LONGVARBINARY", "value", "suitable", "for", "use", "in", "a", "SQL", "statement", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/sql/DataSQLBuilder.php#L145-L153
propelorm/Propel
generator/lib/builder/sql/DataSQLBuilder.php
DataSQLBuilder.getClobSql
protected function getClobSql($clob) { // they took magic __toString() out of PHP5.0.0; this sucks if (is_object($clob)) { return $this->getPlatform()->quote($clob->__toString()); } else { return $this->getPlatform()->quote($clob); } }
php
protected function getClobSql($clob) { // they took magic __toString() out of PHP5.0.0; this sucks if (is_object($clob)) { return $this->getPlatform()->quote($clob->__toString()); } else { return $this->getPlatform()->quote($clob); } }
[ "protected", "function", "getClobSql", "(", "$", "clob", ")", "{", "// they took magic __toString() out of PHP5.0.0; this sucks", "if", "(", "is_object", "(", "$", "clob", ")", ")", "{", "return", "$", "this", "->", "getPlatform", "(", ")", "->", "quote", "(", "$", "clob", "->", "__toString", "(", ")", ")", ";", "}", "else", "{", "return", "$", "this", "->", "getPlatform", "(", ")", "->", "quote", "(", "$", "clob", ")", ";", "}", "}" ]
Gets a representation of a CLOB/LONGVARCHAR value suitable for use in a SQL statement. @param mixed $clob Clob object or string data. @return string
[ "Gets", "a", "representation", "of", "a", "CLOB", "/", "LONGVARCHAR", "value", "suitable", "for", "use", "in", "a", "SQL", "statement", "." ]
train
https://github.com/propelorm/Propel/blob/3f7a284906ce3e402bcb101938270842fdad71fa/generator/lib/builder/sql/DataSQLBuilder.php#L162-L170
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.beforeAction
public function beforeAction($action) { if (parent::beforeAction($action)) { $this->checkPaths(); $this->addProviders(); return true; } return false; }
php
public function beforeAction($action) { if (parent::beforeAction($action)) { $this->checkPaths(); $this->addProviders(); return true; } return false; }
[ "public", "function", "beforeAction", "(", "$", "action", ")", "{", "if", "(", "parent", "::", "beforeAction", "(", "$", "action", ")", ")", "{", "$", "this", "->", "checkPaths", "(", ")", ";", "$", "this", "->", "addProviders", "(", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}" ]
{@inheritdoc}
[ "{" ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L186-L195
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.actionTemplates
public function actionTemplates() { $foundTemplates = $this->findTemplatesFiles(); if (!$foundTemplates) { $this->notifyNoTemplatesFound(); } else { $this->notifyTemplatesCanBeGenerated($foundTemplates); } }
php
public function actionTemplates() { $foundTemplates = $this->findTemplatesFiles(); if (!$foundTemplates) { $this->notifyNoTemplatesFound(); } else { $this->notifyTemplatesCanBeGenerated($foundTemplates); } }
[ "public", "function", "actionTemplates", "(", ")", "{", "$", "foundTemplates", "=", "$", "this", "->", "findTemplatesFiles", "(", ")", ";", "if", "(", "!", "$", "foundTemplates", ")", "{", "$", "this", "->", "notifyNoTemplatesFound", "(", ")", ";", "}", "else", "{", "$", "this", "->", "notifyTemplatesCanBeGenerated", "(", "$", "foundTemplates", ")", ";", "}", "}" ]
Lists all available fixtures template files.
[ "Lists", "all", "available", "fixtures", "template", "files", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L200-L209
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.actionGenerate
public function actionGenerate() { $templatesInput = func_get_args(); if (empty($templatesInput)) { throw new Exception('You should specify input fixtures template files'); } $foundTemplates = $this->findTemplatesFiles($templatesInput); $notFoundTemplates = array_diff($templatesInput, $foundTemplates); if ($notFoundTemplates) { $this->notifyNotFoundTemplates($notFoundTemplates); } if (!$foundTemplates) { $this->notifyNoTemplatesFound(); return static::EXIT_CODE_NORMAL; } if (!$this->confirmGeneration($foundTemplates)) { return static::EXIT_CODE_NORMAL; } $templatePath = Yii::getAlias($this->templatePath); $fixtureDataPath = Yii::getAlias($this->fixtureDataPath); FileHelper::createDirectory($fixtureDataPath); $generatedTemplates = []; foreach ($foundTemplates as $templateName) { $this->generateFixtureFile($templateName, $templatePath, $fixtureDataPath); $generatedTemplates[] = $templateName; } $this->notifyTemplatesGenerated($generatedTemplates); }
php
public function actionGenerate() { $templatesInput = func_get_args(); if (empty($templatesInput)) { throw new Exception('You should specify input fixtures template files'); } $foundTemplates = $this->findTemplatesFiles($templatesInput); $notFoundTemplates = array_diff($templatesInput, $foundTemplates); if ($notFoundTemplates) { $this->notifyNotFoundTemplates($notFoundTemplates); } if (!$foundTemplates) { $this->notifyNoTemplatesFound(); return static::EXIT_CODE_NORMAL; } if (!$this->confirmGeneration($foundTemplates)) { return static::EXIT_CODE_NORMAL; } $templatePath = Yii::getAlias($this->templatePath); $fixtureDataPath = Yii::getAlias($this->fixtureDataPath); FileHelper::createDirectory($fixtureDataPath); $generatedTemplates = []; foreach ($foundTemplates as $templateName) { $this->generateFixtureFile($templateName, $templatePath, $fixtureDataPath); $generatedTemplates[] = $templateName; } $this->notifyTemplatesGenerated($generatedTemplates); }
[ "public", "function", "actionGenerate", "(", ")", "{", "$", "templatesInput", "=", "func_get_args", "(", ")", ";", "if", "(", "empty", "(", "$", "templatesInput", ")", ")", "{", "throw", "new", "Exception", "(", "'You should specify input fixtures template files'", ")", ";", "}", "$", "foundTemplates", "=", "$", "this", "->", "findTemplatesFiles", "(", "$", "templatesInput", ")", ";", "$", "notFoundTemplates", "=", "array_diff", "(", "$", "templatesInput", ",", "$", "foundTemplates", ")", ";", "if", "(", "$", "notFoundTemplates", ")", "{", "$", "this", "->", "notifyNotFoundTemplates", "(", "$", "notFoundTemplates", ")", ";", "}", "if", "(", "!", "$", "foundTemplates", ")", "{", "$", "this", "->", "notifyNoTemplatesFound", "(", ")", ";", "return", "static", "::", "EXIT_CODE_NORMAL", ";", "}", "if", "(", "!", "$", "this", "->", "confirmGeneration", "(", "$", "foundTemplates", ")", ")", "{", "return", "static", "::", "EXIT_CODE_NORMAL", ";", "}", "$", "templatePath", "=", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ";", "$", "fixtureDataPath", "=", "Yii", "::", "getAlias", "(", "$", "this", "->", "fixtureDataPath", ")", ";", "FileHelper", "::", "createDirectory", "(", "$", "fixtureDataPath", ")", ";", "$", "generatedTemplates", "=", "[", "]", ";", "foreach", "(", "$", "foundTemplates", "as", "$", "templateName", ")", "{", "$", "this", "->", "generateFixtureFile", "(", "$", "templateName", ",", "$", "templatePath", ",", "$", "fixtureDataPath", ")", ";", "$", "generatedTemplates", "[", "]", "=", "$", "templateName", ";", "}", "$", "this", "->", "notifyTemplatesGenerated", "(", "$", "generatedTemplates", ")", ";", "}" ]
Generates fixtures and fill them with Faker data. For example, ``` //generate fixtures in russian language yii fixture/generate user --count=5 --language=ru_RU //generate several fixtures yii fixture/generate user profile team ``` @throws \yii\base\InvalidParamException @throws \yii\console\Exception
[ "Generates", "fixtures", "and", "fill", "them", "with", "Faker", "data", ".", "For", "example" ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L226-L264
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.actionGenerateAll
public function actionGenerateAll() { $foundTemplates = $this->findTemplatesFiles(); if (!$foundTemplates) { $this->notifyNoTemplatesFound(); return static::EXIT_CODE_NORMAL; } if (!$this->confirmGeneration($foundTemplates)) { return static::EXIT_CODE_NORMAL; } $templatePath = Yii::getAlias($this->templatePath); $fixtureDataPath = Yii::getAlias($this->fixtureDataPath); FileHelper::createDirectory($fixtureDataPath); $generatedTemplates = []; foreach ($foundTemplates as $templateName) { $this->generateFixtureFile($templateName, $templatePath, $fixtureDataPath); $generatedTemplates[] = $templateName; } $this->notifyTemplatesGenerated($generatedTemplates); }
php
public function actionGenerateAll() { $foundTemplates = $this->findTemplatesFiles(); if (!$foundTemplates) { $this->notifyNoTemplatesFound(); return static::EXIT_CODE_NORMAL; } if (!$this->confirmGeneration($foundTemplates)) { return static::EXIT_CODE_NORMAL; } $templatePath = Yii::getAlias($this->templatePath); $fixtureDataPath = Yii::getAlias($this->fixtureDataPath); FileHelper::createDirectory($fixtureDataPath); $generatedTemplates = []; foreach ($foundTemplates as $templateName) { $this->generateFixtureFile($templateName, $templatePath, $fixtureDataPath); $generatedTemplates[] = $templateName; } $this->notifyTemplatesGenerated($generatedTemplates); }
[ "public", "function", "actionGenerateAll", "(", ")", "{", "$", "foundTemplates", "=", "$", "this", "->", "findTemplatesFiles", "(", ")", ";", "if", "(", "!", "$", "foundTemplates", ")", "{", "$", "this", "->", "notifyNoTemplatesFound", "(", ")", ";", "return", "static", "::", "EXIT_CODE_NORMAL", ";", "}", "if", "(", "!", "$", "this", "->", "confirmGeneration", "(", "$", "foundTemplates", ")", ")", "{", "return", "static", "::", "EXIT_CODE_NORMAL", ";", "}", "$", "templatePath", "=", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ";", "$", "fixtureDataPath", "=", "Yii", "::", "getAlias", "(", "$", "this", "->", "fixtureDataPath", ")", ";", "FileHelper", "::", "createDirectory", "(", "$", "fixtureDataPath", ")", ";", "$", "generatedTemplates", "=", "[", "]", ";", "foreach", "(", "$", "foundTemplates", "as", "$", "templateName", ")", "{", "$", "this", "->", "generateFixtureFile", "(", "$", "templateName", ",", "$", "templatePath", ",", "$", "fixtureDataPath", ")", ";", "$", "generatedTemplates", "[", "]", "=", "$", "templateName", ";", "}", "$", "this", "->", "notifyTemplatesGenerated", "(", "$", "generatedTemplates", ")", ";", "}" ]
Generates all fixtures template path that can be found.
[ "Generates", "all", "fixtures", "template", "path", "that", "can", "be", "found", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L269-L295
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.notifyNotFoundTemplates
protected function notifyNotFoundTemplates($templatesNames) { $this->stdout("The following fixtures templates were NOT found:\n\n", Console::FG_RED); foreach ($templatesNames as $name) { $this->stdout("\t * $name \n", Console::FG_GREEN); } $this->stdout("\n"); }
php
protected function notifyNotFoundTemplates($templatesNames) { $this->stdout("The following fixtures templates were NOT found:\n\n", Console::FG_RED); foreach ($templatesNames as $name) { $this->stdout("\t * $name \n", Console::FG_GREEN); } $this->stdout("\n"); }
[ "protected", "function", "notifyNotFoundTemplates", "(", "$", "templatesNames", ")", "{", "$", "this", "->", "stdout", "(", "\"The following fixtures templates were NOT found:\\n\\n\"", ",", "Console", "::", "FG_RED", ")", ";", "foreach", "(", "$", "templatesNames", "as", "$", "name", ")", "{", "$", "this", "->", "stdout", "(", "\"\\t * $name \\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "}", "$", "this", "->", "stdout", "(", "\"\\n\"", ")", ";", "}" ]
Notifies user that given fixtures template files were not found. @param array $templatesNames @since 2.0.4
[ "Notifies", "user", "that", "given", "fixtures", "template", "files", "were", "not", "found", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L302-L311
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.notifyNoTemplatesFound
protected function notifyNoTemplatesFound() { $this->stdout("No fixtures template files matching input conditions were found under the path:\n\n", Console::FG_RED); $this->stdout("\t " . Yii::getAlias($this->templatePath) . " \n\n", Console::FG_GREEN); }
php
protected function notifyNoTemplatesFound() { $this->stdout("No fixtures template files matching input conditions were found under the path:\n\n", Console::FG_RED); $this->stdout("\t " . Yii::getAlias($this->templatePath) . " \n\n", Console::FG_GREEN); }
[ "protected", "function", "notifyNoTemplatesFound", "(", ")", "{", "$", "this", "->", "stdout", "(", "\"No fixtures template files matching input conditions were found under the path:\\n\\n\"", ",", "Console", "::", "FG_RED", ")", ";", "$", "this", "->", "stdout", "(", "\"\\t \"", ".", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ".", "\" \\n\\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "}" ]
Notifies user that there was not found any files matching given input conditions. @since 2.0.4
[ "Notifies", "user", "that", "there", "was", "not", "found", "any", "files", "matching", "given", "input", "conditions", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L317-L321
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.notifyTemplatesGenerated
protected function notifyTemplatesGenerated($templatesNames) { $this->stdout("The following fixtures template files were generated:\n\n", Console::FG_YELLOW); foreach ($templatesNames as $name) { $this->stdout("\t* " . $name . "\n", Console::FG_GREEN); } $this->stdout("\n"); }
php
protected function notifyTemplatesGenerated($templatesNames) { $this->stdout("The following fixtures template files were generated:\n\n", Console::FG_YELLOW); foreach ($templatesNames as $name) { $this->stdout("\t* " . $name . "\n", Console::FG_GREEN); } $this->stdout("\n"); }
[ "protected", "function", "notifyTemplatesGenerated", "(", "$", "templatesNames", ")", "{", "$", "this", "->", "stdout", "(", "\"The following fixtures template files were generated:\\n\\n\"", ",", "Console", "::", "FG_YELLOW", ")", ";", "foreach", "(", "$", "templatesNames", "as", "$", "name", ")", "{", "$", "this", "->", "stdout", "(", "\"\\t* \"", ".", "$", "name", ".", "\"\\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "}", "$", "this", "->", "stdout", "(", "\"\\n\"", ")", ";", "}" ]
Notifies user that given fixtures template files were generated. @param array $templatesNames @since 2.0.4
[ "Notifies", "user", "that", "given", "fixtures", "template", "files", "were", "generated", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L328-L337
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.notifyTemplatesCanBeGenerated
protected function notifyTemplatesCanBeGenerated($templatesNames) { $this->stdout("Template files path: ", Console::FG_YELLOW); $this->stdout(Yii::getAlias($this->templatePath) . "\n\n", Console::FG_GREEN); foreach ($templatesNames as $name) { $this->stdout("\t* " . $name . "\n", Console::FG_GREEN); } $this->stdout("\n"); }
php
protected function notifyTemplatesCanBeGenerated($templatesNames) { $this->stdout("Template files path: ", Console::FG_YELLOW); $this->stdout(Yii::getAlias($this->templatePath) . "\n\n", Console::FG_GREEN); foreach ($templatesNames as $name) { $this->stdout("\t* " . $name . "\n", Console::FG_GREEN); } $this->stdout("\n"); }
[ "protected", "function", "notifyTemplatesCanBeGenerated", "(", "$", "templatesNames", ")", "{", "$", "this", "->", "stdout", "(", "\"Template files path: \"", ",", "Console", "::", "FG_YELLOW", ")", ";", "$", "this", "->", "stdout", "(", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ".", "\"\\n\\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "foreach", "(", "$", "templatesNames", "as", "$", "name", ")", "{", "$", "this", "->", "stdout", "(", "\"\\t* \"", ".", "$", "name", ".", "\"\\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "}", "$", "this", "->", "stdout", "(", "\"\\n\"", ")", ";", "}" ]
Notifies user about templates which could be generated. @param array $templatesNames @since 2.0.4
[ "Notifies", "user", "about", "templates", "which", "could", "be", "generated", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L344-L354
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.findTemplatesFiles
protected function findTemplatesFiles(array $templatesNames = []) { $findAll = ($templatesNames == []); if ($findAll) { $files = FileHelper::findFiles(Yii::getAlias($this->templatePath), ['only' => ['*.php']]); } else { $filesToSearch = []; foreach ($templatesNames as $fileName) { $filesToSearch[] = $fileName . '.php'; } $files = FileHelper::findFiles(Yii::getAlias($this->templatePath), ['only' => $filesToSearch]); } $foundTemplates = []; foreach ($files as $fileName) { // strip templatePath from current template's full path $relativeName = str_replace(Yii::getAlias($this->templatePath) . DIRECTORY_SEPARATOR, "", $fileName); $relativeDir = dirname($relativeName) == '.' ? '' : dirname($relativeName) . '/'; // strip extension $relativeName = $relativeDir . basename($relativeName,'.php'); $foundTemplates[] = $relativeName; } return $foundTemplates; }
php
protected function findTemplatesFiles(array $templatesNames = []) { $findAll = ($templatesNames == []); if ($findAll) { $files = FileHelper::findFiles(Yii::getAlias($this->templatePath), ['only' => ['*.php']]); } else { $filesToSearch = []; foreach ($templatesNames as $fileName) { $filesToSearch[] = $fileName . '.php'; } $files = FileHelper::findFiles(Yii::getAlias($this->templatePath), ['only' => $filesToSearch]); } $foundTemplates = []; foreach ($files as $fileName) { // strip templatePath from current template's full path $relativeName = str_replace(Yii::getAlias($this->templatePath) . DIRECTORY_SEPARATOR, "", $fileName); $relativeDir = dirname($relativeName) == '.' ? '' : dirname($relativeName) . '/'; // strip extension $relativeName = $relativeDir . basename($relativeName,'.php'); $foundTemplates[] = $relativeName; } return $foundTemplates; }
[ "protected", "function", "findTemplatesFiles", "(", "array", "$", "templatesNames", "=", "[", "]", ")", "{", "$", "findAll", "=", "(", "$", "templatesNames", "==", "[", "]", ")", ";", "if", "(", "$", "findAll", ")", "{", "$", "files", "=", "FileHelper", "::", "findFiles", "(", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ",", "[", "'only'", "=>", "[", "'*.php'", "]", "]", ")", ";", "}", "else", "{", "$", "filesToSearch", "=", "[", "]", ";", "foreach", "(", "$", "templatesNames", "as", "$", "fileName", ")", "{", "$", "filesToSearch", "[", "]", "=", "$", "fileName", ".", "'.php'", ";", "}", "$", "files", "=", "FileHelper", "::", "findFiles", "(", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ",", "[", "'only'", "=>", "$", "filesToSearch", "]", ")", ";", "}", "$", "foundTemplates", "=", "[", "]", ";", "foreach", "(", "$", "files", "as", "$", "fileName", ")", "{", "// strip templatePath from current template's full path", "$", "relativeName", "=", "str_replace", "(", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ".", "DIRECTORY_SEPARATOR", ",", "\"\"", ",", "$", "fileName", ")", ";", "$", "relativeDir", "=", "dirname", "(", "$", "relativeName", ")", "==", "'.'", "?", "''", ":", "dirname", "(", "$", "relativeName", ")", ".", "'/'", ";", "// strip extension", "$", "relativeName", "=", "$", "relativeDir", ".", "basename", "(", "$", "relativeName", ",", "'.php'", ")", ";", "$", "foundTemplates", "[", "]", "=", "$", "relativeName", ";", "}", "return", "$", "foundTemplates", ";", "}" ]
Returns array containing fixtures templates file names. You can specify what files to find by the given parameter. @param array $templatesNames template file names to search. If empty then all files will be searched. @return array @since 2.0.4
[ "Returns", "array", "containing", "fixtures", "templates", "file", "names", ".", "You", "can", "specify", "what", "files", "to", "find", "by", "the", "given", "parameter", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L363-L391
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.getGenerator
public function getGenerator() { if ($this->_generator === null) { $language = $this->language === null ? Yii::$app->language : $this->language; $this->_generator = \Faker\Factory::create(str_replace('-', '_', $language)); } return $this->_generator; }
php
public function getGenerator() { if ($this->_generator === null) { $language = $this->language === null ? Yii::$app->language : $this->language; $this->_generator = \Faker\Factory::create(str_replace('-', '_', $language)); } return $this->_generator; }
[ "public", "function", "getGenerator", "(", ")", "{", "if", "(", "$", "this", "->", "_generator", "===", "null", ")", "{", "$", "language", "=", "$", "this", "->", "language", "===", "null", "?", "Yii", "::", "$", "app", "->", "language", ":", "$", "this", "->", "language", ";", "$", "this", "->", "_generator", "=", "\\", "Faker", "\\", "Factory", "::", "create", "(", "str_replace", "(", "'-'", ",", "'_'", ",", "$", "language", ")", ")", ";", "}", "return", "$", "this", "->", "_generator", ";", "}" ]
Returns Faker generator instance. Getter for private property. @return \Faker\Generator
[ "Returns", "Faker", "generator", "instance", ".", "Getter", "for", "private", "property", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L397-L404
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.checkPaths
public function checkPaths() { $path = Yii::getAlias($this->templatePath, false); if (!$path || !is_dir($path)) { throw new Exception("The template path \"{$this->templatePath}\" does not exist"); } }
php
public function checkPaths() { $path = Yii::getAlias($this->templatePath, false); if (!$path || !is_dir($path)) { throw new Exception("The template path \"{$this->templatePath}\" does not exist"); } }
[ "public", "function", "checkPaths", "(", ")", "{", "$", "path", "=", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ",", "false", ")", ";", "if", "(", "!", "$", "path", "||", "!", "is_dir", "(", "$", "path", ")", ")", "{", "throw", "new", "Exception", "(", "\"The template path \\\"{$this->templatePath}\\\" does not exist\"", ")", ";", "}", "}" ]
Check if the template path and migrations path exists and writable.
[ "Check", "if", "the", "template", "path", "and", "migrations", "path", "exists", "and", "writable", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L409-L416
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.addProviders
public function addProviders() { foreach ($this->providers as $provider) { $this->generator->addProvider(new $provider($this->generator)); } }
php
public function addProviders() { foreach ($this->providers as $provider) { $this->generator->addProvider(new $provider($this->generator)); } }
[ "public", "function", "addProviders", "(", ")", "{", "foreach", "(", "$", "this", "->", "providers", "as", "$", "provider", ")", "{", "$", "this", "->", "generator", "->", "addProvider", "(", "new", "$", "provider", "(", "$", "this", "->", "generator", ")", ")", ";", "}", "}" ]
Adds users providers to the faker generator.
[ "Adds", "users", "providers", "to", "the", "faker", "generator", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L421-L426
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.generateFixtureFile
public function generateFixtureFile($templateName, $templatePath, $fixtureDataPath) { $fixtures = []; for ($i = 0; $i < $this->count; $i++) { $fixtures[$templateName . $i] = $this->generateFixture($templatePath . '/' . $templateName . '.php', $i); } $content = $this->exportFixtures($fixtures); // data file full path $dataFile = $fixtureDataPath . '/'. $templateName . '.php'; // data file directory, create if it doesn't exist $dataFileDir = dirname($dataFile); if (!file_exists($dataFileDir)) { FileHelper::createDirectory($dataFileDir); } file_put_contents($dataFile, $content); }
php
public function generateFixtureFile($templateName, $templatePath, $fixtureDataPath) { $fixtures = []; for ($i = 0; $i < $this->count; $i++) { $fixtures[$templateName . $i] = $this->generateFixture($templatePath . '/' . $templateName . '.php', $i); } $content = $this->exportFixtures($fixtures); // data file full path $dataFile = $fixtureDataPath . '/'. $templateName . '.php'; // data file directory, create if it doesn't exist $dataFileDir = dirname($dataFile); if (!file_exists($dataFileDir)) { FileHelper::createDirectory($dataFileDir); } file_put_contents($dataFile, $content); }
[ "public", "function", "generateFixtureFile", "(", "$", "templateName", ",", "$", "templatePath", ",", "$", "fixtureDataPath", ")", "{", "$", "fixtures", "=", "[", "]", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "this", "->", "count", ";", "$", "i", "++", ")", "{", "$", "fixtures", "[", "$", "templateName", ".", "$", "i", "]", "=", "$", "this", "->", "generateFixture", "(", "$", "templatePath", ".", "'/'", ".", "$", "templateName", ".", "'.php'", ",", "$", "i", ")", ";", "}", "$", "content", "=", "$", "this", "->", "exportFixtures", "(", "$", "fixtures", ")", ";", "// data file full path", "$", "dataFile", "=", "$", "fixtureDataPath", ".", "'/'", ".", "$", "templateName", ".", "'.php'", ";", "// data file directory, create if it doesn't exist", "$", "dataFileDir", "=", "dirname", "(", "$", "dataFile", ")", ";", "if", "(", "!", "file_exists", "(", "$", "dataFileDir", ")", ")", "{", "FileHelper", "::", "createDirectory", "(", "$", "dataFileDir", ")", ";", "}", "file_put_contents", "(", "$", "dataFile", ",", "$", "content", ")", ";", "}" ]
Generates fixture file by the given fixture template file. @param string $templateName template file name @param string $templatePath path where templates are stored @param string $fixtureDataPath fixture data path where generated file should be written
[ "Generates", "fixture", "file", "by", "the", "given", "fixture", "template", "file", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L457-L476
yiisoft/yii2-faker
src/FixtureController.php
FixtureController.confirmGeneration
public function confirmGeneration($files) { $this->stdout("Fixtures will be generated under the path: \n", Console::FG_YELLOW); $this->stdout("\t" . Yii::getAlias($this->fixtureDataPath) . "\n\n", Console::FG_GREEN); $this->stdout("Templates will be taken from path: \n", Console::FG_YELLOW); $this->stdout("\t" . Yii::getAlias($this->templatePath) . "\n\n", Console::FG_GREEN); foreach ($files as $fileName) { $this->stdout("\t* " . $fileName . "\n", Console::FG_GREEN); } return $this->confirm('Generate above fixtures?'); }
php
public function confirmGeneration($files) { $this->stdout("Fixtures will be generated under the path: \n", Console::FG_YELLOW); $this->stdout("\t" . Yii::getAlias($this->fixtureDataPath) . "\n\n", Console::FG_GREEN); $this->stdout("Templates will be taken from path: \n", Console::FG_YELLOW); $this->stdout("\t" . Yii::getAlias($this->templatePath) . "\n\n", Console::FG_GREEN); foreach ($files as $fileName) { $this->stdout("\t* " . $fileName . "\n", Console::FG_GREEN); } return $this->confirm('Generate above fixtures?'); }
[ "public", "function", "confirmGeneration", "(", "$", "files", ")", "{", "$", "this", "->", "stdout", "(", "\"Fixtures will be generated under the path: \\n\"", ",", "Console", "::", "FG_YELLOW", ")", ";", "$", "this", "->", "stdout", "(", "\"\\t\"", ".", "Yii", "::", "getAlias", "(", "$", "this", "->", "fixtureDataPath", ")", ".", "\"\\n\\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "$", "this", "->", "stdout", "(", "\"Templates will be taken from path: \\n\"", ",", "Console", "::", "FG_YELLOW", ")", ";", "$", "this", "->", "stdout", "(", "\"\\t\"", ".", "Yii", "::", "getAlias", "(", "$", "this", "->", "templatePath", ")", ".", "\"\\n\\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "foreach", "(", "$", "files", "as", "$", "fileName", ")", "{", "$", "this", "->", "stdout", "(", "\"\\t* \"", ".", "$", "fileName", ".", "\"\\n\"", ",", "Console", "::", "FG_GREEN", ")", ";", "}", "return", "$", "this", "->", "confirm", "(", "'Generate above fixtures?'", ")", ";", "}" ]
Prompts user with message if he confirm generation with given fixture templates files. @param array $files @return bool
[ "Prompts", "user", "with", "message", "if", "he", "confirm", "generation", "with", "given", "fixture", "templates", "files", "." ]
train
https://github.com/yiisoft/yii2-faker/blob/2f548188b2961f097c08623214f5190e3cf2f1ac/src/FixtureController.php#L483-L495
guzzle/guzzle-services
src/RequestLocation/JsonLocation.php
JsonLocation.visit
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $this->jsonData[$param->getWireName()] = $this->prepareValue( $command[$param->getName()], $param ); return $request->withBody(Psr7\stream_for(\GuzzleHttp\json_encode($this->jsonData))); }
php
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $this->jsonData[$param->getWireName()] = $this->prepareValue( $command[$param->getName()], $param ); return $request->withBody(Psr7\stream_for(\GuzzleHttp\json_encode($this->jsonData))); }
[ "public", "function", "visit", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Parameter", "$", "param", ")", "{", "$", "this", "->", "jsonData", "[", "$", "param", "->", "getWireName", "(", ")", "]", "=", "$", "this", "->", "prepareValue", "(", "$", "command", "[", "$", "param", "->", "getName", "(", ")", "]", ",", "$", "param", ")", ";", "return", "$", "request", "->", "withBody", "(", "Psr7", "\\", "stream_for", "(", "\\", "GuzzleHttp", "\\", "json_encode", "(", "$", "this", "->", "jsonData", ")", ")", ")", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Parameter $param @return RequestInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Parameter", "$param" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/JsonLocation.php#L40-L51
guzzle/guzzle-services
src/RequestLocation/JsonLocation.php
JsonLocation.after
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { $data = $this->jsonData; $this->jsonData = []; // Add additional parameters to the JSON document $additional = $operation->getAdditionalParameters(); if ($additional && ($additional->getLocation() === $this->locationName)) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $data[$key] = $this->prepareValue($value, $additional); } } } // Don't overwrite the Content-Type if one is set if ($this->jsonContentType && !$request->hasHeader('Content-Type')) { $request = $request->withHeader('Content-Type', $this->jsonContentType); } return $request->withBody(Psr7\stream_for(\GuzzleHttp\json_encode($data))); }
php
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { $data = $this->jsonData; $this->jsonData = []; // Add additional parameters to the JSON document $additional = $operation->getAdditionalParameters(); if ($additional && ($additional->getLocation() === $this->locationName)) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $data[$key] = $this->prepareValue($value, $additional); } } } // Don't overwrite the Content-Type if one is set if ($this->jsonContentType && !$request->hasHeader('Content-Type')) { $request = $request->withHeader('Content-Type', $this->jsonContentType); } return $request->withBody(Psr7\stream_for(\GuzzleHttp\json_encode($data))); }
[ "public", "function", "after", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Operation", "$", "operation", ")", "{", "$", "data", "=", "$", "this", "->", "jsonData", ";", "$", "this", "->", "jsonData", "=", "[", "]", ";", "// Add additional parameters to the JSON document", "$", "additional", "=", "$", "operation", "->", "getAdditionalParameters", "(", ")", ";", "if", "(", "$", "additional", "&&", "(", "$", "additional", "->", "getLocation", "(", ")", "===", "$", "this", "->", "locationName", ")", ")", "{", "foreach", "(", "$", "command", "->", "toArray", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "$", "operation", "->", "hasParam", "(", "$", "key", ")", ")", "{", "$", "data", "[", "$", "key", "]", "=", "$", "this", "->", "prepareValue", "(", "$", "value", ",", "$", "additional", ")", ";", "}", "}", "}", "// Don't overwrite the Content-Type if one is set", "if", "(", "$", "this", "->", "jsonContentType", "&&", "!", "$", "request", "->", "hasHeader", "(", "'Content-Type'", ")", ")", "{", "$", "request", "=", "$", "request", "->", "withHeader", "(", "'Content-Type'", ",", "$", "this", "->", "jsonContentType", ")", ";", "}", "return", "$", "request", "->", "withBody", "(", "Psr7", "\\", "stream_for", "(", "\\", "GuzzleHttp", "\\", "json_encode", "(", "$", "data", ")", ")", ")", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Operation $operation @return MessageInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Operation", "$operation" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/JsonLocation.php#L60-L84
guzzle/guzzle-services
src/GuzzleClient.php
GuzzleClient.getCommand
public function getCommand($name, array $args = []) { if (!$this->description->hasOperation($name)) { $name = ucfirst($name); if (!$this->description->hasOperation($name)) { throw new \InvalidArgumentException( "No operation found named {$name}" ); } } // Merge in default command options $args += $this->getConfig('defaults'); return parent::getCommand($name, $args); }
php
public function getCommand($name, array $args = []) { if (!$this->description->hasOperation($name)) { $name = ucfirst($name); if (!$this->description->hasOperation($name)) { throw new \InvalidArgumentException( "No operation found named {$name}" ); } } // Merge in default command options $args += $this->getConfig('defaults'); return parent::getCommand($name, $args); }
[ "public", "function", "getCommand", "(", "$", "name", ",", "array", "$", "args", "=", "[", "]", ")", "{", "if", "(", "!", "$", "this", "->", "description", "->", "hasOperation", "(", "$", "name", ")", ")", "{", "$", "name", "=", "ucfirst", "(", "$", "name", ")", ";", "if", "(", "!", "$", "this", "->", "description", "->", "hasOperation", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"No operation found named {$name}\"", ")", ";", "}", "}", "// Merge in default command options", "$", "args", "+=", "$", "this", "->", "getConfig", "(", "'defaults'", ")", ";", "return", "parent", "::", "getCommand", "(", "$", "name", ",", "$", "args", ")", ";", "}" ]
Returns the command if valid; otherwise an Exception @param string $name @param array $args @return CommandInterface @throws \InvalidArgumentException
[ "Returns", "the", "command", "if", "valid", ";", "otherwise", "an", "Exception" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/GuzzleClient.php#L67-L82
guzzle/guzzle-services
src/GuzzleClient.php
GuzzleClient.getDeserializer
private function getDeserializer($responseToResultTransformer) { $process = (! isset($this->config['process']) || $this->config['process'] === true); return $responseToResultTransformer ==! null ? $responseToResultTransformer : new Deserializer($this->description, $process); }
php
private function getDeserializer($responseToResultTransformer) { $process = (! isset($this->config['process']) || $this->config['process'] === true); return $responseToResultTransformer ==! null ? $responseToResultTransformer : new Deserializer($this->description, $process); }
[ "private", "function", "getDeserializer", "(", "$", "responseToResultTransformer", ")", "{", "$", "process", "=", "(", "!", "isset", "(", "$", "this", "->", "config", "[", "'process'", "]", ")", "||", "$", "this", "->", "config", "[", "'process'", "]", "===", "true", ")", ";", "return", "$", "responseToResultTransformer", "==", "!", "null", "?", "$", "responseToResultTransformer", ":", "new", "Deserializer", "(", "$", "this", "->", "description", ",", "$", "process", ")", ";", "}" ]
Returns the passed Deserializer when set, a new instance otherwise @param callable|null $responseToResultTransformer @return \GuzzleHttp\Command\Guzzle\Deserializer
[ "Returns", "the", "passed", "Deserializer", "when", "set", "a", "new", "instance", "otherwise" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/GuzzleClient.php#L113-L120
guzzle/guzzle-services
src/GuzzleClient.php
GuzzleClient.processConfig
protected function processConfig(array $config) { // set defaults as an array if not provided if (!isset($config['defaults'])) { $config['defaults'] = []; } // Add the handlers based on the configuration option $stack = $this->getHandlerStack(); if (!isset($config['validate']) || $config['validate'] === true) { $stack->push(new ValidatedDescriptionHandler($this->description), 'validate_description'); } if (!isset($config['process']) || $config['process'] === true) { // TODO: This belongs to the Deserializer and should be handled there. // Question: What is the result when the Deserializer is bypassed? // Possible answer: The raw response. } }
php
protected function processConfig(array $config) { // set defaults as an array if not provided if (!isset($config['defaults'])) { $config['defaults'] = []; } // Add the handlers based on the configuration option $stack = $this->getHandlerStack(); if (!isset($config['validate']) || $config['validate'] === true) { $stack->push(new ValidatedDescriptionHandler($this->description), 'validate_description'); } if (!isset($config['process']) || $config['process'] === true) { // TODO: This belongs to the Deserializer and should be handled there. // Question: What is the result when the Deserializer is bypassed? // Possible answer: The raw response. } }
[ "protected", "function", "processConfig", "(", "array", "$", "config", ")", "{", "// set defaults as an array if not provided", "if", "(", "!", "isset", "(", "$", "config", "[", "'defaults'", "]", ")", ")", "{", "$", "config", "[", "'defaults'", "]", "=", "[", "]", ";", "}", "// Add the handlers based on the configuration option", "$", "stack", "=", "$", "this", "->", "getHandlerStack", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "config", "[", "'validate'", "]", ")", "||", "$", "config", "[", "'validate'", "]", "===", "true", ")", "{", "$", "stack", "->", "push", "(", "new", "ValidatedDescriptionHandler", "(", "$", "this", "->", "description", ")", ",", "'validate_description'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "config", "[", "'process'", "]", ")", "||", "$", "config", "[", "'process'", "]", "===", "true", ")", "{", "// TODO: This belongs to the Deserializer and should be handled there.", "// Question: What is the result when the Deserializer is bypassed?", "// Possible answer: The raw response.", "}", "}" ]
Prepares the client based on the configuration settings of the client. @param array $config Constructor config as an array
[ "Prepares", "the", "client", "based", "on", "the", "configuration", "settings", "of", "the", "client", "." ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/GuzzleClient.php#L149-L168
guzzle/guzzle-services
src/RequestLocation/XmlLocation.php
XmlLocation.after
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { foreach ($this->buffered as $param) { $this->visitWithValue( $command[$param->getName()], $param, $operation ); } $this->buffered = []; $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $additional->setName($key); $this->visitWithValue($value, $additional, $operation); } } $additional->setName(null); } // If data was found that needs to be serialized, then do so $xml = ''; if ($this->writer) { $xml = $this->finishDocument($this->writer); } elseif ($operation->getData('xmlAllowEmpty')) { // Check if XML should always be sent for the command $writer = $this->createRootElement($operation); $xml = $this->finishDocument($writer); } if ($xml !== '') { $request = $request->withBody(Psr7\stream_for($xml)); // Don't overwrite the Content-Type if one is set if ($this->contentType && !$request->hasHeader('Content-Type')) { $request = $request->withHeader('Content-Type', $this->contentType); } } $this->writer = null; return $request; }
php
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { foreach ($this->buffered as $param) { $this->visitWithValue( $command[$param->getName()], $param, $operation ); } $this->buffered = []; $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $additional->setName($key); $this->visitWithValue($value, $additional, $operation); } } $additional->setName(null); } // If data was found that needs to be serialized, then do so $xml = ''; if ($this->writer) { $xml = $this->finishDocument($this->writer); } elseif ($operation->getData('xmlAllowEmpty')) { // Check if XML should always be sent for the command $writer = $this->createRootElement($operation); $xml = $this->finishDocument($writer); } if ($xml !== '') { $request = $request->withBody(Psr7\stream_for($xml)); // Don't overwrite the Content-Type if one is set if ($this->contentType && !$request->hasHeader('Content-Type')) { $request = $request->withHeader('Content-Type', $this->contentType); } } $this->writer = null; return $request; }
[ "public", "function", "after", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Operation", "$", "operation", ")", "{", "foreach", "(", "$", "this", "->", "buffered", "as", "$", "param", ")", "{", "$", "this", "->", "visitWithValue", "(", "$", "command", "[", "$", "param", "->", "getName", "(", ")", "]", ",", "$", "param", ",", "$", "operation", ")", ";", "}", "$", "this", "->", "buffered", "=", "[", "]", ";", "$", "additional", "=", "$", "operation", "->", "getAdditionalParameters", "(", ")", ";", "if", "(", "$", "additional", "&&", "$", "additional", "->", "getLocation", "(", ")", "==", "$", "this", "->", "locationName", ")", "{", "foreach", "(", "$", "command", "->", "toArray", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "$", "operation", "->", "hasParam", "(", "$", "key", ")", ")", "{", "$", "additional", "->", "setName", "(", "$", "key", ")", ";", "$", "this", "->", "visitWithValue", "(", "$", "value", ",", "$", "additional", ",", "$", "operation", ")", ";", "}", "}", "$", "additional", "->", "setName", "(", "null", ")", ";", "}", "// If data was found that needs to be serialized, then do so", "$", "xml", "=", "''", ";", "if", "(", "$", "this", "->", "writer", ")", "{", "$", "xml", "=", "$", "this", "->", "finishDocument", "(", "$", "this", "->", "writer", ")", ";", "}", "elseif", "(", "$", "operation", "->", "getData", "(", "'xmlAllowEmpty'", ")", ")", "{", "// Check if XML should always be sent for the command", "$", "writer", "=", "$", "this", "->", "createRootElement", "(", "$", "operation", ")", ";", "$", "xml", "=", "$", "this", "->", "finishDocument", "(", "$", "writer", ")", ";", "}", "if", "(", "$", "xml", "!==", "''", ")", "{", "$", "request", "=", "$", "request", "->", "withBody", "(", "Psr7", "\\", "stream_for", "(", "$", "xml", ")", ")", ";", "// Don't overwrite the Content-Type if one is set", "if", "(", "$", "this", "->", "contentType", "&&", "!", "$", "request", "->", "hasHeader", "(", "'Content-Type'", ")", ")", "{", "$", "request", "=", "$", "request", "->", "withHeader", "(", "'Content-Type'", ",", "$", "this", "->", "contentType", ")", ";", "}", "}", "$", "this", "->", "writer", "=", "null", ";", "return", "$", "request", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Operation $operation @return RequestInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Operation", "$operation" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/XmlLocation.php#L67-L114
guzzle/guzzle-services
src/RequestLocation/XmlLocation.php
XmlLocation.addXml
protected function addXml(\XMLWriter $writer, Parameter $param, $value) { $value = $param->filter($value); $type = $param->getType(); $name = $param->getWireName(); $prefix = null; $namespace = $param->getData('xmlNamespace'); if (false !== strpos($name, ':')) { list($prefix, $name) = explode(':', $name, 2); } if ($type == 'object' || $type == 'array') { if (!$param->getData('xmlFlattened')) { if ($namespace) { $writer->startElementNS(null, $name, $namespace); } else { $writer->startElement($name); } } if ($param->getType() == 'array') { $this->addXmlArray($writer, $param, $value); } elseif ($param->getType() == 'object') { $this->addXmlObject($writer, $param, $value); } if (!$param->getData('xmlFlattened')) { $writer->endElement(); } return; } if ($param->getData('xmlAttribute')) { $this->writeAttribute($writer, $prefix, $name, $namespace, $value); } else { $this->writeElement($writer, $prefix, $name, $namespace, $value); } }
php
protected function addXml(\XMLWriter $writer, Parameter $param, $value) { $value = $param->filter($value); $type = $param->getType(); $name = $param->getWireName(); $prefix = null; $namespace = $param->getData('xmlNamespace'); if (false !== strpos($name, ':')) { list($prefix, $name) = explode(':', $name, 2); } if ($type == 'object' || $type == 'array') { if (!$param->getData('xmlFlattened')) { if ($namespace) { $writer->startElementNS(null, $name, $namespace); } else { $writer->startElement($name); } } if ($param->getType() == 'array') { $this->addXmlArray($writer, $param, $value); } elseif ($param->getType() == 'object') { $this->addXmlObject($writer, $param, $value); } if (!$param->getData('xmlFlattened')) { $writer->endElement(); } return; } if ($param->getData('xmlAttribute')) { $this->writeAttribute($writer, $prefix, $name, $namespace, $value); } else { $this->writeElement($writer, $prefix, $name, $namespace, $value); } }
[ "protected", "function", "addXml", "(", "\\", "XMLWriter", "$", "writer", ",", "Parameter", "$", "param", ",", "$", "value", ")", "{", "$", "value", "=", "$", "param", "->", "filter", "(", "$", "value", ")", ";", "$", "type", "=", "$", "param", "->", "getType", "(", ")", ";", "$", "name", "=", "$", "param", "->", "getWireName", "(", ")", ";", "$", "prefix", "=", "null", ";", "$", "namespace", "=", "$", "param", "->", "getData", "(", "'xmlNamespace'", ")", ";", "if", "(", "false", "!==", "strpos", "(", "$", "name", ",", "':'", ")", ")", "{", "list", "(", "$", "prefix", ",", "$", "name", ")", "=", "explode", "(", "':'", ",", "$", "name", ",", "2", ")", ";", "}", "if", "(", "$", "type", "==", "'object'", "||", "$", "type", "==", "'array'", ")", "{", "if", "(", "!", "$", "param", "->", "getData", "(", "'xmlFlattened'", ")", ")", "{", "if", "(", "$", "namespace", ")", "{", "$", "writer", "->", "startElementNS", "(", "null", ",", "$", "name", ",", "$", "namespace", ")", ";", "}", "else", "{", "$", "writer", "->", "startElement", "(", "$", "name", ")", ";", "}", "}", "if", "(", "$", "param", "->", "getType", "(", ")", "==", "'array'", ")", "{", "$", "this", "->", "addXmlArray", "(", "$", "writer", ",", "$", "param", ",", "$", "value", ")", ";", "}", "elseif", "(", "$", "param", "->", "getType", "(", ")", "==", "'object'", ")", "{", "$", "this", "->", "addXmlObject", "(", "$", "writer", ",", "$", "param", ",", "$", "value", ")", ";", "}", "if", "(", "!", "$", "param", "->", "getData", "(", "'xmlFlattened'", ")", ")", "{", "$", "writer", "->", "endElement", "(", ")", ";", "}", "return", ";", "}", "if", "(", "$", "param", "->", "getData", "(", "'xmlAttribute'", ")", ")", "{", "$", "this", "->", "writeAttribute", "(", "$", "writer", ",", "$", "prefix", ",", "$", "name", ",", "$", "namespace", ",", "$", "value", ")", ";", "}", "else", "{", "$", "this", "->", "writeElement", "(", "$", "writer", ",", "$", "prefix", ",", "$", "name", ",", "$", "namespace", ",", "$", "value", ")", ";", "}", "}" ]
Recursively build the XML body @param \XMLWriter $writer XML to modify @param Parameter $param API Parameter @param mixed $value Value to add
[ "Recursively", "build", "the", "XML", "body" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/XmlLocation.php#L155-L189
guzzle/guzzle-services
src/RequestLocation/XmlLocation.php
XmlLocation.writeAttribute
protected function writeAttribute($writer, $prefix, $name, $namespace, $value) { if ($namespace) { $writer->writeAttributeNS($prefix, $name, $namespace, $value); } else { $writer->writeAttribute($name, $value); } }
php
protected function writeAttribute($writer, $prefix, $name, $namespace, $value) { if ($namespace) { $writer->writeAttributeNS($prefix, $name, $namespace, $value); } else { $writer->writeAttribute($name, $value); } }
[ "protected", "function", "writeAttribute", "(", "$", "writer", ",", "$", "prefix", ",", "$", "name", ",", "$", "namespace", ",", "$", "value", ")", "{", "if", "(", "$", "namespace", ")", "{", "$", "writer", "->", "writeAttributeNS", "(", "$", "prefix", ",", "$", "name", ",", "$", "namespace", ",", "$", "value", ")", ";", "}", "else", "{", "$", "writer", "->", "writeAttribute", "(", "$", "name", ",", "$", "value", ")", ";", "}", "}" ]
Write an attribute with namespace if used @param \XMLWriter $writer XMLWriter instance @param string $prefix Namespace prefix if any @param string $name Attribute name @param string $namespace The uri of the namespace @param string $value The attribute content
[ "Write", "an", "attribute", "with", "namespace", "if", "used" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/XmlLocation.php#L200-L207
guzzle/guzzle-services
src/RequestLocation/XmlLocation.php
XmlLocation.writeElement
protected function writeElement(\XMLWriter $writer, $prefix, $name, $namespace, $value) { if ($namespace) { $writer->startElementNS($prefix, $name, $namespace); } else { $writer->startElement($name); } if (strpbrk($value, '<>&')) { $writer->writeCData($value); } else { $writer->writeRaw($value); } $writer->endElement(); }
php
protected function writeElement(\XMLWriter $writer, $prefix, $name, $namespace, $value) { if ($namespace) { $writer->startElementNS($prefix, $name, $namespace); } else { $writer->startElement($name); } if (strpbrk($value, '<>&')) { $writer->writeCData($value); } else { $writer->writeRaw($value); } $writer->endElement(); }
[ "protected", "function", "writeElement", "(", "\\", "XMLWriter", "$", "writer", ",", "$", "prefix", ",", "$", "name", ",", "$", "namespace", ",", "$", "value", ")", "{", "if", "(", "$", "namespace", ")", "{", "$", "writer", "->", "startElementNS", "(", "$", "prefix", ",", "$", "name", ",", "$", "namespace", ")", ";", "}", "else", "{", "$", "writer", "->", "startElement", "(", "$", "name", ")", ";", "}", "if", "(", "strpbrk", "(", "$", "value", ",", "'<>&'", ")", ")", "{", "$", "writer", "->", "writeCData", "(", "$", "value", ")", ";", "}", "else", "{", "$", "writer", "->", "writeRaw", "(", "$", "value", ")", ";", "}", "$", "writer", "->", "endElement", "(", ")", ";", "}" ]
Write an element with namespace if used @param \XMLWriter $writer XML writer resource @param string $prefix Namespace prefix if any @param string $name Element name @param string $namespace The uri of the namespace @param string $value The element content
[ "Write", "an", "element", "with", "namespace", "if", "used" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/XmlLocation.php#L218-L231
guzzle/guzzle-services
src/RequestLocation/XmlLocation.php
XmlLocation.startDocument
protected function startDocument($encoding) { $this->writer = new \XMLWriter(); if (!$this->writer->openMemory()) { throw new \RuntimeException('Unable to open XML document in memory'); } if (!$this->writer->startDocument('1.0', $encoding)) { throw new \RuntimeException('Unable to start XML document'); } return $this->writer; }
php
protected function startDocument($encoding) { $this->writer = new \XMLWriter(); if (!$this->writer->openMemory()) { throw new \RuntimeException('Unable to open XML document in memory'); } if (!$this->writer->startDocument('1.0', $encoding)) { throw new \RuntimeException('Unable to start XML document'); } return $this->writer; }
[ "protected", "function", "startDocument", "(", "$", "encoding", ")", "{", "$", "this", "->", "writer", "=", "new", "\\", "XMLWriter", "(", ")", ";", "if", "(", "!", "$", "this", "->", "writer", "->", "openMemory", "(", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to open XML document in memory'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "writer", "->", "startDocument", "(", "'1.0'", ",", "$", "encoding", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'Unable to start XML document'", ")", ";", "}", "return", "$", "this", "->", "writer", ";", "}" ]
Create a new xml writer and start a document @param string $encoding document encoding @return \XMLWriter the writer resource @throws \RuntimeException if the document cannot be started
[ "Create", "a", "new", "xml", "writer", "and", "start", "a", "document" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/XmlLocation.php#L241-L252
guzzle/guzzle-services
src/ResponseLocation/JsonLocation.php
JsonLocation.before
public function before( ResultInterface $result, ResponseInterface $response, Parameter $model ) { $body = (string) $response->getBody(); $body = $body ?: "{}"; $this->json = \GuzzleHttp\json_decode($body, true); // relocate named arrays, so that they have the same structure as // arrays nested in objects and visit can work on them in the same way if ($model->getType() === 'array' && ($name = $model->getName())) { $this->json = [$name => $this->json]; } return $result; }
php
public function before( ResultInterface $result, ResponseInterface $response, Parameter $model ) { $body = (string) $response->getBody(); $body = $body ?: "{}"; $this->json = \GuzzleHttp\json_decode($body, true); // relocate named arrays, so that they have the same structure as // arrays nested in objects and visit can work on them in the same way if ($model->getType() === 'array' && ($name = $model->getName())) { $this->json = [$name => $this->json]; } return $result; }
[ "public", "function", "before", "(", "ResultInterface", "$", "result", ",", "ResponseInterface", "$", "response", ",", "Parameter", "$", "model", ")", "{", "$", "body", "=", "(", "string", ")", "$", "response", "->", "getBody", "(", ")", ";", "$", "body", "=", "$", "body", "?", ":", "\"{}\"", ";", "$", "this", "->", "json", "=", "\\", "GuzzleHttp", "\\", "json_decode", "(", "$", "body", ",", "true", ")", ";", "// relocate named arrays, so that they have the same structure as", "// arrays nested in objects and visit can work on them in the same way", "if", "(", "$", "model", "->", "getType", "(", ")", "===", "'array'", "&&", "(", "$", "name", "=", "$", "model", "->", "getName", "(", ")", ")", ")", "{", "$", "this", "->", "json", "=", "[", "$", "name", "=>", "$", "this", "->", "json", "]", ";", "}", "return", "$", "result", ";", "}" ]
@param \GuzzleHttp\Command\ResultInterface $result @param \Psr\Http\Message\ResponseInterface $response @param \GuzzleHttp\Command\Guzzle\Parameter $model @return \GuzzleHttp\Command\ResultInterface
[ "@param", "\\", "GuzzleHttp", "\\", "Command", "\\", "ResultInterface", "$result", "@param", "\\", "Psr", "\\", "Http", "\\", "Message", "\\", "ResponseInterface", "$response", "@param", "\\", "GuzzleHttp", "\\", "Command", "\\", "Guzzle", "\\", "Parameter", "$model" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/ResponseLocation/JsonLocation.php#L34-L49
guzzle/guzzle-services
src/ResponseLocation/JsonLocation.php
JsonLocation.recurse
private function recurse(Parameter $param, $value) { if (!is_array($value)) { return $param->filter($value); } $result = []; $type = $param->getType(); if ($type == 'array') { $items = $param->getItems(); foreach ($value as $val) { $result[] = $this->recurse($items, $val); } } elseif ($type == 'object' && !isset($value[0])) { // On the above line, we ensure that the array is associative and // not numerically indexed if ($properties = $param->getProperties()) { foreach ($properties as $property) { $key = $property->getWireName(); if (array_key_exists($key, $value)) { $result[$property->getName()] = $this->recurse( $property, $value[$key] ); // Remove from the value so that AP can later be handled unset($value[$key]); } } } // Only check additional properties if everything wasn't already // handled if ($value) { $additional = $param->getAdditionalProperties(); if ($additional === null || $additional === true) { // Merge the JSON under the resulting array $result += $value; } elseif ($additional instanceof Parameter) { // Process all child elements according to the given schema foreach ($value as $prop => $val) { $result[$prop] = $this->recurse($additional, $val); } } } } return $param->filter($result); }
php
private function recurse(Parameter $param, $value) { if (!is_array($value)) { return $param->filter($value); } $result = []; $type = $param->getType(); if ($type == 'array') { $items = $param->getItems(); foreach ($value as $val) { $result[] = $this->recurse($items, $val); } } elseif ($type == 'object' && !isset($value[0])) { // On the above line, we ensure that the array is associative and // not numerically indexed if ($properties = $param->getProperties()) { foreach ($properties as $property) { $key = $property->getWireName(); if (array_key_exists($key, $value)) { $result[$property->getName()] = $this->recurse( $property, $value[$key] ); // Remove from the value so that AP can later be handled unset($value[$key]); } } } // Only check additional properties if everything wasn't already // handled if ($value) { $additional = $param->getAdditionalProperties(); if ($additional === null || $additional === true) { // Merge the JSON under the resulting array $result += $value; } elseif ($additional instanceof Parameter) { // Process all child elements according to the given schema foreach ($value as $prop => $val) { $result[$prop] = $this->recurse($additional, $val); } } } } return $param->filter($result); }
[ "private", "function", "recurse", "(", "Parameter", "$", "param", ",", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "return", "$", "param", "->", "filter", "(", "$", "value", ")", ";", "}", "$", "result", "=", "[", "]", ";", "$", "type", "=", "$", "param", "->", "getType", "(", ")", ";", "if", "(", "$", "type", "==", "'array'", ")", "{", "$", "items", "=", "$", "param", "->", "getItems", "(", ")", ";", "foreach", "(", "$", "value", "as", "$", "val", ")", "{", "$", "result", "[", "]", "=", "$", "this", "->", "recurse", "(", "$", "items", ",", "$", "val", ")", ";", "}", "}", "elseif", "(", "$", "type", "==", "'object'", "&&", "!", "isset", "(", "$", "value", "[", "0", "]", ")", ")", "{", "// On the above line, we ensure that the array is associative and", "// not numerically indexed", "if", "(", "$", "properties", "=", "$", "param", "->", "getProperties", "(", ")", ")", "{", "foreach", "(", "$", "properties", "as", "$", "property", ")", "{", "$", "key", "=", "$", "property", "->", "getWireName", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "key", ",", "$", "value", ")", ")", "{", "$", "result", "[", "$", "property", "->", "getName", "(", ")", "]", "=", "$", "this", "->", "recurse", "(", "$", "property", ",", "$", "value", "[", "$", "key", "]", ")", ";", "// Remove from the value so that AP can later be handled", "unset", "(", "$", "value", "[", "$", "key", "]", ")", ";", "}", "}", "}", "// Only check additional properties if everything wasn't already", "// handled", "if", "(", "$", "value", ")", "{", "$", "additional", "=", "$", "param", "->", "getAdditionalProperties", "(", ")", ";", "if", "(", "$", "additional", "===", "null", "||", "$", "additional", "===", "true", ")", "{", "// Merge the JSON under the resulting array", "$", "result", "+=", "$", "value", ";", "}", "elseif", "(", "$", "additional", "instanceof", "Parameter", ")", "{", "// Process all child elements according to the given schema", "foreach", "(", "$", "value", "as", "$", "prop", "=>", "$", "val", ")", "{", "$", "result", "[", "$", "prop", "]", "=", "$", "this", "->", "recurse", "(", "$", "additional", ",", "$", "val", ")", ";", "}", "}", "}", "}", "return", "$", "param", "->", "filter", "(", "$", "result", ")", ";", "}" ]
Recursively process a parameter while applying filters @param Parameter $param API parameter being validated @param mixed $value Value to process. @return mixed|null
[ "Recursively", "process", "a", "parameter", "while", "applying", "filters" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/ResponseLocation/JsonLocation.php#L128-L175
guzzle/guzzle-services
src/QuerySerializer/Rfc3986Serializer.php
Rfc3986Serializer.aggregate
public function aggregate(array $queryParams) { $queryString = http_build_query($queryParams, null, '&', PHP_QUERY_RFC3986); if ($this->removeNumericIndices) { $queryString = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $queryString); } return $queryString; }
php
public function aggregate(array $queryParams) { $queryString = http_build_query($queryParams, null, '&', PHP_QUERY_RFC3986); if ($this->removeNumericIndices) { $queryString = preg_replace('/%5B[0-9]+%5D/simU', '%5B%5D', $queryString); } return $queryString; }
[ "public", "function", "aggregate", "(", "array", "$", "queryParams", ")", "{", "$", "queryString", "=", "http_build_query", "(", "$", "queryParams", ",", "null", ",", "'&'", ",", "PHP_QUERY_RFC3986", ")", ";", "if", "(", "$", "this", "->", "removeNumericIndices", ")", "{", "$", "queryString", "=", "preg_replace", "(", "'/%5B[0-9]+%5D/simU'", ",", "'%5B%5D'", ",", "$", "queryString", ")", ";", "}", "return", "$", "queryString", ";", "}" ]
{@inheritDoc}
[ "{" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/QuerySerializer/Rfc3986Serializer.php#L23-L32
guzzle/guzzle-services
src/ResponseLocation/HeaderLocation.php
HeaderLocation.visit
public function visit( ResultInterface $result, ResponseInterface $response, Parameter $param ) { // Retrieving a single header by name $name = $param->getName(); if ($header = $response->getHeader($param->getWireName())) { if (is_array($header)) { $header = array_shift($header); } $result[$name] = $param->filter($header); } return $result; }
php
public function visit( ResultInterface $result, ResponseInterface $response, Parameter $param ) { // Retrieving a single header by name $name = $param->getName(); if ($header = $response->getHeader($param->getWireName())) { if (is_array($header)) { $header = array_shift($header); } $result[$name] = $param->filter($header); } return $result; }
[ "public", "function", "visit", "(", "ResultInterface", "$", "result", ",", "ResponseInterface", "$", "response", ",", "Parameter", "$", "param", ")", "{", "// Retrieving a single header by name", "$", "name", "=", "$", "param", "->", "getName", "(", ")", ";", "if", "(", "$", "header", "=", "$", "response", "->", "getHeader", "(", "$", "param", "->", "getWireName", "(", ")", ")", ")", "{", "if", "(", "is_array", "(", "$", "header", ")", ")", "{", "$", "header", "=", "array_shift", "(", "$", "header", ")", ";", "}", "$", "result", "[", "$", "name", "]", "=", "$", "param", "->", "filter", "(", "$", "header", ")", ";", "}", "return", "$", "result", ";", "}" ]
@param ResultInterface $result @param ResponseInterface $response @param Parameter $param @return ResultInterface
[ "@param", "ResultInterface", "$result", "@param", "ResponseInterface", "$response", "@param", "Parameter", "$param" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/ResponseLocation/HeaderLocation.php#L31-L46
guzzle/guzzle-services
src/RequestLocation/HeaderLocation.php
HeaderLocation.visit
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $value = $command[$param->getName()]; return $request->withHeader($param->getWireName(), $param->filter($value)); }
php
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $value = $command[$param->getName()]; return $request->withHeader($param->getWireName(), $param->filter($value)); }
[ "public", "function", "visit", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Parameter", "$", "param", ")", "{", "$", "value", "=", "$", "command", "[", "$", "param", "->", "getName", "(", ")", "]", ";", "return", "$", "request", "->", "withHeader", "(", "$", "param", "->", "getWireName", "(", ")", ",", "$", "param", "->", "filter", "(", "$", "value", ")", ")", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Parameter $param @return MessageInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Parameter", "$param" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/HeaderLocation.php#L33-L41
guzzle/guzzle-services
src/Operation.php
Operation.getData
public function getData($name = null) { if ($name === null) { return $this->config['data']; } elseif (isset($this->config['data'][$name])) { return $this->config['data'][$name]; } else { return null; } }
php
public function getData($name = null) { if ($name === null) { return $this->config['data']; } elseif (isset($this->config['data'][$name])) { return $this->config['data'][$name]; } else { return null; } }
[ "public", "function", "getData", "(", "$", "name", "=", "null", ")", "{", "if", "(", "$", "name", "===", "null", ")", "{", "return", "$", "this", "->", "config", "[", "'data'", "]", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "config", "[", "'data'", "]", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "config", "[", "'data'", "]", "[", "$", "name", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get extra data from the operation @param string $name Name of the data point to retrieve or null to retrieve all of the extra data. @return mixed|null
[ "Get", "extra", "data", "from", "the", "operation" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Operation.php#L247-L256
guzzle/guzzle-services
src/Operation.php
Operation.resolveParameters
private function resolveParameters() { // Parameters need special handling when adding foreach ($this->config['parameters'] as $name => $param) { if (!is_array($param)) { throw new \InvalidArgumentException( "Parameters must be arrays, {$this->config['name']}.$name is ".gettype($param) ); } $param['name'] = $name; $this->parameters[$name] = new Parameter( $param, ['description' => $this->description] ); } if ($this->config['additionalParameters']) { if (is_array($this->config['additionalParameters'])) { $this->additionalParameters = new Parameter( $this->config['additionalParameters'], ['description' => $this->description] ); } else { $this->additionalParameters = $this->config['additionalParameters']; } } }
php
private function resolveParameters() { // Parameters need special handling when adding foreach ($this->config['parameters'] as $name => $param) { if (!is_array($param)) { throw new \InvalidArgumentException( "Parameters must be arrays, {$this->config['name']}.$name is ".gettype($param) ); } $param['name'] = $name; $this->parameters[$name] = new Parameter( $param, ['description' => $this->description] ); } if ($this->config['additionalParameters']) { if (is_array($this->config['additionalParameters'])) { $this->additionalParameters = new Parameter( $this->config['additionalParameters'], ['description' => $this->description] ); } else { $this->additionalParameters = $this->config['additionalParameters']; } } }
[ "private", "function", "resolveParameters", "(", ")", "{", "// Parameters need special handling when adding", "foreach", "(", "$", "this", "->", "config", "[", "'parameters'", "]", "as", "$", "name", "=>", "$", "param", ")", "{", "if", "(", "!", "is_array", "(", "$", "param", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"Parameters must be arrays, {$this->config['name']}.$name is \"", ".", "gettype", "(", "$", "param", ")", ")", ";", "}", "$", "param", "[", "'name'", "]", "=", "$", "name", ";", "$", "this", "->", "parameters", "[", "$", "name", "]", "=", "new", "Parameter", "(", "$", "param", ",", "[", "'description'", "=>", "$", "this", "->", "description", "]", ")", ";", "}", "if", "(", "$", "this", "->", "config", "[", "'additionalParameters'", "]", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "config", "[", "'additionalParameters'", "]", ")", ")", "{", "$", "this", "->", "additionalParameters", "=", "new", "Parameter", "(", "$", "this", "->", "config", "[", "'additionalParameters'", "]", ",", "[", "'description'", "=>", "$", "this", "->", "description", "]", ")", ";", "}", "else", "{", "$", "this", "->", "additionalParameters", "=", "$", "this", "->", "config", "[", "'additionalParameters'", "]", ";", "}", "}", "}" ]
Process the description and extract the parameter config @return void
[ "Process", "the", "description", "and", "extract", "the", "parameter", "config" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Operation.php#L285-L311
guzzle/guzzle-services
src/Serializer.php
Serializer.prepareRequest
protected function prepareRequest( CommandInterface $command, RequestInterface $request ) { $visitedLocations = []; $operation = $this->description->getOperation($command->getName()); // Visit each actual parameter foreach ($operation->getParams() as $name => $param) { /* @var Parameter $param */ $location = $param->getLocation(); // Skip parameters that have not been set or are URI location if ($location == 'uri' || !$command->hasParam($name)) { continue; } if (!isset($this->locations[$location])) { throw new \RuntimeException("No location registered for $name"); } $visitedLocations[$location] = true; $request = $this->locations[$location]->visit($command, $request, $param); } // Ensure that the after() method is invoked for additionalParameters /** @var Parameter $additional */ if ($additional = $operation->getAdditionalParameters()) { $visitedLocations[$additional->getLocation()] = true; } // Call the after() method for each visited location foreach (array_keys($visitedLocations) as $location) { $request = $this->locations[$location]->after($command, $request, $operation); } return $request; }
php
protected function prepareRequest( CommandInterface $command, RequestInterface $request ) { $visitedLocations = []; $operation = $this->description->getOperation($command->getName()); // Visit each actual parameter foreach ($operation->getParams() as $name => $param) { /* @var Parameter $param */ $location = $param->getLocation(); // Skip parameters that have not been set or are URI location if ($location == 'uri' || !$command->hasParam($name)) { continue; } if (!isset($this->locations[$location])) { throw new \RuntimeException("No location registered for $name"); } $visitedLocations[$location] = true; $request = $this->locations[$location]->visit($command, $request, $param); } // Ensure that the after() method is invoked for additionalParameters /** @var Parameter $additional */ if ($additional = $operation->getAdditionalParameters()) { $visitedLocations[$additional->getLocation()] = true; } // Call the after() method for each visited location foreach (array_keys($visitedLocations) as $location) { $request = $this->locations[$location]->after($command, $request, $operation); } return $request; }
[ "protected", "function", "prepareRequest", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ")", "{", "$", "visitedLocations", "=", "[", "]", ";", "$", "operation", "=", "$", "this", "->", "description", "->", "getOperation", "(", "$", "command", "->", "getName", "(", ")", ")", ";", "// Visit each actual parameter", "foreach", "(", "$", "operation", "->", "getParams", "(", ")", "as", "$", "name", "=>", "$", "param", ")", "{", "/* @var Parameter $param */", "$", "location", "=", "$", "param", "->", "getLocation", "(", ")", ";", "// Skip parameters that have not been set or are URI location", "if", "(", "$", "location", "==", "'uri'", "||", "!", "$", "command", "->", "hasParam", "(", "$", "name", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "locations", "[", "$", "location", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"No location registered for $name\"", ")", ";", "}", "$", "visitedLocations", "[", "$", "location", "]", "=", "true", ";", "$", "request", "=", "$", "this", "->", "locations", "[", "$", "location", "]", "->", "visit", "(", "$", "command", ",", "$", "request", ",", "$", "param", ")", ";", "}", "// Ensure that the after() method is invoked for additionalParameters", "/** @var Parameter $additional */", "if", "(", "$", "additional", "=", "$", "operation", "->", "getAdditionalParameters", "(", ")", ")", "{", "$", "visitedLocations", "[", "$", "additional", "->", "getLocation", "(", ")", "]", "=", "true", ";", "}", "// Call the after() method for each visited location", "foreach", "(", "array_keys", "(", "$", "visitedLocations", ")", "as", "$", "location", ")", "{", "$", "request", "=", "$", "this", "->", "locations", "[", "$", "location", "]", "->", "after", "(", "$", "command", ",", "$", "request", ",", "$", "operation", ")", ";", "}", "return", "$", "request", ";", "}" ]
Prepares a request for sending using location visitors @param CommandInterface $command @param RequestInterface $request Request being created @return RequestInterface @throws \RuntimeException If a location cannot be handled
[ "Prepares", "a", "request", "for", "sending", "using", "location", "visitors" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Serializer.php#L71-L105
guzzle/guzzle-services
src/Serializer.php
Serializer.createRequest
protected function createRequest(CommandInterface $command) { $operation = $this->description->getOperation($command->getName()); // If command does not specify a template, assume the client's base URL. if (null === $operation->getUri()) { return new Request( $operation->getHttpMethod(), $this->description->getBaseUri() ); } return $this->createCommandWithUri($operation, $command); }
php
protected function createRequest(CommandInterface $command) { $operation = $this->description->getOperation($command->getName()); // If command does not specify a template, assume the client's base URL. if (null === $operation->getUri()) { return new Request( $operation->getHttpMethod(), $this->description->getBaseUri() ); } return $this->createCommandWithUri($operation, $command); }
[ "protected", "function", "createRequest", "(", "CommandInterface", "$", "command", ")", "{", "$", "operation", "=", "$", "this", "->", "description", "->", "getOperation", "(", "$", "command", "->", "getName", "(", ")", ")", ";", "// If command does not specify a template, assume the client's base URL.", "if", "(", "null", "===", "$", "operation", "->", "getUri", "(", ")", ")", "{", "return", "new", "Request", "(", "$", "operation", "->", "getHttpMethod", "(", ")", ",", "$", "this", "->", "description", "->", "getBaseUri", "(", ")", ")", ";", "}", "return", "$", "this", "->", "createCommandWithUri", "(", "$", "operation", ",", "$", "command", ")", ";", "}" ]
Create a request for the command and operation @param CommandInterface $command @return RequestInterface @throws \RuntimeException
[ "Create", "a", "request", "for", "the", "command", "and", "operation" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Serializer.php#L115-L128
guzzle/guzzle-services
src/Serializer.php
Serializer.createCommandWithUri
private function createCommandWithUri( Operation $operation, CommandInterface $command ) { // Get the path values and use the client config settings $variables = []; foreach ($operation->getParams() as $name => $arg) { /* @var Parameter $arg */ if ($arg->getLocation() == 'uri') { if (isset($command[$name])) { $variables[$name] = $arg->filter($command[$name]); if (!is_array($variables[$name])) { $variables[$name] = (string) $variables[$name]; } } } } // Expand the URI template. $uri = \GuzzleHttp\uri_template($operation->getUri(), $variables); return new Request( $operation->getHttpMethod(), Uri::resolve($this->description->getBaseUri(), $uri) ); }
php
private function createCommandWithUri( Operation $operation, CommandInterface $command ) { // Get the path values and use the client config settings $variables = []; foreach ($operation->getParams() as $name => $arg) { /* @var Parameter $arg */ if ($arg->getLocation() == 'uri') { if (isset($command[$name])) { $variables[$name] = $arg->filter($command[$name]); if (!is_array($variables[$name])) { $variables[$name] = (string) $variables[$name]; } } } } // Expand the URI template. $uri = \GuzzleHttp\uri_template($operation->getUri(), $variables); return new Request( $operation->getHttpMethod(), Uri::resolve($this->description->getBaseUri(), $uri) ); }
[ "private", "function", "createCommandWithUri", "(", "Operation", "$", "operation", ",", "CommandInterface", "$", "command", ")", "{", "// Get the path values and use the client config settings", "$", "variables", "=", "[", "]", ";", "foreach", "(", "$", "operation", "->", "getParams", "(", ")", "as", "$", "name", "=>", "$", "arg", ")", "{", "/* @var Parameter $arg */", "if", "(", "$", "arg", "->", "getLocation", "(", ")", "==", "'uri'", ")", "{", "if", "(", "isset", "(", "$", "command", "[", "$", "name", "]", ")", ")", "{", "$", "variables", "[", "$", "name", "]", "=", "$", "arg", "->", "filter", "(", "$", "command", "[", "$", "name", "]", ")", ";", "if", "(", "!", "is_array", "(", "$", "variables", "[", "$", "name", "]", ")", ")", "{", "$", "variables", "[", "$", "name", "]", "=", "(", "string", ")", "$", "variables", "[", "$", "name", "]", ";", "}", "}", "}", "}", "// Expand the URI template.", "$", "uri", "=", "\\", "GuzzleHttp", "\\", "uri_template", "(", "$", "operation", "->", "getUri", "(", ")", ",", "$", "variables", ")", ";", "return", "new", "Request", "(", "$", "operation", "->", "getHttpMethod", "(", ")", ",", "Uri", "::", "resolve", "(", "$", "this", "->", "description", "->", "getBaseUri", "(", ")", ",", "$", "uri", ")", ")", ";", "}" ]
Create a request for an operation with a uri merged onto a base URI @param \GuzzleHttp\Command\Guzzle\Operation $operation @param \GuzzleHttp\Command\CommandInterface $command @return \GuzzleHttp\Psr7\Request
[ "Create", "a", "request", "for", "an", "operation", "with", "a", "uri", "merged", "onto", "a", "base", "URI" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Serializer.php#L138-L163
guzzle/guzzle-services
src/RequestLocation/FormParamLocation.php
FormParamLocation.visit
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $this->formParamsData['form_params'][$param->getWireName()] = $this->prepareValue( $command[$param->getName()], $param ); return $request; }
php
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $this->formParamsData['form_params'][$param->getWireName()] = $this->prepareValue( $command[$param->getName()], $param ); return $request; }
[ "public", "function", "visit", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Parameter", "$", "param", ")", "{", "$", "this", "->", "formParamsData", "[", "'form_params'", "]", "[", "$", "param", "->", "getWireName", "(", ")", "]", "=", "$", "this", "->", "prepareValue", "(", "$", "command", "[", "$", "param", "->", "getName", "(", ")", "]", ",", "$", "param", ")", ";", "return", "$", "request", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Parameter $param @return RequestInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Parameter", "$param" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/FormParamLocation.php#L38-L49
guzzle/guzzle-services
src/RequestLocation/FormParamLocation.php
FormParamLocation.after
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { $data = $this->formParamsData; $this->formParamsData = []; $modify = []; // Add additional parameters to the form_params array $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $data['form_params'][$key] = $this->prepareValue($value, $additional); } } } $body = http_build_query($data['form_params'], '', '&'); $modify['body'] = Psr7\stream_for($body); $modify['set_headers']['Content-Type'] = $this->contentType; $request = Psr7\modify_request($request, $modify); return $request; }
php
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { $data = $this->formParamsData; $this->formParamsData = []; $modify = []; // Add additional parameters to the form_params array $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $data['form_params'][$key] = $this->prepareValue($value, $additional); } } } $body = http_build_query($data['form_params'], '', '&'); $modify['body'] = Psr7\stream_for($body); $modify['set_headers']['Content-Type'] = $this->contentType; $request = Psr7\modify_request($request, $modify); return $request; }
[ "public", "function", "after", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Operation", "$", "operation", ")", "{", "$", "data", "=", "$", "this", "->", "formParamsData", ";", "$", "this", "->", "formParamsData", "=", "[", "]", ";", "$", "modify", "=", "[", "]", ";", "// Add additional parameters to the form_params array", "$", "additional", "=", "$", "operation", "->", "getAdditionalParameters", "(", ")", ";", "if", "(", "$", "additional", "&&", "$", "additional", "->", "getLocation", "(", ")", "==", "$", "this", "->", "locationName", ")", "{", "foreach", "(", "$", "command", "->", "toArray", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "$", "operation", "->", "hasParam", "(", "$", "key", ")", ")", "{", "$", "data", "[", "'form_params'", "]", "[", "$", "key", "]", "=", "$", "this", "->", "prepareValue", "(", "$", "value", ",", "$", "additional", ")", ";", "}", "}", "}", "$", "body", "=", "http_build_query", "(", "$", "data", "[", "'form_params'", "]", ",", "''", ",", "'&'", ")", ";", "$", "modify", "[", "'body'", "]", "=", "Psr7", "\\", "stream_for", "(", "$", "body", ")", ";", "$", "modify", "[", "'set_headers'", "]", "[", "'Content-Type'", "]", "=", "$", "this", "->", "contentType", ";", "$", "request", "=", "Psr7", "\\", "modify_request", "(", "$", "request", ",", "$", "modify", ")", ";", "return", "$", "request", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Operation $operation @return RequestInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Operation", "$operation" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/FormParamLocation.php#L58-L83
guzzle/guzzle-services
src/Deserializer.php
Deserializer.visit
protected function visit(Parameter $model, ResponseInterface $response) { $result = new Result(); $context = ['visitors' => []]; if ($model->getType() === 'object') { $result = $this->visitOuterObject($model, $result, $response, $context); } elseif ($model->getType() === 'array') { $result = $this->visitOuterArray($model, $result, $response, $context); } else { throw new \InvalidArgumentException('Invalid response model: ' . $model->getType()); } // Call the after() method of each found visitor /** @var ResponseLocationInterface $visitor */ foreach ($context['visitors'] as $visitor) { $result = $visitor->after($result, $response, $model); } return $result; }
php
protected function visit(Parameter $model, ResponseInterface $response) { $result = new Result(); $context = ['visitors' => []]; if ($model->getType() === 'object') { $result = $this->visitOuterObject($model, $result, $response, $context); } elseif ($model->getType() === 'array') { $result = $this->visitOuterArray($model, $result, $response, $context); } else { throw new \InvalidArgumentException('Invalid response model: ' . $model->getType()); } // Call the after() method of each found visitor /** @var ResponseLocationInterface $visitor */ foreach ($context['visitors'] as $visitor) { $result = $visitor->after($result, $response, $model); } return $result; }
[ "protected", "function", "visit", "(", "Parameter", "$", "model", ",", "ResponseInterface", "$", "response", ")", "{", "$", "result", "=", "new", "Result", "(", ")", ";", "$", "context", "=", "[", "'visitors'", "=>", "[", "]", "]", ";", "if", "(", "$", "model", "->", "getType", "(", ")", "===", "'object'", ")", "{", "$", "result", "=", "$", "this", "->", "visitOuterObject", "(", "$", "model", ",", "$", "result", ",", "$", "response", ",", "$", "context", ")", ";", "}", "elseif", "(", "$", "model", "->", "getType", "(", ")", "===", "'array'", ")", "{", "$", "result", "=", "$", "this", "->", "visitOuterArray", "(", "$", "model", ",", "$", "result", ",", "$", "response", ",", "$", "context", ")", ";", "}", "else", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Invalid response model: '", ".", "$", "model", "->", "getType", "(", ")", ")", ";", "}", "// Call the after() method of each found visitor", "/** @var ResponseLocationInterface $visitor */", "foreach", "(", "$", "context", "[", "'visitors'", "]", "as", "$", "visitor", ")", "{", "$", "result", "=", "$", "visitor", "->", "after", "(", "$", "result", ",", "$", "response", ",", "$", "model", ")", ";", "}", "return", "$", "result", ";", "}" ]
Handles visit() and after() methods of the Response locations @param Parameter $model @param ResponseInterface $response @return Result|ResultInterface|void
[ "Handles", "visit", "()", "and", "after", "()", "methods", "of", "the", "Response", "locations" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Deserializer.php#L110-L130
guzzle/guzzle-services
src/Deserializer.php
Deserializer.triggerBeforeVisitor
private function triggerBeforeVisitor( $location, Parameter $model, ResultInterface $result, ResponseInterface $response, array &$context ) { if (!isset($this->responseLocations[$location])) { throw new \RuntimeException("Unknown location: $location"); } $context['visitors'][$location] = $this->responseLocations[$location]; $result = $this->responseLocations[$location]->before( $result, $response, $model ); return $result; }
php
private function triggerBeforeVisitor( $location, Parameter $model, ResultInterface $result, ResponseInterface $response, array &$context ) { if (!isset($this->responseLocations[$location])) { throw new \RuntimeException("Unknown location: $location"); } $context['visitors'][$location] = $this->responseLocations[$location]; $result = $this->responseLocations[$location]->before( $result, $response, $model ); return $result; }
[ "private", "function", "triggerBeforeVisitor", "(", "$", "location", ",", "Parameter", "$", "model", ",", "ResultInterface", "$", "result", ",", "ResponseInterface", "$", "response", ",", "array", "&", "$", "context", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "responseLocations", "[", "$", "location", "]", ")", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "\"Unknown location: $location\"", ")", ";", "}", "$", "context", "[", "'visitors'", "]", "[", "$", "location", "]", "=", "$", "this", "->", "responseLocations", "[", "$", "location", "]", ";", "$", "result", "=", "$", "this", "->", "responseLocations", "[", "$", "location", "]", "->", "before", "(", "$", "result", ",", "$", "response", ",", "$", "model", ")", ";", "return", "$", "result", ";", "}" ]
Handles the before() method of Response locations @param string $location @param Parameter $model @param ResultInterface $result @param ResponseInterface $response @param array $context @return ResultInterface
[ "Handles", "the", "before", "()", "method", "of", "Response", "locations" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Deserializer.php#L142-L162
guzzle/guzzle-services
src/Deserializer.php
Deserializer.visitOuterObject
private function visitOuterObject( Parameter $model, ResultInterface $result, ResponseInterface $response, array &$context ) { $parentLocation = $model->getLocation(); // If top-level additionalProperties is a schema, then visit it $additional = $model->getAdditionalProperties(); if ($additional instanceof Parameter) { // Use the model location if none set on additionalProperties. $location = $additional->getLocation() ?: $parentLocation; $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context); } // Use 'location' from all individual defined properties, but fall back // to the model location if no per-property location is set. Collect // the properties that need to be visited into an array. $visitProperties = []; foreach ($model->getProperties() as $schema) { $location = $schema->getLocation() ?: $parentLocation; if ($location) { $visitProperties[] = [$location, $schema]; // Trigger the before method on each unique visitor location if (!isset($context['visitors'][$location])) { $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context); } } } // Actually visit each response element foreach ($visitProperties as $property) { $result = $this->responseLocations[$property[0]]->visit($result, $response, $property[1]); } return $result; }
php
private function visitOuterObject( Parameter $model, ResultInterface $result, ResponseInterface $response, array &$context ) { $parentLocation = $model->getLocation(); // If top-level additionalProperties is a schema, then visit it $additional = $model->getAdditionalProperties(); if ($additional instanceof Parameter) { // Use the model location if none set on additionalProperties. $location = $additional->getLocation() ?: $parentLocation; $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context); } // Use 'location' from all individual defined properties, but fall back // to the model location if no per-property location is set. Collect // the properties that need to be visited into an array. $visitProperties = []; foreach ($model->getProperties() as $schema) { $location = $schema->getLocation() ?: $parentLocation; if ($location) { $visitProperties[] = [$location, $schema]; // Trigger the before method on each unique visitor location if (!isset($context['visitors'][$location])) { $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context); } } } // Actually visit each response element foreach ($visitProperties as $property) { $result = $this->responseLocations[$property[0]]->visit($result, $response, $property[1]); } return $result; }
[ "private", "function", "visitOuterObject", "(", "Parameter", "$", "model", ",", "ResultInterface", "$", "result", ",", "ResponseInterface", "$", "response", ",", "array", "&", "$", "context", ")", "{", "$", "parentLocation", "=", "$", "model", "->", "getLocation", "(", ")", ";", "// If top-level additionalProperties is a schema, then visit it", "$", "additional", "=", "$", "model", "->", "getAdditionalProperties", "(", ")", ";", "if", "(", "$", "additional", "instanceof", "Parameter", ")", "{", "// Use the model location if none set on additionalProperties.", "$", "location", "=", "$", "additional", "->", "getLocation", "(", ")", "?", ":", "$", "parentLocation", ";", "$", "result", "=", "$", "this", "->", "triggerBeforeVisitor", "(", "$", "location", ",", "$", "model", ",", "$", "result", ",", "$", "response", ",", "$", "context", ")", ";", "}", "// Use 'location' from all individual defined properties, but fall back", "// to the model location if no per-property location is set. Collect", "// the properties that need to be visited into an array.", "$", "visitProperties", "=", "[", "]", ";", "foreach", "(", "$", "model", "->", "getProperties", "(", ")", "as", "$", "schema", ")", "{", "$", "location", "=", "$", "schema", "->", "getLocation", "(", ")", "?", ":", "$", "parentLocation", ";", "if", "(", "$", "location", ")", "{", "$", "visitProperties", "[", "]", "=", "[", "$", "location", ",", "$", "schema", "]", ";", "// Trigger the before method on each unique visitor location", "if", "(", "!", "isset", "(", "$", "context", "[", "'visitors'", "]", "[", "$", "location", "]", ")", ")", "{", "$", "result", "=", "$", "this", "->", "triggerBeforeVisitor", "(", "$", "location", ",", "$", "model", ",", "$", "result", ",", "$", "response", ",", "$", "context", ")", ";", "}", "}", "}", "// Actually visit each response element", "foreach", "(", "$", "visitProperties", "as", "$", "property", ")", "{", "$", "result", "=", "$", "this", "->", "responseLocations", "[", "$", "property", "[", "0", "]", "]", "->", "visit", "(", "$", "result", ",", "$", "response", ",", "$", "property", "[", "1", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Visits the outer object @param Parameter $model @param ResultInterface $result @param ResponseInterface $response @param array $context @return ResultInterface
[ "Visits", "the", "outer", "object" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Deserializer.php#L173-L210
guzzle/guzzle-services
src/Deserializer.php
Deserializer.visitOuterArray
private function visitOuterArray( Parameter $model, ResultInterface $result, ResponseInterface $response, array &$context ) { // Use 'location' defined on the top of the model if (!($location = $model->getLocation())) { return; } // Trigger the before method on each unique visitor location if (!isset($context['visitors'][$location])) { $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context); } // Visit each item in the response $result = $this->responseLocations[$location]->visit($result, $response, $model); return $result; }
php
private function visitOuterArray( Parameter $model, ResultInterface $result, ResponseInterface $response, array &$context ) { // Use 'location' defined on the top of the model if (!($location = $model->getLocation())) { return; } // Trigger the before method on each unique visitor location if (!isset($context['visitors'][$location])) { $result = $this->triggerBeforeVisitor($location, $model, $result, $response, $context); } // Visit each item in the response $result = $this->responseLocations[$location]->visit($result, $response, $model); return $result; }
[ "private", "function", "visitOuterArray", "(", "Parameter", "$", "model", ",", "ResultInterface", "$", "result", ",", "ResponseInterface", "$", "response", ",", "array", "&", "$", "context", ")", "{", "// Use 'location' defined on the top of the model", "if", "(", "!", "(", "$", "location", "=", "$", "model", "->", "getLocation", "(", ")", ")", ")", "{", "return", ";", "}", "// Trigger the before method on each unique visitor location", "if", "(", "!", "isset", "(", "$", "context", "[", "'visitors'", "]", "[", "$", "location", "]", ")", ")", "{", "$", "result", "=", "$", "this", "->", "triggerBeforeVisitor", "(", "$", "location", ",", "$", "model", ",", "$", "result", ",", "$", "response", ",", "$", "context", ")", ";", "}", "// Visit each item in the response", "$", "result", "=", "$", "this", "->", "responseLocations", "[", "$", "location", "]", "->", "visit", "(", "$", "result", ",", "$", "response", ",", "$", "model", ")", ";", "return", "$", "result", ";", "}" ]
Visits the outer array @param Parameter $model @param ResultInterface $result @param ResponseInterface $response @param array $context @return ResultInterface|void
[ "Visits", "the", "outer", "array" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Deserializer.php#L221-L241
guzzle/guzzle-services
src/Deserializer.php
Deserializer.handleErrorResponses
protected function handleErrorResponses( ResponseInterface $response, RequestInterface $request, CommandInterface $command, Operation $operation ) { $errors = $operation->getErrorResponses(); // We iterate through each errors in service description. If the descriptor contains both a phrase and // status code, there must be an exact match of both. Otherwise, a match of status code is enough $bestException = null; foreach ($errors as $error) { $code = (int) $error['code']; if ($response->getStatusCode() !== $code) { continue; } if (isset($error['phrase']) && ! ($error['phrase'] === $response->getReasonPhrase())) { continue; } $bestException = $error['class']; // If there is an exact match of phrase + code, then we cannot find a more specialized exception in // the array, so we can break early instead of iterating the remaining ones if (isset($error['phrase'])) { break; } } if (null !== $bestException) { throw new $bestException($response->getReasonPhrase(), $command, null, $request, $response); } // If we reach here, no exception could be match from descriptor, and Guzzle exception will propagate if // option "http_errors" is set to true, which is the default setting. }
php
protected function handleErrorResponses( ResponseInterface $response, RequestInterface $request, CommandInterface $command, Operation $operation ) { $errors = $operation->getErrorResponses(); // We iterate through each errors in service description. If the descriptor contains both a phrase and // status code, there must be an exact match of both. Otherwise, a match of status code is enough $bestException = null; foreach ($errors as $error) { $code = (int) $error['code']; if ($response->getStatusCode() !== $code) { continue; } if (isset($error['phrase']) && ! ($error['phrase'] === $response->getReasonPhrase())) { continue; } $bestException = $error['class']; // If there is an exact match of phrase + code, then we cannot find a more specialized exception in // the array, so we can break early instead of iterating the remaining ones if (isset($error['phrase'])) { break; } } if (null !== $bestException) { throw new $bestException($response->getReasonPhrase(), $command, null, $request, $response); } // If we reach here, no exception could be match from descriptor, and Guzzle exception will propagate if // option "http_errors" is set to true, which is the default setting. }
[ "protected", "function", "handleErrorResponses", "(", "ResponseInterface", "$", "response", ",", "RequestInterface", "$", "request", ",", "CommandInterface", "$", "command", ",", "Operation", "$", "operation", ")", "{", "$", "errors", "=", "$", "operation", "->", "getErrorResponses", "(", ")", ";", "// We iterate through each errors in service description. If the descriptor contains both a phrase and", "// status code, there must be an exact match of both. Otherwise, a match of status code is enough", "$", "bestException", "=", "null", ";", "foreach", "(", "$", "errors", "as", "$", "error", ")", "{", "$", "code", "=", "(", "int", ")", "$", "error", "[", "'code'", "]", ";", "if", "(", "$", "response", "->", "getStatusCode", "(", ")", "!==", "$", "code", ")", "{", "continue", ";", "}", "if", "(", "isset", "(", "$", "error", "[", "'phrase'", "]", ")", "&&", "!", "(", "$", "error", "[", "'phrase'", "]", "===", "$", "response", "->", "getReasonPhrase", "(", ")", ")", ")", "{", "continue", ";", "}", "$", "bestException", "=", "$", "error", "[", "'class'", "]", ";", "// If there is an exact match of phrase + code, then we cannot find a more specialized exception in", "// the array, so we can break early instead of iterating the remaining ones", "if", "(", "isset", "(", "$", "error", "[", "'phrase'", "]", ")", ")", "{", "break", ";", "}", "}", "if", "(", "null", "!==", "$", "bestException", ")", "{", "throw", "new", "$", "bestException", "(", "$", "response", "->", "getReasonPhrase", "(", ")", ",", "$", "command", ",", "null", ",", "$", "request", ",", "$", "response", ")", ";", "}", "// If we reach here, no exception could be match from descriptor, and Guzzle exception will propagate if", "// option \"http_errors\" is set to true, which is the default setting.", "}" ]
Reads the "errorResponses" from commands, and trigger appropriate exceptions In order for the exception to be properly triggered, all your exceptions must be instance of "GuzzleHttp\Command\Exception\CommandException". If that's not the case, your exceptions will be wrapped around a CommandException @param ResponseInterface $response @param RequestInterface $request @param CommandInterface $command @param Operation $operation
[ "Reads", "the", "errorResponses", "from", "commands", "and", "trigger", "appropriate", "exceptions" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Deserializer.php#L255-L293
guzzle/guzzle-services
src/RequestLocation/QueryLocation.php
QueryLocation.visit
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $uri = $request->getUri(); $query = Psr7\parse_query($uri->getQuery()); $query[$param->getWireName()] = $this->prepareValue( $command[$param->getName()], $param ); $uri = $uri->withQuery($this->querySerializer->aggregate($query)); return $request->withUri($uri); }
php
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $uri = $request->getUri(); $query = Psr7\parse_query($uri->getQuery()); $query[$param->getWireName()] = $this->prepareValue( $command[$param->getName()], $param ); $uri = $uri->withQuery($this->querySerializer->aggregate($query)); return $request->withUri($uri); }
[ "public", "function", "visit", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Parameter", "$", "param", ")", "{", "$", "uri", "=", "$", "request", "->", "getUri", "(", ")", ";", "$", "query", "=", "Psr7", "\\", "parse_query", "(", "$", "uri", "->", "getQuery", "(", ")", ")", ";", "$", "query", "[", "$", "param", "->", "getWireName", "(", ")", "]", "=", "$", "this", "->", "prepareValue", "(", "$", "command", "[", "$", "param", "->", "getName", "(", ")", "]", ",", "$", "param", ")", ";", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "$", "this", "->", "querySerializer", "->", "aggregate", "(", "$", "query", ")", ")", ";", "return", "$", "request", "->", "withUri", "(", "$", "uri", ")", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Parameter $param @return RequestInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Parameter", "$param" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/QueryLocation.php#L42-L58
guzzle/guzzle-services
src/RequestLocation/QueryLocation.php
QueryLocation.after
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $uri = $request->getUri(); $query = Psr7\parse_query($uri->getQuery()); $query[$key] = $this->prepareValue( $value, $additional ); $uri = $uri->withQuery($this->querySerializer->aggregate($query)); $request = $request->withUri($uri); } } } return $request; }
php
public function after( CommandInterface $command, RequestInterface $request, Operation $operation ) { $additional = $operation->getAdditionalParameters(); if ($additional && $additional->getLocation() == $this->locationName) { foreach ($command->toArray() as $key => $value) { if (!$operation->hasParam($key)) { $uri = $request->getUri(); $query = Psr7\parse_query($uri->getQuery()); $query[$key] = $this->prepareValue( $value, $additional ); $uri = $uri->withQuery($this->querySerializer->aggregate($query)); $request = $request->withUri($uri); } } } return $request; }
[ "public", "function", "after", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Operation", "$", "operation", ")", "{", "$", "additional", "=", "$", "operation", "->", "getAdditionalParameters", "(", ")", ";", "if", "(", "$", "additional", "&&", "$", "additional", "->", "getLocation", "(", ")", "==", "$", "this", "->", "locationName", ")", "{", "foreach", "(", "$", "command", "->", "toArray", "(", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "!", "$", "operation", "->", "hasParam", "(", "$", "key", ")", ")", "{", "$", "uri", "=", "$", "request", "->", "getUri", "(", ")", ";", "$", "query", "=", "Psr7", "\\", "parse_query", "(", "$", "uri", "->", "getQuery", "(", ")", ")", ";", "$", "query", "[", "$", "key", "]", "=", "$", "this", "->", "prepareValue", "(", "$", "value", ",", "$", "additional", ")", ";", "$", "uri", "=", "$", "uri", "->", "withQuery", "(", "$", "this", "->", "querySerializer", "->", "aggregate", "(", "$", "query", ")", ")", ";", "$", "request", "=", "$", "request", "->", "withUri", "(", "$", "uri", ")", ";", "}", "}", "}", "return", "$", "request", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Operation $operation @return RequestInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Operation", "$operation" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/QueryLocation.php#L67-L91
guzzle/guzzle-services
src/RequestLocation/BodyLocation.php
BodyLocation.visit
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $oldValue = $request->getBody()->getContents(); $value = $command[$param->getName()]; $value = $param->getName() . '=' . $param->filter($value); if ($oldValue !== '') { $value = $oldValue . '&' . $value; } return $request->withBody(Psr7\stream_for($value)); }
php
public function visit( CommandInterface $command, RequestInterface $request, Parameter $param ) { $oldValue = $request->getBody()->getContents(); $value = $command[$param->getName()]; $value = $param->getName() . '=' . $param->filter($value); if ($oldValue !== '') { $value = $oldValue . '&' . $value; } return $request->withBody(Psr7\stream_for($value)); }
[ "public", "function", "visit", "(", "CommandInterface", "$", "command", ",", "RequestInterface", "$", "request", ",", "Parameter", "$", "param", ")", "{", "$", "oldValue", "=", "$", "request", "->", "getBody", "(", ")", "->", "getContents", "(", ")", ";", "$", "value", "=", "$", "command", "[", "$", "param", "->", "getName", "(", ")", "]", ";", "$", "value", "=", "$", "param", "->", "getName", "(", ")", ".", "'='", ".", "$", "param", "->", "filter", "(", "$", "value", ")", ";", "if", "(", "$", "oldValue", "!==", "''", ")", "{", "$", "value", "=", "$", "oldValue", ".", "'&'", ".", "$", "value", ";", "}", "return", "$", "request", "->", "withBody", "(", "Psr7", "\\", "stream_for", "(", "$", "value", ")", ")", ";", "}" ]
@param CommandInterface $command @param RequestInterface $request @param Parameter $param @return MessageInterface
[ "@param", "CommandInterface", "$command", "@param", "RequestInterface", "$request", "@param", "Parameter", "$param" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/RequestLocation/BodyLocation.php#L33-L48
guzzle/guzzle-services
src/Parameter.php
Parameter.filter
public function filter($value) { // Formats are applied exclusively and supersed filters if ($this->format) { if (!$this->serviceDescription) { throw new \RuntimeException('No service description was set so ' . 'the value cannot be formatted.'); } return $this->serviceDescription->format($this->format, $value); } // Convert Boolean values if ($this->type == 'boolean' && !is_bool($value)) { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); } // Apply filters to the value if ($this->filters) { foreach ($this->filters as $filter) { if (is_array($filter)) { // Convert complex filters that hold value place holders foreach ($filter['args'] as &$data) { if ($data == '@value') { $data = $value; } elseif ($data == '@api') { $data = $this; } } $value = call_user_func_array( $filter['method'], $filter['args'] ); } else { $value = call_user_func($filter, $value); } } } return $value; }
php
public function filter($value) { // Formats are applied exclusively and supersed filters if ($this->format) { if (!$this->serviceDescription) { throw new \RuntimeException('No service description was set so ' . 'the value cannot be formatted.'); } return $this->serviceDescription->format($this->format, $value); } // Convert Boolean values if ($this->type == 'boolean' && !is_bool($value)) { $value = filter_var($value, FILTER_VALIDATE_BOOLEAN); } // Apply filters to the value if ($this->filters) { foreach ($this->filters as $filter) { if (is_array($filter)) { // Convert complex filters that hold value place holders foreach ($filter['args'] as &$data) { if ($data == '@value') { $data = $value; } elseif ($data == '@api') { $data = $this; } } $value = call_user_func_array( $filter['method'], $filter['args'] ); } else { $value = call_user_func($filter, $value); } } } return $value; }
[ "public", "function", "filter", "(", "$", "value", ")", "{", "// Formats are applied exclusively and supersed filters", "if", "(", "$", "this", "->", "format", ")", "{", "if", "(", "!", "$", "this", "->", "serviceDescription", ")", "{", "throw", "new", "\\", "RuntimeException", "(", "'No service description was set so '", ".", "'the value cannot be formatted.'", ")", ";", "}", "return", "$", "this", "->", "serviceDescription", "->", "format", "(", "$", "this", "->", "format", ",", "$", "value", ")", ";", "}", "// Convert Boolean values", "if", "(", "$", "this", "->", "type", "==", "'boolean'", "&&", "!", "is_bool", "(", "$", "value", ")", ")", "{", "$", "value", "=", "filter_var", "(", "$", "value", ",", "FILTER_VALIDATE_BOOLEAN", ")", ";", "}", "// Apply filters to the value", "if", "(", "$", "this", "->", "filters", ")", "{", "foreach", "(", "$", "this", "->", "filters", "as", "$", "filter", ")", "{", "if", "(", "is_array", "(", "$", "filter", ")", ")", "{", "// Convert complex filters that hold value place holders", "foreach", "(", "$", "filter", "[", "'args'", "]", "as", "&", "$", "data", ")", "{", "if", "(", "$", "data", "==", "'@value'", ")", "{", "$", "data", "=", "$", "value", ";", "}", "elseif", "(", "$", "data", "==", "'@api'", ")", "{", "$", "data", "=", "$", "this", ";", "}", "}", "$", "value", "=", "call_user_func_array", "(", "$", "filter", "[", "'method'", "]", ",", "$", "filter", "[", "'args'", "]", ")", ";", "}", "else", "{", "$", "value", "=", "call_user_func", "(", "$", "filter", ",", "$", "value", ")", ";", "}", "}", "}", "return", "$", "value", ";", "}" ]
Run a value through the filters OR format attribute associated with the parameter. @param mixed $value Value to filter @return mixed Returns the filtered value @throws \RuntimeException when trying to format when no service description is available.
[ "Run", "a", "value", "through", "the", "filters", "OR", "format", "attribute", "associated", "with", "the", "parameter", "." ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Parameter.php#L258-L297
guzzle/guzzle-services
src/Parameter.php
Parameter.getProperties
public function getProperties() { if (!$this->propertiesCache) { $this->propertiesCache = []; foreach (array_keys($this->properties) as $name) { $this->propertiesCache[$name] = $this->getProperty($name); } } return $this->propertiesCache; }
php
public function getProperties() { if (!$this->propertiesCache) { $this->propertiesCache = []; foreach (array_keys($this->properties) as $name) { $this->propertiesCache[$name] = $this->getProperty($name); } } return $this->propertiesCache; }
[ "public", "function", "getProperties", "(", ")", "{", "if", "(", "!", "$", "this", "->", "propertiesCache", ")", "{", "$", "this", "->", "propertiesCache", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "this", "->", "properties", ")", "as", "$", "name", ")", "{", "$", "this", "->", "propertiesCache", "[", "$", "name", "]", "=", "$", "this", "->", "getProperty", "(", "$", "name", ")", ";", "}", "}", "return", "$", "this", "->", "propertiesCache", ";", "}" ]
Get the properties of the parameter @return Parameter[]
[ "Get", "the", "properties", "of", "the", "parameter" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Parameter.php#L498-L508
guzzle/guzzle-services
src/Parameter.php
Parameter.getAdditionalProperties
public function getAdditionalProperties() { if (is_array($this->additionalProperties)) { $this->additionalProperties = new static( $this->additionalProperties, ['description' => $this->serviceDescription] ); } return $this->additionalProperties; }
php
public function getAdditionalProperties() { if (is_array($this->additionalProperties)) { $this->additionalProperties = new static( $this->additionalProperties, ['description' => $this->serviceDescription] ); } return $this->additionalProperties; }
[ "public", "function", "getAdditionalProperties", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "additionalProperties", ")", ")", "{", "$", "this", "->", "additionalProperties", "=", "new", "static", "(", "$", "this", "->", "additionalProperties", ",", "[", "'description'", "=>", "$", "this", "->", "serviceDescription", "]", ")", ";", "}", "return", "$", "this", "->", "additionalProperties", ";", "}" ]
Get the additionalProperties value of the parameter @return bool|Parameter|null
[ "Get", "the", "additionalProperties", "value", "of", "the", "parameter" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Parameter.php#L539-L549
guzzle/guzzle-services
src/Parameter.php
Parameter.addFilter
private function addFilter($filter) { if (is_array($filter)) { if (!isset($filter['method'])) { throw new \InvalidArgumentException( 'A [method] value must be specified for each complex filter' ); } } if (!$this->filters) { $this->filters = [$filter]; } else { $this->filters[] = $filter; } return $this; }
php
private function addFilter($filter) { if (is_array($filter)) { if (!isset($filter['method'])) { throw new \InvalidArgumentException( 'A [method] value must be specified for each complex filter' ); } } if (!$this->filters) { $this->filters = [$filter]; } else { $this->filters[] = $filter; } return $this; }
[ "private", "function", "addFilter", "(", "$", "filter", ")", "{", "if", "(", "is_array", "(", "$", "filter", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "filter", "[", "'method'", "]", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'A [method] value must be specified for each complex filter'", ")", ";", "}", "}", "if", "(", "!", "$", "this", "->", "filters", ")", "{", "$", "this", "->", "filters", "=", "[", "$", "filter", "]", ";", "}", "else", "{", "$", "this", "->", "filters", "[", "]", "=", "$", "filter", ";", "}", "return", "$", "this", ";", "}" ]
Add a filter to the parameter @param string|array $filter Method to filter the value through @return self @throws \InvalidArgumentException
[ "Add", "a", "filter", "to", "the", "parameter" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Parameter.php#L623-L640
guzzle/guzzle-services
src/Parameter.php
Parameter.has
public function has($var) { if (!is_string($var)) { throw new \InvalidArgumentException('Expected a string. Got: ' . (is_object($var) ? get_class($var) : gettype($var))); } return isset($this->{$var}) && !empty($this->{$var}); }
php
public function has($var) { if (!is_string($var)) { throw new \InvalidArgumentException('Expected a string. Got: ' . (is_object($var) ? get_class($var) : gettype($var))); } return isset($this->{$var}) && !empty($this->{$var}); }
[ "public", "function", "has", "(", "$", "var", ")", "{", "if", "(", "!", "is_string", "(", "$", "var", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "'Expected a string. Got: '", ".", "(", "is_object", "(", "$", "var", ")", "?", "get_class", "(", "$", "var", ")", ":", "gettype", "(", "$", "var", ")", ")", ")", ";", "}", "return", "isset", "(", "$", "this", "->", "{", "$", "var", "}", ")", "&&", "!", "empty", "(", "$", "this", "->", "{", "$", "var", "}", ")", ";", "}" ]
Check if a parameter has a specific variable and if it set. @param string $var @return bool
[ "Check", "if", "a", "parameter", "has", "a", "specific", "variable", "and", "if", "it", "set", "." ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Parameter.php#L648-L654
guzzle/guzzle-services
src/ResponseLocation/XmlLocation.php
XmlLocation.recursiveProcess
private function recursiveProcess( Parameter $param, \SimpleXMLElement $node ) { $result = []; $type = $param->getType(); if ($type == 'object') { $result = $this->processObject($param, $node); } elseif ($type == 'array') { $result = $this->processArray($param, $node); } else { // We are probably handling a flat data node (i.e. string or // integer), so let's check if it's childless, which indicates a // node containing plain text. if ($node->children()->count() == 0) { // Retrieve text from node $result = (string) $node; } } // Filter out the value if (isset($result)) { $result = $param->filter($result); } return $result; }
php
private function recursiveProcess( Parameter $param, \SimpleXMLElement $node ) { $result = []; $type = $param->getType(); if ($type == 'object') { $result = $this->processObject($param, $node); } elseif ($type == 'array') { $result = $this->processArray($param, $node); } else { // We are probably handling a flat data node (i.e. string or // integer), so let's check if it's childless, which indicates a // node containing plain text. if ($node->children()->count() == 0) { // Retrieve text from node $result = (string) $node; } } // Filter out the value if (isset($result)) { $result = $param->filter($result); } return $result; }
[ "private", "function", "recursiveProcess", "(", "Parameter", "$", "param", ",", "\\", "SimpleXMLElement", "$", "node", ")", "{", "$", "result", "=", "[", "]", ";", "$", "type", "=", "$", "param", "->", "getType", "(", ")", ";", "if", "(", "$", "type", "==", "'object'", ")", "{", "$", "result", "=", "$", "this", "->", "processObject", "(", "$", "param", ",", "$", "node", ")", ";", "}", "elseif", "(", "$", "type", "==", "'array'", ")", "{", "$", "result", "=", "$", "this", "->", "processArray", "(", "$", "param", ",", "$", "node", ")", ";", "}", "else", "{", "// We are probably handling a flat data node (i.e. string or", "// integer), so let's check if it's childless, which indicates a", "// node containing plain text.", "if", "(", "$", "node", "->", "children", "(", ")", "->", "count", "(", ")", "==", "0", ")", "{", "// Retrieve text from node", "$", "result", "=", "(", "string", ")", "$", "node", ";", "}", "}", "// Filter out the value", "if", "(", "isset", "(", "$", "result", ")", ")", "{", "$", "result", "=", "$", "param", "->", "filter", "(", "$", "result", ")", ";", "}", "return", "$", "result", ";", "}" ]
Recursively process a parameter while applying filters @param Parameter $param API parameter being processed @param \SimpleXMLElement $node Node being processed @return array
[ "Recursively", "process", "a", "parameter", "while", "applying", "filters" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/ResponseLocation/XmlLocation.php#L105-L132
guzzle/guzzle-services
src/ResponseLocation/XmlLocation.php
XmlLocation.xmlToArray
private static function xmlToArray( \SimpleXMLElement $xml, $ns = null, $nesting = 0 ) { $result = []; $children = $xml->children($ns, true); foreach ($children as $name => $child) { $attributes = (array) $child->attributes($ns, true); if (!isset($result[$name])) { $childArray = self::xmlToArray($child, $ns, $nesting + 1); $result[$name] = $attributes ? array_merge($attributes, $childArray) : $childArray; continue; } // A child element with this name exists so we're assuming // that the node contains a list of elements if (!is_array($result[$name])) { $result[$name] = [$result[$name]]; } elseif (!isset($result[$name][0])) { // Convert the first child into the first element of a numerically indexed array $firstResult = $result[$name]; $result[$name] = []; $result[$name][] = $firstResult; } $childArray = self::xmlToArray($child, $ns, $nesting + 1); if ($attributes) { $result[$name][] = array_merge($attributes, $childArray); } else { $result[$name][] = $childArray; } } // Extract text from node $text = trim((string) $xml); if ($text === '') { $text = null; } // Process attributes $attributes = (array) $xml->attributes($ns, true); if ($attributes) { if ($text !== null) { $result['value'] = $text; } $result = array_merge($attributes, $result); } elseif ($text !== null) { $result = $text; } // Make sure we're always returning an array if ($nesting == 0 && !is_array($result)) { $result = [$result]; } return $result; }
php
private static function xmlToArray( \SimpleXMLElement $xml, $ns = null, $nesting = 0 ) { $result = []; $children = $xml->children($ns, true); foreach ($children as $name => $child) { $attributes = (array) $child->attributes($ns, true); if (!isset($result[$name])) { $childArray = self::xmlToArray($child, $ns, $nesting + 1); $result[$name] = $attributes ? array_merge($attributes, $childArray) : $childArray; continue; } // A child element with this name exists so we're assuming // that the node contains a list of elements if (!is_array($result[$name])) { $result[$name] = [$result[$name]]; } elseif (!isset($result[$name][0])) { // Convert the first child into the first element of a numerically indexed array $firstResult = $result[$name]; $result[$name] = []; $result[$name][] = $firstResult; } $childArray = self::xmlToArray($child, $ns, $nesting + 1); if ($attributes) { $result[$name][] = array_merge($attributes, $childArray); } else { $result[$name][] = $childArray; } } // Extract text from node $text = trim((string) $xml); if ($text === '') { $text = null; } // Process attributes $attributes = (array) $xml->attributes($ns, true); if ($attributes) { if ($text !== null) { $result['value'] = $text; } $result = array_merge($attributes, $result); } elseif ($text !== null) { $result = $text; } // Make sure we're always returning an array if ($nesting == 0 && !is_array($result)) { $result = [$result]; } return $result; }
[ "private", "static", "function", "xmlToArray", "(", "\\", "SimpleXMLElement", "$", "xml", ",", "$", "ns", "=", "null", ",", "$", "nesting", "=", "0", ")", "{", "$", "result", "=", "[", "]", ";", "$", "children", "=", "$", "xml", "->", "children", "(", "$", "ns", ",", "true", ")", ";", "foreach", "(", "$", "children", "as", "$", "name", "=>", "$", "child", ")", "{", "$", "attributes", "=", "(", "array", ")", "$", "child", "->", "attributes", "(", "$", "ns", ",", "true", ")", ";", "if", "(", "!", "isset", "(", "$", "result", "[", "$", "name", "]", ")", ")", "{", "$", "childArray", "=", "self", "::", "xmlToArray", "(", "$", "child", ",", "$", "ns", ",", "$", "nesting", "+", "1", ")", ";", "$", "result", "[", "$", "name", "]", "=", "$", "attributes", "?", "array_merge", "(", "$", "attributes", ",", "$", "childArray", ")", ":", "$", "childArray", ";", "continue", ";", "}", "// A child element with this name exists so we're assuming", "// that the node contains a list of elements", "if", "(", "!", "is_array", "(", "$", "result", "[", "$", "name", "]", ")", ")", "{", "$", "result", "[", "$", "name", "]", "=", "[", "$", "result", "[", "$", "name", "]", "]", ";", "}", "elseif", "(", "!", "isset", "(", "$", "result", "[", "$", "name", "]", "[", "0", "]", ")", ")", "{", "// Convert the first child into the first element of a numerically indexed array", "$", "firstResult", "=", "$", "result", "[", "$", "name", "]", ";", "$", "result", "[", "$", "name", "]", "=", "[", "]", ";", "$", "result", "[", "$", "name", "]", "[", "]", "=", "$", "firstResult", ";", "}", "$", "childArray", "=", "self", "::", "xmlToArray", "(", "$", "child", ",", "$", "ns", ",", "$", "nesting", "+", "1", ")", ";", "if", "(", "$", "attributes", ")", "{", "$", "result", "[", "$", "name", "]", "[", "]", "=", "array_merge", "(", "$", "attributes", ",", "$", "childArray", ")", ";", "}", "else", "{", "$", "result", "[", "$", "name", "]", "[", "]", "=", "$", "childArray", ";", "}", "}", "// Extract text from node", "$", "text", "=", "trim", "(", "(", "string", ")", "$", "xml", ")", ";", "if", "(", "$", "text", "===", "''", ")", "{", "$", "text", "=", "null", ";", "}", "// Process attributes", "$", "attributes", "=", "(", "array", ")", "$", "xml", "->", "attributes", "(", "$", "ns", ",", "true", ")", ";", "if", "(", "$", "attributes", ")", "{", "if", "(", "$", "text", "!==", "null", ")", "{", "$", "result", "[", "'value'", "]", "=", "$", "text", ";", "}", "$", "result", "=", "array_merge", "(", "$", "attributes", ",", "$", "result", ")", ";", "}", "elseif", "(", "$", "text", "!==", "null", ")", "{", "$", "result", "=", "$", "text", ";", "}", "// Make sure we're always returning an array", "if", "(", "$", "nesting", "==", "0", "&&", "!", "is_array", "(", "$", "result", ")", ")", "{", "$", "result", "=", "[", "$", "result", "]", ";", "}", "return", "$", "result", ";", "}" ]
Convert an XML document to an array. @param \SimpleXMLElement $xml @param int $nesting @param null $ns @return array
[ "Convert", "an", "XML", "document", "to", "an", "array", "." ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/ResponseLocation/XmlLocation.php#L252-L310
guzzle/guzzle-services
src/Description.php
Description.getOperation
public function getOperation($name) { if (!$this->hasOperation($name)) { throw new \InvalidArgumentException("No operation found named $name"); } // Lazily create operations as they are retrieved if (!($this->operations[$name] instanceof Operation)) { $this->operations[$name]['name'] = $name; $this->operations[$name] = new Operation($this->operations[$name], $this); } return $this->operations[$name]; }
php
public function getOperation($name) { if (!$this->hasOperation($name)) { throw new \InvalidArgumentException("No operation found named $name"); } // Lazily create operations as they are retrieved if (!($this->operations[$name] instanceof Operation)) { $this->operations[$name]['name'] = $name; $this->operations[$name] = new Operation($this->operations[$name], $this); } return $this->operations[$name]; }
[ "public", "function", "getOperation", "(", "$", "name", ")", "{", "if", "(", "!", "$", "this", "->", "hasOperation", "(", "$", "name", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"No operation found named $name\"", ")", ";", "}", "// Lazily create operations as they are retrieved", "if", "(", "!", "(", "$", "this", "->", "operations", "[", "$", "name", "]", "instanceof", "Operation", ")", ")", "{", "$", "this", "->", "operations", "[", "$", "name", "]", "[", "'name'", "]", "=", "$", "name", ";", "$", "this", "->", "operations", "[", "$", "name", "]", "=", "new", "Operation", "(", "$", "this", "->", "operations", "[", "$", "name", "]", ",", "$", "this", ")", ";", "}", "return", "$", "this", "->", "operations", "[", "$", "name", "]", ";", "}" ]
Get an API operation by name @param string $name Name of the command @return Operation @throws \InvalidArgumentException if the operation is not found
[ "Get", "an", "API", "operation", "by", "name" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Description.php#L137-L150
guzzle/guzzle-services
src/Description.php
Description.getModel
public function getModel($id) { if (!$this->hasModel($id)) { throw new \InvalidArgumentException("No model found named $id"); } // Lazily create models as they are retrieved if (!($this->models[$id] instanceof Parameter)) { $this->models[$id] = new Parameter( $this->models[$id], ['description' => $this] ); } return $this->models[$id]; }
php
public function getModel($id) { if (!$this->hasModel($id)) { throw new \InvalidArgumentException("No model found named $id"); } // Lazily create models as they are retrieved if (!($this->models[$id] instanceof Parameter)) { $this->models[$id] = new Parameter( $this->models[$id], ['description' => $this] ); } return $this->models[$id]; }
[ "public", "function", "getModel", "(", "$", "id", ")", "{", "if", "(", "!", "$", "this", "->", "hasModel", "(", "$", "id", ")", ")", "{", "throw", "new", "\\", "InvalidArgumentException", "(", "\"No model found named $id\"", ")", ";", "}", "// Lazily create models as they are retrieved", "if", "(", "!", "(", "$", "this", "->", "models", "[", "$", "id", "]", "instanceof", "Parameter", ")", ")", "{", "$", "this", "->", "models", "[", "$", "id", "]", "=", "new", "Parameter", "(", "$", "this", "->", "models", "[", "$", "id", "]", ",", "[", "'description'", "=>", "$", "this", "]", ")", ";", "}", "return", "$", "this", "->", "models", "[", "$", "id", "]", ";", "}" ]
Get a shared definition structure. @param string $id ID/name of the model to retrieve @return Parameter @throws \InvalidArgumentException if the model is not found
[ "Get", "a", "shared", "definition", "structure", "." ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Description.php#L160-L175
guzzle/guzzle-services
src/Description.php
Description.getModels
public function getModels() { $models = []; foreach ($this->models as $name => $model) { $models[$name] = $this->getModel($name); } return $models; }
php
public function getModels() { $models = []; foreach ($this->models as $name => $model) { $models[$name] = $this->getModel($name); } return $models; }
[ "public", "function", "getModels", "(", ")", "{", "$", "models", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "models", "as", "$", "name", "=>", "$", "model", ")", "{", "$", "models", "[", "$", "name", "]", "=", "$", "this", "->", "getModel", "(", "$", "name", ")", ";", "}", "return", "$", "models", ";", "}" ]
Get all models of the service description. @return array
[ "Get", "all", "models", "of", "the", "service", "description", "." ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Description.php#L182-L190
guzzle/guzzle-services
src/Description.php
Description.getData
public function getData($key = null) { if ($key === null) { return $this->extraData; } elseif (isset($this->extraData[$key])) { return $this->extraData[$key]; } else { return null; } }
php
public function getData($key = null) { if ($key === null) { return $this->extraData; } elseif (isset($this->extraData[$key])) { return $this->extraData[$key]; } else { return null; } }
[ "public", "function", "getData", "(", "$", "key", "=", "null", ")", "{", "if", "(", "$", "key", "===", "null", ")", "{", "return", "$", "this", "->", "extraData", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "extraData", "[", "$", "key", "]", ")", ")", "{", "return", "$", "this", "->", "extraData", "[", "$", "key", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Get arbitrary data from the service description that is not part of the Guzzle service description specification. @param string $key Data key to retrieve or null to retrieve all extra @return null|mixed
[ "Get", "arbitrary", "data", "from", "the", "service", "description", "that", "is", "not", "part", "of", "the", "Guzzle", "service", "description", "specification", "." ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/Description.php#L255-L264
guzzle/guzzle-services
src/SchemaFormatter.php
SchemaFormatter.format
public function format($format, $value) { switch ($format) { case 'date-time': return $this->formatDateTime($value); case 'date-time-http': return $this->formatDateTimeHttp($value); case 'date': return $this->formatDate($value); case 'time': return $this->formatTime($value); case 'timestamp': return $this->formatTimestamp($value); case 'boolean-string': return $this->formatBooleanAsString($value); default: return $value; } }
php
public function format($format, $value) { switch ($format) { case 'date-time': return $this->formatDateTime($value); case 'date-time-http': return $this->formatDateTimeHttp($value); case 'date': return $this->formatDate($value); case 'time': return $this->formatTime($value); case 'timestamp': return $this->formatTimestamp($value); case 'boolean-string': return $this->formatBooleanAsString($value); default: return $value; } }
[ "public", "function", "format", "(", "$", "format", ",", "$", "value", ")", "{", "switch", "(", "$", "format", ")", "{", "case", "'date-time'", ":", "return", "$", "this", "->", "formatDateTime", "(", "$", "value", ")", ";", "case", "'date-time-http'", ":", "return", "$", "this", "->", "formatDateTimeHttp", "(", "$", "value", ")", ";", "case", "'date'", ":", "return", "$", "this", "->", "formatDate", "(", "$", "value", ")", ";", "case", "'time'", ":", "return", "$", "this", "->", "formatTime", "(", "$", "value", ")", ";", "case", "'timestamp'", ":", "return", "$", "this", "->", "formatTimestamp", "(", "$", "value", ")", ";", "case", "'boolean-string'", ":", "return", "$", "this", "->", "formatBooleanAsString", "(", "$", "value", ")", ";", "default", ":", "return", "$", "value", ";", "}", "}" ]
Format a value by a registered format name @param string $format Registered format used to format the value @param mixed $value Value being formatted @return mixed
[ "Format", "a", "value", "by", "a", "registered", "format", "name" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/SchemaFormatter.php#L17-L35
guzzle/guzzle-services
src/SchemaFormatter.php
SchemaFormatter.dateFormatter
protected function dateFormatter($dateTime, $format) { if (is_numeric($dateTime)) { return gmdate($format, (int) $dateTime); } if (is_string($dateTime)) { $dateTime = new \DateTime($dateTime); } if ($dateTime instanceof \DateTimeInterface) { static $utc; if (!$utc) { $utc = new \DateTimeZone('UTC'); } return $dateTime->setTimezone($utc)->format($format); } throw new \InvalidArgumentException('Date/Time values must be either ' . 'be a string, integer, or DateTime object'); }
php
protected function dateFormatter($dateTime, $format) { if (is_numeric($dateTime)) { return gmdate($format, (int) $dateTime); } if (is_string($dateTime)) { $dateTime = new \DateTime($dateTime); } if ($dateTime instanceof \DateTimeInterface) { static $utc; if (!$utc) { $utc = new \DateTimeZone('UTC'); } return $dateTime->setTimezone($utc)->format($format); } throw new \InvalidArgumentException('Date/Time values must be either ' . 'be a string, integer, or DateTime object'); }
[ "protected", "function", "dateFormatter", "(", "$", "dateTime", ",", "$", "format", ")", "{", "if", "(", "is_numeric", "(", "$", "dateTime", ")", ")", "{", "return", "gmdate", "(", "$", "format", ",", "(", "int", ")", "$", "dateTime", ")", ";", "}", "if", "(", "is_string", "(", "$", "dateTime", ")", ")", "{", "$", "dateTime", "=", "new", "\\", "DateTime", "(", "$", "dateTime", ")", ";", "}", "if", "(", "$", "dateTime", "instanceof", "\\", "DateTimeInterface", ")", "{", "static", "$", "utc", ";", "if", "(", "!", "$", "utc", ")", "{", "$", "utc", "=", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ";", "}", "return", "$", "dateTime", "->", "setTimezone", "(", "$", "utc", ")", "->", "format", "(", "$", "format", ")", ";", "}", "throw", "new", "\\", "InvalidArgumentException", "(", "'Date/Time values must be either '", ".", "'be a string, integer, or DateTime object'", ")", ";", "}" ]
Perform the actual DateTime formatting @param int|string|\DateTime $dateTime Date time value @param string $format Format of the result @return string @throws \InvalidArgumentException
[ "Perform", "the", "actual", "DateTime", "formatting" ]
train
https://github.com/guzzle/guzzle-services/blob/9e3abf20161cbf662d616cbb995f2811771759f7/src/SchemaFormatter.php#L46-L66
goodby/csv
src/Goodby/CSV/Export/Standard/Exporter.php
Exporter.export
public function export($filename, $rows) { $delimiter = $this->config->getDelimiter(); $enclosure = $this->config->getEnclosure(); $enclosure = empty($enclosure) ? "\0" : $enclosure; $newline = $this->config->getNewline(); $fromCharset = $this->config->getFromCharset(); $toCharset = $this->config->getToCharset(); $fileMode = $this->config->getFileMode(); $columnHeaders = $this->config->getColumnHeaders(); try { $csv = new CsvFileObject($filename, $fileMode); } catch ( \Exception $e ) { throw new IOException($e->getMessage(), null, $e); } $csv->setNewline($newline); if ( $toCharset ) { $csv->setCsvFilter(function($line) use($toCharset, $fromCharset) { return mb_convert_encoding($line, $toCharset, $fromCharset); }); } if (count($columnHeaders) > 0) { $this->checkRowConsistency($columnHeaders); $csv->fputcsv($columnHeaders, $delimiter, $enclosure); } foreach ( $rows as $row ) { $this->checkRowConsistency($row); $csv->fputcsv($row, $delimiter, $enclosure); } $csv->fflush(); }
php
public function export($filename, $rows) { $delimiter = $this->config->getDelimiter(); $enclosure = $this->config->getEnclosure(); $enclosure = empty($enclosure) ? "\0" : $enclosure; $newline = $this->config->getNewline(); $fromCharset = $this->config->getFromCharset(); $toCharset = $this->config->getToCharset(); $fileMode = $this->config->getFileMode(); $columnHeaders = $this->config->getColumnHeaders(); try { $csv = new CsvFileObject($filename, $fileMode); } catch ( \Exception $e ) { throw new IOException($e->getMessage(), null, $e); } $csv->setNewline($newline); if ( $toCharset ) { $csv->setCsvFilter(function($line) use($toCharset, $fromCharset) { return mb_convert_encoding($line, $toCharset, $fromCharset); }); } if (count($columnHeaders) > 0) { $this->checkRowConsistency($columnHeaders); $csv->fputcsv($columnHeaders, $delimiter, $enclosure); } foreach ( $rows as $row ) { $this->checkRowConsistency($row); $csv->fputcsv($row, $delimiter, $enclosure); } $csv->fflush(); }
[ "public", "function", "export", "(", "$", "filename", ",", "$", "rows", ")", "{", "$", "delimiter", "=", "$", "this", "->", "config", "->", "getDelimiter", "(", ")", ";", "$", "enclosure", "=", "$", "this", "->", "config", "->", "getEnclosure", "(", ")", ";", "$", "enclosure", "=", "empty", "(", "$", "enclosure", ")", "?", "\"\\0\"", ":", "$", "enclosure", ";", "$", "newline", "=", "$", "this", "->", "config", "->", "getNewline", "(", ")", ";", "$", "fromCharset", "=", "$", "this", "->", "config", "->", "getFromCharset", "(", ")", ";", "$", "toCharset", "=", "$", "this", "->", "config", "->", "getToCharset", "(", ")", ";", "$", "fileMode", "=", "$", "this", "->", "config", "->", "getFileMode", "(", ")", ";", "$", "columnHeaders", "=", "$", "this", "->", "config", "->", "getColumnHeaders", "(", ")", ";", "try", "{", "$", "csv", "=", "new", "CsvFileObject", "(", "$", "filename", ",", "$", "fileMode", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "IOException", "(", "$", "e", "->", "getMessage", "(", ")", ",", "null", ",", "$", "e", ")", ";", "}", "$", "csv", "->", "setNewline", "(", "$", "newline", ")", ";", "if", "(", "$", "toCharset", ")", "{", "$", "csv", "->", "setCsvFilter", "(", "function", "(", "$", "line", ")", "use", "(", "$", "toCharset", ",", "$", "fromCharset", ")", "{", "return", "mb_convert_encoding", "(", "$", "line", ",", "$", "toCharset", ",", "$", "fromCharset", ")", ";", "}", ")", ";", "}", "if", "(", "count", "(", "$", "columnHeaders", ")", ">", "0", ")", "{", "$", "this", "->", "checkRowConsistency", "(", "$", "columnHeaders", ")", ";", "$", "csv", "->", "fputcsv", "(", "$", "columnHeaders", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "$", "this", "->", "checkRowConsistency", "(", "$", "row", ")", ";", "$", "csv", "->", "fputcsv", "(", "$", "row", ",", "$", "delimiter", ",", "$", "enclosure", ")", ";", "}", "$", "csv", "->", "fflush", "(", ")", ";", "}" ]
{@inherit} @throws StrictViolationException
[ "{" ]
train
https://github.com/goodby/csv/blob/079ac7bcd7a55a01a1f7c62cecc0c50497530905/src/Goodby/CSV/Export/Standard/Exporter.php#L50-L85
goodby/csv
src/Goodby/CSV/Export/Standard/Exporter.php
Exporter.checkRowConsistency
private function checkRowConsistency($row) { if ( $this->strict === false ) { return; } $current = count($row); if ( $this->rowConsistency === null ) { $this->rowConsistency = $current; } if ( $current !== $this->rowConsistency ) { throw new StrictViolationException(); } $this->rowConsistency = $current; }
php
private function checkRowConsistency($row) { if ( $this->strict === false ) { return; } $current = count($row); if ( $this->rowConsistency === null ) { $this->rowConsistency = $current; } if ( $current !== $this->rowConsistency ) { throw new StrictViolationException(); } $this->rowConsistency = $current; }
[ "private", "function", "checkRowConsistency", "(", "$", "row", ")", "{", "if", "(", "$", "this", "->", "strict", "===", "false", ")", "{", "return", ";", "}", "$", "current", "=", "count", "(", "$", "row", ")", ";", "if", "(", "$", "this", "->", "rowConsistency", "===", "null", ")", "{", "$", "this", "->", "rowConsistency", "=", "$", "current", ";", "}", "if", "(", "$", "current", "!==", "$", "this", "->", "rowConsistency", ")", "{", "throw", "new", "StrictViolationException", "(", ")", ";", "}", "$", "this", "->", "rowConsistency", "=", "$", "current", ";", "}" ]
Check if the column count is consistent with comparing other rows @param array|\Countable $row @throws Exception\StrictViolationException
[ "Check", "if", "the", "column", "count", "is", "consistent", "with", "comparing", "other", "rows" ]
train
https://github.com/goodby/csv/blob/079ac7bcd7a55a01a1f7c62cecc0c50497530905/src/Goodby/CSV/Export/Standard/Exporter.php#L92-L109
goodby/csv
src/Goodby/CSV/Export/Standard/CsvFileObject.php
CsvFileObject.fputcsv
public function fputcsv($fields, $delimiter = null, $enclosure = null, $escape = null) { // Temporary output a line to memory to get line as string $fp = fopen('php://temp', 'w+'); $arguments = func_get_args(); array_unshift($arguments, $fp); call_user_func_array('fputcsv', $arguments); rewind($fp); $line = ''; while ( feof($fp) === false ) { $line .= fgets($fp); } fclose($fp); /** * Because the php_fputcsv() implementation in PHP´s source code * has a hardcoded "\n", this method replaces the last LF code * with what the client code wishes. */ $line = rtrim($line, "\n"). $this->newline; // if the enclosure was '' | false if (empty($enclosure)) { $line = str_replace("\0", '', $line); } if ( is_callable($this->csvFilter) ) { $line = call_user_func($this->csvFilter, $line); } return $this->fwrite($line); }
php
public function fputcsv($fields, $delimiter = null, $enclosure = null, $escape = null) { // Temporary output a line to memory to get line as string $fp = fopen('php://temp', 'w+'); $arguments = func_get_args(); array_unshift($arguments, $fp); call_user_func_array('fputcsv', $arguments); rewind($fp); $line = ''; while ( feof($fp) === false ) { $line .= fgets($fp); } fclose($fp); /** * Because the php_fputcsv() implementation in PHP´s source code * has a hardcoded "\n", this method replaces the last LF code * with what the client code wishes. */ $line = rtrim($line, "\n"). $this->newline; // if the enclosure was '' | false if (empty($enclosure)) { $line = str_replace("\0", '', $line); } if ( is_callable($this->csvFilter) ) { $line = call_user_func($this->csvFilter, $line); } return $this->fwrite($line); }
[ "public", "function", "fputcsv", "(", "$", "fields", ",", "$", "delimiter", "=", "null", ",", "$", "enclosure", "=", "null", ",", "$", "escape", "=", "null", ")", "{", "// Temporary output a line to memory to get line as string", "$", "fp", "=", "fopen", "(", "'php://temp'", ",", "'w+'", ")", ";", "$", "arguments", "=", "func_get_args", "(", ")", ";", "array_unshift", "(", "$", "arguments", ",", "$", "fp", ")", ";", "call_user_func_array", "(", "'fputcsv'", ",", "$", "arguments", ")", ";", "rewind", "(", "$", "fp", ")", ";", "$", "line", "=", "''", ";", "while", "(", "feof", "(", "$", "fp", ")", "===", "false", ")", "{", "$", "line", ".=", "fgets", "(", "$", "fp", ")", ";", "}", "fclose", "(", "$", "fp", ")", ";", "/**\n * Because the php_fputcsv() implementation in PHP´s source code\n * has a hardcoded \"\\n\", this method replaces the last LF code\n * with what the client code wishes.\n */", "$", "line", "=", "rtrim", "(", "$", "line", ",", "\"\\n\"", ")", ".", "$", "this", "->", "newline", ";", "// if the enclosure was '' | false", "if", "(", "empty", "(", "$", "enclosure", ")", ")", "{", "$", "line", "=", "str_replace", "(", "\"\\0\"", ",", "''", ",", "$", "line", ")", ";", "}", "if", "(", "is_callable", "(", "$", "this", "->", "csvFilter", ")", ")", "{", "$", "line", "=", "call_user_func", "(", "$", "this", "->", "csvFilter", ",", "$", "line", ")", ";", "}", "return", "$", "this", "->", "fwrite", "(", "$", "line", ")", ";", "}" ]
Write a field array as a CSV line @param array $fields @param string $delimiter @param string $enclosure @param useless $escape THIS PARAM IS UNSED, BUT REQUIRED EXISTS, see https://bugs.php.net/bug.php?id=68479 and https://github.com/goodby/csv/issues/56 @return int|void
[ "Write", "a", "field", "array", "as", "a", "CSV", "line" ]
train
https://github.com/goodby/csv/blob/079ac7bcd7a55a01a1f7c62cecc0c50497530905/src/Goodby/CSV/Export/Standard/CsvFileObject.php#L50-L84
goodby/csv
src/Goodby/CSV/Import/Standard/StreamFilter/ConvertMbstringEncoding.php
ConvertMbstringEncoding.register
public static function register() { if ( self::$hasBeenRegistered === true ) { return; } if ( stream_filter_register(self::getFilterName(), __CLASS__) === false ) { throw new RuntimeException('Failed to register stream filter: '.self::getFilterName()); } self::$hasBeenRegistered = true; }
php
public static function register() { if ( self::$hasBeenRegistered === true ) { return; } if ( stream_filter_register(self::getFilterName(), __CLASS__) === false ) { throw new RuntimeException('Failed to register stream filter: '.self::getFilterName()); } self::$hasBeenRegistered = true; }
[ "public", "static", "function", "register", "(", ")", "{", "if", "(", "self", "::", "$", "hasBeenRegistered", "===", "true", ")", "{", "return", ";", "}", "if", "(", "stream_filter_register", "(", "self", "::", "getFilterName", "(", ")", ",", "__CLASS__", ")", "===", "false", ")", "{", "throw", "new", "RuntimeException", "(", "'Failed to register stream filter: '", ".", "self", "::", "getFilterName", "(", ")", ")", ";", "}", "self", "::", "$", "hasBeenRegistered", "=", "true", ";", "}" ]
Register this class as a stream filter @throws \RuntimeException
[ "Register", "this", "class", "as", "a", "stream", "filter" ]
train
https://github.com/goodby/csv/blob/079ac7bcd7a55a01a1f7c62cecc0c50497530905/src/Goodby/CSV/Import/Standard/StreamFilter/ConvertMbstringEncoding.php#L43-L54
goodby/csv
src/Goodby/CSV/Import/Standard/StreamFilter/ConvertMbstringEncoding.php
ConvertMbstringEncoding.getFilterURL
public static function getFilterURL($filename, $fromCharset, $toCharset = null) { if ( $toCharset === null ) { return sprintf('php://filter/convert.mbstring.encoding.%s/resource=%s', $fromCharset, $filename); } else { return sprintf('php://filter/convert.mbstring.encoding.%s:%s/resource=%s', $fromCharset, $toCharset, $filename); } }
php
public static function getFilterURL($filename, $fromCharset, $toCharset = null) { if ( $toCharset === null ) { return sprintf('php://filter/convert.mbstring.encoding.%s/resource=%s', $fromCharset, $filename); } else { return sprintf('php://filter/convert.mbstring.encoding.%s:%s/resource=%s', $fromCharset, $toCharset, $filename); } }
[ "public", "static", "function", "getFilterURL", "(", "$", "filename", ",", "$", "fromCharset", ",", "$", "toCharset", "=", "null", ")", "{", "if", "(", "$", "toCharset", "===", "null", ")", "{", "return", "sprintf", "(", "'php://filter/convert.mbstring.encoding.%s/resource=%s'", ",", "$", "fromCharset", ",", "$", "filename", ")", ";", "}", "else", "{", "return", "sprintf", "(", "'php://filter/convert.mbstring.encoding.%s:%s/resource=%s'", ",", "$", "fromCharset", ",", "$", "toCharset", ",", "$", "filename", ")", ";", "}", "}" ]
Return filter URL @param string $filename @param string $fromCharset @param string $toCharset @return string
[ "Return", "filter", "URL" ]
train
https://github.com/goodby/csv/blob/079ac7bcd7a55a01a1f7c62cecc0c50497530905/src/Goodby/CSV/Import/Standard/StreamFilter/ConvertMbstringEncoding.php#L63-L70
goodby/csv
src/Goodby/CSV/Import/Standard/Interpreter.php
Interpreter.interpret
public function interpret($line) { $this->checkRowConsistency($line); if (!is_array($line)) { throw new InvalidLexicalException('line is must be array'); } $this->notify($line); }
php
public function interpret($line) { $this->checkRowConsistency($line); if (!is_array($line)) { throw new InvalidLexicalException('line is must be array'); } $this->notify($line); }
[ "public", "function", "interpret", "(", "$", "line", ")", "{", "$", "this", "->", "checkRowConsistency", "(", "$", "line", ")", ";", "if", "(", "!", "is_array", "(", "$", "line", ")", ")", "{", "throw", "new", "InvalidLexicalException", "(", "'line is must be array'", ")", ";", "}", "$", "this", "->", "notify", "(", "$", "line", ")", ";", "}" ]
interpret line @param $line @return void @throws \Goodby\CSV\Import\Protocol\Exception\InvalidLexicalException
[ "interpret", "line" ]
train
https://github.com/goodby/csv/blob/079ac7bcd7a55a01a1f7c62cecc0c50497530905/src/Goodby/CSV/Import/Standard/Interpreter.php#L36-L45
goodby/csv
src/Goodby/CSV/Import/Standard/Interpreter.php
Interpreter.notify
private function notify($line) { $observers = $this->observers; foreach ($observers as $observer) { $this->delegate($observer, $line); } }
php
private function notify($line) { $observers = $this->observers; foreach ($observers as $observer) { $this->delegate($observer, $line); } }
[ "private", "function", "notify", "(", "$", "line", ")", "{", "$", "observers", "=", "$", "this", "->", "observers", ";", "foreach", "(", "$", "observers", "as", "$", "observer", ")", "{", "$", "this", "->", "delegate", "(", "$", "observer", ",", "$", "line", ")", ";", "}", "}" ]
notify to observers @param $line
[ "notify", "to", "observers" ]
train
https://github.com/goodby/csv/blob/079ac7bcd7a55a01a1f7c62cecc0c50497530905/src/Goodby/CSV/Import/Standard/Interpreter.php#L69-L76
mikehaertl/php-tmpfile
src/File.php
File.send
public function send($filename = null, $contentType, $inline = false) { header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: '.$contentType); header('Content-Transfer-Encoding: binary'); // #84: Content-Length leads to "network connection was lost" on iOS $isIOS = preg_match('/i(phone|pad|pod)/i', $_SERVER['HTTP_USER_AGENT']); if (!$isIOS) { header('Content-Length: '.filesize($this->_fileName)); } if ($filename!==null || $inline) { $disposition = $inline ? 'inline' : 'attachment'; header("Content-Disposition: $disposition; filename=\"$filename\""); } readfile($this->_fileName); }
php
public function send($filename = null, $contentType, $inline = false) { header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Type: '.$contentType); header('Content-Transfer-Encoding: binary'); // #84: Content-Length leads to "network connection was lost" on iOS $isIOS = preg_match('/i(phone|pad|pod)/i', $_SERVER['HTTP_USER_AGENT']); if (!$isIOS) { header('Content-Length: '.filesize($this->_fileName)); } if ($filename!==null || $inline) { $disposition = $inline ? 'inline' : 'attachment'; header("Content-Disposition: $disposition; filename=\"$filename\""); } readfile($this->_fileName); }
[ "public", "function", "send", "(", "$", "filename", "=", "null", ",", "$", "contentType", ",", "$", "inline", "=", "false", ")", "{", "header", "(", "'Pragma: public'", ")", ";", "header", "(", "'Expires: 0'", ")", ";", "header", "(", "'Cache-Control: must-revalidate, post-check=0, pre-check=0'", ")", ";", "header", "(", "'Content-Type: '", ".", "$", "contentType", ")", ";", "header", "(", "'Content-Transfer-Encoding: binary'", ")", ";", "// #84: Content-Length leads to \"network connection was lost\" on iOS", "$", "isIOS", "=", "preg_match", "(", "'/i(phone|pad|pod)/i'", ",", "$", "_SERVER", "[", "'HTTP_USER_AGENT'", "]", ")", ";", "if", "(", "!", "$", "isIOS", ")", "{", "header", "(", "'Content-Length: '", ".", "filesize", "(", "$", "this", "->", "_fileName", ")", ")", ";", "}", "if", "(", "$", "filename", "!==", "null", "||", "$", "inline", ")", "{", "$", "disposition", "=", "$", "inline", "?", "'inline'", ":", "'attachment'", ";", "header", "(", "\"Content-Disposition: $disposition; filename=\\\"$filename\\\"\"", ")", ";", "}", "readfile", "(", "$", "this", "->", "_fileName", ")", ";", "}" ]
Send tmp file to client, either inline or as download @param string|null $filename the filename to send. If empty, the file is streamed inline. @param string $contentType the Content-Type header @param bool $inline whether to force inline display of the file, even if filename is present.
[ "Send", "tmp", "file", "to", "client", "either", "inline", "or", "as", "download" ]
train
https://github.com/mikehaertl/php-tmpfile/blob/0ff48ed52ffee46d0f21fc34e8806f15467eb9b1/src/File.php#L70-L90
vgrem/phpSPO
src/Runtime/Auth/OAuthTokenProvider.php
OAuthTokenProvider.acquireToken
public function acquireToken($parameters) { $request = $this->createRequest($parameters); $response = Requests::execute($request); $this->parseToken($response); }
php
public function acquireToken($parameters) { $request = $this->createRequest($parameters); $response = Requests::execute($request); $this->parseToken($response); }
[ "public", "function", "acquireToken", "(", "$", "parameters", ")", "{", "$", "request", "=", "$", "this", "->", "createRequest", "(", "$", "parameters", ")", ";", "$", "response", "=", "Requests", "::", "execute", "(", "$", "request", ")", ";", "$", "this", "->", "parseToken", "(", "$", "response", ")", ";", "}" ]
Acquires the access token @param array $parameters @throws \Exception
[ "Acquires", "the", "access", "token" ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/Runtime/Auth/OAuthTokenProvider.php#L78-L83
vgrem/phpSPO
src/Runtime/Auth/OAuthTokenProvider.php
OAuthTokenProvider.parseToken
private function parseToken($tokenValue) { $tokenPayload = json_decode($tokenValue); if (is_object($tokenPayload)) { $this->accessToken = $tokenPayload; if (isset($tokenPayload->id_token)) { $idToken = $tokenPayload->id_token; $idTokenPayload = base64_decode( explode('.', $idToken)[1] ); $this->accessToken->id_token_info = json_decode($idTokenPayload, true); } } }
php
private function parseToken($tokenValue) { $tokenPayload = json_decode($tokenValue); if (is_object($tokenPayload)) { $this->accessToken = $tokenPayload; if (isset($tokenPayload->id_token)) { $idToken = $tokenPayload->id_token; $idTokenPayload = base64_decode( explode('.', $idToken)[1] ); $this->accessToken->id_token_info = json_decode($idTokenPayload, true); } } }
[ "private", "function", "parseToken", "(", "$", "tokenValue", ")", "{", "$", "tokenPayload", "=", "json_decode", "(", "$", "tokenValue", ")", ";", "if", "(", "is_object", "(", "$", "tokenPayload", ")", ")", "{", "$", "this", "->", "accessToken", "=", "$", "tokenPayload", ";", "if", "(", "isset", "(", "$", "tokenPayload", "->", "id_token", ")", ")", "{", "$", "idToken", "=", "$", "tokenPayload", "->", "id_token", ";", "$", "idTokenPayload", "=", "base64_decode", "(", "explode", "(", "'.'", ",", "$", "idToken", ")", "[", "1", "]", ")", ";", "$", "this", "->", "accessToken", "->", "id_token_info", "=", "json_decode", "(", "$", "idTokenPayload", ",", "true", ")", ";", "}", "}", "}" ]
Parse the id token that represents a JWT token that contains information about the user @param string $tokenValue
[ "Parse", "the", "id", "token", "that", "represents", "a", "JWT", "token", "that", "contains", "information", "about", "the", "user" ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/Runtime/Auth/OAuthTokenProvider.php#L103-L116
vgrem/phpSPO
src/OutlookServices/MessageCollection.php
MessageCollection.createMessage
public function createMessage() { $message = new Message($this->getContext()); $this->addChild($message); $qry = new CreateEntityQuery($message); $this->getContext()->addQuery($qry, $message); return $message; }
php
public function createMessage() { $message = new Message($this->getContext()); $this->addChild($message); $qry = new CreateEntityQuery($message); $this->getContext()->addQuery($qry, $message); return $message; }
[ "public", "function", "createMessage", "(", ")", "{", "$", "message", "=", "new", "Message", "(", "$", "this", "->", "getContext", "(", ")", ")", ";", "$", "this", "->", "addChild", "(", "$", "message", ")", ";", "$", "qry", "=", "new", "CreateEntityQuery", "(", "$", "message", ")", ";", "$", "this", "->", "getContext", "(", ")", "->", "addQuery", "(", "$", "qry", ",", "$", "message", ")", ";", "return", "$", "message", ";", "}" ]
Creates a Draft Message resource @return Message
[ "Creates", "a", "Draft", "Message", "resource" ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/OutlookServices/MessageCollection.php#L17-L23
vgrem/phpSPO
src/OutlookServices/EventCollection.php
EventCollection.createEvent
public function createEvent() { $event = new Event($this->getContext(),null); $this->addChild($event); $qry = new CreateEntityQuery($event); $this->getContext()->addQuery($qry, $event); return $event; }
php
public function createEvent() { $event = new Event($this->getContext(),null); $this->addChild($event); $qry = new CreateEntityQuery($event); $this->getContext()->addQuery($qry, $event); return $event; }
[ "public", "function", "createEvent", "(", ")", "{", "$", "event", "=", "new", "Event", "(", "$", "this", "->", "getContext", "(", ")", ",", "null", ")", ";", "$", "this", "->", "addChild", "(", "$", "event", ")", ";", "$", "qry", "=", "new", "CreateEntityQuery", "(", "$", "event", ")", ";", "$", "this", "->", "getContext", "(", ")", "->", "addQuery", "(", "$", "qry", ",", "$", "event", ")", ";", "return", "$", "event", ";", "}" ]
Create an event in the user's primary calendar or a specific calendar by posting to the calendar's events endpoint. @return Event
[ "Create", "an", "event", "in", "the", "user", "s", "primary", "calendar", "or", "a", "specific", "calendar", "by", "posting", "to", "the", "calendar", "s", "events", "endpoint", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/OutlookServices/EventCollection.php#L15-L21
vgrem/phpSPO
src/SharePoint/SPList.php
SPList.addItem
public function addItem(array $listItemCreationInformation) { $items = new ListItemCollection($this->getContext(), new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"items")); $listItem = new ListItem($this->getContext()); $listItem->parentCollection = $items; $listItem->setProperty('ParentList',$this,false); foreach($listItemCreationInformation as $key => $value){ $listItem->setProperty($key,$value); } $qry = new CreateEntityQuery($listItem); $this->getContext()->addQuery($qry,$listItem); return $listItem; }
php
public function addItem(array $listItemCreationInformation) { $items = new ListItemCollection($this->getContext(), new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"items")); $listItem = new ListItem($this->getContext()); $listItem->parentCollection = $items; $listItem->setProperty('ParentList',$this,false); foreach($listItemCreationInformation as $key => $value){ $listItem->setProperty($key,$value); } $qry = new CreateEntityQuery($listItem); $this->getContext()->addQuery($qry,$listItem); return $listItem; }
[ "public", "function", "addItem", "(", "array", "$", "listItemCreationInformation", ")", "{", "$", "items", "=", "new", "ListItemCollection", "(", "$", "this", "->", "getContext", "(", ")", ",", "new", "ResourcePathEntity", "(", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"items\"", ")", ")", ";", "$", "listItem", "=", "new", "ListItem", "(", "$", "this", "->", "getContext", "(", ")", ")", ";", "$", "listItem", "->", "parentCollection", "=", "$", "items", ";", "$", "listItem", "->", "setProperty", "(", "'ParentList'", ",", "$", "this", ",", "false", ")", ";", "foreach", "(", "$", "listItemCreationInformation", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "listItem", "->", "setProperty", "(", "$", "key", ",", "$", "value", ")", ";", "}", "$", "qry", "=", "new", "CreateEntityQuery", "(", "$", "listItem", ")", ";", "$", "this", "->", "getContext", "(", ")", "->", "addQuery", "(", "$", "qry", ",", "$", "listItem", ")", ";", "return", "$", "listItem", ";", "}" ]
The recommended way to add a list item is to send a POST request to the ListItemCollection resource endpoint, as shown in ListItemCollection request examples. @param array $listItemCreationInformation Creation information for a List item @return ListItem List Item resource
[ "The", "recommended", "way", "to", "add", "a", "list", "item", "is", "to", "send", "a", "POST", "request", "to", "the", "ListItemCollection", "resource", "endpoint", "as", "shown", "in", "ListItemCollection", "request", "examples", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/SPList.php#L22-L35
vgrem/phpSPO
src/SharePoint/SPList.php
SPList.getItemById
public function getItemById($id) { return new ListItem( $this->getContext(), new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"items({$id})") ); }
php
public function getItemById($id) { return new ListItem( $this->getContext(), new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"items({$id})") ); }
[ "public", "function", "getItemById", "(", "$", "id", ")", "{", "return", "new", "ListItem", "(", "$", "this", "->", "getContext", "(", ")", ",", "new", "ResourcePathEntity", "(", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"items({$id})\"", ")", ")", ";", "}" ]
Returns the list item with the specified list item identifier. @param integer $id SPList Item id @return ListItem List Item resource
[ "Returns", "the", "list", "item", "with", "the", "specified", "list", "item", "identifier", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/SPList.php#L42-L48
vgrem/phpSPO
src/SharePoint/SPList.php
SPList.getItems
public function getItems(CamlQuery $camlQuery = null) { $items = new ListItemCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"items")); if(isset($camlQuery)){ $qry = new InvokePostMethodQuery( $this->getResourcePath(), "GetItems", null, $camlQuery ); $this->getContext()->addQuery($qry,$items); } return $items; }
php
public function getItems(CamlQuery $camlQuery = null) { $items = new ListItemCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"items")); if(isset($camlQuery)){ $qry = new InvokePostMethodQuery( $this->getResourcePath(), "GetItems", null, $camlQuery ); $this->getContext()->addQuery($qry,$items); } return $items; }
[ "public", "function", "getItems", "(", "CamlQuery", "$", "camlQuery", "=", "null", ")", "{", "$", "items", "=", "new", "ListItemCollection", "(", "$", "this", "->", "getContext", "(", ")", ",", "new", "ResourcePathEntity", "(", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"items\"", ")", ")", ";", "if", "(", "isset", "(", "$", "camlQuery", ")", ")", "{", "$", "qry", "=", "new", "InvokePostMethodQuery", "(", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"GetItems\"", ",", "null", ",", "$", "camlQuery", ")", ";", "$", "this", "->", "getContext", "(", ")", "->", "addQuery", "(", "$", "qry", ",", "$", "items", ")", ";", "}", "return", "$", "items", ";", "}" ]
Returns a collection of items from the list based on the specified query. @param CamlQuery $camlQuery @return ListItemCollection
[ "Returns", "a", "collection", "of", "items", "from", "the", "list", "based", "on", "the", "specified", "query", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/SPList.php#L56-L69
vgrem/phpSPO
src/SharePoint/SPList.php
SPList.deleteObject
public function deleteObject() { $qry = new DeleteEntityQuery($this); $this->getContext()->addQuery($qry); $this->removeFromParentCollection(); }
php
public function deleteObject() { $qry = new DeleteEntityQuery($this); $this->getContext()->addQuery($qry); $this->removeFromParentCollection(); }
[ "public", "function", "deleteObject", "(", ")", "{", "$", "qry", "=", "new", "DeleteEntityQuery", "(", "$", "this", ")", ";", "$", "this", "->", "getContext", "(", ")", "->", "addQuery", "(", "$", "qry", ")", ";", "$", "this", "->", "removeFromParentCollection", "(", ")", ";", "}" ]
The recommended way to delete a list is to send a DELETE request to the List resource endpoint, as shown in List request examples.
[ "The", "recommended", "way", "to", "delete", "a", "list", "is", "to", "send", "a", "DELETE", "request", "to", "the", "List", "resource", "endpoint", "as", "shown", "in", "List", "request", "examples", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/SPList.php#L84-L89
vgrem/phpSPO
src/SharePoint/SPList.php
SPList.getUserEffectivePermissions
public function getUserEffectivePermissions($loginName) { $permissions = new BasePermissions(); $qry = new InvokeMethodQuery( $this->getResourcePath(), "GetUserEffectivePermissions", array(rawurlencode($loginName)) ); $this->getContext()->addQuery($qry,$permissions); return $permissions; }
php
public function getUserEffectivePermissions($loginName) { $permissions = new BasePermissions(); $qry = new InvokeMethodQuery( $this->getResourcePath(), "GetUserEffectivePermissions", array(rawurlencode($loginName)) ); $this->getContext()->addQuery($qry,$permissions); return $permissions; }
[ "public", "function", "getUserEffectivePermissions", "(", "$", "loginName", ")", "{", "$", "permissions", "=", "new", "BasePermissions", "(", ")", ";", "$", "qry", "=", "new", "InvokeMethodQuery", "(", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"GetUserEffectivePermissions\"", ",", "array", "(", "rawurlencode", "(", "$", "loginName", ")", ")", ")", ";", "$", "this", "->", "getContext", "(", ")", "->", "addQuery", "(", "$", "qry", ",", "$", "permissions", ")", ";", "return", "$", "permissions", ";", "}" ]
Gets the set of permissions for the specified user @param string $loginName @return BasePermissions
[ "Gets", "the", "set", "of", "permissions", "for", "the", "specified", "user" ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/SPList.php#L97-L107
vgrem/phpSPO
src/SharePoint/User.php
User.getGroups
public function getGroups() { if(!$this->isPropertyAvailable('Groups')){ $this->setProperty("Groups", new GroupCollection($this->getContext(), new ResourcePathEntity($this->getContext(),$this->getResourcePath(), "groups"))); } return $this->getProperty("Groups"); }
php
public function getGroups() { if(!$this->isPropertyAvailable('Groups')){ $this->setProperty("Groups", new GroupCollection($this->getContext(), new ResourcePathEntity($this->getContext(),$this->getResourcePath(), "groups"))); } return $this->getProperty("Groups"); }
[ "public", "function", "getGroups", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isPropertyAvailable", "(", "'Groups'", ")", ")", "{", "$", "this", "->", "setProperty", "(", "\"Groups\"", ",", "new", "GroupCollection", "(", "$", "this", "->", "getContext", "(", ")", ",", "new", "ResourcePathEntity", "(", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"groups\"", ")", ")", ")", ";", "}", "return", "$", "this", "->", "getProperty", "(", "\"Groups\"", ")", ";", "}" ]
Gets the collection of groups of which the user is a member. @return GroupCollection
[ "Gets", "the", "collection", "of", "groups", "of", "which", "the", "user", "is", "a", "member", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/User.php#L23-L29
vgrem/phpSPO
src/SharePoint/Web.php
Web.getLists
public function getLists() { if(!$this->isPropertyAvailable('Lists')){ $this->setProperty("Lists", new ListCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"Lists"))); } return $this->getProperty("Lists"); }
php
public function getLists() { if(!$this->isPropertyAvailable('Lists')){ $this->setProperty("Lists", new ListCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"Lists"))); } return $this->getProperty("Lists"); }
[ "public", "function", "getLists", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isPropertyAvailable", "(", "'Lists'", ")", ")", "{", "$", "this", "->", "setProperty", "(", "\"Lists\"", ",", "new", "ListCollection", "(", "$", "this", "->", "getContext", "(", ")", ",", "new", "ResourcePathEntity", "(", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"Lists\"", ")", ")", ")", ";", "}", "return", "$", "this", "->", "getProperty", "(", "\"Lists\"", ")", ";", "}" ]
Gets the collection of all lists that are contained in the Web site available to the current user based on the permissions of the current user. @return ListCollection
[ "Gets", "the", "collection", "of", "all", "lists", "that", "are", "contained", "in", "the", "Web", "site", "available", "to", "the", "current", "user", "based", "on", "the", "permissions", "of", "the", "current", "user", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/Web.php#L114-L120
vgrem/phpSPO
src/SharePoint/Web.php
Web.getWebs
public function getWebs() { if(!$this->isPropertyAvailable('Webs')){ $this->setProperty("Webs", new WebCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"webs"))); } return $this->getProperty("Webs"); }
php
public function getWebs() { if(!$this->isPropertyAvailable('Webs')){ $this->setProperty("Webs", new WebCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"webs"))); } return $this->getProperty("Webs"); }
[ "public", "function", "getWebs", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isPropertyAvailable", "(", "'Webs'", ")", ")", "{", "$", "this", "->", "setProperty", "(", "\"Webs\"", ",", "new", "WebCollection", "(", "$", "this", "->", "getContext", "(", ")", ",", "new", "ResourcePathEntity", "(", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"webs\"", ")", ")", ")", ";", "}", "return", "$", "this", "->", "getProperty", "(", "\"Webs\"", ")", ";", "}" ]
Gets a Web site collection object that represents all Web sites immediately beneath the Web site, excluding children of those Web sites. @return WebCollection
[ "Gets", "a", "Web", "site", "collection", "object", "that", "represents", "all", "Web", "sites", "immediately", "beneath", "the", "Web", "site", "excluding", "children", "of", "those", "Web", "sites", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/Web.php#L127-L133
vgrem/phpSPO
src/SharePoint/Web.php
Web.getFolders
public function getFolders() { if(!isset($this->Folders)){ $this->Folders = new FolderCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"folders")); } return $this->Folders; }
php
public function getFolders() { if(!isset($this->Folders)){ $this->Folders = new FolderCollection($this->getContext(),new ResourcePathEntity($this->getContext(),$this->getResourcePath(),"folders")); } return $this->Folders; }
[ "public", "function", "getFolders", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "Folders", ")", ")", "{", "$", "this", "->", "Folders", "=", "new", "FolderCollection", "(", "$", "this", "->", "getContext", "(", ")", ",", "new", "ResourcePathEntity", "(", "$", "this", "->", "getContext", "(", ")", ",", "$", "this", "->", "getResourcePath", "(", ")", ",", "\"folders\"", ")", ")", ";", "}", "return", "$", "this", "->", "Folders", ";", "}" ]
Gets the collection of all first-level folders in the Web site. @return FolderCollection
[ "Gets", "the", "collection", "of", "all", "first", "-", "level", "folders", "in", "the", "Web", "site", "." ]
train
https://github.com/vgrem/phpSPO/blob/4ec81109a154f88d188f9e87c7d7f004e91af666/src/SharePoint/Web.php#L151-L157