Example #1
0
 function test_should_send_params()
 {
     $params = array('testing' => array('user' => 'bermi', 'nested' => array('one', 'two')));
     $expected = Ak::toJson($params['testing']);
     Ak::compat('http_build_query');
     $query = http_build_query($params);
     foreach ($this->verbs as $verb) {
         $this->assertEqual($this->Client->{$verb}($this->url . '/json/?' . $query), $expected, "{$verb} passing params via url");
         $this->assertEqual($this->Client->{$verb}($this->url . '/json', array('params' => $params)), $expected, "{$verb} passing params via params option");
     }
 }
Example #2
0
 public function getUrlWithParams($url, $params)
 {
     $parts = parse_url($url);
     Ak::compat('http_build_query');
     $parts['query'] = http_build_query($params);
     return $this->_httpRenderQuery($parts);
 }
Example #3
0
File: Ak.php Project: joeymetal/v1
 function mime_content_type($file)
 {
     static $mime_types;
     Ak::compat('mime_content_type');
     $mime = mime_content_type($file);
     if (empty($mime)) {
         empty($mime_types) ? require AK_LIB_DIR . DS . 'utils' . DS . 'mime_types.php' : null;
         $file_name = substr($file, strrpos($file, '/') + 1);
         $file_extension = substr($file_name, strrpos($file_name, '.') + 1);
         $mime = !empty($mime_types[$file_extension]) ? $mime_types[$file_extension] : false;
     }
     return $mime;
 }
Example #4
0
    function _storePageCache($content, $cacheId,$cacheGroup, $timestamp = null)
    {
        $filename = AK_TMP_DIR.DS.'cache'.DS.$cacheGroup.DS.$cacheId.'.php';
        if (!file_exists(dirname($filename))) {
            $res = mkdir(dirname($filename),0755,true);
        }
        if(!AK_PHP5) {

            Ak::compat('file_put_contents');

        }
        file_put_contents($filename, $content);
        if($timestamp == null) {
            $timestamp=time();
        }
        touch($filename,$timestamp);
        return array($filename,$timestamp);
    }
Example #5
0
    /**
    * Adds a sanitized version of $conditions to the $sql string. Note that the passed $sql string is changed.
    */
    function addConditions(&$sql, $conditions = null, $table_alias = null)
    {
        if (empty($sql)) {
            $concat = '';
        }
        //if (is_string($conditions) && (stristr($conditions,' WHERE ') || stristr($conditions,'SELECT'))) {
        if (is_string($conditions) && (preg_match('/^SELECT.*?WHERE/is',trim($conditions)))) {// || stristr($conditions,'SELECT'))) {
            $concat = '';
            $sql = $conditions;
            $conditions = '';
        } else {

            $concat = 'WHERE';
        }
        $concat = empty($sql) ? '' : ' WHERE ';
        if (stristr($sql,' WHERE ')) $concat = ' AND ';
        if (empty($conditions) && $this->_getDatabaseType() == 'sqlite') $conditions = '1';  // sqlite HACK

        if($this->getInheritanceColumn() !== false && $this->descendsFromActiveRecord($this)){
            $type_condition = $this->typeCondition($table_alias);
            if (empty($sql)) {
                $sql .= !empty($type_condition) ? $concat.$type_condition : '';
                $concat = ' AND ';
                if (!empty($conditions)) {
                    $conditions = '('.$conditions.')';
                }
            } else {
                Ak::compat('stripos');
                if (($wherePos=stripos($sql,'WHERE'))!==false) {
                    if (!empty($type_condition)) {
                        $oldConditions = trim(substr($sql,$wherePos+5));
                        $sql = substr($sql,0,$wherePos).' WHERE '.$type_condition.' AND ('.$oldConditions.')';
                        $concat = ' AND ';
                    }
                    if (!empty($conditions)) {
                        $conditions = '('.$conditions.')';
                    }
                } else {
                    if (!empty($type_condition)) {
                        //$oldConditions = trim(substr($sql,$wherePos+5));
                        $sql = $sql.' WHERE '.$type_condition.'';
                        $concat = ' AND ';
                    }
                    if (!empty($conditions)) {
                        $conditions = '('.$conditions.')';
                    }
                }

            }
        }

        if(!empty($conditions)){

            $sql  .= $concat.$conditions;
            $concat = ' AND ';

        }


        return $sql;
    }
Example #6
0
 function _storePageCache($content, $cacheId, $cacheGroup)
 {
     $filename = AK_TMP_DIR . DS . 'cache' . DS . $cacheGroup . DS . $cacheId . '.php';
     if (!file_exists(dirname($filename))) {
         $res = mkdir(dirname($filename), 0755, true);
     }
     if (!AK_PHP5) {
         Ak::compat('file_put_contents');
     }
     file_put_contents($filename, $content);
     return $filename;
 }
Example #7
0
<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
// +----------------------------------------------------------------------+
// | Akelos Framework - http://www.akelos.org                             |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+
Ak::compat('http_build_query');
/**
 * Native PHP URL rewriting for the Akelos Framework.
 * 
 * @package AkelosFramework
 * @subpackage Reporting
 * @author Bermi Ferrer <bermi a.t akelos c.om>
 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */
