• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP fGrammar类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中fGrammar的典型用法代码示例。如果您正苦于以下问题:PHP fGrammar类的具体用法?PHP fGrammar怎么用?PHP fGrammar使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了fGrammar类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。

示例1: setupORM

 protected function setupORM()
 {
     if ($this->isOrmSettedUp) {
         return;
     }
     $this->defineConstants();
     // Extract port from host. See wpdb::db_connect
     $port = null;
     $host = $this->wp->getDbHost();
     if (preg_match('/^(.+):(\\d+)$/', trim($host), $m)) {
         $host = $m[1];
         $port = $m[2];
     }
     $database = new fDatabase('mysql', $this->wp->getDbName(), $this->wp->getDbUser(), $this->wp->getDbPassword(), $host, $port);
     // $database->enableDebugging(true);
     fORMDatabase::attach($database);
     fORM::mapClassToTable('WpTesting_Model_Test', WP_DB_PREFIX . 'posts');
     fORM::mapClassToTable('WpTesting_Model_Question', WPT_DB_PREFIX . 'questions');
     fORM::mapClassToTable('WpTesting_Model_Taxonomy', WP_DB_PREFIX . 'term_taxonomy');
     fORM::mapClassToTable('WpTesting_Model_GlobalAnswer', WP_DB_PREFIX . 'terms');
     fORM::mapClassToTable('WpTesting_Model_Answer', WPT_DB_PREFIX . 'answers');
     fORM::mapClassToTable('WpTesting_Model_Scale', WP_DB_PREFIX . 'terms');
     fORM::mapClassToTable('WpTesting_Model_Score', WPT_DB_PREFIX . 'scores');
     fORM::mapClassToTable('WpTesting_Model_Passing', WPT_DB_PREFIX . 'passings');
     fORM::mapClassToTable('WpTesting_Model_Result', WP_DB_PREFIX . 'terms');
     fORM::mapClassToTable('WpTesting_Model_Formula', WPT_DB_PREFIX . 'formulas');
     fORM::mapClassToTable('WpTesting_Model_Respondent', WP_DB_PREFIX . 'users');
     fGrammar::addSingularPluralRule('Taxonomy', 'Taxonomy');
     fGrammar::addSingularPluralRule('Score', 'Score');
     fGrammar::addSingularPluralRule('Answer', 'Answer');
     $schema = fORMSchema::retrieve('name:default');
     $fkOptions = array('on_delete' => 'cascade', 'on_update' => 'cascade');
     $schema->setKeysOverride(array(array('column' => 'test_id', 'foreign_table' => WP_DB_PREFIX . 'posts', 'foreign_column' => 'ID') + $fkOptions), WPT_DB_PREFIX . 'questions', 'foreign');
     $schema->setKeysOverride(array(array('column' => 'answer_id', 'foreign_table' => WPT_DB_PREFIX . 'answers', 'foreign_column' => 'answer_id') + $fkOptions, array('column' => 'scale_id', 'foreign_table' => WP_DB_PREFIX . 'terms', 'foreign_column' => 'term_id') + $fkOptions), WPT_DB_PREFIX . 'scores', 'foreign');
     $schema->setKeysOverride(array(array('column' => 'test_id', 'foreign_table' => WP_DB_PREFIX . 'posts', 'foreign_column' => 'ID') + $fkOptions, array('column' => 'respondent_id', 'foreign_table' => WP_DB_PREFIX . 'users', 'foreign_column' => 'ID') + $fkOptions), WPT_DB_PREFIX . 'passings', 'foreign');
     $schema->setKeysOverride(array(array('column' => 'answer_id', 'foreign_table' => WPT_DB_PREFIX . 'answers', 'foreign_column' => 'answer_id') + $fkOptions, array('column' => 'passing_id', 'foreign_table' => WPT_DB_PREFIX . 'passings', 'foreign_column' => 'passing_id') + $fkOptions), WPT_DB_PREFIX . 'passing_answers', 'foreign');
     $schema->setKeysOverride(array(array('column' => 'test_id', 'foreign_table' => WP_DB_PREFIX . 'posts', 'foreign_column' => 'ID') + $fkOptions, array('column' => 'result_id', 'foreign_table' => WP_DB_PREFIX . 'terms', 'foreign_column' => 'term_id') + $fkOptions), WPT_DB_PREFIX . 'formulas', 'foreign');
     $schema->setColumnInfoOverride(null, WP_DB_PREFIX . 'term_relationships', 'term_order');
     $schema->setKeysOverride(array(array('column' => 'object_id', 'foreign_table' => WP_DB_PREFIX . 'posts', 'foreign_column' => 'ID') + $fkOptions, array('column' => 'term_taxonomy_id', 'foreign_table' => WP_DB_PREFIX . 'term_taxonomy', 'foreign_column' => 'term_taxonomy_id') + $fkOptions), WP_DB_PREFIX . 'term_relationships', 'foreign');
     $schema->setKeysOverride(array(array('column' => 'term_id', 'foreign_table' => WP_DB_PREFIX . 'terms', 'foreign_column' => 'term_id') + $fkOptions), WP_DB_PREFIX . 'term_taxonomy', 'foreign');
     $schema->setKeysOverride(array(array('column' => 'question_id', 'foreign_table' => WPT_DB_PREFIX . 'questions', 'foreign_column' => 'question_id') + $fkOptions, array('column' => 'global_answer_id', 'foreign_table' => WP_DB_PREFIX . 'terms', 'foreign_column' => 'term_id') + $fkOptions), WPT_DB_PREFIX . 'answers', 'foreign');
     $schema->setKeysOverride(array(), WPT_DB_PREFIX . 'sections', 'foreign');
     $schema->setKeysOverride(array(), WPT_DB_PREFIX . 'fields', 'foreign');
     $schema->setKeysOverride(array(), WPT_DB_PREFIX . 'field_values', 'foreign');
     $this->wp->doAction('wp_testing_orm_setup', $schema, $database);
     $this->isOrmSettedUp = true;
 }
