/Sugar/Util.php

Description

Miscellaneous utility functions used by Sugar.

Provides several utility functions used by the Sugar codebase.

PHP version 5

LICENSE:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Functions
Sugar_Util_EscapeJavascript (line 90)

Performs string-escaping for JavaScript values.

This is the equivalent of running addslashes() and then replacing control characters with their escaped equivalents.

  • return: Formatted result.
string Sugar_Util_EscapeJavascript (mixed $string)
  • mixed $string: String to escape.
Sugar_Util_GetArg (line 48)

Returns an argument from a function parameter list, supporting both position and named parameters and default values.

  • return: Value of parameter if given, or the default value otherwise.
mixed Sugar_Util_GetArg (array $params, string $name, [mixed $default = null])
  • array $params: Function parameter list.
  • string $name: Parameter name.
  • mixed $default: Default value if parameter is not specified.
Sugar_Util_IsVector (line 64)

Checks if an array is a "vector," or an array with only integral indexes starting at zero and incrementally increasing. Used only for nice exporting to JavaScript.

Only really used for Sugar_Util_Json.

  • return: True if array is a vector.
bool Sugar_Util_IsVector (array $array)
  • array $array: Array to check.
Sugar_Util_Json (line 106)

Formats a PHP value in JavaScript format.

We can probably juse use json_encode() instead of this, except json_encode() is PHP 5.2 only.

  • return: Formatted result.
string Sugar_Util_Json (mixed $value)
  • mixed $value: Value to format.
Sugar_Util_SearchForFile (line 182)

Attempt to locate a file in one or more source directories.

  • return: The full path to the file if found, false otherwise.
mixed Sugar_Util_SearchForFile (mixed $haystack, string $needle)
  • mixed $haystack: The directory/directories to search in.
  • string $needle: The file being searched for.
Sugar_Util_ValueToTime (line 160)

Convert a value into a timestamp. This is essentially strtotime(), except that if an integer timestamp is passed in it is returned verbatim, and if the value cannot be parsed, it returns the current timestamp.

  • return: Timestamp.
int Sugar_Util_ValueToTime (mixed $value)
  • mixed $value: Time value to parse.

Documentation generated on Sat, 18 Sep 2010 05:27:03 +0000 by phpDocumentor 1.4.3