Skip to content

Instantly share code, notes, and snippets.

@totten
Created October 14, 2016 12:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save totten/f080b6fa821d1b6c4d6711e750f04cd2 to your computer and use it in GitHub Desktop.
Save totten/f080b6fa821d1b6c4d6711e750f04cd2 to your computer and use it in GitHub Desktop.
diff --git a/CRM/Utils/PhpData.php b/CRM/Utils/PhpData.php
new file mode 100644
index 0000000..0f3cac9
--- /dev/null
+++ b/CRM/Utils/PhpData.php
@@ -0,0 +1,58 @@
+<?php
+
+/**
+ * Read/write a serialized data file based on PHP's var_export() format
+ *
+ * @code
+ * $data = CRM_Utils_PhpData::create('/tmp/example.php')->load();
+ * CRM_Utils_PhpData::create('/tmp/example.php')->save($data);
+ * @endCode
+ */
+class CRM_Utils_PhpData {
+
+ /**
+ * @var string
+ */
+ protected $path;
+
+ /**
+ * @var
+ */
+ protected $header;
+
+ public function __construct($path, $header = NULL) {
+ $this->path = $path;
+ $this->header = $header;
+ }
+
+ /**
+ * @param string $path
+ * @param string|NULL $header
+ * @return \CRM_Utils_PhpData
+ */
+ public static function create($path, $header = NULL) {
+ return new CRM_Utils_PhpData($path, $header);
+ }
+
+ /**
+ * Read from file
+ */
+ public function load() {
+ return include $this->path;
+ }
+
+ /**
+ * Write the xml document
+ */
+ public function save($data) {
+ $content = "<?php\n";
+ if ($this->header) {
+ $content .= $this->header;
+ }
+ $content .= "\nreturn ";
+ $content .= var_export($data, TRUE);
+ $content .= ";";
+ file_put_contents($this->path, $content);
+ }
+
+}
diff --git a/templates/CRM/common/civicrm.settings.php.template b/templates/CRM/common/civicrm.settings.php.template
index 44f2d7b..6216e60 100644
--- a/templates/CRM/common/civicrm.settings.php.template
+++ b/templates/CRM/common/civicrm.settings.php.template
@@ -419,6 +419,13 @@ if (CIVICRM_UF === 'UnitTests') {
if (!defined('CIVICRM_MYSQL_STRICT')) define('CIVICRM_MYSQL_STRICT', true);
}
+if (file_exists(__DIR__ . '/civicrm.settings.extra.php')) {
+ $data = require_once __DIR__ . '/civicrm.settings.extra.php';
+ foreach ($data['define'] as $key => $value) {
+ if (!defined($key)) define($key, $value);
+ }
+}
+
/**
*
* Do not change anything below this line. Keep as is
@bakmanhans
Copy link

How do I implement this code onto a 4.7 CiviCRM, WordPress installation. I need to add the extra "CiviCRM in it's own directory" feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment