Classes:

search
AdvancedSearchForm
ContentControllerSearchExtension
EndsWithFilter
ExactMatchFilter
ExactMatchMultiFilter
FulltextFilter
FulltextSearchable
GreaterThanFilter
LessThanFilter
NegationFilter
PartialMatchFilter
SearchContext
SearchFilter
SearchForm
StartsWithFilter
StartsWithMultiFilter
SubstringFilter
WithinRangeFilter
core
Aggregate
Aggregate_Relationship
ClassInfo
CSSContentParser
Extension
ManifestBuilder
Object
SS_Cache
TokenisedRegularExpression
ValidationResult
YamlFixture
filesystem
Archive
File
Filesystem
FlushGeneratedImagesTask
Folder
Folder_UnusedAssetsField
GD
Image
Image_Cached
TarballArchive
Upload
Upload_Validator
view
ArrayData
Requirements
Requirements_Backend
SSViewer
SSViewer_Cached_PartialParser
SSViewer_FromString
SSViewer_PartialParser
ViewableData
ViewableData_Customised
ViewableData_Debugger
misc
ArrayLib
BBCodeParser
Convert
Cookie
DataDifferencer
Geoip
HTMLCleaner
HTTP
i18n
Profiler
ShortcodeParser
SSHTMLBBCodeParser
SSHTMLBBCodeParser_Filter
SSHTMLBBCodeParser_Filter_Basic
SSHTMLBBCodeParser_Filter_EmailLinks
SSHTMLBBCodeParser_Filter_Extended
SSHTMLBBCodeParser_Filter_Images
SSHTMLBBCodeParser_Filter_Links
SSHTMLBBCodeParser_Filter_Lists
TextParser
Translatable_Transformation
XML
security
Authenticator
BasicAuth
ChangePasswordForm
Group
GroupCsvBulkLoader
LoginAttempt
LoginForm
Member
MemberAuthenticator
MemberCsvBulkLoader
MemberLoginForm
MemberPassword
Member_ChangePasswordEmail
Member_DatetimeOptionsetField
Member_ForgotPasswordEmail
Member_GroupSet
Member_ProfileForm
Member_SignupEmail
Member_Validator
NullSecurityToken
NZGovtPasswordValidator
PasswordEncryptor
PasswordEncryptor_LegacyPHPHash
PasswordEncryptor_MySQLOldPassword
PasswordEncryptor_MySQLPassword
PasswordEncryptor_None
PasswordEncryptor_NotFoundException
PasswordEncryptor_PHPHash
PasswordValidator
Permission
PermissionCheckboxSetField
PermissionCheckboxSetField_Readonly
PermissionRole
PermissionRoleCode
Permission_Group
RandomGenerator
Security
SecurityToken
dev
BuildTask
CliDebugView
Debug
DebugView
DevelopmentAdmin
MigrationTask
MySQLDatabaseConfigurationHelper
PhpUnitWrapper
PhpUnitWrapper_3_4
PhpUnitWrapper_3_5
PhpUnitWrapper_Exception
SapphireREPL
SS_Backtrace
SS_Cli
SS_Log
SS_LogEmailWriter
SS_LogErrorEmailFormatter
SS_LogErrorFileFormatter
SS_LogFileWriter
SS_ZendLog
TaskRunner
model
Boolean
ComponentSet
Currency
DatabaseAdmin
DataObject
DataObjectDecorator
DataObjectLog
DataObjectSet
DataObjectSet_Iterator
Date
DB
DBField
Decimal
Double
Enum
Float
ForeignKey
Hierarchy
HTMLText
HTMLVarchar
Int
Money
MultiEnum
MySQLDatabase
MySQLQuery
Percentage
PrimaryKey
SiteTreeDecorator
SQLMap
SQLMap_Iterator
SQLQuery
SS_Database
SS_Datetime
SS_Query
StringField
Text
Time
Transliterator
Varchar
Versioned
Versioned_Version
Year
cron
CliController
DailyTask
HourlyTask
MonthlyTask
QuarterHourlyTask
ScheduledTask
WeeklyTask
YearlyTask
testing
CliTestReporter
FunctionalTest
InstallerTest
JSTestRunner
PHPUnit_Framework_TestCase
SapphireTest
SapphireTestReporter
SapphireTestSuite
SS_TestListener
TestRunner
TestSession
TestSession_STResponseWrapper
TestViewer
tools
CodeViewer
ModelViewer
ModelViewer_Field
ModelViewer_Model
ModelViewer_Module
ModelViewer_Relation
control
ContentController
ContentNegotiator
Controller
Director
ModelAsController
Page_Controller
RequestHandler
RootURLController
SapphireInfo
Session
SS_HTTPRequest
SS_HTTPResponse
SS_HTTPResponse_Exception
bulkloading
CSVParser
formatters
DataFormatter
FormEncodedDataFormatter
JSONDataFormatter
XMLDataFormatter
forms
DateField_View_JQuery
DatetimeField
FormScaffolder
NestedForm
i18n
DBLocale
i18nTextCollector
Translatable
email
Email
Email_BounceHandler
Email_BounceRecord
Mailer
QueuedEmail
QueuedEmailDispatchTask
TestMailer
tasks
EncryptAllPasswordsTask
i18nTextCollectorTask
MigrateSiteTreeLinkingTask
MigrateTranslatableTask
RemoveOrphanedPagesTask
UpgradeSiteTreePermissionSchemaTask
integration
RestfulService
RestfulService_Response
RSSFeed
RSSFeed_Entry
SapphireSoapServer
SS_HTMLValue
VersionedRestfulServer
fields-formattedinput
MoneyField
api
RestfulServer
RestfulServer_Item
RestfulServer_List
SOAPModelAccess
parsers
SQLFormatter
validation
ValidationException
widgets
Widget
WidgetArea
Widget_Controller
Widget_TreeDropdownField

