Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T13672 factories #14097

Merged
merged 28 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
17b483b
Removed obsolete tests and added factory tests
niden May 18, 2019
bb1fba6
Made serializer optional; Added factories for Image/Cache
niden May 18, 2019
b85dbd9
Added translation factories - refactored abstract classes
niden May 18, 2019
9722f56
Corrected nativearray tests
niden May 18, 2019
32f67a3
Removed obsolete tests; Corrected helper
niden May 18, 2019
0fc70b0
Refactored csv/nativearray translate tests
niden May 18, 2019
12c36f1
Fixed factory tests
niden May 18, 2019
49a1cf6
Adjusting translate tests
niden May 18, 2019
63a9fac
Refatored factory adapters
niden May 18, 2019
8936ac9
Refactoring on object creation and corrected tests
niden May 19, 2019
1ede804
Revert "Refactoring on object creation and corrected tests"
niden May 19, 2019
275269f
Refactor the interpolator factory
niden May 19, 2019
76dd3f6
Fixed test
niden May 19, 2019
91edcec
Refactored classes updated changelog
niden May 19, 2019
5248c4d
Reorganizing tests
niden May 19, 2019
f24b221
Removed obsolete tests
niden May 19, 2019
b2c42a2
Corrections to factories and tests
niden May 19, 2019
f542726
Added Pdo factory; adjusted tests
niden May 19, 2019
f0990d1
Adjusted assets and changelog
niden May 19, 2019
93e7535
Updated changelog
niden May 19, 2019
ae27a9b
Corrected reference
niden May 19, 2019
2732458
Adjustments; Added Logger\AdapterFactory and tests
niden May 20, 2019
68d1e62
Refactoring image adapters; Adjustements to factories and tests
niden May 20, 2019
17ac143
Adjusted the sample ini file
niden May 20, 2019
85ae297
Updated the changelog
niden May 20, 2019
eec055a
Adjusted the changelog
niden May 20, 2019
c8f2047
Corrected test references
niden May 20, 2019
39741ee
Minor fixes based on review
niden May 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 27 additions & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,35 @@
# [4.0.0-beta.1](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0-beta.1) (2019-xx-xx)

## Added
- Added `Phalcon\Factory\Exception` for factory exceptions. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Added `Phalcon\Filter\FilterInterface` for custom filter implementations. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Added `Phalcon\Db\Adapter\PdoFactory`: Factory to create PDO adapters. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Added `Phalcon\Image\ImageFactory`: Factory to create image adapters. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Added `Phalcon\Image\LoggerFactory`: Factory to create logger objects. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Added `Phalcon\Translate\InterpolatorFactory`: Factory to create interpolator objects. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Added `Phalcon\Translate\TranslateFactory`: Factory to create translate objects. [#13672](https://github.com/phalcon/cphalcon/issues/13672)

## Changed
- Renamed `Phalcon\Annotations\Adapter\Files` to `Phalcon\Annotations\Adapter\Stream`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Annotations\Adapter` to `Phalcon\Annotations\Adapter\AbstractAdapter`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Annotations\AdapterInterface` to `Phalcon\Annotations\Adapter\AdapterInterface`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Annotations\Factory` to `Phalcon\Annotations\AnnotationsFactory`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Config\Factory` to `Phalcon\Config\ConfigFactory`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Filter\FilterLocator` to `Phalcon\Filter\Filter`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Filter\FilterLocatorFactory` to `Phalcon\Filter\FilterFactory`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Image\Adapter` to `Phalcon\Image\Adapter\AbstractAdapter`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Image\AdapterInterface` to `Phalcon\Image\Adapter\AdapterInterface`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Paginator\Adapter` to `Phalcon\Paginator\Adapter\AbstractAdapter`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Paginator\AdapterInterface` to `Phalcon\Paginator\Adapter\AdapterInterface`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Renamed `Phalcon\Paginator\Factory` to `Phalcon\Paginator\PaginatorFactory`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)

