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 Lipiec, 2015

Simon Holywell: PHP date localisation with setlocale

Simon Holywell: PHP date localisation with setlocale

Simon Holywell as written up a tutorial for his site showing you how to use setlocale to do PHP date localization.

Localising sites can be a chore, but PHP has the venerable setlocale() to use system locales. These are like templates or profiles that describe how various types of data should be displayed. Should a price have a comma or point to indicate the decimals? When printing a date should PHP output Monday or Montag?

All of these considerations are locale specific and they map to a geographical area. Various cultures have their own standards for displaying this kind of information not to mention different languages to accommodate.

He shows how to find the locales your system supports and how to install them if the one(s) you need are missing. With it correctly installed, the system knows how to use it but PHP needs a little extra help. With a call to the setlocale method and the use of a special date string modifier (in this case “%B” for the month name) PHP knows to use the locale-aware version of the data…but only with strftime not the normal PHP date handling.

Link: https://www.simonholywell.com/post/2015/07/php-date-setlocale-localisation/
Source: http://www.phpdeveloper.org/news/22963

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

Simon Holywell: PHP date localisation with setlocale

Simon Holywell: PHP date localisation with setlocale

Simon Holywell as written up a tutorial for his site showing you how to use setlocale to do PHP date localization.

Localising sites can be a chore, but PHP has the venerable setlocale() to use system locales. These are like templates or profiles that describe how various types of data should be displayed. Should a price have a comma or point to indicate the decimals? When printing a date should PHP output Monday or Montag?

All of these considerations are locale specific and they map to a geographical area. Various cultures have their own standards for displaying this kind of information not to mention different languages to accommodate.

He shows how to find the locales your system supports and how to install them if the one(s) you need are missing. With it correctly installed, the system knows how to use it but PHP needs a little extra help. With a call to the setlocale method and the use of a special date string modifier (in this case “%B” for the month name) PHP knows to use the locale-aware version of the data…but only with strftime not the normal PHP date handling.

Link: https://www.simonholywell.com/post/2015/07/php-date-setlocale-localisation/
Source: http://www.phpdeveloper.org/news/22963

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

SitePoint PHP Blog: Defensive Programming in PHP

SitePoint PHP Blog: Defensive Programming in PHP

In an article from the SitePoint PHP blog author Jeff Smith walks us through some advice he has about defensive programming in PHP, that is good practices for writing code that more gracefully handles potential error points.

Defensive programming, simply put, is programming with the intent to anticipate likely failure points. The goal is to circumvent those likely problems before they occur. You see the problem, right? There’s something inherently difficult with the advice “expect the unexpected” and it’s made many times worse when one alters it to “expect the unexpected and try to prevent it”. Let’s look at some practical examples.

He touches on a few of the most common places where errors could be introduced with unexpected input or functionality:

  • Conditional Statements
  • User Input (and trusting it….hint: never)
  • Assumptions [Made] About Your Code
  • Tunnel Vision (or not using good development practices)

  • Consistency in Syntax and Naming

Each point in the list includes a brief summary of what to look out for and things you can do to prevent the problem. It’s by no means an exhaustive list, but it is a good place to start.

Link: http://www.sitepoint.com/defensive-programming-in-php/
Source: http://www.phpdeveloper.org/news/22962

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

SitePoint PHP Blog: Defensive Programming in PHP

SitePoint PHP Blog: Defensive Programming in PHP

In an article from the SitePoint PHP blog author Jeff Smith walks us through some advice he has about defensive programming in PHP, that is good practices for writing code that more gracefully handles potential error points.

Defensive programming, simply put, is programming with the intent to anticipate likely failure points. The goal is to circumvent those likely problems before they occur. You see the problem, right? There’s something inherently difficult with the advice “expect the unexpected” and it’s made many times worse when one alters it to “expect the unexpected and try to prevent it”. Let’s look at some practical examples.

