예제 #1
0
 public function testPathResolver()
 {
     $fs = new Filesystem();
     $root = $this->_root . '/';
     $virtPath = new Path();
     $virtPath->set('default', $root);
     runBench(array('new path (new obj and dir)' => function () use($fs, $root) {
         $newDir = $root . mt_rand();
         $fs->mkdir($newDir);
         // start
         $virtPath = new Path();
         $virtPath->set('default', $newDir);
         $result = $virtPath->get('default:');
         // end
         return $result;
     }, 'same path (new)' => function () use($fs, $root) {
         $virtPath = new Path();
         $virtPath->set('default', $root);
         $result = $virtPath->get('default:');
         return $result;
     }, 'same path' => function () use($fs, $root, $virtPath) {
         $result = $virtPath->get('default:');
         return $result;
     }), array('count' => 1000, 'name' => 'path resolver'));
 }
예제 #2
0
파일: Lang.php 프로젝트: jbzoo/lang
 /**
  * @param string $module
  * @param string $format
  * @return Data
  */
 protected function _listFactory($module, $format)
 {
     $key = $module . '.' . $format;
     if ($list = $this->_storage->get($key)) {
         return $list;
     }
     if ($module === self::DEFAULT_MODULE) {
         $path = $module . ':langs/' . $this->_code . '.' . $format;
     } else {
         $path = $module . ':langs/' . $this->_code . '.' . $module . '.' . $format;
     }
     $listPath = $this->_path->get($path);
     // @codeCoverageIgnoreStart
     if ('php' === $format) {
         $list = new PHPArray($listPath);
     } elseif ('json' === $format) {
         $list = new JSON($listPath);
     } elseif ('ini' === $format) {
         $list = new Ini($listPath);
     } elseif ('yml' === $format) {
         $list = new Yml($listPath);
     } else {
         $list = new Data([]);
     }
     // @codeCoverageIgnoreEnd
     $this->_storage->set($key, $list);
     return $list;
 }
예제 #3
0
 /**
  * Setup test data
  */
 public function setUp()
 {
     $_SERVER['HTTP_HOST'] = 'test.dev';
     $_SERVER['REQUEST_URI'] = '/request';
     $this->_fixtPath = PROJECT_ROOT . '/tests/fixtures';
     $this->_cachePath = PROJECT_ROOT . '/build/cache';
     // cleanup
     $this->_fs = new Filesystem();
     $this->_fs->remove($this->_cachePath);
     $this->_fs->mkdir($this->_cachePath);
     // Prepare lib
     $this->_path = new Path();
     $this->_path->setRoot($this->_fixtPath);
     $this->_path->set('assets', 'root:assets');
     $this->_manager = new Manager($this->_path);
     $this->_factory = $this->_manager->getFactory();
     $this->_collection = $this->_manager->getCollection();
 }
예제 #4
0
파일: Cms.php 프로젝트: JBZoo/CrossCMS
 /**
  * Cms constructor.
  * @param array $values
  */
 public function __construct(array $values = array())
 {
     parent::__construct($values);
     $this['type'] = $this->_getCMSType();
     $this['ns'] = __NAMESPACE__ . '\\' . $this['type'] . '\\';
     $this['db'] = function ($cms) {
         SqlBuilder::set($cms['type']);
         // init SQLBuilder Driver
         $className = $cms['ns'] . 'Database';
         $database = new $className($cms);
         return $database;
     };
     $this['path'] = function ($cms) {
         $className = $cms['ns'] . 'Path';
         /** @var AbstractPath $helper */
         $helper = new $className($cms);
         $path = Path::getInstance('crosscms');
         $path->setRoot($helper->getRoot());
         $preDefinedPaths = ['upload' => $helper->getUpload(), 'cache' => $helper->getCache(), 'tmpl' => $helper->getTmpl(), 'logs' => $helper->getLogs(), 'tmp' => $helper->getTmp(), 'crosscms' => __DIR__ . '/../src'];
         foreach ($preDefinedPaths as $alias => $pathValue) {
             if (!is_dir($pathValue)) {
                 mkdir($pathValue, 0755, true);
             }
             $path->set($alias, $pathValue);
         }
         return $path;
     };
     $this['events'] = function ($cms) {
         $eventManager = new EventManager();
         $className = $cms['ns'] . 'Events';
         $helper = new $className($cms, $eventManager);
         return $helper;
     };
     $this['lang'] = function ($cms) {
         $className = $cms['ns'] . 'Lang';
         /** @var AbstractLang $helper */
         $helper = new $className($cms);
         $lang = new Lang($helper->getCode());
         $helper->setCustomLang($lang);
         return $helper;
     };
 }
