Completed
Push — master ( 7b9104...2433c1 )
by Tim
02:44
created

HelperUtility::getSignalSlotDispatcher()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Helper Utility.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\Utility;
9
10
use TYPO3\CMS\Core\Database\Connection;
11
use TYPO3\CMS\Core\Database\ConnectionPool;
12
use TYPO3\CMS\Core\Exception;
13
use TYPO3\CMS\Core\Messaging\FlashMessage;
14
use TYPO3\CMS\Core\Messaging\FlashMessageService;
15
use TYPO3\CMS\Core\Utility\GeneralUtility;
16
use TYPO3\CMS\Extbase\Object\ObjectManager;
17
use TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface;
18
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
19
20
/**
21
 * Helper Utility.
22
 */
23
class HelperUtility
24
{
25
    /**
26
     * Get the query for the given class name oder object.
27
     *
28
     * @param string|object $objectName
29
     *
30
     * @return QueryInterface
31
     *
32
     * @throws \TYPO3\CMS\Extbase\Object\Exception
33
     */
34
    public static function getQuery($objectName)
35
    {
36
        $objectName = \is_object($objectName) ? \get_class($objectName) : $objectName;
37
        /** @var PersistenceManagerInterface $manager */
38
        static $manager = null;
39
        if (null === $manager) {
40
            $manager = GeneralUtility::makeInstance(ObjectManager::class)->get(PersistenceManagerInterface::class);
41
        }
42
43
        return $manager->createQueryForType($objectName);
44
    }
45
46
    /**
47
     * Create a flash message.
48
     *
49
     * @param string $message
50
     * @param string $title
51
     * @param int    $mode
52
     *
53
     * @throws Exception
54
     */
55
    public static function createFlashMessage($message, $title = '', $mode = FlashMessage::OK)
56
    {
57
        $flashMessage = GeneralUtility::makeInstance(FlashMessage::class, $message, $title, $mode, true);
58
        $flashMessageService = GeneralUtility::makeInstance(FlashMessageService::class);
59
        $messageQueue = $flashMessageService->getMessageQueueByIdentifier();
60
        $messageQueue->enqueue($flashMessage);
61
    }
62
63
    /**
64
     * Get the database connection.
65
     *
66
     * @param mixed $table
67
     *
68
     * @return Connection
69
     */
70
    public static function getDatabaseConnection($table)
71
    {
72
        return GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($table);
73
    }
74
}
75