Re: [fw-general] How are you using Zend_Filter_Input?

2007-10-26 Thread Mathew Byrne
What I've been doing is creating a subclass of Zend_Filter_Input that  
adds the ability to automatically add filters and inputs from class  
members and automatically sets up paths for filters/validators. So  
the following is possible:


class Input_Form extends Jb_Filter_Input
{
$_filters = array ( ... );

$_validators = array ( ... )';
}

This simplifies code a lot, and is especially useful if you have a  
lot of forms requiring validation.


If you're expecting one of your incoming variables to be an array  
(say for instance the 'phone[]' variable you described) then  
Zend_Filter_Input will automatically apply Filters and Validators to  
each element of that array separately (i.e. it wont actually pass an  
array to your filters and validators). So in your case you need to  
name each of the fields separately and use the fields Meta-command to  
specify which fields should be passed to your validator. That way,  
your validator will recieve an array containing the fields you  
specified. e.g.:


class Input_Form extends Jb_Filter_Input
{
$_filters = array ( ... );

$_validators = array (
'phone' => array (
'fields' => array ('phone-1', 'phone-2', 'phone-3', 
'phone-4'),
'PhoneValidator'
)
);
}

Obviously you'd need to implement the phone validator first. SpotSec  
had a great example article regarding validating multiple fields with  
a single rule:


http://www.spotsec.com/blogs/archive/2007/8/18/zend_validate- 
stringequals-implementation?Itemid=125


Cheers,

Mathew Byrne

On 27/10/2007, at 12:09 PM, Ryan Lange wrote:

I'm curious how others are using the current (as of ZF 1.0.2)  
implementation of Zend_Filter_Input. I'm trying to use it for a  
contact form, but everything I've typed out seems clumsy and overly  
complicated. (Maybe that's just the cost of flexibility, though,  
because even the "less basic" examples in the documentation look  
extremely convoluted.)


For instance, I have one hidden field (using CSS) on the form  
that's used in spam detection. This field needs to remain  
completely untouched by the filters I set, but in order to do that,  
I have to explicitly assign the filters to /every/ other field (14  
of them) rather than use the "*" wildcard.


Also, I have no clue how to handle multiple fields of the same  
name. This same contact form allows the user to provide their phone  
number if they wish. This consists of 4 fields that represent parts  
of a U.S. telephone number, all with the name "phone[]": ([___])  
[___]-[] ext. [_]


If any one can provide any insight or examples of their own of  
their, that'd be great.



Thanks,
Ryan Lange


[fw-general] How are you using Zend_Filter_Input?

2007-10-26 Thread Ryan Lange
I'm curious how others are using the current (as of ZF 1.0.2) 
implementation of Zend_Filter_Input. I'm trying to use it for a contact 
form, but everything I've typed out seems clumsy and overly complicated. 
(Maybe that's just the cost of flexibility, though, because even the 
"less basic" examples in the documentation look extremely convoluted.)


For instance, I have one hidden field (using CSS) on the form that's 
used in spam detection. This field needs to remain completely untouched 
by the filters I set, but in order to do that, I have to explicitly 
assign the filters to /every/ other field (14 of them) rather than use 
the "*" wildcard.


Also, I have no clue how to handle multiple fields of the same name. 
This same contact form allows the user to provide their phone number if 
they wish. This consists of 4 fields that represent parts of a U.S. 
telephone number, all with the name "phone[]": ([___]) [___]-[] ext. 
[_]


If any one can provide any insight or examples of their own of their, 
that'd be great.



Thanks,
Ryan Lange


Re: [fw-general] [fw-core] Utility functions: Calculating binary string length

2007-10-26 Thread dandean

I disagree - the point in grouping functions by static classes instead of
plain old functions would be to avoid the annoying outcome of php functions
in the past: no standard naming implementation.

Example: what's clearer and more predictable:

strlen()
String::length()

str_split();
String::split()

Other examples of poor function naming conventions which would not be
repeated in static classes of method types:

html_ entity_ decode()
htmlentities()

See what I mean?