Files:

Show/hide

DatabaseConfigurationHelper.php
DateField.php
Page.php
Translatable.php
subpackage api
RestfulServer.php
SOAPModelAccess.php
subpackage bulkloading
CSVParser.php
subpackage control
ContentController.php
ContentNegotiator.php
Controller.php
Director.php
HTTPRequest.php
HTTPResponse.php
ModelAsController.php
NestedController.php
RequestHandler.php
RootURLController.php
SapphireInfo.php
Session.php
subpackage core
Aggregate.php
Cache.php
ClassInfo.php
cli-script.php
ConfigureFromEnv.php
CSSContentParser.php
Extension.php
ManifestBuilder.php
Object.php
TokenisedRegularExpression.php
ValidationResult.php
YamlFixture.php
subpackage cron
CliController.php
DailyTask.php
HourlyTask.php
MonthlyTask.php
QuarterHourlyTask.php
ScheduledTask.php
WeeklyTask.php
YearlyTask.php
subpackage dev
Backtrace.php
BuildTask.php
Cli.php
CliDebugView.php
Debug.php
DebugView.php
DevelopmentAdmin.php
Log.php
LogEmailWriter.php
LogErrorEmailFormatter.php
LogErrorFileFormatter.php
LogFileWriter.php
MigrationTask.php
MySQLDatabaseConfigurationHelper.php
PhpUnitWrapper_3_4.php
PhpUnitWrapper_3_5.php
SapphireREPL.php
TaskRunner.php
ZendLog.php
subpackage email
Email.php
Mailer.php
QueuedEmail.php
QueuedEmailDispatchTask.php
TestMailer.php
subpackage fields-formattedinput
MoneyField.php
subpackage filesystem
Archive.php
File.php
Filesystem.php
FlushGeneratedImagesTask.php
Folder.php
GD.php
Image.php
TarballArchive.php
Upload.php
subpackage formatters
DataFormatter.php
FormEncodedDataFormatter.php
JSONDataFormatter.php
XMLDataFormatter.php
subpackage forms
DatetimeField.php
FormScaffolder.php
NestedForm.php
subpackage i18n
DBLocale.php
i18nEntityProvider.php
i18nTextCollector.php
subpackage integration
HTMLValue.php
RestfulService.php
RSSFeed.php
SapphireSoapServer.php
VersionedRestfulServer.php
subpackage misc
ArrayLib.php
Basic.php
BBCodeParser.php
Convert.php
Cookie.php
DataDifferencer.php
EmailLinks.php
Extended.php
Filter.php
Geoip.php
HTMLBBCodeParser.php
HTMLCleaner.php
HTTP.php
i18n.php
Images.php
Links.php
Lists.php
Profiler.php
ShortcodeParser.php
TextParser.php
XML.php
subpackage model
Boolean.php
ComponentSet.php
CompositeDBField.php
Currency.php
CurrentPageIdentifier.php
Database.php
DatabaseAdmin.php
DataObject.php
DataObjectDecorator.php
DataObjectInterface.php
DataObjectLog.php
DataObjectSet.php
Date.php
Datetime.php
DB.php
DBField.php
Decimal.php
Double.php
Enum.php
Float.php
ForeignKey.php
Hierarchy.php
HTMLText.php
HTMLVarchar.php
Int.php
Money.php
MultiEnum.php
MySQLDatabase.php
Percentage.php
PrimaryKey.php
SiteTreeDecorator.php
SQLMap.php
SQLQuery.php
StringField.php
Text.php
Time.php
Transliterator.php
Varchar.php
Versioned.php
Year.php
subpackage parsers
SQLFormatter.php
subpackage search
AdvancedSearchForm.php
ContentControllerSearchExtension.php
EndsWithFilter.php
ExactMatchFilter.php
ExactMatchMultiFilter.php
FulltextFilter.php
FulltextSearchable.php
GreaterThanFilter.php
LessThanFilter.php
NegationFilter.php
PartialMatchFilter.php
SearchContext.php
SearchFilter.php
SearchForm.php
StartsWithFilter.php
StartsWithMultiFilter.php
SubstringFilter.php
WithinRangeFilter.php
subpackage security
Authenticator.php
BasicAuth.php
ChangePasswordForm.php
Group.php
GroupCsvBulkLoader.php
LoginAttempt.php
LoginForm.php
Member.php
MemberAuthenticator.php
MemberCsvBulkLoader.php
MemberLoginForm.php
MemberPassword.php
NZGovtPasswordValidator.php
PasswordEncryptor.php
PasswordValidator.php
Permission.php
PermissionCheckboxSetField.php
PermissionProvider.php
PermissionRole.php
PermissionRoleCode.php
RandomGenerator.php
Security.php
SecurityToken.php
subpackage tasks
EncryptAllPasswordsTask.php
i18nTextCollectorTask.php
MigrateSiteTreeLinkingTask.php
MigrateTranslatableTask.php
RemoveOrphanedPagesTask.php
UpgradeSiteTreePermissionSchemaTask.php
subpackage testing
CliTestReporter.php
FunctionalTest.php
InstallerTest.php
JSTestRunner.php
PhpUnitWrapper.php
SapphireTest.php
SapphireTestReporter.php
SapphireTestSuite.php
TestListener.php
TestOnly.php
TestRunner.php
TestSession.php
TestViewer.php
subpackage tools
CodeViewer.php
ModelViewer.php
subpackage validation
ValidationException.php
subpackage view
ArrayData.php
Requirements.php
SSViewer.php
ViewableData.php
subpackage widgets
Widget.php
WidgetArea.php

