本文整理汇总了PHP中Zend\Form\Annotation\AnnotationBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP AnnotationBuilder类的具体用法?PHP AnnotationBuilder怎么用?PHP AnnotationBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AnnotationBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getForm
protected function getForm()
{
$builder = new AnnotationBuilder();
$entity = new TestEntity();
$form = $builder->createForm($entity);
return $form;
}
示例2: authenticateAction
public function authenticateAction()
{
$user = new Forms\Login();
$builder = new AnnotationBuilder();
$form = $builder->createForm($user);
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->getPost());
if ($form->isValid()) {
$user = $request->getPost('username');
$pass = $request->getPost('password');
$redir = urldecode($this->params()->fromQuery('redir'));
$authService = $this->getAuthService();
$authService->setIdentity($user);
$authService->setCredential($pass);
$result = $authService->authenticate();
/* $d = new \Zend\Debug\Debug();
$d->dump($result);
die; */
foreach ($result->getMessages() as $message) {
//save message temporary into flashmessenger
$this->flashmessenger()->addMessage($message);
}
$conf = $this->getServiceLocator()->get('IdAuth\\Config');
if ($conf['settings']['usePrevPageRedir']) {
return $this->redirect()->toUrl($redir);
} else {
return $this->redirect()->toRoute('idAuth');
}
}
}
return $this->redirect()->toRoute('idAuth/login');
}
示例3: indexAction
/**
* The default action - show the home page
*/
public function indexAction()
{
// init vars
$data = NULL;
$table = $this->getServiceLocator()->get('city-codes-table');
$catList = $this->getServiceLocator()->get('form-demo-categories');
$cityList = $table->getAllCityCodesForForm();
$countryList = $table->getAllCountryCodesForForm();
// submit button
$submit = new Submit('submit');
$submit->setAttribute('value', 'Submit');
// build form
$builder = new AnnotationBuilder();
$entity = $this->getServiceLocator()->get('form-demo-listings-entity');
$form = $builder->createForm($entity);
$form->get('category')->setValueOptions(array_combine($catList, $catList));
$form->getInputFilter()->get('category')->getValidatorChain()->attachByName('InArray', array('haystack' => $catList));
$form->get('country')->setValueOptions($countryList);
$form->getInputFilter()->get('country')->getValidatorChain()->attachByName('InArray', array('haystack' => $countryList));
$form->add($submit);
$form->bind($entity);
if ($this->getRequest()->isPost()) {
$form->setData($this->params()->fromPost());
if ($form->isValid()) {
$data = $form->getData();
}
}
return new ViewModel(array('form' => $form, 'data' => $data, 'cityList' => $cityList));
}
示例4: __construct
/**
* @param EntityManager $entityManager
* @param Entity\EntityAbstract $object
*/
public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
{
parent::__construct($object->get('underscore_entity_name'));
$doctrineHydrator = new DoctrineHydrator($entityManager);
$this->setHydrator($doctrineHydrator)->setObject($object);
$builder = new AnnotationBuilder();
/**
* Go over the different form elements and add them to the form
*/
foreach ($builder->createForm($object)->getElements() as $element) {
/**
* Go over each element to add the objectManager to the EntitySelect
*/
if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
$element->setOptions(array_merge_recursive($element->getOptions(), ['object_manager' => $entityManager]));
}
if ($element instanceof Radio) {
$attributes = $element->getAttributes();
$valueOptionsArray = 'get' . ucfirst($attributes['array']);
$element->setOptions(array_merge_recursive($element->getOptions(), ['value_options' => $object->{$valueOptionsArray}()]));
}
//Add only when a type is provided
if (array_key_exists('type', $element->getAttributes())) {
$this->add($element);
}
}
}
示例5: addAction
public function addAction()
{
// The annotation builder help us create a form from the annotations in the user entity.
$builder = new AnnotationBuilder();
$entity = $this->serviceLocator->get('user-entity');
$form = $builder->createForm($entity);
$form->add(array('name' => 'password_verify', 'type' => 'Zend\\Form\\Element\\Password', 'attributes' => array('placeholder' => 'Verify Password Here...', 'required' => 'required'), 'options' => array('label' => 'Verify Password')), array('priority' => $form->get('password')->getOption('priority')));
// This is the special code that protects our form being submitted from automated scripts
$form->add(array('name' => 'csrf', 'type' => 'Zend\\Form\\Element\\Csrf'));
// This is the submit button
$form->add(array('name' => 'submit', 'type' => 'Zend\\Form\\Element\\Submit', 'attributes' => array('value' => 'Submit', 'required' => 'false')));
// We bind the entity to the user. If the form tries to read/write data from/to the entity
// it will use the hydrator specified in the entity to achieve this. In our case we use ClassMethods
// hydrator which means that reading will happen calling the getter methods and writing will happen by
// calling the setter methods.
$form->bind($entity);
if ($this->getRequest()->isPost()) {
$data = array_merge_recursive($this->getRequest()->getPost()->toArray(), $this->getRequest()->getFiles()->toArray());
$form->setData($data);
if ($form->isValid()) {
// We use now the Doctrine 2 entity manager to save user data to the database
$entityManager = $this->serviceLocator->get('entity-manager');
$entityManager->persist($entity);
$entityManager->flush();
$this->flashmessenger()->addSuccessMessage('User was added successfully.');
$event = new EventManager('user');
$event->trigger('register', $this, array('user' => $entity));
// redirect the user to the view user action
return $this->redirect()->toRoute('user/default', array('controller' => 'account', 'action' => 'view', 'id' => $entity->getId()));
}
}
// pass the data to the view for visualization
return array('form1' => $form);
}
示例6: __construct
/**
* @param EntityManager $entityManager
*/
public function __construct(EntityManager $entityManager)
{
parent::__construct('doa');
$doa = new Entity\Doa();
$doctrineHydrator = new DoctrineHydrator($entityManager, 'Affiliation\\Entity\\Doa');
$this->setHydrator($doctrineHydrator)->setObject($doa);
$builder = new AnnotationBuilder();
/**
* Go over the different form elements and add them to the form
*/
foreach ($builder->createForm($doa)->getElements() as $element) {
/**
* Go over each element to add the objectManager to the EntitySelect
*/
if ($element instanceof EntitySelect) {
$element->setOptions(['object_manager' => $entityManager]);
}
//Add only when a type is provided
if (array_key_exists('type', $element->getAttributes())) {
$this->add($element);
}
}
$this->add(['type' => '\\Zend\\Form\\Element\\Select', 'name' => 'contact', 'options' => ["label" => "txt-signer"]]);
$this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'options' => ["label" => "txt-source-file", "help-block" => _("txt-attachment-requirements")]]);
}
示例7: validateJSONAction
/**
* For JS AJAX validation - validates a property of Equipment object.
* @return JSON status=ok|error,message={string}
*/
public function validateJSONAction()
{
try {
$propName = $this->params()->fromPost('propName');
if (!in_array($propName, Equipment::propertyNames())) {
throw new \Exception('Wrong property provided.');
}
$value = $this->params()->fromPost('value');
if (!$propName || !$value) {
throw new \Exception('No property and/or value given.');
}
$equipment = new Equipment();
$builder = new AnnotationBuilder();
$form = $builder->createForm($equipment);
$form->setData(array($propName => $value))->isValid();
$elements = $form->getElements();
$element = $elements[$propName];
if (count($element->getMessages())) {
return $this->myJsonModel(array('status' => 'error', 'message' => $element->getMessages()));
} else {
return $this->myJsonModel(array('status' => 'ok', 'message' => ''));
}
} catch (\Exception $e) {
// @TODO: set status to syserror so JS doesn't confuse with
// validation error
return $this->myJsonModel(array('status' => 'error', 'message' => $e->getMessage()));
}
}
示例8: __construct
/**
* @param EntityManager $entityManager
* @param Entity\EntityAbstract $object
*/
public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
{
parent::__construct($object->get('underscore_entity_name'));
$doctrineHydrator = new DoctrineHydrator($entityManager);
$this->setHydrator($doctrineHydrator)->setObject($object);
$builder = new AnnotationBuilder();
/**
* Go over the different form elements and add them to the form
*/
foreach ($builder->createForm($object)->getElements() as $element) {
/**
* Go over each element to add the objectManager to the EntitySelect
*/
if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
$element->setOptions(array_merge_recursive($element->getOptions(), ['object_manager' => $entityManager]));
}
if ($element instanceof Radio) {
$attributes = $element->getAttributes();
$valueOptionsArray = 'get' . ucfirst($attributes['array']);
$element->setOptions(array_merge_recursive($element->getOptions(), ['value_options' => $object->{$valueOptionsArray}()]));
}
//Add only when a type is provided
if (array_key_exists('type', $element->getAttributes())) {
$this->add($element);
}
}
$this->add(['type' => '\\Zend\\Form\\Element\\Select', 'name' => 'organisation', 'options' => ['disable_inarray_validator' => true, "label" => _("txt-organisation"), "help-block" => _("txt-organisation-help-block")]]);
$this->add(['type' => '\\Zend\\Form\\Element\\Text', 'name' => 'branch', 'options' => ["label" => _("txt-branch"), "help-block" => _("txt-branch-help-block")]]);
}
示例9: __construct
/**
* @param EntityManager $entityManager
* @param Entity\EntityAbstract $object
*/
public function __construct(EntityManager $entityManager, Entity\EntityAbstract $object)
{
parent::__construct($object->get('underscore_entity_name'));
$doctrineHydrator = new DoctrineHydrator($entityManager);
$this->setHydrator($doctrineHydrator)->setObject($object);
$builder = new AnnotationBuilder();
/*
* Go over the different form elements and add them to the form
*/
foreach ($builder->createForm($object)->getElements() as $element) {
/*
* Go over each element to add the objectManager to the EntitySelect
*/
if ($element instanceof EntitySelect || $element instanceof EntityMultiCheckbox) {
$element->setOptions(['object_manager' => $entityManager]);
}
if ($element instanceof Radio) {
$attributes = $element->getAttributes();
$valueOptionsArray = 'get' . ucfirst($attributes['array']);
$element->setOptions(['value_options' => $object->{$valueOptionsArray}()]);
}
//Add only when a type is provided
if (array_key_exists('type', $element->getAttributes())) {
$this->add($element);
}
}
$this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'attributes' => ["class" => "form-control"], 'options' => ["label" => _("txt-source-file"), "help-block" => _("txt-attachment-requirements")]]);
}
示例10: getFeedbackForm
/**
* Returns constructed Feedback
*
* @param ServiceManager $sm ServiceManager
*
* @return Form
*/
public static function getFeedbackForm(ServiceManager $sm)
{
$builder = new AnnotationBuilder();
$form = $builder->createForm('\\Swissbib\\Feedback\\Form\\FeedbackForm');
$form->add(new Csrf('security'));
$form->add(['name' => 'submit', 'type' => 'Submit', 'attributes' => ['value' => 'feedback.form.submit']]);
return $form;
}
示例11: getForm
public function getForm()
{
if (!$this->form) {
$user = new User();
$builder = new AnnotationBuilder();
$this->form = $builder->createForm($user);
}
return $this->form;
}
示例12: getForm
private function getForm()
{
if (!$this->form) {
$form = new LoginForm();
$builder = new AnnotationBuilder();
$this->form = $builder->createForm($form);
}
return $this->form;
}
示例13: getCopyForm
/**
* @param ServiceManager $sm
*
* @return Form
*/
public static function getCopyForm(ServiceManager $sm)
{
AbstractValidator::setDefaultTranslator($sm->get('\\VuFind\\Translator'));
$builder = new AnnotationBuilder();
$form = $builder->createForm('\\Swissbib\\Record\\Form\\CopyForm');
$form->add(new Csrf('security'));
$form->add(['name' => 'submit', 'type' => 'Submit', 'attributes' => ['value' => 'request_copy_text']]);
return $form;
}
示例14: __construct
public function __construct()
{
$this->lastAttemptResult = LoginLogoutService::$failedLoginAttempt;
$this->authservice = new AuthenticationService();
$this->authservice->setStorage(new \Main\Service\UserSessionStorage());
$user = new User();
$builder = new AnnotationBuilder();
$this->form = $builder->createForm($user);
}
示例15: factory
public static function factory(PeepEntity $peep = null)
{
if (null === $peep) {
$peep = __NAMESPACE__ . '\\PeepEntity';
}
$builder = new AnnotationBuilder();
$form = $builder->createForm($peep);
$form->add(new CsrfElement('secure'));
$form->add(array('name' => 'peep', 'attributes' => array('type' => 'submit', 'value' => 'Peep!')));
if ($peep instanceof PeepEntity) {
$form->bind($peep);
}
return $form;
}