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 - » PHP Components: Dealing With PEAR Dependency Quirks
    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 is very simple simply depend on the beta version package name HTTP Request2 name channel pear php net channel min 2 0 0beta1 min max 2 999 9999 max package With this change made the PEAR installer does the right thing and installs HTTP Request2 just like I want it to It remains to be seen what will happen when HTTP Request 2 0 0 and beyond are released Will the PEAR installer download it or will I have to come back and edit the dependency in package xml I ll post news on that when the time comes With the right dependency information in package xml I can now get back to cranking out the code for the repustateApi component 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 No Comments Marcello says March 28th 2011 at 11 09 am Go on Personally I m really envolved in this post s serie Very interesting and very well written Thanks Marcello says March 28th 2011 at 11 09 am Go

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


  • Stuart on PHP - » PHP Components: Working With Non-Namespaced Components
    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 No Comments Richy C says October 26th 2011 at 10 38 am Hi Stuart I did ask this over Twitter but 140 characters aren t long enough to convey the question I had Basically I would like my multiple packages created by Phix to be namespaced under a common organisation name i e richyc package a richyc package b with files such as richyc package c monkey island php being namespace richycpackage cmonkey class island This is to avoid clashes for example my autoloader vs yours What would be the best name to put in project name in the build properties and the ideal layout of the code I have src php richyc package c monkey island php I ve got it compiling PEAR modules but it s just refining it at the moment Any advice welcome Stuart Herbert says October 26th 2011 at 12 23 pm Hi Rich I would recommend setting project name to be package a or package b as appropriate The layout you ve suggested looks like what I would do in the same circumstances Hope that helps Stu Richy C says October 26th 2011 at 10 38 am Hi Stuart I did ask this over Twitter but 140 characters aren t long enough to convey the question I had Basically I would like my multiple packages created by Phix to be namespaced under a common organisation name i e richyc package a richyc package b with files such as richyc package c monkey island php being namespace richycpackage cmonkey class island This is to avoid clashes for example my autoloader vs yours What would be the best name to put in project name in the build properties and the ideal layout of

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

  • Stuart on PHP - » PHP Components: Testing Remote Web Services The Quick And Nasty Way
    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

    Original URL path: http://blog.stuartherbert.com/php/2011/03/29/testing-remote-web-services-the-quick-and-nasty-way/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: Unit Test Coverage For Components
    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 No Comments Simon says March 30th 2011 at 11 52 am Thanks Stuart It ll be interesting to see what comments this will draw as there has recently been lot of internet bashing of those of us who aim for 100 and I think that s a shame As you point out the bugs will typically be in the untested portion plus it s a lot easier to keep coverage at 100 than it is at 79 84 simply because you do spot it when some new untested code creeps in I m glad you qualified this with the caveat that 100 is a step in the right direction rather than a silver bullet full of magic guarantees I think a lot of the bashers don t realise that us compulsive testers do appreciate that Simon says March 30th 2011 at 11 52 am Thanks Stuart It ll be interesting to see what comments this will draw as there has recently been lot of internet bashing of those of us who aim for 100 and I think that

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

  • Stuart on PHP - » PHP Components: Making A PEAR-Compatible Package
    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 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

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

  • Stuart on PHP - » PHP Components: Setting Up Your Own PEAR Channel
    pear channel discover pear pirum project org pear install pirum Pirum This installs a command line tool that you ll use to create your PEAR channel Next you need to configure Apache to serve your PEAR channel to the world By convention PEAR channels normally are http pear project whatever or http pear vendor whatever The PEAR installer works best if your PEAR channel files are in the DocumentRoot of your website Let s say that the DocumentRoot of your PEAR channel is going to be var www pear example com Once you ve configured Apache to serve pear example from from var www pear example com you need to create a pirum xml file to describe your PEAR channel This is a very simple file that tells Pirum the essential information it needs to create your PEAR channel s files mkdir var www pear example com cd var www pear example com vi pirum xml For pear example com the pirum xml file would look like this xml version 1 0 encoding UTF 8 server name pear example com name summary Example PEAR channel summary alias Example alias url http pear example com url server Now we need to tell pirum to build our PEAR channel files cd var www pear example com pirum build Congratulations you now have your own PEAR channel Remember to change pear example com to be the actual name of your own PEAR channel and you too can have your own PEAR channel up and running in about 10 minutes first time around Once you ve built a PEAR compatible package from your component it s one command in Pirum to publish that package on your PEAR channel Adding A Package To Your Own PEAR Channel Let s say I m going to publish my RepustateApi package on the pear example com channel I created above The full sequence of commands to create and publish the channel is stuart Devel repustateApi phing pear package stuart Devel repustateApi pirum add var www pear example com dist repustateAPI 0 1 0 tgz It s that straight forward Now in reality you re unlikely to be developing your PHP components on your public webserver You re more likely to be developing your PHP components on your local desktop or laptop or on a shared development server and then uploading the final results to your public webserver This is how we work at Gradwell right now and in the next blog post I ll go through our actual workflow for publishing a new or updated component showing you how we re setup to both support multiple contributors and disconnected development 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

    Original URL path: http://blog.stuartherbert.com/php/2011/03/30/setting-up-your-own-pear-channel/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: 3 Tips For Publishing Your Own PEAR Channel
    copy of your PEAR channel to your public webserver Btw if you do a lot development disconnected from the internet like I do having a local copy of your PEAR channel is pretty much a must Tip 2 Tag Your Releases Once you ve decided that your component is ready to share with everyone on your PEAR channel that s the time to tag your release in source control It s dead easy to do and it gives you and anyone else who takes over maintenance of your code a record of what was in each release Here s how to do it in git stuart Devel sental repustateApi git tag a m Release 0 1 0 0 1 0 stuart Devel sental repustateApi git push tags origin master If you re publishing on GitHub you can then go to your component on there and forever more see your code for that release Here s the repustateApi component at version 0 1 0 on GitHub as a real example of tagged code An even better example is Sebastian Bergmann s PHPUnit project where at the time of writing there are 193 tags to see As an aside we really should be digitally signing these tags but that is a topic in its own right for a later blog post Tip 3 Publish Your PEAR Channel Via Source Control It isn t just the code for your components that can be tracked via source control there is nothing stopping you from publishing your PEAR channel via source control too pear gradwell com is our public PEAR channel and we have a pear gradwell com repo up on GitHub for it This makes it extremely easy to publish new packages to our PEAR channel On my dev box I add a new release to source control like this stuart var www pear gradwell com git clone git github com Gradwell pear gradwell com git stuart var www pear gradwell com pirum add Devel repustateApi dist repustateApi 0 1 0 tgz stuart var www pear gradwell com git add i stuart var www pear gradwell com git commit m Added repustateApi 0 1 0 stuart var www pear gradwell com git push origin master and then I SSH into our public webserver and simply do stuart var www pear gradwell com git pull Job done This is actually a very handy setup when you have more than one developer publishing packages Each of your developers merges their new releases into source control so that no one trips over each other very important in a distributed team and everyone can clearly see who has published what 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

    Original URL path: http://blog.stuartherbert.com/php/2011/03/31/3-tips-for-publishing-your-own-pear-channel/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » PHP Components: Publishing Your PEAR Channel On Github
    before your pages will appear on http yourusername github com pear repository the first time you push your changes Following pushes should update the pages almost instantly Now on to see if it works as it should if pear channel discover http yourusername github com pear repository does not return any errors everything went fine You might want to check http yourusername github com pear repository using a browser to see if it has been uploaded first you will get a 404 if it is not Creating A PEAR Package Using Phix If you are using Phix to help maintain your project you have an environment which already is configured for generating PEAR packages But first you have to configure Phix so that it will generate the proper package xml file First we edit the project channel value in build properties project channel yourusername github com pear repository Then we go on to the package xml file most of the everyday stuff like adding files etc will be handled by Phix but the descriptions version history and package requirements need to be edited manually See the PEAR package xml documentation for more information Don t forget to bump version info in build properties and change log information in package xml when you are creating a new package version When you have got the package xml and build properties configured properly use the command phing pear package to create a PEAR package which will be placed in dist packagename X Y Z tgz Adding The Package To Your PEAR Channel To add a PEAR package you just use pirum add my pear repository my pear package X Y Z tgz cd my pear repository git commit a m Added my pear package X Y Z git push Then visit yourusername github com pear repository with your browser to see a list of all the uploaded packages Conclusion In the beginning there was only pear php net the only resource for PEAR packages in the world Then other package channels arrived and publishing your own PEAR package channel became really easy with Pirum Now you don t even need your own web server to host it you can host it on GitHub along with the source code for your PEAR package Now if we only can get some kind of PEAR channel aggregator or similar thing to avoid having to use channel discover for every new tool we want to install Footnotes The channel name must match the regular expression a zA Z0 9 a zA Z0 9 a zA Z0 9 You might want to turn off email notifications for successful page builds because the emails can easily pile up if you make many pushes 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

    Original URL path: http://blog.stuartherbert.com/php/2011/09/22/php-components-publishing-your-pear-channel-on-github/ (2016-05-02)
    Open archived version from archive



  •