• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ICanBoogie / ICanBoogie / 11651757567

03 Nov 2024 01:28PM UTC coverage: 41.117%. Remained the same
11651757567

push

github

olvlvl
Tidy

81 of 197 relevant lines covered (41.12%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.67
/lib/Hooks.php
1
<?php
2

3
namespace ICanBoogie;
4

5
use ICanBoogie\Storage\APCStorage;
6
use ICanBoogie\Storage\FileStorage;
7
use ICanBoogie\Storage\Storage;
8
use ICanBoogie\Storage\StorageCollection;
9

10
use function sha1;
11
use function substr;
12

13
final class Hooks
14
{
15
    /**
16
     * Creates a storage engine for synthesized configurations.
17
     *
18
     * If APC is available the method returns a storage collection or {@see APCStorage} and
19
     * {@see FileStorage}, otherwise a {@see FileStorage} is returned.
20
     * {@see FileStorage\Adapter\PHPAdapter} is used as adapter for {@see FileStorage}.
21
     *
22
     * @return Storage<string, mixed>
23
     */
24
    public static function create_storage_for_configs(Application $app): Storage
25
    {
26
        $directory = $app->config->var_cache_configs;
1✔
27
        $storage = new FileStorage($directory, new FileStorage\Adapter\PHPAdapter());
1✔
28

29
        return self::with_apc_storage($storage, 'icanboogie:config:');
1✔
30
    }
31

32
    /**
33
     * Creates a storage engine for synthesized configurations.
34
     *
35
     * If APC is available the method returns a storage collection or {@see APCStorage} and
36
     * {@see FileStorage}, otherwise a {@see FileStorage} is returned.
37
     *
38
     * @return Storage<string, mixed>
39
     */
40
    public static function create_storage_for_vars(Application $app): Storage
41
    {
42
        $directory = $app->config->var_lib;
1✔
43
        $storage = new FileStorage($directory);
1✔
44

45
        return self::with_apc_storage($storage, 'icanboogie:vars:');
1✔
46
    }
47

48
    /**
49
     * If APC is available the method returns a storage collection with a {@see APCStorage}
50
     * instance and the specified storage instance.
51
     *
52
     * @param Storage<string, mixed> $storage
53
     *
54
     * @return Storage<string, mixed>
55
     */
56
    private static function with_apc_storage(Storage $storage, string $prefix): Storage
57
    {
58
        if (!APCStorage::is_available()) {
2✔
59
            return $storage;
×
60
        }
61

62
        return new StorageCollection([ new APCStorage(self::make_apc_prefix() . $prefix), $storage ]);
2✔
63
    }
64

65
    /**
66
     * Makes an APC prefix for the application.
67
     */
68
    private static function make_apc_prefix(): string
69
    {
70
        return substr(sha1(getcwd() ?: __DIR__), 0, 8) . ':';
2✔
71
    }
72

73
    /*
74
     * Events
75
     */
76

77
    /**
78
     * Clears configuration cache.
79
     */
80
    public static function on_clear_cache(Application\ClearCacheEvent $event): void
81
    {
82
        $event->app->storage_for_configs->clear();
2✔
83
        $event->cleared('app.storage_for_configs');
2✔
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc