{"action":"created","issue":{"url":"https://api.github.com/repos/goetas/xsd2php/issues/76","labels_url":"https://api.github.com/repos/goetas/xsd2php/issues/76/labels{/name}","comments_url":"https://api.github.com/repos/goetas/xsd2php/issues/76/comments","events_url":"https://api.github.com/repos/goetas/xsd2php/issues/76/events","html_url":"https://github.com/goetas/xsd2php/issues/76","id":69092755,"number":76,"title":"Generate constructors","user":{"login":"demonkoryu","id":55936,"avatar_url":"https://avatars.githubusercontent.com/u/55936?v=3","gravatar_id":"","url":"https://api.github.com/users/demonkoryu","html_url":"https://github.com/demonkoryu","followers_url":"https://api.github.com/users/demonkoryu/followers","following_url":"https://api.github.com/users/demonkoryu/following{/other_user}","gists_url":"https://api.github.com/users/demonkoryu/gists{/gist_id}","starred_url":"https://api.github.com/users/demonkoryu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/demonkoryu/subscriptions","organizations_url":"https://api.github.com/users/demonkoryu/orgs","repos_url":"https://api.github.com/users/demonkoryu/repos","events_url":"https://api.github.com/users/demonkoryu/events{/privacy}","received_events_url":"https://api.github.com/users/demonkoryu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-17T08:17:59Z","updated_at":"2015-05-01T07:55:17Z","closed_at":null,"body":"I can't comfortably use the xsd2php-generated classes for creating deep object trees, since there are no type-hinted constructors for complex types, like wsdl2phpgenerator has.\r\n\r\nTo show what I mean:\r\n\r\nThe current way requires to write everything backwards:\r\n```php\r\n$rq = new SearchRequest();\r\n$rq->setLanguageCode( 'de-DE' );\r\n$rq->setTimestamp( new DateTime() );\r\n$rq->setTarget( 'Fake' );\r\n$search = new RegionListSearchType();\r\n$trip = new TripType();\r\n$journey = new JourneyType();\r\n$traveller = new TravellerType();\r\n$traveller->setAge(25);\r\n$journey->setTravellerList([$traveller, $traveller]);\r\n$journey->setDepartureAirportCountry('de');\r\n$trip->setJourney($journey);\r\n$search->setTrip($trip);\r\n$options = new RegionListOptionsType();\r\n$options->setResultsPerPage(1000);\r\n$options->setResultOffset(0);\r\n$search->setOptions($options);\r\n$rq->setSearch($search);\r\n```\r\n\r\nThe way I would like to use:\r\n```php\r\n$rq = new Request( \r\n\t'de-DE',\r\n\tnew DateTime(),\r\n\t'Fake', \r\n\tnew Search( \r\n\t\tnew Trip( \r\n\t\t\tnew Journey( \r\n\t\t\t\t[ new TravellerType( 25 ), new TravellerType( 25 ) ], \r\n\t\t\t\t'de' \r\n\t\t\t) \r\n\t\t),\r\n\t\tnew SearchOptions(0, 1000)\r\n\t)\t\r\n);\r\n```\r\n\r\nThe constructor would have the nillable elements as default parameters with value `null`, just like wsdl2phpgenerator does."},"comment":{"url":"https://api.github.com/repos/goetas/xsd2php/issues/comments/98071930","html_url":"https://github.com/goetas/xsd2php/issues/76#issuecomment-98071930","issue_url":"https://api.github.com/repos/goetas/xsd2php/issues/76","id":98071930,"user":{"login":"goetas","id":776743,"avatar_url":"https://avatars.githubusercontent.com/u/776743?v=3","gravatar_id":"","url":"https://api.github.com/users/goetas","html_url":"https://github.com/goetas","followers_url":"https://api.github.com/users/goetas/followers","following_url":"https://api.github.com/users/goetas/following{/other_user}","gists_url":"https://api.github.com/users/goetas/gists{/gist_id}","starred_url":"https://api.github.com/users/goetas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goetas/subscriptions","organizations_url":"https://api.github.com/users/goetas/orgs","repos_url":"https://api.github.com/users/goetas/repos","events_url":"https://api.github.com/users/goetas/events{/privacy}","received_events_url":"https://api.github.com/users/goetas/received_events","type":"User","site_admin":false},"created_at":"2015-05-01T07:55:17Z","updated_at":"2015-05-01T07:55:17Z","body":"I was thinking months ago about this feature (can not find the issue on github) but I was not convinced on how to implement it... Your work looks good, and can be a nice feature to have.\r\n\r\n> --constructors='mandatory' -> add all properties to constructor arguments and make them mandatory\r\n\r\nWhat about optional tags/attributes, will they be mandatory too?\r\n\r\n> --constructors='optional' -> add all properties to constructor arguments and make them optional (default null)\r\n\r\nmake sense\r\n\r\n> --constructors='scaffold' -> this will create a constructor that will instantiate a new class of every subclass the class has.\r\n\r\nThis is the most controverse feature since you loose the control over your object. Plus, would be useful if this option can be combined with the `--constructors='optional'` option. \r\n```php\r\n  public function __construct(Address $address=null)\r\n  {\r\n    $this->address = $address ?: new Address();\r\n  }\r\n```\r\n\r\nExtra question: How do you decide the arguments order?"}}