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

[ZF2] DoctrineAnnotations fails when there is no [space] on the first line ... #331

Closed
nickurt opened this issue Jul 28, 2014 · 13 comments
Closed
Assignees

Comments

@nickurt
Copy link

nickurt commented Jul 28, 2014

I cannot open issues in the doctrine/annotations repository, so I do it here.

I'm using in Doctrine Annotations (Form Annotations) in Zend2, but it always fails when there is no [space] on the first line ...

Fails:

/**[nospacehere]
 * @Annotation\Type("text")

Works:

/**[spacehere]
 * @Annotation\Type("text")

Zend gives me this errors ...

Fatal error: Call to undefined method Zend\Form\Element::setValueOptions() in [..]

Zend\Form\View\Helper\FormLabel::__invoke expects either label content as the second argument, or that the element provided has a label attribute; neither found

Versions

  • Doctrine\Common: 2.4.2
  • Doctrine\Annotations: 1.2.0
@Ocramius
Copy link
Member

@nickurt any backtrace? The exception seems to have nothing to do with annotations...

@nickurt
Copy link
Author

nickurt commented Jul 28, 2014

#0 [internal function]: Zend\Form\View\Helper\FormLabel->__invoke(Object(Zend\Form\Element), NULL)
#1 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php(399): call_user_func_array(Object(Zend\Form\View\Helper\FormLabel), Array)
#2 [..]/httpdocs/module/Profile/view/profile/profile/settings.phtml(33): Zend\View\Renderer\PhpRenderer->__call('formLabel', Array)
#3 [..]/httpdocs/module/Profile/view/profile/profile/settings.phtml(33): Zend\View\Renderer\PhpRenderer->formLabel(Object(Zend\Form\Element), NULL)
#4 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/View/Renderer/PhpRenderer.php(506): include('/var/www/sites/...')
#5 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/View/View.php(205): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#6 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/View/View.php(233): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#7 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/View/View.php(198): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#8 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(102): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#9 [internal function]: Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#10 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#11 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('render', Object(Zend\Mvc\MvcEvent), Array)
#12 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(352): Zend\EventManager\EventManager->trigger('render', Object(Zend\Mvc\MvcEvent))
#13 [..]/httpdocs/vendor/zendframework/zendframework/library/Zend/Mvc/Application.php(327): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#14 [..]/httpdocs/public/index.php(17): Zend\Mvc\Application->run()
#15 {main}

@Ocramius
Copy link
Member

Nothing related to annotations there... You should debug into it and verify what is being changed in parameters passed from the form builder to the form.

@nickurt
Copy link
Author

nickurt commented Jul 28, 2014

Ok,

/** 
 * @Annotation\Type("Zend\Form\Element\Text")
 * @Annotation\Required({"required":"true" })
 * @Annotation\Filter({"name":"StripTags"})
 * @Annotation\Options({"label":"FirstName", "placement":"prepend"})
 * @Annotation\Attributes({"placeholder":"John", "id":"first_name", "class":"form-control", "autofocus":true})
 * @Annotation\Decorator("name":"label")
 * @Annotation\Validator({"name":"StringLength","options":{"min":2,"max":64}})
 */
public $first_name;

Without [space] on first line gives met this ( $form->get('first_name') )

Zend\Form\Element Object ( [attributes:protected] => Array ( [name] => first_name ) [label:protected] => [labelAttributes:protected] => Array ( ) [labelOptions:protected] => Array ( ) [messages:protected] => Array ( ) [options:protected] => Array ( ) [value:protected] => )

And with [space] on the first line gives me this

Zend\Form\Element\Text Object ( [attributes:protected] => Array ( [type] => text [name] => first_name [required] => required [placeholder] => John [id] => first_name [class] => form-control [autofocus] => 1 ) [label:protected] => FirstName [labelAttributes:protected] => Array ( ) [labelOptions:protected] => Array ( ) [messages:protected] => Array ( ) [options:protected] => Array ( [label] => FirstName [placement] => prepend ) [value:protected] => )

@Ocramius
Copy link
Member

Can you try reading those with the raw annotation reader?

@nickurt
Copy link
Author

nickurt commented Jul 28, 2014

$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reflClass = new \ReflectionProperty('\Profile\Form\Settings', 'first_name');
$classAnnotations = $reader->getPropertyAnnotations($reflClass);

Gives me (with space/without spaces) gives me ...

