Пример #1
0
    function _addWebService($service_name, &$WebService)
    {
        $Apis =& $WebService->getApis();

        foreach (array_keys($Apis) as $k){
            $api_methods =& $Apis[$k]->getApiMethods();
            foreach (array_keys($api_methods) as $k){
                $api_method =& $api_methods[$k];
                $public_name = AkInflector::variablize($api_method->public_name);
                $signatures = var_export(array_merge($api_method->returns, $api_method->expects),  true);
                $documentation = var_export($this->_getDocumentationForMethod($api_method), true);

                $this->_callbacks[] = "
                
        \$this->addCallback(
        '$service_name.$public_name',
        'this:_{$service_name}_{$api_method->name}_call',
        $signatures,
        $documentation
        );
            ";

                $this->_methods[] = "
                
    function _{$service_name}_{$api_method->name}_call()
    {
        \$args = func_get_args();
        return call_user_func_array(array(&\$this->_{$service_name}, '".$api_method->name."'), (array)\$args[0]); 
    }
                    ";

            }
        }
    }
Пример #2
0
    function Block($match, $state)
    {
        switch ($state){
            case AK_LEXER_ENTER:
                $this->_block = '';
                $this->_block_params = array();
                $this->_block_data = array();
                if(strstr($match, '=')){
                    list($parameters, $match) = explode('=', $match);
                    $parameters = array_diff(array_map('trim', Ak::toArray(trim($parameters,' (){|'.$this->_SINTAGS_OPEN_HELPER_TAG))), array(''));
                    foreach ($parameters as $parameter){
                        if($parameter = $this->_convertSintagsVarToPhp($parameter)){
                            $this->_block_params[] = $parameter;
                        }else{
                            return false;
                        }
                    }
                }
                $method_or_var_names = array_diff(array_map('trim', Ak::toArray(trim($match,' (){|'.$this->_SINTAGS_OPEN_HELPER_TAG))), array(''));
                foreach ($method_or_var_names as $method_or_var_name){
                    if($helper = $this->_getHelperNameForMethod($method_or_var_name)){
                        if(!strpos($helper, 'helper')){
                            $method_or_var_name = AkInflector::variablize($method_or_var_name);
                        }
                        $this->_block_data[] = "\${$helper}->$method_or_var_name()";
                        return true;
                    }elseif(!strstr($match,'(') && $php_variable = $this->_convertSintagsVarToPhp($method_or_var_name)){
                        $this->_block_data[] = $php_variable;
                    }else{
                        $this->addError(Ak::t('Could not find a helper to handle the method "%method" you called in your view', array('%method'=>$method_or_var_name)));
                    }
                }

                break;
            case AK_LEXER_MATCHED:
                $this->_block_keys = array();
                $parameters = Ak::toArray($match);
                foreach ($parameters as $parameter){
                    if($parameter = $this->_convertSintagsVarToPhp($parameter)){
                        $this->_block_keys[] = $parameter;
                    }else{
                        return false;
                    }
                }
                break;
            case AK_LEXER_UNMATCHED:
                $this->_block .= $match;
                break;
            case AK_LEXER_EXIT:

                $this->output .= "<?php \n";
                foreach ($this->_block_data as $k=>$block_data){
                    if(strstr($block_data,'->')){
                        /**
                         * @todo Implement helper calls on blocks
                         */
                    }else{
                        $this->output .= "if(!empty($block_data)){\n";
                        if(!empty($this->_block_params[$k])){
                            $this->output .= "    {$this->_block_params[$k]} = array();\n";
                        }
                        $this->output .= "    foreach (array_keys((array)$block_data) as \$ak_sintags_key){\n";
                        if(count($this->_block_keys) == 1){
                            $this->output .= "        {$this->_block_keys[0]} =& {$block_data}[\$ak_sintags_key];\n";
                        }
                        $this->output .= "       $this->_block;\n";
                        if(!empty($this->_block_params[$k])){
                            $this->output .= "        {$this->_block_params[$k]}[\$ak_sintags_key] = {$block_data}[\$ak_sintags_key];\n";
                        }
                        $this->output .= "    }\n";
                        $this->output .= "}";
                    }
                }
                $this->output .= "?>";

                return true;
        }

        return true;
    }
