示例#1
0
 function getConf($name)
 {
     $name = $this->_normalizeConfName($name);
     if (isset($this->confs[$name])) {
         return $this->confs[$name];
     }
     $ext = substr($name, strpos($name, '.'));
     if ($ext == '.ini') {
         $file = $this->_locateConfFiles($name);
         if (lmb_env_has('LIMB_VAR_DIR')) {
             $this->confs[$name] = new lmbCachedIni($file, lmb_env_get('LIMB_VAR_DIR') . '/ini/');
         } else {
             $this->confs[$name] = new lmbIni($file);
         }
     } elseif ($ext == '.yml') {
         $file = $this->_locateConfFiles($name);
         $this->confs[$name] = $this->parseYamlFile(lmbFs::normalizePath($file));
     } elseif ($ext == '.conf.php') {
         $file = $this->_locateConfFiles($name);
         if (!count($file)) {
             throw new lmbFileNotFoundException($name);
         }
         $this->confs[$name] = new lmbConf(lmbFs::normalizePath($file));
     } else {
         throw new lmbException("'{$ext}' type configuration is not supported!");
     }
     return $this->confs[$name];
 }
示例#2
0
 function getRootDir()
 {
     if (!($root_dir = lmb_env_get('LIMB_DOCUMENT_ROOT', false))) {
         throw new lmbMacroException('Not set require env LIMB_DOCUMENT_ROOT!');
     }
     return $root_dir;
 }
示例#3
0
    function testRequirePackageClass()
    {
        $package_name = 'require_package_source';
        $package_source_dir = lmb_env_get('LIMB_PACKAGES_DIR') . '/' . $package_name . '/src/';
        $package_class = 'SourceFileForTests';
        $this->createPackageMainFile($package_name, lmb_env_get('LIMB_PACKAGES_DIR'));
        if (!file_exists($package_source_dir)) {
            mkdir($package_source_dir);
        }
        $source_file_content = <<<EOD
<?php
class {$package_class} {
  static function increase() {
    lmbPackagesFunctionsTest::\$counter++;
  }
}
EOD;
        file_put_contents($package_source_dir . '/' . $package_class . '.class.php', $source_file_content);
        $this->assertIdentical(0, lmbPackagesFunctionsTest::$counter);
        lmb_package_require($package_name);
        $this->assertIdentical(1, lmbPackagesFunctionsTest::$counter);
        lmb_require_package_class($package_name, 'SourceFileForTests');
        call_user_func(array($package_class, 'increase'));
        $this->assertIdentical(2, lmbPackagesFunctionsTest::$counter);
    }
示例#4
0
 function createLocaleObject($locale)
 {
     $file = $this->toolkit->findFileByAlias($locale . '.ini', lmb_env_get('LIMB_LOCALE_INCLUDE_PATH'), 'i18n_locale');
     if (lmb_env_has('LIMB_VAR_DIR')) {
         return new lmbLocale($locale, new lmbCachedIni($file, lmb_env_get('LIMB_VAR_DIR') . '/locale/'));
     } else {
         return new lmbLocale($locale, new lmbIni($file));
     }
 }
 function __construct()
 {
     parent::__construct();
     $items = explode(';', lmb_env_get('LIMB_SUPPORTED_VIEW_TYPES'));
     foreach ($items as $item) {
         list($ext, $class) = explode('=', $item);
         $this->view_types[$ext] = $class;
     }
 }
示例#6
0
 function __construct($path_offset = null, $base_path = null)
 {
     $this->path_offset = lmb_env_get('LIMB_HTTP_OFFSET_PATH');
     if (!is_null($path_offset)) {
         $this->path_offset = $path_offset;
     }
     $this->base_path = lmb_env_get('LIMB_HTTP_BASE_PATH');
     if (!is_null($base_path)) {
         $this->base_path = $base_path;
     }
 }
