idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
56,900
protected function setNumberMinMax ( $ options ) { if ( isset ( $ options [ 'minmax' ] ) ) { if ( $ options [ 'minmax' ] == false ) { unset ( $ options [ 'minmax' ] ) ; return $ options ; } return $ this -> setQuickNumberMinMax ( $ options ) ; } $ min = array_get ( $ options , 'min' , 0 ) ; $ max = array_get ( $ options , 'max' , 10 ) ; return array_merge ( $ options , compact ( 'min' , 'max' ) ) ; }
Set the number min max on the attributes .
56,901
public function setTargetUri ( $ targetUri ) { if ( null === $ targetUri ) { $ targetUri = '' ; } $ this -> _targetUri = ( string ) $ targetUri ; return $ this ; }
Set target Uri
56,902
public function setReplyMethod ( $ methodName ) { if ( ! preg_match ( '#^[/?]#' , $ methodName ) ) { $ this -> _targetUri = rtrim ( $ this -> _targetUri , '/' ) . '/' ; } $ this -> _targetUri = $ this -> _targetUri . $ methodName ; return $ this ; }
Set reply method
56,903
public static function reflectClass ( $ class , $ argv = false , $ namespace = '' ) { if ( is_object ( $ class ) ) { $ reflection = new ReflectionObject ( $ class ) ; } elseif ( class_exists ( $ class ) ) { $ reflection = new ReflectionClass ( $ class ) ; } else { require_once 'Zend/Server/Reflection/Exception.php' ; throw new Zend_Server_Reflection_Exception ( 'Invalid class or object passed to attachClass()' ) ; } if ( $ argv && ! is_array ( $ argv ) ) { require_once 'Zend/Server/Reflection/Exception.php' ; throw new Zend_Server_Reflection_Exception ( 'Invalid argv argument passed to reflectClass' ) ; } return new Zend_Server_Reflection_Class ( $ reflection , $ namespace , $ argv ) ; }
Perform class reflection to create dispatch signatures
56,904
public static function reflectFunction ( $ function , $ argv = false , $ namespace = '' ) { if ( ! is_string ( $ function ) || ! function_exists ( $ function ) ) { require_once 'Zend/Server/Reflection/Exception.php' ; throw new Zend_Server_Reflection_Exception ( 'Invalid function "' . $ function . '" passed to reflectFunction' ) ; } if ( $ argv && ! is_array ( $ argv ) ) { require_once 'Zend/Server/Reflection/Exception.php' ; throw new Zend_Server_Reflection_Exception ( 'Invalid argv argument passed to reflectClass' ) ; } return new Zend_Server_Reflection_Function ( new ReflectionFunction ( $ function ) , $ namespace , $ argv ) ; }
Perform function reflection to create dispatch signatures
56,905
public static function getIconTcaSelectItems ( int $ id = 1 , int $ typeNum = 0 ) : array { $ icons = [ [ '---' , '' ] ] ; foreach ( self :: getIcons ( $ id , $ typeNum ) as $ iconBasename => $ iconName ) { $ icons [ ] = [ $ iconName , $ iconBasename ] ; } return $ icons ; }
Return all icons as TCA select items
56,906
public static function getIcons ( int $ id = 1 , int $ typeNum = 0 ) : array { $ icons = [ ] ; $ typoScriptKey = 'plugin.tx_twcomponentlibrary.settings.iconDirectories' ; $ iconDirectories = TypoScriptUtility :: extractTypoScriptKeyForPidAndType ( $ id , $ typeNum , $ typoScriptKey ) ; $ iconDirectories = GeneralUtility :: trimExplode ( ',' , $ iconDirectories [ 'iconDirectories' ] , true ) ; foreach ( $ iconDirectories as $ iconDirectory ) { $ iconsBaseDirectory = GeneralUtility :: getFileAbsFileName ( $ iconDirectory ) ; foreach ( glob ( $ iconsBaseDirectory . DIRECTORY_SEPARATOR . '*.svg' ) as $ iconFile ) { $ iconBasename = basename ( $ iconFile ) ; $ iconName = trim ( preg_replace ( '/([A-Z])/' , " $1" , pathinfo ( $ iconBasename , PATHINFO_FILENAME ) ) ) ; $ icons [ $ iconBasename ] = $ iconName ; } } asort ( $ icons ) ; return $ icons ; }
Return all icon assets
56,907
public function generateId ( ) { return sprintf ( '%08X-%04X-%04X-%02X%02X-%012X' , mt_rand ( ) , mt_rand ( 0 , 65535 ) , bindec ( substr_replace ( sprintf ( '%016b' , mt_rand ( 0 , 65535 ) ) , '0100' , 11 , 4 ) ) , bindec ( substr_replace ( sprintf ( '%08b' , mt_rand ( 0 , 255 ) ) , '01' , 5 , 2 ) ) , mt_rand ( 0 , 255 ) , mt_rand ( ) ) ; }
generate a unique id
56,908
public function classNameForEvent ( $ event ) : string { if ( ! isset ( $ this -> eventClasses [ $ event ] ) ) { throw new \ InvalidArgumentException ( "Could not find a class for the event {$event}." ) ; } return $ this -> eventClasses [ $ event ] ; }
retrieve the fully qualified class name for an event name
56,909
public function setType ( $ type ) { if ( ! in_array ( $ type , $ this -> _types ) ) { require_once 'Zend/Server/Exception.php' ; throw new Zend_Server_Exception ( 'Invalid method callback type passed to ' . __CLASS__ . '::' . __METHOD__ ) ; } $ this -> _type = $ type ; return $ this ; }
Set callback type
56,910
public function toArray ( ) { $ type = $ this -> getType ( ) ; $ array = array ( 'type' => $ type , ) ; if ( 'function' == $ type ) { $ array [ 'function' ] = $ this -> getFunction ( ) ; } else { $ array [ 'class' ] = $ this -> getClass ( ) ; $ array [ 'method' ] = $ this -> getMethod ( ) ; } return $ array ; }
Cast callback to array
56,911
public function introspect ( $ serviceClass , $ options = array ( ) ) { $ this -> _options = $ options ; if ( strpbrk ( $ serviceClass , '\\/<>' ) ) { return $ this -> _returnError ( 'Invalid service name' ) ; } $ serviceClass = str_replace ( '.' , '_' , $ serviceClass ) ; if ( ! class_exists ( $ serviceClass ) ) { require_once 'Zend/Loader.php' ; Zend_Loader :: loadClass ( $ serviceClass , $ this -> _getServicePath ( ) ) ; } $ serv = $ this -> _xml -> createElement ( 'service-description' ) ; $ serv -> setAttribute ( 'xmlns' , 'http://ns.adobe.com/flex/service-description/2008' ) ; $ this -> _types = $ this -> _xml -> createElement ( 'types' ) ; $ this -> _ops = $ this -> _xml -> createElement ( 'operations' ) ; $ r = Zend_Server_Reflection :: reflectClass ( $ serviceClass ) ; $ this -> _addService ( $ r , $ this -> _ops ) ; $ serv -> appendChild ( $ this -> _types ) ; $ serv -> appendChild ( $ this -> _ops ) ; $ this -> _xml -> appendChild ( $ serv ) ; return $ this -> _xml -> saveXML ( ) ; }
Create XML definition on an AMF service class
56,912
protected function _addClassAttributes ( $ typename , DOMElement $ typexml ) { if ( ! class_exists ( $ typename , false ) ) { return ; } $ rc = new Zend_Reflection_Class ( $ typename ) ; foreach ( $ rc -> getProperties ( ) as $ prop ) { if ( ! $ prop -> isPublic ( ) ) { continue ; } $ propxml = $ this -> _xml -> createElement ( 'property' ) ; $ propxml -> setAttribute ( 'name' , $ prop -> getName ( ) ) ; $ type = $ this -> _registerType ( $ this -> _getPropertyType ( $ prop ) ) ; $ propxml -> setAttribute ( 'type' , $ type ) ; $ typexml -> appendChild ( $ propxml ) ; } }
Generate map of public class attributes
56,913
protected function _addService ( Zend_Server_Reflection_Class $ refclass , DOMElement $ target ) { foreach ( $ refclass -> getMethods ( ) as $ method ) { if ( ! $ method -> isPublic ( ) || $ method -> isConstructor ( ) || ( '__' == substr ( $ method -> name , 0 , 2 ) ) ) { continue ; } foreach ( $ method -> getPrototypes ( ) as $ proto ) { $ op = $ this -> _xml -> createElement ( 'operation' ) ; $ op -> setAttribute ( 'name' , $ method -> getName ( ) ) ; $ rettype = $ this -> _registerType ( $ proto -> getReturnType ( ) ) ; $ op -> setAttribute ( 'returnType' , $ rettype ) ; foreach ( $ proto -> getParameters ( ) as $ param ) { $ arg = $ this -> _xml -> createElement ( 'argument' ) ; $ arg -> setAttribute ( 'name' , $ param -> getName ( ) ) ; $ type = $ param -> getType ( ) ; if ( $ type == 'mixed' && ( $ pclass = $ param -> getClass ( ) ) ) { $ type = $ pclass -> getName ( ) ; } $ ptype = $ this -> _registerType ( $ type ) ; $ arg -> setAttribute ( 'type' , $ ptype ) ; if ( $ param -> isDefaultValueAvailable ( ) ) { $ arg -> setAttribute ( 'defaultvalue' , $ param -> getDefaultValue ( ) ) ; } $ op -> appendChild ( $ arg ) ; } $ target -> appendChild ( $ op ) ; } } }
Build XML service description from reflection class
56,914
protected function _getPropertyType ( Zend_Reflection_Property $ prop ) { $ docBlock = $ prop -> getDocComment ( ) ; if ( ! $ docBlock ) { return 'Unknown' ; } if ( ! $ docBlock -> hasTag ( 'var' ) ) { return 'Unknown' ; } $ tag = $ docBlock -> getTag ( 'var' ) ; return trim ( $ tag -> getDescription ( ) ) ; }
Extract type of the property from DocBlock
56,915
protected function _getServicePath ( ) { if ( isset ( $ this -> _options [ 'server' ] ) ) { return $ this -> _options [ 'server' ] -> getDirectory ( ) ; } if ( isset ( $ this -> _options [ 'directories' ] ) ) { return $ this -> _options [ 'directories' ] ; } return array ( ) ; }
Get the array of service directories
56,916
protected function _phpTypeToAS ( $ typename ) { if ( class_exists ( $ typename ) ) { $ vars = get_class_vars ( $ typename ) ; if ( isset ( $ vars [ '_explicitType' ] ) ) { return $ vars [ '_explicitType' ] ; } } if ( false !== ( $ asname = Zend_Amf_Parse_TypeLoader :: getMappedClassName ( $ typename ) ) ) { return $ asname ; } return $ typename ; }
Map from PHP type name to AS type name
56,917
protected function _registerType ( $ typename ) { if ( isset ( $ this -> _typesMap [ $ typename ] ) ) { return $ this -> _typesMap [ $ typename ] ; } if ( in_array ( $ typename , array ( 'void' , 'null' , 'mixed' , 'unknown_type' ) ) ) { return 'Unknown' ; } if ( 'array' == $ typename ) { return 'Unknown[]' ; } if ( in_array ( $ typename , array ( 'int' , 'integer' , 'bool' , 'boolean' , 'float' , 'string' , 'object' , 'Unknown' , 'stdClass' ) ) ) { return $ typename ; } $ asTypeName = $ this -> _phpTypeToAS ( $ typename ) ; $ this -> _typesMap [ $ typename ] = $ asTypeName ; $ typeEl = $ this -> _xml -> createElement ( 'type' ) ; $ typeEl -> setAttribute ( 'name' , $ asTypeName ) ; $ this -> _addClassAttributes ( $ typename , $ typeEl ) ; $ this -> _types -> appendChild ( $ typeEl ) ; return $ asTypeName ; }
Register new type on the system
56,918
public function getLanguages ( ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ languages = SnippetLanguage :: get ( ) ; $ response [ 'data' ] = array ( ) ; foreach ( $ languages as $ lang ) { if ( $ lang -> Hidden && $ lang -> Snippets ( ) -> Count ( ) == 0 ) { continue ; } $ response [ 'data' ] [ ] = array ( 'language' => $ lang -> Name , 'file_extension' => $ lang -> FileExtension , 'shjs_code' => $ lang -> HighlightCode , 'hidden' => $ lang -> Hidden , 'id' => $ lang -> ID ) ; } return $ response ; }
Gets the list of languages
56,919
public function getSnippets ( ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ languages = SnippetLanguage :: get ( ) ; foreach ( $ languages as $ lang ) { if ( $ lang -> Snippets ( ) -> Count ( ) > 0 ) { $ snippets = $ this -> overviewList ( $ lang -> Snippets ( ) -> filter ( 'FolderID' , 0 ) , 'Title' , 'ID' , 'LanguageID' ) ; $ response [ 'data' ] [ ] = array ( 'id' => $ lang -> ID , 'language' => $ lang -> Name , 'folders' => $ this -> mapFolders ( $ lang -> Folders ( ) ) , 'snippets' => $ snippets ) ; } } return $ response ; }
Gets a list of snippets in an array of languages
56,920
private function mapFolders ( SS_List $ folders , $ searchQuery = null ) { $ result = array ( ) ; foreach ( $ folders as $ folder ) { if ( ! empty ( $ searchQuery ) && $ searchQuery !== false ) { $ searchEngine = Config :: inst ( ) -> get ( 'CodeBank' , 'snippet_search_engine' ) ; if ( $ searchEngine && class_exists ( $ searchEngine ) && in_array ( 'ICodeBankSearchEngine' , class_implements ( $ searchEngine ) ) ) { $ searchEngine = new $ searchEngine ( ) ; } else { $ searchEngine = new DefaultCodeBankSearchEngine ( ) ; } $ snippets = $ searchEngine -> doSnippetSearch ( $ searchQuery , false , $ folder -> ID ) ; } else { $ snippets = $ folder -> Snippets ( ) ; } $ snippets = $ this -> overviewList ( $ snippets , 'Title' , 'ID' , 'LanguageID' ) ; if ( ! empty ( $ searchQuery ) && $ searchQuery !== false && count ( $ snippets ) == 0 ) { continue ; } $ result [ ] = array ( 'id' => $ folder -> ID , 'name' => $ folder -> Name , 'languageID' => $ folder -> LanguageID , 'folders' => $ this -> mapFolders ( $ folder -> Folders ( ) , $ searchQuery ) , 'snippets' => $ snippets ) ; } return $ result ; }
Maps the folder and its decendents through recurrsion
56,921
public function getSnippetsByLanguage ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ lang = SnippetLanguage :: get ( ) -> byID ( intval ( $ data -> id ) ) ; if ( ! empty ( $ lang ) && $ lang !== false && $ lang -> ID != 0 && $ lang -> Snippets ( ) -> Count ( ) > 0 ) { $ snippets = $ this -> arrayUnmap ( $ lang -> Snippets ( ) -> filter ( 'FolderID' , 0 ) -> map ( 'ID' , 'Title' ) -> toArray ( ) ) ; $ response [ 'data' ] [ ] = array ( 'id' => $ lang -> ID , 'language' => $ lang -> Name , 'folders' => $ this -> mapFolders ( $ lang -> Folders ( ) ) , 'snippets' => $ snippets ) ; } return $ response ; }
Gets a list of snippets that are in the selected index in an array of languages
56,922
public function searchSnippets ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ languages = SnippetLanguage :: get ( ) ; foreach ( $ languages as $ lang ) { $ searchEngine = Config :: inst ( ) -> get ( 'CodeBank' , 'snippet_search_engine' ) ; if ( $ searchEngine && class_exists ( $ searchEngine ) && in_array ( 'ICodeBankSearchEngine' , class_implements ( $ searchEngine ) ) ) { $ searchEngine = new $ searchEngine ( ) ; } else { $ searchEngine = new DefaultCodeBankSearchEngine ( ) ; } $ snippets = $ searchEngine -> doSnippetSearch ( $ data -> query , $ lang -> ID ) ; if ( $ snippets -> Count ( ) > 0 ) { $ snippets = $ this -> arrayUnmap ( $ snippets -> filter ( 'FolderID' , 0 ) -> map ( 'ID' , 'Title' ) -> toArray ( ) ) ; $ response [ 'data' ] [ ] = array ( 'id' => $ lang -> ID , 'language' => $ lang -> Name , 'folders' => $ this -> mapFolders ( $ lang -> Folders ( ) , $ data -> query ) , 'snippets' => $ snippets ) ; } } return $ response ; }
Searches for snippets that match the information the client in the search field
56,923
public function getSnippetRevisions ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ snippet = Snippet :: get ( ) -> byID ( $ data -> id ) ; if ( ! empty ( $ snippet ) && $ snippet !== false && $ snippet -> ID != 0 ) { $ revisions = $ snippet -> Versions ( ) -> map ( 'ID' , 'Created' ) ; $ i = 0 ; foreach ( $ revisions as $ id => $ date ) { $ response [ 'data' ] [ ] = array ( 'id' => $ id , 'date' => ( $ i == 0 ? '{Current Revision}' : $ date ) ) ; $ i ++ ; } } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.SNIPPET_NOT_FOUND' , '_Snippet not found' ) ; } return $ response ; }
Gets a revisions of the snippet
56,924
public function getSnippetTextFromRevision ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ revision = SnippetVersion :: get ( ) -> byID ( intval ( $ data -> id ) ) ; if ( ! empty ( $ revision ) && $ revision !== false && $ revision -> ID != 0 ) { $ lang = $ revision -> Parent ( ) -> Language ( ) ; $ snippetScript = '<script type="text/javascript" src="app:/tools/external/syntaxhighlighter/brushes/shBrush' . $ lang -> HighlightCode . '.js"></script>' ; if ( $ lang -> UserLanguage == true && ! empty ( $ lang -> BrushFile ) ) { $ snippetScript = "<script type=\"text/javascript\">\n" . @ file_get_contents ( Director :: baseFolder ( ) . '/' . $ lang -> BrushFile ) . "\n</script>" ; } $ response [ 'data' ] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' . '<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">' . '<head>' . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . '<link type="text/css" rel="stylesheet" href="app:/tools/external/syntaxhighlighter/themes/shCore.css"/>' . '<link type="text/css" rel="stylesheet" href="app:/tools/external/syntaxhighlighter/themes/shCore' . $ data -> style . '.css"/>' . '<link type="text/css" rel="stylesheet" href="app:/tools/external/syntaxhighlighter/themes/shTheme' . $ data -> style . '.css"/>' . '<link type="text/css" rel="stylesheet" href="app:/tools/syntaxhighlighter.css"/>' . '<script type="text/javascript" src="app:/tools/external/syntaxhighlighter/brushes/shCore.js"></script>' . $ snippetScript . '<script type="text/javascript" src="app:/tools/external/jquery-packed.js"></script>' . '<script type="text/javascript" src="app:/tools/highlight_helper.js"></script>' . '</head>' . '<body>' . '<pre class="brush: ' . strtolower ( $ lang -> HighlightCode ) . '" style="font-size:10pt;">' . htmlentities ( preg_replace ( '/\r\n|\n|\r/' , "\n" , $ revision -> Text ) , null , 'UTF-8' ) . '</pre>' . '</body>' . '</html>' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.REVISION_NOT_FOUND' , '_Revision not found' ) ; } return $ response ; }
Gets the of the snippet from a revision
56,925
public function newSnippet ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } try { $ snippet = new Snippet ( ) ; $ snippet -> Title = $ data -> title ; $ snippet -> Description = $ data -> description ; $ snippet -> Text = $ data -> code ; $ snippet -> Tags = $ data -> tags ; $ snippet -> LanguageID = $ data -> language ; $ snippet -> CreatorID = Member :: currentUserID ( ) ; $ snippet -> PackageID = $ data -> packageID ; if ( $ data -> folderID > 0 ) { $ folder = SnippetFolder :: get ( ) -> byID ( intval ( $ data -> folderID ) ) ; if ( empty ( $ folder ) || $ folder === false || $ folder -> ID == 0 ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBankAPI.FOLDER_DOES_NOT_EXIST' , '_Folder does not exist' ) ; return $ response ; } if ( $ folder -> LanguageID != $ snippet -> LanguageID ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBankAPI.FOLDER_NOT_LANGUAGE' , '_Folder is not in the same language as the snippet' ) ; return $ response ; } } $ snippet -> write ( ) ; $ response [ 'status' ] = "HELO" ; } catch ( Exception $ e ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = "Internal Server error occured" ; } return $ response ; }
Saves a new snippet
56,926
public function saveSnippet ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } try { $ snippet = Snippet :: get ( ) -> byID ( intval ( $ data -> id ) ) ; if ( ! empty ( $ snippet ) && $ snippet !== false && $ snippet -> ID != 0 ) { $ snippet -> Title = $ data -> title ; $ snippet -> Description = $ data -> description ; $ snippet -> Text = $ data -> code ; $ snippet -> Tags = $ data -> tags ; if ( $ snippet -> LanguageID != $ data -> language ) { $ lang = SnippetLanguage :: get ( ) -> byID ( intval ( $ data -> language ) ) ; if ( ! empty ( $ lang ) && $ lang !== false && $ lang -> ID > 0 ) { if ( $ lang -> Hidden ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.LANGUAGE_HIDDEN' , '_You cannot assign this snippet to a hidden language' ) ; return $ response ; } } else { throw new Exception ( 'Language not found' ) ; } } $ snippet -> LanguageID = $ data -> language ; $ snippet -> LastEditorID = Member :: currentUserID ( ) ; $ snippet -> PackageID = $ data -> packageID ; $ snippet -> write ( ) ; $ response [ 'status' ] = 'HELO' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.SNIPPET_NOT_FOUND' , '_Snippet not found' ) ; } } catch ( Exception $ e ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = "Internal Server error occured" ; } return $ response ; }
Saves an existing snippet
56,927
public function deleteSnippet ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; try { $ snippet = Snippet :: get ( ) -> byID ( intval ( $ data -> id ) ) ; if ( ! empty ( $ snippet ) && $ snippet !== false && $ snippet -> ID != 0 ) { if ( $ snippet -> canDelete ( ) == false ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = "Not authorized" ; return $ response ; } $ snippet -> delete ( ) ; $ response [ 'status' ] = 'HELO' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.SNIPPET_NOT_FOUND' , '_Snippet not found' ) ; } } catch ( Exception $ e ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = "Internal Server error occured" ; } return $ response ; }
Deletes a snippet from the database
56,928
public function getSnippetDiff ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; $ snippet1 = SnippetVersion :: get ( ) -> byID ( intval ( $ data -> mainRev ) ) ; if ( empty ( $ snippet1 ) || $ snippet1 === false || $ snippet1 -> ID == 0 ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.MAIN_REVISION_NOT_FOUND' , '_Main revision not found' ) ; return $ response ; } $ snippet1 = preg_replace ( '/\r\n|\n|\r/' , "\n" , $ snippet1 -> Text ) ; $ snippet2 = SnippetVersion :: get ( ) -> byID ( intval ( $ data -> compRev ) ) ; if ( empty ( $ snippet2 ) || $ snippet1 === false || $ snippet2 -> ID == 0 ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.COMPARE_REVISION_NOT_FOUND' , '_Compare revision not found' ) ; return $ response ; } $ snippet2 = preg_replace ( '/\r\n|\n|\r/' , "\n" , $ snippet2 -> Text ) ; $ diff = new Text_Diff ( 'auto' , array ( preg_split ( '/\n/' , $ snippet2 ) , preg_split ( '/\n/' , $ snippet1 ) ) ) ; $ renderer = new Text_Diff_Renderer_unified ( array ( 'leading_context_lines' => 1 , 'trailing_context_lines' => 1 ) ) ; $ response [ 'data' ] = array ( 'mainRev' => $ snippet1 , 'compRev' => $ snippet2 , 'diff' => $ renderer -> render ( $ diff ) ) ; return $ response ; }
Gets the snippet text for the two revisions as well as a unified diff file of the revisions
56,929
public function getPackages ( ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ response [ 'data' ] = $ this -> overviewList ( SnippetPackage :: get ( ) ) ; return $ response ; }
Gets the list of packages
56,930
public function getPackageInfo ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ package = SnippetPackage :: get ( ) -> byID ( intval ( $ data -> id ) ) ; if ( ! empty ( $ package ) && $ package !== false && $ package -> ID != 0 ) { $ response [ 'data' ] = array ( 'id' => $ package -> ID , 'title' => $ package -> Title , 'snippets' => $ this -> overviewList ( $ package -> Snippets ( ) , 'Title' , 'ID' , 'Language.Title' ) ) ; $ response [ 'status' ] = 'HELO' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PACKAGE_NOT_FOUND' , '_Package not found' ) ; } return $ response ; }
Gets the details of a package
56,931
public function packageRemoveSnippet ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ package = SnippetPackage :: get ( ) -> byID ( intval ( $ data -> packageID ) ) ; if ( ! empty ( $ package ) && $ package !== false && $ package -> ID != 0 ) { $ package -> Snippets ( ) -> removeByID ( intval ( $ data -> snippetID ) ) ; $ response [ 'status' ] = 'HELO' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PACKAGE_NOT_FOUND' , '_Package not found' ) ; } return $ response ; }
Removes a snippet from a package
56,932
public function findSnippetAutoComplete ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ snippets = Snippet :: get ( ) -> filter ( 'Title:StartsWith' , Convert :: raw2sql ( $ data -> pattern ) ) -> limit ( 20 ) ; $ response [ 'status' ] = 'HELO' ; $ response [ 'data' ] = $ this -> overviewList ( $ snippets ) ; return $ response ; }
Finds a snippet begining with the data passed
56,933
public function addSnippetToPackage ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ package = SnippetPackage :: get ( ) -> byID ( intval ( $ data -> packageID ) ) ; if ( ! empty ( $ package ) && $ package !== false && $ package -> ID != 0 ) { $ snippet = Snippet :: get ( ) -> byID ( intval ( $ data -> snippetID ) ) ; if ( ! empty ( $ snippet ) && $ snippet !== false && $ snippet -> ID != 0 ) { $ package -> Snippets ( ) -> add ( $ snippet ) ; $ response [ 'status' ] = 'HELO' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.SNIPPET_NOT_FOUND' , '_Snippet not found' ) ; } $ response [ 'status' ] = 'HELO' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PACKAGE_NOT_FOUND' , '_Package not found' ) ; } return $ response ; }
Adds a snippet to a package
56,934
public function deletePackage ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ package = SnippetPackage :: get ( ) -> byID ( intval ( $ data -> id ) ) ; if ( ! empty ( $ package ) && $ package !== false && $ package -> ID != 0 ) { $ package -> delete ( ) ; $ response [ 'status' ] = 'HELO' ; } else { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PACKAGE_NOT_FOUND' , '_Package not found' ) ; } return $ response ; }
Deletes a package
56,935
public function newFolder ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ language = SnippetLanguage :: get ( ) -> byID ( intval ( $ data -> languageID ) ) ; if ( empty ( $ language ) || $ language === false || $ language -> ID == 0 ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBankAPI.LANGUAGE_NOT_FOUND' , '_Language not found' ) ; return $ response ; } if ( $ data -> parentID > 0 ) { $ folder = SnippetFolder :: get ( ) -> byID ( intval ( $ data -> parentID ) ) ; if ( empty ( $ folder ) || $ folder === false || $ folder -> ID == 0 ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBankAPI.FOLDER_DOES_NOT_EXIST' , '_Folder does not exist' ) ; return $ response ; } if ( $ folder -> LanguageID != $ language -> ID ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBankAPI.FOLDER_NOT_LANGUAGE' , '_Folder is not in the same language as the snippet' ) ; return $ response ; } } $ existingCheck = SnippetFolder :: get ( ) -> filter ( 'Name:nocase' , Convert :: raw2sql ( $ data -> name ) ) -> filter ( 'LanguageID' , $ language -> ID ) -> filter ( 'ParentID' , $ data -> parentID ) ; if ( $ existingCheck -> Count ( ) > 0 ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBank.FOLDER_EXISTS' , '_A folder already exists with that name' ) ; return $ response ; } try { $ snippetFolder = new SnippetFolder ( ) ; $ snippetFolder -> Name = $ data -> name ; $ snippetFolder -> LanguageID = $ data -> languageID ; $ snippetFolder -> ParentID = $ data -> parentID ; $ snippetFolder -> write ( ) ; $ response [ 'status' ] = "HELO" ; } catch ( Exception $ e ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = "Internal Server error occured" ; } return $ response ; }
Saves a new folder
56,936
public function renameFolder ( $ data ) { $ response = CodeBank_ClientAPI :: responseBase ( ) ; if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { $ response [ 'status' ] = 'EROR' ; $ response [ 'message' ] = _t ( 'CodeBankAPI.PERMISSION_DENINED' , '_Permission Denied' ) ; return $ response ; } $ snippetFolder = SnippetFolder :: get ( ) -> byID ( intval ( $ data -> id ) ) ; if ( empty ( $ snippetFolder ) || $ snippetFolder === false || $ snippetFolder -> ID == 0 ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBankAPI.FOLDER_DOES_NOT_EXIST' , '_Folder does not exist' ) ; return $ response ; } $ existingCheck = SnippetFolder :: get ( ) -> filter ( 'ID:not' , $ snippetFolder -> ID ) -> filter ( 'Name:nocase' , Convert :: raw2sql ( $ data -> name ) ) -> filter ( 'LanguageID' , $ snippetFolder -> LanguageID ) -> filter ( 'ParentID' , $ snippetFolder -> ParentID ) ; if ( $ existingCheck -> Count ( ) > 0 ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = _t ( 'CodeBank.FOLDER_EXISTS' , '_A folder already exists with that name' ) ; return $ response ; } try { $ snippetFolder -> Name = $ data -> name ; $ snippetFolder -> write ( ) ; $ response [ 'status' ] = "HELO" ; } catch ( Exception $ e ) { $ response [ 'status' ] = "EROR" ; $ response [ 'message' ] = "Internal Server error occured" ; } return $ response ; }
Renames a folder
56,937
final protected function arrayUnmap ( $ array , $ keyLbl = 'id' , $ valueLbl = 'title' ) { $ result = array ( ) ; foreach ( $ array as $ key => $ value ) { $ result [ ] = array ( $ keyLbl => $ key , $ valueLbl => $ value ) ; } return $ result ; }
Converts an array where the key and value should be mapped to a nested array
56,938
final protected function overviewList ( SS_List $ list , $ labelField = 'Title' , $ idField = 'ID' ) { $ result = array ( ) ; $ idFieldLower = strtolower ( $ idField ) ; $ labelFieldLower = strtolower ( $ labelField ) ; $ args = func_get_args ( ) ; unset ( $ args [ 0 ] ) ; unset ( $ args [ 1 ] ) ; unset ( $ args [ 2 ] ) ; foreach ( $ list as $ item ) { $ obj = new stdClass ( ) ; $ obj -> $ idFieldLower = $ item -> $ idField ; $ obj -> $ labelFieldLower = $ item -> $ labelField ; if ( count ( $ args ) > 0 ) { foreach ( $ args as $ field ) { $ fieldLower = strtolower ( $ field ) ; if ( strpos ( $ field , '.' ) !== false ) { $ fieldLower = str_replace ( '.' , '-' , $ fieldLower ) ; $ fieldBits = explode ( '.' , $ field ) ; $ value = $ item ; for ( $ i = 0 ; $ i < count ( $ fieldBits ) ; $ i ++ ) { $ fieldBit = $ fieldBits [ $ i ] ; if ( $ i == count ( $ fieldBits ) - 1 ) { $ value = $ value -> $ fieldBit ; } else { $ value = $ value -> $ fieldBit ( ) ; } } if ( ! is_object ( $ value ) ) { $ obj -> $ fieldLower = $ value ; } } else { $ obj -> $ fieldLower = $ item -> $ field ; } } } $ result [ ] = $ obj ; } return $ result ; }
Converts an SS_List into an array of items with and id and a title key
56,939
final protected function sortToTop ( $ value , $ field , $ array ) { foreach ( $ array as $ key => $ item ) { if ( $ item -> $ field == $ value ) { unset ( $ array [ $ key ] ) ; array_unshift ( $ array , $ item ) ; break ; } } return $ array ; }
Sorts an item to the top of the list
56,940
protected function getDependencyTemplateResources ( ) { $ templateResources = [ ] ; foreach ( $ this -> dependencies as $ dependency ) { $ templateResources [ ] = $ this -> objectManager -> get ( $ dependency ) -> getPreviewTemplateResources ( ) ; } return $ templateResources ; }
Get the template resources of component dependencies
56,941
protected function determineExtensionName ( ) { $ reflectionClass = new \ ReflectionClass ( $ this ) ; $ componentFilePath = dirname ( $ reflectionClass -> getFileName ( ) ) ; $ extensionDirPosition = strpos ( $ componentFilePath , 'ext' . DIRECTORY_SEPARATOR ) ; if ( $ extensionDirPosition === false ) { throw new \ RuntimeException ( 'Invalid component path' , 1481360976 ) ; } $ componentPath = explode ( DIRECTORY_SEPARATOR , substr ( $ componentFilePath , $ extensionDirPosition + strlen ( 'ext' . DIRECTORY_SEPARATOR ) ) ) ; $ extensionKey = array_shift ( $ componentPath ) ; if ( ! in_array ( $ extensionKey , ExtensionManagementUtility :: getLoadedExtensionListArray ( ) ) ) { throw new \ RuntimeException ( sprintf ( 'Unknown extension key "%s"' , $ extensionKey ) , 1481361198 ) ; } $ this -> extensionKey = $ extensionKey ; $ this -> extensionName = GeneralUtility :: underscoredToUpperCamelCase ( $ extensionKey ) ; if ( array_shift ( $ componentPath ) !== 'Components' ) { throw new \ RuntimeException ( 'Invalid component path' , 1481360976 ) ; } $ this -> componentPath = array_map ( [ static :: class , 'expandComponentName' ] , $ componentPath ) ; }
Find the extension name the current component belongs to
56,942
protected function determineNameAndVariant ( ) { $ reflectionClass = new \ ReflectionClass ( $ this ) ; $ componentName = preg_replace ( '/Component$/' , '' , $ reflectionClass -> getShortName ( ) ) ; list ( $ this -> basename , $ variant ) = preg_split ( '/_+/' , $ componentName , 2 ) ; $ this -> name = self :: expandComponentName ( $ this -> basename ) ; $ this -> variant = self :: expandComponentName ( $ variant ) ; }
Determine the component name and variant
56,943
public static function expandComponentName ( $ componentPath ) { return trim ( implode ( ' ' , array_map ( 'ucwords' , preg_split ( '/_+/' , GeneralUtility :: camelCaseToLowerCaseUnderscored ( $ componentPath ) ) ) ) ) ? : null ; }
Prepare a component path
56,944
protected function addDocumentation ( ) { $ docDirectory = $ this -> getDocumentationDirectory ( ) ; if ( is_dir ( $ docDirectory ) ) { $ validIndexDocuments = [ 'index.md' , 'readme.md' , strtolower ( $ this -> basename . '.md' ) ] ; $ indexDocument = null ; $ documents = [ ] ; foreach ( scandir ( $ docDirectory ) as $ document ) { if ( ! is_file ( $ docDirectory . DIRECTORY_SEPARATOR . $ document ) ) { continue ; } if ( in_array ( strtolower ( $ document ) , $ validIndexDocuments ) ) { if ( $ indexDocument === null ) { $ indexDocument = $ docDirectory . DIRECTORY_SEPARATOR . $ document ; } continue ; } $ documents [ ] = $ docDirectory . DIRECTORY_SEPARATOR . $ document ; } if ( $ indexDocument !== null ) { $ this -> addNotice ( file_get_contents ( $ indexDocument ) ) ; return ; } if ( count ( $ documents ) ) { $ listing = [ ] ; foreach ( $ documents as $ document ) { $ extension = strtolower ( pathinfo ( $ document , PATHINFO_EXTENSION ) ) ; $ listing [ ] = '* ' . ( in_array ( $ extension , [ 'jpg' , 'jpeg' , 'png' , 'gif' , 'svg' ] ) ? '!' : '' ) . '[' . pathinfo ( $ document , PATHINFO_FILENAME ) . '](' . basename ( $ document ) . ')' ; } $ this -> addNotice ( implode ( PHP_EOL , $ listing ) ) ; } } }
Add an external documentation
56,945
protected function getDocumentationDirectory ( $ rootRelative = false ) { $ reflectionObject = new \ ReflectionObject ( $ this ) ; $ componentFile = $ reflectionObject -> getFileName ( ) ; $ docDirectory = dirname ( $ componentFile ) . DIRECTORY_SEPARATOR . $ this -> basename ; return $ rootRelative ? substr ( $ docDirectory , strlen ( PATH_site ) - 1 ) : $ docDirectory ; }
Return the documentation directory for this component
56,946
protected function exportNotice ( $ notice ) { $ docDirectoryPath = strtr ( $ this -> getDocumentationDirectory ( true ) , [ DIRECTORY_SEPARATOR => '/' ] ) . '/' ; return preg_replace_callback ( '/\[([^\]]*?)\]\(([^\)]*?)\)/' , function ( $ match ) use ( $ docDirectoryPath ) { return '[' . $ match [ 1 ] . '](' . ( preg_match ( '%^https?\:\/\/%i' , $ match [ 2 ] ) ? '' : $ docDirectoryPath ) . $ match [ 2 ] . ')' ; } , $ notice ) ; }
Export a notice
56,947
final public function export ( ) { $ properties = [ 'status' => $ this -> status , 'name' => $ this -> name , 'variant' => $ this -> variant , 'label' => $ this -> label , 'class' => get_class ( $ this ) , 'type' => $ this -> type , 'valid' => false , 'path' => $ this -> componentPath , 'docs' => $ this -> getDocumentationDirectory ( ) , ] ; try { $ properties = array_merge ( $ properties , $ this -> exportInternal ( ) ) ; $ properties [ 'request' ] = $ this -> exportRequest ( ) ; $ properties [ 'valid' ] = true ; } catch ( \ Exception $ e ) { $ properties [ 'error' ] = $ e -> getMessage ( ) ; } return $ properties ; }
Export the component s properties
56,948
protected function exportRequest ( ) { if ( $ this -> languageParameter ) { $ this -> request -> setArgument ( $ this -> languageParameter , $ this -> sysLanguage ) ; } $ this -> request -> setControllerExtensionName ( $ this -> extensionName ) ; $ this -> request -> setArgument ( 'id' , $ this -> page ) ; if ( intval ( $ this -> typeNum ) ) { $ this -> request -> setArgument ( 'type' , intval ( $ this -> typeNum ) ) ; } return [ 'method' => $ this -> request -> getMethod ( ) , 'arguments' => $ this -> request -> getArguments ( ) , ] ; }
Export the request options
56,949
protected function addResource ( $ resource ) { $ resource = trim ( $ resource ) ; if ( strlen ( $ resource ) ) { $ this -> resources [ ] = $ resource ; } }
Add an associated resource
56,950
protected function setPreview ( $ preview ) { if ( ! ( $ preview instanceof TemplateInterface ) && ! is_string ( $ preview ) && ( $ preview !== null ) ) { throw new \ RuntimeException ( 'Invalid preview preview' , 1481368492 ) ; } $ this -> preview = $ preview ; }
Set a preview template
56,951
protected function initializeTSFE ( ) { $ GLOBALS [ 'TSFE' ] = TypoScriptUtility :: getTSFE ( $ this -> page , $ this -> typeNum ) ; $ GLOBALS [ 'TSFE' ] -> cObj = new ContentObjectRenderer ( $ GLOBALS [ 'TSFE' ] ) ; $ GLOBALS [ 'TSFE' ] -> cObj -> start ( $ GLOBALS [ 'TSFE' ] -> page , 'pages' ) ; return $ GLOBALS [ 'TSFE' ] -> cObj ; }
Initialize a global Frontend renderer and return a content object renderer instance
56,952
protected function addError ( $ property , $ message ) { $ this -> validationErrors -> forProperty ( $ property ) -> addError ( new Error ( $ message , time ( ) ) ) ; }
Register a validation error
56,953
function compute_string_distance ( $ string1 , $ string2 ) { $ chars1 = count_chars ( $ string1 ) ; $ chars2 = count_chars ( $ string2 ) ; $ difference = array_sum ( array_map ( array ( & $ this , 'difference' ) , $ chars1 , $ chars2 ) ) ; if ( ! $ string1 ) return $ difference ; return $ difference / strlen ( $ string1 ) ; }
Computes a number that is intended to reflect the distance between two strings .
56,954
public function setAuth ( Zend_Amf_Auth_Abstract $ auth ) { $ this -> _auth = $ auth ; if ( ( null === $ this -> getAcl ( ) ) && method_exists ( $ auth , 'getAcl' ) ) { $ this -> setAcl ( $ auth -> getAcl ( ) ) ; } return $ this ; }
Set authentication adapter
56,955
protected function _checkAcl ( $ object , $ function ) { if ( ! $ this -> _acl ) { return true ; } if ( $ object ) { $ class = is_object ( $ object ) ? get_class ( $ object ) : $ object ; if ( ! $ this -> _acl -> has ( $ class ) ) { require_once 'Zend/Acl/Resource.php' ; $ this -> _acl -> add ( new Zend_Acl_Resource ( $ class ) ) ; } $ call = array ( $ object , "initAcl" ) ; if ( is_callable ( $ call ) && ! call_user_func ( $ call , $ this -> _acl ) ) { return true ; } } else { $ class = null ; } $ auth = Zend_Auth :: getInstance ( ) ; if ( $ auth -> hasIdentity ( ) ) { $ role = $ auth -> getIdentity ( ) -> role ; } else { if ( $ this -> _acl -> hasRole ( Zend_Amf_Constants :: GUEST_ROLE ) ) { $ role = Zend_Amf_Constants :: GUEST_ROLE ; } else { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( "Unauthenticated access not allowed" ) ; } } if ( $ this -> _acl -> isAllowed ( $ role , $ class , $ function ) ) { return true ; } else { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( "Access not allowed" ) ; } }
Check if the ACL allows accessing the function or method
56,956
protected function _loadCommandMessage ( Zend_Amf_Value_Messaging_CommandMessage $ message ) { require_once 'Zend/Amf/Value/Messaging/AcknowledgeMessage.php' ; switch ( $ message -> operation ) { case Zend_Amf_Value_Messaging_CommandMessage :: DISCONNECT_OPERATION : case Zend_Amf_Value_Messaging_CommandMessage :: CLIENT_PING_OPERATION : $ return = new Zend_Amf_Value_Messaging_AcknowledgeMessage ( $ message ) ; break ; case Zend_Amf_Value_Messaging_CommandMessage :: LOGIN_OPERATION : $ data = explode ( ':' , base64_decode ( $ message -> body ) ) ; $ userid = $ data [ 0 ] ; $ password = isset ( $ data [ 1 ] ) ? $ data [ 1 ] : "" ; if ( empty ( $ userid ) ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Login failed: username not supplied' ) ; } if ( ! $ this -> _handleAuth ( $ userid , $ password ) ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Authentication failed' ) ; } $ return = new Zend_Amf_Value_Messaging_AcknowledgeMessage ( $ message ) ; break ; case Zend_Amf_Value_Messaging_CommandMessage :: LOGOUT_OPERATION : if ( $ this -> _auth ) { Zend_Auth :: getInstance ( ) -> clearIdentity ( ) ; } $ return = new Zend_Amf_Value_Messaging_AcknowledgeMessage ( $ message ) ; break ; default : require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'CommandMessage::' . $ message -> operation . ' not implemented' ) ; break ; } return $ return ; }
Handles each of the 11 different command message types .
56,957
protected function _errorMessage ( $ objectEncoding , $ message , $ description , $ detail , $ code , $ line ) { $ return = null ; switch ( $ objectEncoding ) { case Zend_Amf_Constants :: AMF0_OBJECT_ENCODING : return array ( 'description' => ( $ this -> isProduction ( ) ) ? '' : $ description , 'detail' => ( $ this -> isProduction ( ) ) ? '' : $ detail , 'line' => ( $ this -> isProduction ( ) ) ? 0 : $ line , 'code' => $ code ) ; case Zend_Amf_Constants :: AMF3_OBJECT_ENCODING : require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php' ; $ return = new Zend_Amf_Value_Messaging_ErrorMessage ( $ message ) ; $ return -> faultString = $ this -> isProduction ( ) ? '' : $ description ; $ return -> faultCode = $ code ; $ return -> faultDetail = $ this -> isProduction ( ) ? '' : $ detail ; break ; } return $ return ; }
Create appropriate error message
56,958
protected function _handleAuth ( $ userid , $ password ) { if ( ! $ this -> _auth ) { return true ; } $ this -> _auth -> setCredentials ( $ userid , $ password ) ; $ auth = Zend_Auth :: getInstance ( ) ; $ result = $ auth -> authenticate ( $ this -> _auth ) ; if ( $ result -> isValid ( ) ) { if ( ! $ this -> isSession ( ) ) { $ this -> setSession ( ) ; } return true ; } else { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( "Authentication failed: " . join ( "\n" , $ result -> getMessages ( ) ) , $ result -> getCode ( ) ) ; } }
Handle AMF authentication
56,959
public function handle ( $ request = null ) { if ( $ request === null || ! $ request instanceof Zend_Amf_Request ) { $ request = $ this -> getRequest ( ) ; } else { $ this -> setRequest ( $ request ) ; } if ( $ this -> isSession ( ) ) { if ( isset ( $ _COOKIE [ $ this -> _sessionName ] ) ) { session_id ( $ _COOKIE [ $ this -> _sessionName ] ) ; } } try { $ this -> _handle ( $ request ) ; $ response = $ this -> getResponse ( ) ; } catch ( Exception $ e ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Handle error: ' . $ e -> getMessage ( ) . ' ' . $ e -> getLine ( ) , 0 , $ e ) ; } return $ response ; }
Handle an AMF call from the gateway .
56,960
public function setRequest ( $ request ) { if ( is_string ( $ request ) && class_exists ( $ request ) ) { $ request = new $ request ( ) ; if ( ! $ request instanceof Zend_Amf_Request ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Invalid request class' ) ; } } elseif ( ! $ request instanceof Zend_Amf_Request ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Invalid request object' ) ; } $ this -> _request = $ request ; return $ this ; }
Set request object
56,961
public function setResponse ( $ response ) { if ( is_string ( $ response ) && class_exists ( $ response ) ) { $ response = new $ response ( ) ; if ( ! $ response instanceof Zend_Amf_Response ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Invalid response class' ) ; } } elseif ( ! $ response instanceof Zend_Amf_Response ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Invalid response object' ) ; } $ this -> _response = $ response ; return $ this ; }
Public access method to private Zend_Amf_Server_Response reference
56,962
public function getResponse ( ) { if ( null === ( $ response = $ this -> _response ) ) { require_once 'Zend/Amf/Response/Http.php' ; $ this -> setResponse ( new Zend_Amf_Response_Http ( ) ) ; } return $ this -> _response ; }
get a reference to the Zend_Amf_response instance
56,963
public function setClass ( $ class , $ namespace = '' , $ argv = null ) { if ( is_string ( $ class ) && ! class_exists ( $ class ) ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Invalid method or class' ) ; } elseif ( ! is_string ( $ class ) && ! is_object ( $ class ) ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Invalid method or class; must be a classname or object' ) ; } $ argv = null ; if ( 2 < func_num_args ( ) ) { $ argv = array_slice ( func_get_args ( ) , 2 ) ; } if ( $ namespace == '' ) { $ namespace = is_object ( $ class ) ? get_class ( $ class ) : $ class ; } $ this -> _classAllowed [ is_object ( $ class ) ? get_class ( $ class ) : $ class ] = true ; $ this -> _methods [ ] = Zend_Server_Reflection :: reflectClass ( $ class , $ argv , $ namespace ) ; $ this -> _buildDispatchTable ( ) ; return $ this ; }
Attach a class or object to the server
56,964
public function addFunction ( $ function , $ namespace = '' ) { if ( ! is_string ( $ function ) && ! is_array ( $ function ) ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Unable to attach function' ) ; } $ argv = null ; if ( 2 < func_num_args ( ) ) { $ argv = array_slice ( func_get_args ( ) , 2 ) ; } $ function = ( array ) $ function ; foreach ( $ function as $ func ) { if ( ! is_string ( $ func ) || ! function_exists ( $ func ) ) { require_once 'Zend/Amf/Server/Exception.php' ; throw new Zend_Amf_Server_Exception ( 'Unable to attach function' ) ; } $ this -> _methods [ ] = Zend_Server_Reflection :: reflectFunction ( $ func , $ argv , $ namespace ) ; } $ this -> _buildDispatchTable ( ) ; return $ this ; }
Attach a function to the server
56,965
public function handleAuthenticationSuccess ( TokenInterface $ token , Request $ request , GuardAuthenticatorInterface $ guardAuthenticator , $ providerKey ) { $ response = $ guardAuthenticator -> onAuthenticationSuccess ( $ request , $ token , $ providerKey ) ; if ( $ response instanceof Response || null === $ response ) { return $ response ; } throw new \ UnexpectedValueException ( sprintf ( 'The %s::onAuthenticationSuccess method must return null or a Response object. You returned %s.' , get_class ( $ guardAuthenticator ) , is_object ( $ response ) ? get_class ( $ response ) : gettype ( $ response ) ) ) ; }
Returns the on success response for the given GuardAuthenticator .
56,966
public function writeDouble ( $ stream ) { $ stream = pack ( 'd' , $ stream ) ; if ( ! $ this -> _bigEndian ) { $ stream = strrev ( $ stream ) ; } $ this -> _stream .= $ stream ; return $ this ; }
Writes an IEEE 754 double - precision floating point number from the data stream .
56,967
public function setFile ( $ path ) { if ( empty ( $ path ) || ! is_readable ( $ path ) ) { require_once 'Zend/Auth/Adapter/Http/Resolver/Exception.php' ; throw new Zend_Auth_Adapter_Http_Resolver_Exception ( 'Path not readable: ' . $ path ) ; } $ this -> _file = $ path ; return $ this ; }
Set the path to the credentials file
56,968
private function eventIsFound ( DomainEvent $ targetEvent , DomainEvents $ realEvents ) { $ found = $ realEvents -> filter ( function ( $ realEvent ) use ( $ targetEvent ) { try { $ eventsAreEqual = $ this -> eventsAreEqual ( $ realEvent , $ targetEvent ) ; } catch ( FailureException $ e ) { $ eventsAreEqual = false ; } return $ eventsAreEqual ; } ) ; return $ found -> count ( ) != 0 ; }
returns true if an event is found
56,969
private function eventsAreEqual ( $ e1 , $ e2 ) { if ( get_class ( $ e1 ) != get_class ( $ e2 ) ) { return false ; } $ reflection = new \ ReflectionClass ( $ e1 ) ; $ fields = array_map ( function ( $ property ) { return $ property -> name ; } , $ reflection -> getProperties ( ) ) ; $ allMatch = true ; foreach ( $ fields as $ field ) { $ property = new \ ReflectionProperty ( get_class ( $ e1 ) , $ field ) ; $ property -> setAccessible ( true ) ; $ e1Value = $ property -> getValue ( $ e1 ) ; $ e2Value = $ property -> getValue ( $ e2 ) ; if ( is_array ( $ e1Value ) ) { for ( $ i = 0 ; $ i < count ( $ e1Value ) ; $ i ++ ) { $ setMatches = $ this -> compareProperties ( $ e1 , $ e1Value [ $ i ] , $ e2Value [ $ i ] , $ property ) ; if ( ! $ setMatches ) { $ allMatch = false ; } } } else { $ setMatches = $ this -> compareProperties ( $ e1 , $ e1Value , $ e2Value , $ property ) ; if ( ! $ setMatches ) { $ allMatch = false ; } } } return $ allMatch ; }
pull requests accepted
56,970
public function authenticate ( ) { $ id = $ this -> _id ; if ( ! empty ( $ id ) ) { $ consumer = new Zend_OpenId_Consumer ( $ this -> _storage ) ; $ consumer -> setHttpClient ( $ this -> _httpClient ) ; if ( ! $ this -> _check_immediate ) { if ( ! $ consumer -> login ( $ id , $ this -> _returnTo , $ this -> _root , $ this -> _extensions , $ this -> _response ) ) { return new Zend_Auth_Result ( Zend_Auth_Result :: FAILURE , $ id , array ( "Authentication failed" , $ consumer -> getError ( ) ) ) ; } } else { if ( ! $ consumer -> check ( $ id , $ this -> _returnTo , $ this -> _root , $ this -> _extensions , $ this -> _response ) ) { return new Zend_Auth_Result ( Zend_Auth_Result :: FAILURE , $ id , array ( "Authentication failed" , $ consumer -> getError ( ) ) ) ; } } } else { $ params = ( isset ( $ _SERVER [ 'REQUEST_METHOD' ] ) && $ _SERVER [ 'REQUEST_METHOD' ] == 'POST' ) ? $ _POST : $ _GET ; $ consumer = new Zend_OpenId_Consumer ( $ this -> _storage ) ; $ consumer -> setHttpClient ( $ this -> _httpClient ) ; if ( $ consumer -> verify ( $ params , $ id , $ this -> _extensions ) ) { return new Zend_Auth_Result ( Zend_Auth_Result :: SUCCESS , $ id , array ( "Authentication successful" ) ) ; } else { return new Zend_Auth_Result ( Zend_Auth_Result :: FAILURE , $ id , array ( "Authentication failed" , $ consumer -> getError ( ) ) ) ; } } }
Authenticates the given OpenId identity . Defined by Zend_Auth_Adapter_Interface .
56,971
protected function guardType ( $ items ) : void { if ( ! is_array ( $ items ) ) { $ items = array ( $ items ) ; } foreach ( $ items as $ item ) { if ( ! $ item instanceof $ this -> collectionType ) { throw new \ InvalidArgumentException ( "Got " . ( is_object ( $ item ) ? get_class ( $ item ) : $ item ) . " but expected " . $ this -> collectionType ) ; } } }
ensure that items added to the collection conform to the defined collection type
56,972
public function map ( Callable $ f ) : Collection { try { return new static ( array_map ( $ f , $ this -> items ) ) ; } catch ( \ Exception $ e ) { return new Collection ( array_map ( $ f , $ this -> items ) ) ; } }
return a new instance of this collection with values that have been transformed by the provided function .
56,973
protected function _find ( $ type , $ id ) { if ( is_array ( $ id ) ) { return $ this -> __mfind ( $ this -> index ( ) , $ type , $ id ) ; } else { return $ this -> __find ( $ this -> index ( ) , $ type , $ id ) ; } }
A decorator method to get specific document by its id . If the id is and array of strings or integers then multiple documents will be retreived by id .
56,974
protected function __query ( $ index , $ type = null , array $ query = [ ] ) { $ result = $ this -> client -> search ( [ 'index' => $ index , 'body' => array_merge_recursive ( $ query , $ this -> additionalQuery ( ) ) ] + ( $ type ? [ 'type' => $ type ] : [ ] ) ) ; return $ this -> _makeResult ( $ result ) ; }
The actual method to call client s search method . Returns Result object
56,975
protected function __find ( $ index , $ type , $ id ) { try { $ result = $ this -> client -> get ( [ 'index' => $ index , 'type' => $ type , 'id' => $ id ] ) ; if ( $ result [ 'found' ] ) { return $ this -> _makeModel ( $ result ) ; } else { return null ; } } catch ( \ Exception $ e ) { trigger_error ( $ e -> getMessage ( ) , E_USER_WARNING ) ; return null ; } }
The actual method to call client s get method . Returns either a Model object or null on failure .
56,976
protected function __mfind ( $ index , $ type , $ ids ) { try { $ docs = $ this -> client -> mget ( [ 'index' => $ index , 'type' => $ type , 'body' => [ "ids" => $ ids ] ] ) ; $ result = [ 'ids' => $ ids , 'found' => [ ] , 'missed' => [ ] , 'docs' => [ ] ] ; $ missed = [ ] + $ ids ; foreach ( $ docs [ 'docs' ] as $ doc ) { if ( $ doc [ 'found' ] ) { $ result [ 'docs' ] [ ] = $ doc ; $ result [ 'found' ] [ ] = $ doc [ '_id' ] ; unset ( $ missed [ array_search ( $ doc [ '_id' ] , $ missed ) ] ) ; } } $ result [ 'missed' ] = $ missed ; return $ this -> _makeMultiGetResult ( $ result ) ; } catch ( \ Exception $ e ) { trigger_error ( $ e -> getMessage ( ) , E_USER_WARNING ) ; return null ; } }
The actual method to call client s mget method . Returns either a result of Model objects or null on failure .
56,977
protected function _meta ( $ features = null , array $ options = [ ] ) { if ( $ features ) { $ features = join ( ',' , array_map ( function ( $ item ) { return '_' . strtolower ( trim ( $ item , '_' ) ) ; } , is_scalar ( $ features ) ? explode ( "," , $ features ) : $ features ) ) ; } $ options = [ 'index' => $ this -> index ( ) ] + $ options + ( $ features ? [ 'feature' => $ features ] : [ ] ) ; $ result = $ this -> client -> indices ( ) -> get ( $ options ) ; $ result = array_pop ( $ result ) ; return $ result ; }
Retreives the meta data of an index
56,978
public static function discoverAll ( ) { $ components = [ ] ; foreach ( ExtensionManagementUtility :: getLoadedExtensionListArray ( ) as $ extensionKey ) { $ components = array_merge ( $ components , self :: discoverExtensionComponents ( $ extensionKey ) ) ; } return $ components ; }
Discover all components
56,979
protected static function discoverExtensionComponents ( $ extensionKey ) { $ extCompRootDirectory = ExtensionManagementUtility :: extPath ( $ extensionKey , 'Components' ) ; return is_dir ( $ extCompRootDirectory ) ? self :: discoverExtensionComponentDirectory ( $ extCompRootDirectory ) : [ ] ; }
Discover the components of a single extension
56,980
protected static function discoverExtensionComponentDirectory ( $ directory ) { $ components = [ ] ; $ directoryIterator = new \ RecursiveDirectoryIterator ( $ directory ) ; $ recursiveIterator = new \ RecursiveIteratorIterator ( $ directoryIterator ) ; $ regexIterator = new \ RegexIterator ( $ recursiveIterator , PATH_SEPARATOR . '^' . preg_quote ( $ directory . DIRECTORY_SEPARATOR ) . '.+Component\.php$' . PATH_SEPARATOR , \ RecursiveRegexIterator :: GET_MATCH ) ; foreach ( $ regexIterator as $ component ) { foreach ( self :: discoverClassesInFile ( file_get_contents ( $ component [ 0 ] ) ) as $ className ) { $ classReflection = new \ ReflectionClass ( $ className ) ; if ( $ classReflection -> implementsInterface ( ComponentInterface :: class ) ) { $ components [ ] = self :: addLocalConfiguration ( $ component [ 0 ] , self :: discoverComponent ( $ className ) ) ; } } } return $ components ; }
Recursively scan a directory for components and return a component list
56,981
protected static function discoverClassesInFile ( $ phpCode ) { $ classes = array ( ) ; $ tokens = token_get_all ( $ phpCode ) ; $ gettingClassname = $ gettingNamespace = false ; $ namespace = '' ; $ lastToken = null ; for ( $ t = 0 , $ tokenCount = count ( $ tokens ) ; $ t < $ tokenCount ; ++ $ t ) { $ token = $ tokens [ $ t ] ; if ( is_array ( $ token ) && ( $ token [ 0 ] == T_NAMESPACE ) ) { $ namespace = '' ; $ gettingNamespace = true ; continue ; } if ( is_array ( $ token ) && ( $ token [ 0 ] == T_CLASS ) && ( ! is_array ( $ lastToken ) || ( $ lastToken [ 0 ] !== T_PAAMAYIM_NEKUDOTAYIM ) ) ) { $ gettingClassname = true ; } if ( $ gettingNamespace === true ) { if ( is_array ( $ token ) && in_array ( $ token [ 0 ] , [ T_STRING , T_NS_SEPARATOR ] ) ) { $ namespace .= $ token [ 1 ] ; } elseif ( $ token === ';' ) { $ gettingNamespace = false ; } } elseif ( $ gettingClassname === true ) { if ( is_array ( $ token ) && ( $ token [ 0 ] == T_STRING ) ) { $ classes [ ] = ( $ namespace ? $ namespace . '\\' : '' ) . $ token [ 1 ] ; $ gettingClassname = false ; } } $ lastToken = $ token ; } return $ classes ; }
Discover the classes declared in a file
56,982
protected static function addLocalConfiguration ( $ componentDirectory , array $ component ) { $ component [ 'local' ] = [ ] ; $ componentDirectories = [ ] ; for ( $ dir = 0 ; $ dir < count ( $ component [ 'path' ] ) ; ++ $ dir ) { $ componentDirectory = $ componentDirectories [ ] = dirname ( $ componentDirectory ) ; } foreach ( array_reverse ( $ componentDirectories ) as $ componentDirectory ) { $ component [ 'local' ] [ ] = self :: getLocalConfiguration ( $ componentDirectory ) ; } return $ component ; }
Amend the directory specific local configuration
56,983
protected static function getLocalConfiguration ( $ dirname ) { if ( is_dir ( $ dirname ) && empty ( self :: $ localConfigurations [ $ dirname ] ) ) { $ localConfig = $ dirname . DIRECTORY_SEPARATOR . 'local.json' ; self :: $ localConfigurations [ $ dirname ] = file_exists ( $ localConfig ) ? ( array ) @ \ json_decode ( file_get_contents ( $ localConfig ) ) : [ ] ; } return self :: $ localConfigurations [ $ dirname ] ; }
Read cache and return a directory specific local configuration
56,984
public function writeObject ( $ object ) { foreach ( $ object as $ key => & $ value ) { if ( $ key [ 0 ] == "_" ) continue ; $ this -> _stream -> writeUTF ( $ key ) ; $ this -> writeTypeMarker ( $ value ) ; } $ this -> _stream -> writeInt ( 0 ) ; $ this -> _stream -> writeByte ( Zend_Amf_Constants :: AMF0_OBJECTTERM ) ; return $ this ; }
Write a PHP array with string or mixed keys .
56,985
public function writeArray ( & $ array ) { $ length = count ( $ array ) ; if ( ! $ length < 0 ) { $ this -> _stream -> writeLong ( 0 ) ; } else { $ this -> _stream -> writeLong ( $ length ) ; for ( $ i = 0 ; $ i < $ length ; $ i ++ ) { $ value = isset ( $ array [ $ i ] ) ? $ array [ $ i ] : null ; $ this -> writeTypeMarker ( $ value ) ; } } return $ this ; }
Write a standard numeric array to the output stream . If a mixed array is encountered call writeTypeMarker with mixed array .
56,986
public function writeDate ( $ data ) { if ( $ data instanceof DateTime ) { $ dateString = $ data -> format ( 'U' ) ; } elseif ( $ data instanceof Zend_Date ) { $ dateString = $ data -> toString ( 'U' ) ; } else { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Invalid date specified; must be a DateTime or Zend_Date object' ) ; } $ dateString *= 1000 ; $ this -> _stream -> writeDouble ( $ dateString ) ; $ this -> _stream -> writeInt ( 0 ) ; return $ this ; }
Convert the DateTime into an AMF Date
56,987
public function writeTypedObject ( $ data ) { $ this -> _stream -> writeUTF ( $ this -> _className ) ; $ this -> writeObject ( $ data ) ; return $ this ; }
Write a class mapped object to the output stream .
56,988
public function writeAmf3TypeMarker ( & $ data ) { require_once 'Zend/Amf/Parse/Amf3/Serializer.php' ; $ serializer = new Zend_Amf_Parse_Amf3_Serializer ( $ this -> _stream ) ; $ serializer -> writeTypeMarker ( $ data ) ; return $ this ; }
Encountered and AMF3 Type Marker use AMF3 serializer . Once AMF3 is encountered it will not return to AMf0 .
56,989
protected function getClassName ( $ object ) { require_once 'Zend/Amf/Parse/TypeLoader.php' ; $ className = '' ; switch ( true ) { case Zend_Amf_Parse_TypeLoader :: getMappedClassName ( get_class ( $ object ) ) : $ className = Zend_Amf_Parse_TypeLoader :: getMappedClassName ( get_class ( $ object ) ) ; break ; case isset ( $ object -> _explicitType ) : $ className = $ object -> _explicitType ; break ; case method_exists ( $ object , 'getASClassName' ) : $ className = $ object -> getASClassName ( ) ; break ; case ( $ object instanceof stdClass ) : $ className = '' ; break ; default : $ className = get_class ( $ object ) ; break ; } if ( ! $ className == '' ) { return $ className ; } else { return false ; } }
Find if the class name is a class mapped name and return the respective classname if it is .
56,990
public static function extractTypoScriptKeyForPidAndType ( $ id , $ typeNum , $ key ) { $ key = trim ( $ key ) ; if ( ! strlen ( $ key ) ) { throw new \ RuntimeException ( sprintf ( 'Invalid TypoScript key "%s"' , $ key ) , 1481365294 ) ; } $ TSFE = self :: getTSFE ( $ id , $ typeNum ) ; list ( $ name , $ conf ) = GeneralUtility :: makeInstance ( TypoScriptParser :: class ) -> getVal ( $ key , $ TSFE -> tmpl -> setup ) ; $ lastKey = explode ( '.' , $ key ) ; $ lastKey = array_pop ( $ lastKey ) ; return [ $ lastKey => $ name , $ lastKey . '.' => $ conf ] ; }
Extract and return a TypoScript key for a particular page and type
56,991
public static function getTSFE ( $ id , $ typeNum ) { if ( ! is_object ( $ GLOBALS [ 'TT' ] ) ) { $ GLOBALS [ 'TT' ] = new TimeTracker ( false ) ; $ GLOBALS [ 'TT' ] -> start ( ) ; } if ( ! array_key_exists ( "$id/$typeNum" , self :: $ frontendControllers ) ) { $ tsfeBackup = empty ( $ GLOBALS [ 'TSFE' ] ) ? null : $ GLOBALS [ 'TSFE' ] ; $ GLOBALS [ 'TSFE' ] = GeneralUtility :: makeInstance ( TypoScriptFrontendController :: class , $ GLOBALS [ 'TYPO3_CONF_VARS' ] , $ id , $ typeNum ) ; $ GLOBALS [ 'TSFE' ] -> sys_page = GeneralUtility :: makeInstance ( PageRepository :: class ) ; $ GLOBALS [ 'TSFE' ] -> sys_page -> init ( true ) ; $ GLOBALS [ 'TSFE' ] -> connectToDB ( ) ; $ GLOBALS [ 'TSFE' ] -> initFEuser ( ) ; $ GLOBALS [ 'TSFE' ] -> determineId ( ) ; $ GLOBALS [ 'TSFE' ] -> initTemplate ( ) ; $ GLOBALS [ 'TSFE' ] -> rootLine = $ GLOBALS [ 'TSFE' ] -> sys_page -> getRootLine ( $ id , '' ) ; try { $ GLOBALS [ 'TSFE' ] -> getConfigArray ( ) ; } catch ( ServiceUnavailableException $ e ) { } if ( ! empty ( $ GLOBALS [ 'TSFE' ] -> config [ 'config' ] [ 'absRefPrefix' ] ) ) { $ absRefPrefix = trim ( $ GLOBALS [ 'TSFE' ] -> config [ 'config' ] [ 'absRefPrefix' ] ) ; $ GLOBALS [ 'TSFE' ] -> absRefPrefix = ( $ absRefPrefix === 'auto' ) ? GeneralUtility :: getIndpEnv ( 'TYPO3_SITE_PATH' ) : $ absRefPrefix ; } else { $ GLOBALS [ 'TSFE' ] -> absRefPrefix = '' ; } self :: $ frontendControllers [ "$id/$typeNum" ] = $ GLOBALS [ 'TSFE' ] ; if ( $ tsfeBackup ) { $ GLOBALS [ 'TSFE' ] = $ tsfeBackup ; } else { unset ( $ GLOBALS [ 'TSFE' ] ) ; } } return self :: $ frontendControllers [ "$id/$typeNum" ] ; }
Instantiate a Frontend controller for the given configuration
56,992
public static function serialize ( $ prefix , array $ typoscript , $ indent = 0 ) { $ serialized = [ ] ; ksort ( $ typoscript , SORT_NATURAL ) ; foreach ( $ typoscript as $ key => $ value ) { $ line = str_repeat ( ' ' , $ indent * 4 ) ; $ line .= trim ( strlen ( $ prefix ) ? "$prefix.$key" : $ key , '.' ) ; if ( is_array ( $ value ) ) { if ( count ( $ value ) === 1 ) { $ line .= '.' . self :: serialize ( '' , $ value , 0 ) ; } else { $ line .= ' {' . PHP_EOL . self :: serialize ( '' , $ value , $ indent + 1 ) . PHP_EOL . '}' ; } } elseif ( preg_match ( '/\R/' , $ value ) ) { $ line .= ' (' . PHP_EOL . $ value . PHP_EOL . ')' ; } else { $ line .= ' = ' . $ value ; } $ serialized [ ] = $ line ; } return implode ( PHP_EOL , $ serialized ) ; }
Serialize a TypoScript fragment
56,993
public function getSteamID64 ( ) { if ( PHP_INT_SIZE == 4 ) { $ ret = new Math_BigInteger ( ) ; $ ret = $ ret -> add ( ( new Math_BigInteger ( $ this -> universe ) ) -> bitwise_leftShift ( 56 ) ) ; $ ret = $ ret -> add ( ( new Math_BigInteger ( $ this -> type ) ) -> bitwise_leftShift ( 52 ) ) ; $ ret = $ ret -> add ( ( new Math_BigInteger ( $ this -> instance ) ) -> bitwise_leftShift ( 32 ) ) ; $ ret = $ ret -> add ( new Math_BigInteger ( $ this -> accountid ) ) ; return $ ret -> toString ( ) ; } return ( string ) ( ( $ this -> universe << 56 ) | ( $ this -> type << 52 ) | ( $ this -> instance << 32 ) | ( $ this -> accountid ) ) ; }
Gets the SteamID as a 64 - bit integer
56,994
public static function makeForQueryInstance ( Query $ instance , array $ query = [ ] ) { $ query = static :: make ( $ query ) ; return $ query -> setQueryInstance ( $ instance ) ; }
Initiates a new query builder for a specific Query instance
56,995
public function getEditForm ( $ id = null , $ fields = null ) { $ defaultPanel = Config :: inst ( ) -> get ( 'AdminRootController' , 'default_panel' ) ; if ( $ defaultPanel == 'CodeBank' ) { $ defaultPanel = 'SecurityAdmin' ; $ sng = singleton ( $ defaultPanel ) ; } $ fields = new FieldList ( new TabSet ( 'Root' , new Tab ( 'Main' , new HeaderField ( 'IPMessageTitle' , _t ( 'CodeBank.IP_MESSAGE_TITLE' , '_You must agree to the following terms before using Code Bank' ) , 2 ) , new LiteralField ( 'IPMessage' , '<div class="ipMessage"><div class="middleColumn">' . CodeBankConfig :: CurrentConfig ( ) -> dbObject ( 'IPMessage' ) -> forTemplate ( ) . '</div></div>' ) , new HiddenField ( 'RedirectLink' , 'RedirectLink' , $ sng -> Link ( ) ) ) ) ) ; if ( Session :: get ( 'CodeBankIPAgreed' ) === true ) { $ fields -> addFieldToTab ( 'Root.Main' , new HiddenField ( 'AgreementAgreed' , 'AgreementAgreed' , Session :: get ( 'CodeBankIPAgreed' ) ) ) ; } $ actions = new FieldList ( FormAction :: create ( 'doDisagree' , _t ( 'CodeBankIPAgreement.DISAGREE' , '_Disagree' ) ) -> addExtraClass ( 'ss-ui-action-destructive' ) , FormAction :: create ( 'doAgree' , _t ( 'CodeBankIPAgreement.AGREE' , '_Agree' ) ) -> addExtraClass ( 'ss-ui-action-constructive' ) ) ; $ form = CMSForm :: create ( $ this , 'EditForm' , $ fields , $ actions ) -> setHTMLID ( 'Form_EditForm' ) ; $ form -> disableDefaultAction ( ) ; $ form -> addExtraClass ( 'cms-edit-form' ) ; $ form -> setTemplate ( $ this -> getTemplatesWithSuffix ( '_EditForm' ) ) ; $ form -> addExtraClass ( 'center ' . $ this -> BaseCSSClasses ( ) ) ; $ form -> setAttribute ( 'data-pjax-fragment' , 'CurrentForm' ) ; if ( CB_VERSION != '@@VERSION@@' && CodeBankConfig :: CurrentConfig ( ) -> Version != CB_VERSION . ' ' . CB_BUILD_DATE ) { $ form -> setMessage ( _t ( 'CodeBank.UPDATE_NEEDED' , '_A database upgrade is required please run {startlink}dev/build{endlink}.' , array ( 'startlink' => '<a href="dev/build?flush=all">' , 'endlink' => '</a>' ) ) , 'error' ) ; } else if ( $ this -> hasOldTables ( ) ) { $ form -> setMessage ( _t ( 'CodeBank.MIGRATION_AVAILABLE' , '_It appears you are upgrading from Code Bank 2.2.x, your old data can be migrated {startlink}click here to begin{endlink}, though it is recommended you backup your database first.' , array ( 'startlink' => '<a href="dev/tasks/CodeBankLegacyMigrate">' , 'endlink' => '</a>' ) ) , 'warning' ) ; } $ form -> Actions ( ) -> push ( new LiteralField ( 'CodeBankVersion' , '<p class="codeBankVersion">Code Bank: ' . $ this -> getVersion ( ) . '</p>' ) ) ; Requirements :: javascript ( CB_DIR . '/javascript/CodeBank.IPMessage.js' ) ; return $ form ; }
Gets the form used for agreeing or disagreeing to the ip agreement
56,996
protected function addElementError ( $ message ) { if ( $ this -> element === null ) { throw new \ RuntimeException ( 'Create a form element prior to adding a validation error' , 1519731421 ) ; } $ this -> addError ( $ this -> element -> getIdentifier ( ) , $ message ) ; }
Register a validation error for the form element
56,997
public function doAdd ( $ data , Form $ form ) { $ record = $ this -> getRecord ( null ) ; $ form -> saveInto ( $ record ) ; $ record -> write ( ) ; $ editController = singleton ( 'CodeBank' ) ; $ editController -> setCurrentPageID ( $ record -> ID ) ; return $ this -> redirect ( Controller :: join_links ( singleton ( 'CodeBank' ) -> Link ( 'show' ) , $ record -> ID ) ) ; }
Handles adding the snippet to the database
56,998
public function getContents ( ) { if ( $ this -> offset !== - 1 ) { $ this -> stream -> seek ( $ this -> offset ) ; } if ( $ this -> maxLength !== - 1 ) { return $ this -> stream -> read ( $ this -> maxLength ) ; } return $ this -> stream -> getContents ( ) ; }
Return the contents of the file
56,999
public function addListener ( Listener $ listener ) : void { $ this -> listeners = $ this -> listeners -> add ( $ listener ) ; }
add an event listener to the dispatcher