Skip to content

Commit

Permalink
update ConvertMbstringEncoding
Browse files Browse the repository at this point in the history
  • Loading branch information
suin committed Dec 5, 2012
1 parent 4e02421 commit 868c3f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Goodby\CSV\Import\Standard\StreamFilter;

use php_user_filter;
use RuntimeException;

class ConvertMbstringEncoding extends php_user_filter
{
Expand All @@ -11,6 +12,11 @@ class ConvertMbstringEncoding extends php_user_filter
*/
const FILTER_NAMESPACE = 'convert.mbstring.encoding.';

/**
* @var bool
*/
private $hasBeenRegistered = false;

/**
* @var string
*/
Expand All @@ -22,13 +28,25 @@ class ConvertMbstringEncoding extends php_user_filter
private $toCharset;

/**
* Return filter name
* @return string
*/
public static function getFilterName()
{
return self::FILTER_NAMESPACE.'*';
}

/**
* Register this class as a stream filter
* @throws \RuntimeException
*/
public static function register()
{
if ( stream_filter_register(self::getFilterName(), __CLASS__) === false ) {
throw new RuntimeException('Failed to register stream filter: '.self::getFilterName());
}
}

/**
* @return bool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,15 @@ public function test_when_invalid_parameter_given_it_returns_false()
$filter->filtername = $filterString;
$this->assertFalse($filter->onCreate());
}

public function test_register_filter()
{
ConvertMbstringEncoding::register();
$filterName = ConvertMbstringEncoding::getFilterName();
$registeredFilters = stream_get_filters();
$this->assertTrue(in_array($filterName, $registeredFilters));

$this->setExpectedException('RuntimeException', "Failed to register stream filter: ".$filterName);
ConvertMbstringEncoding::register();
}
}

0 comments on commit 868c3f8

Please sign in to comment.