Example #1
0
 public function &set_translation_domain($component_name)
 {
     // If no component name is set, then it's from the core
     // translations are going to get searched.
     if (!$component_name) {
         $component_name = 'midgardmvc_core';
     }
     // Checking if TAL translator is already available
     if (isset($this->tr[$component_name])) {
         // useDomain must be called. Otherwise gettext context is not changed
         $this->tr[$component_name]->useDomain($component_name);
         return $this->tr[$component_name];
     }
     try {
         $this->tr[$component_name] = new PHPTAL_GetTextTranslator();
         $this->tr[$component_name]->setLanguage($this->language . '.utf8', $this->language);
     } catch (Exception $e) {
         echo $e;
     }
     // register gettext domain to use
     $path = midgardmvc_core::get_component_path($component_name) . '/locale/';
     $this->tr[$component_name]->addDomain($component_name, $path);
     // specify current domain
     $this->tr[$component_name]->useDomain($component_name);
     return $this->tr[$component_name];
 }
 public function setUp()
 {
     $path = midgardmvc_core::get_component_path('midgardmvc_core') . '/configuration/defaults.yml';
     $yaml = file_get_contents($path);
     $this->testConfiguration = midgardmvc_core::read_yaml($yaml);
     parent::setUp();
 }
Example #3
0
 public function __construct($name, array $manifest)
 {
     $this->path = midgardmvc_core::get_component_path($name);
     $this->name = $name;
     $this->manifest = $manifest;
     if ($manifest['extends']) {
         $this->parent = midgardmvc_core::get_instance()->component->get($manifest['extends']);
     }
     array_walk($manifest['observations'], array($this, 'register_observation'));
 }
 public function test_get_element_include()
 {
     $request = midgardmvc_core_request::get_for_intent('/subdir');
     $routes = midgardmvc_core::get_instance()->component->get_routes($request);
     $request->set_route($routes['index']);
     midgardmvc_core::get_instance()->context->create($request);
     $original_element = file_get_contents(midgardmvc_core::get_component_path('midgardmvc_core') . '/templates/ROOT.xhtml');
     $element = midgardmvc_core::get_instance()->templating->get_element($this->_core->context->get_request(), 'ROOT');
     $this->assertNotEquals($original_element, $element, 'Template returned by templating service should not be the same as the template file because of includes');
     $this->assertTrue(strpos($element, '<h1 property="mgd:title" tal:content="current_component/object/title">Title</h1>') !== false);
     midgardmvc_core::get_instance()->context->delete();
 }
Example #5
0
<?php

/**
 * @package midgardmvc_core
 * @author The Midgard Project, http://www.midgard-project.org
 * @copyright The Midgard Project, http://www.midgard-project.org
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 */
require_once midgardmvc_core::get_component_path('midgardmvc_core') . '/services/cache.php';
/**
 * Midgard cache backend.
 *
 * This cache backend stores cached data to host's parameter
 * Primary use for the backend is for testing and developing purposes
 *
 * @package midgardmvc_core
 */