Bryce Lohr-2 wrote:
> 
> I agree that a plain old function would be the best solution in this 
> situation. I think classes full of static methods provide no real value, 
> from an object-oriented design perspective. All you get is a bunch of 
> extra typing.
> 
> It's true the framework currently has no place for normal function 
> libraries, but, personally, I think it would be better to make one than 
> to start introducing such static classes. The core contributors to this 
> framework are really smart people; they should be more than capable of 
> keeping these kinds of function libraries from getting out of control.
> 
> Just my $0.02,
> Bryce Lohr
> 
> 
> Jack Sleight wrote:
>>
>> Shahar Evron wrote:
>>>
>>> True, a function is a natural solution - but I think most core people
>>> would consider adding functions to ZF to be against all design concepts.
>>> There is a middle path of course - utility classes grouping static
>>> methods.
>>>   
>> Yeah, I guess that in order to fit in with the framework design static 
>> classes would make the most sense. I didn't suggest it because I've 
>> read articles by people that say you shouldn't use classes for simply 
>> grouping static methods; but to be honest I don't really see why it 
>> matters so much, especially if it solves a common problem.
>>> class Zend_Utility_String {
>>> /**
>>>  * Calculate the byte-length of a string
>>>  *
>>>  * @param  string  $string  * @return integer String length
>>>  */
>>> static public function ByteLength($string);
>>>
>>> /**
>>>  * Split a string into words, grouping quoted phrases together
>>>  *
>>>  * @param  string  $string  * @param  string  $groupBy   
>>> * @return array   Tokenized words
>>>  */
>>> static public function tokenize($string, $groupBy = '"');
>>>
>>> static public function ...
>>> }
>>>
>>> class Zend_Utility_Math
>>> {
>>> static public function ...
>>> }
>>>
>>> // .. and so on - // I'd even rename classes like Zend_Debug to 
>>> Zend_Utility_Debug...
>>>
>>>   
>> Yeah, I think something like this would be very beneficial, and I'm 
>> sure the need for utility methods will come up again. In fact there 
>> are probably quite a few static methods in the framework already that 
>> could be refactored into such classes, to make them easily available.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Utility-functions%3A-Calculating-binary-string-length-tf4698527s16154.html#a13438061
Sent from the Zend Framework mailing list archive at Nabble.com.



[fw-general] Re: [fw-core] Utility functions: Calculating binary string length

2007-10-26 Thread Bryce Lohr
I agree that a plain old function would be the best solution in this 
situation. I think classes full of static methods provide no real value, 
from an object-oriented design perspective. All you get is a bunch of 
extra typing.


It's true the framework currently has no place for normal function 
libraries, but, personally, I think it would be better to make one than 
to start introducing such static classes. The core contributors to this 
framework are really smart people; they should be more than capable of 
keeping these kinds of function libraries from getting out of control.


Just my $0.02,
Bryce Lohr


Jack Sleight wrote:


Shahar Evron wrote:


True, a function is a natural solution - but I think most core people
would consider adding functions to ZF to be against all design concepts.
There is a middle path of course - utility classes grouping static
methods.
  
Yeah, I guess that in order to fit in with the framework design static 
classes would make the most sense. I didn't suggest it because I've 
read articles by people that say you shouldn't use classes for simply 
grouping static methods; but to be honest I don't really see why it 
matters so much, especially if it solves a common problem.

class Zend_Utility_String {
/**
 * Calculate the byte-length of a string
 *
 * @param  string  $string  * @return integer String length
 */
static public function ByteLength($string);

/**
 * Split a string into words, grouping quoted phrases together
 *
 * @param  string  $string  * @param  string  $groupBy   
* @return array   Tokenized words

 */
static public function tokenize($string, $groupBy = '"');

static public function ...
}

class Zend_Utility_Math
{
static public function ...
}

// .. and so on - // I'd even rename classes like Zend_Debug to 
Zend_Utility_Debug...


  
Yeah, I think something like this would be very beneficial, and I'm 
sure the need for utility methods will come up again. In fact there 
are probably quite a few static methods in the framework already that 
could be refactored into such classes, to make them easily available.


[fw-general] Re: [fw-core] Utility functions: Calculating binary string length

2007-10-26 Thread Jack Sleight


Shahar Evron wrote:


True, a function is a natural solution - but I think most core people
would consider adding functions to ZF to be against all design concepts.
There is a middle path of course - utility classes grouping static
methods. 

  
Yeah, I guess that in order to fit in with the framework design static 
classes would make the most sense. I didn't suggest it because I've read 
articles by people that say you shouldn't use classes for simply 
grouping static methods; but to be honest I don't really see why it 
matters so much, especially if it solves a common problem.
class Zend_Utility_String 
{

/**
 * Calculate the byte-length of a string
 *
	 * @param  string  $string 
	 * @return integer String length

 */
static public function ByteLength($string);

/**
 * Split a string into words, grouping quoted phrases together
 *
	 * @param  string  $string 
	 * @param  string  $groupBy  
	 * @return array   Tokenized words

 */
static public function tokenize($string, $groupBy = '"');

static public function ...
}

