Skip to content

Commit

Permalink
Squashed 'src/Pingpong/Support/' changes from f1472eb..9401c19
Browse files Browse the repository at this point in the history
9401c19 CS Fixes
22b2c64 Added Stub class to pingpong/support component
34bf6e8 Fix conflict
11144af PSR-2

git-subtree-dir: src/Pingpong/Support
git-subtree-split: 9401c19b1dbdff01606e7362b931fcffade38fb2
  • Loading branch information
Gravitano committed May 27, 2015
1 parent c9bdb12 commit 2d7f040
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 75 deletions.
9 changes: 4 additions & 5 deletions Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
use Illuminate\Support\Collection;
use Pingpong\Support\Json;

class Json {
class Json
{

/**
* The file path.
Expand Down Expand Up @@ -198,8 +199,7 @@ public function get($key, $default = null)
*/
public function __call($method, $arguments = [])
{
if (method_exists($this, $method))
{
if (method_exists($this, $method)) {
return call_user_func_array([$this, $method], $arguments);
}

Expand All @@ -215,5 +215,4 @@ public function __toString()
{
return $this->getContents();
}

}
}
155 changes: 155 additions & 0 deletions Stub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?php

namespace Pingpong\Support;

class Stub
{

/**
* The stub path.
*
* @var string
*/
protected $path;

/**
* The base path of stub file.
*
* @var null|string
*/
protected static $basePath = null;

/**
* The replacements array.
*
* @var array
*/
protected $replaces = [];

/**
* The contructor.
*
* @param string $path
* @param array $replaces
*/
public function __construct($path, array $replaces = [])
{
$this->path = $path;
$this->replaces = $replaces;
}

/**
* Create new self instance.
*
* @param string $path
* @param array $replaces
* @return self
*/
public static function create($path, array $replaces = [])
{
return new static($path, $replaces);
}

/**
* Set stub path.
*
* @param string $path
* @return self
*/
public function setPath($path)
{
$this->path = $path;

return $this;
}

/**
* Get stub path.
*
* @return string
*/
public function getPath()
{
return static::$basePath . $this->path;
}

/**
* Set base path.
*
* @param string $path
* @return void
*/
public static function setBasePath($path)
{
static::$basePath = $path;
}

/**
* Get base path.
*
* @return string|null
*/
public static function getBasePath()
{
return static::$basePath;
}

/**
* Get stub contents.
*
* @return mixed|string
*/
public function getContents()
{
$contents = file_get_contents($this->getPath());

foreach ($this->replaces as $search => $replace) {
$contents = str_replace('$' . strtoupper($search) . '$', $replace, $contents);
}

return $contents;
}

/**
* Get stub contents.
*
* @return string
*/
public function render()
{
return $this->getContents();
}

/**
* Set replacements array.
*
* @param array $replaces
* @return $this
*/
public function replace(array $replaces = [])
{
$this->replaces = $replaces;

return $this;
}

/**
* Get replacements.
*
* @return array
*/
public function getReplaces()
{
return $this->replaces;
}

/**
* Handle magic method __toString.
*
* @return string
*/
public function __toString()
{
return $this->render();
}
}
17 changes: 8 additions & 9 deletions Traits/Imageable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

namespace Pingpong\Support\Traits;

trait Imageable {
trait Imageable
{

/**
* Delete image from current instance.
*
*
* @return boolean
*/
public function deleteImage()
{
if (file_exists($path = $this->getImagePath()))
{
if (file_exists($path = $this->getImagePath())) {
@unlink($path);

return true;
Expand All @@ -23,7 +23,7 @@ public function deleteImage()

/**
* Get image path.
*
*
* @return string
*/
public function getImagePath()
Expand All @@ -33,7 +33,7 @@ public function getImagePath()

/**
* Get image url.
*
*
* @return string
*/
public function getImageUrl()
Expand All @@ -43,7 +43,7 @@ public function getImageUrl()

/**
* Accessor for "image_url".
*
*
* @param string $value
* @return string
*/
Expand All @@ -54,12 +54,11 @@ public function getImageUrlAttribute($value)

/**
* Determine whether the current file has image.
*
*
* @return boolean
*/
public function hasImage()
{
return ! empty($this->image) && file_exists($this->getImagePath());
}

}
79 changes: 40 additions & 39 deletions Traits/Publishable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,48 @@

namespace Pingpong\Support\Traits;

trait Publishable {
trait Publishable
{

/**
* Query scope for only published data.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder
*/
public function scopeOnlyPublished($query)
{
return $query->whereNotNull(self::PUBLISHED_AT);
}
/**
* Query scope for only published data.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder
*/
public function scopeOnlyPublished($query)
{
return $query->whereNotNull(self::PUBLISHED_AT);
}

/**
* Query scope for only drafted data.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder
*/
public function scopeOnlyDrafted($query)
{
return $query->whereNull(self::PUBLISHED_AT);
}
/**
* Query scope for only drafted data.
*
* @param \Illuminate\Database\Query\Builder $query
* @return \Illuminate\Database\Query\Builder
*/
public function scopeOnlyDrafted($query)
{
return $query->whereNull(self::PUBLISHED_AT);
}

/**
* Determine whether the current model/data is published.
*
* @return boolean
*/
public function published()
{
return ! $this->drafted();
}
/**
* Determine whether the current model/data is published.
*
* @return boolean
*/
public function published()
{
return ! $this->drafted();
}

/**
* Determine whether the current model/data is drafted.
*
* @return boolean
*/
public function drafted()
{
return is_null($this->{self::PUBLISHED_AT});
}
/**
* Determine whether the current model/data is drafted.
*
* @return boolean
*/
public function drafted()
{
return is_null($this->{self::PUBLISHED_AT});
}
}
Loading

0 comments on commit 2d7f040

Please sign in to comment.