class midgardmvc_core_services_cache_midgard extends midgardmvc_core_services_cache_base implements midgardmvc_core_services_cache
{
    private $cache_object = null;
    public function __construct()
    {
        parent::__construct();
        $this->cache_object = midgardmvc_core::get_instance()->hierarchy->get_root_node()->get_object();
    }
    public function put($module, $identifier, $data)
    {
        return;
        $this->cache_object->set_parameter("midgardmvc_core_services_cache_midgard:{$module}", $identifier, serialize($data));
    }
    public function get($module, $identifier)
Example #6
0
<?php

/**
 * @package midgardmvc_core
 * @author The Midgard Project, http://www.midgard-project.org
 * @copyright The Midgard Project, http://www.midgard-project.org
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 */
include midgardmvc_core::get_component_path('midgardmvc_core') . '/services/cache.php';
/**
 * memcached cache backend.
 * 
 * Backend requires Memcache PECL package for PHP, and memcached to be running.
 *
 * @package midgardmvc_core
 */
class midgardmvc_core_services_cache_memcached extends midgardmvc_core_services_cache_base implements midgardmvc_core_services_cache
{
    private $memcache;
    private $name;
    private $memcache_operational = false;
    public function __construct()
    {
        if (!extension_loaded('memcache')) {
            throw new Exception('memcached cache configured but "Memcache" PHP extension not installed.');
        }
        $this->memcache = new Memcache();
        $this->memcache_operational = @$this->memcache->pconnect('localhost', 11211);
        if (!isset(midgardmvc_core::get_instance()->context->host)) {
            $this->name = 'MidgardMVC';
        } else {
Example #7
0
<?php

/**
 * @package midgardmvc_core
 * @author The Midgard Project, http://www.midgard-project.org
 * @copyright The Midgard Project, http://www.midgard-project.org
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 */
include midgardmvc_core::get_component_path('midgardmvc_core') . '/services/uimessages.php';
/**
 * Basic UI Message class
 *
 * @package midgardmvc_core
 */
class midgardmvc_core_services_uimessages_midgard extends midgardmvc_core_services_uimessages_baseclass implements midgardmvc_core_services_uimessages
{
    private $configuration = array();
    private $jsconfiguration = '{}';
    /**
     * The current message stack
     *
     * @var Array
     * @access private
     */
    private $message_stack = array();
    /**
     * List of messages retrieved from session to avoid storing them again
     *
     * @var Array
     * @access private
     */
Example #8
0
 private function load_all_manifests()
 {
     // Load manifests enabled in site configuration and cache them
     $components = midgardmvc_core::get_instance()->configuration->components;
     foreach ($components as $component => $setup_info) {
         $component_path = midgardmvc_core::get_component_path($component);
         if (!file_exists("{$component_path}/manifest.yml")) {
             throw new Exception("Component {$component} specified in application configuration is not installed");
         }
         $this->manifests[$component] = $this->load_manifest_file($component, "{$component_path}/manifest.yml");
     }
 }
Example #9
0
 public static function write_yaml($yaml)
 {
     if (empty($yaml)) {
         return '';
     }
     static $use_yaml = null;
     static $yaml_function = null;
     if (is_null($use_yaml)) {
         // Check for YAML extension
         if (extension_loaded('yaml')) {
             $yaml_function = 'yaml_emit';
             $use_yaml = true;
         } elseif (extension_loaded('syck')) {
             $yaml_function = 'syck_dump';
             $use_yaml = true;
         }
         if (!$use_yaml) {
             // YAML PHP extension is not loaded, include the pure-PHP implementation
             if (!class_exists('sfYaml')) {
                 require midgardmvc_core::get_component_path('midgardmvc_core') . '/helpers/sfYaml/sfYaml.php';
             }
         }
     }
     if (!$use_yaml) {
         return sfYaml::dump($yaml);
     }
     return $yaml_function($yaml);
 }
Example #10
0
 public function test_get_description()
 {
     $component = midgardmvc_core::get_instance()->component->get('midgardmvc_core');
     $original = file_get_contents(midgardmvc_core::get_component_path('midgardmvc_core') . '/README.md');
     $this->assertEquals($original, $component->get_description());
 }
Example #11
0
 /**
  * Helper for module initialization. Usually called via getters
  *
  * @param string $module Name of module to load
  */
 private function load_module($module)
 {
     if (isset($this->modules[$module])) {
         return;
     }
     $module_file = midgardmvc_core::get_component_path('midgardmvc_core') . "/services/cache/module/{$module}.php";
     if (!file_exists($module_file)) {
         throw new Exception("Cache module {$module} not installed");
     }
     $module_class = "midgardmvc_core_services_cache_module_{$module}";
     $module_config = array();
     if (isset($this->configuration["module_{$module}"])) {
         $module_config = $this->configuration["module_{$module}"];
     }
     $this->modules[$module] = new $module_class($module_config);
 }