What Libraries and script you prepare for new PHP Project

Hello everyone;

I always wandered what other developers use in there projects

What are the must have libraries for any new project
and how you organize them

I read few articles about this but i would love to know more things from SitePoint members.

IM NOT TALKING ABOUT FRAMEWORKS HERE.

To what i read you organize your files this way

img
—layout
—content
—and maybe more things needed

css
----reset.css
----common.css

js
----Jquery.js
----maybe something else

resources
----library
--------- DBclass.php
--------- fprmvalidationclass.php
--------- MaybeAuthClass.php
--------- CommonFunc.php

----template
------------header.php
------------content.php
------------footer.php
------------sidebar.php
----config.php

What do you usually do for your organization and prepare ready script for your new project…?

Grateful as usual

Here’s a simplified version of what I would use in real life. It might give you new ideas to mull.

src/ (your PHP here)
	controllers/
		BlogController.php
	templates/
		layout.html.php
		Blog/
			list.html.php
			show.html.php
			edit.html.php
	model/
		entities/
			Blog.php
		repositories/
			BlogRepository.php
	config/
		config.yml
vendor/ (third-party PHP here)
	swiftmailer/
	doctrine/
	twig/
web/ (publicly accessible files here)
	images/
	css/
	js/
	index.php (all requests go through this single entry point)

Thanks Jeff for the reply

In term of organizing its really interesting Thank you for the tip.

But How do you route your code …!!!
Do you use a particulate class or functions to handle it…

Any other class o library you use beside the ones mentioned

What about the rest of developers here… Any experience you would like to share with us?

I checked the third party libraries you have mentioned
I got to say Why would someone need a framework…?

swiftmailer
doctrine
twig

These libraries are nice though im not into template engines,… Twig…
I found few other libraries
Good for any new project
PDF Generator
-tcpdf
Image Manipulation
-wideimage
Charts
-PHP/SWF Charts (Though i prefer a class that does not make it flash)
Authentication
-PHPUserClass

Anymore suggestion for common libraries …?

Do you mean going from a URL to a controller? The low-tech solution could look something like this:

function routingMatch($urlPath)
{
    if ($urlPath == '/') {
        return array('controller' => 'Blog', 'action' => 'list');
    } elseif ($urlPath == '/show' && isset($_GET['id'])) {
        return array('controller' => 'Blog', 'action' => 'show');
    }
}

// ...

$routeParameters = routingMatch($_SERVER['REQUEST_URI']);

Or we could use the Symfony Routing component. (Beside being a full-stack framework, Symfony is also a set of standalone libraries, so we can use the routing component without using the full framework.)

// src/config/routing.php

use Symfony\\Component\\Routing\\RouteCollection;
use Symfony\\Component\\Routing\\Route;

$collection = new RouteCollection();

$collection->add('blog_list', new Route('/', array(
    'controller' => 'Blog', 'action' => 'list',
)));

$collection->add('blog_show', new Route('/show/{id}', array(
    'controller' => 'Blog', 'action' => 'show',
)));

return $collection;
// web/index.php

use Symfony\\Component\\Routing\\RequestContext;
use Symfony\\Component\\Routing\\Matcher\\UrlMatcher;

$routes = require __DIR__.'/../src/config/routing.php';
$context = new RequestContext('/base-url');

$matcher = new UrlMatcher($routes, $context);

$parameters = $matcher->match($_SERVER['REQUEST_URI']);

In my case, I do actually use the full-stack Symfony framework, so I can define my routes in a few ways. The first is the plain PHP way, similar to the config/routing.php shown above. Or I have the option to use YAML.

# app/config/routing.yml

blog_list:
    pattern:   /
    defaults:  { _controller: AcmeBlogBundle:Blog:list }

blog_show:
    pattern:   /show/{id}
    defaults:  { _controller: AcmeBlogBundle:Blog:show }

Or I have the option to use annotations within the controller itself.

// src/Acme/BlogBundle/Controller/BlogController.php

use Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller;
use Sensio\\Bundle\\FrameworkExtraBundle\\Configuration\\Route;

class BlogController extends Controller
{
    /**
     * @Route("/")
     */
    public function listAction()
    {
        // ...
    }

    /**
     * @Route("/show/{id}")
     */
    public function showAction($id)
    {
        // ...
    }
}

Thanks Jeff
Its really informative.

Now i have a good idea how it works.