Jeśli jesteś właścicielem tej strony, możesz wyłączyć reklamę poniżej zmieniając pakiet na PRO lub VIP w panelu naszego hostingu już od 4zł!

Archive for Czerwiec, 2015

Easy Laravel Book: Using Scopes With Laravel 5

Easy Laravel Book: Using Scopes With Laravel 5

The “Easy Laravel Book” website has posted a new tutorial today looking at the use of scopes in Laravel, a packaging method for creating reusable chunks of code for use across the application.

Applying conditions to queries gives you to power to retrieve and present filtered data in every imaginable manner. Some of these conditions will be used more than others, and Laravel provides a solution for cleanly packaging these conditions into easily readable and reusable statements, known as a scope. In this tutorial I’ll show you how to easily integrate scopes into your Laravel models.

He starts with a simple example of a “where” clause made into a method having a name starting with “scope”. This is a hard-coded scope but he also shows an example of the other option, dynamic scopes, allowing for input from the user as a part of the execution. He also shows a quick example of using these same scopes with relations, making them a part of the “find” result chain.

Link: http://www.easylaravelbook.com/blog/2015/06/23/using-scopes-with-laravel-5/
Source: http://www.phpdeveloper.org/news/22864

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

SitePoint PHP Blog: Introduction to Chain of Responsibility

SitePoint PHP Blog: Introduction to Chain of Responsibility

The SitePoint PHP blog has a recent post where they dig into the details of the Chain of Responsibility design pattern, a commonly used structure that makes for easier workflow handling and encapsulation.

The Chain of Responsibility is a behavioral design pattern that processes a request through a series of processor (handlers/receivers) objects. The request is sent from one handler object to another and processed by one (pure implementation) or all of the handlers. All the handlers are part of the chain.

They get into the detail of the parts of the pattern first: the abstract handler that defines the structure and a set of concrete handler classes based on this structure. He also mentions a few other object types that could be involved including a Client, Request and Response objects. He includes an example of the base abstract handler class with “setSuccessor” and “handler” methods to provide the “chain” from one handler to another. He creates a more advanced version of the handler that does some additional checking on the handler results to see if it needs to continue. Finally, he gets down to the Client class that handles the ordering of the chain before processing. He also shows how a service container (dependency injection) could be integrated to manage creating object instances.

Link: http://www.sitepoint.com/introduction-to-chain-of-responsibility/
Source: http://www.phpdeveloper.org/news/22863

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Joe Ferguson: Install Homestead into your project

Joe Ferguson: Install Homestead into your project

As the Laravel News site mentions in one of their latest posts, the Laravel Homestead project received an update recently that makes it easier to install per-project rather than the previous “one install for everything” setup.

Over the weekend, Homestead received a new update that allows you to run it on a per project basis. Previously Homestead was designed so that you install it once on your system and share all your sites within the virtual machine. Joe Ferguson created the pull request to help get this feature implemented and he has a full write up on his blog.

This change pulls in the functionality doing all the hard work for you. It copies over needed files and setting up the Homestead vagrant instance directly from inside the project. Joe also describes the command line options you can provide, defining a name and hostname for the new instance. You can find out more about it in the official documentation.

Link: http://www.joeferguson.me/install-homestead-into-your-project/
Source: http://www.phpdeveloper.org/news/22862

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

David Lundgren: SPL FileObject & LimitIterator

David Lundgren: SPL FileObject & LimitIterator

In the latest post to his site David Lundgren takes a look at two pieces of PHP’s SPL libraries – the FileObject and LimitIterator.

Over that last couple of weeks I’ve come to use the SPL far more than I have in the past. The SplFileObject for reading CSV files is far more convenient than the fgetcsv() function, and associated code needed for a CSV file. Using the LimitIterator allowed me to easily bypass the first row of the CSV, as they were headers and I knew the format of those headers.

