Skip to content

Commit

Permalink
Merge pull request #24 from wagnert/master
Browse files Browse the repository at this point in the history
Refactoring for new DI functionality
  • Loading branch information
wagnert committed Apr 11, 2018
2 parents 3053096 + ff3d88e commit 6586da7
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 42 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ php:
matrix:
allow_failures:
- php: 7.0

before_install:
- pecl install pthreads-2.0.10
- pecl install xdebug
- if [[ "$TRAVIS_PHP_VERSION" < "7.0" ]]; then pecl install pthreads-2.0.10; fi
- if [[ "$TRAVIS_PHP_VERSION" = "7.0" ]] || [[ "$TRAVIS_PHP_VERSION" > "7.0" ]]; then pecl install pthreads-3.1.6; fi
- pecl install xdebug-2.5.5
- phpenv rehash
- wget https://scrutinizer-ci.com/ocular.phar

Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# Version 5.0.0

## Bugfixes

* None

## Features

* Add @Inject annotation
* Refactor descriptors for optimized bean initialization
* Remove session ID parameter from BeanContextInterface::lookup() method
* Remove session ID parameter from ResourceLocatorInterface::lookup() method

# Version 4.0.0

## Bugfixes
Expand All @@ -6,6 +19,7 @@

## Features

* Switch to latest appserver-io/lang branch ~3.0
* Remove parameters session ID and args from BeanContextInterface::newInstance() method

# Version 3.0.0
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"homepage" : "https://github.com/appserver-io-psr/epb",
"license" : "OSL-3.0",
"require" : {
"php" : ">=5.4.0",
"appserver-io/lang" : "~1.0"
"php" : ">=5.5.0",
"appserver-io/lang" : "~3.0"
},
"require-dev" : {
"appserver-io/build" : "~1.0"
Expand Down Expand Up @@ -38,4 +38,4 @@
"keywords" : [
"php enterprise beans"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,23 @@
abstract class AbstractBeanAnnotation extends ReflectionAnnotation
{

/**
* The constructor the initializes the instance with the
* data passed with the token.
*
* @param string $annotationName The annotation name
* @param array $values The annotation values
*/
public function __construct($annotationName, array $values = array())
{

// pre-initialize the shared flag if NOT found in the passed values
isset($values[AnnotationKeys::SHARED]) ? null : $values[AnnotationKeys::SHARED] = true;

// pass the paremeters to the parent instance
parent::__construct($annotationName, $values);
}

/**
* Returns the value of the name attribute.
*
Expand Down Expand Up @@ -69,4 +86,16 @@ public function getLookup()
return $this->values[AnnotationKeys::LOOKUP];
}
}

/**
* Returns the value of the shared attribute.
*
* @return boolean The annotations shared attribute
*/
public function getShared()
{
if (isset($this->values[AnnotationKeys::SHARED])) {
return $this->values[AnnotationKeys::SHARED];
}
}
}
35 changes: 35 additions & 0 deletions src/AppserverIo/Psr/EnterpriseBeans/Annotations/AnnotationKeys.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,39 @@ class AnnotationKeys
* @var string
*/
const UNIT_NAME = 'unitName';

/**
* Key for the annotation property 'factory'.
*
* @var string
*/
const FACTORY = 'factory';

/**
* Key for the annotation property 'factoryType'.
*
* @var string
*/
const FACTORY_TYPE = 'factoryType';

/**
* Key for the annotation property 'factoryMethod'.
*
* @var string
*/
const FACTORY_METHOD = 'factoryMethod';

/**
* Key for the annotation property 'method'.
*
* @var string
*/
const METHOD = 'method';

/**
* Key for the annotation property 'shared'.
*
* @var string
*/
const SHARED = 'shared';
}
12 changes: 0 additions & 12 deletions src/AppserverIo/Psr/EnterpriseBeans/Annotations/EnterpriseBean.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,4 @@ public function getBeanName()
return $this->values[AnnotationKeys::BEAN_NAME];
}
}

/**
* Returns the value of the lookup name attribute.
*
* @return string|null The annotations lookup name attribute
*/
public function getLookup()
{
if (isset($this->values[AnnotationKeys::LOOKUP])) {
return $this->values[AnnotationKeys::LOOKUP];
}
}
}
112 changes: 112 additions & 0 deletions src/AppserverIo/Psr/EnterpriseBeans/Annotations/Inject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

/**
* AppserverIo\Psr\EnterpriseBeans\Annotations\Inject
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* PHP version 5
*
* @author Tim Wagner <tw@appserver.io>
* @copyright 2015 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io-psr/apb
* @link http://www.appserver.io
*/

namespace AppserverIo\Psr\EnterpriseBeans\Annotations;