## Fixed
- Fixed `Phalcon\Mvc\View::getRender()` to call `view->finish()` instead of `ob_end_clean()`. [#14095](https://github.com/phalcon/cphalcon/pull/14095)

## Removed
- Removed `Phalcon\Session\Factory`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)
- Removed `Phalcon\Factory` and `Phalcon\FactoryInterface`. [#13672](https://github.com/phalcon/cphalcon/issues/13672)

# [4.0.0-alpha.5](https://github.com/phalcon/cphalcon/releases/tag/v4.0.0-alpha.5) (2019-05-18)

## Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
* file that was distributed with this source code.
*/

namespace Phalcon\Annotations;
namespace Phalcon\Annotations\Adapter;

use Phalcon\Annotations\AdapterInterface;
use Phalcon\Annotations\Adapter\AdapterInterface;
use Phalcon\Annotations\Reader;
use Phalcon\Annotations\Exception;
use Phalcon\Annotations\Collection;
Expand All @@ -22,7 +22,7 @@ use Phalcon\Annotations\ReaderInterface;
*
* This is the base class for Phalcon\Annotations adapters
*/
abstract class Adapter implements AdapterInterface
abstract class AbstractAdapter implements AdapterInterface
{
protected annotations = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* file that was distributed with this source code.
*/

namespace Phalcon\Annotations;
namespace Phalcon\Annotations\Adapter;

use Phalcon\Annotations\Reflection;
use Phalcon\Annotations\Collection;
Expand Down
4 changes: 2 additions & 2 deletions phalcon/Annotations/Adapter/Apcu.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Phalcon\Annotations\Adapter;

use Phalcon\Annotations\Adapter;
use Phalcon\Annotations\Adapter\AbstractAdapter;
use Phalcon\Annotations\Reflection;

/**
Expand All @@ -24,7 +24,7 @@ use Phalcon\Annotations\Reflection;
* $annotations = new Apcu();
*</code>
*/
class Apcu extends Adapter
class Apcu extends AbstractAdapter
{
/**
* @var string
Expand Down
4 changes: 2 additions & 2 deletions phalcon/Annotations/Adapter/Memory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Phalcon\Annotations\Adapter;

use Phalcon\Annotations\Adapter;
use Phalcon\Annotations\Adapter\AbstractAdapter;
use Phalcon\Annotations\Reflection;

/**
Expand All @@ -19,7 +19,7 @@ use Phalcon\Annotations\Reflection;
* Stores the parsed annotations in memory. This adapter is the suitable
* development/testing
*/
class Memory extends Adapter
class Memory extends AbstractAdapter
{
/**
* Data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@

namespace Phalcon\Annotations\Adapter;

use Phalcon\Annotations\Adapter;
use Phalcon\Annotations\Adapter\AbstractAdapter;
use Phalcon\Annotations\Reflection;
use Phalcon\Annotations\Exception;

/**
* Phalcon\Annotations\Adapter\Files
* Phalcon\Annotations\Adapter\Stream
*
* Stores the parsed annotations in files. This adapter is suitable for production
*
*<code>
* use Phalcon\Annotations\Adapter\Files;
* use Phalcon\Annotations\Adapter\Stream;
*
* $annotations = new Files(
* $annotations = new Stream(
* [
* "annotationsDir" => "app/cache/annotations/",
* ]
* );
*</code>
*/
class Files extends Adapter
class Stream extends AbstractAdapter
{
/**
* @var string
*/
protected annotationsDir = "./";

/**
* Phalcon\Annotations\Adapter\Files constructor
* Phalcon\Annotations\Adapter\Stream constructor
*/
public function __construct(array options = []) -> void
{
Expand Down
69 changes: 69 additions & 0 deletions phalcon/Annotations/AnnotationsFactory.zep
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@

/**
* This file is part of the Phalcon Framework.
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
*/

namespace Phalcon\Annotations;

use Phalcon\Annotations\Adapter\AbstractAdapter;
use Phalcon\Factory\AbstractFactory;
use Phalcon\Helper\Arr;

class AnnotationsFactory extends AbstractFactory
{
/**
* AdapterFactory constructor.
*/
public function __construct(array! services = [])
{
this->init(services);
}

/**
* Factory to create an instace from a Config object
*/
public function load(var config) -> var
{
var name, options;

let config = this->checkConfig(config),
name = config["adapter"];

unset config["adapter"];

let options = Arr::get(config, "options", []);

return this->newInstance(name, options);
}

/**
* Create a new instance of the adapter
*/
public function newInstance(string! name, array! options = []) -> <AbstractAdapter>
{
var definition;

this->checkService(name);

if !isset this->services[name] {
let definition = this->mapper[name],
this->services[name] = new {definition}(options);
}

return this->services[name];
}

protected function getAdapters() -> array
{
return [
"apcu" : "\\Phalcon\\Annotations\\Adapter\\Apcu",
"memory" : "\\Phalcon\\Annotations\\Adapter\\Memory",
"stream" : "\\Phalcon\\Annotations\\Adapter\\Stream"
];
}
}
42 changes: 0 additions & 42 deletions phalcon/Annotations/Factory.zep

This file was deleted.

47 changes: 16 additions & 31 deletions phalcon/Cache/AdapterFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,11 @@ namespace Phalcon\Cache;

use Phalcon\Cache\Adapter\AbstractAdapter;
use Phalcon\Cache\Exception\Exception;
use Phalcon\Factory\AbstractFactory;
use Phalcon\Storage\SerializerFactory;

class AdapterFactory
class AdapterFactory extends AbstractFactory
{
/**
* @var array
*/
private mapper = [];

/**
* @var array
*/
private services = [];

/**
* @var <SerializerFactory>
*/
Expand All @@ -34,26 +25,11 @@ class AdapterFactory
/**
* AdapterFactory constructor.
*/
public function __construct(<SerializerFactory> factory, array! services = [])
public function __construct(<SerializerFactory> factory = null, array! services = [])
{
var adapters, name, service;

let this->serializerFactory = factory;

let adapters = [
"apcu" : "\\Phalcon\\Cache\\Adapter\\Apcu",
"libmemcached" : "\\Phalcon\\Cache\\Adapter\\Libmemcached",
"memory" : "\\Phalcon\\Cache\\Adapter\\Memory",
"redis" : "\\Phalcon\\Cache\\Adapter\\Redis",
"stream" : "\\Phalcon\\Cache\\Adapter\\Stream"
];

let adapters = array_merge(adapters, services);

for name, service in adapters {
let this->mapper[name] = service;
unset(this->services[name]);
}
this->init(services);
}

/**
Expand All @@ -63,9 +39,7 @@ class AdapterFactory
{
var definition;

if !isset this->mapper[name] {
throw new Exception("Service " . name . " is not registered");
}
this->checkService(name);

if !isset this->services[name] {
let definition = this->mapper[name],
Expand All @@ -74,4 +48,15 @@ class AdapterFactory

return this->services[name];
}

protected function getAdapters() -> array
{
return [
"apcu" : "\\Phalcon\\Cache\\Adapter\\Apcu",
"libmemcached" : "\\Phalcon\\Cache\\Adapter\\Libmemcached",
"memory" : "\\Phalcon\\Cache\\Adapter\\Memory",
"redis" : "\\Phalcon\\Cache\\Adapter\\Redis",
"stream" : "\\Phalcon\\Cache\\Adapter\\Stream"
];
}
}
33 changes: 33 additions & 0 deletions phalcon/Cache/CacheFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ use Phalcon\Cache\Adapter\AdapterInterface;
use Phalcon\Cache\AdapterFactory;
use Phalcon\Cache\Cache;
use Phalcon\Cache\CacheInterface;
use Phalcon\Cache\Exception\Exception;
use Phalcon\Config;
use Phalcon\Factory\AbstractFactory;
use Phalcon\Helper\Arr;

/**
* Phalcon\CacheFactory
Expand All @@ -35,6 +39,35 @@ class CacheFactory
let this->adapterFactory = factory;
}

/**
* Factory to create an instace from a Config object
*/
public function load(var config) -> var
{
var name, options;

if typeof config == "object" && config instanceof Config {
let config = config->toArray();
}

if unlikely typeof config !== "array" {
throw new Exception(
"Config must be array or Phalcon\\Config object"
);
}

if unlikely !isset config["adapter"] {
throw new Exception(
"You must provide 'adapter' option in factory config parameter."
);
}

let name = config["adapter"],
options = Arr::get(config, "options", []);

return this->newInstance(name, options);
}

/**
* Constructor.
*
Expand Down
Loading