Preview all Pygments Styles for your code highlighting needs

Published on Tuesday, 22 February 2011.

For quickly outputting all the styles (available on my system) I used:

$ for i in  monokai manni perldoc borland colorful default murphy 
            vs trac tango fruity autumn bw emacs pastie friendly native;
    do pygmentize -f html -S $i -a .highlight > $i.css; 
  done

So now you should be able to preview a stylesheet by just clicking on any of the following links:

<?php 
class A_Request {

    private $_fields = array(
        'title',
        'fullname',
        'email',
        'company',
      );

    private $_optional_fields = array(
        'company',
    );

    private $_specific_validations = array(
        'email' => 'valid_email',
    );

    private $_request;

    private $_errors;

    private $_model;

    public function __construct() {
        $this->_request = array();
        $this->_errors  = array();
    }

    public function initialize($data) {
        foreach ($this->_fields as $field) {
            if ( ! in_array($field, $this->_optional_fields)) {
                if (array_key_exists($field, $this->_validation_exceptions)) {
                    $method = $this->_validation_exceptions[$field];
                    $this->$method($data[$field]);
                    continue;
                }

                if (isset($data[$field]) AND !empty($data[$field])) {
                    if (array_key_exists($field, $this->_specific_validations)) {
                        $method = $this->_specific_validations[$field];
                        $this->$method($data[$field]);
                    }
                    $this->_request[$field] = $data[$field];
                } else {
                    $this->_errors[$field] = 'error';
                }
            } else {
                if (isset($data[$field])) {
                    $this->_request[$field] = $data[$field];
                }
            }
        }
    }

    public function get_fields() {
        if ( ! empty($this->_request)) {
            return $this->_request;
        }

        return $this->_fields;
    }

    public function get_errors() {
        if ( ! empty($this->_errors)) {
            $this->_errors['has_errors'] = true;
        }

        return $this->_errors;
    }

    public function valid_email($str) {
        $valid = ( ! preg_match(
            "/^([a-z0-9\+_\-]+)(\.[a-z0-9\+_\-]+)*@([a-z0-9\-]+\.)+[a-z]{2,6}$/ix", 
            $str
        ) ) ? FALSE : TRUE;

        if ( ! $valid) {
            $this->_errors['email'] = 'error';
        }
    }

    public function is_valid() {
        if (empty($this->_errors)) {
            return true;
        }

        return false;
    }

    public function set_model($model) {
        $this->_model = $model;
    }

    public function create() {
        return $this->_model->create($this->_request);
    }

    public function get($id) {
        return $this->_model->get($id);
    }

}