/**
* Annotation implementation representing a @Inject annotation on a class method/property.
*
* @author Tim Wagner <tw@appserver.io>
* @copyright 2015 TechDivision GmbH <info@appserver.io>
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io-psr/epb
* @link http://www.appserver.io
*/
class Inject extends AbstractBeanAnnotation
{

/**
* The annotation for a default timeout method.
*
* @var string
*/
const ANNOTATION = 'Inject';

/**
* This method returns the class name as
* a string.
*
* @return string
*/
public static function __getClass()
{
return __CLASS__;
}

/**
* Returns the value of the bean name attribute.
*
* @return string|null The annotations bean Name attribute
*/
public function getBeanName()
{
if (isset($this->values[AnnotationKeys::BEAN_NAME])) {
return $this->values[AnnotationKeys::BEAN_NAME];
}
}

/**
* Returns the value of the type attribute.
*
* @return string The annotations type attribute
*/
public function getType()
{
if (isset($this->values[AnnotationKeys::TYPE])) {
return $this->values[AnnotationKeys::TYPE];
}
}

/**
* Returns the value of the factory attribute.
*
* @return string The annotations factory attribute
*/
public function getFactory()
{
if (isset($this->values[AnnotationKeys::FACTORY])) {
return $this->values[AnnotationKeys::FACTORY];
}
}

/**
* Returns the value of the factory type attribute.
*
* @return string The annotations factory type attribute
*/
public function getFactoryType()
{
if (isset($this->values[AnnotationKeys::FACTORY_TYPE])) {
return $this->values[AnnotationKeys::FACTORY_TYPE];
}
}

/**
* Returns the value of the factory method attribute.
*
* @return string The annotations factory method attribute
*/
public function getFactoryMethod()
{
if (isset($this->values[AnnotationKeys::FACTORY_METHOD])) {
return $this->values[AnnotationKeys::FACTORY_METHOD];
}
}
}
12 changes: 11 additions & 1 deletion src/AppserverIo/Psr/EnterpriseBeans/Annotations/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ class Schedule extends ReflectionAnnotation
*/
const ANNOTATION = 'Schedule';

/**
* The default number to append to an alias if a number is missing
* @var string
*/
const DEFAULT_NUMBER = '1';

/**
* The aliases to be replaced with valid CRON values.
*
* @var array
*/
protected $aliases = array('EVERY' => '*', 'ZERO' => '0');
protected $aliases = array('EVERY' => '*', 'ZERO' => '0', 'SLASH' => '/');

/**
* The constructor the initializes the instance with the
Expand All @@ -80,6 +86,10 @@ public function __construct($annotationName, array $values = array())
// check if we've to replace the value
foreach ($this->aliases as $aliasKey => $aliasValue) {
$value = str_replace($aliasKey, $aliasValue, $value);
// Append the default number to the SLASH alias value if no number is given
if ((preg_match('/\/$/', $value)) === 1) {
$value .= self::DEFAULTNUMBER;
}
}
// set the value
$this->values[$member] = $value;
Expand Down
17 changes: 3 additions & 14 deletions src/AppserverIo/Psr/EnterpriseBeans/BeanContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,12 @@ public function getWebappPath();
* will be returned.
*
* @param string $className The name of the session bean's class
* @param string $sessionId The session ID
* @param array $args The arguments passed to the session beans constructor
*
* @return object The requested bean instance
* @throws \AppserverIo\Psr\EnterpriseBeans\InvalidBeanTypeException Is thrown if passed class name is no session bean or is a entity bean (not implemented yet)
*/
public function lookup($className, $sessionId = null, array $args = array());

/**
* Attaches the passed bean, depending on it's type to the container.
*
* @param object $instance The bean instance to attach
* @param string $sessionId The session-ID when we have stateful session bean
*
* @return void
* @throws \Exception Is thrown if we have a stateful session bean, but no session-ID passed
*/
public function attach($instance, $sessionId = null);
public function lookup($className, array $args = array());

/**
* Returns a new reflection class instance for the passed class name.
Expand Down Expand Up @@ -117,8 +105,9 @@ public function getReflectionClassForObject($instance);
* Returns a new instance of the passed class name.
*
* @param string $className The fully qualified class name to return the instance for
* @param array $args Arguments to pass to the constructor of the instance
*
* @return object The instance itself
*/
public function newInstance($className);
public function newInstance($className, array $args = array());
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @link https://github.com/appserver-io-psr/epb
* @link http://www.appserver.io
*
* @method array getPersistenceUnitReferences() getPersistenceUnitReferences() The array with the persistence unit references.
*/
interface BeanDescriptorInterface
{
Expand Down Expand Up @@ -63,9 +61,23 @@ public function getEpbReferences();
public function getResReferences();

/**
* Returns an array with the merge EBP, resource and persistence unit references.
* The array with the resource references.
*
* @return array The resource references
*/
public function getBeanReferences();

/**
* The array with the persistence unit references.
*
* @return array The persistence unit references
*/
public function getPersistenceUnitReferences();

/**
* Returns an array with the all references.
*
* @return array The array with the merge all bean references
* @return array The array with the merge all references
*/
public function getReferences();

Expand Down

0 comments on commit 6586da7

Please sign in to comment.