class Zend_Utility_Math
{
static public function ...
}

// .. and so on - 
// I'd even rename classes like Zend_Debug to Zend_Utility_Debug...


  
Yeah, I think something like this would be very beneficial, and I'm sure 
the need for utility methods will come up again. In fact there are 
probably quite a few static methods in the framework already that could 
be refactored into such classes, to make them easily available.

--
Jack


[fw-general] Re: [fw-core] Utility functions: Calculating binary string length

2007-10-26 Thread Shahar Evron
Hi,

On Fri, 2007-10-26 at 18:52 +0100, Jack Sleight wrote:
> This may go against the intended design of the framework in the first 
> place, but in a typical application such a function would just be a 
> standard function, not part of any class. There's no doubt that there 
> are plenty of gaps in the functions that come with PHP, so a problem 
> like this may well crop up again.
> 

True, a function is a natural solution - but I think most core people
would consider adding functions to ZF to be against all design concepts.
There is a middle path of course - utility classes grouping static
methods. 

> Couldn't the framework introduce a standard way of defining these 
> utility functions, which could easily be included by Zend_Loader?

Yes - as static class methods ;)

This of course depends on real need - I currently only have one itch to
scratch - but there might be more similar itches, that might be grouped
into related classes - for example:

class Zend_Utility_String 
{
/**
 * Calculate the byte-length of a string
 *
 * @param  string  $string 
 * @return integer String length
 */
static public function ByteLength($string);

/**
 * Split a string into words, grouping quoted phrases together
 *
 * @param  string  $string 
 * @param  string  $groupBy  
 * @return array   Tokenized words
 */
static public function tokenize($string, $groupBy = '"');

static public function ...
}

class Zend_Utility_Math
{
static public function ...
}

// .. and so on - 
// I'd even rename classes like Zend_Debug to Zend_Utility_Debug...

?>

Of course, this approach depends on actual need - since I don't have
good examples, I can't say there really is a need.

Shahar.


> I've run into the same problem myself when developing a set of my own 
> components that work with/extend ZF. Currently I just have a folder 
> called "functions", at the same level as the "library" folder, which 
> contains a few PHP files with all my additional functions.
> 
> Just a thought.
> 
> Shahar Evron wrote:
> > Hi all,
> >
> > I am working on one of the Http_Client bugs, ZF-2098, which describes a
> > problem the Http_Client has when sending multi-byte encoded (eg. UTF8
> > Chinese) text in the request body when mbstring is loaded and overloads
> > the strlen() function. This happens because I've been using strlen() to
> > calculate the body size (in bytes - not in characters). 
> >
> > This works in most cases, but when mbstring overloads strlen with
> > mb_strlen - what you get is the string length in characters and not in
> > bytes. 
> >
> > Brian DeShong already proposed a patch fixing the problem, but I've
> > found that there are several Zend_Http classes that suffer from the same
> > problem. I'm sure that other ZF classes, as well as users, who need a
> > transparent way to calculate string length in bytes, irregardless of
> > loaded extensions or PHP version (no idea what PHP 6 / 5.3 would cause
> > in this case). 
> >
> > So, is there any component of the framework where you would see a
> > static ::strByteLength($string) method? I was going to implement one in
> > Zend_Http_Client - but it's not really Zend_Http_Client specific. 
> >
> > Suggestions welcome ;)
> >
> > Shahar.
> >
> >   



signature.asc
Description: This is a digitally signed message part


[fw-general] Re: [fw-core] Utility functions: Calculating binary string length

2007-10-26 Thread Jack Sleight
This may go against the intended design of the framework in the first 
place, but in a typical application such a function would just be a 
standard function, not part of any class. There's no doubt that there 
are plenty of gaps in the functions that come with PHP, so a problem 
like this may well crop up again.


Couldn't the framework introduce a standard way of defining these 
utility functions, which could easily be included by Zend_Loader?


I've run into the same problem myself when developing a set of my own 
components that work with/extend ZF. Currently I just have a folder 
called "functions", at the same level as the "library" folder, which 
contains a few PHP files with all my additional functions.


Just a thought.

Shahar Evron wrote:

