php – Internet Strategy Guide https://phpprotip.com Together we can defeat the internet Tue, 07 Mar 2017 02:01:20 +0000 en-US hourly 1 https://wordpress.org/?v=4.7.31 55205001 Copyright © Internet Strategy Guide 2013 chance@chancegarcia.com (Internet Strategy Guide) chance@chancegarcia.com (Internet Strategy Guide) http://phpprotip.com/wp-content/plugins/podpress/images/powered_by_podpress.jpg Internet Strategy Guide https://phpprotip.com 144 144 Together we can defeat the internet Internet Strategy Guide Internet Strategy Guide chance@chancegarcia.com no no PHPStorm File Templates Includes Custom Variables https://phpprotip.com/2012/02/phpstorm-file-templates-includes-custom-variables/ https://phpprotip.com/2012/02/phpstorm-file-templates-includes-custom-variables/#comments Sat, 11 Feb 2012 01:39:46 +0000 http://phpprotip.com/?p=564 PHPStorm’s File template settings are very versatile. They allow you to not only make a file template, but also allow you to parse out redundant elements (such as licensing) in the template by allowing an includes section. In your File Template, any undefined variable automatically elicits a prompt from PHPStorm.

PHPStorm allows you access to the includes section via the #parse directive. If you’re want To have Custom variables to be filled in correctly via prompt, you will need to have the variable declared in the template.

Example

“chance license.php”

/**
* @package ${Package}
* @author Chance Garcia
* @copyright (C)Copyright ${YEAR} chancegarcia.com
*/

In the above includes example, I’m wanting to have a custom variable named Package. I can only cause PHPStorm to prompt for this value if I include the variable in my template. If I’m already using the variable in the template, then it will fill in when the includes file is parsed.

Example:

<?php
#parse("chance license.php")

class ${Package}_#if(${ExtraClassInfo} != "")${ExtraClassInfo}_#end${NAME}
{

}

In the above template, the ${Package} variable will be given a prompt since it is used in the template and an unknown variable and the parsed “chance license.php” include will be able to use that prompt value.

I am also using another variable to Prompt for extra class name information. Since PHPStorm uses Velocity Template Language (VTL), I am able to use the VTL conditional syntax to insert that information if it is entered and ignore it if it is not. This technique is useful in a situation where you want your include file to have a custom variable value but do not need to display this value in your template.

Example:

<?xml version="1.0"?>
<!--
#if(${Package})#end
#parse("chance license.php")
-->

 

In the above example, we make PHPStorm prompt for the custom value needed for out parsed include file. This gives us our expected include file without printing our custom variable anywhere else in our template.

 

Update: I made a github repo (https://github.com/chancegarcia/phpstorm-templates) of my templates for better examples and in case I lose my settings.

Enhanced by Zemanta
]]>
https://phpprotip.com/2012/02/phpstorm-file-templates-includes-custom-variables/feed/ 1 564
MAMP PRO, PECL, SSH2, and OSX CLI (AKA acronym madness) https://phpprotip.com/2011/11/mamp-pro-pecl-ssh2-and-osx-cli-aka-acronym-madness/ https://phpprotip.com/2011/11/mamp-pro-pecl-ssh2-and-osx-cli-aka-acronym-madness/#comments Tue, 08 Nov 2011 05:47:02 +0000 http://phpprotip.com/?p=548 Or madness in general. So as you may know, I’ve started using PHPStorm to work locally. I decided to dust off an old SSH2 wrapper I wrote and play with how PHPStorm uses PHPUnit and does refactoring. I knew that I would have to install the extension via PECL and was like, “Oh it can’t be that bad to do it through MAMP PRO” and as you may have guessed, I sealed my own fate for a couple hours. One thing I can say is that, even though I use a convenient app like MAMP PRO to set up my local development environment, I’m glad my sysadmin-fu is up to snuff enough to fly without the conveniences because after this ordeal, I feel like I might as well have made my MAMP stack from scratch with all the hoops I jumped tonight. (I’m pretty sure that last sentence is also one of the worst run-on sentences ever).