예제 #5
0
 public function testGetRoot()
 {
     $dir = __DIR__;
     $path = new Path();
     $path->setRoot($dir);
     $manager = new Manager($path);
     isSame(FS::clean($dir), FS::clean($manager->getPath()->getRoot()));
 }
예제 #6
0
define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp');
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
define('CAKE', CORE_PATH . 'src' . DS);
//  Create test app folders.
$folder = new Folder();
$folder->create(LOGS, 0777);
$folder->create(SESSIONS, 0777);
$folder->create(CACHE, 0777);
$folder->create(CACHE . 'view', 0777);
$folder->create(CACHE . 'models', 0777);
date_default_timezone_set('UTC');
mb_internal_encoding('UTF-8');
//  Include CakePHP framework.
/** @noinspection PhpIncludeInspection */
require_once CAKE_CORE_INCLUDE_PATH . '/config/bootstrap.php';
$path = Path::getInstance();
//  Load union core plugin.
Plugin::load('Union/Core', ['routes' => true, 'bootstrap' => true]);
$path->setRoot(APP_ROOT);
$path->set('cache', ASSETS_CACHE);
$path->set('Union/Core', ROOT);
//  Write union test application config.
Configure::write('debug', true);
Configure::write('App', ['namespace' => 'TestApp', 'encoding' => 'UTF-8', 'base' => false, 'baseUrl' => env('SCRIPT_NAME'), 'dir' => APP_DIR, 'fullBaseUrl' => 'http://localhost', 'locale' => 'ru_RU', 'paths' => ['plugins' => [APP_ROOT . 'Plugins' . DS], 'templates' => [APP . 'Template' . DS, ROOT . '/vendor/union-cms/core/src/Template/'], 'locales' => [APP . 'Locale' . DS]]]);
Configure::write('Theme', ['site' => 'Site', 'admin' => 'Admin']);
Configure::write('Session', ['defaults' => 'php']);
//  Write configure for cache model.
Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cms_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cms_model_', 'serialize' => true]]);
//  Ensure default test connection is defined.
if (!getenv('db_dsn')) {
    putenv('db_dsn=sqlite:///:memory:');
예제 #7
0
파일: PathTest.php 프로젝트: JBZoo/Path
 public function testRootPreDefinedAlias()
 {
     $path = new Path(__DIR__);
     $curFile = basename(__FILE__);
     $this->_is(__FILE__, $path->get('root:' . $curFile));
 }
예제 #8
0
파일: Plugin.php 프로젝트: UnionCMS/Core
 /**
  * Loads a plugin.
  *
  * @param string $plugin
  * @param array $config
  * @return void
  */
 public static function load($plugin, array $config = [])
 {
     $config += ['events' => false];
     parent::load($plugin, $config);
     if (self::loaded($plugin)) {
         $path = self::path($plugin);
         Union::mergeConfig('App.paths.locales', $path . 'src' . DS . 'Locale' . DS);
         Path::getInstance()->set($plugin, $path);
     }
     self::events($plugin);
 }
예제 #9
0
파일: bootstrap.php 프로젝트: UnionCMS/Core
 *
 * This file is part of the of the simple cms based on CakePHP 3.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package   Core
 * @license   MIT
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
 * @link      https://github.com/UnionCMS/Core
 * @author    Sergey Kalistratov <*****@*****.**>
 */
use JBZoo\Path\Path;
use Cake\Core\Configure;
use Union\Core\Utility\Hook;
//  Set virtual file system.
$path = Path::getInstance('default');
$path->setRoot(ROOT);
/**
 * Union CMS configuration.
 *
 * - docDir     - html document dir
 * - iconPrefix - icon class prefix (Default is "Awesome Font")
 * - btnPrefix  - button prefix (Default is "Bootstrap Framework)
 */
Configure::write('Union', ['docDir' => 'ltr', 'iconPref' => 'fa', 'btnPref' => 'btn', 'lineTab' => '    ']);
Configure::write('Cache.defaultConfig', ['className' => 'File', 'duration' => '+1 hour', 'path' => CACHE . 'queries' . DS, 'prefix' => 'un_']);
/** @noinspection PhpIncludeInspection */
require_once dirname(__DIR__) . DS . 'src' . DS . 'functions.php';
/** @noinspection PhpIncludeInspection */
require_once __DIR__ . DS . 'defines.php';
//  Load union core events configure.
예제 #10
0
파일: Html.php 프로젝트: JBZoo/Html
 /**
  * Html constructor.
  */
 public function __construct()
 {
     parent::__construct(array());
     $path = Path::getInstance(Html::PATH_KEY);
     $path->add(__DIR__ . '/' . Html::RENDER_DIR, 'core');
 }