예제 #1
0
 /**
  * Return a new AbstractModule object.
  *
  * @param array $data Module dependencies.
  */
 public function __construct(array $data)
 {
     $this->setLogger($data['logger']);
     if (!isset($data['app'])) {
         $data['app'] = App::instance();
     }
     $this->setApp($data['app']);
 }
 /**
  * @return string
  */
 public function defaultEngine()
 {
     $config = App::instance()->config();
     if ($config->has('view.default_engine')) {
         return $config->get('view.default_engine');
     } else {
         return 'mustache';
     }
 }
 /**
  * Google maps api key.
  *
  * @return string|null Google maps api key.
  */
 public function gmapApiKey()
 {
     $appConfig = App::instance()->config();
     $key = $appConfig->get('apis.google.map.key');
     return $key ? $key : null;
 }
예제 #4
0
<?php

use Charcoal\App\App;
use Charcoal\App\AppConfig;
use Charcoal\App\AppContainer;
// Composer autoloader for Charcoal's psr4-compliant Unit Tests
$autoloader = (require __DIR__ . '/../vendor/autoload.php');
$autoloader->add('Charcoal\\', __DIR__ . '/src/');
$autoloader->add('Charcoal\\Tests\\', __DIR__);
$config = new AppConfig(['base_path' => dirname(__DIR__) . '/', 'metadata' => ['paths' => [dirname(__DIR__) . '/metadata/']]]);
$GLOBALS['container'] = new AppContainer(['config' => $config, 'cache' => new \Stash\Pool(), 'logger' => new \Psr\Log\NullLogger()]);
// Charcoal / Slim is the main app
$GLOBALS['app'] = App::instance($GLOBALS['container']);
$GLOBALS['app']->setLogger(new \Psr\Log\NullLogger());
 /**
  * @param string $category The category ident to load permissions from.
  * @return array
  */
 private function loadCategoryPermissions($category)
 {
     $factory = \Charcoal\App\App::instance()->getContainer()->get('model/factory');
     $adminAcl = $this->adminAcl();
     $roleAcl = $this->roleAcl();
     $loader = new \Charcoal\Loader\CollectionLoader(['logger' => $this->logger, 'factory' => $factory]);
     $model = $factory->create(Permission::class);
     $loader->setModel($model);
     $loader->addFilter('category', $category);
     $permissions = $loader->load();
     $ret = [];
     foreach ($permissions as $perm) {
         $ident = $perm->id();
         $permission = ['ident' => $ident, 'name' => $perm->name()];
         if (in_array($ident, $this->roleAllowed)) {
             $permission['status'] = 'allowed';
         } elseif (in_array($ident, $this->roleDenied)) {
             $permission['status'] = 'denied';
         } else {
             $permission['status'] = '';
         }
         if ($adminAcl->hasResource($ident)) {
             $permission['parent_status'] = $adminAcl->isAllowed($ident, 'admin') ? 'allowed' : 'denied';
         } else {
             $permission['parent_status'] = '';
         }
         $ret[] = $permission;
     }
     return $ret;
 }
/** If we're not using PHP 5.6+, explicitly set the default character set. */
if (PHP_VERSION_ID < 50600) {
    ini_set('default_charset', 'UTF-8');
}
/**
 * If you are using PHP's built-in server, return FALSE
 * for existing files on the filesystem.
 */
if (PHP_SAPI === 'cli-server') {
    $file = __DIR__ . preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']);
    if (is_file($file)) {
        return false;
    }
}
/** Register the Composer autoloader */
require dirname(__DIR__) . '/vendor/autoload.php';
/** Start new or resume existing session */
if (!session_id()) {
    session_start();
}
/** Import the application's settings */
$appConfig = new AppConfig();
$appConfig->addFile(dirname(__DIR__) . '/config/config.php');
/** Build the DI container */
$container = new AppContainer(['config' => $appConfig, 'settings' => ['displayErrorDetails' => true]]);
/** Instantiate a Charcoal~Slim application */
$app = App::instance($container);
/**
 * Run The Application
 */
$app->run();