Пример #3
0
 /**
  * Options for pear ImageTransform are normally in lower camelCase so we need to remap the option keys
  * to adhere to the framework convention of underscored options
  */
 protected function _variablizeOptions_(&$options)
 {
     foreach ($options as $k => $v) {
         $options[AkInflector::variablize($k)] = $v;
     }
 }
Пример #4
0
    /**
    * Akelos data types are mapped to phpAdodb data types
    *
    * Returns the Akelos data type for an Adodb Column Object
    *
    * 'C'=>'string', // Varchar, capped to 255 characters.
    * 'X' => 'text' // Larger varchar, capped to 4000 characters (to be compatible with Oracle).
    * 'XL' => 'text' // For Oracle, returns CLOB, otherwise the largest varchar size.
    *
    * 'C2' => 'string', // Multibyte varchar
    * 'X2' => 'string', // Multibyte varchar (largest size)
    *
    * 'B' => 'binary', // BLOB (binary large object)
    *
    * 'D' => array('date', 'datetime'), //  Date (some databases do not support this, and we return a datetime type)
    * 'T' =>  array('datetime', 'timestamp'), //Datetime or Timestamp
    * 'L' => 'boolean', // Integer field suitable for storing booleans (0 or 1)
    * 'I' => // Integer (mapped to I4)
    * 'I1' => 'integer', // 1-byte integer
    * 'I2' => 'integer', // 2-byte integer
    * 'I4' => 'integer', // 4-byte integer
    * 'I8' => 'integer', // 8-byte integer
    * 'F' => 'float', // Floating point number
    * 'N' => 'integer' //  Numeric or decimal number
    *
    * @return string One of this 'string','text','integer','float','datetime','timestamp',
    * 'time', 'name','date', 'binary', 'boolean'
    */
    function getAkelosDataType(&$adodb_column_object)
    {
        $config_var_name = AkInflector::variablize($adodb_column_object->name.'_data_type');
        if(!empty($this->{$config_var_name})){
            return $this->{$config_var_name};
        }
        if(stristr($adodb_column_object->type, 'BLOB')){
            return 'binary';
        }
        if(!empty($adodb_column_object->auto_increment)) {
            return 'serial';
        }
        $meta_type = $this->_dataDictionary->MetaType($adodb_column_object);
        $adodb_data_types = array(
        'C'=>'string', // Varchar, capped to 255 characters.
        'X' => 'text', // Larger varchar, capped to 4000 characters (to be compatible with Oracle).
        'XL' => 'text', // For Oracle, returns CLOB, otherwise the largest varchar size.

        'C2' => 'string', // Multibyte varchar
        'X2' => 'string', // Multibyte varchar (largest size)

        'B' => 'binary', // BLOB (binary large object)

        'D' => array('date'), //  Date
        'T' =>  array('datetime', 'timestamp'), //Datetime or Timestamp
        'L' => 'boolean', // Integer field suitable for storing booleans (0 or 1)
        'R' => 'serial', // Serial Integer
        'I' => 'integer', // Integer (mapped to I4)
        'I1' => 'integer', // 1-byte integer
        'I2' => 'integer', // 2-byte integer
        'I4' => 'integer', // 4-byte integer
        'I8' => 'integer', // 8-byte integer
        'F' => 'float', // Floating point number
        'N' => 'decimal' //  Numeric or decimal number
        );

        $result = !isset($adodb_data_types[$meta_type]) ?
        'string' :
        (is_array($adodb_data_types[$meta_type]) ? $adodb_data_types[$meta_type][0] : $adodb_data_types[$meta_type]);

        if($result == 'text'){
            if(stristr($adodb_column_object->type, 'CHAR') | (isset($adodb_column_object->max_length) && $adodb_column_object->max_length > 0 &&$adodb_column_object->max_length < 256 )){
                return 'string';
            }
        }

        if($this->_getDatabaseType() == 'mysql'){
            if($result == 'integer' && stristr($adodb_column_object->type, 'TINYINT')){
                return 'boolean';
            }
        }elseif($this->_getDatabaseType() == 'postgre'){
            if($adodb_column_object->type == 'timestamp' || $result == 'datetime'){
                $adodb_column_object->max_length = 19;
            }
        }elseif($this->_getDatabaseType() == 'sqlite'){
            if($result == 'integer' && (int)$adodb_column_object->max_length === 1 && stristr($adodb_column_object->type, 'TINYINT')){
                return 'boolean';
            }elseif($result == 'integer' && stristr($adodb_column_object->type, 'DOUBLE')){
                return 'float';
            }
        }

        if($result == 'datetime' && substr($adodb_column_object->name,-3) == '_on'){
            $result = 'date';
        }

        return $result;
    }