Class: Convert

Source Location: /sapphire/core/Convert.php

Inheritance:

Summary: Library of conversion functions, implemented as static methods.

Methods

public static array2json ( $val ) Convert an array into a JSON encoded string.
public static html2raw ( $data, [$preserveLinks = false], [$wordWrap = 60], [$config = null] ) Simple conversion of HTML to plaintext.
public static json2array ( $val ) Convert a JSON string into an array.
public static json2obj ( $val ) Convert a JSON encoded string into an object.
public static linkIfMatch ( $string ) Create a link if the string is a valid URL
public static raw2att ( $val ) Convert a value to be suitable for an XML attribute.
public static raw2htmlatt ( $val ) Convert a value to be suitable for an HTML attribute.
public static raw2js ( $val ) Ensure that text is properly escaped for Javascript.
public static raw2json ( $val ) Uses the PHP 5.2 native json_encode function if available, otherwise falls back to the Services_JSON class.
public static raw2mailto ( $data ) There are no real specifications on correctly encoding mailto-links, but this seems to be compatible with most of the user-agents.
public static raw2sql ( $val )
public static raw2xml ( $val ) Ensure that text is properly escaped for XML.
protected static recursiveXMLToArray ( $xml ) Function recursively run from Convert::xml2array()
public static xml2array ( $val )
public static xml2raw ( $val ) Convert XML to raw text.

