ICanBoogie/ICanBoogie 4.0.x
  • Namespace
  • Class

Namespaces

  • ICanBoogie
    • Application
    • Autoconfig
    • Binding
    • Routing
    • Session

Classes

  • AlreadyAuthenticated
  • AppConfig
  • Core
  • Debug
  • Helpers
  • Hooks
  • Logger
  • LogLevel
  • SessionWithEvent

Interfaces

  • LoggerInterface

Traits

  • AppAccessor
  • LoggerTrait

Exceptions

  • ApplicationAlreadyBooted
  • ApplicationAlreadyInstantiated
  • ApplicationAlreadyRunning
  • ApplicationNotInstantiated

Constants

  • TOKEN_ALPHA
  • TOKEN_ALPHA_UPCASE
  • TOKEN_NUMERIC
  • TOKEN_SYMBOL
  • TOKEN_SYMBOL_WIDE

Functions

  • app
  • boot
  • excerpt
  • generate_token
  • generate_token_wide
  • get_autoconfig
  • log
  • log_error
  • log_info
  • log_success
  • log_time
  • resolve_app_paths
  • resolve_instance_name
  • strip_root
  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  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 
<?php

/*
 * This file is part of the ICanBoogie package.
 *
 * (c) Olivier Laviale <olivier.laviale@gmail.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace ICanBoogie;

use ICanBoogie\Storage\APCStorage;
use ICanBoogie\Storage\FileStorage;
use ICanBoogie\Storage\Storage;
use ICanBoogie\Storage\StorageCollection;

class Hooks
{
    /**
     * If APC is available the method return a storage collection with a {@link APCStorage}
     * instance and the specified storage instance.
     *
     * @param Storage $storage
     * @param string $prefix Prefix for the {@link APCStorage} instance.
     *
     * @return Storage|StorageCollection
     */
    static private function with_apc_storage(Storage $storage, $prefix)
    {
        if (!APCStorage::is_available())
        {
            return $storage;
        }

        return new StorageCollection([ new APCStorage(self::make_apc_prefix() . $prefix), $storage ]);
    }

    /**
     * Makes an APC prefix for the application.
     *
     * @return string
     */
    static public function make_apc_prefix()
    {
        return substr(sha1(ROOT), 0, 8) . ':';
    }

    /**
     * Creates a storage engine for synthesized configurations.
     *
     * If APC is available the method returns a storage collection or {@link APCStorage} and
     * {@link FileStorage}, otherwise a {@link FileStorage} is returned.
     *
     * @param Application $app
     *
     * @return Storage
     */
    static public function create_storage_for_configs(Application $app)
    {
        $directory = $app->config[AppConfig::REPOSITORY_CACHE_CONFIGS];
        $storage = new FileStorage($directory);

        return self::with_apc_storage($storage, 'icanboogie:configs:');
    }

    /**
     * Creates a storage engine for synthesized configurations.
     *
     * If APC is available the method returns a storage collection or {@link APCStorage} and
     * {@link FileStorage}, otherwise a {@link FileStorage} is returned.
     *
     * @param Application $app
     *
     * @return Storage
     */
    static public function create_storage_for_vars(Application $app)
    {
        $directory = $app->config[AppConfig::REPOSITORY_VARS];
        $storage = new FileStorage($directory);

        return self::with_apc_storage($storage, 'icanboogie:vars:');
    }

    /*
     * Events
     */

    /**
     * Clears configurations cache.
     *
     * @param Application\ClearCacheEvent $event
     * @param Application $app
     */
    static public function on_clear_cache(Application\ClearCacheEvent $event, Application $app)
    {
        $app->storage_for_configs->clear();
    }
}
ICanBoogie/ICanBoogie 4.0.x API documentation generated by ApiGen