idx int64 0 60.3k | question stringlengths 101 6.21k | target stringlengths 7 803 |
|---|---|---|
16,400 | public static function getSalt ( ) : string { $ result = '' ; try { $ result = static :: readSaltFromFile ( ) ; } catch ( InvalidArgumentException $ e ) { Log :: warning ( "Failed to read salt from file" ) ; } if ( $ result ) { return $ result ; } try { $ salt = static :: generateSalt ( ) ; static :: writeSaltToFile ( $ salt ) ; $ result = static :: readSaltFromFile ( ) ; } catch ( InvalidArgumentException $ e ) { throw new InvalidArgumentException ( "Failed to regenerate and save new salt: " . $ e -> getMessage ( ) , 0 , $ e ) ; } Log :: warning ( "New salt is generated and stored. Users might need to logout and clean their cookies." ) ; return $ result ; } | Get configured salt string |
16,401 | protected static function readSaltFromFile ( ) : string { Utility :: validatePath ( static :: $ saltFile ) ; $ result = file_get_contents ( static :: $ saltFile ) ; $ result = $ result ? : '' ; static :: validateSalt ( $ result ) ; return $ result ; } | Read salt string from file |
16,402 | protected static function writeSaltToFile ( string $ salt ) : void { static :: validateSalt ( $ salt ) ; $ result = @ file_put_contents ( static :: $ saltFile , $ salt ) ; if ( ( $ result === false ) || ( $ result <> strlen ( $ salt ) ) ) { throw new InvalidArgumentException ( "Failed to write salt to file [" . static :: $ saltFile . "]" ) ; } } | Write a valid salt string to file |
16,403 | protected static function validateSalt ( string $ salt ) : void { if ( ! ctype_print ( $ salt ) ) { throw new InvalidArgumentException ( "Salt is not a printable string" ) ; } static :: validateSaltMinLength ( ) ; $ saltLength = strlen ( $ salt ) ; if ( $ saltLength < static :: $ saltMinLength ) { throw new InvalidArgumentException ( "Salt length of $saltLength characters is less than expected " . static :: $ saltMinLength ) ; } } | Validate salt string |
16,404 | protected static function generateSalt ( ) : string { $ result = '' ; static :: validateSaltMinLength ( ) ; $ pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ; $ poolSize = strlen ( $ pool ) ; for ( $ i = 0 ; $ i < static :: $ saltMinLength ; $ i ++ ) { $ result .= $ pool [ rand ( 0 , $ poolSize - 1 ) ] ; } return $ result ; } | Generate salt string |
16,405 | public function getBrowser ( $ startPage , $ type = '*firefox' ) { $ url = 'http://' . $ this -> host . ':' . $ this -> port . '/selenium-server/driver/' ; $ driver = new Driver ( $ url , $ this -> timeout ) ; $ class = $ this -> browserClass ; return new $ class ( $ driver , $ startPage , $ type ) ; } | Creates a new browser instance . |
16,406 | public function describeTable ( $ table ) { if ( ! $ this -> connection -> expr ( 'show tables like []' , [ $ table ] ) -> get ( ) ) { return [ ] ; } $ result = [ ] ; foreach ( $ this -> connection -> expr ( 'describe {}' , [ $ table ] ) as $ row ) { $ row2 = [ ] ; $ row2 [ 'name' ] = $ row [ 'Field' ] ; $ row2 [ 'pk' ] = $ row [ 'Key' ] == 'PRI' ; $ row2 [ 'type' ] = preg_replace ( '/\(.*/' , '' , $ row [ 'Type' ] ) ; $ result [ ] = $ row2 ; } return $ result ; } | Return database table descriptions . DB engine specific . |
16,407 | public function getHash ( ) { if ( null === $ this -> hash ) { $ this -> hash = $ this -> calculateHash ( ) ; } return $ this -> hash ; } | Returns the hash of the form object which should be calculated only once for performance concerns . |
16,408 | public function register ( $ handledErrors = E_ALL ) { $ errHandler = [ $ this , 'handleError' ] ; $ exHandler = [ $ this , 'handleException' ] ; $ handledErrors = is_int ( $ handledErrors ) ? $ handledErrors : E_ALL ; set_error_handler ( $ errHandler , $ handledErrors ) ; set_exception_handler ( $ exHandler ) ; return $ this ; } | Register this handler as the exception and error handler . |
16,409 | public function registerShutdown ( ) { if ( self :: $ reservedMemory === null ) { self :: $ reservedMemory = str_repeat ( 'x' , 10240 ) ; register_shutdown_function ( __CLASS__ . '::handleFatalError' ) ; } self :: $ exceptionHandler = [ $ this , 'handleException' ] ; return $ this ; } | Register this handler as the shutdown handler . |
16,410 | protected function fetchProcessorInstanceFromCache ( $ cacheIdentifier , FormObject $ formObject ) { $ cacheInstance = CacheService :: get ( ) -> getCacheInstance ( ) ; if ( $ cacheInstance -> has ( $ cacheIdentifier ) ) { $ instance = $ cacheInstance -> get ( $ cacheIdentifier ) ; $ instance -> attachFormObject ( $ formObject ) ; } else { $ instance = $ this -> getNewProcessorInstance ( $ formObject ) ; $ instance -> calculateAllTrees ( ) ; $ cacheInstance -> set ( $ cacheIdentifier , $ instance ) ; } return $ instance ; } | Will either fetch the processor instance from cache using the given identifier or calculate it and store it in cache . |
16,411 | public function verify ( $ response ) { $ result = $ this -> getVerificationResult ( $ response ) ; if ( $ result [ 'success' ] ) { return true ; } if ( ! empty ( $ result [ 'error-codes' ] ) ) { $ this -> errors = $ result [ 'error-codes' ] ; } return false ; } | Returns whether the given response was successful . |
16,412 | protected function getScriptSrc ( $ onloadCallbackName ) { $ url = static :: SCRIPT_URL ; $ queryArgs = [ ] ; \ parse_str ( \ parse_url ( $ url , PHP_URL_QUERY ) , $ queryArgs ) ; $ queryArgs [ 'onload' ] = $ onloadCallbackName ; $ queryArgs [ 'render' ] = 'explicit' ; $ url = \ sprintf ( '%s?%s' , \ strtok ( $ url , '?' ) , \ http_build_query ( $ queryArgs ) ) ; return $ url ; } | Returns the recaptcha API script source with an onload callback . |
16,413 | private function getContentTypeHandler ( ServerRequestInterface $ request ) { $ acceptHeader = $ request -> getHeaderLine ( 'Accept' ) ; $ acceptedTypes = explode ( ',' , $ acceptHeader ) ; foreach ( $ this -> handlers as $ contentType => $ handler ) { if ( $ this -> doesTypeMatch ( $ acceptedTypes , $ contentType ) ) { return $ handler ; } } return reset ( $ this -> handlers ) ; } | Get a content handler based on Accept header in the request . |
16,414 | public function beforeSave ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) : void { if ( ! is_callable ( $ this -> getConfig ( 'callback' ) ) ) { return ; } $ user = call_user_func ( $ this -> getConfig ( 'callback' ) ) ; if ( empty ( $ user [ 'id' ] ) ) { return ; } if ( $ entity -> isNew ( ) && empty ( $ entity -> get ( $ this -> getConfig ( 'created_by' ) ) ) ) { $ entity -> set ( $ this -> getConfig ( 'created_by' ) , $ user [ 'id' ] ) ; } $ userId = $ entity -> isDirty ( $ this -> getConfig ( 'modified_by' ) ) && ! empty ( $ this -> getConfig ( 'modified_by' ) ) ? $ entity -> get ( $ this -> getConfig ( 'modified_by' ) ) : $ user [ 'id' ] ; $ entity -> set ( $ this -> getConfig ( 'modified_by' ) , $ userId ) ; } | BeforeSave callback method . |
16,415 | public function build ( InputSettings $ settings ) { $ this -> settings = $ settings ; $ this -> setElement ( ) ; $ this -> setValidator ( ) ; $ this -> setLabel ( ) ; $ this -> setDefault ( ) ; $ this -> setAttributes ( ) ; $ this -> setData ( ) ; $ this -> setAdditionalOptions ( ) ; return $ this -> getElement ( ) ; } | Method for building form element |
16,416 | public function initElement ( ) { if ( is_null ( $ this -> settings ) ) { $ this -> settings = new InputSettings ( ) ; } return $ this -> build ( $ this -> settings ) ; } | Method sets element and return object instance . Only for form builder purpose . |
16,417 | public function setLabel ( ) { if ( $ this -> settings -> getValue ( InputSettings :: LABEL_PARAM ) ) { $ this -> element -> setLabel ( $ this -> settings -> getValue ( InputSettings :: LABEL_PARAM ) ) ; } else { $ this -> element -> setLabel ( preg_replace ( '/.*\\\/' , '' , get_class ( $ this ) ) ) ; } } | Default setter for element label |
16,418 | public function setDefault ( ) { if ( $ this -> settings -> getValue ( InputSettings :: DEFAULTS_PARAM ) ) { $ this -> element -> setDefault ( $ this -> settings -> getValue ( InputSettings :: DEFAULTS_PARAM ) ) ; } } | Default setter for element default value |
16,419 | public function setAttributes ( ) { if ( $ this -> settings -> getValue ( InputSettings :: PLACEHOLDER_PARAM ) ) { $ this -> element -> setAttribute ( 'placeholder' , $ this -> settings -> getValue ( InputSettings :: PLACEHOLDER_PARAM ) ) ; } } | Default setter for placeholder attribute |
16,420 | protected function getNewInstance ( ) { $ className = $ this -> objectMetadata -> getName ( ) ; if ( class_exists ( $ className ) === false ) { throw new \ RuntimeException ( 'Unable to create new instance of ' . $ className ) ; } return new $ className ; } | Return a new instance of the object |
16,421 | protected function setValue ( $ object , $ value , $ setter ) { if ( method_exists ( $ object , $ setter ) ) { $ object -> $ setter ( $ value ) ; } } | Call a setter of the object |
16,422 | public function getAssetHandler ( $ className ) { if ( false === array_key_exists ( $ className , $ this -> instances ) ) { if ( false === class_exists ( $ className ) ) { throw ClassNotFoundException :: wrongAssetHandlerClassName ( $ className ) ; } $ instance = GeneralUtility :: makeInstance ( $ className , $ this ) ; if ( false === $ instance instanceof AbstractAssetHandler ) { throw InvalidArgumentTypeException :: wrongAssetHandlerType ( get_class ( $ instance ) ) ; } $ this -> instances [ $ className ] = $ instance ; } return $ this -> instances [ $ className ] ; } | Return an instance of the wanted asset handler . Local storage is handled . |
16,423 | public function getFormInitializationJavaScriptCode ( ) { $ formName = GeneralUtility :: quoteJSvalue ( $ this -> getFormObject ( ) -> getName ( ) ) ; $ formConfigurationJson = $ this -> handleFormConfiguration ( $ this -> getFormConfiguration ( ) ) ; $ javaScriptCode = <<<JS(function() { Fz.Form.register($formName, $formConfigurationJson);})();JS ; return $ javaScriptCode ; } | Generates and returns JavaScript code to instantiate a new form . |
16,424 | protected function getFormConfiguration ( ) { $ formConfigurationArray = $ this -> getFormObject ( ) -> getConfiguration ( ) -> toArray ( ) ; $ this -> removeFieldsValidationConfiguration ( $ formConfigurationArray ) -> addClassNameProperty ( $ formConfigurationArray ) ; return ArrayService :: get ( ) -> arrayToJavaScriptJson ( $ formConfigurationArray ) ; } | Returns a JSON array containing the form configuration . |
16,425 | protected function removeFieldsValidationConfiguration ( array & $ formConfiguration ) { foreach ( $ formConfiguration [ 'fields' ] as $ fieldName => $ fieldConfiguration ) { if ( true === isset ( $ fieldConfiguration [ 'validation' ] ) ) { unset ( $ fieldConfiguration [ 'validation' ] ) ; unset ( $ fieldConfiguration [ 'activation' ] ) ; $ formConfiguration [ 'fields' ] [ $ fieldName ] = $ fieldConfiguration ; } } return $ this ; } | To lower the length of the JavaScript code we remove useless fields validation configuration . |
16,426 | public function getJavaScriptCode ( ) { $ realTranslations = [ ] ; $ translationsBinding = [ ] ; foreach ( $ this -> translations as $ key => $ value ) { $ hash = HashService :: get ( ) -> getHash ( $ value ) ; $ realTranslations [ $ hash ] = $ value ; $ translationsBinding [ $ key ] = $ hash ; } $ jsonRealTranslations = $ this -> handleRealTranslations ( ArrayService :: get ( ) -> arrayToJavaScriptJson ( $ realTranslations ) ) ; $ jsonTranslationsBinding = $ this -> handleTranslationsBinding ( ArrayService :: get ( ) -> arrayToJavaScriptJson ( $ translationsBinding ) ) ; return <<<JSFz.Localization.addLocalization($jsonRealTranslations, $jsonTranslationsBinding);JS ; } | Will generate and return the JavaScript code which add all registered translations to the JavaScript library . |
16,427 | public function getTranslationKeysForFieldValidation ( Field $ field , $ validationName ) { $ result = [ ] ; if ( true === $ field -> hasValidation ( $ validationName ) ) { $ key = $ field -> getName ( ) . '-' . $ validationName ; $ this -> storeTranslationsForFieldValidation ( $ field ) ; $ result = $ this -> translationKeysForFieldValidation [ $ key ] ; } return $ result ; } | Returns the keys which are bound to translations for a given field validation rule . |
16,428 | public function injectTranslationsForFormFieldsValidation ( ) { $ formConfiguration = $ this -> getFormObject ( ) -> getConfiguration ( ) ; foreach ( $ formConfiguration -> getFields ( ) as $ field ) { $ this -> storeTranslationsForFieldValidation ( $ field ) ; } return $ this ; } | Will loop on each field of the given form and get every translations for the validation rules messages . |
16,429 | protected function storeTranslationsForFieldValidation ( Field $ field ) { if ( false === $ this -> translationsForFieldValidationWereInjected ( $ field ) ) { $ fieldName = $ field -> getName ( ) ; foreach ( $ field -> getValidation ( ) as $ validationName => $ validation ) { $ messages = ValidatorService :: get ( ) -> getValidatorMessages ( $ validation -> getClassName ( ) , $ validation -> getMessages ( ) ) ; foreach ( $ messages as $ key => $ message ) { $ message = MessageService :: get ( ) -> parseMessageArray ( $ message , [ '{0}' , '{1}' , '{2}' , '{3}' , '{4}' , '{5}' , '{6}' , '{7}' , '{8}' , '{9}' , '{10}' ] ) ; $ localizationKey = $ this -> getIdentifierForFieldValidationName ( $ field , $ validationName , $ key ) ; $ this -> addTranslation ( $ localizationKey , $ message ) ; $ messages [ $ key ] = $ localizationKey ; } $ this -> translationKeysForFieldValidation [ $ fieldName . '-' . $ validationName ] = $ messages ; $ key = $ this -> getFormObject ( ) -> getClassName ( ) . '-' . $ field -> getName ( ) ; $ this -> injectedTranslationKeysForFieldValidation [ $ key ] = true ; } } return $ this ; } | Will loop on each validation rule of the given field and get the translations of the rule messages . |
16,430 | protected function translationsForFieldValidationWereInjected ( Field $ field ) { $ key = $ this -> getFormObject ( ) -> getClassName ( ) . '-' . $ field -> getName ( ) ; return true === isset ( $ this -> injectedTranslationKeysForFieldValidation [ $ key ] ) ; } | Checks if the given field validation rules were already handled by this asset handler . |
16,431 | public static function getConfigurationObjectServices ( ) { return ServiceFactory :: getInstance ( ) -> attach ( ServiceInterface :: SERVICE_CACHE ) -> with ( ServiceInterface :: SERVICE_CACHE ) -> setOption ( CacheService :: OPTION_CACHE_NAME , InternalCacheService :: CONFIGURATION_OBJECT_CACHE_IDENTIFIER ) -> setOption ( CacheService :: OPTION_CACHE_BACKEND , InternalCacheService :: get ( ) -> getBackendCache ( ) ) -> attach ( ServiceInterface :: SERVICE_PARENTS ) -> attach ( ServiceInterface :: SERVICE_DATA_PRE_PROCESSOR ) -> attach ( ServiceInterface :: SERVICE_MIXED_TYPES ) ; } | Will initialize correctly the configuration object settings . |
16,432 | public function addForm ( FormObject $ form ) { if ( true === $ this -> hasForm ( $ form -> getClassName ( ) , $ form -> getName ( ) ) ) { throw DuplicateEntryException :: formWasAlreadyRegistered ( $ form ) ; } $ form -> getConfiguration ( ) -> setParents ( [ $ this ] ) ; $ this -> forms [ $ form -> getClassName ( ) ] [ $ form -> getName ( ) ] = $ form ; } | Adds a form to the forms list of this FormZ configuration . Note that this function will also handle the parent service from the configuration_object extension . |
16,433 | public function calculateHash ( ) { $ fullArray = $ this -> toArray ( ) ; $ configurationArray = [ 'view' => $ fullArray [ 'view' ] , 'settings' => $ fullArray [ 'settings' ] ] ; $ this -> hash = HashService :: get ( ) -> getHash ( serialize ( $ configurationArray ) ) ; } | Calculates a hash for this configuration which can be used as a unique identifier . It should be called once before the configuration is put in cache so it is not needed to call it again after being fetched from cache . |
16,434 | public function buildCode ( ) { $ code = '' ; if ( $ this -> documentation ) { $ code .= ' /**' . "\n" ; $ code .= ' * ' . str_replace ( "\n" , "\n * " , wordwrap ( $ this -> documentation , 73 ) ) . "\n" ; $ code .= ' */' . "\n" ; } $ code .= ' public function ' . $ this -> name . '(' . implode ( ', ' , $ this -> parameters ) . ')' . "\n" ; $ code .= ' {' . "\n" ; $ code .= ' ' . str_replace ( "\n" , "\n " , $ this -> body ) . "\n" ; $ code .= ' }' ; $ code = preg_replace ( '/[ ]+$/m' , '' , $ code ) ; return $ code ; } | Builds the PHP code for the method . |
16,435 | public function createVocabulary ( $ name ) { if ( $ this -> vocabulary -> where ( 'name' , $ name ) -> count ( ) ) { throw new Exceptions \ VocabularyExistsException ( ) ; } return $ this -> vocabulary -> create ( [ 'name' => $ name ] ) ; } | Create a new Vocabulary with the given name |
16,436 | public function getVocabularyByNameAsArray ( $ name ) { $ vocabulary = $ this -> vocabulary -> where ( 'name' , $ name ) -> first ( ) ; if ( ! is_null ( $ vocabulary ) ) { return $ vocabulary -> terms -> pluck ( 'name' , 'id' ) -> toArray ( ) ; } return [ ] ; } | Get a Vocabulary by name |
16,437 | public function getVocabularyByNameOptionsArray ( $ name ) { $ vocabulary = $ this -> vocabulary -> where ( 'name' , $ name ) -> first ( ) ; if ( is_null ( $ vocabulary ) ) { return [ ] ; } $ parents = $ this -> term -> whereParent ( 0 ) -> whereVocabularyId ( $ vocabulary -> id ) -> orderBy ( 'weight' , 'ASC' ) -> get ( ) ; $ options = [ ] ; foreach ( $ parents as $ parent ) { $ options [ $ parent -> id ] = $ parent -> name ; $ this -> recurse_children ( $ parent , $ options ) ; } return $ options ; } | Get a Vocabulary by name as an options array for dropdowns |
16,438 | private function recurse_children ( $ parent , & $ options , $ depth = 1 ) { $ parent -> childrens -> map ( function ( $ child ) use ( & $ options , $ depth ) { $ options [ $ child -> id ] = str_repeat ( '-' , $ depth ) . ' ' . $ child -> name ; if ( $ child -> childrens ) { $ this -> recurse_children ( $ child , $ options , $ depth + 1 ) ; } } ) ; } | Recursively visit the children of a term and generate the - option array for dropdowns |
16,439 | public function deleteVocabularyByName ( $ name ) { $ vocabulary = $ this -> vocabulary -> where ( 'name' , $ name ) -> first ( ) ; if ( ! is_null ( $ vocabulary ) ) { return $ vocabulary -> delete ( ) ; } return FALSE ; } | Delete a Vocabulary by name |
16,440 | public function createTerm ( $ vid , $ name , $ parent = 0 , $ weight = 0 ) { $ vocabulary = $ this -> vocabulary -> findOrFail ( $ vid ) ; $ term = [ 'name' => $ name , 'vocabulary_id' => $ vid , 'parent' => $ parent , 'weight' => $ weight , ] ; return $ this -> term -> create ( $ term ) ; } | Create a new term in a specific vocabulary |
16,441 | public function isValid ( $ condition ) { $ conditionTree = ConditionParser :: get ( ) -> parse ( $ condition ) ; if ( true === $ conditionTree -> getValidationResult ( ) -> hasErrors ( ) ) { $ errorMessage = $ this -> translateErrorMessage ( 'validator.form.condition_is_valid.error' , 'formz' , [ $ condition -> getExpression ( ) , $ conditionTree -> getValidationResult ( ) -> getFirstError ( ) -> getMessage ( ) ] ) ; $ this -> addError ( $ errorMessage , self :: ERROR_CODE ) ; } } | Checks if the value is a valid condition string . |
16,442 | protected function alias ( $ aliasKey , $ serviceKey ) { $ this -> bindFactory ( $ aliasKey , function ( Container $ app ) use ( $ serviceKey ) { return $ app [ $ serviceKey ] ; } ) ; } | Alias a service name to another one within the service container allowing for example concrete types to be aliased to an interface or legacy string service keys against concrete class names . |
16,443 | protected function autoBind ( $ className , callable $ parameterFactory = null ) { $ this -> bind ( $ className , $ this -> closureFactory -> createAutoWireClosure ( $ className , $ parameterFactory ) ) ; } | Automatically bind and wire a service using the Injector . Accepts an optional callable to build parameter overrides |
16,444 | protected function autoBindFactory ( $ className , callable $ parameterFactory = null ) { $ this -> bindFactory ( $ className , $ this -> closureFactory -> createAutoWireClosure ( $ className , $ parameterFactory ) ) ; } | Automatically bind and wire a factory using the Injector . Accepts an optional callable to build parameter overrides . |
16,445 | public function create ( $ className , $ parameters = [ ] ) { $ reflectionClass = new \ ReflectionClass ( $ className ) ; if ( ! $ reflectionClass -> hasMethod ( "__construct" ) ) { return $ reflectionClass -> newInstanceWithoutConstructor ( ) ; } if ( ! $ reflectionClass -> getMethod ( '__construct' ) -> isPublic ( ) ) { throw new InjectorInvocationException ( "Injector failed to create $className - constructor isn't public." . " Do you need to use a static factory method instead?" ) ; } try { $ parameters = $ this -> buildParameterArray ( $ this -> inspector -> getSignatureByReflectionClass ( $ reflectionClass , "__construct" ) , $ parameters ) ; return $ reflectionClass -> newInstanceArgs ( $ parameters ) ; } catch ( MissingRequiredParameterException $ e ) { throw new InjectorInvocationException ( "Can't create $className " . " - __construct() missing parameter '" . $ e -> getParameterString ( ) . "'" . " could not be found. Either register it as a service or pass it to create via parameters." ) ; } catch ( InjectorInvocationException $ e ) { throw new InjectorInvocationException ( $ e -> getMessage ( ) . PHP_EOL . " => (Called when creating $className)" ) ; } } | Instantiate an object and attempt to inject the dependencies for the class by mapping constructor parameter \ names to objects registered within the IoC container . |
16,446 | public function canAutoCreate ( $ className ) { foreach ( $ this -> autoCreateWhiteList as $ regex ) { if ( preg_match ( $ regex , $ className ) ) { return true ; } } return false ; } | Check whether the Injector has been configured to allow automatic construction of the given FQCN as a dependency |
16,447 | private function buildParameterArray ( $ methodSignature , $ providedParameters ) { $ parameters = [ ] ; foreach ( $ methodSignature as $ position => $ parameterData ) { if ( ! isset ( $ parameterData [ 'variadic' ] ) ) { $ parameters [ $ position ] = $ this -> resolveParameter ( $ position , $ parameterData , $ providedParameters ) ; } else { foreach ( $ providedParameters as $ variadicParameter ) { $ parameters [ ] = $ variadicParameter ; } } } return $ parameters ; } | Construct the parameter array to be passed to a method call based on its parameter signature |
16,448 | public function getSignatureByReflectionClass ( \ ReflectionClass $ reflectionClass , $ methodName ) { $ className = $ reflectionClass -> getName ( ) ; return $ this -> getMethodSignature ( $ className , $ methodName , $ reflectionClass ) ; } | Fetch the method signature of a method when we have already created a \ ReflectionClass |
16,449 | public function createAutoWireClosure ( $ className , callable $ parameterFactory = null ) { return function ( Container $ app ) use ( $ className , $ parameterFactory ) { $ parameters = $ parameterFactory ? $ parameterFactory ( $ app ) : [ ] ; return $ this -> injector -> create ( $ className , $ parameters ) ; } ; } | Generate a closure that will use the Injector to auto - wire a service definition . |
16,450 | private function createProxy ( $ className , callable $ serviceFactory , Container $ app ) { return $ this -> proxyFactory -> createProxy ( $ className , function ( & $ wrappedObject , $ proxy , $ method , $ parameters , & $ initializer ) use ( $ className , $ serviceFactory , $ app ) { $ wrappedObject = $ serviceFactory ( $ app ) ; $ initializer = null ; return true ; } ) ; } | Create a project object for the specified ClassName bound to the given ServiceFactory method . |
16,451 | public function classmap ( ) { $ path = $ this -> composerPath . $ this -> classmapName ; $ i = 0 ; if ( is_file ( $ path ) ) { $ data = include $ path ; foreach ( $ data as $ key => $ value ) { if ( false === empty ( $ value ) ) { $ this -> libs [ addcslashes ( $ key , '\\' ) ] = $ value ; $ i ++ ; } } $ this -> log [ ] = 'Imported ' . $ i . ' classes from classmap' ; return $ i ; } $ this -> log [ ] = 'Warn: classmap not found' ; return false ; } | Load autoload_classmap . php classes |
16,452 | public function psr0 ( ) { $ i = $ this -> load ( $ this -> composerPath . $ this -> psrZeroName ) ; if ( $ i !== false ) { $ this -> log [ ] = 'Imported ' . $ i . ' classes from psr0' ; return $ i ; } $ this -> log [ ] = 'Warn: psr0 not found' ; return false ; } | Load autoload_namespaces . php classes used by PSR - 0 packages |
16,453 | public function psr4 ( ) { $ i = $ this -> load ( $ this -> composerPath . $ this -> psrFourName ) ; if ( $ i !== false ) { $ this -> log [ ] = 'Imported ' . $ i . ' classes from psr4' ; return $ i ; } $ this -> log [ ] = 'Warn: psr4 not found' ; return false ; } | Load autoload_psr4 . php classes used by PSR - 4 packages |
16,454 | public function save ( $ path ) { if ( count ( $ this -> libs ) === 0 ) { return false ; } $ handle = fopen ( $ path , 'w' ) ; if ( $ handle === false ) { throw new \ InvalidArgumentException ( 'This path is not writabled: ' . $ path ) ; } $ first = true ; $ eol = chr ( 10 ) ; fwrite ( $ handle , '<?php' . $ eol . 'return array(' ) ; foreach ( $ this -> libs as $ key => $ value ) { $ value = self :: relativePath ( $ value ) ; fwrite ( $ handle , ( $ first ? '' : ',' ) . $ eol . " '" . $ key . "' => '" . $ value . "'" ) ; $ first = false ; } fwrite ( $ handle , $ eol . ');' . $ eol ) ; fclose ( $ handle ) ; return true ; } | Save imported packages path to file in PHP format |
16,455 | public static function version ( $ name ) { $ file = INPHINIT_ROOT . 'composer.lock' ; $ data = is_file ( $ file ) ? json_decode ( file_get_contents ( $ file ) ) : false ; if ( empty ( $ data -> packages ) ) { return false ; } $ version = false ; foreach ( $ data -> packages as $ package ) { if ( $ package -> name === $ name ) { $ version = $ package -> version ; break ; } } $ data = null ; return $ version ; } | Get package version from composer . lock file |
16,456 | public function get ( $ object ) : array { $ values = $ this -> storage -> get ( $ object ) ; return ( $ values === null ) ? [ ] : $ values ; } | Returns the values associated to the given object . |
16,457 | public function add ( $ object , $ value ) : void { $ values = $ this -> get ( $ object ) ; $ values [ ] = $ value ; $ this -> storage -> set ( $ object , $ values ) ; } | Adds data associated with the given object . |
16,458 | private function getDimensions ( \ media_subdef $ subdef ) { $ outWidth = $ subdef -> get_width ( ) ; $ outHeight = $ subdef -> get_height ( ) | $ outWidth ; $ thumbnail_height = $ subdef -> get_height ( ) > 0 ? $ subdef -> get_height ( ) : 120 ; $ thumbnail_width = $ subdef -> get_width ( ) > 0 ? $ subdef -> get_width ( ) : 120 ; $ subdefRatio = 0 ; $ thumbnailRatio = $ thumbnail_width / $ thumbnail_height ; if ( $ outWidth > 0 && $ outHeight > 0 ) { $ subdefRatio = $ outWidth / $ outHeight ; } if ( $ thumbnailRatio > $ subdefRatio ) { if ( $ outWidth > $ thumbnail_width ) { $ outWidth = $ thumbnail_width ; } $ outHeight = $ outWidth / $ thumbnail_width * $ thumbnail_height ; $ top = ( $ outHeight - $ outHeight ) / 2 ; } else { if ( $ outHeight > $ thumbnail_height ) { $ outHeight = $ thumbnail_height ; } $ outWidth = $ outHeight * $ thumbnail_width / $ thumbnail_height ; $ top = ( ( $ outHeight - $ outHeight ) / 2 ) ; } return [ 'width' => round ( $ outWidth ) , 'height' => round ( $ outHeight ) , 'top' => $ top ] ; } | Php raw implementation of thumbnails . html . twig macro |
16,459 | public function getVideoTextTrackContent ( MediaInformation $ media , $ id ) { $ id = ( int ) $ id ; $ record = $ media -> getResource ( ) -> get_record ( ) ; $ videoTextTrack = false ; if ( $ record -> getType ( ) === 'video' ) { $ databox = $ record -> getDatabox ( ) ; $ vttIds = [ ] ; foreach ( $ databox -> get_meta_structure ( ) as $ meta ) { if ( preg_match ( '/^VideoTextTrack(.*)$/iu' , $ meta -> get_name ( ) , $ foundParts ) ) { $ vttIds [ ] = $ meta -> get_id ( ) ; } } foreach ( $ record -> get_caption ( ) -> get_fields ( null , true ) as $ field ) { if ( ! in_array ( $ id , $ vttIds ) || $ id !== $ field -> get_meta_struct_id ( ) ) { continue ; } foreach ( $ field -> get_values ( ) as $ value ) { $ videoTextTrack = $ value -> getValue ( ) ; } } } return $ videoTextTrack ; } | Fetch vtt files content if exists |
16,460 | public static function ignoreif ( $ callback ) { if ( is_callable ( $ callback ) === false ) { throw new Exception ( 'Invalid callback' ) ; } App :: on ( 'init' , function ( ) use ( $ callback ) { if ( $ callback ( ) ) { App :: env ( 'maintenance' , false ) ; } } ) ; } | Up the site only in certain conditions eg . the site administrator of the IP . |
16,461 | public static function createFromFormat ( $ format , $ date , $ tz = null ) { if ( $ tz !== null ) { $ tz = static :: safeCreateDateTimeZone ( $ tz ) ; } $ instance = new static ( $ tz ) ; $ instance -> parseFormat ( $ format , $ date ) ; return $ instance ; } | Create a JDate instance from a specific format |
16,462 | private static function calculateYearInQuadCycle ( $ year ) { $ yearInGrandCycle = static :: calculateYearInGrandCycle ( $ year ) ; $ yearInQuadCycle = $ yearInGrandCycle % static :: FIRST_QUAD_CYCLE ; if ( ( static :: GRAND_CYCLE_LENGTH - static :: SECOND_QUAD_CYCLE ) < $ yearInGrandCycle ) { $ yearInQuadCycle = $ yearInGrandCycle - ( 21 * static :: FIRST_QUAD_CYCLE ) ; } return $ yearInQuadCycle ; } | check the quad cycle type & count |
16,463 | private static function calculateYearInGrandCycle ( $ year ) { $ grandCycle = static :: calculateGrandCycle ( $ year ) ; if ( $ grandCycle < 0 ) { $ year = ( static :: GRAND_CYCLE_BEGINNING + ( $ grandCycle * static :: GRAND_CYCLE_LENGTH ) ) - $ year ; } elseif ( $ grandCycle > 0 ) { $ year = $ year - ( static :: GRAND_CYCLE_BEGINNING + ( $ grandCycle * static :: GRAND_CYCLE_LENGTH ) ) ; } else { $ year -= static :: GRAND_CYCLE_BEGINNING ; } $ yearInGrandCycle = abs ( $ year ) + 1 ; return $ yearInGrandCycle ; } | returns the number of year in current grand cycle |
16,464 | private static function calculateGrandCycle ( $ year ) { $ endOfFirstGrandCycle = static :: GRAND_CYCLE_BEGINNING + static :: GRAND_CYCLE_LENGTH ; $ grandCycle = 0 ; if ( $ year < static :: GRAND_CYCLE_BEGINNING ) { $ beginningYear = static :: GRAND_CYCLE_BEGINNING ; while ( $ year < $ beginningYear ) { $ beginningYear -= static :: GRAND_CYCLE_LENGTH ; $ grandCycle -- ; } } elseif ( $ year >= $ endOfFirstGrandCycle ) { $ beginningYear = $ endOfFirstGrandCycle ; while ( $ year >= $ beginningYear ) { $ beginningYear += static :: GRAND_CYCLE_LENGTH ; $ grandCycle ++ ; } } return $ grandCycle ; } | calculate that which grand cycle we are in |
16,465 | private function setYear ( $ year ) { if ( $ year == $ this -> year ) { return ; } $ this -> year = ( int ) $ year ; $ maximumDayAvailable = static :: getMonthLength ( $ this -> year , $ this -> month ) ; if ( $ this -> day > $ maximumDayAvailable ) { $ this -> day = $ maximumDayAvailable ; } } | Update year in jalali date |
16,466 | private function setMonth ( $ month ) { if ( $ month == $ this -> month ) { return ; } $ yearToSet = $ this -> year ; $ monthToSet = $ month ; if ( $ monthToSet < 1 ) { $ monthToSet = abs ( $ monthToSet ) ; $ yearToSet -- ; $ yearToSet -= floor ( $ monthToSet / 12 ) ; $ monthToSet = 12 - ( $ monthToSet % 12 ) ; } elseif ( $ monthToSet > 12 ) { $ yearToSet += floor ( $ monthToSet / 12 ) ; $ monthToSet = ( $ month % 12 ) ; if ( $ monthToSet == 0 ) { $ monthToSet = 12 ; $ yearToSet -- ; } } $ this -> month = ( int ) $ monthToSet ; $ this -> setYear ( $ yearToSet ) ; } | Update month in jalali date |
16,467 | private function setDay ( $ day ) { if ( $ day == $ this -> day ) { return ; } $ maximumDayOfMonth = static :: getMonthLength ( $ this -> month , $ this -> year ) ; $ dayToSet = $ day ; if ( $ dayToSet < 1 ) { $ dayToSet = abs ( $ dayToSet ) ; while ( $ dayToSet > $ maximumDayOfMonth ) { $ dayToSet -= $ maximumDayOfMonth ; $ month = $ this -> month - 1 ; $ this -> setMonth ( $ month ) ; $ maximumDayOfMonth = static :: getMonthLength ( $ this -> month , $ this -> year ) ; } $ dayToSet = $ maximumDayOfMonth - $ dayToSet ; $ month = $ this -> month - 1 ; $ this -> setMonth ( $ month ) ; } elseif ( $ dayToSet > $ maximumDayOfMonth ) { while ( $ dayToSet > $ maximumDayOfMonth ) { $ dayToSet -= $ maximumDayOfMonth ; $ month = $ this -> month + 1 ; $ this -> setMonth ( $ month ) ; $ maximumDayOfMonth = static :: getMonthLength ( $ this -> month , $ this -> year ) ; } } $ this -> day = ( int ) $ dayToSet ; } | Update day in jalali date |
16,468 | public function year ( $ value ) { $ this -> setDate ( $ value , $ this -> month , $ this -> day ) ; return $ this ; } | Set the instance s year |
16,469 | public function setDate ( $ year , $ month , $ day ) { $ this -> setYear ( ( int ) $ year ) ; $ this -> setMonth ( ( int ) $ month ) ; $ this -> setDay ( ( int ) $ day ) ; $ this -> updateGeorgianFromJalali ( ) ; return $ this ; } | Sets the current date of the DateTime object to a different date . |
16,470 | public function setTime ( $ hour , $ minute , $ second = 0 ) { $ this -> carbon -> setTime ( $ hour , $ minute , $ second ) ; return $ this ; } | Sets the current time of the DateTime object to a different time . |
16,471 | private function updateJalaliFromGeorgian ( $ force = false ) { if ( $ this -> converted && ! $ force ) { return ; } list ( $ year , $ month , $ day ) = self :: julian2jalali ( self :: georgian2julian ( $ this -> carbon -> year , $ this -> carbon -> month , $ this -> carbon -> day ) ) ; $ this -> year = $ year ; $ this -> month = $ month ; $ this -> day = $ day ; $ this -> converted = true ; } | Update the Jalali Core from the Carbon As Georgian Core |
16,472 | protected static function jalali2julian ( $ year , $ month , $ day ) { $ parsed = self :: parseJalali ( $ year ) ; return self :: georgian2julian ( $ parsed [ 'gYear' ] , 3 , $ parsed [ 'march' ] ) + ( $ month - 1 ) * 31 - self :: division ( $ month , 7 ) * ( $ month - 7 ) + $ day - 1 ; } | Converts a date of the Jalali calendar to the Julian Day number . |
16,473 | protected static function julian2jalali ( $ julianDayNumber ) { $ gYear = self :: julian2georgian ( $ julianDayNumber ) [ 0 ] ; $ year = $ gYear - static :: HEGIRA_STARTING_YEAR ; $ parsed = self :: parseJalali ( $ year ) ; $ jdn1f = self :: georgian2julian ( $ gYear , 3 , $ parsed [ 'march' ] ) ; $ passed = $ julianDayNumber - $ jdn1f ; if ( $ passed >= 0 ) { if ( $ passed <= 185 ) { $ month = 1 + self :: division ( $ passed , 31 ) ; $ day = ( $ passed % 31 ) + 1 ; return [ $ year , $ month , $ day ] ; } else { $ passed -= 186 ; } } else { $ year -= 1 ; $ passed += 179 ; if ( $ parsed [ 'leap' ] === 1 ) { $ passed += 1 ; } } $ month = 7 + self :: division ( $ passed , 30 ) ; $ day = ( $ passed % 30 ) + 1 ; return [ $ year , $ month , $ day ] ; } | Converts the Julian Day number to a date in the Jalali calendar . |
16,474 | public function fromArray ( array $ data ) { if ( empty ( $ data ) ) { throw new DomException ( 'Array is empty' , 2 ) ; } elseif ( count ( $ data ) > 1 ) { throw new DomException ( 'Root array accepts only a key' , 2 ) ; } elseif ( Helper :: seq ( $ data ) ) { throw new DomException ( 'Document accpet only a node' , 2 ) ; } if ( $ this -> documentElement ) { $ this -> removeChild ( $ this -> documentElement ) ; } $ this -> enableRestoreInternal ( true ) ; $ this -> generate ( $ this , $ data ) ; $ this -> raise ( $ this -> exceptionlevel ) ; $ this -> enableRestoreInternal ( false ) ; } | Convert a array in node elements |
16,475 | public function toJson ( $ format = Document :: MININAL , $ options = 0 ) { $ this -> exceptionlevel = 4 ; $ json = json_encode ( $ this -> toArray ( $ format ) , $ options ) ; $ this -> exceptionlevel = 3 ; return $ json ; } | Convert DOM to JSON string |
16,476 | public function toArray ( $ type = Document :: SIMPLE ) { switch ( $ type ) { case Document :: MININAL : $ this -> simple = false ; $ this -> complete = false ; break ; case Document :: SIMPLE : $ this -> simple = true ; break ; case Document :: COMPLETE : $ this -> complete = true ; break ; default : throw new DomException ( 'Invalid type' , 2 ) ; } return $ this -> getNodes ( $ this -> childNodes , true ) ; } | Convert DOM to Array |
16,477 | public function save ( $ path , $ format = Document :: XML ) { switch ( $ format ) { case Document :: XML : $ format = 'saveXML' ; break ; case Document :: HTML : $ format = 'saveHTML' ; break ; case Document :: JSON : $ format = 'toJson' ; break ; default : throw new DomException ( 'Invalid format' , 2 ) ; } $ tmp = Storage :: temp ( $ this -> $ format ( ) , 'tmp' , '~xml-' ) ; if ( $ tmp === false ) { throw new DomException ( 'Can\'t create tmp file' , 2 ) ; } elseif ( copy ( $ tmp , $ path ) === false ) { throw new DomException ( 'Can\'t copy tmp file to ' . $ path , 2 ) ; } else { unlink ( $ tmp ) ; } } | Save file to location |
16,478 | public function getNamespaces ( \ DOMElement $ element = null ) { if ( $ this -> xpath === null ) { $ this -> xpath = new \ DOMXPath ( $ this ) ; } if ( $ element === null ) { $ nodes = $ this -> xpath -> query ( 'namespace::*' ) ; } else { $ nodes = $ this -> xpath -> query ( 'namespace::*' , $ element ) ; } $ ns = array ( ) ; if ( $ nodes ) { foreach ( $ nodes as $ node ) { $ arr = $ element -> getAttribute ( $ node -> nodeName ) ; if ( $ arr ) { $ ns [ $ node -> nodeName ] = $ arr ; } } $ nodes = null ; } return $ ns ; } | Get namespace attributes from root element or specific element |
16,479 | public function query ( $ selector , \ DOMNode $ context = null ) { $ this -> enableRestoreInternal ( true ) ; if ( $ this -> selector === null ) { $ this -> selector = new Selector ( $ this ) ; } $ nodes = $ this -> selector -> get ( $ selector , $ context ) ; $ this -> raise ( $ this -> exceptionlevel ) ; $ this -> enableRestoreInternal ( false ) ; return $ nodes ; } | Use query - selector like CSS jQuery querySelectorAll |
16,480 | public function first ( $ selector , \ DOMNode $ context = null ) { $ this -> exceptionlevel = 4 ; $ nodes = $ this -> query ( $ selector , $ context ) ; $ this -> exceptionlevel = 3 ; $ node = $ nodes -> length ? $ nodes -> item ( 0 ) : null ; $ nodes = null ; return $ node ; } | Use query - selector like CSS jQuery querySelector |
16,481 | public function getCard ( $ index = 0 , $ failOnNoCardFound = false ) { if ( ! array_key_exists ( $ index , $ this -> reel [ 'cards' ] ) ) { if ( $ failOnNoCardFound ) { throw new Exception \ NoCardFoundException ( sprintf ( "Cannot resolve a card value for the '%s' slot. (Perhaps you need to set a '_default' alias for the slot or the card of index 0 is missing from the slot's assigned reel?)" , $ this -> name ) ) ; } switch ( $ this -> undefinedCardResolution ) { case UndefinedCardResolution :: NO_CARD_FOUND_EXCEPTION : default : throw new Exception \ NoCardFoundException ( sprintf ( "Card of index %d was not found in the slot `%s`." , $ index , $ this -> name ) ) ; case UndefinedCardResolution :: DEFAULT_CARD : return $ this -> getDefaultCard ( ) ; case UndefinedCardResolution :: FALLBACK_CARD : return $ this -> getFallbackCard ( ) ; case UndefinedCardResolution :: BLANK_CARD : return '' ; } } return $ this -> reel [ 'cards' ] [ $ index ] ; } | Get a value of a card by its index . If the card does not exist resolve based on the slot s resolve_undefined setting . |
16,482 | public function getCardByAlias ( $ alias ) { if ( ! array_key_exists ( $ alias , $ this -> aliases ) ) { throw new Exception \ NoSuchAliasException ( sprintf ( 'Alias "%s" has not been assigned to any cards.' , $ alias ) ) ; } return $ this -> getCard ( $ this -> aliases [ $ alias ] ) ; } | Get a card from the reel by an alias . |
16,483 | function FrontMatter ( $ input ) { if ( ! $ this -> startsWith ( $ input , $ this -> yaml_separator ) ) { $ final [ 'content' ] = $ input ; return $ final ; } $ document = explode ( $ this -> yaml_separator , $ input , 3 ) ; switch ( sizeof ( $ document ) ) { case 0 : case 1 : $ front_matter = "" ; $ content = "" ; break ; case 2 : $ front_matter = $ document [ 1 ] ; $ content = "" ; break ; default : $ front_matter = $ document [ 1 ] ; $ content = $ document [ 2 ] ; } try { $ final = Yaml :: parse ( $ front_matter ) ; } catch ( ParseException $ e ) { printf ( "Unable to parse the YAML string: %s" , $ e -> getMessage ( ) ) ; } $ final [ 'content' ] = $ content ; return $ final ; } | FrontMatter method rturns all the variables from a YAML Frontmatter input |
16,484 | protected function Read ( $ file ) { $ fh = fopen ( $ file , 'r' ) ; $ fileSize = filesize ( $ file ) ; if ( ! empty ( $ fileSize ) ) { $ data = fread ( $ fh , $ fileSize ) ; $ data = str_replace ( array ( "\r\n" , "\r" , "\n" ) , "\n" , $ data ) ; } else { $ data = '' ; } fclose ( $ fh ) ; return $ data ; } | Read Method Read file and returns it s contents |
16,485 | public static function parseVersion ( $ version ) { if ( preg_match ( '#^(\d+)\.(\d+)\.(\d+)(\-([\w.\-]+)|)$#' , $ version , $ match ) ) { return ( object ) array ( 'major' => $ match [ 1 ] , 'minor' => $ match [ 2 ] , 'patch' => $ match [ 3 ] , 'extra' => empty ( $ match [ 5 ] ) ? null : $ match [ 5 ] ) ; } return false ; } | Parse version format |
16,486 | public static function toAscii ( $ text ) { $ encode = mb_detect_encoding ( $ text , mb_detect_order ( ) , true ) ; return 'ASCII' === $ encode ? $ text : iconv ( $ encode , 'ASCII//TRANSLIT//IGNORE' , $ text ) ; } | Convert string to ASCII |
16,487 | public static function capitalize ( $ text , $ delimiter = '-' , $ glue = '' ) { return implode ( $ glue , array_map ( 'ucfirst' , explode ( $ delimiter , strtolower ( $ text ) ) ) ) ; } | Capitalize words using hyphen or a custom delimiter . |
16,488 | public static function extract ( $ path , $ items ) { $ paths = explode ( '.' , $ path ) ; foreach ( $ paths as $ value ) { if ( self :: iterable ( $ items ) && array_key_exists ( $ value , $ items ) ) { $ items = $ items [ $ value ] ; } else { return false ; } } return $ items ; } | Read array by path using dot |
16,489 | public static function resolve ( $ path ) { if ( empty ( $ path ) ) { return false ; } $ path = Uri :: canonpath ( $ path ) ; if ( $ path . '/' === self :: path ( ) || strpos ( $ path , self :: path ( ) ) === 0 ) { return $ path ; } return self :: path ( ) . $ path ; } | Convert path to storage path |
16,490 | public static function autoclean ( $ path , $ time = - 1 ) { $ path = self :: resolve ( $ path ) ; if ( $ path !== false && is_dir ( $ path ) && ( $ dh = opendir ( $ path ) ) ) { if ( $ time < 0 ) { $ time = App :: env ( 'appdata_expires' ) ; } $ expires = REQUEST_TIME - $ time ; $ path .= '/' ; while ( false !== ( $ file = readdir ( $ dh ) ) ) { $ current = $ path . $ file ; if ( is_file ( $ current ) && filemtime ( $ current ) < $ expires ) { unlink ( $ current ) ; } } closedir ( $ dh ) ; $ dh = null ; } } | Clear old files in a folder from storage path |
16,491 | public static function put ( $ path , $ data = null , $ flags = null ) { $ path = self :: resolve ( $ path ) ; if ( $ path === false ) { return false ; } $ data = is_numeric ( $ data ) === false && ! $ data ? '' : $ data ; if ( is_file ( $ path ) && ! $ data ) { return true ; } $ flags = $ flags ? $ flags : FILE_APPEND | LOCK_EX ; return self :: createFolder ( dirname ( $ path ) ) && file_put_contents ( $ path , $ data , $ flags ) !== false ; } | Create a file in a folder in storage or append data to existing file |
16,492 | public static function remove ( $ path ) { $ path = self :: resolve ( $ path ) ; return $ path && is_file ( $ path ) && unlink ( $ path ) ; } | Delete a file in storage |
16,493 | public static function removeFolder ( $ path ) { $ path = self :: resolve ( $ path ) ; return $ path && is_dir ( $ path ) && self :: rrmdir ( $ path ) ; } | Remove recursive folders in storage folder |
16,494 | private static function rrmdir ( $ path ) { $ path .= '/' ; foreach ( array_diff ( scandir ( $ path ) , array ( '..' , '.' ) ) as $ file ) { $ current = $ path . $ file ; if ( is_dir ( $ current ) ) { if ( self :: rrmdir ( $ current ) === false ) { return false ; } } elseif ( unlink ( $ current ) === false ) { return false ; } } return rmdir ( $ path ) ; } | Remove recursive folders |
16,495 | public function commit ( $ unlock = true ) { if ( empty ( $ this -> insertions ) && empty ( $ this -> deletions ) ) { return null ; } $ this -> lock ( ) ; $ data = '' ; rewind ( $ this -> handle ) ; $ data = trim ( stream_get_contents ( $ this -> handle ) ) ; if ( $ data !== '' ) { $ data = unserialize ( $ data ) ; $ this -> data = $ this -> insertions + $ data ; $ data = null ; foreach ( $ this -> deletions as $ key => $ value ) { unset ( $ this -> data [ $ key ] ) ; } } else { $ this -> data = $ this -> insertions ; } $ this -> insertions = array ( ) ; $ this -> deletions = array ( ) ; $ this -> write ( ) ; if ( $ unlock ) { flock ( $ this -> handle , LOCK_UN ) ; } $ this -> iterator = new \ ArrayIterator ( $ this -> data ) ; } | Lock session file and save variables |
16,496 | private function read ( ) { $ this -> lock ( ) ; $ data = '' ; rewind ( $ this -> handle ) ; $ data = trim ( stream_get_contents ( $ this -> handle ) ) ; if ( $ data !== '' ) { $ this -> data = unserialize ( $ data ) ; $ data = null ; } flock ( $ this -> handle , LOCK_UN ) ; $ this -> iterator = new \ ArrayIterator ( $ this -> data ) ; } | Read session file |
16,497 | private function write ( ) { ftruncate ( $ this -> handle , 0 ) ; rewind ( $ this -> handle ) ; fwrite ( $ this -> handle , serialize ( $ this -> data ) ) ; } | Write variables in session file |
16,498 | public static function setup ( $ byType , array $ attributes ) { if ( 0 !== preg_match ( '#^(' . self :: $ alloweds . '|select|form)$#' , $ type ) ) { self :: $ preAttrs [ $ byType ] = $ attributes ; } } | Define default attributes for all elements |
16,499 | public static function comboRange ( $ name , $ low , $ high , $ step = null , $ value = null , array $ attributes = array ( ) ) { $ range = $ step !== null ? range ( $ low , $ high , $ step ) : range ( $ low , $ high ) ; $ range = array_combine ( $ range , $ range ) ; return self :: combo ( $ name , $ range , $ value , $ attributes ) ; } | Generate combo by range |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.