Variables

(none)

Constants

(none)

Class Details

Library of conversion functions, implemented as static methods.

The methods are all of the form (format)2(format), where the format is one of

raw: A UTF8 string attr: A UTF8 string suitable for inclusion in an HTML attribute js: A UTF8 string suitable for inclusion in a double-quoted javascript string.

array: A PHP associative array json: JavaScript object notation

html: HTML source suitable for use in a page or email text: Plain-text content, suitable for display to a user as-is, or insertion in a plaintext email.

Objects of type ViewableData can have an "escaping type", which determines if they are automatically escaped before output by SSViewer.

[ Top ]


Class Methods

public static array2json

static string array2json( array $val)

[line 152]

Convert an array into a JSON encoded string.

Parameters:

  • array $val - Array to convert

[ Top ]

public static html2raw

static void html2raw( $data $data, [$preserveLinks $preserveLinks = false], [$wordwrap $wordWrap = 60], [ $config = null])

[line 248]

Simple conversion of HTML to plaintext.

Parameters:

  • $data $data - string
  • $preserveLinks $preserveLinks - boolean
  • $wordwrap $wordWrap - array
  • $config -

[ Top ]

public static json2array

static array|boolean json2array( string $val)

[line 185]

Convert a JSON string into an array.

Parameters:

  • string $val - JSON string to convert

[ Top ]

public static json2obj

static mixed json2obj( string $val)

[line 172]

Convert a JSON encoded string into an object.

Parameters:

  • string $val -

[ Top ]

public static linkIfMatch

static A linkIfMatch( string $string)

[line 234]

Create a link if the string is a valid URL

  • @return link to the URL if string is a URL

Parameters:

  • string $string - The string to linkify

[ Top ]

public static raw2att

static array|string raw2att( array|string $val)

[line 31]

Convert a value to be suitable for an XML attribute.

Parameters:

  • array|string $val - String to escape, or array of strings

[ Top ]

public static raw2htmlatt

static array|string raw2htmlatt( array|string $val)

[line 51]

Convert a value to be suitable for an HTML attribute.

This is useful for converting human readable values into a value suitable for an ID or NAME attribute.

Parameters:

  • array|string $val - String to escape, or array of strings

[ Top ]

public static raw2js

static array|string raw2js( array|string $val)

[line 84]

Ensure that text is properly escaped for Javascript.

Parameters:

  • array|string $val - String to escape, or array of strings

[ Top ]

public static raw2json

static string raw2json( mixed $val)

[line 104]

Uses the PHP 5.2 native json_encode function if available, otherwise falls back to the Services_JSON class.

Parameters:

  • mixed $val -

[ Top ]

public static raw2mailto

static string raw2mailto( $data $data)

[line 331]

There are no real specifications on correctly encoding mailto-links, but this seems to be compatible with most of the user-agents.

Does nearly the same as rawurlencode(). Please only encode the values, not the whole url, e.g. "mailto:test@test.com?subject=" . Convert::raw2mailto($subject)

Parameters:

  • $data $data - string

[ Top ]

public static raw2sql

static void raw2sql( $val)

[line 114]

Parameters:

  • $val -

[ Top ]

public static raw2xml

static array|string raw2xml( array|string $val)

[line 69]

Ensure that text is properly escaped for XML.

  • @see dt-escape

Parameters:

  • array|string $val - String to escape, or array of strings

[ Top ]

protected static recursiveXMLToArray

static void recursiveXMLToArray( $xml)

[line 209]

Function recursively run from Convert::xml2array()

Parameters:

  • $xml -

[ Top ]

public static xml2array

static void xml2array( $val)

[line 200]

Parameters:

  • $val -

[ Top ]

public static xml2raw

static void xml2raw( $val)

[line 128]

Convert XML to raw text.

  • @todo Currently &#xxx; entries are stripped; they should be converted
  • @uses Convert::html2raw()

Parameters:

  • $val -

[ Top ]

Comments

Comment policy: Please use comments for tips and corrections about the described functionality. Comments are moderated, we reserve the right to remove comments that are inappropriate or are no longer relevant.
Use the Silverstripe Forum to ask questions.

blog comments powered by Disqus

Documentation generated on Thu, 17 May 2012 03:56:50 +1200 by phpDocumentor 1.4.3