Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

NetTuts.com:
Generate Random Alphanumeric Strings in PHP
Nov 21, 2018 @ 17:52:17

On the NetTuts.com site they've posted a tutorial showing how to generate random alphanumeric strings in PHP including information on how the different "randomness" methods work in PHP (and when to use which method).

Let me begin this post by saying that almost no event is truly random. Even the outcome of a classic coin toss could in theory be predicted if we knew the effect of every factor involved, like air friction, gravity, and initial force.

The same thing is applicable to the generation of random numbers and alphanumeric strings. The best we can hope for is to generate numbers and strings that don't seem to follow a pattern and can't be practically predicted by an attacker.

In this tutorial, we will cover different techniques for generating random numbers and alphanumeric strings in PHP. Some of them will be cryptographically secure, while others are meant only for casual use, like assigning pseudo-random file names or creating URLs and suggesting usernames.

They start with a look at generating random numbers using the rand, mt_rand and random_int functions. There's a mention of which to use when cryptographically secure random integers are needed as well. They also talk about seeding the random number generator and generating random float values.

From there they move on to the focus of the article - generating the random alphanumeric strings using a few different methods:

  • generating "shuffled" strings
  • generating random strings
  • generate random hexadecimal strings
  • generating cryptographically secure random strings

Each of the above sections (as well as the previous ones) come with code examples and explanations of the randomness each provides.

tagged: generate random alphanumeric strings tutorial cryptography

Link: https://code.tutsplus.com/tutorials/generate-random-alphanumeric-strings-in-php--cms-32132

Tomas Votruba:
New in Symplify 5: Generate Rich, Precise and Smart Changelog in Seconds
Oct 02, 2018 @ 15:21:45

In a new post to his site Tomas Votruba talks about how to use Simplify to generate a changelog for your project's updates and output it into a CHANGELOG.md file.

ChangelogLinker started as a small tool to complete links to PRs, authors, and versions in CHANGELOG.md. Then it started to generate the CHANGELOG.md.

Where is now and how to start using it?

He starts by showing how to install the package via Composer and how to use it for:

  • Multiple CHANGELOG.md for Smaller Versions
  • [using] Smarter Last Change Detection
  • Removing Dead Links
  • Improved Category Detection

The last one is quite handy as it gives more context to the items in the resulting Changelog rather than just a list of commits.

tagged: symplify changelog tutorial generate output

Link: https://www.tomasvotruba.cz/blog/2018/10/01/new-in-symplify-5-generate-rich-precise-and-smart-changelog-in-seconds/

Matthias Noback:
About fixtures
Jul 10, 2018 @ 15:21:05

Matthias Noback has written up an article on his site covering a tool that's common in many web applications, especially for testing: fixture data. In the post he makes some suggestions about effective ways to use them to provide more "real world" results for tests.

System and integration tests need database fixtures. These fixtures should be representative and diverse enough to "fake" normal usage of the application, so that the tests using them will catch any issues that might occur once you deploy the application to the production environment. There are many different options for dealing with fixtures; let's explore some of them.

He makes four suggestions of ways to handle fixtures:

  1. Generate them the "natural" way via interaction with the application and taking a snapshot of the data.
  2. Generate them at runtime for the tests, reloading them each time
  3. Manual insertion of custom data into the database for all tests
  4. Manual insertion of custom data into the database for each test case

He finishes the post by asking a question for those considering using fixture data: do you need them at all? Testing should be isolated from external sources so maybe they're not really needed...

tagged: fixtures list suggestions natural generate custom data database

Link: https://matthiasnoback.nl/2018/07/about-fixtures/

TutsPlus.com:
Programming With Yii: Generating Documentation
Jun 02, 2017 @ 16:14:03

The TutsPlus site has posted the latest article in their "Programming with Yii" tutorial series, this time covering the generation of documentation for the API code that's been created to power the application.

Recently, I wrote about building REST APIs for your Yii application and expanded custom APIs for our startup series application, Meeting Planner.

In today's tutorial, I'll introduce you to Yii's apidoc extension, which automatically generates browsable documentation for your code. I'm going to use it to generate API documentation for Meeting Planner.

The tutorial starts off with helping you get the extension installed (via Composer) and links to a few examples of the end result. The tutorial then goes through how to add your own comments to your current files that will be output in the final result directly. This includes open text descriptions and other DocBlock information. It then shows how to generate the documentation, how to navigate the resulting HTML pages and some examples of what it will look like for the current code.

tagged: programming yii2 generate documentation tutorial series package

Link: https://code.tutsplus.com/tutorials/programming-with-yii-generating-documentation--cms-27899

Master Zend Framework:
How To Generate Class Factories The Easy Way with FactoryCreator
Jan 20, 2017 @ 16:07:57

The Master Zend Framework site has a new tutorial posted guiding you through the process of generating class factories the easy way with the help of the "FactoryCreator" tool in the Zend ServiceManager component.

If there’s one thing that’s always frustrated me when working with Zend Framework, it’s having to create factories for classes. Sure, it’s gotten easier as Zend ServiceManager’s continued to ever improve. And PhpStorm and Zend ServiceManager Grand Master, Gary Hockin, has given me a number of great tips and suggestions.

But it’s always been something I’ve felt frustrated by. Perhaps you feel the same. [...] But, what I’ve felt for some time is that they could also make it easier for us to follow these best practices too, such as with some tooling support. In the latest release of Zend ServiceManager, version 3.2.0, they have.