The first thing you need to know is that the PECL command is located at the directory

/Applications/MAMP/bin/php/php5.3.6/bin

when I tried to run

sudo ./pecl install -a ssh2 channel://pecl.php.net/ssh2-0.11.3

from that directory, I got the error:

Notice: unserialize(): Error at offset 267 of 1133 bytes in Config.php on line 1050
PHP Notice: unserialize(): Error at offset 267 of 1133 bytes in /Applications/MAMP/bin/php/php5.3.6/lib/php/PEAR/Config.php on line 1050
ERROR: The default config file is not a valid config file or is corrupted.

I found out later that the error is most likely caused by the file

/Applications/MAMP/bin/php/php5.3.6/conf/pear.conf

So if you get an error, try doing

sudo mv /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf.bkp

If you’re still getting the error, you can also the following:

  1. Install Xcode Tools from your Mac OS X DVD or download it from Apple Developer Connection
  2. Download the complete PHP source code from php.net into /Applications/MAMP/bin/php/php5.3.6/
  3. Create an include directory in the the php5.3.6 directory.
  4. Unzip/tar the php source archive and move it to/Applications/MAMP/bin/php/php5.3.6/include/
  5. Rename the php source directory to just php (so then it will look like /Applications/MAMP/bin/php/php5.3.6/include/php)
  6. In Terminal use the following commands to compile the extension:
    cd /Applications/MAMP/bin/php/php5.3.6/include/php
    ./configure

