Skip to content

Commit 37aca81

Browse files
committed
Merge branch 'master' of github.com:troydavisson/PHRETS
2 parents 4dd3e18 + 53548ea commit 37aca81

44 files changed

Lines changed: 67 additions & 19 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Configuration
1313
protected $username;
1414
protected $password;
1515
protected $login_url;
16-
protected $user_agent = 'PHRETS/2.0';
16+
protected $user_agent = 'PHRETS/2.5';
1717
protected $user_agent_password;
1818
/** @var RETSVersion */
1919
protected $rets_version;

src/Http/Response.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ public function __construct(ResponseInterface $response)
2121

2222
public function xml()
2323
{
24-
return new \SimpleXMLElement((string) $this->response->getBody());
24+
$body = (string) $this->response->getBody();
25+
26+
// Remove any carriage return / newline in XML response.
27+
$body = trim($body);
28+
29+
return new \SimpleXMLElement($body);
2530
}
2631

2732
public function __call($method, $args = [])
@@ -32,7 +37,7 @@ public function __call($method, $args = [])
3237
public function getHeader($name)
3338
{
3439
$headers = $this->response->getHeader($name);
35-
40+
3641
if ($headers) {
3742
return implode('; ', $headers);
3843
} else {

src/Interpreters/GetObject.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public static function ids($content_ids, $object_ids)
3030
protected static function split($value, $dash_ranges = true)
3131
{
3232
if (!is_array($value)) {
33-
if (preg_match('/\:/', $value)) {
33+
if (stripos($value, ':') !== false) {
3434
$value = array_map('trim', explode(':', $value));
35-
} elseif (preg_match('/\,/', $value)) {
35+
} elseif (stripos($value, ',') !== false) {
3636
$value = array_map('trim', explode(',', $value));
3737
} elseif ($dash_ranges and preg_match('/(\d+)\-(\d+)/', $value, $matches)) {
3838
$value = range($matches[1], $matches[2]);

src/Models/Metadata/Base.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,20 @@ public function setSession($session)
3333
*/
3434
public function __call($name, $args = [])
3535
{
36-
if (preg_match('/^set/', strtolower($name))) {
36+
$name = strtolower($name);
37+
$action = substr($name, 0, 3);
38+
39+
if ($action === 'set') {
3740
foreach (array_merge($this->getXmlElements(), $this->getXmlAttributes()) as $attr) {
38-
if (strtolower('set' . $attr) == strtolower($name)) {
41+
if (strtolower('set' . $attr) == $name) {
3942
$this->values[$attr] = $args[0];
4043
break;
4144
}
4245
}
4346
return $this;
44-
} elseif (preg_match('/^get/', strtolower($name))) {
47+
} elseif ($action === 'get') {
4548
foreach (array_merge($this->getXmlElements(), $this->getXmlAttributes()) as $attr) {
46-
if (strtolower('get' . $attr) == strtolower($name)) {
49+
if (strtolower('get' . $attr) == $name) {
4750
return \array_get($this->values, $attr);
4851
}
4952
}

src/Parsers/Search/OneX.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,20 @@ protected function getRestrictedIndicator(Session $rets, &$xml, $parameters)
8383
protected function getColumnNames(Session $rets, &$xml, $parameters)
8484
{
8585
$delim = $this->getDelimiter($rets, $xml, $parameters);
86+
$delimLength = strlen($delim);
8687

8788
// break out and track the column names in the response
8889
$column_names = "{$xml->COLUMNS[0]}";
8990

90-
// take out the first delimiter
91-
$column_names = preg_replace("/^{$delim}/", "", $column_names);
91+
// Take out the first delimiter
92+
if (substr($column_names, 0, $delimLength) == $delim) {
93+
$column_names = substr($column_names, $delimLength);
94+
}
9295

93-
// take out the last delimiter
94-
$column_names = preg_replace("/{$delim}\$/", "", $column_names);
96+
// Take out the last delimiter
97+
if (substr($column_names, -$delimLength) == $delim) {
98+
$column_names = substr($column_names, 0, -$delimLength);
99+
}
95100

96101
// parse and return the rest
97102
return explode($delim, $column_names);
@@ -109,13 +114,21 @@ protected function parseRecords(Session $rets, &$xml, $parameters, Results $rs)
109114
protected function parseRecordFromLine(Session $rets, &$xml, $parameters, &$line, Results $rs)
110115
{
111116
$delim = $this->getDelimiter($rets, $xml, $parameters);
117+
$delimLength = strlen($delim);
112118

113119
$r = new Record;
114-
$field_data = (string)$line;
120+
$field_data = (string) $line;
121+
122+
// Take out the first delimiter
123+
if (substr($field_data, 0, $delimLength) == $delim) {
124+
$field_data = substr($field_data, $delimLength);
125+
}
126+
127+
// Take out the last delimiter
128+
if (substr($field_data, -$delimLength) == $delim) {
129+
$field_data = substr($field_data, 0, -$delimLength);
130+
}
115131

116-
// split up DATA row on delimiter found earlier
117-
$field_data = preg_replace("/^{$delim}/", "", $field_data);
118-
$field_data = preg_replace("/{$delim}\$/", "", $field_data);
119132
$field_data = explode($delim, $field_data);
120133

121134
foreach ($rs->getHeaders() as $key => $name) {

src/Session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function GetObject($resource, $type, $content_ids, $object_ids = '*', $lo
131131
]
132132
);
133133

134-
if (preg_match('/multipart/', $response->getHeader('Content-Type'))) {
134+
if (stripos($response->getHeader('Content-Type'), 'multipart') !== false) {
135135
$parser = $this->grab(Strategy::PARSER_OBJECT_MULTIPLE);
136136
$collection = $parser->parse($response);
137137
} else {
@@ -388,7 +388,7 @@ protected function request($capability, $options = [], $is_retry = false)
388388

389389
$this->debug('Response: HTTP ' . $response->getStatusCode());
390390

391-
if (preg_match('/text\/xml/', $response->getHeader('Content-Type')) and $capability != 'GetObject') {
391+
if (stripos($response->getHeader('Content-Type'), 'text/xml') !== false and $capability != 'GetObject') {
392392
$parser = $this->grab(Strategy::PARSER_XML);
393393
$xml = $parser->parse($response);
394394

tests/Http/ResponseTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
class ResponseTest extends PHPUnit_Framework_TestCase {
4+
5+
/** @test **/
6+
public function it_creates_valid_xml()
7+
{
8+
$body = "<?xml version='1.0' encoding='UTF-8'?><guestbook><guest><fname>First Name</fname><lname>Last Name</lname></guest></guestbook>";
9+
$guzzleResponse = new GuzzleHttp\Psr7\Response(200, ['X-Foo' => 'Bar'], $body);
10+
11+
$response = new PHRETS\Http\Response($guzzleResponse);
12+
13+
$this->assertEquals(1, $response->xml()->count());
14+
}
15+
16+
/** @test **/
17+
public function it_creates_valid_xml_with_new_lines()
18+
{
19+
$body = "\n\n\r<?xml version='1.0' encoding='UTF-8'?><guestbook><guest><fname>First Name</fname><lname>Last Name</lname></guest></guestbook>\r\n\n";
20+
$guzzleResponse = new GuzzleHttp\Psr7\Response(200, ['X-Foo' => 'Bar'], $body);
21+
22+
$response = new PHRETS\Http\Response($guzzleResponse);
23+
24+
$this->assertEquals(1, $response->xml()->count());
25+
}
26+
}

tests/Integration/BaseIntegration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function setUp()
2828

2929
$watcher = new Gsaulmon\GuzzleRecorder\GuzzleRecorder(__DIR__ . '/Fixtures/Http');
3030
$watcher->addIgnoredHeader('Accept');
31+
$watcher->addIgnoredHeader('User-Agent');
3132
$watcher->addIgnoredHeader('Cookie');
3233

3334
$watcher->attach_to($new_client);

tests/Integration/Fixtures/Http/get/retsgw.flexmls.com/action_rets2_1_Action/c137023b38529b645fb39f8ad8279cd2.txt renamed to tests/Integration/Fixtures/Http/get/retsgw.flexmls.com/action_rets2_1_Action/d5d441322368e5c2ad059621979b0d88.txt

File renamed without changes.

tests/Integration/Fixtures/Http/get/retsgw.flexmls.com/action_rets2_1_Login/5f7f2002a41ef7e295cfafd7761604d6.txt renamed to tests/Integration/Fixtures/Http/get/retsgw.flexmls.com/action_rets2_1_Login/03cd0f6cb206f18aed8f4979939a9482.txt

File renamed without changes.

0 commit comments

Comments
 (0)