archive-com.com » COM » S » STUARTHERBERT.COM

Total: 477

Choose link from "Titles, links and description words view":

Or switch to "Titles and links view".
  • Stuart on PHP - » 2011 » April
    pear pear pear upgrade Gradwell ComponentManager Once the latest version of ComponentManager has been installed you will need upgrade the skeletons of your existing components by doing cd where I put it my component phix php library upgrade This release has been tested on Ubuntu 10 10 Fedora 14 Any problems let me know About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Last Call For Requirements For A PEAR Channel Aggregator Posted by Stuart Herbert on April 27th 2011 in Toolbox A couple of weeks ago I posted a call for requirements for a PEAR channel aggregator There s already been a sizeable response so far but if you haven t had your say yet please head on over and leave a comment soon I ll write up a summary of the suggested requirements on Monday About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Ade Slade s DbUnit Talk Posted by Stuart Herbert on April 15th 2011 in phpsw 2 Intermediate Toolbox At phpsw this week former Gradwell er and all round good guy Ade Slade delivered a great talk about DbUnit Testing in general and doing testing the right way in particular is one of his great passions as a developer and he certainly brought a lot of enthusiasm and hands on experience to an often neglected part of unit testing one s code The talk and slides are on Ade s blog About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP Components Shipping Data Files With Your Components Posted by Stuart Herbert on April 11th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components I m now going under the bonnet of our components and looking at the different file roles that the PEAR installer expects to find when we distribute our component as a PEAR compatible package Although the vast majority of your components will simply be libraries of code sometimes you might need to ship data files for them to operate on Thanks to the PEAR installer s data role this is possible What Is A Data File A data file the data file role supported by the PEAR installer is an arbitrary file that your code either reads from or in the case of images et al serves up to other programs There are some important practices and limitations that you need to follow to avoid any disappointments or nasty surprises Data files should not be PHP code that you plan on executing Your users expect your code to be in the standard place which is usr share php for popular Linux systems or vendor php in the per app sandbox Follow the rule of no surprises and make sure you put your code where your users expect to look for it For example PEAR s HTTP2 Request component ships PHP code in its data folder code to rebuild the Public Suffix List which is itself a data file The chances are that most of HTTP2 Request s users are unaware that the data folder exists and that there is code in the data folder which they might need to use Another example is ezComponent s ConsoleTools which ships a UML diagram for ezComponents in its data folder This probably belongs in the docs folder if it is meant to be read by developers using ConsoleTools My local usr share php contains many more relevant examples yours probably does too Our component skeleton offers an alternative approach to ship generate list php a properly installed command line program or perhaps as a drop in command for phix Data files cannot be written to your code should treat them as read only When your data files are installed for system wide use the files are owned by the root user Unless there is an almighty security cock up your code will never ever actually get to run with the root user s security privileges If your code tries to write to these data files it will generate a runtime error But this won t show up when you unit test your code So remember and don t write the code in the first place Where Do Data Files Go Inside The Component s Structure If we take a look at the ComponentManagerPhpLibrary component you ll find the data files are inside in the src data folder These are the skeleton files used for a PHP library component src data is meant to be a folder that holds the data files that you want installed into the computer system Where Do Data Files Get Installed When you use the PEAR installer to install your component pear install phix ComponentManagerPhpLibrary all of the files in your component s src data folder gets installed into usr share php data package name on your computer The PEAR installer s behaviour here is different to both command line scripts and PHP code the installer creates a sub folder with the name of your package and then installs your data files into this sub folder and not into the main data dir folder This isn t a problem in practice as long as you are aware of the different behaviour here The data file script src data php library README md therefore ends up installed onto your computer as usr share php data ComponentManagerPhpLibrary php library README md There s always the possibility that some Linux distros and Mac OS X will install data files into a different folder You can see where the PEAR installer will put these files on your computer by running sudo pear config show grep data dir PEAR data directory data dir usr share php data If you want to read these data files from your PHP code you cannot safely hard code the final installation location into your scripts it will vary from OS to OS and will also be different again if your component is installed into a vendor directory You ll need to locate these files using a different technique How Do I Locate The Data Files From My PHP Code Take a look at the top of the LibraryComponentFolder class from the ComponentManagerPhpLibrary component code lang php class LibraryComponentFolder extends ComponentFolder const DATA DIR DATA DIR ComponentManagerPhpLibrary php library code DATA DIR is a token that at runtime the PEAR installer expands to be the fully qualified path to the top of the computer s data dir Underneath that you need to remember to add your component s name to the path otherwise you ll be scratching your head and wondering why you can t find the data files The full instructions that tell the PEAR installer to expand this token are added to your component s package xml file when we build the PEAR compatible package I ll look at the final package xml file in detail towards the end of this series of blog posts How Do I Unit Test PHP Code That Relies On Data FIles There is one important downside to this technique any unit tests that rely on loading data from your data directory are going to fail because DATA DIR is only expanded when the PEAR installer installs your component At the time of writing I don t have an easy solution for this but leave it with me and I ll find a solution for this before the end of this series of blog posts About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP South West phpsw User Group Meeting 7pm Wednesday 13th April 2011 Bristol Posted by Stuart Herbert on April 11th 2011 in phpsw March s meeting of the PHP SouthWest User Group will be at The Golden Guinea in Redcliffe Bristol from 7pm on Wednesday 13th April What Is Planned Ade Slade will be giving his talk on unit testing something he has a deep passion for We ll also discuss progress on the phpsw community website and be looking for more volunteers to help build and maintain it How To Get There We ll be at The Golden Guinea 19 Guinea Street Bristol BS1 6SX It s a short walk from Bristol Temple Meads Railway Station if you re coming by train How To Get Involved Please join the PHPSW Google Group and say hello About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Gathering Requirements For A PEAR Channel Aggregator Posted by Stuart Herbert on April 9th 2011 in Toolbox I ve had several conversations on Twitter about how it could be a good idea for someone to setup a new community website for PHP components This website would not host components itself it would track all of the independently published PEAR channels and be the one stop shop for users to come to whenever they needed to find a component to solve a requirement I think this would be a good thing for the PHP ecosystem So requirements What do you want from such a website What do you want it to do How do you want it to work At this stage the sky s the limit Leave your requirements in the comments please and I ll pull them together into a summary post next weekend Once the requirements are stable ish I d like to organise a hackathon to get the first version built and live If you re up for that and want to help make that happen do ping me on Twitter stuherbert About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP Components Shipping A Command Line Program Posted by Stuart Herbert on April 6th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components I m now going under the bonnet of our components and looking at the different file roles that the PEAR installer expects to find when we distribute our component as a PEAR compatible package One of the useful file roles allows us to install new command line programs such as PHPUnit or Phix onto a computer for everyone to use What Is A Command Line Program A command line program the script file role supported by the PEAR installer is a PHP script that your users run from inside Terminal or Command on Windows It allows you to put powerful tools in the hands of your users You can also run them as scheduled jobs via cron Where Do Command Line Scripts Go Inside The Component s Structure If we take a look at the phix component you ll find the command line program itself in the src bin folder src bin is meant to be a folder that holds the commands that you want installed into the computer system In theory you could put sub folders under here but this is not supported If you look at phix s actual code you ll see that the phix command line program loads code that exists in the src php folder of the component and is installed into usr share php when the PEAR installer installs the component Your classes should go in src php just like with any other component Where Do Command Line Programs Get Installed When you use the PEAR installer to install your component pear install phix phix all of the files in your component s src bin folder gets installed into usr bin on your computer The command line script src bin phix therefore ends up installed onto your computer as usr bin phix The reason why the PEAR installer installs your PHP code under usr bin is because this folder is normally part of a user s search path in Terminal That allows users to run your command line program simply by phix without having to specify the full path to your command line program I haven t seen it personally but there s always the possibility that some Linux distros and Mac OS X will install command line programs into a different folder You can see where the PEAR installer will put these files on your computer by running sudo pear config show grep bin dir PEAR executables directory bin dir usr bin How Do I Make My Command Line Program Executable You re probably used to running PHP scripts from the command line like this php my script php but for command line programs you don t want your users having to remember to run everything through the PHP interpreter each time UNIX and UNIX like operating systems such as Linux have a long tradition of writing command line programs using scripting languages If you put a shebang the characters hash pling at the top of your script you can tell your operating system how to execute your script usr bin env php php PHP code goes here The line usr bin env php tells your operating system to use the PHP CLI interpreter wherever it is in your Terminal s path to run this script Using usr bin env in this way normally makes your script portable across different Linux distros About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP Components Shipping Reusable PHP Code Posted by Stuart Herbert on April 5th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components I m now going under the bonnet of our components and looking at the different file roles that the PEAR installer expects to find when we distribute our component as a PEAR compatible package To get started I m going to start with the obvious file role the PHP code that a component is all about What

    Original URL path: http://blog.stuartherbert.com/php/2011/04/ (2016-05-02)
    Open archived version from archive


  • Stuart on PHP - » 2011 » March
    have been executed during the unit tests and which lines of code have gone untested making it very easy for you to see where the gaps in your testing are Aim For 100 Code Coverage I m the first to admit that this is something I ve changed my tune over When I was trained as a professional engineer in the 1990 s we were taught to do 100 code coverage and frankly the cost of writing all those tests seemed horrendous to me On one project I worked on the project manager told me that he budgeted 40 of our time for writing tests As the dot com bubble came and everyone rushed to compete on Internet Time no I didn t believe in it then and I definitely don t believe in it now the emphasis was on shipping code with all possible haste 100 code coverage seemed a luxury no one could afford Today with the benefit of 20 20 hindsight I can clearly see that the costs of shipping partially working barely working code are just too high Even cobbled together code ends up surviving for many years longer than anyone anticipated and that just means generation after generation of programmer having to waste time maintaining the code or spending their time instead creating and shipping their own barely working code I ve been experimenting with and developing this approach to components in PHP since summer 2010 annual vacations are great for getting some hacking done and there s no way I m going to admit how many bugs I found in my own code code I was actively using when I went back to add 100 coverage Suffice to say it was a lot and more than enough to convince me of just how important 100 code coverage is to a component 100 code coverage does not guarantee that your code is bug free it is not the magic target that will produce zero defect code But it is a good step in the right direction About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP Components Testing Remote Web Services The Quick And Nasty Way Posted by Stuart Herbert on March 29th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components To be a success all components need high quality unit tests and this applies to the component I am building a client for Repustate com s semantic analysis API But how do you go about creating the unit tests for a remote web service without the process becoming onerous or even dangerous Can You Test The Quick And Nasty Way This is the first question that always comes to mind whenever I m writing an API client I don t want to do it the classical way of creating my own mockup of the web service if that can be avoided Mockups are slower to build and they perpetuate any misunderstandings I have about the API and its behaviour I want to test directly against the API so that I can catch errors immediately and have confidence that my code will work in production Technically these are integration tests not unit tests and there are good arguments out there for also having the mocked up unit tests too but I m a pragmatic engineer and I need to get this done before my app s requirements change Now this all comes down to whether or not the web service makes life easy for developers or not Does the web service provide a test API where I can reset the state of my account to a known position before I start testing This is the holy grail for writing tests against an API Tests must be deterministic same data in must always produce the same result out to be trustworthy Being able to use a test API where I can control the starting conditions before I run my tests gives me everything I need to safely test against the web service s endpoint Sadly you re more likely to see a unicorn than come across one of these but never give up hope Is the API destructive in a disruptive way If I have to test against the live API can I do so safely Can I write tests that will not cause trouble for my production systems that are using the API Often the answer to this is yes which is great news Not as good as our unicorn test API above but something I can work with Do I have to mock up the API locally This is the testing of last resort tbh but sometimes you re left with no choice on the matter And it s worth me mentioning that API mockups are actually the best way to deal with regression tests against your own client as they allow you to catch badly formed requests to the remote API perfectly At the time of writing I couldn t find my unicorn test API for Repustate but because their live API is entirely non destructive there is little risk in making my unit tests for this component work against the live API Never Commit Your API Key Like many web services Repustate s requires you to apply for an API key which is then used to authorise your web service requests This allows Repustate to keep track of who is doing what and allows them to revoke access if the web service is abused To run the tests against the live API my test code is going to need to know the API key that I ve obtained from Repustate But if I commit that to the component s public GitHub repo I m simply asking for every script kiddie to abuse that key It s simply not safe to commit this key And it wouldn t be safe if the repo was private how do I know that one day the repo won t be open sourced with the key available to find in the repo s history Never ever ever commit an API key to a component s source control repo But my test code needs this API key Where can it get the API key from We could put the key in a config file that s installed by an uber secret component and indeed this is a practical approach when you re controlling the deployment of apps in the enterprise Just don t make it so secret that your own devs can t work on it That kinda brings a lot of work to a standstill But that won t work for an opensourced component that hopefully others will find useful So we need to put the API key somewhere else just for the tests to work Getting The Key From The Environment The easiest place for the unit tests to look is in the process s environment First I need to set the key like this stuart Devel sental repustateApi export REPUSTATE KEY my API key This puts the key into the environment of my terminal s bash shell When I run the tests from this shell the API key will be available for my tests to use code lang php apiKey getenv REPUSTATE KEY code This is a handy tip and it means I can now get on with the quick and dirty approach to unit testing my component without worrying about giving anyone my API key to abuse It does cause one problem though anyone who downloads my component and tries to run the unit tests will simply see them fail I will mention it in the component s README md file but I cannot rely on anyone actually reading that file in all honesty For now I ve addressed that by testing for the REPUSTATE KEY environment variable and if it doesn t exist the unit tests die with clear instructions rather than fail About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP Components Working With Non Namespaced Components Posted by Stuart Herbert on March 28th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components A component based approach works well with the new namespace support added to PHP 5 3 and indeed I m making full use of this in the components I m building for this tutorial But not everyone is ready to move to namespaces and when you start to consume older components inside yours you might run into errors Namespaces Recapped The whole idea behind namespaces is to make life easier for developers by doing away with having to type incredibly long class names all the time For example take the ConsoleDisplayLib component I recently released In the pre PHP 5 3 days I would have had to define the classes it provides like this code lang php class Phix Project ConsoleDisplayLib StdOut code and then when I wanted to use it I would have to do this code lang php stdout new Phix Project ConsoleDisplayLib StdOut code A workable system to be sure and one that OO PHP programmers have used for many years but hardly RSI friendly I m sure you agree With namespaces however things change The class is now defined like this code lang php class Phix ProjectConsoleDisplayLibStdOut code Note the use of instead of underscores That s PHP s new namespace separator and it tells PHP that the class StdOut lives inside the Phix ProjectConsoleDisplayLib namespace which in turn lives inside the Phix Project namespace Namespaces are just another kind of scope like local scope vs global scope Hold that thought because it s these new scopes that affect our attempts to mix in non namespaced code If I m writing code that is part of ConsoleDisplayLib to create a new StdOut object I now only need to do this code lang php namespace Phix ProjectConsoleDisplayLib stdout new StdOut code PHP automatically expands StdOut to mean Phix ProjectConsoleDisplayLibStdOut because I ve used the namespace keyword to tell PHP that this code is part of Phix ProjectConsoleDisplayLib And that is where the fun begins Adding HTTP Request2 To RepustateApi I ve made the choice to reuse the existing PEAR component HTTP Request2 The PEAR project doesn t currently use namespaces all classes defined by HTTP Request2 exist in the global scope So if I try to use HTTP Request2 like this inside my Repustate API client code lang php namespace GradwellRepustateApi httpClient new HTTP Request2 url HTTP Request2 METHOD POST code PHP reports the fatal error Class GradwellRepustateApiHTTP Request2 not found First time you see this you might be wondering what is going on and how to fix it After all the class is called HTTP Request2 Why is PHP trying to load a class called GradwellRepustateApiHTTP Request2 The answer is simple By using the namespace keyword at the top of the file I ve told PHP to assume that all of the code in this file is part of the GradwellRepustateAPI scope So just like in my ConsoleDisplayLib example where PHP automatically expanded StdOut to be Phix ProjectConsoleDisplayLibStdOut PHP is going to expand HTTP Request2 to be GradwellRepustateApiHTTP Request2 That isn t what we want but that s PHP s fault We need to tell PHP that in this case we want it to load HTTP Request2 and not GradwellRepustateApiHTTP Request2 Load From The Global Namespace Getting PHP to load code from the global namespace instead of from your component s namespace is very easy you ve just got to remember to do it everywhere Simply make sure you ve put a at the start of any classnames that are part of the global namespace code lang php namespace GradwellRepustateApi httpClient new HTTP Request2 url HTTP Request2 METHOD POST code Remember to do this and you ll have no trouble working with non namespaced components inside your own components About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP Components Dealing With PEAR Dependency Quirks Posted by Stuart Herbert on March 28th 2011 in Examples phix Toolbox In my Beyond Frameworks talk I explained how a component based architecture can help answer some of the important i e expensive questions you might face when creating long lived apps that rely on a PHP framework In this series of blog posts I m going to look at how to go about creating and working with components Last week I began work on a simple component to talk to the Repustate semantic analysis API To save myself a bit of effort I thought it would make sense to make my API client reuse PEAR s existing HTTP Request2 component No sense in re inventing the wheel I thought But that s where my troubles began There are a few quirks in the way that the PEAR installer handles version numbers and you need to know how to deal with them if you re going to re use PEAR project components in your own apps Adding A Dependency On HTTP Request2 HTTP Request2 is PEAR s very useful wrapper around making HTTP requests from your app At the time of writing there are 22 PEAR packages that rely on it a good indicator that this component is doing something right Making the repustateApi component rely on PEAR s HTTP Request2 should be as simple as adding the following to the lt required section in package xml package name HTTP Request2 name channel pear php net channel min 2 0 0 min max 2 999 9999 max package But when I try to rebuild the vendor folder this is the sandbox where all of the component s dependencies are installed so that we can run our unit tests using the command phing build vendor I get an error echo Populating vendor with dependencies exec Executing command phix pear register channels 2 1 exec Registering PEAR channel pear gradwell com exec Adding Channel pear gradwell com succeeded exec Discovery of channel pear gradwell com succeeded exec Registering PEAR channel pear php net exec Channel pear php net is already initialized exec Executing command pear c home stuarth Devel sental repustateApi tm p pear config install alldeps home stuarth Devel sental repustateApi buil d package xml 2 1 exec Failed to download pear HTTP Request2 version 2 0 0 version 2 0 0 version 2 999 9999 exec downloading Autoloader 2 0 1 tgz exec Starting to download Autoloader 2 0 1 tgz 2 080 bytes exec done 2 080 bytes exec install ok channel pear gradwell com Autoloader 2 0 1 So what s going on And what do we need to change to make this dependency work PEAR Version Numbers and Stability There are two things preventing the PEAR installer from downloading the package The package s version number is 2 0 0beta2 not plain old 2 0 0 The package has been marked as beta quality rather than as a stable release From HTTP Request2 s point of view this is all perfectly reasonable The package authors are currently transitioning from the older PHP4 based HTTP Request and they re not yet ready to unleash HTTP Request2 on the world As a result the PEAR installer is rightly looking at the dependency information I ve set and telling me that HTTP Request2 is not yet at version 2 0 0 The PEAR installer doesn t just use version numbers when handling dependencies If you dig deep into package xml you ll find not only a version tag but also a stability tag Here s the tags from PEAR s HTTP Request2 s package xml at the time of writing version release 2 0 0beta2 release api 2 0 0 api version stability release beta release api beta api stability How To Depend On A Beta PEAR Component The fix we need to make to package xml

    Original URL path: http://blog.stuartherbert.com/php/2011/03/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » 2011 » February
    the first published blog post url http blog stuartherbert com photography rawHtml file get contents url preg match rawHtml matches blogPosts array flickrPhotos array latestPost matches 1 nextPost url p latestPost function updatePhotos photoIndex flickrPhotos blogPosts f foreach photoIndex as photoId flickrPhoto we must rewrite the description preg match Copyright s flickrPhoto description matches if isset matches 1 description matches 1 else description description Copyright c Stuart Herbert Blog Twitter Facebook n Photography Merthyr Road Daily Desktop Wallpaper 25 9 Twitter nn if count flickrPhoto blogPosts 1 description Want to know more about this photo See this blog entry nn else description Want to know more about this photo See these blog entries nn foreach flickrPhoto blogPosts as postUrl blogPost description blogPost title n description is made now to upload it echo Photo photoId flickrPhoto title n echo URL flickrPhoto url n echo Old flickrPhoto description n echo New description n echo nPushing changes to Flickr f photos setMeta photoId flickrPhoto title description echo donen while nextPost null photoIndex array echo Downloading nextPost rawHtml file get contents nextPost echo donen if rawHtml die Unable to download HTML for URL nextPost n preg match Us rawHtml matches postUrl matches 2 title matches 3 echo Blog post title is titlen echo Blog post url is postUrln preg match Previous Post rawHtml matches if isset matches 1 nextPost matches 1 else nextPost null preg match Us rawHtml matches if isset matches 1 die regex failed againn entryHtml matches 1 preg match all http www flickr com photos stuartherbert 0 9 entryHtml matches blogPosts postUrl url postUrl blogPosts postUrl title title blogPosts postUrl matches matches foreach matches 1 as flickrPhoto parts explode flickrPhoto photoId parts count parts 2 photoInfo f photos getInfo photoId flickrPhotos photoId url flickrPhoto flickrPhotos photoId title photoInfo title flickrPhotos photoId description photoInfo description flickrPhotos photoId blogPosts postUrl blogPosts postUrl note the photos we need to update because we have seen this post photoIndex photoId flickrPhotos photoId echo Photo photoInfo title n updatePhotos photoIndex flickrPhotos blogPosts f echo nn echo Photo scraping complete nn when we get to here we have photos to go and update on flickr code About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan 1 comment PHP South West phpsw User Group Meeting 7pm Wednesday 9th February 2011 Posted by Stuart Herbert on February 1st 2011 in phpsw February s meeting of the PHP SouthWest User Group will be at The Golden Guinea in Redcliffe Bristol from 7pm on Wednesday 9th February What Is Planned I m speaking at the

    Original URL path: http://blog.stuartherbert.com/php/2011/02/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » 2010 » October
    Stuart Herbert on October 19th 2010 in phpnw Conferences Another year another great PHP North West conference organised by Jeremy Coates and his team at Magma Digital and the PHP North West User Group This year I went along with my camera to try my hand at conference photography for the first time in between attending plenty of great talks These are my best shots of Jeremy Coates who led the organising effort for the conference There ll be more shots from the conference tomorrow I ve also posted my thoughts on being a first time conference photographer over on my photography blog Copyright c Stuart Herbert Blog Twitter Facebook Photography Merthyr Road Daily Desktop Wallpaper 25 9 Twitter About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHPNW10 Friday Social Posted by Stuart Herbert on October 18th 2010 in phpnw Conferences Another year another great PHP North West conference organised by Jeremy Coates and his team at Magma Digital and the PHP North West User Group This year I went along with my camera to try my hand at conference photography for the first time in between attending plenty of great talks These are the best of my shots from the pre conference socials on the Friday night before the conference There ll be more shots from the conference tomorrow I ve also posted my thoughts on being a first time conference photographer over on my photography blog Copyright c Stuart Herbert Blog Twitter Facebook Photography Merthyr Road Daily Desktop Wallpaper 25 9 Twitter About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment PHP South West phpsw User Group Meeting 7pm Tonight Bristol Posted by Stuart Herbert on October 13th 2010 in phpsw Tonight s meeting of the PHP SouthWest User Group will be at The Third Floor Bush House Bristol from 7pm We ll be in the conference room for an hour and then from 8pm downstairs in the bar at the Arnolfini What Is Planned There were quite a

    Original URL path: http://blog.stuartherbert.com/php/2010/10/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » 2010 » August
    source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Setting Up A PHP Southwest UK User Group Posted by Stuart Herbert on August 19th 2010 in News London and the North West of the UK have their own successful PHP user groups and it s time we had one here in the South West I ve setup a PHP SW group on Google to get us started and we re already talking about where probably the centre of Bristol and when to have our first meet up Why not join the group and the discussion I m hoping to appeal to folks using PHP who live or work in the Bristol Bath South Wales and South West of England regions to come along and join in There must be plenty of us in the area About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Latest Photos Categories phpnw 1

    Original URL path: http://blog.stuartherbert.com/php/2010/08/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » 2010 » July
    m happy to pass back PHP has the assert method to help with this but it is deficient and best avoided I d like to share the approach I m currently using for this to get constructive feedback on how to evolve the style further At the heart of this approach lies the constraint It is a test that must be satisfied a bit like a runtime unit test We could do this inline code lang php function breakMe inputData I am bad data enforce our constraint if is array inputData throw new Exception Bad data inputData expected array code but the problem with that is that it quickly bulks out your code with a lot of repetitive and avoidable content An ideal candidate to make into a function or a method which could yield code lang php function constraint mustBeArray testData if is array testData throw new Exception Constraint failed function breakMe inputData I am bad data our constraint is now in a nice function constraint mustBeArray inputData code Here we are trading performance the cost of a function call for both developer efficiency and reduced future maintenance costs In general the trade off is worth it most PHP developers work on small sites where developers are more expensive than runtime costs within reason The time saved from proving that code is working and bailing immediately we prove otherwise is worth saving We re also introducing an important principle there s no return value to check If execution continues on the line below the call to constraint mustBeArray we can assume that the constraint was passed If the constraint failed we let whatever exception handlers there are well handle it There s a couple of problems with this style that have been nagging me It has a lot of advantages and is probably good enough but There s no autoload support in PHP for functions making it a pain to work with a large number of functions in an app or framework Life is easier if the constraints are defined as object methods instead There s limited potential to re use constraints once they have been defined They have to be explicitly called It would be great if they could be passed into say a data model layer of some kind as parameters to assist in data integrity checking Note the common thread of making sure that bad data is detected as early as possible and pro actively rejected by the app This led me to a more OO style code lang php class MyFramework Array static public function mustBeArray testData if is array testData throw new Exception Constraint failed function breakMe inputData I am bad data constraint is now in a reusable object method MyFramework Array mustBeArray inputData code Well it is object oriented for sure but it still isn t reusable but it could be with lambda functions code lang php class MyFramework Array static public function mustBeArray testData create the lambda function constraint function testData if

    Original URL path: http://blog.stuartherbert.com/php/2010/07/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » 2010 » February
    is that third parties can make money off it not just the original creator provider Now if only Zend had an outreach programme for making Zend Server suited both technically and commercially for ISPs like where I work to consider adopting for their shared hosting and VPS customers About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Can HipHop Help The Planet Posted by Stuart Herbert on February 3rd 2010 in Opinion PHP In Business Toolbox By now you might have heard the details of HipHop Facebook s PHP to C convertor that was announced yesterday Like most of you I m eagerly awaiting the release of the code so that I can play with it and learn in detail what it can do and what it can t For now Marco s post seems to have the most technical information in it so far I m with Sebastian on this one Whether or not you think Facebook s HipHop is relevant to you I think they deserve credit for having shared their particular solution with the wider community They ll get extra credit when they actually release some code After all they ve built on top of open source in the first place giving something back to the community is part and parcel of being a good member of the community How many of you earn your living from open source but have never contributed anything back But that isn t really what I want to blog about today I ve been following the chat on Twitter about HipHop and I think all the nay sayers have been overlooking an important point HipHop has the potential to reduce the amount of power consumed in running a website And surely that can only be a good thing for all of us If you don t run your own servers in a data centre for example you use a virtual server or host on a shared hosting solution then perhaps you might not be aware that the power required by each server in a rack is often a major factor in the overall cost of running the servers Whether or not you believe in climate change energy prices are on the rise Whether or not you believe in peak oil oil and natural gas supply issues are forecast to push energy prices up further Taking steps to get more work done per unit of power consumed has been the focus of hardware manufacturers for several years now

    Original URL path: http://blog.stuartherbert.com/php/2010/02/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » 2010 » January
    try and learn a bit more about your plans to move to PHP 5 3 and whether or not you actually followed through A huge thank you to everyone who voted I m not talking at any conferences this year so I ve published the planned PHP 5 3 adoption talk online for anyone who s interested in what the PHP user community told us via these polls As well as the raw data I ve included an analysis of what the data might mean and some talking points about what the PHP Group might want to do differently when PHP 6 or PHP 5 4 if there is one is released You can find the talk online at Slideshare along with all of my older talks I hope you find it useful and informative Php 5 3 Adoption View more presentations from stuartherbert About The Author Stuart has been writing PHP applications since 2003 and has been contributing to open source software since 1994 He was an early writer for php architect a co author of the Official Zend Certification Study Guide for PHP 4 and a regular speaker at conferences and user groups since 2004 When he s not designing software Stuart loves to explore the world through a camera lens spend time with his beloved guitars and continue his study to T ai Chi Chu an Taijiquan Be the first to leave a comment Playing With Storytlr Posted by Stuart Herbert on January 26th 2010 in Storytlr I haven t been blogging very much for some time now since the car crash my weekends have mostly been spent recovering from the long commute to and from work during the week But I do tweet a lot and thought it would be a good idea to update my website to show more of a lifestream rather than just the blog Storytlr has been getting a few mentions recently such as this story on Arstechnica since its authors decided to release it under the Apache license Based on Zend Framework Storytlr is relatively simple to install but not yet as polished as WordPress has become My first impressions are that it has promise but that it s not yet a 1 0 release in terms of quality That surprised me given that the guys used to run a business based on this but full credit to them for placing the code under an open source license so that the community can keep it alive The Google project I wouldn t say it was dead but at the time of writing it hadn t been updated for over six weeks There s also a github project from the Storytlr authors and jmhobbs has an active clone of the Storytlr project where he s busy adding some much needed polish I ve cloned the project too and I ll commit fixes and improvements such as improving the Twitter plugin and a new podcasting plugin there as and when time allows I

    Original URL path: http://blog.stuartherbert.com/php/2010/01/ (2016-05-02)
    Open archived version from archive



  •