]> git.mxchange.org Git - core.git/commitdiff
Added first client (HTTP) classes and interfaces for rewrite of the very simple metho...
authorRoland Haeder <roland@mxchange.org>
Mon, 12 May 2014 20:44:35 +0000 (22:44 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 12 May 2014 20:44:35 +0000 (22:44 +0200)
Signed-off-by: Roland Häder <roland@mxchange.org>
inc/classes/interfaces/client/.htaccess [new file with mode: 0644]
inc/classes/interfaces/client/class_Client.php [new file with mode: 0644]
inc/classes/main/client/.htaccess [new file with mode: 0644]
inc/classes/main/client/class_ [new file with mode: 0644]
inc/classes/main/client/class_BaseClient.php [new file with mode: 0644]
inc/classes/main/client/http/.htaccess [new file with mode: 0644]
inc/classes/main/client/http/class_HttpClient.php [new file with mode: 0644]
inc/classes/main/factories/client/.htaccess [new file with mode: 0644]
inc/classes/main/factories/client/class_ClientFactory.php [new file with mode: 0644]

diff --git a/inc/classes/interfaces/client/.htaccess b/inc/classes/interfaces/client/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/interfaces/client/class_Client.php b/inc/classes/interfaces/client/class_Client.php
new file mode 100644 (file)
index 0000000..a3aa288
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+/**
+ * An interface for clients (e.g. HTTP, FTP, ...)
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+interface Client extends FrameworkInterface {
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/client/.htaccess b/inc/classes/main/client/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/client/class_ b/inc/classes/main/client/class_
new file mode 100644 (file)
index 0000000..59ccec1
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * A ??? client class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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 ???Client extends BaseClient implements Client {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this Client class and prepares it for usage
+        *
+        * @return      $clientInstance         An instance of a Client class
+        */
+       public final static function create???Client () {
+               // Get a new instance
+               $clientInstance = new ???Client();
+
+               // Return the prepared instance
+               return $clientInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/client/class_BaseClient.php b/inc/classes/main/client/class_BaseClient.php
new file mode 100644 (file)
index 0000000..5d67a54
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+/**
+ * A general client class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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 BaseClient extends BaseFrameworkSystem {
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of the class
+        * @return      void
+        */
+       protected function __construct ($className) {
+               // Call parent constructor
+               parent::__construct($className);
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/client/http/.htaccess b/inc/classes/main/client/http/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/client/http/class_HttpClient.php b/inc/classes/main/client/http/class_HttpClient.php
new file mode 100644 (file)
index 0000000..ec4da77
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/**
+ * A HTTP client class
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2012 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @link               http://www.ship-simu.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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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 HttpClient extends BaseClient implements Client {
+       /**
+        * Protected constructor
+        *
+        * @return      void
+        */
+       protected function __construct () {
+               // Call parent constructor
+               parent::__construct(__CLASS__);
+       }
+
+       /**
+        * Creates an instance of this Client class and prepares it for usage
+        *
+        * @return      $clientInstance         An instance of a Client class
+        */
+       public final static function createHttpClient () {
+               // Get a new instance
+               $clientInstance = new HttpClient();
+
+               // Return the prepared instance
+               return $clientInstance;
+       }
+}
+
+// [EOF]
+?>
diff --git a/inc/classes/main/factories/client/.htaccess b/inc/classes/main/factories/client/.htaccess
new file mode 100644 (file)
index 0000000..3a42882
--- /dev/null
@@ -0,0 +1 @@
+Deny from all
diff --git a/inc/classes/main/factories/client/class_ClientFactory.php b/inc/classes/main/factories/client/class_ClientFactory.php
new file mode 100644 (file)
index 0000000..a46749b
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+/**
+ * An general object factory
+ *
+ * @author             Roland Haeder <webmaster@shipsimu.org>
+ * @version            0.0.0
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2013 Core Developer Team
+ * @license            GNU GPL 3.0 or any newer version
+ * @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
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * 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 ObjectFactory extends BaseFactory {
+       /**
+        * Protected constructor
+        *
+        * @param       $className      Name of this class
+        * @return      void
+        */
+       protected function __construct ($className = __CLASS__) {
+               // Call parent constructor
+               parent::__construct($className);
+       }
+
+       /**
+        * Creates a new object given by the name or throws an exception if
+        * the class was not found. No parameters for the object are currently
+        * supported.
+        *
+        * @param       $className                      Name of the class we shall construct
+        * @param       $args                           Arguments in an indexed array
+        * @return      $objectInstance         An instance of the requested object
+        * @throws      NoClassException        If the requested class was not found
+        * @throws      EmptyVariableException  If a variable is empty unexpectly
+        */
+       public static final function createObjectByName ($className, array $args=array()) {
+               // First get an instance of this factory
+               $factoryInstance = new ObjectFactory();
+
+               // Is the class name valid and is the class there?
+               if (empty($className)) {
+                       // Throw an exception here
+                       throw new EmptyVariableException(array($factoryInstance, 'className'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } elseif (!class_exists($className)) {
+                       // Then throw an exception
+                       throw new NoClassException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND);
+               }
+
+               // Create method name
+               $methodName = sprintf("create%s", $className);
+
+               // Run the user function
+               $objectInstance = call_user_func_array(array($className, $methodName), $args);
+
+               // Count this one up
+               self::countObject($className);
+
+               // Return the prepared instance
+               return $objectInstance;
+       }
+
+       /**
+        * Creates an object by it's configured name
+        *
+        * @param       $configEnttry           Configuration entry to read
+        * @param       $args                           Arguments in an indexed array
+        * @return      $objectInstance         An instance of the requested object
+        */
+       public static final function createObjectByConfiguredName ($configEntry, array $args=array()) {
+               // Read the configuration entry
+               $className = FrameworkConfiguration::getSelfInstance()->getConfigEntry($configEntry);
+
+               // Send this to the other factory...
+               $objectInstance = self::createObjectByName($className, $args);
+
+               // Return the instance
+               return $objectInstance;
+       }
+}
+
+// [EOF]
+?>