示例#7
0
 function getLogDSNes()
 {
     $default_dsn = 'file://' . lmbFs::normalizePath(lmb_env_get('LIMB_VAR_DIR') . '/log/error.log');
     if (!$this->toolkit->hasConf('common')) {
         return array($default_dsn);
     }
     $conf = $this->toolkit->getConf('common');
     if (!isset($conf['logs'])) {
         return array($default_dsn);
     }
     return $conf['logs'];
 }
示例#8
0
/**
 * @package core
 * @version $Id$
 */
function lmb_package_require($name, $packages_dir = '')
{
    if (!$packages_dir) {
        $packages_dir = lmb_env_get('LIMB_PACKAGES_DIR');
    }
    $main_file_path = $packages_dir . $name . '/common.inc.php';
    try {
        lmb_require($packages_dir . $name . '/common.inc.php');
    } catch (lmbPHPFileNotFoundException $e) {
        lmb_require('limb/core/src/exception/lmbNoSuchPackageException.class.php');
        throw new lmbNoSuchPackageException("Package '{$name}' not found", array('name' => $name, 'dir' => $packages_dir, 'main_file' => $main_file_path));
    }
}
示例#9
0
 function __construct($config = array())
 {
     $conf = lmbToolkit::instance()->getConf('mail');
     $this->use_phpmail = $conf['use_phpmail'];
     $this->smtp_host = $conf['smtp_host'];
     $this->smtp_port = $conf['smtp_port'];
     $this->smtp_auth = $conf['smtp_auth'];
     $this->smtp_user = $conf['smtp_user'];
     $this->smtp_password = $conf['smtp_password'];
     $this->setConfig($config);
     $php_mailer_version = lmb_env_get('PHPMAILER_VERSION_NAME', 'phpmailer-5.1');
     include_once 'limb/mail/lib/' . $php_mailer_version . '/class.phpmailer.php';
 }
示例#10
0
 function testGetFilesLocator_CacheConditions()
 {
     $old_mode = lmb_env_get('LIMB_APP_MODE');
     $old_var_dir = lmb_env_get('LIMB_VAR_DIR');
     lmb_env_set('LIMB_APP_MODE', 'devel');
     lmb_env_remove('LIMB_VAR_DIR');
     $this->assertIsA($this->tools->getFileLocator('foo', 'locator1'), 'lmbFileLocator');
     lmb_env_set('LIMB_VAR_DIR', $old_var_dir);
     $this->assertIsA($this->tools->getFileLocator('foo', 'locator2'), 'lmbFileLocator');
     lmb_env_set('LIMB_APP_MODE', 'production');
     $this->assertIsA($this->tools->getFileLocator('foo', 'locator3'), 'lmbCachingFileLocator');
     lmb_env_set('LIMB_APP_MODE', $old_mode);
 }
 function testDispatchWithOffset()
 {
     $old_offset = lmb_env_get('LIMB_HTTP_OFFSET_PATH');
     $config_array = array(array('path' => ':controller/:action'));
     $routes = new lmbRoutes($config_array);
     $this->toolkit->setRoutes($routes);
     $dispatcher = new lmbRoutesRequestDispatcher();
     lmb_env_set('LIMB_HTTP_OFFSET_PATH', 'app');
     $this->request->getUri()->reset('http://example.com/app/news/admin_display');
     $result = $dispatcher->dispatch($this->request);
     $this->assertEqual($result['controller'], 'news');
     $this->assertEqual($result['action'], 'admin_display');
     lmb_env_set('LIMB_HTTP_OFFSET_PATH', $old_offset);
 }
 function testOnceRender()
 {
     $root = lmb_env_get('LIMB_VAR_DIR') . '/www/';
     lmb_env_set('LIMB_DOCUMENT_ROOT', $root);
     lmbFs::safeWrite($root . 'style/main.css', 'body {background-url: url("../images/one.jpg");}');
     lmbFs::safeWrite($root . 'images/one.jpg', 'simple content');
     $template = '{{css_compiled src="style/main.css" dir="media/css" /}}';
     $page = $this->_createMacroTemplate($template, 'tpl.html');
     $content = $page->render();
     $src = $this->toolkit->addVersionToUrl('media/css/style-main.css');
     $this->assertEqual('<link rel="stylesheet" type="text/css" href="' . $src . '" />', $content);
     $compiled_file = $root . 'media/css/style-main.css';
     $src = $this->toolkit->addVersionToUrl('images/one.jpg');
     $this->assertEqual('body {background-url: url(' . $src . ');}', file_get_contents($compiled_file));
 }
