Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/40' into develop
Browse files Browse the repository at this point in the history
Close #40
Close #43
  • Loading branch information
weierophinney committed Feb 22, 2016
2 parents afa5739 + 04b2b8b commit a427fa3
Show file tree
Hide file tree
Showing 27 changed files with 1,033 additions and 472 deletions.
29 changes: 28 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,32 @@ matrix:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.5
env:
- EVENT_MANAGER_VERSION="^2.6.2"
- HYDRATOR_VERSION="^1.1"
- SERVICE_MANAGER_VERSION="^2.7.5"
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- php: 5.6
env:
- EVENT_MANAGER_VERSION="^2.6.2"
- HYDRATOR_VERSION="^1.1"
- SERVICE_MANAGER_VERSION="^2.7.5"
- php: 7
- php: 7
env:
- EVENT_MANAGER_VERSION="^2.6.2"
- HYDRATOR_VERSION="^1.1"
- SERVICE_MANAGER_VERSION="^2.7.5"
- php: hhvm
- php: hhvm
env:
- EVENT_MANAGER_VERSION="^2.6.2"
- HYDRATOR_VERSION="^1.1"
- SERVICE_MANAGER_VERSION="^2.7.5"
allow_failures:
- php: 7
- php: hhvm

notifications:
Expand All @@ -39,9 +58,17 @@ before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ $EVENT_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-eventmanager:$EVENT_MANAGER_VERSION" ; fi
- if [[ $EVENT_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-eventmanager:^3.0" ; fi
- if [[ $HYDRATOR_VERSION != '' ]]; then composer require --no-update "zendframework/zend-stdlib:^2.7" ; fi
- if [[ $HYDRATOR_VERSION != '' ]]; then composer require --no-update "zendframework/zend-hydrator:$HYDRATOR_VERSION" ; fi
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
- if [[ $SERVICE_MANAGER_VERSION = '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
- if [[ $SERVICE_MANAGER_VERSION = '' ]]; then composer remove --dev --no-update zendframework/zend-captcha zendframework/zend-session ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
- composer info -i

script:
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then ./vendor/bin/phpunit --coverage-clover clover.xml ; fi
Expand Down
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.7.0 - TBD
## 2.7.0 - 2016-02-22

### Added

Expand All @@ -18,7 +18,13 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#40](https://github.com/zendframework/zend-form/pull/40) and
[#43](https://github.com/zendframework/zend-form/pull/43) prepare the
component to be forwards compatible with each of the following:
- zend-eventmanager v3
- zend-hydrator v2.1
- zend-servicemanager v3
- zend-stdlib v3

## 2.6.1 - TBD

Expand Down
59 changes: 36 additions & 23 deletions book/zend.form.advanced-use-of-forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class Phone extends Element implements InputProviderInterface
protected $validator;

/**
* Get a validator if none has been set.
*
* @return ValidatorInterface
*/
* Get a validator if none has been set.
*
* @return ValidatorInterface
*/
public function getValidator()
{
if (null === $this->validator) {
Expand Down Expand Up @@ -160,34 +160,42 @@ First, add the custom element to the plugin manager, in your `Module.php` class:
```php
namespace Application;

use Application\Form\Element\Phone;
use Zend\Form\ElementFactory;
use Zend\ModuleManager\Feature\FormElementProviderInterface;

class Module implements FormElementProviderInterface
{
public function getFormElementConfig()
{
return array(
'invokables' => array(
'phone' => 'Application\Form\Element\Phone'
)
);
return [
'aliases' => [
'phone' => Phone::class,
],
'factories' => [
Phone::class => ElementFactory::class,
],
];
}
}
```

Or, you can do the same in your `module.config.php` file:

```php
return array(
'form_elements' => array(
'invokables' => array(
'phone' => 'Application\Form\Element\Phone'
)
)
);
return [
'form_elements' => [
'aliases' => [
'phone' => Phone::class,
],
'factories' => [
Phone::class => ElementFactory::class,
],
],
];
```

You can use a factory instead of an invokable in order to handle dependencies in your
`ElementFactory` is the default factory for form elements. Use your own if you need to handle dependencies in your
elements/fieldsets/forms.

**And now comes the first catch.**
Expand Down Expand Up @@ -240,22 +248,27 @@ same key as the element you want to replace:
```php
namespace Application;

use Application\Form\Element\MyEmail;
use Zend\Form\ElementFactory;
use Zend\ModuleManager\Feature\FormElementProviderInterface;

class Module implements FormElementProviderInterface
{
public function getFormElementConfig()
{
return array(
'invokables' => array(
'Email' => 'Application\Form\Element\MyEmail'
)
);
return [
'aliases' => [
'email' => MyEmail::class,
],
'factories' => [
MyEmail::class => ElementFactory::class,
],
];
}
}
```

Now, whenever you'll create an element whose `type` is 'Email', it will create the custom Email
Now, whenever you'll create an element whose `type` is 'email', it will create the custom Email
element instead of the built-in one.

> ## Note
Expand Down
32 changes: 15 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,24 @@
}
},
"require": {
"php": ">=5.5",
"zendframework/zend-inputfilter": "~2.5",
"zendframework/zend-hydrator": "~1.0",
"zendframework/zend-stdlib": "~2.7"
"php": "^5.5 || ^7.0",
"zendframework/zend-inputfilter": "^2.6",
"zendframework/zend-hydrator": "^1.1 || ^2.1",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"doctrine/annotations": "~1.0",
"zendframework/zend-cache": "~2.5",
"zendframework/zend-captcha": "~2.5",
"zendframework/zend-code": "~2.5",
"zendframework/zend-di": "~2.5",
"zendframework/zend-eventmanager": "~2.5",
"zendframework/zend-filter": "~2.5",
"zendframework/zend-i18n": "~2.5",
"zendframework/zend-mvc": "~2.5",
"zendframework/zend-servicemanager": "~2.5",
"zendframework/zend-session": "~2.5",
"zendframework/zend-text": "~2.5",
"zendframework/zend-validator": "~2.5",
"zendframework/zend-view": "~2.5",
"zendframework/zend-cache": "^2.6.1",
"zendframework/zend-captcha": "^2.5",
"zendframework/zend-code": "^2.6",
"zendframework/zend-eventmanager": "^2.6.2 || ^3.0",
"zendframework/zend-filter": "^2.6",
"zendframework/zend-i18n": "^2.6",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-session": "^2.5",
"zendframework/zend-text": "^2.6",
"zendframework/zend-validator": "^2.6",
"zendframework/zend-view": "^2.6.2",
"zendframework/zendservice-recaptcha": "*",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
Expand Down
55 changes: 34 additions & 21 deletions src/Annotation/AnnotationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public function setEventManager(EventManagerInterface $events)
__CLASS__,
get_class($this),
]);
$events->attach(new ElementAnnotationsListener());
$events->attach(new FormAnnotationsListener());
(new ElementAnnotationsListener())->attach($events);
(new FormAnnotationsListener())->attach($events);
$this->events = $events;
return $this;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ protected function configureForm($annotations, $reflection, $formSpec, $filterSp
foreach ($annotations as $annotation) {
$events->trigger(__FUNCTION__, $this, [
'annotation' => $annotation,
'name' => $name,
'name' => $name,
'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
]);
Expand Down Expand Up @@ -318,31 +318,30 @@ protected function configureElement($annotations, $reflection, $formSpec, $filte
'name' => $name,
]);

$event = new Event();
$event->setParams([
$params = [
'name' => $name,
'elementSpec' => $elementSpec,
'inputSpec' => $inputSpec,
'formSpec' => $formSpec,
'filterSpec' => $filterSpec,
]);
];
foreach ($annotations as $annotation) {
$event->setParam('annotation', $annotation);
$events->trigger(__FUNCTION__, $this, $event);
$params['annotation'] = $annotation;
$events->trigger(__FUNCTION__, $this, $params);
}

// Since "type" is a reserved name in the filter specification,
// we need to add the specification without the name as the key.
// In all other cases, though, the name is fine.
if ($event->getParam('inputSpec')->count() > 1) {
if ($params['inputSpec']->count() > 1) {
if ($name === 'type') {
$filterSpec[] = $event->getParam('inputSpec');
$filterSpec[] = $params['inputSpec'];
} else {
$filterSpec[$name] = $event->getParam('inputSpec');
$filterSpec[$name] = $params['inputSpec'];
}
}

$elementSpec = $event->getParam('elementSpec');
$elementSpec = $params['elementSpec'];
$type = (isset($elementSpec['spec']['type']))
? $elementSpec['spec']['type']
: 'Zend\Form\Element';
Expand Down Expand Up @@ -389,12 +388,20 @@ public function preserveDefinedOrder()
*/
protected function discoverName($annotations, $reflection)
{
$results = $this->getEventManager()->trigger('discoverName', $this, [
$event = new Event();
$event->setName(__FUNCTION__);
$event->setTarget($this);
$event->setParams([
'annotations' => $annotations,
'reflection' => $reflection,
], function ($r) {
return (is_string($r) && !empty($r));
});
]);

$results = $this->getEventManager()->triggerEventUntil(
function ($r) {
return (is_string($r) && !empty($r));
},
$event
);
return $results->last();
}

Expand All @@ -406,11 +413,17 @@ protected function discoverName($annotations, $reflection)
*/
protected function checkForExclude($annotations)
{
$results = $this->getEventManager()->trigger('checkForExclude', $this, [
'annotations' => $annotations,
], function ($r) {
return (true === $r);
});
$event = new Event();
$event->setName(__FUNCTION__);
$event->setTarget($this);
$event->setParams(['annotations' => $annotations]);

$results = $this->getEventManager()->triggerEventUntil(
function ($r) {
return (true === $r);
},
$event
);
return (bool) $results->last();
}

Expand Down
40 changes: 20 additions & 20 deletions src/Annotation/ElementAnnotationsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,27 @@ class ElementAnnotationsListener extends AbstractAnnotationsListener
/**
* {@inheritDoc}
*/
public function attach(EventManagerInterface $events)
public function attach(EventManagerInterface $events, $priority = 1)
{
$this->listeners[] = $events->attach('configureElement', [$this, 'handleAllowEmptyAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleAttributesAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleComposedObjectAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleContinueIfEmptyAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleErrorMessageAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleFilterAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleFlagsAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleHydratorAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleInputAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleObjectAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleOptionsAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleRequiredAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleTypeAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleValidatorAnnotation']);

$this->listeners[] = $events->attach('discoverName', [$this, 'handleNameAnnotation']);
$this->listeners[] = $events->attach('discoverName', [$this, 'discoverFallbackName']);

$this->listeners[] = $events->attach('checkForExclude', [$this, 'handleExcludeAnnotation']);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleAllowEmptyAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleAttributesAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleComposedObjectAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleContinueIfEmptyAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleErrorMessageAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleFilterAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleFlagsAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleHydratorAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleInputAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleObjectAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleOptionsAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleRequiredAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleTypeAnnotation'], $priority);
$this->listeners[] = $events->attach('configureElement', [$this, 'handleValidatorAnnotation'], $priority);

$this->listeners[] = $events->attach('discoverName', [$this, 'handleNameAnnotation'], $priority);
$this->listeners[] = $events->attach('discoverName', [$this, 'discoverFallbackName'], $priority);

$this->listeners[] = $events->attach('checkForExclude', [$this, 'handleExcludeAnnotation'], $priority);
}

/**
Expand Down
Loading

0 comments on commit a427fa3

Please sign in to comment.