本文整理汇总了PHP中xPDO::getOption方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::getOption方法的具体用法?PHP xPDO::getOption怎么用?PHP xPDO::getOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDO
的用法示例。
在下文中一共展示了xPDO::getOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _getControllerPath
public static function _getControllerPath(xPDO &$modx, $path)
{
if (!($_path = $modx->getOption('shopmodx.core_path', null))) {
$_path = $modx->getOption('core_path') . 'components/shopmodx/';
}
$_path .= "controllers/default/{$path}/";
return $_path;
}
示例2: getControllerPath
public static function getControllerPath(xPDO &$modx)
{
$path = $modx->getOption('modsociety.controller_path', null);
if (empty($path)) {
$path = $modx->getOption('modsociety.core_path', null, $modx->getOption('core_path', null) . 'components/modsociety/') . 'controllers/mgr/';
}
$path .= "societytopic/";
return $path;
}
示例3: getOption
/**
* Get an option for the MODX hashing service.
*
* Searches for local options and then prefixes keys with encrypt_ to look for
* MODX System Settings.
*
* @param string $key The option key to get a value for.
* @param array|null $options An optional array of options to look in first.
* @param mixed $default An optional default value to return if no value is set.
* @return mixed The option value or the specified default if not found.
*/
public function getOption($key, $options = null, $default = null) {
if (is_array($options) && array_key_exists($key, $options)) {
$option = $options[$key];
} elseif (array_key_exists($key, $this->options)) {
$option = $this->options[$key];
} else {
$option = $this->modx->getOption('hashing_' . $key, $this->options, $default);
}
return $option;
}
示例4: loadCache
/**
* @static
* @param xPDO|modX $modx
* @return array|mixed
*/
public static function loadCache(xPDO &$modx)
{
if (!$modx->getCacheManager()) {
return array();
}
$cacheKey = 'extension-packages';
$cache = $modx->cacheManager->get($cacheKey, array(xPDO::OPT_CACHE_KEY => $modx->getOption('cache_extension_packages_key', null, 'namespaces'), xPDO::OPT_CACHE_HANDLER => $modx->getOption('cache_extension_packages_handler', null, $modx->getOption(xPDO::OPT_CACHE_HANDLER)), xPDO::OPT_CACHE_FORMAT => (int) $modx->getOption('cache_extension_packages_format', null, $modx->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP))));
if (empty($cache)) {
$cache = $modx->cacheManager->generateExtensionPackagesCache($cacheKey);
}
return $cache;
}
示例5: sendEmail
/**
* Send an email to the user
*
* @param string $message The body of the email
* @param array $options An array of options
* @return boolean True if successful
*/
public function sendEmail($message, array $options = array())
{
if (!$this->xpdo instanceof modX) {
return false;
}
$profile = $this->getOne('Profile');
if (empty($profile)) {
return false;
}
$this->xpdo->getService('mail', 'mail.modPHPMailer');
if (!$this->xpdo->mail) {
return false;
}
$this->xpdo->mail->set(modMail::MAIL_BODY, $message);
$this->xpdo->mail->set(modMail::MAIL_FROM, $this->xpdo->getOption('from', $options, $this->xpdo->getOption('emailsender')));
$this->xpdo->mail->set(modMail::MAIL_FROM_NAME, $this->xpdo->getOption('fromName', $options, $this->xpdo->getOption('site_name')));
$this->xpdo->mail->set(modMail::MAIL_SENDER, $this->xpdo->getOption('sender', $options, $this->xpdo->getOption('emailsender')));
$this->xpdo->mail->set(modMail::MAIL_SUBJECT, $this->xpdo->getOption('subject', $options, $this->xpdo->getOption('emailsubject')));
$this->xpdo->mail->address('to', $profile->get('email'), $profile->get('fullname'));
$this->xpdo->mail->address('reply-to', $this->xpdo->getOption('sender', $options, $this->xpdo->getOption('emailsender')));
$this->xpdo->mail->setHTML($this->xpdo->getOption('html', $options, true));
if ($this->xpdo->mail->send() == false) {
return false;
}
$this->xpdo->mail->reset();
return true;
}
示例6: args
protected function args(array $args = array())
{
if (!is_array($this->xpdo->version)) {
$this->xpdo->getVersionData();
}
$baseArgs = array('api_key' => $this->get('api_key'), 'username' => $this->get('username'), 'uuid' => $this->xpdo->uuid, 'database' => $this->xpdo->config['dbtype'], 'revolution_version' => $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version'], 'supports' => $this->xpdo->version['code_name'] . '-' . $this->xpdo->version['full_version'], 'http_host' => $this->xpdo->getOption('http_host'), 'php_version' => XPDO_PHP_VERSION, 'language' => $this->xpdo->getOption('manager_language'));
return array_merge($baseArgs, $args);
}
示例7: getOption
/**
* 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.
*/
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;
}
示例8: getProfilePhoto
/**
* Retrieve the profile photo, if any
*
* @param int $width The desired photo width
* @param int $height The desired photo height
*
* @return string The photo URL
*/
public function getProfilePhoto($width = 128, $height = 128)
{
if (empty($this->Profile->photo)) {
return '';
}
$this->xpdo->loadClass('sources.modMediaSource');
/** @var modMediaSource $source */
$source = modMediaSource::getDefaultSource($this->xpdo, $this->xpdo->getOption('photo_profile_source'));
$source->initialize();
$path = $source->getBasePath($this->Profile->photo) . $this->Profile->photo;
return $this->xpdo->getOption('connectors_url', MODX_CONNECTORS_URL) . "system/phpthumb.php?zc=1&h={$height}&w={$width}&src={$path}";
}
示例9: loadCollection
/**
* Custom collection loader that forces access policy checking.
*
* {@inheritdoc}
*/
public static function loadCollection(xPDO &$xpdo, $className, $criteria = null, $cacheFlag = true)
{
$objCollection = array();
if (!($className = $xpdo->loadClass($className))) {
return $objCollection;
}
$rows = false;
$fromCache = false;
$collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if (!is_object($criteria)) {
$criteria = $xpdo->getCriteria($className, $criteria, $cacheFlag);
}
if (is_object($criteria)) {
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
$rows = $xpdo->fromCache($criteria, $className);
$fromCache = is_array($rows) && !empty($rows);
}
if (!$fromCache) {
$rows = xPDOObject::_loadRows($xpdo, $className, $criteria);
}
$cacheRows = array();
if (is_array($rows)) {
foreach ($rows as $row) {
if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) {
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) {
$cacheRows[] = $row;
}
}
}
} elseif (is_object($rows)) {
while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
if (modAccessibleObject::_loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag)) {
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag && !$fromCache) {
$cacheRows[] = $row;
}
}
}
}
if (!$fromCache && $xpdo->_cacheEnabled && $collectionCaching > 0 && $cacheFlag && !empty($cacheRows)) {
$xpdo->toCache($criteria, $cacheRows, $cacheFlag);
}
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'modAccessibleObject::loadCollection() - No valid statement could be found in or generated from the given criteria.');
}
return $objCollection;
}
示例10: getControllerPath
public static function getControllerPath(xPDO &$modx)
{
return $modx->getOption('phptemplates.core_path', null, $modx->getOption('core_path') . 'components/phptemplates/') . 'controllers/phptemplateresource/';
}
示例11: loadCollection
/**
* Custom collection loader that forces access policy checking.
*
* {@inheritdoc}
*/
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 ($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) {
modAccessibleObject :: _loadCollectionInstance($xpdo, $objCollection, $className, $criteria, $row, $fromCache, $cacheFlag);
}
} elseif (is_object($rows)) {
$cacheRows = array();
while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
modAccessibleObject :: _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;
}
示例12: remove
/**
* Remove the persistent instance of an object permanently.
*
* Deletes the persistent object instance stored in the database when
* called, including any dependent objects defined by composite foreign key
* relationships.
*
* @todo Implement some way to reassign ownership of related composite
* objects when remove is called, perhaps by passing another object
* instance as an optional parameter, or creating a separate method.
*
* @param array $ancestors Keeps track of classes which have already been
* removed to prevent loop with circular references.
* @return boolean Returns true on success, false on failure.
*/
public function remove(array $ancestors = array())
{
$result = false;
$pk = $this->getPrimaryKey();
if ($pk && $this->xpdo->getConnection(array(xPDO::OPT_CONN_MUTABLE => true))) {
if (!empty($this->_composites)) {
$current = array($this->_class, $this->_alias);
foreach ($this->_composites as $compositeAlias => $composite) {
if (in_array($compositeAlias, $ancestors) || in_array($composite['class'], $ancestors)) {
continue;
}
if ($composite['cardinality'] === 'many') {
if ($many = $this->getMany($compositeAlias)) {
/** @var xPDOObject $one */
foreach ($many as $one) {
$ancestors[] = $compositeAlias;
$newAncestors = $ancestors + $current;
if (!$one->remove($newAncestors)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing dependent object: " . print_r($one->toArray('', true), true));
}
}
unset($many);
}
} elseif ($one = $this->getOne($compositeAlias)) {
$ancestors[] = $compositeAlias;
$newAncestors = $ancestors + $current;
if (!$one->remove($newAncestors)) {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, "Error removing dependent object: " . print_r($one->toArray('', true), true));
}
unset($one);
}
}
}
$delete = $this->xpdo->newQuery($this->_class);
$delete->command('DELETE');
$delete->where($pk);
// $delete->limit(1);
$stmt = $delete->prepare();
if (is_object($stmt)) {
$tstart = microtime(true);
if (!($result = $stmt->execute())) {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not delete from ' . $this->_table . '; primary key specified was ' . print_r($pk, true) . "\n" . print_r($stmt->errorInfo(), true));
} else {
$this->xpdo->queryTime += microtime(true) - $tstart;
$this->xpdo->executedQueries++;
$callback = $this->getOption(xPDO::OPT_CALLBACK_ON_REMOVE);
if ($callback && is_callable($callback)) {
call_user_func($callback, array('className' => $this->_class, 'criteria' => $delete, 'object' => $this));
}
if ($this->xpdo->_cacheEnabled && $this->xpdo->getOption('cache_db', null, false)) {
/** @var xPDOCache $dbCache */
$dbCache = $this->xpdo->getCacheManager()->getCacheProvider($this->getOption('cache_db_key', null, 'db'), 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, 'cache.xPDOFileCache')), xPDO::OPT_CACHE_FORMAT => (int) $this->getOption('cache_db_format', null, $this->getOption(xPDO::OPT_CACHE_FORMAT, null, xPDOCacheManager::CACHE_PHP)), xPDO::OPT_CACHE_EXPIRES => (int) $this->getOption(xPDO::OPT_CACHE_DB_EXPIRES, null, $this->getOption(xPDO::OPT_CACHE_EXPIRES, null, 0)), xPDO::OPT_CACHE_PREFIX => $this->getOption('cache_db_prefix', null, xPDOCacheManager::CACHE_DIR)));
if (!$dbCache->delete($this->_class, array('multiple_object_delete' => true))) {
$this->xpdo->log(xPDO::LOG_LEVEL_WARN, "Could not remove cache entries for {$this->_class}", '', __METHOD__, __FILE__, __LINE__);
}
}
$this->xpdo->log(xPDO::LOG_LEVEL_INFO, "Removed {$this->_class} instance with primary key " . print_r($pk, true));
}
} else {
$this->xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not build criteria to delete from ' . $this->_table . '; primary key specified was ' . print_r($pk, true));
}
}
return $result;
}
示例13: loadCollectionGraph
/**
* 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.
*/
public static function loadCollectionGraph(xPDO &$xpdo, $className, $graph, $criteria, $cacheFlag)
{
$objCollection = array();
if ($query = $xpdo->newQuery($className, $criteria, $cacheFlag)) {
$query->bindGraph($graph);
$fromCache = false;
$collectionCaching = (int) $xpdo->getOption(xPDO::OPT_CACHE_DB_COLLECTIONS, array(), 1);
if ($collectionCaching > 0 && $xpdo->_cacheEnabled && $cacheFlag) {
$rows = $xpdo->fromCache($criteria);
$fromCache = !empty($rows);
}
if (!$fromCache && ($stmt = $query->prepare())) {
if ($stmt->execute()) {
$objCollection = $query->hydrateGraph($stmt, $cacheFlag);
}
} else {
$objCollection = $query->hydrateGraph($rows, $cacheFlag);
}
}
return $objCollection;
}
示例14: findPolicy
/**
* Find all policies for this object
*
* @param string $context
* @return array
*/
public function findPolicy($context = '')
{
$policy = array();
$enabled = true;
$context = 'mgr';
if ($context === $this->xpdo->context->get('key')) {
$enabled = (bool) $this->xpdo->getOption('access_media_source_enabled', null, true);
} elseif ($this->xpdo->getContext($context)) {
$enabled = (bool) $this->xpdo->contexts[$context]->getOption('access_media_source_enabled', true);
}
if ($enabled) {
if (empty($this->_policies) || !isset($this->_policies[$context])) {
$accessTable = $this->xpdo->getTableName('sources.modAccessMediaSource');
$sourceTable = $this->xpdo->getTableName('sources.modMediaSource');
$policyTable = $this->xpdo->getTableName('modAccessPolicy');
$sql = "SELECT Acl.target, Acl.principal, Acl.authority, Acl.policy, Policy.data FROM {$accessTable} Acl " . "LEFT JOIN {$policyTable} Policy ON Policy.id = Acl.policy " . "JOIN {$sourceTable} Source ON Acl.principal_class = 'modUserGroup' " . "AND (Acl.context_key = :context OR Acl.context_key IS NULL OR Acl.context_key = '') " . "AND Source.id = Acl.target " . "WHERE Acl.target = :source " . "GROUP BY Acl.target, Acl.principal, Acl.authority, Acl.policy";
$bindings = array(':source' => $this->get('id'), ':context' => $context);
$query = new xPDOCriteria($this->xpdo, $sql, $bindings);
if ($query->stmt && $query->stmt->execute()) {
while ($row = $query->stmt->fetch(PDO::FETCH_ASSOC)) {
$policy['sources.modAccessMediaSource'][$row['target']][] = array('principal' => $row['principal'], 'authority' => $row['authority'], 'policy' => $row['data'] ? $this->xpdo->fromJSON($row['data'], true) : array());
}
}
$this->_policies[$context] = $policy;
} else {
$policy = $this->_policies[$context];
}
}
return $policy;
}
示例15: getFileChunk
/**
* @param string $tpl
* @param array $placeholders
* @return string
*/
public function getFileChunk($tpl, array $placeholders = array())
{
$output = '';
$file = $tpl;
if (!file_exists($file)) {
$file = $this->modx->getOption('manager_path') . 'templates/' . $this->modx->getOption('manager_theme', null, 'default') . '/' . $tpl;
}
if (!file_exists($file)) {
$file = $this->modx->getOption('manager_path') . 'templates/default/' . $tpl;
}
if (file_exists($file)) {
/** @var modChunk $chunk */
$chunk = $this->modx->newObject('modChunk');
$chunk->setCacheable(false);
$tplContent = file_get_contents($file);
$chunk->setContent($tplContent);
$output = $chunk->process($placeholders);
}
return $output;
}