Skip to content

Commit

Permalink
master : Fix Namespace and other issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Aden committed Dec 2, 2014
1 parent 342a123 commit f916df2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 41 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "adenfraser/blade-alternate",
"name": "AdenFraser/blade-alternate",
"description": "",
"authors": [
{
Expand All @@ -13,7 +13,7 @@
},
"autoload": {
"psr-0": {
"adenfraser\\BladeAlternate": "src/"
"AdenFraser\\BladeAlternate": "src/"
}
},
"minimum-stability": "dev"
Expand Down
59 changes: 30 additions & 29 deletions src/AdenFraser/BladeAlternate/BladeAlternate.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
<?php namespace adenfraser\BladeAlternate;
<?php namespace AdenFraser\BladeAlternate;

class BladeAlternate {

public $counts = array();

public function increment($key) {

if ( ! array_key_exists($key, $this->counts) ) $this->reset($key);
$this->counts[$key]++;
return $this->counts[$key];
}

public function reset($key) {
$this->counts[$key] = 0;
return $this;
}

public function choose() {

$items = func_get_args();
$index = $this->increment($key = $this->getKey() );
if ($index == count($items)) $this->reset($key);
return $items[$index - 1];
}

public function getKey() {
$bt = debug_backtrace();
$trace = $bt[1];
return "{$trace['file']}@{$trace['line']}";

}
public $counts = array();

public function increment($key)
{
if ( ! array_key_exists($key, $this->counts) ) $this->reset($key);
$this->counts[$key]++;
return $this->counts[$key];
}

public function reset($key)
{
$this->counts[$key] = 0;
return $this;
}

public function choose()
{
$items = func_get_args();
$index = $this->increment($key = $this->getKey() );
if ($index == count($items)) $this->reset($key);
return $items[$index - 1];
}

public function getKey()
{
$bt = debug_backtrace();
$trace = $bt[1];
return "{$trace['file']}@{$trace['line']}";
}

}
18 changes: 8 additions & 10 deletions src/AdenFraser/BladeAlternate/BladeAlternateServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php namespace adenfraser\BladeAlternate;
<?php namespace AdenFraser\BladeAlternate;

use Illuminate\Support\ServiceProvider;

Expand All @@ -24,32 +24,30 @@ public function register()
$this->registerBladeExtension();
}

public function registerAlternate() {

$this->app->singleton('blade.alternator', 'adenfraser\BladeAlternate\BladeAlternate');

public function registerAlternate()
{
$this->app->singleton('blade.alternate', 'AdenFraser\BladeAlternate\BladeAlternate');
}

public function registerBladeExtension() {

public function registerBladeExtension()
{
$compiler = $this->app['view.engine.resolver']->resolve('blade')->getCompiler();
$compiler->extend(function($value, $blade){

$pattern = $blade->createMatcher('alternate');
return preg_replace($pattern, "$1<?php echo app('blade.alternator')->choose$2; ?>", $value);
return preg_replace($pattern, "$1<?php echo app('blade.alternate')->choose$2; ?>", $value);
});

}


/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('blade.alternator');
return array('blade.alternate');
}

}

0 comments on commit f916df2

Please sign in to comment.