idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
57,100
public function AddPackageForm ( ) { $ sng = singleton ( 'SnippetPackage' ) ; $ fields = new FieldList ( new TabSet ( 'Root' , new Tab ( 'Main' , _t ( 'PackageSelectionField.MAIN' , '_Main' ) , new TextField ( 'Title' , _t ( 'PackageSelectionField.TITLE' , '_Title' ) , null , 300 ) ) ) ) ; $ actions = new FieldList ( FormAction :: create ( 'doAddPackage' , _t ( 'PackageSelectionField.CREATE' , '_Create' ) ) -> addExtraClass ( 'ss-ui-action-constructive' ) -> setAttribute ( 'data-icon' , 'accept' ) -> setUseButtonTag ( true ) ) ; $ validator = new RequiredFields ( 'Title' ) ; return Form :: create ( $ this , 'AddPackageForm' , $ fields , $ actions , $ validator ) -> addExtraClass ( 'member-profile-form' ) -> setFormAction ( $ this -> Link ( 'AddPackageForm' ) ) ; }
Generates the form for adding packages
57,101
public function doAddPackage ( $ data , Form $ form ) { $ record = new SnippetPackage ( ) ; if ( $ record -> canEdit ( ) ) { $ form -> saveInto ( $ record ) ; $ record -> write ( ) ; Requirements :: customScript ( "window.parent.jQuery('#" . $ this -> getName ( ) . "').entwine('ss').handleSuccessResult(" . $ record -> ID . ");" ) ; return $ this -> renderWith ( 'CMSDialog' , array ( 'Form' => '' ) ) ; } return Controller :: curr ( ) -> redirectBack ( ) ; }
Handles adding of the package
57,102
public function readInteger ( ) { $ count = 1 ; $ intReference = $ this -> _stream -> readByte ( ) ; $ result = 0 ; while ( ( ( $ intReference & 0x80 ) != 0 ) && $ count < 4 ) { $ result <<= 7 ; $ result |= ( $ intReference & 0x7f ) ; $ intReference = $ this -> _stream -> readByte ( ) ; $ count ++ ; } if ( $ count < 4 ) { $ result <<= 7 ; $ result |= $ intReference ; } else { $ result <<= 8 ; $ result |= $ intReference ; if ( ( $ result & 0x10000000 ) != 0 ) { $ result |= ~ 0xFFFFFFF ; } } return $ result ; }
Read and deserialize an integer
57,103
public function readString ( ) { $ stringReference = $ this -> readInteger ( ) ; if ( ( $ stringReference & 0x01 ) == 0 ) { $ stringReference = $ stringReference >> 1 ; if ( $ stringReference >= count ( $ this -> _referenceStrings ) ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Undefined string reference: ' . $ stringReference ) ; } return $ this -> _referenceStrings [ $ stringReference ] ; } $ length = $ stringReference >> 1 ; if ( $ length ) { $ string = $ this -> _stream -> readBytes ( $ length ) ; $ this -> _referenceStrings [ ] = $ string ; } else { $ string = "" ; } return $ string ; }
Read and deserialize a string
57,104
public function readDate ( ) { $ dateReference = $ this -> readInteger ( ) ; if ( ( $ dateReference & 0x01 ) == 0 ) { $ dateReference = $ dateReference >> 1 ; if ( $ dateReference >= count ( $ this -> _referenceObjects ) ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Undefined date reference: ' . $ dateReference ) ; } return $ this -> _referenceObjects [ $ dateReference ] ; } $ timestamp = floor ( $ this -> _stream -> readDouble ( ) / 1000 ) ; require_once 'Zend/Date.php' ; $ dateTime = new Zend_Date ( $ timestamp ) ; $ this -> _referenceObjects [ ] = $ dateTime ; return $ dateTime ; }
Read and deserialize a date
57,105
public function readArray ( ) { $ arrayReference = $ this -> readInteger ( ) ; if ( ( $ arrayReference & 0x01 ) == 0 ) { $ arrayReference = $ arrayReference >> 1 ; if ( $ arrayReference >= count ( $ this -> _referenceObjects ) ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Unknow array reference: ' . $ arrayReference ) ; } return $ this -> _referenceObjects [ $ arrayReference ] ; } $ data = array ( ) ; $ this -> _referenceObjects [ ] = & $ data ; $ key = $ this -> readString ( ) ; while ( $ key != '' ) { $ data [ $ key ] = $ this -> readTypeMarker ( ) ; $ key = $ this -> readString ( ) ; } $ arrayReference = $ arrayReference >> 1 ; for ( $ i = 0 ; $ i < $ arrayReference ; $ i ++ ) { $ data [ ] = $ this -> readTypeMarker ( ) ; } return $ data ; }
Read amf array to PHP array
57,106
public function readXmlString ( ) { $ xmlReference = $ this -> readInteger ( ) ; $ length = $ xmlReference >> 1 ; $ string = $ this -> _stream -> readBytes ( $ length ) ; return simplexml_load_string ( $ string ) ; }
Convert XML to SimpleXml If user wants DomDocument they can use dom_import_simplexml
57,107
public function guessMimeType ( $ filepath ) { $ magic_file = $ this -> getFileManager ( ) -> getMagicFile ( ) ; $ mimetype = finfo_file ( finfo_open ( FILEINFO_MIME_TYPE , $ magic_file ) , $ filepath ) ; $ extension = pathinfo ( $ filepath , PATHINFO_EXTENSION ) ; $ match_extension = $ this -> matchMimetypeExtension ( $ mimetype , $ extension ) ; if ( $ mimetype == "application/octet-stream" || ! $ match_extension ) { $ mimetype = finfo_file ( finfo_open ( FILEINFO_MIME_TYPE ) , $ filepath ) ; } $ this -> setMimetype ( $ mimetype ) ; if ( isset ( self :: $ humanReadableTypes [ $ mimetype ] ) ) { $ this -> setReadableType ( self :: $ humanReadableTypes [ $ mimetype ] ) ; } else { $ this -> setReadableType ( "Undefined" ) ; } $ this -> setFileclass ( $ mimetype ) ; }
Try to guess the mimetypes first with a custom magic file . This fix the problems with wrong mime type detection .
57,108
public function matchMimetypeExtension ( $ mimetype , $ extension ) { $ mime_extensions = self :: $ mimetypes_extensions ; if ( isset ( $ mime_extensions [ $ extension ] ) && $ mime_extensions [ $ extension ] == $ mimetype ) { return true ; } return false ; }
Check if the mimetype match with the extension
57,109
public function setFileclass ( $ mimetype ) { switch ( $ mimetype ) { case 'directory' : $ fileclass = "dir" ; $ this -> is_dir = true ; break ; case 'application/pdf' : $ fileclass = "pdf" ; break ; case 'application/zip' : case 'application/x-gzip' : case 'application/x-bzip2' : case 'application/x-zip' : case 'application/x-rar' : case 'application/x-tar' : $ fileclass = "zip" ; break ; case 'video/mp4' : case 'video/ogg' : case 'video/mpeg' : case 'application/ogg' : $ fileclass = "video" ; $ this -> is_video = true ; break ; case 'audio/ogg' : case 'audio/mpeg' : $ fileclass = "audio" ; $ this -> is_audio = true ; break ; case 'image/jpeg' : case 'image/jpg' : case 'image/gif' : case 'image/png' : $ fileclass = "image" ; $ this -> is_image = true ; break ; case 'image/svg+xml' : $ fileclass = "svg" ; $ this -> is_image = true ; break ; case 'text/x-shellscript' : $ fileclass = 'shellscript' ; break ; case 'text/html' : case 'text/javascript' : case 'text/css' : case 'text/xml' : case 'application/javascript' : case 'application/xml' : $ fileclass = "code" ; break ; case 'text/x-php' : $ fileclass = "php" ; break ; case 'application/x-shockwave-flash' : $ fileclass = 'swf' ; break ; default : $ fileclass = "default" ; break ; } $ this -> fileclass = $ fileclass ; }
Set the file class
57,110
public function getFilepath ( $ include_filename = false ) { $ filepath = $ this -> filepath ; if ( $ include_filename ) { $ filepath .= FileManager :: DS . $ this -> getFilename ( ) ; } return $ filepath ; }
Returns the full path to the file
57,111
public function setUsages ( FileManager $ file_manager ) { $ usages = array ( ) ; $ usage_class = $ file_manager -> getUsagesClass ( ) ; if ( $ usage_class != false ) { $ usage_object = new $ usage_class ; $ usages_result = $ usage_object -> returnUsages ( $ this -> getFilepath ( true ) ) ; if ( ! empty ( $ usages_result ) ) { $ usages = $ usages_result ; } } $ this -> usages = count ( $ usages ) ; }
Set the locations where the file is used in an array .
57,112
public function getWebPath ( $ trim = false ) { if ( $ trim ) { return trim ( $ this -> web_path , FileManager :: DS ) ; } else { return $ this -> web_path ; } }
Returns the web path of the file
57,113
public function manipulateCacheActions ( & $ cacheActions , & $ optionValues ) { $ extensionConfiguration = $ GLOBALS [ 'TYPO3_CONF_VARS' ] [ 'EXT' ] [ 'extParams' ] [ 'tw_componentlibrary' ] ; if ( $ GLOBALS [ 'BE_USER' ] -> isAdmin ( ) && ! empty ( $ extensionConfiguration [ 'componentlibrary' ] ) ) { $ componentLibrary = $ extensionConfiguration [ 'componentlibrary' ] ; $ cacheActions [ ] = array ( 'id' => $ componentLibrary , 'title' => 'LLL:EXT:tw_componentlibrary/Resources/Private/Language/locallang_core.xlf:cache.' . $ componentLibrary . '.title' , 'description' => 'LLL:EXT:tw_componentlibrary/Resources/Private/Language/locallang_core.xlf:cache.' . $ componentLibrary . '.description' , 'href' => '/typo3/index.php?route=%2F' . $ componentLibrary , 'iconIdentifier' => 'tx_twcomponentlibrary_cache' ) ; } }
Add an entry to the CacheMenuItems array
57,114
public function get ( string $ name ) : Projection { return $ this -> projections -> filter ( function ( Projection $ projection ) use ( $ name ) { return $ projection -> name ( ) === $ name ; } ) -> first ( ) ; }
retrieve a projection based on its string name
57,115
public function handle ( DomainEvent $ event ) : void { $ this -> projections -> each ( function ( Projection $ projection ) use ( $ event ) { $ projection -> handle ( $ event ) ; } ) ; }
receive a domain event and hand it off to every projection
57,116
public function createFileManager ( array $ parameters , $ driver , $ dir_path = null ) { $ file_manager = new FileManager ( $ parameters , $ driver , $ this -> container ) ; $ this -> file_manager = $ file_manager ; $ file_manager -> setDirPaths ( $ dir_path ) ; $ this -> setDisplayType ( ) ; return $ file_manager ; }
Create the file manager object
57,117
public function getFilePath ( FileManager $ file_manager ) { $ current_file = $ file_manager -> getCurrentFile ( ) ; $ target_file = $ file_manager -> getTargetFile ( ) ; if ( ( $ current_file -> getFilename ( ) == "" && ! is_null ( $ target_file -> getFilename ( ) ) ) ) { throw new \ Exception ( "Filename cannot be empty when there is a target file" ) ; } $ root = $ file_manager -> getUploadPath ( ) ; $ dir_path = $ file_manager -> getDirPath ( ) ; if ( empty ( $ dir_path ) ) { $ dir = $ root ; } else { if ( strcasecmp ( "../" , $ dir_path ) >= 1 ) { throw new \ Exception ( "Invalid filepath or filename" ) ; } $ dir = $ this -> getFileManager ( ) -> DirTrim ( $ root , $ dir_path , true ) ; } try { $ file_manager -> checkPath ( $ dir ) ; if ( ! is_null ( $ target_file ) ) { $ file_manager -> checkPath ( $ target_file -> getFilepath ( true ) ) ; } } catch ( \ Exception $ e ) { throw new \ Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } return $ dir ; }
Get and check the current file path
57,118
public function checkToken ( $ request_token ) { $ token_manager = $ this -> container -> get ( 'security.csrf.token_manager' ) ; $ token = new CsrfToken ( 'file_manager' , $ request_token ) ; $ valid = $ token_manager -> isTokenValid ( $ token ) ; if ( ! $ valid ) { throw new InvalidCsrfTokenException ( ) ; } }
Check if the form token is valid
57,119
public function getRenderOptions ( Form $ form ) { $ file_manager = $ this -> getFileManager ( ) ; $ dir_files = scandir ( $ file_manager -> getDir ( ) ) ; $ root_dirs = scandir ( $ file_manager -> getUploadPath ( ) ) ; $ is_popup = $ this -> container -> get ( 'request' ) -> get ( 'popup' ) ? true : false ; $ options [ 'files' ] = $ this -> getFiles ( $ dir_files ) ; $ options [ 'file_body_display' ] = $ file_manager -> getDisplayType ( ) ; $ options [ 'dirs' ] = $ this -> getDirectoryTree ( $ root_dirs , $ file_manager -> getUploadPath ( ) , "" ) ; $ options [ 'isPopup' ] = $ is_popup ; $ options [ 'copy_file' ] = $ this -> container -> get ( 'session' ) -> get ( 'copy' ) ; $ options [ 'form' ] = $ form -> createView ( ) ; $ options [ 'copy_type' ] = FileManager :: FILE_COPY ; $ options [ 'cut_type' ] = FileManager :: FILE_CUT ; $ options [ 'root_folder' ] = $ file_manager -> getPath ( ) ; $ options [ 'current_path' ] = $ file_manager -> getDirPath ( ) ; $ options [ 'upload_allow' ] = $ file_manager -> getExtensionsAllowed ( ) ; $ options [ 'usages' ] = $ file_manager -> getUsagesClass ( ) ; $ options [ 'theme_css' ] = $ file_manager -> getThemeCss ( ) ; return $ options ; }
Returns an array with all the rendered options
57,120
public function getFiles ( array $ dir_files , $ files = array ( ) ) { foreach ( $ dir_files as $ file ) { $ filepath = $ this -> getFileManager ( ) -> DirTrim ( $ this -> getFileManager ( ) -> getDir ( ) , $ file , true ) ; if ( $ file [ 0 ] != "." ) { $ files [ ] = new FileInfo ( $ filepath , $ this -> getFileManager ( ) ) ; } } return $ files ; }
Returns all files in the current directory
57,121
public function setDisplayType ( ) { $ file_manager = $ this -> getFileManager ( ) ; $ session = $ this -> container -> get ( 'session' ) ; $ display_type = $ session -> get ( self :: DISPLAY_TYPE_SESSION ) ; if ( $ this -> container -> get ( 'request' ) -> get ( 'display_type' ) != null ) { $ display_type = $ this -> container -> get ( 'request' ) -> get ( 'display_type' ) ; $ session -> set ( self :: DISPLAY_TYPE_SESSION , $ display_type ) ; } else { if ( is_null ( $ display_type ) ) { $ display_type = self :: DISPLAY_TYPE_BLOCK ; } } $ file_body_display = $ display_type !== null ? $ display_type : self :: DISPLAY_TYPE_BLOCK ; $ file_manager -> setDisplayType ( $ file_body_display ) ; }
Set the display type
57,122
public function getDirectoryTree ( $ dir_files , $ dir , $ dir_path , $ dirs = array ( ) ) { foreach ( $ dir_files as $ file ) { $ filepath = $ this -> getFileManager ( ) -> DirTrim ( $ dir , $ file , true ) ; if ( $ file [ 0 ] != "." ) { if ( is_dir ( $ filepath ) ) { $ new_dir_files = scandir ( $ filepath ) ; $ new_dir_path = $ this -> getFileManager ( ) -> DirTrim ( $ dir_path , $ file , true ) ; $ new_dir = $ this -> getFileManager ( ) -> getUploadPath ( ) . FileManager :: DS . $ this -> getFileManager ( ) -> DirTrim ( $ new_dir_path ) ; $ fileType = "directory" ; $ tmp_array = array ( "mimetype" => $ fileType , "name" => $ file , "path" => $ this -> getFileManager ( ) -> DirTrim ( $ new_dir_path ) , "tree" => $ this -> getDirectoryTree ( $ new_dir_files , $ new_dir , $ new_dir_path , array ( ) ) , ) ; $ dirs [ ] = $ tmp_array ; } } } return $ dirs ; }
Returns the directory tree of the given path . This will loop itself until it has all directories
57,123
public function handleAction ( FileManager $ fileManager , Request $ request , $ action ) { $ response = new Response ( ) ; try { $ dir = $ this -> getFilePath ( $ fileManager ) ; $ fileManager -> setDir ( $ dir ) ; $ fileManager -> checkPath ( ) ; if ( $ request -> getMethod ( ) === 'POST' ) { $ this -> checkToken ( $ request -> get ( 'token' ) ) ; } switch ( $ action ) { case FileManager :: FILE_DELETE : $ fileManager -> deleteFile ( ) ; break ; case FileManager :: FILE_MOVE : $ fileManager -> moveFile ( ) ; break ; case FileManager :: FILE_EXTRACT : $ fileManager -> extractZip ( ) ; break ; case FileManager :: FILE_RENAME : $ fileManager -> renameFile ( ) ; break ; case FileManager :: FILE_NEW_DIR : $ fileManager -> newDirectory ( ) ; break ; case FileManager :: FILE_COPY : case FileManager :: FILE_CUT : $ this -> copyFile ( $ action ) ; break ; case FileManager :: FILE_PASTE : $ this -> pasteFile ( ) ; break ; case FileManager :: FILE_INFO : $ response = new JsonResponse ( ) ; $ response -> setData ( json_encode ( $ fileManager -> getCurrentFile ( ) -> toArray ( ) ) ) ; break ; } } catch ( \ Exception $ e ) { $ response -> setContent ( $ e -> getMessage ( ) ) ; $ response -> setStatusCode ( $ e -> getCode ( ) == null ? 500 : $ e -> getCode ( ) ) ; } return $ response ; }
Validates the request and handles the action
57,124
public function doDelete ( $ data , Form $ form ) { $ record = $ this -> currentPage ( ) ; if ( $ record -> canDelete ( ) ) { Session :: set ( 'CodeBank.deletedSnippetID' , $ record -> ID ) ; $ record -> delete ( ) ; $ this -> response -> addHeader ( 'X-Status' , rawurlencode ( _t ( 'CodeBank.SNIPPET_DELETED' , '_Snippet has been deleted' ) ) ) ; } else { $ this -> response -> addHeader ( 'X-Status' , rawurlencode ( _t ( 'CodeBank.PERMISSION_DENIED' , '_Permission Denied' ) ) ) ; } $ this -> redirect ( 'admin/codeBank/' ) ; return $ this -> getResponseNegotiator ( ) -> respond ( $ this -> request ) ; }
Deletes the snippet from the database
57,125
public function writeMessage ( Zend_Amf_Parse_OutputStream $ stream ) { $ objectEncoding = $ this -> _objectEncoding ; $ stream -> writeByte ( 0x00 ) ; $ stream -> writeByte ( $ objectEncoding ) ; $ headerCount = count ( $ this -> _headers ) ; $ stream -> writeInt ( $ headerCount ) ; foreach ( $ this -> getAmfHeaders ( ) as $ header ) { $ serializer = new Zend_Amf_Parse_Amf0_Serializer ( $ stream ) ; $ stream -> writeUTF ( $ header -> name ) ; $ stream -> writeByte ( $ header -> mustRead ) ; $ stream -> writeLong ( Zend_Amf_Constants :: UNKNOWN_CONTENT_LENGTH ) ; if ( is_object ( $ header -> data ) ) { $ placeholder = null ; $ serializer -> writeTypeMarker ( $ placeholder , null , $ header -> data ) ; } else { $ serializer -> writeTypeMarker ( $ header -> data ) ; } } $ bodyCount = count ( $ this -> _bodies ) ; $ stream -> writeInt ( $ bodyCount ) ; foreach ( $ this -> _bodies as $ body ) { $ serializer = new Zend_Amf_Parse_Amf0_Serializer ( $ stream ) ; $ stream -> writeUTF ( $ body -> getTargetURI ( ) ) ; $ stream -> writeUTF ( $ body -> getResponseURI ( ) ) ; $ stream -> writeLong ( Zend_Amf_Constants :: UNKNOWN_CONTENT_LENGTH ) ; $ bodyData = $ body -> getData ( ) ; $ markerType = ( $ this -> _objectEncoding == Zend_Amf_Constants :: AMF0_OBJECT_ENCODING ) ? null : Zend_Amf_Constants :: AMF0_AMF3 ; if ( is_object ( $ bodyData ) ) { $ placeholder = null ; $ serializer -> writeTypeMarker ( $ placeholder , $ markerType , $ bodyData ) ; } else { $ serializer -> writeTypeMarker ( $ bodyData , $ markerType ) ; } } return $ this ; }
Serialize the PHP data types back into Actionscript and create and AMF stream .
57,126
public function setCallback ( $ callback ) { if ( is_array ( $ callback ) ) { require_once 'Zend/Server/Method/Callback.php' ; $ callback = new Zend_Server_Method_Callback ( $ callback ) ; } elseif ( ! $ callback instanceof Zend_Server_Method_Callback ) { require_once 'Zend/Server/Exception.php' ; throw new Zend_Server_Exception ( 'Invalid method callback provided' ) ; } $ this -> _callback = $ callback ; return $ this ; }
Set method callback
57,127
public function addPrototype ( $ prototype ) { if ( is_array ( $ prototype ) ) { require_once 'Zend/Server/Method/Prototype.php' ; $ prototype = new Zend_Server_Method_Prototype ( $ prototype ) ; } elseif ( ! $ prototype instanceof Zend_Server_Method_Prototype ) { require_once 'Zend/Server/Exception.php' ; throw new Zend_Server_Exception ( 'Invalid method prototype provided' ) ; } $ this -> _prototypes [ ] = $ prototype ; return $ this ; }
Add prototype to method definition
57,128
public function setObject ( $ object ) { if ( ! is_object ( $ object ) && ( null !== $ object ) ) { require_once 'Zend/Server/Exception.php' ; throw new Zend_Server_Exception ( 'Invalid object passed to ' . __CLASS__ . '::' . __METHOD__ ) ; } $ this -> _object = $ object ; return $ this ; }
Set object to use with method calls
57,129
public function toArray ( ) { $ prototypes = $ this -> getPrototypes ( ) ; $ signatures = array ( ) ; foreach ( $ prototypes as $ prototype ) { $ signatures [ ] = $ prototype -> toArray ( ) ; } return array ( 'name' => $ this -> getName ( ) , 'callback' => $ this -> getCallback ( ) -> toArray ( ) , 'prototypes' => $ signatures , 'methodHelp' => $ this -> getMethodHelp ( ) , 'invokeArguments' => $ this -> getInvokeArguments ( ) , 'object' => $ this -> getObject ( ) , ) ; }
Serialize to array
57,130
public function authenticate ( ) { $ optionsRequired = array ( 'filename' , 'realm' , 'username' , 'password' ) ; foreach ( $ optionsRequired as $ optionRequired ) { if ( null === $ this -> { "_$optionRequired" } ) { require_once 'Zend/Auth/Adapter/Exception.php' ; throw new Zend_Auth_Adapter_Exception ( "Option '$optionRequired' must be set before authentication" ) ; } } if ( false === ( $ fileHandle = @ fopen ( $ this -> _filename , 'r' ) ) ) { require_once 'Zend/Auth/Adapter/Exception.php' ; throw new Zend_Auth_Adapter_Exception ( "Cannot open '$this->_filename' for reading" ) ; } $ id = "$this->_username:$this->_realm" ; $ idLength = strlen ( $ id ) ; $ result = array ( 'code' => Zend_Auth_Result :: FAILURE , 'identity' => array ( 'realm' => $ this -> _realm , 'username' => $ this -> _username , ) , 'messages' => array ( ) ) ; while ( $ line = trim ( fgets ( $ fileHandle ) ) ) { if ( substr ( $ line , 0 , $ idLength ) === $ id ) { if ( $ this -> _secureStringCompare ( substr ( $ line , - 32 ) , md5 ( "$this->_username:$this->_realm:$this->_password" ) ) ) { $ result [ 'code' ] = Zend_Auth_Result :: SUCCESS ; } else { $ result [ 'code' ] = Zend_Auth_Result :: FAILURE_CREDENTIAL_INVALID ; $ result [ 'messages' ] [ ] = 'Password incorrect' ; } return new Zend_Auth_Result ( $ result [ 'code' ] , $ result [ 'identity' ] , $ result [ 'messages' ] ) ; } } $ result [ 'code' ] = Zend_Auth_Result :: FAILURE_IDENTITY_NOT_FOUND ; $ result [ 'messages' ] [ ] = "Username '$this->_username' and realm '$this->_realm' combination not found" ; return new Zend_Auth_Result ( $ result [ 'code' ] , $ result [ 'identity' ] , $ result [ 'messages' ] ) ; }
Defined by Zend_Auth_Adapter_Interface
57,131
public static function parse ( $ arguments , $ content = null , $ parser = null ) { if ( ! array_key_exists ( 'id' , $ arguments ) ) { return '<p><b><i>' . _t ( 'CodeBankShortCode.MISSING_ID_ATTRIBUTE' , '_Short Code missing the id attribute' ) . '</i></b></p>' ; } $ snippet = Snippet :: get ( ) -> byID ( intval ( $ arguments [ 'id' ] ) ) ; if ( empty ( $ snippet ) || $ snippet === false || $ snippet -> ID == 0 ) { return '<p><b><i>' . _t ( 'CodeBankShortCode.SNIPPET_NOT_FOUND' , '_Snippet not found' ) . '</i></b></p>' ; } $ snippetText = $ snippet -> SnippetText ; if ( array_key_exists ( 'version' , $ arguments ) ) { $ version = $ snippet -> Version ( intval ( $ arguments [ 'version' ] ) ) ; if ( empty ( $ version ) || $ version === false || $ version -> ID == 0 ) { $ snippetText = $ version -> Text ; } } Requirements :: css ( CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCore.css' ) ; Requirements :: css ( CB_DIR . '/javascript/external/syntaxhighlighter/themes/shCoreDefault.css' ) ; Requirements :: css ( CB_DIR . '/javascript/external/syntaxhighlighter/themes/shThemeDefault.css' ) ; Requirements :: javascript ( THIRDPARTY_DIR . '/jquery/jquery.js' ) ; Requirements :: javascript ( CB_DIR . '/javascript/external/syntaxhighlighter/brushes/shCore.js' ) ; Requirements :: javascript ( CB_DIR . '/javascript/external/syntaxhighlighter/brushes/' . self :: getBrushName ( $ snippet -> Language ( ) -> HighlightCode ) . '.js' ) ; Requirements :: javascriptTemplate ( CB_DIR . '/javascript/CodeBankShortCode.template.js' , array ( 'ID' => $ snippet -> ID ) , 'snippet-highlightinit-' . $ snippet -> ID ) ; $ obj = new ViewableData ( ) ; return $ obj -> renderWith ( 'CodeBankShortCode' , array ( 'ID' => $ snippet -> ID , 'Title' => $ snippet -> getField ( 'Title' ) , 'Description' => $ snippet -> getField ( 'Description' ) , 'SnippetText' => DBField :: create_field ( 'Text' , $ snippetText ) , 'HighlightCode' => strtolower ( $ snippet -> Language ( ) -> HighlightCode ) ) ) ; }
Parses the snippet short code
57,132
protected function _setupPrimaryAssignment ( ) { if ( $ this -> _primaryAssignment === null ) { $ this -> _primaryAssignment = array ( 1 => self :: PRIMARY_ASSIGNMENT_SESSION_ID ) ; } else if ( ! is_array ( $ this -> _primaryAssignment ) ) { $ this -> _primaryAssignment = array ( 1 => ( string ) $ this -> _primaryAssignment ) ; } else if ( isset ( $ this -> _primaryAssignment [ 0 ] ) ) { array_unshift ( $ this -> _primaryAssignment , null ) ; unset ( $ this -> _primaryAssignment [ 0 ] ) ; } if ( count ( $ this -> _primaryAssignment ) !== count ( $ this -> _primary ) ) { require_once 'Zend/Session/SaveHandler/Exception.php' ; throw new Zend_Session_SaveHandler_Exception ( "Value for configuration option '" . self :: PRIMARY_ASSIGNMENT . "' must have an assignment " . "for each session table primary key." ) ; } else if ( ! in_array ( self :: PRIMARY_ASSIGNMENT_SESSION_ID , $ this -> _primaryAssignment ) ) { require_once 'Zend/Session/SaveHandler/Exception.php' ; throw new Zend_Session_SaveHandler_Exception ( "Value for configuration option '" . self :: PRIMARY_ASSIGNMENT . "' must have an assignment " . "for the session id ('" . self :: PRIMARY_ASSIGNMENT_SESSION_ID . "')." ) ; } }
Initialize session table primary key value assignment
57,133
public function toDomainEvents ( ) : DomainEvents { return DomainEvents :: make ( $ this -> map ( function ( StreamEvent $ streamEvent ) { return $ streamEvent -> event ( ) ; } ) -> toArray ( ) ) ; }
return a DomainEvents collection containing the domain events from within this stream events collection
57,134
public function scopeWithRelations ( Builder $ builder , $ relations = null ) { $ with = [ ] ; foreach ( $ this -> getWithRelationsList ( $ relations ) as $ relation ) { list ( $ relation , $ scope ) = $ this -> _parseRelation ( $ relation ) ; if ( $ this -> isWithableRelation ( $ builder , $ relation ) ) { if ( $ scope ) { $ with [ $ relation ] = function ( $ query ) use ( $ scope ) { $ query -> $ scope ( ) ; } ; } else { $ with [ ] = $ relation ; } } } $ builder -> with ( $ with ) ; }
Add eager loaded relations .
57,135
protected function _parseRelation ( $ relation ) { $ scope = null ; if ( strpos ( $ relation , ':' ) !== false ) { list ( $ relation , $ scope ) = explode ( ':' , $ relation ) ; } return [ $ relation , $ scope ] ; }
Parse relation string to extract relation name and optional scope
57,136
public static function getMappedClassName ( $ className ) { $ mappedName = array_search ( $ className , self :: $ classMap ) ; if ( $ mappedName ) { return $ mappedName ; } $ mappedName = array_search ( $ className , array_flip ( self :: $ classMap ) ) ; if ( $ mappedName ) { return $ mappedName ; } return false ; }
Looks up the supplied call name to its mapped class name
57,137
public static function addResourceDirectory ( $ prefix , $ dir ) { if ( self :: $ _resourceLoader ) { self :: $ _resourceLoader -> addPrefixPath ( $ prefix , $ dir ) ; } }
Add directory to the list of places where to look for resource handlers
57,138
public static function getResourceParser ( $ resource ) { if ( self :: $ _resourceLoader ) { $ type = preg_replace ( "/[^A-Za-z0-9_]/" , " " , get_resource_type ( $ resource ) ) ; $ type = str_replace ( " " , "" , ucwords ( $ type ) ) ; return self :: $ _resourceLoader -> load ( $ type ) ; } return false ; }
Get plugin class that handles this resource
57,139
public static function handleResource ( $ resource ) { if ( ! self :: $ _resourceLoader ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Unable to handle resources - resource plugin loader not set' ) ; } try { while ( is_resource ( $ resource ) ) { $ resclass = self :: getResourceParser ( $ resource ) ; if ( ! $ resclass ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Can not serialize resource type: ' . get_resource_type ( $ resource ) ) ; } $ parser = new $ resclass ( ) ; if ( is_callable ( array ( $ parser , 'parse' ) ) ) { $ resource = $ parser -> parse ( $ resource ) ; } else { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( "Could not call parse() method on class $resclass" ) ; } } return $ resource ; } catch ( Zend_Amf_Exception $ e ) { throw new Zend_Amf_Exception ( $ e -> getMessage ( ) , $ e -> getCode ( ) , $ e ) ; } catch ( Exception $ e ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Can not serialize resource type: ' . get_resource_type ( $ resource ) , 0 , $ e ) ; } }
Convert resource to a serializable object
57,140
protected function _fullModelClass ( ) { $ baseClassName = $ this -> modelClassName ( ) ; $ classNamePattern = $ this -> modelClassNamePattern ( ) ; if ( $ classNamePattern && strpos ( $ classNamePattern , '{type}' ) !== false ) { $ fullClassName = str_replace ( "{type}" , $ baseClassName , $ classNamePattern ) ; } elseif ( $ classNamePattern ) { $ fullClassName = "{$classNamePattern}{$baseClassName}" ; } else { $ fullClassName = "\\{$baseClassName}" ; } return $ fullClassName ; }
Creates the full model class name
57,141
public function setType ( $ type ) { if ( ! is_string ( $ type ) && ( null !== $ type ) ) { require_once 'Zend/Server/Reflection/Exception.php' ; throw new Zend_Server_Reflection_Exception ( 'Invalid parameter type' ) ; } $ this -> _type = $ type ; }
Set parameter type
57,142
public function setDescription ( $ description ) { if ( ! is_string ( $ description ) && ( null !== $ description ) ) { require_once 'Zend/Server/Reflection/Exception.php' ; throw new Zend_Server_Reflection_Exception ( 'Invalid parameter description' ) ; } $ this -> _description = $ description ; }
Set parameter description
57,143
public function readObject ( $ object = null ) { if ( $ object === null ) { $ object = array ( ) ; } while ( true ) { $ key = $ this -> _stream -> readUTF ( ) ; $ typeMarker = $ this -> _stream -> readByte ( ) ; if ( $ typeMarker != Zend_Amf_Constants :: AMF0_OBJECTTERM ) { $ object [ $ key ] = $ this -> readTypeMarker ( $ typeMarker ) ; } else { break ; } } $ this -> _reference [ ] = $ object ; return ( object ) $ object ; }
Read AMF objects and convert to PHP objects
57,144
public function readReference ( ) { $ key = $ this -> _stream -> readInt ( ) ; if ( ! array_key_exists ( $ key , $ this -> _reference ) ) { require_once 'Zend/Amf/Exception.php' ; throw new Zend_Amf_Exception ( 'Invalid reference key: ' . $ key ) ; } return $ this -> _reference [ $ key ] ; }
Read reference objects
57,145
public function readDate ( ) { $ timestamp = floor ( $ this -> _stream -> readDouble ( ) / 1000 ) ; $ offset = $ this -> _stream -> readInt ( ) ; require_once 'Zend/Date.php' ; $ date = new Zend_Date ( $ timestamp ) ; return $ date ; }
Convert AS Date to Zend_Date
57,146
public function readTypedObject ( ) { require_once 'Zend/Amf/Parse/TypeLoader.php' ; $ className = $ this -> _stream -> readUTF ( ) ; $ loader = Zend_Amf_Parse_TypeLoader :: loadType ( $ className ) ; $ returnObject = new $ loader ( ) ; $ properties = get_object_vars ( $ this -> readObject ( ) ) ; foreach ( $ properties as $ key => $ value ) { if ( $ key ) { $ returnObject -> $ key = $ value ; } } if ( $ returnObject instanceof Zend_Amf_Value_Messaging_ArrayCollection ) { $ returnObject = get_object_vars ( $ returnObject ) ; } return $ returnObject ; }
Read Class that is to be mapped to a server class .
57,147
public function readAmf3TypeMarker ( ) { require_once 'Zend/Amf/Parse/Amf3/Deserializer.php' ; $ deserializer = new Zend_Amf_Parse_Amf3_Deserializer ( $ this -> _stream ) ; $ this -> _objectEncoding = Zend_Amf_Constants :: AMF3_OBJECT_ENCODING ; return $ deserializer -> readTypeMarker ( ) ; }
AMF3 data type encountered load AMF3 Deserializer to handle type markers .
57,148
private function instantiateParameters ( Command $ command ) { return array_map ( function ( \ ReflectionParameter $ param ) { return $ this -> container -> get ( $ param -> getType ( ) -> getName ( ) ) ; } , ( new ReflectionClass ( get_class ( $ command ) ) ) -> getMethod ( 'execute' ) -> getParameters ( ) ) ; }
instantiate the parameters for the command s execution method using the constructor injected container .
57,149
public function fetch ( $ path ) { $ result = $ this -> result ; $ keys = explode ( "." , $ path ) ; foreach ( $ keys as $ key ) { if ( ! array_key_exists ( $ key , $ result ) ) { return null ; } $ result = $ result [ $ key ] ; } return $ result ; }
Gets specific value from within the result set using dot notation
57,150
public function setParent ( Zend_Server_Reflection_Node $ node , $ new = false ) { $ this -> _parent = $ node ; if ( $ new ) { $ node -> attachChild ( $ this ) ; return ; } }
Set parent node
57,151
public function attachChild ( Zend_Server_Reflection_Node $ node ) { $ this -> _children [ ] = $ node ; if ( $ node -> getParent ( ) !== $ this ) { $ node -> setParent ( $ this ) ; } }
Attach a child node
57,152
public function getEndPoints ( ) { $ endPoints = array ( ) ; if ( ! $ this -> hasChildren ( ) ) { return $ endPoints ; } foreach ( $ this -> _children as $ child ) { $ value = $ child -> getValue ( ) ; if ( null === $ value ) { $ endPoints [ ] = $ this ; } elseif ( ( null !== $ value ) && $ child -> hasChildren ( ) ) { $ childEndPoints = $ child -> getEndPoints ( ) ; if ( ! empty ( $ childEndPoints ) ) { $ endPoints = array_merge ( $ endPoints , $ childEndPoints ) ; } } elseif ( ( null !== $ value ) && ! $ child -> hasChildren ( ) ) { $ endPoints [ ] = $ child ; } } return $ endPoints ; }
Retrieve the bottommost nodes of this node s tree
57,153
protected function _canAccess ( $ object ) { if ( ! is_object ( $ object ) ) { $ object = singleton ( $ object ) ; } if ( ! ( $ object instanceof CodeBank_APIClass ) ) { if ( Director :: isDev ( ) && $ object instanceof ZendAmfServiceBrowser ) { return true ; } return false ; } $ perms = $ object -> getRequiredPermissions ( ) ; if ( ! empty ( $ perms ) && $ perms !== false ) { if ( ! is_array ( $ perms ) ) { throw new Zend_Amf_Exception ( 'CodeBank_APIClass::getRequiredPermissions() Should return an array of permissions to check' ) ; return false ; } foreach ( $ perms as $ permission ) { if ( ! Permission :: check ( $ permission ) ) { return false ; } } } return true ; }
Checks to see if the member can access the requested class
57,154
public function describeTable ( $ dbType , $ dbDescription , $ tableName ) { $ db = $ this -> _connect ( $ dbType , $ dbDescription ) ; return $ db -> describeTable ( $ tableName ) ; }
Describe database object .
57,155
public function connect ( $ dbType , $ dbDescription ) { $ db = $ this -> _connect ( $ dbType , $ dbDescription ) ; $ db -> listTables ( ) ; return true ; }
Test database connection
57,156
public function getTables ( $ dbType , $ dbDescription ) { $ db = $ this -> _connect ( $ dbType , $ dbDescription ) ; return $ db -> listTables ( ) ; }
Get the list of database tables
57,157
protected function mergeTemplateResources ( TemplateResources $ templateResources ) { $ this -> stylesheets = array_merge ( $ this -> stylesheets , $ templateResources -> getStylesheets ( ) ) ; $ this -> headerScripts = array_merge ( $ this -> headerScripts , $ templateResources -> getHeaderScripts ( ) ) ; $ this -> headerIncludes = array_merge ( $ this -> headerIncludes , $ templateResources -> getHeaderIncludes ( ) ) ; $ this -> footerScripts = array_merge ( $ this -> footerScripts , $ templateResources -> getFooterScripts ( ) ) ; $ this -> footerIncludes = array_merge ( $ this -> footerIncludes , $ templateResources -> getFooterIncludes ( ) ) ; }
Merge a set of template resources
57,158
public static function addCommonStylesheets ( $ commonStylesheets ) { foreach ( GeneralUtility :: trimExplode ( ',' , $ commonStylesheets , true ) as $ commonStylesheet ) { $ commonStylesheet = self :: resolveUrl ( $ commonStylesheet ) ; if ( $ commonStylesheet ) { self :: $ commonStylesheets [ ] = $ commonStylesheet ; } } }
Add common stylesheets
57,159
public static function addCommonHeaderScripts ( $ commonHeaderScripts ) { foreach ( GeneralUtility :: trimExplode ( ',' , $ commonHeaderScripts , true ) as $ commonHeaderScript ) { $ commonHeaderScript = self :: resolveUrl ( $ commonHeaderScript ) ; if ( $ commonHeaderScript ) { self :: $ commonHeaderScripts [ ] = $ commonHeaderScript ; } } }
Add common header scripts
57,160
public static function addCommonFooterScripts ( $ commonFooterScripts ) { foreach ( GeneralUtility :: trimExplode ( ',' , $ commonFooterScripts , true ) as $ commonFooterScript ) { $ commonFooterScript = self :: resolveUrl ( $ commonFooterScript ) ; if ( $ commonFooterScript ) { self :: $ commonFooterScripts [ ] = $ commonFooterScript ; } } }
Add common footer scripts
57,161
public function addStylesheet ( $ url ) { $ url = self :: resolveUrl ( $ url ) ; if ( $ url ) { $ this -> stylesheets [ self :: hashResource ( $ url ) ] = $ url ; } }
Add a CSS stylesheet
57,162
protected static function resolveUrl ( $ url ) { $ url = trim ( $ url ) ; if ( strlen ( $ url ) ) { if ( preg_match ( '%^https?\:\/\/%' , $ url ) ) { return $ url ; } $ absScript = GeneralUtility :: getFileAbsFileName ( $ url ) ; if ( is_file ( $ absScript ) ) { return substr ( $ absScript , strlen ( PATH_site ) ) ; } } return null ; }
Resolve a URL
57,163
public function addHeaderScript ( $ url ) { $ url = self :: resolveUrl ( $ url ) ; if ( $ url ) { $ this -> headerScripts [ self :: hashResource ( $ url ) ] = $ url ; } }
Add a header JavaScript
57,164
public function addHeaderInclude ( $ path ) { $ path = trim ( $ path ) ; if ( strlen ( $ path ) ) { $ absPath = GeneralUtility :: getFileAbsFileName ( $ path ) ; if ( is_file ( $ absPath ) ) { $ include = file_get_contents ( $ absPath ) ; $ this -> headerIncludes [ self :: hashResource ( $ include ) ] = $ include ; } } }
Add a header inclusion resource
57,165
public function addFooterScript ( $ url ) { $ url = self :: resolveUrl ( $ url ) ; if ( $ url ) { $ this -> footerScripts [ self :: hashResource ( $ url ) ] = $ url ; } }
Add a footer JavaScript
57,166
public function addFooterInclude ( $ path ) { $ path = trim ( $ path ) ; if ( strlen ( $ path ) ) { $ absPath = GeneralUtility :: getFileAbsFileName ( $ path ) ; if ( is_file ( $ absPath ) ) { $ include = file_get_contents ( $ absPath ) ; $ this -> footerIncludes [ self :: hashResource ( $ include ) ] = $ include ; } } }
Add a footer inclusion resource
57,167
public function getTemplateResources ( ) { return new TemplateResources ( $ this -> stylesheets , $ this -> headerScripts , $ this -> headerIncludes , $ this -> footerScripts , $ this -> footerIncludes ) ; }
Return all template resources
57,168
public function handle ( DomainEvent $ event ) : void { $ method = lcfirst ( $ this -> getShortName ( $ event ) ) ; if ( method_exists ( $ this , $ method ) ) { $ this -> $ method ( $ event ) ; } }
receives domain events and routes them to a method with their name
57,169
public function createGraph ( $ graph ) { $ tempDot = tempnam ( sys_get_temp_dir ( ) , 'DOT_' ) ; $ this -> registerTempFile ( $ tempDot ) ; file_put_contents ( $ tempDot , $ graph ) ; $ dotCommand = 'dot -Tsvg -Nfontname=sans-serif -Efontname=sans-serif ' . CommandUtility :: escapeShellArgument ( $ tempDot ) ; $ output = $ returnValue = null ; CommandUtility :: exec ( $ dotCommand , $ output , $ returnValue ) ; return $ returnValue ? '' : implode ( '' , ( array ) $ output ) ; }
Create an SVG component graph
57,170
public function key ( $ name ) : string { if ( ! isset ( $ this -> details [ $ name ] ) ) { throw new CryptographicDetailsDoNotContainKey ( $ name ) ; } return $ this -> details [ $ name ] ; }
get the value for a key from the cryptographic details
57,171
public function index ( ) { Session :: start ( ) ; $ server = new CodeBankAMFServer ( ) ; $ classes = ClassInfo :: implementorsOf ( 'CodeBank_APIClass' ) ; foreach ( $ classes as $ class ) { $ server -> setClass ( $ class ) ; } if ( Director :: isDev ( ) ) { $ server -> setClass ( 'ZendAmfServiceBrowser' ) ; ZendAmfServiceBrowser :: $ ZEND_AMF_SERVER = $ server ; } if ( class_exists ( 'CodeBankAPITest' ) && $ this -> _testAMFRequest !== false ) { $ server -> setRequest ( $ this -> _testAMFRequest ) ; $ server -> setResponse ( new Zend_Amf_Response ( ) ) ; } $ server -> setProduction ( ! Director :: isDev ( ) ) ; $ response = $ server -> handle ( ) ; if ( ! class_exists ( 'CodeBankAPITest' ) ) { $ this -> response -> addHeader ( 'Content-Type' , 'application/x-amf' ) ; } Session :: save ( ) ; return $ response ; }
Handles all amf requests
57,172
public function export_to_client ( ) { if ( ! Permission :: check ( 'CODE_BANK_ACCESS' ) ) { return Security :: permissionFailure ( $ this ) ; } set_time_limit ( 480 ) ; $ languages = $ this -> queryToArray ( DB :: query ( 'SELECT "ID", "Name", "FileExtension", "HighlightCode", "UserLanguage" FROM "SnippetLanguage"' ) ) ; $ snippets = $ this -> queryToArray ( DB :: query ( 'SELECT "ID", "Title", "Description", "Tags", "LanguageID", "PackageID", "FolderID" FROM "Snippet"' ) ) ; $ versions = $ this -> queryToArray ( DB :: query ( 'SELECT "ID", "Created", "Text", "ParentID" FROM "SnippetVersion"' ) ) ; $ packages = $ this -> queryToArray ( DB :: query ( 'SELECT "ID", "Title" FROM "SnippetPackage"' ) ) ; $ folders = $ this -> queryToArray ( DB :: query ( 'SELECT "ID", "Name", "ParentID", "LanguageID" FROM "SnippetFolder"' ) ) ; $ response = array ( 'format' => 'ToClient' , 'data' => array ( 'languages' => $ languages , 'snippets' => $ snippets , 'versions' => $ versions , 'packages' => $ packages , 'folders' => $ folders ) ) ; SS_HTTPRequest :: send_file ( json_encode ( $ response ) , date ( 'Y-m-d_hi' ) . '.cbexport' , 'application/json' ) -> output ( ) ; Session :: save ( ) ; exit ; }
Builds a json export file for importing on the client
57,173
private function queryToArray ( SS_Query $ source ) { $ result = array ( ) ; foreach ( $ source as $ row ) { $ result [ ] = $ row ; } return $ result ; }
Merges a database resultset into an array
57,174
final protected function getVersion ( ) { if ( CB_VERSION != '@@VERSION@@' ) { return CB_VERSION . ' ' . CB_BUILD_DATE ; } $ composerLockPath = BASE_PATH . '/composer.lock' ; if ( file_exists ( $ composerLockPath ) ) { $ cache = SS_Cache :: factory ( 'CodeBank_Version' ) ; $ cacheKey = filemtime ( $ composerLockPath ) ; $ version = $ cache -> load ( $ cacheKey ) ; if ( $ version ) { $ version = $ version ; } else { $ version = '' ; } if ( ! $ version && $ jsonData = file_get_contents ( $ composerLockPath ) ) { $ lockData = json_decode ( $ jsonData ) ; if ( $ lockData && isset ( $ lockData -> packages ) ) { foreach ( $ lockData -> packages as $ package ) { if ( $ package -> name == 'undefinedoffset/silverstripe-codebank' && isset ( $ package -> version ) ) { $ version = $ package -> version ; break ; } } $ cache -> save ( $ version , $ cacheKey ) ; } } } if ( ! empty ( $ version ) ) { return $ version ; } return _t ( 'CodeBank.DEVELOPMENT_BUILD' , '_Development Build' ) ; }
Gets the current version of Code Bank
57,175
public function useFileLogger ( string $ dir ) : self { $ this -> setLogger ( new \ BearFramework \ App \ FileLogger ( $ dir ) ) ; return $ this ; }
Enables a file logger for directory specified .
57,176
public function setLogger ( \ BearFramework \ App \ ILogger $ logger ) : self { if ( $ this -> logger !== null ) { throw new \ Exception ( 'A logger is already set!' ) ; } $ this -> logger = $ logger ; return $ this ; }
Sets a new logger .
57,177
public function useFileDriver ( string $ dir ) : self { $ this -> setDriver ( new \ BearFramework \ App \ FileDataDriver ( $ dir ) ) ; return $ this ; }
Enables the file data driver using the directory specified .
57,178
public function setDriver ( \ BearFramework \ App \ IDataDriver $ driver ) : self { if ( $ this -> driver !== null ) { throw new \ Exception ( 'A data driver is already set!' ) ; } $ this -> driver = $ driver ; if ( $ this -> filenameProtocol !== null ) { \ BearFramework \ Internal \ DataItemStreamWrapper :: $ environment [ $ this -> filenameProtocol ] = [ $ this , $ driver ] ; } return $ this ; }
Sets a new data driver .
57,179
private function getDriver ( ) : \ BearFramework \ App \ IDataDriver { if ( $ this -> driver !== null ) { return $ this -> driver ; } throw new \ Exception ( 'No data driver specified! Use useFileDriver() or setDriver() to specify one.' ) ; }
Returns the data driver .
57,180
public function make ( string $ key = null , string $ value = null ) : \ BearFramework \ App \ DataItem { if ( $ this -> newDataItemCache === null ) { $ this -> newDataItemCache = new \ BearFramework \ App \ DataItem ( ) ; } $ object = clone ( $ this -> newDataItemCache ) ; if ( $ key !== null ) { if ( ! $ this -> validate ( $ key ) ) { throw new \ InvalidArgumentException ( 'The key provided (' . $ key . ') is not valid! It may contain only the following characters: "a-z", "0-9", ".", "/", "-" and "_".' ) ; } $ object -> key = $ key ; } if ( $ value !== null ) { $ object -> value = $ value ; } return $ object ; }
Constructs a new data item and returns it .
57,181
public function delete ( string $ key ) : self { if ( ! $ this -> validate ( $ key ) ) { throw new \ InvalidArgumentException ( 'The key provided (' . $ key . ') is not valid! It may contain only the following characters: "a-z", "0-9", ".", "/", "-" and "_".' ) ; } $ driver = $ this -> getDriver ( ) ; $ driver -> delete ( $ key ) ; if ( $ this -> hasEventListeners ( 'itemDelete' ) ) { $ this -> dispatchEvent ( 'itemDelete' , new \ BearFramework \ App \ Data \ ItemDeleteEventDetails ( $ key ) ) ; } if ( $ this -> hasEventListeners ( 'itemChange' ) ) { $ this -> dispatchEvent ( 'itemChange' , new \ BearFramework \ App \ Data \ ItemChangeEventDetails ( $ key ) ) ; } return $ this ; }
Deletes the data item specified and it s metadata .
57,182
public function getFilename ( string $ key ) : string { if ( ! $ this -> validate ( $ key ) ) { throw new \ InvalidArgumentException ( 'The key provided (' . $ key . ') is not valid! It may contain only the following characters: "a-z", "0-9", ".", "/", "-" and "_".' ) ; } if ( $ this -> filenameProtocol === null ) { throw new \ Exception ( 'No filenameProtocol specified!' ) ; } return $ this -> filenameProtocol . '://' . $ key ; }
Returns the filename of the data item specified .
57,183
static function register ( string $ id , string $ dir , $ options = [ ] ) : bool { if ( isset ( self :: $ data [ $ id ] ) ) { return false ; } if ( ! isset ( $ id { 0 } ) ) { throw new \ InvalidArgumentException ( 'The value of the id argument cannot be empty.' ) ; } $ dir = rtrim ( \ BearFramework \ Internal \ Utilities :: normalizePath ( $ dir ) , '/' ) ; if ( ! is_dir ( $ dir ) ) { throw new \ InvalidArgumentException ( 'The value of the dir argument is not a valid directory.' ) ; } self :: $ data [ $ id ] = new \ BearFramework \ Addon ( $ id , $ dir , $ options ) ; return true ; }
Registers an addon .
57,184
static function get ( string $ id ) : ? \ BearFramework \ Addon { if ( isset ( self :: $ data [ $ id ] ) ) { return clone ( self :: $ data [ $ id ] ) ; } return null ; }
Returns information about the addon specified .
57,185
static function getList ( ) { $ list = new \ BearFramework \ DataList ( ) ; foreach ( self :: $ data as $ addon ) { $ list [ ] = clone ( $ addon ) ; } return $ list ; }
Returns a list of all registered addons .
57,186
public function make ( string $ name = null , string $ value = null ) : \ BearFramework \ App \ Response \ Cookie { if ( $ this -> newCookieCache === null ) { $ this -> newCookieCache = new \ BearFramework \ App \ Response \ Cookie ( ) ; } $ object = clone ( $ this -> newCookieCache ) ; if ( $ name !== null ) { $ object -> name = $ name ; } if ( $ value !== null ) { $ object -> value = $ value ; } return $ object ; }
Constructs a new cookie and returns it .
57,187
public function get ( string $ name ) : ? \ BearFramework \ App \ Response \ Cookie { if ( isset ( $ this -> data [ $ name ] ) ) { return clone ( $ this -> data [ $ name ] ) ; } return null ; }
Returns a cookie or null if not found .
57,188
public function delete ( string $ name ) : self { if ( isset ( $ this -> data [ $ name ] ) ) { unset ( $ this -> data [ $ name ] ) ; } return $ this ; }
Deletes a cookie if exists .
57,189
public function getList ( ) { $ list = new \ BearFramework \ DataList ( ) ; foreach ( $ this -> data as $ cookie ) { $ list [ ] = clone ( $ cookie ) ; } return $ list ; }
Returns a list of all cookies .
57,190
public function useAppDataDriver ( string $ keyPrefix = '.temp/cache/' ) : self { $ app = App :: get ( ) ; $ this -> setDriver ( new \ BearFramework \ App \ DataCacheDriver ( $ app -> data , $ keyPrefix ) ) ; return $ this ; }
Enables the app cache driver . The cached data will be stored in the app data repository .
57,191
public function setDriver ( \ BearFramework \ App \ ICacheDriver $ driver ) : self { if ( $ this -> driver !== null ) { throw new \ Exception ( 'A cache driver is already set!' ) ; } $ this -> driver = $ driver ; return $ this ; }
Sets a new cache driver .
57,192
private function getDriver ( ) : \ BearFramework \ App \ ICacheDriver { if ( $ this -> driver !== null ) { return $ this -> driver ; } throw new \ Exception ( 'No cache driver specified! Use useAppDataDriver() or setDriver() to specify one.' ) ; }
Returns the cache driver .
57,193
public function make ( string $ key = null , $ value = null ) : \ BearFramework \ App \ CacheItem { if ( $ this -> newCacheItemCache === null ) { $ this -> newCacheItemCache = new CacheItem ( ) ; } $ object = clone ( $ this -> newCacheItemCache ) ; if ( $ key !== null ) { $ object -> key = $ key ; } if ( $ value !== null ) { $ object -> value = $ value ; } return $ object ; }
Constructs a new cache item and returns it .
57,194
public function set ( CacheItem $ item ) : self { $ driver = $ this -> getDriver ( ) ; $ driver -> set ( $ item -> key , $ item -> value , $ item -> ttl ) ; if ( $ this -> hasEventListeners ( 'itemSet' ) ) { $ this -> dispatchEvent ( 'itemSet' , new \ BearFramework \ App \ Cache \ ItemSetEventDetails ( clone ( $ item ) ) ) ; } if ( $ this -> hasEventListeners ( 'itemChange' ) ) { $ this -> dispatchEvent ( 'itemChange' , new \ BearFramework \ App \ Cache \ ItemChangeEventDetails ( $ item -> key ) ) ; } return $ this ; }
Stores a cache item .
57,195
public function get ( string $ key ) : ? \ BearFramework \ App \ CacheItem { $ driver = $ this -> getDriver ( ) ; $ item = null ; $ value = $ driver -> get ( $ key ) ; if ( $ value !== null ) { $ item = $ this -> make ( $ key , $ value ) ; } if ( $ this -> hasEventListeners ( 'itemGet' ) ) { $ this -> dispatchEvent ( 'itemGet' , new \ BearFramework \ App \ Cache \ ItemGetEventDetails ( $ key , $ item === null ? null : clone ( $ item ) ) ) ; } if ( $ this -> hasEventListeners ( 'itemRequest' ) ) { $ this -> dispatchEvent ( 'itemRequest' , new \ BearFramework \ App \ Cache \ ItemRequestEventDetails ( $ key ) ) ; } return $ item ; }
Returns the cache item stored or null if not found .
57,196
public function getValue ( string $ key ) { $ driver = $ this -> getDriver ( ) ; $ value = $ driver -> get ( $ key ) ; if ( $ this -> hasEventListeners ( 'itemGetValue' ) ) { $ this -> dispatchEvent ( 'itemGetValue' , new \ BearFramework \ App \ Cache \ ItemGetValueEventDetails ( $ key , $ value ) ) ; } if ( $ this -> hasEventListeners ( 'itemRequest' ) ) { $ this -> dispatchEvent ( 'itemRequest' , new \ BearFramework \ App \ Cache \ ItemRequestEventDetails ( $ key ) ) ; } return $ value ; }
Returns the value of the cache item specified .
57,197
public function exists ( string $ key ) : bool { $ driver = $ this -> getDriver ( ) ; $ exists = $ driver -> get ( $ key ) !== null ; if ( $ this -> hasEventListeners ( 'itemExists' ) ) { $ this -> dispatchEvent ( 'itemExists' , new \ BearFramework \ App \ Cache \ ItemExistsEventDetails ( $ key , $ exists ) ) ; } if ( $ this -> hasEventListeners ( 'itemRequest' ) ) { $ this -> dispatchEvent ( 'itemRequest' , new \ BearFramework \ App \ Cache \ ItemRequestEventDetails ( $ key ) ) ; } return $ exists ; }
Returns information whether a key exists in the cache .
57,198
public function make ( string $ name = null , string $ value = null ) : \ BearFramework \ App \ Response \ Header { if ( $ this -> newHeaderCache === null ) { $ this -> newHeaderCache = new \ BearFramework \ App \ Response \ Header ( ) ; } $ object = clone ( $ this -> newHeaderCache ) ; if ( $ name !== null ) { $ object -> name = $ name ; } if ( $ value !== null ) { $ object -> value = $ value ; } return $ object ; }
Constructs a new header and returns it .
57,199
public function getValue ( string $ name ) : ? string { if ( isset ( $ this -> data [ $ name ] ) ) { return $ this -> data [ $ name ] -> value ; } return null ; }
Returns the value of the header or null if not found .