Skip to content

Commit

Permalink
Merge branch 'release/1.0.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
romaninsh committed Jul 4, 2016
2 parents 4b9ab90 + 835026e commit 3dc69f5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 8 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

**Agile Core is a collection of PHP Traits for designing object-oriented frameworks**

[![Join the chat at https://gitter.im/atk4/data](https://badges.gitter.im/atk4/data.svg)](https://gitter.im/atk4/data?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Gitter](https://img.shields.io/gitter/room/atk4/data.svg?maxAge=2592000)](https://gitter.im/atk4/dataset?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Documentation Status](https://readthedocs.org/projects/agile-core/badge/?version=latest)](http://agile-core.readthedocs.io/en/latest/?badge=latest)
[![License](https://poser.pugx.org/atk4/core/license)](https://packagist.org/packages/atk4/core)
[![GitHub release](https://img.shields.io/github/release/atk4/core.svg?maxAge=2592000)](https://packagist.org/packages/atk4/core)
[![Build Status](https://travis-ci.org/atk4/core.png?branch=develop)](https://travis-ci.org/atk4/core)
[![Code Climate](https://codeclimate.com/github/atk4/core/badges/gpa.svg)](https://codeclimate.com/github/atk4/core)
[![Test Coverage](https://codeclimate.com/github/atk4/core/badges/coverage.svg)](https://codeclimate.com/github/atk4/core/coverage)
Expand Down Expand Up @@ -30,20 +33,20 @@ See http://agile-core.readthedocs.io/

## Current Status

Stable (BETA1)
Stable

## Roadmap

```
1.1 Implement Debug
1.2 Implement Factory
1.3 Implement QuickException
1.4 Implement Sessions
1.5 Implement Renderable and Template
1.2 Implement QuickException
1.3 Implement Sessions
1.4 Implement Renderable and Template
```

## Past Updates

* 04 Jul: Implemented FactoryTrait
* 21 May: Released 1.0: Implemented ContainerTrait, Trackable, Initializer, AppScope, Hooks, DynamicMethod
* 11 May: Released 0.1
* 11 May: Finished basic docs
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function add($obj, $args = [])
{
if (isset($this->_factoryTrait)) {
// Factory allows us to pass string-type objects
$obj = $this->_add_Factory($obj, $args);
$obj = $this->factory($obj, $args);
}
$obj = $this->_add_Container($obj, $args);

Expand Down
40 changes: 39 additions & 1 deletion src/FactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,48 @@

trait FactoryTrait {

public $_factoryTrait = true;

/**
* Determine class name, call constructor
*/
function factory($object, $defaults) {
function factory($object, $defaults = []) {
if (is_object($object)) {
return $object;
}
return new $object($defaults);
}

/**
* First normalize class name, then add specified prefix to
* class name if it's passed and not already added.
* Class name can have namespaces and they are treated prefectly.
*
* If object is passed as $name parameter, then same object is returned.
*
* Example: normalizeClassName('User','Model') == 'Model_User';
*
* @param string|object $name Name of class or object
* @param string $prefix Optional prefix for class name
*
* @return string|object Full, normalized class name or received object
*/
public function normalizeClassName($name, $prefix = null)
{
if (!is_string($name)) {
return $name;
}

$name = str_replace('/', '\\', $name);
if ($prefix !== null) {
$class = ltrim(strrchr($name, '\\'), '\\') ?: $name;
$prefix = ucfirst($prefix);
if (strpos($class, $prefix) !== 0) {
$name = preg_replace('|^(.*\\\)?(.*)$|', '\1'.$prefix.'_\2', $name);
}
}

return $name;
}

}

0 comments on commit 3dc69f5

Please sign in to comment.