Hi all,

I am working on one of the Http_Client bugs, ZF-2098, which describes a
problem the Http_Client has when sending multi-byte encoded (eg. UTF8
Chinese) text in the request body when mbstring is loaded and overloads
the strlen() function. This happens because I've been using strlen() to
calculate the body size (in bytes - not in characters). 


This works in most cases, but when mbstring overloads strlen with
mb_strlen - what you get is the string length in characters and not in
bytes. 


Brian DeShong already proposed a patch fixing the problem, but I've
found that there are several Zend_Http classes that suffer from the same
problem. I'm sure that other ZF classes, as well as users, who need a
transparent way to calculate string length in bytes, irregardless of
loaded extensions or PHP version (no idea what PHP 6 / 5.3 would cause
in this case). 


So, is there any component of the framework where you would see a
static ::strByteLength($string) method? I was going to implement one in
Zend_Http_Client - but it's not really Zend_Http_Client specific. 


Suggestions welcome ;)

Shahar.

  


--
Jack


[fw-general] CGI server, htaccess problem. cannot do rewrite rule to use ZF

2007-10-26 Thread Julian Davchev

Hi, using php 5.2.1 running as php5
I have following .htaccess file

AddType application/x-httpd-php5 .php

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php

problem is when I try to run

example.com

I get
The requested URL /example.com/www/root/index.php was not found on this
server.


And I see it is there..Was thinking this is perhaps of CGI or what..as I
have never had this problem before.
If I change index.php to something else... error messages changes so I
guess rewrite engine is actually working.


Any idea someone?


[fw-general] Re: [fw-core] Utility functions: Calculating binary string length

2007-10-26 Thread Shahar Evron
Hi,

Well, that's one solution, but IMHO it seems a bit artificial - I mean,
we're not really filtering anything, as in taking input and manipulating
it.

Shahar.

On Fri, 2007-10-26 at 13:08 -0400, Darby Felton wrote:
> Hi Shahar,
> 
> This operation may fit nicely as:
> 
> class Zend_Filter_StringByteLength implements Zend_Filter_Interface
> {
> /**
>  * Returns the length in bytes of the string $value
>  *
>  * @param  string $value
>  * @throws Zend_Filter_Exception If determining byte length is
> impossible
>  * @return integer
>  */
> public function filter($value)
> {
> /**
>  * @todo Implementation
>  */
> }
> }
> 
> or something similar?
> 
> Best regards,
> Darby
> 
> Shahar Evron wrote:
> > Hi all,
> > 
> > I am working on one of the Http_Client bugs, ZF-2098, which describes a
> > problem the Http_Client has when sending multi-byte encoded (eg. UTF8
> > Chinese) text in the request body when mbstring is loaded and overloads
> > the strlen() function. This happens because I've been using strlen() to
> > calculate the body size (in bytes - not in characters). 
> > 
> > This works in most cases, but when mbstring overloads strlen with
> > mb_strlen - what you get is the string length in characters and not in
> > bytes. 
> > 
> > Brian DeShong already proposed a patch fixing the problem, but I've
> > found that there are several Zend_Http classes that suffer from the same
> > problem. I'm sure that other ZF classes, as well as users, who need a
> > transparent way to calculate string length in bytes, irregardless of
> > loaded extensions or PHP version (no idea what PHP 6 / 5.3 would cause
> > in this case). 
> > 
> > So, is there any component of the framework where you would see a
> > static ::strByteLength($string) method? I was going to implement one in
> > Zend_Http_Client - but it's not really Zend_Http_Client specific. 
> > 
> > Suggestions welcome ;)
> > 
> > Shahar.
> > 
-- 
Shahar Evron [EMAIL PROTECTED]
Technical Consultant
Zend Technologies

Mobile: +972 54 30 99 446
Office: +972  3 75 39 500 ext. 9546



signature.asc
Description: This is a digitally signed message part


[fw-general] Re: [fw-core] Utility functions: Calculating binary string length

2007-10-26 Thread Darby Felton
Hi Shahar,

This operation may fit nicely as:

class Zend_Filter_StringByteLength implements Zend_Filter_Interface
{
/**
 * Returns the length in bytes of the string $value
 *
 * @param  string $value
 * @throws Zend_Filter_Exception If determining byte length is
impossible
 * @return integer
 */
public function filter($value)
{
/**
 * @todo Implementation
 */
}
}

or something similar?

Best regards,
Darby

