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 - » Toolbox
    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 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 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 Be the first to leave a comment Beyond Frameworks The Page Posted by Stuart Herbert on March 26th 2011 in Toolbox I ve put together a page on my blog to collate my Beyond Frameworks series of articles about building PHP components into one convenient place If you re enjoying the series you might find it a handy reference page to bookmark And if you missed the beginning of the series why not head on over and see what I m up to PS Thank you to everyone who has left comments or pinged me on Twitter so far The feedback is excellent to have more please Be the first to leave a comment PHP Components How To Run Your Component s Unit Tests Posted by Stuart Herbert on March 25th 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 Earlier today I created some very basic unit tests for my repustateApi component Unit tests are an essential part of developing your component but how do you run them Running Your Component s Code From The Command Line Many old skool developers choose to work largely from the command line You can happily run PHPUnit by hand from the command line yourself each time but if you re taking advantage of the extra data that PHPUnit can report back on that soon gets to be a lot of typing This is where the build xml file in our skeleton comes in handy To run your unit tests from the command line all you need to do is run the command phing test stuart Devel sental repustateApi phing test Buildfile home stuart Devel sental repustateApi build xml property Loading home stuart Devel sental repustateApi build properties lint phplint home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php No syntax errors detected run unittests delete Deleting directory home stuart Devel sental repustateApi review code coverage mkdir Created dir home stuart Devel sental repustateApi review code c overage exec Executing command phpunit bootstrap home stuart Devel sental repustateApi src tests unit tests bootstrap php coverage html home stuart Devel sental repustateApi review code coverage coverage clover home stuart Devel sental repustateApi review logs phpunit xml home stuart Devel sental repustateApi src tests unit tests 2 1 exec PHPUnit 3 5 3 by Sebastian Bergmann exec exec EE exec exec Time 0 seconds Memory 4 00Mb exec exec There were 2 errors exec exec 1 GradwellRepustateApiClientTest testCanRetrieveSentimentScor eForTextByJson exec Exception oh dear exec exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 209 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 151 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 90 exec home stuart Devel sental repustateApi src tests unit tests php G radwell RepustateApi ClientTest php 70 exec exec 2 GradwellRepustateApiClientTest testCanRetrieveSentimentScor eForUrlByJson exec Exception oh dear exec exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 209 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 151 exec home stuart Devel sental repustateApi src php Gradwell Repustate Api Client php 116 exec home stuart Devel sental repustateApi src tests unit tests php G radwell RepustateApi ClientTest php 83 exec exec FAILURES exec Tests 3 Assertions 1 Errors 2 exec exec Writing code coverage data to XML file this may take a moment exec exec Generating code coverage report this may take a moment Execution of target run unittests failed for the following reason home st uart Devel sental repustateApi build xml 108 40 Task exited with code 2 BUILD FAILED home stuart Devel sental repustateApi build xml 108 40 Task exited with cod e 2 Total time 0 5951 seconds That went bang in a spectacular way At this stage where we have tests but don t yet have a working Repustate API client that s exactly what should happen As I work through the code and satisfy the tests we should quickly get to the point where we have more tests and that they all pass Here s an example of another component our CommandLineLib which has many tests that all succeed just so that you can see what a successful test run should look like Buildfile home stuart Devel GWC CommandLineLib build xml property Loading home stuart Devel GWC CommandLineLib build properties lint phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib CommandLineParser php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib ParsedSwitches php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib DefinedArg php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib DefinedSwitch php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib DefinedSwitches php No syntax errors detected phplint home stuart Devel GWC CommandLineLib src php Phix Project Comman dLineLib ParsedSwitch php No syntax errors detected run unittests delete Deleting directory home stuart Devel GWC CommandLineLib review c ode coverage mkdir Created dir home stuart Devel GWC CommandLineLib review code co verage exec Executing command phpunit bootstrap home stuart Devel GWC Com mandLineLib src tests unit tests bootstrap php coverage html home stuart D evel GWC CommandLineLib review code coverage coverage clover home stuart D evel GWC CommandLineLib review logs phpunit xml home stuart Devel GWC Comman dLineLib src tests unit tests 2 1 exec PHPUnit 3 5 3 by Sebastian Bergmann exec exec 60 78 exec exec exec Time 1 second Memory 5 75Mb exec exec OK 78 tests 407 assertions exec exec Writing code coverage data to XML file this may take a moment exec exec Generating code coverage report this may take a moment echo echo The code coverage report is in home stuart Devel GWC CommandLine Lib review code coverage test BUILD FINISHED Total time 3 7912 seconds Command Line Test Run Explained The component s build xml file contains targets sequences of instructions that you can invoke by using phing When you run the command phing test here s what happens phing loads the build xml file in the current working directory So make sure you re in your component s top level folder when you run phing build xml sucks in the build properties file where we set the component s name and version number These properties are in a separate file so that it s safe to replace build xml with new versions as we improve the component s skeleton files in the future via the phix php library upgrade command phing runs the test target in build xml which tells it to actually run the lint and run unittests targets The lint target does a syntax check on all of your PHP files As your component grows and the time it takes to run your unit tests grows too a quick syntax check can save a developer wasting a surprising amount of time If the syntax check is successful the run unittests target runs next The run unittests target invokes PHPUnit telling it to use the skeleton s bootstrap file and to write out the results in XML format to feed into other tools later on It also tells PHPUnit to write out code coverage data as HTML We ll look at that in a later blog post Running Your Unit Tests From Netbeans If the command line isn t for you don t worry the component skeleton is also designed to make it very easy to run your unit tests from inside Netbeans I m assuming that it will be just as easy to do this from other IDEs that support PHPUnit but I haven t tested any myself First of all you need to setup your project in Netbeans to tell it where your tests are Open the project s properties dialog box and then set the Test Folder to be your unit tests folder Next open the PHPUnit settings in the project s properties dialog box and tick the Use Bootstrap box and then tell Netbeans to use the bootstrap file inside the unit tests folder so that the PHPUnit settings look like this Now we re all set to run the tests from inside Netbeans In the project browser simply right click on the Client php file and select Test from the popup menu Netbeans will run the tests for you and tell you exactly where they broke I hope you find these tools useful and time saving I m going to beaver away over the weekend getting several components completed and will be back on Monday to go through more of the things you need to know if you re going to successfully go Beyond Frameworks and shift to a component based architecture Have a great weekend Be the first to leave a comment PHP Components Where To Put Your Component s Unit Tests Posted by Stuart Herbert on March 25th 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 ve started work on creating the components for my simple app The first component is repustateApi which will be a PHP client for Repustate com s semantic analysis API With the component s metadata all done and the decision made to start with unit tests let s get the unit tests written and running The First Unit Tests Repustate s API is extremely simple to use making it the ideal choice for my first semantic analysis client It s very low risk to knock up a client and see if their API does the job if the API isn t suitable under heavy testing and I m forced to try someone else s semantic analysis API I haven t lost much time in the attempt As a result my initial unit tests can be extremely simple code lang php namespace GradwellRepustateApi class ClientTest extends PHPUnit Framework TestCase public function setUp this apiKey public function testCanCreateClient create the client with a valid key client new Client this apiKey did it work this assertTrue client instanceof Client public function testCanRetrieveSentimentScoreForTextByJson setup client new Client this apiKey text this is a happy piece of text do the test score client callScoreForText text json evaluate result here this assertTrue score false public function testCanRetrieveSentimentScoreForUrlByJson setup client new Client this apiKey url http www stuartherbert com do the test score client

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


  • Stuart on PHP - » Toolbox
    Wrong With The Existing MSSQL Extension For PHP or why do we need an improved SQL Server extension for PHP The existing MSSQL extension works well but has a few practical limitations that have to be worked around Limited to varchar 255 support SQL Server 2000 and later support varchar columns longer than 255 bytes in size but unfortunately the old TDS based MSSQL extension can only support up to varchar 255 No support for unicode columns like nvarchar The size of a varchar column is specified in bytes not characters If you re working with UTF8 or UTF16 encoded data one non ASCII character takes up multiple bytes of space This cuts down on the amount of characters you can store in a varchar field and it makes things like HTML form validation er interesting nvarchar by contrast is advertised as a variable size datatype for storing multi byte characters nvarchar 255 holds 255 characters not 255 bytes No PDO drivers Although there s some debate about the performance merits of PDO PDO s prepared statement support is a real boon when it comes to preventing SQL injection attacks Poor error reporting The MSSQL extension doesn t provide an equivalent to mysql error et al which is a bit of a pain At the moment I ve no idea whether Microsoft s extension addresses any of these issues There s no documentation online just a exe file that isn t going to run under OS X I ll have a look at it when I get to my Windows PC at work and see what it can and can t do 15 comments Tucked Away In RedHat Enterprise Server 5 s targeted SELinux Policy Posted by Stuart Herbert on April 25th 2007 in Toolbox is this little labeling rule in the file contexts usr lib 64 httpd modules libphp5 so system u object r textrel shlib t s0 Does this mean that RedHat is shipping a mod php5 that isn t compiled for relocatable code support See my earlier post on compiling PHP as relocatable code If they are according to this page by Ulrich Drepper hey doesn t he work for RedHat then RedHat Enterprise Server 5 s copy of mod php5 might be using more RAM per Apache process than necessary which will impact scalability and capacity Be the first to leave a comment Getting PHP 4 running on RedHat Enterprise Linux 5 Posted by Stuart Herbert on April 4th 2007 in Toolbox I ve been playing around with RedHat s newly released Enterprise Linux 5 This comes with PHP 5 1 6 which I ve taken off my test box and replaced with a copy of PHP 4 built from source After installing PHP 4 the first time I tried to start up Apache it failed with this error Cannot load modules libphp4 so into server modules libphp4 so cannot restore segment prot after reloc Permission denied This is an error message from SELinux which is

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

  • Stuart on PHP - » Sharing My Reading List, Looking For Recommendations
    Connor says July 31st 2011 at 10 07 am Planet PEAR is a small aggregation of the goings on in PEAR land not huge traffic but occasionally providing a few useful posts One which I think is quite useful is http planetrdf com it s focused on structured data and has been going for some time If you have an interest in open data it s well worth a read especially posts about rdfa Perhaps a little niche but if you work with front end web things trying to sell products or share content it s worth getting to know the community Pete says July 31st 2011 at 11 56 am FunctionSource the new Ajaxian is always a good read I ll be adding some of these feeds thanks for the tip Stuart Herbert says July 31st 2011 at 8 27 pm Thanks FunctionSource looks like a useful blog to be reading Pete says July 31st 2011 at 11 56 am FunctionSource the new Ajaxian is always a good read I ll be adding some of these feeds thanks for the tip Stuart Herbert says July 31st 2011 at 8 27 pm Thanks FunctionSource looks like a useful blog to be reading Philip Norton says August 1st 2011 at 3 02 pm That s a great list and a neat idea I have subscribed to most of the PHP related blogs over the years so I have added the ones that I m not subscribed to I ve been writing mainly PHP stuff on code for a couple of years now and I ve tried a few times to get onto PlanetPHP with no success Maybe my writing isn t quite up to scratch I have managed to get the odd mention on phpdeveloper org which is pretty good Actually phpdeveloper org is a pretty good resource as Chris will write a short synopsis of the article so you can decide if you want to read more or not Philip Norton says August 1st 2011 at 3 02 pm That s a great list and a neat idea I have subscribed to most of the PHP related blogs over the years so I have added the ones that I m not subscribed to I ve been writing mainly PHP stuff on code for a couple of years now and I ve tried a few times to get onto PlanetPHP with no success Maybe my writing isn t quite up to scratch I have managed to get the odd mention on phpdeveloper org which is pretty good Actually phpdeveloper org is a pretty good resource as Chris will write a short synopsis of the article so you can decide if you want to read more or not Fernando says August 1st 2011 at 3 37 pm Also sometimes you get something interesting in twitter Fernando says August 1st 2011 at 3 37 pm Also sometimes you get something interesting in twitter LornaJane says August 3rd 2011 at 11 14 am I

    Original URL path: http://blog.stuartherbert.com/php/2011/07/31/sharing-my-reading-list-looking-for-recommendations/ (2016-05-02)
    Open archived version from archive

  • Stuart on PHP - » TechniqueNW 10
    in an idealistic world You are right when you suggest this is food for thought From my perspective though this sort of reaction would be consistent with flash s last days the flash dev business doesn t go so well the flash devs take a gov sponsored training weekend at training weekend flash is what people are familiar with they feel most comfortable in flash workshop the devs who arent using a struggling technology stride on without going to training weekend Perhaps that s not the way it is but you are right when you say it s food for thought Tim Dobson says January 31st 2010 at 8 49 pm Interesting commentary You re quite diplomatic there One way of looking at it probably quite a controversial one might be that NWV M are helping to prop up a dead dying technology On the other hand is it possible that your twitter friends are living in an idealistic world You are right when you suggest this is food for thought From my perspective though this sort of reaction would be consistent with flash s last days the flash dev business doesn t go so well the flash devs take a gov sponsored training weekend at training weekend flash is what people are familiar with they feel most comfortable in flash workshop the devs who arent using a struggling technology stride on without going to training weekend Perhaps that s not the way it is but you are right when you say it s food for thought Oliver says February 1st 2010 at 9 08 pm I m no fan of flash but I wouldn t call it a dead technology Have a look at flex you can do some amazing things with it Apple might not support flash but it ll come to the Pre and to Android and that might be more important in the long run I d say that as long as Microsoft doesn t support HTML5 the way e g Chrome or Safari does there s no way around flash for most users Oliver says February 1st 2010 at 9 08 pm I m no fan of flash but I wouldn t call it a dead technology Have a look at flex you can do some amazing things with it Apple might not support flash but it ll come to the Pre and to Android and that might be more important in the long run I d say that as long as Microsoft doesn t support HTML5 the way e g Chrome or Safari does there s no way around flash for most users Carwyn Balch says May 13th 2010 at 8 29 pm Flash is in no way dead the advertising and media markets heavily depend on banners presentation websites with the wow factor It would be difficult to expect the media to disappear over 5 to 10 years To have no backward support for the iPad will not affect its consumption by the

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

  • Stuart's Photography - » Morecambe At Sunrise
    200 IS that are out of focus Still needs more investigation but I m coming to the conclusion that this particular model or maybe just my particular camera simply can t focus on anything beyond the middle distance Even setting the camera to focus on infinity doesn t seem to help But I am very impressed with the colours captured by this camera All I ve had to do in post is sharpen and crop to taste No colour editing at all Closing Thoughts This is exactly one of the scenarios I have a pocket camera for to take advantage of an unexpected opportunity I m still learning how to get the best out of my new Canon IXUS 200 IS but focusing problems aside it s proving to be a great camera to take everywhere with me 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 6 Comments Stuart Herbert On PHP TechniqueNW 10 says January 31st 2010 at 7 55 pm I also took some photos of Morecambe before the Saturday workshops Stuart Herbert On PHP TechniqueNW 10 says January 31st 2010 at 7 55 pm I also took some photos of Morecambe before the Saturday workshops PHP help TechniqueNW 10 says March 11th 2010 at 6 20 pm I also took some photos of Morecambe before the Saturday workshops started Related Posts PHP 5 3 Adoption Some NumbersPlaying With PHP help TechniqueNW 10 says March 11th 2010 at 6 20 pm I also took some photos of Morecambe before the Saturday workshops started Related Posts PHP 5 3 Adoption Some NumbersPlaying With The Channel In The Mud OneDegree says July 2nd 2010 at 8 03 pm Channel In The Mud Image by Stuart Herbert You can learn more about these photos on my blog and also learn about the Technique NorthWest event that I was in Morecambe The Channel In The Mud OneDegree says July 2nd 2010 at 8 03 pm Channel In The Mud Image by Stuart Herbert You can learn more about these photos on my blog and also learn about the Technique NorthWest event that I was in Morecambe Add Your Comments To This Article Using The Form Below Your name required Your email address will not be published required Your website Your comment Your comments may not appear until they have been approved by a moderator Latest Photos Categories A4054 Merthyr Road A469 A470 Trunk Road A473 A48 Abercanaid Administrative Articles Opinion Post Production Barry Barry Docks Barry Railway Brecon and Merthyr Railway Bristol Channel Bute

    Original URL path: http://blog.stuartherbert.com/photography/2010/01/31/morecambe-at-sunrise/ (2016-05-02)
    Open archived version from archive



  •