Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

ClusterIndex: changed the way cluster gateways are instanciated

  • Loading branch information...
commit 11733229de9e2b43a0fb31b6840098b3b001099c 1 parent a52f0ce
@bdunogier bdunogier authored
View
16 index_cluster.php
@@ -33,7 +33,7 @@
ini_set( 'display_errors', CLUSTER_ENABLE_DEBUG );
-require "kernel/clustering/gateway.php";
+require_once "kernel/clustering/gateway.php";
if ( defined( 'CLUSTER_STORAGE_GATEWAY_PATH' ) && CLUSTER_STORAGE_GATEWAY_PATH )
$clusterGatewayFile = CLUSTER_STORAGE_GATEWAY_PATH;
@@ -47,16 +47,6 @@
}
// We use require_once as the gateway file may have been included before for initialization purpose
-$gatewayClass = require_once $clusterGatewayFile;
-$gateway = new $gatewayClass(
- array(
- "host" => CLUSTER_STORAGE_HOST,
- "port" => defined( "CLUSTER_STORAGE_PORT" ) ? CLUSTER_STORAGE_PORT : null,
- "user" => CLUSTER_STORAGE_USER,
- "password" => CLUSTER_STORAGE_PASS,
- "name" => CLUSTER_STORAGE_DB,
- "charset" => CLUSTER_STORAGE_CHARSET,
- )
-);
-
+require_once $clusterGatewayFile;
+$gateway = ezpClusterGateway::getGateway();
$gateway->retrieve( ltrim( $_SERVER['SCRIPT_URL'], '/' ) );
View
3  kernel/clustering/dbmysql.php
@@ -61,5 +61,4 @@ public function close()
}
}
-// return the class name for easier instanciation
-return 'ezpDbMySQLClusterGateway';
+ezpClusterGateway::setGatewayClass( 'ezpDbMySQLClusterGateway' );
View
3  kernel/clustering/dbmysqli.php
@@ -56,5 +56,4 @@ public function close()
}
}
-// return the class name for easier instanciation
-return 'ezpDbMySQLiClusterGateway';
+ezpClusterGateway::setGatewayClass( 'ezpDbMySQLiClusterGateway' );
View
3  kernel/clustering/dfsmysqli.php
@@ -67,5 +67,4 @@ public function close()
}
}
-// return the class name for easier instanciation
-return 'ezpDfsMySQLiClusterGateway';
+ezpClusterGateway::setGatewayClass( 'ezpDfsMySQLiClusterGateway' );
View
3  kernel/clustering/dfspostgresql.php
@@ -68,5 +68,4 @@ public function close()
}
}
-// return the class name for easier instanciation
-return 'ezpDfsPostgresqlClusterGateway';
+ezpClusterGateway::setGatewayClass( 'ezpDfsPostgresqlClusterGateway' );
View
37 kernel/clustering/gateway.php
@@ -14,6 +14,12 @@
abstract class ezpClusterGateway
{
/**
+ * The active gateway class
+ * @var string
+ */
+ private static $gatewayClass;
+
+ /**
* Database instance, optional
*
* @var mixed
@@ -285,4 +291,35 @@ private function notModified()
}
exit;
}
+
+ /**
+ * Sets the gateway class to $gatewayClass
+ *
+ * @param string $gatewayClass
+ */
+ public static function setGatewayClass( $gatewayClass )
+ {
+ self::$gatewayClass = $gatewayClass;
+ }
+
+ /**
+ * Returns an instance of the gateway class depending on {@link setGatewayClass()}
+ *
+ * @return ezpClusterGateway
+ */
+ public static function getGateway()
+ {
+ $gatewayClass = self::$gatewayClass;
+
+ return new $gatewayClass(
+ array(
+ "host" => CLUSTER_STORAGE_HOST,
+ "port" => defined( "CLUSTER_STORAGE_PORT" ) ? CLUSTER_STORAGE_PORT : null,
+ "user" => CLUSTER_STORAGE_USER,
+ "password" => CLUSTER_STORAGE_PASS,
+ "name" => CLUSTER_STORAGE_DB,
+ "charset" => CLUSTER_STORAGE_CHARSET,
+ )
+ );
+ }
}

2 comments on commit 1173322

@gggeek

getGateway will raise a php fatal error if there is an error in the configuration file (class not found). Is this fine or should we trap that error and wrap it in a nicer error 500?

@bdunogier
Owner
Please sign in to comment.
Something went wrong with that request. Please try again.