Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

[WIP] Zend\Filter harmonization (Issue 5119) #5436

Closed
wants to merge 16 commits into from
Closed

[WIP] Zend\Filter harmonization (Issue 5119) #5436

wants to merge 16 commits into from

Conversation

ThaDafinser
Copy link
Contributor

Filters have currently different behaviours, like:

  • return on wrong input value
  • trigger errors
  • throw exceptions

See issue here: #5119 (comment)

this PR should harmoize to one behaviour.

Todo list

  • Zend\Filter\* - except the list bellow
    • Zend\Filter\Callback - not possible to check? as a user defined function is awaited (could be everything)
    • Zend\Filter\Compress - commit missing + travis check
    • Zend\Filter\DateTimeFormatter - commit missing + travis check
    • Zend\Filter\Decompress - commit missing + travis check
    • Zend\Filter\Decrypt - commit missing + travis check
    • Zend\Filter\Encrypt - commit missing + travis check
    • Zend\Filter\Inflector - not possible to check?
  • Zend\Filter\File*
  • Zend\Filter\Word*
  • Zend\I18n\Filter\* - commit missing + travis check

@bakura10
Copy link
Contributor

bakura10 commented Nov 7, 2013

I think most of those changes are BC. I've done already a lot of work to clean filters for ZF3 (#5097), maybe you could directly do PR to my branch so that those changes are also included in the refactor branch? What do you think?

@ThaDafinser
Copy link
Contributor Author

@bakura10 most of the changes are definetly no BC breaks.

The only difference is, that there is now always a check of the filtered values, before filtering and no error is triggered.
If a Filter has been used currently right, there will be no BC break.

For me both ways are okay. ZF2 or ZF3....someone else shall decide 😄

@texdc
Copy link
Contributor

texdc commented Nov 9, 2013

Speaking of the behavior of filters, keep this in mind.

@bakura10
Copy link
Contributor

bakura10 commented Nov 9, 2013

That's an interesting thing @texdc . In fact, hydrator filters are... well... filters. They don't hydrate/extract unwanting filter. In fact, what you would want would be to rename Filter component to Sanitizer component? I'm not against this idea, however I'm wondering if it would be a good thing to do. People are accustomed to using the Zend\Filter component since... many many many years. Changing this now would indeed confuse a lot of people. Again, the tradeoff between correctness, usage and simplicity is not an easy task.

@@ -24,6 +24,10 @@ class Decrypt extends Encrypt
*/
public function filter($value)
{
if(!is_string($value)){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add space after if before open parenthesis and after close parenthesis before open bracket.

@ThaDafinser
Copy link
Contributor Author

@samsonasik coding standards should be fine now. (i hope i didn't missed a spot...is there also a automatically fixer?)
@weierophinney the phunit.xml which is reverted

About the notes for the "null" check. It's the same behaviour....null is not a scalar, so it return itself (which is null)

/* original */
if (null === $value) {
    return null;
}
if (!is_scalar($value)) {
    return $value;
}

/* new */
//the same, if the value is null -> it will return null...
if (!is_scalar($value)) {
    return $value;
}

_Missing_
foreach / data provider for unittests....don't know when i have time....:-/

@ThaDafinser
Copy link
Contributor Author

@ThaDafinser
Copy link
Contributor Author

In my second last commit, i fixed the call in invoke.

I don't understand why null have to be passed, but i let now pass null again in my last commit.

namespace ZendTest\Filter;

use Zend\Filter\Decompress as DecompressFilter;

/**
 * @group      Zend_Filter
 */
class DecompressTest extends \PHPUnit_Framework_TestCase
    public function testCompressToFile()
    {
        $filter   = new DecompressFilter('bz2');
        $archive = __DIR__ . '/../_files/compressed.bz2';
        $filter->setArchive($archive);

        $content = $filter->compress('compress me');
        $this->assertTrue($content);

        $filter2  = new DecompressFilter('bz2');
        $content2 = $filter2($archive);
        $this->assertEquals('compress me', $content2);

        $filter3 = new DecompressFilter('bz2');
        $filter3->setArchive($archive);
        $content3 = $filter3(null);
        $this->assertEquals('compress me', $content3);
    }

@ThaDafinser
Copy link
Contributor Author

@weierophinney everything fine or not?

@weierophinney
Copy link
Member

@ThaDafinser Yes, I think so -- need to review again. (Been busy getting Apigility ready for beta...)

@dstockto
Copy link

dstockto commented Feb 4, 2014

This would be good to have since currently adding filters in apigility causes breakage if the inputs come in as something the filters cannot deal with.

weierophinney added a commit that referenced this pull request Feb 4, 2014
[WIP] Zend\Filter harmonization (Issue 5119)

Conflicts:
	library/Zend/I18n/Filter/NumberFormat.php
weierophinney added a commit that referenced this pull request Feb 4, 2014
- Detailing what the PR accomplishes, as it's a slight change in behavior.
weierophinney added a commit that referenced this pull request Feb 4, 2014
@weierophinney weierophinney added this to the 2.3.0 milestone Feb 4, 2014
@weierophinney weierophinney self-assigned this Feb 4, 2014
@weierophinney
Copy link
Member

Merged to develop for release with 2.3.0.

@ThaDafinser
Copy link
Contributor Author

Yiiiha :-) finally

@dstockto
Copy link

dstockto commented Feb 5, 2014

@ThaDafinser Thanks for doing this, it solves a big problem I was having

weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
…ZendFilter

[WIP] Zend\Filter harmonization (Issue 5119)

Conflicts:
	library/Zend/I18n/Filter/NumberFormat.php
weierophinney added a commit to zendframework/zend-i18n that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
…ZendFilter

[WIP] Zend\Filter harmonization (Issue 5119)

Conflicts:
	library/Zend/I18n/Filter/NumberFormat.php
weierophinney added a commit to zendframework/zend-filter that referenced this pull request May 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants