]> git.mxchange.org Git - hub.git/blobdiff - application/hub/main/filter/node/class_NodePhpRequirementsFilter.php
Better name for the miner: It "mines" for Hubcoins.
[hub.git] / application / hub / main / filter / node / class_NodePhpRequirementsFilter.php
index 2012ca5d47322d9cb7193d2c4c7b8cf3b9e171a8..7cba2b5ca371859eaff41ae81f319f4712d60b8e 100644 (file)
@@ -2,11 +2,11 @@
 /**
  * A PhpRequirements filter for nodes
  *
- * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 Hub Developer Team
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Hub Developer Team
  * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.ship-simu.org
+ * @link               http://www.shipsimu.org
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class NodePhpRequirementsFilter extends BaseFilter implements Filterable {
+class NodePhpRequirementsFilter extends BaseNodeFilter implements Filterable {
        /**
         * Protected constructor
         *
@@ -37,7 +37,7 @@ class NodePhpRequirementsFilter extends BaseFilter implements Filterable {
         *
         * @return      $filterInstance         An instance of this filter class
         */
-       public final static function createNodePhpRequirementsFilter () {
+       public static final function createNodePhpRequirementsFilter () {
                // Get a new instance
                $filterInstance = new NodePhpRequirementsFilter();
 
@@ -51,11 +51,36 @@ class NodePhpRequirementsFilter extends BaseFilter implements Filterable {
         * @param       $requestInstance        An instance of a class with an Requestable interface
         * @param       $responseInstance       An instance of a class with an Responseable interface
         * @return      void
-        * @todo        0% done
+        * @throws      FilterChainException    If a required PHP function is not available
+        * @todo        Add more test and try to add an extra message to the thrown exception
         */
        public function execute (Requestable $requestInstance, Responseable $responseInstance) {
-               // Implement this!
-               $this->partialStub('Please implement this method.');
+               // By default, the requirement check is passed and zero checks are failed
+               $checkPassed = TRUE;
+               $checksFailed = 0;
+
+               // Socket support is essential...
+               if (!function_exists('socket_create')) {
+                       // Test failed
+                       $checkPassed = FALSE;
+                       $checksFailed++;
+               } // END - if
+
+               // If scrypt() is not found (ext-scrypt) then the "Hubcoins reward" is not working
+               if ((extension_loaded('scrypt')) && (is_callable('scrypt'))) {
+                       // Mark it as working
+                       self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt and a callable scrypt() function found. "Hubcoin reward" feature possible.');
+                       $this->getConfigInstance()->setConfigEntry('extension_scrypt_loaded', TRUE);
+               } else {
+                       // Not working (not all have ext-scrypt installed
+                       self::createDebugInstance(__CLASS__)->debugOutput('FILTER[' . __METHOD__ . ':' . __LINE__ . '] ext-scrypt not found or scrypt() function not found. "Hubcoin reward" feature disabled.');
+               }
+
+               // Are all tests passed?
+               if ($checkPassed === FALSE) {
+                       // Throw an exception
+                       throw new FilterChainException($this, self::EXCEPTION_FILTER_CHAIN_INTERCEPTED);
+               } // END - if
        }
 }