He goes on to talk about two tools that are included in this latest release: the ConfigDumper and FactoryCreator. He helps you get the FactoryCreator tool installed and provides a simple example of it in use, generating the factory for a "JournalService" class. He includes the results of the generation of the simple example before moving on to a more complicated example: a TableGateway object. The final example shows the generation of the factory for an "Actions" class, handling the controller processing for a simple MVC application. If you're a bit shorter on time, he's also created a screencast version of the tutorial you can view in-page or over on Vimeo.

tagged: zendframework generate class factory factorycreator tutorial screencast

Link: http://www.masterzendframework.com/simple-factory-generation-with-factorycreator/

Freek Van der Herten:
Automatically generate a sitemap in Laravel
Sep 01, 2016 @ 15:51:31

Freek Van der Herten has a post to his site sharing a package and showing how to use it to generate a sitemap for your Laravel application automatically.

Today my company released a package called laravel-sitemap. There are already a lot of excellent sitemap packages out there. They all have in common that you have to manually add links that must appear in the sitemap. With our new package that isn’t required. It can automatically build up a sitemap by crawling a site. In this post I’d like to explain why we built it and how it works.

He starts off talking about why a sitemap might even be needed, mostly related to other automatic systems (like search engine spiders) that would use to reach even the far parts of your application. He then gets into the code, showing two examples of generating the XML document: one that's more manual and another using the "generator" to create based off of a base URL. He ends the post talking about some limitations of the package and includes a few links for further reading on the subject of sitemaps.

tagged: sitemap laravel application package example tutorial generate

Link: https://murze.be/2016/08/automatically-generate-a-sitemap-in-laravel/

Freek Van der Herten:
A modern package to generate html menus
Mar 25, 2016 @ 16:17:38

In this new post to his site Freek Van der Herten shares a new package he's worked up to help generate and maintain the status of menus in a Laravel application. While this example is Laravel-centric, there's also a framework-agnostic package that can be used in any application structure too.

Virtually every website displays some sort of menu. Generating html menus might seem simple, but it can become complex very quickly. Not only do you have to render some basic html, but you also have to manage which item is active. If a menu has a submenu you’ll also want the parents of an active item to be active. Sometimes you want to insert some html between menu items.

There are some packages out there that can help generating menus, but most of them have a messy API or have become victims of feature creep. Thanks why we decided to create our own modern menu package that has a beautiful API to work with.

He spends the rest of the post introducing the package, starting with the generation of a basic menu (and something a bit more complex). He also shows the use of the isActive method call to mark something as "active" but the package will handle that automatically for you if you'd like to keep it simple. He ends the post with a listing of the components that make this menu handling work (three of them) and some of the "modern PHP" functionality that they use.

tagged: menu package library html generate output manage active

Link: https://murze.be/2016/03/a-modern-package-to-generate-menus/

Lorna Mitchell:
Generating a File List for Phan
Nov 27, 2015 @ 16:38:33

Lorna Mitchell has shared a tip she's found helpful when using the phan static analysis tool for finding only PHP files via a simple grep.

Phan is the PHP Analyzer for PHP 7 code. I've been using it, partly out of curiosity, and partly to look at what the implications of upgrading my various projects will be. [...] I generated my filelist.txt files with a little help from grep - by looking for all files with opening PHP tags in, and putting that list of filenames into a file.

The phan tool is still pretty young but it provides a good example of how to use the new php-ast handling to parse and analyze PHP code.

tagged: phan file list generate quick tip grep static analysis tool

Link: http://www.lornajane.net/posts/2015/generating-a-file-list-for-phan

SitePoint PHP Blog:
Automatic PHP Code Generation with Memio
May 05, 2015 @ 16:52:07

On the SitePoint PHP blog a new tutorial shows you how to generate code with Memio, a relatively new PHP-based tool that lets you define "models" as structures for the code you need generated.

Ever thought of writing code responsible for generating certain PHP classes, methods, properties automatically? Read on to get the details on when exactly automatic code generation may be helpful and – what’s most important – how to implement it properly using the Memio library.

He starts with a bit of introduction to the basic concept of code generation and mentions a few places it's currently used. Then he gets into the examples, starting with a bit of code showing how to get Twig loaded and injected into the Memio instance. From there he shows a simple example of creating a class with a single method and single line of code. With the basics understood, he gets into a more "real world" example of generating ORM classes with getters and setters for the different properties/column names.

tagged: tutorial generate code memio library example orm realworld

Link: http://www.sitepoint.com/automatic-php-code-generation-memio/

SitePoint PHP Blog:
Generating PHP Documentation with Sami
Apr 28, 2015 @ 14:55:31

The SitePoint PHP blog has a new tutorial posted today showing you how to generate API documentation with Sami, a "Friends of PHP" project that's currently used to generate API documentation similar to what the Symfony project provides. In this case "API" refers to your class and method structures, not something like a REST API.

Documenting your methods, classes, and functions is becoming second nature for everyone, so it makes sense to have a way to generate a separate documentation instead of navigating through the source code. In this article, I’m going to introduce you to Sami, the new API documentation generator.

He starts with a brief introduction to the DocBlock commenting methods and why you might want to choose Sami over other document generation tools (like phpDocumentor). He then helps you get Sami installed as a phar archive and how to use it to generate the document output for the Laravel Illuminate package. He includes the code you can use to set up the Sami configuration and an example of the output from the command execution. He then includes a bit about the versioning of the documentation, using themes and customizing the look and feel through custom assets and markup changes.

tagged: sami api documentation generate tutorial symfony introduction

Link: http://www.sitepoint.com/generating-php-documentation-sami/


Trending Topics: