From: Tim Otten Date: Thu, 7 Mar 2013 02:17:50 +0000 (-0500) Subject: CRM-12039 - Add checkRequirements to CRM_Extension_Container_Interface X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=0bb81f2469af536ec5d7da7806acb44659f580e6;p=civicrm-core.git CRM-12039 - Add checkRequirements to CRM_Extension_Container_Interface --- diff --git a/CRM/Extension/Container/Basic.php b/CRM/Extension/Container/Basic.php index c6fe7a674b..696700b817 100644 --- a/CRM/Extension/Container/Basic.php +++ b/CRM/Extension/Container/Basic.php @@ -96,6 +96,29 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface $this->baseUrl = rtrim($baseUrl, '/'); } + /** + * {@inheritdoc} + */ + public function checkRequirements() { + $errors = array(); + + if (empty($this->baseDir) || !is_dir($this->baseDir)) { + $errors[] = array( + 'title' => ts('Invalid Base Directory'), + 'message' => ts('An extension container has been defined with a blank directory.'), + ); + } + if (empty($this->baseUrl)) { + dpm($this); + $errors[] = array( + 'title' => ts('Invalid Base URL'), + 'message' => ts('An extension container has been defined with a blank URL.'), + ); + } + + return $errors; + } + /** * {@inheritdoc} */ @@ -142,7 +165,7 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface */ protected function getRelPath($key) { $keypaths = $this->getRelPaths(); - if (! isset($keypaths[$key])) { + if (!isset($keypaths[$key])) { throw new CRM_Extension_Exception_MissingException("Failed to find extension: $key"); } return $keypaths[$key]; @@ -190,7 +213,7 @@ class CRM_Extension_Container_Basic implements CRM_Extension_Container_Interface */ protected function getRelUrl($key) { $relUrls = $this->getRelUrls(); - if (! isset($relUrls[$key])) { + if (!isset($relUrls[$key])) { throw new CRM_Extension_Exception_MissingException("Failed to find extension: $key"); } return $relUrls[$key]; diff --git a/CRM/Extension/Container/Collection.php b/CRM/Extension/Container/Collection.php index 337722a08a..6b69b794df 100644 --- a/CRM/Extension/Container/Collection.php +++ b/CRM/Extension/Container/Collection.php @@ -79,6 +79,16 @@ class CRM_Extension_Container_Collection implements CRM_Extension_Container_Inte /** * {@inheritdoc} */ + public function checkRequirements() { + $errors = array(); + foreach ($this->containers as $container) { + $errors = array_merge($errors, $container->checkRequirements()); + } + return $errors; + } + /** + * {@inheritdoc} + */ public function getKeys() { $k2c = $this->getKeysToContainer(); return array_keys($k2c); diff --git a/CRM/Extension/Container/Interface.php b/CRM/Extension/Container/Interface.php index 0f3b5e9fa5..6a18094ef9 100644 --- a/CRM/Extension/Container/Interface.php +++ b/CRM/Extension/Container/Interface.php @@ -37,6 +37,13 @@ */ interface CRM_Extension_Container_Interface { + /** + * Determine if any unmet requirements prevent use of this container. + * + * @return array list of error messages; empty if OK + */ + public function checkRequirements(); + /** * Get a list of extensions available in this container *