Generating PHP code documentation with Sphinx? [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
Sphinx is a Python library to generate nice documentation from a set of ReST formatted text files. Not the tool used for full-text searching
I'm also fully aware of doxygen / phpdoc tools. I'm trying to figure out if there is a way of using Sphinx to document PHP projects? Or even any other non-Python languages?
https://www.sphinx-doc.org/en/master/

Sphinx and ReST can be used as generic documentation tools, in my experience. There's nothing about Sphinx which obligates you to only use it for Python-based projects. For example, in my work, I've used it to build a user guide and an XML-RPC API reference. In both cases, I had no use for sphinx.ext.autodoc or other Python-specific extras. The documentation was written "by hand," with mostly generic ReST directives, rather than the specialty directives provided by Sphinx. For what it's worth, I have not yet needed to create a custom ReST directive for non-Python documentation.
Even if you're working with a PHP project, I think you'll find Sphinx useful. For example most of the directives provided by the module specific markup are actually quite general. I don't see why you couldn't or wouldn't use these constructs to document stuff from languages other than Python. Likewise, Sphinx makes it pretty easy to show code examples in other languages. There's even a configuration value to change the default to any language which Pygments supports (which includes PHP). If you're feeling particularly ambitious, you could even create a Sphinx extension to pluck something relevant from your PHP code.
All that said, be sure to consider the audience for your documentation project. While I think Sphinx is an excellent tool and would recommend it for a wide range of documentation projects, if your audience is expecting something else, be mindful of that. For example, if you were documenting a Java project, much of your audience may be expecting Javadoc-style documents. If you deviate from that expectation, make sure it's not just for kicks (i.e., it gives you better docs than you'd get otherwise) and be prepared to (briefly) make the case for what you've done differently (e.g. with a FAQ answer or introduction).
Finally, any documentation is better than no documentation, regardless the tool used to create them. Use any tool that helps you, if it's the difference between getting something out there and not.

Just released a few days ago:
http://mark-story.com/posts/view/sphinx-phpdomain-released

CakePHP is using Sphinx for its new documentation, and I wrote the phpdomain for sphinx. While there isn't a way to automatically include your php doc blocks into sphinx, I still think its one of the better documentation authoring tools available. Its great for more narrative style documentation. But with the phpdomain you can make api docs as well.

The Doctrine project, an ORM for PHP, uses Sphinx to generate their online documentation at www.doctrine-project.org. They use a custom pygment for PHP. The documentation is available on Github at https://github.com/doctrine/orm-documentation. It includes the custom PHP pygment css file.
Also the python-pygments package comes with many pygment styles which you can try out by changing the pygments_style = value in your sphinx conf.py configuration file. For example, to try out the pastie highlighting sytle, which is part of python-pygments, you use
pygments_sytle = 'pastie'

As far as I'm concerned, you can document just about any syntax in Sphinx as far as you doesn't limit yourself with languages supported by autodoc. You can create beautiful API References using standard Sphinx directives like .. class, .. method, .. function and other. They work perfectly apart from the source code and doesn't require any automatic generation and linking to the sources.
You can also create generic admonitions with some special class, that you could later hook to CSS:
.. admonition Title
:class: Ololo
This text could be formatted any way you want, using the ``Ololo`` tag.
There are also roles (they allow custom classes too) and other means of adding text with some special formatting, if the original directives aren't sufficient to you.
If you decide to create your docs async from the source code, make sure you disable checking the code coverage and other code-related features in your conf.py or on project initiation.
PS: You can see a very good answer on elements with custom classes here.

Related

My Content Management System [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I intend to develop a Content Management System (CMS) like shown in the figure below;
Figure: Intended CMS design
Is it possible to completely develop it using PHP's standard library?
Do I need to use a PHP web framework? If so, why and what framework is ideal?
I hope to use MySQL as backend.
I hope to use below technologies as front end;
HTML5 and CSS3 - hard code by myself (Is there any framework or something make it easy? I heard something lesscss.org)
jQuery - to make HTML elements functional
Ajax - to avoid page refreshing
Bootstrap - to make my CMS responsive
Are there any technologies I do use, or any suggestions?
I prefer to improve my HTML, CSS, PHP and other technologies by learning and hard coding. So I hope not to use CMS like
joomla, WordPress, etc. Am I right?
Please note: I've already searched Google extensively before I put my questions here. But I am unable to confirm what I do next. Your comments are appreciated.
Your questions really look well researched and I think everybody with the intention of building a custom-made CMS has come to this point where they ask themselves these fundamental questions (in other words: good questions!). Now to some answers:
1) Yes it is possible.
2) Although building a CMS in pure, native, hard-coded PHP is possible, I wouldn't recommend it for production. You could do it, and you would largely profit from the experience, but there are many little problems (like Routing / User-Management / Authentication / Communicating with Database / Form-Building (like in your screenshot) / etc.) that are already solved by a good Framework.
Also as you are a beginner, you are naturally overwhelmed by the problems and decisions you have to solve/make. This is also a good point why a framework would be a good starter. Although some solutions are sometimes a little too opinionated, they still give you a good structure to start with and most of the times follow best practices of our industry.
Which framework is the most ideal for your project, you'll have to decide on your own, based on your requirements, but some common ones are:
Symfony (probably the most known and most used php-framework, but also very abstract / I would recommend this on a really big project, where you work in a team and you are aiming for flexible maintainability)
Laravel (excerpt from their website: An amazing ORM, painless routing, powerful queue library, and simple authentication give you the tools you need for modern, maintainable PHP.)
Silex (the little brother of Symfony, info from their website: Silex is a PHP microframework for PHP. It is built on the shoulders of Symfony2 and Pimple and also inspired by sinatra.)
FatFreeFramework (from their website: A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust web applications - fast!)
As I used Silex myself many times and also when I began with best-practice PHP, I recommend to start with it, if you decide to write your own CMS. I pretty fast did some Management-CMS similar to your screenshot with it (with their Form-Builder) and was happy with the result.
3) Again this is up to you. For the backend you will probably use MySQL anyway, if you just need a database. In the frontend using HTML5/CSS you could try jQuery and Bootstrap (and then here their less or sass implementation).
If you really don't have too much logic for your JavaScript, you could also try to just use native JS, without jQuery. This way you will also learn more about the language and have less vendor-dependencies the user has to download.
4) If you are really up to learning a lot, then yes, you should probably hand-code everything yourself. This way you also have total control of what code gets delivered to your user. That's a problem with most common CMS: they pollute your code through some other plugins or something and you quickly loose control over your output.
But if you need to be fast there are also CMS that address this issue by giving you total control over your output and giving you creative freedom, like MODX does.
In the end it is up to you and especially the needs of your project. If it's a simple website and you conveniently want to edit the content and also have some starter-help, then I recommend to use a CMS.
If you really want to learn about all this stuff and you have some special needs, then go on and code your custom-coded application. In any way: good luck! :)

Are there any PHP *websites* that have made their source available? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
It's not hard to find example PHP code. The problem seems to be that most of it is frameworks/libraries/etc. This is great, but I'd like to see an example of an actual website.
This stems from my perception that I can't build anything but "toys." My websites tend to be fairly CRUDdy, and it feels like my sites are a bit of generic MVC stuff and a lot of "SELECT" and "INSERT" statements.
I just want some assurance that I'm not "doing it wrong" since these are personal projects, and I'd like to use them to get a job.
Below is a good site that also make its source available (which is very well commented and easy to follow/understand, from a Zend Framework standpoint)
http://www.dasprids.de/
Instructions/info for the source
http://www.dasprids.de/behind-the-site
Actual source
http://site.svn.dasprids.de/
Check out MediaWiki. That's the same software that runs Wikipedia, and it's open source.
It's worth noting that the php.net website is itself open source.
What about PHPBB, which is neither a framework, nor a library?
There are also plenty of Open Source websites you can find just by making some search. Especially blogs, content management systems, etc.
Edit: responding to the first comment to my answer, I want just to add that looking at Open Source websites would probably help to have an image of what large (or not so large) projects are, and also how things are done by experienced developers (for example using PDO, SQL transactions, templates, etc.).
But please take in account that most of the time, those projects are developed by several people. And since PHP does not have any coding standard and does everything possible to force the people to not use good practices, large, collaborative projects are not so good at improving your coding standard nor learning good practices. For this, books may me much more helpful, especially books about good practices.
It may be worth looking at wordpress. I haven't looked at the php behind it, but I know I learned a lot looking at the DB definitions.
Usually a framework is a good compromise between writing quality code and performance. Larger websites that need scale come up with their own custom hacks which eventually evolve into frameworks. In my experience writing in pure PHP it's too easy to go the quickest way to implementing a feature and end up with a mishmash of code, but others might be more disciplined.
It's not hard to find example PHP
code.
Good point is that you know how to find code. You said your code ends up in a generic MVC and CRUDdy, i think this is what most of the web applications around are doing. But the important thing to consider here is they do these MVC/CRUD stuffs in managed way and following standard Object Oriented Design Patterns.
If you want to get examples of real PHP applications then search for open source codes for that specific type application and not frameworks/libraries. Frameworks/libraries are a bunch of PHP CLASSES combined together following the application design architectures and they are supposed to provide you a code base to start your new project with existing set of usable codes, not that they give you the "application feel" rather "structured feel" at the starting point. But once you get along these frameworks/libraries working together to provide you a structured way to build your application, things will really ease later. Your job is guaranteed ;)
If you want to develop codes with these MVC frameworks then start with Codeigniter. It is well documented and as you stated your existing code turns out to be like MVC, you'll grab this framework and how to build with it in one shot. I've written a Hello World in Codeigniter you can refer to start with it. (Also Refer: Codeigniter Documentation)
To find code for real application (not frameworks/libraries) you might think of slightly changing your search queries, search for categories of web application or alike you want to see, not just for the code to do this and code to do that, always search for the better and efficient ways to code and develop things. Github, Sourceforge.net, Google Code are really great places to search for "real" & "cool" open source PHP applications.
Well, actually you can learn a lot by studying a solid framework like ie. the Zend Framework. If you would like to learn that I suggest you first have a look at the Zend Framework Quickstart and then start reading Surviving the deep end. Once you covered these, you should have learned the basics of the Zend Framework, and then you can start looking at open source projects that use it. As far as CMSes go, there are a few using the Zend Framework, like TomatoCMS and pimCore.
BTW Creating a website isn't exactly rocket science, most sites are in fact just a collection of dull CRUD screens (sometimes spiced up with some AJAX to deliver a better user experience) that are used to add content to the site...
On beta.mkforlag.com, where I try out new ideas and develop new pages and new layout for the main domain, most of the source code can be seen. Most of the site is in Swedish, but most of the php code (comments, variable names etc.) is in English.
You should also keep in mind that although I've been using PHP a couple of years I'm no PHP expert and most likely "doing it wrong" in many cases. If you're not that advanced, though, you may find at least some of my code useful.
My code of satya-weblog.com is almost live. I am using wordpress V 2.9, so download that and you know about my site!
Check at symfony framework also and you come to know of propel, yml etc

