SitePoint PHPGoogle Analytics API v3 and PHP: Filters and Charts (7.11.2014, 17:00 UTC)

In the previous parts, we talked about how to use the Google Analytics API and created a demo showing some base functionality. In this part, we’re going to expand the demo.

spacer

New functionality

We’ll be adding some new functionality:

  • Date range: we can query data from a specific date range.
  • Max results: in the previous part we used 10 results for speed purposes, now we are going to take it as a user input.
  • Filters: we can filter the result using some specific dimensions or metrics.
  • Order: we can order the result using the queried dimensions.
  • Chart type: this is not a Google Analytics functionality, but we’re going to make some prettier graphs using Highcharts.

Date range

For the date range selection we’re going to use bootstrap-daterangepicker.
First, we include the CSS and JS files and the dependencies.

// views/home.blade.php
<</span>div class="form-group">
            <</span>label class="col-sm-3 control-label" for="">Date range<</span>/label>
            
</</span>div> </</span>div>

We create the the date range component.

Continue reading %Google Analytics API v3 and PHP: Filters and Charts%

Link
Stefan KoopmanschapThe Inter-team Standup (7.11.2014, 13:00 UTC)

For WeCamp 2014, we were creating multiple teams that would all work on their own project. But since we wanted to maximize the exposure of all delegates to the lessons learned by all teams, we needed to create a moment where people could exchange their ideas, their lessons, their work.

Since our schedule already contained a 15-minute standup meeting for each team, it was not hard to come up with the idea of organizing a central stand-up meeting with all teams.

Our Inter-team standup was simple: All members of all teams would be meeting together. Each team would appoint a single representative that would tell everyone what the team had been working on, what challenges they encountered and what solutions they’d chosen. For us, not just the what was important but also the why of decisions. Since we want people to not just learn about the approach but also why this approach was taken, we tried to put some focus on that as well.

Taking this outside the camp

Recently at a customer, we were having a discussion about how to improve the communication between the different development teams. Both teams work (partially) on the same codebase, each with their own responsibility. While doing their work, they may (try to) solve the same problems. That seems inefficient and may result in inconsistent solutions to the same problem.

During this discussion I thought back of WeCamp and proposed we would try this approach. This week we had our first standup, which was quite interesting. It’s good to hear, in just a couple of minutes, what the other team is working on and what problems they are solving. We did notice that the meetup needs a bit more preparation from the teams to make it more efficient, but the concept of having a (in our case) weekly meetup of 10-15 minutes seems to work well.

Don’t replace normal communications

It is important to realize that this meeting is not meant to replace all other forms of communication between teams. Aside from this, it is important that individual team members can visit the other team when they have a question, that they have Skype/Slack/HipChat/IRC to communicate, that they talk to eachother by the watercooler or coffeemachine and that they go to lunch together. The inter-team standup is simply an organized and structured way of exchanging challenges and possible solutions. So far it works, I’m curious what more this will bring.

Link
Fabien PotencierAbout Personal Github Accounts (6.11.2014, 17:02 UTC)

Many of you have a user account on Github. But what are you using it for? As far as Open-Source is concerned, I'm using mine for two different usages:

  • as a way to contribute to other projects by forking repositories and making pull-requests;

  • as a way to host some of my Open-Source projects.

But the more I think about it, the more I think the second usage is most the time wrong. If you are publishing a small snippet of code, a small demo, the code for a tutorial you wrote on your blog, that makes a lot of sense. But when it comes to useful and/or popular Open-Source projects, I think that is a mistake.

An Open-Source project should not be tied too much to its creator; the creator just happens to be the first contributor. And for many projects, it will stay that way for a very long time, which is fine. But gradually, as more people contribute, it can confuse some users. The license you choose helps a lot and the way you are responding to pull requests and issues is also a great way to show you openness. But that's not enough in the long term. Of course, understanding when it becomes a problem is up to you and definitely not easy. Here are some of my thoughts about some problems I identified in the past.

First, it makes the original developer special and not aligned with how others contribute; you cannot for instance fork the project to make a pull request (with a not-so-nice side-effect of Packagist publishing your branches, which is obviously wrong.)

Then, bringing awareness through a well established organization is probably easier than promoting yourself; it makes your project more easily discoverable.

Also, what if someone starts to contribute more than you? What if you are not interested in maintaining the project anymore? Github makes it very easy to transfer a project to another person, but organizations are almost always a better way in that case.

