idx
int64 0
60.3k
| question
stringlengths 101
6.21k
| target
stringlengths 7
803
|
|---|---|---|
57,400
|
protected function checkBrowserAndroidThinkPadTablet ( ) { if ( stripos ( $ this -> _agent , 'Android' ) !== false ) { if ( stripos ( $ this -> _agent , 'ThinkPad Tablet' ) !== false ) { $ this -> setVersion ( self :: VERSION_UNKNOWN ) ; $ this -> setMobile ( true ) ; $ this -> setBrowser ( self :: BROWSER_LENOVO_THINKPAD_TABLET ) ; return true ; } } return false ; }
|
Determine if the browser is a Lenovo ThinkPad Tablet or not add by BugBuster
|
57,401
|
protected function checkBrowserAndroidXoomTablet ( ) { if ( stripos ( $ this -> _agent , 'Android' ) !== false ) { if ( stripos ( $ this -> _agent , 'Xoom Build' ) !== false ) { $ this -> setVersion ( self :: VERSION_UNKNOWN ) ; $ this -> setMobile ( true ) ; $ this -> setBrowser ( self :: BROWSER_MOTOROLA_XOOM_TABLET ) ; return true ; } } return false ; }
|
Determine if the browser is a Motorola Xoom Tablet or not add by BugBuster
|
57,402
|
protected function checkBrowserAndroidAsusTransfomerPad ( ) { if ( stripos ( $ this -> _agent , 'Android' ) !== false ) { if ( stripos ( $ this -> _agent , 'ASUS Transformer Pad' ) !== false ) { $ this -> setVersion ( self :: VERSION_UNKNOWN ) ; $ this -> setMobile ( true ) ; $ this -> setBrowser ( self :: BROWSER_ASUS_TRANSFORMER_PAD ) ; return true ; } } return false ; }
|
Determine if the browser is a Asus Transfomer Pad or not add by BugBuster
|
57,403
|
public function getPlatformVersion ( ) { if ( $ this -> _platformVersion === self :: PLATFORM_UNKNOWN ) { $ this -> _platformVersion = $ this -> _platform ; } return $ this -> _platformVersion ; }
|
The name of the platform . All return types are from the class contants Fallback platformVersion with platform if platformVersion unknown
|
57,404
|
protected function setLang ( ) { $ array = explode ( "," , $ this -> _accept_language ) ; $ ca = count ( $ array ) ; for ( $ i = 0 ; $ i < $ ca ; $ i ++ ) { $ array [ $ i ] = str_replace ( " " , null , $ array [ $ i ] ) ; $ array [ $ i ] = substr ( $ array [ $ i ] , 0 , 2 ) ; $ array [ $ i ] = strtolower ( $ array [ $ i ] ) ; } $ array = array_unique ( $ array ) ; $ this -> _lang = strtoupper ( $ array [ 0 ] ) ; if ( empty ( $ this -> _lang ) || strlen ( $ this -> _lang ) < 2 ) { $ this -> _lang = 'Unknown' ; } return true ; }
|
Ermittle akzeptierten Sprachen
|
57,405
|
public function handle ( string $ method = null , string $ path = null , $ action , array $ arguments = [ ] , ContainerInterface $ di = null ) { $ this -> di = $ di ; if ( is_null ( $ action ) ) { return ; } if ( is_callable ( $ action ) ) { if ( is_array ( $ action ) && is_string ( $ action [ 0 ] ) && class_exists ( $ action [ 0 ] ) ) { $ action [ ] = $ arguments ; return $ this -> handleAsControllerAction ( $ action ) ; } return $ this -> handleAsCallable ( $ action , $ arguments ) ; } if ( is_string ( $ action ) && class_exists ( $ action ) ) { $ callable = $ this -> isControllerAction ( $ method , $ path , $ action ) ; if ( $ callable ) { return $ this -> handleAsControllerAction ( $ callable ) ; } } if ( $ di && is_array ( $ action ) && isset ( $ action [ 0 ] ) && isset ( $ action [ 1 ] ) && is_string ( $ action [ 0 ] ) ) { return $ this -> handleUsingDi ( $ action , $ arguments , $ di ) ; } throw new ConfigurationException ( "Handler for route does not seem to be a callable action." ) ; }
|
Handle the action for a route and return the results .
|
57,406
|
public function getHandlerType ( $ action , ContainerInterface $ di = null ) { if ( is_null ( $ action ) ) { return "null" ; } if ( is_callable ( $ action ) ) { return "callable" ; } if ( is_string ( $ action ) && class_exists ( $ action ) ) { $ callable = $ this -> isControllerAction ( null , null , $ action ) ; if ( $ callable ) { return "controller" ; } } if ( $ di && is_array ( $ action ) && isset ( $ action [ 0 ] ) && isset ( $ action [ 1 ] ) && is_string ( $ action [ 0 ] ) && $ di -> has ( $ action [ 0 ] ) && is_callable ( [ $ di -> get ( $ action [ 0 ] ) , $ action [ 1 ] ] ) ) { return "di" ; } return "not found" ; }
|
Get an informative string representing the handler type .
|
57,407
|
protected function isControllerAction ( string $ method = null , string $ path = null , string $ class ) { $ method = ucfirst ( strtolower ( $ method ) ) ; $ args = explode ( "/" , $ path ) ; $ action = array_shift ( $ args ) ; $ action = empty ( $ action ) ? "index" : $ action ; $ action = str_replace ( "-" , "" , $ action ) ; $ action1 = "{$action}Action{$method}" ; $ action2 = "{$action}Action" ; $ action3 = "catchAll{$method}" ; $ action4 = "catchAll" ; foreach ( [ $ action1 , $ action2 ] as $ target ) { try { $ refl = new \ ReflectionMethod ( $ class , $ target ) ; if ( ! $ refl -> isPublic ( ) ) { throw new NotFoundException ( "Controller method '$class::$target' is not a public method." ) ; } return [ $ class , $ target , $ args ] ; } catch ( \ ReflectionException $ e ) { ; } } foreach ( [ $ action3 , $ action4 ] as $ target ) { try { $ refl = new \ ReflectionMethod ( $ class , $ target ) ; if ( ! $ refl -> isPublic ( ) ) { throw new NotFoundException ( "Controller method '$class::$target' is not a public method." ) ; } array_unshift ( $ args , $ action ) ; return [ $ class , $ target , $ args ] ; } catch ( \ ReflectionException $ e ) { ; } } return false ; }
|
Check if items can be used to call a controller action verify that the controller exists the action has a class - method to call .
|
57,408
|
protected function handleAsControllerAction ( array $ callable ) { $ class = $ callable [ 0 ] ; $ action = $ callable [ 1 ] ; $ args = $ callable [ 2 ] ; $ obj = new $ class ( ) ; $ refl = new \ ReflectionClass ( $ class ) ; $ diInterface = "Anax\Commons\ContainerInjectableInterface" ; $ appInterface = "Anax\Commons\AppInjectableInterface" ; if ( $ this -> di && $ refl -> implementsInterface ( $ diInterface ) ) { $ obj -> setDI ( $ this -> di ) ; } elseif ( $ this -> di && $ refl -> implementsInterface ( $ appInterface ) ) { if ( ! $ this -> di -> has ( "app" ) ) { throw new ConfigurationException ( "Controller '$class' implements AppInjectableInterface but \$app is not available in \$di." ) ; } $ obj -> setApp ( $ this -> di -> get ( "app" ) ) ; } try { $ refl = new \ ReflectionMethod ( $ class , "initialize" ) ; if ( $ refl -> isPublic ( ) ) { $ obj -> initialize ( ) ; } } catch ( \ ReflectionException $ e ) { ; } $ refl = new \ ReflectionMethod ( $ obj , $ action ) ; $ paramIsVariadic = false ; foreach ( $ refl -> getParameters ( ) as $ param ) { if ( $ param -> isVariadic ( ) ) { $ paramIsVariadic = true ; break ; } } if ( ! $ paramIsVariadic && $ refl -> getNumberOfParameters ( ) < count ( $ args ) ) { throw new NotFoundException ( "Controller '$class' with action method '$action' valid but to many parameters. Got " . count ( $ args ) . ", expected " . $ refl -> getNumberOfParameters ( ) . "." ) ; } try { $ res = $ obj -> $ action ( ... $ args ) ; } catch ( \ ArgumentCountError $ e ) { throw new NotFoundException ( $ e -> getMessage ( ) ) ; } catch ( \ TypeError $ e ) { throw new NotFoundException ( $ e -> getMessage ( ) ) ; } return $ res ; }
|
Call the controller action with optional arguments and call initialisation methods if available .
|
57,409
|
protected function handleAsCallable ( $ action , array $ arguments ) { if ( is_array ( $ action ) && isset ( $ action [ 0 ] ) && isset ( $ action [ 1 ] ) && is_string ( $ action [ 0 ] ) && is_string ( $ action [ 1 ] ) && class_exists ( $ action [ 0 ] ) ) { $ refl = new \ ReflectionMethod ( $ action [ 0 ] , $ action [ 1 ] ) ; if ( $ refl -> isPublic ( ) && ! $ refl -> isStatic ( ) ) { $ obj = new $ action [ 0 ] ( ) ; return $ obj -> { $ action [ 1 ] } ( ... $ arguments ) ; } } $ refl = is_array ( $ action ) ? new \ ReflectionMethod ( $ action [ 0 ] , $ action [ 1 ] ) : new \ ReflectionFunction ( $ action ) ; $ params = $ refl -> getParameters ( ) ; if ( isset ( $ params [ 0 ] ) && $ params [ 0 ] -> getName ( ) === "di" ) { array_unshift ( $ arguments , $ this -> di ) ; } return call_user_func ( $ action , ... $ arguments ) ; }
|
Handle as callable support callables where the method is not static .
|
57,410
|
private function checkPartMatchingType ( $ value , $ type ) { switch ( $ type ) { case "digit" : return ctype_digit ( $ value ) ; break ; case "hex" : return ctype_xdigit ( $ value ) ; break ; case "alpha" : return ctype_alpha ( $ value ) ; break ; case "alphanum" : return ctype_alnum ( $ value ) ; break ; default : return false ; } }
|
Check if value is matching a certain type of values .
|
57,411
|
private function matchPart ( $ rulePart , $ queryPart , & $ args ) { $ match = false ; $ first = isset ( $ rulePart [ 0 ] ) ? $ rulePart [ 0 ] : '' ; switch ( $ first ) { case '*' : $ match = true ; break ; case '{' : $ match = $ this -> checkPartAsArgument ( $ rulePart , $ queryPart , $ args ) ; break ; default : $ match = ( $ rulePart == $ queryPart ) ; break ; } return $ match ; }
|
Match part of rule and query .
|
57,412
|
private function matchRequestMethod ( string $ method = null , array $ supported = null ) { if ( $ supported && ! in_array ( $ method , $ supported ) ) { return false ; } return true ; }
|
Check if the request method matches .
|
57,413
|
private function namespaceMatches ( ) : bool { $ currentNamespace = ( $ this -> currentNamespace && is_array ( $ this -> currentNamespace -> name -> parts ) ) ? $ this -> currentNamespace -> name -> toString ( ) : '' ; return $ currentNamespace === $ this -> reflectedClass -> getNamespaceName ( ) ; }
|
Checks if the current namespace matches with the one provided with the reflection class
|
57,414
|
public function swapExtensionFilter ( $ path_or_url , $ extension ) { $ path = $ this -> decomposeUrl ( $ path_or_url ) ; $ path_parts = pathinfo ( $ path [ 'path' ] ) ; $ new_path = $ path_parts [ 'filename' ] . "." . $ extension ; if ( ! empty ( $ path_parts [ 'dirname' ] ) && $ path_parts [ 'dirname' ] !== "." ) { $ new_path = $ path_parts [ 'dirname' ] . DIRECTORY_SEPARATOR . $ new_path ; $ new_path = preg_replace ( '#/+#' , '/' , $ new_path ) ; } $ output = $ path [ 'prefix' ] . $ new_path . $ path [ 'suffix' ] ; return $ output ; }
|
Swap the file extension on a passed url or path
|
57,415
|
public function swapDirectoryFilter ( $ path_or_url , $ directory ) { $ path = $ this -> decomposeUrl ( $ path_or_url ) ; $ path_parts = pathinfo ( $ path [ 'path' ] ) ; $ new_path = $ directory . DIRECTORY_SEPARATOR . $ path_parts [ 'basename' ] ; $ output = $ path [ 'prefix' ] . $ new_path . $ path [ 'suffix' ] ; return $ output ; }
|
Swap the file directory on a passed url or path
|
57,416
|
public function appendSuffixFilter ( $ path_or_url , $ suffix ) { $ path = $ this -> decomposeUrl ( $ path_or_url ) ; $ path_parts = pathinfo ( $ path [ 'path' ] ) ; $ new_path = $ path_parts [ 'filename' ] . $ suffix . "." . $ path_parts [ 'extension' ] ; if ( ! empty ( $ path_parts [ 'dirname' ] ) && $ path_parts [ 'dirname' ] !== "." ) { $ new_path = $ path_parts [ 'dirname' ] . DIRECTORY_SEPARATOR . $ new_path ; $ new_path = preg_replace ( '#/+#' , '/' , $ new_path ) ; } $ output = $ path [ 'prefix' ] . $ new_path . $ path [ 'suffix' ] ; return $ output ; }
|
Append a suffix a passed url or path
|
57,417
|
private function decomposeUrl ( $ path_or_url ) { $ result = array ( ) ; if ( filter_var ( $ path_or_url , FILTER_VALIDATE_URL ) ) { $ url_parts = parse_url ( $ path_or_url ) ; $ result [ 'prefix' ] = $ url_parts [ 'scheme' ] . "://" . $ url_parts [ 'host' ] ; $ result [ 'path' ] = $ url_parts [ 'path' ] ; $ result [ 'suffix' ] = "" ; $ result [ 'suffix' ] .= ( empty ( $ url_parts [ 'query' ] ) ) ? "" : "?" . $ url_parts [ 'query' ] ; $ result [ 'suffix' ] .= ( empty ( $ url_parts [ 'fragment' ] ) ) ? "" : "#" . $ url_parts [ 'fragment' ] ; } else { $ result [ 'prefix' ] = "" ; $ result [ 'path' ] = $ path_or_url ; $ result [ 'suffix' ] = "" ; } return $ result ; }
|
Decompose a url into a prefix path and suffix
|
57,418
|
public function get ( QueryCacheBuilder $ builder , $ columns = [ '*' ] ) { if ( ! $ this -> enabled ( ) ) { return $ this -> performQuery ( $ builder , $ columns ) ; } $ key = $ this -> generateKey ( $ builder , $ columns ) ; $ cache = $ this -> getCache ( $ builder ) ; return $ cache -> remember ( $ key , $ this -> length , function ( ) use ( $ builder , $ columns ) { return $ this -> performQuery ( $ builder , $ columns ) ; } ) ; }
|
Gets the model results .
|
57,419
|
protected function getCache ( QueryCacheBuilder $ builder ) { return $ this -> isTaggable ( ) ? Cache :: store ( $ this -> store ) -> tags ( $ this -> getTag ( $ builder ) ) : Cache :: store ( $ this -> store ) ; }
|
Gets a Cache instance .
|
57,420
|
protected function generateKey ( QueryCacheBuilder $ builder , array $ columns ) { $ sql = $ builder -> select ( $ columns ) -> toSql ( ) ; $ whereClause = serialize ( $ builder -> getBindings ( ) ) ; return sha1 ( $ sql . $ whereClause ) ; }
|
Generates the cache key .
|
57,421
|
public function flush ( $ tag ) { if ( $ this -> isTaggable ( ) ) { return Cache :: tags ( $ tag ) -> flush ( ) ; } return Cache :: flush ( ) ; }
|
Flushes the cache for a model .
|
57,422
|
public function addInternalRoute ( string $ path = null , $ handler , string $ info = null ) : void { $ route = new Route ( ) ; $ route -> set ( null , null , $ path , $ handler , $ info ) ; $ this -> internalRoutes [ $ path ] = $ route ; }
|
Add an internal route to the router this route is not exposed to the browser and the end user .
|
57,423
|
public function handle ( $ path , $ method = null ) { try { $ match = false ; foreach ( $ this -> routes as $ route ) { if ( $ route -> match ( $ path , $ method ) ) { $ this -> lastRoute = $ route ; $ match = true ; $ results = $ route -> handle ( $ path , $ this -> di ) ; if ( $ results ) { return $ results ; } } } return $ this -> handleInternal ( "404" , "No route could be matched by the router." ) ; } catch ( ForbiddenException $ e ) { return $ this -> handleInternal ( "403" , $ e -> getMessage ( ) ) ; } catch ( NotFoundException $ e ) { return $ this -> handleInternal ( "404" , $ e -> getMessage ( ) ) ; } catch ( InternalErrorException $ e ) { return $ this -> handleInternal ( "500" , $ e -> getMessage ( ) ) ; } catch ( \ Exception $ e ) { if ( $ this -> mode === Router :: DEVELOPMENT ) { throw $ e ; } return $ this -> handleInternal ( "500" , $ e -> getMessage ( ) ) ; } }
|
Handle the routes and match them towards the request dispatch them when a match is made . Each route handler may throw exceptions that may redirect to an internal route for error handling . Several routes can match and if the routehandler does not break execution flow the route matching will carry on . Only the last routehandler will get its return value returned further .
|
57,424
|
public function handleInternal ( string $ path , string $ message = null ) { $ route = $ this -> internalRoutes [ $ path ] ?? $ this -> internalRoutes [ null ] ?? null ; if ( ! $ route ) { throw new NotFoundException ( "No internal route to handle: " . $ path ) ; } $ this -> errorMessage = $ message ; if ( $ message ) { $ route -> setArguments ( [ $ message ] ) ; } $ route -> setMatchedPath ( $ path ) ; $ this -> lastRoute = $ route ; return $ route -> handle ( null , $ this -> di ) ; }
|
Handle an internal route the internal routes are not exposed to the end user .
|
57,425
|
public function addController ( $ mount = null , $ handler = null , $ info = null ) { $ this -> addRoute ( null , $ mount , null , $ handler , $ info ) ; }
|
Add a route having a controller as a handler .
|
57,426
|
public function always ( $ handler , $ info = null ) { $ this -> addRoute ( null , null , null , $ handler , $ info ) ; }
|
Add a default route which will be applied for any path and any request method .
|
57,427
|
public function all ( $ method , $ handler , $ info = null ) { $ this -> addRoute ( $ method , null , null , $ handler , $ info ) ; }
|
Add a default route which will be applied for any path if the choosen request method is matching .
|
57,428
|
public function get ( $ path , $ handler , $ info = null ) { $ this -> addRoute ( [ "GET" ] , null , $ path , $ handler , $ info ) ; }
|
Shortcut to add a GET route for the http request method GET .
|
57,429
|
public function post ( $ path , $ handler , $ info = null ) { $ this -> addRoute ( [ "POST" ] , null , $ path , $ handler , $ info ) ; }
|
Shortcut to add a POST route for the http request method POST .
|
57,430
|
public function put ( $ path , $ handler , $ info = null ) { $ this -> addRoute ( [ "PUT" ] , null , $ path , $ handler , $ info ) ; }
|
Shortcut to add a PUT route for the http request method PUT .
|
57,431
|
public function patch ( $ path , $ handler , $ info = null ) { $ this -> addRoute ( [ "PATCH" ] , null , $ path , $ handler , $ info ) ; }
|
Shortcut to add a PATCH route for the http request method PATCH .
|
57,432
|
public function delete ( $ path , $ handler , $ info = null ) { $ this -> addRoute ( [ "DELETE" ] , null , $ path , $ handler , $ info ) ; }
|
Shortcut to add a DELETE route for the http request method DELETE .
|
57,433
|
public function options ( $ path , $ handler , $ info = null ) { $ this -> addRoute ( [ "OPTIONS" ] , null , $ path , $ handler , $ info ) ; }
|
Shortcut to add a OPTIONS route for the http request method OPTIONS .
|
57,434
|
protected function checkEngineGeneric ( ) { if ( preg_match ( '/\?q=/' , $ this -> _http_referer ) || preg_match ( '/\&q=/' , $ this -> _http_referer ) ) { $ this -> _search_engine = self :: SEARCH_ENGINE_GENERIC ; if ( isset ( $ this -> _parse_result [ 'q' ] ) ) { $ this -> _keywords = $ this -> _parse_result [ 'q' ] ; } return true ; } return false ; }
|
Last Check for unknown Search Engines
|
57,435
|
public function fetchJson ( $ parameters = [ ] ) { if ( ! isset ( $ parameters [ 'url' ] ) ) { Craft :: error ( 'URL parameter not set' , __METHOD__ ) ; return false ; } $ data = self :: getUrl ( $ parameters [ 'url' ] ) ; return json_decode ( $ data , true ) ; }
|
Returns JSON from URL .
|
57,436
|
public function updateCMSFields ( FieldList $ fields ) { $ msg = _t ( 'JonoM\ShareCare\ShareCareFields.CMSMessage' , 'The preview is automatically generated from your content. You can override the default values using these fields:' ) ; $ tab = 'Root.' . _t ( 'JonoM\ShareCare\ShareCare.TabName' , 'Share' ) ; if ( $ msg ) { $ fields -> addFieldToTab ( $ tab , new LiteralField ( 'ShareCareFieldsMessage' , '<div class="message notice"><p>' . $ msg . '</p></div>' ) ) ; } $ fields -> addFieldToTab ( $ tab , TextField :: create ( 'OGTitleCustom' , _t ( 'JonoM\ShareCare\ShareCareFields.ShareTitle' , 'Share title' ) ) -> setAttribute ( 'placeholder' , $ this -> owner -> getDefaultOGTitle ( ) ) -> setMaxLength ( 90 ) ) ; $ fields -> addFieldToTab ( $ tab , TextAreaField :: create ( 'OGDescriptionCustom' , _t ( 'JonoM\ShareCare\ShareCareFields.ShareDescription' , 'Share description' ) ) -> setAttribute ( 'placeholder' , $ this -> owner -> getDefaultOGDescription ( ) ) -> setRows ( 2 ) ) ; $ fields -> addFieldToTab ( $ tab , UploadField :: create ( 'OGImageCustom' , _t ( 'JonoM\ShareCare\ShareCareFields.ShareImage' , 'Share image' ) ) -> setAllowedFileCategories ( 'image' ) -> setAllowedMaxFileNumber ( 1 ) -> setDescription ( _t ( 'JonoM\ShareCare\ShareCareFields.ShareImageRatio' , '{Link}Optimum image ratio</a> is 1.91:1. (1200px wide by 630px tall or better)' , array ( 'Link' => '<a href="https://developers.facebook.com/docs/sharing/best-practices#images" target="_blank">' ) ) ) ) ; if ( ShareCare :: config ( ) -> get ( 'pinterest' ) ) { $ fields -> addFieldToTab ( $ tab , UploadField :: create ( 'PinterestImageCustom' , _t ( 'ShareCareFields.PinterestImage' , 'Pinterest image' ) ) -> setAllowedFileCategories ( 'image' ) -> setAllowedMaxFileNumber ( 1 ) -> setDescription ( _t ( 'JonoM\ShareCare\ShareCareFields.PinterestImageDescription' , 'Square/portrait or taller images look best on Pinterest. This image should be at least 750px wide.' ) ) ) ; } }
|
Add CMS fields to allow setting of custom open graph values .
|
57,437
|
protected function getUploadedFile ( $ data ) { $ file = null ; if ( $ data !== null && is_array ( $ data ) && isset ( $ data [ FileType :: RADIO_FIELDNAME ] ) ) { switch ( $ data [ FileType :: RADIO_FIELDNAME ] ) { case FileType :: FILE_URL : if ( ! empty ( $ data [ FileType :: URL_FIELDNAME ] ) ) { $ fileurl = $ data [ FileType :: URL_FIELDNAME ] ; $ fileparts = explode ( '/' , $ fileurl ) ; $ filename = urldecode ( array_pop ( $ fileparts ) ) ; $ parsedFileName = parse_url ( $ filename ) ; $ filePath = sprintf ( '%s/%s' , sys_get_temp_dir ( ) , $ parsedFileName [ 'path' ] ) ; file_put_contents ( $ filePath , file_get_contents ( $ fileurl ) ) ; $ file = new File ( $ filePath ) ; } break ; case FileType :: FILE_UPLOAD : if ( isset ( $ data [ FileType :: UPLOAD_FIELDNAME ] ) && $ data [ FileType :: UPLOAD_FIELDNAME ] instanceof UploadedFile ) { $ file = $ data [ FileType :: UPLOAD_FIELDNAME ] ; } break ; } } return $ file ; }
|
Get the File object from the form data .
|
57,438
|
protected function validateFile ( $ file , FormEvent $ event ) { if ( $ file instanceof File ) { $ isValidFile = true ; if ( ! empty ( $ this -> allowedFileTypes ) && null !== $ mime = $ file -> getMimeType ( ) ) { if ( ! in_array ( $ mime , $ this -> allowedFileTypes ) ) { $ isValidFile = false ; $ message = $ this -> translator -> trans ( 'zicht_filemanager.wrong_type' , array ( '%this_type%' => $ mime , '%allowed_types%' => implode ( ', ' , $ this -> allowedFileTypes ) ) , $ event -> getForm ( ) -> getConfig ( ) -> getOption ( 'translation_domain' ) ) ; $ event -> getForm ( ) -> addError ( new FormError ( $ message ) ) ; $ event -> setData ( array ( FileType :: UPLOAD_FIELDNAME => $ event -> getForm ( ) -> getData ( ) ) ) ; } } if ( $ isValidFile ) { $ purgatoryFileManager = $ this -> getPurgatoryFileManager ( ) ; $ entity = $ event -> getForm ( ) -> getParent ( ) -> getConfig ( ) -> getDataClass ( ) ; $ data = $ event -> getData ( ) ; $ replaceFile = isset ( $ data [ FileType :: KEEP_PREVIOUS_FILENAME ] ) && $ data [ FileType :: KEEP_PREVIOUS_FILENAME ] === '1' ; $ forceFilename = $ replaceFile ? $ event -> getForm ( ) -> getData ( ) : '' ; $ path = $ purgatoryFileManager -> prepare ( $ file , $ entity , $ this -> field , true , $ forceFilename ) ; $ purgatoryFileManager -> save ( $ file , $ path ) ; $ this -> prepareData ( $ data , $ path , $ event -> getForm ( ) -> getPropertyPath ( ) ) ; $ event -> setData ( $ data ) ; } } }
|
Validate file .
|
57,439
|
public function preSubmit ( FormEvent $ event ) { $ data = $ event -> getData ( ) ; $ entity = $ event -> getForm ( ) -> getParent ( ) -> getConfig ( ) -> getDataClass ( ) ; if ( isset ( $ data [ FileType :: REMOVE_FIELDNAME ] ) && $ data [ FileType :: REMOVE_FIELDNAME ] === '1' ) { $ event -> setData ( null ) ; $ data = null ; return ; } if ( null !== ( $ file = $ this -> getUploadedFile ( $ data ) ) ) { $ this -> validateFile ( $ file , $ event ) ; } else { $ hash = $ data [ FileType :: HASH_FIELDNAME ] ; $ filename = $ data [ FileType :: FILENAME_FIELDNAME ] ; if ( ! empty ( $ hash ) && ! empty ( $ filename ) && PurgatoryHelper :: makeHash ( $ event -> getForm ( ) -> getPropertyPath ( ) , $ filename ) === $ hash ) { $ path = $ this -> getPurgatoryFileManager ( ) -> getFilePath ( $ entity , $ this -> field , $ filename ) ; $ this -> prepareData ( $ data , $ path , $ event -> getForm ( ) -> getPropertyPath ( ) ) ; $ event -> setData ( $ data ) ; } elseif ( $ event -> getForm ( ) -> getData ( ) !== null ) { unset ( $ data [ FileType :: HASH_FIELDNAME ] ) ; unset ( $ data [ FileType :: FILENAME_FIELDNAME ] ) ; $ originalFormData = $ event -> getForm ( ) -> getData ( ) ; $ path = $ this -> fileManager -> getFilePath ( $ entity , $ this -> field , $ originalFormData ) ; try { $ file = new File ( $ path ) ; $ data [ FileType :: UPLOAD_FIELDNAME ] = $ file ; $ event -> setData ( $ data ) ; } catch ( FileNotFoundException $ e ) { } } } }
|
Just before the form is submitted check if there is no data entered and if so set the old data back .
|
57,440
|
private function prepareData ( & $ data , $ path , $ propertyPath ) { $ file = new File ( $ path ) ; $ data [ FileType :: FILENAME_FIELDNAME ] = $ file -> getBasename ( ) ; $ data [ FileType :: HASH_FIELDNAME ] = PurgatoryHelper :: makeHash ( $ propertyPath , $ data [ FileType :: FILENAME_FIELDNAME ] ) ; $ data [ FileType :: UPLOAD_FIELDNAME ] = $ file ; $ file -> metaData = $ data ; }
|
Prepares the data before sending it to the form
|
57,441
|
public function injectEventManager ( $ assertion , $ serviceLocator ) { if ( ! $ assertion instanceof EventManagerAwareInterface ) { return ; } $ container = $ this -> container ; $ events = $ assertion -> getEventManager ( ) ; if ( ! $ events instanceof EventManagerInterface ) { $ events = $ container -> get ( 'EventManager' ) ; $ assertion -> setEventManager ( $ events ) ; } else { } }
|
Injects a shared event manager aware event manager .
|
57,442
|
protected function getAllowedTypes ( array $ options ) { $ types = null ; if ( isset ( $ options [ 'file_types' ] ) ) { $ types = $ options [ 'file_types' ] ; $ self = $ this ; if ( ! is_array ( $ types ) ) { $ types = explode ( ',' , $ types ) ; $ types = array_map ( 'trim' , $ types ) ; } array_walk ( $ types , function ( & $ val ) use ( $ self ) { if ( false == preg_match ( '#^([^/]+)/([\w|\.|\-]+)#' , $ val ) ) { $ val = $ self -> getMimeType ( $ val ) ; } } ) ; } return $ types ; }
|
Update options field file_types so if only extension is given it will try to determine mime type
|
57,443
|
public function isRole ( $ role , $ inherit = false , $ onlyParents = false ) { if ( $ role instanceof RoleInterface ) { $ role = $ role -> getRoleId ( ) ; } $ userRole = $ this -> getUser ( ) -> getRole ( ) ; $ isRole = $ userRole == $ role ; if ( 'recruiter' == $ role ) { $ inherit = true ; } if ( $ isRole || ! $ inherit ) { return $ isRole ; } $ acl = $ this -> getAcl ( ) ; return method_exists ( $ acl , 'inheritsRole' ) && $ acl -> inheritsRole ( $ userRole , $ role , $ onlyParents ) ; }
|
Returns true if the logged in user is of a specific role .
|
57,444
|
public function formAction ( ) { $ isNew = 'new' == $ this -> params ( 'mode' ) ; $ form = $ this -> formManager -> get ( 'Auth/Group' , array ( 'mode' => $ this -> params ( 'mode' ) ) ) ; $ repository = $ this -> repositories -> get ( 'Auth/Group' ) ; if ( $ isNew ) { $ group = new \ Auth \ Entity \ Group ( ) ; } else { if ( $ this -> getRequest ( ) -> isPost ( ) ) { $ data = $ this -> params ( ) -> fromPost ( 'data' ) ; $ id = isset ( $ data [ 'id' ] ) ? $ data [ 'id' ] : false ; } else { $ id = $ this -> params ( ) -> fromQuery ( 'id' , false ) ; } if ( ! $ id ) { throw new \ RuntimeException ( 'No id.' ) ; } $ group = $ repository -> find ( $ id ) ; } $ form -> bind ( $ group ) ; if ( $ this -> getRequest ( ) -> isPost ( ) ) { $ form -> setData ( $ _POST ) ; $ isOk = $ form -> isValid ( ) ; $ isUsersOk = ! empty ( $ group -> users ) ; if ( $ isOk ) { if ( $ isUsersOk ) { if ( $ isNew ) { $ user = $ this -> auth ( ) -> getUser ( ) ; $ group -> setOwner ( $ user ) ; $ groups = $ user -> getGroups ( ) ; $ message = 'Group created' ; $ groups -> add ( $ group ) ; } else { $ message = 'Group updated' ; } $ this -> notification ( ) -> success ( $ message ) ; return $ this -> redirect ( ) -> toRoute ( 'lang/my-groups' ) ; } } if ( ! $ isUsersOk ) { $ form -> get ( 'data' ) -> get ( 'users' ) -> setNoUsersError ( true ) ; } $ this -> notification ( ) -> error ( 'Changes not saved.' ) ; } return array ( 'form' => $ form , 'isNew' => $ isNew , ) ; }
|
Handles the form .
|
57,445
|
public function searchUsersAction ( ) { if ( ! $ this -> getRequest ( ) -> isXmlHttpRequest ( ) ) { throw new \ RuntimeException ( 'This action must be called via ajax request' ) ; } $ model = new JsonModel ( ) ; $ query = $ this -> params ( ) -> fromPost ( 'query' , false ) ; if ( ! $ query ) { $ query = $ this -> params ( ) -> fromQuery ( 'q' , false ) ; } if ( false === $ query ) { $ result = array ( ) ; } else { $ repositories = $ this -> repositories ; $ repository = $ repositories -> get ( 'Auth/User' ) ; $ users = $ repository -> findByQuery ( $ query ) ; $ userFilter = $ this -> filterManager -> get ( 'Auth/Entity/UserToSearchResult' ) ; $ filterFunc = function ( $ user ) use ( $ userFilter ) { return $ userFilter -> filter ( $ user ) ; } ; $ result = array_values ( array_map ( $ filterFunc , $ users -> toArray ( ) ) ) ; } $ model -> setVariables ( $ result ) ; return $ model ; }
|
Helper action for userselect form element .
|
57,446
|
public function attachShared ( SharedEventManagerInterface $ events , $ priority = 1000 ) { $ events -> attach ( 'Zend\Mvc\Application' , MvcEvent :: EVENT_BOOTSTRAP , array ( $ this , 'onBootstrap' ) , $ priority ) ; $ this -> listener = [ $ this , 'onBootstrap' ] ; }
|
Attach to a shared event manager
|
57,447
|
public function detachShared ( SharedEventManagerInterface $ events ) { if ( $ events -> detach ( $ this -> listener , 'Zend\Mvc\Application' ) ) { $ this -> listener = null ; } return $ this ; }
|
Detach all our listeners from the event manager
|
57,448
|
public function getManagedEntities ( ) { $ entities = array ( ) ; foreach ( $ this -> kernel -> getBundles ( ) as $ bundle ) { $ entityPath = $ bundle -> getPath ( ) . '/Entity' ; if ( is_dir ( $ entityPath ) ) { $ iter = new \ RegexIterator ( new \ RecursiveIteratorIterator ( new \ RecursiveDirectoryIterator ( $ entityPath ) ) , '/\.php$/' ) ; foreach ( $ iter as $ file ) { $ entityName = substr ( ltrim ( str_replace ( realpath ( $ entityPath ) , '' , realpath ( $ file -> getPathname ( ) ) ) , '/' ) , 0 , - 4 ) ; $ alias = Str :: classname ( get_class ( $ bundle ) ) . ':' . str_replace ( '/' , '\\' , $ entityName ) ; try { $ repos = $ this -> doctrine -> getRepository ( $ alias ) ; $ className = $ repos -> getClassName ( ) ; $ classMetaData = $ this -> metadata -> getMetadataForClass ( $ className ) ; foreach ( $ classMetaData -> propertyMetadata as $ property => $ metadata ) { if ( isset ( $ metadata -> fileManager ) ) { $ entities [ ] = $ alias ; break ; } } } catch ( \ Exception $ e ) { } } } } return $ entities ; }
|
Returns all entities having file annotations
|
57,449
|
public function setDefaultUser ( $ login , $ password , $ role = \ Auth \ Entity \ User :: ROLE_RECRUITER ) { $ this -> defaultUser = array ( $ login , $ password , $ role ) ; return $ this ; }
|
Sets default user login and password .
|
57,450
|
public function getToken ( ) { if ( ! $ this -> token ) { $ session = new Session ( 'Auth' ) ; if ( ! $ session -> token ) { $ session -> token = uniqid ( ) ; } $ this -> token = $ session -> token ; } return $ this -> token ; }
|
Gets the anonymous identification key .
|
57,451
|
public function init ( ) { $ this -> setName ( 'data' ) -> setLabel ( 'Group data' ) -> setUseAsBaseFieldset ( true ) -> setHydrator ( new EntityHydrator ( ) ) ; $ this -> add ( array ( 'type' => 'Hidden' , 'name' => 'id' , ) ) ; $ this -> add ( array ( 'type' => 'Text' , 'name' => 'name' , 'options' => array ( 'label' => 'Group name' , 'description' => 'Select a group name. You can add users to your group and then work together on jobs and job applications.' , ) , ) ) ; $ this -> add ( array ( 'type' => 'Auth/Group/Users' , ) ) ; }
|
Initialises the fieldset
|
57,452
|
protected function setEntity ( $ entityClass ) { $ this -> repos = $ this -> doctrine -> getRepository ( $ entityClass ) ; $ this -> className = $ this -> repos -> getClassName ( ) ; $ this -> classMetaData = $ this -> metadataFactory -> getMetadataForClass ( $ this -> className ) ; }
|
Set the Entity being processed .
|
57,453
|
final protected function log ( $ str , $ logLevel = 0 ) { if ( isset ( $ this -> logger ) ) { call_user_func ( $ this -> logger , $ str , $ logLevel ) ; } }
|
Write a log to the logger
|
57,454
|
public function getAutoloaderConfig ( ) { $ addProvidersDir = null ; $ directories = [ __DIR__ . '/../../../../hybridauth/hybridauth/additional-providers' , __DIR__ . '/../../../../vendor/hybridauth/hybridauth/additional-providers' , ] ; foreach ( $ directories as $ directory ) { if ( is_dir ( $ directory ) ) { $ addProvidersDir = $ directory ; break ; } } if ( is_null ( $ addProvidersDir ) ) { throw new InvalidArgumentException ( 'HybridAuth additional providers directories is not found.' ) ; } return array ( 'Zend\Loader\ClassMapAutoloader' => array ( array ( 'Hybrid_Providers_XING' => $ addProvidersDir . '/hybridauth-xing/Providers/XING.php' , ) , array ( 'Hybrid_Providers_Github' => $ addProvidersDir . '/hybridauth-github/Providers/GitHub.php' , ) , ) , ) ; }
|
Loads module specific autoloader configuration .
|
57,455
|
public function onDispatchError ( MvcEvent $ e ) { $ ex = $ e -> getParam ( 'exception' ) ; $ model = $ e -> getResult ( ) ; if ( $ model instanceof ViewModel && Application :: ERROR_EXCEPTION == $ e -> getError ( ) && 0 === strpos ( $ ex -> getMessage ( ) , 'Your application id and secret' ) ) { $ model -> setTemplate ( 'auth/error/social-profiles-unconfigured' ) ; } }
|
Sets a specific view template if social network login is unconfigured .
|
57,456
|
final public function typehintMethod ( $ class , string $ method , array $ custom = [ ] ) { $ className = get_class ( $ class ) ; $ reflectionMethod = new ReflectionMethod ( $ className , $ method ) ; $ reflectionParameters = $ reflectionMethod -> getParameters ( ) ; $ params = $ this -> resolveParams ( $ reflectionParameters , $ custom ) ; return call_user_func_array ( [ $ class , $ method ] , $ params ) ; }
|
Typehint a class method .
|
57,457
|
final public function typehintFunction ( string $ functionName , array $ custom = [ ] ) { $ reflectionFunction = new ReflectionFunction ( $ functionName ) ; $ reflectionParameters = $ reflectionFunction -> getParameters ( ) ; $ params = $ this -> resolveParams ( $ reflectionParameters , $ custom ) ; return call_user_func_array ( $ functionName , $ params ) ; }
|
Typehint a function .
|
57,458
|
public function hydrate ( array $ data , $ object ) { foreach ( $ data as $ name => $ value ) { if ( ! isset ( $ this -> profileClassMap [ $ name ] ) ) { continue ; } if ( empty ( $ value ) ) { foreach ( $ object as $ p ) { if ( $ p instanceof $ this -> profileClassMap [ $ name ] ) { $ object -> removeElement ( $ p ) ; continue 2 ; } } continue ; } if ( is_string ( $ value ) ) { $ value = \ Zend \ Json \ Json :: decode ( $ value , \ Zend \ Json \ Json :: TYPE_ARRAY ) ; } foreach ( $ object as $ p ) { if ( $ p instanceof $ this -> profileClassMap [ $ name ] ) { $ p -> setData ( $ value ) ; continue 2 ; } } $ class = $ this -> profileClassMap [ $ name ] ; $ profile = new $ class ( ) ; $ profile -> setData ( $ value ) ; $ object -> add ( $ profile ) ; } return $ object ; }
|
Adds or removes a social profile from the collection .
|
57,459
|
public function extract ( $ object ) { $ return = array ( ) ; foreach ( $ object as $ profile ) { $ return [ strtolower ( $ profile -> getName ( ) ) ] = $ profile -> getData ( ) ; } return $ return ; }
|
Extracts profile data from the collection .
|
57,460
|
public function find ( $ id , $ lockMode = \ Doctrine \ ODM \ MongoDB \ LockMode :: NONE , $ lockVersion = null , array $ options = [ ] ) { return $ this -> assertEntity ( parent :: find ( $ id , $ lockMode , $ lockVersion ) , $ options ) ; }
|
Finds a document by its identifier
|
57,461
|
public function findByProfileIdentifier ( $ identifier , $ provider , array $ options = [ ] ) { return $ this -> findOneBy ( array ( 'profiles.' . $ provider . '.auth.identifier' => $ identifier ) , $ options ) ? : $ this -> findOneBy ( array ( 'profile.identifier' => $ identifier ) , $ options ) ; }
|
Finds user by profile identifier
|
57,462
|
public function isProfileAssignedToAnotherUser ( $ curentUserId , $ identifier , $ provider ) { $ qb = $ this -> createQueryBuilder ( null ) ; $ qb -> field ( '_id' ) -> notEqual ( $ curentUserId ) -> addAnd ( $ qb -> expr ( ) -> addOr ( $ qb -> expr ( ) -> field ( 'profiles.' . $ provider . '.auth.identifier' ) -> equals ( $ identifier ) ) -> addOr ( $ qb -> expr ( ) -> field ( 'profile.identifier' ) -> equals ( $ identifier ) ) ) ; return $ qb -> count ( ) -> getQuery ( ) -> execute ( ) > 0 ; }
|
Returns true if profile is already assigned to anotherUser
|
57,463
|
public function findByQuery ( $ query ) { $ qb = $ this -> createQueryBuilder ( ) ; $ parts = explode ( ' ' , trim ( $ query ) ) ; foreach ( $ parts as $ q ) { $ regex = new \ MongoRegex ( '/^' . $ query . '/i' ) ; $ qb -> addOr ( $ qb -> expr ( ) -> field ( 'info.firstName' ) -> equals ( $ regex ) ) ; $ qb -> addOr ( $ qb -> expr ( ) -> field ( 'info.lastName' ) -> equals ( $ regex ) ) ; $ qb -> addOr ( $ qb -> expr ( ) -> field ( 'info.email' ) -> equals ( $ regex ) ) ; } $ qb -> sort ( array ( 'info.lastName' => 1 ) ) -> sort ( array ( 'info.email' => 1 ) ) ; return $ qb -> getQuery ( ) -> execute ( ) ; }
|
Find user by query
|
57,464
|
public function copyUserInfo ( Info $ info ) { $ contact = new Info ( ) ; $ contact -> fromArray ( Info :: toArray ( $ info ) ) ; }
|
Copy user info into the applications info Entity
|
57,465
|
public function isAvailable ( ) { if ( ! empty ( $ this -> adapter ) ) { return true ; } $ user = $ this -> getUser ( ) ; $ sessionDataStored = $ user -> getAuthSession ( $ this -> providerKey ) ; if ( empty ( $ sessionDataStored ) ) { return false ; } $ hybridAuth = $ this -> getHybridAuth ( ) ; $ hybridAuth -> restoreSessionData ( $ sessionDataStored ) ; if ( $ hybridAuth -> isConnectedWith ( $ this -> providerKey ) ) { return true ; } return false ; }
|
for backend there is only one possibility to get a connection and that is by stored Session
|
57,466
|
public function getAdapter ( ) { if ( empty ( $ this -> adapter ) ) { $ user = $ this -> getUser ( ) ; $ sessionDataStored = $ user -> getAuthSession ( $ this -> providerKey ) ; $ hybridAuth = $ this -> getHybridAuth ( ) ; if ( ! empty ( $ sessionDataStored ) ) { $ hybridAuth -> restoreSessionData ( $ sessionDataStored ) ; } $ adapter = $ hybridAuth -> authenticate ( $ this -> providerKey ) ; $ sessionData = $ hybridAuth -> getSessionData ( ) ; if ( $ sessionData != $ sessionDataStored ) { $ user -> updateAuthSession ( $ this -> providerKey , $ sessionData ) ; } $ this -> adapter = $ adapter ; } return $ this -> adapter ; }
|
everything relevant is happening here included the interactive registration if the User already has a session it is retrieved
|
57,467
|
public function sweepProvider ( ) { $ user = $ this -> getUser ( ) ; $ hybridAuth = $ this -> getHybridAuth ( ) ; if ( $ hybridAuth -> isConnectedWith ( $ this -> providerKey ) ) { $ this -> getAdapter ( $ this -> providerKey ) -> logout ( ) ; } $ user -> removeSessionData ( $ this -> providerKey ) ; unset ( $ this -> adapter ) ; return $ this ; }
|
logout and clears the stored Session
|
57,468
|
public function clearThumbnailAction ( Request $ request ) { $ path = $ request -> get ( 'path' ) ; $ filter = $ request -> get ( 'filter' ) ; $ response = [ 'error' => false , 'success' => false ] ; if ( $ path && $ filter ) { $ cacheManager = $ this -> get ( 'liip_imagine.cache.manager' ) ; $ cacheManager -> remove ( $ path ) ; $ cacheManager -> getBrowserPath ( $ path , $ filter ) ; $ response [ 'success' ] = true ; $ response [ 'url' ] = $ cacheManager -> generateUrl ( $ path , $ filter ) ; } else { $ response [ 'error' ] = 'No "path" or "filter" provided' ; } return new JsonResponse ( $ response ) ; }
|
Remove thumbnail for given path
|
57,469
|
public function shorts ( ) { $ out = array ( ) ; foreach ( $ this -> definedShortFlags as $ key => $ data ) { $ out [ $ key ] = $ data [ self :: DEF_VALUE ] ; } return $ out ; }
|
Returns an array of short - flag call - counts indexed by character
|
57,470
|
public function longs ( ) { $ out = array ( ) ; foreach ( $ this -> definedFlags as $ key => $ data ) { $ out [ $ key ] = $ data [ self :: DEF_VALUE ] ; } return $ out ; }
|
Returns an array of long - flag values indexed by flag name
|
57,471
|
public function & short ( $ letter , $ usage = '' ) { $ this -> definedShortFlags [ $ letter [ 0 ] ] = array ( self :: DEF_VALUE => 0 , self :: DEF_USAGE => $ usage , ) ; return $ this -> definedShortFlags [ $ letter [ 0 ] ] [ 'value' ] ; }
|
Defines a short - flag of specified name and usage string . The return value is a reference to an integer variable that stores the number of times the short - flag was called .
|
57,472
|
public function & bool ( $ name , $ value = null , $ usage = '' ) { return $ this -> _storeFlag ( self :: TYPE_BOOL , $ name , $ value , $ usage ) ; }
|
Defines a bool long - flag of specified name default value and usage string . The return value is a reference to a variable that stores the value of the flag .
|
57,473
|
public function & float ( $ name , $ value = null , $ usage = '' ) { return $ this -> _storeFlag ( self :: TYPE_FLOAT , $ name , $ value , $ usage ) ; }
|
Defines a float long - flag of specified name default value and usage string . The return value is a reference to a variable that stores the value of the flag .
|
57,474
|
public function & int ( $ name , $ value = null , $ usage = '' ) { return $ this -> _storeFlag ( self :: TYPE_INT , $ name , $ value , $ usage ) ; }
|
Defines an integer long - flag of specified name default value and usage string . The return value is a reference to a variable that stores the value of the flag .
|
57,475
|
public function & uint ( $ name , $ value = null , $ usage = '' ) { return $ this -> _storeFlag ( self :: TYPE_UINT , $ name , $ value , $ usage ) ; }
|
Defines a unsigned integer long - flag of specified name default value and usage string . The return value is a reference to a variable that stores the value of the flag .
|
57,476
|
public function & string ( $ name , $ value = null , $ usage = '' ) { return $ this -> _storeFlag ( self :: TYPE_STRING , $ name , $ value , $ usage ) ; }
|
Defines a string long - flag of specified name default value and usage string . The return value is a reference to a variable that stores the value of the flag .
|
57,477
|
public function getDefaults ( ) { $ output = '' ; $ final = array ( ) ; $ max = 0 ; foreach ( $ this -> definedShortFlags as $ char => $ data ) { $ final [ "-{$char}" ] = $ data [ self :: DEF_USAGE ] ; } foreach ( $ this -> definedFlags as $ flag => $ data ) { $ key = "--{$flag}" ; $ final [ $ key ] = ( $ data [ self :: DEF_REQUIRED ] ? "<{$data[self::DEF_TYPE]}> " : ( $ data [ self :: DEF_TYPE ] == self :: TYPE_BOOL ? '' : "[{$data[self::DEF_TYPE]}] " ) ) . $ data [ self :: DEF_USAGE ] ; $ max = max ( $ max , strlen ( $ key ) ) ; } foreach ( $ final as $ flag => $ usage ) { $ output .= sprintf ( '%' . ( $ max + 5 ) . 's' , $ flag ) . " {$usage}" . PHP_EOL ; } return $ output ; }
|
Returns the default values of all defined command - line flags as a formatted string .
|
57,478
|
public function parse ( array $ args = null , $ ignoreExceptions = false , $ skipFirstArgument = true ) { if ( $ args === null ) { $ args = $ GLOBALS [ 'argv' ] ; } if ( $ skipFirstArgument ) { array_shift ( $ args ) ; } list ( $ longParams , $ shortParams , $ this -> arguments ) = $ this -> splitArguments ( $ args , $ this -> definedFlags ) ; foreach ( $ longParams as $ name => $ value ) { if ( ! isset ( $ this -> definedFlags [ $ name ] ) ) { if ( ! $ ignoreExceptions ) { throw new InvalidFlagParamException ( 'Unknown option: --' . $ name ) ; } } else { $ defined_flag = & $ this -> definedFlags [ $ name ] ; if ( $ this -> validateType ( $ defined_flag [ self :: DEF_TYPE ] , $ value ) ) { $ defined_flag [ self :: DEF_VALUE ] = $ value ; $ defined_flag [ self :: DEF_PARSED ] = true ; } else { if ( ! $ ignoreExceptions ) { throw new InvalidFlagTypeException ( 'Option --' . $ name . ' expected type: "' . $ defined_flag [ self :: DEF_TYPE ] . '"' ) ; } } } } foreach ( $ shortParams as $ char => $ value ) { if ( ! isset ( $ this -> definedShortFlags [ $ char ] ) ) { if ( ! $ ignoreExceptions ) { throw new InvalidFlagParamException ( 'Unknown option: -' . $ char ) ; } } else { $ this -> definedShortFlags [ $ char ] [ self :: DEF_VALUE ] = $ value ; } } foreach ( $ this -> definedFlags as $ name => $ data ) { if ( $ data [ self :: DEF_VALUE ] === null ) { if ( ! $ ignoreExceptions ) { throw new MissingFlagParamException ( 'Expected option --' . $ name . ' missing.' ) ; } } } $ this -> parsed = true ; }
|
Parses flag definitions from the argument list which should include the command name . Must be called after all flags are defined and before flags are accessed by the program .
|
57,479
|
public function isValid ( $ value ) { if ( $ value == $ this -> allowName ) { return true ; } foreach ( $ this -> getUser ( ) -> getGroups ( ) as $ group ) { if ( $ group -> getName ( ) == $ value ) { $ this -> error ( self :: MSG_NOT_UNIQUE , $ value ) ; return false ; } } return true ; }
|
Returns true if the given value is unique among the groups of the user .
|
57,480
|
public function prepare ( File $ file , $ entity , $ field , $ noclobber = true , $ forceFilename = '' ) { $ dir = $ this -> getDir ( $ entity , $ field ) ; if ( $ forceFilename ) { $ pathname = $ dir . '/' . $ forceFilename ; } else { if ( $ file instanceof UploadedFile ) { $ fileName = $ file -> getClientOriginalName ( ) ; } else { $ fileName = $ file -> getBasename ( ) ; } $ i = 0 ; do { $ f = $ this -> namingStrategy -> normalize ( $ fileName , $ i ++ ) ; $ pathname = $ dir . '/' . $ f ; } while ( $ noclobber && $ this -> fs -> exists ( $ pathname ) ) ; $ this -> fs -> mkdir ( dirname ( $ pathname ) , 0777 & ~ umask ( ) , true ) ; $ this -> fs -> touch ( $ pathname ) ; } $ this -> preparedPaths [ ] = $ pathname ; return $ pathname ; }
|
Prepares a file for upload which means that a stub file is created at the point where the file otherwise would be uploaded .
|
57,481
|
public function save ( File $ file , $ preparedPath ) { if ( false === ( $ i = array_search ( $ preparedPath , $ this -> preparedPaths ) ) ) { throw new \ RuntimeException ( "{$preparedPath} is not prepared by the filemanager" ) ; } unset ( $ this -> preparedPaths [ $ i ] ) ; $ existed = $ this -> fs -> exists ( $ preparedPath ) ; @ $ this -> fs -> remove ( $ preparedPath ) ; try { $ this -> dispatchEvent ( $ existed ? ResourceEvent :: REPLACED : ResourceEvent :: CREATED , $ preparedPath ) ; $ file -> move ( dirname ( $ preparedPath ) , basename ( $ preparedPath ) ) ; } catch ( FileException $ fileException ) { throw new FileException ( $ fileException -> getMessage ( ) . "\n(hint: check the 'upload_max_filesize' in php.ini)" , 0 , $ fileException ) ; } }
|
Save a file to a previously prepared path .
|
57,482
|
public function delete ( $ filePath ) { $ relativePath = $ this -> fs -> makePathRelative ( $ filePath , $ this -> root ) ; if ( preg_match ( '!(^|/)\.\.!' , $ relativePath ) ) { throw new \ RuntimeException ( "{$relativePath} does not seem to be managed by the filemanager" ) ; } if ( $ this -> fs -> exists ( $ filePath ) ) { $ this -> fs -> remove ( $ filePath ) ; $ this -> dispatchEvent ( ResourceEvent :: DELETED , $ filePath ) ; return true ; } return false ; }
|
Delete a file path
|
57,483
|
public function getFileUrl ( $ entity , $ field , $ fileName = null ) { if ( func_num_args ( ) < 3 ) { if ( $ entity ) { $ fileName = PropertyHelper :: getValue ( $ entity , $ field ) ; } } if ( $ fileName instanceof File ) { $ fileName = $ fileName -> getBasename ( ) ; } if ( $ fileName ) { return ltrim ( $ this -> httpRoot . '/' . $ this -> getRelativePath ( $ entity , $ field ) . '/' . $ fileName , '/' ) ; } return null ; }
|
Return the url to the file .
|
57,484
|
private function dispatchEvent ( $ eventType , $ filePath ) { if ( null !== $ this -> eventDispatcher ) { $ relativePath = $ this -> fs -> makePathRelative ( dirname ( $ filePath ) , $ this -> root ) . basename ( $ filePath ) ; $ this -> eventDispatcher -> dispatch ( $ eventType , new ResourceEvent ( $ relativePath , $ this -> httpRoot , $ this -> root ) ) ; if ( null !== $ this -> imagineConfig ) { if ( false !== strpos ( $ relativePath , '/../' ) || 0 === strpos ( $ relativePath , '../' ) ) { return ; } list ( $ cacheManager , $ filterConfig ) = $ this -> imagineConfig ; $ webPath = $ this -> httpRoot . '/' . $ relativePath ; $ cacheManager -> remove ( $ webPath ) ; foreach ( $ filterConfig -> all ( ) as $ name => $ filter ) { $ url = $ cacheManager -> resolve ( $ webPath , $ name ) ; $ relativeUrl = parse_url ( $ url , PHP_URL_PATH ) ; $ url = $ this -> fs -> makePathRelative ( dirname ( $ relativeUrl ) , $ this -> httpRoot ) . basename ( $ relativeUrl ) ; if ( false === strpos ( $ url , '../' ) ) { $ this -> eventDispatcher -> dispatch ( $ eventType , new ResourceEvent ( $ url , $ this -> httpRoot , $ this -> root ) ) ; } } } } }
|
Dispatch an event for changed resources
|
57,485
|
public function isListed ( $ institution ) { foreach ( $ this -> getElements ( ) as $ raListing ) { if ( $ raListing -> institution === $ institution ) { return true ; } } return false ; }
|
Checks if a certain institution is listed in the RA listing
|
57,486
|
public static function setValue ( $ entity , $ field , $ value ) { $ entity -> { 'set' . ucfirst ( Str :: camel ( $ field ) ) } ( $ value ) ; }
|
Calls a setter in the entity with the specified value
|
57,487
|
public function getManagedFields ( $ entity ) { $ class = get_class ( $ entity ) ; if ( ! isset ( $ this -> managedFields [ $ class ] ) ) { $ entityClass = get_class ( $ entity ) ; $ this -> managedFields [ $ class ] = array ( ) ; do { $ metadata = $ this -> metadataFactory -> getMetadataForClass ( $ entityClass ) ; foreach ( $ metadata -> propertyMetadata as $ field => $ metadata ) { if ( isset ( $ metadata -> fileManager ) ) { $ this -> managedFields [ $ class ] [ ] = $ field ; } } } while ( $ entityClass = get_parent_class ( $ entityClass ) ) ; $ this -> managedFields [ $ class ] = array_unique ( $ this -> managedFields [ $ class ] ) ; } return $ this -> managedFields [ $ class ] ; }
|
Returns all field names that are managed
|
57,488
|
public function preUpdate ( $ eventArgs ) { $ entity = $ eventArgs -> getEntity ( ) ; $ changeset = $ eventArgs -> getEntityChangeSet ( ) ; foreach ( $ this -> metadata -> getManagedFields ( $ entity ) as $ field ) { if ( isset ( $ changeset [ $ field ] ) ) { list ( $ old , $ new ) = $ changeset [ $ field ] ; if ( $ old ) { $ tempFilePath = $ this -> fileManager -> getFilePath ( $ entity , $ field , $ old ) ; if ( $ new && ( ( string ) $ new ) && ( string ) $ new == $ tempFilePath ) { $ new = $ new -> getBasename ( ) ; } else { $ filepath = $ this -> fileManager -> getFilePath ( $ entity , $ field , $ old ) ; $ this -> unitOfWork [ spl_object_hash ( $ entity ) ] [ $ field ] [ 'delete' ] = function ( FileManager $ fm ) use ( $ filepath ) { $ fm -> delete ( $ filepath ) ; } ; } } if ( is_string ( $ new ) ) { $ eventArgs -> setNewValue ( $ field , $ new ) ; } else { if ( null !== $ new ) { $ eventArgs -> setNewValue ( $ field , $ this -> scheduleForUpload ( $ new , $ entity , $ field ) ) ; } } } } }
|
Replaces a file value and removes the old file .
|
57,489
|
public function preRemove ( $ eventArgs ) { $ entity = $ eventArgs -> getEntity ( ) ; foreach ( $ this -> metadata -> getManagedFields ( $ entity ) as $ field ) { $ file = PropertyHelper :: getValue ( $ entity , $ field ) ; if ( $ file ) { $ filepath = $ this -> fileManager -> getFilePath ( $ entity , $ field , $ file ) ; $ this -> unitOfWork [ spl_object_hash ( $ entity ) ] [ $ field ] [ 'delete' ] = function ( FileManager $ fm ) use ( $ filepath ) { $ fm -> delete ( $ filepath ) ; } ; } } }
|
Removes the files attached to the entity
|
57,490
|
public function scheduleForUpload ( $ value , $ entity , $ field ) { if ( is_string ( $ value ) ) { $ value = new FixtureFile ( $ this -> fileManager -> getFilePath ( $ entity , $ field , $ value ) ) ; } if ( $ value instanceof File ) { $ replaceFile = isset ( $ value -> metaData [ 'keep_previous_filename' ] ) and $ value -> metaData [ 'keep_previous_filename' ] ; $ path = $ this -> fileManager -> prepare ( $ value , $ entity , $ field , ! $ replaceFile ) ; $ fileName = basename ( $ path ) ; PropertyHelper :: setValue ( $ entity , $ field , $ fileName ) ; $ this -> unitOfWork [ spl_object_hash ( $ entity ) ] [ $ field ] [ 'save' ] = function ( $ fm ) use ( $ value , $ path ) { $ fm -> save ( $ value , $ path ) ; } ; return $ fileName ; } else { throw new \ InvalidArgumentException ( "Invalid argument to scheduleForUpload(): " . gettype ( $ value ) ) ; } }
|
Puts the upload in the unit of work to be executed when the flush is done .
|
57,491
|
public function doFlush ( ) { while ( $ unit = array_shift ( $ this -> unitOfWork ) ) { while ( $ operations = array_shift ( $ unit ) ) { while ( $ callback = array_shift ( $ operations ) ) { call_user_func ( $ callback , $ this -> fileManager ) ; } } } }
|
Executes all scheduled callbacks in the unit of work .
|
57,492
|
public function init ( ) { $ this -> setName ( 'users' ) ; $ this -> setLabel ( 'Users' ) ; $ this -> setAttribute ( 'id' , 'users' ) ; $ this -> setTargetElement ( array ( 'type' => 'hidden' , 'name' => 'user' , ) ) ; $ this -> setCount ( 0 ) -> setAllowRemove ( true ) -> setAllowAdd ( true ) -> setShouldCreateTemplate ( true ) ; }
|
Initialises the collection .
|
57,493
|
public function removeSessionData ( $ key = null ) { $ authSessionRefresh = array ( ) ; foreach ( $ this -> authSessions as $ authSession ) { if ( isset ( $ key ) && $ key != $ authSession -> getName ( ) ) { $ authSessionRefresh [ ] = $ authSession ; } } $ this -> authSessions = $ authSessionRefresh ; return $ this ; }
|
removes a stored Session
|
57,494
|
public function addProfileButton ( $ name , $ options = null ) { if ( null === $ options ) { $ options [ 'label' ] = ucfirst ( $ name ) ; } elseif ( is_string ( $ options ) ) { $ options = array ( 'label' => $ options ) ; } if ( ! isset ( $ options [ 'fetch_url' ] ) ) { $ options [ 'fetch_url' ] = sprintf ( $ this -> fetchUrl , $ name ) ; } if ( ! isset ( $ options [ 'preview_url' ] ) && $ this -> previewUrl ) { $ options [ 'preview_url' ] = sprintf ( $ this -> previewUrl , $ options [ 'label' ] ) ; } if ( ! isset ( $ options [ 'icon' ] ) ) { $ options [ 'icon' ] = $ name ; } $ options [ 'disable_capable' ] [ 'description' ] = sprintf ( 'Allow users to attach their %s profile.' , $ options [ 'label' ] ) ; $ this -> add ( array ( 'type' => 'Auth/SocialProfilesButton' , 'name' => $ name , 'options' => $ options , ) ) ; return $ this ; }
|
Adds a profile button .
|
57,495
|
public function clear ( ) { $ session = $ this -> getSessionContainer ( ) ; if ( ! $ session -> isSwitchedUser ) { return false ; } $ oldSession = unserialize ( $ session -> session ) ; $ ref = $ session -> ref ; $ _SESSION = $ oldSession ; return $ ref ? $ ref : true ; }
|
Restores the original user .
|
57,496
|
public function setSessionParams ( array $ params , $ merge = false ) { $ session = $ this -> getSessionContainer ( ) ; if ( isset ( $ session -> params ) && $ merge ) { $ params = ArrayUtils :: merge ( $ session -> params , $ params ) ; } $ session -> params = $ params ; return $ this ; }
|
Set additional params .
|
57,497
|
private function getSessionContainer ( ) { if ( ! $ this -> sessionContainer ) { $ this -> sessionContainer = new Container ( self :: SESSION_NAMESPACE ) ; } return $ this -> sessionContainer ; }
|
Gets the session container .
|
57,498
|
private function exchangeAuthUser ( $ id ) { $ storage = $ this -> auth -> getStorage ( ) ; $ originalUserId = $ storage -> read ( ) ; $ this -> auth -> clearIdentity ( ) ; $ storage -> write ( $ id ) ; if ( $ acl = $ this -> getAclPlugin ( ) ) { $ acl -> setUser ( $ this -> auth -> getUser ( ) ) ; } return $ originalUserId ; }
|
Exchanges the authenticated user in AuthenticationService .
|
57,499
|
public function filter ( $ value ) { if ( ! $ value instanceof User ) { return array ( ) ; } $ info = $ value -> getInfo ( ) ; return array ( 'id' => $ value -> getId ( ) , 'name' => $ info -> displayName , 'image' => $ info -> image ? $ info -> image -> uri : '' , 'email' => $ info -> email , ) ; }
|
Filters an user to a search result array .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.