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/xPDOGenerator.php | xPDOGenerator.getPlatformClass | public function getPlatformClass($domainClass) {
$relative = (strpos($domainClass, '\\') !== 0);
$exploded = explode('\\', ltrim($domainClass, '\\'));
$slice = array_slice($exploded, -1);
$class = $slice[0];
$namespace = implode('\\', array_slice($exploded, 0, -1));
if (!empty($namespace)) $namespace .= '\\';
if ($relative) {
$platformClass = "\\{$this->model['package']}\\{$namespace}{$this->model['platform']}\\{$class}";
} else {
$platformClass = "\\{$namespace}{$this->model['platform']}\\{$class}";
}
return $platformClass;
} | php | public function getPlatformClass($domainClass) {
$relative = (strpos($domainClass, '\\') !== 0);
$exploded = explode('\\', ltrim($domainClass, '\\'));
$slice = array_slice($exploded, -1);
$class = $slice[0];
$namespace = implode('\\', array_slice($exploded, 0, -1));
if (!empty($namespace)) $namespace .= '\\';
if ($relative) {
$platformClass = "\\{$this->model['package']}\\{$namespace}{$this->model['platform']}\\{$class}";
} else {
$platformClass = "\\{$namespace}{$this->model['platform']}\\{$class}";
}
return $platformClass;
} | [
"public",
"function",
"getPlatformClass",
"(",
"$",
"domainClass",
")",
"{",
"$",
"relative",
"=",
"(",
"strpos",
"(",
"$",
"domainClass",
",",
"'\\\\'",
")",
"!==",
"0",
")",
";",
"$",
"exploded",
"=",
"explode",
"(",
"'\\\\'",
",",
"ltrim",
"(",
"$",... | Get the platform class name of the specified domain class.
It should be relative to the current model namespace or absolute.
@param string $domainClass A domain class to get the platform class name from.
@return string The corresponding platform class name for the domain class. | [
"Get",
"the",
"platform",
"class",
"name",
"of",
"the",
"specified",
"domain",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOGenerator.php#L731-L744 | train |
modxcms/xpdo | src/xPDO/Om/xPDOManager.php | xPDOManager.getTransport | public function getTransport() {
if ($this->transport === null || !$this->transport instanceof xPDOTransport) {
$transportClass= $this->xpdo->getOption('xPDOTransport.class', null, 'xPDOTransport');
$this->transport= new $transportClass($this);
if ($this->transport === null || !$this->transport instanceof xPDOTransport) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not load xPDOTransport [{$transportClass}] class.");
}
}
return $this->transport;
} | php | public function getTransport() {
if ($this->transport === null || !$this->transport instanceof xPDOTransport) {
$transportClass= $this->xpdo->getOption('xPDOTransport.class', null, 'xPDOTransport');
$this->transport= new $transportClass($this);
if ($this->transport === null || !$this->transport instanceof xPDOTransport) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Could not load xPDOTransport [{$transportClass}] class.");
}
}
return $this->transport;
} | [
"public",
"function",
"getTransport",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"transport",
"===",
"null",
"||",
"!",
"$",
"this",
"->",
"transport",
"instanceof",
"xPDOTransport",
")",
"{",
"$",
"transportClass",
"=",
"$",
"this",
"->",
"xpdo",
"->"... | Gets a data transport mechanism for this xPDOManager instance.
@return xPDOTransport | [
"Gets",
"a",
"data",
"transport",
"mechanism",
"for",
"this",
"xPDOManager",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOManager.php#L192-L201 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCache.php | xPDOCache.getCacheKey | public function getCacheKey($key, $options = array()) {
$prefix = $this->getOption('cache_prefix', $options);
if (!empty($prefix)) $key = $prefix . $key;
$key = str_replace('\\', '/', $key);
return $this->key . '/' . $key;
} | php | public function getCacheKey($key, $options = array()) {
$prefix = $this->getOption('cache_prefix', $options);
if (!empty($prefix)) $key = $prefix . $key;
$key = str_replace('\\', '/', $key);
return $this->key . '/' . $key;
} | [
"public",
"function",
"getCacheKey",
"(",
"$",
"key",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"prefix",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'cache_prefix'",
",",
"$",
"options",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$"... | Get the actual cache key the implementation will use.
@param string $key The identifier the application uses.
@param array $options Additional options for the operation.
@return string The identifier with any implementation specific prefixes or other
transformations applied. | [
"Get",
"the",
"actual",
"cache",
"key",
"the",
"implementation",
"will",
"use",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCache.php#L81-L86 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOVehicle.php | xPDOVehicle.register | public function register(& $transport) {
$vPackage = isset($this->payload['vehicle_package']) ? $this->payload['vehicle_package'] : '';
$vClass = isset($this->payload['vehicle_class']) ? $this->payload['vehicle_class'] : $this->class;
$class = isset($this->payload['class']) ? $this->payload['class'] : $vClass;
$entry = array(
'vehicle_package' => $vPackage,
'vehicle_class' => $vClass,
'class' => $class,
'guid' => $this->payload['guid'],
'native_key' => array_key_exists('native_key', $this->payload) ? $this->payload['native_key'] : null,
'filename' => str_replace('\\', '/', $class) . '/' . $this->payload['filename'],
);
if (isset($this->payload['namespace'])) {
$entry['namespace'] = $this->payload['namespace'];
}
return $entry;
} | php | public function register(& $transport) {
$vPackage = isset($this->payload['vehicle_package']) ? $this->payload['vehicle_package'] : '';
$vClass = isset($this->payload['vehicle_class']) ? $this->payload['vehicle_class'] : $this->class;
$class = isset($this->payload['class']) ? $this->payload['class'] : $vClass;
$entry = array(
'vehicle_package' => $vPackage,
'vehicle_class' => $vClass,
'class' => $class,
'guid' => $this->payload['guid'],
'native_key' => array_key_exists('native_key', $this->payload) ? $this->payload['native_key'] : null,
'filename' => str_replace('\\', '/', $class) . '/' . $this->payload['filename'],
);
if (isset($this->payload['namespace'])) {
$entry['namespace'] = $this->payload['namespace'];
}
return $entry;
} | [
"public",
"function",
"register",
"(",
"&",
"$",
"transport",
")",
"{",
"$",
"vPackage",
"=",
"isset",
"(",
"$",
"this",
"->",
"payload",
"[",
"'vehicle_package'",
"]",
")",
"?",
"$",
"this",
"->",
"payload",
"[",
"'vehicle_package'",
"]",
":",
"''",
"... | Build a manifest entry to be registered in a transport for this vehicle.
@param xPDOTransport &$transport The xPDOTransport instance to register
the vehicle into.
@return array An array of vehicle attributes that will be registered into
an xPDOTransport manifest. | [
"Build",
"a",
"manifest",
"entry",
"to",
"be",
"registered",
"in",
"a",
"transport",
"for",
"this",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOVehicle.php#L44-L60 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOVehicle.php | xPDOVehicle.get | public function get(& $transport, $options = array (), $element = null) {
$artifact = null;
if ($element === null) $element = $this->payload;
$artifact = array_merge($options, $element);
return $artifact;
} | php | public function get(& $transport, $options = array (), $element = null) {
$artifact = null;
if ($element === null) $element = $this->payload;
$artifact = array_merge($options, $element);
return $artifact;
} | [
"public",
"function",
"get",
"(",
"&",
"$",
"transport",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"element",
"=",
"null",
")",
"{",
"$",
"artifact",
"=",
"null",
";",
"if",
"(",
"$",
"element",
"===",
"null",
")",
"$",
"element",
"=... | Retrieve an artifact represented in this vehicle.
By default, this method simply returns the raw payload merged with the
provided options, but you can optionally provide a payload element
specifically on which to operate as well as override the method in
derivatives to further transform the returned artifact.
@param xPDOTransport $transport The transport package containing this
vehicle.
@param array $options Options that apply to the artifact or retrieval
process.
@param array $element An optional payload element representing a specific
part of the artifact to operate on. If not specified, the root element
of the payload is used.
@return array | [
"Retrieve",
"an",
"artifact",
"represented",
"in",
"this",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOVehicle.php#L79-L84 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOVehicle.php | xPDOVehicle.validate | public function validate(& $transport, & $object, $options = array ()) {
$validated = true;
if (isset ($this->payload['validate'])) {
foreach ($this->payload['validate'] as $rKey => $r) {
$type = $r['type'];
$body = $r['body'];
switch ($type) {
case 'php' :
// if (isset ($options[xPDOTransport::VALIDATE_PHP]) && !$options[xPDOTransport::VALIDATE_PHP]) {
// continue;
// }
$fileMeta = $transport->xpdo->fromJSON($body, true);
$fileName = $fileMeta['name'];
$fileSource = $transport->path . $fileMeta['source'];
if (!$validated = include ($fileSource)) {
if (!isset($fileMeta['silent_fail']) || !$fileMeta['silent_fail']) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOVehicle validator failed: type php ({$fileSource})");
}
}
break;
default :
$transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support validators of type {$type}.");
break;
}
}
} else {
$validated = true;
}
return $validated;
} | php | public function validate(& $transport, & $object, $options = array ()) {
$validated = true;
if (isset ($this->payload['validate'])) {
foreach ($this->payload['validate'] as $rKey => $r) {
$type = $r['type'];
$body = $r['body'];
switch ($type) {
case 'php' :
// if (isset ($options[xPDOTransport::VALIDATE_PHP]) && !$options[xPDOTransport::VALIDATE_PHP]) {
// continue;
// }
$fileMeta = $transport->xpdo->fromJSON($body, true);
$fileName = $fileMeta['name'];
$fileSource = $transport->path . $fileMeta['source'];
if (!$validated = include ($fileSource)) {
if (!isset($fileMeta['silent_fail']) || !$fileMeta['silent_fail']) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOVehicle validator failed: type php ({$fileSource})");
}
}
break;
default :
$transport->xpdo->log(xPDO::LOG_LEVEL_WARN, "xPDOVehicle does not support validators of type {$type}.");
break;
}
}
} else {
$validated = true;
}
return $validated;
} | [
"public",
"function",
"validate",
"(",
"&",
"$",
"transport",
",",
"&",
"$",
"object",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"validated",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"payload",
"[",
"'validate... | Validate any dependencies for the object represented in this vehicle.
@param xPDOTransport &$transport A reference to the xPDOTransport in
which this vehicle is stored.
@param xPDOObject &$object An object reference to access during
validation.
@param array $options Additional options for the validation process.
@return boolean Indicating if the validation was successful. | [
"Validate",
"any",
"dependencies",
"for",
"the",
"object",
"represented",
"in",
"this",
"vehicle",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOVehicle.php#L242-L272 | train |
modxcms/xpdo | src/xPDO/Transport/xPDOVehicle.php | xPDOVehicle.store | public function store(& $transport) {
$stored = false;
$cacheManager = $transport->xpdo->getCacheManager();
if ($cacheManager && !empty ($this->payload)) {
$this->_compilePayload($transport);
$content = '<?php return ';
$content .= var_export($this->payload, true);
$content .= ';';
$this->payload['filename'] = $this->payload['signature'] . '.vehicle';
$vFileName = $transport->path . $transport->signature . '/' . str_replace('\\', '/', $this->payload['class']) . '/' . $this->payload['filename'];
if (!($stored = $cacheManager->writeFile($vFileName, $content))) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not store vehicle to file ' . $vFileName);
}
}
return $stored;
} | php | public function store(& $transport) {
$stored = false;
$cacheManager = $transport->xpdo->getCacheManager();
if ($cacheManager && !empty ($this->payload)) {
$this->_compilePayload($transport);
$content = '<?php return ';
$content .= var_export($this->payload, true);
$content .= ';';
$this->payload['filename'] = $this->payload['signature'] . '.vehicle';
$vFileName = $transport->path . $transport->signature . '/' . str_replace('\\', '/', $this->payload['class']) . '/' . $this->payload['filename'];
if (!($stored = $cacheManager->writeFile($vFileName, $content))) {
$transport->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not store vehicle to file ' . $vFileName);
}
}
return $stored;
} | [
"public",
"function",
"store",
"(",
"&",
"$",
"transport",
")",
"{",
"$",
"stored",
"=",
"false",
";",
"$",
"cacheManager",
"=",
"$",
"transport",
"->",
"xpdo",
"->",
"getCacheManager",
"(",
")",
";",
"if",
"(",
"$",
"cacheManager",
"&&",
"!",
"empty",... | Store this xPDOVehicle instance into an xPDOTransport.
@param xPDOTransport &$transport The transport to store the vehicle in.
@return boolean Indicates if the vehicle was stored in the transport. | [
"Store",
"this",
"xPDOVehicle",
"instance",
"into",
"an",
"xPDOTransport",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Transport/xPDOVehicle.php#L348-L364 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getInstance | public static function getInstance($id = null, $config = null, $forceNew = false) {
$instances =& self::$instances;
if (is_null($id)) {
if (!is_null($config) || $forceNew || empty($instances)) {
$id = uniqid(__CLASS__);
} else {
$id = key($instances);
}
}
if ($forceNew || !array_key_exists($id, $instances) || !($instances[$id] instanceof xPDO)) {
$instances[$id] = new xPDO(null, null, null, $config);
} elseif ($instances[$id] instanceof xPDO && is_array($config)) {
$instances[$id]->config = array_merge($instances[$id]->config, $config);
}
if (!($instances[$id] instanceof xPDO)) {
throw new xPDOException("Error getting " . __CLASS__ . " instance, id = {$id}");
}
return $instances[$id];
} | php | public static function getInstance($id = null, $config = null, $forceNew = false) {
$instances =& self::$instances;
if (is_null($id)) {
if (!is_null($config) || $forceNew || empty($instances)) {
$id = uniqid(__CLASS__);
} else {
$id = key($instances);
}
}
if ($forceNew || !array_key_exists($id, $instances) || !($instances[$id] instanceof xPDO)) {
$instances[$id] = new xPDO(null, null, null, $config);
} elseif ($instances[$id] instanceof xPDO && is_array($config)) {
$instances[$id]->config = array_merge($instances[$id]->config, $config);
}
if (!($instances[$id] instanceof xPDO)) {
throw new xPDOException("Error getting " . __CLASS__ . " instance, id = {$id}");
}
return $instances[$id];
} | [
"public",
"static",
"function",
"getInstance",
"(",
"$",
"id",
"=",
"null",
",",
"$",
"config",
"=",
"null",
",",
"$",
"forceNew",
"=",
"false",
")",
"{",
"$",
"instances",
"=",
"&",
"self",
"::",
"$",
"instances",
";",
"if",
"(",
"is_null",
"(",
"... | Create, retrieve, or update specific xPDO instances.
@param string|int|null $id An optional identifier for the instance. If not set
a uniqid will be generated and used as the key for the instance.
@param array|ContainerInterface|null $config An optional container or array of config data
for the instance.
@param bool $forceNew If true a new instance will be created even if an instance
with the provided $id already exists in xPDO::$instances.
@throws xPDOException If a valid instance is not retrieved.
@return xPDO An instance of xPDO. | [
"Create",
"retrieve",
"or",
"update",
"specific",
"xPDO",
"instances",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L223-L241 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.initConfig | protected function initConfig($data) {
if ($data instanceof ContainerInterface) {
$this->services = $data;
if ($this->services->has('config')) {
$data = $this->services->get('config');
}
}
if (!is_array($data)) {
$data = array(xPDO::OPT_TABLE_PREFIX => '');
}
return $data;
} | php | protected function initConfig($data) {
if ($data instanceof ContainerInterface) {
$this->services = $data;
if ($this->services->has('config')) {
$data = $this->services->get('config');
}
}
if (!is_array($data)) {
$data = array(xPDO::OPT_TABLE_PREFIX => '');
}
return $data;
} | [
"protected",
"function",
"initConfig",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"instanceof",
"ContainerInterface",
")",
"{",
"$",
"this",
"->",
"services",
"=",
"$",
"data",
";",
"if",
"(",
"$",
"this",
"->",
"services",
"->",
"has",
"(",
... | Initialize an xPDO config array.
@param ContainerInterface|array $data The config input source. Currently accepts a dependency
container that has a 'config' entry containing the xPDO configuration array, or an array
containing the configuration directly (deprecated).
@return array An array of xPDO config data. | [
"Initialize",
"an",
"xPDO",
"config",
"array",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L346-L358 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.addConnection | public function addConnection($dsn, $username= '', $password= '', array $options= array(), $driverOptions= null) {
$added = false;
$connection= new xPDOConnection($this, $dsn, $username, $password, $options, $driverOptions);
if ($connection instanceof xPDOConnection) {
$this->_connections[]= $connection;
$added= true;
}
return $added;
} | php | public function addConnection($dsn, $username= '', $password= '', array $options= array(), $driverOptions= null) {
$added = false;
$connection= new xPDOConnection($this, $dsn, $username, $password, $options, $driverOptions);
if ($connection instanceof xPDOConnection) {
$this->_connections[]= $connection;
$added= true;
}
return $added;
} | [
"public",
"function",
"addConnection",
"(",
"$",
"dsn",
",",
"$",
"username",
"=",
"''",
",",
"$",
"password",
"=",
"''",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"driverOptions",
"=",
"null",
")",
"{",
"$",
"added",
"=",
"fa... | Add an xPDOConnection instance to the xPDO connection pool.
@param string $dsn A PDO DSN representing the connection details.
@param string $username The username credentials for the connection.
@param string $password The password credentials for the connection.
@param array $options An array of options for the connection.
@param null $driverOptions An array of PDO driver options for the connection.
@return boolean True if a valid connection was added. | [
"Add",
"an",
"xPDOConnection",
"instance",
"to",
"the",
"xPDO",
"connection",
"pool",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L370-L378 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getConnection | public function getConnection(array $options = array()) {
$conn =& $this->connection;
$mutable = $this->getOption(xPDO::OPT_CONN_MUTABLE, $options, null);
if (!($conn instanceof xPDOConnection) || ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable())))) {
if (!empty($this->_connections)) {
shuffle($this->_connections);
$conn = reset($this->_connections);
while ($conn) {
if ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable()))) {
$conn = next($this->_connections);
continue;
}
$this->connection =& $conn;
break;
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not get a valid xPDOConnection", '', __METHOD__, __FILE__, __LINE__);
}
}
return $this->connection;
} | php | public function getConnection(array $options = array()) {
$conn =& $this->connection;
$mutable = $this->getOption(xPDO::OPT_CONN_MUTABLE, $options, null);
if (!($conn instanceof xPDOConnection) || ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable())))) {
if (!empty($this->_connections)) {
shuffle($this->_connections);
$conn = reset($this->_connections);
while ($conn) {
if ($mutable !== null && (($mutable == true && !$conn->isMutable()) || ($mutable == false && $conn->isMutable()))) {
$conn = next($this->_connections);
continue;
}
$this->connection =& $conn;
break;
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not get a valid xPDOConnection", '', __METHOD__, __FILE__, __LINE__);
}
}
return $this->connection;
} | [
"public",
"function",
"getConnection",
"(",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"conn",
"=",
"&",
"$",
"this",
"->",
"connection",
";",
"$",
"mutable",
"=",
"$",
"this",
"->",
"getOption",
"(",
"xPDO",
"::",
"OPT_CONN_MUTABL... | Get an xPDOConnection from the xPDO connection pool.
@param array $options An array of options for getting the connection.
@return xPDOConnection|null An xPDOConnection instance or null if no connection could be retrieved. | [
"Get",
"an",
"xPDOConnection",
"from",
"the",
"xPDO",
"connection",
"pool",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L386-L406 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.connect | public function connect($driverOptions= array (), array $options= array()) {
$connected = false;
$this->getConnection($options);
if ($this->connection instanceof xPDOConnection) {
$connected = $this->connection->connect($driverOptions);
if ($connected) {
$this->pdo =& $this->connection->pdo;
}
}
return $connected;
} | php | public function connect($driverOptions= array (), array $options= array()) {
$connected = false;
$this->getConnection($options);
if ($this->connection instanceof xPDOConnection) {
$connected = $this->connection->connect($driverOptions);
if ($connected) {
$this->pdo =& $this->connection->pdo;
}
}
return $connected;
} | [
"public",
"function",
"connect",
"(",
"$",
"driverOptions",
"=",
"array",
"(",
")",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"connected",
"=",
"false",
";",
"$",
"this",
"->",
"getConnection",
"(",
"$",
"options",
")",
";"... | Get or create a PDO connection to a database specified in the configuration.
@param array $driverOptions An optional array of driver options to use
when creating the connection.
@param array $options An array of xPDO options for the connection.
@return boolean Returns true if the PDO connection was created successfully. | [
"Get",
"or",
"create",
"a",
"PDO",
"connection",
"to",
"a",
"database",
"specified",
"in",
"the",
"configuration",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L416-L426 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.setPackage | public function setPackage($pkg= '', $path= '', $prefix= null) {
if (empty($path) && isset($this->packages[$pkg])) {
$path= $this->packages[$pkg]['path'];
$prefix= !is_string($prefix) && array_key_exists('prefix', $this->packages[$pkg]) ? $this->packages[$pkg]['prefix'] : $prefix;
}
$set= $this->addPackage($pkg, $path, $prefix);
$this->package= $set == true ? $pkg : $this->package;
if ($set && is_string($prefix)) $this->config[xPDO::OPT_TABLE_PREFIX]= $prefix;
return $set;
} | php | public function setPackage($pkg= '', $path= '', $prefix= null) {
if (empty($path) && isset($this->packages[$pkg])) {
$path= $this->packages[$pkg]['path'];
$prefix= !is_string($prefix) && array_key_exists('prefix', $this->packages[$pkg]) ? $this->packages[$pkg]['prefix'] : $prefix;
}
$set= $this->addPackage($pkg, $path, $prefix);
$this->package= $set == true ? $pkg : $this->package;
if ($set && is_string($prefix)) $this->config[xPDO::OPT_TABLE_PREFIX]= $prefix;
return $set;
} | [
"public",
"function",
"setPackage",
"(",
"$",
"pkg",
"=",
"''",
",",
"$",
"path",
"=",
"''",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"path",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"packages",
"[",
"$",
"pkg... | Sets a specific model package to use when looking up classes.
This package is of the form package.subpackage.subsubpackage and will be
added to the beginning of every xPDOObject class that is referenced in
xPDO methods such as {@link xPDO::loadClass()}, {@link xPDO::getObject()},
{@link xPDO::getCollection()}, {@link xPDOObject::getOne()}, {@link
xPDOObject::addOne()}, etc.
@param string $pkg A package name to use when looking up classes in xPDO.
@param string $path The root path for looking up classes in this package.
@param string|null $prefix Provide a string to define a package-specific table_prefix.
@return bool | [
"Sets",
"a",
"specific",
"model",
"package",
"to",
"use",
"when",
"looking",
"up",
"classes",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L442-L451 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getDescendants | public function getDescendants($className) {
$descendants = array();
if (isset($this->classMap[$className])) {
$descendants = $this->classMap[$className];
if ($descendants) {
foreach ($descendants as $descendant) {
$descendants = array_merge($descendants, $this->getDescendants($descendant));
}
}
}
return $descendants;
} | php | public function getDescendants($className) {
$descendants = array();
if (isset($this->classMap[$className])) {
$descendants = $this->classMap[$className];
if ($descendants) {
foreach ($descendants as $descendant) {
$descendants = array_merge($descendants, $this->getDescendants($descendant));
}
}
}
return $descendants;
} | [
"public",
"function",
"getDescendants",
"(",
"$",
"className",
")",
"{",
"$",
"descendants",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"classMap",
"[",
"$",
"className",
"]",
")",
")",
"{",
"$",
"descendants",
"=",
"$",... | Gets a list of derivative classes for the specified className.
The specified className must be xPDOObject or a derivative class.
@param string $className The name of the class to retrieve derivatives for.
@return array An array of derivative classes or an empty array. | [
"Gets",
"a",
"list",
"of",
"derivative",
"classes",
"for",
"the",
"specified",
"className",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L534-L545 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getOption | public function getOption($key, $options = null, $default = null, $skipEmpty = false) {
$option = null;
if (is_string($key) && !empty($key)) {
$found = false;
if (isset($options[$key])) {
$found = true;
$option = $options[$key];
}
if ((!$found || ($skipEmpty && $option === '')) && isset($this->config[$key])) {
$found = true;
$option = $this->config[$key];
}
if (!$found || ($skipEmpty && $option === ''))
$option = $default;
}
else if (is_array($key)) {
if (!is_array($option)) {
$default = $option;
$option = array();
}
foreach($key as $k) {
$option[$k] = $this->getOption($k, $options, $default);
}
}
else
$option = $default;
return $option;
} | php | public function getOption($key, $options = null, $default = null, $skipEmpty = false) {
$option = null;
if (is_string($key) && !empty($key)) {
$found = false;
if (isset($options[$key])) {
$found = true;
$option = $options[$key];
}
if ((!$found || ($skipEmpty && $option === '')) && isset($this->config[$key])) {
$found = true;
$option = $this->config[$key];
}
if (!$found || ($skipEmpty && $option === ''))
$option = $default;
}
else if (is_array($key)) {
if (!is_array($option)) {
$default = $option;
$option = array();
}
foreach($key as $k) {
$option[$k] = $this->getOption($k, $options, $default);
}
}
else
$option = $default;
return $option;
} | [
"public",
"function",
"getOption",
"(",
"$",
"key",
",",
"$",
"options",
"=",
"null",
",",
"$",
"default",
"=",
"null",
",",
"$",
"skipEmpty",
"=",
"false",
")",
"{",
"$",
"option",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
... | Get an xPDO configuration option value by key.
@param string $key The option key.
@param array|null $options A set of options to override those from xPDO.
@param mixed|null $default An optional default value to return if no value is found.
@param bool $skipEmpty True if empty string values should be ignored.
@return mixed The configuration option value. | [
"Get",
"an",
"xPDO",
"configuration",
"option",
"value",
"by",
"key",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L696-L726 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.call | public function call($class, $method, array $args = array(), $transient = false) {
$return = null;
$callback = '';
if ($transient) {
$className = $this->loadClass($class, '', false, true);
if ($className) {
$callback = array($className, $method);
}
} else {
$className = $this->loadClass($class);
if ($className) {
$className = $this->getPlatformClass($className);
$callback = array($className, $method);
}
}
if (!empty($callback) && is_callable($callback)) {
try {
$return = $className::$method(...$args);
} catch (\Exception $e) {
$this->log(xPDO::LOG_LEVEL_ERROR, "An exception occurred calling {$className}::{$method}() - " . $e->getMessage());
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "{$class}::{$method}() is not a valid static method.");
}
return $return;
} | php | public function call($class, $method, array $args = array(), $transient = false) {
$return = null;
$callback = '';
if ($transient) {
$className = $this->loadClass($class, '', false, true);
if ($className) {
$callback = array($className, $method);
}
} else {
$className = $this->loadClass($class);
if ($className) {
$className = $this->getPlatformClass($className);
$callback = array($className, $method);
}
}
if (!empty($callback) && is_callable($callback)) {
try {
$return = $className::$method(...$args);
} catch (\Exception $e) {
$this->log(xPDO::LOG_LEVEL_ERROR, "An exception occurred calling {$className}::{$method}() - " . $e->getMessage());
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "{$class}::{$method}() is not a valid static method.");
}
return $return;
} | [
"public",
"function",
"call",
"(",
"$",
"class",
",",
"$",
"method",
",",
"array",
"$",
"args",
"=",
"array",
"(",
")",
",",
"$",
"transient",
"=",
"false",
")",
"{",
"$",
"return",
"=",
"null",
";",
"$",
"callback",
"=",
"''",
";",
"if",
"(",
... | Call a static method from a valid package class with arguments.
Will always search for database-specific class files first.
@param string $class The name of a class to to get the static method from.
@param string $method The name of the method you want to call.
@param array $args An array of arguments for the method.
@param boolean $transient Indicates if the class has dbtype derivatives. Set to true if you
want to use on classes not derived from xPDOObject.
@return mixed|null The callback method's return value or null if no valid method is found. | [
"Call",
"a",
"static",
"method",
"from",
"a",
"valid",
"package",
"class",
"with",
"arguments",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L750-L775 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.newObject | public function newObject($className, $fields= array ()) {
$instance= null;
if ($className = $this->loadClass($className)) {
$className = self::getPlatformClass($className);
/** @var Om\xPDOObject $instance */
if ($instance = new $className($this)) {
if (is_array($fields) && !empty($fields)) {
$instance->fromArray($fields);
}
}
}
return $instance;
} | php | public function newObject($className, $fields= array ()) {
$instance= null;
if ($className = $this->loadClass($className)) {
$className = self::getPlatformClass($className);
/** @var Om\xPDOObject $instance */
if ($instance = new $className($this)) {
if (is_array($fields) && !empty($fields)) {
$instance->fromArray($fields);
}
}
}
return $instance;
} | [
"public",
"function",
"newObject",
"(",
"$",
"className",
",",
"$",
"fields",
"=",
"array",
"(",
")",
")",
"{",
"$",
"instance",
"=",
"null",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{... | Creates a new instance of a specified class.
All new objects created with this method are transient until {@link
xPDOObject::save()} is called the first time and is reflected by the
{@link xPDOObject::$_new} property.
@param string $className Name of the class to get a new instance of.
@param array $fields An associated array of field names/values to
populate the object with.
@return Om\xPDOObject|null A new instance of the specified class, or null if a
new object could not be instantiated. | [
"Creates",
"a",
"new",
"instance",
"of",
"a",
"specified",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L790-L802 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getObject | public function getObject($className, $criteria= null, $cacheFlag= true) {
$instance= null;
$this->sanitizePKCriteria($className, $criteria);
if ($criteria !== null) {
$instance = $this->call($className, 'load', array(& $this, $className, $criteria, $cacheFlag));
}
return $instance;
} | php | public function getObject($className, $criteria= null, $cacheFlag= true) {
$instance= null;
$this->sanitizePKCriteria($className, $criteria);
if ($criteria !== null) {
$instance = $this->call($className, 'load', array(& $this, $className, $criteria, $cacheFlag));
}
return $instance;
} | [
"public",
"function",
"getObject",
"(",
"$",
"className",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"instance",
"=",
"null",
";",
"$",
"this",
"->",
"sanitizePKCriteria",
"(",
"$",
"className",
",",
"$",
"cri... | Retrieves a single object instance by the specified criteria.
The criteria can be a primary key value, and array of primary key values
(for multiple primary key objects) or an {@link xPDOCriteria} object. If
no $criteria parameter is specified, no class is found, or an object
cannot be located by the supplied criteria, null is returned.
@uses xPDOObject::load()
@param string $className Name of the class to get an instance of.
@param mixed $criteria Primary key of the record or a xPDOCriteria object.
@param mixed $cacheFlag If an integer value is provided, this specifies
the time to live in the object cache; if cacheFlag === false, caching is
ignored for the object and if cacheFlag === true, the object will live in
cache indefinitely.
@return Om\xPDOObject|null An instance of the class, or null if it could not be
instantiated. | [
"Retrieves",
"a",
"single",
"object",
"instance",
"by",
"the",
"specified",
"criteria",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L822-L829 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getCollection | public function getCollection($className, $criteria= null, $cacheFlag= true) {
return $this->call($className, 'loadCollection', array(& $this, $className, $criteria, $cacheFlag));
} | php | public function getCollection($className, $criteria= null, $cacheFlag= true) {
return $this->call($className, 'loadCollection', array(& $this, $className, $criteria, $cacheFlag));
} | [
"public",
"function",
"getCollection",
"(",
"$",
"className",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"call",
"(",
"$",
"className",
",",
"'loadCollection'",
",",
"array",
"(",
"&",
... | Retrieves a collection of xPDOObjects by the specified xPDOCriteria.
@uses xPDOObject::loadCollection()
@param string $className Name of the class to search for instances of.
@param object|array|string $criteria An xPDOCriteria object or an array
search expression.
@param mixed $cacheFlag If an integer value is provided, this specifies
the time to live in the result set cache; if cacheFlag === false, caching
is ignored for the collection and if cacheFlag === true, the objects will
live in cache until flushed by another process.
@return array|null An array of class instances retrieved. | [
"Retrieves",
"a",
"collection",
"of",
"xPDOObjects",
"by",
"the",
"specified",
"xPDOCriteria",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L844-L846 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getIterator | public function getIterator($className, $criteria= null, $cacheFlag= true) {
return new xPDOIterator($this, array('class' => $className, 'criteria' => $criteria, 'cacheFlag' => $cacheFlag));
} | php | public function getIterator($className, $criteria= null, $cacheFlag= true) {
return new xPDOIterator($this, array('class' => $className, 'criteria' => $criteria, 'cacheFlag' => $cacheFlag));
} | [
"public",
"function",
"getIterator",
"(",
"$",
"className",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"return",
"new",
"xPDOIterator",
"(",
"$",
"this",
",",
"array",
"(",
"'class'",
"=>",
"$",
"className",
",",
"... | Retrieves an iterable representation of a collection of xPDOObjects.
@param string $className Name of the class to search for instances of.
@param mixed $criteria An xPDOCriteria object or representation.
@param bool $cacheFlag If an integer value is provided, this specifies
the time to live in the result set cache; if cacheFlag === false, caching
is ignored for the collection and if cacheFlag === true, the objects will
live in cache until flushed by another process.
@return xPDOIterator An iterable representation of a collection. | [
"Retrieves",
"an",
"iterable",
"representation",
"of",
"a",
"collection",
"of",
"xPDOObjects",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L859-L861 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.updateCollection | public function updateCollection($className, array $set, $criteria= null) {
$affected = false;
if ($this->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
$query = $this->newQuery($className);
if ($query && !empty($set)) {
$query->command('UPDATE');
$query->set($set);
if (!empty($criteria)) $query->where($criteria);
if ($query->prepare()) {
$affected = $this->exec($query->toSQL());
if ($affected === false) {
$this->log(xPDO::LOG_LEVEL_ERROR, "Error updating {$className} instances using query " . $query->toSQL(), '', __METHOD__, __FILE__, __LINE__);
} else {
if ($this->getOption(xPDO::OPT_CACHE_DB)) {
$relatedClasses = array($query->getTableClass());
$related = array_merge($this->getAggregates($className), $this->getComposites($className));
foreach ($related as $relatedAlias => $relatedMeta) {
$relatedClasses[] = $relatedMeta['class'];
}
$relatedClasses = array_unique($relatedClasses);
foreach ($relatedClasses as $relatedClass) {
$this->cacheManager->delete($relatedClass, array(
xPDO::OPT_CACHE_KEY => $this->getOption('cache_db_key', null, 'db'),
xPDO::OPT_CACHE_HANDLER => $this->getOption(xPDO::OPT_CACHE_DB_HANDLER, null, $this->getOption(xPDO::OPT_CACHE_HANDLER, null, 'xPDO\\Cache\\xPDOFileCache')),
xPDO::OPT_CACHE_FORMAT => (integer) $this->getOption('cache_db_format', null, $this->getOption(xPDO::OPT_CACHE_FORMAT, null, Cache\xPDOCacheManager::CACHE_PHP)),
xPDO::OPT_CACHE_PREFIX => $this->getOption('cache_db_prefix', null, Cache\xPDOCacheManager::CACHE_DIR),
'multiple_object_delete' => true
));
}
}
$callback = $this->getOption(xPDO::OPT_CALLBACK_ON_SAVE);
if ($callback && is_callable($callback)) {
call_user_func($callback, array('className' => $className, 'criteria' => $query, 'object' => null));
}
}
}
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not get connection for writing data", '', __METHOD__, __FILE__, __LINE__);
}
return $affected;
} | php | public function updateCollection($className, array $set, $criteria= null) {
$affected = false;
if ($this->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
$query = $this->newQuery($className);
if ($query && !empty($set)) {
$query->command('UPDATE');
$query->set($set);
if (!empty($criteria)) $query->where($criteria);
if ($query->prepare()) {
$affected = $this->exec($query->toSQL());
if ($affected === false) {
$this->log(xPDO::LOG_LEVEL_ERROR, "Error updating {$className} instances using query " . $query->toSQL(), '', __METHOD__, __FILE__, __LINE__);
} else {
if ($this->getOption(xPDO::OPT_CACHE_DB)) {
$relatedClasses = array($query->getTableClass());
$related = array_merge($this->getAggregates($className), $this->getComposites($className));
foreach ($related as $relatedAlias => $relatedMeta) {
$relatedClasses[] = $relatedMeta['class'];
}
$relatedClasses = array_unique($relatedClasses);
foreach ($relatedClasses as $relatedClass) {
$this->cacheManager->delete($relatedClass, array(
xPDO::OPT_CACHE_KEY => $this->getOption('cache_db_key', null, 'db'),
xPDO::OPT_CACHE_HANDLER => $this->getOption(xPDO::OPT_CACHE_DB_HANDLER, null, $this->getOption(xPDO::OPT_CACHE_HANDLER, null, 'xPDO\\Cache\\xPDOFileCache')),
xPDO::OPT_CACHE_FORMAT => (integer) $this->getOption('cache_db_format', null, $this->getOption(xPDO::OPT_CACHE_FORMAT, null, Cache\xPDOCacheManager::CACHE_PHP)),
xPDO::OPT_CACHE_PREFIX => $this->getOption('cache_db_prefix', null, Cache\xPDOCacheManager::CACHE_DIR),
'multiple_object_delete' => true
));
}
}
$callback = $this->getOption(xPDO::OPT_CALLBACK_ON_SAVE);
if ($callback && is_callable($callback)) {
call_user_func($callback, array('className' => $className, 'criteria' => $query, 'object' => null));
}
}
}
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not get connection for writing data", '', __METHOD__, __FILE__, __LINE__);
}
return $affected;
} | [
"public",
"function",
"updateCollection",
"(",
"$",
"className",
",",
"array",
"$",
"set",
",",
"$",
"criteria",
"=",
"null",
")",
"{",
"$",
"affected",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"getConnection",
"(",
"array",
"(",
"xPDO",
"::",
... | Update field values across a collection of xPDOObjects.
@param string $className Name of the class to update fields of.
@param array $set An associative array of field/value pairs representing the updates to make.
@param mixed $criteria An xPDOCriteria object or representation.
@return bool|int The number of instances affected by the update or false on failure. | [
"Update",
"field",
"values",
"across",
"a",
"collection",
"of",
"xPDOObjects",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L871-L912 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.removeObject | public function removeObject($className, $criteria) {
$removed= false;
if ($this->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
if ($this->getCount($className, $criteria) === 1) {
if ($query= $this->newQuery($className)) {
$query->command('DELETE');
$query->where($criteria);
if ($query->prepare()) {
if ($this->exec($query->toSQL()) !== 1) {
$this->log(xPDO::LOG_LEVEL_ERROR, "xPDO->removeObject - Error deleting {$className} instance using query " . $query->toSQL());
} else {
$removed= true;
if ($this->getOption(xPDO::OPT_CACHE_DB)) {
$this->cacheManager->delete(Cache\xPDOCacheManager::CACHE_DIR . $query->getAlias(), array('multiple_object_delete' => true));
}
$callback = $this->getOption(xPDO::OPT_CALLBACK_ON_REMOVE);
if ($callback && is_callable($callback)) {
call_user_func($callback, array('className' => $className, 'criteria' => $query));
}
}
}
}
} else {
$this->log(xPDO::LOG_LEVEL_WARN, "xPDO->removeObject - {$className} instance to remove not found!");
if ($this->getDebug() === true) $this->log(xPDO::LOG_LEVEL_DEBUG, "xPDO->removeObject - {$className} instance to remove not found using criteria " . print_r($criteria, true));
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not get connection for writing data", '', __METHOD__, __FILE__, __LINE__);
}
return $removed;
} | php | public function removeObject($className, $criteria) {
$removed= false;
if ($this->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
if ($this->getCount($className, $criteria) === 1) {
if ($query= $this->newQuery($className)) {
$query->command('DELETE');
$query->where($criteria);
if ($query->prepare()) {
if ($this->exec($query->toSQL()) !== 1) {
$this->log(xPDO::LOG_LEVEL_ERROR, "xPDO->removeObject - Error deleting {$className} instance using query " . $query->toSQL());
} else {
$removed= true;
if ($this->getOption(xPDO::OPT_CACHE_DB)) {
$this->cacheManager->delete(Cache\xPDOCacheManager::CACHE_DIR . $query->getAlias(), array('multiple_object_delete' => true));
}
$callback = $this->getOption(xPDO::OPT_CALLBACK_ON_REMOVE);
if ($callback && is_callable($callback)) {
call_user_func($callback, array('className' => $className, 'criteria' => $query));
}
}
}
}
} else {
$this->log(xPDO::LOG_LEVEL_WARN, "xPDO->removeObject - {$className} instance to remove not found!");
if ($this->getDebug() === true) $this->log(xPDO::LOG_LEVEL_DEBUG, "xPDO->removeObject - {$className} instance to remove not found using criteria " . print_r($criteria, true));
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not get connection for writing data", '', __METHOD__, __FILE__, __LINE__);
}
return $removed;
} | [
"public",
"function",
"removeObject",
"(",
"$",
"className",
",",
"$",
"criteria",
")",
"{",
"$",
"removed",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"getConnection",
"(",
"array",
"(",
"xPDO",
"::",
"OPT_CONN_MUTABLE",
"=>",
"true",
")",
")",
... | Remove an instance of the specified className by a supplied criteria.
@param string $className The name of the class to remove an instance of.
@param mixed $criteria Valid xPDO criteria for selecting an instance.
@return boolean True if the instance is successfully removed. | [
"Remove",
"an",
"instance",
"of",
"the",
"specified",
"className",
"by",
"a",
"supplied",
"criteria",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L921-L951 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getCount | public function getCount($className, $criteria = null) {
$count = 0;
if ($query = $this->newQuery($className, $criteria)) {
$stmt = null;
$expr = '*';
if ($pk = $this->getPK($className)) {
if (!is_array($pk)) {
$pk = array($pk);
}
$expr = $this->getSelectColumns($className, $query->getAlias(), '', $pk);
}
if (isset($query->query['columns'])) {
$query->query['columns'] = array();
}
if (!empty($query->query['groupby']) || !empty($query->query['having'])) {
$query->select($expr);
if ($query->prepare()) {
$countQuery = new xPDOCriteria($this, "SELECT COUNT(*) FROM ({$query->toSQL(false)}) cq", $query->bindings, $query->cacheFlag);
$stmt = $countQuery->prepare();
}
} else {
$query->select(array("COUNT(DISTINCT {$expr})"));
$stmt = $query->prepare();
}
if ($stmt && $stmt->execute()) {
$count = intval($stmt->fetchColumn());
}
}
return $count;
} | php | public function getCount($className, $criteria = null) {
$count = 0;
if ($query = $this->newQuery($className, $criteria)) {
$stmt = null;
$expr = '*';
if ($pk = $this->getPK($className)) {
if (!is_array($pk)) {
$pk = array($pk);
}
$expr = $this->getSelectColumns($className, $query->getAlias(), '', $pk);
}
if (isset($query->query['columns'])) {
$query->query['columns'] = array();
}
if (!empty($query->query['groupby']) || !empty($query->query['having'])) {
$query->select($expr);
if ($query->prepare()) {
$countQuery = new xPDOCriteria($this, "SELECT COUNT(*) FROM ({$query->toSQL(false)}) cq", $query->bindings, $query->cacheFlag);
$stmt = $countQuery->prepare();
}
} else {
$query->select(array("COUNT(DISTINCT {$expr})"));
$stmt = $query->prepare();
}
if ($stmt && $stmt->execute()) {
$count = intval($stmt->fetchColumn());
}
}
return $count;
} | [
"public",
"function",
"getCount",
"(",
"$",
"className",
",",
"$",
"criteria",
"=",
"null",
")",
"{",
"$",
"count",
"=",
"0",
";",
"if",
"(",
"$",
"query",
"=",
"$",
"this",
"->",
"newQuery",
"(",
"$",
"className",
",",
"$",
"criteria",
")",
")",
... | Retrieves a count of xPDOObjects by the specified xPDOCriteria.
@param string $className Class of xPDOObject to count instances of.
@param mixed $criteria Any valid xPDOCriteria object or expression.
@return integer The number of instances found by the criteria. | [
"Retrieves",
"a",
"count",
"of",
"xPDOObjects",
"by",
"the",
"specified",
"xPDOCriteria",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L997-L1026 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getObjectGraph | public function getObjectGraph($className, $graph, $criteria= null, $cacheFlag= true) {
$object= null;
if ($collection= $this->getCollectionGraph($className, $graph, $criteria, $cacheFlag)) {
if (!count($collection) === 1) {
$this->log(xPDO::LOG_LEVEL_WARN, 'getObjectGraph criteria returned more than one instance.');
}
$object= reset($collection);
}
return $object;
} | php | public function getObjectGraph($className, $graph, $criteria= null, $cacheFlag= true) {
$object= null;
if ($collection= $this->getCollectionGraph($className, $graph, $criteria, $cacheFlag)) {
if (!count($collection) === 1) {
$this->log(xPDO::LOG_LEVEL_WARN, 'getObjectGraph criteria returned more than one instance.');
}
$object= reset($collection);
}
return $object;
} | [
"public",
"function",
"getObjectGraph",
"(",
"$",
"className",
",",
"$",
"graph",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"object",
"=",
"null",
";",
"if",
"(",
"$",
"collection",
"=",
"$",
"this",
"->",
... | Retrieves an xPDOObject instance with specified related objects.
@uses xPDO::getCollectionGraph()
@param string $className The name of the class to return an instance of.
@param string|array $graph A related object graph in array or JSON
format, e.g. array('relationAlias'=>array('subRelationAlias'=>array()))
or {"relationAlias":{"subRelationAlias":{}}}. Note that the empty arrays
are necessary in order for the relation to be recognized.
@param mixed $criteria A valid xPDOCriteria instance or expression.
@param boolean|integer $cacheFlag Indicates if the result set should be
cached, and optionally for how many seconds.
@return object The object instance with related objects from the graph
hydrated, or null if no instance can be located by the criteria. | [
"Retrieves",
"an",
"xPDOObject",
"instance",
"with",
"specified",
"related",
"objects",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1043-L1052 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getCollectionGraph | public function getCollectionGraph($className, $graph, $criteria= null, $cacheFlag= true) {
return $this->call($className, 'loadCollectionGraph', array(& $this, $className, $graph, $criteria, $cacheFlag));
} | php | public function getCollectionGraph($className, $graph, $criteria= null, $cacheFlag= true) {
return $this->call($className, 'loadCollectionGraph', array(& $this, $className, $graph, $criteria, $cacheFlag));
} | [
"public",
"function",
"getCollectionGraph",
"(",
"$",
"className",
",",
"$",
"graph",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"call",
"(",
"$",
"className",
",",
"'loadCollectionGraph'",... | Retrieves a collection of xPDOObject instances with related objects.
@uses xPDOQuery::bindGraph()
@param string $className The name of the class to return a collection of.
@param string|array $graph A related object graph in array or JSON
format, e.g. array('relationAlias'=>array('subRelationAlias'=>array()))
or {"relationAlias":{"subRelationAlias":{}}}. Note that the empty arrays
are necessary in order for the relation to be recognized.
@param mixed $criteria A valid xPDOCriteria instance or condition string.
@param boolean $cacheFlag Indicates if the result set should be cached.
@return array An array of instances matching the criteria with related
objects from the graph hydrated. An empty array is returned when no
matches are found. | [
"Retrieves",
"a",
"collection",
"of",
"xPDOObject",
"instances",
"with",
"related",
"objects",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1069-L1071 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getValue | public function getValue($stmt, $column= null) {
$value = null;
if (is_object($stmt) && $stmt instanceof \PDOStatement) {
$tstart = microtime(true);
if ($stmt->execute()) {
$this->queryTime += microtime(true) - $tstart;
$this->executedQueries++;
$value= $stmt->fetchColumn($column);
$stmt->closeCursor();
} else {
$this->queryTime += microtime(true) - $tstart;
$this->executedQueries++;
$this->log(xPDO::LOG_LEVEL_ERROR, "Error " . $stmt->errorCode() . " executing statement: \n" . print_r($stmt->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "No valid PDOStatement provided to getValue", '', __METHOD__, __FILE__, __LINE__);
}
return $value;
} | php | public function getValue($stmt, $column= null) {
$value = null;
if (is_object($stmt) && $stmt instanceof \PDOStatement) {
$tstart = microtime(true);
if ($stmt->execute()) {
$this->queryTime += microtime(true) - $tstart;
$this->executedQueries++;
$value= $stmt->fetchColumn($column);
$stmt->closeCursor();
} else {
$this->queryTime += microtime(true) - $tstart;
$this->executedQueries++;
$this->log(xPDO::LOG_LEVEL_ERROR, "Error " . $stmt->errorCode() . " executing statement: \n" . print_r($stmt->errorInfo(), true), '', __METHOD__, __FILE__, __LINE__);
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "No valid PDOStatement provided to getValue", '', __METHOD__, __FILE__, __LINE__);
}
return $value;
} | [
"public",
"function",
"getValue",
"(",
"$",
"stmt",
",",
"$",
"column",
"=",
"null",
")",
"{",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"is_object",
"(",
"$",
"stmt",
")",
"&&",
"$",
"stmt",
"instanceof",
"\\",
"PDOStatement",
")",
"{",
"$",
"tst... | Execute a PDOStatement and get a single column value from the first row of the result set.
@param \PDOStatement $stmt A prepared PDOStatement object ready to be executed.
@param null|integer $column 0-indexed number of the column you wish to retrieve from the row. If
null or no value is supplied, it fetches the first column.
@return mixed The value of the specified column from the first row of the result set, or null. | [
"Execute",
"a",
"PDOStatement",
"and",
"get",
"a",
"single",
"column",
"value",
"from",
"the",
"first",
"row",
"of",
"the",
"result",
"set",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1081-L1099 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getCriteria | public function getCriteria($className, $type= null, $cacheFlag= true) {
return $this->newQuery($className, $type, $cacheFlag);
} | php | public function getCriteria($className, $type= null, $cacheFlag= true) {
return $this->newQuery($className, $type, $cacheFlag);
} | [
"public",
"function",
"getCriteria",
"(",
"$",
"className",
",",
"$",
"type",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"newQuery",
"(",
"$",
"className",
",",
"$",
"type",
",",
"$",
"cacheFlag",
")",
";"... | Convert any valid criteria into an xPDOQuery instance.
@todo Get criteria pre-defined in an {@link xPDOObject} class metadata
definition by name.
@todo Define callback functions as an alternative to retreiving criteria
sql and/or bindings from the metadata.
@param string $className The class to get predefined criteria for.
@param string $type The type of criteria to get (you can define any
type you want, but 'object' and 'collection' are the typical criteria
for retrieving single and multiple instances of an object).
@param boolean|integer $cacheFlag Indicates if the result is cached and
optionally for how many seconds.
@return Om\xPDOCriteria A criteria object or null if not found. | [
"Convert",
"any",
"valid",
"criteria",
"into",
"an",
"xPDOQuery",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1118-L1120 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getCriteriaType | public function getCriteriaType($criteria) {
$type = gettype($criteria);
if ($type === 'object') {
$type = get_class($criteria);
if (!$criteria instanceof Om\xPDOCriteria) {
$this->log(xPDO::LOG_LEVEL_WARN, "Invalid criteria object of class {$type} encountered.", '', __METHOD__, __FILE__, __LINE__);
$type = null;
} elseif ($criteria instanceof Om\xPDOQuery) {
$type = 'xPDOQuery';
} else {
$type = 'xPDOCriteria';
}
}
return $type;
} | php | public function getCriteriaType($criteria) {
$type = gettype($criteria);
if ($type === 'object') {
$type = get_class($criteria);
if (!$criteria instanceof Om\xPDOCriteria) {
$this->log(xPDO::LOG_LEVEL_WARN, "Invalid criteria object of class {$type} encountered.", '', __METHOD__, __FILE__, __LINE__);
$type = null;
} elseif ($criteria instanceof Om\xPDOQuery) {
$type = 'xPDOQuery';
} else {
$type = 'xPDOCriteria';
}
}
return $type;
} | [
"public",
"function",
"getCriteriaType",
"(",
"$",
"criteria",
")",
"{",
"$",
"type",
"=",
"gettype",
"(",
"$",
"criteria",
")",
";",
"if",
"(",
"$",
"type",
"===",
"'object'",
")",
"{",
"$",
"type",
"=",
"get_class",
"(",
"$",
"criteria",
")",
";",
... | Validate and return the type of a specified criteria variable.
@param mixed $criteria An xPDOCriteria instance or any valid criteria variable.
@return string|null The type of valid criteria passed, or null if the criteria is not valid. | [
"Validate",
"and",
"return",
"the",
"type",
"of",
"a",
"specified",
"criteria",
"variable",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1128-L1142 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.addDerivativeCriteria | public function addDerivativeCriteria($className, $criteria) {
if ($criteria instanceof Om\xPDOQuery && ($className = $this->loadClass($className)) && !isset($this->map[$className]['table'])) {
if (isset($this->map[$className]['fields']['class_key']) && !empty($this->map[$className]['fields']['class_key'])) {
$criteria->where(array('class_key' => $this->map[$className]['fields']['class_key']));
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "#1: Automatically adding class_key criteria for derivative query of class {$className}");
}
} else {
foreach ($this->getAncestry($className, false) as $ancestor) {
if (isset($this->map[$ancestor]['table']) && isset($this->map[$ancestor]['fields']['class_key'])) {
$criteria->where(array('class_key' => $className));
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "#2: Automatically adding class_key criteria for derivative query of class {$className} from base table class {$ancestor}");
}
break;
}
}
}
}
return $criteria;
} | php | public function addDerivativeCriteria($className, $criteria) {
if ($criteria instanceof Om\xPDOQuery && ($className = $this->loadClass($className)) && !isset($this->map[$className]['table'])) {
if (isset($this->map[$className]['fields']['class_key']) && !empty($this->map[$className]['fields']['class_key'])) {
$criteria->where(array('class_key' => $this->map[$className]['fields']['class_key']));
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "#1: Automatically adding class_key criteria for derivative query of class {$className}");
}
} else {
foreach ($this->getAncestry($className, false) as $ancestor) {
if (isset($this->map[$ancestor]['table']) && isset($this->map[$ancestor]['fields']['class_key'])) {
$criteria->where(array('class_key' => $className));
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "#2: Automatically adding class_key criteria for derivative query of class {$className} from base table class {$ancestor}");
}
break;
}
}
}
}
return $criteria;
} | [
"public",
"function",
"addDerivativeCriteria",
"(",
"$",
"className",
",",
"$",
"criteria",
")",
"{",
"if",
"(",
"$",
"criteria",
"instanceof",
"Om",
"\\",
"xPDOQuery",
"&&",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className"... | Add criteria when requesting a derivative class row automatically.
This applies class_key filtering for single-table inheritance queries and may
provide a convenient location for similar features in the future.
@param string $className A valid xPDOObject derivative table class.
@param Om\xPDOQuery $criteria A valid xPDOQuery instance.
@return Om\xPDOQuery The xPDOQuery instance with derivative criteria added. | [
"Add",
"criteria",
"when",
"requesting",
"a",
"derivative",
"class",
"row",
"automatically",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1154-L1174 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getPackage | public function getPackage($className) {
$package= '';
if ($className= $this->loadClass($className)) {
if (isset($this->map[$className]['package'])) {
$package= $this->map[$className]['package'];
}
if (!$package && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['package']) && ($package= $this->map[$ancestor]['package'])) {
break;
}
}
}
}
return $package;
} | php | public function getPackage($className) {
$package= '';
if ($className= $this->loadClass($className)) {
if (isset($this->map[$className]['package'])) {
$package= $this->map[$className]['package'];
}
if (!$package && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['package']) && ($package= $this->map[$ancestor]['package'])) {
break;
}
}
}
}
return $package;
} | [
"public",
"function",
"getPackage",
"(",
"$",
"className",
")",
"{",
"$",
"package",
"=",
"''",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",... | Gets the package name from a specified class name.
@param string $className The name of the class to lookup the package for.
@return string The package the class belongs to. | [
"Gets",
"the",
"package",
"name",
"from",
"a",
"specified",
"class",
"name",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1182-L1197 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getService | public function getService($name, $class= '', $path= '', $params= array ()) {
$service= null;
if (!$this->services->has($name) || !is_object($this->services->get($name))) {
if (empty ($class) && isset ($this->config[$name . '.class'])) {
$class= $this->config[$name . '.class'];
} elseif (empty ($class)) {
$class= $name;
}
$className= $this->loadClass($class, $path, false, true);
if (!empty($className)) {
$service = new $className($this, $params);
if ($service) {
$this->services->add($name, $service);
$this->$name= $this->services->get($name);
}
}
}
if ($this->services->has($name)) {
$service = $this->services->get($name);
} else {
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "Problem getting service {$name}, instance of class {$class}, from path {$path}, with params " . print_r($params, true));
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Problem getting service {$name}, instance of class {$class}, from path {$path}");
}
}
return $service;
} | php | public function getService($name, $class= '', $path= '', $params= array ()) {
$service= null;
if (!$this->services->has($name) || !is_object($this->services->get($name))) {
if (empty ($class) && isset ($this->config[$name . '.class'])) {
$class= $this->config[$name . '.class'];
} elseif (empty ($class)) {
$class= $name;
}
$className= $this->loadClass($class, $path, false, true);
if (!empty($className)) {
$service = new $className($this, $params);
if ($service) {
$this->services->add($name, $service);
$this->$name= $this->services->get($name);
}
}
}
if ($this->services->has($name)) {
$service = $this->services->get($name);
} else {
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "Problem getting service {$name}, instance of class {$class}, from path {$path}, with params " . print_r($params, true));
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Problem getting service {$name}, instance of class {$class}, from path {$path}");
}
}
return $service;
} | [
"public",
"function",
"getService",
"(",
"$",
"name",
",",
"$",
"class",
"=",
"''",
",",
"$",
"path",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"service",
"=",
"null",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"service... | Load and return a named service class instance.
@deprecated Use the service/DI container to access services. Will be removed in 3.1.
@param string $name The variable name of the instance.
@param string $class The service class name.
@param string $path An optional root path to search for the class.
@param array $params An array of optional params to pass to the service
class constructor.
@return object|null A reference to the service class instance or null if
it could not be loaded. | [
"Load",
"and",
"return",
"a",
"named",
"service",
"class",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1212-L1239 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getTableName | public function getTableName($className, $includeDb= false) {
$table= null;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['table'])) {
$table= $this->map[$className]['table'];
if (isset($this->map[$className]['package']) && isset($this->packages[$this->map[$className]['package']]['prefix'])) {
$table= $this->packages[$this->map[$className]['package']]['prefix'] . $table;
} else {
$table= $this->getOption(xPDO::OPT_TABLE_PREFIX, null, '') . $table;
}
}
if (!$table && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['table']) && $table= $this->map[$ancestor]['table']) {
if (isset($this->map[$ancestor]['package']) && isset($this->packages[$this->map[$ancestor]['package']]['prefix'])) {
$table= $this->packages[$this->map[$ancestor]['package']]['prefix'] . $table;
} else {
$table= $this->getOption(xPDO::OPT_TABLE_PREFIX, null, '') . $table;
}
break;
}
}
}
}
if ($table) {
$table= $this->_getFullTableName($table, $includeDb);
if ($this->getDebug() === true) $this->log(xPDO::LOG_LEVEL_DEBUG, 'Returning table name: ' . $table . ' for class: ' . $className);
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, 'Could not get table name for class: ' . $className);
}
return $table;
} | php | public function getTableName($className, $includeDb= false) {
$table= null;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['table'])) {
$table= $this->map[$className]['table'];
if (isset($this->map[$className]['package']) && isset($this->packages[$this->map[$className]['package']]['prefix'])) {
$table= $this->packages[$this->map[$className]['package']]['prefix'] . $table;
} else {
$table= $this->getOption(xPDO::OPT_TABLE_PREFIX, null, '') . $table;
}
}
if (!$table && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['table']) && $table= $this->map[$ancestor]['table']) {
if (isset($this->map[$ancestor]['package']) && isset($this->packages[$this->map[$ancestor]['package']]['prefix'])) {
$table= $this->packages[$this->map[$ancestor]['package']]['prefix'] . $table;
} else {
$table= $this->getOption(xPDO::OPT_TABLE_PREFIX, null, '') . $table;
}
break;
}
}
}
}
if ($table) {
$table= $this->_getFullTableName($table, $includeDb);
if ($this->getDebug() === true) $this->log(xPDO::LOG_LEVEL_DEBUG, 'Returning table name: ' . $table . ' for class: ' . $className);
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, 'Could not get table name for class: ' . $className);
}
return $table;
} | [
"public",
"function",
"getTableName",
"(",
"$",
"className",
",",
"$",
"includeDb",
"=",
"false",
")",
"{",
"$",
"table",
"=",
"null",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
... | Gets the actual run-time table name from a specified class name.
@param string $className The name of the class to lookup a table name
for.
@param boolean $includeDb Qualify the table name with the database name.
@return string The table name for the class, or null if unsuccessful. | [
"Gets",
"the",
"actual",
"run",
"-",
"time",
"table",
"name",
"from",
"a",
"specified",
"class",
"name",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1249-L1280 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getTableClass | public function getTableClass($className) {
$tableClass= null;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['table'])) {
$tableClass= $className;
}
if (!$tableClass && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['table'])) {
$tableClass= $ancestor;
break;
}
}
}
}
if ($tableClass) {
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, 'Returning table class: ' . $tableClass . ' for class: ' . $className);
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, 'Could not get table class for class: ' . $className);
}
return $tableClass;
} | php | public function getTableClass($className) {
$tableClass= null;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['table'])) {
$tableClass= $className;
}
if (!$tableClass && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['table'])) {
$tableClass= $ancestor;
break;
}
}
}
}
if ($tableClass) {
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, 'Returning table class: ' . $tableClass . ' for class: ' . $className);
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, 'Could not get table class for class: ' . $className);
}
return $tableClass;
} | [
"public",
"function",
"getTableClass",
"(",
"$",
"className",
")",
"{",
"$",
"tableClass",
"=",
"null",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",... | Get the class which defines the table for a specified className.
@param string $className The name of a class to determine the table class from.
@return null|string The name of a class defining the table for the specified className; null if not found. | [
"Get",
"the",
"class",
"which",
"defines",
"the",
"table",
"for",
"a",
"specified",
"className",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1288-L1311 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getTableMeta | public function getTableMeta($className) {
$tableMeta= null;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['tableMeta'])) {
$tableMeta= $this->map[$className]['tableMeta'];
}
if (!$tableMeta && $ancestry= $this->getAncestry($className)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['tableMeta'])) {
if ($tableMeta= $this->map[$ancestor]['tableMeta']) {
break;
}
}
}
}
}
return $tableMeta;
} | php | public function getTableMeta($className) {
$tableMeta= null;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['tableMeta'])) {
$tableMeta= $this->map[$className]['tableMeta'];
}
if (!$tableMeta && $ancestry= $this->getAncestry($className)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['tableMeta'])) {
if ($tableMeta= $this->map[$ancestor]['tableMeta']) {
break;
}
}
}
}
}
return $tableMeta;
} | [
"public",
"function",
"getTableMeta",
"(",
"$",
"className",
")",
"{",
"$",
"tableMeta",
"=",
"null",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
... | Gets the actual run-time table metadata from a specified class name.
@param string $className The name of the class to lookup a table name
for.
@return string The table meta data for the class, or null if
unsuccessful. | [
"Gets",
"the",
"actual",
"run",
"-",
"time",
"table",
"metadata",
"from",
"a",
"specified",
"class",
"name",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1321-L1338 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getInherit | public function getInherit($className) {
$inherit= false;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['inherit'])) {
$inherit= $this->map[$className]['inherit'];
}
if (!$inherit && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['inherit'])) {
$inherit= $this->map[$ancestor]['inherit'];
break;
}
}
}
}
if (!empty($inherit)) {
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, 'Returning inherit: ' . $inherit . ' for class: ' . $className);
}
} else {
$inherit= 'none';
}
return $inherit;
} | php | public function getInherit($className) {
$inherit= false;
if ($className= $this->loadClass($className)) {
if (isset ($this->map[$className]['inherit'])) {
$inherit= $this->map[$className]['inherit'];
}
if (!$inherit && $ancestry= $this->getAncestry($className, false)) {
foreach ($ancestry as $ancestor) {
if (isset ($this->map[$ancestor]['inherit'])) {
$inherit= $this->map[$ancestor]['inherit'];
break;
}
}
}
}
if (!empty($inherit)) {
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, 'Returning inherit: ' . $inherit . ' for class: ' . $className);
}
} else {
$inherit= 'none';
}
return $inherit;
} | [
"public",
"function",
"getInherit",
"(",
"$",
"className",
")",
"{",
"$",
"inherit",
"=",
"false",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"-... | Indicates the inheritance model for the xPDOObject class specified.
@param string $className The class to determine the table inherit type from.
@return string single, multiple, or none | [
"Indicates",
"the",
"inheritance",
"model",
"for",
"the",
"xPDOObject",
"class",
"specified",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1346-L1369 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getFieldAliases | public function getFieldAliases($className) {
$fieldAliases= array ();
if ($className= $this->loadClass($className)) {
if ($ancestry= $this->getAncestry($className)) {
for ($i= count($ancestry) - 1; $i >= 0; $i--) {
if (isset ($this->map[$ancestry[$i]]['fieldAliases'])) {
$fieldAliases= array_merge($fieldAliases, $this->map[$ancestry[$i]]['fieldAliases']);
}
}
}
if ($this->getInherit($className) === 'single') {
$descendants= $this->getDescendants($className);
if ($descendants) {
foreach ($descendants as $descendant) {
$descendantClass= $this->loadClass($descendant);
if ($descendantClass && isset($this->map[$descendantClass]['fieldAliases'])) {
$fieldAliases= array_merge($fieldAliases, array_diff_key($this->map[$descendantClass]['fieldAliases'], $fieldAliases));
}
}
}
}
}
return $fieldAliases;
} | php | public function getFieldAliases($className) {
$fieldAliases= array ();
if ($className= $this->loadClass($className)) {
if ($ancestry= $this->getAncestry($className)) {
for ($i= count($ancestry) - 1; $i >= 0; $i--) {
if (isset ($this->map[$ancestry[$i]]['fieldAliases'])) {
$fieldAliases= array_merge($fieldAliases, $this->map[$ancestry[$i]]['fieldAliases']);
}
}
}
if ($this->getInherit($className) === 'single') {
$descendants= $this->getDescendants($className);
if ($descendants) {
foreach ($descendants as $descendant) {
$descendantClass= $this->loadClass($descendant);
if ($descendantClass && isset($this->map[$descendantClass]['fieldAliases'])) {
$fieldAliases= array_merge($fieldAliases, array_diff_key($this->map[$descendantClass]['fieldAliases'], $fieldAliases));
}
}
}
}
}
return $fieldAliases;
} | [
"public",
"function",
"getFieldAliases",
"(",
"$",
"className",
")",
"{",
"$",
"fieldAliases",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
"(",
"$",
"ances... | Gets a collection of field aliases for an object by class name.
@param string $className The name of the class to lookup field aliases for.
@return array An array of field aliases with aliases as keys and actual field names as values. | [
"Gets",
"a",
"collection",
"of",
"field",
"aliases",
"for",
"an",
"object",
"by",
"class",
"name",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1452-L1475 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getValidationRules | public function getValidationRules($className) {
$rules= array();
if ($className= $this->loadClass($className)) {
if ($ancestry= $this->getAncestry($className)) {
for ($i= count($ancestry) - 1; $i >= 0; $i--) {
if (isset($this->map[$ancestry[$i]]['validation']['rules'])) {
$rules= array_merge($rules, $this->map[$ancestry[$i]]['validation']['rules']);
}
}
}
if ($this->getInherit($className) === 'single') {
$descendants= $this->getDescendants($className);
if ($descendants) {
foreach ($descendants as $descendant) {
$descendantClass= $this->loadClass($descendant);
if ($descendantClass && isset($this->map[$descendantClass]['validation']['rules'])) {
$rules= array_merge($rules, array_diff_key($this->map[$descendantClass]['validation']['rules'], $rules));
}
}
}
}
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "Returning validation rules: " . print_r($rules, true));
}
}
return $rules;
} | php | public function getValidationRules($className) {
$rules= array();
if ($className= $this->loadClass($className)) {
if ($ancestry= $this->getAncestry($className)) {
for ($i= count($ancestry) - 1; $i >= 0; $i--) {
if (isset($this->map[$ancestry[$i]]['validation']['rules'])) {
$rules= array_merge($rules, $this->map[$ancestry[$i]]['validation']['rules']);
}
}
}
if ($this->getInherit($className) === 'single') {
$descendants= $this->getDescendants($className);
if ($descendants) {
foreach ($descendants as $descendant) {
$descendantClass= $this->loadClass($descendant);
if ($descendantClass && isset($this->map[$descendantClass]['validation']['rules'])) {
$rules= array_merge($rules, array_diff_key($this->map[$descendantClass]['validation']['rules'], $rules));
}
}
}
}
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "Returning validation rules: " . print_r($rules, true));
}
}
return $rules;
} | [
"public",
"function",
"getValidationRules",
"(",
"$",
"className",
")",
"{",
"$",
"rules",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
"(",
"$",
"ancestry"... | Gets a set of validation rules defined for an object by class name.
@param string $className The name of the class to lookup validation rules
for.
@return array An array featuring field names as the array keys, and
arrays of validation rule information as the array values; empty array is
returned if unsuccessful. | [
"Gets",
"a",
"set",
"of",
"validation",
"rules",
"defined",
"for",
"an",
"object",
"by",
"class",
"name",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1486-L1512 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getPKType | public function getPKType($className, $pk= false) {
$pktype= null;
if ($actualClassName= $this->loadClass($className)) {
if (!$pk)
$pk= $this->getPK($actualClassName);
if (!is_array($pk))
$pk= array($pk);
$ancestry= $this->getAncestry($actualClassName, true);
foreach ($pk as $_pk) {
foreach ($ancestry as $parentClass) {
if (isset ($this->map[$parentClass]['fieldMeta'][$_pk]['phptype'])) {
$pktype[$_pk]= $this->map[$parentClass]['fieldMeta'][$_pk]['phptype'];
break;
}
}
}
if (is_array($pktype) && count($pktype) == 1) {
$pktype= reset($pktype);
}
elseif (empty($pktype)) {
$pktype= null;
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not load class {$className}!");
}
return $pktype;
} | php | public function getPKType($className, $pk= false) {
$pktype= null;
if ($actualClassName= $this->loadClass($className)) {
if (!$pk)
$pk= $this->getPK($actualClassName);
if (!is_array($pk))
$pk= array($pk);
$ancestry= $this->getAncestry($actualClassName, true);
foreach ($pk as $_pk) {
foreach ($ancestry as $parentClass) {
if (isset ($this->map[$parentClass]['fieldMeta'][$_pk]['phptype'])) {
$pktype[$_pk]= $this->map[$parentClass]['fieldMeta'][$_pk]['phptype'];
break;
}
}
}
if (is_array($pktype) && count($pktype) == 1) {
$pktype= reset($pktype);
}
elseif (empty($pktype)) {
$pktype= null;
}
} else {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not load class {$className}!");
}
return $pktype;
} | [
"public",
"function",
"getPKType",
"(",
"$",
"className",
",",
"$",
"pk",
"=",
"false",
")",
"{",
"$",
"pktype",
"=",
"null",
";",
"if",
"(",
"$",
"actualClassName",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
")",
"{",
"if",
"... | Gets the type of primary key field for a class.
@param string $className The name of the class to lookup the primary key
type for.
@param mixed $pk Optional specific PK column or columns to get type(s) for.
@return string The type of the field representing a class instance primary
key, or null if no primary key is found or defined for the class. | [
"Gets",
"the",
"type",
"of",
"primary",
"key",
"field",
"for",
"a",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1620-L1646 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getGraph | public function getGraph($className, $depth= 3, &$parents = array(), &$visited = array()) {
$graph = array();
$className = $this->loadClass($className);
if ($className && $depth > 0) {
$depth--;
$parents = array_merge($parents, $this->getAncestry($className));
$parentsNested = array_unique($parents);
$visitNested = array_merge($visited, array($className));
$relations = array_merge($this->getAggregates($className), $this->getComposites($className));
foreach ($relations as $alias => $relation) {
if (in_array($relation['class'], $visited)) {
continue;
}
$childGraph = array();
if ($depth > 0 && !in_array($relation['class'], $parents)) {
$childGraph = $this->getGraph($relation['class'], $depth, $parentsNested, $visitNested);
}
$graph[$alias] = $childGraph;
}
$visited[] = $className;
}
return $graph;
} | php | public function getGraph($className, $depth= 3, &$parents = array(), &$visited = array()) {
$graph = array();
$className = $this->loadClass($className);
if ($className && $depth > 0) {
$depth--;
$parents = array_merge($parents, $this->getAncestry($className));
$parentsNested = array_unique($parents);
$visitNested = array_merge($visited, array($className));
$relations = array_merge($this->getAggregates($className), $this->getComposites($className));
foreach ($relations as $alias => $relation) {
if (in_array($relation['class'], $visited)) {
continue;
}
$childGraph = array();
if ($depth > 0 && !in_array($relation['class'], $parents)) {
$childGraph = $this->getGraph($relation['class'], $depth, $parentsNested, $visitNested);
}
$graph[$alias] = $childGraph;
}
$visited[] = $className;
}
return $graph;
} | [
"public",
"function",
"getGraph",
"(",
"$",
"className",
",",
"$",
"depth",
"=",
"3",
",",
"&",
"$",
"parents",
"=",
"array",
"(",
")",
",",
"&",
"$",
"visited",
"=",
"array",
"(",
")",
")",
"{",
"$",
"graph",
"=",
"array",
"(",
")",
";",
"$",
... | Get a complete relation graph for an xPDOObject class.
@param string $className A fully-qualified xPDOObject class name.
@param int $depth The depth to retrieve relations for the graph, defaults to 3.
@param array &$parents An array of parent classes to avoid traversing circular dependencies.
@param array &$visited An array of already visited classes to avoid traversing circular dependencies.
@return array An xPDOObject relation graph, or an empty array if no graph can be constructed. | [
"Get",
"a",
"complete",
"relation",
"graph",
"for",
"an",
"xPDOObject",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1719-L1741 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getAncestry | public function getAncestry($className, $includeSelf= true) {
$ancestry= array ();
if ($actualClassName= $this->loadClass($className)) {
$ancestor= $actualClassName;
if ($includeSelf) {
$ancestry[]= $actualClassName;
}
while ($ancestor= get_parent_class($ancestor)) {
$ancestry[]= $ancestor;
}
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "Returning ancestry for {$className}: " . print_r($ancestry, 1));
}
}
return $ancestry;
} | php | public function getAncestry($className, $includeSelf= true) {
$ancestry= array ();
if ($actualClassName= $this->loadClass($className)) {
$ancestor= $actualClassName;
if ($includeSelf) {
$ancestry[]= $actualClassName;
}
while ($ancestor= get_parent_class($ancestor)) {
$ancestry[]= $ancestor;
}
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "Returning ancestry for {$className}: " . print_r($ancestry, 1));
}
}
return $ancestry;
} | [
"public",
"function",
"getAncestry",
"(",
"$",
"className",
",",
"$",
"includeSelf",
"=",
"true",
")",
"{",
"$",
"ancestry",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"actualClassName",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")"... | Retrieves the complete ancestry for a class.
@param string $className The name of the class.
@param bool $includeSelf Determines if the specified class should be
included in the resulting array.
@return array An array of string class names representing the class
hierarchy, or an empty array if unsuccessful. | [
"Retrieves",
"the",
"complete",
"ancestry",
"for",
"a",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1752-L1767 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getSelectColumns | public function getSelectColumns($className, $tableAlias= '', $columnPrefix= '', $columns= array (), $exclude= false) {
return $this->call($className, 'getSelectColumns', array(&$this, $className, $tableAlias, $columnPrefix, $columns, $exclude));
} | php | public function getSelectColumns($className, $tableAlias= '', $columnPrefix= '', $columns= array (), $exclude= false) {
return $this->call($className, 'getSelectColumns', array(&$this, $className, $tableAlias, $columnPrefix, $columns, $exclude));
} | [
"public",
"function",
"getSelectColumns",
"(",
"$",
"className",
",",
"$",
"tableAlias",
"=",
"''",
",",
"$",
"columnPrefix",
"=",
"''",
",",
"$",
"columns",
"=",
"array",
"(",
")",
",",
"$",
"exclude",
"=",
"false",
")",
"{",
"return",
"$",
"this",
... | Gets select columns from a specific class for building a query.
@uses xPDOObject::getSelectColumns()
@param string $className The name of the class to build the column list
from.
@param string $tableAlias An optional alias for the class table, to be
used in complex queries with multiple tables.
@param string $columnPrefix An optional string with which to prefix the
columns returned, to avoid name collisions in return columns.
@param array $columns An optional array of columns to include.
@param boolean $exclude If true, will exclude columns in the previous
parameter, instead of including them.
@return string A valid SQL string of column names for a SELECT statement. | [
"Gets",
"select",
"columns",
"from",
"a",
"specific",
"class",
"for",
"building",
"a",
"query",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1784-L1786 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getFKDefinition | function getFKDefinition($parentClass, $alias) {
$def= null;
$parentClass= $this->loadClass($parentClass);
if ($parentClass && $alias) {
if ($aggregates= $this->getAggregates($parentClass)) {
if (isset ($aggregates[$alias])) {
$def= $aggregates[$alias];
$def['type']= 'aggregate';
}
}
if ($composites= $this->getComposites($parentClass)) {
if (isset ($composites[$alias])) {
$def= $composites[$alias];
$def['type']= 'composite';
}
}
}
if ($def === null) {
$this->log(xPDO::LOG_LEVEL_ERROR, 'No foreign key definition for parentClass: ' . $parentClass . ' using relation alias: ' . $alias);
}
return $def;
} | php | function getFKDefinition($parentClass, $alias) {
$def= null;
$parentClass= $this->loadClass($parentClass);
if ($parentClass && $alias) {
if ($aggregates= $this->getAggregates($parentClass)) {
if (isset ($aggregates[$alias])) {
$def= $aggregates[$alias];
$def['type']= 'aggregate';
}
}
if ($composites= $this->getComposites($parentClass)) {
if (isset ($composites[$alias])) {
$def= $composites[$alias];
$def['type']= 'composite';
}
}
}
if ($def === null) {
$this->log(xPDO::LOG_LEVEL_ERROR, 'No foreign key definition for parentClass: ' . $parentClass . ' using relation alias: ' . $alias);
}
return $def;
} | [
"function",
"getFKDefinition",
"(",
"$",
"parentClass",
",",
"$",
"alias",
")",
"{",
"$",
"def",
"=",
"null",
";",
"$",
"parentClass",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"parentClass",
")",
";",
"if",
"(",
"$",
"parentClass",
"&&",
"$",
"... | Gets an aggregate or composite relation definition from a class.
@param string $parentClass The class from which the relation is defined.
@param string $alias The alias identifying the related class.
@return array The aggregate or composite definition details in an array
or null if no definition is found. | [
"Gets",
"an",
"aggregate",
"or",
"composite",
"relation",
"definition",
"from",
"a",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1796-L1817 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getModelVersion | public function getModelVersion($className) {
$version = '1.0';
$className= $this->loadClass($className);
if ($className && isset($this->map[$className]['version'])) {
$version= $this->map[$className]['version'];
}
return $version;
} | php | public function getModelVersion($className) {
$version = '1.0';
$className= $this->loadClass($className);
if ($className && isset($this->map[$className]['version'])) {
$version= $this->map[$className]['version'];
}
return $version;
} | [
"public",
"function",
"getModelVersion",
"(",
"$",
"className",
")",
"{",
"$",
"version",
"=",
"'1.0'",
";",
"$",
"className",
"=",
"$",
"this",
"->",
"loadClass",
"(",
"$",
"className",
")",
";",
"if",
"(",
"$",
"className",
"&&",
"isset",
"(",
"$",
... | Gets the version string of the schema the specified class was generated from.
@param string $className The name of the class to get the model version from.
@return string The version string for the schema model the class was generated from. | [
"Gets",
"the",
"version",
"string",
"of",
"the",
"schema",
"the",
"specified",
"class",
"was",
"generated",
"from",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1825-L1832 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getManager | public function getManager() {
if ($this->manager === null || !$this->manager instanceof Om\xPDOManager) {
$managerClass = '\\xPDO\\Om\\' . $this->config['dbtype'] . '\\xPDOManager';
$this->manager= new $managerClass($this);
if (!$this->manager) {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not load xPDOManager class.");
}
}
return $this->manager;
} | php | public function getManager() {
if ($this->manager === null || !$this->manager instanceof Om\xPDOManager) {
$managerClass = '\\xPDO\\Om\\' . $this->config['dbtype'] . '\\xPDOManager';
$this->manager= new $managerClass($this);
if (!$this->manager) {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not load xPDOManager class.");
}
}
return $this->manager;
} | [
"public",
"function",
"getManager",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"manager",
"===",
"null",
"||",
"!",
"$",
"this",
"->",
"manager",
"instanceof",
"Om",
"\\",
"xPDOManager",
")",
"{",
"$",
"managerClass",
"=",
"'\\\\xPDO\\\\Om\\\\'",
".",
... | Gets the manager class for this xPDO connection.
The manager class can perform operations such as creating or altering
table structures, creating data containers, generating custom persistence
classes, and other advanced operations that do not need to be loaded
frequently.
@return Om\xPDOManager|null An xPDOManager instance for the xPDO connection, or null
if a manager class can not be instantiated. | [
"Gets",
"the",
"manager",
"class",
"for",
"this",
"xPDO",
"connection",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1845-L1854 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getDriver | public function getDriver() {
if ($this->driver === null || !$this->driver instanceof Om\xPDODriver) {
$driverClass = '\\xPDO\\Om\\' . $this->config['dbtype'] . '\\xPDODriver';
$this->driver= new $driverClass($this);
if (!$this->driver) {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not load xPDODriver class for the {$this->config['dbtype']} PDO driver.");
}
}
return $this->driver;
} | php | public function getDriver() {
if ($this->driver === null || !$this->driver instanceof Om\xPDODriver) {
$driverClass = '\\xPDO\\Om\\' . $this->config['dbtype'] . '\\xPDODriver';
$this->driver= new $driverClass($this);
if (!$this->driver) {
$this->log(xPDO::LOG_LEVEL_ERROR, "Could not load xPDODriver class for the {$this->config['dbtype']} PDO driver.");
}
}
return $this->driver;
} | [
"public",
"function",
"getDriver",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"driver",
"===",
"null",
"||",
"!",
"$",
"this",
"->",
"driver",
"instanceof",
"Om",
"\\",
"xPDODriver",
")",
"{",
"$",
"driverClass",
"=",
"'\\\\xPDO\\\\Om\\\\'",
".",
"$",
... | Gets the driver class for this xPDO connection.
The driver class provides baseline data and operations for a specific database driver.
@return Om\xPDODriver|null An xPDODriver instance for the xPDO connection, or null
if a driver class can not be instantiated. | [
"Gets",
"the",
"driver",
"class",
"for",
"this",
"xPDO",
"connection",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1864-L1873 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getCachePath | public function getCachePath() {
if (!$this->cachePath) {
if ($this->getCacheManager()) {
$this->cachePath= $this->cacheManager->getCachePath();
}
}
return $this->cachePath;
} | php | public function getCachePath() {
if (!$this->cachePath) {
if ($this->getCacheManager()) {
$this->cachePath= $this->cacheManager->getCachePath();
}
}
return $this->cachePath;
} | [
"public",
"function",
"getCachePath",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cachePath",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getCacheManager",
"(",
")",
")",
"{",
"$",
"this",
"->",
"cachePath",
"=",
"$",
"this",
"->",
"cacheManager"... | Gets the absolute path to the cache directory.
@return string The full cache directory path. | [
"Gets",
"the",
"absolute",
"path",
"to",
"the",
"cache",
"directory",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1880-L1887 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getCacheManager | public function getCacheManager($class= 'xPDO\\Cache\\xPDOCacheManager', $options = array('path' => XPDO_CORE_PATH, 'ignorePkg' => true)) {
if ($this->cacheManager === null || !is_object($this->cacheManager) || !($this->cacheManager instanceof $class)) {
if ($this->cacheManager= new $class($this, $options)) {
$this->_cacheEnabled= true;
}
}
return $this->cacheManager;
} | php | public function getCacheManager($class= 'xPDO\\Cache\\xPDOCacheManager', $options = array('path' => XPDO_CORE_PATH, 'ignorePkg' => true)) {
if ($this->cacheManager === null || !is_object($this->cacheManager) || !($this->cacheManager instanceof $class)) {
if ($this->cacheManager= new $class($this, $options)) {
$this->_cacheEnabled= true;
}
}
return $this->cacheManager;
} | [
"public",
"function",
"getCacheManager",
"(",
"$",
"class",
"=",
"'xPDO\\\\Cache\\\\xPDOCacheManager'",
",",
"$",
"options",
"=",
"array",
"(",
"'path'",
"=>",
"XPDO_CORE_PATH",
",",
"'ignorePkg'",
"=>",
"true",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"... | Gets an xPDOCacheManager instance.
This class is responsible for handling all types of caching operations for the xPDO core.
@param string $class Optional name of a derivative xPDOCacheManager class.
@param array $options An array of options for the cache manager instance; valid options include:
- path = Optional root path for looking up the $class.
- ignorePkg = If false and you do not specify a path, you can look up custom xPDOCacheManager
derivatives in declared packages.
@return Cache\xPDOCacheManager The xPDOCacheManager for this xPDO instance. | [
"Gets",
"an",
"xPDOCacheManager",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1901-L1908 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.setLogLevel | public function setLogLevel($level= xPDO::LOG_LEVEL_FATAL) {
$oldLevel = $this->logLevel;
$this->logLevel= intval($level);
return $oldLevel;
} | php | public function setLogLevel($level= xPDO::LOG_LEVEL_FATAL) {
$oldLevel = $this->logLevel;
$this->logLevel= intval($level);
return $oldLevel;
} | [
"public",
"function",
"setLogLevel",
"(",
"$",
"level",
"=",
"xPDO",
"::",
"LOG_LEVEL_FATAL",
")",
"{",
"$",
"oldLevel",
"=",
"$",
"this",
"->",
"logLevel",
";",
"$",
"this",
"->",
"logLevel",
"=",
"intval",
"(",
"$",
"level",
")",
";",
"return",
"$",
... | Sets the logging level state for the xPDO instance.
@param integer $level The logging level to switch to.
@return integer The previous log level. | [
"Sets",
"the",
"logging",
"level",
"state",
"for",
"the",
"xPDO",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1936-L1940 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.log | public function log($level, $msg, $target= '', $def= '', $file= '', $line= '') {
$this->_log($level, $msg, $target, $def, $file, $line);
} | php | public function log($level, $msg, $target= '', $def= '', $file= '', $line= '') {
$this->_log($level, $msg, $target, $def, $file, $line);
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"msg",
",",
"$",
"target",
"=",
"''",
",",
"$",
"def",
"=",
"''",
",",
"$",
"file",
"=",
"''",
",",
"$",
"line",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"_log",
"(",
"$",
"level",
",... | Log a message with details about where and when an event occurs.
@param integer $level The level of the logged message.
@param string $msg The message to log.
@param string $target The logging target.
@param string $def The name of a defining structure (such as a class) to
help identify the message source.
@param string $file A filename in which the log event occurred.
@param string $line A line number to help locate the source of the event
within the indicated file. | [
"Log",
"a",
"message",
"with",
"details",
"about",
"where",
"and",
"when",
"an",
"event",
"occurs",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L1992-L1994 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.getDebugBacktrace | public function getDebugBacktrace() {
$backtrace= array ();
foreach (debug_backtrace() as $levelKey => $levelElement) {
foreach ($levelElement as $traceKey => $traceElement) {
if ($traceKey == 'object' && $traceElement instanceof Om\xPDOObject) {
$backtrace[$levelKey][$traceKey]= $traceElement->toArray('', true);
} elseif ($traceKey == 'object') {
$backtrace[$levelKey][$traceKey]= get_class($traceElement);
} else {
$backtrace[$levelKey][$traceKey]= $traceElement;
}
}
}
return $backtrace;
} | php | public function getDebugBacktrace() {
$backtrace= array ();
foreach (debug_backtrace() as $levelKey => $levelElement) {
foreach ($levelElement as $traceKey => $traceElement) {
if ($traceKey == 'object' && $traceElement instanceof Om\xPDOObject) {
$backtrace[$levelKey][$traceKey]= $traceElement->toArray('', true);
} elseif ($traceKey == 'object') {
$backtrace[$levelKey][$traceKey]= get_class($traceElement);
} else {
$backtrace[$levelKey][$traceKey]= $traceElement;
}
}
}
return $backtrace;
} | [
"public",
"function",
"getDebugBacktrace",
"(",
")",
"{",
"$",
"backtrace",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"debug_backtrace",
"(",
")",
"as",
"$",
"levelKey",
"=>",
"$",
"levelElement",
")",
"{",
"foreach",
"(",
"$",
"levelElement",
"as",
"... | Returns an abbreviated backtrace of debugging information.
This function returns just the fields returned via xPDOObject::toArray()
on xPDOObject instances, and simply the class name for other objects, to
reduce the amount of unnecessary information returned.
@return array The abbreviated backtrace. | [
"Returns",
"an",
"abbreviated",
"backtrace",
"of",
"debugging",
"information",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2090-L2104 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO._getLogLevel | protected function _getLogLevel($level) {
switch ($level) {
case xPDO::LOG_LEVEL_DEBUG :
$levelText= 'DEBUG';
break;
case xPDO::LOG_LEVEL_INFO :
$levelText= 'INFO';
break;
case xPDO::LOG_LEVEL_WARN :
$levelText= 'WARN';
break;
case xPDO::LOG_LEVEL_ERROR :
$levelText= 'ERROR';
break;
default :
$levelText= 'FATAL';
}
return $levelText;
} | php | protected function _getLogLevel($level) {
switch ($level) {
case xPDO::LOG_LEVEL_DEBUG :
$levelText= 'DEBUG';
break;
case xPDO::LOG_LEVEL_INFO :
$levelText= 'INFO';
break;
case xPDO::LOG_LEVEL_WARN :
$levelText= 'WARN';
break;
case xPDO::LOG_LEVEL_ERROR :
$levelText= 'ERROR';
break;
default :
$levelText= 'FATAL';
}
return $levelText;
} | [
"protected",
"function",
"_getLogLevel",
"(",
"$",
"level",
")",
"{",
"switch",
"(",
"$",
"level",
")",
"{",
"case",
"xPDO",
"::",
"LOG_LEVEL_DEBUG",
":",
"$",
"levelText",
"=",
"'DEBUG'",
";",
"break",
";",
"case",
"xPDO",
"::",
"LOG_LEVEL_INFO",
":",
"... | Gets a logging level as a string representation.
@param integer $level The logging level to retrieve a string for.
@return string The string representation of a valid logging level. | [
"Gets",
"a",
"logging",
"level",
"as",
"a",
"string",
"representation",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2112-L2130 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.escape | public function escape($string) {
$string = trim($string, $this->_escapeCharOpen . $this->_escapeCharClose);
return $this->_escapeCharOpen . $string . $this->_escapeCharClose;
} | php | public function escape($string) {
$string = trim($string, $this->_escapeCharOpen . $this->_escapeCharClose);
return $this->_escapeCharOpen . $string . $this->_escapeCharClose;
} | [
"public",
"function",
"escape",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"_escapeCharOpen",
".",
"$",
"this",
"->",
"_escapeCharClose",
")",
";",
"return",
"$",
"this",
"->",
"_escapeCharOpen",... | Escapes the provided string using the platform-specific escape character.
Different database engines escape string literals in SQL using different characters. For example, this is used to
escape column names that might match a reserved string for that SQL interpreter. To write database agnostic
queries with xPDO, it is highly recommend to escape any database or column names in any native SQL strings used.
@param string $string A string to escape using the platform-specific escape characters.
@return string The string escaped with the platform-specific escape characters. | [
"Escapes",
"the",
"provided",
"string",
"using",
"the",
"platform",
"-",
"specific",
"escape",
"character",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2142-L2145 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.literal | public function literal($string) {
$string = trim($string, $this->_escapeCharOpen . $this->_escapeCharClose . $this->_quoteChar);
return $string;
} | php | public function literal($string) {
$string = trim($string, $this->_escapeCharOpen . $this->_escapeCharClose . $this->_quoteChar);
return $string;
} | [
"public",
"function",
"literal",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"_escapeCharOpen",
".",
"$",
"this",
"->",
"_escapeCharClose",
".",
"$",
"this",
"->",
"_quoteChar",
")",
";",
"retur... | Use to insert a literal string into a SQL query without escaping or quoting.
@param string $string A string to return as a literal, unescaped and unquoted.
@return string The string with any escape or quote characters trimmed. | [
"Use",
"to",
"insert",
"a",
"literal",
"string",
"into",
"a",
"SQL",
"query",
"without",
"escaping",
"or",
"quoting",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2153-L2156 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO._getFullTableName | private function _getFullTableName($baseTableName, $includeDb= false) {
$fqn= '';
if (!empty ($baseTableName)) {
if ($includeDb) {
$fqn .= $this->escape($this->config['dbname']) . '.';
}
$fqn .= $this->escape($baseTableName);
}
return $fqn;
} | php | private function _getFullTableName($baseTableName, $includeDb= false) {
$fqn= '';
if (!empty ($baseTableName)) {
if ($includeDb) {
$fqn .= $this->escape($this->config['dbname']) . '.';
}
$fqn .= $this->escape($baseTableName);
}
return $fqn;
} | [
"private",
"function",
"_getFullTableName",
"(",
"$",
"baseTableName",
",",
"$",
"includeDb",
"=",
"false",
")",
"{",
"$",
"fqn",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"baseTableName",
")",
")",
"{",
"if",
"(",
"$",
"includeDb",
")",
"{"... | Adds the table prefix, and optionally database name, to a given table.
@param string $baseTableName The table name as specified in the object
model.
@param boolean $includeDb Qualify the table name with the database name.
@return string The fully-qualified and quoted table name for the | [
"Adds",
"the",
"table",
"prefix",
"and",
"optionally",
"database",
"name",
"to",
"a",
"given",
"table",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2166-L2175 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.parseDSN | public static function parseDSN($string) {
$result= array ();
$pos= strpos($string, ':');
$result['dbtype']= strtolower(substr($string, 0, $pos));
$parameters= explode(';', substr($string, ($pos +1)));
for ($a= 0, $b= count($parameters); $a < $b; $a++) {
$tmp= explode('=', $parameters[$a]);
if (count($tmp) == 2) {
$result[strtolower(trim($tmp[0]))]= trim($tmp[1]);
} else {
$result['dbname']= trim($parameters[$a]);
}
}
if (!isset($result['dbname']) && isset($result['database'])) {
$result['dbname'] = $result['database'];
}
if (!isset($result['host']) && isset($result['server'])) {
$result['host'] = $result['server'];
}
return $result;
} | php | public static function parseDSN($string) {
$result= array ();
$pos= strpos($string, ':');
$result['dbtype']= strtolower(substr($string, 0, $pos));
$parameters= explode(';', substr($string, ($pos +1)));
for ($a= 0, $b= count($parameters); $a < $b; $a++) {
$tmp= explode('=', $parameters[$a]);
if (count($tmp) == 2) {
$result[strtolower(trim($tmp[0]))]= trim($tmp[1]);
} else {
$result['dbname']= trim($parameters[$a]);
}
}
if (!isset($result['dbname']) && isset($result['database'])) {
$result['dbname'] = $result['database'];
}
if (!isset($result['host']) && isset($result['server'])) {
$result['host'] = $result['server'];
}
return $result;
} | [
"public",
"static",
"function",
"parseDSN",
"(",
"$",
"string",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"string",
",",
"':'",
")",
";",
"$",
"result",
"[",
"'dbtype'",
"]",
"=",
"strtolower",
"(",
... | Parses a DSN and returns an array of the connection details.
@static
@param string $string The DSN to parse.
@return array An array of connection details from the DSN.
@todo Have this method handle all methods of DSN specification as handled
by latest native PDO implementation. | [
"Parses",
"a",
"DSN",
"and",
"returns",
"an",
"array",
"of",
"the",
"connection",
"details",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2186-L2206 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.fromJSON | public function fromJSON($src, $asArray= true) {
$decoded= '';
if ($src) {
if (!function_exists('json_decode')) {
throw new xPDOException();
} else {
$decoded= json_decode($src, $asArray);
}
}
return $decoded;
} | php | public function fromJSON($src, $asArray= true) {
$decoded= '';
if ($src) {
if (!function_exists('json_decode')) {
throw new xPDOException();
} else {
$decoded= json_decode($src, $asArray);
}
}
return $decoded;
} | [
"public",
"function",
"fromJSON",
"(",
"$",
"src",
",",
"$",
"asArray",
"=",
"true",
")",
"{",
"$",
"decoded",
"=",
"''",
";",
"if",
"(",
"$",
"src",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'json_decode'",
")",
")",
"{",
"throw",
"new",
... | Converts a JSON source string into an equivalent PHP representation.
@param string $src A JSON source string.
@param boolean $asArray Indicates if the result should treat objects as
associative arrays; since all JSON associative arrays are objects, the default
is true. Set to false to have JSON objects returned as PHP objects.
@throws xPDOException If json_decode is not available.
@return mixed The PHP representation of the JSON source. | [
"Converts",
"a",
"JSON",
"source",
"string",
"into",
"an",
"equivalent",
"PHP",
"representation",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2413-L2423 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.newQuery | public function newQuery($class, $criteria= null, $cacheFlag= true) {
$xpdoQueryClass= '\\xPDO\\Om\\' . $this->config['dbtype'] . '\\xPDOQuery';
if ($query= new $xpdoQueryClass($this, $class, $criteria)) {
$query->cacheFlag= $cacheFlag;
}
return $query;
} | php | public function newQuery($class, $criteria= null, $cacheFlag= true) {
$xpdoQueryClass= '\\xPDO\\Om\\' . $this->config['dbtype'] . '\\xPDOQuery';
if ($query= new $xpdoQueryClass($this, $class, $criteria)) {
$query->cacheFlag= $cacheFlag;
}
return $query;
} | [
"public",
"function",
"newQuery",
"(",
"$",
"class",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"xpdoQueryClass",
"=",
"'\\\\xPDO\\\\Om\\\\'",
".",
"$",
"this",
"->",
"config",
"[",
"'dbtype'",
"]",
".",
"'\\\\x... | Creates an new xPDOQuery for a specified xPDOObject class.
@param string $class The class to create the xPDOQuery for.
@param mixed $criteria Any valid xPDO criteria expression.
@param boolean|integer $cacheFlag Indicates if the result should be cached
and optionally for how many seconds (if passed an integer greater than 0).
@return Om\xPDOQuery The resulting xPDOQuery instance or false if unsuccessful. | [
"Creates",
"an",
"new",
"xPDOQuery",
"for",
"a",
"specified",
"xPDOObject",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2574-L2580 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.escSplit | public static function escSplit($char, $str, $escToken = '`', $limit = 0) {
$split= array();
$charPos = strpos($str, $char);
if ($charPos !== false) {
if ($charPos === 0) {
$searchPos = 1;
$startPos = 1;
} else {
$searchPos = 0;
$startPos = 0;
}
$escOpen = false;
$strlen = strlen($str);
for ($i = $startPos; $i <= $strlen; $i++) {
if ($i == $strlen) {
$tmp= trim(substr($str, $searchPos));
if (!empty($tmp)) $split[]= $tmp;
break;
}
if ($str[$i] == $escToken) {
$escOpen = $escOpen == true ? false : true;
continue;
}
if (!$escOpen && $str[$i] == $char) {
$tmp= trim(substr($str, $searchPos, $i - $searchPos));
if (!empty($tmp)) {
$split[]= $tmp;
if ($limit > 0 && count($split) >= $limit) {
break;
}
}
$searchPos = $i + 1;
}
}
} else {
$split[]= trim($str);
}
return $split;
} | php | public static function escSplit($char, $str, $escToken = '`', $limit = 0) {
$split= array();
$charPos = strpos($str, $char);
if ($charPos !== false) {
if ($charPos === 0) {
$searchPos = 1;
$startPos = 1;
} else {
$searchPos = 0;
$startPos = 0;
}
$escOpen = false;
$strlen = strlen($str);
for ($i = $startPos; $i <= $strlen; $i++) {
if ($i == $strlen) {
$tmp= trim(substr($str, $searchPos));
if (!empty($tmp)) $split[]= $tmp;
break;
}
if ($str[$i] == $escToken) {
$escOpen = $escOpen == true ? false : true;
continue;
}
if (!$escOpen && $str[$i] == $char) {
$tmp= trim(substr($str, $searchPos, $i - $searchPos));
if (!empty($tmp)) {
$split[]= $tmp;
if ($limit > 0 && count($split) >= $limit) {
break;
}
}
$searchPos = $i + 1;
}
}
} else {
$split[]= trim($str);
}
return $split;
} | [
"public",
"static",
"function",
"escSplit",
"(",
"$",
"char",
",",
"$",
"str",
",",
"$",
"escToken",
"=",
"'`'",
",",
"$",
"limit",
"=",
"0",
")",
"{",
"$",
"split",
"=",
"array",
"(",
")",
";",
"$",
"charPos",
"=",
"strpos",
"(",
"$",
"str",
"... | Splits a string on a specified character, ignoring escaped content.
@static
@param string $char A character to split the tag content on.
@param string $str The string to operate on.
@param string $escToken A character used to surround escaped content; all
content within a pair of these tokens will be ignored by the split
operation.
@param integer $limit Limit the number of results. Default is 0 which is
no limit. Note that setting the limit to 1 will only return the content
up to the first instance of the split character and will discard the
remainder of the string.
@return array An array of results from the split operation, or an empty
array. | [
"Splits",
"a",
"string",
"on",
"a",
"specified",
"character",
"ignoring",
"escaped",
"content",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2598-L2636 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.parseBindings | public function parseBindings($sql, $bindings) {
if (!empty($sql) && !empty($bindings)) {
$bound = array();
foreach ($bindings as $k => $param) {
if (!is_array($param)) {
$v= $param;
$type= $this->getPDOType($param);
$bindings[$k]= array(
'value' => $v,
'type' => $type
);
} else {
$v= $param['value'];
$type= $param['type'];
}
if (!$v) {
switch ($type) {
case \PDO::PARAM_INT:
$v= '0';
break;
case \PDO::PARAM_BOOL:
$v= '0';
break;
default:
break;
}
}
if ($type > 0) {
$v= $this->quote($v, $type);
} else {
$v= 'NULL';
}
if (!is_int($k) || substr($k, 0, 1) === ':') {
$pattern= '/' . $k . '\b/';
$bound[$pattern] = str_replace(array('\\', '$'), array('\\\\', '\$'), $v);
} else {
$pattern = '/(\?)(\b)?/';
$sql = preg_replace($pattern, ':' . $k . '$2', $sql, 1);
$bound['/:' . $k . '\b/'] = str_replace(array('\\', '$'), array('\\\\', '\$'), $v);
}
}
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "{$sql}\n" . print_r($bound, true));
}
if (!empty($bound)) {
$sql= preg_replace(array_keys($bound), array_values($bound), $sql);
}
}
return $sql;
} | php | public function parseBindings($sql, $bindings) {
if (!empty($sql) && !empty($bindings)) {
$bound = array();
foreach ($bindings as $k => $param) {
if (!is_array($param)) {
$v= $param;
$type= $this->getPDOType($param);
$bindings[$k]= array(
'value' => $v,
'type' => $type
);
} else {
$v= $param['value'];
$type= $param['type'];
}
if (!$v) {
switch ($type) {
case \PDO::PARAM_INT:
$v= '0';
break;
case \PDO::PARAM_BOOL:
$v= '0';
break;
default:
break;
}
}
if ($type > 0) {
$v= $this->quote($v, $type);
} else {
$v= 'NULL';
}
if (!is_int($k) || substr($k, 0, 1) === ':') {
$pattern= '/' . $k . '\b/';
$bound[$pattern] = str_replace(array('\\', '$'), array('\\\\', '\$'), $v);
} else {
$pattern = '/(\?)(\b)?/';
$sql = preg_replace($pattern, ':' . $k . '$2', $sql, 1);
$bound['/:' . $k . '\b/'] = str_replace(array('\\', '$'), array('\\\\', '\$'), $v);
}
}
if ($this->getDebug() === true) {
$this->log(xPDO::LOG_LEVEL_DEBUG, "{$sql}\n" . print_r($bound, true));
}
if (!empty($bound)) {
$sql= preg_replace(array_keys($bound), array_values($bound), $sql);
}
}
return $sql;
} | [
"public",
"function",
"parseBindings",
"(",
"$",
"sql",
",",
"$",
"bindings",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sql",
")",
"&&",
"!",
"empty",
"(",
"$",
"bindings",
")",
")",
"{",
"$",
"bound",
"=",
"array",
"(",
")",
";",
"foreach",
... | Parses parameter bindings in SQL prepared statements.
@param string $sql A SQL prepared statement to parse bindings in.
@param array $bindings An array of parameter bindings to use for the replacements.
@return string The SQL with the binding placeholders replaced. | [
"Parses",
"parameter",
"bindings",
"in",
"SQL",
"prepared",
"statements",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2645-L2694 | train |
modxcms/xpdo | src/xPDO/xPDO.php | xPDO.sanitizePKCriteria | protected function sanitizePKCriteria($className, &$criteria) {
if (is_scalar($criteria)) {
$pkType = $this->getPKType($className);
if (is_string($pkType)) {
if (is_string($criteria) && !xPDOQuery::isValidClause($criteria)) {
$criteria = null;
} else {
switch ($pkType) {
case 'int':
case 'integer':
$criteria = (int)$criteria;
break;
case 'string':
if (is_int($criteria)) {
$criteria = (string)$criteria;
}
break;
}
}
} elseif (is_array($pkType)) {
$criteria = null;
}
}
} | php | protected function sanitizePKCriteria($className, &$criteria) {
if (is_scalar($criteria)) {
$pkType = $this->getPKType($className);
if (is_string($pkType)) {
if (is_string($criteria) && !xPDOQuery::isValidClause($criteria)) {
$criteria = null;
} else {
switch ($pkType) {
case 'int':
case 'integer':
$criteria = (int)$criteria;
break;
case 'string':
if (is_int($criteria)) {
$criteria = (string)$criteria;
}
break;
}
}
} elseif (is_array($pkType)) {
$criteria = null;
}
}
} | [
"protected",
"function",
"sanitizePKCriteria",
"(",
"$",
"className",
",",
"&",
"$",
"criteria",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"criteria",
")",
")",
"{",
"$",
"pkType",
"=",
"$",
"this",
"->",
"getPKType",
"(",
"$",
"className",
")",
";",... | Sanitize criteria expected to represent primary key values.
@param string $className The name of the class.
@param mixed &$criteria A reference to the criteria being used. | [
"Sanitize",
"criteria",
"expected",
"to",
"represent",
"primary",
"key",
"values",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/xPDO.php#L2718-L2741 | train |
modxcms/xpdo | src/xPDO/Reflect/xPDOReflectionClass.php | xPDOReflectionClass.getSource | public function getSource($element = null, $start = null, $end = false, $includeComment = true) {
$source = false;
/* @var \ReflectionClass|\ReflectionFunctionAbstract|\ReflectionProperty $element */
if ($element === null) $element =& $this;
if ($element instanceof \ReflectionClass || $element instanceof \ReflectionFunctionAbstract) {
if (is_readable($element->getFileName())) {
try {
$sourceArray = $this->getSourceArray($element, $start, $end);
if ($includeComment) {
$comment = $element->getDocComment();
if (!empty($comment)) {
array_unshift($sourceArray, ($element instanceof \ReflectionClass ? '' : ' ') . "{$comment}\n");
}
}
$source = implode('', $sourceArray);
} catch (\Exception $e) {
throw new \xPDO\xPDOException("Error getting source from Reflection element: {$e->getMessage()}");
}
}
} elseif ($element instanceof \ReflectionProperty) {
$source = ' ';
if ($includeComment) {
$comment = $element->getDocComment();
if (!empty($comment)) {
$source = "\n {$comment}\n ";
}
}
if ($element->isPublic()) {
$source .= 'public ';
} elseif ($element->isProtected()) {
$source .= 'protected ';
} elseif ($element->isPrivate()) {
$source .= 'private ';
}
if ($element->isStatic()) {
$source .= 'static ';
}
$source .= '$' . $element->getName();
if (array_key_exists($element->getName(), $this->defaultProperties) && !is_null($this->defaultProperties[$element->getName()])) {
$source .= ' = ' . xPDOGenerator::varExport($this->defaultProperties[$element->getName()], 1);
}
$source .= ';';
}
return $source;
} | php | public function getSource($element = null, $start = null, $end = false, $includeComment = true) {
$source = false;
/* @var \ReflectionClass|\ReflectionFunctionAbstract|\ReflectionProperty $element */
if ($element === null) $element =& $this;
if ($element instanceof \ReflectionClass || $element instanceof \ReflectionFunctionAbstract) {
if (is_readable($element->getFileName())) {
try {
$sourceArray = $this->getSourceArray($element, $start, $end);
if ($includeComment) {
$comment = $element->getDocComment();
if (!empty($comment)) {
array_unshift($sourceArray, ($element instanceof \ReflectionClass ? '' : ' ') . "{$comment}\n");
}
}
$source = implode('', $sourceArray);
} catch (\Exception $e) {
throw new \xPDO\xPDOException("Error getting source from Reflection element: {$e->getMessage()}");
}
}
} elseif ($element instanceof \ReflectionProperty) {
$source = ' ';
if ($includeComment) {
$comment = $element->getDocComment();
if (!empty($comment)) {
$source = "\n {$comment}\n ";
}
}
if ($element->isPublic()) {
$source .= 'public ';
} elseif ($element->isProtected()) {
$source .= 'protected ';
} elseif ($element->isPrivate()) {
$source .= 'private ';
}
if ($element->isStatic()) {
$source .= 'static ';
}
$source .= '$' . $element->getName();
if (array_key_exists($element->getName(), $this->defaultProperties) && !is_null($this->defaultProperties[$element->getName()])) {
$source .= ' = ' . xPDOGenerator::varExport($this->defaultProperties[$element->getName()], 1);
}
$source .= ';';
}
return $source;
} | [
"public",
"function",
"getSource",
"(",
"$",
"element",
"=",
"null",
",",
"$",
"start",
"=",
"null",
",",
"$",
"end",
"=",
"false",
",",
"$",
"includeComment",
"=",
"true",
")",
"{",
"$",
"source",
"=",
"false",
";",
"/* @var \\ReflectionClass|\\Reflection... | Get the reconstructed source of the Class.
@param null $element
@param null $start
@param bool $end
@param bool $includeComment
@throws \xPDO\xPDOException
@return bool|string | [
"Get",
"the",
"reconstructed",
"source",
"of",
"the",
"Class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Reflect/xPDOReflectionClass.php#L34-L78 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.getCacheProvider | public function getCacheProvider($key = '', $options = array()) {
$objCache = null;
if (empty($key)) {
$key = $this->getOption(xPDO::OPT_CACHE_KEY, $options, 'default');
}
$objCacheClass= 'xPDO\\Cache\\xPDOFileCache';
if (!isset($this->caches[$key]) || !is_object($this->caches[$key])) {
if ($cacheClass = $this->getOption($key . '_' . xPDO::OPT_CACHE_HANDLER, $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options))) {
$cacheClass = $this->xpdo->loadClass($cacheClass, XPDO_CORE_PATH, false, true);
if ($cacheClass) {
$objCacheClass= $cacheClass;
}
}
$options[xPDO::OPT_CACHE_KEY]= $key;
$this->caches[$key] = new $objCacheClass($this->xpdo, $options);
if (empty($this->caches[$key]) || !$this->caches[$key]->isInitialized()) {
$this->caches[$key] = new xPDOFileCache($this->xpdo, $options);
}
$objCache = $this->caches[$key];
$objCacheClass= get_class($objCache);
} else {
$objCache =& $this->caches[$key];
$objCacheClass= get_class($objCache);
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Returning {$objCacheClass}:{$key} cache provider from available providers: " . print_r(array_keys($this->caches), 1));
return $objCache;
} | php | public function getCacheProvider($key = '', $options = array()) {
$objCache = null;
if (empty($key)) {
$key = $this->getOption(xPDO::OPT_CACHE_KEY, $options, 'default');
}
$objCacheClass= 'xPDO\\Cache\\xPDOFileCache';
if (!isset($this->caches[$key]) || !is_object($this->caches[$key])) {
if ($cacheClass = $this->getOption($key . '_' . xPDO::OPT_CACHE_HANDLER, $options, $this->getOption(xPDO::OPT_CACHE_HANDLER, $options))) {
$cacheClass = $this->xpdo->loadClass($cacheClass, XPDO_CORE_PATH, false, true);
if ($cacheClass) {
$objCacheClass= $cacheClass;
}
}
$options[xPDO::OPT_CACHE_KEY]= $key;
$this->caches[$key] = new $objCacheClass($this->xpdo, $options);
if (empty($this->caches[$key]) || !$this->caches[$key]->isInitialized()) {
$this->caches[$key] = new xPDOFileCache($this->xpdo, $options);
}
$objCache = $this->caches[$key];
$objCacheClass= get_class($objCache);
} else {
$objCache =& $this->caches[$key];
$objCacheClass= get_class($objCache);
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Returning {$objCacheClass}:{$key} cache provider from available providers: " . print_r(array_keys($this->caches), 1));
return $objCache;
} | [
"public",
"function",
"getCacheProvider",
"(",
"$",
"key",
"=",
"''",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"objCache",
"=",
"null",
";",
"if",
"(",
"empty",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"-... | Get an instance of a provider which implements the xPDOCache interface.
@param string $key
@param array $options
@return xPDOCache|null | [
"Get",
"an",
"instance",
"of",
"a",
"provider",
"which",
"implements",
"the",
"xPDOCache",
"interface",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L47-L73 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.getCachePath | public function getCachePath() {
$cachePath= false;
if (!isset ($this->xpdo->config['cache_path'])) {
while (true) {
if (!empty ($_ENV['TMP'])) {
if ($cachePath= strtr($_ENV['TMP'], '\\', '/'))
break;
}
if (!empty ($_ENV['TMPDIR'])) {
if ($cachePath= strtr($_ENV['TMPDIR'], '\\', '/'))
break;
}
if (!empty ($_ENV['TEMP'])) {
if ($cachePath= strtr($_ENV['TEMP'], '\\', '/'))
break;
}
if ($temp_file= @ tempnam(md5(uniqid(rand(), true)), '')) {
$cachePath= strtr(dirname($temp_file), '\\', '/');
@ unlink($temp_file);
}
break;
}
if ($cachePath) {
if ($cachePath{strlen($cachePath) - 1} != '/') $cachePath .= '/';
$cachePath .= '.xpdo-cache';
}
}
else {
$cachePath= strtr($this->xpdo->config['cache_path'], '\\', '/');
}
if ($cachePath) {
$perms = $this->getOption('new_folder_permissions', null, $this->getFolderPermissions());
if (is_string($perms)) $perms = octdec($perms);
if (@ $this->writeTree($cachePath, $perms)) {
if ($cachePath{strlen($cachePath) - 1} != '/') $cachePath .= '/';
if (!is_writeable($cachePath)) {
@ chmod($cachePath, $perms);
}
} else {
$cachePath= false;
}
}
return $cachePath;
} | php | public function getCachePath() {
$cachePath= false;
if (!isset ($this->xpdo->config['cache_path'])) {
while (true) {
if (!empty ($_ENV['TMP'])) {
if ($cachePath= strtr($_ENV['TMP'], '\\', '/'))
break;
}
if (!empty ($_ENV['TMPDIR'])) {
if ($cachePath= strtr($_ENV['TMPDIR'], '\\', '/'))
break;
}
if (!empty ($_ENV['TEMP'])) {
if ($cachePath= strtr($_ENV['TEMP'], '\\', '/'))
break;
}
if ($temp_file= @ tempnam(md5(uniqid(rand(), true)), '')) {
$cachePath= strtr(dirname($temp_file), '\\', '/');
@ unlink($temp_file);
}
break;
}
if ($cachePath) {
if ($cachePath{strlen($cachePath) - 1} != '/') $cachePath .= '/';
$cachePath .= '.xpdo-cache';
}
}
else {
$cachePath= strtr($this->xpdo->config['cache_path'], '\\', '/');
}
if ($cachePath) {
$perms = $this->getOption('new_folder_permissions', null, $this->getFolderPermissions());
if (is_string($perms)) $perms = octdec($perms);
if (@ $this->writeTree($cachePath, $perms)) {
if ($cachePath{strlen($cachePath) - 1} != '/') $cachePath .= '/';
if (!is_writeable($cachePath)) {
@ chmod($cachePath, $perms);
}
} else {
$cachePath= false;
}
}
return $cachePath;
} | [
"public",
"function",
"getCachePath",
"(",
")",
"{",
"$",
"cachePath",
"=",
"false",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"xpdo",
"->",
"config",
"[",
"'cache_path'",
"]",
")",
")",
"{",
"while",
"(",
"true",
")",
"{",
"if",
"(",
... | Get the absolute path to a writable directory for storing files.
@access public
@return string The absolute path of the xPDO cache directory. | [
"Get",
"the",
"absolute",
"path",
"to",
"a",
"writable",
"directory",
"for",
"storing",
"files",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L134-L177 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.writeFile | public function writeFile($filename, $content, $mode= 'wb', $options= array()) {
$written= false;
if (!is_array($options)) {
$options = is_scalar($options) && !is_bool($options) ? array('new_folder_permissions' => $options) : array();
}
$dirname= dirname($filename);
if (!file_exists($dirname)) {
$this->writeTree($dirname, $options);
}
$mode = str_replace('+', '', $mode);
switch ($mode[0]) {
case 'a':
$append = true;
break;
default:
$append = false;
break;
}
$fmode = (strlen($mode) > 1 && in_array($mode[1], array('b', 't'))) ? "a{$mode[1]}" : 'a';
$file= @fopen($filename, $fmode);
if ($file) {
if ($append === true) {
$written= fwrite($file, $content);
} else {
$locked = false;
$attempt = 1;
$attempts = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 1);
$attemptDelay = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000);
while (!$locked && ($attempts === 0 || $attempt <= $attempts)) {
if ($this->getOption('use_flock', $options, true)) {
$locked = flock($file, LOCK_EX | LOCK_NB);
} else {
$lockFile = $this->lockFile($filename, $options);
$locked = $lockFile != false;
}
if (!$locked && $attemptDelay > 0 && ($attempts === 0 || $attempt < $attempts)) {
usleep($attemptDelay);
}
$attempt++;
}
if ($locked) {
fseek($file, 0);
ftruncate($file, 0);
$written= fwrite($file, $content);
if ($this->getOption('use_flock', $options, true)) {
flock($file, LOCK_UN);
} else {
$this->unlockFile($filename, $options);
}
}
}
@fclose($file);
}
return ($written !== false);
} | php | public function writeFile($filename, $content, $mode= 'wb', $options= array()) {
$written= false;
if (!is_array($options)) {
$options = is_scalar($options) && !is_bool($options) ? array('new_folder_permissions' => $options) : array();
}
$dirname= dirname($filename);
if (!file_exists($dirname)) {
$this->writeTree($dirname, $options);
}
$mode = str_replace('+', '', $mode);
switch ($mode[0]) {
case 'a':
$append = true;
break;
default:
$append = false;
break;
}
$fmode = (strlen($mode) > 1 && in_array($mode[1], array('b', 't'))) ? "a{$mode[1]}" : 'a';
$file= @fopen($filename, $fmode);
if ($file) {
if ($append === true) {
$written= fwrite($file, $content);
} else {
$locked = false;
$attempt = 1;
$attempts = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPTS, $options, 1);
$attemptDelay = (integer) $this->getOption(xPDO::OPT_CACHE_ATTEMPT_DELAY, $options, 1000);
while (!$locked && ($attempts === 0 || $attempt <= $attempts)) {
if ($this->getOption('use_flock', $options, true)) {
$locked = flock($file, LOCK_EX | LOCK_NB);
} else {
$lockFile = $this->lockFile($filename, $options);
$locked = $lockFile != false;
}
if (!$locked && $attemptDelay > 0 && ($attempts === 0 || $attempt < $attempts)) {
usleep($attemptDelay);
}
$attempt++;
}
if ($locked) {
fseek($file, 0);
ftruncate($file, 0);
$written= fwrite($file, $content);
if ($this->getOption('use_flock', $options, true)) {
flock($file, LOCK_UN);
} else {
$this->unlockFile($filename, $options);
}
}
}
@fclose($file);
}
return ($written !== false);
} | [
"public",
"function",
"writeFile",
"(",
"$",
"filename",
",",
"$",
"content",
",",
"$",
"mode",
"=",
"'wb'",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"written",
"=",
"false",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
... | Writes a file to the filesystem.
@access public
@param string $filename The absolute path to the location the file will
be written in.
@param string $content The content of the newly written file.
@param string $mode The php file mode to write in. Defaults to 'wb'. Note that this method always
uses a (with b or t if specified) to open the file and that any mode except a means existing file
contents will be overwritten.
@param array $options An array of options for the function.
@return int|bool Returns the number of bytes written to the file or false on failure. | [
"Writes",
"a",
"file",
"to",
"the",
"filesystem",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L192-L246 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.lockFile | public function lockFile($file, array $options = array()) {
$locked = false;
$lockDir = $this->getOption('lock_dir', $options, $this->getCachePath() . 'locks' . DIRECTORY_SEPARATOR);
if ($this->writeTree($lockDir, $options)) {
$lockFile = $this->lockFileName($file, $options);
if (!file_exists($lockFile)) {
$myPID = (php_sapi_name() == 'cli' || !isset($_SERVER['SERVER_ADDR']) ? gethostname() : $_SERVER['SERVER_ADDR']) . '.' . getmypid();
$myPID .= mt_rand();
$tmpLockFile = "{$lockFile}.{$myPID}";
if (file_put_contents($tmpLockFile, $myPID)) {
if (link($tmpLockFile, $lockFile)) {
$locked = true;
}
@unlink($tmpLockFile);
}
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "The lock_dir at {$lockDir} is not writable and could not be created");
}
if (!$locked) $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "Attempt to lock file {$file} failed");
return $locked;
} | php | public function lockFile($file, array $options = array()) {
$locked = false;
$lockDir = $this->getOption('lock_dir', $options, $this->getCachePath() . 'locks' . DIRECTORY_SEPARATOR);
if ($this->writeTree($lockDir, $options)) {
$lockFile = $this->lockFileName($file, $options);
if (!file_exists($lockFile)) {
$myPID = (php_sapi_name() == 'cli' || !isset($_SERVER['SERVER_ADDR']) ? gethostname() : $_SERVER['SERVER_ADDR']) . '.' . getmypid();
$myPID .= mt_rand();
$tmpLockFile = "{$lockFile}.{$myPID}";
if (file_put_contents($tmpLockFile, $myPID)) {
if (link($tmpLockFile, $lockFile)) {
$locked = true;
}
@unlink($tmpLockFile);
}
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "The lock_dir at {$lockDir} is not writable and could not be created");
}
if (!$locked) $this->xpdo->log(xPDO::LOG_LEVEL_WARN, "Attempt to lock file {$file} failed");
return $locked;
} | [
"public",
"function",
"lockFile",
"(",
"$",
"file",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"locked",
"=",
"false",
";",
"$",
"lockDir",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'lock_dir'",
",",
"$",
"options",
",",
... | Add an exclusive lock to a file for atomic write operations in multi-threaded environments.
xPDO::OPT_USE_FLOCK must be set to false (or 0) or xPDO will assume flock is reliable.
@param string $file The name of the file to lock.
@param array $options An array of options for the process.
@return boolean True only if the current process obtained an exclusive lock for writing. | [
"Add",
"an",
"exclusive",
"lock",
"to",
"a",
"file",
"for",
"atomic",
"write",
"operations",
"in",
"multi",
"-",
"threaded",
"environments",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L257-L278 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.lockFileName | protected function lockFileName($file, array $options = array()) {
$lockDir = $this->getOption('lock_dir', $options, $this->getCachePath() . 'locks' . DIRECTORY_SEPARATOR);
return $lockDir . preg_replace('/\W/', '_', $file) . $this->getOption(xPDO::OPT_LOCKFILE_EXTENSION, $options, '.lock');
} | php | protected function lockFileName($file, array $options = array()) {
$lockDir = $this->getOption('lock_dir', $options, $this->getCachePath() . 'locks' . DIRECTORY_SEPARATOR);
return $lockDir . preg_replace('/\W/', '_', $file) . $this->getOption(xPDO::OPT_LOCKFILE_EXTENSION, $options, '.lock');
} | [
"protected",
"function",
"lockFileName",
"(",
"$",
"file",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"lockDir",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'lock_dir'",
",",
"$",
"options",
",",
"$",
"this",
"->",
"getCachePat... | Get an absolute path to a lock file for a specified file path.
@param string $file The absolute path to get the lock filename for.
@param array $options An array of options for the process.
@return string The absolute path for the lock file | [
"Get",
"an",
"absolute",
"path",
"to",
"a",
"lock",
"file",
"for",
"a",
"specified",
"file",
"path",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L297-L300 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.writeTree | public function writeTree($dirname, $options= array()) {
$written= false;
if (!empty ($dirname)) {
if (!is_array($options)) $options = is_scalar($options) && !is_bool($options) ? array('new_folder_permissions' => $options) : array();
$mode = $this->getOption('new_folder_permissions', $options, $this->getFolderPermissions());
if (is_string($mode)) $mode = octdec($mode);
$dirname= strtr(trim($dirname), '\\', '/');
if ($dirname{strlen($dirname) - 1} == '/') $dirname = substr($dirname, 0, strlen($dirname) - 1);
if (is_dir($dirname) || (is_writable(dirname($dirname)) && @mkdir($dirname, $mode))) {
$written= true;
} elseif (!$this->writeTree(dirname($dirname), $options)) {
$written= false;
} else {
$written= @ mkdir($dirname, $mode);
}
if ($written && !is_writable($dirname)) {
@ chmod($dirname, $mode);
}
}
return $written;
} | php | public function writeTree($dirname, $options= array()) {
$written= false;
if (!empty ($dirname)) {
if (!is_array($options)) $options = is_scalar($options) && !is_bool($options) ? array('new_folder_permissions' => $options) : array();
$mode = $this->getOption('new_folder_permissions', $options, $this->getFolderPermissions());
if (is_string($mode)) $mode = octdec($mode);
$dirname= strtr(trim($dirname), '\\', '/');
if ($dirname{strlen($dirname) - 1} == '/') $dirname = substr($dirname, 0, strlen($dirname) - 1);
if (is_dir($dirname) || (is_writable(dirname($dirname)) && @mkdir($dirname, $mode))) {
$written= true;
} elseif (!$this->writeTree(dirname($dirname), $options)) {
$written= false;
} else {
$written= @ mkdir($dirname, $mode);
}
if ($written && !is_writable($dirname)) {
@ chmod($dirname, $mode);
}
}
return $written;
} | [
"public",
"function",
"writeTree",
"(",
"$",
"dirname",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"written",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dirname",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
... | Recursively writes a directory tree of files to the filesystem
@access public
@param string $dirname The directory to write
@param array $options An array of options for the function. Can also be a value representing
a permissions mode to write new directories with, though this is deprecated.
@return boolean Returns true if the directory was successfully written. | [
"Recursively",
"writes",
"a",
"directory",
"tree",
"of",
"files",
"to",
"the",
"filesystem"
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L311-L331 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.copyFile | public function copyFile($source, $target, $options = array()) {
$copied= false;
if (!is_array($options)) $options = is_scalar($options) && !is_bool($options) ? array('new_file_permissions' => $options) : array();
if (func_num_args() === 4) $options['new_folder_permissions'] = func_get_arg(3);
if ($this->writeTree(dirname($target), $options)) {
$existed= file_exists($target);
if ($existed && $this->getOption('copy_newer_only', $options, false) && (($ttime = filemtime($target)) > ($stime = filemtime($source)))) {
$this->xpdo->log(xPDO::LOG_LEVEL_INFO, "xPDOCacheManager->copyFile(): Skipping copy of newer file {$target} ({$ttime}) from {$source} ({$stime})");
} else {
$copied= copy($source, $target);
}
if ($copied) {
if (!$this->getOption('copy_preserve_permissions', $options, false)) {
$fileMode = $this->getOption('new_file_permissions', $options, $this->getFilePermissions());
if (is_string($fileMode)) $fileMode = octdec($fileMode);
@ chmod($target, $fileMode);
}
if ($this->getOption('copy_preserve_filemtime', $options, true)) @ touch($target, filemtime($source));
if ($this->getOption('copy_return_file_stat', $options, false)) {
$stat = stat($target);
if (is_array($stat)) {
$stat['overwritten']= $existed;
$copied = array($target => $stat);
}
}
}
}
if (!$copied) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOCacheManager->copyFile(): Could not copy file {$source} to {$target}");
}
return $copied;
} | php | public function copyFile($source, $target, $options = array()) {
$copied= false;
if (!is_array($options)) $options = is_scalar($options) && !is_bool($options) ? array('new_file_permissions' => $options) : array();
if (func_num_args() === 4) $options['new_folder_permissions'] = func_get_arg(3);
if ($this->writeTree(dirname($target), $options)) {
$existed= file_exists($target);
if ($existed && $this->getOption('copy_newer_only', $options, false) && (($ttime = filemtime($target)) > ($stime = filemtime($source)))) {
$this->xpdo->log(xPDO::LOG_LEVEL_INFO, "xPDOCacheManager->copyFile(): Skipping copy of newer file {$target} ({$ttime}) from {$source} ({$stime})");
} else {
$copied= copy($source, $target);
}
if ($copied) {
if (!$this->getOption('copy_preserve_permissions', $options, false)) {
$fileMode = $this->getOption('new_file_permissions', $options, $this->getFilePermissions());
if (is_string($fileMode)) $fileMode = octdec($fileMode);
@ chmod($target, $fileMode);
}
if ($this->getOption('copy_preserve_filemtime', $options, true)) @ touch($target, filemtime($source));
if ($this->getOption('copy_return_file_stat', $options, false)) {
$stat = stat($target);
if (is_array($stat)) {
$stat['overwritten']= $existed;
$copied = array($target => $stat);
}
}
}
}
if (!$copied) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "xPDOCacheManager->copyFile(): Could not copy file {$source} to {$target}");
}
return $copied;
} | [
"public",
"function",
"copyFile",
"(",
"$",
"source",
",",
"$",
"target",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"copied",
"=",
"false",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"$",
"options",
"=",
"is... | Copies a file from a source file to a target directory.
@access public
@param string $source The absolute path of the source file.
@param string $target The absolute path of the target destination
directory.
@param array $options An array of options for this function.
@return boolean|array Returns true if the copy operation was successful, or a single element
array with filename as key and stat results of the successfully copied file as a result. | [
"Copies",
"a",
"file",
"from",
"a",
"source",
"file",
"to",
"a",
"target",
"directory",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L344-L375 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.endsWith | public function endsWith($string, $pattern) {
$matched= false;
if (is_string($string) && ($stringLen= strlen($string))) {
if (is_array($pattern)) {
foreach ($pattern as $subPattern) {
if (is_string($subPattern) && $this->endsWith($string, $subPattern)) {
$matched= true;
break;
}
}
} elseif (is_string($pattern)) {
if (($patternLen= strlen($pattern)) && $stringLen >= $patternLen) {
$matched= (substr($string, -$patternLen) === $pattern);
}
}
}
return $matched;
} | php | public function endsWith($string, $pattern) {
$matched= false;
if (is_string($string) && ($stringLen= strlen($string))) {
if (is_array($pattern)) {
foreach ($pattern as $subPattern) {
if (is_string($subPattern) && $this->endsWith($string, $subPattern)) {
$matched= true;
break;
}
}
} elseif (is_string($pattern)) {
if (($patternLen= strlen($pattern)) && $stringLen >= $patternLen) {
$matched= (substr($string, -$patternLen) === $pattern);
}
}
}
return $matched;
} | [
"public",
"function",
"endsWith",
"(",
"$",
"string",
",",
"$",
"pattern",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
"&&",
"(",
"$",
"stringLen",
"=",
"strlen",
"(",
"$",
"string",
")",
")",
")",
... | Sees if a string ends with a specific pattern or set of patterns.
@access public
@param string $string The string to check.
@param string|array $pattern The pattern or an array of patterns to check against.
@return boolean True if the string ends with the pattern or any of the patterns provided. | [
"Sees",
"if",
"a",
"string",
"ends",
"with",
"a",
"specific",
"pattern",
"or",
"set",
"of",
"patterns",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L528-L545 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.matches | public function matches($string, $pattern) {
$matched= false;
if (is_string($string) && ($stringLen= strlen($string))) {
if (is_array($pattern)) {
foreach ($pattern as $subPattern) {
if (is_string($subPattern) && $this->matches($string, $subPattern)) {
$matched= true;
break;
}
}
} elseif (is_string($pattern)) {
$matched= preg_match($pattern, $string);
}
}
return $matched;
} | php | public function matches($string, $pattern) {
$matched= false;
if (is_string($string) && ($stringLen= strlen($string))) {
if (is_array($pattern)) {
foreach ($pattern as $subPattern) {
if (is_string($subPattern) && $this->matches($string, $subPattern)) {
$matched= true;
break;
}
}
} elseif (is_string($pattern)) {
$matched= preg_match($pattern, $string);
}
}
return $matched;
} | [
"public",
"function",
"matches",
"(",
"$",
"string",
",",
"$",
"pattern",
")",
"{",
"$",
"matched",
"=",
"false",
";",
"if",
"(",
"is_string",
"(",
"$",
"string",
")",
"&&",
"(",
"$",
"stringLen",
"=",
"strlen",
"(",
"$",
"string",
")",
")",
")",
... | Sees if a string matches a specific pattern or set of patterns.
@access public
@param string $string The string to check.
@param string|array $pattern The pattern or an array of patterns to check against.
@return boolean True if the string matched the pattern or any of the patterns provided. | [
"Sees",
"if",
"a",
"string",
"matches",
"a",
"specific",
"pattern",
"or",
"set",
"of",
"patterns",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L555-L570 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.generateObject | public function generateObject($obj, $objName, $generateObjVars= false, $generateRelated= false, $objRef= 'this->xpdo', $format= xPDOCacheManager::CACHE_PHP) {
$source= false;
if (is_object($obj) && $obj instanceof \xPDO\Om\xPDOObject) {
$className= $obj->_class;
$source= "\${$objName}= \${$objRef}->newObject('{$className}');\n";
$source .= "\${$objName}->fromArray(" . var_export($obj->toArray('', true), true) . ", '', true, true);\n";
if ($generateObjVars && $objectVars= get_object_vars($obj)) {
foreach ($objectVars as $vk => $vv) {
if ($vk === 'modx') {
$source .= "\${$objName}->{$vk}= & \${$objRef};\n";
}
elseif ($vk === 'xpdo') {
$source .= "\${$objName}->{$vk}= & \${$objRef};\n";
}
elseif (!is_resource($vv)) {
$source .= "\${$objName}->{$vk}= " . var_export($vv, true) . ";\n";
}
}
}
if ($generateRelated && !empty ($obj->_relatedObjects)) {
foreach ($obj->_relatedObjects as $className => $fk) {
foreach ($fk as $key => $relObj) {} /* TODO: complete $generateRelated functionality */
}
}
}
return $source;
} | php | public function generateObject($obj, $objName, $generateObjVars= false, $generateRelated= false, $objRef= 'this->xpdo', $format= xPDOCacheManager::CACHE_PHP) {
$source= false;
if (is_object($obj) && $obj instanceof \xPDO\Om\xPDOObject) {
$className= $obj->_class;
$source= "\${$objName}= \${$objRef}->newObject('{$className}');\n";
$source .= "\${$objName}->fromArray(" . var_export($obj->toArray('', true), true) . ", '', true, true);\n";
if ($generateObjVars && $objectVars= get_object_vars($obj)) {
foreach ($objectVars as $vk => $vv) {
if ($vk === 'modx') {
$source .= "\${$objName}->{$vk}= & \${$objRef};\n";
}
elseif ($vk === 'xpdo') {
$source .= "\${$objName}->{$vk}= & \${$objRef};\n";
}
elseif (!is_resource($vv)) {
$source .= "\${$objName}->{$vk}= " . var_export($vv, true) . ";\n";
}
}
}
if ($generateRelated && !empty ($obj->_relatedObjects)) {
foreach ($obj->_relatedObjects as $className => $fk) {
foreach ($fk as $key => $relObj) {} /* TODO: complete $generateRelated functionality */
}
}
}
return $source;
} | [
"public",
"function",
"generateObject",
"(",
"$",
"obj",
",",
"$",
"objName",
",",
"$",
"generateObjVars",
"=",
"false",
",",
"$",
"generateRelated",
"=",
"false",
",",
"$",
"objRef",
"=",
"'this->xpdo'",
",",
"$",
"format",
"=",
"xPDOCacheManager",
"::",
... | Generate a PHP executable representation of an xPDOObject.
@todo Complete $generateRelated functionality.
@todo Add stdObject support.
@access public
@param \xPDO\Om\xPDOObject $obj An xPDOObject to generate the cache file for
@param string $objName The name of the xPDOObject
@param boolean $generateObjVars If true, will also generate maps for all
object variables. Defaults to false.
@param boolean $generateRelated If true, will also generate maps for all
related objects. Defaults to false.
@param string $objRef The reference to the xPDO instance, in string
format.
@param int $format The format to cache in. Defaults to
xPDOCacheManager::CACHE_PHP, which is set to cache in executable PHP format.
@return string The source map file, in string format. | [
"Generate",
"a",
"PHP",
"executable",
"representation",
"of",
"an",
"xPDOObject",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L591-L617 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.add | public function add($key, & $var, $lifetime= 0, $options= array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options))) {
$value= null;
if (is_object($var) && $var instanceof \xPDO\Om\xPDOObject) {
$value= $var->toArray('', true);
} else {
$value= $var;
}
$return= $cache->add($key, $value, $lifetime, $options);
}
return $return;
} | php | public function add($key, & $var, $lifetime= 0, $options= array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options))) {
$value= null;
if (is_object($var) && $var instanceof \xPDO\Om\xPDOObject) {
$value= $var->toArray('', true);
} else {
$value= $var;
}
$return= $cache->add($key, $value, $lifetime, $options);
}
return $return;
} | [
"public",
"function",
"add",
"(",
"$",
"key",
",",
"&",
"$",
"var",
",",
"$",
"lifetime",
"=",
"0",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"return",
"=",
"false",
";",
"if",
"(",
"$",
"cache",
"=",
"$",
"this",
"->",
"get... | Add a key-value pair to a cache provider if it does not already exist.
@param string $key A unique key identifying the item being stored.
@param mixed & $var A reference to the PHP variable representing the item.
@param integer $lifetime Seconds the item will be valid in cache.
@param array $options Additional options for the cache add operation.
@return boolean True if the add was successful. | [
"Add",
"a",
"key",
"-",
"value",
"pair",
"to",
"a",
"cache",
"provider",
"if",
"it",
"does",
"not",
"already",
"exist",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L628-L640 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.set | public function set($key, & $var, $lifetime= 0, $options= array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options), $options)) {
$value= null;
if (is_object($var) && $var instanceof \xPDO\Om\xPDOObject) {
$value= $var->toArray('', true);
} else {
$value= $var;
}
$return= $cache->set($key, $value, $lifetime, $options);
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No cache implementation found.');
}
return $return;
} | php | public function set($key, & $var, $lifetime= 0, $options= array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options), $options)) {
$value= null;
if (is_object($var) && $var instanceof \xPDO\Om\xPDOObject) {
$value= $var->toArray('', true);
} else {
$value= $var;
}
$return= $cache->set($key, $value, $lifetime, $options);
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No cache implementation found.');
}
return $return;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"&",
"$",
"var",
",",
"$",
"lifetime",
"=",
"0",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"return",
"=",
"false",
";",
"if",
"(",
"$",
"cache",
"=",
"$",
"this",
"->",
"get... | Set a key-value pair in a cache provider.
@access public
@param string $key A unique key identifying the item being set.
@param mixed & $var A reference to the PHP variable representing the item.
@param integer $lifetime Seconds the item will be valid in objcache.
@param array $options Additional options for the cache set operation.
@return boolean True if the set was successful | [
"Set",
"a",
"key",
"-",
"value",
"pair",
"in",
"a",
"cache",
"provider",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L676-L690 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.delete | public function delete($key, $options = array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options), $options)) {
$return= $cache->delete($key, $options);
}
return $return;
} | php | public function delete($key, $options = array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options), $options)) {
$return= $cache->delete($key, $options);
}
return $return;
} | [
"public",
"function",
"delete",
"(",
"$",
"key",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"return",
"=",
"false",
";",
"if",
"(",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCacheProvider",
"(",
"$",
"this",
"->",
"getOption",
"(",... | Delete a key-value pair from a cache provider.
@access public
@param string $key A unique key identifying the item being deleted.
@param array $options Additional options for the cache deletion.
@return boolean True if the deletion was successful. | [
"Delete",
"a",
"key",
"-",
"value",
"pair",
"from",
"a",
"cache",
"provider",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L700-L706 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.clean | public function clean($options = array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options), $options)) {
$return= $cache->flush($options);
}
return $return;
} | php | public function clean($options = array()) {
$return= false;
if ($cache = $this->getCacheProvider($this->getOption(xPDO::OPT_CACHE_KEY, $options), $options)) {
$return= $cache->flush($options);
}
return $return;
} | [
"public",
"function",
"clean",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"return",
"=",
"false",
";",
"if",
"(",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCacheProvider",
"(",
"$",
"this",
"->",
"getOption",
"(",
"xPDO",
"::",
"OP... | Flush the contents of a cache provider.
@access public
@param array $options Additional options for the cache flush.
@return boolean True if the flush was successful. | [
"Flush",
"the",
"contents",
"of",
"a",
"cache",
"provider",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L731-L737 | train |
modxcms/xpdo | src/xPDO/Cache/xPDOCacheManager.php | xPDOCacheManager.refresh | public function refresh(array $providers = array(), array &$results = array()) {
if (empty($providers)) {
foreach ($this->caches as $cacheKey => $cache) {
$providers[$cacheKey] = array();
}
}
foreach ($providers as $key => $options) {
if (array_key_exists($key, $this->caches) && !array_key_exists($key, $results)) {
$results[$key] = $this->clean(array_merge($options, array(xPDO::OPT_CACHE_KEY => $key)));
}
}
return (array_search(false, $results, true) === false);
} | php | public function refresh(array $providers = array(), array &$results = array()) {
if (empty($providers)) {
foreach ($this->caches as $cacheKey => $cache) {
$providers[$cacheKey] = array();
}
}
foreach ($providers as $key => $options) {
if (array_key_exists($key, $this->caches) && !array_key_exists($key, $results)) {
$results[$key] = $this->clean(array_merge($options, array(xPDO::OPT_CACHE_KEY => $key)));
}
}
return (array_search(false, $results, true) === false);
} | [
"public",
"function",
"refresh",
"(",
"array",
"$",
"providers",
"=",
"array",
"(",
")",
",",
"array",
"&",
"$",
"results",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"providers",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"... | Refresh specific or all cache providers.
The default behavior is to call clean() with the provided options
@param array $providers An associative array with keys representing the cache provider key
and the value an array of options.
@param array &$results An associative array for collecting results for each provider.
@return array An array of results for each provider that is refreshed. | [
"Refresh",
"specific",
"or",
"all",
"cache",
"providers",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Cache/xPDOCacheManager.php#L749-L761 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._loadCollectionInstance | public static function _loadCollectionInstance(xPDO & $xpdo, array & $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag=true) {
$loaded = false;
if ($obj= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row)) {
if (($cacheKey= $obj->getPrimaryKey()) && !$obj->isLazy()) {
if (is_array($cacheKey)) {
$pkval= implode('-', $cacheKey);
} else {
$pkval= $cacheKey;
}
/* set OPT_CACHE_DB_COLLECTIONS to 2 to cache instances by primary key from collection result sets */
if ($xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1) == 2 && $xpdo->_cacheEnabled && $cacheFlag) {
if (!$fromCache) {
$pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
$xpdo->toCache($pkCriteria, $obj, $cacheFlag);
} else {
$obj->_cacheFlag= true;
}
}
$objCollection[$pkval]= $obj;
$loaded = true;
} else {
$objCollection[]= $obj;
$loaded = true;
}
}
return $loaded;
} | php | public static function _loadCollectionInstance(xPDO & $xpdo, array & $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag=true) {
$loaded = false;
if ($obj= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row)) {
if (($cacheKey= $obj->getPrimaryKey()) && !$obj->isLazy()) {
if (is_array($cacheKey)) {
$pkval= implode('-', $cacheKey);
} else {
$pkval= $cacheKey;
}
/* set OPT_CACHE_DB_COLLECTIONS to 2 to cache instances by primary key from collection result sets */
if ($xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1) == 2 && $xpdo->_cacheEnabled && $cacheFlag) {
if (!$fromCache) {
$pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
$xpdo->toCache($pkCriteria, $obj, $cacheFlag);
} else {
$obj->_cacheFlag= true;
}
}
$objCollection[$pkval]= $obj;
$loaded = true;
} else {
$objCollection[]= $obj;
$loaded = true;
}
}
return $loaded;
} | [
"public",
"static",
"function",
"_loadCollectionInstance",
"(",
"xPDO",
"&",
"$",
"xpdo",
",",
"array",
"&",
"$",
"objCollection",
",",
"$",
"className",
",",
"$",
"criteria",
",",
"$",
"row",
",",
"$",
"fromCache",
",",
"$",
"cacheFlag",
"=",
"true",
")... | Responsible for loading an instance into a collection.
@static
@param xPDO &$xpdo A valid xPDO instance.
@param array &$objCollection The collection to load the instance into.
@param string $className Name of the class.
@param mixed $criteria A valid primary key, criteria array, or xPDOCriteria instance.
@param array $row The associative array containing the instance data.
@param bool $fromCache If the instance is for the cache
@param bool|int $cacheFlag Indicates if the objects should be cached and
optionally, by specifying an integer value, for how many seconds.
@return bool True if a valid instance was loaded, false otherwise. | [
"Responsible",
"for",
"loading",
"an",
"instance",
"into",
"a",
"collection",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L355-L381 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.load | public static function load(xPDO & $xpdo, $className, $criteria, $cacheFlag= true) {
$instance= null;
$fromCache= false;
if ($className= $xpdo->loadClass($className)) {
if (!is_object($criteria)) {
$criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
}
if ($criteria instanceof xPDOCriteria) {
$criteria = $xpdo->addDerivativeCriteria($className, $criteria);
$row= null;
if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) {
$row= $xpdo->fromCache($criteria, $className);
}
if ($row === null || !is_array($row)) {
if ($rows= xPDOObject :: _loadRows($xpdo, $className, $criteria)) {
$row= $rows->fetch(\PDO::FETCH_ASSOC);
$rows->closeCursor();
}
} else {
$fromCache= true;
}
if (!is_array($row)) {
if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true));
} else {
$instance= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row);
if (is_object($instance)) {
if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) {
$xpdo->toCache($criteria, $instance, $cacheFlag);
if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey= $instance->getPrimaryKey()) && !$instance->isLazy()) {
$pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
$xpdo->toCache($pkCriteria, $instance, $cacheFlag);
}
}
if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true));
}
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.');
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className);
}
return $instance;
} | php | public static function load(xPDO & $xpdo, $className, $criteria, $cacheFlag= true) {
$instance= null;
$fromCache= false;
if ($className= $xpdo->loadClass($className)) {
if (!is_object($criteria)) {
$criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
}
if ($criteria instanceof xPDOCriteria) {
$criteria = $xpdo->addDerivativeCriteria($className, $criteria);
$row= null;
if ($xpdo->_cacheEnabled && $criteria->cacheFlag && $cacheFlag) {
$row= $xpdo->fromCache($criteria, $className);
}
if ($row === null || !is_array($row)) {
if ($rows= xPDOObject :: _loadRows($xpdo, $className, $criteria)) {
$row= $rows->fetch(\PDO::FETCH_ASSOC);
$rows->closeCursor();
}
} else {
$fromCache= true;
}
if (!is_array($row)) {
if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Fetched empty result set from statement: " . print_r($criteria->sql, true) . " with bindings: " . print_r($criteria->bindings, true));
} else {
$instance= xPDOObject :: _loadInstance($xpdo, $className, $criteria, $row);
if (is_object($instance)) {
if (!$fromCache && $cacheFlag && $xpdo->_cacheEnabled) {
$xpdo->toCache($criteria, $instance, $cacheFlag);
if ($xpdo->getOption(xPDO::OPT_CACHE_DB_OBJECTS_BY_PK) && ($cacheKey= $instance->getPrimaryKey()) && !$instance->isLazy()) {
$pkCriteria = $xpdo->newQuery($className, $cacheKey, $cacheFlag);
$xpdo->toCache($pkCriteria, $instance, $cacheFlag);
}
}
if ($xpdo->getDebug() === true) $xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Loaded object instance: " . print_r($instance->toArray('', true), true));
}
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'No valid statement could be found in or generated from the given criteria.');
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Invalid class specified: ' . $className);
}
return $instance;
} | [
"public",
"static",
"function",
"load",
"(",
"xPDO",
"&",
"$",
"xpdo",
",",
"$",
"className",
",",
"$",
"criteria",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"instance",
"=",
"null",
";",
"$",
"fromCache",
"=",
"false",
";",
"if",
"(",
"$"... | Load an instance of an xPDOObject or derivative class.
@static
@param xPDO &$xpdo A valid xPDO instance.
@param string $className Name of the class.
@param mixed $criteria A valid primary key, criteria array, or
xPDOCriteria instance.
@param bool|int $cacheFlag Indicates if the objects should be cached and
optionally, by specifying an integer value, for how many seconds.
@return object|null An instance of the requested class, or null if it
could not be instantiated. | [
"Load",
"an",
"instance",
"of",
"an",
"xPDOObject",
"or",
"derivative",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L396-L439 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.loadCollection | public static function loadCollection(xPDO & $xpdo, $className, $criteria= null, $cacheFlag= true) {
$objCollection= array ();
$fromCache = false;
if (!$className= $xpdo->loadClass($className)) return $objCollection;
$rows= false;
$fromCache= false;
$collectionCaching = (integer) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if (!is_object($criteria)) {
$criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag);
}
if (is_object($criteria)) {
$criteria = $xpdo->addDerivativeCriteria($className, $criteria);
}
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
$rows= $xpdo->fromCache($criteria);
$fromCache = (is_array($rows) && !empty($rows));
}
if (!$fromCache && is_object($criteria)) {
$rows= xPDOObject :: _loadRows($xpdo, $className, $criteria);
}
if (is_array ($rows)) {
foreach ($rows as $row) {
xPDOObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
}
} elseif (is_object($rows)) {
$cacheRows = array();
while ($row = $rows->fetch(\PDO::FETCH_ASSOC)) {
xPDOObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $cacheRows[] = $row;
}
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $rows =& $cacheRows;
}
if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($rows)) {
$xpdo->toCache($criteria, $rows, $cacheFlag);
}
return $objCollection;
} | php | public static function loadCollection(xPDO & $xpdo, $className, $criteria= null, $cacheFlag= true) {
$objCollection= array ();
$fromCache = false;
if (!$className= $xpdo->loadClass($className)) return $objCollection;
$rows= false;
$fromCache= false;
$collectionCaching = (integer) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if (!is_object($criteria)) {
$criteria= $xpdo->getCriteria($className, $criteria, $cacheFlag);
}
if (is_object($criteria)) {
$criteria = $xpdo->addDerivativeCriteria($className, $criteria);
}
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
$rows= $xpdo->fromCache($criteria);
$fromCache = (is_array($rows) && !empty($rows));
}
if (!$fromCache && is_object($criteria)) {
$rows= xPDOObject :: _loadRows($xpdo, $className, $criteria);
}
if (is_array ($rows)) {
foreach ($rows as $row) {
xPDOObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
}
} elseif (is_object($rows)) {
$cacheRows = array();
while ($row = $rows->fetch(\PDO::FETCH_ASSOC)) {
xPDOObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $cacheRows[] = $row;
}
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) $rows =& $cacheRows;
}
if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($rows)) {
$xpdo->toCache($criteria, $rows, $cacheFlag);
}
return $objCollection;
} | [
"public",
"static",
"function",
"loadCollection",
"(",
"xPDO",
"&",
"$",
"xpdo",
",",
"$",
"className",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"objCollection",
"=",
"array",
"(",
")",
";",
"$",
"fromCache"... | Load a collection of xPDOObject instances.
@static
@param xPDO &$xpdo A valid xPDO instance.
@param string $className Name of the class.
@param mixed $criteria A valid primary key, criteria array, or xPDOCriteria instance.
@param boolean|integer $cacheFlag Indicates if the objects should be
cached and optionally, by specifying an integer value, for how many
seconds.
@return array An array of xPDOObject instances or an empty array if no instances are loaded. | [
"Load",
"a",
"collection",
"of",
"xPDOObject",
"instances",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L453-L489 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.loadCollectionGraph | public static function loadCollectionGraph(xPDO & $xpdo, $className, $graph, $criteria, $cacheFlag) {
$objCollection = array();
if ($query= $xpdo->newQuery($className, $criteria, $cacheFlag)) {
$query = $xpdo->addDerivativeCriteria($className, $query);
$query->bindGraph($graph);
$rows = array();
$fromCache = false;
$collectionCaching = (integer) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
$rows= $xpdo->fromCache($query);
$fromCache = !empty($rows);
}
if (!$fromCache) {
if ($query->prepare()) {
$tstart = microtime(true);
if ($query->stmt->execute()) {
$xpdo->queryTime += microtime(true) - $tstart;
$xpdo->executedQueries++;
$objCollection= $query->hydrateGraph($query->stmt, $cacheFlag);
} else {
$xpdo->queryTime += microtime(true) - $tstart;
$xpdo->executedQueries++;
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error {$query->stmt->errorCode()} executing query: {$query->sql} - " . print_r($query->stmt->errorInfo(), true));
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error {$xpdo->errorCode()} preparing statement: {$query->sql} - " . print_r($xpdo->errorInfo(), true));
}
} elseif (!empty($rows)) {
$objCollection= $query->hydrateGraph($rows, $cacheFlag);
}
}
return $objCollection;
} | php | public static function loadCollectionGraph(xPDO & $xpdo, $className, $graph, $criteria, $cacheFlag) {
$objCollection = array();
if ($query= $xpdo->newQuery($className, $criteria, $cacheFlag)) {
$query = $xpdo->addDerivativeCriteria($className, $query);
$query->bindGraph($graph);
$rows = array();
$fromCache = false;
$collectionCaching = (integer) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
$rows= $xpdo->fromCache($query);
$fromCache = !empty($rows);
}
if (!$fromCache) {
if ($query->prepare()) {
$tstart = microtime(true);
if ($query->stmt->execute()) {
$xpdo->queryTime += microtime(true) - $tstart;
$xpdo->executedQueries++;
$objCollection= $query->hydrateGraph($query->stmt, $cacheFlag);
} else {
$xpdo->queryTime += microtime(true) - $tstart;
$xpdo->executedQueries++;
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error {$query->stmt->errorCode()} executing query: {$query->sql} - " . print_r($query->stmt->errorInfo(), true));
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error {$xpdo->errorCode()} preparing statement: {$query->sql} - " . print_r($xpdo->errorInfo(), true));
}
} elseif (!empty($rows)) {
$objCollection= $query->hydrateGraph($rows, $cacheFlag);
}
}
return $objCollection;
} | [
"public",
"static",
"function",
"loadCollectionGraph",
"(",
"xPDO",
"&",
"$",
"xpdo",
",",
"$",
"className",
",",
"$",
"graph",
",",
"$",
"criteria",
",",
"$",
"cacheFlag",
")",
"{",
"$",
"objCollection",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
... | Load a collection of xPDOObject instances and a graph of related objects.
@static
@param xPDO &$xpdo A valid xPDO instance.
@param string $className Name of the class.
@param string|array $graph A related object graph in array or JSON
format, e.g. array('relationAlias'=>array('subRelationAlias'=>array()))
or {"relationAlias":{"subRelationAlias":{}}}. Note that the empty arrays
are necessary in order for the relation to be recognized.
@param mixed $criteria A valid primary key, criteria array, or xPDOCriteria instance.
@param boolean|integer $cacheFlag Indicates if the objects should be
cached and optionally, by specifying an integer value, for how many
seconds.
@return array An array of xPDOObject instances or an empty array if no instances are loaded. | [
"Load",
"a",
"collection",
"of",
"xPDOObject",
"instances",
"and",
"a",
"graph",
"of",
"related",
"objects",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L507-L539 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getSelectColumns | public static function getSelectColumns(xPDO & $xpdo, $className, $tableAlias= '', $columnPrefix= '', $columns= array (), $exclude= false) {
$columnarray= array ();
$aColumns= $xpdo->getFields($className);
if ($aColumns) {
if (!empty ($tableAlias)) {
$tableAlias= $xpdo->escape($tableAlias);
$tableAlias.= '.';
}
if (!$exclude && !empty($columns)) {
foreach ($columns as $column) {
if (!in_array($column, array_keys($aColumns))) {
continue;
}
$columnarray[$column]= "{$tableAlias}" . $xpdo->escape($column);
if (!empty ($columnPrefix)) {
$columnarray[$column]= $columnarray[$column] . " AS " . $xpdo->escape("{$columnPrefix}{$column}");
}
}
} else {
foreach (array_keys($aColumns) as $k) {
if ($exclude && in_array($k, $columns)) {
continue;
}
elseif (empty ($columns)) {
$columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k);
}
elseif ($exclude || in_array($k, $columns)) {
$columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k);
} else {
continue;
}
if (!empty ($columnPrefix)) {
$columnarray[$k]= $columnarray[$k] . " AS " . $xpdo->escape("{$columnPrefix}{$k}");
}
}
}
}
return implode(', ', $columnarray);
} | php | public static function getSelectColumns(xPDO & $xpdo, $className, $tableAlias= '', $columnPrefix= '', $columns= array (), $exclude= false) {
$columnarray= array ();
$aColumns= $xpdo->getFields($className);
if ($aColumns) {
if (!empty ($tableAlias)) {
$tableAlias= $xpdo->escape($tableAlias);
$tableAlias.= '.';
}
if (!$exclude && !empty($columns)) {
foreach ($columns as $column) {
if (!in_array($column, array_keys($aColumns))) {
continue;
}
$columnarray[$column]= "{$tableAlias}" . $xpdo->escape($column);
if (!empty ($columnPrefix)) {
$columnarray[$column]= $columnarray[$column] . " AS " . $xpdo->escape("{$columnPrefix}{$column}");
}
}
} else {
foreach (array_keys($aColumns) as $k) {
if ($exclude && in_array($k, $columns)) {
continue;
}
elseif (empty ($columns)) {
$columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k);
}
elseif ($exclude || in_array($k, $columns)) {
$columnarray[$k]= "{$tableAlias}" . $xpdo->escape($k);
} else {
continue;
}
if (!empty ($columnPrefix)) {
$columnarray[$k]= $columnarray[$k] . " AS " . $xpdo->escape("{$columnPrefix}{$k}");
}
}
}
}
return implode(', ', $columnarray);
} | [
"public",
"static",
"function",
"getSelectColumns",
"(",
"xPDO",
"&",
"$",
"xpdo",
",",
"$",
"className",
",",
"$",
"tableAlias",
"=",
"''",
",",
"$",
"columnPrefix",
"=",
"''",
",",
"$",
"columns",
"=",
"array",
"(",
")",
",",
"$",
"exclude",
"=",
"... | Get a set of column names from an xPDOObject for use in SQL queries.
@static
@param xPDO &$xpdo A reference to an initialized xPDO instance.
@param string $className The class name to get columns from.
@param string $tableAlias An optional alias for the table in the query.
@param string $columnPrefix An optional prefix to prepend to each column name.
@param array $columns An optional array of field names to include or exclude
(include is default behavior).
@param boolean $exclude Determines if any specified columns should be included
or excluded from the set of results.
@return string A comma-delimited list of the field names for use in a SELECT clause. | [
"Get",
"a",
"set",
"of",
"column",
"names",
"from",
"an",
"xPDOObject",
"for",
"use",
"in",
"SQL",
"queries",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L555-L593 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.addFieldAlias | public function addFieldAlias($field, $alias) {
$added = false;
if (array_key_exists($field, $this->_fields)) {
if (!array_key_exists($alias, $this->_fields)) {
$this->_fields[$alias] =& $this->_fields[$field];
if (!array_key_exists($alias, $this->_fieldAliases)) {
$this->_fieldAliases[$alias] = $field;
if (!array_key_exists($alias, $this->xpdo->map[$this->_class]['fieldAliases'])) {
$this->xpdo->map[$this->_class]['fieldAliases'][$alias]= $field;
}
}
$added = true;
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "The alias {$alias} is already in use as a field name in objects of class {$this->_class}", '', __METHOD__, __FILE__, __LINE__);
}
}
return $added;
} | php | public function addFieldAlias($field, $alias) {
$added = false;
if (array_key_exists($field, $this->_fields)) {
if (!array_key_exists($alias, $this->_fields)) {
$this->_fields[$alias] =& $this->_fields[$field];
if (!array_key_exists($alias, $this->_fieldAliases)) {
$this->_fieldAliases[$alias] = $field;
if (!array_key_exists($alias, $this->xpdo->map[$this->_class]['fieldAliases'])) {
$this->xpdo->map[$this->_class]['fieldAliases'][$alias]= $field;
}
}
$added = true;
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "The alias {$alias} is already in use as a field name in objects of class {$this->_class}", '', __METHOD__, __FILE__, __LINE__);
}
}
return $added;
} | [
"public",
"function",
"addFieldAlias",
"(",
"$",
"field",
",",
"$",
"alias",
")",
"{",
"$",
"added",
"=",
"false",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"_fields",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exi... | Add an alias as a reference to an actual field of the object.
@param string $field The field name to create a reference to.
@param string $alias The name of the reference.
@return bool True if the reference is added successfully. | [
"Add",
"an",
"alias",
"as",
"a",
"reference",
"to",
"an",
"actual",
"field",
"of",
"the",
"object",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L661-L678 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getOption | public function getOption($key, $options = null, $default = null) {
if (is_array($options) && array_key_exists($key, $options)) {
$value= $options[$key];
} elseif (array_key_exists($key, $this->_options)) {
$value= $this->_options[$key];
} else {
$value= $this->xpdo->getOption($key, null, $default);
}
return $value;
} | php | public function getOption($key, $options = null, $default = null) {
if (is_array($options) && array_key_exists($key, $options)) {
$value= $options[$key];
} elseif (array_key_exists($key, $this->_options)) {
$value= $this->_options[$key];
} else {
$value= $this->xpdo->getOption($key, null, $default);
}
return $value;
} | [
"public",
"function",
"getOption",
"(",
"$",
"key",
",",
"$",
"options",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"options",
")",
... | Get an option value for this instance.
@param string $key The option key to retrieve a value for.
@param array|null $options An optional array to search for a value in first.
@param mixed $default A default value to return if no value is found; null is the default.
@return mixed The value of the option or the provided default if it is not set. | [
"Get",
"an",
"option",
"value",
"for",
"this",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L688-L697 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getOne | public function getOne($alias, $criteria= null, $cacheFlag= true) {
$object= null;
if ($fkdef= $this->getFKDefinition($alias)) {
$k= $fkdef['local'];
$fk= $fkdef['foreign'];
if (isset ($this->_relatedObjects[$alias])) {
if (is_object($this->_relatedObjects[$alias])) {
$object= & $this->_relatedObjects[$alias];
return $object;
}
}
if ($criteria === null) {
$criteria= array ($fk => $this->get($k));
if (isset($fkdef['criteria']) && isset($fkdef['criteria']['foreign'])) {
$criteria= array($fkdef['criteria']['foreign'], $criteria);
}
}
if ($object= $this->xpdo->getObject($fkdef['class'], $criteria, $cacheFlag)) {
$this->_relatedObjects[$alias]= $object;
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_WARN, "Could not getOne: foreign key definition for alias {$alias} not found.");
}
return $object;
} | php | public function getOne($alias, $criteria= null, $cacheFlag= true) {
$object= null;
if ($fkdef= $this->getFKDefinition($alias)) {
$k= $fkdef['local'];
$fk= $fkdef['foreign'];
if (isset ($this->_relatedObjects[$alias])) {
if (is_object($this->_relatedObjects[$alias])) {
$object= & $this->_relatedObjects[$alias];
return $object;
}
}
if ($criteria === null) {
$criteria= array ($fk => $this->get($k));
if (isset($fkdef['criteria']) && isset($fkdef['criteria']['foreign'])) {
$criteria= array($fkdef['criteria']['foreign'], $criteria);
}
}
if ($object= $this->xpdo->getObject($fkdef['class'], $criteria, $cacheFlag)) {
$this->_relatedObjects[$alias]= $object;
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_WARN, "Could not getOne: foreign key definition for alias {$alias} not found.");
}
return $object;
} | [
"public",
"function",
"getOne",
"(",
"$",
"alias",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"object",
"=",
"null",
";",
"if",
"(",
"$",
"fkdef",
"=",
"$",
"this",
"->",
"getFKDefinition",
"(",
"$",
"alia... | Gets an object related to this instance by a foreign key relationship.
Use this for 1:? (one:zero-or-one) or 1:1 relationships, which you can
distinguish by setting the nullability of the field representing the
foreign key.
For all 1:* relationships for this instance, see {@link getMany()}.
@see xPDOObject::getMany()
@see xPDOObject::addOne()
@see xPDOObject::addMany()
@param string $alias Alias of the foreign class representing the related
object.
@param object $criteria xPDOCriteria object to get the related objects
@param boolean|integer $cacheFlag Indicates if the object should be
cached and optionally, by specifying an integer value, for how many
seconds.
@return xPDOObject|null The related object or null if no instance exists. | [
"Gets",
"an",
"object",
"related",
"to",
"this",
"instance",
"by",
"a",
"foreign",
"key",
"relationship",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1099-L1123 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getMany | public function getMany($alias, $criteria= null, $cacheFlag= true) {
$collection= $this->_getRelatedObjectsByFK($alias, $criteria, $cacheFlag);
return $collection;
} | php | public function getMany($alias, $criteria= null, $cacheFlag= true) {
$collection= $this->_getRelatedObjectsByFK($alias, $criteria, $cacheFlag);
return $collection;
} | [
"public",
"function",
"getMany",
"(",
"$",
"alias",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"_getRelatedObjectsByFK",
"(",
"$",
"alias",
",",
"$",
"criteria",
",",
"$",... | Gets a collection of objects related by aggregate or composite relations.
@see xPDOObject::getOne()
@see xPDOObject::addOne()
@see xPDOObject::addMany()
@param string $alias Alias of the foreign class representing the related
object.
@param object $criteria xPDOCriteria object to get the related objects
@param boolean|integer $cacheFlag Indicates if the objects should be
cached and optionally, by specifying an integer value, for how many
seconds.
@return array A collection of related objects or an empty array. | [
"Gets",
"a",
"collection",
"of",
"objects",
"related",
"by",
"aggregate",
"or",
"composite",
"relations",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1140-L1143 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getIterator | public function getIterator($alias, $criteria= null, $cacheFlag= true) {
$iterator = false;
$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);
}
$iterator = $this->xpdo->getIterator($fkMeta['class'], $criteria, $cacheFlag);
}
return $iterator;
} | php | public function getIterator($alias, $criteria= null, $cacheFlag= true) {
$iterator = false;
$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);
}
$iterator = $this->xpdo->getIterator($fkMeta['class'], $criteria, $cacheFlag);
}
return $iterator;
} | [
"public",
"function",
"getIterator",
"(",
"$",
"alias",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"$",
"iterator",
"=",
"false",
";",
"$",
"fkMeta",
"=",
"$",
"this",
"->",
"getFKDefinition",
"(",
"$",
"alias",
... | Get an xPDOIterator for a collection of objects related by aggregate or composite relations.
@param string $alias The alias of the relation.
@param null|array|xPDOCriteria $criteria A valid xPDO criteria expression.
@param bool|int $cacheFlag Indicates if the objects should be cached and optionally, by
specifying an integer values, for how many seconds.
@return bool|xPDOIterator An iterator for the collection or false if no relation is found. | [
"Get",
"an",
"xPDOIterator",
"for",
"a",
"collection",
"of",
"objects",
"related",
"by",
"aggregate",
"or",
"composite",
"relations",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1154-L1182 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.addMany | public function addMany(& $obj, $alias= '') {
$added= false;
if (!is_array($obj)) {
if (is_object($obj)) {
if (empty ($alias)) {
if ($obj->_alias == $obj->_class) {
$aliases = $this->_getAliases($obj->_class, 1);
if (!empty($aliases)) {
$obj->_alias = reset($aliases);
}
}
$alias= $obj->_alias;
}
if ($fkMeta= $this->getFKDefinition($alias)) {
$obj->_alias= $alias;
if ($fkMeta['cardinality'] === 'many') {
if ($obj->_new) {
$objpk= '__new' . (isset ($this->_relatedObjects[$alias]) ? count($this->_relatedObjects[$alias]) : 0);
} else {
$objpk= $obj->getPrimaryKey();
if (is_array($objpk)) {
$objpk= implode('-', $objpk);
}
}
$this->_relatedObjects[$alias][$objpk]= $obj;
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Added related object with alias: ' . $alias . ' and pk: ' . $objpk . "\n" . print_r($obj->toArray('', true), true));
$added= true;
}
}
}
} else {
foreach ($obj as $o) {
$added= $this->addMany($o, $alias);
}
}
return $added;
} | php | public function addMany(& $obj, $alias= '') {
$added= false;
if (!is_array($obj)) {
if (is_object($obj)) {
if (empty ($alias)) {
if ($obj->_alias == $obj->_class) {
$aliases = $this->_getAliases($obj->_class, 1);
if (!empty($aliases)) {
$obj->_alias = reset($aliases);
}
}
$alias= $obj->_alias;
}
if ($fkMeta= $this->getFKDefinition($alias)) {
$obj->_alias= $alias;
if ($fkMeta['cardinality'] === 'many') {
if ($obj->_new) {
$objpk= '__new' . (isset ($this->_relatedObjects[$alias]) ? count($this->_relatedObjects[$alias]) : 0);
} else {
$objpk= $obj->getPrimaryKey();
if (is_array($objpk)) {
$objpk= implode('-', $objpk);
}
}
$this->_relatedObjects[$alias][$objpk]= $obj;
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, 'Added related object with alias: ' . $alias . ' and pk: ' . $objpk . "\n" . print_r($obj->toArray('', true), true));
$added= true;
}
}
}
} else {
foreach ($obj as $o) {
$added= $this->addMany($o, $alias);
}
}
return $added;
} | [
"public",
"function",
"addMany",
"(",
"&",
"$",
"obj",
",",
"$",
"alias",
"=",
"''",
")",
"{",
"$",
"added",
"=",
"false",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"obj",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"obj",
")",
")",
"{"... | Adds an object or collection of objects related to this class.
This method adds an object or collection of objects in a one-to-
many foreign key relationship with this object to the internal list of
related objects. By adding these related objects, you can cascade
{@link xPDOObject::save()}, {@link xPDOObject::remove()}, and other
operations based on the type of relationships defined.
@see xPDOObject::addOne()
@see xPDOObject::getOne()
@see xPDOObject::getMany()
@param mixed &$obj A single object or collection of objects to be related
to this instance via the intersection class.
@param string $alias An optional alias, required only for instances where
you have more than one relation defined to the same class.
@return boolean Indicates if the addMany was successful. | [
"Adds",
"an",
"object",
"or",
"collection",
"of",
"objects",
"related",
"to",
"this",
"class",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1271-L1307 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._saveRelatedObjects | protected function _saveRelatedObjects() {
$saved= 0;
if (!empty ($this->_relatedObjects)) {
foreach ($this->_relatedObjects as $alias => $ro) {
$objects= array ();
if (is_object($ro)) {
$primaryKey= $ro->_new ? '__new' : $ro->getPrimaryKey();
if (is_array($primaryKey)) $primaryKey= implode('-', $primaryKey);
$objects[$primaryKey]= & $ro;
$cardinality= 'one';
}
elseif (is_array($ro)) {
$objects= $ro;
$cardinality= 'many';
}
if (!empty($objects)) {
foreach ($objects as $pk => $obj) {
if ($fkMeta= $this->getFKDefinition($alias)) {
if ($this->_saveRelatedObject($obj, $fkMeta)) {
if ($cardinality == 'many') {
$newPk= $obj->getPrimaryKey();
if (is_array($newPk)) $newPk= implode('-', $newPk);
if ($pk != $newPk) {
$this->_relatedObjects[$alias][$newPk]= $obj;
unset($this->_relatedObjects[$alias][$pk]);
}
}
$saved++;
}
}
}
}
}
}
return $saved;
} | php | protected function _saveRelatedObjects() {
$saved= 0;
if (!empty ($this->_relatedObjects)) {
foreach ($this->_relatedObjects as $alias => $ro) {
$objects= array ();
if (is_object($ro)) {
$primaryKey= $ro->_new ? '__new' : $ro->getPrimaryKey();
if (is_array($primaryKey)) $primaryKey= implode('-', $primaryKey);
$objects[$primaryKey]= & $ro;
$cardinality= 'one';
}
elseif (is_array($ro)) {
$objects= $ro;
$cardinality= 'many';
}
if (!empty($objects)) {
foreach ($objects as $pk => $obj) {
if ($fkMeta= $this->getFKDefinition($alias)) {
if ($this->_saveRelatedObject($obj, $fkMeta)) {
if ($cardinality == 'many') {
$newPk= $obj->getPrimaryKey();
if (is_array($newPk)) $newPk= implode('-', $newPk);
if ($pk != $newPk) {
$this->_relatedObjects[$alias][$newPk]= $obj;
unset($this->_relatedObjects[$alias][$pk]);
}
}
$saved++;
}
}
}
}
}
}
return $saved;
} | [
"protected",
"function",
"_saveRelatedObjects",
"(",
")",
"{",
"$",
"saved",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_relatedObjects",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_relatedObjects",
"as",
"$",
"alias",
"=>... | Searches for any related objects with pending changes to save.
@access protected
@uses xPDOObject::_saveRelatedObject()
@return integer The number of related objects processed. | [
"Searches",
"for",
"any",
"related",
"objects",
"with",
"pending",
"changes",
"to",
"save",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1519-L1554 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._saveRelatedObject | protected function _saveRelatedObject(& $obj, $fkMeta) {
$saved= false;
$local= $fkMeta['local'];
$foreign= $fkMeta['foreign'];
$cardinality= $fkMeta['cardinality'];
$owner= isset ($fkMeta['owner']) ? $fkMeta['owner'] : '';
if (!$owner) {
$owner= $cardinality === 'many' ? 'foreign' : 'local';
}
$criteria = isset($fkMeta['criteria']) ? $fkMeta['criteria'] : null;
if ($owner === 'local' && $fk= $this->get($local)) {
$obj->set($foreign, $fk);
if (isset($criteria['foreign']) && is_array($criteria['foreign'])) {
foreach ($criteria['foreign'] as $critKey => $critVal) {
if (is_numeric($critKey)) continue;
$obj->set($critKey, $critVal);
}
}
$saved= $obj->save();
} elseif ($owner === 'foreign') {
if ($obj->isNew() || !empty($obj->_dirty)) {
$saved= $obj->save();
}
$fk= $obj->get($foreign);
if ($fk) {
$this->set($local, $fk);
if (isset($criteria['local']) && is_array($criteria['local'])) {
foreach ($criteria['local'] as $critKey => $critVal) {
if (is_numeric($critKey)) continue;
$this->set($critKey, $critVal);
}
}
}
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG , ($saved ? 'Successfully saved' : 'Could not save') . " related object\nMain object: " . print_r($this->toArray('', true), true) . "\nRelated Object: " . print_r($obj->toArray('', true), true));
return $saved;
} | php | protected function _saveRelatedObject(& $obj, $fkMeta) {
$saved= false;
$local= $fkMeta['local'];
$foreign= $fkMeta['foreign'];
$cardinality= $fkMeta['cardinality'];
$owner= isset ($fkMeta['owner']) ? $fkMeta['owner'] : '';
if (!$owner) {
$owner= $cardinality === 'many' ? 'foreign' : 'local';
}
$criteria = isset($fkMeta['criteria']) ? $fkMeta['criteria'] : null;
if ($owner === 'local' && $fk= $this->get($local)) {
$obj->set($foreign, $fk);
if (isset($criteria['foreign']) && is_array($criteria['foreign'])) {
foreach ($criteria['foreign'] as $critKey => $critVal) {
if (is_numeric($critKey)) continue;
$obj->set($critKey, $critVal);
}
}
$saved= $obj->save();
} elseif ($owner === 'foreign') {
if ($obj->isNew() || !empty($obj->_dirty)) {
$saved= $obj->save();
}
$fk= $obj->get($foreign);
if ($fk) {
$this->set($local, $fk);
if (isset($criteria['local']) && is_array($criteria['local'])) {
foreach ($criteria['local'] as $critKey => $critVal) {
if (is_numeric($critKey)) continue;
$this->set($critKey, $critVal);
}
}
}
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG , ($saved ? 'Successfully saved' : 'Could not save') . " related object\nMain object: " . print_r($this->toArray('', true), true) . "\nRelated Object: " . print_r($obj->toArray('', true), true));
return $saved;
} | [
"protected",
"function",
"_saveRelatedObject",
"(",
"&",
"$",
"obj",
",",
"$",
"fkMeta",
")",
"{",
"$",
"saved",
"=",
"false",
";",
"$",
"local",
"=",
"$",
"fkMeta",
"[",
"'local'",
"]",
";",
"$",
"foreign",
"=",
"$",
"fkMeta",
"[",
"'foreign'",
"]",... | Save a related object with pending changes.
This function is also responsible for setting foreign keys when new
related objects are being saved, as well as local keys when the host
object is new and needs the foreign key.
@access protected
@param xPDOObject &$obj A reference to the related object.
@param array $fkMeta The meta data representing the relation.
@return boolean True if a related object was dirty and saved successfully. | [
"Save",
"a",
"related",
"object",
"with",
"pending",
"changes",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1568-L1604 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getPKType | public function getPKType() {
if ($this->_pktype === null) {
if ($this->_pk === null) {
$this->getPK();
}
$this->_pktype= $this->xpdo->getPKType($this->_class);
}
return $this->_pktype;
} | php | public function getPKType() {
if ($this->_pktype === null) {
if ($this->_pk === null) {
$this->getPK();
}
$this->_pktype= $this->xpdo->getPKType($this->_class);
}
return $this->_pktype;
} | [
"public",
"function",
"getPKType",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_pktype",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_pk",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"getPK",
"(",
")",
";",
"}",
"$",
"this",
"->",... | Gets the type of the primary key field for the object.
@return string The type of the primary key field for this instance. | [
"Gets",
"the",
"type",
"of",
"the",
"primary",
"key",
"field",
"for",
"the",
"object",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1783-L1791 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getFKClass | public function getFKClass($k) {
$fkclass= null;
$k = $this->getField($k, true);
if (is_string($k)) {
if (!empty ($this->_aggregates)) {
foreach ($this->_aggregates as $aggregateAlias => $aggregate) {
if ($aggregate['local'] === $k) {
$fkclass= $aggregate['class'];
break;
}
}
}
if (!$fkclass && !empty ($this->_composites)) {
foreach ($this->_composites as $compositeAlias => $composite) {
if ($composite['local'] === $k) {
$fkclass= $composite['class'];
break;
}
}
}
$fkclass= $this->xpdo->loadClass($fkclass);
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Returning foreign key class {$fkclass} for column {$k}");
return $fkclass;
} | php | public function getFKClass($k) {
$fkclass= null;
$k = $this->getField($k, true);
if (is_string($k)) {
if (!empty ($this->_aggregates)) {
foreach ($this->_aggregates as $aggregateAlias => $aggregate) {
if ($aggregate['local'] === $k) {
$fkclass= $aggregate['class'];
break;
}
}
}
if (!$fkclass && !empty ($this->_composites)) {
foreach ($this->_composites as $compositeAlias => $composite) {
if ($composite['local'] === $k) {
$fkclass= $composite['class'];
break;
}
}
}
$fkclass= $this->xpdo->loadClass($fkclass);
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Returning foreign key class {$fkclass} for column {$k}");
return $fkclass;
} | [
"public",
"function",
"getFKClass",
"(",
"$",
"k",
")",
"{",
"$",
"fkclass",
"=",
"null",
";",
"$",
"k",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"k",
",",
"true",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"k",
")",
")",
"{",
"if",
"("... | Get the name of a class related by foreign key to a specified field key.
This is generally used to lookup classes involved in one-to-one
relationships with the current object.
@param string $k The field name or key to lookup a related class for.
@return bool|null|string | [
"Get",
"the",
"name",
"of",
"a",
"class",
"related",
"by",
"foreign",
"key",
"to",
"a",
"specified",
"field",
"key",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1802-L1826 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getFieldName | public function getFieldName($k, $alias= null) {
if ($this->fieldNames === null) {
$this->_initFields();
}
$name= null;
$k = $this->getField($k, true);
if (is_string($k) && isset ($this->fieldNames[$k])) {
$name= $this->fieldNames[$k];
}
if ($name !== null && $alias !== null) {
$name= str_replace("{$this->_table}.", "{$alias}.", $name);
}
return $name;
} | php | public function getFieldName($k, $alias= null) {
if ($this->fieldNames === null) {
$this->_initFields();
}
$name= null;
$k = $this->getField($k, true);
if (is_string($k) && isset ($this->fieldNames[$k])) {
$name= $this->fieldNames[$k];
}
if ($name !== null && $alias !== null) {
$name= str_replace("{$this->_table}.", "{$alias}.", $name);
}
return $name;
} | [
"public",
"function",
"getFieldName",
"(",
"$",
"k",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fieldNames",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_initFields",
"(",
")",
";",
"}",
"$",
"name",
"=",
"null",
";... | Gets a field name as represented in the database container.
This gets the name of the field, fully-qualified by either the object
table name or a specified alias, and properly quoted.
@param string $k The simple name of the field.
@param string $alias An optional alias for the table in a specific query.
@return string The name of the field, qualified with the table name or an
optional table alias. | [
"Gets",
"a",
"field",
"name",
"as",
"represented",
"in",
"the",
"database",
"container",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1853-L1866 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getField | public function getField($key, $validate = false) {
$field = $key;
if (!array_key_exists($key, $this->_fieldMeta)) {
if (array_key_exists($key, $this->_fieldAliases)) {
$field = $this->_fieldAliases[$key];
} elseif ($validate === true) {
$field = false;
}
}
return $field;
} | php | public function getField($key, $validate = false) {
$field = $key;
if (!array_key_exists($key, $this->_fieldMeta)) {
if (array_key_exists($key, $this->_fieldAliases)) {
$field = $this->_fieldAliases[$key];
} elseif ($validate === true) {
$field = false;
}
}
return $field;
} | [
"public",
"function",
"getField",
"(",
"$",
"key",
",",
"$",
"validate",
"=",
"false",
")",
"{",
"$",
"field",
"=",
"$",
"key",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"_fieldMeta",
")",
")",
"{",
"if",
"... | Get a field name, looking up any by alias if not an actual field.
@param string $key The field name or alias to translate to the actual field name.
@param bool $validate If true, the method will return false if the field or an alias
of it is not found. Otherwise, the key is returned as passed.
@return string|bool The actual field name, the key as passed, or false if not a field
or alias and validate is true. | [
"Get",
"a",
"field",
"name",
"looking",
"up",
"any",
"by",
"alias",
"if",
"not",
"an",
"actual",
"field",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1877-L1887 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getGraph | public function getGraph($graph = true, $criteria = null, $cacheFlag = true) {
/* graph is true, get all relations to max depth */
if ($graph === true) {
$graph = $this->xpdo->getGraph($this->_class);
}
/* graph is an int, get relations to depth of graph */
if (is_int($graph)) {
$graph = $this->xpdo->getGraph($this->_class, $graph);
}
/* graph defined as JSON, convert to array */
if (is_string($graph)) {
$graph= $this->xpdo->fromJSON($graph);
}
/* graph as an array */
if (is_array($graph)) {
foreach ($graph as $alias => $branch) {
$fkMeta = $this->getFKDefinition($alias);
if ($fkMeta) {
$fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
if ($criteria === null) {
$query= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$query= array($fkCriteria, $query);
}
} else {
$query= $this->xpdo->newQuery($fkMeta['class'], $criteria);
$addCriteria= array("{$query->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$fkAddCriteria = array();
foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
if (is_numeric($fkCritKey)) continue;
$fkAddCriteria["{$query->getAlias()}.{$fkCritKey}"] = $fkCritVal;
}
if (!empty($fkAddCriteria)) {
$addCriteria = array($fkAddCriteria, $addCriteria);
}
}
$query->andCondition($addCriteria);
}
$collection = $this->xpdo->call($fkMeta['class'], 'loadCollectionGraph', array(
&$this->xpdo,
$fkMeta['class'],
$branch,
$query,
$cacheFlag
));
if (!empty($collection)) {
if ($fkMeta['cardinality'] == 'many') {
$this->_relatedObjects[$alias] = $collection;
} else {
$this->_relatedObjects[$alias] = reset($collection);
}
}
}
}
} else {
$graph = false;
}
return $graph;
} | php | public function getGraph($graph = true, $criteria = null, $cacheFlag = true) {
/* graph is true, get all relations to max depth */
if ($graph === true) {
$graph = $this->xpdo->getGraph($this->_class);
}
/* graph is an int, get relations to depth of graph */
if (is_int($graph)) {
$graph = $this->xpdo->getGraph($this->_class, $graph);
}
/* graph defined as JSON, convert to array */
if (is_string($graph)) {
$graph= $this->xpdo->fromJSON($graph);
}
/* graph as an array */
if (is_array($graph)) {
foreach ($graph as $alias => $branch) {
$fkMeta = $this->getFKDefinition($alias);
if ($fkMeta) {
$fkCriteria = isset($fkMeta['criteria']) && isset($fkMeta['criteria']['foreign']) ? $fkMeta['criteria']['foreign'] : null;
if ($criteria === null) {
$query= array($fkMeta['foreign'] => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$query= array($fkCriteria, $query);
}
} else {
$query= $this->xpdo->newQuery($fkMeta['class'], $criteria);
$addCriteria= array("{$query->getAlias()}.{$fkMeta['foreign']}" => $this->get($fkMeta['local']));
if ($fkCriteria !== null) {
$fkAddCriteria = array();
foreach ($fkCriteria as $fkCritKey => $fkCritVal) {
if (is_numeric($fkCritKey)) continue;
$fkAddCriteria["{$query->getAlias()}.{$fkCritKey}"] = $fkCritVal;
}
if (!empty($fkAddCriteria)) {
$addCriteria = array($fkAddCriteria, $addCriteria);
}
}
$query->andCondition($addCriteria);
}
$collection = $this->xpdo->call($fkMeta['class'], 'loadCollectionGraph', array(
&$this->xpdo,
$fkMeta['class'],
$branch,
$query,
$cacheFlag
));
if (!empty($collection)) {
if ($fkMeta['cardinality'] == 'many') {
$this->_relatedObjects[$alias] = $collection;
} else {
$this->_relatedObjects[$alias] = reset($collection);
}
}
}
}
} else {
$graph = false;
}
return $graph;
} | [
"public",
"function",
"getGraph",
"(",
"$",
"graph",
"=",
"true",
",",
"$",
"criteria",
"=",
"null",
",",
"$",
"cacheFlag",
"=",
"true",
")",
"{",
"/* graph is true, get all relations to max depth */",
"if",
"(",
"$",
"graph",
"===",
"true",
")",
"{",
"$",
... | Load a graph of related objects to the current object.
@param boolean|string|array|integer $graph An option to tell how to deal with related objects. If integer, will
traverse related objects up to a $graph level of depth and load them to the object.
If an array, will traverse required related object and load them to the object.
If true, will traverse the entire graph and append all related objects to the object (default behavior).
@param xPDOCriteria|array|string|integer $criteria A valid xPDO criteria representation.
@param boolean|integer $cacheFlag Indicates if the objects should be cached and optionally, by specifying an
integer value, for how many seconds.
@return array|boolean The graph that was loaded or false if nothing was loaded. | [
"Load",
"a",
"graph",
"of",
"related",
"objects",
"to",
"the",
"current",
"object",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1901-L1960 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.toArray | public function toArray($keyPrefix= '', $rawValues= false, $excludeLazy= false, $includeRelated= false) {
$objArray= null;
if (is_array($this->_fields)) {
$keys= array_keys($this->_fields);
if (!$excludeLazy && $this->isLazy()) {
$this->_loadFieldData($this->_lazy);
}
foreach ($keys as $key) {
if (!$excludeLazy || !$this->isLazy($key)) {
$objArray[$keyPrefix . $key]= $rawValues ? $this->_fields[$key] : $this->get($key);
}
}
}
if (!empty($includeRelated)) {
$graph = null;
if (is_int($includeRelated) && $includeRelated > 0) {
$graph = $this->xpdo->getGraph($this->_class, $includeRelated);
} elseif (is_string($includeRelated)) {
$graph = $this->xpdo->fromJSON($includeRelated);
} elseif (is_array($includeRelated)) {
$graph = $includeRelated;
}
if ($includeRelated === true || is_array($graph)) {
foreach ($this->_relatedObjects as $alias => $branch) {
if ($includeRelated === true || array_key_exists($alias, $graph)) {
if (is_array($branch)){
/** @var xPDOObject $obj */
foreach($branch as $pk => $obj){
$objArray[$alias][$pk] = $obj->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
}
} elseif ($branch instanceof xPDOObject) {
$objArray[$alias] = $branch->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
}
}
}
}
}
return $objArray;
} | php | public function toArray($keyPrefix= '', $rawValues= false, $excludeLazy= false, $includeRelated= false) {
$objArray= null;
if (is_array($this->_fields)) {
$keys= array_keys($this->_fields);
if (!$excludeLazy && $this->isLazy()) {
$this->_loadFieldData($this->_lazy);
}
foreach ($keys as $key) {
if (!$excludeLazy || !$this->isLazy($key)) {
$objArray[$keyPrefix . $key]= $rawValues ? $this->_fields[$key] : $this->get($key);
}
}
}
if (!empty($includeRelated)) {
$graph = null;
if (is_int($includeRelated) && $includeRelated > 0) {
$graph = $this->xpdo->getGraph($this->_class, $includeRelated);
} elseif (is_string($includeRelated)) {
$graph = $this->xpdo->fromJSON($includeRelated);
} elseif (is_array($includeRelated)) {
$graph = $includeRelated;
}
if ($includeRelated === true || is_array($graph)) {
foreach ($this->_relatedObjects as $alias => $branch) {
if ($includeRelated === true || array_key_exists($alias, $graph)) {
if (is_array($branch)){
/** @var xPDOObject $obj */
foreach($branch as $pk => $obj){
$objArray[$alias][$pk] = $obj->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
}
} elseif ($branch instanceof xPDOObject) {
$objArray[$alias] = $branch->toArray($keyPrefix, $rawValues, $excludeLazy, $includeRelated === true ? true : $graph[$alias]);
}
}
}
}
}
return $objArray;
} | [
"public",
"function",
"toArray",
"(",
"$",
"keyPrefix",
"=",
"''",
",",
"$",
"rawValues",
"=",
"false",
",",
"$",
"excludeLazy",
"=",
"false",
",",
"$",
"includeRelated",
"=",
"false",
")",
"{",
"$",
"objArray",
"=",
"null",
";",
"if",
"(",
"is_array",... | Copies the object fields and corresponding values to an associative array.
@param string $keyPrefix An optional prefix to prepend to the field values.
@param boolean $rawValues An optional flag indicating if you want the raw values instead of
those returned by the {@link xPDOObject::get()} function.
@param boolean $excludeLazy An option flag indicating if you want to exclude lazy fields from
the resulting array; the default behavior is to include them which means the object will
query the database for the lazy fields before providing the value.
@param boolean|integer|string|array $includeRelated Describes if and how to include loaded related object fields.
As an integer all loaded related objects in the graph up to that level of depth will be included.
As a string, only loaded related objects matching the JSON graph representation will be included.
As an array, only loaded related objects matching the graph array will be included.
As boolean true, all currently loaded related objects will be included.
@return array An array representation of the object fields/values. | [
"Copies",
"the",
"object",
"fields",
"and",
"corresponding",
"values",
"to",
"an",
"associative",
"array",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L1978-L2016 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.fromArray | public function fromArray($fldarray, $keyPrefix= '', $setPrimaryKeys= false, $rawValues= false, $adhocValues= false) {
if (is_array($fldarray)) {
$pkSet= false;
$generatedKey= false;
foreach ($fldarray as $key => $val) {
if (!empty ($keyPrefix)) {
$prefixPos= strpos($key, $keyPrefix);
if ($prefixPos === 0) {
$key= substr($key, strlen($keyPrefix));
} else {
continue;
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Stripped prefix {$keyPrefix} to produce key {$key}");
}
$key = $this->getField($key);
if (isset ($this->_fieldMeta[$key]['index']) && $this->_fieldMeta[$key]['index'] == 'pk') {
if ($setPrimaryKeys) {
if (isset ($this->_fieldMeta[$key]['generated'])) {
$generatedKey= true;
}
if ($this->_new) {
if ($rawValues || $generatedKey) {
$this->_setRaw($key, $val);
} else {
$this->set($key, $val);
}
$pkSet= true;
}
}
}
elseif (isset ($this->_fieldMeta[$key])) {
if ($rawValues) {
$this->_setRaw($key, $val);
} else {
$this->set($key, $val);
}
}
elseif ($adhocValues || $this->getOption(xPDO::OPT_HYDRATE_ADHOC_FIELDS)) {
if ($rawValues) {
$this->_setRaw($key, $val);
} else {
$this->set($key, $val);
}
}
if ($this->isLazy($key)) {
$this->_lazy = array_diff($this->_lazy, array($key));
}
}
}
} | php | public function fromArray($fldarray, $keyPrefix= '', $setPrimaryKeys= false, $rawValues= false, $adhocValues= false) {
if (is_array($fldarray)) {
$pkSet= false;
$generatedKey= false;
foreach ($fldarray as $key => $val) {
if (!empty ($keyPrefix)) {
$prefixPos= strpos($key, $keyPrefix);
if ($prefixPos === 0) {
$key= substr($key, strlen($keyPrefix));
} else {
continue;
}
if ($this->xpdo->getDebug() === true) $this->xpdo->log(xPDO::LOG_LEVEL_DEBUG, "Stripped prefix {$keyPrefix} to produce key {$key}");
}
$key = $this->getField($key);
if (isset ($this->_fieldMeta[$key]['index']) && $this->_fieldMeta[$key]['index'] == 'pk') {
if ($setPrimaryKeys) {
if (isset ($this->_fieldMeta[$key]['generated'])) {
$generatedKey= true;
}
if ($this->_new) {
if ($rawValues || $generatedKey) {
$this->_setRaw($key, $val);
} else {
$this->set($key, $val);
}
$pkSet= true;
}
}
}
elseif (isset ($this->_fieldMeta[$key])) {
if ($rawValues) {
$this->_setRaw($key, $val);
} else {
$this->set($key, $val);
}
}
elseif ($adhocValues || $this->getOption(xPDO::OPT_HYDRATE_ADHOC_FIELDS)) {
if ($rawValues) {
$this->_setRaw($key, $val);
} else {
$this->set($key, $val);
}
}
if ($this->isLazy($key)) {
$this->_lazy = array_diff($this->_lazy, array($key));
}
}
}
} | [
"public",
"function",
"fromArray",
"(",
"$",
"fldarray",
",",
"$",
"keyPrefix",
"=",
"''",
",",
"$",
"setPrimaryKeys",
"=",
"false",
",",
"$",
"rawValues",
"=",
"false",
",",
"$",
"adhocValues",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
... | Sets object fields from an associative array of key => value pairs.
@param array $fldarray An associative array of key => values.
@param string $keyPrefix Specify an optional prefix to strip from all array
keys in fldarray.
@param boolean $setPrimaryKeys Optional param to set generated primary keys.
@param boolean $rawValues Optional way to set values without calling the
{@link xPDOObject::set()} method.
@param boolean $adhocValues Optional way to set adhoc values so that all the values of
fldarray become object vars. | [
"Sets",
"object",
"fields",
"from",
"an",
"associative",
"array",
"of",
"key",
"=",
">",
"value",
"pairs",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2030-L2079 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.addValidationRule | public function addValidationRule($field, $name, $type, $rule, array $parameters= array()) {
$field = $this->getField($field);
if (is_string($field)) {
if (!$this->_validationLoaded) $this->_loadValidation();
if (!isset($this->_validationRules[$field])) $this->_validationRules[$field]= array();
$this->_validationRules[$field][$name]= array(
'type' => $type,
'rule' => $rule,
'parameters' => array()
);
foreach ($parameters as $paramKey => $paramValue) {
$this->_validationRules[$field][$name]['parameters'][$paramKey]= $paramValue;
}
}
} | php | public function addValidationRule($field, $name, $type, $rule, array $parameters= array()) {
$field = $this->getField($field);
if (is_string($field)) {
if (!$this->_validationLoaded) $this->_loadValidation();
if (!isset($this->_validationRules[$field])) $this->_validationRules[$field]= array();
$this->_validationRules[$field][$name]= array(
'type' => $type,
'rule' => $rule,
'parameters' => array()
);
foreach ($parameters as $paramKey => $paramValue) {
$this->_validationRules[$field][$name]['parameters'][$paramKey]= $paramValue;
}
}
} | [
"public",
"function",
"addValidationRule",
"(",
"$",
"field",
",",
"$",
"name",
",",
"$",
"type",
",",
"$",
"rule",
",",
"array",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"getField",
"(",
"$",
"fiel... | Add a validation rule to an object field for this instance.
@param string $field The field key to apply the rule to.
@param string $name A name to identify the rule.
@param string $type The type of rule.
@param string $rule The rule definition.
@param array $parameters Any input parameters for the rule. | [
"Add",
"a",
"validation",
"rule",
"to",
"an",
"object",
"field",
"for",
"this",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2090-L2104 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.removeValidationRules | public function removeValidationRules($field = null, array $rules = array()) {
if (!$this->_validationLoaded) $this->_loadValidation();
if (empty($rules) && is_string($field)) {
unset($this->_validationRules[$this->getField($field)]);
} elseif (empty($rules) && is_null($field)) {
$this->_validationRules = array();
} elseif (is_array($rules) && !empty($rules) && is_string($field)) {
$field = $this->getField($field);
foreach ($rules as $name) {
unset($this->_validationRules[$field][$name]);
}
}
} | php | public function removeValidationRules($field = null, array $rules = array()) {
if (!$this->_validationLoaded) $this->_loadValidation();
if (empty($rules) && is_string($field)) {
unset($this->_validationRules[$this->getField($field)]);
} elseif (empty($rules) && is_null($field)) {
$this->_validationRules = array();
} elseif (is_array($rules) && !empty($rules) && is_string($field)) {
$field = $this->getField($field);
foreach ($rules as $name) {
unset($this->_validationRules[$field][$name]);
}
}
} | [
"public",
"function",
"removeValidationRules",
"(",
"$",
"field",
"=",
"null",
",",
"array",
"$",
"rules",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_validationLoaded",
")",
"$",
"this",
"->",
"_loadValidation",
"(",
")",
";... | Remove one or more validation rules from this instance.
@param string $field An optional field name to remove rules from. If not
specified or null, all rules from all columns will be removed.
@param array $rules An optional array of rule names to remove if a single
field is specified. If $field is null, this parameter is ignored. | [
"Remove",
"one",
"or",
"more",
"validation",
"rules",
"from",
"this",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2114-L2126 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject.getValidator | public function getValidator() {
if (!$this->_validator instanceof xPDOValidator) {
$validatorClass = $this->getOption(xPDO::OPT_VALIDATOR_CLASS, null, 'xPDO\\Validation\\xPDOValidator');
if ($validatorClass = $this->xpdo->loadClass($validatorClass, '', false, true)) {
$this->_validator = new $validatorClass($this);
}
}
return $this->_validator;
} | php | public function getValidator() {
if (!$this->_validator instanceof xPDOValidator) {
$validatorClass = $this->getOption(xPDO::OPT_VALIDATOR_CLASS, null, 'xPDO\\Validation\\xPDOValidator');
if ($validatorClass = $this->xpdo->loadClass($validatorClass, '', false, true)) {
$this->_validator = new $validatorClass($this);
}
}
return $this->_validator;
} | [
"public",
"function",
"getValidator",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_validator",
"instanceof",
"xPDOValidator",
")",
"{",
"$",
"validatorClass",
"=",
"$",
"this",
"->",
"getOption",
"(",
"xPDO",
"::",
"OPT_VALIDATOR_CLASS",
",",
"null",
... | Get the xPDOValidator class configured for this instance.
@return xPDOValidator|null The xPDOValidator instance or null if it could
not be loaded. | [
"Get",
"the",
"xPDOValidator",
"class",
"configured",
"for",
"this",
"instance",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2134-L2142 | train |
modxcms/xpdo | src/xPDO/Om/xPDOObject.php | xPDOObject._loadValidation | public function _loadValidation($reload= false) {
if (!$this->_validationLoaded || $reload == true) {
$validation= $this->xpdo->getValidationRules($this->_class);
$this->_validationLoaded= true;
foreach ($validation as $column => $rules) {
foreach ($rules as $name => $rule) {
$parameters = array_diff($rule, array($rule['type'], $rule['rule']));
$this->addValidationRule($column, $name, $rule['type'], $rule['rule'], $parameters);
}
}
}
} | php | public function _loadValidation($reload= false) {
if (!$this->_validationLoaded || $reload == true) {
$validation= $this->xpdo->getValidationRules($this->_class);
$this->_validationLoaded= true;
foreach ($validation as $column => $rules) {
foreach ($rules as $name => $rule) {
$parameters = array_diff($rule, array($rule['type'], $rule['rule']));
$this->addValidationRule($column, $name, $rule['type'], $rule['rule'], $parameters);
}
}
}
} | [
"public",
"function",
"_loadValidation",
"(",
"$",
"reload",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_validationLoaded",
"||",
"$",
"reload",
"==",
"true",
")",
"{",
"$",
"validation",
"=",
"$",
"this",
"->",
"xpdo",
"->",
"getValid... | Used to load validation from the object map.
@access public
@param boolean $reload Indicates if the schema validation rules should be
reloaded. | [
"Used",
"to",
"load",
"validation",
"from",
"the",
"object",
"map",
"."
] | 45e481377e80a3fd1a7362c1d285cddacda70048 | https://github.com/modxcms/xpdo/blob/45e481377e80a3fd1a7362c1d285cddacda70048/src/xPDO/Om/xPDOObject.php#L2151-L2162 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.