Skip to content

Commit

Permalink
[phalcon#13915] - CS work on the annotations classes
Browse files Browse the repository at this point in the history
  • Loading branch information
niden committed Mar 23, 2019
1 parent e4fa00f commit 4a38f44
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 207 deletions.
94 changes: 47 additions & 47 deletions phalcon/annotations/adapter.zep
Expand Up @@ -25,28 +25,9 @@ use Phalcon\Annotations\ReaderInterface;
abstract class Adapter implements AdapterInterface
{

protected _reader;
protected reader;

protected _annotations;

/**
* Sets the annotations parser
*/
public function setReader(<ReaderInterface> reader)
{
let this->_reader = reader;
}

/**
* Returns the annotation reader
*/
public function getReader() -> <ReaderInterface>
{
if typeof this->_reader != "object" {
let this->_reader = new Reader();
}
return this->_reader;
}
protected annotations;

/**
* Parses or retrieves all the annotations found in a class
Expand All @@ -66,7 +47,7 @@ abstract class Adapter implements AdapterInterface
let realClassName = className;
}

let annotations = this->_annotations;
let annotations = this->annotations;
if typeof annotations == "array" {
if isset annotations[realClassName] {
return annotations[realClassName];
Expand All @@ -90,36 +71,14 @@ abstract class Adapter implements AdapterInterface
*/
if typeof parsedAnnotations == "array" {
let classAnnotations = new Reflection(parsedAnnotations),
this->_annotations[realClassName] = classAnnotations;
this->annotations[realClassName] = classAnnotations;
this->{"write"}(realClassName, classAnnotations);
}
}

return classAnnotations;
}

/**
* Returns the annotations found in all the class' methods
*/
public function getMethods(string className) -> array
{
var classAnnotations;

/**
* Get the full annotations from the class
*/
let classAnnotations = this->get(className);

/**
* A valid annotations reflection is an object
*/
if typeof classAnnotations == "object" {
return classAnnotations->getMethodsAnnotations();
}

return [];
}

/**
* Returns the annotations found in a specific method
*/
Expand Down Expand Up @@ -155,7 +114,7 @@ abstract class Adapter implements AdapterInterface
/**
* Returns the annotations found in all the class' methods
*/
public function getProperties(string className) -> array
public function getMethods(string className) -> array
{
var classAnnotations;

Expand All @@ -168,7 +127,7 @@ abstract class Adapter implements AdapterInterface
* A valid annotations reflection is an object
*/
if typeof classAnnotations == "object" {
return classAnnotations->getPropertiesAnnotations();
return classAnnotations->getMethodsAnnotations();
}

return [];
Expand Down Expand Up @@ -203,4 +162,45 @@ abstract class Adapter implements AdapterInterface
*/
return new Collection();
}

/**
* Returns the annotations found in all the class' methods
*/
public function getProperties(string className) -> array
{
var classAnnotations;

/**
* Get the full annotations from the class
*/
let classAnnotations = this->get(className);

/**
* A valid annotations reflection is an object
*/
if typeof classAnnotations == "object" {
return classAnnotations->getPropertiesAnnotations();
}

return [];
}

/**
* Returns the annotation reader
*/
public function getReader() -> <ReaderInterface>
{
if typeof this->reader != "object" {
let this->reader = new Reader();
}
return this->reader;
}

/**
* Sets the annotations parser
*/
public function setReader(<ReaderInterface> reader)
{
let this->reader = reader;
}
}
23 changes: 14 additions & 9 deletions phalcon/annotations/adapter/apcu.zep
Expand Up @@ -26,26 +26,31 @@ use Phalcon\Annotations\Reflection;
*/
class Apcu extends Adapter
{
/**
* @var string
*/
protected prefix = "";

protected _prefix = "";

protected _ttl = 172800;
/**
* @var int
*/
protected ttl = 172800;

/**
* Phalcon\Annotations\Adapter\Apcu constructor
*
* @param array options
*/
public function __construct(options = null)
public function __construct(options = null) -> void
{
var prefix, ttl;

if typeof options == "array" {
if fetch prefix, options["prefix"] {
let this->_prefix = prefix;
let this->prefix = prefix;
}
if fetch ttl, options["lifetime"] {
let this->_ttl = ttl;
let this->ttl = ttl;
}
}
}
Expand All @@ -55,14 +60,14 @@ class Apcu extends Adapter
*/
public function read(string! key) -> <Reflection> | bool
{
return apcu_fetch(strtolower("_PHAN" . this->_prefix . key));
return apcu_fetch(strtolower("_PHAN" . this->prefix . key));
}

/**
* Writes parsed annotations to APCu
*/
public function write(string! key, <Reflection> data)
public function write(string! key, <Reflection> data) -> void
{
return apcu_store(strtolower("_PHAN" . this->_prefix . key), data, this->_ttl);
return apcu_store(strtolower("_PHAN" . this->prefix . key), data, this->ttl);
}
}
15 changes: 9 additions & 6 deletions phalcon/annotations/adapter/files.zep
Expand Up @@ -31,17 +31,20 @@ use Phalcon\Annotations\Exception;
*/
class Files extends Adapter
{
protected _annotationsDir = "./";
/**
* @var string
*/
protected annotationsDir = "./";

/**
* Phalcon\Annotations\Adapter\Files constructor
*/
public function __construct(array options = [])
public function __construct(array options = []) -> void
{
var annotationsDir;

if fetch annotationsDir, options["annotationsDir"] {
let this->_annotationsDir = annotationsDir;
let this->annotationsDir = annotationsDir;
}
}

Expand All @@ -55,7 +58,7 @@ class Files extends Adapter
/**
* Paths must be normalized before be used as keys
*/
let path = this->_annotationsDir . prepare_virtual_path(key, "_") . ".php";
let path = this->annotationsDir . prepare_virtual_path(key, "_") . ".php";

if file_exists(path) {
return require path;
Expand All @@ -67,14 +70,14 @@ class Files extends Adapter
/**
* Writes parsed annotations to files
*/
public function write(string! key, <Reflection> data)
public function write(string! key, <Reflection> data) -> void
{
var path;

/**
* Paths must be normalized before be used as keys
*/
let path = this->_annotationsDir . prepare_virtual_path(key, "_") . ".php";
let path = this->annotationsDir . prepare_virtual_path(key, "_") . ".php";

if (file_put_contents(path, "<?php return " . var_export(data, true) . "; ") === false) {
throw new Exception("Annotations directory cannot be written");
Expand Down
8 changes: 4 additions & 4 deletions phalcon/annotations/adapter/memory.zep
Expand Up @@ -24,7 +24,7 @@ class Memory extends Adapter
* Data
* @var mixed
*/
protected _data;
protected data;

/**
* Reads parsed annotations from memory
Expand All @@ -33,7 +33,7 @@ class Memory extends Adapter
{
var data;

if fetch data, this->_data[strtolower(key)] {
if fetch data, this->data[strtolower(key)] {
return data;
}

Expand All @@ -43,11 +43,11 @@ class Memory extends Adapter
/**
* Writes parsed annotations to memory
*/
public function write(string! key, <Reflection> data)
public function write(string! key, <Reflection> data) -> void
{
var lowercasedKey;

let lowercasedKey = strtolower(key);
let this->_data[lowercasedKey] = data;
let this->data[lowercasedKey] = data;
}
}

0 comments on commit 4a38f44

Please sign in to comment.