generate PHP classes from XSD? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 10 months ago.
Improve this question
Is there in the world analogues of JavaBeans or JAXB for PHP?
Is it possible to generate PHP classes from XML schema?
It's common practice to publish API's as XSD schemas. Java and C# guys can get advantage of this by generating classes right from XSD. Is there same tool for PHP?
I'm working now on this issue and going to release the tool as soon as it reaches more-less stable state. Check here https://web.archive.org/web/20111026063725/http://mikebevz.com/xsd-to-php-tool/
Upd. I've just release first working prototype, it works fine with UBL 2.0 schemas and one simple schema, but more serious testing is on the way. I'd appreciate if you send schemas you're working with, so I'd include them in the test suite.
Upd. 2. XSD2PHP reached version 0.0.5. Check the progress on https://github.com/moyarada/XSD-to-PHP
The main reasons for using XSD class generators is to
Get compile time checking
An easier syntax than plain old XML API's
Auto completion in your IDE.
Now contrast this with PHP. PHP does not have compile time checking and it has support for dynamic methods/properties. This voids two of the main reasons above and makes this a non-issue unless you really need auto completion. In other words, there is reason to use an XSD class generator in PHP, and that is probably also why none exist.
My suggestion is to use PHPs Simple XML which creates properties to match the XML dynamically during runtime. If you validate your XML against the XSD file and then create a Simple XML object, you have your XML object structure complete with methods and properties, without having to generate code. A perfectly good approach in PHP.
Note that I don't state that SimpleXML is the same as generated XSD classes, of course not.. But it is pretty close, usage and API-wise. You still end up doing something like $company->employee[2]->firstname either way.
This seems to do a decent job https://github.com/goetas-webservices/xsd2php
I wish it handled enumeration validation, but seemed to work ok in my use case. I found the META .yml files it generates helpful.
XSD schemas are usually written in WSDL files on SOAP Web Services.
wsdl2php is a tool for parsing WSDL(XSD) schemas to php classes. It uses php's native SoapClient as it's client:
https://github.com/jbarciauskas/wsdl2php
This library seems to be the best choice nowadays:
https://github.com/goetas/xsd2php
It generates PHP classes for XML Elements and can convert it back and forth:
XML -> PHP -> XML
I looked into that a while ago, and I certainly could not find one. If your schema is simple, there's a guy who hacked a simple version together for flat schemas.
That's all I know about. Normally these guys are good at supporting languages other than the main ones, but they don't do PHP either.
The DMS Software Reengineering Toolkit is configurable code generation machinery, that can be used to process arbitrary formal documents as input. DMS can be used to generate
code in arbitary output languages.
We have used it to generate native Java and COBOL XML readers and writers from DTDs, which are the elder cousin of schemas. The same ideas would be easily applied to PHP.
There is another recent tool called PiBX a JiBX inspired tool.
From the site:
PiBX is an XML-Data-Binding framework for PHP.
With PiBX you can generate PHP classes based off an available
XML-Schema. These classes can be used to marshal the informations to
XML without hassling with schema checks, constraints or restrictions.

