本文整理汇总了PHP中Core::GetComponent方法的典型用法代码示例。如果您正苦于以下问题:PHP Core::GetComponent方法的具体用法?PHP Core::GetComponent怎么用?PHP Core::GetComponent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Core
的用法示例。
在下文中一共展示了Core::GetComponent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preg_replace
'file' => '',
'name' => SITENAME,
'sname' => preg_replace('/[^a-z0-9-\.\+]*/i', '', str_replace(' ', '-', SITENAME)),
'xml' => null,
];
}
else{
echo "Found the following bundles:" . NL;
foreach($bundles as $b){
echo $b['name'] . ' (' . $b['file'] . ')' . NL;
}
}
sleep(1);
// Prompt the user with what version the new bundles will be.
$version = Core::GetComponent('core')->getVersion();
$version = CLI::PromptUser('Please set the bundled version or', 'text', $version);
foreach($bundles as $b){
/** @var XMLLoader|null $xml */
$xml = $b['xml'];
$destdir = $dir . '/' . $b['sname'];
// Check the dest directory for current versions.
if(!is_dir($destdir)) mkdir($destdir);
$desttgz = $b['sname'] . '-' . $version;
if(!is_dir($destdir . '/' . $desttgz)) mkdir($destdir . '/' . $desttgz);
// Get a list of packages to export.
示例2: analytics
public function analytics()
{
$request = $this->getPageRequest();
$view = $this->getView();
$manager = \Core\user()->checkAccess('p:/package_repository/view_analytics');
if (!$manager) {
return View::ERROR_ACCESSDENIED;
}
// Retrieve a list of connections to this repo for both downloading and checks!
$where = new \Core\Datamodel\DatasetWhereClause();
$where->addWhereSub('OR', ['baseurl = /packagerepository', 'baseurl = /packagerepository/download']);
// Default to a 3-month window for now just to have a relatively useful sample of data.
// This will be expanded to include a filter at some point in time.
$window = new \Core\Date\DateTime();
$window->modify('-3 months');
$window = $window->format('U');
// Generate a boilerplate dataset for the all-history view.
// This is required because the graphing software expects all data to be in the same columns,
// and these columns are simply indexed arrays.
// As we're pulling the data potentially out-of-order and across different versions,
// this array will provide a consistent scaffold for unset versions.
$allboilerplate = [];
// Series Boilerplate
$allmonths = [];
// Labels
// This goes back 12 months.
$date = new \Core\Date\DateTime();
$date->modify('-11 months');
for ($i = 1; $i <= 12; $i++) {
$allboilerplate[$date->format('Ym')] = null;
$allmonths[] = $date->format('M');
$date->nextMonth();
}
$raw = UserActivityModel::FindRaw($where);
// Will contain a list of useragents along with the count of how many access.
$useragents = [];
// Will contain how many times a given IP has requested the site.
// This is for a metric that currently is not enabled.
$ipaddresses = [];
// A rich list of hosts along with the latest version, the IP connecting from, and the date of the last check.
$hosts = [];
// All series for the bar graph at the top of the page, Keyed by version and contains the total number of hits.
$allseries = [];
$allseries['Total'] = ['class' => 'series-other', 'name' => 'Total', 'title' => 'Total', 'useragent' => '', 'values' => $allboilerplate];
// Used so I can compare the version of the connecting useragent against the current version of Core.
// This of course does noothing to ensure that this site is updated, but it at least should give some perspective.
$currentVersion = Core::VersionSplit(Core::GetComponent('core')->getVersion());
foreach ($raw as $dat) {
if (strpos($dat['useragent'], '(http://corepl.us)') !== false) {
/** @var string $ua ex: "Core Plus 1.2.3" */
$ua = str_replace(' (http://corepl.us)', '', $dat['useragent']);
/** @var string $version Just the version, ex: "1.2.3" */
$version = str_replace('Core Plus ', '', $ua);
/** @var string $referrer Original Site/Server, ex: "http://corepl.us" */
$referrer = $dat['referrer'] ? $dat['referrer'] : $dat['ip_addr'];
// The set of logic to compare the current version of Core against the version connecting.
// This is used primarily to set a class name onto the graphs so that they can be coloured specifically.
$v = Core::VersionSplit($version);
// These two values are used in the historical map, (as revision may be a bit useless at this scale).
$briefVersion = $v['major'] . '.' . $v['minor'] . '.x';
$briefUA = 'Core Plus ' . $briefVersion;
if ($v['major'] == $currentVersion['major'] && $v['minor'] == $currentVersion['minor']) {
// Check is same version as current (or newer), blue!
$class = 'series-current';
} elseif ($v['major'] + 2 <= $currentVersion['major']) {
// Check is at least 2 major versions out of date, red.
$class = 'series-outdated-2';
} elseif ($v['major'] + 1 <= $currentVersion['major']) {
// Check is at least 1 major version out of date, green.
$class = 'series-outdated-1';
} else {
// Same major version, close enough.
$class = 'series-outdated-0';
}
$month = date('Ym', $dat['datetime']);
} else {
$ua = 'Other';
$briefUA = 'Other';
$version = null;
$briefVersion = null;
$referrer = null;
$class = 'series-other';
$month = null;
}
// All Data!
if ($month && array_key_exists($month, $allboilerplate)) {
if (!isset($allseries[$briefUA])) {
$allseries[$briefUA] = ['class' => $class, 'name' => $briefVersion, 'title' => $briefUA, 'useragent' => $briefUA, 'values' => $allboilerplate];
}
$allseries[$briefUA]['values'][$month]++;
//$allseries['Total']['values'][$month]++;
}
// Is this data new enough to display on the graph?
// This is required because the "all" graph at the top needs all-time, (or at least the past 12 months).
if ($dat['datetime'] >= $window) {
// USER AGENT DATA
if (!isset($useragents[$ua])) {
$useragents[$ua] = ['value' => 0, 'class' => $class, 'name' => $version, 'title' => $ua, 'useragent' => $ua];
}
$useragents[$ua]['value']++;
//.........这里部分代码省略.........
示例3: getMailer
/**
* Get the mailer responsible for sending this email.
*
* @return PHPMailer
*/
public function getMailer() {
if (!$this->_mailer) {
$this->_mailer = new PHPMailer(true);
// Load in some default options for this email based on the configuration options.
$this->_mailer->From = ConfigHandler::Get('/core/email/from');
if (!$this->_mailer->From) $this->_mailer->From = 'website@' . $_SERVER['HTTP_HOST'];
$this->_mailer->Sender = $this->_mailer->From;
$this->_mailer->FromName = ConfigHandler::Get('/core/email/from_name');
$this->_mailer->Mailer = ConfigHandler::Get('/core/email/mailer');
$this->_mailer->Sendmail = ConfigHandler::Get('/core/email/sendmail_path');
if ($this->_mailer->Mailer == 'smtp') {
$this->_mailer->Host = ConfigHandler::Get('/core/email/smtp_host');
$this->_mailer->Port = ConfigHandler::Get('/core/email/smtp_port');
switch(ConfigHandler::Get('/core/email/smtp_auth')){
case 'LOGIN':
case 'PLAIN':
$this->_mailer->AuthType = ConfigHandler::Get('/core/email/smtp_auth');
$this->_mailer->Username = ConfigHandler::Get('/core/email/smtp_user');
$this->_mailer->Password = ConfigHandler::Get('/core/email/smtp_password');
$this->_mailer->SMTPAuth = true;
break;
case 'NTLM':
$this->_mailer->AuthType = ConfigHandler::Get('/core/email/smtp_auth');
$this->_mailer->Username = ConfigHandler::Get('/core/email/smtp_user');
$this->_mailer->Password = ConfigHandler::Get('/core/email/smtp_password');
$this->_mailer->Realm = ConfigHandler::Get('/core/email/smtp_domain');
$this->_mailer->SMTPAuth = true;
break;
case 'NONE':
$this->_mailer->SMTPAuth = false;
break;
}
$this->_mailer->SMTPSecure =
(ConfigHandler::Get('/core/email/smtp_security') == 'none') ?
'' : ConfigHandler::Get('/core/email/smtp_security');
}
// Tack on some anti-abuse and meta headers.
// These don't actually serve an explict function, but are added because.
$this->_mailer->AddCustomHeader('X-AntiAbuse: This header was added to track abuse, please include it with any abuse report');
if (\Core\user()->exists()) {
$this->_mailer->AddCustomHeader('X-AntiAbuse: User_id - ' . \Core\user()->get('id'));
$this->_mailer->AddCustomHeader('X-AntiAbuse: User_name - ' . \Core\user()->getDisplayName());
}
$this->_mailer->AddCustomHeader('X-AntiAbuse: Original Domain - ' . SERVERNAME);
$this->_mailer->AddCustomHeader('X-AntiAbuse: Sitename - ' . SITENAME);
$this->_mailer->AddCustomHeader('MimeOLE: Core Plus');
$this->_mailer->AddCustomHeader('X-Content-Encoded-By: Core Plus ' . Core::GetComponent()->getVersion());
$this->_mailer->XMailer = 'Core Plus ' . Core::GetComponent()->getVersion() . ' (http://corepl.us)';
}
return $this->_mailer;
}
示例4: GetVersion
public static function GetVersion() {
return Core::GetComponent()->getVersionInstalled();
}
示例5: fetch
public function fetch(){
$generator = 'Core Plus';
// Hide version numbers when not in development!
if(DEVELOPMENT_MODE) $generator .= ' ' . Core::GetComponent()->getVersion();
return array(
'generator' => '<meta name="generator" content="' . $generator . '"/>'
);
}
示例6: isCurrent
/**
* Check if this package is already installed and current (at least as new version installed)
*
* @return boolean
*/
public function isCurrent() {
switch($this->getType()){
case 'core':
case 'component':
$c = Core::GetComponent($this->getName());
if (!$c) return false; // Not installed? Not current.
return version_compare($c->getVersion(), $this->getVersion(), 'ge');
case 'theme':
$t = ThemeHandler::GetTheme($this->getName());
if (!$t) return false; // Not installed? Not current.
return version_compare($t->getVersion(), $this->getVersion(), 'ge');
}
}
示例7: render
/**
* Render this view and send all appropriate headers to the browser, (if applicable)
*
* @return void
*/
public function render() {
// Before I go about rendering anything, enable UTF-8 to ensure proper i18n!
if ($this->contenttype && $this->contenttype == View::CTYPE_HTML) {
View::AddMeta('http-equiv="Content-Type" content="text/html;charset=UTF-8"');
}
$data = $this->fetch();
// Be sure to send the content type and status to the browser, (if it's a page)
if (
!headers_sent() &&
($this->mode == View::MODE_PAGE || $this->mode == View::MODE_PAGEORAJAX || $this->mode == View::MODE_AJAX || $this->mode == View::MODE_NOOUTPUT || $this->mode == View::MODE_EMAILORPRINT)
) {
switch ($this->error) {
case View::ERROR_NOERROR:
header('Status: 200 OK', true, $this->error);
break;
case View::ERROR_BADREQUEST:
header('Status: 400 Bad Request', true, $this->error);
break;
case View::ERROR_UNAUTHORIZED:
header('Status: 401 Unauthorized', true, $this->error);
break;
case View::ERROR_PAYMENTREQUIRED:
header('Status: 402 Payment Required', true, $this->error);
break;
case View::ERROR_ACCESSDENIED:
header('Status: 403 Forbidden', true, $this->error);
break;
case View::ERROR_NOTFOUND:
header('Status: 404 Not Found', true, $this->error);
break;
case View::ERROR_METHODNOTALLOWED:
header('Status: 405 Method Not Allowed', true, $this->error);
break;
case View::ERROR_NOTACCEPTABLE:
header('Status: 406 Not Acceptable', true, $this->error);
break;
case View::ERROR_PROXYAUTHENTICATIONREQUIRED:
header('Status: 407 Proxy Authentication Required', true, $this->error);
break;
case View::ERROR_REQUESTTIMEOUT:
header('Status: 408 Request Time-out', true, $this->error);
break;
case View::ERROR_CONFLICT:
header('Status: 409 Conflict', true, $this->error);
break;
case View::ERROR_GONE:
header('Status: 410 Gone', true, $this->error);
break;
case View::ERROR_LENGTHREQUIRED:
header('Status: 411 Length Required', true, $this->error);
break;
case View::ERROR_PRECONDITIONFAILED:
header('Status: 412 Precondition Failed', true, $this->error);
break;
case View::ERROR_ENTITYTOOLARGE:
header('Status: 413 Request Entity Too Large', true, $this->error);
break;
case View::ERROR_URITOOLARGE:
header('Status: 414 Request-URI Too Large', true, $this->error);
break;
case View::ERROR_UNSUPPORTEDMEDIATYPE:
header('Status: 415 Unsupported Media Type', true, $this->error);
break;
case View::ERROR_RANGENOTSATISFIABLE:
header('Status: 416 Requested range not satisfiable', true, $this->error);
break;
case View::ERROR_EXPECTATIONFAILED:
header('Status: 417 Expectation Failed', true, $this->error);
break;
case View::ERROR_SERVERERROR:
header('Status: 500 Internal Server Error', true, $this->error);
break;
default:
header('Status: 500 Internal Server Error', true, $this->error);
break; // I don't know WTF happened...
}
if ($this->contenttype) {
if ($this->contenttype == View::CTYPE_HTML) header('Content-Type: text/html; charset=UTF-8');
else header('Content-Type: ' . $this->contenttype);
}
//mb_internal_encoding('utf-8');
header('X-Content-Encoded-By: Core Plus' . (DEVELOPMENT_MODE ? ' ' . Core::GetComponent()->getVersion() : ''));
if(\ConfigHandler::Get('/core/security/x-frame-options')){
header('X-Frame-Options: ' . \ConfigHandler::Get('/core/security/x-frame-options'));
}
if(\ConfigHandler::Get('/core/security/csp-frame-ancestors')){
header('Content-Security-Policy: frame-ancestors \'self\' ' . \ConfigHandler::Get('/core/security/content-security-policy'));
}
//.........这里部分代码省略.........
示例8: savePackageXML
/**
* Save or get the package XML for this theme. This is useful for the
* packager
*
* @param boolean $minified
* @param string $filename
*/
public function savePackageXML($minified = true, $filename = false)
{
// Instantiate a new XML Loader object and get it ready to use.
$dom = new \XMLLoader();
$dom->setRootName('package');
$dom->load();
// Populate the root attributes for this theme package.
$dom->getRootDOM()->setAttribute('type', 'theme');
$dom->getRootDOM()->setAttribute('name', $this->getName());
$dom->getRootDOM()->setAttribute('version', $this->getVersion());
// Declare the packager
$dom->createElement('packager[version="' . \Core::GetComponent()->getVersion() . '"]');
/* // Themes don't have any provide directives.
// Copy over any provide directives.
foreach ($this->_xmlloader->getRootDOM()->getElementsByTagName('provides') as $u) {
$newu = $dom->getDOM()->importNode($u);
$dom->getRootDOM()->appendChild($newu);
}
$dom->getElement('/provides[type="component"][name="' . strtolower($this->getName()) . '"][version="' . $this->getVersion() . '"]');
*/
/* // Themes don't have any requrie directives.
// Copy over any requires directives.
foreach ($this->_xmlloader->getRootDOM()->getElementsByTagName('requires') as $u) {
$newu = $dom->getDOM()->importNode($u);
$dom->getRootDOM()->appendChild($newu);
}
*/
// Copy over any upgrade directives.
// This one can be useful for an existing installation to see if this
// package can provide a valid upgrade path.
foreach ($this->_xmlloader->getRootDOM()->getElementsByTagName('upgrade') as $u) {
$newu = $dom->getDOM()->importNode($u);
$dom->getRootDOM()->appendChild($newu);
}
// Tack on description
$desc = $this->_xmlloader->getElement('/description', false);
if ($desc) {
$newd = $dom->getDOM()->importNode($desc);
$newd->nodeValue = $desc->nodeValue;
$dom->getRootDOM()->appendChild($newd);
}
$out = $minified ? $dom->asMinifiedXML() : $dom->asPrettyXML();
if ($filename) {
file_put_contents($filename, $out);
} else {
return $out;
}
}
示例9: DispatchHook
/**
* Dispatch an event, optionally passing 1 or more parameters.
*
* @param string $hookName The name of the hook to dispatch
* @param mixed $args
*
* @return mixed
*/
public static function DispatchHook($hookName, $args = null) {
// Prevent any hooks from being dispatched until Core is ready!
if(!Core::GetComponent()) return null;
$hookName = strtolower($hookName); // Case insensitive will prevent errors later on.
Core\Utilities\Logger\write_debug('Dispatching hook ' . $hookName);
//echo "Calling hook $hookName<br>";
//var_dump(HookHandler::$RegisteredHooks[$hookName]);
if (!isset(HookHandler::$RegisteredHooks[$hookName])) {
trigger_error('Tried to dispatch an undefined hook ' . $hookName, E_USER_NOTICE);
return null;
}
\Core\Utilities\Profiler\Profiler::GetDefaultProfiler()->record('Dispatching hook ' . $hookName);
$args = func_get_args();
// Drop off the hook name from the arguments.
array_shift($args);
$hook = HookHandler::$RegisteredHooks[$hookName];
$result = call_user_func_array(array(&$hook, 'dispatch'), $args);
Core\Utilities\Logger\write_debug('Dispatched hook ' . $hookName);
\Core\Utilities\Profiler\Profiler::GetDefaultProfiler()->record('Dispatched hook ' . $hookName);
return $result;
}
示例10: opendir
'component' => $core,
'dir' => ROOT_PDIR . 'core/',
];
unset($core);
// Load in all components currently on the system
// Open the "component" directory and look for anything with a valid component.xml file.
$dir = ROOT_PDIR . 'components';
$dh = opendir($dir);
while(($file = readdir($dh)) !== false){
if($file{0} == '.') continue;
if(!is_dir($dir . '/' . $file)) continue;
if(!is_readable($dir . '/' . $file . '/' . 'component.xml')) continue;
$c = Core::GetComponent($file);
// Is this not valid?
if(!$c){
CLI::PrintLine('Skipping invalid component ' . $file);
continue;
}
// What's this file's version?
$xml = new XMLLoader();
$xml->setRootName('component');
if(!$xml->loadFromFile($dir . '/' . $file . '/component.xml')){
CLI::PrintLine('Skipping component ' . $file . ', unable to load XML file');
continue;
}
示例11: PerformInstall
//.........这里部分代码省略.........
}
}
while(sizeof($pendingqueue) && sizeof($pendingqueue) != $lastsizeofqueue);
// Do validation checks on all these changes. I need to make sure I have the GPG key for each one.
// This is done here to save having to download the files from the remote server first.
foreach($checkedqueue as $target){
// It'll be validated prior to installation anyway.
if(!$target['key']) continue;
$output = array();
exec('gpg --homedir "' . GPG_HOMEDIR . '" --list-public-keys "' . $target['key'] . '"', $output, $result);
if($result > 0){
// Key validation failed!
if($verbose){
echo implode("<br/>\n", $output);
}
return [
'status' => 0,
'message' => $c['typetitle'] . ' failed GPG verification! Is the key ' . $target['key'] . ' installed?'
];
}
}
// Check that the queued packages have not been locally modified if installed.
if($verbose){
self::_PrintHeader('Checking for local modifications');
}
foreach($checkedqueue as $target){
if($target['status'] == 'update'){
switch($target['type']){
case 'core':
$c = Core::GetComponent('core');
break;
case 'components':
$c = Core::GetComponent($target['name']);
break;
case 'themes':
$c = null;
break;
}
if($c){
// Are there changes?
if(sizeof($c->getChangedAssets())){
foreach($c->getChangedAssets() as $change){
$changes[] = 'Overwrite locally-modified asset ' . $change;
}
}
if(sizeof($c->getChangedFiles())){
foreach($c->getChangedFiles() as $change){
$changes[] = 'Overwrite locally-modified file ' . $change;
}
}
if(sizeof($c->getChangedTemplates())){
foreach($c->getChangedTemplates() as $change){
$changes[] = 'Overwrite locally-modified template ' . $change;
}
}
}
}
}
// If dry run is enabled, stop here.
示例12: __construct
public function __construct()
{
// Load in the settings from Core.
$this->width = ConfigHandler::Get('/captcha/width');
$this->height = ConfigHandler::Get('/captcha/height');
$this->minWordLength = ConfigHandler::Get('/captcha/minlength');
$this->maxWordLength = ConfigHandler::Get('/captcha/maxlength');
$this->lineWidth = ConfigHandler::Get('/captcha/linethrough');
$this->Yperiod = ConfigHandler::Get('/captcha/yperiod');
$this->Yamplitude = ConfigHandler::Get('/captcha/yamplitude');
$this->Xperiod = ConfigHandler::Get('/captcha/xperiod');
$this->Xamplitude = ConfigHandler::Get('/captcha/xamplitude');
$this->maxRotation = ConfigHandler::Get('/captcha/maxrotation');
$this->blur = ConfigHandler::Get('/captcha/blur');
// Ensure it knows where to look for the "resources"...
$this->resourcesPath = Core::GetComponent('coolphpcaptcha')->getBaseDir() . "libs/cool-php-captcha/resources";
}
示例13: runRequirementChecks
public function runRequirementChecks(){
$requires = $this->getRequires();
$results = [];
foreach ($requires as $r) {
$check = [
'require' => $r,
'result' => [
'passed' => false,
'available' => null,
'message' => null,
],
];
switch ($r['type']) {
case 'component':
if (!Core::IsComponentAvailable($r['name'])) {
// Component is not available.
$check['result']['message'] = $check['result']['message'] = 'Missing component ' . $r['name'];
}
elseif (!Core::IsComponentAvailable($r['name'], $r['version'], $r['operation'])) {
$check['result']['available'] = Core::GetComponent($r['name'])->getVersionInstalled();
$check['result']['message'] = 'Requires component ' . $r['vstring'] . ', ' . $check['available'] . ' available.';
}
else{
$check['result']['passed'] = true;
$check['result']['available'] = Core::GetComponent($r['name'])->getVersionInstalled();
$check['result']['message'] = 'Component ' . $r['vstring'] . ' is available';
}
$results[] = $check;
break;
case 'define':
// Ensure that whatever define the script is expecting is there... this is useful for the EXEC_MODE define.
if (!defined($r['name'])) {
$check['result']['message'] = $check['result']['message'] = 'Missing define ' . $r['name'];
}
elseif ($r['value'] != null && constant($r['name']) != $r['value']) {
// Also if they opted to include a value... check that too.
$check['result']['message'] = $check['result']['message'] = 'Incorrect define ' . $r['name'] . ', expected value of: ' . $r['value'];
}
else{
$check['result']['passed'] = true;
$check['result']['available'] = true;
$check['result']['message'] = 'Define ' . $r['name'] . ' is set and correct';
}
$results[] = $check;
break;
case 'function':
// Requires a specific function to exist. This is most common with built-in PHP functions,
// such as gd, ldap, or imap support.
if(!function_exists($r['name'])){
$check['result']['message'] = $check['result']['message'] = 'Missing function ' . $r['name'];
}
else{
$check['result']['passed'] = true;
$check['result']['available'] = true;
$check['result']['message'] = 'Function ' . $r['name'] . ' is available';
}
$results[] = $check;
break;
case 'jslibrary':
if (!Core::IsJSLibraryAvailable($r['name'])) {
// The library is not even available!
$check['result']['message'] = 'Missing JSlibrary ' . $r['name'];
}
else{
$check['result']['passed'] = true;
$check['result']['available'] = true;
$check['result']['message'] = 'JSLibrary ' . $r['name'] . ' is available';
}
$results[] = $check;
break;
case 'library':
if (!Core::IsLibraryAvailable($r['name'])) {
// The library is not even available!
$check['result']['message'] = 'Missing library ' . $r['name'];
}
elseif (!Core::IsLibraryAvailable($r['name'], $r['version'], $r['operation'])) {
// The library is available, but is out of date.
$check['result']['available'] = Core::GetLibraryVersion($r['name']);
$check['result']['message'] = 'Requires library ' . $r['vstring'] . ', ' . $check['available'] . ' available.';
}
else{
$check['result']['passed'] = true;
$check['result']['available'] = Core::GetLibraryVersion($r['name']);
$check['result']['message'] = 'Library ' . $r['vstring'] . ' is available';
}
$results[] = $check;
break;
case 'phpextension':
$v = phpversion($r['name']);
//.........这里部分代码省略.........
示例14: component_enable
/**
* Page that is called to enable a given component.
*
* Performs all the necessary checks before enable, ie: dependencies from other components.
*/
public function component_enable() {
$view = $this->getView();
$req = $this->getPageRequest();
// This is a json-only page.
$view->contenttype = View::CTYPE_JSON;
// This is a post-only page!
/*if(!$req->isPost()){
$view->error = View::ERROR_BADREQUEST;
return;
}*/
$name = strtolower($req->getParameter(0));
$dryrun = $req->getParameter('dryrun');
$c = Core::GetComponent($name);
if(!$c){
$view->error = View::ERROR_NOTFOUND;
return;
}
if($c instanceof Component){
$view->error = View::ERROR_SERVERERROR;
$view->jsondata = array('message' => 'Requested component is not a valid 2.1 version component, please upgrade ' . $name);
return;
}
// Create a reverse map of what components are the basis of which components, this will make it easier
// to do the necessary mapping.
$provides = array('library' => array(), 'component' => array());
foreach(Core::GetComponents() as $ccheck){
// I only want to look at enabled components.
if(!$ccheck->isEnabled()) continue;
foreach($ccheck->getProvides() as $p){
$provides[$p['type']][$p['name']] = $p['version'];
}
}
// And check this component's requirements.
$requires = $c->getRequires();
foreach($requires as $r){
if(!isset($provides[$r['type']][$r['name']])){
$view->jsondata = array('message' => 'Unable to locate requirement ' . $r['type'] . ' ' . $r['name']);
return;
}
$op = ($r['operation']) ? $r['operation'] : 'ge';
if(!Core::VersionCompare($provides[$r['type']][$r['name']], $r['version'], $op)){
$view->jsondata = array('message' => 'Dependency version for ' . $r['type'] . ' ' . $r['name'] . ' ' . $op . ' ' . $r['version'] . ' not met');
return;
}
}
if(!$dryrun){
// I want to record a list of actual changes performed.
$changes = array();
$changes[] = 'Enabling component ' . $c->getName();
$change = $c->enable();
if(is_array($change)) $changes = array_merge($changes, $change);
$logmsg = implode("\n", $changes);
SystemLogModel::LogSecurityEvent(
'/updater/component/enabled',
$logmsg
);
}
$view->jsondata = array('changes' => array($name), 'dryrun' => $dryrun);
}
示例15: _setupComponent
private function _setupComponent(){
$this->_xmlFile = \ComponentFactory::ResolveNameToFile($this->_keyname);
if(!$this->_xmlFile){
throw new \Exception('XML file for requested component not found. [' . $this->_keyname . ']');
}
// Resolve it to the full path
$this->_xmlFile = ROOT_PDIR . $this->_xmlFile;
$this->_base = new DirectoryLocal(dirname($this->_xmlFile));
$this->_iterator = new DirectoryIterator($this->_base);
$baseDir = $this->_base->getPath();
// Get the XMLLoader object for this file. This will allow me to have more fine-tune control over the file.
$this->_xmlLoader = new \XMLLoader();
$this->_xmlLoader->setRootName('component');
if(!$this->_xmlLoader->loadFromFile($this->_xmlFile)){
throw new \Exception('Unable to load XML file ' . $this->_xmlFile);
}
$this->_iterator->findDirectories = false;
$this->_iterator->recursive = true;
$this->_iterator->ignores = [
'component.xml',
'dev/',
'tests/',
];
// @todo Should I support ignored files in the component.xml file?
// advantage, developers can have tools in their directories that are not meant to be packaged.
// disadvantage, currently no component other than core requires this.....
/*$list = $this->getElements('/ignorefiles/file');
foreach($list as $el){
$it->addIgnores($this->getBaseDir() . $el->getAttribute('filename'));
}*/
// Not a 2.1 component version?... well it needs to be!
// This actually needs to work with a variety of versions.
$componentapiversion = $this->_xmlLoader->getDOM()->doctype->systemId;
switch($componentapiversion){
case 'http://corepl.us/api/2_1/component.dtd':
case 'http://corepl.us/api/2_4/component.dtd':
// Now I can load the component itself, now that I know that the metafile is a 2.1 compatible version.
$comp = \Core::GetComponent($this->_keyname);
// Because the editor may request a component by key name, translate that to the pretty name.
$this->_name = $comp->getName();
//$comp = new \Component_2_1($this->_xmlFile);
//$comp->load();
break;
default:
throw new \Exception('Unsupported component version, please ensure that your doctype systemid is correct.');
}
$this->_licenses = [];
foreach($this->_xmlLoader->getElements('//component/licenses/license') as $el){
/** @var \DOMElement $el */
$url = @$el->getAttribute('url');
$this->_licenses[] = [
'title' => $el->nodeValue,
'url' => $url
];
}
$this->_authors = [];
foreach($this->_xmlLoader->getElements('//component/authors/author') as $el){
$this->_authors[] = [
'name' => $el->getAttribute('name'),
'email' => @$el->getAttribute('email'),
];
}
$this->_changelog = new Changelog\Parser($this->_name, $baseDir . 'CHANGELOG');
$this->_gitPaths = [
$baseDir,
];
}