public function newRenderer() { $kernel = kernel(); $this->env = $kernel->twig->env; $this->loader = $kernel->twig->loader; return $this->env; }
public function registerBundleDir($dir) { $this->bundleDirs[] = $dir; if ($twig = kernel()->twig) { $twig->loader->addPath($dir); } }
public function execute() { $router = kernel()->router; $router->compile(); $dumper = new ConsoleDumper(); $dumper->dump($router->routes); }
public function execute() { $bundles = kernel()->bundles; $config = []; $kernel = kernel(); $config['name'] = 'site/' . strtolower($kernel->getApplicationId()); $config['version'] = '1.0'; $config['require'] = []; foreach ($bundles as $bundle) { if ($bundle instanceof ComposerConfigBridge) { if ($deps = $bundle->getComposerDependency()) { $this->mergeConfig($config, $deps); } } } foreach ($kernel->services as $service) { if ($service instanceof ComposerConfigBridge) { if ($deps = $service->getComposerDependency()) { $this->mergeConfig($config, $deps); } } } $config['require-dev'] = ["corneltek/phpunit-testmore" => "dev-master"]; $config['scripts'] = ["post-install-cmd" => ["Phifty\\Installer\\ComposerInstaller::postInstall"]]; echo json_encode($config, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); }
public function generate($ns, $controllerName) { $app = strtolower($ns) == 'app' ? kernel()->getApp() : (kernel()->bundle($ns) ?: kernel()->bundles->load($ns)); if (!$app) { throw new Exception("Application or bundle not found."); } if (strrpos($controllerName, 'Controller') === false) { $controllerName .= 'Controller'; } $args = func_get_args(); $args = array_splice($args, 2); $controllerActions = array('indexAction'); foreach ($args as $arg) { $controllerActions[] = $arg . 'Action'; } $dir = $app->locate(); $className = $ns . '\\Controller\\' . $controllerName; $classDir = $dir . DIRECTORY_SEPARATOR . 'Controller'; $classFile = $classDir . DIRECTORY_SEPARATOR . $controllerName . '.php'; if (!file_exists($classDir)) { mkdir($classDir, 0755, true); } if (file_exists($classFile)) { $this->logger->info("Found existing {$classFile}, skip"); return; } $this->render('Controller.php.twig', $classFile, array('namespace' => $ns, 'controllerName' => $controllerName, 'controllerActions' => $controllerActions)); }
public function testKernel() { $kernel = kernel(); $this->assertNotNull($kernel); $this->assertFileExists($kernel->webroot); $this->assertFileExists($kernel->rootDir); }
public function execute() { // xxx: Can use universal requirement checker. // // $req = new Universal\Requirement\Requirement; // $req->extensions( 'apc','mbstring' ); // $req->classes( 'ClassName' , 'ClassName2' ); // $req->functions( 'func1' , 'func2' , 'function3' ) // $exts = array('apc', 'pdo', 'pdo_mysql', 'pdo_sqlite', 'pdo_pgsql', 'gd', 'mysqli'); echo "extensions:\n"; foreach ($exts as $ext) { $this->printResult($ext, extension_loaded($ext)); } $this->printResult('reflection', class_exists('ReflectionObject')); echo "classes:\n"; $this->printResult('lazyrecord', class_exists('LazyRecord\\BaseModel', true)); $this->printResult('assetkit', class_exists('AssetKit\\AssetLoader', true)); $this->printResult('roller', class_exists('Roller\\Router', true)); echo "config:\n"; $this->printResult('short_open_tag', ini_get('short_open_tag')); $this->printResult('roller extension', extension_loaded('roller')); $kernel = kernel(); if ($configext = $kernel->config->get('Requirement.Extensions')) { foreach ($configext as $extname) { $this->printResult("{$extname} extension", extension_loaded($extname)); } } // TODO: // 1. get services and get dependencies from these services for checking foreach ($kernel->bundles as $bundle) { // $dir = $plugin->getTemplateDir(); } }
public function run() { $kernel = kernel(); $frameworkId = $kernel::FRAMEWORK_ID; $appId = $kernel->config->framework->ApplicationID; /* merge/update framework locale into app locale dir */ $finder = Finder::create()->files()->name('*.po')->in(PH_ROOT . DIRECTORY_SEPARATOR . 'locale'); $itr = $finder->getIterator(); foreach ($itr as $item) { # echo $item->getPathname(). "\n"; $sourceDir = dirname($item->getPathname()); $sourceRelPath = FileUtils::remove_base($item->getPathname(), PH_ROOT); $sourceRelDir = dirname($sourceRelPath); $targetDir = PH_APP_ROOT . DIRECTORY_SEPARATOR . $sourceRelDir; FileUtils::mkpath($targetDir); $sourcePo = $sourceDir . DIRECTORY_SEPARATOR . $frameworkId . '.po'; $targetPo = $targetDir . DIRECTORY_SEPARATOR . $appId . '.po'; # var_dump( $sourcePo , $targetPo ); if (file_exists($targetPo)) { $this->log("Msgcat " . basename($sourcePo) . ' => ' . basename($targetPo)); $merged = ''; $h = popen("msgcat {$sourcePo} {$targetPo}", 'r'); while (!feof($h)) { // send the current file part to the browser $merged .= fread($h, 1024); } pclose($h); $this->log("Writing back to "); file_put_contents($targetPo, $merged); } else { $this->log("Copying files.."); copy($sourcePo, $targetPo); } } }
public function generate($ns, $name) { $app = kernel()->app($ns) ?: kernel()->bundle($ns, true); if (!$app) { throw new Exception("{$ns} application or plugin not found."); } $emailClassName = $name . 'Email'; $handle = Inflector::getInstance()->underscore($name); $dir = $app->locate(); $className = $ns . '\\Email\\' . $emailClassName; $classDir = $dir . DIRECTORY_SEPARATOR . 'Email'; $classFile = $classDir . DIRECTORY_SEPARATOR . $emailClassName . '.php'; if (!file_exists($classDir)) { mkdir($classDir, 0755, true); } if (file_exists($classFile)) { $this->logger->info("Found existing {$classFile}, skip"); } else { $this->render('Email.php.twig', $classFile, array('namespace' => $ns, 'emailClassName' => $emailClassName, 'emailHandle' => $handle)); } foreach (kernel()->locale->available() as $locale => $name) { $templateFile = $app->getTemplateDir() . DIRECTORY_SEPARATOR . 'email' . DIRECTORY_SEPARATOR . $locale . DIRECTORY_SEPARATOR . $handle . '.html'; if (file_exists($templateFile)) { $this->logger->info("Found existing {$templateFile}, skip"); continue; } $this->render('EmailTemplate.html.twig', $templateFile, array('namespace' => $ns, 'emailClassName' => $emailClassName, 'emailHandle' => $handle)); } /* */ }
public function execute() { $options = $this->options; $config = $this->getAssetConfig(); $loader = $this->getAssetLoader(); $installer = $options->link ? new LinkInstaller($config) : new Installer($config); $installer->logger = $this->logger; $loader = $this->getAssetLoader(); $kernel = kernel(); $this->logger->info("Installing assets from applications..."); foreach ($kernel->applications as $application) { $assetNames = $application->assets(); $assets = $loader->loadAssets($assetNames); foreach ($assets as $asset) { $this->logger->info("Installing {$asset->name} ..."); $installer->install($asset); } } $this->logger->info("Installing assets from bundles..."); foreach ($kernel->bundles as $plugin) { $assetNames = $plugin->assets(); $assets = $loader->loadAssets($assetNames); foreach ($assets as $asset) { $this->logger->info("Installing {$asset->name} ..."); $installer->install($asset); } } $compiledDir = $config->getCompiledDir(); if (!file_exists($compiledDir)) { $this->logger->info("Creating asset compiled dir: {$compiledDir}"); $this->logger->info("Please chmod this directory as you need."); mkdir($compiledDir, 0777, true); } $this->logger->info("Done"); }
public function generate($ns, $schemaName) { $app = strtolower($ns) == 'app' ? kernel()->getApp() : (kernel()->bundle($ns) ?: kernel()->bundles->load($ns)); if (!$app) { throw new Exception("{$ns} application or plugin not found."); } if (strrpos($schemaName, 'Schema') === false) { $schemaName .= 'Schema'; } $args = func_get_args(); $args = array_splice($args, 2); $schemaColumns = array(); foreach ($args as $arg) { $list = explode(':', $arg); $schemaColumns[] = array('name' => $list[0], 'type' => $list[1], 'var' => @$list[2]); } $dir = $app->locate(); $className = $ns . '\\Model\\' . $schemaName; $classDir = $dir . DIRECTORY_SEPARATOR . 'Model'; $classFile = $classDir . DIRECTORY_SEPARATOR . $schemaName . '.php'; if (!file_exists($classDir)) { mkdir($classDir, 0755, true); } if (file_exists($classFile)) { $this->logger->info("Found existing {$classFile}, skip"); return; } $this->render('Schema.php.twig', $classFile, array('namespace' => $ns, 'schemaName' => $schemaName, 'schemaColumns' => $schemaColumns)); }
public function execute() { $kernel = kernel(); $localeDir = $kernel->config->get('framework', 'Services.LocaleService.Directory') ?: 'locale'; $frameworkLocaleDir = PH_ROOT . DIRECTORY_SEPARATOR . 'locale'; $langs = $kernel->config->get('framework', 'Services.LocaleService.Langs')->config; $cwd = getcwd(); $appPoFiles = array(); $frameworkId = Kernel::FRAMEWORK_ID; $appId = $kernel->config->framework->ApplicationID; $frameworkPoFilename = $frameworkId . '.po'; $appPoFilename = $appId . '.po'; $this->logger->info("Compiling message catalog..."); // Update message catalog $finder = Finder::create()->files()->name('*.po')->in($localeDir); foreach ($finder->getIterator() as $file) { $targetFile = futil_replace_extension($file, 'mo'); $this->logger->info("Compiling messages {$file} to {$targetFile}"); $cmd = sprintf('msgfmt -v --use-fuzzy -o %s %s', $targetFile, $file); $this->logger->debug($cmd); system($cmd, $retval); if ($retval != 0) { die('xgettext error'); } } }
public function testCurrentUserService() { $kernel = kernel(); $service = new Phifty\ServiceProvider\CurrentUserServiceProvider(); $service->register($kernel, array()); ok($service); ok($kernel->currentUser); }
public function execute() { $kernel = kernel(); $webroot = $kernel->webroot; foreach (kernel()->plugins as $plugin) { // Exporting Web directory } }
public function schema() { $this->column('lang')->varchar(12)->validValues(function () { return array_flip(kernel()->locale->available()); })->label('語言')->default(function () { return kernel()->locale->getDefault(); })->renderAs('SelectInput'); }
public function testRegisterTwigService() { $kernel = kernel(); $twig = new \Phifty\Service\TwigService(); $twig->register($kernel, array('Environment' => array('debug' => true, 'cache' => 'cache/path', 'autoload' => 'auto_reload'), 'TemplateDirs' => array('applications', 'bundles'))); $this->assertNotNull($kernel->twig); $this->assertNotNull($kernel->twig->env, 'get environment'); $this->assertNotNull($kernel->twig->loader, 'get loader'); }
public function generate($ns, $crudId) { $bundle = kernel()->app($ns) ?: kernel()->bundle($ns, true); if (!$bundle) { throw new Exception("{$ns} application or plugin not found."); } $crudId = Inflector::getInstance()->underscore($crudId); $templateDir = $bundle->getTemplateDir() . DIRECTORY_SEPARATOR . $crudId; $this->copyDir('template', $templateDir); }
public function render($attributes = array()) { $id = $this->getSerialId(); $html = parent::render($attributes); $recordClass = $this->record_class; $record = new $recordClass(); $deleteAction = $record->getRecordActionClass('Delete'); $env = kernel()->twig->env; $html .= $env->render('@CRUD/widgets/quick_crud_widget.html', array('deleteAction' => str_replace('\\', '::', $deleteAction), 'selectInputId' => $id, 'dataLabelField' => $record->getDataLabelField(), 'dataValueField' => $record->getDataValueField(), 'dialogPath' => $this->dialog_path, 'self' => $this)); return $html; }
public function run() { kernel()->library->load('han-convert'); $convertion = $this->arg('convertion'); if (!in_array($convertion, $this->convertionFunctions)) { return $this->error('Invalid convertion method.'); } $records = $this->loadRecords(); $this->convertRecords($convertion, $records); return $this->success(count($records) . '個項目轉換成功'); }
public function run() { if (!kernel()->currentUser->hasLoggedIn()) { return $this->error('無上傳權限。'); } parent::run(); $filePath = $this->arg('file'); $session = kernel()->session; $session->set('_current_upload', $filePath); return $this->success('上傳成功', ['filepath' => $filePath]); }
public function execute() { $sources = kernel()->config->get('framework', 'Services.BundleService.Sources'); foreach ($sources as $source) { $get = $this->createCommand('\\Phifty\\Command\\BundleCommand\\GetCommand'); if ($optTargetDir = $this->optionSpecs->find('target-dir')) { $get->options['target-dir'] = clone $optTargetDir; $get->options['target-dir']->setValue($source['into']); $get->executeWrapper([$source['from']]); } } }
public function run() { $template = $this->template; $args = $this->args; $engine = new \Phifty\View\Twig(kernel()); $viewClass = kernel()->config->get('framework', 'View.Class') ?: 'Phifty\\View'; $view = new $viewClass($engine); if ($args) { $view->assign($args); } return $view->render($template); }
public function __construct(Kernel $kernel) { $this->kernel = $kernel; $this->engine = new \Phifty\View\Twig($kernel); $this->init(); // register args $this->args['Kernel'] = $kernel; $this->args['Request'] = new HttpRequest(); // helper functions // TODO: refactor to event $this->args['Web'] = new Web(); kernel()->event->trigger('view.init', $this); }
public function __construct($options = array()) { $this->kernel = kernel(); /* save options */ $this->options = $options; /* preprocess options */ if (isset($options['template_dirs'])) { $this->templateDirs = (array) $options['template_dirs']; } if (empty($this->templateDirs)) { $this->templateDirs = $this->getDefaultTemplateDirs(); } }
public function __construct() { if (extension_loaded('mongo')) { $this->encoder = 'bson_encode'; $this->decoder = 'bson_decode'; } elseif (extension_loaded('json')) { $this->encoder = 'json_encode'; $this->decoder = 'json_decode'; } $this->config = kernel()->config->framework->Notification; $this->publishPoint = $this->config && $this->config->PublishPoint ? $this->config->PublishPoint : 'tcp://localhost:55555'; $this->subscribePoint = $this->config && $this->config->subscribePoint ? $this->config->subscribePoint : 'tcp://localhost:55556'; $this->context = new ZMQContext(1); }
public function __construct($args = array()) { $record = null; if (is_object($args)) { $record = $args; } else { if (isset($args['record'])) { $record = $args['record']; $this->userModelClass = get_class($record); } else { $this->userModelClass = isset($args['model_class']) ? $args['model_class'] : kernel()->config->get('framework', 'CurrentUser.Model') ?: 'User\\Model\\User'; // default user model (User\Model\User) } if (isset($args['session_prefix'])) { $this->sessionPrefix = $args['session_prefix']; } if (isset($args['primary_key'])) { $this->primaryKey = $args['primary_key']; } } /** * Initialize a session pool with prefix 'user_' */ $this->session = new Session($this->sessionPrefix); /* if record is specified, update session from record */ if ($record) { if (!$this->setRecord($record)) { throw new Exception('CurrentUser can not be loaded from record.'); } } else { // load record from session, // get current user record id, and find record from it. // // TODO: use virtual loading, do not manipulate database if we have // data in session already. // // TODO: provide a verify option to verify database item before // loading. if ($userId = $this->session->get($this->primaryKey)) { $class = $this->userModelClass; $virtualRecord = new $class(); foreach ($virtualRecord->getColumnNames() as $name) { $virtualRecord->{$name} = $this->session->get($name); } $this->record = $virtualRecord; // $this->setRecord(new $this->userModelClass(array( $this->primaryKey => $userId ))); } } }
public function initEngine($engine = null, $engineOpts = null) { if ($engine) { /* if it's an engine object already, just save it */ if (is_object($engine)) { $this->engine = $engine; } else { $this->engine = \Phifty\View\Engine::createEngine($engine, $engineOpts); } } else { /* get default engine from config */ $backend = kernel()->config->get('framework', 'View.Backend') ?: 'twig'; $this->engine = \Phifty\View\Engine::createEngine($backend, $engineOpts); } }
public function execute() { $kernel = kernel(); $config = $this->getAssetConfig(); $loader = $this->getAssetLoader(); $this->logger->info("Finding assets from applications..."); foreach ($kernel->applications as $application) { $this->registerBundleAssets($application); } $this->logger->info("Finding assets from bundles..."); foreach ($kernel->bundles as $bundle) { $this->registerBundleAssets($bundle); } $loader->saveEntries(); }
public function generate($ns, $modelName, $crudId = null) { $bundle = kernel()->app($ns) ?: kernel()->bundle($ns, true); if (!$bundle) { throw new Exception("{$ns} application or bundle not found."); } if (!$crudId) { $crudId = Inflector::getInstance()->underscore($modelName); } $bundleName = $bundle->getNamespace(); $modelClass = $bundleName . '\\Model\\' . $modelName; $handlerClass = $modelName . 'CRUDHandler'; $classFile = $bundle->locate() . DIRECTORY_SEPARATOR . $handlerClass . '.php'; $this->render('CRUDHandler.php.twig', $classFile, array('handlerClass' => $handlerClass, 'bundleName' => $bundleName, 'modelClass' => $modelClass, 'crudId' => $crudId)); }
public function execute() { $kernel = kernel(); $dirs = array(); $dirs[] = FileUtils::path_join(PH_APP_ROOT, 'cache', 'view'); $dirs[] = FileUtils::path_join(PH_APP_ROOT, 'cache', 'config'); $dirs[] = 'locale'; $dirs[] = 'applications'; $dirs[] = 'bin'; $dirs[] = 'bundles'; $dirs[] = 'config'; $dirs[] = 'webroot'; /* for hard links */ $dirs[] = 'webroot' . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'images'; $dirs[] = 'webroot' . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'css'; $dirs[] = 'webroot' . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'js'; $dirs[] = 'webroot' . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'upload'; FileUtils::mkpath($dirs, true); // TODO: create .htaccess file $this->logger->info("Changing permissions..."); $chmods = array(); $chmods[] = array("og+rw", "cache"); $chmods[] = array("og+rw", $kernel->webroot . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'upload'); foreach ($chmods as $mod) { $this->logger->info("{$mod[0]} {$mod[1]}", 1); system("chmod -R {$mod[0]} {$mod[1]}"); } $this->logger->info("Linking bin/phifty"); if (!file_exists('bin/phifty')) { symlink('../phifty/bin/phifty', 'bin/phifty'); } # init config $this->logger->info("Copying config files..."); copy_if_not_exists(FileUtils::path_join(PH_ROOT, 'config', 'framework.app.yml'), FileUtils::path_join(PH_APP_ROOT, 'config', 'framework.yml')); // copy_if_not_exists(FileUtils::path_join(PH_ROOT,'config','application.dev.yml'), FileUtils::path_join(PH_APP_ROOT,'config','application.yml') ); copy_if_not_exists(FileUtils::path_join(PH_ROOT, 'config', 'database.app.yml'), FileUtils::path_join(PH_APP_ROOT, 'config', 'database.yml')); copy_if_not_exists(FileUtils::path_join(PH_ROOT, 'webroot', 'index.php'), FileUtils::path_join(PH_APP_ROOT, 'webroot', 'index.php')); copy_if_not_exists(FileUtils::path_join(PH_ROOT, 'webroot', '.htaccess'), FileUtils::path_join(PH_APP_ROOT, 'webroot', '.htaccess')); $this->logger->info('Application is initialized, please edit your config files and run:'); echo <<<DOC \$ bin/phifty build-conf \$ bin/phifty asset \$ lazy build-conf config/database.yml DOC; }