本文整理汇总了PHP中xPDO::setPackage方法的典型用法代码示例。如果您正苦于以下问题:PHP xPDO::setPackage方法的具体用法?PHP xPDO::setPackage怎么用?PHP xPDO::setPackage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xPDO
的用法示例。
在下文中一共展示了xPDO::setPackage方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConnection
/**
* Get an xPDO connection to the database.
*
* @param int $mode
* @return xPDO A copy of the xpdo object.
*/
public function getConnection($mode = 0)
{
if ($this->settings && empty($mode)) {
$mode = (int) $this->settings->get('installmode');
}
if (empty($mode)) {
$mode = modInstall::MODE_NEW;
}
if ($mode === modInstall::MODE_UPGRADE_REVO) {
$errors = array();
$this->xpdo = $this->_modx($errors);
} else {
if (!is_object($this->xpdo)) {
$options = array();
if ($this->settings->get('new_folder_permissions')) {
$options['new_folder_permissions'] = $this->settings->get('new_folder_permissions');
}
if ($this->settings->get('new_file_permissions')) {
$options['new_file_permissions'] = $this->settings->get('new_file_permissions');
}
$this->xpdo = $this->_connect($this->settings->get('database_dsn'), $this->settings->get('database_user'), $this->settings->get('database_password'), $this->settings->get('table_prefix'), $options);
if (!$this->xpdo instanceof xPDO) {
return $this->xpdo;
}
$this->xpdo->setOption('cache_path', MODX_CORE_PATH . 'cache/');
if ($mode === modInstall::MODE_UPGRADE_REVO_ADVANCED) {
if ($this->xpdo->connect()) {
$errors = array();
$this->xpdo = $this->_modx($errors);
} else {
return $this->lexicon('db_err_connect_upgrade');
}
}
}
}
if (is_object($this->xpdo) && $this->xpdo instanceof xPDO) {
$this->xpdo->setLogTarget(array('target' => 'FILE', 'options' => array('filename' => 'install.' . MODX_CONFIG_KEY . '.' . strftime('%Y-%m-%dT%H.%M.%S') . '.log')));
$this->xpdo->setLogLevel(xPDO::LOG_LEVEL_ERROR);
$this->xpdo->setPackage('modx', MODX_CORE_PATH . 'model/', $this->settings->get('table_prefix'));
}
return $this->xpdo;
}
示例2: array
@unlink($packageDirectory . 'core.transport.zip');
}
if (file_exists($packageDirectory . 'core') && is_dir($packageDirectory . 'core')) {
$cacheManager->deleteTree($packageDirectory . 'core', array('deleteTop' => true, 'skipDirs' => false, 'extensions' => '*'));
}
if (!file_exists($packageDirectory . 'core') && !file_exists($packageDirectory . 'core.transport.zip')) {
$xpdo->log(xPDO::LOG_LEVEL_INFO, 'Removed pre-existing core/ and core.transport.zip.');
flush();
} else {
$xpdo->log(xPDO::LOG_LEVEL_ERROR, 'Could not remove core/ and core.transport.zip before starting build.');
flush();
}
/* create core transport package */
$package = new xPDOTransport($xpdo, 'core', $packageDirectory);
unset($packageDirectory);
$xpdo->setPackage('modx', MODX_CORE_PATH . 'model/');
$xpdo->loadClass('modAccess');
$xpdo->loadClass('modAccessibleObject');
$xpdo->loadClass('modAccessibleSimpleObject');
$xpdo->loadClass('modPrincipal');
$xpdo->log(xPDO::LOG_LEVEL_INFO, 'Core transport package created.');
flush();
/* core namespace */
$namespace = $xpdo->newObject('modNamespace');
$namespace->set('name', 'core');
$namespace->set('path', '{core_path}');
$namespace->set('assets_path', '{assets_path}');
$package->put($namespace, array(xPDOTransport::PRESERVE_KEYS => true, xPDOTransport::UPDATE_OBJECT => true));
unset($namespace);
$xpdo->log(xPDO::LOG_LEVEL_INFO, 'Core Namespace packaged.');
flush();
示例3: xPDO
<p>The <code>%s</code> directory is not writable by PHP.</p>
<p>Adjust the permissions and try again.</p>', $d));
exit;
}
}
if ($verbose) {
print_msg(sprintf('<br/><strong>Ok:</strong> The necessary directories exist and have the correct permissions inside of <br/>
<code>%s</code>', $package_dir));
}
// Delete/regenerate map files?
if (file_exists($xml_schema_file) && !$regenerate_schema && $verbose) {
print_msg(sprintf('<br/><strong>Ok:</strong> Using existing XML schema file:<br/><code>%s</code>', $xml_schema_file));
}
$xpdo = new xPDO("mysql:host={$database_server};dbname={$dbase}", $database_user, $database_password, $table_prefix);
// Set the package name and root path of that package
$xpdo->setPackage($package_name, $package_dir, $package_dir);
$xpdo->setDebug($debug);
$manager = $xpdo->getManager();
$generator = $manager->getGenerator();
//Use this to create an XML schema from an existing database
if ($regenerate_schema) {
$xml = $generator->writeSchema($xml_schema_file, $package_name, 'xPDOObject', $table_prefix, $restrict_prefix);
if ($verbose) {
print_msg(sprintf('<br/><strong>Ok:</strong> XML schema file generated: <code>%s</code>', $xml_schema_file));
}
}
// Use this to generate classes and maps from your schema
if ($regenerate_classes) {
print_msg('<br/>Attempting to remove/regenerate class files...');
delete_class_files($class_dir);
delete_class_files($mysql_class_dir);
示例4: die
<?php
if (!is_object($modx)) {
die("You shouldn't be here!");
}
// Load configuration
require_once 'config.php';
$snippetUrl = $modx->config['base_url'] . 'assets/snippets/Gregorian/';
$snippetDir = $_SERVER['DOCUMENT_ROOT'] . $snippetUrl;
// Load xPDO
$xpdo = new xPDO(XPDO_DSN, XPDO_DB_USER, XPDO_DB_PASS, XPDO_TABLE_PREFIX, array(PDO_ATTR_ERRMODE => PDO_ERRMODE_WARNING, PDO_ATTR_PERSISTENT => false, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$xpdo->setPackage('Gregorian', $snippetDir . 'model/');
// $xpdo->setDebug();
// $xpdo->setLoglevel(XPDO_LOG_LEVEL_INFO);
$moduleUrl = "{$_SERVER['SCRIPT_NAME']}?a={$_REQUEST['a']}&id={$_REQUEST['id']}";
$output = '';
$output .= "<a href='{$moduleUrl}&action=createContent'>Create random content</a><br />";
$output .= "<a href='{$moduleUrl}&action=createTables'>Create database tables</a><br />";
if (array_key_exists('action', $_REQUEST)) {
switch ($_REQUEST['action']) {
case 'createContent':
// Generate 10 random events in the future
$calendar = $xpdo->getObject('Gregorian', 1);
for ($i = 0; $i < 10; $i++) {
$start = time() + rand(1, 10) * 3600 * 24;
$fields = array('summary' => "Test event number {$i}", 'dtstart' => date('Y-m-d H:i', $start));
if (rand(0, 10) > 5) {
$fields['dtend'] = date('Y-m-d H:i', $start + rand(1, 48) * 3600);
}
$fields['allday'] = rand(0, 10) > 5;
if (rand(0, 10) > 5) {
示例5: microtime
<?php
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
$properties = array();
include_once dirname(dirname(dirname(__FILE__))) . '/xpdo/xpdo.class.php';
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/config.core.php';
require_once dirname(dirname(dirname(dirname(__FILE__)))) . '/_build/build.properties.php';
foreach (array('mysql', 'sqlsrv') as $driver) {
$xpdo = new xPDO($properties["{$driver}_string_dsn_nodb"], $properties["{$driver}_string_username"], $properties["{$driver}_string_password"], $properties["{$driver}_array_options"], $properties["{$driver}_array_driverOptions"]);
$xpdo->setPackage('modx', dirname(XPDO_CORE_PATH) . '/model/');
$xpdo->setDebug(true);
$manager = $xpdo->getManager();
$generator = $manager->getGenerator();
$generator->classTemplate = <<<EOD
<?php
/**
* [+phpdoc-package+]
* [+phpdoc-subpackage+]
*/
/**
* [+phpdoc-package+]
* [+phpdoc-subpackage+]
*/
class [+class+] extends [+extends+] {
}
EOD;
$generator->platformTemplate = <<<EOD
<?php
示例6: microtime
<?php
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
require_once 'build.config.php';
include_once '../../xpdo/xpdo.class.php';
//Set some valid connection properties here
$xpdo = new xPDO(XPDO_DSN, XPDO_DB_USER, XPDO_DB_PASS, XPDO_TABLE_PREFIX, array(PDO_ATTR_ERRMODE => PDO_ERRMODE_WARNING, PDO_ATTR_PERSISTENT => false, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$xpdo->setPackage('Gregorian', XPDO_CORE_PATH . '../model/');
$xpdo->setDebug(true);
$manager = $xpdo->getManager();
$generator = $manager->getGenerator();
//Use this to generate classes and maps from a schema
// NOTE: by default, only maps are overwritten; delete class files if you want to regenerate classes
$generator->classTemplate = <<<EOD
<?php
class [+class+] extends [+extends+] {
function [+class+](& \$xpdo) {
\$this->__construct(\$xpdo);
}
function __construct(& \$xpdo) {
parent :: __construct(\$xpdo);
}
}
?>
EOD;
$generator->platformTemplate = <<<EOD
<?php
require_once (dirname(dirname(__FILE__)) . '/[+class-lowercase+].class.php');
示例7: dirname
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
$properties = array();
include dirname(dirname(dirname(dirname(__FILE__)))) . '/xpdo/xpdo.class.php';
include dirname(dirname(dirname(dirname(__FILE__)))) . '/test/properties.inc.php';
$dbtypes = array('mysql', 'sqlite', 'sqlsrv');
foreach ($dbtypes as $dbtype) {
$xpdo = new xPDO($properties["{$dbtype}_string_dsn_test"], $properties["{$dbtype}_string_username"], $properties["{$dbtype}_string_password"], $properties["{$dbtype}_array_driverOptions"]);
$xpdo->setPackage('sample', $properties['xpdo_test_path'] . 'model/');
$xpdo->setLogTarget(XPDO_CLI_MODE ? 'ECHO' : 'HTML');
$xpdo->setLogLevel(xPDO::LOG_LEVEL_INFO);
// $xpdo->setDebug(true);
$xpdo->getManager();
$xpdo->manager->getGenerator();
//Use this to create a schema from an existing database
#$xml= $xpdo->manager->generator->writeSchema(XPDO_CORE_PATH . '../model/schema/sample.' . $dbtype . '.schema.xml', 'sample', 'xPDOObject', '');
//Use this to generate classes and maps from a schema
// NOTE: by default, only maps are overwritten; delete class files if you want to regenerate classes
$xpdo->manager->generator->parseSchema($properties['xpdo_test_path'] . 'model/schema/sample.' . $dbtype . '.schema.xml', $properties['xpdo_test_path'] . 'model/');
$xpdo->manager->generator->parseSchema($properties['xpdo_test_path'] . 'model/schema/sample.sti.' . $dbtype . '.schema.xml', $properties['xpdo_test_path'] . 'model/');
unset($xpdo);
}
$mtime = microtime();
$mtime = explode(" ", $mtime);
示例8: microtime
* data migration.
*
* @todo some manual intervention is needed to set up the table relationships we need
*
* Thanks to Jason Coward for posting how do set up a schema from a database:
* http://modxcms.com/forums/index.php/topic,16562.0.html
*/
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
//Customize this line based on the location of your script
include_once '../../../xpdo/xpdo.class.php';
$xpdo = new xPDO('mysql:host=localhost;dbname=wordpress_devtrench', 'root', '', 'wp_');
// Set the package name and root path of that package
$xpdo->setPackage('wordpress', XPDO_CORE_PATH . '../model/');
$xpdo->setDebug(true);
$manager = $xpdo->getManager();
$generator = $manager->getGenerator();
//Use this to create a schema from an existing database
//$xml= $generator->writeSchema(XPDO_CORE_PATH . '../model/schema/wordpress.mysql.schema.xml', 'wordpress', 'xPDOObject', 'wp_');
//Use this to generate classes and maps from your schema
// NOTE: by default, only maps are overwritten; delete class files if you want to regenerate classes
$generator->parseSchema(XPDO_CORE_PATH . '../model/wordpress/schema/wordpress.mysql.schema.xml', XPDO_CORE_PATH . '../model/');
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
echo "\nExecution time: {$totalTime}\n";
示例9: microtime
<?php
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tstart = $mtime;
require_once 'build.config.php';
include_once '../../xpdo/xpdo.class.php';
//Set some valid connection properties here
$xpdo = new xPDO(XPDO_DSN, XPDO_DB_USER, XPDO_DB_PASS, XPDO_TABLE_PREFIX, array(PDO_ATTR_ERRMODE => PDO_ERRMODE_WARNING, PDO_ATTR_PERSISTENT => false, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY => true));
$xpdo->setPackage('Gregorian', dirname(dirname(__FILE__)) . '/');
$xpdo->setDebug(true);
$manager = $xpdo->getManager();
$classes = array('Gregorian', 'GregorianEvent', 'GregorianTag', 'GregorianEventTag');
foreach ($classes as $class) {
$manager->createObjectContainer($class);
}
$mtime = microtime();
$mtime = explode(" ", $mtime);
$mtime = $mtime[1] + $mtime[0];
$tend = $mtime;
$totalTime = $tend - $tstart;
$totalTime = sprintf("%2.4f s", $totalTime);
echo "\nExecution time: {$totalTime}\n";
exit;