And I'm not even talking the bus factor.

As you might have guessed by now, Github organizations is the solution. A organization fixes all the problems and then some more; and creating one is very easy. Again, that only makes sense when your project is somewhat successful, and probably even more interesting if you have more than one such projects.

A while ago, I decided to do that for Silex and I moved it to its own organization. And I did the same for Twig recently for the same reasons. For those projects, it made sense to create a dedicated organization because there is more than one repositories; we moved along some related repositories (like the Silex skeleton or the Twig extensions).

Organizations are also a great way to create a group of people working on related topics (like FriendsOfSymfony) or people working with the same standards (The League of Extraordinary Packages).

Last year, I co-created such an organization: FriendsOfPhp. A couple of weeks ago, I moved the PHP security advisories database from the sensiolabs organization to the FriendsOfPhp one and I explained my motivations in a blog post.

Today, I'm doing the same with several of my projects that were previously part of my personal Github account. I have not created an organization per project because they are either too small or they don't need more than one repository; so they would not benefit from a standalone organization.

  • Sismo: A Continuous Testing Server
  • Sami: An API documentation generator
  • PHP-CS-Fixer: A script that fixes Coding Standards
  • Goutte: A simple PHP Web Scraper

If you cloned one of these repositories in the past, you can easily switch to the new Git URL via the following command:

$ git remote set-url origin https://github.com/FriendsOfPhp/XXX.git

spacer
Link
SitePoint PHPHow to Run Multiple Versions of PHP on One Server (6.11.2014, 17:00 UTC)

In this particular post, we’ll demo a solution to install multiple versions of Phalcon and PHP and run them on a single web server. PHP 5.5.x and 5.6.x will be used here, but you can replace them with other versions. Any servers that support PHP-FPM should be enough but we recommend using Nginx. The environment used in this tutorial is Fedora OS - a Linux system, but the instructions are almost identical for any other *nix OS.

Preliminary Note

This tutorial will cover the installation of PHP 5.5.x with Phalcon 1.3.x and PHP 5.6.x with Phalcon 2.0.0. We’ll also build some additional PHP extensions such as APC, memcache, memcached, and ioncube.

Installing Nginx

Nginx is an available package in Fedora OS which we can install as follows:

  sudo yum install nginx

Then, we create the system startup links for Nginx and start it

  sudo chkconfig nginx on
  sudo service nginx start

Continue reading %How to Run Multiple Versions of PHP on One Server%

Link
Pádraic BradyPHP-FIG: All Your Dramas Are Belong To Us (6.11.2014, 16:33 UTC)

spacer

spacer A quick Twitter check shows that most tweets recently mentioning PHP-FIG have veered towards the less than impressed end of the spectrum, and I can’t blame those folk who are either disgusted at recent discussions or staking out marshmallows for when the flames rise up again. As I stated in a thread yesterday, I’m currently embarrassed by my association with the group. Whether people like it or not, the conduct of the group casts a shadow on all of its members, and I don’t want its dancing fires of madness reflecting on me.

The list is being overrun by emotionally charged language, derailed threads, personalised attacks, ad-hoc rule enforcement, one-upmanship, and a zero-compromise attitude when debating. In between these, real work is getting done. However, this gets a fraction of the attention, publicity and participation.

If folk want to contribute something useful, Lukas Kahwe Smith is proposing some security related standards (which may go forward as PSR-8 if/when an acceptance vote is organised). Matthew Weier O’Phinney and others are powering through the PSR-7 HTTP messages proposal. There’s other PSRs in progress too! PSR-6 for a caching interface and PSR-5 for a PHPDoc Standard.

The outcome of these “dramas” is to hide all of this good work behind a wall of horse manure. This crap also alienates potential contributors, discourages collaboration, and turns us into a laughing stock on social media. In fact, I’m feeling like I’ve heard something like this before…

There’s an ongoing joke between many people who follow PHP internals development (or used to follow) that it is a toxic kindergarten.

- Anthony Ferrara: blog.ircmaxell.com/2013/09/rambling-on-internals.html

Yes, it’s time to invoke Anthony “Sir Clarity” Ferrara. Run ye for yonder hills. Anthony makes a bunch of useful points that apply to PHP-FIG just as they do to PHP Internals so it’s well worth re-reading that article and ruminating on its contents. While closing that article, Anthony makes the most obvious point of all:

…unless people realize and talk about the problems, they can never be solved.

