Permalink
Browse files

Merge pull request #17 from jeremiahsmall/development

Add fieldMap and toArray support
  • Loading branch information...
2 parents 6bac06c + c536c55 commit 8884bba3555765312cc60d7c21522cf97e19eadb @jeremiahsmall committed Mar 20, 2013
@@ -13,42 +13,42 @@
abstract class AbstractLoader implements LoaderInterface
{
-
+
protected $credentials;
protected $username;
protected $args;
protected $commandURL;
-
+
protected function createCredentials()
{
$username = $this->adapter->getUsername();
$password = $this->adapter->getPassword();
-
+
$this->username = $username;
$this->credentials = empty($username)?'':$username.':'.$password;
return $this->credentials;
}
-
+
protected function createArgs()
{
$dbname = $this->adapter->getDbname();
$layoutname = $this->adapter->getLayoutname();
$commandstring = $this->adapter->getCommandstring();
-
+
$this->args = "-db=$dbname&-lay=$layoutname&$commandstring";
return $this->args;
}
-
+
protected function createCommandURL()
{
$credentials = self::createCredentials();
$args = self::createArgs();
-
+
$protocol = $this->adapter->getProtocol();
$hostname = $this->adapter->getHostname();
$port = $this->adapter->getPort();
$fmresultsetUri = $this->adapter->getFmresultsetUri();
-
+
$this->commandURL = "$protocol://$credentials@$hostname:$port$fmresultsetUri?$args";
return $this->commandURL;
}
@@ -57,13 +57,13 @@ protected function setAdapterCommandURLdebug()
{
$this->adapter->setCommandURLdebug(empty($this->credentials)?$this->commandURL:str_replace($this->credentials, $this->username.':[...]', $this->commandURL));
}
-
+
protected function prepare()
{
self::createCredentials();
self::createArgs();
self::createCommandURL();
self::setAdapterCommandURLdebug();
}
-
-}
+
+}
@@ -17,50 +17,50 @@
class Curl extends AbstractLoader
{
-
+
protected function createPostURL()
{
$protocol = $this->adapter->getProtocol();
$hostname = $this->adapter->getHostname();
$port = $this->adapter->getPort();
$fmresultsetUri = $this->adapter->getFmresultsetUri();
-
+
return "$protocol://$hostname:$port$fmresultsetUri";
}
-
+
/**
* @return SimpleXMLElement
*/
public function load(Adapter $adapter)
{
$this->adapter = $adapter;
-
+
self::prepare();
-
-
+
+
$curlHandle = curl_init(self::createPostURL());
-
+
curl_setopt($curlHandle, CURLOPT_USERPWD, $this->credentials);
curl_setopt($curlHandle, CURLOPT_POST, TRUE);
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $this->args);
-
+
ob_start();
-
+
if (!curl_exec($curlHandle)) {
ob_end_clean();
throw new LoaderException('cURL was unable to connect.');
}
-
+
curl_close($curlHandle);
-
+
$data = trim(ob_get_contents());
-
+
ob_end_clean();
-
+
libxml_use_internal_errors(true);
-
+
return simplexml_load_string($data);
-
+
}
-
+
}
@@ -16,20 +16,20 @@
class FileGetContents extends AbstractLoader
{
-
+
/**
* @return SimpleXMLElement
*/
public function load(Adapter $adapter)
{
$this->adapter = $adapter;
-
+
self::prepare();
-
+
libxml_use_internal_errors(true);
-
+
return simplexml_load_string(file_get_contents($this->commandURL));
-
+
}
-
+
}
@@ -16,29 +16,29 @@
class FilePostContents extends AbstractLoader
{
-
+
protected function createPostURL()
{
$protocol = $this->adapter->getProtocol();
$hostname = $this->adapter->getHostname();
$port = $this->adapter->getPort();
$fmresultsetUri = $this->adapter->getFmresultsetUri();
-
+
return "$protocol://$hostname:$port$fmresultsetUri";
}
-
+
/**
* @return SimpleXMLElement
*/
public function load(Adapter $adapter)
{
$this->adapter = $adapter;
-
+
self::prepare();
-
+
libxml_use_internal_errors(true);
$authheader = empty($this->credentials) ? '' : 'Authorization: Basic '.base64_encode($this->credentials) . PHP_EOL;
-
+
$opts = array('http' =>
array(
'method' => 'POST',
@@ -51,12 +51,12 @@ public function load(Adapter $adapter)
'content' => $this->args
)
);
-
+
$context = stream_context_create($opts);
-
-
+
+
return simplexml_load_string(file_get_contents(self::createPostURL(), FALSE , $context));
-
+
}
-
+
}
@@ -13,12 +13,11 @@
interface LoaderInterface
{
-
+
/**
* @param array $simpleFMAdapterRow
* @return SimpleXMLElement
*/
public function load(Adapter $adapter);
-
-}
+}
@@ -20,7 +20,7 @@ class Mock extends AbstractLoader
* @var string
*/
protected $testXml;
-
+
/**
* @return the $testXml
*/
@@ -29,7 +29,7 @@ public function getTestXml ()
return $this->testXml;
}
- /**
+ /**
* @param string $testXml
*/
public function setTestXml ($testXml)
@@ -38,21 +38,21 @@ public function setTestXml ($testXml)
return $this;
}
- /**
+ /**
* @return SimpleXMLElement
*/
public function load(Adapter $adapter, $testXmlOverride=NULL)
{
$this->adapter = $adapter;
-
+
$testXml = $testXmlOverride ? $testXmlOverride : $this->testXml;
-
+
self::prepare();
-
+
libxml_use_internal_errors(true);
-
+
return simplexml_load_string($testXml);
-
+
}
-
+
}
@@ -1,7 +1,7 @@
<?php
/**
* This source file is subject to the MIT license that is bundled with this package in the file LICENSE.txt.
- *
+ *
* @package Soliant\SimpleFM
* @copyright Copyright (c) 2007-2013 Soliant Consulting, Inc. (http://www.soliantconsulting.com)
* @author jsmall@soliantconsulting.com
@@ -11,5 +11,5 @@
final class Version
{
- const VERSION = '2.0.0beta5';
+ const VERSION = '2.0.0beta6';
}
@@ -1,7 +1,7 @@
<?php
/**
* This source file is subject to the MIT license that is bundled with this package in the file LICENSE.txt.
- *
+ *
* @package Soliant\SimpleFM
* @copyright Copyright (c) 2007-2013 Soliant Consulting, Inc. (http://www.soliantconsulting.com)
* @author jsmall@soliantconsulting.com
@@ -4,4 +4,4 @@
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
-}
+}
@@ -5,4 +5,4 @@
class RuntimeException extends \RuntimeException implements ExceptionInterface
{
-}
+}
@@ -4,4 +4,4 @@
class UnexpectedValueException extends \UnexpectedValueException implements ExceptionInterface
{
-}
+}
@@ -115,7 +115,7 @@ public function __construct(array $config, Adapter $simpleFmValidateAdapter)
$this->accountNameField = $config['accountNameField'];
}
-
+
/**
* @return Soliant\SimpleFM\ZF2\Authentication\Adapter\Auth
*/
@@ -124,7 +124,7 @@ public function setUsername($username){
$this->credentials['username'] = $username;
return $this;
}
-
+
/**
* @return Soliant\SimpleFM\ZF2\Authentication\Adapter\Auth
*/
@@ -133,7 +133,7 @@ public function setPassword($password){
$this->credentials['password'] = $password;
return $this;
}
-
+
/**
* @return Zend\Authentication\Result
@@ -143,19 +143,19 @@ public function authenticate()
$this->simpleFmValidateAdapter->setLayoutname($this->identityLayout);
$this->simpleFmValidateAdapter->setCredentials($this->credentials);
-
+
$command = array(
$this->accountNameField => "==" . self::escapeStringForFileMakerSearch($this->username),
'-find' => NULL,
);
$this->simpleFmValidateAdapter->setCommandarray($command);
-
+
$result = $this->simpleFmValidateAdapter->execute();
-
+
$error = $result['error'];
$errortext = $result['errortext'];
$errortype = $result['errortype'];
-
+
// Based on the status, return auth result
switch ($error) {
case '0':
@@ -186,7 +186,7 @@ public function authenticate()
);
}
}
-
+
static public function escapeStringForFileMakerSearch($string)
{
return str_replace('@', '\@', $string);
@@ -4,4 +4,4 @@
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
-}
+}
Oops, something went wrong. Retry.

0 comments on commit 8884bba

Please sign in to comment.