Helpers::hasFlashedMessage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace WebDevEtc\BlogEtc;
4
5
use Gate;
6
use Session;
7
use WebDevEtc\BlogEtc\Gates\GateTypes;
8
9
class Helpers
10
{
11
    /**
12
     * What key to use for the session::flash / pull / has.
13
     */
14
    public const FLASH_MESSAGE_SESSION_KEY = 'WEBDEVETC_FLASH';
15
16
    public static function hasAdminGateAccess(): bool
17
    {
18
        return Gate::allows(GateTypes::MANAGE_BLOG_ADMIN);
19
    }
20
21
    public static function hasCommentGateAccess(): bool
22
    {
23
        return Gate::allows(GateTypes::ADD_COMMENT);
24
    }
25
26
    /**
27
     * @deprecated use pullFlashedMessage() instead
28
     */
29
    public static function pull_flashed_message(): ?string
30
    {
31
        return self::pullFlashedMessage();
32
    }
33
34
    /**
35
     * return the flashed message. Use with ::has_flashed_message() if you need to check if it has a value...
36
     *
37
     * @return string
38
     */
39
    public static function pullFlashedMessage(): ?string
40
    {
41
        return Session::pull(self::FLASH_MESSAGE_SESSION_KEY);
42
    }
43
44
    /**
45
     * @deprecated use hasFlashedMessage() instead
46
     */
47
    public static function has_flashed_message(): bool
48
    {
49
        return self::hasFlashedMessage();
50
    }
51
52
    /**
53
     * Is there a flashed message?
54
     */
55
    public static function hasFlashedMessage(): bool
56
    {
57
        return Session::has(self::FLASH_MESSAGE_SESSION_KEY);
58
    }
59
60
    //## Depreciated methods:
61
62
    /**
63
     * @deprecated use flashMessage() instead
64
     */
65
    public static function flash_message(string $message): void
66
    {
67
        self::flashMessage($message);
68
    }
69
70
    /**
71
     * Set a new flash message - used in the BlogEtc Admin panel to flash messages to user
72
     * such as 'post created'.
73
     */
74
    public static function flashMessage(string $message): void
75
    {
76
        Session::flash(self::FLASH_MESSAGE_SESSION_KEY, $message);
77
    }
78
79
    /**
80
     * @deprecated use rssHtmlTag() instead
81
     */
82
    public static function rss_html_tag(): string
83
    {
84
        return self::rssHtmlTag();
85
    }
86
87
    /**
88
     * Use this in your blade/template files, within <head> to auto insert the links to rss feed.
89
     */
90
    public static function rssHtmlTag(): string
91
    {
92
        return '<link rel="alternate" type="application/atom+xml" title="Atom RSS Feed" href="'
93
            .e(route('blogetc.feed')).'?type=atom" />'
94
            .'<link rel="alternate" type="application/rss+xml" title="XML RSS Feed" href="'
95
            .e(route('blogetc.feed')).'?type=rss" />';
96
    }
97
98
    /**
99
     * This method is depreciated. Just use the config() directly.
100
     *
101
     * @deprecated
102
     */
103
    public static function image_sizes(): array
104
    {
105
        return config('blogetc.image_sizes');
106
    }
107
}
108