Going back on threads for the past few months, I’ve listed a set of “rules” that people have mentioned or, at least, never objected to. I would ask PHP-FIG members to a) read them, b) make comments if they want, c) suggest additions, d) consider a +1, and e) consider calling out people if they breach them.

https://groups.google.com/forum/#!topic/php-fig/MJOjBDjTzvg

Let’s start diverting some of this high energy effort into PSRs…

Link
SitePoint PHPHow to Set Up Continuous Deployment with Ninefold (6.11.2014, 16:00 UTC)

This post was sponsored by Ninefold. Thank you for supporting the sponsors who make SitePoint possible!

I can remember back in the day, nine-ish years ago, when deployment was a manual process. Sometimes, in took 99 minutes to deploy even the simplest of sites. On the Tedium and Frustration Scale, deployment was a solid '9'.

Thankfully, those days are behind us. With Continuous Integration having grown into a common, nay expected, practice, how could things get better? The answer? Continuous Deployment. Now, let’s get our terms straight, because there are about 999 ways that Continuous Deployment can be defined, so I’ll pick the one I like.

Continuous Deployment is the practice of automatically deploying every code change that passes automated tests to production.

This is not the same as Continuous Delivery, where you automatically deliver code changes to a staging environment where rigorous integration testing ensues. Continuous Deployment (CDep for the rest of this article) means, you make a change, push it to the main repository, the tests run AND pass, and the code is deployed to production. BOOM! (Incidentally, this post and I agree on these definitions.)

CDep is not for the weak or weakly test-covered. Those who dare attempt CDep have great confidence that the automated tests cover all the functionality of the application. This is no small feat. I would say 99.999% of projects probably don’t have the test coverage to pull of CDep. But for those that make the effort and have the discipline, their rewards are great: Confidence that changes won't cause regressions and that you won't be losing time doing manual deployments. The fruits of CDep labor are the sweetest on the vine.

The growing ubiquity of CDep is directly attributable to the rise of the Platforms-as-a-Service (PaaS). There are many PaaS, and today we’re going to check out Ninefold.

spacer

Ninefold is a PaaS that specializes in hosting Rails applications. Alongside the ease of deployment that comes with most PaaS offerings, Ninefold also offers numerous plugins for things like Redis, PostgreSQL, SendGrid, New Relic, Memcached, and others. A critical differentiator for Ninefold is the ability to add raw Virtual Servers. If there isn’t a plugin for a piece of software you want to leverage, simply spin up a VM and host it yourself.

Ninefold also integrates with various Continuous Integration platforms, such as Codeship, TravisCI, and CircleCI.

My demonstration today will show you how to use Ninefold and Codeship to easily create a CDep workflow for a Rails application.

NineThings

Our application is a simple Rails app that services the critical needs of those who desire to list things that come in multiples of 9. Users can add a thing and its nine-multiple to the growing list of NineThings. This is THE /insert current big-time social app here/-killer. Here’s what it looks like:

spacer

Isn’t it beautiful? I am not going into detail about how it’s setup, simply because it is a just-use-the-generator Rails app with the foundation-rails gem added to make it a bit cleaner. The NineThings model-view-controller sequence was generated using the scaffold generator. Oh, and I am using PostgreSQL. Nothing special in this setup.

The source is in this Github repository, which is what I will use when registering the application with Ninefold. Feel free to fork the app (or pick your own Rails app) and follow along.

Continue reading %How to Set Up Continuous Deployment with Ninefold%

Link
Liip Functional Programming in PHP (5.11.2014, 20:50 UTC)

Functional programming techniques in PHP

Functional programming has gained a lot of traction those 3 to 5 last years. First, there are some success stories around it : Twitter move to Scala, Whatsapp being written in Erlang. Then we have some new kick-ass languages like Rust. Finally, it seems the new hype is to create a functional language compiling to javascript : Elm, Purescript. On a more academic front, there is also research on new concepts like dependant typing, see Idris for example.

Those are all cool and shiny new toys, but we can benefit from some techniques without having to learn a new tool, just by applying some principles to our everyday PHP! But first of all, what exactly is functional programing?

Functional programming

Functional programming is a paradigm as are imperative, logical and OO programming. The main point is that everything is a function, in the mathematical sense. The corollary of that is that you cannot have side effects since all outputs depends solely on the input of the function. It also means you cannot have any mutable state, once something was computed, it cannot be changed to something else.

