idea - Zend_Encoder

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

idea - Zend_Encoder

OnyxRaven

I've been doing some work with some of the symmetric Filters - especially
encryption and urlencoding.  What I've come up with is a more 'formal' class
which encompasses and encoder and a decoder.  

The idea is that the same Zend_Encoder based class should be just an
identity to the value passed in.

(given scalar $x, $params to Crypt;)
$enc = new Zend_Encoder_Crypt($params);
$y1 = $enc->encode($x);
$y2 = $enc->decode($y1);
assert($x === $y);

An Encoder could easily be just a composition of Filter objects.

Encoder chaining would run encode() in the order specified in the chain, but
decode() would run in reverse order.

$enc->addEncoder(Zend_Encoder_Base64)
$enc->addEncoder(Zend_Encoder_UrlEncode);
$enc->encode(); // runs Base64->encode(); UrlEncode->encode();
$enc->decode(); // runs UrlEncode->decode(); Base64->decode();

Is this a valuable class?  If so, I'll happily put together the proposal and
start up some basic implementations.
--
View this message in context: http://n4.nabble.com/idea-Zend-Encoder-tp1749646p1749646.html
Sent from the Zend Framework mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: idea - Zend_Encoder

Hector Virgen
This sounds like a really good idea! But I'm not too sure about the namespace "Encode". Do you think there might be more opportunities for two-way transformation besides just encoding? I'm thinking gzip/deflate, encrypt/decrypt, etc.

--
Hector


On Fri, Apr 2, 2010 at 2:17 PM, OnyxRaven <[hidden email]> wrote:

I've been doing some work with some of the symmetric Filters - especially
encryption and urlencoding.  What I've come up with is a more 'formal' class
which encompasses and encoder and a decoder.

The idea is that the same Zend_Encoder based class should be just an
identity to the value passed in.

(given scalar $x, $params to Crypt;)
$enc = new Zend_Encoder_Crypt($params);
$y1 = $enc->encode($x);
$y2 = $enc->decode($y1);
assert($x === $y);

An Encoder could easily be just a composition of Filter objects.

Encoder chaining would run encode() in the order specified in the chain, but
decode() would run in reverse order.

$enc->addEncoder(Zend_Encoder_Base64)
$enc->addEncoder(Zend_Encoder_UrlEncode);
$enc->encode(); // runs Base64->encode(); UrlEncode->encode();
$enc->decode(); // runs UrlEncode->decode(); Base64->decode();

Is this a valuable class?  If so, I'll happily put together the proposal and
start up some basic implementations.
--
View this message in context: http://n4.nabble.com/idea-Zend-Encoder-tp1749646p1749646.html
Sent from the Zend Framework mailing list archive at Nabble.com.

--
Hector Virgen
Reply | Threaded
Open this post in threaded view
|

Re: idea - Zend_Encoder

OnyxRaven
Yeah, I tried to come up with something else - Codec was one - but really, gzip, crypt, etc are special cases of encoding.  I don't know, if anyone can come up with a good alternative I'm open to ideas there.  

On Mon, Apr 5, 2010 at 5:27 PM, Hector Virgen <[hidden email]> wrote:
This sounds like a really good idea! But I'm not too sure about the namespace "Encode". Do you think there might be more opportunities for two-way transformation besides just encoding? I'm thinking gzip/deflate, encrypt/decrypt, etc.

--
Hector


On Fri, Apr 2, 2010 at 2:17 PM, OnyxRaven <[hidden email]> wrote:

I've been doing some work with some of the symmetric Filters - especially
encryption and urlencoding.  What I've come up with is a more 'formal' class
which encompasses and encoder and a decoder.

The idea is that the same Zend_Encoder based class should be just an
identity to the value passed in.

(given scalar $x, $params to Crypt;)
$enc = new Zend_Encoder_Crypt($params);
$y1 = $enc->encode($x);
$y2 = $enc->decode($y1);
assert($x === $y);

An Encoder could easily be just a composition of Filter objects.

Encoder chaining would run encode() in the order specified in the chain, but
decode() would run in reverse order.

$enc->addEncoder(Zend_Encoder_Base64)
$enc->addEncoder(Zend_Encoder_UrlEncode);
$enc->encode(); // runs Base64->encode(); UrlEncode->encode();
$enc->decode(); // runs UrlEncode->decode(); Base64->decode();

Is this a valuable class?  If so, I'll happily put together the proposal and
start up some basic implementations.
--
View this message in context: http://n4.nabble.com/idea-Zend-Encoder-tp1749646p1749646.html
Sent from the Zend Framework mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: idea - Zend_Encoder

weierophinney
Administrator
In reply to this post by Hector Virgen
-- Hector Virgen <[hidden email]> wrote
(on Monday, 05 April 2010, 04:27 PM -0700):
> This sounds like a really good idea! But I'm not too sure about the namespace
> "Encode". Do you think there might be more opportunities for two-way
> transformation besides just encoding? I'm thinking gzip/deflate, encrypt/
> decrypt, etc.

Please don't forget that We _do_ already have Filters for encryption and
compression, as well as Zend_Crypt; let's not re-invent the wheels we've
already built. :)