That should allow you to run the PECL command however, you will probably get a complaint about not having libssh installed. So you will have to

  1. go download libssh2 (http://www.libssh2.org/). As much as I like git, I recommend  downloading the latest release tarball instead of cloning the repo. For some reason, I got a version incompatibility error when trying to run the PECL install with the repo version and had to do all these steps over with the tarball release version.
  2. unzip the directory and cd to the upacked directory in the terminal.
  3. run: ./configure; make all install;
    libssh should compile and place the output file in src/*.o
  4. copy all headers from the include folder within the libssh2 directory to
    /usr/local/include/
  5. copy all compiled files (*.o) from the src folder within the libssh2
    directory to /usr/local/lib/

After you’ve successfully ran the the PECL install, it should tell you to  Add the line

extension=ssh2.so

to the Dynamic Extensions area of your php.ini file. I believe both MAMP and MAMP PRO allow you to edit the necessary ini through File>Edit Template.

MAMP edit php.ini

 

Lastly, restart apache. You should be able to see the SSH2 extension when you load a phpinfo() page.

Bonus round:

I’m not sure how I have  PHP CLI working in OSX but if you’ve followed the steps above and try to verify the extension install with through the cli, it won’t show up.

$ php -a
php> phpinfo();

This is because (if you’re also using MAMP PRO) the binaries are different. The good news is that you can make things happy in 3 easy steps

  1. run `sudo ln -s /Applications/MAMP/bin/php/php5.3.6/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so /usr/lib/php/extensions/no-debug-non-zts-20090626/ssh2.so` in the terminal.
  2.  Edit the /etc/php.ini (copy /etc/php.ini.default if /etc/php.ini doesn’t exist)  like you did for the MAMP php.ini(s)
  3. profit.

Note: I still have to install PHPUnit into my current setup so that may or may not elicit another blog post.

Sources:

  • http://smbjorklund.no/how-enable-pecl-uploadprogress-extention-mamp
  • http://php.net/manual/en/ref.ssh2.php
  • http://forum.mamp.info/viewtopic.php?t=13815
Enhanced by Zemanta
]]>
https://phpprotip.com/2011/11/mamp-pro-pecl-ssh2-and-osx-cli-aka-acronym-madness/feed/ 2 548
Magento Extension GitIgnore Stub https://phpprotip.com/2011/10/magento-extension-gitignore-stub/ https://phpprotip.com/2011/10/magento-extension-gitignore-stub/#comments Mon, 24 Oct 2011 15:15:57 +0000 http://phpprotip.com/?p=538 As you may or may not know, I’ve been working with Magento lately. In the past few months, one thing I’ve found that I needed is a stock .gitignore file for when making extensions. Haven’t found one so I made one on github and will also post here for anyone else in need site. I’m still relatively new at working with Magento and in someways git/github so please feel free to critique/streamline.


# replace {company} and {extension} placeholders with your information

# ignore phpstorm files
/.idea

# Ignore all not in app & skin
/*
!/app/
!/js/

# ignore all in js, except module files for this module
/js/*
!/js/{company}/

# Ignore all in app, except code & etc
# Ignore all in app/code except /local/{company}
/app/*
!/app/code/
!/app/etc/
!/app/design/

# Ignore all in app/code/local except {company}
/app/code/core
/app/code/community
/app/code/local/*
!app/code/local/{company}/
# use lines below if you have multiple company extensions
# and want to just commit a specific one
#/app/code/local/{company}/*
#!app/code/local/{company}/{extension}

# Ignore all of app/etc except our specific module files
/app/etc/*
!/app/etc/modules/
/app/etc/modules/*
!/app/etc/modules/{company}_{package}.xml

#Ignore all of app/design except for our files
/app/design/*
!app/design/frontend/
!app/design/adminhtml/
/app/design/frontend/*
!/app/design/frontend/base/
/app/design/frontend/base/default/etc/
/app/design/frontend/base/default/template/*
!/app/design/frontend/base/default/template/{extension}/
/app/design/frontend/base/default/layout/*
!/app/design/frontend/base/default/layout/{extension}/*
/app/design/adminhtml/*
!/app/design/adminhtml/default/
/app/design/adminhtml/default/find/
/app/design/adminhtml/default/default/etc/
/app/design/adminhtml/default/default/locale/
/app/design/adminhtml/default/default/template/*
!/app/design/adminhtml/default/default/template/{extension}/
/app/design/adminhtml/default/default/layout/*
!/app/design/adminhtml/default/default/layout/{extension}/*

Enhanced by Zemanta
]]>
https://phpprotip.com/2011/10/magento-extension-gitignore-stub/feed/ 2 538
Using MySQL Workbench with MAMP https://phpprotip.com/2011/10/using-mysql-workbench-with-mamp/ https://phpprotip.com/2011/10/using-mysql-workbench-with-mamp/#comments Fri, 07 Oct 2011 06:07:52 +0000 http://phpprotip.com/?p=527 Recently I’ve started working locally due to the PHPStorm IDE. In order to work locally, I invested in MAMP Pro to make use of their GUI interface for configuring vhosts. I also like to use MySQL Workbench for my database work, unfortunately these 2 items never seemed to work together for me before. After a brief google search I was able to find out how to connect to MAMP’s MySQL install to do SQL Development, which is by done by choosing the local socket connection method and using the value /Applications/MAMP/tmp/mysql/mysql.sock for the connection.

MySQL Workbench MAMP Socket Connection Settings
MySQL Workbench MAMP Connection Settings

After setting that up, I got to thinking, “I’m already using an IDE for code convenience and a GUI for vhost convenience, I should set up Server Administration with MySQL Workbench too!” So after some googling, I found an article to help me set up Server Administration with MAMP. Unfortunately the article only got things partially working and has no way to comment on it to have it corrected. So I’m going to outline the steps. Also I just noticed that the images with the article are updated correctly but it’s hard to cut and paste an image of something someone has done so I’ll just give you the value pairs

  • Configuration File: /Applications/MAMP/tmp/mysql/my.cnf
  • Start: /Applications/MAMP/bin/startMysql.sh –
  • Stop: /Applications/MAMP/bin/stopMysql.sh –
  • Check MySQL Status: ps -xa | grep “/Applications/MAMP/Library/bin/[m]ysqld”
If the check status doesn’t work, just do a
ps -xa | grep MAMP
and find the correct path to mysqld
And that’s all you need to know.
MySQL Workbench MAMP System Profile Settings Tab
Enhanced by Zemanta
]]>
https://phpprotip.com/2011/10/using-mysql-workbench-with-mamp/feed/ 3 527
expected exceptions annotations, mocked object calls, oh my. https://phpprotip.com/2010/12/expected-exceptions-annotations-mocked-object-calls-oh-my/ https://phpprotip.com/2010/12/expected-exceptions-annotations-mocked-object-calls-oh-my/#comments Fri, 24 Dec 2010 15:06:11 +0000 http://phpprotip.com/?p=490 Note: I have tested this in PHPUnit 3.4.1 and haven’t tried it out in 3.5.
Anyone who has worked with PHPUnit has most likely worked with expected exceptions and mock objects. The nice thing about working with expected exceptions is that we have access to a handy @expectedException annotation. I’ve gotten into the habit of using this for exceptions my fixtures should throw but also for when I’m using a mock object to verify a method call. So my tests usually expect foo_exception for fixture throws and when i’m testing method calls via a mock, they expect Exception. Therein lies my problem. Because all my custom class exceptions obviously extend the Exception class, I can get some false positives in testing.

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();
require_once('foo.php');
class tmpTest extends PHPUnit_Framework_Testcase
{

    /**
     * @expectedException Exception
     */
    public function testFooBar()
    {
        $foo=new foo();
        $foo->bar();
    }

    /**
     * @expectedException Exception
     */
    public function testBarBaz()
    {
        $mock=$this->getMock('foo',array('baz'));
        $mock->expects($this->any())
         ->method('baz')
         ->will($this->throwException(new Exception('baz')));
        $mock->barbaz();
    }
}
class foo_exception extends Exception{}

class foo
{
    public function bar()
    {
        throw new foo_exception('bar');
    }

    public function baz()
    {
        echo "bwahn";
    }

    public function barbaz()
    {
        $this->bar();
        $this->baz();
    }
}

So here we have an expectation for Exception but if we look at the code, we see that the bar method throws a foo_exception and the testBarBaz test is trying to test for the baz call via a mock that throws an Exception. if we change the annotation to expect foo_exception, the test still passes. This leads me to believe the best way to isolate the behavior we wish to test is to not use annotation for these sorts of tests. Or if you want to use annotation, be sure to use a unique exception for the mock. This means, unfortunately for me, that I’ll have to go back through all my tests and ensure there’s no false positives.

Lesson learned: be careful using shortcuts (and don’t stand in the fire).

On a side note, this part of PHPUnit is why those tests will behave that way. The behavior is completely my fault but I wanted to confirm it was behaving because of how it was verifying the expected exception.

Enhanced by Zemanta
]]>
https://phpprotip.com/2010/12/expected-exceptions-annotations-mocked-object-calls-oh-my/feed/ 5 490
fun with arrays and requirement chains https://phpprotip.com/2010/12/fun-with-arrays-and-requirement-chains/ https://phpprotip.com/2010/12/fun-with-arrays-and-requirement-chains/#comments Wed, 01 Dec 2010 21:21:09 +0000 http://phpprotip.com/?p=484 Recently, I had to figure out if a given set of features contained all of their necessary requirements.

For better or worse, the table was modeled so that the feature table referenced itself so that it could create a parent/child requirement chain. For example:

feature_id requirement_id
2 null
5 2
7 null
11 5

So my problem is to find out if a given set of requested features, make sure that the requirements are also present. This includes any requirements the requirement feature may have. In this example, 11 requires 5 which requires 2.
Let’s take $featureRequest1=array(2,5,7,11) and $featureRequest2=array(7,5,11). If I were to run a look up of requirements, I would find that we have

$requirements=array(2,5).

I tried to use the php in_array function but it didn’t work as I expected it to.

in_array($requirements,$featureRequest1); // i expect true
var_dump(in_array($requirements,$featureRequest1)); // false
in_array($requirements,$featureRequest2); // i expect false
var_dump(in_array($requirements,$featureRequest2)); // false

I then realized what I need is for there to be a clear intersection between the requirements and the request.

$requirements==array_intersect($requirements,$featureRequest1); // expect true
var_dump($requirements==array_intersect($requirements,$featureRequest1)); // true
$requirements==array_intersect($requirements,$featureRequest2); // expect false
var_dump($requirements==array_intersect($requirements,$featureRequest2)); // false

I should probably note that array_interest will preserve the array keys. To fix it, you can either flip the 2 arguments or pass the return array to array_values

]]>
https://phpprotip.com/2010/12/fun-with-arrays-and-requirement-chains/feed/ 2 484
Meet the PHP Dev Derby Team https://phpprotip.com/2010/09/meet-the-php-dev-derby-team/ https://phpprotip.com/2010/09/meet-the-php-dev-derby-team/#respond Fri, 10 Sep 2010 14:45:57 +0000 http://phpprotip.com/?p=469 I liked how the Dev Derby website did team leader profiles and decided to try to do something similar. No one provided any pictures but most did answer some questions I asked so without much further ado, meet the PHP Dev Derby Team.

The team consists of

  • Dennis Rogers (@_drogers)
  • Max Beatty (@maxbeatty)
  • Matthew Haralovich (aka zon)
  • Grant Simpson (@grantls)
  • Ryan Dagey (@dageytech)

Update: added in Ryan Dagey’s answers. And photo.

Meet Dennis Rogers (@_drogers)

What do you like about PHP?

It’s what I know, and free.

What book,movie or album do you think best embodies your personality?

Anchorman

What is your biggest pet peeve?

The expression “pet peeve”

What inspires you?

Power Ballads.

2 or 3 favorite quotes, sayings, etc. (e.g. “If you want to achieve greatness, stop asking for permission”)

“that’s a bold statement”

Meet Max Beatty (@maxbeatty)

What do you like about PHP?

I like PHP because it gets the job done. You can do what you need to do with it.

What book,movie or album do you think best embodies your personality?

I’ve recently drawn some eerily similarities between myself and Tony Hsieh in his book Delivering Happiness, but Mark Hoppus wouldn’t be a bad comparison – easy going, fun loving, knows his stuff at the end of the day.

What is your biggest pet peeve?

Making things harder and more complex than they need to be.

What inspires you?

Simplicity. Anything that has everything it needs and nothing more.

2 or 3 favorite quotes, sayings, etc. (e.g. “If you want to achieve greatness, stop asking for permission”)

“There is no such thing as information overload, just bad design. If something is cluttered and confusing, fix your design”. – Edward Tufte

“You can here because we do this better than you, and part of that is letting our creatives be unproductive until they are.” – Don Draper

Meet Ryan Dagey

What do you like about PHP?

Coming from a C[++] background, I found PHP easy to pick up.  Outside of VBScript, PHP was my first formal scripting language, so I appreciated how quickly I could develop a script to do what I needed, compared to compile&  debugging.
Another favorite PHP feature of mine is easy integration into web frameworks, even when using object-oriented.  Compared with C#,PHP makes accomplishing the simplest and complex tasks as natural as writing pseudo-code.

What book,movie or album do you think best embodies your personality?

“The Usual Suspects”

What is your biggest pet peeve?

People’s pet peeves, I take people as they are, very much a laid back go with the flow, laissez-faire attitude guy

What inspires you?

I’m inspired by those who achieve the impossible, learning about great feats of science and the unyielding quest for answers.

2 or 3 favorite quotes, sayings, etc. (e.g. “If you want to achieve greatness, stop asking for permission”)

Do or do not, there is no try -Yoda
Courage is not the absence of fear, but the mastery of fear -Samuel Clemens

Enhanced by Zemanta
]]>
https://phpprotip.com/2010/09/meet-the-php-dev-derby-team/feed/ 0 469
Call to Arms https://phpprotip.com/2010/08/call-to-arms/ https://phpprotip.com/2010/08/call-to-arms/#comments Fri, 20 Aug 2010 18:15:08 +0000 http://phpprotip.com/?p=458
A selection of programming language textbooks ...
Image via Wikipedia

How much code can you generate in a day?

We are actively recruiting participants to take place in a developer event (“Dev Derby“) that pits one language against others. It is a day-long programming challenge where teams of developers work to create an application serving a real-world need. Five teams will represent different programming languages—PHP, C#, Ruby, ColdFusion, and Java—to produce a demo application that will be released as open source software.

http://devderby.com/application/

Team Leaders for each language will review applications and select competitively balanced squads. There is no cost to enter, but spots on teams are limited. Winning teams can win prizes and all participants are eligible for discounts to other tech events taking place that week.

The Dev Derby will start and end on Saturday, September 11, 2010, in Bloomington, Indiana. It is part of The Combine (http://thecombine.org), the area’s first major technology conference, and at the start of the BFusion/BFlex conference (http://bflex.info). Dev Derby involves an intense six-hour coding session.

Each challenge submission will be judged by knowledge leaders and representatives of the non-profit organizations benefiting from this work. The criteria spans Design (features and UI choices made), Technical Efficiency (code and performance), Communication (documentation and presentation), and Practical Value (use, adoption, and maintenance).

Prizes will be awarded at the end of the day, following a panel discussion about the development process and the future of application programming.

Dev Derby is situated in The Combine along with other technology-related events, such as Tech Cocktail, Ignite Bloomington, and a variety of of other gatherings. It is hosted by the BFusion/BFlex conference, a two-day hands-on training event from the experts of Adobe Flex and ColdFusion. Dev Derby is inspired by our experience with Startup Weekend in 2008, but with a short day of coding and focused on a specific challenge.

Apply now: http://devderby.com/application/

Enhanced by Zemanta
]]>
https://phpprotip.com/2010/08/call-to-arms/feed/ 1 458
Valuable Professional Reading https://phpprotip.com/2010/08/valuable-professional-reading/ https://phpprotip.com/2010/08/valuable-professional-reading/#comments Wed, 11 Aug 2010 19:12:38 +0000 http://phpprotip.com/?p=451
book cover
Image via Wikipedia

The team leaders for Dev Derby have been asked to list what we consider valuable professional reading. Our book selections are not limited to our respective Languages. I thought I would share my list with everyone.

The first 2 (GoF design patterns and Patterns of enterprise application architecture) really just need to be in every developer’s library. The rest are a collections of books I’ve read and liked as well as recommendations from developers I like and respect. Keith Casey pointed me in the general direction of a lot of these books.I suspect that some of the Dev Derby people will end up contacting various publishers to solicit swag sometime soon.

In other news about Dev Derby, I think that an application for teams should be available to announce sometime soon geneerinen cialis. I do know we have a deadline for selection approaching and it’s kinda hard to select without people to select from.

GoF design patterns:
* ISBN-10: 0201633612
* ISBN-13: 978-020163361

Patterns of enterprise application architecture:
* ISBN-10: 0321127420
* ISBN-13: 978-0321127426

Code Reading:
* ISBN-10: 0201799405
* ISBN-13: 978-0201799408

Guide to PHP Design Patterns:
* ISBN-10: 0973589825
* ISBN-13: 978-0973589825

Building Scalable Web Sites:
* ISBN-10: 0596102356
* ISBN-13: 978-0596102357

Peopleware:
* ISBN-10: 0932633439
* ISBN-13: 978-0932633439

Mythical Man Month:
* ISBN-10: 0201835959
* ISBN-13: 978-0201835953

The Pragmatic Programmer:
* ISBN-10: 020161622X
* ISBN-13: 978-0201616224

Code Complete:
* ISBN-10: 0735619670
* ISBN-13: 978-0735619678

Zend PHP 5 Certification Study Guide:
* ISBN-10: 0973862149
* ISBN-13: 978-0973862140

Guide to PHP Security:
* ISBN-10: 0973862106
* ISBN-13: 978-0973862102

Guide to Enterprise PHP Development:
* ISBN-10: 0973862181
* ISBN-13: 978-0973862188

Guide to Programming with Zend Framework
* ISBN-10: 0973862157
* ISBN-13: 978-0973862157

Enhanced by Zemanta
]]>
https://phpprotip.com/2010/08/valuable-professional-reading/feed/ 1 451
Auth/ACL implementation strategies https://phpprotip.com/2010/08/authacl-implementation-strategies/ https://phpprotip.com/2010/08/authacl-implementation-strategies/#comments Mon, 09 Aug 2010 18:52:21 +0000 http://phpprotip.com/?p=384 I’m going to talk more about ACLs than Auth. Auth is simple, it’s the ACL that will trip you up.  Since both concepts are coupled together when you’re making a login system, I feel it’s appropriate to at least touch on Auth. What I want to cover is the ways we can create the ACL object to suit needs based on the scale of the project. I’m going to assume that readers have a passing familiarity with using the Auth and Acl objects and may have even implemented them into projects.

Zend_Auth

The reason I say Auth is simple is because Zend Framework makes it simple with their Zend_Auth class. You can pick an auth style, implement and then go from there. For the purpose of this discussion, I’ll be talking using Database authentication. So after one has set up a login page that uses Zend_Auth (there are already a lot of articles that cover this so i’ll move on), the major bear you have to tackle is using the Zend_Auth_Result to determine proper access. Sounds simple, that’s what Zend_Acl is for.

Zend_Acl

So how do we create our Acl? Again, ZF’s reference guide gives us some handy-dandy examples of using their object but how you utilize the object depends on your scale. Other articles give you a way to bind the two together, usually via a controller plugin of some sort. The thing that can be tricky is how you want the Acl and Auth to interact with each other within that plugin. I utilize a controller plugin that fires off an Auth/Acl check in the dispatchLoopStartup() method. If no Zend_Auth_Result object exists, it assigns a guest role and if one does exist, it searches the Zend_Auth_Storage for a role value (assigning guest if one doesn’t exist somehow) and checks that value against the Acl that was created in my Bootstrap. My biggest conundrum has always been translating Requests into Resources. I’ll talk more on that later viagra from india.

Scaling

I tend to put my scaling into one of the following categories: small,decent or ZOMG. Small is something like a personal site or a proof-of-concept/self-tutorial project where my users will probably be a 1-5 roles and 1-5 resources at best. Decent is most collaborative niche projects with 50-100 resources. ZOMG is where the number of resources I’m dealing with is >100, unknown or potentially large. I define my ACLs in my Bootstrap in one of three ways:

  1. Hardcoded
  2. As part of my Navigation Object properties
  3. Pulled from a database

Hardcoded

This one is easy to implement since if you follow the ZF reference or the numerous guides/posts you find when you google for auth/acl systems, you’ll be able to hardcode your ACL. I find this ideal for small projects where the number of resources is relatively low and the growth of adding additional resources is non-existent. This is the simplest way to do things.

Navigation-based

This method makes use of the Zend_Navigation object. Brandon Savage wrote up a nice guide to integrating ACLs into you r Navigation. I usually instantiate my Navigation objects in the Bootstrap from a XML file. The only tricky thing I found with this is finding the appropriate Navigation_Page (that tells us our resource/permissions) from the Request object. I tend to utilize this method when the growth of resources occurs at a slow pace.

Database-driven

This particular method is what spurred me to write about Auth and Acl. I see this solution as ideal for a high amount of resources or where the growth of resources to have fast spurts.  This solution can allow for ease of maintenance and is scalable. Even though it is a scalable solution, I kind of see it as overkill for smaller, low-growth projects.

Multiple project ACLs

Since I’ve began working with Zend Framework, I have used it to create both internal apps in addition to running my company’s main site. To date, I have a total of eleven internal applications, some of which require Auth/Acl and some of which do not. Those that do not require them will soon be requiring them due to future features we wish to implement for them. At first I was working on a drag and drop solution for setting up an Auth/ACL system for any given project. I was going to work it a stand-alone module where all the developer has to do is call the Module Bootstrap within the Application Bootstrap. The drag and drop solution was going to rely on the project’s Navigation object for determining the ACL of a requested page. Then it occurred to me that even if I could make this ‘simple’ drag and drop solution, we’d be faced with reapplying it to ten more projects and have subsequent setup processes for each additional project. This seemed highly inefficient and a pain in my ass.

Control Panel

My next realization was that there was multiple overlap on the users accessing various internal applications and way too many vhosts to make for each project. It seemed like it would be better to do the ultimate refactor and create a centralized control panel for people to authenticate and access internal applications.

I was still hung up on wanting to reuse my Navigation based code when I figured out that maintaining the navigation XML would be another nightmare. I had attempted a database solution for one project and it became a pain to maintain the ACL when I introduced Routing to the project. It was a bitter and hateful experience to get it working and since both the Auth/ACL and Routing parts of the project were done before I had embraced unit testing, sorting through my crazy monkey patching logic would only intensify my rage. I also recalled that the biggest issue with that proto-solution was translating the Request into a Resource.

In the schema shown on the right, the Resource.Name corresponded to the Request’s Controller and Privilege.Name corresponded to Request’s Action. When the ACL was created in the Bootstrap, it would create Module.Name_Resource.Name as the resource then associate privileges to that resource. Routing and Controller forwarding made this whole thing hard to mentally track. I ended up having a lot of monkey patch entries to make it work in the end.

So here I was, just generally damned when I thought up a way around the issues I had with the previous schema. I would need to have the Resource.Name independent of the Request URI in order to avoid routing issues. By associating the Resource to a URI, I don’t have to account for if Routing exists or not. The URI will always be available and the core ACL system will be independent of any Routes that do/don’t/might exist. Privileges bound to action seemed like a lot of overkill since all privileges come down to CRUD (though I always like the BREAD acronym better). In addition, privileges would be off in their own world and reused when necessary (the last schema had too many redundant privileges associated to different resources).

As I stated earlier, the goal is a unified login for internal apps (there are currently eleven and this number will grow). The user table consists of a username, password and control panel role. This role allows for future interfaces to be built that can manage the control panel such as adding a project or adding users. If you’re wondering why I have the password column as able to be null, it’s to support some legacy items. Next major table is the project table which lets me have a project_user table  that is also has a role associated with it. I made role a separate table since a lot of the projects overlap on roles such as guest and admin. Resources can be specifically named or generalized as necessary. All my links (URIs) can share a resource name if necessary. Finally there is the privilege table along with a resource_privilege table that allows me to maintain those relationships. While I have a separate control_panel_role, I decided that the control panel resource/privilege system doesn’t need to be separate. I only wanted to make sure that the control panel system was accessible even if there was no projects available for selection. I’m planning on making the past projects into modules under this system and all future internal apps accessible/controlled from here. I lack any co-workers that I’m able to debate the merits of this idea with and given that this will be a major refactor of my work thus far, I am asking for feedback on the idea. Am I missing any other viable ways of defining the ACL that would be easier/better? I’m not a DBA so I’m wondering if my tables are actually optimized well enough. Any other issues or thoughts I haven’t considered?

Enhanced by Zemanta
]]>
https://phpprotip.com/2010/08/authacl-implementation-strategies/feed/ 3 384