Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SilverStripe meetup

SilverStripe meetup

Firesphere

March 09, 2016
Tweet

More Decks by Firesphere

Other Decks in Technology

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. DEMO! 16 march, 2016 • Wellington • Simon Erkelens Let’s

    see what I’m talking about IDEAnnotator
  9. 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') ); }
  10. 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
  11. 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
  12. 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
  13. 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