Skip to content

Commit

Permalink
Move vendor/Joomla to src/Joomla. Update necessary paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
dongilbert committed Mar 27, 2013
0 parents commit 0a5405f
Show file tree
Hide file tree
Showing 16 changed files with 6,120 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
vendor/
composer.phar
composer.lock
phpunit.xml
106 changes: 106 additions & 0 deletions Factory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php
/**
* Part of the Joomla Framework Http Package
*
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/

namespace Joomla\Http;

use Joomla\Registry\Registry;

/**
* HTTP factory class.
*
* @since 1.0
*/
class Factory
{
/**
* Method to recieve Http instance.
*
* @param Registry $options Client options object.
* @param mixed $adapters Adapter (string) or queue of adapters (array) to use for communication.
*
* @return Http Joomla Http class
*
* @since 1.0
*/
public static function getHttp(Registry $options = null, $adapters = null)
{
if (empty($options))
{
$options = new Registry;
}

return new Http($options, self::getAvailableDriver($options, $adapters));
}

/**
* Finds an available http transport object for communication
*
* @param Registry $options Option for creating http transport object
* @param mixed $default Adapter (string) or queue of adapters (array) to use
*
* @return TransportInterface Interface sub-class
*
* @since 1.0
*/
public static function getAvailableDriver(Registry $options, $default = null)
{
if (is_null($default))
{
$availableAdapters = self::getHttpTransports();
}
else
{
settype($default, 'array');
$availableAdapters = $default;
}

// Check if there is at least one available http transport adapter
if (!count($availableAdapters))
{
return false;
}

foreach ($availableAdapters as $adapter)
{
$class = '\\Joomla\\Http\\Transport\\' . ucfirst($adapter);

if ($class::isSupported())
{
return new $class($options);
}
}

return false;
}

/**
* Get the http transport handlers
*
* @return array An array of available transport handlers
*
* @since 1.0
*/
public static function getHttpTransports()
{
$names = array();
$iterator = new \DirectoryIterator(__DIR__ . '/Transport');

foreach ($iterator as $file)
{
$fileName = $file->getFilename();

// Only load for php files.
if ($file->isFile() && $file->getExtension() == 'php')
{
$names[] = substr($fileName, 0, strrpos($fileName, '.'));
}
}

return $names;
}
}
Loading

0 comments on commit 0a5405f

Please sign in to comment.