array(6) {
  [0]=>
  object(Zend\Form\Annotation\Type)#717 (1) {
    ["value":protected]=>
    string(22) "Zend\Form\Element\Text"
  }
  [1]=>
  object(Zend\Form\Annotation\Required)#718 (1) {
    ["required":protected]=>
    bool(true)
  }
  [2]=>
  object(Zend\Form\Annotation\Filter)#719 (1) {
    ["value":protected]=>
    array(1) {
      ["name"]=>
      string(9) "StripTags"
    }
  }
  [3]=>
  object(Zend\Form\Annotation\Options)#720 (1) {
    ["value":protected]=>
    array(2) {
      ["label"]=>
      string(8) "FirstName"
      ["placement"]=>
      string(7) "prepend"
    }
  }
  [4]=>
  object(Zend\Form\Annotation\Attributes)#721 (1) {
    ["value":protected]=>
    array(4) {
      ["placeholder"]=>
      string(4) "John"
      ["id"]=>
      string(10) "first_name"
      ["class"]=>
      string(12) "form-control"
      ["autofocus"]=>
      bool(true)
    }
  }
  [5]=>
  object(Zend\Form\Annotation\Validator)#723 (1) {
    ["value":protected]=>
    array(2) {
      ["name"]=>
      string(12) "StringLength"
      ["options"]=>
      array(2) {
        ["min"]=>
        int(2)
        ["max"]=>
        int(64)
      }
    }
  }
}

@Ocramius
Copy link
Member

@nickurt so there's no differences in the annotation reader logic? Are you also checking if the opcode cache is cleared?

@nickurt
Copy link
Author

nickurt commented Jul 28, 2014

Nope,
I only removed ' * @Annotation\Decorator("name":"label")' due that was an incorrect line, but then the problem still exists.

Cleared the cache already on dev/live server, it only works on my dev server and not on the live server ...

This threads seems to be related to it

@nickurt
Copy link
Author

nickurt commented Jul 29, 2014

@Ocramius Any updates what I can do/how to solve it?

@nickurt
Copy link
Author

nickurt commented Jul 30, 2014

Another one ...

$reader = new \Doctrine\Common\Annotations\AnnotationReader();
$reflProperty = new \ReflectionProperty('\EventsPayments\Form\Payments\CreatePaymentIdeal', 'amount');
$propAnnotations = $reader->getPropertyAnnotations($reflProperty);
array(2) {
  [0]=>
  object(Zend\Form\Annotation\Type)#563 (1) {
    ["value":protected]=>
    string(24) "Zend\Form\Element\Hidden"
  }
  [1]=>
  object(Zend\Form\Annotation\Attributes)#583 (1) {
    ["value":protected]=>
    array(2) {
      ["id"]=>
      string(6) "amount"
      ["value"]=>
      string(4) "0.01"
    }
  }
}

Becomes

<input name="amount" type="text" value="0.01">

In the layout ...

@Ocramius
Copy link
Member

@nickurt I'm thinking that this is a Zend\Code issue, and unrelated with doctrine/common.

I suggest checking the output near https://github.com/zendframework/zf2/blob/fc50881c9b44e6e0e426edb3d9c2b2a1311ef97a/library/Zend/Code/Annotation/Parser/DoctrineAnnotationParser.php#L101, being especially careful about what is being passed to the annotation parser.

@nickurt
Copy link
Author

nickurt commented Jul 30, 2014

@Ocramius Ok, is it good to continue this thread, or to move to zf2 issues?,

Btw, debugged this one, and got this results ...

AnnotationClass (with space)

string(29) "Zend\Form\Annotation\Hydrator"
string(25) "Zend\Form\Annotation\Name"
string(25) "Zend\Form\Annotation\Type"
string(29) "Zend\Form\Annotation\Required"
string(27) "Zend\Form\Annotation\Filter"
string(28) "Zend\Form\Annotation\Options"
string(31) "Zend\Form\Annotation\Attributes"
string(30) "Zend\Form\Annotation\Validator"

AnnotationClass (without space)

string(29) "Zend\Form\Annotation\Hydrator"
string(25) "Zend\Form\Annotation\Name"

AnnotationString (with space)

string(71) "@\Zend\Form\Annotation\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")"
string(40) "@\Zend\Form\Annotation\Name("settings")"
string(54) "@\Zend\Form\Annotation\Type("Zend\Form\Element\Text")"
string(54) "@\Zend\Form\Annotation\Required({"required":"true" })"
string(52) "@\Zend\Form\Annotation\Filter({"name":"StripTags"})"
string(76) "@\Zend\Form\Annotation\Options({"label":"FirstName", "placement":"prepend"})"
string(119) "@\Zend\Form\Annotation\Attributes({"placeholder":"John", "id":"first_name", "class":"form-control", "autofocus":true})"
string(87) "@\Zend\Form\Annotation\Validator({"name":"StringLength","options":{"min":2,"max":64}})"

AnnotationString (without space)

string(71) "@\Zend\Form\Annotation\Hydrator("Zend\Stdlib\Hydrator\ObjectProperty")"
string(40) "@\Zend\Form\Annotation\Name("settings")"

@Ocramius
Copy link
Member

@nickurt yes, this is a zf2 bug. Closing here, please open an issue on the zf2 issue tracker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants