1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 10:15:28 +02:00

Update numerous core classes to support the new wired() method, plus correct any found instances of the ProcessWire instance not being passed along to a Wire derived instance.

This commit is contained in:
Ryan Cramer
2020-05-29 14:09:17 -04:00
parent 365af73635
commit d2e381f987
38 changed files with 193 additions and 93 deletions

View File

@@ -61,7 +61,11 @@ abstract class AdminThemeFramework extends AdminTheme {
public function __construct() {
parent::__construct();
$this->set('useAsLogin', false);
}
public function wired() {
$this->sanitizer = $this->wire('sanitizer');
parent::wired();
}
/**

View File

@@ -123,33 +123,43 @@ class FileCompiler extends Wire {
*
*/
public function __construct($sourcePath, array $options = array()) {
$this->options = array_merge($this->options, $options);
$globalOptions = $this->wire('config')->fileCompilerOptions;
if(strpos($sourcePath, '..') !== false) $sourcePath = realpath($sourcePath);
if(DIRECTORY_SEPARATOR != '/') $sourcePath = str_replace(DIRECTORY_SEPARATOR, '/', $sourcePath);
$this->sourcePath = rtrim($sourcePath, '/') . '/';
}
/**
* Wired to instance
*
*/
public function wired() {
/** @var Config $config */
$config = $this->wire('config');
$globalOptions = $config->fileCompilerOptions;
if(is_array($globalOptions)) {
$this->globalOptions = array_merge($this->globalOptions, $globalOptions);
}
if(!empty($this->globalOptions['extensions'])) {
$this->extensions = $this->globalOptions['extensions'];
}
if(empty($this->globalOptions['cachePath'])) {
$this->cachePath = $this->wire('config')->paths->cache . $this->className() . '/';
$this->cachePath = $config->paths->cache . $this->className() . '/';
} else {
$this->cachePath = rtrim($this->globalOptions['cachePath'], '/') . '/';
}
if(!strlen(__NAMESPACE__)) {
// when PW compiled without namespace support
$this->options['skipIfNamespace'] = false;
$this->options['namespace'] = true;
}
if(strpos($sourcePath, '..') !== false) $sourcePath = realpath($sourcePath);
if(DIRECTORY_SEPARATOR != '/') $sourcePath = str_replace(DIRECTORY_SEPARATOR, '/', $sourcePath);
$this->sourcePath = rtrim($sourcePath, '/') . '/';
parent::wired();
}
/**
@@ -159,6 +169,7 @@ class FileCompiler extends Wire {
*
*/
protected function init() {
if(!$this->isWired()) $this->wired();
static $preloaded = false;
$config = $this->wire('config');

View File

@@ -77,8 +77,9 @@ class Fuel implements \IteratorAggregate {
*
*/
static protected $commonNames = array(
'page' => 1, 'pages' => 1, 'session' => 1, 'input' => 1, 'sanitizer' => 1, 'config' => 1,
'user' => 1, 'users' => 1, 'fields' => 1, 'templates' => 1, 'database' => 1, 'modules' => 1,
'page' => 1, 'pages' => 1, 'session' => 1, 'input' => 1, 'sanitizer' => 1,
'config' => 1, 'user' => 1, 'users' => 1, 'fields' => 1, 'templates' => 1,
'database' => 1, 'modules' => 1, 'hooks' => 1,
);
/**

View File

@@ -101,7 +101,7 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
* Label displayed when a value is required but missing
*
*/
protected $requiredLabel = '';
protected $requiredLabel = 'Missing required value';
/**
* Whether or not column width is handled internally
@@ -117,26 +117,42 @@ class InputfieldWrapper extends Inputfield implements \Countable, \IteratorAggre
*/
public function __construct() {
parent::__construct();
$this->children = new InputfieldsArray();
$this->children = new InputfieldsArray();
$this->set('skipLabel', Inputfield::skipLabelFor);
$this->requiredLabel = $this->_('Missing required value');
$columnWidthSpacing = $this->wire('config')->inputfieldColumnWidthSpacing;
$columnWidthSpacing = is_null($columnWidthSpacing) ? 1 : (int) $columnWidthSpacing;
$this->set('columnWidthSpacing', $columnWidthSpacing);
$this->set('useDependencies', true); // whether or not to use consider field dependencies during processing
// allow optional override of any above settings with a $config->InputfieldWrapper array.
$settings = $this->wire('config')->InputfieldWrapper;
if(is_array($settings)) foreach($settings as $key => $value) {
if($key == 'requiredLabel') {
$this->requiredLabel = $value;
} else if($key == 'useColumnWidth') {
$this->useColumnWidth = $value;
} else {
$this->set($key, $value);
}
}
$this->set('renderValueMode', false);
$this->set('quietMode', false); // suppress label, description and notes
$this->set('columnWidthSpacing', 0);
}
public function wired() {
/** @var Config $config */
$config = $this->wire('config');
$this->wire($this->children);
$this->requiredLabel = $this->_('Missing required value');
$columnWidthSpacing = $config->inputfieldColumnWidthSpacing;
$columnWidthSpacing = is_null($columnWidthSpacing) ? 1 : (int) $columnWidthSpacing;
if($columnWidthSpacing > 0) $this->set('columnWidthSpacing', $columnWidthSpacing);
$columnWidthSpacing = null;
$settings = $config->InputfieldWrapper;
if(is_array($settings)) {
foreach($settings as $key => $value) {
if($key == 'requiredLabel') {
$this->requiredLabel = $value;
} else if($key == 'useColumnWidth') {
$this->useColumnWidth = $value;
} else {
$this->set($key, $value);
}
}
}
parent::wired();
}
/**

View File

@@ -312,7 +312,11 @@ class Modules extends WireArray {
public function __construct($path) {
parent::__construct();
$this->addPath($path);
}
public function wired() {
$this->coreModulesDir = '/' . $this->wire('config')->urls->data('modules');
parent::wired();
}
/**
@@ -5091,7 +5095,8 @@ class Modules extends WireArray {
// compile if necessary
if($compile) {
$compiler = new FileCompiler(dirname($file));
/** @var FileCompiler $compiler */
$compiler = $this->wire(new FileCompiler(dirname($file)));
$compiledFile = $compiler->compile(basename($file));
if($compiledFile) $file = $compiledFile;
}

View File

@@ -93,6 +93,7 @@ class PagefilesManager extends Wire {
*
*/
public function __construct(Page $page) {
$page->wire($this);
$this->init($page);
}

View File

@@ -161,6 +161,7 @@ class Pageimage extends Pagefile {
public function __construct(Pagefiles $pagefiles, $filename) {
if(!$pagefiles instanceof Pageimages) throw new WireException("Pageimage::__construct requires instance of Pageimages");
$pagefiles->wire($this);
$this->pageimages = $pagefiles;
parent::__construct($pagefiles, $filename);
}

View File

@@ -538,8 +538,7 @@ class PagesParents extends Wire {
// identify parents to store for $page
foreach($page->parents() as $parent) {
$parents_id = (int) $parent->id;
if($parents_id < 2) break;
$inserts[] = "$pages_id,$parents_id";
if($parents_id > 1) $inserts[] = "$pages_id,$parents_id";
}
if(count($inserts)) {

View File

@@ -71,7 +71,7 @@ class SessionCSRF extends Wire {
if(empty($tokenValue)) {
// $tokenValue = md5($this->page->path() . mt_rand() . microtime()) . md5($this->page->name . $this->config->userAuthSalt . mt_rand());
$rand = new WireRandom();
$tokenValue = $rand->base64(32);
$tokenValue = $rand->base64(32, array('fast' => true));
$this->session->set($this, $tokenName, $tokenValue);
}
return $tokenValue;

View File

@@ -775,6 +775,7 @@ class Tfa extends WireData implements Module, ConfigurableModule {
// fieldset for TFA settings
$fieldset = new InputfieldWrapper();
$this->wire($fieldset);
$settings = $this->getUserSettings($user);
if(!$this->enabledForUser($user, $settings)) {
$this->getUserSettingsInputfields($user, $fieldset, $settings);

View File

@@ -298,7 +298,11 @@ class WireDataDB extends WireData implements \Countable {
*
*/
public function table($tableName = '') {
if($tableName !== '') $this->table = strtolower($this->wire('database')->escapeTable($tableName));
if($tableName === '') return $this->table;
if(!ctype_alnum(str_replace('_', '', $tableName))) {
$tableName = preg_replace('/[^_a-zA-Z0-9]/', '_', $tableName);
}
$this->table = strtolower($tableName);
return $this->table;
}

View File

@@ -1187,7 +1187,8 @@ class WireFileTools extends Wire {
} else {
$f = '';
}
$compiler = new FileCompiler(dirname($file), $options);
/** @var FileCompiler $compiler */
$compiler = $this->wire(new FileCompiler(dirname($file), $options));
$compiledFile = $compiler->compile(basename($file));
if($f) $compiled[$f] = $compiledFile;
return $compiledFile;

View File

@@ -136,6 +136,7 @@ if($page->process && $page->process != 'ProcessPageView') {
}
$controller = new ProcessController();
$wire->wire($controller);
$controller->setProcessName($page->process);
$initFile = $config->paths->adminTemplates . 'init.php';
if(is_file($initFile)) {