FW::beforeContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace fieldwork;
4
5
/**
6
 * Static class used to globally register and retrieve forms
7
 * @package fieldwork
8
 */
9
class FW
10
{
11
12
    private static $forms       = array();
13
    private static $ajaxMethods = array();
14
15
    /**
16
     * Registers given form globally
17
     *
18
     * @param Form $form
19
     */
20
    static function registerForm (Form $form)
21
    {
22
        if (!in_array($form, self::$forms))
23
            array_push(self::$forms, $form);
24
    }
25
26
    /**
27
     * Retrieves a form by its slug
28
     *
29
     * @param string $slug
30
     *
31
     * @return Form|null form or null if not found
32
     */
33
    static function getForm ($slug)
34
    {
35
        foreach (self::$forms as $form)
36
            /* @var $form Form */
37
            if ($form->getGlobalSlug() == $slug)
38
                return $form;
39
        return null;
40
    }
41
42
    /**
43
     * Lists slugs of all ajax methods
44
     * @return array
45
     */
46
    static function listAjaxMethods ()
47
    {
48
        return array_keys(self::$ajaxMethods);
49
    }
50
51
    /**
52
     * If any of your form callbacks uses header redirects, make sure to call before_content() and after_content()
53
     * before output starts and after output ends.
54
     */
55
    static function beforeContent ()
56
    {
57
        ob_start();
58
    }
59
60
    /**
61
     * If any of your form callbacks uses header redirects, make sure to call before_content() and after_content()
62
     * before output starts and after output ends.
63
     */
64
    static function afterContent ()
65
    {
66
        ob_end_flush();
67
    }
68
}