{"id":203,"date":"2014-04-17T05:28:47","date_gmt":"2014-04-17T05:28:47","guid":{"rendered":"https:\/\/www.heliossolutions.co\/blog\/?p=203"},"modified":"2017-10-27T14:09:01","modified_gmt":"2017-10-27T14:09:01","slug":"php-api-documentation-generator","status":"publish","type":"post","link":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/","title":{"rendered":"PHP API documentation generator"},"content":{"rendered":"<p>There are lots of document generator out there , many of them quite good. Perhaps the best of them would be phpDocumentor version 2. Lets have a look why Sami is different from phpdocumentor.<\/p>\n<ul class=\"bloginnercontent\">\n<li>It uses\u00a0<a href=\"http:\/\/twig.sensiolabs.org\/\">Twig<\/a>\u00a0for templating.<\/li>\n<li>It is able to manage versions of your code to generate documentation for all of them in a single tree (without the overhead of re-parsing everything for each version of course).<\/li>\n<li>It uses a PHP file for configuration to give a very flexible way of tweaking the API generation.<\/li>\n<li>It uses a dependency injection container (<a href=\"https:\/\/github.com\/fabpot\/Pimple\">Pimple<\/a>) to let you override any internal class.<\/li>\n<li>It only works with PHP 5.3 (but it can generate documentation for PHP 5.2 projects).<\/li>\n<li>It uses the excellent\u00a0<a href=\"https:\/\/github.com\/nikic\/PHP-Parser\">PHP Parser<\/a>\u00a0project for PHP code parsing.<\/li>\n<\/ul>\n<h3>Installation:<\/h3>\n<p>Get Sami from Github (or integrate it as a dependency in your project Composer file<\/p>\n<p>Sami uses Composer to manage its dependencies so just run the composer<\/p>\n[php]$ composer.phar install \u201d[\/php]\n<p>To confirm everything worked fine just execute the sami.php file.<\/p>\n[php]$ php sami.php[\/php]\n<h4>Configuration<\/h4>\n<p>Before generating documentation, you must create a configuration file.<\/p>\n[php]&lt;?php<\/p>\n<p>return new Sami\\Sami(&#8216;\/path\/to\/symfony\/src&#8217;);<br \/>\n[\/php]\n<p>The first argument of constructor is the path to the code to generate documentation for. One valid method is to use PHP iterator (for that use the Symfony Finder class)<\/p>\n[php]\nuse Sami\\Sami;<br \/>\nuse Symfony\\Component\\Finder\\Finder;<\/p>\n<p>$iterator = Finder::create()<br \/>\n    -&gt;files()<br \/>\n    -&gt;name(&#8216;*.php&#8217;)<br \/>\n    -&gt;exclude(&#8216;Resources&#8217;)<br \/>\n    -&gt;exclude(&#8216;Tests&#8217;)<br \/>\n    -&gt;in(&#8216;\/path\/to\/symfony\/src&#8217;)<br \/>\n;<\/p>\n<p>return new Sami($iterator);<\/p>\n[\/php]\n<p>The Sami constructor optionally takes an array of options as a second argument:<\/p>\n[php]\nreturn new Sami($iterator, array(<br \/>\n    &#8216;theme&#8217;                =&gt; &#8216;symfony&#8217;,<br \/>\n    &#8216;title&#8217;                =&gt; &#8216;Symfony2 API&#8217;,<br \/>\n    &#8216;build_dir&#8217;            =&gt; __DIR__.&#8217;\/build&#8217;,<br \/>\n    &#8216;cache_dir&#8217;            =&gt; __DIR__.&#8217;\/cache&#8217;,<br \/>\n    &#8216;default_opened_level&#8217; =&gt; 2,<br \/>\n));<\/p>\n[\/php]\n<hr \/>\n<h4>Configuration for different versions:<\/h4>\n[php]\n&lt;?php<\/p>\n<p>use Sami\\Sami;<br \/>\nuse Sami\\Version\\GitVersionCollection;<br \/>\nuse Symfony\\Component\\Finder\\Finder;<\/p>\n<p>$iterator = Finder::create()<br \/>\n    -&gt;files()<br \/>\n    -&gt;name(&#8216;*.php&#8217;)<br \/>\n    -&gt;exclude(&#8216;Resources&#8217;)<br \/>\n    -&gt;exclude(&#8216;Tests&#8217;)<br \/>\n    -&gt;in($dir = &#8216;\/path\/to\/symfony\/src&#8217;)<br \/>\n;<\/p>\n<p>\/\/ generate documentation for all v2.0.* tags, the 2.0 branch, and the master one<br \/>\n$versions = GitVersionCollection::create($dir)<br \/>\n    -&gt;addFromTags(&#8216;v2.0.*&#8217;)<br \/>\n    -&gt;add(&#8216;2.0&#8217;, &#8216;2.0 branch&#8217;)<br \/>\n    -&gt;add(&#8216;master&#8217;, &#8216;master branch&#8217;)<br \/>\n;<\/p>\n<p>return new Sami($iterator, array(<br \/>\n    &#8216;theme&#8217;                =&gt; &#8216;symfony&#8217;,<br \/>\n    &#8216;versions&#8217;             =&gt; $versions,<br \/>\n    &#8216;title&#8217;                =&gt; &#8216;Symfony2 API&#8217;,<br \/>\n    &#8216;build_dir&#8217;            =&gt; __DIR__.&#8217;\/..\/build\/sf2\/%version%&#8217;,<br \/>\n    &#8216;cache_dir&#8217;            =&gt; __DIR__.&#8217;\/..\/cache\/sf2\/%version%&#8217;,<br \/>\n    &#8216;default_opened_level&#8217; =&gt; 2,<br \/>\n));<\/p>\n[\/php]\n<hr \/>\n<h3>Rendering<\/h3>\n<p>Now that we have a configuration file, let&#8217;s generate the API documentation:<\/p>\n[php]$ php sami.php update \/path\/to\/config.php[\/php]\n<p>The generated documentation can be found under the configured build\/ directory (note that the client side search engine does not work on Chrome due to JavaScript execution restriction &#8212; it works fine in Firefox).<\/p>\n<p>Sami also detects problems in your phpdoc and can tell you what you need to fix if you add the -v option:<\/p>\n[php]$ php sami.php update \/path\/to\/config.php -v[\/php]\n<p>That&#8217;s all , enjoy the new gained knowledge.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are lots of document generator out there , many of them quite good. Perhaps the best of them would\u2026<\/p>\n","protected":false},"author":3,"featured_media":208,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[26],"tags":[44],"class_list":["post-203","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-open-source","tag-php-document-generator"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>PHP API documentation generator - Helios Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PHP API documentation generator - Helios Blog\" \/>\n<meta property=\"og:description\" content=\"There are lots of document generator out there , many of them quite good. Perhaps the best of them would\u2026\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/\" \/>\n<meta property=\"og:site_name\" content=\"Helios Blog\" \/>\n<meta property=\"article:published_time\" content=\"2014-04-17T05:28:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-10-27T14:09:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"480\" \/>\n\t<meta property=\"og:image:height\" content=\"360\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"helios\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"helios\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/\"},\"author\":{\"name\":\"helios\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38\"},\"headline\":\"PHP API documentation generator\",\"datePublished\":\"2014-04-17T05:28:47+00:00\",\"dateModified\":\"2017-10-27T14:09:01+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/\"},\"wordCount\":517,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg\",\"keywords\":[\"PHP Document Generator\"],\"articleSection\":[\"Open Source\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/\",\"url\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/\",\"name\":\"PHP API documentation generator - Helios Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg\",\"datePublished\":\"2014-04-17T05:28:47+00:00\",\"dateModified\":\"2017-10-27T14:09:01+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage\",\"url\":\"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg\",\"contentUrl\":\"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg\",\"width\":480,\"height\":360},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.heliossolutions.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PHP API documentation generator\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#website\",\"url\":\"https:\/\/www.heliossolutions.co\/blog\/\",\"name\":\"Helios Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.heliossolutions.co\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#organization\",\"name\":\"Helios\",\"url\":\"https:\/\/www.heliossolutions.co\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png\",\"contentUrl\":\"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png\",\"width\":250,\"height\":47,\"caption\":\"Helios\"},\"image\":{\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38\",\"name\":\"helios\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g\",\"caption\":\"helios\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"PHP API documentation generator - Helios Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/","og_locale":"en_US","og_type":"article","og_title":"PHP API documentation generator - Helios Blog","og_description":"There are lots of document generator out there , many of them quite good. Perhaps the best of them would\u2026","og_url":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/","og_site_name":"Helios Blog","article_published_time":"2014-04-17T05:28:47+00:00","article_modified_time":"2017-10-27T14:09:01+00:00","og_image":[{"width":480,"height":360,"url":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg","type":"image\/jpeg"}],"author":"helios","twitter_card":"summary_large_image","twitter_misc":{"Written by":"helios","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#article","isPartOf":{"@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/"},"author":{"name":"helios","@id":"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38"},"headline":"PHP API documentation generator","datePublished":"2014-04-17T05:28:47+00:00","dateModified":"2017-10-27T14:09:01+00:00","mainEntityOfPage":{"@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/"},"wordCount":517,"commentCount":0,"publisher":{"@id":"https:\/\/www.heliossolutions.co\/blog\/#organization"},"image":{"@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage"},"thumbnailUrl":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg","keywords":["PHP Document Generator"],"articleSection":["Open Source"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/","url":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/","name":"PHP API documentation generator - Helios Blog","isPartOf":{"@id":"https:\/\/www.heliossolutions.co\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage"},"image":{"@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage"},"thumbnailUrl":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg","datePublished":"2014-04-17T05:28:47+00:00","dateModified":"2017-10-27T14:09:01+00:00","breadcrumb":{"@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#primaryimage","url":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg","contentUrl":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager.jpg","width":480,"height":360},{"@type":"BreadcrumbList","@id":"https:\/\/www.heliossolutions.co\/blog\/php-api-documentation-generator\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.heliossolutions.co\/blog\/"},{"@type":"ListItem","position":2,"name":"PHP API documentation generator"}]},{"@type":"WebSite","@id":"https:\/\/www.heliossolutions.co\/blog\/#website","url":"https:\/\/www.heliossolutions.co\/blog\/","name":"Helios Blog","description":"","publisher":{"@id":"https:\/\/www.heliossolutions.co\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.heliossolutions.co\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.heliossolutions.co\/blog\/#organization","name":"Helios","url":"https:\/\/www.heliossolutions.co\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png","contentUrl":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2023\/01\/Helios-blue-website.png","width":250,"height":47,"caption":"Helios"},"image":{"@id":"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/person\/ce1ab8197db1f84358e99b203e8f6b38","name":"helios","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.heliossolutions.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/acb724e9e4c2d0799bde8878da07c0aa?s=96&d=mm&r=g","caption":"helios"}}]}},"feat_image_thumb":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager-480x250.jpg","mainsite_thumb":"https:\/\/www.heliossolutions.co\/blog\/wp-content\/uploads\/2014\/01\/php-ducoment-manager-150x170.jpg","alt_text":"","_links":{"self":[{"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/posts\/203","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/comments?post=203"}],"version-history":[{"count":0,"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/posts\/203\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/media\/208"}],"wp:attachment":[{"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/media?parent=203"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/categories?post=203"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.heliossolutions.co\/blog\/wp-json\/wp\/v2\/tags?post=203"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}