Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code 'EUR' not found #1

Closed
webdeal opened this issue Jan 9, 2020 · 4 comments
Closed

Code 'EUR' not found #1

webdeal opened this issue Jan 9, 2020 · 4 comments

Comments

@webdeal
Copy link

webdeal commented Jan 9, 2020

  • bug report? yes
  • feature request? no
  • version: 2.2

Description

I have code:
$code = 'EUR';
$cnb = new \CnbApi\CnbApi(storage_path('app/cnb'));
$a = $cnb->findRateByCode($code);
print_r($a);
exit;

When I run it, it shows error: Code 'EUR' not found
Where can be problem?

@filipsedivy
Copy link
Owner

When I tried to reproduce the code, everything worked.

When you run this code, does it work?

$code = 'EUR';
$cnb = new \CnbApi\CnbApi();
$a = $cnb->findRateByCode($code);
print_r($a);

@webdeal
Copy link
Author

webdeal commented Jan 10, 2020

The same problem. Don't affect the result.

@TomasHalasz
Copy link

I have the same error. And I found reason. It depends on OS type. In Linux/OSX is everything OK, but on Windows with XAMPP I got error. So in cnb-api/Cnb.php at line 33 is CSV file exploded to array by PHP_EOL:

    public function getEntity(): ExchangeRate
    {
        $lines = explode(PHP_EOL, $this->content);

and there it is, because PHP_EOL gives (for me) wrong string in Windows OS.
I found on internet function for detecting used EOL, made some changes and solution is here:

$eol = $this->detectEol($this->content);
$lines = explode($eol, $this->content);

and function detectEol() is here:

/**Detects the end-of-line character of a string.
@param string $str      The string to check.
@return string The detected EOL, or default one.
 */
private static function detectEOL($str) {
	static $eols = array(
		'EOL_ACORN'   => "\n\r",  // 0x0A - 0x0D - acorn BBC
		'EOL_WINDOWS' => "\r\n",  // 0x0D - 0x0A - Windows, DOS OS/2
		'EOL_UNIX'    => "\n",    // 0x0A -      - Unix, OSX
		'EOL_TRS80'   => "\r",    // 0x0D -      - Apple ][, TRS80
	);
	$curCount = 0;
	$curEol = '';
	foreach($eols as $eol) {
		if( ($count = substr_count($str, $eol)) > $curCount) {
			$curCount = $count;
			$curEol = $eol;
		}
	}
	return $curEol;
}  // detectEOL

@filipsedivy
Copy link
Owner

@TomasHalasz Thank you for reporting as soon as I get Windows and XAMPP, so I'll try and fix it immediately.

Please wait until the end of this weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants