Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/spl/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ int main(int argc, char **argv) {
CPPFLAGS=$old_CPPFLAGS
AC_DEFINE_UNQUOTED(HAVE_PACKED_OBJECT_VALUE, $ac_result, [Whether struct _zend_object_value is packed])
AC_DEFINE(HAVE_SPL, 1, [Whether you want SPL (Standard PHP Library) support])
PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c, no)
PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h])
PHP_NEW_EXTENSION(spl, php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_validators.c spl_filters.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c, no)
PHP_INSTALL_HEADERS([ext/spl], [php_spl.h spl_array.h spl_validators.h spl_filters.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h])
PHP_ADD_EXTENSION_DEP(spl, pcre, true)
4 changes: 2 additions & 2 deletions ext/spl/config.w32
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// $Id$
// vim:ft=javascript

EXTENSION("spl", "php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c", false /*never shared */);
EXTENSION("spl", "php_spl.c spl_functions.c spl_engine.c spl_iterators.c spl_validators.c spl_filters.c spl_array.c spl_directory.c spl_exceptions.c spl_observer.c spl_dllist.c spl_heap.c spl_fixedarray.c", false /*never shared */);
AC_DEFINE('HAVE_SPL', 1);
PHP_SPL="yes";
PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h");
PHP_INSTALL_HEADERS("ext/spl", "php_spl.h spl_validators.h spl_filters.h spl_array.h spl_directory.h spl_engine.h spl_exceptions.h spl_functions.h spl_iterators.h spl_observer.h spl_dllist.h spl_heap.h spl_fixedarray.h");
4 changes: 4 additions & 0 deletions ext/spl/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ standard problems.
<file role="src" name="php_spl.h"/>
<file role="src" name="spl_array.c"/>
<file role="src" name="spl_array.h"/>
<file role="src" name="spl_filters.c"/>
<file role="src" name="spl_filters.h"/>
<file role="src" name="spl_directory.c"/>
<file role="src" name="spl_directory.h"/>
<file role="src" name="spl_engine.c"/>
Expand All @@ -34,6 +36,8 @@ standard problems.
<file role="src" name="spl_functions.h"/>
<file role="src" name="spl_iterators.c"/>
<file role="src" name="spl_iterators.h"/>
<file role="src" name="spl_validators.c"/>
<file role="src" name="spl_validators.h"/>
<file role="doc" name="CREDITS"/>
<file role="doc" name="README"/>
<file role="doc" name="TODO"/>
Expand Down
8 changes: 7 additions & 1 deletion ext/spl/php_spl.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "spl_dllist.h"
#include "spl_fixedarray.h"
#include "spl_heap.h"
#include "spl_validators.h"
#include "spl_filters.h"
#include "zend_exceptions.h"
#include "zend_interfaces.h"
#include "ext/standard/php_rand.h"
Expand Down Expand Up @@ -195,6 +197,7 @@ PHP_FUNCTION(class_uses)
SPL_ADD_CLASS(DomainException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(EmptyIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(FilesystemIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(Filter, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(FilterIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(GlobIterator, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(InfiniteIterator, z_list, sub, allow, ce_flags); \
Expand Down Expand Up @@ -239,6 +242,7 @@ PHP_FUNCTION(class_uses)
SPL_ADD_CLASS(SplTempFileObject, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(UnderflowException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(UnexpectedValueException, z_list, sub, allow, ce_flags); \
SPL_ADD_CLASS(Validator, z_list, sub, allow, ce_flags); \

/* {{{ proto array spl_classes()
Return an array containing the names of all clsses and interfaces defined in SPL */
Expand Down Expand Up @@ -939,7 +943,9 @@ PHP_MINIT_FUNCTION(spl)
PHP_MINIT(spl_heap)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_fixedarray)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_observer)(INIT_FUNC_ARGS_PASSTHRU);

PHP_MINIT(spl_filters)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(spl_validators)(INIT_FUNC_ARGS_PASSTHRU);

return SUCCESS;
}
/* }}} */
Expand Down
56 changes: 56 additions & 0 deletions ext/spl/spl_filters.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2012 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Axel Etcheverry <axel@etcheverry.biz> |
+----------------------------------------------------------------------+
*/

/* $Id$ */

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_interfaces.h"

#include "php_spl.h"
#include "spl_functions.h"
#include "spl_engine.h"
#include "spl_filters.h"

PHPAPI zend_class_entry *spl_ce_Filter;

ZEND_BEGIN_ARG_INFO(arginfo_filter_filter, 0)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

static const zend_function_entry spl_funcs_Filter[] = {
SPL_ABSTRACT_ME(Filter, filter, arginfo_filter_filter)
PHP_FE_END
};

/* {{{ PHP_MINIT_FUNCTION(spl_filters)
*/
PHP_MINIT_FUNCTION(spl_filters)
{

REGISTER_SPL_INTERFACE(Filter);

return SUCCESS;
}
/* }}} */

43 changes: 43 additions & 0 deletions ext/spl/spl_filters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2012 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Axel Etcheverry <axel@etcheverry.biz> |
+----------------------------------------------------------------------+
*/

/* $Id$ */

#ifndef SPL_FILTER_H
#define SPL_FILTER_H

#include "php.h"
#include "php_spl.h"
#if HAVE_PCRE || HAVE_BUNDLED_PCRE
#include "ext/pcre/php_pcre.h"
#endif

extern PHPAPI zend_class_entry *spl_ce_Filter;

PHP_MINIT_FUNCTION(spl_filters);

#endif /* SPL_FILTER_H */

/*
* Local Variables:
* c-basic-offset: 4
* tab-width: 4
* End:
* vim600: fdm=marker
* vim: noet sw=4 ts=4
*/
60 changes: 60 additions & 0 deletions ext/spl/spl_validators.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2012 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Axel Etcheverry <axel@etcheverry.biz> |
+----------------------------------------------------------------------+
*/

/* $Id$ */


#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include "php.h"
#include "php_ini.h"
#include "ext/standard/info.h"
#include "zend_interfaces.h"

#include "php_spl.h"
#include "spl_functions.h"
#include "spl_engine.h"
#include "spl_validators.h"

PHPAPI zend_class_entry *spl_ce_Validator;

ZEND_BEGIN_ARG_INFO(arginfo_validator_void, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_INFO(arginfo_validator_is_valid, 0)
ZEND_ARG_INFO(0, value)
ZEND_END_ARG_INFO()

static const zend_function_entry spl_funcs_Validator[] = {
SPL_ABSTRACT_ME(Validator, isValid, arginfo_validator_is_valid)
SPL_ABSTRACT_ME(Validator, getMessages, arginfo_validator_void)
PHP_FE_END
};

/* {{{ PHP_MINIT_FUNCTION(spl_validators)
*/
PHP_MINIT_FUNCTION(spl_validators)
{

REGISTER_SPL_INTERFACE(Validator);

return SUCCESS;
}
/* }}} */
31 changes: 31 additions & 0 deletions ext/spl/spl_validators.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2012 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Axel Etcheverry <axel@etcheverry.biz> |
+----------------------------------------------------------------------+
*/

/* $Id$ */

#ifndef SPL_VALIDATOR_H
#define SPL_VALIDATOR_H

#include "php.h"
#include "php_spl.h"

extern PHPAPI zend_class_entry *spl_ce_Validator;

PHP_MINIT_FUNCTION(spl_validators);

#endif /* SPL_VALIDATOR_H */
20 changes: 20 additions & 0 deletions ext/spl/tests/filters_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
SPL: Filter
--FILE--
<?php
class TrimFilter implements Filter
{
public function filter($str)
{
return trim($str);
}
}

$o = new TrimFilter();

var_dump($o instanceof Filter) . PHP_EOL;
var_dump($o->filter(' good '));
?>
--EXPECT--
bool(true)
string(4) "good"
40 changes: 40 additions & 0 deletions ext/spl/tests/validator_001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
--TEST--
SPL: Validator
--FILE--
<?php
class Test implements Validator
{
protected $messages = array();

public function isValid($value)
{
if($value == 'test') {
return true;
}

$this->messages[] = sprintf("Error : '%s' is not equal to 'test'", $value);

return false;
}

public function getMessages()
{
return $this->messages;
}
}

$test = new Test();

var_dump($test instanceof Validator) . PHP_EOL;
var_dump($test->isValid('test')) . PHP_EOL;
var_dump($test->isValid('test1')) . PHP_EOL;
var_dump($test->getMessages()) . PHP_EOL;
?>
--EXPECT--
bool(true)
bool(true)
bool(false)
array(1) {
[0]=>
string(38) "Error : 'test1' is not equal to 'test'"
}