This can be cumbersome a time, so a distinction was made between pure functional languages (like Haskel or Ocaml) and other function languages, Scala for example, where you can introduce mutable variables or even do plain old Java.

Another issue are input and outputs which are by definition mutable, the "problem" has been resolved in most functional languages by wrapping them into a Monad, the rest of this blog post will not talk about that, so I won't explain this barbaric word, but feel free to do some research on the internet, it is really interesting.

Despite all those lengthy explanation, functional programming is first and for all a way of thinking and solving issues than can be used in any languages. It is just easier to do in some that are designed for it.

The advantages

Since the output depends solely on the input, reasoning about a function is made a whole lot easier, you have everything under the eyes, there is no need to keep in mind any kind of global or shared state, thus reducing complexity a lot.

Testing is made easier, you don't have to mock a lot of dependencies or create big ass objects, you just need to pass the arguments your function need.

A functional style also often result in writing small and self-contained functions used later as building blocks for bigger functionality, resulting in clearly decoupled code and extended reusability.

A nice little bonus of a pure function is that you can cache its result, this is called memoization but more about that later.

A perhaps less appealing argument for us, is that calls to pure function can easily be distributed across threads or even computers because you have the guarantee that the inputs are enough to perform the computation and that there will be no side effects. It is simply a matter of combining the results again at the end.

The basics

The first important thing is that functions are, more or less, first class citizen in the PHP world :

// Function as a variable
$func = function() {
    return 42;
};

// Function as a return type
function createFunction() {
    return function() { return "Thanks for all the fish"; };
};
$func2 = createFunction();

// Function as a parameter
function display($func) {
    echo $func()."\n\n";
}

// Call a function by name
call_user_func_array('strtoupper', $someString);

// objects as functions
class SomeClass {
    public function __invoke($param1, $param2) {
        [...]
    }
}
$instance = new SomeClass();
$instance('First', 'Second'); // call the __invoke() method

Knowing that, we can start playing around with basic functional concepts. For each example, the "common" way of doing things will be presented first followed by the functional one. As it is often the case in functional programming, we will most of the time manipulate an array.

Applying a function to all elements :

// The imperative way :

foreach($stringArray as $k => $v) {
    $stringArray[$k] = strtoupper($v);
}


// The functional way :

$result = array_map('strtoupper', $stringArray);

"Reduce" an array, often called "fold" in functional languages :

// The imperative way :