示例#13
0
 protected function _renderEditor()
 {
     include_once lmb_env_get('LIMB_CKEDITOR_DIR') . '/ckeditor.php';
     $editor = new CKeditor();
     if ($this->_helper->getOption('basePath')) {
         $editor->basePath = $this->_helper->getOption('basePath');
     } else {
         $editor->basePath = '/shared/wysiwyg/ckeditor/';
     }
     $config = array();
     if ($this->_helper->getOption('Config')) {
         $config = $this->_helper->getOption('Config');
     }
     $editor->editor($this->getAttribute('name'), $this->getValue(), $config);
 }
示例#14
0
 static function getTmpDir()
 {
     if (lmb_env_has('LIMB_VAR_DIR')) {
         return lmb_env_get('LIMB_VAR_DIR');
     }
     if ($path = session_save_path()) {
         if (($pos = strpos($path, ';')) !== false) {
             $path = substr($path, $pos + 1);
         }
         return $path;
     }
     if ($tmp = getenv('TMP') || ($tmp = getenv('TEMP') || ($tmp = getenv('TMPDIR')))) {
         return $tmp;
     }
     //gracefull falback?
     return '/tmp';
 }
 function testGzipStatic()
 {
     if (!function_exists('gzencode')) {
         return print "Skip: function gzencode not exists.\n";
     }
     lmb_env_set('LIMB_DOCUMENT_ROOT', lmb_env_get('LIMB_VAR_DIR') . '/www/');
     lmbFs::safeWrite(lmb_env_get('LIMB_VAR_DIR') . '/www/one.js', 'var window = {};');
     $doc_root = lmb_env_get('LIMB_DOCUMENT_ROOT');
     $template = '{{file:version src="one.js" gzip_static_dir="media/var/gz" gzip_level="9" }}';
     $page = $this->_createMacroTemplate($template, 'tpl.html');
     $content = $page->render();
     $file = 'media/var/gz/one.js';
     $this->assertEqual($content, $this->toolkit->addVersionToUrl($file, false));
     $this->assertEqual('var window = {};', file_get_contents($doc_root . $file));
     $gz_file = $doc_root . $file . '.gz';
     $this->assertTrue(file_exists($gz_file));
     $this->assertEqual(gzencode('var window = {};', 9, FORCE_DEFLATE), file_get_contents($gz_file));
 }
