Skip to content

Commit 06318bc

Browse files
committed
Merge branch 'master' of github.com:onPHP/onphp-framework
2 parents c975afd + dc6b62a commit 06318bc

File tree

6 files changed

+91
-10
lines changed

6 files changed

+91
-10
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/***************************************************************************
3+
* Copyright (C) 2011 by Alexey S. Denisov *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU Lesser General Public License as *
7+
* published by the Free Software Foundation; either version 3 of the *
8+
* License, or (at your option) any later version. *
9+
* *
10+
***************************************************************************/
11+
12+
/**
13+
* @ingroup Filters
14+
**/
15+
final class CallbackFilter implements Filtrator
16+
{
17+
/**
18+
* @var Closure
19+
*/
20+
private $callback = null;
21+
22+
/**
23+
* @return CallbackFilter
24+
**/
25+
public static function create(Closure $callback)
26+
{
27+
return new self($callback);
28+
}
29+
30+
public function __construct(Closure $callback)
31+
{
32+
$this->callback = $callback;
33+
}
34+
35+
public function apply($value)
36+
{
37+
return $this->callback->__invoke($value);
38+
}
39+
}
40+
?>

doc/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
* main/Crypto/Base62Utils.class.php: assert check in decode() added.
44

5+
2011-06-01 Alexey S. Denisov
6+
7+
* core/Form/Filters/CallbackFilter.class.php: implemented CallbackFilter
8+
to work with anonymous functions.
9+
510
2011-06-01 Sergey S. Sergeev
611

712
* main/Crypto/Base62Utils.class.php: Base62 encode/decode implemented.

main/Net/Mail/Mail.class.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
* License, or (at your option) any later version. *
99
* *
1010
***************************************************************************/
11-
12-
/**
13-
* @ingroup Exceptions
14-
**/
15-
class MailException extends BaseException {/*_*/};
16-
17-
/**
18-
* @ingroup Exceptions
19-
**/
20-
class MailNotSentException extends MailException {/*_*/};
2111

2212
/**
2313
* @ingroup Mail

main/Net/Mail/MailException.class.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/***************************************************************************
3+
* Copyright (C) 2004-2007 by Anton E. Lebedevich *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU Lesser General Public License as *
7+
* published by the Free Software Foundation; either version 3 of the *
8+
* License, or (at your option) any later version. *
9+
* *
10+
***************************************************************************/
11+
12+
/**
13+
* @ingroup Exceptions
14+
**/
15+
class MailException extends BaseException {/*_*/};
16+
?>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/***************************************************************************
3+
* Copyright (C) 2004-2007 by Anton E. Lebedevich *
4+
* *
5+
* This program is free software; you can redistribute it and/or modify *
6+
* it under the terms of the GNU Lesser General Public License as *
7+
* published by the Free Software Foundation; either version 3 of the *
8+
* License, or (at your option) any later version. *
9+
* *
10+
***************************************************************************/
11+
12+
/**
13+
* @ingroup Exceptions
14+
**/
15+
class MailNotSentException extends MailException {/*_*/};
16+
?>

test/core/FiltersTest.class.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,5 +228,19 @@ public function testUtf16ConverterFilter()
228228
Utf16ConverterFilter::me()->apply('привет')
229229
);
230230
}
231+
232+
public function testCallbackFilter()
233+
{
234+
//simple test
235+
$postApply = ' and my applying';
236+
$filter = CallbackFilter::create(function($value) use ($postApply) {
237+
return $value . $postApply;
238+
});
239+
240+
$this->assertEquals(
241+
'one another value and my applying',
242+
$filter->apply('one another value')
243+
);
244+
}
231245
}
232246
?>

0 commit comments

Comments
 (0)