开发者ID:pmanterys,项目名称:wp-mw-newsletter,代码行数:47,代码来源:Facade.php


示例2: checkURLFields

 /**
  * Validates the URL fields, requiring that any URL fields that have a value are valid URLs
  * 
  * @param  array &$messages  The messages to display to the user
  * @return void
  */
 private function checkURLFields(&$messages)
 {
     foreach ($this->url_fields as $url_field) {
         $value = trim(fRequest::get($url_field));
         if (self::stringlike($value) && !preg_match('#^https?://[^ ]+$#iD', $value)) {
             $messages[] = self::compose('%sPlease enter a URL in the form http://www.example.com/page', fValidationException::formatField(fGrammar::humanize($url_field)));
         }
     }
 }
开发者ID:philip,项目名称:flourish,代码行数:15,代码来源:fValidation.php


示例3: replicate

 /**
  * Generates a clone of the current record, removing any auto incremented primary key value and allowing for replicating related records
  * 
  * This method will accept three different sets of parameters:
  * 
  *  - No parameters: this object will be cloned
  *  - A single `TRUE` value: this object plus all many-to-many associations and all child records (recursively) will be cloned
  *  - Any number of plural related record class names: the many-to-many associations or child records that correspond to the classes specified will be cloned
  * 
  * The class names specified can be a simple class name if there is only a
  * single route between the two corresponding database tables. If there is 
  * more than one route between the two tables, the class name should be
  * substituted with a string in the format `'RelatedClass{route}'`.
  * 
  * @param  string $related_class  The plural related class to replicate - see method description for details
  * @param  string ...
  * @return fActiveRecord  The cloned record
  */
 public function replicate($related_class = NULL)
 {
     fORM::callHookCallbacks($this, 'pre::replicate()', $this->values, $this->old_values, $this->related_records, $this->cache, fActiveRecord::$replicate_level);
     fActiveRecord::$replicate_level++;
     $class = get_class($this);
     $hash = self::hash($this->values, $class);
     $schema = fORMSchema::retrieve($class);
     $table = fORM::tablize($class);
     // If the object has not been replicated yet, do it now
     if (!isset(fActiveRecord::$replicate_map[$class])) {
         fActiveRecord::$replicate_map[$class] = array();
     }
     if (!isset(fActiveRecord::$replicate_map[$class][$hash])) {
         fActiveRecord::$replicate_map[$class][$hash] = clone $this;
         // We need the primary key to get a hash, otherwise certain recursive relationships end up losing members
         $pk_columns = $schema->getKeys($table, 'primary');
         if (sizeof($pk_columns) == 1 && $schema->getColumnInfo($table, $pk_columns[0], 'auto_increment')) {
             fActiveRecord::$replicate_map[$class][$hash]->values[$pk_columns[0]] = $this->values[$pk_columns[0]];
         }
     }
     $clone = fActiveRecord::$replicate_map[$class][$hash];
     $parameters = func_get_args();
     $recursive = FALSE;
     $many_to_many_relationships = $schema->getRelationships($table, 'many-to-many');
     $one_to_many_relationships = $schema->getRelationships($table, 'one-to-many');
     // When just TRUE is passed we recursively replicate all related records
     if (sizeof($parameters) == 1 && $parameters[0] === TRUE) {
         $parameters = array();
         $recursive = TRUE;
         foreach ($many_to_many_relationships as $relationship) {
             $parameters[] = fGrammar::pluralize(fORM::classize($relationship['related_table'])) . '{' . $relationship['join_table'] . '}';
         }
         foreach ($one_to_many_relationships as $relationship) {
             $parameters[] = fGrammar::pluralize(fORM::classize($relationship['related_table'])) . '{' . $relationship['related_column'] . '}';
         }
     }
     $record_sets = array();
     foreach ($parameters as $parameter) {
         // Parse the Class{route} strings
         if (strpos($parameter, '{') !== FALSE) {
             $brace = strpos($parameter, '{');
             $related_class = fGrammar::singularize(substr($parameter, 0, $brace));
             $related_class = fORM::getRelatedClass($class, $related_class);
             $related_table = fORM::tablize($related_class);
             $route = substr($parameter, $brace + 1, -1);
         } else {
             $related_class = fGrammar::singularize($parameter);
             $related_class = fORM::getRelatedClass($class, $related_class);
             $related_table = fORM::tablize($related_class);
             $route = fORMSchema::getRouteName($schema, $table, $related_table);
         }
         // Determine the kind of relationship
         $many_to_many = FALSE;
         $one_to_many = FALSE;
         foreach ($many_to_many_relationships as $relationship) {
             if ($relationship['related_table'] == $related_table && $relationship['join_table'] == $route) {
                 $many_to_many = TRUE;
                 break;
             }
         }
         foreach ($one_to_many_relationships as $relationship) {
             if ($relationship['related_table'] == $related_table && $relationship['related_column'] == $route) {
                 $one_to_many = TRUE;
                 break;
             }
         }
         if (!$many_to_many && !$one_to_many) {
             throw new fProgrammerException('The related class specified, %1$s, does not appear to be in a many-to-many or one-to-many relationship with %$2s', $parameter, get_class($this));
         }
         // Get the related records
         $record_set = fORMRelated::buildRecords($class, $this->values, $this->related_records, $related_class, $route);
         // One-to-many records need to be replicated, possibly recursively
         if ($one_to_many) {
             if ($recursive) {
                 $records = $record_set->call('replicate', TRUE);
             } else {
                 $records = $record_set->call('replicate');
             }
             $record_set = fRecordSet::buildFromArray($related_class, $records);
             $record_set->call('set' . fGrammar::camelize($route, TRUE), NULL);
         }
         // Cause the related records to be associated with the new clone
//.........这里部分代码省略.........
开发者ID:mrjwc,项目名称:printmaster,代码行数:101,代码来源:fActiveRecord.php


示例4: upload

 /**
  * Uploads a file
  * 
  * @internal
  * 
  * @param  fActiveRecord $object            The fActiveRecord instance
  * @param  array         &$values           The current values
  * @param  array         &$old_values       The old values
  * @param  array         &$related_records  Any records related to this record
  * @param  array         &$cache            The cache array for the record
  * @param  string        $method_name       The method that was called
  * @param  array         $parameters        The parameters passed to the method
  * @return fFile  The uploaded file
  */
 public static function upload($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters)
 {
     $class = get_class($object);
     list($action, $subject) = fORM::parseMethod($method_name);
     $column = fGrammar::underscorize($subject);
     $existing_temp_file = FALSE;
     // Try to upload the file putting it in the temp dir incase there is a validation problem with the record
     try {
         $upload_dir = self::$file_upload_columns[$class][$column];
         $temp_dir = self::prepareTempDir($upload_dir);
         if (!fUpload::check($column)) {
             throw new fExpectedException('Please upload a file');
         }
         $uploader = self::setUpFUpload($class, $column);
         $file = $uploader->move($temp_dir, $column);
         // If there was an eror, check to see if we have an existing file
     } catch (fExpectedException $e) {
         // If there is an existing file and none was uploaded, substitute the existing file
         $existing_file = fRequest::get('existing-' . $column);
         $delete_file = fRequest::get('delete-' . $column, 'boolean');
         $no_upload = $e->getMessage() == self::compose('Please upload a file');
         if ($existing_file && $delete_file && $no_upload) {
             $file = NULL;
         } elseif ($existing_file) {
             $file_path = $upload_dir->getPath() . $existing_file;
             $file = fFilesystem::createObject($file_path);
             $current_file = $values[$column];
             // If the existing file is the same as the current file, we can just exit now
             if ($current_file && $current_file instanceof fFile && $file->getPath() == $current_file->getPath()) {
                 return;
             }
             $existing_temp_file = TRUE;
         } else {
             $file = NULL;
         }
     }
     // Assign the file
     fActiveRecord::assign($values, $old_values, $column, $file);
     // Perform the file upload inheritance
     if (!empty(self::$column_inheritence[$class][$column])) {
         foreach (self::$column_inheritence[$class][$column] as $other_column) {
             if ($file) {
                 // Image columns will only inherit if it is an fImage object
                 if (!$file instanceof fImage && isset(self::$image_upload_columns[$class]) && array_key_exists($other_column, self::$image_upload_columns[$class])) {
                     continue;
                 }
                 $other_upload_dir = self::$file_upload_columns[$class][$other_column];
                 $other_temp_dir = self::prepareTempDir($other_upload_dir);
                 if ($existing_temp_file) {
                     $other_file = fFilesystem::createObject($other_temp_dir->getPath() . $file->getName());
                 } else {
                     $other_file = $file->duplicate($other_temp_dir, FALSE);
                 }
             } else {
                 $other_file = $file;
             }
             fActiveRecord::assign($values, $old_values, $other_column, $other_file);
             if (!$existing_temp_file && $other_file) {
                 self::processImage($class, $other_column, $other_file);
             }
         }
     }
     // Process the file
     if (!$existing_temp_file && $file) {
         self::processImage($class, $column, $file);
     }
     return $file;
 }
开发者ID:mrjwc,项目名称:printmaster,代码行数:82,代码来源:fORMFile.php


示例5: printPiece

 /**
  * Prints out a piece of a template
  *
  * @param string $template  The name of the template to print
  * @param string $piece     The piece of the template to print
  * @param array  $data      The data to replace the variables with
  * @return void
  */
 private static function printPiece($template, $name, $data)
 {
     if (!isset(self::$templates[$template]['pieces'][$name])) {
         throw new fProgrammerException('The template piece, %s, was not specified when defining the %s template', $name, $template);
     }
     $piece = self::$templates[$template]['pieces'][$name];
     preg_match_all('#\\{\\{ (\\w+)((?:\\|\\w+)+)? \\}\\}#', $piece, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $variable = $match[1];
         $value = !isset($data[$variable]) ? NULL : $data[$variable];
         if (isset($match[2])) {
             $filters = array_slice(explode('|', $match[2]), 1);
             foreach ($filters as $filter) {
                 if (!in_array($filter, self::$filters)) {
                     throw new fProgrammerException('The filter specified, %1$s, is invalid. Must be one of: %2$s.', $filter, join(', ', self::$filters));
                 }
                 if (!strlen($value)) {
                     continue;
                 }
                 if ($filter == 'inflect') {
                     $value = fGrammar::inflectOnQuantity($data['total_records'], $value);
                 } elseif ($filter == 'lower') {
                     $value = fUTF8::lower($value);
                 } elseif ($filter == 'url_encode') {
                     $value = urlencode($value);
                 } elseif ($filter == 'humanize') {
                     $value = fGrammar::humanize($value);
                 }
             }
         }
         $piece = preg_replace('#' . preg_quote($match[0], '#') . '#', fHTML::encode($value), $piece, 1);
     }
     echo $piece;
 }
开发者ID:alandsidel,项目名称:flourish-classes,代码行数:42,代码来源:fPagination.php


示例6: makeFieldName

 /**
  * Creates the name for a field taking into account custom field names
  * 
  * @param string $field  The field to get the name for
  * @return string  The field name
  */
 private function makeFieldName($field)
 {
     if (isset($this->field_names[$field])) {
         return $this->field_names[$field];
     }
     $suffix = '';
     $bracket_pos = strpos($field, '[');
     if ($bracket_pos !== FALSE) {
         $array_dereference = substr($field, $bracket_pos);
         $field = substr($field, 0, $bracket_pos);
         preg_match_all('#(?<=\\[)[^\\[\\]]+(?=\\])#', $array_dereference, $array_keys, PREG_SET_ORDER);
         $array_keys = array_map('current', $array_keys);
         foreach ($array_keys as $array_key) {
             if (is_numeric($array_key)) {
                 $suffix .= ' #' . ($array_key + 1);
             } else {
                 $suffix .= ' ' . fGrammar::humanize($array_key);
             }
         }
     }
     return fGrammar::humanize($field) . $suffix;
 }
开发者ID:JhunCabas,项目名称:material-management,代码行数:28,代码来源:fValidation.php


示例7: setRandomStrings

 /**
  * Sets the appropriate column values to a random string if the object is new
  *
  * @internal
  *
  * @param  fActiveRecord $object            The fActiveRecord instance
  * @param  array         &$values           The current values
  * @param  array         &$old_values       The old values
  * @param  array         &$related_records  Any records related to this record
  * @param  array         &$cache            The cache array for the record
  * @return string  The formatted link
  */
 public static function setRandomStrings($object, &$values, &$old_values, &$related_records, &$cache)
 {
     if ($object->exists()) {
         return;
     }
     $class = get_class($object);
     $table = fORM::tablize($class);
     foreach (self::$random_columns[$class] as $column => $settings) {
         if (fActiveRecord::hasOld($old_values, $column) && $values[$column]) {
             continue;
         }
         self::generate($object, $values, $old_values, $related_records, $cache, 'generate' . fGrammar::camelize($column, TRUE), array());
     }
 }
开发者ID:gopalgrover23,项目名称:flourish-classes,代码行数:26,代码来源:fORMColumn.php


示例8: reflectPhpDoc

 /**
  * Generates phpdoc for class
  * @return string
  */
 public function reflectPhpDoc()
 {
     $signatures = array();
     $class = get_class($this);
     $table = fORM::tablize($class);
     $schema = fORMSchema::retrieve($class);
     foreach ($schema->getColumnInfo($table) as $column => $columnInfo) {
         $camelizedColumn = fGrammar::camelize($column, TRUE);
         // Get and set methods
         $fixedType = $columnInfo['type'];
         if ($fixedType == 'blob') {
             $fixedType = 'string';
         }
         if ($fixedType == 'varchar') {
             $fixedType = 'string';
         }
         if ($fixedType == 'date') {
             $fixedType = 'fDate|string';
         }
         if ($fixedType == 'timestamp') {
             $fixedType = 'fTimestamp|string';
         }
         if ($fixedType == 'time') {
             $fixedType = 'fTime|string';
         }
         $firstFixedType = reset(explode('|', $fixedType));
         $signatures[] = $this->generateMagicMethodPhpDoc('get' . $camelizedColumn, array(), $firstFixedType, "Gets the current value of {$column}");
         $signatures[] = $this->generateMagicMethodPhpDoc('set' . $camelizedColumn, array($fixedType => $column), $class, "Sets the value for {$column}");
     }
     return $signatures;
 }
开发者ID:pmanterys,项目名称:wp-mw-newsletter,代码行数:35,代码来源:AbstractModel.php


示例9: reflect

 /**
  * Adjusts the fActiveRecord::reflect() signatures of columns that have been configured in this class
  * 
  * @internal
  * 
  * @param  string  $class                 The class to reflect
  * @param  array   &$signatures           The associative array of `{method name} => {signature}`
  * @param  boolean $include_doc_comments  If doc comments should be included with the signature
  * @return void
  */
 public static function reflect($class, &$signatures, $include_doc_comments)
 {
     $image_columns = isset(self::$image_upload_columns[$class]) ? array_keys(self::$image_upload_columns[$class]) : array();
     $file_columns = isset(self::$file_upload_columns[$class]) ? array_keys(self::$file_upload_columns[$class]) : array();
     foreach ($file_columns as $column) {
         $camelized_column = fGrammar::camelize($column, TRUE);
         $noun = 'file';
         if (in_array($column, $image_columns)) {
             $noun = 'image';
         }
         $signature = '';
         if ($include_doc_comments) {
             $signature .= "/**\n";
             $signature .= " * Encodes the filename of " . $column . " for output into an HTML form\n";
             $signature .= " * \n";
             $signature .= " * Only the filename will be returned, any directory will be stripped.\n";
             $signature .= " * \n";
             $signature .= " * @return string  The HTML form-ready value\n";
             $signature .= " */\n";
         }
         $encode_method = 'encode' . $camelized_column;
         $signature .= 'public function ' . $encode_method . '()';
         $signatures[$encode_method] = $signature;
         if (in_array($column, $image_columns)) {
             $signature = '';
             if ($include_doc_comments) {
                 $signature .= "/**\n";
                 $signature .= " * Takes the existing image and runs it through the prescribed fImage method calls\n";
                 $signature .= " * \n";
                 $signature .= " * @return void\n";
                 $signature .= " */\n";
             }
             $process_method = 'process' . $camelized_column;
             $signature .= 'public function ' . $process_method . '()';
             $signatures[$process_method] = $signature;
         }
         $signature = '';
         if ($include_doc_comments) {
             $signature .= "/**\n";
             $signature .= " * Prepares the filename of " . $column . " for output into HTML\n";
             $signature .= " * \n";
             $signature .= " * By default only the filename will be returned and any directory will be stripped.\n";
             $signature .= " * The \$include_web_path parameter changes this behaviour.\n";
             $signature .= " * \n";
             $signature .= " * @param  boolean \$include_web_path  If the full web path to the " . $noun . " should be included\n";
             $signature .= " * @return string  The HTML-ready value\n";
             $signature .= " */\n";
         }
         $prepare_method = 'prepare' . $camelized_column;
         $signature .= 'public function ' . $prepare_method . '($include_web_path=FALSE)';
         $signatures[$prepare_method] = $signature;
         $signature = '';
         if ($include_doc_comments) {
             $signature .= "/**\n";
             $signature .= " * Takes a file uploaded through an HTML form for " . $column . " and moves it into the specified directory\n";
             $signature .= " * \n";
             $signature .= " * Any columns that were designated as inheriting from this column will get a copy\n";
             $signature .= " * of the uploaded file.\n";
             $signature .= " * \n";
             if ($noun == 'image') {
                 $signature .= " * Any fImage calls that were added to the column will be processed on the uploaded image.\n";
                 $signature .= " * \n";
             }
             $signature .= " * @return void\n";
             $signature .= " */\n";
         }
         $upload_method = 'upload' . $camelized_column;
         $signature .= 'public function ' . $upload_method . '()';
         $signatures[$upload_method] = $signature;
         $signature = '';
         if ($include_doc_comments) {
             $signature .= "/**\n";
             $signature .= " * Takes a file that exists on the filesystem and copies it into the specified directory for " . $column . "\n";
             $signature .= " * \n";
             if ($noun == 'image') {
                 $signature .= " * Any fImage calls that were added to the column will be processed on the copied image.\n";
                 $signature .= " * \n";
             }
             $signature .= " * @return void\n";
             $signature .= " */\n";
         }
         $set_method = 'set' . $camelized_column;
         $signature .= 'public function ' . $set_method . '()';
         $signatures[$set_method] = $signature;
         $signature = '';
         if ($include_doc_comments) {
             $signature .= "/**\n";
             $signature .= " * Returns metadata about " . $column . "\n";
             $signature .= " * \n";
             $signature .= " * @param  string \$element  The element to return. Must be one of: 'type', 'not_null', 'default', 'valid_values', 'max_length', 'feature', 'directory'.\n";
//.........这里部分代码省略.........
开发者ID:jsuarez,项目名称:MyDesign,代码行数:101,代码来源:fORMFile.php


示例10: tablize

 /**
  * Takes a class name (or class) and turns it into a table name - Uses custom mapping if set
  * 
  * @param  mixed $class  he class name or instance of the class
  * @return string  The table name
  */
 public static function tablize($class)
 {
     if (!isset(self::$class_table_map[$class])) {
         self::$class_table_map[$class] = fGrammar::underscorize(fGrammar::pluralize($class));
     }
     return self::$class_table_map[$class];
 }
开发者ID:jsuarez,项目名称:MyDesign,代码行数:13,代码来源:fORM.php


示例11: buildRecords

 /**
  * Recursivly builds records.
  *
  * @param array* $completed_fixtures
  *   Completed records is stored in this array
  * @param $fixture_data
  *   Build records of this fixture
  */
 private function buildRecords(&$completed_fixtures, $fixture_name, $traverse = TRUE)
 {
     if (array_key_exists($fixture_name, $completed_fixtures)) {
         return;
     }
     // Load data
     if (isset($this->fixture_data[$fixture_name]) === FALSE) {
         $this->loadFixture($fixture_name);
     }
     $class_name = fORM::classize($fixture_name);
     // If the class does not exists created it
     if (class_exists($class_name) === FALSE) {
         fORM::defineActiveRecordClass($class_name);
     }
     // Create the records
     $method_name = NULL;
     $record = NULL;
     $records = array();
     foreach ($this->fixture_data[$fixture_name] as $record_data) {
         $record = new $class_name();
         foreach ($record_data as $key => $value) {
             $method_name = 'set' . fGrammar::camelize($key, $upper = TRUE);
             $value = $this->applyHookCallbacks(self::PreSetBuildHook, $fixture_name, $key, $value);
             if ($this->isRelationshipKey($fixture_name, $key)) {
                 $related_table = $this->getRelatedTable($fixture_name, $key);
                 $required = $this->isRequiredKey($fixture_name, $key);
                 if ($traverse && array_key_exists($related_table, $completed_fixtures) === FALSE && $fixture_name !== $related_table) {
                     if (isset($value) && array_key_exists($related_table, $this->fixture_sources)) {
                         $this->buildRecords($completed_fixtures, $related_table);
                         array_unshift($this->tables_to_tear_down, $related_table);
                     }
                 }
             }
             $record->{$method_name}($value);
         }
         $record->store();
         $records[] = $record;
     }
     $completed_fixtures[$fixture_name] = fRecordSet::buildFromArray($class_name, $records);
 }
开发者ID:mblarsen,项目名称:ffixture,代码行数:48,代码来源:fFixture.php


示例12: configureTimezoneColumn

 /**
  * Sets a timestamp column to store the timezone in another column
  * 
  * Since not all databases support timezone information in timestamp 
  * columns, this method allows storing the timezone in another columns. 
  * When the timestamp and timezone are retrieved from the database, they
  * will be automatically combined together into an fTimestamp object.
  * 
  * @param  mixed  $class             The class name or instance of the class to set the column format
  * @param  string $timestamp_column  The timestamp column to store the timezone for
  * @param  string $timezone_column   The column to store the timezone in
  * @return void
  */
 public static function configureTimezoneColumn($class, $timestamp_column, $timezone_column)
 {
     $class = fORM::getClass($class);
     $table = fORM::tablize($class);
     $schema = fORMSchema::retrieve($class);
     $timestamp_data_type = $schema->getColumnInfo($table, $timestamp_column, 'type');
     if ($timestamp_data_type != 'timestamp') {
         throw new fProgrammerException('The timestamp column specified, %1$s, is a %2$s column. Must be a %3$s to have a related timezone column.', $timestamp_column, $data_type, 'timestamp');
     }
     $timezone_column_data_type = $schema->getColumnInfo($table, $timezone_column, 'type');
     $valid_timezone_column_data_types = array('varchar', 'char', 'text');
     if (!in_array($timezone_column_data_type, $valid_timezone_column_data_types)) {
         throw new fProgrammerException('The timezone column specified, %1$s, is a %2$s column. Must be %3$s to be set as a timezone column.', $timezone_column, $timezone_column_data_type, join(', ', $valid_timezone_column_data_types));
     }
     if (!fORM::checkHookCallback($class, 'post::validate()', self::validateTimezoneColumns)) {
         fORM::registerHookCallback($class, 'post::validate()', self::validateTimezoneColumns);
     }
     if (!fORM::checkHookCallback($class, 'post::loadFromResult()', self::makeTimestampObjects)) {
         fORM::registerHookCallback($class, 'post::loadFromResult()', self::makeTimestampObjects);
     }
     if (!fORM::checkHookCallback($class, 'pre::validate()', self::makeTimestampObjects)) {
         fORM::registerHookCallback($class, 'pre::validate()', self::makeTimestampObjects);
     }
     fORM::registerInspectCallback($class, $timezone_column, self::inspect);
     fORM::registerActiveRecordMethod($class, 'set' . fGrammar::camelize($timestamp_column, TRUE), self::setTimestampColumn);
     fORM::registerActiveRecordMethod($class, 'set' . fGrammar::camelize($timezone_column, TRUE), self::setTimezoneColumn);
     if (empty(self::$timestamp_columns[$class])) {
         self::$timestamp_columns[$class] = array();
     }
     self::$timestamp_columns[$class][$timestamp_column] = $timezone_column;
     if (empty(self::$timezone_columns[$class])) {
         self::$timezone_columns[$class] = array();
     }
     self::$timezone_columns[$class][$timezone_column] = $timestamp_column;
 }
开发者ID:philip,项目名称:flourish,代码行数:48,代码来源:fORMDate.php


示例13: __construct

 /**
  * Creates an object to represent an image on the filesystem
  * 
  * @throws fValidationException  When no image was specified, when the image does not exist or when the path specified is not an image
  * 
  * @param  string  $file_path    The path to the image
  * @param  boolean $skip_checks  If file checks should be skipped, which improves performance, but may cause undefined behavior - only skip these if they are duplicated elsewhere
  * @return fImage
  */
 public function __construct($file_path, $skip_checks = FALSE)
 {
     self::determineProcessor();
     parent::__construct($file_path, $skip_checks);
     if (!self::isImageCompatible($file_path)) {
         $valid_image_types = array('GIF', 'JPG', 'PNG');
         if (self::$processor == 'imagemagick') {
             $valid_image_types[] = 'TIF';
         }
         throw new fValidationException('The image specified, %1$s, is not a valid %2$s file', $file_path, fGrammar::joinArray($valid_image_types, 'or'));
     }
 }
开发者ID:philip,项目名称:flourish,代码行数:21,代码来源:fImage.php


示例14: placeRSS

 /**
  * Prints an RSS `link` HTML tag to the output
  * 
  * @param  mixed $info  The path or array containing the `'path'` to the RSS xml file. May also contain a `'title'` key for the title of the RSS feed.
  * @return void
  */
 protected function placeRSS($info)
 {
     if (!is_array($info)) {
         $info = array('path' => $info, 'title' => fGrammar::humanize(preg_replace('#.*?([^/]+).(rss|xml)$#iD', '\\1', $info)));
     }
     if (!isset($info['title'])) {
         throw new fProgrammerException('The RSS value %s is missing the title key', $info);
     }
     echo '<link rel="alternate" type="application/rss+xml" href="' . $info['path'] . '" title="' . $info['title'] . '" />' . "\n";
 }
开发者ID:philip,项目名称:flourish,代码行数:16,代码来源:fTemplating.php


示例15: tearDown

 public function tearDown()
 {
     fGrammar::reset();
 }
开发者ID:nurulimamnotes,项目名称:flourish-old,代码行数:4,代码来源:fGrammarTest.php


示例16: getFuzzyDifference

 /**
  * Returns the approximate difference in time, discarding any unit of measure but the least specific.
  * 
  * The output will read like:
  * 
  *  - "This timestamp is `{return value}` the provided one" when a timestamp it passed
  *  - "This timestamp is `{return value}`" when no timestamp is passed and comparing with the current timestamp
  * 
  * Examples of output for a timestamp passed might be:
  * 
  *  - `'5 minutes after'`
  *  - `'2 hours before'`
  *  - `'2 days after'`
  *  - `'at the same time'`
  * 
  * Examples of output for no timestamp passed might be:
  * 
  *  - `'5 minutes ago'`
  *  - `'2 hours ago'`
  *  - `'2 days from now'`
  *  - `'1 year ago'`
  *  - `'right now'`
  * 
  * You would never get the following output since it includes more than one unit of time measurement:
  * 
  *  - `'5 minutes and 28 seconds'`
  *  - `'3 weeks, 1 day and 4 hours'`
  * 
  * Values that are close to the next largest unit of measure will be rounded up:
  * 
  *  - `'55 minutes'` would be represented as `'1 hour'`, however `'45 minutes'` would not
  *  - `'29 days'` would be represented as `'1 month'`, but `'21 days'` would be shown as `'3 weeks'`
  * 
  * @param  fTimestamp|object|string|integer $other_timestamp  The timestamp to create the difference with, `NULL` is interpreted as now
  * @return string  The fuzzy difference in time between the this timestamp and the one provided
  */
 public function getFuzzyDifference($other_timestamp = NULL)
 {
     $relative_to_now = FALSE;
     if ($other_timestamp === NULL) {
         $relative_to_now = TRUE;
     }
     $other_timestamp = new fTimestamp($other_timestamp);
     $diff = $this->timestamp - $other_timestamp->timestamp;
     if (abs($diff) < 10) {
         if ($relative_to_now) {
             return self::compose('right now');
         }
         return self::compose('at the same time');
     }
     $break_points = array(45 => array(1, self::compose('second'), self::compose('seconds')), 2700 => array(60, self::compose('minute'), self::compose('minutes')), 64800 => array(3600, self::compose('hour'), self::compose('hours')), 432000 => array(86400, self::compose('day'), self::compose('days')), 1814400 => array(604800, self::compose('week'), self::compose('weeks')), 23328000 => array(2592000, self::compose('month'), self::compose('months')), 2147483647 => array(31536000, self::compose('year'), self::compose('years')));
     foreach ($break_points as $break_point => $unit_info) {
         if (abs($diff) > $break_point) {
             continue;
         }
         $unit_diff = round(abs($diff) / $unit_info[0]);
         $units = fGrammar::inflectOnQuantity($unit_diff, $unit_info[1], $unit_info[2]);
         break;
     }
     if ($relative_to_now) {
         if ($diff > 0) {
             return self::compose('%1$s %2$s from now', $unit_diff, $units);
         }
         return self::compose('%1$s %2$s ago', $unit_diff, $units);
     }
     if ($diff > 0) {
         return self::compose('%1$s %2$s after', $unit_diff, $units);
     }
     return self::compose('%1$s %2$s before', $unit_diff, $units);
 }
开发者ID:jsuarez,项目名称:MyDesign,代码行数:70,代码来源:fTimestamp.php


示例17: setMoneyColumn

 /**
  * Sets the money column and then tries to objectify it with an related currency column
  *
  * @internal
  *
  * @param  fActiveRecord $object            The fActiveRecord instance
  * @param  array         &$values           The current values
  * @param  array         &$old_values       The old values
  * @param  array         &$related_records  Any records related to this record
  * @param  array         &$cache            The cache array for the record
  * @param  string        $method_name       The method that was called
  * @param  array         $parameters        The parameters passed to the method
  * @return fActiveRecord  The record object, to allow for method chaining
  */
 public static function setMoneyColumn($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters)
 {
     list($action, $subject) = fORM::parseMethod($method_name);
     $column = fGrammar::underscorize($subject);
     $class = get_class($object);
     if (count($parameters) < 1) {
         throw new fProgrammerException('The method, %s(), requires at least one parameter', $method_name);
     }
     $value = $parameters[0];
     fActiveRecord::assign($values, $old_values, $column, $value);
     $currency_column = self::$money_columns[$class][$column];
     // See if we can make an fMoney object out of the values
     self::objectifyMoneyWithCurrency($values, $old_values, $column, $currency_column);
     if ($currency_column) {
         if ($value instanceof fMoney) {
             fActiveRecord::assign($values, $old_values, $currency_column, $value->getCurrency());
         }
     }
     return $object;
 }
开发者ID:gopalgrover23,项目名称:flourish-classes,代码行数:34,代码来源:fORMMoney.php


示例18: setTimezoneColumn

 /**
  * Sets the timezone column and then tries to objectify the related timestamp column
  *
  * @internal
  *
  * @param  fActiveRecord $object            The fActiveRecord instance
  * @param  array         &$values           The current values
  * @param  array         &$old_values       The old values
  * @param  array         &$related_records  Any records related to this record
  * @param  array         &$cache            The cache array for the record
  * @param  string        $method_name       The method that was called
  * @param  array         $parameters        The parameters passed to the method
  * @return fActiveRecord  The record object, to allow for method chaining
  */
 public static function setTimezoneColumn($object, &$values, &$old_values, &$related_records, &$cache, $method_name, $parameters)
 {
     list($action, $subject) = fORM::parseMethod($method_name);
     $column = fGrammar 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP fHTML类代码示例发布时间:2022-05-23
下一篇:
PHP fCore类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap