Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Asset provider. Added simple Logger.
- Loading branch information
Showing
6 changed files
with
151 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Phpsog; | ||
|
||
/** | ||
* | ||
* @author Marc Ermshaus <marc@ermshaus.org> | ||
*/ | ||
class Logger | ||
{ | ||
public function log($text) | ||
{ | ||
echo $text . "\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace Phpsog\Provider\Asset; | ||
|
||
use Phpsog\Exporter; | ||
use SplFileInfo; | ||
use Kaloa\Filesystem\PathHelper; | ||
|
||
/** | ||
* | ||
* @author Marc Ermshaus <marc@ermshaus.org> | ||
*/ | ||
class Provider | ||
{ | ||
/** | ||
* | ||
* @var array | ||
*/ | ||
protected $config; | ||
|
||
/** | ||
* | ||
* @var Exporter | ||
*/ | ||
protected $exporter; | ||
|
||
/** | ||
* | ||
* @var PathHelper | ||
*/ | ||
protected $pathHelper; | ||
|
||
/** | ||
* | ||
* @param array $config | ||
* @param Exporter $exporter | ||
* @param PathHelper $pathHelper | ||
*/ | ||
public function __construct(array $config, Exporter $exporter, | ||
PathHelper $pathHelper) | ||
{ | ||
$this->config = $config; | ||
$this->exporter = $exporter; | ||
$this->pathHelper = $pathHelper; | ||
} | ||
|
||
/** | ||
* | ||
* @param SplFileInfo $file | ||
*/ | ||
public function compile(SplFileInfo $file) | ||
{ | ||
$file = $file->getPathname(); | ||
$config = $this->config; | ||
|
||
$relativePath = substr($file, strlen($config['project.dir'] | ||
. '/' . $config['resources.dir'] . '/')); | ||
|
||
$exportPath = $config['project.dir'] . '/' . $config['export.dir'] | ||
. '/' . pathinfo($relativePath, PATHINFO_DIRNAME) | ||
. '/' . basename($relativePath); | ||
|
||
$content = file_get_contents($file); | ||
|
||
$this->exporter->export($exportPath, $content); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
if ((!@include __DIR__.'/../../.composer/autoload.php') && (!@include __DIR__.'/vendor/.composer/autoload.php')) { | ||
die('You must set up the project dependencies, run the following commands:'.PHP_EOL. | ||
'curl -s http://getcomposer.org/installer | php'.PHP_EOL. | ||
'php composer.phar install'.PHP_EOL); | ||
if ( | ||
(!@include __DIR__.'/../../.composer/autoload.php') | ||
&& (!@include __DIR__.'/vendor/.composer/autoload.php') | ||
) { | ||
die('You must set up the project dependencies, run the following commands:' | ||
."\n". | ||
'curl -s http://getcomposer.org/installer | php'."\n". | ||
'php composer.phar install'."\n"); | ||
} | ||
|
||
use Phpsog\Application; | ||
use Phpsog\Exporter; | ||
use Phpsog\Logger; | ||
use Kaloa\Filesystem\PathHelper; | ||
|
||
try { | ||
$params = array( | ||
'config' => '' | ||
); | ||
|
||
if ($argc !== 2) { | ||
$dispatched = false; | ||
|
||
if ($_SERVER['argc'] !== 2) { | ||
throw new Exception('Wrong argument count'); | ||
} else { | ||
$params['config'] = $argv[1]; | ||
if ($_SERVER['argv'][1] === '--version') { | ||
echo 'phpsog ' . Application::VERSION . "\n"; | ||
$dispatched = true; | ||
} else { | ||
$params['config'] = $_SERVER['argv'][1]; | ||
} | ||
} | ||
|
||
if (is_dir($params['config'])) { | ||
$params['config'] .= '/phpsog.ini'; | ||
} | ||
if (!$dispatched) { | ||
if (is_dir($params['config'])) { | ||
$params['config'] .= '/phpsog.ini'; | ||
} | ||
|
||
$ph = new PathHelper(); | ||
$ph = new PathHelper(); | ||
$logger = new Logger(); | ||
|
||
$phpsog = new Application(new Exporter($ph), $ph); | ||
$phpsog = new Application(new Exporter($ph, $logger), $ph); | ||
|
||
$phpsog->loadConfig($params['config']); | ||
$phpsog->loadConfig($params['config']); | ||
|
||
$phpsog->sanitizeEnvironment(); | ||
$phpsog->sanitizeEnvironment(); | ||
|
||
$phpsog->processHtmlProvider(); | ||
$phpsog->processResources(); | ||
$phpsog->processHtmlProvider(); | ||
$phpsog->processResources(); | ||
} | ||
|
||
} catch (Exception $e) { | ||
die('Error: ' . $e->getMessage() . PHP_EOL); | ||
die('Error: ' . $e->getMessage() . "\n"); | ||
} |