Пример #5
0
 /**
  * Akelos data types are mapped to phpAdodb data types
  *
  * Returns the Akelos data type for an Adodb Column Object
  *
  * 'C'=>'string', // Varchar, capped to 255 characters.
  * 'X' => 'text' // Larger varchar, capped to 4000 characters (to be compatible with Oracle).
  * 'XL' => 'text' // For Oracle, returns CLOB, otherwise the largest varchar size.
  *
  * 'C2' => 'string', // Multibyte varchar
  * 'X2' => 'string', // Multibyte varchar (largest size)
  *
  * 'B' => 'binary', // BLOB (binary large object)
  *
  * 'D' => array('date', 'datetime'), //  Date (some databases do not support this, and we return a datetime type)
  * 'T' =>  array('datetime', 'timestamp'), //Datetime or Timestamp
  * 'L' => 'boolean', // Integer field suitable for storing booleans (0 or 1)
  * 'I' => // Integer (mapped to I4)
  * 'I1' => 'integer', // 1-byte integer
  * 'I2' => 'integer', // 2-byte integer
  * 'I4' => 'integer', // 4-byte integer
  * 'I8' => 'integer', // 8-byte integer
  * 'F' => 'float', // Floating point number
  * 'N' => 'integer' //  Numeric or decimal number
  *
  * @return string One of this 'string','text','integer','float','datetime','timestamp',
  * 'time', 'name','date', 'binary', 'boolean'
  */
 public function getAkelosDataType(&$adodb_column_object)
 {
     $config_var_name = AkInflector::variablize($adodb_column_object->name . '_data_type');
     if (!empty($this->{$config_var_name})) {
         return $this->{$config_var_name};
     }
     if (stristr($adodb_column_object->type, 'BLOB')) {
         return 'binary';
     }
     if (!empty($adodb_column_object->auto_increment)) {
         return 'serial';
     }
     $meta_type = $this->_dataDictionary->MetaType($adodb_column_object);
     $adodb_data_types = array('C' => 'string', 'X' => 'text', 'XL' => 'text', 'C2' => 'string', 'X2' => 'string', 'B' => 'binary', 'D' => array('date'), 'T' => array('datetime', 'timestamp'), 'L' => 'boolean', 'R' => 'serial', 'I' => 'integer', 'I1' => 'integer', 'I2' => 'integer', 'I4' => 'integer', 'I8' => 'integer', 'F' => 'float', 'N' => 'decimal');
     $result = !isset($adodb_data_types[$meta_type]) ? 'string' : (is_array($adodb_data_types[$meta_type]) ? $adodb_data_types[$meta_type][0] : $adodb_data_types[$meta_type]);
     if ($result == 'text') {
         if (stristr($adodb_column_object->type, 'CHAR') | (isset($adodb_column_object->max_length) && $adodb_column_object->max_length > 0 && $adodb_column_object->max_length < 256)) {
             return 'string';
         }
     }
     if ($this->_getDatabaseType() == 'mysql') {
         if ($result == 'integer' && stristr($adodb_column_object->type, 'TINYINT')) {
             return 'boolean';
         }
     } elseif ($this->_getDatabaseType() == 'postgre') {
         if ($adodb_column_object->type == 'timestamp' || $result == 'datetime') {
             $adodb_column_object->max_length = 19;
         }
     } elseif ($this->_getDatabaseType() == 'sqlite') {
         if ($result == 'integer' && (int) $adodb_column_object->max_length === 1 && stristr($adodb_column_object->type, 'TINYINT')) {
             return 'boolean';
         } elseif ($result == 'integer' && stristr($adodb_column_object->type, 'DOUBLE')) {
             return 'float';
         }
     }
     if ($result == 'datetime' && substr($adodb_column_object->name, -3) == '_on') {
         $result = 'date';
     }
     return $result;
 }