示例#16
0
function lmb_tests_init_db_dsn()
{
    lmb_env_set('LIMB_CACHE_DB_META_IN_FILE', false);
    if (lmbToolkit::instance()->isDefaultDbDSNAvailable()) {
        $dsn = lmbToolkit::instance()->getDefaultDbDSN();
        static $reported_about;
        if (is_null($reported_about) || $reported_about != $dsn) {
            $pass = $dsn->_getUri()->getPassword();
            $masked_dsn = str_replace($pass, str_pad('*', strlen($pass), '*'), $dsn->toString());
            echo "INFO: Using database '{$masked_dsn}'\n";
            $reported_about = $dsn;
        }
    } else {
        $default_value = 'sqlite://localhost/' . lmb_var_dir() . '/sqlite_tests.db';
        $dsn = lmb_env_get('LIMB_TEST_DB_DSN', $default_value);
        lmbToolkit::instance()->setDefaultDbDSN($dsn);
        echo "INFO: Using default test database '{$dsn}'\n";
    }
}
 function testNotFoundFile()
 {
     lmb_env_set('LIMB_DOCUMENT_ROOT', lmb_env_get('LIMB_VAR_DIR'));
     $template = '{{js:require_once src="js/main.js" }}';
     $page = $this->_createMacroTemplate($template, 'tpl.html');
     try {
         $page->render();
         $this->assertTrue(false);
     } catch (lmbException $e) {
         $this->assertTrue(true);
     }
     $template = '{{js:require_once src="js/main.js" safe="true" }}';
     $page = $this->_createMacroTemplate($template, 'tpl.html');
     try {
         $page->render();
         $this->assertTrue(true);
     } catch (lmbException $e) {
         $this->assertTrue(false);
     }
 }
示例#18
0
 function getFileLocator($paths, $locator_name = null)
 {
     if (!$locator_name) {
         $locator_name = md5($paths);
     }
     if (isset($this->file_locators[$locator_name])) {
         return $this->file_locators[$locator_name];
     }
     if (is_array($paths)) {
         $file_locations = new lmbIncludePathFileLocations($paths);
     } else {
         $file_locations = new lmbIncludePathFileLocations(explode(';', $paths));
     }
     if (lmb_env_has('LIMB_VAR_DIR') && 'devel' != lmb_env_get('LIMB_APP_MODE')) {
         $locator = new lmbCachingFileLocator(new lmbFileLocator($file_locations), lmb_env_get('LIMB_VAR_DIR') . '/locators/', $locator_name);
     } else {
         $locator = new lmbFileLocator($file_locations);
     }
     $this->file_locators[$locator_name] = $locator;
     return $locator;
 }
 function testNotFoundFile()
 {
     $root = lmb_env_get('LIMB_VAR_DIR') . '/www';
     lmb_env_set('LIMB_DOCUMENT_ROOT', $root);
     lmbFs::rm($root);
     $template = '{{js_combined dir="media/"}}{{js_once src="js/main.js" }}{{/js_combined}}';
     $page = $this->_createMacroTemplate($template, 'tpl.html');
     try {
         $page->render();
         $this->assertTrue(false);
     } catch (lmbException $e) {
         $this->assertTrue(true);
     }
     lmbFs::safeWrite($root . '/js/blog.js', 'function blog() {};');
     $template = '{{js_combined dir="media"}}{{js_once src="js/main.js" safe="true" }}{{js_once src="js/blog.js" }}{{/js_combined}}';
     $page = $this->_createMacroTemplate($template, 'tpl.html');
     $page->render();
     $file = array_shift(lmbFs::ls($root . '/media/'));
     $js_content = "/* include main.js - NOT FOUND */\n\n/* include blog.js */\nfunction blog() {};";
     $this->assertEqual(file_get_contents($root . '/media/' . $file), $js_content);
 }
 static function createObjectFromRecord($record, $default_class_name, $conn, $lazy_attributes = null, $use_proxy = false)
 {
     if ($path = $record->get(lmbActiveRecord::getInheritanceField())) {
         $class_name = lmbActiveRecord::getInheritanceClass($record);
         if (!class_exists($class_name)) {
             throw new lmbException("Class '{$class_name}' not found");
         }
     } else {
         $class_name = is_object($default_class_name) ? get_class($default_class_name) : $default_class_name;
     }
     if ($use_proxy || lmb_env_get('LIMB_ACTIVE_RECORD_FORCE_PROXY', false)) {
         $proxy_class = $class_name . '_ARProxy';
         lmbARProxy::generate($proxy_class, $class_name);
         return new $proxy_class($record, $class_name, $conn, $lazy_attributes);
     }
     $object = new $class_name(null, $conn);
     if (is_array($lazy_attributes)) {
         $object->setLazyAttributes($lazy_attributes);
     }
     $object->loadFromRecord($record);
     return $object;
 }