Shahar Evron wrote:
> Hi all,
> 
> I am working on one of the Http_Client bugs, ZF-2098, which describes a
> problem the Http_Client has when sending multi-byte encoded (eg. UTF8
> Chinese) text in the request body when mbstring is loaded and overloads
> the strlen() function. This happens because I've been using strlen() to
> calculate the body size (in bytes - not in characters). 
> 
> This works in most cases, but when mbstring overloads strlen with
> mb_strlen - what you get is the string length in characters and not in
> bytes. 
> 
> Brian DeShong already proposed a patch fixing the problem, but I've
> found that there are several Zend_Http classes that suffer from the same
> problem. I'm sure that other ZF classes, as well as users, who need a
> transparent way to calculate string length in bytes, irregardless of
> loaded extensions or PHP version (no idea what PHP 6 / 5.3 would cause
> in this case). 
> 
> So, is there any component of the framework where you would see a
> static ::strByteLength($string) method? I was going to implement one in
> Zend_Http_Client - but it's not really Zend_Http_Client specific. 
> 
> Suggestions welcome ;)
> 
> Shahar.
> 


[fw-general] Utility functions: Calculating binary string length

2007-10-26 Thread Shahar Evron
Hi all,

I am working on one of the Http_Client bugs, ZF-2098, which describes a
problem the Http_Client has when sending multi-byte encoded (eg. UTF8
Chinese) text in the request body when mbstring is loaded and overloads
the strlen() function. This happens because I've been using strlen() to
calculate the body size (in bytes - not in characters). 

This works in most cases, but when mbstring overloads strlen with
mb_strlen - what you get is the string length in characters and not in
bytes. 

Brian DeShong already proposed a patch fixing the problem, but I've
found that there are several Zend_Http classes that suffer from the same
problem. I'm sure that other ZF classes, as well as users, who need a
transparent way to calculate string length in bytes, irregardless of
loaded extensions or PHP version (no idea what PHP 6 / 5.3 would cause
in this case). 

So, is there any component of the framework where you would see a
static ::strByteLength($string) method? I was going to implement one in
Zend_Http_Client - but it's not really Zend_Http_Client specific. 

Suggestions welcome ;)

Shahar.



signature.asc
Description: This is a digitally signed message part


[fw-general] Zend_Session_Namespace - Optional argument to create namespace in deeper nodes

2007-10-26 Thread Shekar C Reddy
Currently, the namespace component creates namespaces only at the root of
the session:

$user = new Zend_Session_Namespace( 'user' );

=> $_SESSION['user'] = array()


What if I want to store data deeper in the auth node to just group it and
reduce clutter (aka modules) and to be able to count the number of
items/namespaces in a node:

$_SESSION['auth']['user']['id'] = 1;
([node][namespace][key] = value)


In the above case, it would be much more powerful to be able to create the
namespace under the 'auth' node so we could configure the keys in the 'user'
namespace. We could introduce an optional 'node' argument to the
Zend_Session_Namespace::__construct(), like so:

 $user = new Zend_Session_Namespace( 'user', 'auth' );
[create the user namespace under auth node - auth node created automatically
if it does not exist in session]

We can even go as deeper as we could by specifying an intelligent node-path:

 $user = new Zend_Session_Namespace( 'user', 'auth:node2:node3' );
(create the user namespace under $_SESSION[auth][node2][node3] - all created
automatically if they do not exist in session)


I guess the above feature adds more muscle to the namespace component and
enables us to use it more powerfully.


http://framework.zend.com/issues/browse/ZF-2103


Thoughts...?


Re: [fw-general] Can't get ErrorHandler plugin to work as a 404 handler

2007-10-26 Thread JRy

I had a hunch that it may have just been the version of PHP that I was using
(5.2.1) so I upgraded to 5.2.4 and now everything is working fine. Very
strange, but at least everything is working now. :)
-- 
View this message in context: 
http://www.nabble.com/Can%27t-get-ErrorHandler-plugin-to-work-as-a-404-handler-tf4694950s16154.html#a13429858
Sent from the Zend Framework mailing list archive at Nabble.com.



[fw-general] Italian and Spanish forums

2007-10-26 Thread Andrea Mucci
Hi guys

I have opened the First Italian Forum for ZendFramework.

 The link is www.zfforum.it  

The spanish version, www.zfforum.es   is
under construction, but on 2 work days is opened.

Is possible to publicize this forums?

Is not commercial, 

Thanks