Skip to content

Commit

Permalink
[#12591] - Merging changes
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed May 12, 2019
1 parent 63faab5 commit 9fdf80e
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 1,791 deletions.
233 changes: 133 additions & 100 deletions phalcon/Assets/Asset.zep
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class Asset implements AssetInterface
*/
protected attributes { get };

/**
* @var bool
*/
protected autoVersion = false { set };
/**
* @var bool
*/
Expand Down Expand Up @@ -61,6 +65,12 @@ class Asset implements AssetInterface
*/
protected type { get };

/**
* Version of resource
* @var string
*/
protected version { get, set };

/**
* Phalcon\Assets\Asset constructor
*/
Expand All @@ -69,94 +79,30 @@ class Asset implements AssetInterface
string path,
bool local = true,
bool filter = true,
array attributes = []
array attributes = [],
string version = null,
bool autoVersion = false
) -> void
{
let this->type = type,
this->path = path,
this->local = local,
this->filter = filter,
this->attributes = attributes;
}

/**
* Sets the asset's type
*/
public function setType(string type) -> <AssetInterface>
{
let this->type = type;

return this;
}

/**
* Sets the asset's path
*/
public function setPath(string path) -> <AssetInterface>
{
let this->path = path;

return this;
}

/**
* Sets if the asset is local or external
*/
public function setLocal(bool local) -> <AssetInterface>
{
let this->local = local;

return this;
let this->type = type,
this->path = path,
this->local = local,
this->filter = filter,
this->attributes = attributes,
this->version = version,
this->autoVersion = autoVersion;
}

/**
* Sets if the asset must be filtered or not
*/
public function setFilter(bool filter) -> <AssetInterface>
{
let this->filter = filter;

return this;
}

/**
* Sets extra HTML attributes
*/
public function setAttributes(array attributes) -> <AssetInterface>
{
let this->attributes = attributes;

return this;
}

/**
* Sets a target uri for the generated HTML
*/
public function setTargetUri(string targetUri) -> <AssetInterface>
{
let this->targetUri = targetUri;

return this;
}

/**
* Sets the asset's source path
* Gets the asset's key.
*/
public function setSourcePath(string sourcePath) -> <AssetInterface>
public function getAssetKey() -> string
{
let this->sourcePath = sourcePath;

return this;
}
var key;

/**
* Sets the asset's target path
*/
public function setTargetPath(string targetPath) -> <AssetInterface>
{
let this->targetPath = targetPath;
let key = this->getType() . ":" . this->getPath();

return this;
return md5(key);
}

/**
Expand Down Expand Up @@ -207,22 +153,6 @@ class Asset implements AssetInterface
return content;
}

/**
* Returns the real target uri for the generated HTML
*/
public function getRealTargetUri() -> string
{
var targetUri;

let targetUri = this->targetUri;

if empty targetUri {
let targetUri = this->path;
}

return targetUri;
}

/**
* Returns the complete location where the asset is located
*/
Expand Down Expand Up @@ -280,14 +210,117 @@ class Asset implements AssetInterface
}

/**
* Gets the asset's key.
* Returns the real target uri for the generated HTML
*/
public function getAssetKey() -> string
public function getRealTargetUri() -> string
{
var key;
var modificationTime, targetUri, version;

let key = this->getType() . ":" . this->getPath();
let targetUri = this->targetUri;

return md5(key);
if empty targetUri {
let targetUri = this->path;
}

let version = this->version;

if this->autoVersion && this->local {
let modificationTime = filemtime(this->getRealSourcePath()),
version = version ? version . "." . modificationTime : modificationTime;
}

if version {
let targetUri = targetUri . "?ver=" . version;
}

return targetUri;
}

/**
* Checks if resource is using auto version
*/
public function isAutoVersion() -> bool
{
return this->autoVersion;
}

/**
* Sets extra HTML attributes
*/
public function setAttributes(array attributes) -> <AssetInterface>
{
let this->attributes = attributes;

return this;
}

/**
* Sets if the asset must be filtered or not
*/
public function setFilter(bool filter) -> <AssetInterface>
{
let this->filter = filter;

return this;
}

/**
* Sets if the asset is local or external
*/
public function setLocal(bool local) -> <AssetInterface>
{
let this->local = local;

return this;
}

/**
* Sets the asset's source path
*/
public function setSourcePath(string sourcePath) -> <AssetInterface>
{
let this->sourcePath = sourcePath;

return this;
}

/**
* Sets the asset's target path
*/
public function setTargetPath(string targetPath) -> <AssetInterface>
{
let this->targetPath = targetPath;

return this;
}

/**
* Sets a target uri for the generated HTML
*/
public function setTargetUri(string targetUri) -> <AssetInterface>
{
let this->targetUri = targetUri;

return this;
}

/**
* Sets the asset's type
*/
public function setType(string type) -> <AssetInterface>
{
let this->type = type;

return this;
}

/**
* Sets the asset's path
*/
public function setPath(string path) -> <AssetInterface>
{
let this->path = path;

return this;
}
}
11 changes: 9 additions & 2 deletions phalcon/Assets/Asset/Css.zep
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ class Css extends AssetBase
/**
* Phalcon\Assets\Asset\Css
*/
public function __construct(string! path, bool local = true, bool filter = true, array attributes = []) -> void
public function __construct(
string! path,
bool local = true,
bool filter = true,
array attributes = [],
string version = null,
bool autoVersion = false
) -> void
{
parent::__construct("css", path, local, filter, attributes);
parent::__construct("css", path, local, filter, attributes, version, autoVersion);
}
}
11 changes: 9 additions & 2 deletions phalcon/Assets/Asset/Js.zep
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ class Js extends AssetBase
/**
* Phalcon\Assets\Asset\Js
*/
public function __construct(string! path, bool local = true, bool filter = true, array attributes = []) -> void
public function __construct(
string! path,
bool local = true,
bool filter = true,
array attributes = [],
string version = null,
bool autoVersion = false
) -> void
{
parent::__construct("js", path, local, filter, attributes);
parent::__construct("js", path, local, filter, attributes, version, autoVersion);
}
}
Loading

0 comments on commit 9fdf80e

Please sign in to comment.