He includes an example of using these two to read from a CSV file, processing the header information and each row following. He also gives another example of the LimitIterator handing the results of a database query, reducing the array set down to only the first twelve items. You can find out more about these two handy tools in their SPL documentation, FileObject and LimitIterator, as well as the rest of the SPL if you haven’t looked into it before.

Link: http://davidscode.com/blog/2015/06/22/spl-fileobject-limititerator/
Source: http://www.phpdeveloper.org/news/22861

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Community News: Recent posts from PHP Quickfix

Community News: Recent posts from PHP QuickfixRecent posts from the PHP Quickfix site:

Source: http://www.phpdeveloper.org/news/22860

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Symfony Finland: Serving PHP on HTTP/2 with H2O and HHVM (Symfony, WordPress, Drupal…)

Symfony Finland: Serving PHP on HTTP/2 with H2O and HHVM (Symfony, WordPress, Drupal…)

On the Symfony Finland blog there’s a new post showing you how to serve PHP over HTTP/2 with HHVM and H2O. H2O describes itself as a “new generation HTTP server providing quicker response to users when compared to older generation of web servers”.

This article is not about improvements made in HTTP/2 – as there are plenty of locations for you to read up on the internals. It’s a hands on article to get started using HTTP/2 today with popular tools such as Symfony, WordPress and Drupal with the HHVM PHP runtime from Facebook. You can just as well use PHP-FPM.

They start with a bit of a look at the current state of PHP and HTTP/2 on the various major web server types. H2O, while younger, natively supports HTTP/2, he does offer the caveat that “waiting won’t kill you”. Despite this, they go on to show you how to set up the PHP+H2O+HHVM combination complete with configuration examples and what to look for in the logs to ensure HTTP/2 functionality.

Link: https://www.symfony.fi/entry/serving-php-on-http-2-with-h2o-and-hhvm-symfony-wordpress-drupal
Source: http://www.phpdeveloper.org/news/22859

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Sammy Powers: Contributing to the PHP Manual

Sammy Powers: Contributing to the PHP Manual

If you’ve wanted to contribute something back to PHP but aren’t familiar with C (or don’t feel comfortable enough with it) Sammy Powers offers another solution. In his latest post he shows you how to contribute to the PHP documentation and update the manual for new features, missing information or fixes to current code examples.

If you’ve been wanting to contribute to PHP internals, starting with the documentation can be a great entry point; especially because it doesn’t require dusting off those old C books from college. But knowing where to start can be tricky since information on how to contribute to the docs is scattered across the internet. This article is a step-by-step guide of how to contribute documentation to the PHP manual.

He starts with the “quick and dirty” way of editing the manual through the edit.php.net site, but points out that it’s really only useful for smaller changes, not large documentation updates. The rest of the post shows you how to set up the documentation locally and generate the results to validate your changes. He talks some about the DocBook format they’re written in, the build process with the PhD (PHP docs generator) and running the php.net test suite against the changes. This ensures that nothing else has broken on the site in the process.

He shows you where to make your changes, how to generate it from either a skeleton or using the docgen script and submitting the changes back to the repository. There’s also a few other random changes to make before committing the files back via SVN and pushing them back upstream. He ends the post talking about the GoPHP7-ext project and how to find extensions that are missing documentation or where it’s incomplete (easy thanks to an included “check-missing-docs” file included in the repository).

Link: https://www.sammyk.me/how-to-contribute-to-php-documentation
Source: http://www.phpdeveloper.org/news/22848

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Sammy Powers: Contributing to the PHP Manual

Sammy Powers: Contributing to the PHP Manual

If you’ve wanted to contribute something back to PHP but aren’t familiar with C (or don’t feel comfortable enough with it) Sammy Powers offers another solution. In his latest post he shows you how to contribute to the PHP documentation and update the manual for new features, missing information or fixes to current code examples.

