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 - » PHPNW10: Jeremy Coates
    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 Comments are closed Latest Photos Categories phpnw 1 Beginner 2 Intermediate 3 Advanced Brighton PHP Conferences Opinion phix PHP In Business PSR Servers and Hosting Storyplayer Talks Toolbox Training Uncategorized Archives February 2016 January 2016 November 2015 October 2015 August 2015 March 2015 January 2014 May 2013 April 2013 March 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 February 2012 January 2012 October 2011 September 2011 August 2011 July 2011 April 2011 March 2011 February 2011 October 2010 August 2010 July 2010 February 2010 January 2010 October 2009 September 2009 August 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 June 2008 May 2008 April 2008 March 2008 January 2008 December 2007 November 2007 October 2007 July 2007 April 2007 March 2007 February 2007 January 2007 This Month October 2010 M T W T F S S Aug Feb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

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

  • Stuart on PHP - » PHPNW10: Friday Social
    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 Comments are closed Latest Photos Categories phpnw 1 Beginner 2 Intermediate 3 Advanced Brighton PHP Conferences Opinion phix PHP In Business PSR Servers and Hosting Storyplayer Talks Toolbox Training Uncategorized Archives February 2016 January 2016 November 2015 October 2015 August 2015 March 2015 January 2014 May 2013 April 2013 March 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 February 2012 January 2012 October 2011 September 2011 August 2011 July 2011 April 2011 March 2011 February 2011 October 2010 August 2010 July 2010 February 2010 January 2010 October 2009 September 2009 August 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 June 2008 May 2008 April 2008 March 2008 January 2008 December 2007 November 2007 October 2007 July 2007 April 2007 March 2007 February 2007 January 2007 This Month October 2010 M T W T F S S Aug Feb 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

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

  • Stuart on PHP - » PHP South West (#phpsw) User Group Meeting, 7pm Tonight, Bristol
    Bristol BS1 4QD This Google Map has directions if you re walking from Bristol Temple Meads Railway Station When you get to the entrance for Bush House you ll need to press the bottom buzzer marked The Hub to gain access 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 Comments are closed Latest Photos Categories phpnw 1 Beginner 2 Intermediate 3 Advanced Brighton PHP Conferences Opinion phix PHP In Business PSR Servers and Hosting Storyplayer Talks Toolbox Training Uncategorized Archives February 2016 January 2016 November 2015 October 2015 August 2015 March 2015 January 2014 May 2013 April 2013 March 2013 December 2012 November 2012 October 2012 September 2012 August 2012 July 2012 June 2012 May 2012 February 2012 January 2012 October 2011 September 2011 August 2011 July 2011 April 2011 March 2011 February 2011 October 2010 August 2010 July 2010 February 2010 January 2010 October 2009 September 2009 August 2009 May 2009 April 2009 March 2009 February 2009 January 2009 December 2008 November 2008 October 2008 September 2008 August 2008 June 2008 May 2008 April 2008 March 2008 January 2008 December 2007 November 2007 October 2007 July 2007 April 2007 March 2007 February 2007 January 2007 This Month October 2010 M T W T F S S Aug Feb

    Original URL path: http://blog.stuartherbert.com/php/2010/10/13/php-south-west-phpsw-user-group-meeting-7pm-tonight-bristol/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP -
    component s metadata In all honesty after you ve done it a few times you can create a new component in a matter of minutes and this is work you only have to do the once In the next blog post we re going to start creating the initial tests for this component Be the first to leave a comment PHP Components Setting Up Your Component s Metadata Pt 1 Posted by Stuart Herbert on March 24th 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 In the last post I used phix to create an empty component I now need to edit the component s manifest files before I can start cutting code What s Your Component Called The first file we need to edit is called build properties It s a standard format ini file that contains a few bits of data for us to edit When I designed the component skeleton I put these in their own file so that we never have to edit the build xml file which means we can upgrade build xml in future via the phix php library upgrade command An unedited build properties file looks like this project name your project name project majorVersion X project minorVersion Y project patchLevel Z checkstyle standard Zend component type php library component version 3 As this is the first version of my component I m going to call this version of the component repustateApi 0 1 0 That means that I need to change the top four lines of build properties to look like this project name repustateApi project majorVersion 0 project minorVersion 1 project patchLevel 0 You can see the fullly edited build properties file on GitHub Why did I pick 0 1 0 as the version number What s In A Version Number When it comes to components we need to adopt a sane and engineering focused version numbering scheme otherwise we run into a lot of trouble when trying to trust our own and other people s components over time I went into this in some detail in my Beyond Frameworks talk and it basically boils down to this The scheme itself reads major minor patchLevel or if you prefer x y z All versions 1 y z must be 100 backwards compatible You can fix bugs and add new features but if you break backwards compatibility you need to create version 2 y z The people who use your components need to be confident that they can upgrade the component to get the latest fixes and features without any nasty surprises that force them to also go to the trouble of editing their own code Make the major version number your promise to other developers that they can upgrade safely Don t be afraid to create version 2 y z version 3 y z etc as rapidly as needed Google has done exactly this with Chrome and it hasn t exactly done them any harm If you re adding new features and not breaking backwards compatibility turn version 1 0 into version 1 1 1 2 and so on And if you re only putting out bug fixes just increase the last number and turn version 1 0 0 into version 1 0 1 1 0 2 and so on This numbering scheme is called Semantic Versioning Please do follow it That s all that we need to edit in build properties We still need to setup package xml which I ll cover in the next blog post Be the first to leave a comment PHP Components Creating A Skeleton Component Posted by Stuart Herbert on March 24th 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 In my last article I posted a list of questions to consider when decomposing the design of an app and I put together the first cut of the components that will make up my sentiment analysis app Now it s time to get into creating the app s first component using phix Dev Environment Prep If you haven t already you ll need to install phix onto your dev computer You ll find the latest instructions on how to install phix on the Phix Project s website Thankfully we only have to do that once Now with the development environment prepared we can get our component under way Creating The Skeleton For The Component Creating a skeleton component is as easy as stuart Devel sental mkdir repustateApi stuart Devel sental cd repustateApi stuart Devel sental git init Initialized empty Git repository in home stuart Devel sental repustateApi git stuart Devel sental repustateApi phix php library init Initialised empty php library component in What have we created A Quick Tour Of The Skeleton Here s a quick list of what the php library init command has created in the repustateApi folder stuart Devel sental repustateApi git status On branch master Initial commit Untracked files use git add to include in what will be committed gitignore hgignore LICENSE txt README md build properties build xml package xml src nothing added to commit but untracked files present use git add to track Each of the files serves a useful purpose gitignore and hgignore These are basic filters to tell Git and Mercurial what to ignore in here As we develop the component there will be a few temporary folders created which we ll never want to end up in version control Filter files for other version control systems are welcome LICENSE txt Every component needs to come with a clear statement about the rules for re use even if it just says All rights reserved If you re looking to open source your code you ll find many well tested licenses from the Open Source Initiative s website README md Every component needs basic documentation to help a new user get started with it By putting that into a README md file GitHub will automatically pick that up and display it on the component s website build properties This is a file we re going to edit shortly It contains a little bit of metadata about your component such as it s name and version number build xml This is a file for phing a sort of Ant clone written in PHP We re going to use the commands defined in this file to run our unit tests build our PEAR compatible package and even install it for local testing package xml This is the manifest file that the PEAR installer looks for when trying to install your component We re going to edit this file shortly adding in some data about our component but most importantly listing all of the components that our component depends on Don t let the terse PEAR documentation put you off it s quite an easy file to work with and the error prone bits get auto generated for you by the build xml file when the time comes src folder Here s where your source code goes There s a subfolder under here for each of the different types of file that your component might contain Don t worry about that too much for now we ll explain what goes where as we build these components up Why A Skeleton Helps Our skeleton takes care of all of the chores and housekeeping for you leaving you free to focus on writing your code and your tests It gives you a standard structure to work within making it very easy to move from one component to the next or share development duties with a wider and possibly remote team This structure has been carefully designed to work with the somewhat fickle PEAR installer s preconceptions and also to work well with both PHPUnit and Netbeans It should work well with Eclipse PDT too let me know how you get on And old skool vim users shouldn t have any troubles either As the skeleton improves pull requests are very welcome you can use the very handy phix php library upgrade command to get the improvements dropped right into your components Another bonus feature of adopting a standardised skeleton instead of rolling everything by hand In the next blog post we ll get build properties and package xml setup and get the vendor folder created What s the vendor folder I ll tell you next time Be the first to leave a comment PHP Components Decomposing An App Into Components Posted by Stuart Herbert on March 23rd 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 In the last article I set out some very simple requirements for my example app Now that I have an idea of what I want to build I need to break that down into a set of components to create My apologies if you re keen to jump straight to the code it s coming soon and I want to make sure it s the right code when we get there Thought Process Decomposition Decomposition is all about figuring out how to chop up a large problem into a co operating sets of smaller problems If you get the boundaries right across the set then you can solve each of the smaller problems on their own glue it all together and job done In a traditional PHP app decomposition normally means getting into class design When you re working with components you need to decide how you re going to group those classes together into components Figuring out your list of components and their contents very much a creative process I m a visual person so I do it by scribbling on whiteboards or moving things around in OmniGraffle There are few right or wrong solutions most wrong solutions are really just philosophically differences between people but there are a few important questions that I ask myself to avoid problems later down the road Questions When Decomposing To Components When I m deciding what should be grouped into components I m always asking myself these questions Does the component do one job and do it well This is the key question Just like classes that have too many responsibilities become too complex to both use and maintain the exact same trap lies in wait when you start designing components just on a larger scale Take a look at the components that phix is made up of by reading its package xml file Each of those components does one job and only one job phix glues them all together but you could take any one of those components and use it to solve the same problem in a different app Is it clear which components relies on which A good feel good factor for deciding whether you ve got the right components or not is how easy it is to compile a list of which components your app relies on and which components in turn they rely on If you feel any doubt or uncertainty then listen to your heart and carve up the code into a different set of components Ultimately you need to be able to fill out your component s package xml file with a definitive list Take a look at ComponentManager s package xml file as an example It clearly states every component that ComponentManager glues together Do two components mutually depend upon each other One of the key benefits of creating components is being able to isolate change If I change Component A I might have to change Component B too because I ve broken backwards compatibility That doesn t cause any architectural problems Now if I change Component B and then have to change Component A too then that is a very important problem You have to install components one at a time Which one do you install first This problem can also appear in more subtle ways when you have three or more components that rely on each other for example when Component A relies on Component B Component B relies on Component C and then Component C relies on Component A This is an easy one to work out Draw out the list of components as a graph connecting up which components rely on which If you end up with a tree you re fine If your graph has cycles you ve got a problem that needs to be fixed You can t reliably install components with mutual dependencies Is there any shared code I can split out into its own component One way to solve the interdependence problem between Components A and B is to move some of the functionality out into a Component C and then have both Components A and B rely on that instead of each other This is also one way of achieving DRY Don t Repeat Yourself An example of this can be seen in the ComponentManagerShared component Both ComponentManagerPhpLibrary and ComponentManagerPhpDocbook rely on it but they don t need to rely on each other at all How is someone going to install and upgrade this component What I m asking here is will the component be listed in the dependencies section of a component s package xml or an app s or will a user install the component for himself by running the pear command Or maybe both Sometimes you ll want to introduce a meta component into your design to make it very easy to install and upgrade a larger collection of components ComponentManager is a meta package all it does is pull in all the other components that support creating and managing specific types of components Every time I find and fix a bug or add a new feature the bug fix or feature goes into one of the specific components such as ComponentManagerPhpLibrary but you don t need to keep track of them all All you have to do is pear upgrade phix ComponentManager and it takes care of upgrading all of the other components for you Where will your component be installed Components can be installed into two places on a computer system wide e g usr share php or inside an app e g vendor folder inside the app s code tree Does the component work in both places This is a question I personally wish the Doctrine developers had asked themselves At the time of writing Doctrine assumes that it will only be installed system wide making it a real pain in the backside if I want to run two or more separate apps that use Doctrine on the same server By forcing me to install Doctrine system wide they also force me to test and potentially fix all apps that use it in one go whenever I need to upgrade Doctrine The components built using ComponentManager can easily support installing into both system wide or inside an app to suit your choices and I ll show you exactly how that is done when we get there Can I get this functionality from an existing component from someone else Or put another way am I re inventing the wheel here Or living my not invented here dreams Today PHP components are at an embryonic state compared to our cousin languages There aren t all that many out there and support for the PSR0 autoloading standard is still to become widespread That said you should still take a look first before deciding to build your own component Folks like the Symfony 2 community seriously get components and are doing a great job in publishing high quality code that might just suit your needs Am I ever going to re use this code I ve saved the most important question for last Is it worth the trouble There isn t much practically in creating a component for the sake of it If you can t see yourself or anyone else ever re using the code put the code inside another component or your app for now You can always break it out into a component at a later date This is exactly what I did with phix It started off as a single PEAR compatible package and as it evolved I extracted out more and more code into separate PEAR compatible packages when I felt it was worth doing so These are all questions about how to organise the code and it s this organisation this list of components and their dependency graph that then affects the design of the code inside each component It s good to start out with a plan but don t get hung up on it As you build the code and learn to feel what it s like to live with the list of components you ll probably want to make changes to make life easier There s nothing at all wrong with that So what could the component list for my example app look like Component Design For The Sentiment App If I apply these questions to the app I m building in these blog posts I end

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

  • Stuart on PHP -
    Now that my repustateApi client component both has working API calls and 100 code coverage from its unit tests I want to make a PEAR package ready for release At this stage I m only going to release it for internal testing and so that the other components in my app can use it there are plenty of other things to be done before it is really fit to release to the wider world What Is A PEAR Compatible Package The PEAR installer is the de facto standard tool for installing reusable components into a PHP environment Chances are that it was installed onto your computer when PHP was installed if not it s normally available as a package for your operating system of choice One day it will be replaced by Pyrus the next generation PEAR installer Pyrus supports the same packages that the PEAR installer does Both installers know how to download PEAR compatible packages from websites known as channels how to install them and importantly how to upgrade them when new releases become available This makes PEAR compatible packages a good choice when picking the format to ship your component The package itself is a tarball containing package xml a manifest file that tells the PEAR installer all about the package and its contents and your PHP code plus any additional files that you want the PEAR installer to install A lot of the work that has gone into the skeleton files for the component is make it easy to create a PEAR compatible package How To Make A PEAR Compatible Package To make a PEAR compatible package go into the top level folder of your component where the build xml file is and run this command stuart Devel sental repustateApi phing pear package This will build a PEAR compatible package from your source code and put it in the dist folder for you How To Test The Package If you want to test that the package itself is compatible with the PEAR installer go into the top level folder of your component and run this command stuart Devel sental repustateApi phing install vendor This will install your PEAR compatible package into the vendor folder for you alongside your component s dependencies How To Install The Package Onto Your Computer If you want to install your PEAR compatible package into usr share php on your computer go into the top level folder of your component and run this command stuart Devel sental repustateApi sudo phing install system The sudo command will prompt you for your password and will then run phing as the root user so that it has permissions to write into usr share php Of course the very best way to install your PEAR compatible package is by publishing it to your own PEAR channel and that s something I ll explain in the next blog post Be the first to leave a comment PHP Components Unit Test Coverage For Components 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 Working unit tests is only half the battle If your unit test doesn t cover 100 of the code chances are you re shipping bugs 100 code coverage doesn t guarantee bug free code by any means but it s an important step in the right direction There isn t much point in shipping code that other developers cannot trust they will just go elsewhere to get their components How Much Of My Code Is Covered By My Tests The skeleton component created by the phix php library init command makes it very easy for you to see how much of your code is covered by your unit tests To do this you need to make sure that you have Derick s excellent xdebug extension installed After that just run your unit tests from the command line and our skeleton will take care of generating the code coverage data stuart Devel sental repustateApi phing test This command will generate a HTML based report in the review code coverage folder This report shows you exactly which lines 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 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 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 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

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

  • Stuart on PHP -
    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 is array testData throw new Exception Constraint failed if testData null constraint testData else return constraint function breakMe inputData I am bad data we can still call the constraint as before MyFramework Array mustBeArray inputData but we can now also do the following constraint MyFramework Array mustBeArray constraint inputData code This approach gives us the flexibility of both worlds a constraint method that we can call directly and also a constraint function that we can assign to a variable to re use as appropriate There s still a couple of weaknesses with this approach the most obvious one to me that finding these constraint methods is no longer quite as easy you need to know which class they are defined on but the counter argument is that this is why frameworks have to rely on convention We re quite heavily constrained by PHP s syntax and parser limitations here specifically the lack of macros which could avoid runtime costs in production environments and that we can t assign lambda functions to class properties at declaration time I m wondering how this style of declaring constraints could be refined further You can take it as given that we would normally throw something other than Exception Comments welcome Be the first to leave a comment Getting Gearman Up And Running On Ubuntu Karmic Posted by Stuart Herbert on February 26th 2010 in 2 Intermediate Toolbox Gearman is a lightweight high performance solution for farming out processing work from one machine to another I m currently looking at using Gearman as a key part of the architecture of a new web API that I m doing the R D for I ll go into why I need something like this and why I ve chosen Gearman in particular another day Getting Gearman up and running on Ubuntu 9 10 Karmic Koala is very straight forward and only takes a few minutes but oddly not clearly documented on Gearman s own wiki at the time of writing Add ppa gearman developers ppa as a software source sudo apt get install gearman job server sudo apt get install libgearman dev sudo apt get install uuid dev pecl install channel pecl php net gearman 0 6 0 Add a gearman ini to etc php5 conf d with extension gearman so as the contents sudo etc init d apache2 restart Check phpinfo to make sure gearman extension loaded You ll find that the gearmand process is already up and running and listening on port 4730 on localhost All you need to do now is to write some code to take advantage of it Be the first to leave a comment A Small But Interesting Bit Of News From Zend Posted by Stuart Herbert on February 18th 2010 in Toolbox A recent El Reg article about trends in the PHP community caught my eye yesterday morning The headline is about Zend s depressing statistic that the majority of PHP developers do their development on Windows these days which I m assured by Marco is old news and that s worth talking about at some point but it isn t what interested me the most As reported by El Reg Zend s survey results show that seventy per cent use Zend s Studio or Eclipse PHP Developer Tools while 18 per cent use Vim This isn t a case of Zend making wild claims though just less than full reporting by El Reg this time around Zend s own press release make it crystal clear that these are the results of a survey conducted across the Zend Framework developer community most likely but not directly attributed the 2009 survey That they haven t released the breakdown for Zend Studio vs Eclipse PDT is perhaps telling but still the real headline should be In its own community Zend is being very successful at convincing its community members to use multiple Zend products Zend s full stack strategy is starting to yield results and it looks like Zend Framework might have been the missing component that held back their earlier attempts The whole stack has been refreshed true Zend Studio now runs on Eclipse Zend Core has folded into Zend Platform which itself has the new and far better architected Zend Server positioned below it but with Zend Framework Zend are imho now able to appeal to the sort of developer communities who are willing to pay Zend s prices And Zend Framework is finally a product that third parties can make money from making Zend a little more relevant in the daily lives of your average PHP developer I m a great believer that a key component of all really successful products 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 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

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

  • Stuart on PHP -
    course in Manchester in October immediately before the PHPNW09 conference on how to setup and organise your PHP developers to ensure things run smoothly for you and your customers which will include looking at how to get the most out of Trac Learn more about the course or sign up now When it s just you working on one project at a time it s easy enough to keep track of the work you re doing and the work you still need to do to complete the job Chances are you can keep it all in your head or at least keep the discussions with your customer on something like Basecamp in your head You know that you should be using source control and bug tracking because it is best practice but it just seems like too much of an overhead to bother with when it s just you After all you re working on the customer s server and there s no one else editing the code anyway Some of the folks reading this blog post might be cringing at that but I ve lost count of the number of times I ve come across professional PHP developers who work in exactly this way Is it because they don t know better Maybe Is it because it has worked okay for them up to now For sure But eventually there comes a point where one developer becomes a team of two or more Having a team means that you can go after larger projects but it also means that you have to go after larger projects to pay the team Larger projects mean more complicated requirements multiple phased deliveries and a larger more demanding and probably a more complicated customer holding the pay cheque Running a team of PHP developers like all management activity in all walks of life comes down to three key things direction organisation and supervision Only now it isn t just you and a customer just a list that you can keep in your head Now you need to keep track of a larger list of multiple lists for multiple people to work on that need to be brought together in the end and if anything slips through the cracks it s your reputation on the line Getting the customer to come back for repeat business just got a lot less easy to take for granted Trac and Subversion have been part of our community s toolkit for many years now Used correctly you can get yourself and your customers well organised and grow your reputation when you grow your team If you haven t started using them yet both are open source and well backed with plenty of information freely available around the blogosphere on how to use them Or join me in Manchester in early October where I ll show you how they fit into an overall approach to running your team of PHP developers Be the first to leave a comment What Do You Develop On Posted by Stuart Herbert on September 11th 2009 in Toolbox At work we have quite a variety of kit that we use for development Cheap and cheerful desktop machines w multiple monitors and plenty of RAM normally with AMD CPUs These machines mostly run some form of Linux Ubuntu and Debian are both popular Various laptops a fair mix of MacBook Pros and other kit running Linux Virtual machines running on the desktops and laptops used for cross browser testing Virtual machines running on HP servers and blades used for system testing release testing and production It gives us a lot of flexibility allows us to develop and test on standards compliant environments but still use Windows for testing IE and most of the time the developer is the bottleneck not the equipment Recently I ve added both a netbook and an Atom based mini itx machine into the mix and this blog post is my attempt to recommend that you consider doing the same Netbooks are incredibly popular in the wider computer owning population Over here in the UK they come free with many mobile broadband packages making them cheaper than many low end laptops They re sold in the supermarket and the high street Their small form factor and relative lightweight makes them appealing to people who would never willingly cart a traditional laptop around And they run Windows which most people are familiar with After an initial explosion of innovation the specs have settled around a 1 6GHz Atom processor 1 GB of RAM and a 10 1024 600 resolution screen That s not a lot of power and it isn t a lot of screen estate How do your websites look on a netbook Does your home page or your landing pages make an impact at that size or is your site s message partially or completely below the fold How do the rest of the pages look If you re creating an app does the user have enough of a working area to comfortably do their tasks Try using Google Reader or Zimbra on a netbook to see examples of what to avoid And how do your websites run on a netbook Too much Javascript and the pages won t be snappy The CPU won t keep up and the different latencies and throughput of mobile broadband make round trips back to the server much more noticeable Javascript that fires at regular intervals e g rotating marketing spotlight images can force the CPU to switch execution speeds and so drain the netbook s battery much quicker Testing on a netbook is one way you can spot and deal with these problems before your customers do Stuart is running a course in Manchester in October immediately before the PHPNW09 conference on how to setup and organise your PHP developers to ensure things run smoothly for you and your customers Learn more about the course or sign up now Be the first to

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

  • Stuart on PHP - » Arguments From The Boardroom, Not The Bedroom
    money earned by the support contract If you re in this situation your support contract is supposed to be offsetting these costs anyhow You ve been charging in advance for this moment one could argue you now have a moral obligation to pony up the goods Find new services products or components that you can sell to the customer after they have upgraded Maybe there s a particular pet feature they ve wanted but you ve put it off because it was too much trouble to implement in PHP 4 Find out if they ve got the budget and sell them the new stuff to offset the costs of the upgrade Give them the upgrade for free deliberately Use it as a tool to win more work from the customer Find new markets to sell the upgrade into Maybe you ll decide it s not worth continuing to sell the product into your old markets because they can t afford to buy your upgrade or they re costing you too much to service This could be your opportunity to improve your earnings per customer and save face all round at the same time What Are The Alternatives To PHP 5 You can t stay with PHP 4 That doesn t mean that you have to go with PHP 5 You can choose to jump ship entirely and switch to a different technology There s a much wider choice than there was back in 2000 when PHP 4 was released and each choice brings its own opportunities and risks Ruby on Rails is the up and coming technology that everyone s looking at Despite what Terry says about it there is good money to be made by adopting Rails as a solution You can create solutions in Ruby that are a pain in the arse to create in PHP or which aren t possible at all You can sell Rails solutions to customers who won t touch PHP with a bargepole because Rails is seen as enterprisey and a valid competitor to Java and NET Developers of all skill levels can be productive with Rails in a matter of hours and most of them will prefer it over PHP You can create Rails applications that run on Java via JRuby and NET via IronRuby these in particular are emerging markets where competition is still thin on the ground Ruby s performance isn t what it could be atm and the language authors are working hard to address that Many of the third party plugins for Rails are of limited quality and capability Use what you can but be prepared to adapt or create for yourself what you must Keep on top of licensing issues especially when selling solutions to government agencies or other organisations who need to be able to protect themselves from IP violation lawsuits Watch out for performance bottlenecks in badly crafted code Ruby can lend itself to Perl like impenetrableness but can also lend itself to beautiful code too Be prepared for reluctance if your developers are expected to return to working with PHP at some point Java s still there as a solution and although lots of folks hate it the J2EE stack just won t go away and die In fact companies like Red Hat and organisations like Apache are putting more weight than ever behind Java Java is accepted in plenty of places that PHP isn t and in particular is backed by a whole host of developer tools that PHP developers can only drool over Sun is fighting hard to keep Java alive and relevant especially in the face of the threat from Ruby and has recently opensourced Java in an attempt to breathe new life into the language and the platform Java is a language for pendants first and foremost Not the ones who keep you out of trouble because they know where the problems lie but the ones who secretly wish they were able to control every tiny aspect of what you do Everything done in Java seems to take twice as long as in any other language if your developers don t give up in frustration first at the hoops that they have to jump through to try and get anything done Java should have taken over the world but it somehow missed the boat and in the medium term it may well decline in importance NET from Microsoft completes the list of major alternatives to PHP Lots of companies choose Windows as their platform of choice a platform that PHP sadly sucks on when compared to Linux Like Java NET has particularly strong development tools and is accepted by organisations that won t adopt PHP It s just as at home creating web based applications as it is desktop applications The saying goes that no one ever got fired for buying a Microsoft solution by embracing the Microsoft ecosystem you gain access to a large cross section of pointy haired bosses who live by sayings like that one Online documentation can be disappointing with NET especially for folks used to the excellent PHP manual Although NET does include ASP NET many NET solutions also end up using the C language which can be difficult for folks to switch to from PHP The cost of developer tools is an issue as is the cost of support from Microsoft going down the Certified Partner route is a popular solution but that involves retaining staff who have passed specific Microsoft certification exams I have to say though that I ve found Microsoft s support absolutely first rate each and every time I ve had to call on it There are other alternatives too but they are nowhere near as mainstream or as acceptable to potential customers Making The Move Hopefully I ve convinced you to do something about your current dependence on PHP 4 Preferably you ll shift your products and services to PHP 5 and PHP 6 which can t be far

    Original URL path: http://blog.stuartherbert.com/php/2007/07/30/arguments-from-the-boardroom-not-the-bedroom/ (2016-05-02)
    Open archived version from archive



  •