本文整理汇总了PHP中Object::create_from_string方法的典型用法代码示例。如果您正苦于以下问题:PHP Object::create_from_string方法的具体用法?PHP Object::create_from_string怎么用?PHP Object::create_from_string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Object
的用法示例。
在下文中一共展示了Object::create_from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: obj
/**
* @param string $fieldName
* @param array|null|void $arguments
* @param bool|void $forceReturnedObject
* @param bool|void $cache
* @param null|void $cacheName
* @return mixed|null
*/
public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null)
{
// HACK: Don't call the deprecated FormField::Name() method
$methodIsAllowed = true;
if ($this instanceof \FormField && $fieldName == 'Name') {
$methodIsAllowed = false;
}
if ($methodIsAllowed && $this->hasMethod($fieldName)) {
$value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->{$fieldName}();
} else {
$value = $this->{$fieldName};
}
if (!$value instanceof \ViewableData && ($this->castingClass($fieldName) || $forceReturnedObject)) {
if (!($castConstructor = $this->castingHelper($fieldName))) {
$castConstructor = $this->stat('default_cast');
}
$valueObject = \Object::create_from_string($castConstructor, $fieldName);
$valueObject->setValue($value, $this);
$value = $valueObject;
}
if (!$value instanceof \ViewableData && $forceReturnedObject) {
$default = \Config::inst()->get('ViewableData', 'default_cast', \Config::FIRST_SET);
$castedValue = new $default($fieldName);
$castedValue->setValue($value);
$value = $castedValue;
}
return $value;
}
示例2: getTagNameForDBField
/**
* @param string $dbFieldType
* @return string
*/
public function getTagNameForDBField($dbFieldType)
{
// some fields in 3rd-party modules require a name...
$fieldObj = Object::create_from_string($dbFieldType, 'DummyName');
foreach (self::$dbfield_tagnames as $dbClass => $tagName) {
if (class_exists($dbClass)) {
$obj = Object::create_from_string($dbClass);
if ($fieldObj instanceof $obj) {
return $tagName;
}
}
}
return 'string';
}
示例3: allMethodNames
/**
* @todo this is not really a readable code.
* @todo Clean this to make it more readable.
* @param $bool
* @return array
*/
public function allMethodNames($bool)
{
$methods = array();
$classes = Config::inst()->get('EncryptDataObjectFieldsExtension', 'EncryptedDataObjects');
if (in_array($this->owner->ClassName, $classes)) {
$fields = Config::inst()->get($this->owner->ClassName, 'db', Config::UNINHERITED);
foreach ($fields as $fieldName => $fieldType) {
$reflector = Object::create_from_string($fieldType, '')->is_encrypted;
if ($reflector === true) {
$callFunction = strtolower('get' . $fieldName);
self::$db_mapping[$callFunction] = array($fieldName, $fieldType);
$methods[] = strtolower('get' . $fieldName);
}
}
}
return $methods;
}
示例4: obj
/**
* Get the value of a field on this object, automatically inserting the value into any available casting objects
* that have been specified.
*
* @param string $fieldName
* @param array $arguments
* @param bool $forceReturnedObject if TRUE, the value will ALWAYS be casted to an object before being returned,
* even if there is no explicit casting information
* @param string $cacheName a custom cache name
*/
public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null)
{
if (!$cacheName) {
$cacheName = $arguments ? $fieldName . implode(',', $arguments) : $fieldName;
}
if (!isset($this->objCache[$cacheName])) {
// HACK: Don't call the deprecated FormField::Name() method
$methodIsAllowed = true;
if ($this instanceof FormField && $fieldName == 'Name') {
$methodIsAllowed = false;
}
if ($methodIsAllowed && $this->hasMethod($fieldName)) {
$value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->{$fieldName}();
} else {
$value = $this->{$fieldName};
}
if (!is_object($value) && ($this->castingClass($fieldName) || $forceReturnedObject)) {
if (!($castConstructor = $this->castingHelper($fieldName))) {
$castConstructor = $this->config()->default_cast;
}
$valueObject = Object::create_from_string($castConstructor, $fieldName);
$valueObject->setValue($value, $this);
$value = $valueObject;
}
if ($cache) {
$this->objCache[$cacheName] = $value;
}
} else {
$value = $this->objCache[$cacheName];
}
if (!is_object($value) && $forceReturnedObject) {
$default = $this->config()->default_cast;
$castedValue = new $default($fieldName);
$castedValue->setValue($value);
$value = $castedValue;
}
return $value;
}
示例5: obj
/**
* Get the value of a field on this object, automatically inserting the value into any available casting objects
* that have been specified.
*
* @param string $fieldName
* @param array $arguments
* @param bool $forceReturnedObject if TRUE, the value will ALWAYS be casted to an object before being returned,
* even if there is no explicit casting information
* @param string $cacheName a custom cache name
*/
public function obj($fieldName, $arguments = null, $forceReturnedObject = true, $cache = false, $cacheName = null)
{
if (isset($_REQUEST['debug_profile'])) {
Profiler::mark("obj.{$fieldName}", "on a {$this->class} object");
}
if (!$cacheName) {
$cacheName = $arguments ? $fieldName . implode(',', $arguments) : $fieldName;
}
if (!isset($this->objCache[$cacheName])) {
// HACK: Don't call the deprecated FormField::Name() method
$methodIsAllowed = true;
if ($this instanceof FormField && $fieldName == 'Name') {
$methodIsAllowed = false;
}
if ($methodIsAllowed && $this->hasMethod($fieldName)) {
$value = $arguments ? call_user_func_array(array($this, $fieldName), $arguments) : $this->{$fieldName}();
} else {
$value = $this->{$fieldName};
}
if (!is_object($value) && ($this->castingClass($fieldName) || $forceReturnedObject)) {
if (!($castConstructor = $this->castingHelper($fieldName))) {
$castConstructor = $this->stat('default_cast');
}
$valueObject = Object::create_from_string($castConstructor, $fieldName);
$valueObject->setValue($value, $this->hasMethod('toMap') ? $this->toMap() : null);
$value = $valueObject;
}
if ($cache) {
$this->objCache[$cacheName] = $value;
}
} else {
$value = $this->objCache[$cacheName];
}
if (isset($_REQUEST['debug_profile'])) {
Profiler::unmark("obj.{$fieldName}", "on a {$this->class} object");
}
if (!is_object($value) && $forceReturnedObject) {
$default = Config::inst()->get('ViewableData', 'default_cast', Config::FIRST_SET);
$value = new $default($fieldName);
}
return $value;
}
示例6: getField
public function getField($field)
{
// If we already have an object in $this->record, then we should just return that
if (isset($this->record[$field]) && is_object($this->record[$field])) {
return $this->record[$field];
}
// Do we have a field that needs to be lazy loaded?
if (isset($this->record[$field . '_Lazy'])) {
$tableClass = $this->record[$field . '_Lazy'];
$this->loadLazyFields($tableClass);
}
// Otherwise, we need to determine if this is a complex field
if (self::is_composite_field($this->class, $field)) {
$helper = $this->castingHelper($field);
$fieldObj = Object::create_from_string($helper, $field);
$compositeFields = $fieldObj->compositeDatabaseFields();
foreach ($compositeFields as $compositeName => $compositeType) {
if (isset($this->record[$field . $compositeName . '_Lazy'])) {
$tableClass = $this->record[$field . $compositeName . '_Lazy'];
$this->loadLazyFields($tableClass);
}
}
// write value only if either the field value exists,
// or a valid record has been loaded from the database
$value = isset($this->record[$field]) ? $this->record[$field] : null;
if ($value || $this->exists()) {
$fieldObj->setValue($value, $this->record, false);
}
$this->record[$field] = $fieldObj;
return $this->record[$field];
}
return isset($this->record[$field]) ? $this->record[$field] : null;
}
示例7: selectColumnsFromTable
/**
* Update the SELECT clause of the query with the columns from the given table
*/
protected function selectColumnsFromTable(SQLQuery &$query, $tableClass, $columns = null)
{
// Add SQL for multi-value fields
$databaseFields = DataObject::database_fields($tableClass);
$compositeFields = DataObject::composite_fields($tableClass, false);
if ($databaseFields) {
foreach ($databaseFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns)) && !isset($compositeFields[$k])) {
// Update $collidingFields if necessary
if ($expressionForField = $query->expressionForField($k)) {
if (!isset($this->collidingFields[$k])) {
$this->collidingFields[$k] = array($expressionForField);
}
$this->collidingFields[$k][] = "\"{$tableClass}\".\"{$k}\"";
} else {
$query->selectField("\"{$tableClass}\".\"{$k}\"", $k);
}
}
}
}
if ($compositeFields) {
foreach ($compositeFields as $k => $v) {
if ((is_null($columns) || in_array($k, $columns)) && $v) {
$dbO = Object::create_from_string($v, $k);
$dbO->addToQuery($query);
}
}
}
}
示例8: requireTable
/**
* Generate the following table in the database, modifying whatever already exists
* as necessary.
*
* @todo Change detection for CREATE TABLE $options other than "Engine"
*
* @param string $table The name of the table
* @param array $fieldSchema A list of the fields to create, in the same form as DataObject::$db
* @param array $indexSchema A list of indexes to create. See {@link requireIndex()}
* The values of the array can be one of:
* - true: Create a single column index on the field named the same as the index.
* - array('fields' => array('A','B','C'), 'type' => 'index/unique/fulltext'): This gives you full
* control over the index.
* @param boolean $hasAutoIncPK A flag indicating that the primary key on this table is an autoincrement type
* @param string $options SQL statement to append to the CREATE TABLE call.
* @param array $extensions List of extensions
*/
public function requireTable($table, $fieldSchema = null, $indexSchema = null, $hasAutoIncPK = true, $options = array(), $extensions = false)
{
if (!isset($this->tableList[strtolower($table)])) {
$this->transCreateTable($table, $options, $extensions);
$this->alterationMessage("Table {$table}: created", "created");
} else {
if (Config::inst()->get('DBSchemaManager', 'check_and_repair_on_build')) {
$this->checkAndRepairTable($table, $options);
}
// Check if options changed
$tableOptionsChanged = false;
if (isset($options[get_class($this)]) || true) {
if (isset($options[get_class($this)])) {
if (preg_match('/ENGINE=([^\\s]*)/', $options[get_class($this)], $alteredEngineMatches)) {
$alteredEngine = $alteredEngineMatches[1];
$tableStatus = $this->query(sprintf('SHOW TABLE STATUS LIKE \'%s\'', $table))->first();
$tableOptionsChanged = $tableStatus['Engine'] != $alteredEngine;
}
}
}
if ($tableOptionsChanged || $extensions && $this->database->supportsExtensions($extensions)) {
$this->transAlterTable($table, $options, $extensions);
}
}
//DB ABSTRACTION: we need to convert this to a db-specific version:
$this->requireField($table, 'ID', $this->IdColumn(false, $hasAutoIncPK));
// Create custom fields
if ($fieldSchema) {
foreach ($fieldSchema as $fieldName => $fieldSpec) {
//Is this an array field?
$arrayValue = '';
if (strpos($fieldSpec, '[') !== false) {
//If so, remove it and store that info separately
$pos = strpos($fieldSpec, '[');
$arrayValue = substr($fieldSpec, $pos);
$fieldSpec = substr($fieldSpec, 0, $pos);
}
$fieldObj = Object::create_from_string($fieldSpec, $fieldName);
$fieldObj->arrayValue = $arrayValue;
$fieldObj->setTable($table);
$fieldObj->requireField();
}
}
// Create custom indexes
if ($indexSchema) {
foreach ($indexSchema as $indexName => $indexDetails) {
$this->requireIndex($table, $indexName, $indexDetails);
}
}
}
示例9: obj
/**
* Get the value of a field on this object, automatically inserting the value into any available casting objects
* that have been specified.
*
* @param string $fieldName
* @param array $arguments
* @param bool $cache Cache this object
* @param string $cacheName a custom cache name
* @return Object|DBField
*/
public function obj($fieldName, $arguments = [], $cache = false, $cacheName = null)
{
if (!$cacheName && $cache) {
$cacheName = $this->objCacheName($fieldName, $arguments);
}
// Check pre-cached value
$value = $cache ? $this->objCacheGet($cacheName) : null;
if ($value !== null) {
return $value;
}
// Load value from record
if ($this->hasMethod($fieldName)) {
$value = call_user_func_array(array($this, $fieldName), $arguments ?: []);
} else {
$value = $this->{$fieldName};
}
// Cast object
if (!is_object($value)) {
// Force cast
$castingHelper = $this->castingHelper($fieldName);
$valueObject = Object::create_from_string($castingHelper, $fieldName);
$valueObject->setValue($value, $this);
$value = $valueObject;
}
// Record in cache
if ($cache) {
$this->objCacheSet($cacheName, $value);
}
return $value;
}
示例10: selectAllFromTable
/**
* Update the SELECT clause of the query with the columns from the given table
*/
protected function selectAllFromTable(SQLQuery &$query, $tableClass) {
// Add SQL for multi-value fields
$databaseFields = DataObject::database_fields($tableClass);
$compositeFields = DataObject::composite_fields($tableClass, false);
if($databaseFields) foreach($databaseFields as $k => $v) {
if(!isset($compositeFields[$k])) {
// Update $collidingFields if necessary
if(isset($query->select[$k])) {
if(!isset($this->collidingFields[$k])) $this->collidingFields[$k] = array($query->select[$k]);
$this->collidingFields[$k][] = "\"$tableClass\".\"$k\"";
} else {
$query->select[$k] = "\"$tableClass\".\"$k\"";
}
}
}
if($compositeFields) foreach($compositeFields as $k => $v) {
if($v) {
$dbO = Object::create_from_string($v, $k);
$dbO->addToQuery($query);
}
}
}
示例11: getFields
/**
* Gets the field list for a record.
*
* @param GridField $grid
* @param DataObjectInterface $record
* @return FieldList
*/
public function getFields(GridField $grid, DataObjectInterface $record)
{
$cols = $this->getDisplayFields($grid);
$fields = new FieldList();
$list = $grid->getList();
$class = $list ? $list->dataClass() : null;
foreach ($cols as $col => $info) {
$field = null;
if ($info instanceof Closure) {
$field = call_user_func($info, $record, $col, $grid);
} elseif (is_array($info)) {
if (isset($info['callback'])) {
$field = call_user_func($info['callback'], $record, $col, $grid);
} elseif (isset($info['field'])) {
if ($info['field'] == 'LiteralField') {
$field = new $info['field']($col, null);
} else {
$field = new $info['field']($col);
}
}
if (!$field instanceof FormField) {
throw new Exception(sprintf('The field for column "%s" is not a valid form field', $col));
}
}
if (!$field && $list instanceof ManyManyList) {
$extra = $list->getExtraFields();
if ($extra && array_key_exists($col, $extra)) {
$field = Object::create_from_string($extra[$col], $col)->scaffoldFormField();
}
}
if (!$field) {
if ($class && ($obj = singleton($class)->dbObject($col))) {
$field = $obj->scaffoldFormField();
} else {
$field = new ReadonlyField($col);
}
}
if (!$field instanceof FormField) {
throw new Exception(sprintf('Invalid form field instance for column "%s"', $col));
}
$fields->push($field);
}
return $fields;
}
示例12: generateORMDBProperties
/**
* Generate the $db property values.
*
* @param DataObject|DataExtension $className
* @return string
*/
protected function generateORMDBProperties($className)
{
if ($fields = Config::inst()->get($className, 'db', Config::UNINHERITED)) {
foreach ($fields as $fieldName => $dataObjectName) {
$prop = 'string';
$fieldObj = Object::create_from_string($dataObjectName, $fieldName);
if (is_a($fieldObj, 'Int')) {
$prop = 'int';
} elseif (is_a($fieldObj, 'Boolean')) {
$prop = 'boolean';
} elseif (is_a($fieldObj, 'Float') || is_a($fieldObj, 'Decimal')) {
$prop = 'float';
}
$this->resultString .= " * @property {$prop} {$fieldName}\n";
}
}
return true;
}
示例13: testCreate
public function testCreate()
{
/** @var DBHTMLText $field */
$field = Object::create_from_string("HTMLFragment(['whitelist' => 'link'])", 'MyField');
$this->assertEquals(['link'], $field->getWhitelist());
$field = Object::create_from_string("HTMLFragment(['whitelist' => 'link,a'])", 'MyField');
$this->assertEquals(['link', 'a'], $field->getWhitelist());
$field = Object::create_from_string("HTMLFragment(['whitelist' => ['link', 'a']])", 'MyField');
$this->assertEquals(['link', 'a'], $field->getWhitelist());
$field = Object::create_from_string("HTMLFragment", 'MyField');
$this->assertEmpty($field->getWhitelist());
// Test shortcodes
$field = Object::create_from_string("HTMLFragment(['shortcodes' => true])", 'MyField');
$this->assertEquals(true, $field->getProcessShortcodes());
$field = Object::create_from_string("HTMLFragment(['shortcodes' => false])", 'MyField');
$this->assertEquals(false, $field->getProcessShortcodes());
// Mix options
$field = Object::create_from_string("HTMLFragment(['shortcodes' => true, 'whitelist' => ['a'])", 'MyField');
$this->assertEquals(true, $field->getProcessShortcodes());
$this->assertEquals(['a'], $field->getWhitelist());
}
示例14: Backend
public function Backend()
{
return Object::create_from_string("SnowcakeDeploymentBackend");
}
示例15: checkInstances
/**
* Get instances of all the environment checks.
*
* @return array
*/
protected function checkInstances()
{
$output = array();
foreach ($this->checks as $check) {
list($checkClass, $checkTitle) = $check;
if (is_string($checkClass)) {
$checkInst = Object::create_from_string($checkClass);
if ($checkInst instanceof EnvironmentCheck) {
$output[] = array($checkInst, $checkTitle);
} else {
throw new InvalidArgumentException("Bad EnvironmentCheck: '{$checkClass}' - the named class doesn't implement EnvironmentCheck");
}
} else {
if ($checkClass instanceof EnvironmentCheck) {
$output[] = array($checkClass, $checkTitle);
} else {
throw new InvalidArgumentException("Bad EnvironmentCheck: " . var_export($check, true));
}
}
}
return $output;
}