SilverStripe meetup

SilverStripe meetup

78c8b0dece5b99f0fecd2eb64d08eb83?s=128

Firesphere

March 09, 2016
Tweet

Transcript

  1. None
  2. Who am I A Dutchy in Kiwiland 16 march, 2016

    • Wellington • Simon Erkelens • Simon • I work for SilverStripe • @Firesphere • https://github.com/firesphere • https://speakerdeck.com/firesphere • You know it’s me, when you see Hans ◦ Except maybe on Twitter This is Hans, my RDD tool. She’s a cow
  3. DataObject Annotations 16 march, 2016 • Wellington • Simon Erkelens

    It may be hard to write, but it doesn’t have to be hard to use Because typing @property is boring
  4. What are annotations Class and function annotations and usages 16

    march, 2016 • Wellington • Simon Erkelens • PHP Docblocks • Usage • Class information ◦ @author/@description/@property/@method/@package • Function descriptions ◦ @param/@return/@throws/@deprecated • Code Completion • Pat your IDE. He/she’s very happy you use docblocks
  5. Annotations What does it look like /** * @property string

    Title * @property string Content * @property string URLSegment * @property string FAIcon * @method SpecialPage SpecialPage * @method Image Impression */ This is the class class Special extends DataObject { public static $db = array( 'Title' => 'Varchar(255)', 'Content' => 'HTMLText', 'URLSegment' => 'Varchar(255)', 'FAIcon' => 'Varchar(255)' ); public static $has_one = array( 'SpecialPage' => 'SpecialPage', 'Impression' => 'Image', ); } 16 march, 2016 • Wellington • Simon Erkelens Docblocks in your files
  6. Documenting your classes Fun times! Greatest thing about being a

    developer, right? 16 march, 2016 • Wellington • Simon Erkelens • Class docblock • @author • @description • @property • @method • @package • @mixin • @depends • etc. • And let’s not forget the description
  7. Documenting your functions Fun times! Greatest thing about being a

    developer, right? 16 march, 2016 • Wellington • Simon Erkelens • Class docblock • @param • @returns • @throws • @deprecated • And again, description • If it’s hard to write, it should be hard to read ◦ right? • Sorry, can’t help you there
  8. Creating docblocks on your class Fun times! Greatest about being

    a developer, right? 16 march, 2016 • Wellington • Simon Erkelens • Let’s get started with the fun stuff! • IDEAnnotator https://github.com/axyr/silverstripe-ideannotator • StartGeneratedWithDataObjectAnnotator • @property • @mixin • @method • EndGeneratedWithDataObjectAnnotator
  9. DEMO! 16 march, 2016 • Wellington • Simon Erkelens Let’s

    see what I’m talking about IDEAnnotator
  10. DEMO! 16 march, 2016 • Wellington • Simon Erkelens It

    works!
  11. Installation and configuration How to install and use 16 march,

    2016 • Wellington • Simon Erkelens • $ composer require axyr/silverstripe-ideannotator --dev • ONLY RUN IN DEV MODE!!! • Enable in _config.php or config.yml • _config.php if(Director::isDev()) { Config::inst()->update('DataObjectAnnotator', 'enabled', true); Config::inst()->update('DataObjectAnnotator', 'enabled_modules', array('mysite', 'otherfolderinsiteroot') ); }
  12. Installation and configuration How to install and use 16 march,

    2016 • Wellington • Simon Erkelens • $ composer require axyr/silverstripe-ideannotator --dev • ONLY RUN IN DEV MODE!!! • Enable in _config.php or config.yml • config.yml --- Only: environment: 'dev' --- DataObjectAnnotator: enabled: true enabled_modules: - mysite - ss3Gallery
  13. Only in dev mode Really, don’t do this on live

    16 march, 2016 • Wellington • Simon Erkelens • Literally alters the content of your file • Despite testing, we can’t promise your file isn’t broken :’( • There’s no use for updating annotations on live • It’s for your IDE, not your visitor • It’s okay to commit them to your repository though • ?skipannotation=true
  14. But why? Because it’s possible? 16 march, 2016 • Wellington

    • Simon Erkelens • Save time • Instantly all options and methods available in your IDE • Let the annotator do the thinking • No more accidental @property where you mean @method • Even the ID properties for has_one relations are there • Help yourself, help others
  15. Wished features It’s only just a tiny module, you can

    help make it big 16 march, 2016 • Wellington • Simon Erkelens • It’s far from done • Multiple classes in one file • Page_Controller @mixins Page|datarecord • allowed_actions? https://github.com/axyr/silverstripe-ideannotator I was told to add a kitten to my presentation
  16. Thank you! @Firesphere simonerkelens@silverstripe.com https://speakerdeck.com/firesphere 16 march, 2016 • Wellington

    • Simon Erkelens