public static function generateNew(Kernel $kernel, array &$options = array())
 {
     $builder = new UserClosure([], ['$kernel']);
     $builder[] = '$cache = new UniversalCache(array());';
     if (extension_loaded('apcu') && isset($options['APC'])) {
         $builder[] = new Statement(new MethodCall('$cache', 'addBackend', [new NewObject('UniversalCache\\ApcuCache', [$kernel->getApplicationID()])]));
     }
     if (extension_loaded('memcached') && isset($options['Memcached'])) {
         if (isset($options['Memcached']['PersistentId'])) {
             $builder[] = '$memcached = ' . new NewObject('Memcached', [$options['Memcached']['PersistentId']]) . ';';
         } else {
             $builder[] = '$memcached = new Memcached;';
         }
         if (isset($options['Memcached']['Servers'])) {
             foreach ($options['Memcached']['Servers'] as $server) {
                 $builder[] = new Statement(new MethodCall('$memcached', 'addServer', $server));
             }
         }
         $builder[] = new Statement(new MethodCall('$cache', 'addBackend', ['$memcached']));
     }
     if (isset($options['FileSystem'])) {
         $builder[] = new Statement(new MethodCall('$cache', 'addBackend', [new NewObject('UniversalCache\\FileSystemCache', [$kernel->getCacheDir()])]));
     }
     $builder[] = 'return $cache;';
     $className = get_called_class();
     return new NewObject($className, [$options, $builder]);
 }
Exemple #2
0
 public function testPageView()
 {
     $kernel = new Kernel();
     $service = new ViewServiceProvider();
     $kernel->registerService($service, array('Class' => 'Phifty\\View\\Page'));
     $view = $kernel->view;
     $this->assertNotNull($view);
     $this->assertInstanceOf('Phifty\\View\\Page', $view);
 }
Exemple #3
0
function kernel()
{
    static $kernel;
    $kernel = new Kernel();
    $configLoader = new ConfigLoader();
    $configLoader->load('framework', 'vendor/corneltek/phifty-core/config/framework.dev.yml');
    $kernel->registerService(new \Phifty\ServiceProvider\ConfigServiceProvider($configLoader));
    $kernel->registerService(new \Phifty\ServiceProvider\EventServiceProvider());
    return $kernel;
}
 public static function canonicalizeConfig(Kernel $kernel, array $options)
 {
     if (!isset($options['Default'])) {
         $options['Default'] = 'en';
     }
     if (!isset($options['LocaleDir'])) {
         $options['LocaleDir'] = 'locale';
     }
     if (!isset($options['Domain'])) {
         $options['Domain'] = $kernel->getApplicationID();
     }
     if (!isset($options['Langs'])) {
         $options['Langs'] = ['en' => 'English'];
     }
     $options['LocaleDir'] = $kernel->rootDir . DIRECTORY_SEPARATOR . $options['LocaleDir'];
     return $options;
 }
 /**
  * $kernel->asset->loader
  * $kernel->asset->writer.
  */
 public function register(Kernel $kernel, $options = array())
 {
     $kernel->asset = function () use($kernel, $options) {
         $config = new AssetConfig($options);
         $config->setEnvironment($kernel->environment);
         $config->setNamespace($kernel->getApplicationUUID());
         $cache = new UniversalCache(array(new ApcuCache($kernel->getApplicationUUID()), new FileSystemCache($kernel->getCacheDir())));
         $config->setCache($cache);
         $config->setRoot(PH_APP_ROOT);
         $loader = new AssetLoader($config);
         $render = new AssetRender($config, $loader);
         $compiler = $render->getCompiler();
         $compiler->defaultJsCompressor = 'uglifyjs';
         $compiler->defaultCssCompressor = null;
         return (object) array('loader' => $loader, 'config' => $config, 'render' => $render, 'compiler' => $compiler, 'cache' => $cache);
     };
 }
 public function __construct(Kernel $kernel, array $options)
 {
     parent::__construct();
     $this['app_id'] = $options['AppId'];
     $this['session'] = function ($c) use($options) {
         return new Facebook(['app_id' => $options['AppId'], 'app_secret' => $options['AppSecret'], 'default_graph_version' => $options['DefaultGraphVersion']]);
     };
     // make this factory?
     $this['redirect_login_helper'] = $this->factory(function ($c) {
         return $c['session']->getRedirectLoginHelper();
     });
     $this['login_url'] = $this->factory(function ($c) use($options) {
         if (preg_match('#^https?://#', $options['DefaultLoginCallbackUrl'])) {
             $url = $options['DefaultLoginCallbackUrl'];
         } else {
             $url = $kernel->getBaseUrl() . $options['DefaultLoginCallbackUrl'];
         }
         $helper = $c['redirect_login_helper'];
         return $helper->getLoginUrl($url, $options['DefaultPermissions']);
     });
     $this['oauth2_client'] = $this->factory(function ($c) use($options) {
         return $c['session']->getOAuth2Client();
     });
 }
 public function register(Kernel $kernel, $options = array())
 {
     $kernel->registerFactory('view', new ViewFactory($kernel, $options));
 }