示例#21
0
 function testRemoveIncludePathWithTrailingSlashFromClassPath()
 {
     //generating class and placing it in a temp dir
     $var_dir = lmb_env_get('LIMB_VAR_DIR');
     $class = 'Foo' . mt_rand();
     file_put_contents("{$var_dir}/foo.php", "<?php class {$class} { function say() {return 'hello';} }");
     //adding temp dir to include path
     $prev_inc_path = get_include_path();
     set_include_path("{$var_dir}//" . PATH_SEPARATOR . get_include_path());
     //including class and serializing it
     include 'foo.php';
     $foo = new $class();
     $container = new lmbSerializable($foo);
     $file = $this->_writeToFile(serialize($container));
     //now moving generated class's file into subdir
     $new_dir = mt_rand();
     mkdir("{$var_dir}/{$new_dir}");
     rename("{$var_dir}/foo.php", "{$var_dir}/{$new_dir}/foo.php");
     //emulating new include path settings
     $this->assertEqual($this->_phpSerializedObjectCall($file, '->say()', "{$var_dir}/{$new_dir}"), $foo->say());
     set_include_path($prev_inc_path);
 }
示例#22
0
 function doForgotPassword()
 {
     if (!$this->request->hasPost()) {
         return;
     }
     if (!($user = lmbActiveRecord::findFirst('lmbCmsUser', array('email = ?', $this->request->get('email'))))) {
         return $this->flashError("Пользователь с таким значением email не найден", array('Field' => 'email'));
     }
     $this->useForm('password_form');
     if (!$this->error_list->isEmpty()) {
         return;
     }
     $password = $user->generatePassword();
     $user->setNewPassword($password);
     $user->setGeneratedPassword($user->getCryptedPassword($password));
     $user->saveSkipValidation();
     $template = new lmbMacroView('cms_user/forgot_password_email.txt');
     $template->set('user', $user);
     $template->set('approve_password_url', 'http://' . $_SERVER['HTTP_HOST'] . '/cms_user/approve/' . $user->getGeneratedPassword());
     $email_body = $template->render();
     $mailer = new lmbMailer();
     $mailer->sendPlainMail($user->getEmail(), lmb_env_get('ADMIN_EMAIL', "*****@*****.**"), "Password recovery", $email_body);
     $this->flashAndRedirect("Новый пароль выслан на ваш email", '/cms_user/login');
 }
示例#23
0
 function getNormalizeUrlAndVersion($file_src, $safe = false)
 {
     $doc_root = lmb_env_get('LIMB_DOCUMENT_ROOT', false);
     if (!$doc_root) {
         if ($safe) {
             return array($file_src, '00');
         } else {
             throw new lmbException('Not set require env LIMB_DOCUMENT_ROOT!');
         }
     }
     $file = $file_src;
     $path = $doc_root . '/' . $file;
     if (is_file($path) && is_readable($path)) {
         $version = crc32(file_get_contents($path));
     } else {
         if ($safe) {
             $version = 0;
         } else {
             throw new lmbException('File \'' . $file_src . '\' not found in document root (' . $doc_root . ')');
         }
     }
     $version = ($version > 0 ? '1' : '0') . base_convert(abs($version), 10, 36);
     return array($file, $version);
 }
示例#24
0
function lmb_var_dir($value = null)
{
    if ($value) {
        lmb_env_set('LIMB_VAR_DIR', $value);
    } else {
        return lmb_env_get('LIMB_VAR_DIR');
    }
}
 function isCacheEnabled()
 {
     return (bool) lmb_env_get('LIMB_INI_CACHE_ENABLED', true);
 }