If you’ve been wanting to contribute to PHP internals, starting with the documentation can be a great entry point; especially because it doesn’t require dusting off those old C books from college. But knowing where to start can be tricky since information on how to contribute to the docs is scattered across the internet. This article is a step-by-step guide of how to contribute documentation to the PHP manual.

He starts with the “quick and dirty” way of editing the manual through the edit.php.net site, but points out that it’s really only useful for smaller changes, not large documentation updates. The rest of the post shows you how to set up the documentation locally and generate the results to validate your changes. He talks some about the DocBook format they’re written in, the build process with the PhD (PHP docs generator) and running the php.net test suite against the changes. This ensures that nothing else has broken on the site in the process.

He shows you where to make your changes, how to generate it from either a skeleton or using the docgen script and submitting the changes back to the repository. There’s also a few other random changes to make before committing the files back via SVN and pushing them back upstream. He ends the post talking about the GoPHP7-ext project and how to find extensions that are missing documentation or where it’s incomplete (easy thanks to an included “check-missing-docs” file included in the repository).

Link: https://www.sammyk.me/how-to-contribute-to-php-documentation
Source: http://www.phpdeveloper.org/news/22848

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Giorgio Sironi: Property-based testing primer

Giorgio Sironi: Property-based testing primer

Giorgio Sironi has a new post to his site today talking about a method (and tool) around a different sort of testing practice: property-based testing. The difference is that, instead of hard-coding values and evaluating them post-processing, you’re generating random values and ensuring they match against a set of properties, not values.

I’m a great advocate of automated testing and of finding out your code does not work on your machine, 30 seconds after having written it, instead of in production after it has caused a monetary loss and some repair work to be performed. [...] However, classic test suites written with xUnit and BDD styles have some scaling problems they hit when you want to exercise more than some happy paths. [...] Property-based testing is an approach to testing coming from the functional programming world.

He helps to make the point a bit more clear with an example of testing the “sort” function and its results. He talks about how to test it using normal data, empty data, etc. but notes that this kind of testing can become “boring and error-prone”. Instead he proposes the property-based testing of the results. He generates random values to feed into the method and checks to ensure the results are sorting by comparing them to each other. He expands this with a bit more complex example, showing how to test some DateTime handling and evaluating the result with logic in a closure. To help make this kind of testing easier, he’s created a library (Eris) that extends PHPUnit and provides the methods seen in his examples.

Link: http://www.giorgiosironi.com/2015/06/property-based-testing-primer.html
Source: http://www.phpdeveloper.org/news/22847

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>

Giorgio Sironi: Property-based testing primer

Giorgio Sironi: Property-based testing primer

Giorgio Sironi has a new post to his site today talking about a method (and tool) around a different sort of testing practice: property-based testing. The difference is that, instead of hard-coding values and evaluating them post-processing, you’re generating random values and ensuring they match against a set of properties, not values.

I’m a great advocate of automated testing and of finding out your code does not work on your machine, 30 seconds after having written it, instead of in production after it has caused a monetary loss and some repair work to be performed. [...] However, classic test suites written with xUnit and BDD styles have some scaling problems they hit when you want to exercise more than some happy paths. [...] Property-based testing is an approach to testing coming from the functional programming world.

He helps to make the point a bit more clear with an example of testing the “sort” function and its results. He talks about how to test it using normal data, empty data, etc. but notes that this kind of testing can become “boring and error-prone”. Instead he proposes the property-based testing of the results. He generates random values to feed into the method and checks to ensure the results are sorting by comparing them to each other. He expands this with a bit more complex example, showing how to test some DateTime handling and evaluating the result with logic in a closure. To help make this kind of testing easier, he’s created a library (Eris) that extends PHPUnit and provides the methods seen in his examples.

Link: http://www.giorgiosironi.com/2015/06/property-based-testing-primer.html
Source: http://www.phpdeveloper.org/news/22847

<!–
var d = new Date();
r = escape(d.getTime()*Math.random());
document.writeln('’);
//–>