Scaffolding for PHP [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
Is there any thing in PHP to create basic scaffold, like in Rails?
EDIT: I need something to prototype quickly..
Some frameworks like Symfony, CakePHP, Akelos, CodeIgniter and others have support for scaffolding.
However if you don't want to use a framework you can try phpScaffold which generates CRUD scaffold pages based on phpMyAdmin table exports...
I also wanted some fast prototyping, but I wanted it to generate the code, so it's easy to update it. I made many improvements on phpScaffold (HTML5, nice CSS, many models at once, etc) which are published on http://github.com/tute/phpscaffold.
Phreeze makes this simple and easy. http://phreeze.com/
QCodo is another great option. And since it uses reflection to do Code Generation instead of reflection at runtime, you'll likely see better performance.
First, Rails is a framework. PHP is a language. PHP does not have built-in scaffolding support, just as Ruby--the language Rails is build on--does not. A framework like CakePHP, however, does support scaffolding.
Second, I see that you raised an objection to CakePHP because "you still have to do a bunch of stuff." That's true--with any framework, you're going to have to learn new conventions, configurations etc.
CakePHP got plenty of scaffolding options
If you throw Crud + API plugin on top, you basically got everything you need, with tons of nice additions
cakephp-crud: The active successor of the two projects below. Provides both Crud actions, API, Scaffolding, Searches and more
Crud Plugin: https://github.com/nodesagency/Platform-Crud-Plugin
API Plugin: https://github.com/nodesagency/Platform-API-plugin
They all utilize CakePHP events, so its really simple to extend and modify the default behavior
For myslef I Use CodeIniter for development, sure they have scaffolding, but only in terms of a "simple scaffolding" which mean you're not gonna use it in live product (i dunno about everyone but i'm only using it as some tools) .
but if you need some like CRUD generator you can use SparkPlug , or Ignition both of them can be used on Codeigniter
This was asked quite some time ago, but if it's still relevant check out this nice scaffolding class (check the demo)
Yiiframework has a good code scaffolding system called Gii. It's web based. Once you create the tables, you can generate the CRUD classes from within the browser. No command line needed. I like this scaffolding.
If you use CakePHP as the web framework it supports scafalding. See this link for more info. http://book.cakephp.org/2.0/en/controllers/scaffolding.html
I'm not sure what the SO policy is for dead thread revival but I figured I would add my own two cents in case none of the above solutions were satisfactory. If you're looking for a PHP-based MySQL scaffolding tool, check out AMPLE Scaffolder. The entire package is contained within a single PHP file (less than 200k) that can simply be dropped into a web accessible directory whereupon you have immediate access to local and remote MySQL databases based on the internal database permissions. No schema exporting, configuration files, or other hassles. Plus, there's a whole lot of other capabilities to offer as well. Just thought I'd share it in case you were looking for another option. Feel free to check it out and post feedback if you have any questions.

PHP UML Generator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
How do I generate UML diagram based on existing classes in PHP?
There's also the PHP UML tool available from pear.
PHP_UML:
Can generate UML/XMI files in version 1.4, or in version 2.1 (logical, component, and deployment views)
Can generate an API documentation in HTML format
Can generate PHP code (code skeleton) from a given XMI file
Can convert UML/XMI content from version 1.4 to version 2.1
Install it on the command line via:
$ pear install pear/php_uml
(This used to be $ pear install pear/php_uml-alpha but the package has since gone stable.)
Generate your xmi:
$ phpuml -o project.xmi
I strongly recommend BOUML which:
is extremely fast (fastest UML tool ever created, check out benchmarks),
has rock solid PHP import and export support (also supports C++, Java, Python)
is multiplatform (Linux, Windows, other OSes),
is full featured, impressively intensively developed (look at development history, it's hard to believe that such fast progress is possible).
supports plugins, has modular architecture (this allows user contributions, looks like BOUML community is forming up)
phUML
phUML is fully automatic UML class diagramm generator written in PHP, licensed under the BSD license. It is capable of parsing any PHP5 object oriented source code and create an appropriate image representation of the oo structure based on the UML specification.
./phuml -r /var/www/my_project -graphviz -createAssociations false -neato out.png
Step by step guide
the best (Windows) software i have found to do PHP and UML is Sparx Systems Enterprise Architect. besides a pletora of features, it supports the following for PHP:
Reverse engineer object oriented PHP into UML class diagrams
Generate PHP class definitions from UML class diagrams
Synchronize changes made in a UML class into the corresponding PHP class definition
Synchronize changes made in a PHP class definition into the corresponding UML class
Create UML sequence diagrams to show what PHP classes use and how they are used
Produce detailed documentation of your PHP code in standard RTF and HTML format
Perform code engineering on models to generate base PHP pages.
not free ($199), but definitely worth the money.
Have you tried Autodia yet? Last time I tried it it wasn't perfect, but it was good enough.
There's also php2xmi. You have to do a bit of manual work, but it generates all the classes, so all you have to do is to drag them into a classdiagram in Umbrello.
Otherwise, generating a diagram with the use of reflection and graphviz, is fairly simple. I have a snippet over here, that you can use as a starting point.
Here's how I did it (directly from code to PDF drawing without manual drawing of anything):
Use BOUML for "reverse engineering PHP code" [sic] to extract the class model (BOUML is available from "universe" repository of Ubuntu). I seriously recommend BOUML for this step because it's really fast compared to many other programs I have tried. In addition, it seems that BOUML seems to extract the model correctly (for the parts that BOUML even tries to extract).
Use BOUML to export model as XMI 1.4 file
Use ArgoUML to import said XMI file (you can use webstart version for this step)
Export XMI from ArgoUML (I don't know which XMI version/variant the output is but it is not the same result as the output from BOUML. The argouml-graphviz cannot handle XMI file directly from BOUML).
Use argouml-graphviz to convert ArgoUML exported XMI file to dot format (you may need to use saxon instead of xsltproc to get it work due to use of XSLT2)
Use dot or fdp or sfdp to render the class diagram.
Here's an example of suitable command line for using fdp to output PDF diagram (assuming that dot file generated by argouml-graphviz XLST processing is saved as xmi-model.dot):
fdp -Tpdf -Gmaxiter=1000 -Gmindist=0.5 -Gpackmode=node \
-Eweight=0.05 -Elen=1.0 -Eminlen=1.0 -Gsplines=true \
-Goverlap=false xmi-model.dot -oxmi-model.pdf
As an alternative you could try PHP_UML or php2xmi instead of BOUML for doing the "reverse engineering" part. I haven't yet tried that.
(I'm using the phrase "reverse engineering" because it seems that UML people are using those words when they mean extracting class and method information from the source code. I would personally interpret those words as extracting information from executable binary file or captured raw wire data.)
If you prefer drawing the class diagram by hand (instead of using computer to do all the drawing), you can use either BOUML or ArgoUML for the drawing. Using the "reverse engineered" data via BOUML will help in that case.
If you are looking to generate UML easily from your existing PHP Classes you might want to consider PHPStorm 3.0 IDE. It does a good job of replicating existing code into UML.
Have a look at the PHP Storm feature list.
In theory you can use PhpStorm to visualise your classes using UML. The generation is not really great but you can effectively refactor stuff and again, at least preview parents, implementations, constants, attributes, methods and their visibility in a nice way.
Situation
I want to visualise a communication between already existing components to a colleague.
Process using PHPStorm
https://blog.jetbrains.com/phpstorm/2017/09/uml-diagrams-in-phpstorm-2017-2/
Advantages
Nice UI, final diagram.
Able to refactor code from a diagram.
Able to add notes.
The class diagram symbolises private/public properties, constructors, methods nicely.
Disadvantages
No support for PHP 7.
Painfully to use. Can't resize the generated boxes.
When adding a new relation, the previous ones get randomly lost :O wtf?
Restarting PhpStorm destroys the diagrams
Changed my mind, impossible to use relations
Result
Anyway, after some painful hour of work I was only able to generate unrelated boxes and had to use additional program to link relations. Really bad. But I believe once they make it work properly it will be a great feature because as the code changes, the diagrams would be automatically updated!
For now, don't use PhpStorm for UML diagrams.
You can use Visual Paradigm for UML. This might not be the best paid (it's US$699) product, just as an option if anyone would like to try. It can create class diagram from PHP and vice versa, and not only PHP, there's a bunch of language you can choose such as C#, C++, Ruby, Java, VB.NET, Python, Objective C, Perl, etc. There's also a trial you can check on.
Well to be honest, first and foremost you shouldn't generate UML model from code, but code from UML model ;).
Even if you are in a rare situation, when you need to do this reverse engineering, it is generally suggested that you do it by hand or at least tidy-up the diagrams, as auto-generated UML has really poor visual (=information) value most of the time.
If you just need to generate the diagrams, it's probably a good thing to ask yourself why exactly? Who is the intended audience and what is the goal? What does the auto-generated diagram have to offer, what code doesn't?
Basicly I accept only one answer to that question. It just got too big and incomprehensible.
Which again is a reason to start with UML in the first place, as opposed to start coding ;) It's called analysis and it's on decline, because every second guy in business thinks it's a bit too expensive and not really necessary.

Categories