Also, based on the description here, I would argue that the primary
functionality already exists and can be accomplished in Zend_Filter. The
only areas I see as being potenentially new would be URL and Base64
encoding - and these could be added to Zend_Filter easily.

As an example:

    // Encryption
    $filter = new Zend_Filter();
    $filter->addFilter(new Zend_Filter_Encrypt(array('adapter' => 'base64')))
           ->addFilter(new Zend_Filter_Encrypt(array('adapter' => 'urlencode')));
    $encrypted = $filter->filter($someValue);

    // Decryption
    $filter = new Zend_Filter();
    $filter->addFilter(new Zend_Filter_Decrypt(array('adapter' => 'urlencode')))
           ->addFilter(new Zend_Filter_Decrypt(array('adapter' => 'base64')));
    $decrypted = $filter->filter($encrypted);

The API is slightly different than what is presented here, but the
results would be the same.

> On Fri, Apr 2, 2010 at 2:17 PM, OnyxRaven <[hidden email]> wrote:
>
>
>     I've been doing some work with some of the symmetric Filters - especially
>     encryption and urlencoding.  What I've come up with is a more 'formal'
>     class
>     which encompasses and encoder and a decoder.
>
>     The idea is that the same Zend_Encoder based class should be just an
>     identity to the value passed in.
>
>     (given scalar $x, $params to Crypt;)
>     $enc = new Zend_Encoder_Crypt($params);
>     $y1 = $enc->encode($x);
>     $y2 = $enc->decode($y1);
>     assert($x === $y);
>
>     An Encoder could easily be just a composition of Filter objects.
>
>     Encoder chaining would run encode() in the order specified in the chain,
>     but
>     decode() would run in reverse order.
>
>     $enc->addEncoder(Zend_Encoder_Base64)
>     $enc->addEncoder(Zend_Encoder_UrlEncode);
>     $enc->encode(); // runs Base64->encode(); UrlEncode->encode();
>     $enc->decode(); // runs UrlEncode->decode(); Base64->decode();
>
>     Is this a valuable class?  If so, I'll happily put together the proposal
>     and
>     start up some basic implementations.
>     --
>     View this message in context: http://n4.nabble.com/
>     idea-Zend-Encoder-tp1749646p1749646.html
>     Sent from the Zend Framework mailing list archive at Nabble.com.
>
>

--
Matthew Weier O'Phinney
Project Lead            | [hidden email]
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
Reply | Threaded
Open this post in threaded view
|

Re: idea - Zend_Encoder

OnyxRaven
Yeah, I know Filters do already accomplish most of this - the idea here was to 'formalize' the symmetric operation of two filters like urlencode/urldecode, etc.  An Encode could easily be composed of Filter objects (in fact I have a Zend_Encoder_Filter class that takes in the encode and decode Filter objects), and probably most of the base Encoders would just be that.

Like I said, just an idea.
Reply | Threaded
Open this post in threaded view
|

Re: idea - Zend_Encoder

A.J. Brown-3
I really like your implementation, but I'm not sure it belongs in the
framework itself.  As Matthew pointed out, it doesn't accomplish
anything that can't already be done.  It's definitely very convenient,
though.


On Tue, Apr 6, 2010 at 2:25 PM, OnyxRaven <[hidden email]> wrote:

>
> Yeah, I know Filters do already accomplish most of this - the idea here was
> to 'formalize' the symmetric operation of two filters like
> urlencode/urldecode, etc.  An Encode could easily be composed of Filter
> objects (in fact I have a Zend_Encoder_Filter class that takes in the encode
> and decode Filter objects), and probably most of the base Encoders would
> just be that.
>
> Like I said, just an idea.
> --
> View this message in context: http://n4.nabble.com/idea-Zend-Encoder-tp1751553p1753267.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>



--
A.J. Brown
Software Engineer, ZCE
blog : http://ajbrown.org
talk  : (937) 540-0099
chat : IntypicaAJ
Reply | Threaded
Open this post in threaded view
|

Re: idea - Zend_Encoder

OnyxRaven
Thanks.  I will probably just make a blog post and post my code, and if folks want to use it they can.  Looking through the Zend_Filter_Encrypt/Decrypt - it could do the same thing (though, it still feels odd to use it for character encoding type things).

On Tue, Apr 6, 2010 at 1:31 PM, A.J. Brown <[hidden email]> wrote:
I really like your implementation, but I'm not sure it belongs in the
framework itself.  As Matthew pointed out, it doesn't accomplish
anything that can't already be done.  It's definitely very convenient,
though.


On Tue, Apr 6, 2010 at 2:25 PM, OnyxRaven <[hidden email]> wrote:
>
> Yeah, I know Filters do already accomplish most of this - the idea here was
> to 'formalize' the symmetric operation of two filters like
> urlencode/urldecode, etc.  An Encode could easily be composed of Filter
> objects (in fact I have a Zend_Encoder_Filter class that takes in the encode
> and decode Filter objects), and probably most of the base Encoders would
> just be that.
>
> Like I said, just an idea.
> --
> View this message in context: http://n4.nabble.com/idea-Zend-Encoder-tp1751553p1753267.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>



--
A.J. Brown
Software Engineer, ZCE
blog : http://ajbrown.org
talk  : (937) 540-0099
chat : IntypicaAJ