$result = 0;
foreach($int

Truncated by Planet PHP, read more at the original (another 7158 bytes)

Link
Peter PetermannBuilding better project skeletons with Composer (5.11.2014, 17:48 UTC)

Note: This post has originally been posted at binpress, you can find the original post there:  (www.binpress.com/tutorial/better-project-skeletons-with-composer/157)

As the two weeks exclusive i gave to them are now over, i decided to put it here on my blog as well for those who might not stumble over it at binpress. If you haven’t heard of binpress, check them out, they are a market place for opensource solutions.

Building better project skeletons with Composer

The more you use modern frameworks and the more modular you build your PHP applications, the more likely you’ll use a skeleton (or template) for creating new projects. In fact, most of the better known frameworks provide skeletons for you to bootstrap your application with.

Those skeletons are great to get started, but it’s very likely you’ll have your own stack of composer packages that you integrate in each project after a while. Each skeleton will be slightly different, so you’ll likely fork your own. This article is meant to provide you with an understanding on how to build a skeleton that will allow you to automate things as far as possible.

Before We Start

I’ll assume you’ve used composer before, and I’ll also assume you have it installed in a way that calling “composer” in your command line will execute the composer commands.

I will use the word “project” a lot, based on the name of the composer command “create-project”. A skeleton, however, can be for either a complete project, a library, a module/bundle or what ever else you can put in a composer package. Hell, you can probably even abuse a skeleton that, in the end, isn’t a composer package. (I wouldn’t recommend that.) The point is, when you read “project,” try to see it as a blank where you fill in whatever form of a project you require it to be — don’t get put off by the choice of the word.

Please keep in mind that the intent of the code you see here is to show you some of the possibilities. You can replace the example scripts with a task in your Makefile (or any other build system you are using), a shell script, a much more complex PHP script — whatever gets the job done.

Basics

What’s a skeleton?

You probably know this already, but lets start with what is a skeleton and how to use it. A skeleton is a pre-made project that is copied to create a new project. It contains all you need to start a certain type of project.

How do you use a skeleton?

Lets start with the most basic way to use a skeleton. Zend Framework2 currently suggests using their skeleton for a new ZF2 project by using the following commands:

cd my/project/dir
git clone git://github.com/zendframework/ZendSkeletonApplication.git
cd ZendSkeletonApplication
php composer.phar install

Why is ZF2 doing it this way? Basically, they’ve included composer.phar in their skeleton, so you don’t need to install composer yourself. That’s probably okay when getting a new developer new to their framework started, but it comes with a few issues:

  1. You end up with my/project/dir/ZendSkeletonApplication, rather than with my/project/dir
  2. A possibly out-dated composer.phar
  3. A .git dir in your project referencing the skeletons git repository.
  4. You can’t use a script on create-project, as create-project is not executed.
  5. The my/project/dir/ZendSkeletonApplication contains several files that belong to the skeleton project, but are not a skeleton to your project. In this example it’s the README.md, but with other skeletons it might also be build files, rmt config, a changelog…

(Note: Funnily enough, they’ve covered a better way in their README.md).

How can we improve it?

Composer allows for a command named create-project. This command allows us to have Composer deal with doing the actual cloning (and cleaning up the .git) for us. All we need to do is:

    composer create-project thecomposer/package my/project/dir

As I’ve used ZF2 for our example so far, here’s the line that you’d need for ZF2 to work:

    composer create-project -sdev zendframework/skeleton-application my/project/dir

Notice the added -sdev. It’s an option that allows installs with a dev stability set. Why? because ZF2 hasn’t ta

Truncated by Planet PHP, read more at the original (another 10395 bytes)

Link
SitePoint PHPGetting Started with Symfony2 Route Annotations (5.11.2014, 17:00 UTC)

When you download the Standard Symfony 2 Distribution, it includes an interesting bundle named SensioFrameworkExtraBundle which implements a lot of great stuff, especially the opportunity to use annotations directly within your controllers.

The idea behind this article is not to convice developers to embrace this way of doing, but to point the finger at an alternative method to easily configure controllers. Keep in mind that there is no magic recipe, it depends on what you need in each specific scenario.

Symfony 2 implements a strong built-in component to manage all the routes of an application: the Routing Component. Basically, a route maps a URL to a controller action. Because Symfony is intended to be modular, a file is dedicated to this: routing.yml. You will find it in app > config > routing.yml.

Continue reading %Getting Started with Symfony2 Route Annotations%

Link
Nomad PHPZombies and Binary (4.11.2014, 22:08 UTC)

Presented by Christopher Pitt@assertchris You may not use the PHP bitwise operators but every conditional you do is binary logic. These boolean comparisons underpin every-day programming and they can also be modelled in Minecraft. In fact, Minecraft is also a great place to model the internals of many common electronic components!

The post Zombies and Binary appeared first on Nomad PHP.

Link
Search Planet PHP Mozilla Searchbar
Twitter
Follow @planetphp on Twitter
BlogsSitePoint PHPStefan KoopmanschapFabien PotencierPádraic BradyChristian StockerPeter PetermannNomad PHPPHP 10.0 BlogPHP ClassesCal EvansBrandon SavagePHP-GTK CommunityAnthony FerraraChristian WeiskeIlia AlshanetskyUlf WendelChristopher JonesPascal MartinOfficial Blog of the PEAR Group/PEAR PresidentAnna Filinalabs @ Qandidate.comMatthias NobackSymfony CMFBernhard SchussekthePHP.ccMichelangelo van DamQafoo - PHPPHP: Hypertext PreprocessorEvert PotChris ShiflettRafael DohmsPaul M. JonesLorna MitchellDerick RethansHasin HayderPiotr PasichMichael KimsalThomas WeinertMatthew Weier O'PhinneyBen RamseyRoss Tuckeasybib/devSimon HolywellRemi CollettillPaul ReinheimerBradley HoltJohannes Schlüter
Linksspacer   spacer
spacer   spacer
spacer   spacer
FAQ and CodePlanet PHP FAQAdd your PHP blogCode on GitHub
Contactwe@planet-php.net
Sponsors
Hosted by netzwirt.ch and Liip.
Maintained by Chregu Stocker, Tobias Schlitt and more.
Logo designed by Colin Viebrock.
Twitter account by Sepehr Lajevardi
Buttonsspacer   spacer
spacer
PlanetariumPlanet PEARApacheDrupalMySQL
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.