He touches on a few of the most common places where errors could be introduced with unexpected input or functionality:

  • Conditional Statements
  • User Input (and trusting it….hint: never)
  • Assumptions [Made] About Your Code
  • Tunnel Vision (or not using good development practices)

  • Consistency in Syntax and Naming

Each point in the list includes a brief summary of what to look out for and things you can do to prevent the problem. It’s by no means an exhaustive list, but it is a good place to start.

Link: http://www.sitepoint.com/defensive-programming-in-php/
Source: http://www.phpdeveloper.org/news/22962

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

Sameer Borate: Cron Expression Parser in PHP

Sameer Borate: Cron Expression Parser in PHP

If you’ve ever worked with the “cron” tool on a unix-based system, you know that there’s a special syntax that comes along with defining when the commands should run. It can be difficult to get this timing exactly right, especially if you’re very picky about the execution time. In this post from Sameer Borate he shows you a PHP library that can help not only parse current cron configurations but also provides shortcuts for common timings (ex: “daily” or “weekly”).

Working with cron scheduling can many times be a frustrating affair. Although setting a few cron jobs at one time can be easy, calculating cron dates in the future in code can get time consuming quickly. The PHP cron expression parser described here can parse a CRON expression, determine if it is due to run, calculate the next run date of the expression or calculate the previous run date of the expression. You can calculate dates far into the future or past by skipping n number of matching dates.

He includes some examples of putting the library to use to define a cron object based on an expression (either via a shortcut or an actual cron time expression). You can then check to see if the cron is “due” or perform some various operations about its run dates. This includes a formatted output of the previous run time, the next run time and the calculation of the next/previous run time based on a relative timestamp.

Link: http://www.codediesel.com/php/cron-expression-parser-in-php/
Source: http://www.phpdeveloper.org/news/22961

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

Sameer Borate: Cron Expression Parser in PHP

Sameer Borate: Cron Expression Parser in PHP

If you’ve ever worked with the “cron” tool on a unix-based system, you know that there’s a special syntax that comes along with defining when the commands should run. It can be difficult to get this timing exactly right, especially if you’re very picky about the execution time. In this post from Sameer Borate he shows you a PHP library that can help not only parse current cron configurations but also provides shortcuts for common timings (ex: “daily” or “weekly”).

Working with cron scheduling can many times be a frustrating affair. Although setting a few cron jobs at one time can be easy, calculating cron dates in the future in code can get time consuming quickly. The PHP cron expression parser described here can parse a CRON expression, determine if it is due to run, calculate the next run date of the expression or calculate the previous run date of the expression. You can calculate dates far into the future or past by skipping n number of matching dates.

He includes some examples of putting the library to use to define a cron object based on an expression (either via a shortcut or an actual cron time expression). You can then check to see if the cron is “due” or perform some various operations about its run dates. This includes a formatted output of the previous run time, the next run time and the calculation of the next/previous run time based on a relative timestamp.

Link: http://www.codediesel.com/php/cron-expression-parser-in-php/
Source: http://www.phpdeveloper.org/news/22961

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

Rob Allen: Custom OAuth2 authentication in Apiiglity

Rob Allen: Custom OAuth2 authentication in Apiiglity

In an article posted to his site Rob Allen shows you how to hook in the OAuth2 authentication for an Apigility-based application with a pre-existing database table structure that may not match the defaults Apigility is looking for.

I have a client that’s writing an Apigility API that needs to talk to a database that’s already in place. This also includes the users table that is to be used with Apigility’s OAuth2 authentication. Getting Apigility’s OAuth2 integration to talk to a specific table name is quite easy. [...] However, if you want to use different column names, that’s a bit trickier as they are hardcoded in the OAuth2StoragePdo class. To get Apigility’s OAuth2 components to look at the correct columns, you create your own OAuth2 Adapter. I chose to extend ZFOAuth2AdapterPdoAdapter which extends OAuth2StoragePdo and go from there.

