Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Removed the template loader
Browse files Browse the repository at this point in the history
  • Loading branch information
eexit committed May 5, 2012
1 parent ff8870a commit 9264a8f
Showing 1 changed file with 0 additions and 48 deletions.
48 changes: 0 additions & 48 deletions lib/Smak/Portfolio/Silex/Provider/SmakServiceProvider.php
Expand Up @@ -2,12 +2,10 @@

namespace Smak\Portfolio\Silex\Provider;

use Smak\Portfolio\Set;
use Smak\Portfolio\Collection;
use Silex\Application;
use Silex\ServiceProviderInterface;


/**
* SmakServiceProvider.php
*
Expand Down Expand Up @@ -35,55 +33,9 @@ public function register(Application $app)
throw new SmakServiceProviderException('"smak.portfolio.public_path" parameter is mandatory!');
}

// Checks the presence of required parameter
if (empty($app['smak.portfolio.view_path'])) {
throw new SmakServiceProviderException('"smak.portfolio.view_path" parameter is mandatory!');
}

// Twig MUST be registered BEFORE
if (empty($app['twig.path'])) {
throw new SmakServiceProviderException('Twig is required for Smak Portfolio to run properly!');
}

// Registers the application
$app['smak.portfolio'] = $app->share(function() use ($app) {
return new Collection($app['smak.portfolio.content_path']);
});

// Set loader Silex helper
$app['smak.portfolio.load'] = $app->protect(function($set) use ($app) {
if (null == $set->getTemplate() || 0 == $set->count()) {
return false;
}

$set->smak_subpath = dirname(substr($set->getSplInfo()->getRealPath(), strlen(realpath($app['smak.portfolio.content_path']))));

$final_view = $app['smak.portfolio.view_path']
. $set->smak_subpath
. DIRECTORY_SEPARATOR
. $set->getTemplate()->getBasename();

// Checks if the templace view file exists in the destination view path
// or checks if not outdated
if (!is_file($final_view)
|| (sha1_file($set->getTemplate()->getRealPath()) !== sha1_file($final_view))) {

if (!is_dir($app['smak.portfolio.view_path'] . $set->smak_subpath)) {
// Tries the create the parents directories for the view file
if (!mkdir($app['smak.portfolio.view_path'] . $set->smak_subpath, 0700, true)) {
throw new SmakServiceProviderException(sprintf('Unable to create the directory for view file: "%s!"', $set->getTemplate()->getBasename()));
}
}

// Tries to copy the view file
if (!copy($set->getTemplate()->getRealPath(), $final_view)) {
throw new SmakServiceProviderException(sprintf('Unable to copy view file: "%s!"', $set->getTemplate()->getBasename()));
}
}

$twig_view_path = sprintf('%s%s', substr($app['smak.portfolio.view_path'], strlen($app['twig.path'])), $set->smak_subpath);
$set->twig_subpath = sprintf('%s%s%s', $twig_view_path, DIRECTORY_SEPARATOR, $set->getTemplate()->getFilename());
return $set;
});
}
}

0 comments on commit 9264a8f

Please sign in to comment.