Skip to content

sonicradish/SlimPackage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SlimPackage

SlimPackage is a bundling of the following projects

Adjustments/hacks

To get these three layers working together (or for personal enjoyment) the following adjustments/hacks were made:

1. To vendor/php-activerecord/lib/model.php

to make PHPActiveRecord work with the Twig templating engine the __isset() function and set_timestamps() functions were changed

<?php
/**
 * Determines if an attribute exists for this {@link Model}.
 *
 * @param string $attribute_name
 * @return boolean
 */
public function __isset($attribute_name)
{
	return array_key_exists($attribute_name,$this->attributes) 
		|| array_key_exists($attribute_name,static::$alias_attribute)
		|| method_exists($this, "attributes");
}

/**
 * Updates a model's timestamps.
 */
public function set_timestamps()
{
	$now = date('Y-m-d H:i:s');
	try {
		$this->updated_at = $now;
	} catch (UndefinedPropertyException $e) {
			
	}
	try {
		if($this->is_new_record()) {
			$this->created_at = $now;
		}
	} catch (UndefinedPropertyException $e) {
	}

}

2. incorporated Slim-Extras/TwigView.php

This is an extension to get the Slim framework to work with Twig templating engine

2.1 To the TwigView extension the following adjustments were made

2.1.1 Added a static twigFunctions array for easy setting of TwigFunctions and easy loading of Twigfunctions in getEnvironment()
/**
 * @var TwigFunction the custom functions you want to load
 * @param functionName alias for the function
 * @param function the actual function (can be a static class method)
 */
public static $twigFunctions = array();
/**
 * @var TwigEnvironment The Twig environment for rendering templates.
 */
private $twigEnvironment = null;

/**
 * Creates new TwigEnvironment if it doesn't already exist, and returns it.
 *
 * @return Twig_Environment
 */
public function getEnvironment() {
    if ( !$this->twigEnvironment ) {
        require_once self::$twigDirectory . '/Autoloader.php';
        Twig_Autoloader::register();
        $loader = new Twig_Loader_Filesystem($this->getTemplatesDirectory());
        $this->twigEnvironment = new Twig_Environment(
            $loader,
            self::$twigOptions
        );
        
        foreach (self::$twigFunctions as $function) {
        	$this->twigEnvironment->addFunction($function['functionName'], new Twig_Function_Function($function['function']));	            
        }
        
        
        $extension_autoloader = dirname(__FILE__) . '/Extension/TwigAutoloader.php';
        if (file_exists($extension_autoloader)) {
            require_once $extension_autoloader;
            Twig_Extensions_Autoloader::register();

            foreach (self::$twigExtensions as $ext) {
                $this->twigEnvironment->addExtension(new $ext);
            }
        }
    }
    return $this->twigEnvironment;
}
2.1.2 getRender() function added just to catch the result of a template render
public function getRender($template, $data) {
	$env = $this->getEnvironment();
	$template = $env->loadTemplate($template);
	$data = array_merge($data, $this->data);
	return $template->render($data);
}

About

MVC combo of Slim(C) + PHPActiveRecord(M) + Twig(V) + Twitter Bootstrap(V).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 93.1%
  • PHP 6.9%