// ---- Required Files ---- //
require_once AK_LIB_DIR . DS . 'AkObject.php';
if (!defined('OPTIONAL')) {
    define('OPTIONAL', false);
}
if (!defined('COMPULSORY')) {
    define('COMPULSORY', true);
}
if (!defined('COMPULSORY_REGEX')) {
    define('COMPULSORY_REGEX', '([^\\/]+){1}');
}
/**
Example #8
0
if (!defined('AK_NUMBER_REGULAR_EXPRESSION')) {
    define('AK_NUMBER_REGULAR_EXPRESSION', "/^[0-9]+\$/");
}
if (!defined('AK_PHONE_REGULAR_EXPRESSION')) {
    define('AK_PHONE_REGULAR_EXPRESSION', "/^([\\+]?[(]?[\\+]?[ ]?[0-9]{2,3}[)]?[ ]?)?[0-9 ()\\-]{4,25}\$/");
}
if (!defined('AK_DATE_REGULAR_EXPRESSION')) {
    define('AK_DATE_REGULAR_EXPRESSION', "/^(([0-9]{1,2}(\\-|\\/|\\.| )[0-9]{1,2}(\\-|\\/|\\.| )[0-9]{2,4})|([0-9]{2,4}(\\-|\\/|\\.| )[0-9]{1,2}(\\-|\\/|\\.| )[0-9]{1,2})){1}\$/");
}
if (!defined('AK_IP4_REGULAR_EXPRESSION')) {
    define('AK_IP4_REGULAR_EXPRESSION', "/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\$/");
}
if (!defined('AK_POST_CODE_REGULAR_EXPRESSION')) {
    define('AK_POST_CODE_REGULAR_EXPRESSION', "/^[0-9A-Za-z  -]{2,9}\$/");
}
Ak::compat('array_combine');
/**
* Active Record objects doesn't specify their attributes directly, but rather infer them from the table definition with
* which they're linked. Adding, removing, and changing attributes and their type is done directly in the database. Any change
* is instantly reflected in the Active Record objects. The mapping that binds a given Active Record class to a certain
* database table will happen automatically in most common cases, but can be overwritten for the uncommon ones. 
* 
* See the mapping rules in table_name and the full example in README.txt for more insight.
* 
* == Creation ==
* 
* Active Records accepts constructor parameters either in an array or as a list of parameters in a specific format. The array method is especially useful when
* you're receiving the data from somewhere else, like a HTTP request. It works like this:
* 
*   $user = new User(array('name' => 'David', 'occupation' => 'Code Artist'));
*   echo $user->name; // Will print "David"
Example #9
0
} else {
    load_tests(AK_TEST_DIR.DS.'unit'.DS.'suites', $test);
}
if (TextReporter::inCli()) {
    $writeXml = false;
    if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1]=='--xml') {
        $file = isset($_SERVER['argv'][2])?$_SERVER['argv'][2]:false;
        $phpversion = isset($_SERVER['argv'][3])?$_SERVER['argv'][3]:'php5';
        $backend = isset($_SERVER['argv'][4])?$_SERVER['argv'][4]:'mysql';
        $writeXml=true;
        $reporter = new XmlReporter('UTF-8',$phpversion,$backend);
        $run = $test->run($reporter);
    } else {
        $reporter = new TextReporter();
        $run = $test->run($reporter);
    }
    
    if ($writeXml) {
        $contents = $reporter->getXml();
        Ak::compat('file_put_contents');
        file_put_contents($file,$contents);
    }
    exit ($run ? 0 : 1);
    
}
$test->run(new HtmlReporter());



?>
Example #10
0
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2006, Akelos Media, S.L.  & Bermi Ferrer Martinez |
// | Released under the GNU Lesser General Public License, see LICENSE.txt|
// +----------------------------------------------------------------------+

/**
 * @package ActiveRecord
 * @subpackage Associations
 * @author Bermi Ferrer <bermi a.t akelos c.om>
 * @copyright Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
 * @license GNU Lesser General Public License <http://www.gnu.org/copyleft/lesser.html>
 */

defined('AK_HAS_AND_BELONGS_TO_MANY_CREATE_JOIN_MODEL_CLASSES') ? null : define('AK_HAS_AND_BELONGS_TO_MANY_CREATE_JOIN_MODEL_CLASSES' ,true);
defined('AK_HAS_AND_BELONGS_TO_MANY_JOIN_CLASS_EXTENDS') ? null : define('AK_HAS_AND_BELONGS_TO_MANY_JOIN_CLASS_EXTENDS' , 'ActiveRecord');
Ak::compat('stripos');
require_once(AK_LIB_DIR.DS.'AkActiveRecord'.DS.'AkAssociation.php');

/**
* Associates two classes via an intermediate join table.  Unless the join table is explicitly specified as
* an option, it is guessed using the lexical order of the class names. So a join between Developer and Project
* will give the default join table name of "developers_projects" because "D" outranks "P".
*
* Adds the following methods for retrieval and query.
* 'collection' is replaced with the associton identification passed as the first argument, so 
* <tt>var $has_and_belongs_to_many = 'categories'</tt> would make available on the its parent an array of
*  objects on $this->categories and a collection handling interface instance on $this->category (singular form)
* * <tt>collection->load($force_reload = false)</tt> - returns an array of all the associated objects.
*   An empty array is returned if none is found.
* * <tt>collection->add($object, ...)</tt> - adds one or more objects to the collection by creating associations in the join table 
*   (collection->push and $collection->concat are aliases to this method).