He includes the code for this extension of the PdoAdapter (a “OAuth2Adapter” class) in the post showing the definitions of the get user, set user and check password methods the OAuth2 flow needs to match users to OAuth sessions. He also includes the code for the “OAuth2AdapterFactory” class that’s used to pull the custom PDO adapter class into Apigility and, along with some configuration changes, make it available for use. Then it’s just a simple matter of changing the authentication type in the Apigility UI.

Link: http://akrabat.com/custom-oauth2-authentication-in-apiiglity/
Source: http://www.phpdeveloper.org/news/22960

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

Rob Allen: Custom OAuth2 authentication in Apiiglity

Rob Allen: Custom OAuth2 authentication in Apiiglity

In an article posted to his site Rob Allen shows you how to hook in the OAuth2 authentication for an Apigility-based application with a pre-existing database table structure that may not match the defaults Apigility is looking for.

I have a client that’s writing an Apigility API that needs to talk to a database that’s already in place. This also includes the users table that is to be used with Apigility’s OAuth2 authentication. Getting Apigility’s OAuth2 integration to talk to a specific table name is quite easy. [...] However, if you want to use different column names, that’s a bit trickier as they are hardcoded in the OAuth2StoragePdo class. To get Apigility’s OAuth2 components to look at the correct columns, you create your own OAuth2 Adapter. I chose to extend ZFOAuth2AdapterPdoAdapter which extends OAuth2StoragePdo and go from there.

He includes the code for this extension of the PdoAdapter (a “OAuth2Adapter” class) in the post showing the definitions of the get user, set user and check password methods the OAuth2 flow needs to match users to OAuth sessions. He also includes the code for the “OAuth2AdapterFactory” class that’s used to pull the custom PDO adapter class into Apigility and, along with some configuration changes, make it available for use. Then it’s just a simple matter of changing the authentication type in the Apigility UI.

Link: http://akrabat.com/custom-oauth2-authentication-in-apiiglity/
Source: http://www.phpdeveloper.org/news/22960

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

Voices of the ElePHPant: Interview with Jacques Woodcock

Voices of the ElePHPant: Interview with Jacques Woodcock

The Voices of the ElePHPant podcast has posted their latest episode in their series of community interviews. In this latest show host Cal Evans talks with Jacques Woodcock,

Jacques and Cal talk some about his work in the leadership of the Nashville PHP user group. They also talk about how he’s grown and what he’s learned while he was organizing the group. There’s also a mention of the “all user group leadership” meetup they have in the Nashville area, bringing together a cross-functional representative group of the local tech groups. Cal also asks Jacques about the work he’s doing at a startup as CTO and how he actively works on the developer happiness of the team.

You can listen to the episode either through the in-page audio player or by downloading the mp3 to listen at your leisure. Be sure to subscribe to their feed too and get the latest episodes as they’re released.

Link: https://voicesoftheelephpant.com/2015/07/21/interview-with-jacques-woodcock-2/
Source: http://www.phpdeveloper.org/news/22959

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

Voices of the ElePHPant: Interview with Jacques Woodcock

Voices of the ElePHPant: Interview with Jacques Woodcock

The Voices of the ElePHPant podcast has posted their latest episode in their series of community interviews. In this latest show host Cal Evans talks with Jacques Woodcock,

Jacques and Cal talk some about his work in the leadership of the Nashville PHP user group. They also talk about how he’s grown and what he’s learned while he was organizing the group. There’s also a mention of the “all user group leadership” meetup they have in the Nashville area, bringing together a cross-functional representative group of the local tech groups. Cal also asks Jacques about the work he’s doing at a startup as CTO and how he actively works on the developer happiness of the team.

You can listen to the episode either through the in-page audio player or by downloading the mp3 to listen at your leisure. Be sure to subscribe to their feed too and get the latest episodes as they’re released.

Link: https://voicesoftheelephpant.com/2015/07/21/interview-with-jacques-woodcock-2/
Source: http://www.phpdeveloper.org/news/22959

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