示例#26
0
    lmb_env_setor('LIMB_HTTP_REQUEST_PATH', $request->getUri()->toString());
    if (!lmb_env_has('LIMB_HTTP_OFFSET_PATH')) {
        $offset = trim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
        if ($offset && $offset != '.') {
            lmb_env_setor('LIMB_HTTP_OFFSET_PATH', $offset . '/');
        } else {
            lmb_env_setor('LIMB_HTTP_OFFSET_PATH', '');
        }
    }
    if (substr(lmb_env_get('LIMB_HTTP_OFFSET_PATH'), 0, 1) == '/') {
        throw new lmbException('LIMB_HTTP_OFFSET_PATH constant must not have starting slash(' . lmb_env_get('LIMB_HTTP_OFFSET_PATH') . ')!!!');
    }
    //HTTP_BASE_PATH is defined automatically according to current host and offset settings
    lmb_env_setor('LIMB_HTTP_BASE_PATH', $request->getUri()->toString(array('protocol', 'user', 'password', 'host', 'port')) . '/' . lmb_env_get('LIMB_HTTP_OFFSET_PATH'));
    if (!lmb_env_has('LIMB_HTTP_GATEWAY_PATH')) {
        if (lmb_env_has('LIMB_ENABLE_MOD_REWRITE')) {
            lmb_env_setor('LIMB_HTTP_GATEWAY_PATH', lmb_env_get('LIMB_HTTP_BASE_PATH'));
        } else {
            lmb_env_setor('LIMB_HTTP_GATEWAY_PATH', lmb_env_get('LIMB_HTTP_BASE_PATH') . 'index.php/');
        }
    }
    lmb_env_setor('LIMB_HTTP_SHARED_PATH', lmb_env_get('LIMB_HTTP_BASE_PATH') . 'shared/');
    if (substr(lmb_env_get('LIMB_HTTP_BASE_PATH'), -1, 1) != '/') {
        echo 'LIMB_HTTP_BASE_PATH constant must have trailing slash(' . lmb_env_get('LIMB_HTTP_BASE_PATH') . ')!!!';
        exit(1);
    }
    if (substr(lmb_env_get('LIMB_HTTP_SHARED_PATH'), -1, 1) != '/') {
        echo 'LIMB_HTTP_SHARED_PATH constant must have trailing slash(' . lmb_env_get('LIMB_HTTP_SHARED_PATH') . ')!!!';
        exit(1);
    }
}
示例#27
0
 protected function _isFileCachingEnabled()
 {
     return lmb_env_get('LIMB_CACHE_DB_META_IN_FILE', false) && file_exists($this->cache_file);
 }
示例#28
0
 function _saveCache()
 {
     if ($this->map_changed && $this->isCacheEnabled()) {
         lmbFs::safeWrite(lmb_env_get('LIMB_VAR_DIR') . '/locators/controller_action2tpl.cache', serialize($this->action_template_map));
     }
 }
示例#29
0
 function getDbInfo($conn)
 {
     $id = $conn->getHash();
     if (isset($this->db_info[$id])) {
         return $this->db_info[$id];
     }
     if ($this->_isDbInfoCacheEnabled()) {
         $db_info = new lmbDbCachedInfo($conn, lmb_env_get('LIMB_VAR_DIR'));
     } else {
         $db_info = $conn->getDatabaseInfo();
     }
     $this->db_info[$id] = $db_info;
     return $this->db_info[$id];
 }
 function testToUrlWithHttpOffset()
 {
     $old_offset = lmb_env_get('LIMB_HTTP_OFFSET_PATH');
     $config = array('blog' => array('path' => '/blog', 'defaults' => array('controller' => 'Blog', 'action' => 'display')));
     $routes = new lmbRoutes($config);
     lmb_env_set('LIMB_HTTP_OFFSET_PATH', 'app');
     $this->assertEqual($routes->toUrl(array(), 'blog'), '/app/blog');
     lmb_env_set('LIMB_HTTP_OFFSET_PATH', $old_offset);
 }