PVValidator is a dynamically extendable class used to validate inputs.
The class can be used to check for a variety of inputs to validate data from mime types to correct syntax for a URL. The class is also extendable to add more validation rules.
Examples:
//Check if a file is an integer
if(PVValidator::check('integer', '3.4')) {
echo 'I am an integer';
}
if(PVValidator::check('url', 'http://www.google.com')) {
echo 'I am a valid url';
}
//Add custom validation rule
PVValidator::addRule('is_currency', array('function' => function($number) {
return preg_match("/^-?[0-9]+(?:\.[0-9]{1,2})?$/", $number);
}));
//Check against custom rule
if(PVValidator::check(‘is_currecny’, '$10.00')) {
echo 'I am currency';
}
package |
util |
---|
__callStatic(string $method, mixed $args = array()) : mixed
access |
public |
---|
string
The key/name assigned to the method when added
mixed
Arguements to pass to the annoymous function. The function is called using call_user_func_array.
mixed
$value The value returned is the value the stored function returns
_applyFilter(string $class, string $method, mixed $data, array $options = array()) : mixed
access |
protected |
---|
string
The name of the class the filter is in
string
The method the filter is in
mixed
The data that is being passed to the filter
array
options to be passed to the filter. Passed options we be passed to the function. -'default_return' mixed: If no filter is return, the data passed in by default will be return. Can be overriden -'event' string: An event to associate with the filter. Default is null
mixed
$data The data the function returns
_callAdapter(string $class, string $method) : mixed
access |
protected |
---|
string
The name of the class the adapter is in
string
THe name of the method the class is being called from.
mixed
$value A value that the adapter returns
_hasAdapter( $class, string $method) : \boolea
access |
protected |
---|
string
The associated method
\boolea
$hasAdapter Returns true if it has an adapter or false if it doesn not
_hasFilter(string $class, string $method)
string
The class the filter is in
string
The method of the class that the filter is in
_invokeMethod(string $class, string $method, array $args) : mixed
access |
protected |
---|
string
The name of the class to be called
string
The name of the method in the class to be called
array
An array of arguements. Arguements have to be embedded in an array to be called.
mixed
$data Data returned by the function called
_invokeStaticMethod(string $class, string $method, array $args) : mixed
access |
protected |
---|
string
The name of the class to be called
string
The name of the method in the class to be called
array
An array of arguements. Arguements have to be embedded in an array to be called.
mixed
$data Data returned by the function called
_logAdapter(array $data) : void
access |
private |
---|
array
The data in the adapter
_logFilter(array $data) : void
access |
private |
---|
array
The data in the filter
_logObserver(array $data) : void
access |
private |
---|
array
The data in the observer
_notify(string $event) : void
access |
protected |
---|
string
The name of the even that occured that will trigger notifies
_prepareLogData(array $data) : string
access |
private |
---|
array
string
$message JSON encode message of information about the data
addAdapter(string $trigger_class, string $trigger_method, string $call_class, array $options = array()) : void
access |
public |
---|---|
todo |
add ability to adapt singleton class |
string
The class that contains the function the adapter will respond too
string
The method called that will have the adapter to be called.
string
The new class to be called that has the same method name
array
An array of options that be called -'object' string : Assumes that default method in the class to be called is static. If called object needs to be instantiated, change to object to 'instance' and one will be created before the adapter calls the function -'call_method' string: By default the method to be called to override the current one should be the same name. But this can be ovveridden to call a different method. -'type' string: The type of method being called. Default is class_method but if the method is a closure, set the type to be 'closure' and make the $trigger_method the closure
addClassAdapter(mixed $trigger_class, string $call_class, array $options = array()) : void
access |
public |
---|---|
todo |
Add ability to use singleton classes |
mixed
This can either be the name of the class or an object whose methods will be adapted to another class. The class should be included or be autoloaded by this point.
string
The call class is the classes methods that will be called in place of the methods in the trigger_class. These class does not have to be included as this point.
array
Options that be used to further distinguish the behavior of the adapters added -'object' string: Determines if the object being adapted to is static or an instance.Default is static -'call_class' string: The name of the class that the methods will be adapted too. -'class' string: The name of the whose methods will be adapted to another class
addFilter(string $class, string $method, string $filter_class, string $filter_method, array $options = array()) : void
access |
public |
---|
string
The name of the class the filter is going in
string
The name of the method the filter is in
string
The class that the filter resides in.
string
The method in the class that the parameters will be passed too.
array
Options that can be set for further modifying the filter. -'object' string: If the method being called is static, static should be inserted. If its in an instance, 'instance' should be set. Default is set to static. -'event' string: Associate this filter with an event. -'type' string: The type of function being called. Default is class_method but if the function is a closure, set the type to be 'closure' and make the $filter_method the closure
addMethod(string $method, \function $closure) : void
access |
public |
---|
string
The key/value that will be used to call the function
\function
The anonymous function/closure to be added
addObserver(string $event, string $class, string $method, array $options = array()) : void
access |
public |
---|
string
The name of the event that will cause a certain class and method to fire
string
The name of the class that contains the function that will be fired for this event
string
The name of the method that will be fired when the event occurs
array
Options to further the define the firing of an event -'object' string : If the method being called is static, should be set to static. Else set to instance -'class' stinrg : The name of the class to be called. Default is the class that is passed in. -'method' string: The name of the method to be called. Default is the method that is passed in. -'type' string: The type of function being called. Default is class_method but if the function is a closure, set the type to be 'closure' and make the $method the closure
addRule(string $rule, array $options = array()) : void
access |
public |
---|
string
The name of the rule
array
Options that define the rule -'type' string: The type of validation to perform. There are currently 4 supported types.
addToCollection(mixed $data) : void
access |
public |
---|
mixed
Any data type( Object, Array, int, etc) to add to the public data collection
addToCollectionWithName(string $name, mixed $data) : void
access |
public |
---|---|
todo |
check the relevance of get and set |
string
The key/index to assign the value to
mixed
Data to be stored in the collection
check(string $rule) : mixed
access |
public |
---|
string
The name of the rule to check against
mixed
$validate Validates is generally a boolean and returns true or false
checkFileMimeType(string $file, string $mime_text, array $options = array()) : boolean
access |
public |
---|
string
The path to the file to be be checked
string
Some form of text that describes the mime type.
array
Options that can customize how the mime type is to be found. -'search_method' string: The search method can either be found using strpos or preg_match. The default is STRING_POSITION as the method, change to PREG_MATCH to use PREG_MATCH -'magic_file' string: If you have phpinfo installed, it will be used for finding the mime_type. The default magic file is not set and will use the default in the PVFileManager.
boolean
$found Returns true if the mime type was match, otherwise false
clearFilters(string $class, string $method) : void
access |
public |
---|
string
The class the filter is in
string
The method of the class that the filter is in
clearObservers(string $event) : void
access |
public |
---|
string
The event to remove all the observers from
get(string $index) : mixed
access |
public |
---|
string
The index to retrieve a value from
mixed
$data The data that was stored at that index
getInstance() : object
access |
public |
---|---|
object
$instance Returns the instance of a class.
getIterator() : \PVIterator
init(array $config = array()) : void
access |
public |
---|---|
todo |
consider extending the config optiont actually have it doing something |
array
The configuration for init the class
isActiveUrl(string $url) : boolean
todo |
rewrite with PVCommunicator |
---|
string
The url to check if active
boolean
isAiffFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a aiff audio mime type
boolean
$valid Returns true if the value is a aiff audio mime type, otherwise false
isAscFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a gtar file mime type
boolean
$valid Returns true if the value is a gtar file mime type, otherwise false
isAsfFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a asf video mime type
boolean
$valid Returns true if the value is a asf video mime type, otherwise false
isAudioFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is an audio mime type
boolean
$valid Returns true if the value is an audio mime type, otherwise false
isAviFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a avi video mime type
boolean
$valid Returns true if the value is a avi video mime type, otherwise false
isBmpFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a bmp image mime type
boolean
$valid Returns true if the value is a bmp image mime type, otherwise false
isCompressedFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a compressed file mime type
boolean
$valid Returns true if the value is a compressed file mime type, otherwise false
isCssFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a css file mime type
boolean
$valid Returns true if the value is a css file mime type, otherwise false
isDouble(mixed $double) : boolean
access |
public |
---|
mixed
The value to check if it is an double
boolean
$valid Returns true if the value is an integer, otherwise false
isFlvFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a flv video mime type
boolean
$valid Returns true if the value is a flv video mime type, otherwise false
isGifFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a gif image mime type
boolean
$valid Returns true if the value is a gif image mime type, otherwise false
isGTarFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a gtar file mime type
boolean
$valid Returns true if the value is a gtar file mime type, otherwise false
isHtmFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a htm file mime type
boolean
$valid Returns true if the value is a htm file mime type, otherwise false
isHtmlFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a html file mime type
boolean
$valid Returns true if the value is a html file mime type, otherwise false
isID(mixed $id) : boolean
access |
public |
---|
mixed
The value to check if it is an id
boolean
$valid Returns true if the value is an id, otherwise false
isIefFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a ief image mime type
boolean
$valid Returns true if the value is a ief image mime type, otherwise false
isImageFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is an image mime type
boolean
$valid Returns true if the value is an image mime type, otherwise false
isInteger(mixed $int) : boolean
access |
public |
---|
mixed
The value to check if it is an integer
boolean
$valid Returns true if the value is an integer, otherwise false
isJpegFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a jpeg image mime type
boolean
$valid Returns true if the value is a jpeg image mime type, otherwise false
isMicrosoftExcelFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Excel file mime type
boolean
$valid Returns true if the value is a MS Excel file mime type, otherwise false
isMicrosoftExcelXLSFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Excel file mime type
boolean
$valid Returns true if the value is a MS Excel file mime type, otherwise false
isMicrosoftExcelXLSXFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Excel file mime type
boolean
$valid Returns true if the value is a MS Excel file mime type, otherwise false
isMicrosoftPowerPointFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Powerpoint file mime type
boolean
$valid Returns true if the value is a MS Pwerpoint file mime type, otherwise false
isMicrosoftPPTFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Powerpoint file mime type
boolean
$valid Returns true if the value is a MS Powerpoint file mime type, otherwise false
isMicrosoftPPTXFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS PowerPoint file mime type
boolean
$valid Returns true if the value is a MS PowerPoint file mime type, otherwise false
isMicrosoftWordDocFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Word file mime type
boolean
$valid Returns true if the value is a MS Word file mime type, otherwise false
isMicrosoftWordDocxFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Word file mime type
boolean
$valid Returns true if the value is a MS Word file mime type, otherwise false
isMicrosoftWordFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a MS Word file mime type
boolean
$valid Returns true if the value is a MS Word file mime type, otherwise false
isMidiFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a midi mime type
boolean
$valid Returns true if the value is a midi mime type, otherwise false
isMovFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a mov video mime type
boolean
$valid Returns true if the value is a mov video mime type, otherwise false
isMp4File(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a mp4 video mime type
boolean
$valid Returns true if the value is a mp4 video mime type, otherwise false
isMpegAudioFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a mpeg audio mime type
boolean
$valid Returns true if the value is a mpeg audio mime type, otherwise false
isMpegVideoFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a mpeg video mime type
boolean
$valid Returns true if the value is a mpeg video mime type, otherwise false
isMxuFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a mux video mime type
boolean
$valid Returns true if the value is a mux video mime type, otherwise false
isOGGAudioFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a ogg audio mime type
boolean
$valid Returns true if the value is a ogg audio mime type, otherwise false
isOGGVideoFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is an ogg video mime type
boolean
$valid Returns true if the value is an ogg video mime type, otherwise false
isPdfFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a PDF file mime type
boolean
$valid Returns true if the value is a PDF file mime type, otherwise false
isPngFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a png image mime type
boolean
$valid Returns true if the value is a png image mime type, otherwise false
isQuickTimeFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a quick time video mime type
boolean
$valid Returns true if the value is a quick time video mime type, otherwise false
isRealAudioFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a real audio mime type
boolean
$valid Returns true if the value is a real audio mime type, otherwise false
isRealMediaFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a real media video mime type
boolean
$valid Returns true if the value is a real media video mime type, otherwise false
isRtxFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a rich text file mime type
boolean
$valid Returns true if the value is a rich textfile mime type, otherwise false
isTarFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a tar file mime type
boolean
$valid Returns true if the value is a tar file mime type, otherwise false
isTiffFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a tiff image mime type
boolean
$valid Returns true if the value is a tiff image mime type, otherwise false
isTxtFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a text/.txt file mime type
boolean
$valid Returns true if the value is a text/.txt file mime type, otherwise false
isValidEmail(mixed $email) : boolean
access |
public |
---|
mixed
The value to check if it is a valid email.
boolean
$valid Returns true if the value is a valid email, otherwise false
isValidUrl(mixed $url) : boolean
access |
public |
---|
mixed
The value to check if it is a valid url.
boolean
$valid Returns true if the value is a valid url, otherwise false
isVideoFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a video mime type
boolean
$valid Returns true if the value is a video mime type, otherwise false
isWavFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a wav audio mime type
boolean
$valid Returns true if the value is a wav audio mime type, otherwise false
isWebMFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a webm video mime type
boolean
$valid Returns true if the value is a webm video mime type, otherwise false
isWmvFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a wmv video mime type
boolean
$valid Returns true if the value is a wmv video mime type, otherwise false
isZipFile(mixed $mimetype) : boolean
access |
public |
---|
mixed
The value to check if it is a zip file mime type
boolean
$valid Returns true if the value is a zip file mime type, otherwise false
removeAdapter( $class, string $method) : void
access |
public |
---|
string
The associated method
removeClassAdapter( $class) : void
access |
public |
---|
set(string $index, mixed $value) : void
access |
public |
---|
string
The key or index to store the value at
mixed
A mixed value that can be anytype
setAdapterTrace(boolean $trace = false) : void
access |
public |
---|
boolean
Default is false. If set to true, will trace adatper.
setFilterTrace(boolean $trace = false) : void
access |
public |
---|
boolean
Default is false. If set to true, will trace filter.
setObserverTrace(boolean $trace = false) : void
access |
public |
---|
boolean
Default is false. If set to true, will trace observer.
rules :
_collection :
_methods :
_adapters :
_observers :
_instances :
_filters :
_traceAdapters :
_traceFilters :
_traceObservers :