idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
300 | public function down ( array $ elementRef = null , $ x = 0 , $ y = 0 ) { return $ this -> switchIsDown ( ) -> addAction ( WebDriver_Server_Selendroid :: ACTION_POINTER_DOWN , $ this -> getCoordParams ( $ elementRef , $ x , $ y ) ) ; } | Puts pointer down . |
301 | public function flickUp ( $ x , $ y , $ distance , $ duration ) { return $ this -> flick ( $ x , $ y , WebDriver_Server_Selendroid :: DIRECTION_UP , $ distance , $ duration ) ; } | Flicks screen up . |
302 | public function flickDown ( $ x , $ y , $ distance , $ duration ) { return $ this -> flick ( $ x , $ y , WebDriver_Server_Selendroid :: DIRECTION_DOWN , $ distance , $ duration ) ; } | Flicks screen down . |
303 | public function flickLeft ( $ x , $ y , $ distance , $ duration ) { return $ this -> flick ( $ x , $ y , WebDriver_Server_Selendroid :: DIRECTION_LEFT , $ distance , $ duration ) ; } | Flicks screen to the left . |
304 | public function flickRight ( $ x , $ y , $ distance , $ duration ) { return $ this -> flick ( $ x , $ y , WebDriver_Server_Selendroid :: DIRECTION_RIGHT , $ distance , $ duration ) ; } | Flicks screen to the right . |
305 | public function slowFlick ( array $ elementRef = null , $ x , $ y , $ direction , $ distance ) { $ stepSize = 30 ; $ stepCount = ( int ) ( $ distance - $ distance % $ stepSize ) / $ stepSize ; $ this -> down ( $ elementRef , $ x , $ y ) ; list ( $ xMultiplier , $ yMultiplier ) = $ this -> getDirectionMultipliers ( $ direction ) ; for ( $ i = 1 ; $ i <= $ stepCount ; $ i ++ ) { $ offset = $ stepSize * $ i ; $ this -> move ( $ elementRef , $ x + $ offset * $ xMultiplier , $ y + $ offset * $ yMultiplier ) -> pause ( ) ; } $ this -> pause ( 100 ) -> move ( $ elementRef , $ x + $ distance * $ xMultiplier , $ y + $ distance * $ yMultiplier ) -> pause ( 100 ) -> up ( ) ; return $ this ; } | Builds flick that avoids kick in the end . |
306 | public static function getSocialRecord ( $ gid , $ raw = false ) { $ ch = curl_init ( Configuration :: getPrimaryGSLSNode ( ) . '/' . $ gid ) ; if ( Configuration :: getCurlVerbose ( ) >= 2 ) curl_setopt ( $ ch , CURLOPT_VERBOSE , 1 ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_HTTPGET , 1 ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , Configuration :: getGSLSTimeout ( ) ) ; $ result = curl_exec ( $ ch ) ; if ( curl_errno ( $ ch ) != CURLE_OK ) { $ ch = curl_init ( Configuration :: getSecondaryGSLSNode ( ) . '/' . $ gid ) ; if ( Configuration :: getCurlVerbose ( ) >= 2 ) curl_setopt ( $ ch , CURLOPT_VERBOSE , 1 ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_HTTPGET , 1 ) ; $ result = curl_exec ( $ ch ) ; if ( curl_errno ( $ ch ) != CURLE_OK ) { throw new \ Exception ( 'Connection error: ' . curl_error ( $ ch ) ) ; } } $ result = json_decode ( $ result ) ; curl_close ( $ ch ) ; if ( $ result -> responseCode != 200 ) { if ( $ result -> responseCode == 404 ) throw new SocialRecordNotFoundException ( $ result -> message ) ; else throw new \ Exception ( $ result -> message ) ; } else { $ signer = new Sha512 ( ) ; $ token = ( new Parser ( ) ) -> parse ( ( string ) $ result -> socialRecord ) ; $ socialRecord = json_decode ( base64_decode ( $ token -> getClaim ( 'socialRecord' ) ) ) ; $ personalPublicKey = PublicKey :: formatPEM ( $ socialRecord -> personalPublicKey ) ; try { $ token -> verify ( $ signer , $ personalPublicKey ) ; } catch ( \ Exception $ e ) { throw new SocialRecordIntegrityException ( 'SocialRecord integrity compromised: ' . $ e -> getMessage ( ) ) ; } if ( $ raw ) return $ token ; else return SocialRecordBuilder :: buildFromJSON ( json_encode ( $ socialRecord , JSON_UNESCAPED_SLASHES ) ) ; } } | Retrieves a SocialRecord for a given GlobalID from the GSLS . The signed JWT stored in the GSLS will be retrieved the payloads verified and the enclosed SocialRecord object will be returned . |
307 | public static function postSocialRecord ( SocialRecord $ sr , $ personalPrivateKey ) { if ( ! $ sr -> verify ( ) ) throw new \ Exception ( "Error: Invalid Social Record" ) ; $ signer = new Sha512 ( ) ; $ personalPrivateKey = PrivateKey :: formatPEM ( $ personalPrivateKey ) ; $ token = ( new Builder ( ) ) -> set ( 'socialRecord' , base64_encode ( $ sr -> getJSONString ( ) ) ) -> sign ( $ signer , $ personalPrivateKey ) -> getToken ( ) ; $ ch = curl_init ( Configuration :: getPrimaryGSLSNode ( ) ) ; if ( Configuration :: getCurlVerbose ( ) >= 2 ) curl_setopt ( $ ch , CURLOPT_VERBOSE , 1 ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_TIMEOUT , Configuration :: getGSLSTimeout ( ) ) ; curl_setopt ( $ ch , CURLOPT_HTTPHEADER , array ( 'Content-type: application/json' , 'Content-Length: ' . strlen ( ( string ) $ token ) ) ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , ( string ) $ token ) ; $ result = curl_exec ( $ ch ) ; if ( curl_errno ( $ ch ) != CURLE_OK ) { $ ch = curl_init ( Configuration :: getSecondaryGSLSNode ( ) ) ; if ( Configuration :: getCurlVerbose ( ) >= 2 ) curl_setopt ( $ ch , CURLOPT_VERBOSE , 1 ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , 1 ) ; curl_setopt ( $ ch , CURLOPT_HTTPGET , 1 ) ; $ result = curl_exec ( $ ch ) ; if ( curl_errno ( $ ch ) != CURLE_OK ) { throw new \ Exception ( 'Connection error: ' . curl_error ( $ ch ) ) ; } } $ result = json_decode ( $ result ) ; curl_close ( $ ch ) ; if ( $ result -> responseCode != 200 ) { throw new \ Exception ( "Error: " . $ result -> message ) ; } else { return $ result ; } } | Pushes a new SocialRecord to the GSLS . The SocialRecord will be transformed into a signed JWT which is then stored in the GSLS |
308 | public static function createJWT ( SocialRecord $ sr , $ personalPrivateKey ) { $ signer = new Sha512 ( ) ; return ( new Builder ( ) ) -> set ( 'socialRecord' , base64_encode ( $ sr -> getJSONString ( ) ) ) -> sign ( $ signer , $ personalPrivateKey ) -> getToken ( ) ; } | creates a signed JWT |
309 | public function parseResultMovieItem ( $ fallbackUrl = null ) { $ resultItem = $ this -> parseResultItem ( $ this -> crawler , 'mid' , '.info' , $ fallbackUrl ) ; if ( $ resultItem == null ) { return null ; } $ movie = new Movie ( $ resultItem ) ; return $ movie ; } | Parses the First Movie as Result Item . |
310 | public function parseResultTheaterItem ( $ fallbackUrl = null ) { $ resultItem = $ this -> parseResultItem ( $ this -> crawler , 'tid' , '.address, .info' , $ fallbackUrl ) ; if ( $ resultItem == null ) { return null ; } $ theater = new Theater ( $ resultItem ) ; return $ theater ; } | Parses the First Theater as Result Item . |
311 | public static function flatten ( $ array ) { $ return = [ ] ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ return = \ array_merge ( $ return , static :: flatten ( $ value ) ) ; } elseif ( $ value instanceof Collection ) { $ return = \ array_merge ( $ return , static :: flatten ( $ value -> all ( ) ) ) ; } else { $ return [ $ key ] = $ value ; } } return $ return ; } | Flattens nested arrays or Collections into a single array |
312 | protected function validateCustomer ( CustomerInterface $ value ) { if ( empty ( $ value -> getFullName ( ) ) || empty ( $ value -> getEmail ( ) ) ) { throw new InvalidArgumentException ( 'Customer name and email address is expected' ) ; } } | Validate if we got a good Customer instance . |
313 | protected static function checkVersion ( ) { if ( self :: $ checked === true ) { return true ; } $ process = new \ SystemProcess \ SystemProcess ( 'git' ) ; $ process -> nonZeroExitCodeException = true ; $ process -> argument ( '--version' ) -> execute ( ) ; if ( ! preg_match ( '(\\d+(?:\.\\d+)+)' , $ process -> stdoutOutput , $ match ) ) { throw new \ RuntimeException ( 'Could not determine GIT version.' ) ; } if ( version_compare ( $ match [ 0 ] , '1.6' , '>=' ) ) { return self :: $ checked = true ; } throw new \ RuntimeException ( 'Git is required in a minimum version of 1.6.' ) ; } | Verify git version |
314 | public function addNode ( string $ className ) : void { if ( isset ( $ this -> nodes [ $ className ] ) ) { return ; } $ this -> nodes [ $ className ] = new DocumentGraphNode ( $ className ) ; } | Adds a node to the dependency graph . |
315 | public function connect ( string $ source , string $ destination ) : void { $ outNode = $ this -> nodes [ $ source ] ; $ inNode = $ this -> nodes [ $ destination ] ; $ edge = new DocumentGraphEdge ( $ outNode , $ inNode ) ; $ outNode -> addOutEdge ( $ edge ) ; $ inNode -> addInEdge ( $ edge ) ; } | Connects two nodes . |
316 | protected function debugGetRelatedName ( $ e , EntityFace $ face ) { $ names = [ ] ; foreach ( $ face -> getElements ( ) as $ elm ) { if ( StringUtils :: beginsWith ( $ e , $ elm -> getName ( ) ) ) { $ names [ ] = $ elm -> getName ( ) ; } else if ( StringUtils :: endsWith ( $ e , $ elm -> getName ( ) ) ) { $ names [ ] = $ elm -> getName ( ) ; } } return $ names ; } | Allows to debug typos etc .. |
317 | public function addSelector ( $ key , FullParamIdentifier $ paramId ) { if ( $ this -> noIdentifierFor ( $ key ) ) { $ this -> fullParamIdentifierByKey [ $ key ] = [ ] ; } $ this -> fullParamIdentifierByKey [ $ key ] [ ] = $ paramId ; } | Adds a new full param identifier to the map . |
318 | public function setSport ( ChildSport $ v = null ) { if ( $ v === null ) { $ this -> setSportId ( NULL ) ; } else { $ this -> setSportId ( $ v -> getId ( ) ) ; } $ this -> aSport = $ v ; if ( $ v !== null ) { $ v -> addPosition ( $ this ) ; } return $ this ; } | Declares an association between this object and a ChildSport object . |
319 | public function initSkillsRelatedByStartPositionId ( $ overrideExisting = true ) { if ( null !== $ this -> collSkillsRelatedByStartPositionId && ! $ overrideExisting ) { return ; } $ this -> collSkillsRelatedByStartPositionId = new ObjectCollection ( ) ; $ this -> collSkillsRelatedByStartPositionId -> setModel ( '\gossi\trixionary\model\Skill' ) ; } | Initializes the collSkillsRelatedByStartPositionId collection . |
320 | public function getSkillsRelatedByStartPositionIdJoinFeaturedPicture ( Criteria $ criteria = null , ConnectionInterface $ con = null , $ joinBehavior = Criteria :: LEFT_JOIN ) { $ query = ChildSkillQuery :: create ( null , $ criteria ) ; $ query -> joinWith ( 'FeaturedPicture' , $ joinBehavior ) ; return $ this -> getSkillsRelatedByStartPositionId ( $ query , $ con ) ; } | If this collection has already been initialized with an identical criteria it returns the collection . Otherwise if this Position is new it will return an empty collection ; or if this Position has previously been saved it will retrieve related SkillsRelatedByStartPositionId from storage . |
321 | public function initSkillsRelatedByEndPositionId ( $ overrideExisting = true ) { if ( null !== $ this -> collSkillsRelatedByEndPositionId && ! $ overrideExisting ) { return ; } $ this -> collSkillsRelatedByEndPositionId = new ObjectCollection ( ) ; $ this -> collSkillsRelatedByEndPositionId -> setModel ( '\gossi\trixionary\model\Skill' ) ; } | Initializes the collSkillsRelatedByEndPositionId collection . |
322 | public function getSkillsRelatedByEndPositionIdJoinSport ( Criteria $ criteria = null , ConnectionInterface $ con = null , $ joinBehavior = Criteria :: LEFT_JOIN ) { $ query = ChildSkillQuery :: create ( null , $ criteria ) ; $ query -> joinWith ( 'Sport' , $ joinBehavior ) ; return $ this -> getSkillsRelatedByEndPositionId ( $ query , $ con ) ; } | If this collection has already been initialized with an identical criteria it returns the collection . Otherwise if this Position is new it will return an empty collection ; or if this Position has previously been saved it will retrieve related SkillsRelatedByEndPositionId from storage . |
323 | public function addError ( $ errorKey , $ errorValue ) { if ( ! isset ( $ this -> errors [ $ errorKey ] ) ) { $ this -> errors [ $ errorKey ] = [ ] ; } $ this -> errors [ $ errorKey ] [ ] = $ errorValue ; } | Add an error to the internal error array |
324 | public function validateMultipleItems ( array $ validationRule , array $ items , $ fullyQualifiedName ) { $ itemNumber = 1 ; foreach ( $ items as $ item ) { $ tempRule = $ validationRule ; $ tempRule [ 'name' ] = empty ( $ validationRule [ 'name' ] ) ? 'Value number ' . $ itemNumber : $ validationRule [ 'name' ] . ' number ' . $ itemNumber ; $ this -> validateItem ( $ tempRule , $ item , $ fullyQualifiedName ) ; $ itemNumber ++ ; } } | Validate a multile items using the given validation rule . |
325 | public function getTypeValidator ( $ type ) { if ( in_array ( $ type , $ this -> allowedTypeValidators , true ) == false ) { throw new InvalidTypeValidatorException ( 'The type "' . $ type . '" is invalid' ) ; } if ( isset ( $ this -> typeValidators [ $ type ] ) == false ) { $ className = 'Mooti\\Validator\\TypeValidator\\' . ucfirst ( $ type ) . 'Validator' ; $ this -> typeValidators [ $ type ] = $ this -> createNew ( $ className ) ; } return $ this -> typeValidators [ $ type ] ; } | Get a type validator |
326 | public function renderAction ( ) { $ params = $ this -> params ( ) ; $ navigation = $ this -> getServiceLocator ( ) -> get ( 'Grid\Menu\Model\Menu\Model' ) -> findNavigation ( $ params -> fromRoute ( 'id' ) ) ; $ view = new ViewModel ( array ( 'navigation' => $ navigation , 'class' => $ params -> fromRoute ( 'class' ) , ) ) ; return $ view -> setTerminal ( true ) ; } | Render a standalone menu |
327 | public function create ( $ product , $ data , $ storeView = null , $ identifierType = null ) { return $ this -> __createAction ( 'catalogProductAttributeMediaCreate' , func_get_args ( ) ) ; } | Allows you to upload a new product image . |
328 | public function getInfo ( $ productId , $ file , $ storeView = null , $ identifierType = null ) { return $ this -> __createAction ( 'catalogProductAttributeMediaInfo' , func_get_args ( ) ) ; } | Allows you to retrieve information about the specified product image . |
329 | public function update ( $ productId , $ file , $ data , $ storeView = null , $ identifierType = null ) { return $ this -> __createAction ( 'catalogProductAttributeMediaUpdate' , func_get_args ( ) ) ; } | Allows you to update the product image . |
330 | public function add ( $ path , $ group = null , $ depth = null ) { if ( isset ( $ this -> working_group ) ) { $ group = $ this -> working_group ; } else if ( ! isset ( $ group ) ) { throw new RuntimeException ( "Must set group or working group to add directory." ) ; } if ( ! isset ( $ this -> groups [ $ group ] ) ) { $ this -> groups [ $ group ] = array ( ) ; } if ( ! isset ( $ depth ) ) { if ( isset ( $ this -> group_default_depths [ $ group ] ) ) { $ depth = $ this -> group_default_depths [ $ group ] ; } else { $ depth = $ this -> default_search_depth ; } } $ this -> groups [ $ group ] [ $ this -> cleanpath ( $ path ) ] = $ depth ; return $ this ; } | Adds a directory path to a group . |
331 | public function locate ( $ file , $ group = null ) { if ( isset ( $ this -> working_group ) ) { $ group = $ this -> working_group ; } else if ( ! isset ( $ group ) ) { throw new RuntimeException ( "Must set group or working group to locate file." ) ; } if ( isset ( $ this -> found [ $ group ] [ $ file ] ) ) { return $ this -> found [ $ group ] [ $ file ] ; } if ( ! isset ( $ this -> groups [ $ group ] ) ) { throw new InvalidArgumentException ( "Unknown filesystem group $group." ) ; } foreach ( $ this -> groups [ $ group ] as $ path => $ depth ) { if ( $ found = $ this -> search ( $ path , $ file , $ depth ) ) { return $ this -> found [ $ group ] [ $ file ] = $ found ; } } return null ; } | Attempts to locate a file in a given group s directories . |
332 | public function search ( $ dir , $ file , $ depth = null , $ depth_now = 0 ) { if ( ! isset ( $ depth ) ) { $ depth = $ this -> default_search_depth ; } foreach ( $ this -> glob ( $ dir ) as $ item ) { if ( false !== strpos ( $ item , $ file ) ) { return $ item ; } else if ( $ depth_now < $ depth && $ this -> ds === substr ( $ item , - 1 ) ) { if ( $ found = $ this -> search ( $ item , $ file , $ depth , $ depth_now + 1 ) ) { return $ found ; } } } return null ; } | Searches for a file by globbing recursively until the file is found or until the maximum recusion depth is reached . |
333 | public function glob ( $ dir ) { $ dir = $ this -> cleanpath ( $ dir ) ; if ( isset ( $ this -> globs [ $ dir ] ) ) { return $ this -> globs [ $ dir ] ; } return $ this -> globs [ $ dir ] = glob ( $ dir . '/*' , GLOB_MARK | GLOB_NOSORT | GLOB_NOESCAPE ) ; } | Gets a glob of a directory . |
334 | public function setContainer ( ContainerInterface $ container = null ) { $ this -> container = $ container ; if ( $ this -> container -> has ( 'request' ) && $ this -> container -> hasScope ( 'request' ) && $ this -> container -> isScopeActive ( 'request' ) ) { $ this -> request = $ this -> container -> get ( 'request' ) ; } } | Sets the Container . |
335 | public function beforePrepare ( Event $ event ) { $ command = $ event [ 'command' ] ; $ client = $ command -> getClient ( ) ; $ config = $ client -> getConfig ( ) ; if ( $ command -> getOperation ( ) -> hasParam ( 'appKey' ) ) { $ command [ 'appKey' ] = $ config -> get ( 'appKey' ) ; if ( ! $ command [ 'authMode' ] && ! is_null ( $ command -> getClient ( ) -> getAuthMode ( ) ) ) { $ command [ 'authMode' ] = $ command -> getClient ( ) -> getAuthMode ( ) ; } if ( ! $ command [ 'authMode' ] ) throw new ValidationException ( 'authMode is required' ) ; if ( ! in_array ( $ command [ 'authMode' ] , $ this -> authModes ) ) throw new ValidationException ( 'Invalid authMode : ' . $ command [ 'authMode' ] ) ; switch ( true ) { case ( $ command [ 'authMode' ] === 'user' ) : if ( ! $ command [ 'username' ] ) throw new ValidationException ( 'username is required when using the user authMode' ) ; if ( ! $ command [ 'password' ] ) throw new ValidationException ( 'password is required when using the user authMode' ) ; $ username = $ command [ 'username' ] ; $ password = $ command [ 'password' ] ; $ scheme = 'Basic' ; break ; case ( $ token = Session :: get ( 'kinvey' ) ) : case ( $ token = $ client -> getAuthToken ( ) ) ; case ( $ command [ 'authMode' ] === 'session' ) : $ token = null ; if ( $ command [ 'token' ] ) $ token = $ command [ 'token' ] ; if ( $ client -> getAuthToken ( ) ) $ token = $ client -> getAuthToken ( ) ; if ( Session :: get ( 'kinvey' ) ) $ token = Session :: get ( 'kinvey' ) ; if ( ! $ token ) throw new ValidationException ( 'token is required when using the the session authMode' ) ; $ username = $ token ; $ password = null ; $ scheme = 'Kinvey' ; break ; case ( $ command -> getOperation ( ) -> getName ( ) === 'createEntity' && $ command [ 'collection' ] === 'user' ) : case ( $ command [ 'authMode' ] === 'app' ) : $ username = $ config -> get ( 'appKey' ) ; $ password = $ config -> get ( 'appSecret' ) ; $ scheme = 'Basic' ; break ; case ( $ command [ 'authMode' ] === 'admin' ) : $ username = $ config -> get ( 'appKey' ) ; $ password = $ config -> get ( 'masterSecret' ) ; $ scheme = 'Basic' ; break ; } $ command [ 'authHeader' ] = $ this -> getAuthHeader ( $ scheme , $ username , $ password ) ; } } | Inject authorization data into commands . |
336 | protected static function getAuthHeader ( $ scheme , $ username , $ password = null ) { if ( ! $ password ) return $ scheme . ' ' . $ username ; return $ scheme . ' ' . base64_encode ( $ username . ':' . $ password ) ; } | Get the authorization header value for a request . |
337 | public function sendEmail ( $ user , $ subject = "" , $ viewFile , $ content = array ( ) , $ return = true , $ processOutput = true , $ debug = false ) { Yii :: log ( Yii :: t ( 'ciims.core' , 'Use of CiiController::sendEmail is deprecated, and will be dropped in a future version. Use EmailSettings::send instead' ) , 'warning' , 'ciims.core' ) ; $ email = new EmailSettings ; return $ email -> send ( $ user , $ subject , $ viewFile , $ content , $ return , $ processOutput , YII_DEBUG ) ; } | Generic method for sending an email . Instead of having to call a bunch of code all over over the place This method can be called which should be able to handle almost anything . |
338 | public function getTheme ( ) { if ( $ this -> theme != NULL ) return $ this -> themeName ; $ theme = Cii :: getConfig ( 'theme' , 'default' ) ; Yii :: app ( ) -> setTheme ( file_exists ( YiiBase :: getPathOfAlias ( 'base.themes.' . $ theme ) ) ? $ theme : 'default' ) ; $ this -> themeName = $ theme ; return $ theme ; } | Retrieves the appropriate theme |
339 | public function getKeywords ( ) { $ keywords = Cii :: get ( $ this -> params [ 'meta' ] , 'keywords' , '' ) ; if ( Cii :: get ( $ keywords , 'value' , false ) != false ) $ keywords = implode ( ',' , json_decode ( $ keywords [ 'value' ] ) ) ; return $ keywords == "" ? Cii :: get ( $ this -> params [ 'data' ] , 'title' , Cii :: getConfig ( 'name' , Yii :: app ( ) -> name ) ) : $ keywords ; } | Retrieves keywords for use in the viewfile |
340 | public function render ( $ view , $ data = null , $ return = false ) { if ( $ this -> beforeRender ( $ view ) ) { if ( empty ( $ this -> params [ 'meta' ] ) ) $ data [ 'meta' ] = array ( ) ; if ( isset ( $ data [ 'data' ] ) && is_object ( $ data [ 'data' ] ) ) $ this -> params [ 'data' ] = $ data [ 'data' ] -> attributes ; if ( ! $ this -> isInModule ( ) && file_exists ( Yii :: getPathOfAlias ( 'base.themes.' ) . DS . Yii :: app ( ) -> theme -> name . DS . 'Theme.php' ) ) { Yii :: import ( 'base.themes.' . Yii :: app ( ) -> theme -> name . '.Theme' ) ; $ this -> theme = new Theme ; } $ output = $ this -> renderPartial ( $ view , $ data , true ) ; if ( ( $ layoutFile = $ this -> getLayoutFile ( $ this -> layout ) ) !== false ) { if ( ! $ this -> isInModule ( ) ) $ this -> widget ( 'cii.widgets.comments.CiiCommentMaster' , array ( 'type' => Cii :: getCommentProvider ( ) , 'content' => isset ( $ data [ 'data' ] ) && is_a ( $ data [ 'data' ] , 'Content' ) ? $ data [ 'data' ] -> attributes : false ) ) ; $ output = $ this -> renderFile ( $ layoutFile , array ( 'content' => $ output , 'meta' => $ this -> params [ 'meta' ] ) , true ) ; } $ this -> afterRender ( $ view , $ output ) ; $ output = $ this -> processOutput ( $ output ) ; if ( $ return ) return $ output ; else echo $ output ; } } | Overloaded Render allows us to generate dynamic content |
341 | public function setLevel ( $ level ) { if ( ( $ level < 0 ) || ( $ level > 9 ) ) { throw new Exception \ InvalidArgumentException ( 'Level must be between 0 and 9' ) ; } $ this -> options [ 'level' ] = ( int ) $ level ; return $ this ; } | Sets a new compression level |
342 | public function setMode ( $ mode ) { if ( ( $ mode != 'compress' ) && ( $ mode != 'deflate' ) ) { throw new Exception \ InvalidArgumentException ( 'Given compression mode not supported' ) ; } $ this -> options [ 'mode' ] = $ mode ; return $ this ; } | Sets a new compression mode |
343 | public function getClassAndMethodNamesForCalling ( ) : array { $ domain = $ this -> consoleInput -> getDomainName ( ) ; $ action = $ this -> consoleInput -> getActionName ( ) ; $ className = self :: getFQDNClass ( $ domain ) ; return [ $ className , $ domain , $ action ] ; } | Generate the NAMESPACE CLASSNAME AND ACTION for calling |
344 | public static function configureWithPreset ( $ preset , $ settings = null ) { if ( is_string ( $ settings ) ) { return self :: configureWithPreset ( $ preset , json_decode ( file_get_contents ( $ settings ) , true ) ) ; } if ( ! array_key_exists ( $ preset , self :: $ config ) || is_null ( self :: $ config [ $ preset ] ) ) { self :: $ config [ $ preset ] = array ( ) ; } self :: configureDevPlatformSetting ( 'dev-platform' , 'host' , 'MNO_DEVPL_HOST' , $ preset , $ settings ) ; self :: configureDevPlatformSetting ( 'dev-platform' , 'api_path' , 'MNO_DEVPL_API_PATH' , $ preset , $ settings ) ; self :: configureDevPlatformSetting ( 'environment' , 'api_key' , 'MNO_DEVPL_ENV_KEY' , $ preset , $ settings ) ; self :: configureDevPlatformSetting ( 'environment' , 'api_secret' , 'MNO_DEVPL_ENV_SECRET' , $ preset , $ settings ) ; return self :: $ config [ $ preset ] ; } | Configure the Maestrano PHP SDK using the Developer Platform |
345 | public static function loadMarketplacesConfigWithPreset ( $ preset ) { if ( self :: $ cache == NULL ) self :: $ cache = new Maestrano_Util_Cache ( ) ; self :: $ cache -> cache_path = dirname ( __FILE__ ) . '/' ; self :: $ cache -> cache_time = 43200 ; if ( ! $ data = self :: $ cache -> get_cache ( 'dev-platform' ) ) { $ apiKey = self :: $ config [ $ preset ] [ 'environment.api_key' ] ; $ apiSecret = self :: $ config [ $ preset ] [ 'environment.api_secret' ] ; $ host = self :: $ config [ $ preset ] [ 'dev-platform.host' ] ; $ api_path = self :: $ config [ $ preset ] [ 'dev-platform.api_path' ] ; try { $ response = \ Httpful \ Request :: get ( $ host . $ api_path . "marketplaces" ) -> authenticateWith ( $ apiKey , $ apiSecret ) -> send ( ) ; $ data = $ response -> raw_body ; if ( $ response -> code >= 400 ) { throw new Maestrano_Config_Error ( "HTTP Error, code: $response->code" , $ response -> code ) ; } } catch ( Exception $ e ) { error_log ( "maestrano-php: An error occurred while retrieving the marketplaces. Error: $e" ) ; error_log ( "maestrano-php: Re-using existing cached configuration, if any." ) ; if ( ! $ data = self :: $ cache -> get_cached_file ( 'dev-platform' ) ) throw new Maestrano_Config_Error ( "No cached configuration found." ) ; } self :: $ cache -> set_cache ( 'dev-platform' , $ data ) ; } $ json_body = json_decode ( $ data , true ) ; if ( array_key_exists ( 'error' , $ json_body ) ) throw new Maestrano_Config_Error ( "An error occurred while retrieving the marketplaces. Body content: " . print_r ( $ json_body , true ) ) ; self :: loadMultipleMarketplaces ( $ json_body [ 'marketplaces' ] ) ; } | Fetch the dynamic marketplaces configuration for this environment and configure the Maestrano presets |
346 | public static function loadMultipleMarketplaces ( $ conf_array ) { foreach ( $ conf_array as $ marketplace ) { Maestrano :: with ( $ marketplace [ 'marketplace' ] ) -> configure ( $ marketplace ) ; } } | Configure Maestrano presets with fetched marketplaces |
347 | private static function configureDevPlatformSetting ( $ setting_bloc , $ var_name , $ env_var , $ preset , $ settings ) { if ( $ settings != null && array_key_exists ( $ setting_bloc , $ settings ) && array_key_exists ( $ var_name , $ settings [ $ setting_bloc ] ) ) { self :: $ config [ $ preset ] [ "$setting_bloc.$var_name" ] = $ settings [ $ setting_bloc ] [ $ var_name ] ; } elseif ( $ host = getenv ( $ env_var ) ) { self :: $ config [ $ preset ] [ "$setting_bloc.$var_name" ] = $ host ; } else { self :: throwMissingParameterError ( "$setting_bloc.$var_name" ) ; } } | Configure a dev platform setting in the dev platform settings preset |
348 | public function add ( $ handle , $ type , $ args = array ( ) ) { list ( $ src , $ deps , $ ver , $ last ) = $ args ; $ data = array ( ) ; if ( $ src ) $ data [ 'src' ] = $ src ; if ( $ deps ) $ data [ 'deps' ] = $ deps ; if ( $ ver ) $ data [ 'ver' ] = $ ver ; if ( $ last ) $ data [ ( 'script' == $ type ? 'in_footer' : 'media' ) ] = $ last ; $ this -> assets [ $ type ] [ $ handle ] = $ data ; return true ; } | Generic add function |
349 | public function remove ( $ handle , $ type = null ) { if ( ! $ type ) { $ script = false !== array_search ( $ handle , array_keys ( $ this -> assets [ 'script' ] ) ) ; $ style = false !== array_search ( $ handle , array_keys ( $ this -> assets [ 'style' ] ) ) ; if ( $ script && $ style ) { throw new \ RuntimeException ( 'Asset with handle "' . $ handle . '" found in both script as style type.' ) ; } else { $ type = $ script ? 'script' : 'style' ; } } if ( isset ( $ this -> assets [ $ type ] [ $ handle ] ) ) { unset ( $ this -> assets [ $ type ] [ $ handle ] ) ; } return true ; } | Removes asset when no type is given it tries to find it |
350 | public function enqueue ( ) { if ( $ this -> assets ) { foreach ( $ this -> assets as $ type => $ assets ) { $ registerFunc = 'wp_register_' . $ type ; $ enqueueFunc = 'wp_enqueue_' . $ type ; foreach ( $ assets as $ handle => $ data ) { if ( $ data ) { $ data = array_merge ( array ( 'src' => null , 'deps' => array ( ) , 'ver' => false , 'in_footer' => false , 'media' => 'all' , ) , $ data ) ; $ lastArg = 'script' == $ type ? $ data [ 'in_footer' ] : $ data [ 'media' ] ; $ registerFunc ( $ handle , $ data [ 'src' ] , $ data [ 'deps' ] , $ data [ 'ver' ] , $ lastArg ) ; } $ enqueueFunc ( $ handle ) ; } } } if ( $ this -> deregister ) { foreach ( $ this -> deregister as $ type => $ handles ) { $ function = 'wp_deregister_' . $ type ; foreach ( $ handles as $ handle ) { $ function ( $ handle ) ; } } } } | Enqueues all assets |
351 | public function execute ( Framework $ framework , RequestAbstract $ request , Response $ response ) { if ( $ request instanceof WebRequest ) { $ response -> redirectTo ( '/login/' , 307 , true ) ; return ; } $ response -> setOutputPart ( 'sessionNeeded' , 'You need a session to execute this command!' ) ; } | If the request is a WebRequest the user will be redirected to the login page . Otherwise the event handler will display an information message . |
352 | public static function hash_password ( $ uname , $ upass , $ usalt ) { if ( strlen ( $ usalt ) > 16 ) $ usalt = substr ( $ usalt , 0 , 16 ) ; return self :: generate_secret ( $ upass . $ uname , $ usalt ) ; } | Create hashed password . |
353 | public static function verify_password ( $ pass1 , $ pass2 ) { $ pass1 = trim ( $ pass1 ) ; $ pass2 = trim ( $ pass2 ) ; if ( $ pass1 != $ pass2 ) return AdminStoreError :: PASSWORD_NOT_SAME ; if ( strlen ( $ pass1 ) < 4 ) return AdminStoreError :: PASSWORD_TOO_SHORT ; return 0 ; } | Verify plaintext password . |
354 | public static function generate_secret ( $ data , $ key = null , $ length = 64 ) { if ( ! $ key ) $ key = uniqid ( ) . ( string ) mt_rand ( ) ; $ bstr = $ data . $ key ; $ bstr = hash_hmac ( 'sha256' , $ bstr , $ key , true ) ; $ bstr = base64_encode ( $ bstr ) ; $ bstr = str_replace ( [ '/' , '+' , '=' ] , '' , $ bstr ) ; return substr ( $ bstr , 0 , $ length ) ; } | Generate salt . |
355 | public static function verify_site_url ( $ url ) { $ url = trim ( $ url ) ; if ( ! $ url || strlen ( $ url ) > 64 ) return false ; return filter_var ( $ url , FILTER_VALIDATE_URL ) ; } | Verify site url |
356 | public static function verify_email_address ( $ email ) { $ email = trim ( $ email ) ; if ( ! $ email || strlen ( $ email ) > 64 ) return false ; return filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ; } | Verify email address . |
357 | public function method ( $ class , $ method , array $ params = [ ] , $ forceScopeCalls = false ) { $ reflectionClass = new \ ReflectionClass ( is_string ( $ class ) ? $ this -> laraApp -> make ( $ class ) : $ class ) ; $ reflectionMethod = $ reflectionClass -> getMethod ( $ method ) ; $ resolved = $ this -> resolve ( $ reflectionMethod -> getParameters ( ) , $ params ) ; try { $ result = call_user_func_array ( [ $ class , $ method ] , $ resolved ) ; } catch ( \ Exception $ exception ) { if ( $ forceScopeCalls && ( $ reflectionMethod -> isPrivate ( ) || $ reflectionMethod -> isProtected ( ) ) ) { $ reflectionMethod -> setAccessible ( true ) ; $ result = $ reflectionMethod -> invokeArgs ( $ class , $ resolved ) ; $ reflectionMethod -> setAccessible ( false ) ; } else { throw $ exception ; } } return $ result ; } | Resolves class method and calls it . |
358 | protected function _normalizeContainer ( $ container ) { if ( ! ( $ container instanceof BaseContainerInterface ) && ! ( $ container instanceof stdClass ) && ! ( $ container instanceof ArrayAccess ) && ! is_array ( $ container ) ) { throw $ this -> _createInvalidArgumentException ( $ this -> __ ( 'Invalid container' ) , null , null , $ container ) ; } return $ container ; } | Normalizes a container . |
359 | public function configure ( ArrayNodeDefinition $ builder ) { $ children = $ builder -> children ( ) ; $ children -> scalarNode ( 'phantom_server' ) -> isRequired ( ) -> end ( ) ; $ children -> scalarNode ( 'template_cache' ) -> defaultNull ( ) -> end ( ) ; } | Setups configuration for the driver factory . |
360 | protected static function normalizeUploadedFiles ( array $ uploadedFiles ) { $ files = [ ] ; foreach ( $ uploadedFiles as $ key => $ value ) { if ( $ value instanceof UploadedFileInterface ) { $ files [ $ key ] = $ value ; } elseif ( is_array ( $ value ) && isset ( $ value [ 'tmp_name' ] ) ) { $ files [ $ key ] = static :: createUploadedFileFromSpec ( $ value ) ; } elseif ( is_array ( $ value ) ) { $ files [ $ key ] = static :: normalizeUploadedFiles ( $ value ) ; } else { throw new \ InvalidArgumentException ( 'Invalid uploaded files value' ) ; } } return $ files ; } | Normalizes the value of uploadedFiles . |
361 | public function transform ( Did $ did ) { return [ 'id' => $ did -> id , 'text' => $ did -> text , 'created_at' => $ did -> created_at -> toIso8601String ( ) ] ; } | Turn this item object into a generic array |
362 | public function hydrate ( $ classNameOrObject , iterable $ values ) : object { ensure_data ( $ classNameOrObject ) -> isTypeOf ( 'string' , 'object' ) ; return $ this -> denormalize ( $ values , $ classNameOrObject ) ; } | Crea un objeto a partir de un array |
363 | public function extract ( object $ object , string $ snakeCaseSeparator = '_' ) : array { $ this -> nameConverter -> setSnakeCaseSeparator ( $ snakeCaseSeparator ) ; return $ this -> normalize ( $ object ) ; } | Crea un array a partir de un objeto |
364 | public static function encode ( $ data ) { $ json = json_encode ( $ data , JSON_UNESCAPED_SLASHES ) ; $ json = str_replace ( [ "\t" , "\r" , "\n" ] , [ '\\t' , '\\r' , '\\n' ] , $ json ) ; return $ json ; } | Encodes the passed parameter into JSON . Slashes in the resulting JSON will not be escaped per newest Internet standards . |
365 | public static function registerPolicy ( $ config ) { $ modeloM = ucfirst ( basename ( $ config [ 'modelo' ] ) ) ; $ modelo = strtolower ( $ modeloM ) ; $ policyName = $ modeloM . 'Policy' ; $ path = str_finish ( str_replace ( [ "/" ] , [ "\\" ] , app_path ( 'Providers/AuthServiceProvider.php' ) ) , '.php' ) ; $ policyPath = app_path ( 'Policies/' . str_finish ( $ policyName , ".php" ) ) ; $ policyPath = str_finish ( str_replace ( [ "/" ] , [ "\\" ] , $ policyPath ) , '.php' ) ; if ( file_exists ( $ path ) && file_exists ( $ policyPath ) ) { $ modeloM = basename ( $ config [ 'modelo' ] ) ; $ contents = file ( $ path ) ; $ inicio = - 1 ; $ fin = - 1 ; $ encontrado = - 1 ; foreach ( $ contents as $ index => $ line ) { if ( strpos ( $ line , '$policies = [' ) !== false ) { $ inicio = $ index ; } if ( strpos ( $ line , $ config [ 'modelo' ] ) !== false && $ inicio >= 0 && $ fin == - 1 ) { $ encontrado = $ index ; } if ( strpos ( $ line , "];" ) !== false && $ inicio >= 0 && $ fin == - 1 ) { $ fin = $ index ; } } $ newTexto = chr ( 9 ) . "'" . $ config [ 'modelo' ] . "' => 'App\\Policies\\" . $ policyName . "', " . chr ( 13 ) . chr ( 10 ) ; if ( $ encontrado >= 0 ) { $ contents [ $ encontrado ] = $ newTexto ; } elseif ( $ inicio >= 0 && $ fin >= 0 ) { $ newContent = array_slice ( $ contents , 0 , $ fin ) ; $ newContent [ ] = $ newTexto ; foreach ( array_slice ( $ contents , $ fin ) as $ linea ) { $ newContent [ ] = $ linea ; } $ contents = $ newContent ; } $ contents = file_put_contents ( $ path , $ contents ) ; } else { $ contents = false ; } return $ contents ; } | Register a Model Policy in AuthServiceProvider using a config Array |
366 | public static function saveResource ( $ view , $ localized , $ path , $ filename , $ config , $ pathPermissions = 0764 , $ flags = "" ) { $ view = str_start ( $ view , "sirgrimorum::templates." ) ; $ modeloClass = $ config [ 'modelo' ] ; $ modeloM = ucfirst ( basename ( $ config [ 'modelo' ] ) ) ; $ modelo = strtolower ( $ modeloM ) ; $ searchArr = [ "{?php}" , "{php?}" , "[[" , "]]" , "[!!" , "!!]" , "{modelo}" , "{Modelo}" , "{model}" , "{Model}" , "*extends" , "*section" , "*stop" , "*stack" , "*push" , "*if" , "*else" , "*foreach" , "*end" , "{ " . $ modelo . " }" ] ; $ replaceArr = [ "<?php" , "?>" , "{{" , "}}" , "{!!" , "!!}" , $ modelo , $ modeloM , $ modelo , $ modeloM , "@extends" , "@section" , "@stop" , "@stack" , "@push" , "@if" , "@else" , "@foreach" , "@end" , "{" . $ modelo . "}" ] ; $ contenido = view ( $ view , [ "config" => $ config , "localized" => $ localized , "modelo" => $ modelo ] ) -> render ( ) ; $ contenido = str_replace ( $ searchArr , $ replaceArr , $ contenido ) ; if ( substr ( $ path , strlen ( $ path ) - 1 ) == "/" || substr ( $ path , strlen ( $ path ) - 1 ) == "\\" ) { $ path = substr ( $ path , 0 , strlen ( $ path ) - 1 ) ; } if ( ! file_exists ( $ path ) ) { mkdir ( $ path , $ pathPermissions , true ) ; } $ path = str_finish ( str_replace ( [ "/" ] , [ "\\" ] , $ path . str_start ( $ filename , "/" ) ) , '.php' ) ; if ( $ flags == "append" ) { return file_put_contents ( $ path , $ contenido , FILE_APPEND ) ; } else { return file_put_contents ( $ path , $ contenido ) ; } } | Create a new Model related file using a view as a template and a config array as directives |
367 | public static function removeFile ( $ filename , $ public = true ) { if ( $ public ) { $ path = public_path ( $ filename ) ; } else { $ path = base_path ( $ filename ) ; } if ( file_exists ( $ path ) ) { unlink ( $ path ) ; } else { return false ; } } | Remove a file if exists |
368 | public static function registerConfig ( $ config , $ path , $ config_path = "" ) { $ inPath = $ path ; $ path = str_finish ( str_replace ( [ "." , "/" ] , [ "\\" , "\\" ] , $ path ) , '.php' ) ; if ( $ config_path == "" ) { $ config_path = config_path ( $ path ) ; } else { $ config_path = base_path ( $ config_path . str_start ( $ path , "/" ) ) ; } $ path = $ config_path ; $ crudgenConfig = config_path ( "sirgrimorum\\crudgenerator.php" ) ; if ( file_exists ( $ crudgenConfig ) && file_exists ( $ path ) ) { $ modeloM = basename ( $ config [ 'modelo' ] ) ; $ contents = file ( $ crudgenConfig ) ; $ inicio = - 1 ; $ fin = - 1 ; $ encontrado = - 1 ; foreach ( $ contents as $ index => $ line ) { if ( strpos ( $ line , "admin_routes" ) > 0 ) { $ inicio = $ index ; } if ( strpos ( $ line , $ modeloM ) > 0 && $ inicio >= 0 && $ fin == - 1 ) { $ encontrado = $ index ; } if ( strpos ( $ line , "]" ) > 0 && $ inicio >= 0 && $ fin == - 1 ) { $ fin = $ index ; } } $ newTexto = chr ( 9 ) . '"' . $ modeloM . '" => "' . $ inPath . '", ' . chr ( 13 ) . chr ( 10 ) ; if ( $ encontrado >= 0 ) { $ contents [ $ encontrado ] = $ newTexto ; } elseif ( $ inicio >= 0 && $ fin >= 0 ) { $ newContent = array_slice ( $ contents , 0 , $ fin ) ; $ newContent [ ] = $ newTexto ; foreach ( array_slice ( $ contents , $ fin ) as $ linea ) { $ newContent [ ] = $ linea ; } $ contents = $ newContent ; } $ contents = file_put_contents ( $ crudgenConfig , $ contents ) ; } else { $ contents = false ; } return $ contents ; } | Register a configuratio array file in the \ Sirgrimorum \ CrudGenerator \ CrudGenerator config file |
369 | public static function saveConfig ( $ config , $ path , $ config_path = "" ) { $ inPath = $ path ; if ( isset ( $ config [ 'parametros' ] ) ) { $ parametros = $ config [ 'parametros' ] ; unset ( $ config [ 'parametros' ] ) ; } else { $ parametros = "" ; } $ path = str_finish ( str_replace ( [ "." , "/" ] , [ "\\" , "\\" ] , $ path ) , '.php' ) ; if ( $ config_path == "" ) { $ config_path = config_path ( $ path ) ; } else { $ config_path = base_path ( $ config_path . str_start ( $ path , "/" ) ) ; } $ path = $ config_path ; $ strConfig = \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: arrayToFile ( $ config ) ; $ contents = file_put_contents ( $ path , $ strConfig ) ; return $ contents ; } | Create a configuration array file form a configuration array |
370 | private static function arrayToFile ( $ array ) { $ strFile = "<?php" . chr ( 13 ) . chr ( 10 ) . chr ( 13 ) . chr ( 10 ) . "return [" . chr ( 13 ) . chr ( 10 ) ; $ strValue = \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: arrayToFileWrite ( $ array , 0 ) ; $ strFile .= $ strValue . "];" ; return $ strFile ; } | Transform an array into a PHP file content string |
371 | private static function arrayToFileWrite ( $ array , $ numParent ) { $ tabs = "" ; for ( $ index = 0 ; $ index <= $ numParent ; $ index ++ ) { $ tabs .= chr ( 9 ) ; } $ strArr = "" ; foreach ( $ array as $ key => $ value ) { if ( is_array ( $ value ) ) { $ strValue = \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: arrayToFileWrite ( $ value , $ numParent + 1 ) ; $ strArr .= $ tabs . '"' . $ key . '" => [' . chr ( 13 ) . chr ( 10 ) . $ strValue . $ tabs . '], ' . chr ( 13 ) . chr ( 10 ) ; } elseif ( is_bool ( $ value ) ) { if ( $ value ) { $ strValue = "true" ; } else { $ strValue = "false" ; } $ strArr .= $ tabs . '"' . $ key . '" => ' . $ strValue . ', ' . chr ( 13 ) . chr ( 10 ) ; } elseif ( is_callable ( $ value ) && ! is_string ( $ value ) && $ value !== "file" && $ value !== "url" && $ value !== "config" ) { $ closure = new SuperClosure ( $ value ) ; $ strArr .= $ tabs . '"' . $ key . '" => ' . print_r ( $ closure -> getCode ( ) , true ) . ', ' . chr ( 13 ) . chr ( 10 ) ; } elseif ( is_object ( $ value ) ) { $ strArr .= $ tabs . '"' . $ key . '" => "' . serialize ( $ value ) . '", ' . chr ( 13 ) . chr ( 10 ) ; } elseif ( is_string ( $ value ) ) { $ strArr .= $ tabs . '"' . $ key . '" => "' . $ value . '", ' . chr ( 13 ) . chr ( 10 ) ; } elseif ( is_int ( $ value ) ) { $ strArr .= $ tabs . '"' . $ key . '" => ' . $ value . ', ' . chr ( 13 ) . chr ( 10 ) ; } } return $ strArr ; } | Transform an array into a string using identation |
372 | public static function filenameIs ( string $ filename , array $ detalles = [ ] ) { $ allowedMimeTypes = [ 'image' => [ 'image/jpeg' , 'image/gif' , 'image/png' , 'image/bmp' , 'image/x-windows-bmp' , 'image/svg+xml' , 'image/x-icon' , 'image/tiff' ] , 'video' => [ 'video/avi' , 'video/mpeg' , 'video/webm' , 'video/mp4' , 'video/ogg' , 'video/3gpp' , 'application/octet-stream' ] , 'audio' => [ 'audio/mpeg' , 'audio/midi' , 'audio/mod' , 'audio/mpeg3' , 'audio/wav' ] , 'pdf' => [ 'application/pdf' ] , 'text' => [ 'text/html' , 'text/plain' , 'text/richtext' ] , 'office' => [ 'application/mspowerpoint' , 'application/msword' , 'application/excel' , 'application/vnd.ms-excel' , 'application/vnd.ms-powerpoint' ] , 'compressed' => [ 'application/x-compressed' , 'application/zip' , 'multipart/x-zip' , 'application/x-zip-compressed' ] , ] ; $ mimeType = \ Sirgrimorum \ CrudGenerator \ CrudGenerator :: fileMime ( $ filename , $ detalles ) ; foreach ( $ allowedMimeTypes as $ type => $ allowedMimeType ) { if ( in_array ( $ mimeType , $ allowedMimeType ) ) { return $ type ; } } return 'other' ; } | Know if a filename in public is an image with configuration array |
373 | public static function fileMime ( string $ filename , array $ detalles = [ ] ) { if ( isset ( $ detalles [ 'path' ] ) ) { $ path = str_start ( str_replace ( "\\" , "/" , $ filename ) , str_finish ( str_replace ( "\\" , "/" , $ detalles [ 'path' ] ) , '/' ) ) ; } else { $ path = $ filename ; } $ ext = pathinfo ( $ path , PATHINFO_EXTENSION ) ; if ( file_exists ( $ path ) ) { $ typesArray = config ( "sirgrimorum.mimebyext" , [ ] ) ; $ mimeType = "" ; if ( ! count ( $ typesArray ) == 0 ) { if ( isset ( $ typesArray [ $ ext ] ) ) { $ mimeType = $ typesArray [ $ ext ] ; } } $ otro = $ mimeType ; if ( $ mimeType == "" ) { $ finfo = finfo_open ( FILEINFO_MIME_TYPE ) ; $ mimeType = finfo_file ( $ finfo , public_path ( $ path ) ) ; } return $ mimeType ; } else { return false ; } } | Get Mime of a filename in public with configuration array |
374 | public function setReleases ( $ releases ) { if ( ! is_array ( $ releases ) ) { throw new \ Exception ( "The releases parameter must be an array." ) ; } if ( isset ( $ this -> currentRelease ) ) { if ( ! isset ( $ releases [ $ this -> currentRelease [ 'version' ] ] ) ) { unset ( $ this -> currentRelease ) ; } else { $ this -> currentRelease = $ releases [ $ this -> currentRelease [ 'version' ] ] ; } } $ this -> releases = $ releases ; } | Set an array with all releases . The current release must be re - set if this is set and the current release isn t in the array . |
375 | public function setCurrentRelease ( $ currentRelease ) { if ( ! isset ( $ this -> releases [ $ currentRelease [ 'version' ] ] ) ) { throw new \ Exception ( "The current release needs to be part of the release array." ) ; } $ this -> currentRelease = $ currentRelease ; } | Set the current release meaning the latest recommended release . |
376 | public function parse ( string $ input ) : \ DateInterval { $ input = trim ( $ this -> normalizer -> normalize ( $ input ) ) ; $ definition = Pattern :: DEFINE . Pattern :: INTEGER . Pattern :: TIME_PART . ')' ; $ expression = $ definition . Pattern :: INTERVAL_ONLY ; if ( preg_match ( $ expression , $ input , $ matches ) ) { return \ DateInterval :: createFromDateString ( $ input ) ; } throw new FormatException ( "Given string is not a valid time interval." ) ; } | Normalizes any non - strtotime - compatible time string then validates the interval and returns a DateInterval object . No leading or trailing data is accepted . |
377 | public static function normalize ( array $ config ) { $ config [ 'mime_types' ] = ( array ) $ config [ 'mime_types' ] ; $ config [ 'cropper_enabled' ] = ( bool ) $ config [ 'cropper_enabled' ] ; $ config [ 'max_file_size' ] = ( int ) $ config [ 'max_file_size' ] ; $ config [ 'max_height' ] = ( int ) $ config [ 'max_height' ] ; $ config [ 'max_width' ] = ( int ) $ config [ 'max_width' ] ; $ config [ 'min_height' ] = ( int ) $ config [ 'min_height' ] ; $ config [ 'min_width' ] = ( int ) $ config [ 'min_width' ] ; $ config [ 'cropper_coordinates' ] = array_map ( 'intval' , $ config [ 'cropper_coordinates' ] ) ; return $ config ; } | Normalize image config . |
378 | static public function trigger ( string $ event , array $ args = [ ] , bool $ delete = true , $ newthis = null ) : int { if ( ! self :: exists ( $ event ) ) return 0 ; foreach ( self :: $ listeners [ $ event ] as $ listener ) { static $ count = 0 ; if ( $ newthis ) $ listener = $ listener -> bindTo ( $ newthis ) ; $ listener ( ... $ args ) ; $ count ++ ; } if ( $ delete ) self :: delete ( $ event ) ; return $ count ; } | Triggers all of an event s listeners . |
379 | public function dump ( $ file , array $ data ) { $ dir = dirname ( $ file ) ; if ( ! is_dir ( $ dir ) ) { mkdir ( $ dir , 0755 , true ) ; } $ fileInfo = new SplFileInfo ( $ file ) ; if ( $ fileInfo -> isFile ( ) ) { if ( $ fileInfo -> isWritable ( ) ) { $ fileObject = $ fileInfo -> openFile ( 'w' ) ; } else { throw new Exception ( sprintf ( 'File "%s" is not writable.' , $ file ) ) ; } } else { $ fileObject = $ fileInfo -> openFile ( 'w' ) ; } if ( null !== $ fileObject -> fwrite ( '<?php return ' . var_export ( $ data , true ) . ';' ) ) { return true ; } return false ; } | Dump config to file |
380 | public function replace ( $ from , $ to ) { if ( \ is_callable ( $ to ) ) { $ to = $ to ( $ from , $ this -> string ) ; } $ this -> string = \ str_replace ( $ from , $ to , $ this -> string ) ; return $ this ; } | Wrapper for str_replace . |
381 | public function ireplace ( $ from , $ to ) { if ( \ is_callable ( $ to ) ) { $ to = $ to ( $ from , $ this -> string ) ; } $ this -> string = \ str_ireplace ( $ from , $ to , $ this -> string ) ; return $ this ; } | Wrapper for str_ireplace . |
382 | public function upper ( $ encoding = null ) { if ( ! $ this -> hasMbstring ( ) ) { return $ this -> transform ( '\strtoupper' ) ; } $ encoding = $ this -> encoding ( $ encoding ) ; return $ this -> transform ( '\mb_convert_case' , MB_CASE_UPPER , $ encoding ) ; } | Wrapper for strtoupper . |
383 | public function lower ( $ encoding = null ) { if ( ! $ this -> hasMbstring ( ) ) { return $ this -> transform ( '\strtolower' ) ; } $ encoding = $ this -> encoding ( $ encoding ) ; return $ this -> transform ( '\mb_convert_case' , MB_CASE_LOWER , $ encoding ) ; } | Wrapper for strtolower . |
384 | public function upperFirst ( $ encoding = null ) { if ( ! $ this -> hasMbstring ( ) ) { return $ this -> transform ( '\ucfirst' ) ; } $ encoding = $ this -> encoding ( $ encoding ) ; $ string = \ mb_strtoupper ( \ mb_substr ( $ this -> string , 0 , 1 , $ encoding ) , $ encoding ) ; $ this -> string = $ string . \ mb_substr ( $ this -> string , 1 , \ mb_strlen ( $ this -> string , $ encoding ) , $ encoding ) ; return $ this ; } | Wrapper for ucfirst . |
385 | public function lowerFirst ( $ encoding = null ) { if ( ! $ this -> hasMbstring ( ) ) { return $ this -> transform ( '\lcfirst' ) ; } $ encoding = $ this -> encoding ( $ encoding ) ; $ string = \ mb_strtolower ( \ mb_substr ( $ this -> string , 0 , 1 , $ encoding ) , $ encoding ) ; $ this -> string = $ string . \ mb_substr ( $ this -> string , 1 , \ mb_strlen ( $ this -> string , $ encoding ) , $ encoding ) ; return $ this ; } | Wrapper for lcfirst . |
386 | public function upperWords ( $ delimiters = null ) { if ( is_null ( $ delimiters ) ) { $ delimiters = " \t\r\n\f\v" ; } if ( ( version_compare ( PHP_VERSION , '5.4.32' , '>=' ) && version_compare ( PHP_VERSION , '5.5.0' , '<' ) ) || version_compare ( PHP_VERSION , '5.5.16' , '>=' ) ) { return $ this -> transform ( 'ucwords' , $ delimiters ) ; } else { return $ this -> transform ( 'ucwords' ) ; } } | Wrapper for ucwords . |
387 | public function compose ( SQL $ SQL ) { if ( $ this -> _insert ) { return $ this -> _composeInsertQuery ( $ SQL ) ; } else { return $ this -> _composeUpdateQuery ( $ SQL ) ; } } | Composes a query from the QueryBuilder . |
388 | protected function _composeInsertQuery ( SQL $ SQL ) { $ query_pre = "INSERT INTO `$this->_table`" ; if ( empty ( $ this -> _fields ) ) { throw new QueryBuilderException ( 'No fields specified for SQL query' ) ; } $ fields = [ ] ; $ updates = [ ] ; foreach ( $ this -> _fields as $ field => $ value ) { $ prepared = $ this -> _prepareValue ( $ value , $ SQL ) ; $ fields [ $ field ] = $ prepared ; $ updates [ ] = "$field = $prepared" ; } $ query_fields = '(' . implode ( ', ' , array_keys ( $ fields ) ) . ')' ; $ query_values = '(' . implode ( ', ' , $ fields ) . ')' ; $ query_updates = implode ( ', ' , $ updates ) ; return "{$query_pre} {$query_fields} VALUES {$query_values} ON DUPLICATE KEY UPDATE {$query_updates} " ; } | Composes an insert query with an on duplicate key update part . |
389 | protected function _composeUpdateQuery ( SQL $ SQL ) { $ condition = parent :: compose ( $ SQL ) ; $ query_pre = "UPDATE `$this->_table` SET " ; $ query_post = " WHERE $condition" ; $ fields = [ ] ; if ( empty ( $ this -> _fields ) ) { throw new QueryBuilderException ( 'No fields specified for SQL query' ) ; } foreach ( $ this -> _fields as $ field => $ value ) { $ fields [ ] = "$field = " . $ this -> _prepareValue ( $ value , $ SQL ) ; } return $ query_pre . implode ( ', ' , $ fields ) . $ query_post ; } | Composes an update query . |
390 | public function create ( $ transport ) { if ( is_string ( $ transport ) ) { $ transport = $ this -> registry -> getTransport ( $ transport ) ; } if ( ! $ transport instanceof TransportInterface ) { throw new \ InvalidArgumentException ( 'transport should a string or a TransportInterface' ) ; } if ( null !== ( $ extension = $ this -> registry -> getExtension ( 'Rezzza\Jobflow\Extension\Monolog\MonologExtension' ) ) ) { $ this -> logger = $ extension -> getLogger ( ) ; } return new Jobflow ( $ transport , $ this -> jobFactory , new JobMessageFactory , new JobContextFactory , new ExecutionContextFactory , null , $ this -> logger ) ; } | Creates a Jobflow |
391 | public static function decode ( $ json ) { $ object = json_decode ( $ json , true ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { $ error = 'JSON error' ; if ( function_exists ( 'json_last_error_msg' ) ) { $ error = json_last_error_msg ( ) ; } else { switch ( json_last_error ( ) ) { case JSON_ERROR_DEPTH : $ error = 'maximum stack depth exceeded' ; break ; case JSON_ERROR_STATE_MISMATCH : $ error = 'invalid or malformed JSON' ; break ; case JSON_ERROR_CTRL_CHAR : $ error = 'control character error' ; break ; case JSON_ERROR_SYNTAX : $ error = 'JSON syntax error' ; break ; case JSON_ERROR_UTF8 : $ error = 'malformed UTF-8 characters' ; break ; } } throw new JsonException ( $ error ) ; } return $ object ; } | Decode a JSON string . |
392 | protected function GenerateConstantsClass ( $ data ) { if ( count ( $ data ) > 0 ) { $ classGen = new ConstantsAndListClassGenerator ( $ this -> params , $ data ) ; $ classGen -> BuildClass ( ) ; return str_replace ( ".php" , "" , $ classGen -> fileName ) ; } else { return "No class to generate." ; } } | Generate the Constant Class . |
393 | public static function ofObjectType ( $ fullName ) { $ result = self :: of ( $ fullName ) ; if ( ! ( $ result instanceof ObjectType ) ) throw new InvalidArgumentException ( "Argument 'fullName' does not describe a class or interface." ) ; return $ result ; } | Gets a class or interface type with a given name . |
394 | public static function ofClass ( $ fullName ) { $ result = self :: of ( $ fullName ) ; if ( ! ( $ result instanceof ClassType ) ) throw new InvalidArgumentException ( "Argument 'fullName' does not describe a class." ) ; return $ result ; } | Gets a class type with a given name . |
395 | public static function ofInterface ( $ fullName ) { $ result = self :: of ( $ fullName ) ; if ( ! ( $ result instanceof InterfaceType ) ) throw new InvalidArgumentException ( "Argument 'fullName' does not describe an interface." ) ; return $ result ; } | Gets a interface type with a given name . |
396 | public static function of ( $ typeName , RelativeClassNameResolver $ resolver = null ) { $ parts = explode ( "|" , $ typeName ) ; if ( count ( $ parts ) > 1 ) { $ types = array ( ) ; foreach ( $ parts as $ part ) $ types [ ] = self :: of ( $ part , $ resolver ) ; return self :: ofUnion ( $ types ) ; } $ result = PrimitiveType :: parse ( $ typeName ) ; if ( $ result == null ) { if ( substr ( $ typeName , - 2 ) === "[]" ) { $ itemType = self :: of ( substr ( $ typeName , 0 , - 2 ) , $ resolver ) ; return self :: ofArray ( $ itemType ) ; } if ( $ typeName === "array" ) { return self :: ofArray ( self :: ofMixed ( ) ) ; } $ realTypeName = "" ; if ( substr ( $ typeName , 0 , 1 ) === "\\" ) { $ realTypeName = substr ( $ typeName , 1 ) ; } else if ( $ resolver === null ) { $ realTypeName = $ typeName ; } else { $ realTypeName = $ resolver -> resolveRelativeName ( $ typeName ) ; } $ isInterface = interface_exists ( $ realTypeName ) ; if ( ! ( $ isInterface || class_exists ( $ realTypeName ) ) ) throw new ReflectionException ( "Type '" . $ realTypeName . "' does not exist." ) ; if ( $ isInterface ) return InterfaceType :: __internal_create ( $ realTypeName ) ; else return ClassType :: __internal_create ( $ realTypeName ) ; } return $ result ; } | Gets the type with the provided name . Throws an exception if the type is malformed or does not exist . |
397 | public function equals ( EmailAddressInterface $ emailAddress ) : bool { return $ this -> getHost ( ) -> equals ( $ emailAddress -> getHost ( ) ) && $ this -> getUsername ( ) === $ emailAddress -> getUsername ( ) ; } | Returns true if the email address equals other email address false otherwise . |
398 | public function withUsername ( string $ username ) : EmailAddressInterface { if ( ! self :: myValidateUsername ( $ username , $ error ) ) { throw new EmailAddressInvalidArgumentException ( $ error ) ; } return new self ( $ username , $ this -> myHost ) ; } | Returns a copy of the email address instance with the specified username . |
399 | public static function fromParts ( string $ username , HostInterface $ host ) : EmailAddressInterface { if ( ! self :: myValidateUsername ( $ username , $ error ) ) { throw new EmailAddressInvalidArgumentException ( $ error ) ; } return new self ( $ username , $ host ) ; } | Creates an email address from parts . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.