/
myMixins.class.php
68 lines (64 loc) · 1.62 KB
/
myMixins.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* simple mixin class
* this class is built with listener method and two mixin methods
*
* @package default
* @author Wojciech Sznapka <wojciech@sznapka.pl>
* @license GPL
*/
class myMixins
{
/**
* invoker action instance
*
* @var sfActions
* @access private
*/
private $actionInstance = NULL;
/**
* simple listener, it checks whether method from method_not_found event exists in this class
*
* @param sfEvent $event
* @access public
* @return boolean
*/
public function listener(sfEvent $event)
{
// check if not found method exists in this mixin
if (method_exists($this, $event['method'])) {
// store action instance, it's passed in the event subject
$this->actionInstance = $event->getSubject();
// call mixin method with given arguments
$result = call_user_func_array(array($this, $event['method']), $event['arguments']);
// set result to the event, so it's accessible in the action
$event->setReturnValue($result);
// stop notify chain
return true;
}
}
/**
* gets current day with year; it also sets title of the page
*
* @param int $year
* @access private
* @return string
*/
private function getCurrentDay($year)
{
$date = strftime('%A %Y', strtotime($year . date('-m-d')));
$this->actionInstance->getResponse()->setTitle(sprintf("It's %s!", $date));
return $date;
}
/**
* gets current month
*
* @param int $year
* @access private
* @return string
*/
private function getCurrentMonth($year)
{
return strftime('%B', strtotime($year . date('-m-d')));
}
}