repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.validate | public function validate(array $options = array()) {
$validated= false;
if ($validator= $this->getValidator()) {
$validated= $this->_validator->validate($options);
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Validator class executed, result = " . print_r($validated, true));
}
} else {
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "No validator found for {$this->_class} instance.");
}
$validated= true;
}
return $validated;
} | php | public function validate(array $options = array()) {
$validated= false;
if ($validator= $this->getValidator()) {
$validated= $this->_validator->validate($options);
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Validator class executed, result = " . print_r($validated, true));
}
} else {
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "No validator found for {$this->_class} instance.");
}
$validated= true;
}
return $validated;
} | [
"public",
"function",
"validate",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"validated",
"=",
"false",
";",
"if",
"(",
"$",
"validator",
"=",
"$",
"this",
"->",
"getValidator",
"(",
")",
")",
"{",
"$",
"validated",
"=",
"... | Validate the field values using an xPDOValidator.
@param array $options An array of options to pass to the validator.
@return boolean True if validation was successful. | [
"Validate",
"the",
"field",
"values",
"using",
"an",
"xPDOValidator",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2170-L2184 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.isValidated | public function isValidated($key= '') {
$unvalidated = array_diff($this->_dirty, $this->_validated);
if (empty($key)) {
$validated = (count($unvalidated) > 0);
} else {
$validated = !in_array($this->getField($key), $unvalidated);
}
return $validated;
} | php | public function isValidated($key= '') {
$unvalidated = array_diff($this->_dirty, $this->_validated);
if (empty($key)) {
$validated = (count($unvalidated) > 0);
} else {
$validated = !in_array($this->getField($key), $unvalidated);
}
return $validated;
} | [
"public",
"function",
"isValidated",
"(",
"$",
"key",
"=",
"''",
")",
"{",
"$",
"unvalidated",
"=",
"array_diff",
"(",
"$",
"this",
"->",
"_dirty",
",",
"$",
"this",
"->",
"_validated",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
... | Indicates if the object or specified field has been validated.
@param string $key Optional key to check for specific validation.
@return boolean True if the object or specified field has been fully
validated successfully. | [
"Indicates",
"if",
"the",
"object",
"or",
"specified",
"field",
"has",
"been",
"validated",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2193-L2201 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.isLazy | public function isLazy($key= '') {
$lazy = false;
if (empty($key)) {
$lazy = (count($this->_lazy) > 0);
} else {
$key = $this->getField($key, true);
if ($key !== false) {
$lazy = in_array($key, $this->_lazy);
}
}
return $lazy;
} | php | public function isLazy($key= '') {
$lazy = false;
if (empty($key)) {
$lazy = (count($this->_lazy) > 0);
} else {
$key = $this->getField($key, true);
if ($key !== false) {
$lazy = in_array($key, $this->_lazy);
}
}
return $lazy;
} | [
"public",
"function",
"isLazy",
"(",
"$",
"key",
"=",
"''",
")",
"{",
"$",
"lazy",
"=",
"false",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"lazy",
"=",
"(",
"count",
"(",
"$",
"this",
"->",
"_lazy",
")",
">",
"0",
")",
"... | Indicates if the object or specified field is lazy.
@param string $key Optional key to check for laziness.
@return boolean True if the field specified or if any field is lazy if no
field is specified. | [
"Indicates",
"if",
"the",
"object",
"or",
"specified",
"field",
"is",
"lazy",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2210-L2221 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._getRelatedObjectsByFK | protected function _getRelatedObjectsByFK($alias, $criteria= null, $cacheFlag= true) {
$collection= array ();
if (isset($this->_relatedObjects[$alias]) && (is_object($this->_relatedObjects[$alias]) || (is_array($this->_relatedObjects[$alias]) && !empty ($this->_relatedObjects[$alias])))) {
$collection= & $this->_relatedObjects[$alias];
} else {
$fkMeta= $this->getFKDefinition($alias);
if ($fkMeta) {
$fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
if ($criteria === null) {
$criteria= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$criteria= array($fkCriteria, $criteria);
}
} else {
$criteria= $this->xpdo->newQuery($fkMeta['class'], $criteria);
$addCriteria = array("{$criteria->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$fkAddCriteria = array();
foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
if (is_numeric($fkCritKey)) continue;
$fkAddCriteria["{$criteria->getAlias()}.{$fkCritKey}"] = $fkCritVal;
}
if (!empty($fkAddCriteria)) {
$addCriteria = array($fkAddCriteria, $addCriteria);
}
}
$criteria->andCondition($addCriteria);
}
if ($collection= $this->xpdo->getCollection($fkMeta['class'], $criteria, $cacheFlag)) {
$this->_relatedObjects[$alias]= array_diff_key($this->_relatedObjects[$alias], $collection) + $collection;
}
}
}
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "_getRelatedObjectsByFK :: {$alias} :: " . (is_object($criteria) ? print_r($criteria->sql, true)."\n".print_r($criteria->bindings, true) : 'no criteria'));
}
return $collection;
} | php | protected function _getRelatedObjectsByFK($alias, $criteria= null, $cacheFlag= true) {
$collection= array ();
if (isset($this->_relatedObjects[$alias]) && (is_object($this->_relatedObjects[$alias]) || (is_array($this->_relatedObjects[$alias]) && !empty ($this->_relatedObjects[$alias])))) {
$collection= & $this->_relatedObjects[$alias];
} else {
$fkMeta= $this->getFKDefinition($alias);
if ($fkMeta) {
$fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
if ($criteria === null) {
$criteria= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$criteria= array($fkCriteria, $criteria);
}
} else {
$criteria= $this->xpdo->newQuery($fkMeta['class'], $criteria);
$addCriteria = array("{$criteria->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$fkAddCriteria = array();
foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
if (is_numeric($fkCritKey)) continue;
$fkAddCriteria["{$criteria->getAlias()}.{$fkCritKey}"] = $fkCritVal;
}
if (!empty($fkAddCriteria)) {
$addCriteria = array($fkAddCriteria, $addCriteria);
}
}
$criteria->andCondition($addCriteria);
}
if ($collection= $this->xpdo->getCollection($fkMeta['class'], $criteria, $cacheFlag)) {
$this->_relatedObjects[$alias]= array_diff_key($this->_relatedObjects[$alias], $collection) + $collection;
}
}
}
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "_getRelatedObjectsByFK :: {$alias} :: " . (is_object($criteria) ? print_r($criteria->sql, true)."\n".print_r($criteria->bindings, true) : 'no criteria'));
}
return $collection;
} | [
"protected",
"function",
"_getRelatedObjectsByFK",
"(",
"$",
"alias",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"collection",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_related... | Gets related objects by a foreign key and specified criteria.
@access protected
@param string $alias The alias representing the relationship.
@param mixed $criteria An optional xPDO criteria expression.
@param bool|int Indicates if the saved object(s) should be cached and
optionally, by specifying an integer value, for how many seconds before
expiring. Overrides the cacheFlag for the object.
@return array A collection of objects matching the criteria. | [
"Gets",
"related",
"objects",
"by",
"a",
"foreign",
"key",
"and",
"specified",
"criteria",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2234-L2271 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._initFields | protected function _initFields() {
foreach ($this->_fieldMeta as $k => $v) {
$this->fieldNames[$k]= $this->xpdo->escape($this->_table) . '.' . $this->xpdo->escape($k);
}
} | php | protected function _initFields() {
foreach ($this->_fieldMeta as $k => $v) {
$this->fieldNames[$k]= $this->xpdo->escape($this->_table) . '.' . $this->xpdo->escape($k);
}
} | [
"protected",
"function",
"_initFields",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_fieldMeta",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"this",
"->",
"fieldNames",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"xpdo",
"->",
"escape",
... | Initializes the field names with the qualified table name.
Once this is called, you can lookup the qualified name by the field name
itself in {@link xPDOObject::$fieldNames}.
@access protected | [
"Initializes",
"the",
"field",
"names",
"with",
"the",
"qualified",
"table",
"name",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2281-L2285 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.toJSON | public function toJSON($keyPrefix= '', $rawValues= false) {
$json= '';
$array= $this->toArray($keyPrefix, $rawValues);
if ($array) {
$json= $this->xpdo->toJSON($array);
}
return $json;
} | php | public function toJSON($keyPrefix= '', $rawValues= false) {
$json= '';
$array= $this->toArray($keyPrefix, $rawValues);
if ($array) {
$json= $this->xpdo->toJSON($array);
}
return $json;
} | [
"public",
"function",
"toJSON",
"(",
"$",
"keyPrefix",
"=",
"''",
",",
"$",
"rawValues",
"=",
"false",
")",
"{",
"$",
"json",
"=",
"''",
";",
"$",
"array",
"=",
"$",
"this",
"->",
"toArray",
"(",
"$",
"keyPrefix",
",",
"$",
"rawValues",
")",
";",
... | Returns a JSON representation of the object.
@param string $keyPrefix An optional prefix to prepend to the field keys.
@param boolean $rawValues An optional flag indicating if the field values
should be returned raw or via {@link xPDOObject::get()}.
@return string A JSON string representing the object. | [
"Returns",
"a",
"JSON",
"representation",
"of",
"the",
"object",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2295-L2302 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.fromJSON | public function fromJSON($jsonSource, $keyPrefix= '', $setPrimaryKeys= false, $rawValues= false, $adhocValues= false) {
$array= $this->xpdo->fromJSON($jsonSource, true);
if ($array) {
$this->fromArray($array, $keyPrefix, $setPrimaryKeys, $rawValues, $adhocValues);
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'xPDOObject::fromJSON() -- Could not convert jsonSource to a PHP array.');
}
} | php | public function fromJSON($jsonSource, $keyPrefix= '', $setPrimaryKeys= false, $rawValues= false, $adhocValues= false) {
$array= $this->xpdo->fromJSON($jsonSource, true);
if ($array) {
$this->fromArray($array, $keyPrefix, $setPrimaryKeys, $rawValues, $adhocValues);
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'xPDOObject::fromJSON() -- Could not convert jsonSource to a PHP array.');
}
} | [
"public",
"function",
"fromJSON",
"(",
"$",
"jsonSource",
",",
"$",
"keyPrefix",
"=",
"''",
",",
"$",
"setPrimaryKeys",
"=",
"false",
",",
"$",
"rawValues",
"=",
"false",
",",
"$",
"adhocValues",
"=",
"false",
")",
"{",
"$",
"array",
"=",
"$",
"this",
... | Sets the object fields from a JSON object string.
@param string $jsonSource A JSON object string.
@param string $keyPrefix An optional prefix to strip from the keys.
@param boolean $setPrimaryKeys Indicates if primary key fields should be set.
@param boolean $rawValues Indicates if values should be set raw or via
{@link xPDOObject::set()}.
@param boolean $adhocValues Indicates if ad hoc fields should be added to the
xPDOObject from the source object. | [
"Sets",
"the",
"object",
"fields",
"from",
"a",
"JSON",
"object",
"string",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2315-L2322 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.encode | public function encode($source, $type= 'md5') {
if (!is_string($source) || empty ($source)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'xPDOObject::encode() -- Attempt to encode source data that is not a string (or is empty); encoding skipped.');
return $source;
}
switch ($type) {
case 'password':
case 'md5':
$encoded= md5($source);
break;
default :
$encoded= $source;
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOObject::encode() -- Attempt to encode source data using an unsupported encoding algorithm ({$type}).");
break;
}
return $encoded;
} | php | public function encode($source, $type= 'md5') {
if (!is_string($source) || empty ($source)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'xPDOObject::encode() -- Attempt to encode source data that is not a string (or is empty); encoding skipped.');
return $source;
}
switch ($type) {
case 'password':
case 'md5':
$encoded= md5($source);
break;
default :
$encoded= $source;
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOObject::encode() -- Attempt to encode source data using an unsupported encoding algorithm ({$type}).");
break;
}
return $encoded;
} | [
"public",
"function",
"encode",
"(",
"$",
"source",
",",
"$",
"type",
"=",
"'md5'",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"source",
")",
"||",
"empty",
"(",
"$",
"source",
")",
")",
"{",
"$",
"this",
"->",
"xpdo",
"->",
"log",
"(",
"... | Encodes a string using the specified algorithm.
NOTE: This implementation currently only implements md5. To implement additional
algorithms, override this function in your xPDOObject derivative classes.
@param string $source The string source to encode.
@param string $type The type of encoding algorithm to apply, md5 by default.
@return string The encoded string. | [
"Encodes",
"a",
"string",
"using",
"the",
"specified",
"algorithm",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2334-L2350 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.setDirty | public function setDirty($key= '') {
if (empty($key)) {
foreach (array_keys($this->_fieldMeta) as $fIdx => $fieldKey) {
$this->setDirty($fieldKey);
}
}
else {
$key = $this->getField($key, true);
if ($key !== false) {
$this->_dirty[$key] = $key;
if (isset($this->_validated[$key])) unset($this->_validated[$key]);
}
}
} | php | public function setDirty($key= '') {
if (empty($key)) {
foreach (array_keys($this->_fieldMeta) as $fIdx => $fieldKey) {
$this->setDirty($fieldKey);
}
}
else {
$key = $this->getField($key, true);
if ($key !== false) {
$this->_dirty[$key] = $key;
if (isset($this->_validated[$key])) unset($this->_validated[$key]);
}
}
} | [
"public",
"function",
"setDirty",
"(",
"$",
"key",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_fieldMeta",
")",
"as",
"$",
"fIdx",
"=>",
"$",
"fieldKey",
")",
"{... | Add the field to a collection of field keys that have been modified.
This function also clears any validation flag associated with the field.
@param string $key The key of the field to set dirty. | [
"Add",
"the",
"field",
"to",
"a",
"collection",
"of",
"field",
"keys",
"that",
"have",
"been",
"modified",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2379-L2392 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._getDataType | protected function _getDataType($key) {
$type= 'text';
$actualKey = $this->getField($key, true);
if ($actualKey !== false && isset($this->_fieldMeta[$actualKey]['dbtype'])) {
$type= strtolower($this->_fieldMeta[$actualKey]['dbtype']);
} elseif ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "xPDOObject::_getDataType() -- No data type specified for field ({$key}), using `text`.");
}
return $type;
} | php | protected function _getDataType($key) {
$type= 'text';
$actualKey = $this->getField($key, true);
if ($actualKey !== false && isset($this->_fieldMeta[$actualKey]['dbtype'])) {
$type= strtolower($this->_fieldMeta[$actualKey]['dbtype']);
} elseif ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "xPDOObject::_getDataType() -- No data type specified for field ({$key}), using `text`.");
}
return $type;
} | [
"protected",
"function",
"_getDataType",
"(",
"$",
"key",
")",
"{",
"$",
"type",
"=",
"'text'",
";",
"$",
"actualKey",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"key",
",",
"true",
")",
";",
"if",
"(",
"$",
"actualKey",
"!==",
"false",
"&&",
"i... | Gets the database data type for the specified field.
@access protected
@param string $key The field name to get the data type for.
@return string The DB data type of the field. | [
"Gets",
"the",
"database",
"data",
"type",
"for",
"the",
"specified",
"field",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2411-L2420 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._setRaw | protected function _setRaw($key, $val) {
$set = false;
if ($val === null) {
$this->_fields[$key] = null;
$set = true;
} else {
$phptype = $this->_getPHPType($key);
$dbtype = $this->_getDataType($key);
switch ($phptype) {
case 'int':
case 'integer':
case 'boolean':
$this->_fields[$key] = (integer) $val;
$set = true;
break;
case 'float':
$this->_fields[$key] = (float) $val;
$set = true;
break;
case 'array':
if (is_array($val)) {
$this->_fields[$key]= serialize($val);
$set = true;
} elseif (is_string($val)) {
$this->_fields[$key]= $val;
$set = true;
} elseif (is_object($val) && $val instanceof xPDOObject) {
$this->_fields[$key]= serialize($val->toArray());
$set = true;
}
break;
case 'json':
if (!is_string($val)) {
$v = $val;
if (is_array($v)) {
$this->_fields[$key] = $this->xpdo->toJSON($v);
$set = true;
} elseif (is_object($v) && $v instanceof xPDOObject) {
$this->_fields[$key] = $this->xpdo->toJSON($v->toArray());
$set = true;
}
} else {
$this->_fields[$key]= $val;
$set = true;
}
break;
case 'date':
case 'datetime':
case 'timestamp':
if (preg_match('/int/i', $dbtype)) {
$this->_fields[$key] = (integer) $val;
$set = true;
break;
}
default:
$this->_fields[$key] = $val;
$set = true;
}
}
if ($set) $this->setDirty($key);
return $set;
} | php | protected function _setRaw($key, $val) {
$set = false;
if ($val === null) {
$this->_fields[$key] = null;
$set = true;
} else {
$phptype = $this->_getPHPType($key);
$dbtype = $this->_getDataType($key);
switch ($phptype) {
case 'int':
case 'integer':
case 'boolean':
$this->_fields[$key] = (integer) $val;
$set = true;
break;
case 'float':
$this->_fields[$key] = (float) $val;
$set = true;
break;
case 'array':
if (is_array($val)) {
$this->_fields[$key]= serialize($val);
$set = true;
} elseif (is_string($val)) {
$this->_fields[$key]= $val;
$set = true;
} elseif (is_object($val) && $val instanceof xPDOObject) {
$this->_fields[$key]= serialize($val->toArray());
$set = true;
}
break;
case 'json':
if (!is_string($val)) {
$v = $val;
if (is_array($v)) {
$this->_fields[$key] = $this->xpdo->toJSON($v);
$set = true;
} elseif (is_object($v) && $v instanceof xPDOObject) {
$this->_fields[$key] = $this->xpdo->toJSON($v->toArray());
$set = true;
}
} else {
$this->_fields[$key]= $val;
$set = true;
}
break;
case 'date':
case 'datetime':
case 'timestamp':
if (preg_match('/int/i', $dbtype)) {
$this->_fields[$key] = (integer) $val;
$set = true;
break;
}
default:
$this->_fields[$key] = $val;
$set = true;
}
}
if ($set) $this->setDirty($key);
return $set;
} | [
"protected",
"function",
"_setRaw",
"(",
"$",
"key",
",",
"$",
"val",
")",
"{",
"$",
"set",
"=",
"false",
";",
"if",
"(",
"$",
"val",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_fields",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"$",
"set",
"... | Set a raw value on a field converted to the appropriate type.
@access protected
@param string $key The key identifying the field to set.
@param mixed $val The value to set.
@return boolean Returns true if the value was set, false otherwise. | [
"Set",
"a",
"raw",
"value",
"on",
"a",
"field",
"converted",
"to",
"the",
"appropriate",
"type",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2468-L2529 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._getAliases | protected function _getAliases($class, $limit = 0) {
$aliases = array();
$limit = intval($limit);
$array = array('aggregates' => $this->_aggregates, 'composites' => $this->_composites);
foreach ($array as $relType => $relations) {
foreach ($relations as $alias => $def) {
if (isset($def['class']) && $def['class'] == $class) {
$aliases[] = $alias;
if ($limit > 0 && count($aliases) > $limit) break;
}
}
}
return $aliases;
} | php | protected function _getAliases($class, $limit = 0) {
$aliases = array();
$limit = intval($limit);
$array = array('aggregates' => $this->_aggregates, 'composites' => $this->_composites);
foreach ($array as $relType => $relations) {
foreach ($relations as $alias => $def) {
if (isset($def['class']) && $def['class'] == $class) {
$aliases[] = $alias;
if ($limit > 0 && count($aliases) > $limit) break;
}
}
}
return $aliases;
} | [
"protected",
"function",
"_getAliases",
"(",
"$",
"class",
",",
"$",
"limit",
"=",
"0",
")",
"{",
"$",
"aliases",
"=",
"array",
"(",
")",
";",
"$",
"limit",
"=",
"intval",
"(",
"$",
"limit",
")",
";",
"$",
"array",
"=",
"array",
"(",
"'aggregates'"... | Find aliases for any defined object relations of the specified class.
@access protected
@param string $class The name of the class to find aliases from.
@param int $limit An optional limit on the number of aliases to return;
default is 0, i.e. no limit.
@return array An array of aliases or an empty array if none are found. | [
"Find",
"aliases",
"for",
"any",
"defined",
"object",
"relations",
"of",
"the",
"specified",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2540-L2553 | train |
modxcms/xpdo | src/xPDO/xPDOIterator.php | xPDOIterator.fetch | protected function fetch() {
$row = $this->stmt->fetch(\PDO::FETCH_ASSOC);
if (is_array($row) && !empty($row)) {
$instance = $this->xpdo->call($this->class, '_loadInstance', array(& $this->xpdo, $this->class, $this->alias, $row));
if ($instance === null) {
$this->fetch();
} else {
$this->current = $instance;
}
} else {
$this->current = null;
}
} | php | protected function fetch() {
$row = $this->stmt->fetch(\PDO::FETCH_ASSOC);
if (is_array($row) && !empty($row)) {
$instance = $this->xpdo->call($this->class, '_loadInstance', array(& $this->xpdo, $this->class, $this->alias, $row));
if ($instance === null) {
$this->fetch();
} else {
$this->current = $instance;
}
} else {
$this->current = null;
}
} | [
"protected",
"function",
"fetch",
"(",
")",
"{",
"$",
"row",
"=",
"$",
"this",
"->",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"row",
")",
"&&",
"!",
"empty",
"(",
"$",
"row",
")",
... | Fetch the next row from the result set and set it as current.
Calls the _loadInstance() method for the specified class, so it properly
inherits behavior from xPDOObject derivatives. | [
"Fetch",
"the",
"next",
"row",
"from",
"the",
"result",
"set",
"and",
"set",
"it",
"as",
"current",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDOIterator.php#L117-L129 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOScriptVehicle.php | xPDOScriptVehicle._executeScript | protected function _executeScript(& $transport, $options) {
$installed = false;
$vOptions = $this->get($transport, $options);
if (isset ($vOptions['object']) && isset ($vOptions['object']['source'])) {
$object = $vOptions['object'];
if ($this->validate($transport, $object, $vOptions)) {
$fileSource = $transport->path . $object['source'];
if (!$installed = include ($fileSource)) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOScriptVehicle execution failed: ({$fileSource})");
} elseif (!$this->resolve($transport, $object, $vOptions)) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not resolve vehicle for object: ' . print_r($object, true));
if ($transport->xpdo->getDebug() === true) $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Could not resolve vehicle: ' . print_r($vOptions, true));
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not validate vehicle for object: ' . print_r($object, true));
if ($transport->xpdo->getDebug() === true) $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Could not validate vehicle: ' . print_r($vOptions, true));
}
}
return $installed;
} | php | protected function _executeScript(& $transport, $options) {
$installed = false;
$vOptions = $this->get($transport, $options);
if (isset ($vOptions['object']) && isset ($vOptions['object']['source'])) {
$object = $vOptions['object'];
if ($this->validate($transport, $object, $vOptions)) {
$fileSource = $transport->path . $object['source'];
if (!$installed = include ($fileSource)) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOScriptVehicle execution failed: ({$fileSource})");
} elseif (!$this->resolve($transport, $object, $vOptions)) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not resolve vehicle for object: ' . print_r($object, true));
if ($transport->xpdo->getDebug() === true) $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Could not resolve vehicle: ' . print_r($vOptions, true));
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not validate vehicle for object: ' . print_r($object, true));
if ($transport->xpdo->getDebug() === true) $transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Could not validate vehicle: ' . print_r($vOptions, true));
}
}
return $installed;
} | [
"protected",
"function",
"_executeScript",
"(",
"&",
"$",
"transport",
",",
"$",
"options",
")",
"{",
"$",
"installed",
"=",
"false",
";",
"$",
"vOptions",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"transport",
",",
"$",
"options",
")",
";",
"if",
"("... | Execute the script represented by and stored in this vehicle.
@access protected
@param xPDOTransport &$transport A reference the transport this vehicle is stored in.
@param array $options Optional attributes that can be applied to vehicle install process.
@return boolean True if the scripts are executed successfully. | [
"Execute",
"the",
"script",
"represented",
"by",
"and",
"stored",
"in",
"this",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOScriptVehicle.php#L46-L65 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.isValidClause | public static function isValidClause($clause) {
$output = rtrim($clause, ' ;');
$output = preg_replace("/\\\\'.*?\\\\'/", '{mask}', $output);
$output = preg_replace('/\\".*?\\"/', '{mask}', $output);
$output = preg_replace("/'.*?'/", '{mask}', $output);
$output = preg_replace('/".*?"/', '{mask}', $output);
return strpos($output, ';') === false && strpos(strtolower($output), 'union') === false;
} | php | public static function isValidClause($clause) {
$output = rtrim($clause, ' ;');
$output = preg_replace("/\\\\'.*?\\\\'/", '{mask}', $output);
$output = preg_replace('/\\".*?\\"/', '{mask}', $output);
$output = preg_replace("/'.*?'/", '{mask}', $output);
$output = preg_replace('/".*?"/', '{mask}', $output);
return strpos($output, ';') === false && strpos(strtolower($output), 'union') === false;
} | [
"public",
"static",
"function",
"isValidClause",
"(",
"$",
"clause",
")",
"{",
"$",
"output",
"=",
"rtrim",
"(",
"$",
"clause",
",",
"' ;'",
")",
";",
"$",
"output",
"=",
"preg_replace",
"(",
"\"/\\\\\\\\'.*?\\\\\\\\'/\"",
",",
"'{mask}'",
",",
"$",
"outpu... | Make sure a clause is valid and does not contain SQL injection attempts.
@param string $clause The string clause to validate.
@return bool True if the clause is valid. | [
"Make",
"sure",
"a",
"clause",
"is",
"valid",
"and",
"does",
"not",
"contain",
"SQL",
"injection",
"attempts",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L98-L105 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.command | public function command($command= 'SELECT') {
$command= strtoupper(trim($command));
if (preg_match('/(SELECT|UPDATE|DELETE)/', $command)) {
$this->query['command']= $command;
if (in_array($command, array('DELETE','UPDATE'))) $this->_alias= $this->xpdo->getTableName($this->_class);
}
return $this;
} | php | public function command($command= 'SELECT') {
$command= strtoupper(trim($command));
if (preg_match('/(SELECT|UPDATE|DELETE)/', $command)) {
$this->query['command']= $command;
if (in_array($command, array('DELETE','UPDATE'))) $this->_alias= $this->xpdo->getTableName($this->_class);
}
return $this;
} | [
"public",
"function",
"command",
"(",
"$",
"command",
"=",
"'SELECT'",
")",
"{",
"$",
"command",
"=",
"strtoupper",
"(",
"trim",
"(",
"$",
"command",
")",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/(SELECT|UPDATE|DELETE)/'",
",",
"$",
"command",
")",
")"... | Set the type of SQL command you want to build.
The default is SELECT, though it also supports DELETE and UPDATE.
@param string $command The type of SQL statement represented by this object. Default is 'SELECT'.
@return xPDOQuery Returns the current object for convenience. | [
"Set",
"the",
"type",
"of",
"SQL",
"command",
"you",
"want",
"to",
"build",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L174-L181 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.distinct | public function distinct($on = null) {
if ($on === null) {
if (empty($this->query['distinct']) || $this->query['distinct'] !== 'DISTINCT') {
$this->query['distinct']= 'DISTINCT';
} else {
$this->query['distinct']= '';
}
} else {
$this->query['distinct']= $on == true ? 'DISTINCT' : '';
}
return $this;
} | php | public function distinct($on = null) {
if ($on === null) {
if (empty($this->query['distinct']) || $this->query['distinct'] !== 'DISTINCT') {
$this->query['distinct']= 'DISTINCT';
} else {
$this->query['distinct']= '';
}
} else {
$this->query['distinct']= $on == true ? 'DISTINCT' : '';
}
return $this;
} | [
"public",
"function",
"distinct",
"(",
"$",
"on",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"on",
"===",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"query",
"[",
"'distinct'",
"]",
")",
"||",
"$",
"this",
"->",
"query",
"[",
"'d... | Set the DISTINCT attribute of the query.
@param null|boolean $on Defines how to set the distinct attribute:
- null (default) indicates the distinct attribute should be toggled
- any other value is treated as a boolean, i.e. true to set DISTINCT, false to unset
@return xPDOQuery Returns the current object for convenience. | [
"Set",
"the",
"DISTINCT",
"attribute",
"of",
"the",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L191-L202 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.select | public function select($columns= '*') {
if (!is_array($columns)) {
$columns= trim($columns);
if ($columns == '*' || $columns === $this->_alias . '.*' || $columns === $this->xpdo->escape($this->_alias) . '.*') {
$columns= $this->xpdo->getSelectColumns($this->_class, $this->_alias, $this->_alias . '_');
}
$columns= explode(',', $columns);
foreach ($columns as $colKey => $column) $columns[$colKey] = trim($column);
}
if (is_array ($columns)) {
if (!is_array($this->query['columns'])) {
$this->query['columns']= $columns;
} else {
$this->query['columns']= array_merge($this->query['columns'], $columns);
}
}
return $this;
} | php | public function select($columns= '*') {
if (!is_array($columns)) {
$columns= trim($columns);
if ($columns == '*' || $columns === $this->_alias . '.*' || $columns === $this->xpdo->escape($this->_alias) . '.*') {
$columns= $this->xpdo->getSelectColumns($this->_class, $this->_alias, $this->_alias . '_');
}
$columns= explode(',', $columns);
foreach ($columns as $colKey => $column) $columns[$colKey] = trim($column);
}
if (is_array ($columns)) {
if (!is_array($this->query['columns'])) {
$this->query['columns']= $columns;
} else {
$this->query['columns']= array_merge($this->query['columns'], $columns);
}
}
return $this;
} | [
"public",
"function",
"select",
"(",
"$",
"columns",
"=",
"'*'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"columns",
")",
")",
"{",
"$",
"columns",
"=",
"trim",
"(",
"$",
"columns",
")",
";",
"if",
"(",
"$",
"columns",
"==",
"'*'",
"||",
... | Specify columns to return from the SQL query.
@param string $columns Columns to return from the query.
@return xPDOQuery Returns the current object for convenience. | [
"Specify",
"columns",
"to",
"return",
"from",
"the",
"SQL",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L221-L238 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.join | public function join($class, $alias= '', $type= xPDOQuery::SQL_JOIN_CROSS, $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
if ($this->xpdo->loadClass($class)) {
$alias= $alias ? $alias : $class;
$target= & $this->query['from']['joins'];
$targetIdx= count($target);
$target[$targetIdx]= array (
'table' => $this->xpdo->getTableName($class),
'class' => $class,
'alias' => $alias,
'type' => $type,
'conditions' => array ()
);
if (empty ($conditions)) {
$fkMeta= $this->xpdo->getFKDefinition($this->_class, $alias);
if ($fkMeta) {
$parentAlias= isset ($this->_alias) ? $this->_alias : $this->_class;
$local= $fkMeta['local'];
$foreign= $fkMeta['foreign'];
$conditions= $this->xpdo->escape($parentAlias) . '.' . $this->xpdo->escape($local) . ' = ' . $this->xpdo->escape($alias) . '.' . $this->xpdo->escape($foreign);
if (isset($fkMeta['criteria']['local'])) {
$localCriteria = array();
if (is_array($fkMeta['criteria']['local'])) {
foreach ($fkMeta['criteria']['local'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$localCriteria[] = $critVal;
} else {
$localCriteria["{$this->_class}.{$critKey}"] = $critVal;
}
}
}
if (!empty($localCriteria)) {
$conditions = array($localCriteria, $conditions);
}
$foreignCriteria = array();
if (is_array($fkMeta['criteria']['foreign'])) {
foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$foreignCriteria[] = $critVal;
} else {
$foreignCriteria["{$parentAlias}.{$critKey}"] = $critVal;
}
}
}
if (!empty($foreignCriteria)) {
$conditions = array($foreignCriteria, $conditions);
}
}
}
}
$this->condition($target[$targetIdx]['conditions'], $conditions, $conjunction, $binding, $condGroup);
}
return $this;
} | php | public function join($class, $alias= '', $type= xPDOQuery::SQL_JOIN_CROSS, $conditions= array (), $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
if ($this->xpdo->loadClass($class)) {
$alias= $alias ? $alias : $class;
$target= & $this->query['from']['joins'];
$targetIdx= count($target);
$target[$targetIdx]= array (
'table' => $this->xpdo->getTableName($class),
'class' => $class,
'alias' => $alias,
'type' => $type,
'conditions' => array ()
);
if (empty ($conditions)) {
$fkMeta= $this->xpdo->getFKDefinition($this->_class, $alias);
if ($fkMeta) {
$parentAlias= isset ($this->_alias) ? $this->_alias : $this->_class;
$local= $fkMeta['local'];
$foreign= $fkMeta['foreign'];
$conditions= $this->xpdo->escape($parentAlias) . '.' . $this->xpdo->escape($local) . ' = ' . $this->xpdo->escape($alias) . '.' . $this->xpdo->escape($foreign);
if (isset($fkMeta['criteria']['local'])) {
$localCriteria = array();
if (is_array($fkMeta['criteria']['local'])) {
foreach ($fkMeta['criteria']['local'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$localCriteria[] = $critVal;
} else {
$localCriteria["{$this->_class}.{$critKey}"] = $critVal;
}
}
}
if (!empty($localCriteria)) {
$conditions = array($localCriteria, $conditions);
}
$foreignCriteria = array();
if (is_array($fkMeta['criteria']['foreign'])) {
foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$foreignCriteria[] = $critVal;
} else {
$foreignCriteria["{$parentAlias}.{$critKey}"] = $critVal;
}
}
}
if (!empty($foreignCriteria)) {
$conditions = array($foreignCriteria, $conditions);
}
}
}
}
$this->condition($target[$targetIdx]['conditions'], $conditions, $conjunction, $binding, $condGroup);
}
return $this;
} | [
"public",
"function",
"join",
"(",
"$",
"class",
",",
"$",
"alias",
"=",
"''",
",",
"$",
"type",
"=",
"xPDOQuery",
"::",
"SQL_JOIN_CROSS",
",",
"$",
"conditions",
"=",
"array",
"(",
")",
",",
"$",
"conjunction",
"=",
"xPDOQuery",
"::",
"SQL_AND",
",",
... | Join a table represented by the specified class.
@param string $class The classname (or relation alias for aggregates and
composites) of representing the table to be joined.
@param string $alias An optional alias to represent the joined table in
the constructed query.
@param string $type The type of join to perform. See the xPDOQuery::SQL_JOIN
constants.
@param mixed $conditions Conditions of the join specified in any xPDO
compatible criteria object or expression.
@param string $conjunction A conjunction to be applied to the condition
or conditions supplied.
@param array $binding Optional bindings to accompany the conditions.
@param int $condGroup An optional identifier for adding the conditions
to a specific set of conjoined expressions.
@return xPDOQuery Returns the current object for convenience. | [
"Join",
"a",
"table",
"represented",
"by",
"the",
"specified",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L292-L344 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.from | public function from($class, $alias= '') {
if ($class= $this->xpdo->loadClass($class)) {
$alias= $alias ? $alias : $class;
$this->query['from']['tables'][]= array (
'table' => $this->xpdo->getTableName($class),
'alias' => $alias
);
}
return $this;
} | php | public function from($class, $alias= '') {
if ($class= $this->xpdo->loadClass($class)) {
$alias= $alias ? $alias : $class;
$this->query['from']['tables'][]= array (
'table' => $this->xpdo->getTableName($class),
'alias' => $alias
);
}
return $this;
} | [
"public",
"function",
"from",
"(",
"$",
"class",
",",
"$",
"alias",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"class",
"=",
"$",
"this",
"->",
"xpdo",
"->",
"loadClass",
"(",
"$",
"class",
")",
")",
"{",
"$",
"alias",
"=",
"$",
"alias",
"?",
"$",
... | Add a FROM clause to the query.
@param string $class The class representing the table to add.
@param string $alias An optional alias for the class.
@return xPDOQuery Returns the instance. | [
"Add",
"a",
"FROM",
"clause",
"to",
"the",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L365-L374 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.condition | public function condition(& $target, $conditions= '1', $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
$condGroup= intval($condGroup);
if (!isset ($target[$condGroup])) $target[$condGroup]= array ();
try {
$target[$condGroup][] = $this->parseConditions($conditions, $conjunction);
} catch (xPDOException $e) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage());
$this->where("2=1");
}
return $this;
} | php | public function condition(& $target, $conditions= '1', $conjunction= xPDOQuery::SQL_AND, $binding= null, $condGroup= 0) {
$condGroup= intval($condGroup);
if (!isset ($target[$condGroup])) $target[$condGroup]= array ();
try {
$target[$condGroup][] = $this->parseConditions($conditions, $conjunction);
} catch (xPDOException $e) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage());
$this->where("2=1");
}
return $this;
} | [
"public",
"function",
"condition",
"(",
"&",
"$",
"target",
",",
"$",
"conditions",
"=",
"'1'",
",",
"$",
"conjunction",
"=",
"xPDOQuery",
"::",
"SQL_AND",
",",
"$",
"binding",
"=",
"null",
",",
"$",
"condGroup",
"=",
"0",
")",
"{",
"$",
"condGroup",
... | Add a condition to the query.
@param string $target The target clause for the condition.
@param mixed $conditions A valid xPDO criteria expression.
@param string $conjunction The conjunction to use when appending this condition, i.e., AND or OR.
@param mixed $binding A value or PDO binding representation of a value for the condition.
@param integer $condGroup A numeric identifier for associating conditions into groups.
@return xPDOQuery Returns the instance. | [
"Add",
"a",
"condition",
"to",
"the",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L386-L396 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.sortby | public function sortby($column, $direction= 'ASC') {
/* The direction can only be ASC or DESC; anything else is bogus */
if (!in_array(strtoupper($direction), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING'), true)) {
$direction = '';
}
if (!static::isValidClause($column)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'SQL injection attempt detected in sortby column; clause rejected');
} elseif (!empty($column)) {
$this->query['sortby'][] = array('column' => $column, 'direction' => $direction);
}
return $this;
} | php | public function sortby($column, $direction= 'ASC') {
/* The direction can only be ASC or DESC; anything else is bogus */
if (!in_array(strtoupper($direction), array('ASC', 'DESC', 'ASCENDING', 'DESCENDING'), true)) {
$direction = '';
}
if (!static::isValidClause($column)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'SQL injection attempt detected in sortby column; clause rejected');
} elseif (!empty($column)) {
$this->query['sortby'][] = array('column' => $column, 'direction' => $direction);
}
return $this;
} | [
"public",
"function",
"sortby",
"(",
"$",
"column",
",",
"$",
"direction",
"=",
"'ASC'",
")",
"{",
"/* The direction can only be ASC or DESC; anything else is bogus */",
"if",
"(",
"!",
"in_array",
"(",
"strtoupper",
"(",
"$",
"direction",
")",
",",
"array",
"(",
... | Add an ORDER BY clause to the query.
@param string $column Column identifier to sort by.
@param string $direction The direction to sort by, ASC or DESC.
@return xPDOQuery Returns the instance. | [
"Add",
"an",
"ORDER",
"BY",
"clause",
"to",
"the",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L428-L440 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.bindGraph | public function bindGraph($graph) {
if (is_string($graph)) {
$graph= $this->xpdo->fromJSON($graph);
}
if (is_array ($graph)) {
if ($this->graph !== $graph) {
$this->graph= $graph;
$this->select($this->xpdo->getSelectColumns($this->_class, $this->_alias, $this->_alias . '_'));
foreach ($this->graph as $relationAlias => $subRelations) {
$this->bindGraphNode($this->_class, $this->_alias, $relationAlias, $subRelations);
}
if ($pk= $this->xpdo->getPK($this->_class)) {
if (is_array ($pk)) {
foreach ($pk as $key) {
$this->sortby($this->xpdo->escape($this->_alias) . '.' . $this->xpdo->escape($key), 'ASC');
}
} else {
$this->sortby($this->xpdo->escape($this->_alias) . '.' . $this->xpdo->escape($pk), 'ASC');
}
}
}
}
return $this;
} | php | public function bindGraph($graph) {
if (is_string($graph)) {
$graph= $this->xpdo->fromJSON($graph);
}
if (is_array ($graph)) {
if ($this->graph !== $graph) {
$this->graph= $graph;
$this->select($this->xpdo->getSelectColumns($this->_class, $this->_alias, $this->_alias . '_'));
foreach ($this->graph as $relationAlias => $subRelations) {
$this->bindGraphNode($this->_class, $this->_alias, $relationAlias, $subRelations);
}
if ($pk= $this->xpdo->getPK($this->_class)) {
if (is_array ($pk)) {
foreach ($pk as $key) {
$this->sortby($this->xpdo->escape($this->_alias) . '.' . $this->xpdo->escape($key), 'ASC');
}
} else {
$this->sortby($this->xpdo->escape($this->_alias) . '.' . $this->xpdo->escape($pk), 'ASC');
}
}
}
}
return $this;
} | [
"public",
"function",
"bindGraph",
"(",
"$",
"graph",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"graph",
")",
")",
"{",
"$",
"graph",
"=",
"$",
"this",
"->",
"xpdo",
"->",
"fromJSON",
"(",
"$",
"graph",
")",
";",
"}",
"if",
"(",
"is_array",
"("... | Bind an object graph to the query.
@param mixed $graph An array or JSON graph of related objects.
@return xPDOQuery Returns the instance. | [
"Bind",
"an",
"object",
"graph",
"to",
"the",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L483-L506 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.bindGraphNode | public function bindGraphNode($parentClass, $parentAlias, $classAlias, $relations) {
if ($fkMeta= $this->xpdo->getFKDefinition($parentClass, $classAlias)) {
$class= $fkMeta['class'];
$local= $fkMeta['local'];
$foreign= $fkMeta['foreign'];
$this->select($this->xpdo->getSelectColumns($class, $classAlias, $classAlias . '_'));
$expression= $this->xpdo->escape($parentAlias) . '.' . $this->xpdo->escape($local) . ' = ' . $this->xpdo->escape($classAlias) . '.' . $this->xpdo->escape($foreign);
if (isset($fkMeta['criteria']['local'])) {
$localCriteria = array();
if (is_array($fkMeta['criteria']['local'])) {
foreach ($fkMeta['criteria']['local'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$localCriteria[] = $critVal;
} else {
$localCriteria["{$classAlias}.{$critKey}"] = $critVal;
}
}
}
if (!empty($localCriteria)) {
$expression = array($localCriteria, $expression);
}
$foreignCriteria = array();
if (is_array($fkMeta['criteria']['foreign'])) {
foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$foreignCriteria[] = $critVal;
} else {
$foreignCriteria["{$parentAlias}.{$critKey}"] = $critVal;
}
}
}
if (!empty($foreignCriteria)) {
$expression = array($foreignCriteria, $expression);
}
}
$this->leftJoin($class, $classAlias, $expression);
if (!empty ($relations)) {
foreach ($relations as $relationAlias => $subRelations) {
$this->bindGraphNode($class, $classAlias, $relationAlias, $subRelations);
}
}
}
} | php | public function bindGraphNode($parentClass, $parentAlias, $classAlias, $relations) {
if ($fkMeta= $this->xpdo->getFKDefinition($parentClass, $classAlias)) {
$class= $fkMeta['class'];
$local= $fkMeta['local'];
$foreign= $fkMeta['foreign'];
$this->select($this->xpdo->getSelectColumns($class, $classAlias, $classAlias . '_'));
$expression= $this->xpdo->escape($parentAlias) . '.' . $this->xpdo->escape($local) . ' = ' . $this->xpdo->escape($classAlias) . '.' . $this->xpdo->escape($foreign);
if (isset($fkMeta['criteria']['local'])) {
$localCriteria = array();
if (is_array($fkMeta['criteria']['local'])) {
foreach ($fkMeta['criteria']['local'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$localCriteria[] = $critVal;
} else {
$localCriteria["{$classAlias}.{$critKey}"] = $critVal;
}
}
}
if (!empty($localCriteria)) {
$expression = array($localCriteria, $expression);
}
$foreignCriteria = array();
if (is_array($fkMeta['criteria']['foreign'])) {
foreach ($fkMeta['criteria']['foreign'] as $critKey => $critVal) {
if (is_numeric($critKey)) {
$foreignCriteria[] = $critVal;
} else {
$foreignCriteria["{$parentAlias}.{$critKey}"] = $critVal;
}
}
}
if (!empty($foreignCriteria)) {
$expression = array($foreignCriteria, $expression);
}
}
$this->leftJoin($class, $classAlias, $expression);
if (!empty ($relations)) {
foreach ($relations as $relationAlias => $subRelations) {
$this->bindGraphNode($class, $classAlias, $relationAlias, $subRelations);
}
}
}
} | [
"public",
"function",
"bindGraphNode",
"(",
"$",
"parentClass",
",",
"$",
"parentAlias",
",",
"$",
"classAlias",
",",
"$",
"relations",
")",
"{",
"if",
"(",
"$",
"fkMeta",
"=",
"$",
"this",
"->",
"xpdo",
"->",
"getFKDefinition",
"(",
"$",
"parentClass",
... | Bind the node of an object graph to the query.
@param string $parentClass The class representing the relation parent.
@param string $parentAlias The alias the class is assuming.
@param string $classAlias The class representing the related graph node.
@param array $relations Child relations of the current graph node. | [
"Bind",
"the",
"node",
"of",
"an",
"object",
"graph",
"to",
"the",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L516-L558 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.hydrateGraph | public function hydrateGraph($rows, $cacheFlag = true) {
$instances= array ();
$collectionCaching = $this->xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if (is_object($rows)) {
if ($cacheFlag && $this->xpdo->_cacheEnabled && $collectionCaching > 0) {
$cacheRows = array();
}
while ($row = $rows->fetch(\PDO::FETCH_ASSOC)) {
$this->hydrateGraphParent($instances, $row);
if ($cacheFlag && $this->xpdo->_cacheEnabled && $collectionCaching > 0) {
$cacheRows[]= $row;
}
}
if ($cacheFlag && $this->xpdo->_cacheEnabled && $collectionCaching > 0) {
$this->xpdo->toCache($this, $cacheRows, $cacheFlag);
}
} elseif (is_array($rows)) {
foreach ($rows as $row) {
$this->hydrateGraphParent($instances, $row);
}
}
return $instances;
} | php | public function hydrateGraph($rows, $cacheFlag = true) {
$instances= array ();
$collectionCaching = $this->xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if (is_object($rows)) {
if ($cacheFlag && $this->xpdo->_cacheEnabled && $collectionCaching > 0) {
$cacheRows = array();
}
while ($row = $rows->fetch(\PDO::FETCH_ASSOC)) {
$this->hydrateGraphParent($instances, $row);
if ($cacheFlag && $this->xpdo->_cacheEnabled && $collectionCaching > 0) {
$cacheRows[]= $row;
}
}
if ($cacheFlag && $this->xpdo->_cacheEnabled && $collectionCaching > 0) {
$this->xpdo->toCache($this, $cacheRows, $cacheFlag);
}
} elseif (is_array($rows)) {
foreach ($rows as $row) {
$this->hydrateGraphParent($instances, $row);
}
}
return $instances;
} | [
"public",
"function",
"hydrateGraph",
"(",
"$",
"rows",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"$",
"collectionCaching",
"=",
"$",
"this",
"->",
"xpdo",
"->",
"getOption",
"(",
"xPDO",
"::",
"OPT_CA... | Hydrates a graph of related objects from a single result set.
@param array|\PDOStatement $rows A collection of result set rows or an
executed PDOStatement to fetch rows from to hydrating the graph.
@param bool $cacheFlag Indicates if the objects should be cached and
optionally, by specifying an integer value, for how many seconds.
@return array A collection of objects with all related objects from the
graph pre-populated. | [
"Hydrates",
"a",
"graph",
"of",
"related",
"objects",
"from",
"a",
"single",
"result",
"set",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L570-L592 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.hydrateGraphNode | public function hydrateGraphNode(& $row, & $instance, $alias, $relations) {
$relObj= null;
if ($relationMeta= $instance->getFKDefinition($alias)) {
if ($row[$alias.'_'.$relationMeta['foreign']] != null) {
$relObj = $this->xpdo->call($relationMeta['class'], '_loadInstance', array(& $this->xpdo, $relationMeta['class'], $alias, $row));
if ($relObj) {
if (strtolower($relationMeta['cardinality']) == 'many') {
$instance->addMany($relObj, $alias);
} else {
$instance->addOne($relObj, $alias);
}
}
}
}
if (!empty($relations) && $relObj instanceof xPDOObject) {
foreach ($relations as $relationAlias => $subRelations) {
if (is_array($subRelations) && !empty($subRelations)) {
foreach ($subRelations as $subRelation) {
$this->hydrateGraphNode($row, $relObj, $relationAlias, $subRelation);
}
} else {
$this->hydrateGraphNode($row, $relObj, $relationAlias, null);
}
}
}
} | php | public function hydrateGraphNode(& $row, & $instance, $alias, $relations) {
$relObj= null;
if ($relationMeta= $instance->getFKDefinition($alias)) {
if ($row[$alias.'_'.$relationMeta['foreign']] != null) {
$relObj = $this->xpdo->call($relationMeta['class'], '_loadInstance', array(& $this->xpdo, $relationMeta['class'], $alias, $row));
if ($relObj) {
if (strtolower($relationMeta['cardinality']) == 'many') {
$instance->addMany($relObj, $alias);
} else {
$instance->addOne($relObj, $alias);
}
}
}
}
if (!empty($relations) && $relObj instanceof xPDOObject) {
foreach ($relations as $relationAlias => $subRelations) {
if (is_array($subRelations) && !empty($subRelations)) {
foreach ($subRelations as $subRelation) {
$this->hydrateGraphNode($row, $relObj, $relationAlias, $subRelation);
}
} else {
$this->hydrateGraphNode($row, $relObj, $relationAlias, null);
}
}
}
} | [
"public",
"function",
"hydrateGraphNode",
"(",
"&",
"$",
"row",
",",
"&",
"$",
"instance",
",",
"$",
"alias",
",",
"$",
"relations",
")",
"{",
"$",
"relObj",
"=",
"null",
";",
"if",
"(",
"$",
"relationMeta",
"=",
"$",
"instance",
"->",
"getFKDefinition... | Hydrates a node of the object graph.
@param array $row The result set representing the current node.
@param xPDOObject $instance The xPDOObject instance to be hydrated from the node.
@param string $alias The alias identifying the object in the parent relationship.
@param array $relations Child relations of the current node. | [
"Hydrates",
"a",
"node",
"of",
"the",
"object",
"graph",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L620-L645 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.prepare | public function prepare($bindings= array (), $byValue= true, $cacheFlag= null) {
$this->stmt= null;
if ($this->construct() && $this->stmt= $this->xpdo->prepare($this->sql)) {
$this->bind($bindings, $byValue, $cacheFlag);
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not construct or prepare query because it is invalid or could not connect: ' . $this->sql);
}
return $this->stmt;
} | php | public function prepare($bindings= array (), $byValue= true, $cacheFlag= null) {
$this->stmt= null;
if ($this->construct() && $this->stmt= $this->xpdo->prepare($this->sql)) {
$this->bind($bindings, $byValue, $cacheFlag);
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not construct or prepare query because it is invalid or could not connect: ' . $this->sql);
}
return $this->stmt;
} | [
"public",
"function",
"prepare",
"(",
"$",
"bindings",
"=",
"array",
"(",
")",
",",
"$",
"byValue",
"=",
"true",
",",
"$",
"cacheFlag",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"stmt",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"construct",
... | Prepares the xPDOQuery for execution.
@param array $bindings
@param bool $byValue
@param null|int|bool $cacheFlag
@return \PDOStatement The PDOStatement representing the prepared query. | [
"Prepares",
"the",
"xPDOQuery",
"for",
"execution",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L663-L671 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.isConditionalClause | public function isConditionalClause($string) {
$matched= false;
if (is_string($string)) {
if (!static::isValidClause($string)) {
throw new xPDOException("SQL injection attempt detected: {$string}");
}
foreach ($this->_operators as $operator) {
if (strpos(strtoupper($string), $operator) !== false) {
$matched= true;
break;
}
}
}
return $matched;
} | php | public function isConditionalClause($string) {
$matched= false;
if (is_string($string)) {
if (!static::isValidClause($string)) {
throw new xPDOException("SQL injection attempt detected: {$string}");
}
foreach ($this->_operators as $operator) {
if (strpos(strtoupper($string), $operator) !== false) {
$matched= true;
break;
}
}
}
return $matched;
} | [
"public",
"function",
"isConditionalClause",
"(",
"$",
"string",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"isValidClause",
"(",
"$",
"string",
")",
")",
"{... | Determines if a string contains a conditional operator.
@param string $string The string to evaluate.
@throws \xPDO\xPDOException
@return boolean True if the string is a complete conditional SQL clause. | [
"Determines",
"if",
"a",
"string",
"contains",
"a",
"conditional",
"operator",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L835-L849 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.buildConditionalClause | public function buildConditionalClause($conditions, & $conjunction = xPDOQuery::SQL_AND, $isFirst = true) {
$clause= '';
if (is_array($conditions)) {
$groups= count($conditions);
$currentGroup= 1;
$first = true;
$origConjunction = $conjunction;
$groupConjunction = $conjunction;
foreach ($conditions as $groupKey => $group) {
$groupClause = '';
$groupClause.= $this->buildConditionalClause($group, $groupConjunction, $first);
if ($first) {
$conjunction = $groupConjunction;
}
if (!empty($groupClause)) $clause.= $groupClause;
$currentGroup++;
$first = false;
}
$conjunction = $origConjunction;
if ($groups > 1 && !empty($clause)) {
$clause = " ( {$clause} ) ";
}
if (!$isFirst && !empty($clause)) {
$clause = ' ' . $groupConjunction . ' ' . $clause;
}
} elseif (is_object($conditions) && $conditions instanceof xPDOQueryCondition) {
if ($isFirst) {
$conjunction = $conditions->conjunction;
} else {
$clause.= ' ' . $conditions->conjunction . ' ';
}
$clause.= $conditions->sql;
if (!empty ($conditions->binding)) {
$this->bindings[]= $conditions->binding;
}
}
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Returning clause:\n{$clause}\nfrom conditions:\n" . print_r($conditions, 1));
}
return $clause;
} | php | public function buildConditionalClause($conditions, & $conjunction = xPDOQuery::SQL_AND, $isFirst = true) {
$clause= '';
if (is_array($conditions)) {
$groups= count($conditions);
$currentGroup= 1;
$first = true;
$origConjunction = $conjunction;
$groupConjunction = $conjunction;
foreach ($conditions as $groupKey => $group) {
$groupClause = '';
$groupClause.= $this->buildConditionalClause($group, $groupConjunction, $first);
if ($first) {
$conjunction = $groupConjunction;
}
if (!empty($groupClause)) $clause.= $groupClause;
$currentGroup++;
$first = false;
}
$conjunction = $origConjunction;
if ($groups > 1 && !empty($clause)) {
$clause = " ( {$clause} ) ";
}
if (!$isFirst && !empty($clause)) {
$clause = ' ' . $groupConjunction . ' ' . $clause;
}
} elseif (is_object($conditions) && $conditions instanceof xPDOQueryCondition) {
if ($isFirst) {
$conjunction = $conditions->conjunction;
} else {
$clause.= ' ' . $conditions->conjunction . ' ';
}
$clause.= $conditions->sql;
if (!empty ($conditions->binding)) {
$this->bindings[]= $conditions->binding;
}
}
if ($this->xpdo->getDebug() === true) {
$this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Returning clause:\n{$clause}\nfrom conditions:\n" . print_r($conditions, 1));
}
return $clause;
} | [
"public",
"function",
"buildConditionalClause",
"(",
"$",
"conditions",
",",
"&",
"$",
"conjunction",
"=",
"xPDOQuery",
"::",
"SQL_AND",
",",
"$",
"isFirst",
"=",
"true",
")",
"{",
"$",
"clause",
"=",
"''",
";",
"if",
"(",
"is_array",
"(",
"$",
"conditio... | Builds conditional clauses from xPDO condition expressions.
@param array|xPDOQueryCondition $conditions An array of conditions or an xPDOQueryCondition instance.
@param string $conjunction Either xPDOQuery:SQL_AND or xPDOQuery::SQL_OR
@param boolean $isFirst Indicates if this is the first condition in an array.
@return string The generated SQL clause. | [
"Builds",
"conditional",
"clauses",
"from",
"xPDO",
"condition",
"expressions",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L859-L899 | train |
modxcms/xpdo | src/xPDO/Om/xPDOQuery.php | xPDOQuery.wrap | public function wrap($criteria) {
if ($criteria instanceof xPDOQuery) {
$this->_class= $criteria->_class;
$this->_alias= $criteria->_alias;
$this->graph= $criteria->graph;
$this->query= $criteria->query;
}
$this->sql= $criteria->sql;
$this->stmt= $criteria->stmt;
$this->bindings= $criteria->bindings;
$this->cacheFlag= $criteria->cacheFlag;
} | php | public function wrap($criteria) {
if ($criteria instanceof xPDOQuery) {
$this->_class= $criteria->_class;
$this->_alias= $criteria->_alias;
$this->graph= $criteria->graph;
$this->query= $criteria->query;
}
$this->sql= $criteria->sql;
$this->stmt= $criteria->stmt;
$this->bindings= $criteria->bindings;
$this->cacheFlag= $criteria->cacheFlag;
} | [
"public",
"function",
"wrap",
"(",
"$",
"criteria",
")",
"{",
"if",
"(",
"$",
"criteria",
"instanceof",
"xPDOQuery",
")",
"{",
"$",
"this",
"->",
"_class",
"=",
"$",
"criteria",
"->",
"_class",
";",
"$",
"this",
"->",
"_alias",
"=",
"$",
"criteria",
... | Wrap an existing xPDOCriteria into this xPDOQuery instance.
@param xPDOCriteria|xPDOQuery $criteria | [
"Wrap",
"an",
"existing",
"xPDOCriteria",
"into",
"this",
"xPDOQuery",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOQuery.php#L906-L917 | train |
modxcms/xpdo | src/xPDO/xPDOConnection.php | xPDOConnection.connect | public function connect($driverOptions = array()) {
if ($this->pdo === null) {
if (is_array($driverOptions) && !empty($driverOptions)) {
$this->config['driverOptions']= array_merge($this->config['driverOptions'], $driverOptions);
}
try {
$this->pdo= new \PDO($this->config['dsn'], $this->config['username'], $this->config['password'], $this->config['driverOptions']);
} catch (\PDOException $xe) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $xe->getMessage(), '', __METHOD__, __FILE__, __LINE__);
return false;
} catch (\Exception $e) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage(), '', __METHOD__, __FILE__, __LINE__);
return false;
}
$connected= (is_object($this->pdo));
if ($connected) {
$connectFile = XPDO_CORE_PATH . 'om/' . $this->config['dbtype'] . '/connect.inc.php';
if (!empty($this->config['connect_file']) && file_exists($this->config['connect_file'])) {
$connectFile = $this->config['connect_file'];
}
if (file_exists($connectFile)) include ($connectFile);
}
if (!$connected) {
$this->pdo= null;
}
}
$connected= is_object($this->pdo);
return $connected;
} | php | public function connect($driverOptions = array()) {
if ($this->pdo === null) {
if (is_array($driverOptions) && !empty($driverOptions)) {
$this->config['driverOptions']= array_merge($this->config['driverOptions'], $driverOptions);
}
try {
$this->pdo= new \PDO($this->config['dsn'], $this->config['username'], $this->config['password'], $this->config['driverOptions']);
} catch (\PDOException $xe) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $xe->getMessage(), '', __METHOD__, __FILE__, __LINE__);
return false;
} catch (\Exception $e) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, $e->getMessage(), '', __METHOD__, __FILE__, __LINE__);
return false;
}
$connected= (is_object($this->pdo));
if ($connected) {
$connectFile = XPDO_CORE_PATH . 'om/' . $this->config['dbtype'] . '/connect.inc.php';
if (!empty($this->config['connect_file']) && file_exists($this->config['connect_file'])) {
$connectFile = $this->config['connect_file'];
}
if (file_exists($connectFile)) include ($connectFile);
}
if (!$connected) {
$this->pdo= null;
}
}
$connected= is_object($this->pdo);
return $connected;
} | [
"public",
"function",
"connect",
"(",
"$",
"driverOptions",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pdo",
"===",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"driverOptions",
")",
"&&",
"!",
"empty",
"(",
"$",
"driver... | Actually make a connection for this instance via PDO.
@param array $driverOptions An array of PDO driver options for the connection.
@return bool True if a successful connection is made. | [
"Actually",
"make",
"a",
"connection",
"for",
"this",
"instance",
"via",
"PDO",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDOConnection.php#L81-L110 | train |
modxcms/xpdo | src/xPDO/xPDOConnection.php | xPDOConnection.getOption | public function getOption($key, $options = null, $default = null) {
if (is_array($options)) {
$options = array_merge($this->config, $options);
} else {
$options = $this->config;
}
return $this->xpdo->getOption($key, $options, $default);
} | php | public function getOption($key, $options = null, $default = null) {
if (is_array($options)) {
$options = array_merge($this->config, $options);
} else {
$options = $this->config;
}
return $this->xpdo->getOption($key, $options, $default);
} | [
"public",
"function",
"getOption",
"(",
"$",
"key",
",",
"$",
"options",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"this",
"->",... | Get an option set for this xPDOConnection instance.
@param string $key The option key to get a value for.
@param array|null $options An optional array of options to consider.
@param mixed $default A default value to use if the option is not found.
@return mixed The option value. | [
"Get",
"an",
"option",
"set",
"for",
"this",
"xPDOConnection",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDOConnection.php#L120-L127 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.parseSignature | public static function parseSignature($signature) {
$exploded = explode('-', $signature);
$name = current($exploded);
$version = '';
$part = next($exploded);
while ($part !== false) {
$dotPos = strpos($part, '.');
if ($dotPos > 0 && is_numeric(substr($part, 0, $dotPos))) {
$version = $part;
while (($part = next($exploded)) !== false) {
$version .= '-' . $part;
}
break;
} else {
$name .= '-' . $part;
$part = next($exploded);
}
}
return array(
$name,
$version
);
} | php | public static function parseSignature($signature) {
$exploded = explode('-', $signature);
$name = current($exploded);
$version = '';
$part = next($exploded);
while ($part !== false) {
$dotPos = strpos($part, '.');
if ($dotPos > 0 && is_numeric(substr($part, 0, $dotPos))) {
$version = $part;
while (($part = next($exploded)) !== false) {
$version .= '-' . $part;
}
break;
} else {
$name .= '-' . $part;
$part = next($exploded);
}
}
return array(
$name,
$version
);
} | [
"public",
"static",
"function",
"parseSignature",
"(",
"$",
"signature",
")",
"{",
"$",
"exploded",
"=",
"explode",
"(",
"'-'",
",",
"$",
"signature",
")",
";",
"$",
"name",
"=",
"current",
"(",
"$",
"exploded",
")",
";",
"$",
"version",
"=",
"''",
"... | Parse the name and version from a package signature.
@static
@param string $signature The package signature to parse.
@return array An array with two elements containing the name and version respectively. | [
"Parse",
"the",
"name",
"and",
"version",
"from",
"a",
"package",
"signature",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L138-L160 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.compareSignature | public static function compareSignature($signature1, $signature2) {
$value = false;
$parsed1 = self::parseSignature($signature1);
$parsed2 = self::parseSignature($signature2);
if ($parsed1[0] === $parsed2[0]) {
$value = version_compare($parsed1[1], $parsed2[1]);
}
return $value;
} | php | public static function compareSignature($signature1, $signature2) {
$value = false;
$parsed1 = self::parseSignature($signature1);
$parsed2 = self::parseSignature($signature2);
if ($parsed1[0] === $parsed2[0]) {
$value = version_compare($parsed1[1], $parsed2[1]);
}
return $value;
} | [
"public",
"static",
"function",
"compareSignature",
"(",
"$",
"signature1",
",",
"$",
"signature2",
")",
"{",
"$",
"value",
"=",
"false",
";",
"$",
"parsed1",
"=",
"self",
"::",
"parseSignature",
"(",
"$",
"signature1",
")",
";",
"$",
"parsed2",
"=",
"se... | Compares two package versions by signature.
@static
@param string $signature1 A package signature.
@param string $signature2 Another package signature to compare.
@return bool|int Returns -1 if the first version is lower than the second, 0 if they
are equal, and 1 if the second is lower if the package names in the provided
signatures are equal; otherwise returns false. | [
"Compares",
"two",
"package",
"versions",
"by",
"signature",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L172-L180 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport._pack | public static function _pack(& $xpdo, $filename, $path, $source) {
$packed = false;
$packResults = false;
$errors = array();
if ($xpdo->getOption(xPDOTransport::ARCHIVE_WITH, null, 0) != xPDOTransport::ARCHIVE_WITH_PCLZIP && class_exists('ZipArchive')) {
if ($xpdo->getDebug() === true) {
$xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Using xPDOZip / native ZipArchive", null, __METHOD__, __FILE__, __LINE__);
}
$archive = new xPDOZip($xpdo, $filename, array(xPDOZip::CREATE => true, xPDOZip::OVERWRITE => true));
if ($archive) {
$packResults = $archive->pack("{$path}{$source}", array(xPDOZip::ZIP_TARGET => "{$source}/"));
$archive->close();
if (!$archive->hasError() && !empty($packResults)) {
$packed = true;
} else {
$errors = $archive->getErrors();
}
}
} elseif (class_exists('PclZip') || include(XPDO_CORE_PATH . 'Compression/pclzip.lib.php')) {
$archive = new \PclZip($filename);
if ($archive) {
$packResults = $archive->create("{$path}{$source}", PCLZIP_OPT_REMOVE_PATH, "{$path}");
if ($packResults) {
$packed = true;
} else {
$errors = $archive->errorInfo($xpdo->getDebug() === true);
}
}
}
if (!$packed) {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error packing {$path}{$source} to {$filename}: " . print_r($errors, true));
}
if ($xpdo->getDebug() === true) {
$xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Results of packing {$path}{$source} to {$filename}: " . print_r($packResults, true), null, __METHOD__, __FILE__, __LINE__);
}
return $packed;
} | php | public static function _pack(& $xpdo, $filename, $path, $source) {
$packed = false;
$packResults = false;
$errors = array();
if ($xpdo->getOption(xPDOTransport::ARCHIVE_WITH, null, 0) != xPDOTransport::ARCHIVE_WITH_PCLZIP && class_exists('ZipArchive')) {
if ($xpdo->getDebug() === true) {
$xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Using xPDOZip / native ZipArchive", null, __METHOD__, __FILE__, __LINE__);
}
$archive = new xPDOZip($xpdo, $filename, array(xPDOZip::CREATE => true, xPDOZip::OVERWRITE => true));
if ($archive) {
$packResults = $archive->pack("{$path}{$source}", array(xPDOZip::ZIP_TARGET => "{$source}/"));
$archive->close();
if (!$archive->hasError() && !empty($packResults)) {
$packed = true;
} else {
$errors = $archive->getErrors();
}
}
} elseif (class_exists('PclZip') || include(XPDO_CORE_PATH . 'Compression/pclzip.lib.php')) {
$archive = new \PclZip($filename);
if ($archive) {
$packResults = $archive->create("{$path}{$source}", PCLZIP_OPT_REMOVE_PATH, "{$path}");
if ($packResults) {
$packed = true;
} else {
$errors = $archive->errorInfo($xpdo->getDebug() === true);
}
}
}
if (!$packed) {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error packing {$path}{$source} to {$filename}: " . print_r($errors, true));
}
if ($xpdo->getDebug() === true) {
$xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Results of packing {$path}{$source} to {$filename}: " . print_r($packResults, true), null, __METHOD__, __FILE__, __LINE__);
}
return $packed;
} | [
"public",
"static",
"function",
"_pack",
"(",
"&",
"$",
"xpdo",
",",
"$",
"filename",
",",
"$",
"path",
",",
"$",
"source",
")",
"{",
"$",
"packed",
"=",
"false",
";",
"$",
"packResults",
"=",
"false",
";",
"$",
"errors",
"=",
"array",
"(",
")",
... | Pack the resources from path relative to source into an archive with filename.
@uses compression.xPDOZip OR compression.PclZip
@todo Refactor this to be implemented in a service class external to xPDOTransport.
@param xPDO &$xpdo A reference to an xPDO instance.
@param string $filename A valid zip archive filename.
@param string $path An absolute file system path location of the resources to pack.
@param string $source A relative portion of path to include in the archive.
@return boolean True if packed successfully. | [
"Pack",
"the",
"resources",
"from",
"path",
"relative",
"to",
"source",
"into",
"an",
"archive",
"with",
"filename",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L381-L417 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.writeManifest | public function writeManifest() {
$written = false;
if (!empty ($this->vehicles)) {
if (!empty($this->attributes['setup-options']) && is_array($this->attributes['setup-options'])) {
$cacheManager = $this->xpdo->getCacheManager();
$cacheManager->copyFile($this->attributes['setup-options']['source'],$this->path . $this->signature . '/setup-options.php');
$this->attributes['setup-options'] = $this->signature . '/setup-options.php';
}
$manifest = array(
xPDOTransport::MANIFEST_VERSION => $this->manifestVersion,
xPDOTransport::MANIFEST_ATTRIBUTES => $this->attributes,
xPDOTransport::MANIFEST_VEHICLES => $this->vehicles
);
$content = var_export($manifest, true);
$cacheManager = $this->xpdo->getCacheManager();
if ($content && $cacheManager) {
$fileName = $this->path . $this->signature . '/manifest.php';
$content = "<?php return {$content};";
if (!($written = $cacheManager->writeFile($fileName, $content))) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error writing manifest to ' . $fileName);
}
}
}
return $written;
} | php | public function writeManifest() {
$written = false;
if (!empty ($this->vehicles)) {
if (!empty($this->attributes['setup-options']) && is_array($this->attributes['setup-options'])) {
$cacheManager = $this->xpdo->getCacheManager();
$cacheManager->copyFile($this->attributes['setup-options']['source'],$this->path . $this->signature . '/setup-options.php');
$this->attributes['setup-options'] = $this->signature . '/setup-options.php';
}
$manifest = array(
xPDOTransport::MANIFEST_VERSION => $this->manifestVersion,
xPDOTransport::MANIFEST_ATTRIBUTES => $this->attributes,
xPDOTransport::MANIFEST_VEHICLES => $this->vehicles
);
$content = var_export($manifest, true);
$cacheManager = $this->xpdo->getCacheManager();
if ($content && $cacheManager) {
$fileName = $this->path . $this->signature . '/manifest.php';
$content = "<?php return {$content};";
if (!($written = $cacheManager->writeFile($fileName, $content))) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error writing manifest to ' . $fileName);
}
}
}
return $written;
} | [
"public",
"function",
"writeManifest",
"(",
")",
"{",
"$",
"written",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"vehicles",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'setup-options'"... | Write the package manifest file.
@return boolean Indicates if the manifest was successfully written. | [
"Write",
"the",
"package",
"manifest",
"file",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L424-L449 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.getDependencies | public function getDependencies(array $requires = array()) {
$requiresAttribute = $this->getAttribute('requires');
if (is_array($requiresAttribute)) {
$requires = array_merge($requiresAttribute, $requires);
}
return $requires;
} | php | public function getDependencies(array $requires = array()) {
$requiresAttribute = $this->getAttribute('requires');
if (is_array($requiresAttribute)) {
$requires = array_merge($requiresAttribute, $requires);
}
return $requires;
} | [
"public",
"function",
"getDependencies",
"(",
"array",
"$",
"requires",
"=",
"array",
"(",
")",
")",
"{",
"$",
"requiresAttribute",
"=",
"$",
"this",
"->",
"getAttribute",
"(",
"'requires'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"requiresAttribute",
"... | Get dependency requirements for this xPDOTransport.
@param array $requires An optional array of dependent package constraints
to override/supplement those specified in the package metadata.
@return array An array of dependency requirements for the package. | [
"Get",
"dependency",
"requirements",
"for",
"this",
"xPDOTransport",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L530-L536 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.checkPlatformDependencies | public static function checkPlatformDependencies($dependencies) {
if (is_array($dependencies)) {
foreach ($dependencies as $depName => $depRequire) {
switch ($depName) {
case 'php':
if (self::satisfies(PHP_VERSION, $depRequire)) {
unset($dependencies[$depName]);
}
break;
default:
break;
}
}
}
return $dependencies;
} | php | public static function checkPlatformDependencies($dependencies) {
if (is_array($dependencies)) {
foreach ($dependencies as $depName => $depRequire) {
switch ($depName) {
case 'php':
if (self::satisfies(PHP_VERSION, $depRequire)) {
unset($dependencies[$depName]);
}
break;
default:
break;
}
}
}
return $dependencies;
} | [
"public",
"static",
"function",
"checkPlatformDependencies",
"(",
"$",
"dependencies",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"dependencies",
")",
")",
"{",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"depName",
"=>",
"$",
"depRequire",
")",
"{",
"... | Check if any specified platform dependencies are satisfied.
@param array $dependencies An array of dependencies to test.
@return array An array containing any unsatisfied dependencies. | [
"Check",
"if",
"any",
"specified",
"platform",
"dependencies",
"are",
"satisfied",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L560-L575 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.satisfies | public static function satisfies($version, $constraint) {
$satisfied = false;
$constraint = trim($constraint);
if (substr($constraint, 0, 1) === '~') {
$requirement = substr($constraint, 1);
$constraint = ">={$requirement},<" . self::nextSignificantRelease($requirement);
}
if (strpos($constraint, ',') !== false) {
$exploded = explode(',', $constraint);
array_walk($exploded, 'trim');
$satisfies = array();
foreach ($exploded as $requirement) {
$satisfies[] = self::satisfies($version, $requirement);
}
$satisfied = (false === array_search(false, $satisfies, true));
} elseif (($wildcardPos = strpos($constraint, '.*')) > 0) {
$requirement = substr($constraint, 0, $wildcardPos + 1);
$requirements = array(
">=" . $requirement,
"<" . self::nextSignificantRelease($requirement)
);
$satisfies = array();
foreach ($requirements as $requires) {
$satisfies[] = self::satisfies($version, $requires);
}
$satisfied = (false === array_search(false, $satisfies, true));
} elseif (in_array(substr($constraint, 0, 1), array('<', '>', '!'))) {
$operator = substr($constraint, 0, 1);
$versionPos = 1;
if (substr($constraint, 1, 1) === '=') {
$operator .= substr($constraint, 1, 1);
$versionPos++;
}
$requirement = substr($constraint, $versionPos);
$satisfied = version_compare($version, $requirement, $operator);
} elseif ($constraint === '*') {
$satisfied = true;
} elseif (version_compare($version, $constraint) === 0) {
$satisfied = true;
}
return $satisfied;
} | php | public static function satisfies($version, $constraint) {
$satisfied = false;
$constraint = trim($constraint);
if (substr($constraint, 0, 1) === '~') {
$requirement = substr($constraint, 1);
$constraint = ">={$requirement},<" . self::nextSignificantRelease($requirement);
}
if (strpos($constraint, ',') !== false) {
$exploded = explode(',', $constraint);
array_walk($exploded, 'trim');
$satisfies = array();
foreach ($exploded as $requirement) {
$satisfies[] = self::satisfies($version, $requirement);
}
$satisfied = (false === array_search(false, $satisfies, true));
} elseif (($wildcardPos = strpos($constraint, '.*')) > 0) {
$requirement = substr($constraint, 0, $wildcardPos + 1);
$requirements = array(
">=" . $requirement,
"<" . self::nextSignificantRelease($requirement)
);
$satisfies = array();
foreach ($requirements as $requires) {
$satisfies[] = self::satisfies($version, $requires);
}
$satisfied = (false === array_search(false, $satisfies, true));
} elseif (in_array(substr($constraint, 0, 1), array('<', '>', '!'))) {
$operator = substr($constraint, 0, 1);
$versionPos = 1;
if (substr($constraint, 1, 1) === '=') {
$operator .= substr($constraint, 1, 1);
$versionPos++;
}
$requirement = substr($constraint, $versionPos);
$satisfied = version_compare($version, $requirement, $operator);
} elseif ($constraint === '*') {
$satisfied = true;
} elseif (version_compare($version, $constraint) === 0) {
$satisfied = true;
}
return $satisfied;
} | [
"public",
"static",
"function",
"satisfies",
"(",
"$",
"version",
",",
"$",
"constraint",
")",
"{",
"$",
"satisfied",
"=",
"false",
";",
"$",
"constraint",
"=",
"trim",
"(",
"$",
"constraint",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"constraint",
",",... | Test if a version satisfies a version constraint.
@param string $version The version to test.
@param string $constraint The constraint to satisfy.
@return bool TRUE if the version satisfies the constraint; FALSE otherwise. | [
"Test",
"if",
"a",
"version",
"satisfies",
"a",
"version",
"constraint",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L585-L626 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.nextSignificantRelease | public static function nextSignificantRelease($version) {
$parsed = explode('.', $version, 3);
if (count($parsed) > 1) array_pop($parsed);
$parsed[count($parsed) - 1]++;
if (count($parsed) === 1) $parsed[] = '0';
return implode('.', $parsed);
} | php | public static function nextSignificantRelease($version) {
$parsed = explode('.', $version, 3);
if (count($parsed) > 1) array_pop($parsed);
$parsed[count($parsed) - 1]++;
if (count($parsed) === 1) $parsed[] = '0';
return implode('.', $parsed);
} | [
"public",
"static",
"function",
"nextSignificantRelease",
"(",
"$",
"version",
")",
"{",
"$",
"parsed",
"=",
"explode",
"(",
"'.'",
",",
"$",
"version",
",",
"3",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parsed",
")",
">",
"1",
")",
"array_pop",
"(",... | Get the next significant release version for a given version string.
@param string $version A valid SemVer version string.
@return string The next significant version for the specified version. | [
"Get",
"the",
"next",
"significant",
"release",
"version",
"for",
"a",
"given",
"version",
"string",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L635-L641 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.retrieve | public static function retrieve(& $xpdo, $source, $target, $state= xPDOTransport::STATE_PACKED) {
$instance= null;
$signature = basename($source, '.transport.zip');
if (file_exists($source)) {
if (is_writable($target)) {
$manifest = xPDOTransport :: unpack($xpdo, $source, $target, $state);
if ($manifest) {
$instance = new xPDOTransport($xpdo, $signature, $target);
if (!$instance) {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not instantiate a valid xPDOTransport object from the package {$source} to {$target}. SIG: {$signature} MANIFEST: " . print_r($manifest, 1));
}
$manifestVersion = xPDOTransport :: manifestVersion($manifest);
switch ($manifestVersion) {
case '0.1':
$instance->vehicles = xPDOTransport :: _convertManifestVer1_1(xPDOTransport :: _convertManifestVer1_0($manifest));
case '0.2':
$instance->vehicles = xPDOTransport :: _convertManifestVer1_1(xPDOTransport :: _convertManifestVer1_0($manifest[xPDOTransport::MANIFEST_VEHICLES]));
$instance->attributes = $manifest[xPDOTransport::MANIFEST_ATTRIBUTES];
break;
case '1.0':
$instance->vehicles = xPDOTransport :: _convertManifestVer1_1($manifest[xPDOTransport::MANIFEST_VEHICLES]);
$instance->attributes = $manifest[xPDOTransport::MANIFEST_ATTRIBUTES];
break;
default:
$instance->vehicles = $manifest[xPDOTransport::MANIFEST_VEHICLES];
$instance->attributes = $manifest[xPDOTransport::MANIFEST_ATTRIBUTES];
break;
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not unpack package {$source} to {$target}. SIG: {$signature}");
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not unpack package: {$target} is not writable. SIG: {$signature}");
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Package {$source} not found. SIG: {$signature}");
}
return $instance;
} | php | public static function retrieve(& $xpdo, $source, $target, $state= xPDOTransport::STATE_PACKED) {
$instance= null;
$signature = basename($source, '.transport.zip');
if (file_exists($source)) {
if (is_writable($target)) {
$manifest = xPDOTransport :: unpack($xpdo, $source, $target, $state);
if ($manifest) {
$instance = new xPDOTransport($xpdo, $signature, $target);
if (!$instance) {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not instantiate a valid xPDOTransport object from the package {$source} to {$target}. SIG: {$signature} MANIFEST: " . print_r($manifest, 1));
}
$manifestVersion = xPDOTransport :: manifestVersion($manifest);
switch ($manifestVersion) {
case '0.1':
$instance->vehicles = xPDOTransport :: _convertManifestVer1_1(xPDOTransport :: _convertManifestVer1_0($manifest));
case '0.2':
$instance->vehicles = xPDOTransport :: _convertManifestVer1_1(xPDOTransport :: _convertManifestVer1_0($manifest[xPDOTransport::MANIFEST_VEHICLES]));
$instance->attributes = $manifest[xPDOTransport::MANIFEST_ATTRIBUTES];
break;
case '1.0':
$instance->vehicles = xPDOTransport :: _convertManifestVer1_1($manifest[xPDOTransport::MANIFEST_VEHICLES]);
$instance->attributes = $manifest[xPDOTransport::MANIFEST_ATTRIBUTES];
break;
default:
$instance->vehicles = $manifest[xPDOTransport::MANIFEST_VEHICLES];
$instance->attributes = $manifest[xPDOTransport::MANIFEST_ATTRIBUTES];
break;
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not unpack package {$source} to {$target}. SIG: {$signature}");
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not unpack package: {$target} is not writable. SIG: {$signature}");
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Package {$source} not found. SIG: {$signature}");
}
return $instance;
} | [
"public",
"static",
"function",
"retrieve",
"(",
"&",
"$",
"xpdo",
",",
"$",
"source",
",",
"$",
"target",
",",
"$",
"state",
"=",
"xPDOTransport",
"::",
"STATE_PACKED",
")",
"{",
"$",
"instance",
"=",
"null",
";",
"$",
"signature",
"=",
"basename",
"(... | Get an xPDOTransport instance from an existing package.
@param xPDO &$xpdo A reference to an xPDO instance.
@param string $source Path to the packed transport.
@param string $target Path to unpack the transport to.
@param int $state The packed state of the transport.
@return null|xPDOTransport An xPDOTransport instance or null. | [
"Get",
"an",
"xPDOTransport",
"instance",
"from",
"an",
"existing",
"package",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L653-L691 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.unpack | public static function unpack(& $xpdo, $from, $to, $state = xPDOTransport::STATE_PACKED) {
$manifest= null;
if ($state !== xPDOTransport::STATE_UNPACKED) {
$resources = xPDOTransport::_unpack($xpdo, $from, $to);
} else {
$resources = true;
}
if ($resources) {
$manifestFilename = $to . basename($from, '.transport.zip') . '/manifest.php';
if (file_exists($manifestFilename)) {
$manifest= @include ($manifestFilename);
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not find package manifest at {$manifestFilename}");
}
}
return $manifest;
} | php | public static function unpack(& $xpdo, $from, $to, $state = xPDOTransport::STATE_PACKED) {
$manifest= null;
if ($state !== xPDOTransport::STATE_UNPACKED) {
$resources = xPDOTransport::_unpack($xpdo, $from, $to);
} else {
$resources = true;
}
if ($resources) {
$manifestFilename = $to . basename($from, '.transport.zip') . '/manifest.php';
if (file_exists($manifestFilename)) {
$manifest= @include ($manifestFilename);
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not find package manifest at {$manifestFilename}");
}
}
return $manifest;
} | [
"public",
"static",
"function",
"unpack",
"(",
"&",
"$",
"xpdo",
",",
"$",
"from",
",",
"$",
"to",
",",
"$",
"state",
"=",
"xPDOTransport",
"::",
"STATE_PACKED",
")",
"{",
"$",
"manifest",
"=",
"null",
";",
"if",
"(",
"$",
"state",
"!==",
"xPDOTransp... | Unpack the package to prepare for installation and return a manifest.
@param xPDO &$xpdo A reference to an xPDO instance.
@param string $from Filename of the archive containing the transport package.
@param string $to The root path where the contents of the archive should be extracted. This
path must be writable by the user executing the PHP process on the server.
@param integer $state The current state of the package, i.e. packed or unpacked.
@return array The manifest which is included after successful extraction. | [
"Unpack",
"the",
"package",
"to",
"prepare",
"for",
"installation",
"and",
"return",
"a",
"manifest",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L717-L733 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport._unpack | public static function _unpack(& $xpdo, $from, $to) {
$resources = false;
if ($xpdo->getOption(xPDOTransport::ARCHIVE_WITH, null, 0) != xPDOTransport::ARCHIVE_WITH_PCLZIP && class_exists('ZipArchive')) {
$archive = new xPDOZip($xpdo, $from);
if ($archive) {
$resources = $archive->unpack($to);
$archive->close();
}
} elseif (class_exists('PclZip') || include(XPDO_CORE_PATH . 'Compression/pclzip.lib.php')) {
$archive = new \PclZip($from);
if ($archive) {
$resources = $archive->extract(PCLZIP_OPT_PATH, $to);
}
}
return $resources;
} | php | public static function _unpack(& $xpdo, $from, $to) {
$resources = false;
if ($xpdo->getOption(xPDOTransport::ARCHIVE_WITH, null, 0) != xPDOTransport::ARCHIVE_WITH_PCLZIP && class_exists('ZipArchive')) {
$archive = new xPDOZip($xpdo, $from);
if ($archive) {
$resources = $archive->unpack($to);
$archive->close();
}
} elseif (class_exists('PclZip') || include(XPDO_CORE_PATH . 'Compression/pclzip.lib.php')) {
$archive = new \PclZip($from);
if ($archive) {
$resources = $archive->extract(PCLZIP_OPT_PATH, $to);
}
}
return $resources;
} | [
"public",
"static",
"function",
"_unpack",
"(",
"&",
"$",
"xpdo",
",",
"$",
"from",
",",
"$",
"to",
")",
"{",
"$",
"resources",
"=",
"false",
";",
"if",
"(",
"$",
"xpdo",
"->",
"getOption",
"(",
"xPDOTransport",
"::",
"ARCHIVE_WITH",
",",
"null",
","... | Unpack a zip archive to a specified location.
@uses compression.xPDOZip OR compression.PclZip
@todo Refactor this to be implemented in a service class external to xPDOTransport.
@param xPDO &$xpdo A reference to an xPDO instance.
@param string $from An absolute file system location to a valid zip archive.
@param string $to A file system location to extract the contents of the archive to.
@return array|boolean An array of unpacked resources or false on failure. | [
"Unpack",
"a",
"zip",
"archive",
"to",
"a",
"specified",
"location",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L746-L761 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport.manifestVersion | public static function manifestVersion($manifest) {
$version = false;
if (is_array($manifest)) {
if (isset($manifest[xPDOTransport::MANIFEST_VERSION])) {
$version = $manifest[xPDOTransport::MANIFEST_VERSION];
}
elseif (isset($manifest[xPDOTransport::MANIFEST_VEHICLES])) {
$version = '0.2';
}
else {
$version = '0.1';
}
}
return $version;
} | php | public static function manifestVersion($manifest) {
$version = false;
if (is_array($manifest)) {
if (isset($manifest[xPDOTransport::MANIFEST_VERSION])) {
$version = $manifest[xPDOTransport::MANIFEST_VERSION];
}
elseif (isset($manifest[xPDOTransport::MANIFEST_VEHICLES])) {
$version = '0.2';
}
else {
$version = '0.1';
}
}
return $version;
} | [
"public",
"static",
"function",
"manifestVersion",
"(",
"$",
"manifest",
")",
"{",
"$",
"version",
"=",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"manifest",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"manifest",
"[",
"xPDOTransport",
"::",
"MAN... | Returns the structure version of the given manifest array.
@static
@param array $manifest A valid xPDOTransport manifest array.
@return string Version string of the manifest structure. | [
"Returns",
"the",
"structure",
"version",
"of",
"the",
"given",
"manifest",
"array",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L770-L784 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport._convertManifestVer1_0 | protected static function _convertManifestVer1_0($manifestVehicles) {
$manifest = array();
foreach ($manifestVehicles as $vClass => $vehicles) {
foreach ($vehicles as $vKey => $vehicle) {
$entry = array(
'class' => $vClass,
'native_key' => $vehicle['native_key'],
'filename' => $vehicle['filename'],
);
if (isset($vehicle['namespace'])) {
$entry['namespace'] = $vehicle['namespace'];
}
$manifest[] = $entry;
}
}
return $manifest;
} | php | protected static function _convertManifestVer1_0($manifestVehicles) {
$manifest = array();
foreach ($manifestVehicles as $vClass => $vehicles) {
foreach ($vehicles as $vKey => $vehicle) {
$entry = array(
'class' => $vClass,
'native_key' => $vehicle['native_key'],
'filename' => $vehicle['filename'],
);
if (isset($vehicle['namespace'])) {
$entry['namespace'] = $vehicle['namespace'];
}
$manifest[] = $entry;
}
}
return $manifest;
} | [
"protected",
"static",
"function",
"_convertManifestVer1_0",
"(",
"$",
"manifestVehicles",
")",
"{",
"$",
"manifest",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"manifestVehicles",
"as",
"$",
"vClass",
"=>",
"$",
"vehicles",
")",
"{",
"foreach",
"(",
... | Converts older manifest vehicles to 1.0 format.
@static
@access private
@param array $manifestVehicles A structure representing vehicles from a pre-1.0 manifest
format.
@return array Vehicle definition structures converted to 1.0 format. | [
"Converts",
"older",
"manifest",
"vehicles",
"to",
"1",
".",
"0",
"format",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L795-L811 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransport.php | xPDOTransport._convertManifestVer1_1 | protected static function _convertManifestVer1_1($vehicles) {
$manifest = array();
foreach ($vehicles as $vKey => $vehicle) {
$entry = $vehicle;
if (!isset($vehicle['vehicle_class'])) {
$entry['vehicle_class'] = 'xPDOObjectVehicle';
}
if (!isset($vehicle['vehicle_package'])) {
$entry['vehicle_package'] = 'transport';
}
$manifest[] = $entry;
}
return $manifest;
} | php | protected static function _convertManifestVer1_1($vehicles) {
$manifest = array();
foreach ($vehicles as $vKey => $vehicle) {
$entry = $vehicle;
if (!isset($vehicle['vehicle_class'])) {
$entry['vehicle_class'] = 'xPDOObjectVehicle';
}
if (!isset($vehicle['vehicle_package'])) {
$entry['vehicle_package'] = 'transport';
}
$manifest[] = $entry;
}
return $manifest;
} | [
"protected",
"static",
"function",
"_convertManifestVer1_1",
"(",
"$",
"vehicles",
")",
"{",
"$",
"manifest",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"vehicles",
"as",
"$",
"vKey",
"=>",
"$",
"vehicle",
")",
"{",
"$",
"entry",
"=",
"$",
"vehi... | Converts 1.0 manifest vehicles to 1.1 format.
@static
@access private
@param array $vehicles A structure representing vehicles from a pre-1.1 manifest format.
@return array Vehicle definition structures converted to 1.1 format. | [
"Converts",
"1",
".",
"0",
"manifest",
"vehicles",
"to",
"1",
".",
"1",
"format",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransport.php#L821-L834 | train |
modxcms/xpdo | src/xPDO/Om/xPDODriver.php | xPDODriver.getPhpType | public function getPhpType($dbtype) {
$phptype = 'string';
if ($dbtype !== null) {
foreach ($this->dbtypes as $type => $patterns) {
foreach ($patterns as $pattern) {
if (preg_match($pattern, $dbtype)) {
$phptype = $type;
break 2;
}
}
}
}
return $phptype;
} | php | public function getPhpType($dbtype) {
$phptype = 'string';
if ($dbtype !== null) {
foreach ($this->dbtypes as $type => $patterns) {
foreach ($patterns as $pattern) {
if (preg_match($pattern, $dbtype)) {
$phptype = $type;
break 2;
}
}
}
}
return $phptype;
} | [
"public",
"function",
"getPhpType",
"(",
"$",
"dbtype",
")",
"{",
"$",
"phptype",
"=",
"'string'",
";",
"if",
"(",
"$",
"dbtype",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dbtypes",
"as",
"$",
"type",
"=>",
"$",
"patterns",
")",
... | Gets the PHP field type based upon the specified database type.
@access public
@param string $dbtype The database field type to convert.
@return string The associated PHP type | [
"Gets",
"the",
"PHP",
"field",
"type",
"based",
"upon",
"the",
"specified",
"database",
"type",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDODriver.php#L75-L88 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOObjectVehicle.php | xPDOObjectVehicle.get | public function get(& $transport, $options = array (), $element = null) {
$object = null;
$element = parent :: get($transport, $options, $element);
if (isset ($element['class']) && isset ($element['object'])) {
$vClass = $element['class'];
if (!empty ($element['package'])) {
$pkgPrefix = $element['package'];
$pkgKeys = array_keys($transport->xpdo->packages);
if ($pkgFound = in_array($pkgPrefix, $pkgKeys)) {
$pkgPrefix = '';
}
elseif ($pos = strpos($pkgPrefix, '.')) {
$prefixParts = explode('.', $pkgPrefix);
$prefix = '';
foreach ($prefixParts as $prefixPart) {
$prefix .= $prefixPart;
$pkgPrefix = substr($pkgPrefix, $pos +1);
if ($pkgFound = in_array($prefix, $pkgKeys))
break;
$prefix .= '.';
$pos = strpos($pkgPrefix, '.');
}
if (!$pkgFound)
$pkgPrefix = $element['package'];
}
$vClass = (!empty ($pkgPrefix) ? $pkgPrefix . '.' : '') . $vClass;
}
$object = $transport->xpdo->newObject($vClass);
if (is_object($object) && $object instanceof xPDOObject) {
$options = array_merge($options, $element);
$setKeys = false;
if (isset ($options[xPDOTransport::PRESERVE_KEYS])) {
$setKeys = (boolean) $options[xPDOTransport::PRESERVE_KEYS];
}
$object->fromJSON($element['object'], '', $setKeys, true);
}
}
return $object;
} | php | public function get(& $transport, $options = array (), $element = null) {
$object = null;
$element = parent :: get($transport, $options, $element);
if (isset ($element['class']) && isset ($element['object'])) {
$vClass = $element['class'];
if (!empty ($element['package'])) {
$pkgPrefix = $element['package'];
$pkgKeys = array_keys($transport->xpdo->packages);
if ($pkgFound = in_array($pkgPrefix, $pkgKeys)) {
$pkgPrefix = '';
}
elseif ($pos = strpos($pkgPrefix, '.')) {
$prefixParts = explode('.', $pkgPrefix);
$prefix = '';
foreach ($prefixParts as $prefixPart) {
$prefix .= $prefixPart;
$pkgPrefix = substr($pkgPrefix, $pos +1);
if ($pkgFound = in_array($prefix, $pkgKeys))
break;
$prefix .= '.';
$pos = strpos($pkgPrefix, '.');
}
if (!$pkgFound)
$pkgPrefix = $element['package'];
}
$vClass = (!empty ($pkgPrefix) ? $pkgPrefix . '.' : '') . $vClass;
}
$object = $transport->xpdo->newObject($vClass);
if (is_object($object) && $object instanceof xPDOObject) {
$options = array_merge($options, $element);
$setKeys = false;
if (isset ($options[xPDOTransport::PRESERVE_KEYS])) {
$setKeys = (boolean) $options[xPDOTransport::PRESERVE_KEYS];
}
$object->fromJSON($element['object'], '', $setKeys, true);
}
}
return $object;
} | [
"public",
"function",
"get",
"(",
"&",
"$",
"transport",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"element",
"=",
"null",
")",
"{",
"$",
"object",
"=",
"null",
";",
"$",
"element",
"=",
"parent",
"::",
"get",
"(",
"$",
"transport",
... | Retrieve an xPDOObject instance represented in this vehicle.
This method returns the main object contained in the payload, but you can optionally specify
a related_objects node within the payload to retrieve a specific dependent object. | [
"Retrieve",
"an",
"xPDOObject",
"instance",
"represented",
"in",
"this",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOObjectVehicle.php#L31-L69 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOObjectVehicle.php | xPDOObjectVehicle.install | public function install(& $transport, $options) {
$parentObj = null;
$parentMeta = null;
$installed = $this->_installObject($transport, $options, $this->payload, $parentObj, $parentMeta);
return $installed;
} | php | public function install(& $transport, $options) {
$parentObj = null;
$parentMeta = null;
$installed = $this->_installObject($transport, $options, $this->payload, $parentObj, $parentMeta);
return $installed;
} | [
"public",
"function",
"install",
"(",
"&",
"$",
"transport",
",",
"$",
"options",
")",
"{",
"$",
"parentObj",
"=",
"null",
";",
"$",
"parentMeta",
"=",
"null",
";",
"$",
"installed",
"=",
"$",
"this",
"->",
"_installObject",
"(",
"$",
"transport",
",",... | Install the xPDOObjects represented by vehicle into the transport host. | [
"Install",
"the",
"xPDOObjects",
"represented",
"by",
"vehicle",
"into",
"the",
"transport",
"host",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOObjectVehicle.php#L74-L79 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOObjectVehicle.php | xPDOObjectVehicle._installRelated | public function _installRelated(& $transport, & $parent, $element, $options, $owner = '') {
$installed = true;
if ($parent instanceof xPDOObject && isset ($element[xPDOTransport::RELATED_OBJECTS]) && is_array($element[xPDOTransport::RELATED_OBJECTS])) {
foreach ($element[xPDOTransport::RELATED_OBJECTS] as $rAlias => $rVehicles) {
$rMeta = $parent->getFKDefinition($rAlias);
if ($rMeta) {
if (!empty($owner) && $owner !== $rMeta['owner']) continue;
$rOptions = $options;
if (isset($element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES])) {
if (isset($element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rAlias])) {
$rOptions = array_merge($rOptions, $element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rAlias]);
} elseif (isset($element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rMeta['class']])) {
$rOptions = array_merge($rOptions, $element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rMeta['class']]);
}
}
foreach ($rVehicles as $rKey => $rVehicle) {
$installed = $this->_installObject($transport, $rOptions, $rVehicle, $parent, $rMeta);
}
}
}
}
return $installed;
} | php | public function _installRelated(& $transport, & $parent, $element, $options, $owner = '') {
$installed = true;
if ($parent instanceof xPDOObject && isset ($element[xPDOTransport::RELATED_OBJECTS]) && is_array($element[xPDOTransport::RELATED_OBJECTS])) {
foreach ($element[xPDOTransport::RELATED_OBJECTS] as $rAlias => $rVehicles) {
$rMeta = $parent->getFKDefinition($rAlias);
if ($rMeta) {
if (!empty($owner) && $owner !== $rMeta['owner']) continue;
$rOptions = $options;
if (isset($element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES])) {
if (isset($element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rAlias])) {
$rOptions = array_merge($rOptions, $element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rAlias]);
} elseif (isset($element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rMeta['class']])) {
$rOptions = array_merge($rOptions, $element[xPDOTransport::RELATED_OBJECT_ATTRIBUTES][$rMeta['class']]);
}
}
foreach ($rVehicles as $rKey => $rVehicle) {
$installed = $this->_installObject($transport, $rOptions, $rVehicle, $parent, $rMeta);
}
}
}
}
return $installed;
} | [
"public",
"function",
"_installRelated",
"(",
"&",
"$",
"transport",
",",
"&",
"$",
"parent",
",",
"$",
"element",
",",
"$",
"options",
",",
"$",
"owner",
"=",
"''",
")",
"{",
"$",
"installed",
"=",
"true",
";",
"if",
"(",
"$",
"parent",
"instanceof"... | Installs a related object from the vehicle.
@param xPDOTransport &$transport
@param xPDOObject &$parent
@param array $element
@param array $options
@param string $owner
@return bool | [
"Installs",
"a",
"related",
"object",
"from",
"the",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOObjectVehicle.php#L243-L265 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOObjectVehicle.php | xPDOObjectVehicle._uninstallRelated | public function _uninstallRelated(& $transport, & $parent, $element, $options) {
$uninstalled = true;
if (is_object($parent) && isset ($element[xPDOTransport::RELATED_OBJECTS]) && is_array($element[xPDOTransport::RELATED_OBJECTS])) {
$uninstalled = false;
foreach ($element[xPDOTransport::RELATED_OBJECTS] as $rAlias => $rVehicles) {
$parentClass = $parent->_class;
$rMeta = $transport->xpdo->getFKDefinition($parentClass, $rAlias);
if ($rMeta) {
$results = array();
foreach ($rVehicles as $rKey => $rVehicle) {
$results[] = $this->_uninstallObject($transport, $options, $rVehicle, $parent, $rMeta);
}
$uninstalled = (array_search(false, $results) === false);
}
}
}
return $uninstalled;
} | php | public function _uninstallRelated(& $transport, & $parent, $element, $options) {
$uninstalled = true;
if (is_object($parent) && isset ($element[xPDOTransport::RELATED_OBJECTS]) && is_array($element[xPDOTransport::RELATED_OBJECTS])) {
$uninstalled = false;
foreach ($element[xPDOTransport::RELATED_OBJECTS] as $rAlias => $rVehicles) {
$parentClass = $parent->_class;
$rMeta = $transport->xpdo->getFKDefinition($parentClass, $rAlias);
if ($rMeta) {
$results = array();
foreach ($rVehicles as $rKey => $rVehicle) {
$results[] = $this->_uninstallObject($transport, $options, $rVehicle, $parent, $rMeta);
}
$uninstalled = (array_search(false, $results) === false);
}
}
}
return $uninstalled;
} | [
"public",
"function",
"_uninstallRelated",
"(",
"&",
"$",
"transport",
",",
"&",
"$",
"parent",
",",
"$",
"element",
",",
"$",
"options",
")",
"{",
"$",
"uninstalled",
"=",
"true",
";",
"if",
"(",
"is_object",
"(",
"$",
"parent",
")",
"&&",
"isset",
... | Uninstalls related objects from the vehicle. | [
"Uninstalls",
"related",
"objects",
"from",
"the",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOObjectVehicle.php#L360-L377 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOObjectVehicle.php | xPDOObjectVehicle._putRelated | protected function _putRelated(& $transport, $alias, & $object, & $payloadElement) {
if (is_array($payloadElement)) {
if (is_object($object) && $object instanceof xPDOObject) {
if (isset ($this->payload['related_object_attributes'][$alias]) && is_array($this->payload['related_object_attributes'][$alias])) {
$payloadElement = array_merge($payloadElement, $this->payload['related_object_attributes'][$alias]);
}
elseif (isset ($this->payload['related_object_attributes'][$object->_class]) && is_array($this->payload['related_object_attributes'][$object->_class])) {
$payloadElement = array_merge($payloadElement, $this->payload['related_object_attributes'][$object->_class]);
}
$payloadElement['class'] = $object->_class;
$nativeKey = $object->getPrimaryKey();
$payloadElement['object'] = $object->toJSON('', true);
$payloadElement['guid'] = md5(uniqid(rand(), true));
$payloadElement['native_key'] = $nativeKey;
$payloadElement['signature'] = md5($object->_class . '_' . $payloadElement['guid']);
$relatedObjects = array ();
foreach ($object->_relatedObjects as $rAlias => $related) {
if (is_array($related)) {
foreach ($related as $rKey => $rObj) {
if (!isset ($relatedObjects[$rAlias]))
$relatedObjects[$rAlias] = array ();
$guid = md5(uniqid(rand(), true));
$relatedObjects[$rAlias][$guid] = array ();
$this->_putRelated($transport, $rAlias, $rObj, $relatedObjects[$rAlias][$guid]);
}
}
elseif ($related instanceof xPDOObject) {
if (!isset ($relatedObjects[$rAlias]))
$relatedObjects[$rAlias] = array ();
$guid = md5(uniqid(rand(), true));
$relatedObjects[$rAlias][$guid] = array ();
$this->_putRelated($transport, $rAlias, $related, $relatedObjects[$rAlias][$guid]);
}
}
if (!empty ($relatedObjects))
$payloadElement['related_objects'] = $relatedObjects;
}
}
} | php | protected function _putRelated(& $transport, $alias, & $object, & $payloadElement) {
if (is_array($payloadElement)) {
if (is_object($object) && $object instanceof xPDOObject) {
if (isset ($this->payload['related_object_attributes'][$alias]) && is_array($this->payload['related_object_attributes'][$alias])) {
$payloadElement = array_merge($payloadElement, $this->payload['related_object_attributes'][$alias]);
}
elseif (isset ($this->payload['related_object_attributes'][$object->_class]) && is_array($this->payload['related_object_attributes'][$object->_class])) {
$payloadElement = array_merge($payloadElement, $this->payload['related_object_attributes'][$object->_class]);
}
$payloadElement['class'] = $object->_class;
$nativeKey = $object->getPrimaryKey();
$payloadElement['object'] = $object->toJSON('', true);
$payloadElement['guid'] = md5(uniqid(rand(), true));
$payloadElement['native_key'] = $nativeKey;
$payloadElement['signature'] = md5($object->_class . '_' . $payloadElement['guid']);
$relatedObjects = array ();
foreach ($object->_relatedObjects as $rAlias => $related) {
if (is_array($related)) {
foreach ($related as $rKey => $rObj) {
if (!isset ($relatedObjects[$rAlias]))
$relatedObjects[$rAlias] = array ();
$guid = md5(uniqid(rand(), true));
$relatedObjects[$rAlias][$guid] = array ();
$this->_putRelated($transport, $rAlias, $rObj, $relatedObjects[$rAlias][$guid]);
}
}
elseif ($related instanceof xPDOObject) {
if (!isset ($relatedObjects[$rAlias]))
$relatedObjects[$rAlias] = array ();
$guid = md5(uniqid(rand(), true));
$relatedObjects[$rAlias][$guid] = array ();
$this->_putRelated($transport, $rAlias, $related, $relatedObjects[$rAlias][$guid]);
}
}
if (!empty ($relatedObjects))
$payloadElement['related_objects'] = $relatedObjects;
}
}
} | [
"protected",
"function",
"_putRelated",
"(",
"&",
"$",
"transport",
",",
"$",
"alias",
",",
"&",
"$",
"object",
",",
"&",
"$",
"payloadElement",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"payloadElement",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
... | Recursively put related objects into the vehicle.
@access protected
@param xPDOTransport $transport The host xPDOTransport instance.
@param string $alias The alias representing the relation to the parent object.
@param xPDOObject &$object A reference to the dependent object being added into the vehicle.
@param array $payloadElement An element of the payload to place the dependent object in. | [
"Recursively",
"put",
"related",
"objects",
"into",
"the",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOObjectVehicle.php#L443-L481 | train |
modxcms/xpdo | src/xPDO/Om/xPDOCriteria.php | xPDOCriteria.equals | public function equals($obj) {
return (is_object($obj) && $obj instanceof xPDOCriteria && $this->sql === $obj->sql && !array_diff_assoc($this->bindings, $obj->bindings));
} | php | public function equals($obj) {
return (is_object($obj) && $obj instanceof xPDOCriteria && $this->sql === $obj->sql && !array_diff_assoc($this->bindings, $obj->bindings));
} | [
"public",
"function",
"equals",
"(",
"$",
"obj",
")",
"{",
"return",
"(",
"is_object",
"(",
"$",
"obj",
")",
"&&",
"$",
"obj",
"instanceof",
"xPDOCriteria",
"&&",
"$",
"this",
"->",
"sql",
"===",
"$",
"obj",
"->",
"sql",
"&&",
"!",
"array_diff_assoc",
... | Compares to see if two xPDOCriteria instances are the same.
@param object $obj A xPDOCriteria object to compare to this one.
@return boolean true if they are both equal is SQL and bindings, otherwise
false. | [
"Compares",
"to",
"see",
"if",
"two",
"xPDOCriteria",
"instances",
"are",
"the",
"same",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOCriteria.php#L113-L115 | train |
modxcms/xpdo | src/xPDO/Om/xPDOCriteria.php | xPDOCriteria.prepare | public function prepare($bindings= array (), $byValue= true, $cacheFlag= null) {
if ($this->stmt === null || !is_object($this->stmt)) {
if (!empty ($this->sql) && $stmt= $this->xpdo->prepare($this->sql)) {
$this->stmt= & $stmt;
$this->bind($bindings, $byValue, $cacheFlag);
}
}
return $this->stmt;
} | php | public function prepare($bindings= array (), $byValue= true, $cacheFlag= null) {
if ($this->stmt === null || !is_object($this->stmt)) {
if (!empty ($this->sql) && $stmt= $this->xpdo->prepare($this->sql)) {
$this->stmt= & $stmt;
$this->bind($bindings, $byValue, $cacheFlag);
}
}
return $this->stmt;
} | [
"public",
"function",
"prepare",
"(",
"$",
"bindings",
"=",
"array",
"(",
")",
",",
"$",
"byValue",
"=",
"true",
",",
"$",
"cacheFlag",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stmt",
"===",
"null",
"||",
"!",
"is_object",
"(",
"$",
... | Prepares the sql and bindings of this instance into a PDOStatement.
The {@link xPDOCriteria::$sql} attribute must be set in order to prepare
the statement. You can also pass bindings directly to this function and
they will be run through {@link xPDOCriteria::bind()} if the statement
is successfully prepared.
If the {@link xPDOCriteria::$stmt} already exists, it is simply returned.
@param array $bindings Bindings to merge with any existing bindings
defined for this xPDOCriteria instance. Bindings can be simple
associative array of key-value pairs or the value for each key can
contain elements titled value, type, and length corresponding to the
appropriate parameters in the PDOStatement::bindValue() and
PDOStatement::bindParam() functions.
@param boolean $byValue Determines if the $bindings are to be bound as
parameters (by variable reference, the default behavior) or by direct
value (if true).
@param boolean|integer $cacheFlag The cacheFlag indicates the cache state
of the xPDOCriteria object and can be absolutely off (false), absolutely
on (true), or an integer indicating the number of seconds the result will
live in the cache.
@return \PDOStatement The prepared statement, ready to execute. | [
"Prepares",
"the",
"sql",
"and",
"bindings",
"of",
"this",
"instance",
"into",
"a",
"PDOStatement",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOCriteria.php#L142-L150 | train |
modxcms/xpdo | src/xPDO/Om/xPDOCriteria.php | xPDOCriteria.toSQL | public function toSQL($parseBindings = true) {
$sql = $this->sql;
if ($parseBindings && !empty($this->bindings)) {
$sql = $this->xpdo->parseBindings($sql, $this->bindings);
}
return $sql;
} | php | public function toSQL($parseBindings = true) {
$sql = $this->sql;
if ($parseBindings && !empty($this->bindings)) {
$sql = $this->xpdo->parseBindings($sql, $this->bindings);
}
return $sql;
} | [
"public",
"function",
"toSQL",
"(",
"$",
"parseBindings",
"=",
"true",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"sql",
";",
"if",
"(",
"$",
"parseBindings",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"bindings",
")",
")",
"{",
"$",
"sql",
"... | Converts the current xPDOQuery to parsed SQL.
@param bool $parseBindings If true, bindings are parsed locally; otherwise
they are left in place.
@return string The parsed SQL query. | [
"Converts",
"the",
"current",
"xPDOQuery",
"to",
"parsed",
"SQL",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOCriteria.php#L159-L165 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransportVehicle.php | xPDOTransportVehicle._compilePayload | protected function _compilePayload(& $transport) {
parent :: _compilePayload($transport);
$body = array ();
$cacheManager = $transport->xpdo->getCacheManager();
if ($cacheManager) {
if (isset($this->payload['object'])) {
$object = $this->payload['object'];
$fileSource = $object['source'];
$body['source'] = $transport->signature . '/' . str_replace('\\', '/', $this->payload['class']) . '/' . $this->payload['signature'] . '/';
$fileTarget = $transport->path . $body['source'];
$body['target'] = $object['target'];
$fileName = isset ($object['name']) ? $object['name'] : basename($fileSource);
$body['name'] = $fileName;
if (!is_writable($fileTarget)) {
$cacheManager->writeTree($fileTarget);
}
if (file_exists($fileSource) && is_writable($fileTarget)) {
$copied = false;
if (is_file($fileSource)) {
$copied = $cacheManager->copyFile($fileSource, $fileTarget . $fileName);
}
if (!$copied) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not copy file from {$fileSource} to {$fileTarget}{$fileName}");
$body = null;
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} is not writable");
$body = null;
}
}
}
if (!empty($body)) {
$this->payload['object'] = $body;
}
} | php | protected function _compilePayload(& $transport) {
parent :: _compilePayload($transport);
$body = array ();
$cacheManager = $transport->xpdo->getCacheManager();
if ($cacheManager) {
if (isset($this->payload['object'])) {
$object = $this->payload['object'];
$fileSource = $object['source'];
$body['source'] = $transport->signature . '/' . str_replace('\\', '/', $this->payload['class']) . '/' . $this->payload['signature'] . '/';
$fileTarget = $transport->path . $body['source'];
$body['target'] = $object['target'];
$fileName = isset ($object['name']) ? $object['name'] : basename($fileSource);
$body['name'] = $fileName;
if (!is_writable($fileTarget)) {
$cacheManager->writeTree($fileTarget);
}
if (file_exists($fileSource) && is_writable($fileTarget)) {
$copied = false;
if (is_file($fileSource)) {
$copied = $cacheManager->copyFile($fileSource, $fileTarget . $fileName);
}
if (!$copied) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not copy file from {$fileSource} to {$fileTarget}{$fileName}");
$body = null;
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Source file {$fileSource} is missing or {$fileTarget} is not writable");
$body = null;
}
}
}
if (!empty($body)) {
$this->payload['object'] = $body;
}
} | [
"protected",
"function",
"_compilePayload",
"(",
"&",
"$",
"transport",
")",
"{",
"parent",
"::",
"_compilePayload",
"(",
"$",
"transport",
")",
";",
"$",
"body",
"=",
"array",
"(",
")",
";",
"$",
"cacheManager",
"=",
"$",
"transport",
"->",
"xpdo",
"->"... | Copies the transport into the vehicle and transforms the payload for storage. | [
"Copies",
"the",
"transport",
"into",
"the",
"vehicle",
"and",
"transforms",
"the",
"payload",
"for",
"storage",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransportVehicle.php#L27-L61 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOTransportVehicle.php | xPDOTransportVehicle._installTransport | protected function _installTransport(& $transport, $options) {
$installed = false;
$vOptions = $this->get($transport, $options);
if (isset($vOptions['object']) && isset($vOptions['object']['source']) && isset($vOptions['object']['target']) && isset($vOptions['object']['name'])) {
if ($transport->xpdo->getDebug() === true)
$transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Installing Vehicle: " . print_r($vOptions, true));
$state = isset($vOptions['state']) ? $vOptions['state'] : xPDOTransport::STATE_PACKED;
$pkgSource = $transport->path . $vOptions['object']['source'] . $vOptions['object']['name'];
$pkgTarget = eval($vOptions['object']['target']);
$object = xPDOTransport::retrieve($transport->xpdo, $pkgSource, $pkgTarget, $state);
if ($this->validate($transport, $object, $vOptions)) {
$installed = $object->install($vOptions);
if (!$installed) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error installing vehicle: ' . print_r($vOptions, true));
}
elseif (!$this->resolve($transport, $object, $vOptions)) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not resolve vehicle: ' . print_r($vOptions, true));
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not validate vehicle: ' . print_r($vOptions, true));
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not load vehicle: ' . print_r($vOptions, true));
}
return $installed;
} | php | protected function _installTransport(& $transport, $options) {
$installed = false;
$vOptions = $this->get($transport, $options);
if (isset($vOptions['object']) && isset($vOptions['object']['source']) && isset($vOptions['object']['target']) && isset($vOptions['object']['name'])) {
if ($transport->xpdo->getDebug() === true)
$transport->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Installing Vehicle: " . print_r($vOptions, true));
$state = isset($vOptions['state']) ? $vOptions['state'] : xPDOTransport::STATE_PACKED;
$pkgSource = $transport->path . $vOptions['object']['source'] . $vOptions['object']['name'];
$pkgTarget = eval($vOptions['object']['target']);
$object = xPDOTransport::retrieve($transport->xpdo, $pkgSource, $pkgTarget, $state);
if ($this->validate($transport, $object, $vOptions)) {
$installed = $object->install($vOptions);
if (!$installed) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Error installing vehicle: ' . print_r($vOptions, true));
}
elseif (!$this->resolve($transport, $object, $vOptions)) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not resolve vehicle: ' . print_r($vOptions, true));
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not validate vehicle: ' . print_r($vOptions, true));
}
} else {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not load vehicle: ' . print_r($vOptions, true));
}
return $installed;
} | [
"protected",
"function",
"_installTransport",
"(",
"&",
"$",
"transport",
",",
"$",
"options",
")",
"{",
"$",
"installed",
"=",
"false",
";",
"$",
"vOptions",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"transport",
",",
"$",
"options",
")",
";",
"if",
... | Install the xPDOTransport from the vehicle payload.
@param xPDOTransport $transport The host xPDOTransport instance.
@param array $options Any optional attributes to apply to the installation.
@return bool | [
"Install",
"the",
"xPDOTransport",
"from",
"the",
"vehicle",
"payload",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOTransportVehicle.php#L78-L103 | train |
modxcms/xpdo | src/xPDO/Validation/xPDOValidator.php | xPDOValidator.addMessage | public function addMessage($field, $name, $message= null) {
if (empty($message)) $message= $name;
array_push($this->messages, array(
'field' => $field,
'name' => $name,
'message' => $message,
));
} | php | public function addMessage($field, $name, $message= null) {
if (empty($message)) $message= $name;
array_push($this->messages, array(
'field' => $field,
'name' => $name,
'message' => $message,
));
} | [
"public",
"function",
"addMessage",
"(",
"$",
"field",
",",
"$",
"name",
",",
"$",
"message",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"message",
")",
")",
"$",
"message",
"=",
"$",
"name",
";",
"array_push",
"(",
"$",
"this",
"->",
"... | Add a validation message to the stack.
@param string $field The name of the field the message relates to.
@param string $name The name of the rule the message relates to.
@param mixed $message An optional message; the name of the rule is used
if no message is specified. | [
"Add",
"a",
"validation",
"message",
"to",
"the",
"stack",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Validation/xPDOValidator.php#L131-L138 | train |
modxcms/xpdo | src/xPDO/Compression/xPDOZip.php | xPDOZip.pack | public function pack($source, array $options = array()) {
$results = array();
if ($this->_archive) {
$target = $this->getOption(xPDOZip::ZIP_TARGET, $options, '');
if (is_dir($source)) {
if ($dh = opendir($source)) {
if ($source[strlen($source) - 1] !== '/') $source .= '/';
$targetDir = rtrim($target, '/');
if (!empty($targetDir)) {
if ($this->_archive->addEmptyDir($targetDir)) {
$results[$target] = "Successfully added directory {$target} from {$source}";
} else {
$results[$target] = "Error adding directory {$target} from {$source}";
$this->_errors[] = $results[$target];
}
}
while (($file = readdir($dh)) !== false) {
if (is_dir($source . $file)) {
if (($file !== '.') && ($file !== '..')) {
$results = $results + $this->pack($source . $file . '/', array_merge($options, array(xPDOZip::ZIP_TARGET => $target . $file . '/')));
}
} elseif (is_file($source . $file)) {
if ($this->_archive->addFile($source . $file, $target . $file)) {
$results[$target . $file] = "Successfully packed {$target}{$file} from {$source}{$file}";
} else {
$results[$target . $file] = "Error packing {$target}{$file} from {$source}{$file}";
$this->_errors[] = $results[$target . $file];
}
} else {
$results[$target . $file] = "Error packing {$target}{$file} from {$source}{$file}";
$this->_errors[] = $results[$target . $file];
}
}
}
} elseif (is_file($source)) {
$file = basename($source);
if ($this->_archive->addFile($source, $target . $file)) {
$results[$target . $file] = "Successfully packed {$target}{$file} from {$source}";
} else {
$results[$target . $file] = "Error packing {$target}{$file} from {$source}";
$this->_errors[] = $results[$target . $file];
}
} else {
$this->_errors[]= "Invalid source specified: {$source}";
}
}
return $results;
} | php | public function pack($source, array $options = array()) {
$results = array();
if ($this->_archive) {
$target = $this->getOption(xPDOZip::ZIP_TARGET, $options, '');
if (is_dir($source)) {
if ($dh = opendir($source)) {
if ($source[strlen($source) - 1] !== '/') $source .= '/';
$targetDir = rtrim($target, '/');
if (!empty($targetDir)) {
if ($this->_archive->addEmptyDir($targetDir)) {
$results[$target] = "Successfully added directory {$target} from {$source}";
} else {
$results[$target] = "Error adding directory {$target} from {$source}";
$this->_errors[] = $results[$target];
}
}
while (($file = readdir($dh)) !== false) {
if (is_dir($source . $file)) {
if (($file !== '.') && ($file !== '..')) {
$results = $results + $this->pack($source . $file . '/', array_merge($options, array(xPDOZip::ZIP_TARGET => $target . $file . '/')));
}
} elseif (is_file($source . $file)) {
if ($this->_archive->addFile($source . $file, $target . $file)) {
$results[$target . $file] = "Successfully packed {$target}{$file} from {$source}{$file}";
} else {
$results[$target . $file] = "Error packing {$target}{$file} from {$source}{$file}";
$this->_errors[] = $results[$target . $file];
}
} else {
$results[$target . $file] = "Error packing {$target}{$file} from {$source}{$file}";
$this->_errors[] = $results[$target . $file];
}
}
}
} elseif (is_file($source)) {
$file = basename($source);
if ($this->_archive->addFile($source, $target . $file)) {
$results[$target . $file] = "Successfully packed {$target}{$file} from {$source}";
} else {
$results[$target . $file] = "Error packing {$target}{$file} from {$source}";
$this->_errors[] = $results[$target . $file];
}
} else {
$this->_errors[]= "Invalid source specified: {$source}";
}
}
return $results;
} | [
"public",
"function",
"pack",
"(",
"$",
"source",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_archive",
")",
"{",
"$",
"target",
"=",
"$",
"this",
... | Pack the contents from the source into the archive.
@todo Implement custom file filtering options
@param string $source The path to the source file(s) to pack.
@param array $options An array of options for the operation.
@return array An array of results for the operation. | [
"Pack",
"the",
"contents",
"from",
"the",
"source",
"into",
"the",
"archive",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Compression/xPDOZip.php#L75-L122 | train |
modxcms/xpdo | src/xPDO/Compression/xPDOZip.php | xPDOZip.unpack | public function unpack($target, $options = array()) {
$results = false;
if ($this->_archive) {
if (is_dir($target) && is_writable($target)) {
$results = $this->_archive->extractTo($target);
}
}
return $results;
} | php | public function unpack($target, $options = array()) {
$results = false;
if ($this->_archive) {
if (is_dir($target) && is_writable($target)) {
$results = $this->_archive->extractTo($target);
}
}
return $results;
} | [
"public",
"function",
"unpack",
"(",
"$",
"target",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"results",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"_archive",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"target",
")",
"&&",
... | Unpack the compressed contents from the archive to the target.
@param string $target The path of the target location to unpack the files.
@param array $options An array of options for the operation.
@return array An array of results for the operation. | [
"Unpack",
"the",
"compressed",
"contents",
"from",
"the",
"archive",
"to",
"the",
"target",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Compression/xPDOZip.php#L131-L139 | train |
modxcms/xpdo | src/xPDO/Compression/xPDOZip.php | xPDOZip.getOption | public function getOption($key, $options = null, $default = null) {
$option = $default;
if (is_array($key)) {
if (!is_array($option)) {
$default= $option;
$option= array();
}
foreach ($key as $k) {
$option[$k]= $this->getOption($k, $options, $default);
}
} elseif (is_string($key) && !empty($key)) {
if (is_array($options) && !empty($options) && array_key_exists($key, $options)) {
$option = $options[$key];
} elseif (is_array($this->_options) && !empty($this->_options) && array_key_exists($key, $this->_options)) {
$option = $this->_options[$key];
} else {
$option = $this->xpdo->getOption($key, null, $default);
}
}
return $option;
} | php | public function getOption($key, $options = null, $default = null) {
$option = $default;
if (is_array($key)) {
if (!is_array($option)) {
$default= $option;
$option= array();
}
foreach ($key as $k) {
$option[$k]= $this->getOption($k, $options, $default);
}
} elseif (is_string($key) && !empty($key)) {
if (is_array($options) && !empty($options) && array_key_exists($key, $options)) {
$option = $options[$key];
} elseif (is_array($this->_options) && !empty($this->_options) && array_key_exists($key, $this->_options)) {
$option = $this->_options[$key];
} else {
$option = $this->xpdo->getOption($key, null, $default);
}
}
return $option;
} | [
"public",
"function",
"getOption",
"(",
"$",
"key",
",",
"$",
"options",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"option",
"=",
"$",
"default",
";",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"!",
"i... | Get an option from supplied options, the xPDOZip instance options, or xpdo itself.
@param string $key Unique identifier for the option.
@param array $options A set of explicit options to override those from xPDO or the
xPDOZip instance.
@param mixed $default An optional default value to return if no value is found.
@return mixed The value of the option. | [
"Get",
"an",
"option",
"from",
"supplied",
"options",
"the",
"xPDOZip",
"instance",
"options",
"or",
"xpdo",
"itself",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Compression/xPDOZip.php#L159-L179 | train |
yiisoft/yii-rest | src/Serializer.php | Serializer.addPaginationHeaders | protected function addPaginationHeaders($pagination)
{
$links = [];
foreach ($pagination->getLinks(true) as $rel => $url) {
$links[] = "<$url>; rel=$rel";
}
$this->response->setHeader($this->totalCountHeader, $pagination->totalCount);
$this->response->setHeader($this->pageCountHeader, $pagination->getPageCount());
$this->response->setHeader($this->currentPageHeader, $pagination->getPage() + 1);
$this->response->setHeader($this->perPageHeader, $pagination->pageSize);
$this->response->setHeader('Link', implode(', ', $links));
} | php | protected function addPaginationHeaders($pagination)
{
$links = [];
foreach ($pagination->getLinks(true) as $rel => $url) {
$links[] = "<$url>; rel=$rel";
}
$this->response->setHeader($this->totalCountHeader, $pagination->totalCount);
$this->response->setHeader($this->pageCountHeader, $pagination->getPageCount());
$this->response->setHeader($this->currentPageHeader, $pagination->getPage() + 1);
$this->response->setHeader($this->perPageHeader, $pagination->pageSize);
$this->response->setHeader('Link', implode(', ', $links));
} | [
"protected",
"function",
"addPaginationHeaders",
"(",
"$",
"pagination",
")",
"{",
"$",
"links",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"pagination",
"->",
"getLinks",
"(",
"true",
")",
"as",
"$",
"rel",
"=>",
"$",
"url",
")",
"{",
"$",
"links",
"[... | Adds HTTP headers about the pagination to the response.
@param Pagination $pagination | [
"Adds",
"HTTP",
"headers",
"about",
"the",
"pagination",
"to",
"the",
"response",
"."
] | 4f7d812ed077ed836bbf9ea8896e8b07543c5008 | https://github.com/yiisoft/yii-rest/blob/4f7d812ed077ed836bbf9ea8896e8b07543c5008/src/Serializer.php#L236-L248 | train |
yiisoft/yii-rest | src/OptionsAction.php | OptionsAction.run | public function run($id = null)
{
$app = $this->getApp();
if ($app->getRequest()->getMethod() !== 'OPTIONS') {
$app->getResponse()->setStatusCode(405);
}
$options = $id === null ? $this->collectionOptions : $this->resourceOptions;
$app->getResponse()->getHeaderCollection()->set('Allow', implode(', ', $options));
$app->getResponse()->getHeaderCollection()->set('Access-Control-Allow-Method', implode(', ', $options));
} | php | public function run($id = null)
{
$app = $this->getApp();
if ($app->getRequest()->getMethod() !== 'OPTIONS') {
$app->getResponse()->setStatusCode(405);
}
$options = $id === null ? $this->collectionOptions : $this->resourceOptions;
$app->getResponse()->getHeaderCollection()->set('Allow', implode(', ', $options));
$app->getResponse()->getHeaderCollection()->set('Access-Control-Allow-Method', implode(', ', $options));
} | [
"public",
"function",
"run",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"getApp",
"(",
")",
";",
"if",
"(",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"getMethod",
"(",
")",
"!==",
"'OPTIONS'",
")",
"{",
"$"... | Responds to the OPTIONS request.
@param string $id | [
"Responds",
"to",
"the",
"OPTIONS",
"request",
"."
] | 4f7d812ed077ed836bbf9ea8896e8b07543c5008 | https://github.com/yiisoft/yii-rest/blob/4f7d812ed077ed836bbf9ea8896e8b07543c5008/src/OptionsAction.php#L34-L43 | train |
webwizo/laravel-shortcodes | src/Compilers/ShortcodeCompiler.php | ShortcodeCompiler.compileShortcode | protected function compileShortcode($matches)
{
// Set matches
$this->setMatches($matches);
// pars the attributes
$attributes = $this->parseAttributes($this->matches[3]);
// return shortcode instance
return new Shortcode(
$this->getName(),
$attributes,
$this->getContent()
);
} | php | protected function compileShortcode($matches)
{
// Set matches
$this->setMatches($matches);
// pars the attributes
$attributes = $this->parseAttributes($this->matches[3]);
// return shortcode instance
return new Shortcode(
$this->getName(),
$attributes,
$this->getContent()
);
} | [
"protected",
"function",
"compileShortcode",
"(",
"$",
"matches",
")",
"{",
"// Set matches",
"$",
"this",
"->",
"setMatches",
"(",
"$",
"matches",
")",
";",
"// pars the attributes",
"$",
"attributes",
"=",
"$",
"this",
"->",
"parseAttributes",
"(",
"$",
"thi... | Get Compiled Attributes.
@param $matches
@return \Webwizo\Shortcodes\Shortcode | [
"Get",
"Compiled",
"Attributes",
"."
] | e76241c06ed284a15ac2740e8873787faae31f77 | https://github.com/webwizo/laravel-shortcodes/blob/e76241c06ed284a15ac2740e8873787faae31f77/src/Compilers/ShortcodeCompiler.php#L183-L196 | train |
webwizo/laravel-shortcodes | src/Compilers/ShortcodeCompiler.php | ShortcodeCompiler.parseAttributes | protected function parseAttributes($text)
{
// decode attribute values
$text = htmlspecialchars_decode($text, ENT_QUOTES);
$attributes = [];
// attributes pattern
$pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
// Match
if (preg_match_all($pattern, preg_replace('/[\x{00a0}\x{200b}]+/u', " ", $text), $match, PREG_SET_ORDER)) {
foreach ($match as $m) {
if (!empty($m[1])) {
$attributes[strtolower($m[1])] = stripcslashes($m[2]);
} elseif (!empty($m[3])) {
$attributes[strtolower($m[3])] = stripcslashes($m[4]);
} elseif (!empty($m[5])) {
$attributes[strtolower($m[5])] = stripcslashes($m[6]);
} elseif (isset($m[7]) && strlen($m[7])) {
$attributes[] = stripcslashes($m[7]);
} elseif (isset($m[8])) {
$attributes[] = stripcslashes($m[8]);
}
}
} else {
$attributes = ltrim($text);
}
// return attributes
return is_array($attributes) ? $attributes : [$attributes];
} | php | protected function parseAttributes($text)
{
// decode attribute values
$text = htmlspecialchars_decode($text, ENT_QUOTES);
$attributes = [];
// attributes pattern
$pattern = '/(\w+)\s*=\s*"([^"]*)"(?:\s|$)|(\w+)\s*=\s*\'([^\']*)\'(?:\s|$)|(\w+)\s*=\s*([^\s\'"]+)(?:\s|$)|"([^"]*)"(?:\s|$)|(\S+)(?:\s|$)/';
// Match
if (preg_match_all($pattern, preg_replace('/[\x{00a0}\x{200b}]+/u', " ", $text), $match, PREG_SET_ORDER)) {
foreach ($match as $m) {
if (!empty($m[1])) {
$attributes[strtolower($m[1])] = stripcslashes($m[2]);
} elseif (!empty($m[3])) {
$attributes[strtolower($m[3])] = stripcslashes($m[4]);
} elseif (!empty($m[5])) {
$attributes[strtolower($m[5])] = stripcslashes($m[6]);
} elseif (isset($m[7]) && strlen($m[7])) {
$attributes[] = stripcslashes($m[7]);
} elseif (isset($m[8])) {
$attributes[] = stripcslashes($m[8]);
}
}
} else {
$attributes = ltrim($text);
}
// return attributes
return is_array($attributes) ? $attributes : [$attributes];
} | [
"protected",
"function",
"parseAttributes",
"(",
"$",
"text",
")",
"{",
"// decode attribute values",
"$",
"text",
"=",
"htmlspecialchars_decode",
"(",
"$",
"text",
",",
"ENT_QUOTES",
")",
";",
"$",
"attributes",
"=",
"[",
"]",
";",
"// attributes pattern",
"$",... | Parse the shortcode attributes
@author Wordpress
@return array | [
"Parse",
"the",
"shortcode",
"attributes"
] | e76241c06ed284a15ac2740e8873787faae31f77 | https://github.com/webwizo/laravel-shortcodes/blob/e76241c06ed284a15ac2740e8873787faae31f77/src/Compilers/ShortcodeCompiler.php#L274-L303 | train |
webwizo/laravel-shortcodes | src/Compilers/Shortcode.php | Shortcode.get | public function get($attribute, $fallback = null)
{
$value = $this->{$attribute};
if (!is_null($value)) {
return $attribute . '="' . $value . '"';
} elseif (!is_null($fallback)) {
return $attribute . '="' . $fallback . '"';
}
} | php | public function get($attribute, $fallback = null)
{
$value = $this->{$attribute};
if (!is_null($value)) {
return $attribute . '="' . $value . '"';
} elseif (!is_null($fallback)) {
return $attribute . '="' . $fallback . '"';
}
} | [
"public",
"function",
"get",
"(",
"$",
"attribute",
",",
"$",
"fallback",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"{",
"$",
"attribute",
"}",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
... | Get html attribute
@param string $attribute
@return string|null | [
"Get",
"html",
"attribute"
] | e76241c06ed284a15ac2740e8873787faae31f77 | https://github.com/webwizo/laravel-shortcodes/blob/e76241c06ed284a15ac2740e8873787faae31f77/src/Compilers/Shortcode.php#L49-L57 | train |
webwizo/laravel-shortcodes | src/ShortcodesServiceProvider.php | ShortcodesServiceProvider.enableCompiler | public function enableCompiler()
{
// Check if the compiler is auto enabled
$state = $this->app['config']->get('laravel-shortcodes::enabled', false);
// Enable when needed
if ($state) {
$this->app['shortcode.compiler']->enable();
}
} | php | public function enableCompiler()
{
// Check if the compiler is auto enabled
$state = $this->app['config']->get('laravel-shortcodes::enabled', false);
// Enable when needed
if ($state) {
$this->app['shortcode.compiler']->enable();
}
} | [
"public",
"function",
"enableCompiler",
"(",
")",
"{",
"// Check if the compiler is auto enabled",
"$",
"state",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'laravel-shortcodes::enabled'",
",",
"false",
")",
";",
"// Enable when needed",
... | Enable the compiler. | [
"Enable",
"the",
"compiler",
"."
] | e76241c06ed284a15ac2740e8873787faae31f77 | https://github.com/webwizo/laravel-shortcodes/blob/e76241c06ed284a15ac2740e8873787faae31f77/src/ShortcodesServiceProvider.php#L24-L33 | train |
webwizo/laravel-shortcodes | src/ShortcodesServiceProvider.php | ShortcodesServiceProvider.registerView | public function registerView()
{
$finder = $this->app['view']->getFinder();
$this->app->singleton('view', function ($app) use ($finder) {
// Next we need to grab the engine resolver instance that will be used by the
// environment. The resolver will be used by an environment to get each of
// the various engine implementations such as plain PHP or Blade engine.
$resolver = $app['view.engine.resolver'];
$env = new Factory($resolver, $finder, $app['events'], $app['shortcode.compiler']);
// We will also set the container instance on this view environment since the
// view composers may be classes registered in the container, which allows
// for great testable, flexible composers for the application developer.
$env->setContainer($app);
$env->share('app', $app);
return $env;
});
} | php | public function registerView()
{
$finder = $this->app['view']->getFinder();
$this->app->singleton('view', function ($app) use ($finder) {
// Next we need to grab the engine resolver instance that will be used by the
// environment. The resolver will be used by an environment to get each of
// the various engine implementations such as plain PHP or Blade engine.
$resolver = $app['view.engine.resolver'];
$env = new Factory($resolver, $finder, $app['events'], $app['shortcode.compiler']);
// We will also set the container instance on this view environment since the
// view composers may be classes registered in the container, which allows
// for great testable, flexible composers for the application developer.
$env->setContainer($app);
$env->share('app', $app);
return $env;
});
} | [
"public",
"function",
"registerView",
"(",
")",
"{",
"$",
"finder",
"=",
"$",
"this",
"->",
"app",
"[",
"'view'",
"]",
"->",
"getFinder",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'view'",
",",
"function",
"(",
"$",
"app",
"... | Register Laravel view. | [
"Register",
"Laravel",
"view",
"."
] | e76241c06ed284a15ac2740e8873787faae31f77 | https://github.com/webwizo/laravel-shortcodes/blob/e76241c06ed284a15ac2740e8873787faae31f77/src/ShortcodesServiceProvider.php#L70-L89 | train |
stomp-php/stomp-php | src/Transport/FrameFactory.php | FrameFactory.createFrame | public function createFrame($command, array $headers, $body, $legacyMode)
{
foreach ($this->resolver as $resolver) {
if ($frame = $resolver($command, $headers, $body, $legacyMode)) {
return $frame;
}
}
return $this->defaultFrame($command, $headers, $body, $legacyMode);
} | php | public function createFrame($command, array $headers, $body, $legacyMode)
{
foreach ($this->resolver as $resolver) {
if ($frame = $resolver($command, $headers, $body, $legacyMode)) {
return $frame;
}
}
return $this->defaultFrame($command, $headers, $body, $legacyMode);
} | [
"public",
"function",
"createFrame",
"(",
"$",
"command",
",",
"array",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"legacyMode",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"resolver",
"as",
"$",
"resolver",
")",
"{",
"if",
"(",
"$",
"frame",
"=",
... | Creates a frame instance out of the given frame details.
@param string $command
@param array $headers
@param string $body
@param boolean $legacyMode stomp 1.0 mode (headers)
@return Frame | [
"Creates",
"a",
"frame",
"instance",
"out",
"of",
"the",
"given",
"frame",
"details",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/FrameFactory.php#L49-L57 | train |
stomp-php/stomp-php | src/Transport/FrameFactory.php | FrameFactory.defaultFrame | private function defaultFrame($command, array $headers, $body, $legacyMode)
{
$frame = new Frame($command, $headers, $body);
$frame->legacyMode($legacyMode);
return $frame;
} | php | private function defaultFrame($command, array $headers, $body, $legacyMode)
{
$frame = new Frame($command, $headers, $body);
$frame->legacyMode($legacyMode);
return $frame;
} | [
"private",
"function",
"defaultFrame",
"(",
"$",
"command",
",",
"array",
"$",
"headers",
",",
"$",
"body",
",",
"$",
"legacyMode",
")",
"{",
"$",
"frame",
"=",
"new",
"Frame",
"(",
"$",
"command",
",",
"$",
"headers",
",",
"$",
"body",
")",
";",
"... | Creates a new default frame instance.
@param string $command
@param array $headers
@param string $body
@param boolean $legacyMode
@return Frame | [
"Creates",
"a",
"new",
"default",
"frame",
"instance",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/FrameFactory.php#L68-L73 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.setWaitCallback | public function setWaitCallback($waitCallback)
{
if ($waitCallback !== null) {
if (!is_callable($waitCallback)) {
throw new \InvalidArgumentException('$waitCallback must be callable.');
}
}
$this->waitCallback = $waitCallback;
} | php | public function setWaitCallback($waitCallback)
{
if ($waitCallback !== null) {
if (!is_callable($waitCallback)) {
throw new \InvalidArgumentException('$waitCallback must be callable.');
}
}
$this->waitCallback = $waitCallback;
} | [
"public",
"function",
"setWaitCallback",
"(",
"$",
"waitCallback",
")",
"{",
"if",
"(",
"$",
"waitCallback",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"waitCallback",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
... | Sets a wait callback that will be invoked when the connection is waiting for new data.
This is a good place to call `pcntl_signal_dispatch()` if you need to ensure that your process signals in an
interval that is lower as read timeout. You should also return `false` in your callback if you don't want the
connection to continue waiting for data.
@param callable|null $waitCallback | [
"Sets",
"a",
"wait",
"callback",
"that",
"will",
"be",
"invoked",
"when",
"the",
"connection",
"is",
"waiting",
"for",
"new",
"data",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L202-L210 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.parseUrl | private function parseUrl($url)
{
$parsed = parse_url($url);
if ($parsed === false) {
throw new ConnectionException('Unable to parse url '. $url);
}
array_push($this->hosts, $parsed + ['port' => '61613', 'scheme' => 'tcp']);
} | php | private function parseUrl($url)
{
$parsed = parse_url($url);
if ($parsed === false) {
throw new ConnectionException('Unable to parse url '. $url);
}
array_push($this->hosts, $parsed + ['port' => '61613', 'scheme' => 'tcp']);
} | [
"private",
"function",
"parseUrl",
"(",
"$",
"url",
")",
"{",
"$",
"parsed",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"parsed",
"===",
"false",
")",
"{",
"throw",
"new",
"ConnectionException",
"(",
"'Unable to parse url '",
".",
"$",
... | Parse a broker URL
@param string $url Broker URL
@return void
@throws ConnectionException | [
"Parse",
"a",
"broker",
"URL"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L239-L246 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.getHostList | protected function getHostList()
{
$hosts = array_values($this->hosts);
if ($this->params['randomize']) {
shuffle($hosts);
}
return $hosts;
} | php | protected function getHostList()
{
$hosts = array_values($this->hosts);
if ($this->params['randomize']) {
shuffle($hosts);
}
return $hosts;
} | [
"protected",
"function",
"getHostList",
"(",
")",
"{",
"$",
"hosts",
"=",
"array_values",
"(",
"$",
"this",
"->",
"hosts",
")",
";",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'randomize'",
"]",
")",
"{",
"shuffle",
"(",
"$",
"hosts",
")",
";",
... | Get the host list.
@return array | [
"Get",
"the",
"host",
"list",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L366-L373 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.connectSocket | protected function connectSocket(array $host)
{
$this->activeHost = $host;
$errNo = null;
$errStr = null;
$context = stream_context_create($this->context);
$flags = STREAM_CLIENT_CONNECT;
if ($this->persistentConnection) {
$flags |= STREAM_CLIENT_PERSISTENT;
}
$socket = @stream_socket_client(
$host['scheme'] . '://' . $host['host'] . ':' . $host['port'],
$errNo,
$errStr,
$this->connectTimeout,
$flags,
$context
);
if (!is_resource($socket)) {
throw new ConnectionException(sprintf('Failed to connect. (%s: %s)', $errNo, $errStr), $host);
}
if (!@stream_set_blocking($socket, false)) {
throw new ConnectionException('Failed to set non blocking mode for stream.', $host);
}
$this->host = $host['host'];
return $socket;
} | php | protected function connectSocket(array $host)
{
$this->activeHost = $host;
$errNo = null;
$errStr = null;
$context = stream_context_create($this->context);
$flags = STREAM_CLIENT_CONNECT;
if ($this->persistentConnection) {
$flags |= STREAM_CLIENT_PERSISTENT;
}
$socket = @stream_socket_client(
$host['scheme'] . '://' . $host['host'] . ':' . $host['port'],
$errNo,
$errStr,
$this->connectTimeout,
$flags,
$context
);
if (!is_resource($socket)) {
throw new ConnectionException(sprintf('Failed to connect. (%s: %s)', $errNo, $errStr), $host);
}
if (!@stream_set_blocking($socket, false)) {
throw new ConnectionException('Failed to set non blocking mode for stream.', $host);
}
$this->host = $host['host'];
return $socket;
} | [
"protected",
"function",
"connectSocket",
"(",
"array",
"$",
"host",
")",
"{",
"$",
"this",
"->",
"activeHost",
"=",
"$",
"host",
";",
"$",
"errNo",
"=",
"null",
";",
"$",
"errStr",
"=",
"null",
";",
"$",
"context",
"=",
"stream_context_create",
"(",
"... | Try to connect to given host.
@param array $host
@return resource (stream)
@throws ConnectionException if connection setup fails | [
"Try",
"to",
"connect",
"to",
"given",
"host",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L382-L412 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.writeFrame | public function writeFrame(Frame $stompFrame)
{
if (!$this->isConnected()) {
throw new ConnectionException('Not connected to any server.', $this->activeHost);
}
$this->writeData($stompFrame, $this->writeTimeout);
$this->observers->sentFrame($stompFrame);
return true;
} | php | public function writeFrame(Frame $stompFrame)
{
if (!$this->isConnected()) {
throw new ConnectionException('Not connected to any server.', $this->activeHost);
}
$this->writeData($stompFrame, $this->writeTimeout);
$this->observers->sentFrame($stompFrame);
return true;
} | [
"public",
"function",
"writeFrame",
"(",
"Frame",
"$",
"stompFrame",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"throw",
"new",
"ConnectionException",
"(",
"'Not connected to any server.'",
",",
"$",
"this",
"->",
"active... | Write frame to server.
@param Frame $stompFrame
@return boolean
@throws ConnectionException | [
"Write",
"frame",
"to",
"server",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L447-L455 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.writeData | private function writeData($stompFrame, $timeout)
{
$data = (string) $stompFrame;
$offset = 0;
$size = strlen($data);
$lastByteTime = microtime(true);
do {
$written = @fwrite($this->connection, substr($data, $offset), $this->maxWriteBytes);
if ($written === false) {
throw new ConnectionException('Was not possible to write frame!', $this->activeHost);
}
if ($written > 0) {
// offset tracking
$offset += $written;
$lastByteTime = microtime(true);
} else {
// timeout tracking
if ((microtime(true) - $lastByteTime) > $timeout) {
throw new ConnectionException(
'Was not possible to write frame! Write operation timed out.',
$this->activeHost
);
}
}
// keep some time to breath
if ($written < $size) {
time_nanosleep(0, 2500000); // 2.5ms / 0.0025s
}
} while ($offset < $size);
} | php | private function writeData($stompFrame, $timeout)
{
$data = (string) $stompFrame;
$offset = 0;
$size = strlen($data);
$lastByteTime = microtime(true);
do {
$written = @fwrite($this->connection, substr($data, $offset), $this->maxWriteBytes);
if ($written === false) {
throw new ConnectionException('Was not possible to write frame!', $this->activeHost);
}
if ($written > 0) {
// offset tracking
$offset += $written;
$lastByteTime = microtime(true);
} else {
// timeout tracking
if ((microtime(true) - $lastByteTime) > $timeout) {
throw new ConnectionException(
'Was not possible to write frame! Write operation timed out.',
$this->activeHost
);
}
}
// keep some time to breath
if ($written < $size) {
time_nanosleep(0, 2500000); // 2.5ms / 0.0025s
}
} while ($offset < $size);
} | [
"private",
"function",
"writeData",
"(",
"$",
"stompFrame",
",",
"$",
"timeout",
")",
"{",
"$",
"data",
"=",
"(",
"string",
")",
"$",
"stompFrame",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"size",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"$",
"l... | Write passed data to the stream, respecting passed timeout.
@param Frame|string $stompFrame
@param float $timeout in seconds, supporting fractions
@throws ConnectionException | [
"Write",
"passed",
"data",
"to",
"the",
"stream",
"respecting",
"passed",
"timeout",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L464-L495 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.readFrame | public function readFrame()
{
// first we try to check the parser for any leftover frames
if ($frame = $this->parser->nextFrame()) {
return $this->onFrame($frame);
}
if (!$this->hasDataToRead()) {
return false;
}
do {
$read = @fread($this->connection, $this->maxReadBytes);
if ($read === false) {
throw new ConnectionException(sprintf('Was not possible to read data from stream.'), $this->activeHost);
}
// this can be caused by different events on the stream, ex. new data or any kind of signal
// it also happens when a ssl socket was closed on the other side... so we need to test
if ($read === '') {
$this->observers->emptyRead();
// again we give some time here
// as this path is most likely indicating that the socket is not working anymore
time_nanosleep(0, 5000000); // 5ms / 0.005s
return false;
}
$this->parser->addData($read);
if ($frame = $this->parser->nextFrame()) {
return $this->onFrame($frame);
}
} while ($this->isDataOnStream());
return false;
} | php | public function readFrame()
{
// first we try to check the parser for any leftover frames
if ($frame = $this->parser->nextFrame()) {
return $this->onFrame($frame);
}
if (!$this->hasDataToRead()) {
return false;
}
do {
$read = @fread($this->connection, $this->maxReadBytes);
if ($read === false) {
throw new ConnectionException(sprintf('Was not possible to read data from stream.'), $this->activeHost);
}
// this can be caused by different events on the stream, ex. new data or any kind of signal
// it also happens when a ssl socket was closed on the other side... so we need to test
if ($read === '') {
$this->observers->emptyRead();
// again we give some time here
// as this path is most likely indicating that the socket is not working anymore
time_nanosleep(0, 5000000); // 5ms / 0.005s
return false;
}
$this->parser->addData($read);
if ($frame = $this->parser->nextFrame()) {
return $this->onFrame($frame);
}
} while ($this->isDataOnStream());
return false;
} | [
"public",
"function",
"readFrame",
"(",
")",
"{",
"// first we try to check the parser for any leftover frames",
"if",
"(",
"$",
"frame",
"=",
"$",
"this",
"->",
"parser",
"->",
"nextFrame",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"onFrame",
"(",
"$",... | Try to read a frame from the server.
@return Frame|false when no frame to read
@throws ConnectionException
@throws ErrorFrameException | [
"Try",
"to",
"read",
"a",
"frame",
"from",
"the",
"server",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L504-L539 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.hasDataToRead | public function hasDataToRead()
{
if (!$this->isConnected()) {
throw new ConnectionException('Not connected to any server.', $this->activeHost);
}
$isDataInBuffer = $this->connectionHasDataToRead($this->readTimeout[0], $this->readTimeout[1]);
if (!$isDataInBuffer) {
$this->observers->emptyBuffer();
}
return $isDataInBuffer;
} | php | public function hasDataToRead()
{
if (!$this->isConnected()) {
throw new ConnectionException('Not connected to any server.', $this->activeHost);
}
$isDataInBuffer = $this->connectionHasDataToRead($this->readTimeout[0], $this->readTimeout[1]);
if (!$isDataInBuffer) {
$this->observers->emptyBuffer();
}
return $isDataInBuffer;
} | [
"public",
"function",
"hasDataToRead",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"throw",
"new",
"ConnectionException",
"(",
"'Not connected to any server.'",
",",
"$",
"this",
"->",
"activeHost",
")",
";",
"}",
"... | Check if connection has new data which can be read.
This might wait until readTimeout is reached.
@return boolean
@throws ConnectionException
@see Connection::setReadTimeout() | [
"Check",
"if",
"connection",
"has",
"new",
"data",
"which",
"can",
"be",
"read",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L565-L576 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.connectionHasDataToRead | private function connectionHasDataToRead($timeoutSec, $timeoutMicros)
{
$timeout = microtime(true) + $timeoutSec + ($timeoutMicros ? $timeoutMicros / 1000000 : 0);
while (($hasData = $this->isDataOnStream()) === false) {
if ($timeout < microtime(true)) {
return false;
}
if ($this->waitCallback) {
if (call_user_func($this->waitCallback) === false) {
return false;
}
}
$slept = time_nanosleep(0, 2500000); // 2.5ms / 0.0025s
if (\is_array($slept)) {
return false;
}
}
return $hasData === true;
} | php | private function connectionHasDataToRead($timeoutSec, $timeoutMicros)
{
$timeout = microtime(true) + $timeoutSec + ($timeoutMicros ? $timeoutMicros / 1000000 : 0);
while (($hasData = $this->isDataOnStream()) === false) {
if ($timeout < microtime(true)) {
return false;
}
if ($this->waitCallback) {
if (call_user_func($this->waitCallback) === false) {
return false;
}
}
$slept = time_nanosleep(0, 2500000); // 2.5ms / 0.0025s
if (\is_array($slept)) {
return false;
}
}
return $hasData === true;
} | [
"private",
"function",
"connectionHasDataToRead",
"(",
"$",
"timeoutSec",
",",
"$",
"timeoutMicros",
")",
"{",
"$",
"timeout",
"=",
"microtime",
"(",
"true",
")",
"+",
"$",
"timeoutSec",
"+",
"(",
"$",
"timeoutMicros",
"?",
"$",
"timeoutMicros",
"/",
"100000... | See if the connection has data left.
If both timeout-parameters are set to 0, it will return immediately.
@param int $timeoutSec Second-timeout part
@param int $timeoutMicros Microsecond-timeout part
@return bool
@throws ConnectionException | [
"See",
"if",
"the",
"connection",
"has",
"data",
"left",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L588-L608 | train |
stomp-php/stomp-php | src/Network/Connection.php | Connection.isDataOnStream | private function isDataOnStream()
{
$read = [$this->connection];
$write = null;
$except = null;
$hasStreamInfo = @stream_select($read, $write, $except, 0);
if ($hasStreamInfo === false) {
// can return `false` if used in combination with `pcntl_signal` and lead to false errors here
$error = error_get_last();
if ($error && isset($error['message']) && stripos($error['message'], 'interrupted system call') === false) {
throw new ConnectionException(
'Check failed to determine if the socket is readable.',
$this->activeHost
);
}
return null;
}
return !empty($read);
} | php | private function isDataOnStream()
{
$read = [$this->connection];
$write = null;
$except = null;
$hasStreamInfo = @stream_select($read, $write, $except, 0);
if ($hasStreamInfo === false) {
// can return `false` if used in combination with `pcntl_signal` and lead to false errors here
$error = error_get_last();
if ($error && isset($error['message']) && stripos($error['message'], 'interrupted system call') === false) {
throw new ConnectionException(
'Check failed to determine if the socket is readable.',
$this->activeHost
);
}
return null;
}
return !empty($read);
} | [
"private",
"function",
"isDataOnStream",
"(",
")",
"{",
"$",
"read",
"=",
"[",
"$",
"this",
"->",
"connection",
"]",
";",
"$",
"write",
"=",
"null",
";",
"$",
"except",
"=",
"null",
";",
"$",
"hasStreamInfo",
"=",
"@",
"stream_select",
"(",
"$",
"rea... | Checks if there is readable data on the stream.
Will return true if data is available, false if no data is detected and null if the operation was interrupted.
@return bool|null
@throws ConnectionException | [
"Checks",
"if",
"there",
"is",
"readable",
"data",
"on",
"the",
"stream",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Connection.php#L618-L638 | train |
stomp-php/stomp-php | src/Protocol/Protocol.php | Protocol.getConnectFrame | final public function getConnectFrame(
$login = '',
$passcode = '',
array $versions = [],
$host = null,
$heartbeat = [0, 0]
) {
$frame = $this->createFrame('CONNECT');
$frame->legacyMode(true);
if ($login || $passcode) {
$frame->addHeaders(['login' => $login, 'passcode' => $passcode]);
}
if ($this->hasClientId()) {
$frame['client-id'] = $this->getClientId();
}
if (!empty($versions)) {
$frame['accept-version'] = implode(',', $versions);
}
$frame['host'] = $host;
$frame['heart-beat'] = $heartbeat[0] . ',' . $heartbeat[1];
return $frame;
} | php | final public function getConnectFrame(
$login = '',
$passcode = '',
array $versions = [],
$host = null,
$heartbeat = [0, 0]
) {
$frame = $this->createFrame('CONNECT');
$frame->legacyMode(true);
if ($login || $passcode) {
$frame->addHeaders(['login' => $login, 'passcode' => $passcode]);
}
if ($this->hasClientId()) {
$frame['client-id'] = $this->getClientId();
}
if (!empty($versions)) {
$frame['accept-version'] = implode(',', $versions);
}
$frame['host'] = $host;
$frame['heart-beat'] = $heartbeat[0] . ',' . $heartbeat[1];
return $frame;
} | [
"final",
"public",
"function",
"getConnectFrame",
"(",
"$",
"login",
"=",
"''",
",",
"$",
"passcode",
"=",
"''",
",",
"array",
"$",
"versions",
"=",
"[",
"]",
",",
"$",
"host",
"=",
"null",
",",
"$",
"heartbeat",
"=",
"[",
"0",
",",
"0",
"]",
")"... | Get the connect frame
@param string $login
@param string $passcode
@param array $versions
@param string $host
@param int[] $heartbeat
@return \Stomp\Transport\Frame | [
"Get",
"the",
"connect",
"frame"
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Protocol/Protocol.php#L70-L97 | train |
stomp-php/stomp-php | src/Protocol/Protocol.php | Protocol.getSubscribeFrame | public function getSubscribeFrame($destination, $subscriptionId = null, $ack = 'auto', $selector = null)
{
// validate ACK types per spec
// https://stomp.github.io/stomp-specification-1.0.html#frame-ACK
// https://stomp.github.io/stomp-specification-1.1.html#ACK
// https://stomp.github.io/stomp-specification-1.2.html#ACK
if ($this->hasVersion(Version::VERSION_1_1)) {
$validAcks = ['auto', 'client', 'client-individual'];
} else {
$validAcks = ['auto', 'client'];
}
if (!in_array($ack, $validAcks)) {
throw new StompException(
sprintf(
'"%s" is not a valid ack value for STOMP %s. A valid value is one of %s',
$ack,
$this->version,
implode(',', $validAcks)
)
);
}
$frame = $this->createFrame('SUBSCRIBE');
$frame['destination'] = $destination;
$frame['ack'] = $ack;
$frame['id'] = $subscriptionId;
$frame['selector'] = $selector;
return $frame;
} | php | public function getSubscribeFrame($destination, $subscriptionId = null, $ack = 'auto', $selector = null)
{
// validate ACK types per spec
// https://stomp.github.io/stomp-specification-1.0.html#frame-ACK
// https://stomp.github.io/stomp-specification-1.1.html#ACK
// https://stomp.github.io/stomp-specification-1.2.html#ACK
if ($this->hasVersion(Version::VERSION_1_1)) {
$validAcks = ['auto', 'client', 'client-individual'];
} else {
$validAcks = ['auto', 'client'];
}
if (!in_array($ack, $validAcks)) {
throw new StompException(
sprintf(
'"%s" is not a valid ack value for STOMP %s. A valid value is one of %s',
$ack,
$this->version,
implode(',', $validAcks)
)
);
}
$frame = $this->createFrame('SUBSCRIBE');
$frame['destination'] = $destination;
$frame['ack'] = $ack;
$frame['id'] = $subscriptionId;
$frame['selector'] = $selector;
return $frame;
} | [
"public",
"function",
"getSubscribeFrame",
"(",
"$",
"destination",
",",
"$",
"subscriptionId",
"=",
"null",
",",
"$",
"ack",
"=",
"'auto'",
",",
"$",
"selector",
"=",
"null",
")",
"{",
"// validate ACK types per spec",
"// https://stomp.github.io/stomp-specification-... | Get subscribe frame.
@param string $destination
@param string $subscriptionId
@param string $ack
@param string $selector
@return \Stomp\Transport\Frame
@throws StompException; | [
"Get",
"subscribe",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Protocol/Protocol.php#L109-L138 | train |
stomp-php/stomp-php | src/Protocol/Protocol.php | Protocol.getUnsubscribeFrame | public function getUnsubscribeFrame($destination, $subscriptionId = null)
{
$frame = $this->createFrame('UNSUBSCRIBE');
$frame['destination'] = $destination;
$frame['id'] = $subscriptionId;
return $frame;
} | php | public function getUnsubscribeFrame($destination, $subscriptionId = null)
{
$frame = $this->createFrame('UNSUBSCRIBE');
$frame['destination'] = $destination;
$frame['id'] = $subscriptionId;
return $frame;
} | [
"public",
"function",
"getUnsubscribeFrame",
"(",
"$",
"destination",
",",
"$",
"subscriptionId",
"=",
"null",
")",
"{",
"$",
"frame",
"=",
"$",
"this",
"->",
"createFrame",
"(",
"'UNSUBSCRIBE'",
")",
";",
"$",
"frame",
"[",
"'destination'",
"]",
"=",
"$",... | Get unsubscribe frame.
@param string $destination
@param string $subscriptionId
@return \Stomp\Transport\Frame | [
"Get",
"unsubscribe",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Protocol/Protocol.php#L147-L153 | train |
stomp-php/stomp-php | src/Protocol/Protocol.php | Protocol.getNackFrame | public function getNackFrame(Frame $frame, $transactionId = null, $requeue = null)
{
if ($requeue !== null) {
throw new \LogicException('requeue header not supported');
}
if ($this->version === Version::VERSION_1_0) {
throw new StompException('Stomp Version 1.0 has no support for NACK Frames.');
}
$nack = $this->createFrame('NACK');
$nack['transaction'] = $transactionId;
if ($this->hasVersion(Version::VERSION_1_2)) {
$nack['id'] = $frame->getMessageId();
} else {
$nack['message-id'] = $frame->getMessageId();
if ($this->hasVersion(Version::VERSION_1_1)) {
$nack['subscription'] = $frame['subscription'];
}
}
$nack['message-id'] = $frame->getMessageId();
return $nack;
} | php | public function getNackFrame(Frame $frame, $transactionId = null, $requeue = null)
{
if ($requeue !== null) {
throw new \LogicException('requeue header not supported');
}
if ($this->version === Version::VERSION_1_0) {
throw new StompException('Stomp Version 1.0 has no support for NACK Frames.');
}
$nack = $this->createFrame('NACK');
$nack['transaction'] = $transactionId;
if ($this->hasVersion(Version::VERSION_1_2)) {
$nack['id'] = $frame->getMessageId();
} else {
$nack['message-id'] = $frame->getMessageId();
if ($this->hasVersion(Version::VERSION_1_1)) {
$nack['subscription'] = $frame['subscription'];
}
}
$nack['message-id'] = $frame->getMessageId();
return $nack;
} | [
"public",
"function",
"getNackFrame",
"(",
"Frame",
"$",
"frame",
",",
"$",
"transactionId",
"=",
"null",
",",
"$",
"requeue",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"requeue",
"!==",
"null",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'req... | Get message not acknowledge frame.
@param \Stomp\Transport\Frame $frame
@param string $transactionId
@param bool $requeue Requeue header
@return \Stomp\Transport\Frame
@throws StompException
@throws \LogicException | [
"Get",
"message",
"not",
"acknowledge",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Protocol/Protocol.php#L226-L247 | train |
stomp-php/stomp-php | src/Protocol/Protocol.php | Protocol.getDisconnectFrame | public function getDisconnectFrame()
{
$frame = $this->createFrame('DISCONNECT');
if ($this->hasClientId()) {
$frame['client-id'] = $this->getClientId();
}
return $frame;
} | php | public function getDisconnectFrame()
{
$frame = $this->createFrame('DISCONNECT');
if ($this->hasClientId()) {
$frame['client-id'] = $this->getClientId();
}
return $frame;
} | [
"public",
"function",
"getDisconnectFrame",
"(",
")",
"{",
"$",
"frame",
"=",
"$",
"this",
"->",
"createFrame",
"(",
"'DISCONNECT'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasClientId",
"(",
")",
")",
"{",
"$",
"frame",
"[",
"'client-id'",
"]",
"=",
... | Get the disconnect frame.
@return \Stomp\Transport\Frame | [
"Get",
"the",
"disconnect",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Protocol/Protocol.php#L254-L261 | train |
stomp-php/stomp-php | src/Protocol/Protocol.php | Protocol.createFrame | protected function createFrame($command)
{
$frame = new Frame($command);
if ($this->version === Version::VERSION_1_0) {
$frame->legacyMode(true);
}
return $frame;
} | php | protected function createFrame($command)
{
$frame = new Frame($command);
if ($this->version === Version::VERSION_1_0) {
$frame->legacyMode(true);
}
return $frame;
} | [
"protected",
"function",
"createFrame",
"(",
"$",
"command",
")",
"{",
"$",
"frame",
"=",
"new",
"Frame",
"(",
"$",
"command",
")",
";",
"if",
"(",
"$",
"this",
"->",
"version",
"===",
"Version",
"::",
"VERSION_1_0",
")",
"{",
"$",
"frame",
"->",
"le... | Creates a Frame according to the detected STOMP version.
@param string $command
@return Frame | [
"Creates",
"a",
"Frame",
"according",
"to",
"the",
"detected",
"STOMP",
"version",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Protocol/Protocol.php#L320-L329 | train |
stomp-php/stomp-php | src/Broker/Apollo/Apollo.php | Apollo.getSubscribeFrame | public function getSubscribeFrame(
$destination,
$subscriptionId = null,
$ack = 'auto',
$selector = null,
$durable = false
) {
$frame = parent::getSubscribeFrame($destination, $subscriptionId, $ack, $selector);
if ($this->hasClientId() && $durable) {
$frame['persistent'] = 'true';
}
return $frame;
} | php | public function getSubscribeFrame(
$destination,
$subscriptionId = null,
$ack = 'auto',
$selector = null,
$durable = false
) {
$frame = parent::getSubscribeFrame($destination, $subscriptionId, $ack, $selector);
if ($this->hasClientId() && $durable) {
$frame['persistent'] = 'true';
}
return $frame;
} | [
"public",
"function",
"getSubscribeFrame",
"(",
"$",
"destination",
",",
"$",
"subscriptionId",
"=",
"null",
",",
"$",
"ack",
"=",
"'auto'",
",",
"$",
"selector",
"=",
"null",
",",
"$",
"durable",
"=",
"false",
")",
"{",
"$",
"frame",
"=",
"parent",
":... | Apollo subscribe frame.
@param string $destination
@param string $subscriptionId
@param string $ack
@param string $selector
@param boolean $durable durable subscription
@return \Stomp\Transport\Frame | [
"Apollo",
"subscribe",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Broker/Apollo/Apollo.php#L34-L46 | train |
stomp-php/stomp-php | src/Broker/Apollo/Apollo.php | Apollo.getUnsubscribeFrame | public function getUnsubscribeFrame($destination, $subscriptionId = null, $durable = false)
{
$frame = parent::getUnsubscribeFrame($destination, $subscriptionId);
if ($durable) {
$frame['persistent'] = 'true';
}
return $frame;
} | php | public function getUnsubscribeFrame($destination, $subscriptionId = null, $durable = false)
{
$frame = parent::getUnsubscribeFrame($destination, $subscriptionId);
if ($durable) {
$frame['persistent'] = 'true';
}
return $frame;
} | [
"public",
"function",
"getUnsubscribeFrame",
"(",
"$",
"destination",
",",
"$",
"subscriptionId",
"=",
"null",
",",
"$",
"durable",
"=",
"false",
")",
"{",
"$",
"frame",
"=",
"parent",
"::",
"getUnsubscribeFrame",
"(",
"$",
"destination",
",",
"$",
"subscrip... | Apollo unsubscribe frame.
@param string $destination
@param string $subscriptionId
@param bool|false $durable
@return \Stomp\Transport\Frame | [
"Apollo",
"unsubscribe",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Broker/Apollo/Apollo.php#L56-L63 | train |
stomp-php/stomp-php | src/Network/Observer/HeartbeatEmitter.php | HeartbeatEmitter.onHeartbeatFrame | protected function onHeartbeatFrame(Frame $frame, array $beats)
{
if ($frame->getCommand() === self::FRAME_SERVER_CONNECTED) {
$this->intervalServer = $beats[1];
if ($this->intervalClient === null) {
$this->intervalClient = $this->intervalServer;
}
} else {
$this->intervalClient = $beats[0];
$this->rememberActivity();
}
} | php | protected function onHeartbeatFrame(Frame $frame, array $beats)
{
if ($frame->getCommand() === self::FRAME_SERVER_CONNECTED) {
$this->intervalServer = $beats[1];
if ($this->intervalClient === null) {
$this->intervalClient = $this->intervalServer;
}
} else {
$this->intervalClient = $beats[0];
$this->rememberActivity();
}
} | [
"protected",
"function",
"onHeartbeatFrame",
"(",
"Frame",
"$",
"frame",
",",
"array",
"$",
"beats",
")",
"{",
"if",
"(",
"$",
"frame",
"->",
"getCommand",
"(",
")",
"===",
"self",
"::",
"FRAME_SERVER_CONNECTED",
")",
"{",
"$",
"this",
"->",
"intervalServe... | A frame with heartbeat details was detected.
Class should set client or server interval.
@param Frame $frame
@param array $beats
@return void | [
"A",
"frame",
"with",
"heartbeat",
"details",
"was",
"detected",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/HeartbeatEmitter.php#L102-L113 | train |
stomp-php/stomp-php | src/Network/Observer/HeartbeatEmitter.php | HeartbeatEmitter.assertReadTimeoutSufficient | private function assertReadTimeoutSufficient($interval)
{
$readTimeout = $this->connection->getReadTimeout();
$readTimeoutMs = ($readTimeout[0] * 1000) + ($readTimeout[1] / 1000);
if ($interval < $readTimeoutMs) {
throw new HeartbeatException(
'Client heartbeat is lower than connection read timeout, causing failing heartbeats.'
);
}
} | php | private function assertReadTimeoutSufficient($interval)
{
$readTimeout = $this->connection->getReadTimeout();
$readTimeoutMs = ($readTimeout[0] * 1000) + ($readTimeout[1] / 1000);
if ($interval < $readTimeoutMs) {
throw new HeartbeatException(
'Client heartbeat is lower than connection read timeout, causing failing heartbeats.'
);
}
} | [
"private",
"function",
"assertReadTimeoutSufficient",
"(",
"$",
"interval",
")",
"{",
"$",
"readTimeout",
"=",
"$",
"this",
"->",
"connection",
"->",
"getReadTimeout",
"(",
")",
";",
"$",
"readTimeoutMs",
"=",
"(",
"$",
"readTimeout",
"[",
"0",
"]",
"*",
"... | Verify that the client configured heartbeats don't conflict with the connection read timeout.
@param float $interval
@return void | [
"Verify",
"that",
"the",
"client",
"configured",
"heartbeats",
"don",
"t",
"conflict",
"with",
"the",
"connection",
"read",
"timeout",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/HeartbeatEmitter.php#L134-L144 | train |
stomp-php/stomp-php | src/Network/Observer/HeartbeatEmitter.php | HeartbeatEmitter.onDelay | protected function onDelay()
{
try {
$this->connection->sendAlive($this->intervalClient / 1000);
} catch (ConnectionException $e) {
throw new HeartbeatException('Could not send heartbeat to server.', $e);
}
$this->rememberActivity();
} | php | protected function onDelay()
{
try {
$this->connection->sendAlive($this->intervalClient / 1000);
} catch (ConnectionException $e) {
throw new HeartbeatException('Could not send heartbeat to server.', $e);
}
$this->rememberActivity();
} | [
"protected",
"function",
"onDelay",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"connection",
"->",
"sendAlive",
"(",
"$",
"this",
"->",
"intervalClient",
"/",
"1000",
")",
";",
"}",
"catch",
"(",
"ConnectionException",
"$",
"e",
")",
"{",
"throw",
"... | Send a beat to the server.
@return void | [
"Send",
"a",
"beat",
"to",
"the",
"server",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Network/Observer/HeartbeatEmitter.php#L173-L181 | train |
stomp-php/stomp-php | src/Broker/Apollo/Mode/QueueBrowser.php | QueueBrowser.subscribe | public function subscribe()
{
if (!$this->active) {
$this->reachedEnd = false;
$this->client->sendFrame(
$this->getProtocol()->getSubscribeFrame(
$this->subscription->getDestination(),
$this->subscription->getSubscriptionId(),
$this->subscription->getAck(),
$this->subscription->getSelector(),
false
)->addHeaders($this->getHeader())
);
$this->active = true;
}
} | php | public function subscribe()
{
if (!$this->active) {
$this->reachedEnd = false;
$this->client->sendFrame(
$this->getProtocol()->getSubscribeFrame(
$this->subscription->getDestination(),
$this->subscription->getSubscriptionId(),
$this->subscription->getAck(),
$this->subscription->getSelector(),
false
)->addHeaders($this->getHeader())
);
$this->active = true;
}
} | [
"public",
"function",
"subscribe",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"active",
")",
"{",
"$",
"this",
"->",
"reachedEnd",
"=",
"false",
";",
"$",
"this",
"->",
"client",
"->",
"sendFrame",
"(",
"$",
"this",
"->",
"getProtocol",
"(",
... | Initialize subscription.
@return void | [
"Initialize",
"subscription",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Broker/Apollo/Mode/QueueBrowser.php#L99-L114 | train |
stomp-php/stomp-php | src/Broker/Apollo/Mode/QueueBrowser.php | QueueBrowser.read | public function read()
{
if (!$this->active || $this->reachedEnd) {
return false;
}
if ($frame = $this->client->readFrame()) {
if ($this->stopOnEnd && $frame['browser'] == 'end') {
$this->reachedEnd = true;
return false;
}
}
return $frame;
} | php | public function read()
{
if (!$this->active || $this->reachedEnd) {
return false;
}
if ($frame = $this->client->readFrame()) {
if ($this->stopOnEnd && $frame['browser'] == 'end') {
$this->reachedEnd = true;
return false;
}
}
return $frame;
} | [
"public",
"function",
"read",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"active",
"||",
"$",
"this",
"->",
"reachedEnd",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"frame",
"=",
"$",
"this",
"->",
"client",
"->",
"readFrame",
... | Read next message.
@return bool|false|\Stomp\Transport\Frame | [
"Read",
"next",
"message",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Broker/Apollo/Mode/QueueBrowser.php#L140-L152 | train |
stomp-php/stomp-php | src/Protocol/Version.php | Version.getProtocol | public function getProtocol($clientId, $default = 'ActiveMQ/5.11.1')
{
$server = trim($this->frame['server']) ?: $default;
$version = $this->getVersion();
if (stristr($server, 'rabbitmq') !== false) {
return new RabbitMq($clientId, $version, $server);
}
if (stristr($server, 'apache-apollo') !== false) {
return new Apollo($clientId, $version, $server);
}
if (stristr($server, 'activemq') !== false) {
return new ActiveMq($clientId, $version, $server);
}
if (stristr($server, 'open message queue') !== false) {
return new OpenMq($clientId, $version, $server);
}
return new Protocol($clientId, $version, $server);
} | php | public function getProtocol($clientId, $default = 'ActiveMQ/5.11.1')
{
$server = trim($this->frame['server']) ?: $default;
$version = $this->getVersion();
if (stristr($server, 'rabbitmq') !== false) {
return new RabbitMq($clientId, $version, $server);
}
if (stristr($server, 'apache-apollo') !== false) {
return new Apollo($clientId, $version, $server);
}
if (stristr($server, 'activemq') !== false) {
return new ActiveMq($clientId, $version, $server);
}
if (stristr($server, 'open message queue') !== false) {
return new OpenMq($clientId, $version, $server);
}
return new Protocol($clientId, $version, $server);
} | [
"public",
"function",
"getProtocol",
"(",
"$",
"clientId",
",",
"$",
"default",
"=",
"'ActiveMQ/5.11.1'",
")",
"{",
"$",
"server",
"=",
"trim",
"(",
"$",
"this",
"->",
"frame",
"[",
"'server'",
"]",
")",
"?",
":",
"$",
"default",
";",
"$",
"version",
... | Returns the protocol to use.
@param string $clientId
@param string $default server to use of no server detected
@return ActiveMq|Apollo|Protocol|RabbitMq | [
"Returns",
"the",
"protocol",
"to",
"use",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Protocol/Version.php#L70-L87 | train |
stomp-php/stomp-php | src/Broker/ActiveMq/ActiveMq.php | ActiveMq.getSubscribeFrame | public function getSubscribeFrame(
$destination,
$subscriptionId = null,
$ack = 'auto',
$selector = null,
$durable = false
) {
$frame = parent::getSubscribeFrame($destination, $subscriptionId, $ack, $selector);
$frame['activemq.prefetchSize'] = $this->prefetchSize;
if ($durable) {
$frame['activemq.subscriptionName'] = $this->getClientId();
}
return $frame;
} | php | public function getSubscribeFrame(
$destination,
$subscriptionId = null,
$ack = 'auto',
$selector = null,
$durable = false
) {
$frame = parent::getSubscribeFrame($destination, $subscriptionId, $ack, $selector);
$frame['activemq.prefetchSize'] = $this->prefetchSize;
if ($durable) {
$frame['activemq.subscriptionName'] = $this->getClientId();
}
return $frame;
} | [
"public",
"function",
"getSubscribeFrame",
"(",
"$",
"destination",
",",
"$",
"subscriptionId",
"=",
"null",
",",
"$",
"ack",
"=",
"'auto'",
",",
"$",
"selector",
"=",
"null",
",",
"$",
"durable",
"=",
"false",
")",
"{",
"$",
"frame",
"=",
"parent",
":... | ActiveMq subscribe frame.
@param string $destination
@param string $subscriptionId
@param string $ack
@param string $selector
@param boolean|false $durable durable subscription
@return Frame | [
"ActiveMq",
"subscribe",
"frame",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Broker/ActiveMq/ActiveMq.php#L45-L58 | train |
stomp-php/stomp-php | src/Transport/Parser.php | Parser.nextFrame | public function nextFrame()
{
if ($this->parse()) {
$frame = $this->getFrame();
$this->frame = null;
if ($this->observer) {
$this->observer->receivedFrame($frame);
}
return $frame;
}
return null;
} | php | public function nextFrame()
{
if ($this->parse()) {
$frame = $this->getFrame();
$this->frame = null;
if ($this->observer) {
$this->observer->receivedFrame($frame);
}
return $frame;
}
return null;
} | [
"public",
"function",
"nextFrame",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"parse",
"(",
")",
")",
"{",
"$",
"frame",
"=",
"$",
"this",
"->",
"getFrame",
"(",
")",
";",
"$",
"this",
"->",
"frame",
"=",
"null",
";",
"if",
"(",
"$",
"this",
... | Parse current buffer and return the next available frame, otherwise return null.
@return null|Frame | [
"Parse",
"current",
"buffer",
"and",
"return",
"the",
"next",
"available",
"frame",
"otherwise",
"return",
"null",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/Parser.php#L194-L205 | train |
stomp-php/stomp-php | src/Transport/Parser.php | Parser.parse | public function parse()
{
if ($this->buffer === '') {
return false;
}
$this->frame = null;
$this->offset = 0;
$this->bufferSize = strlen($this->buffer);
while ($this->offset < $this->bufferSize) {
if ($this->mode === self::MODE_HEADER) {
$this->skipEmptyLines();
if ($this->detectFrameHead()) {
$this->mode = self::MODE_BODY;
} else {
break;
}
}
if ($this->detectFrameEnd()) {
$this->mode = self::MODE_HEADER;
}
break;
}
if ($this->offset > 0) {
// remove parsed buffer
$this->buffer = substr($this->buffer, $this->offset);
}
return $this->frame !== null;
} | php | public function parse()
{
if ($this->buffer === '') {
return false;
}
$this->frame = null;
$this->offset = 0;
$this->bufferSize = strlen($this->buffer);
while ($this->offset < $this->bufferSize) {
if ($this->mode === self::MODE_HEADER) {
$this->skipEmptyLines();
if ($this->detectFrameHead()) {
$this->mode = self::MODE_BODY;
} else {
break;
}
}
if ($this->detectFrameEnd()) {
$this->mode = self::MODE_HEADER;
}
break;
}
if ($this->offset > 0) {
// remove parsed buffer
$this->buffer = substr($this->buffer, $this->offset);
}
return $this->frame !== null;
} | [
"public",
"function",
"parse",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"buffer",
"===",
"''",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"frame",
"=",
"null",
";",
"$",
"this",
"->",
"offset",
"=",
"0",
";",
"$",
"this",
"->... | Parse current buffer for frames.
@deprecated Will become private in next version. Please use nextFrame().
@return bool | [
"Parse",
"current",
"buffer",
"for",
"frames",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/Parser.php#L215-L243 | train |
stomp-php/stomp-php | src/Transport/Parser.php | Parser.detectFrameHead | private function detectFrameHead()
{
$firstCrLf = strpos($this->buffer, self::HEADER_STOP_CR_LF, $this->offset);
$firstLf = strpos($this->buffer, self::HEADER_STOP_LF, $this->offset);
// we need to use the first available marker, so we need to make sure that cr lf don't overrule lf
if ($firstCrLf !== false && ($firstLf === false || $firstLf > $firstCrLf)) {
$this->extractFrameMeta(substr($this->buffer, $this->offset, $firstCrLf - $this->offset));
$this->offset = $firstCrLf + strlen(self::HEADER_STOP_CR_LF);
return true;
}
if ($firstLf !== false) {
$this->extractFrameMeta(substr($this->buffer, $this->offset, $firstLf - $this->offset));
$this->offset = $firstLf + strlen(self::HEADER_STOP_LF);
return true;
}
return false;
} | php | private function detectFrameHead()
{
$firstCrLf = strpos($this->buffer, self::HEADER_STOP_CR_LF, $this->offset);
$firstLf = strpos($this->buffer, self::HEADER_STOP_LF, $this->offset);
// we need to use the first available marker, so we need to make sure that cr lf don't overrule lf
if ($firstCrLf !== false && ($firstLf === false || $firstLf > $firstCrLf)) {
$this->extractFrameMeta(substr($this->buffer, $this->offset, $firstCrLf - $this->offset));
$this->offset = $firstCrLf + strlen(self::HEADER_STOP_CR_LF);
return true;
}
if ($firstLf !== false) {
$this->extractFrameMeta(substr($this->buffer, $this->offset, $firstLf - $this->offset));
$this->offset = $firstLf + strlen(self::HEADER_STOP_LF);
return true;
}
return false;
} | [
"private",
"function",
"detectFrameHead",
"(",
")",
"{",
"$",
"firstCrLf",
"=",
"strpos",
"(",
"$",
"this",
"->",
"buffer",
",",
"self",
"::",
"HEADER_STOP_CR_LF",
",",
"$",
"this",
"->",
"offset",
")",
";",
"$",
"firstLf",
"=",
"strpos",
"(",
"$",
"th... | Detect frame header end marker, starting from current offset.
@return bool | [
"Detect",
"frame",
"header",
"end",
"marker",
"starting",
"from",
"current",
"offset",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/Parser.php#L270-L288 | train |
stomp-php/stomp-php | src/Transport/Parser.php | Parser.detectFrameEnd | private function detectFrameEnd()
{
$bodySize = null;
if ($this->expectedBodyLength) {
if (($this->bufferSize - $this->offset) >= $this->expectedBodyLength) {
$bodySize = $this->expectedBodyLength;
}
} elseif (($frameEnd = strpos($this->buffer, self::FRAME_END, $this->offset)) !== false) {
$bodySize = $frameEnd - $this->offset;
}
if ($bodySize !== null) {
$this->setFrame($bodySize);
$this->offset += $bodySize + strlen(self::FRAME_END); // x00
}
return $bodySize !== null;
} | php | private function detectFrameEnd()
{
$bodySize = null;
if ($this->expectedBodyLength) {
if (($this->bufferSize - $this->offset) >= $this->expectedBodyLength) {
$bodySize = $this->expectedBodyLength;
}
} elseif (($frameEnd = strpos($this->buffer, self::FRAME_END, $this->offset)) !== false) {
$bodySize = $frameEnd - $this->offset;
}
if ($bodySize !== null) {
$this->setFrame($bodySize);
$this->offset += $bodySize + strlen(self::FRAME_END); // x00
}
return $bodySize !== null;
} | [
"private",
"function",
"detectFrameEnd",
"(",
")",
"{",
"$",
"bodySize",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"expectedBodyLength",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"bufferSize",
"-",
"$",
"this",
"->",
"offset",
")",
">=",
"$"... | Detect frame end marker, starting from current offset.
@return bool | [
"Detect",
"frame",
"end",
"marker",
"starting",
"from",
"current",
"offset",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/Parser.php#L295-L311 | train |
stomp-php/stomp-php | src/Transport/Parser.php | Parser.setFrame | private function setFrame($bodySize)
{
$this->frame = $this->factory->createFrame(
$this->command,
$this->headers,
(string)substr($this->buffer, $this->offset, $bodySize),
$this->legacyMode
);
$this->expectedBodyLength = null;
$this->headers = [];
$this->mode = self::MODE_HEADER;
} | php | private function setFrame($bodySize)
{
$this->frame = $this->factory->createFrame(
$this->command,
$this->headers,
(string)substr($this->buffer, $this->offset, $bodySize),
$this->legacyMode
);
$this->expectedBodyLength = null;
$this->headers = [];
$this->mode = self::MODE_HEADER;
} | [
"private",
"function",
"setFrame",
"(",
"$",
"bodySize",
")",
"{",
"$",
"this",
"->",
"frame",
"=",
"$",
"this",
"->",
"factory",
"->",
"createFrame",
"(",
"$",
"this",
"->",
"command",
",",
"$",
"this",
"->",
"headers",
",",
"(",
"string",
")",
"sub... | Adds a frame from current known command, headers. Uses current offset and given body size.
@param integer $bodySize | [
"Adds",
"a",
"frame",
"from",
"current",
"known",
"command",
"headers",
".",
"Uses",
"current",
"offset",
"and",
"given",
"body",
"size",
"."
] | 4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158 | https://github.com/stomp-php/stomp-php/blob/4c5f0a95330085a86fd852b8ad0b1fbb4e8a4158/src/Transport/Parser.php#L319-L331 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.