idx int64 0 60.3k | question stringlengths 64 4.24k | target stringlengths 5 618 |
|---|---|---|
25,500 | public function content ( $ dots = true ) { $ content = scandir ( $ this -> path ) ; foreach ( $ content as $ file ) { if ( $ dots == false ) { if ( ( strcmp ( $ file , "." ) == 0 ) or ( strcmp ( $ file , ".." ) == 0 ) ) { continue ; } } echo "<a href='" . $ this -> path . "/" . $ file . "'>" . $ file . "</a><br>" ; } } | Prints content of folder . |
25,501 | public function setFeaturedSkillId ( $ id , $ relatedId ) { $ model = $ this -> get ( $ id ) ; if ( $ model === null ) { return new NotFound ( [ 'message' => 'Picture not found.' ] ) ; } if ( $ this -> doSetFeaturedSkillId ( $ model , $ relatedId ) ) { $ this -> dispatch ( PictureEvent :: PRE_FEATURED_SKILL_UPDATE , $ model ) ; $ this -> dispatch ( PictureEvent :: PRE_SAVE , $ model ) ; $ model -> save ( ) ; $ this -> dispatch ( PictureEvent :: POST_FEATURED_SKILL_UPDATE , $ model ) ; $ this -> dispatch ( PictureEvent :: POST_SAVE , $ model ) ; return Updated ( [ 'model' => $ model ] ) ; } return NotUpdated ( [ 'model' => $ model ] ) ; } | Sets the FeaturedSkill id |
25,502 | protected function doSetFeaturedSkillId ( Picture $ model , $ relatedId ) { if ( $ model -> getPictureId ( ) !== $ relatedId ) { $ model -> setPictureId ( $ relatedId ) ; return true ; } return false ; } | Internal mechanism to set the FeaturedSkill id |
25,503 | public function ApplyRules ( $ Fields ) { foreach ( $ Fields as $ Index => $ Row ) { $ Validation = GetValue ( 'Validation' , $ Row ) ; if ( ! $ Validation ) continue ; $ FieldName = GetValue ( 'Name' , $ Row , $ Index ) ; if ( is_string ( $ Validation ) ) { $ this -> ApplyRule ( $ FieldName , $ Validation ) ; } elseif ( is_array ( $ Validation ) ) { foreach ( $ Validation as $ Rule ) { if ( is_array ( $ Rule ) ) { $ this -> ApplyRule ( $ FieldName , $ Rule [ 0 ] , $ Rule [ 1 ] ) ; } else { $ this -> ApplyRule ( $ FieldName , $ Rule ) ; } } } } } | Apply an array of validation rules all at once . |
25,504 | public static function ValidateRule ( $ Value , $ FieldName , $ Rule , $ CustomError = FALSE ) { if ( is_string ( $ Rule ) ) { if ( StringBeginsWith ( $ Rule , 'regex:' , TRUE ) ) { $ RuleName = 'regex' ; $ Args = substr ( $ Rule , 6 ) ; } elseif ( StringBeginsWith ( $ Rule , 'function:' , TRUE ) ) { $ RuleName = substr ( $ Rule , 9 ) ; } else { $ RuleName = $ Rule ; } } elseif ( is_array ( $ Rule ) ) { $ RuleName = GetValue ( 'Name' , $ Rule ) ; $ Args = GetValue ( 'Args' , $ Rule ) ; } if ( ! isset ( $ Args ) ) $ Args = NULL ; if ( function_exists ( $ RuleName ) ) { $ Result = $ RuleName ( $ Value , $ Args ) ; if ( $ Result === TRUE ) return TRUE ; elseif ( $ CustomError ) return $ CustomError ; elseif ( is_string ( $ Result ) ) return $ Result ; else return sprintf ( T ( $ RuleName ) , T ( $ FieldName ) ) ; } else { return sprintf ( 'Validation does not exist: %s.' , $ RuleName ) ; } } | Execute a single validation rule and return its result . |
25,505 | public function getUri ( ) { if ( empty ( $ this -> getConfig ( 'email' ) ) === true ) { throw new \ RuntimeException ( 'No email specified.' ) ; } $ uri = 'http://www.gravatar.com/avatar/' . md5 ( strtolower ( trim ( $ this -> getConfig ( 'email' ) ) ) ) . '.jpg' ; $ args = http_build_query ( [ 's' => $ this -> getConfig ( 'size' ) , 'd' => $ this -> getConfig ( 'defaultUri' ) , ] ) ; if ( empty ( $ args ) === false ) { $ uri .= '?' . $ args ; } return $ uri ; } | Get the gravatar URI . |
25,506 | public function radio ( $ field , $ label ) { $ radio = new Radio ( $ field , $ label ) ; array_push ( $ this -> _elements , $ radio ) ; return $ radio ; } | add radio element |
25,507 | public function withRule ( Rule $ rule ) : RulesCollection { $ rules = array_merge ( $ this -> rules , [ $ rule ] ) ; return new RulesCollection ( $ rules ) ; } | Return a new rules collection with an aditional rule . |
25,508 | private function getNestedErrors ( string $ key , array $ scope , array $ input ) : array { $ parts = explode ( '.' , $ key ) ; $ current = array_shift ( $ parts ) ; $ next = implode ( '.' , $ parts ) ; if ( $ current == '*' && count ( $ parts ) > 0 ) { $ errors = [ ] ; foreach ( $ scope as $ key => $ nested ) { $ new_errors = $ this -> getNestedErrors ( $ next , $ nested , $ input ) ; $ errors = array_merge ( $ errors , $ new_errors ) ; } return $ errors ; } if ( count ( $ parts ) > 0 ) { return $ this -> getNestedErrors ( $ next , $ scope [ $ current ] ?? [ ] , $ input ) ; } return $ this -> getErrors ( $ current , $ scope , $ input ) ; } | Go deeper in the input array for each dot in the rule key . Run the validation when on the last part of the rule key . |
25,509 | private function getErrors ( string $ key , array $ scope , array $ input ) : array { $ errors = [ ] ; foreach ( $ this -> rules as $ rule ) { try { $ rule -> validate ( $ key , $ scope , $ input ) ; } catch ( ValidationException $ e ) { $ parameters = $ e -> getParameters ( ) ; $ errors [ ] = new ValidationError ( $ rule -> getName ( ) , $ parameters ) ; } } return $ errors ; } | Run the validation on a key of the given scope . |
25,510 | public function parseURI ( string $ uri ) : array { if ( $ uri == '' ) { throw new \ InvalidArgumentException ( "URI Could not be empty" ) ; } $ parsedUri = parse_url ( $ uri ) ; if ( $ parsedUri === false ) { throw new \ InvalidArgumentException ( "Unable to parse URI: $uri" ) ; } $ defaultParsedUri = [ 'user' => null , 'pass' => null , 'scheme' => '' , 'host' => '' , 'port' => null , 'path' => '' , 'query' => '' , 'fragment' => '' , ] ; return array_merge ( $ defaultParsedUri , $ parsedUri ) ; } | Parse URI and return full detail |
25,511 | public function removeDefaultPort ( ) { if ( $ this -> port !== null && isset ( $ this -> defaultPorts [ $ this -> getScheme ( ) ] ) && $ this -> defaultPorts [ $ this -> getScheme ( ) ] === $ this -> port ) { $ this -> port = null ; } } | Remove Default Port |
25,512 | public function toUriString ( ) : string { $ uri = '' ; if ( ( $ scheme = $ this -> getScheme ( ) ) != '' ) { $ uri .= $ scheme . ':' ; } if ( ( $ authority = $ this -> getAuthority ( ) ) != '' || $ scheme === 'file' ) { $ uri .= '//' . $ authority ; } $ uri .= $ this -> getPath ( ) ; if ( ( $ query = $ this -> getQuery ( ) ) != '' ) { $ uri .= '?' . $ query ; } if ( ( $ fragment = $ this -> getFragment ( ) ) != '' ) { $ uri .= '#' . $ fragment ; } return $ uri ; } | Convert Uri to String |
25,513 | public static function fixSchemeProxyFromGlobals ( array $ globals = null ) : array { $ globals = $ globals === null ? $ _SERVER : $ globals ; if ( ! empty ( $ globals [ 'HTTPS' ] ) && strtolower ( $ globals [ 'HTTPS' ] ) !== 'off' || isset ( $ globals [ 'HTTP_X_FORWARDED_PROTO' ] ) && $ globals [ 'HTTP_X_FORWARDED_PROTO' ] === 'https' || ! empty ( $ globals [ 'HTTP_FRONT_END_HTTPS' ] ) && strtolower ( $ globals [ 'HTTP_FRONT_END_HTTPS' ] ) !== 'off' ) { $ globals [ 'HTTPS' ] = 'on' ; } return $ globals ; } | Fix Connection Behind Proxy Scheme |
25,514 | public function getDiv ( $ params = array ( ) ) { $ t = new Template ( $ this -> cheminTemplates ) ; $ t -> set_filenames ( ( array ( 'popup' => 'popupGeneric.tpl' ) ) ) ; $ width = 500 ; if ( isset ( $ params [ 'width' ] ) && $ params [ 'width' ] != '' ) { $ width = $ params [ 'width' ] ; } $ height = 500 ; if ( isset ( $ params [ 'height' ] ) && $ params [ 'height' ] != '' ) { $ height = $ params [ 'height' ] ; } $ left = 100 ; if ( isset ( $ params [ 'left' ] ) && $ params [ 'left' ] != '' ) { $ left = $ params [ 'left' ] ; } $ top = 50 ; if ( isset ( $ params [ 'top' ] ) && $ params [ 'top' ] != '' ) { $ top = $ params [ 'top' ] ; } $ titrePopup = "" ; if ( isset ( $ params [ 'titre' ] ) && $ params [ 'titre' ] != '' ) { $ titrePopup = $ params [ 'titre' ] ; } $ codeJsFermer = "" ; if ( isset ( $ params [ 'codeJsFermerButton' ] ) && $ params [ 'codeJsFermerButton' ] != '' ) { $ codeJsFermer = $ params [ 'codeJsFermerButton' ] ; } $ hiddenFields = "" ; if ( isset ( $ params [ 'hiddenFields' ] ) ) { foreach ( $ params [ 'hiddenFields' ] as $ indice => $ value ) { $ hiddenFields .= "<input type='hidden' id='" . $ indice . "' name='" . $ indice . "' value='" . $ value . "'>" ; } } $ t -> assign_vars ( array ( 'width' => $ width , 'height' => $ height , 'left' => $ left , 'top' => $ top , 'hiddenFields' => $ hiddenFields , 'divIdPopup' => 'div' . $ this -> idPopup , 'tdIdPopup' => 'td' . $ this -> idPopup , 'iFrameIdPopup' => 'iFrame' . $ this -> idPopup , 'lienSrcIFrame' => $ params [ 'lienSrcIFrame' ] , 'titrePopup' => $ titrePopup , 'codeJsFermer' => $ codeJsFermer ) ) ; ob_start ( ) ; $ t -> pparse ( 'popup' ) ; $ html = ob_get_contents ( ) ; ob_end_clean ( ) ; return $ html ; } | renvoi le code HTML de la popup en calque |
25,515 | private function prepareOptions ( array $ options ) { if ( ! Arr :: has ( $ options , 'method' ) ) { Arr :: set ( $ options , 'method' , 'post' ) ; } if ( ! Arr :: has ( $ options , 'action' ) ) { Arr :: set ( $ options , 'action' , '' ) ; } return $ options ; } | prepare options for build |
25,516 | public function chainingGetMethod ( $ key ) { $ newCollection = new self ( ) ; foreach ( $ this -> items as $ item ) { if ( $ item instanceof self ) { foreach ( $ item as $ subItem ) { $ newCollection -> put ( $ newCollection -> count ( ) , $ subItem -> $ key ) ; } continue ; } if ( is_object ( $ item ) && ! $ item instanceof self && $ item -> $ key instanceof self ) { foreach ( $ item -> $ key as $ subItem ) { $ newCollection -> put ( $ newCollection -> count ( ) , $ subItem ) ; } continue ; } $ newCollection -> put ( $ newCollection -> count ( ) , $ item -> $ key ) ; } return $ newCollection ; } | Dynamically retrieve attributes on the model . |
25,517 | public static function attrToArray ( $ object ) { if ( is_array ( $ object ) || is_object ( $ object ) ) { $ result = [ ] ; foreach ( $ object as $ key => $ value ) { $ result [ $ key ] = self :: attrToArray ( $ value ) ; } return $ result ; } return $ object ; } | Extract attributes object in array . |
25,518 | public static function fromArray ( array $ attributes ) { $ object = new ArrayObject ( ) ; foreach ( $ attributes as $ key => $ val ) { $ object [ $ key ] = $ val ; } return $ object ; } | Array attributes to object class ArrayObject . |
25,519 | public static function retrieve ( $ context ) { if ( $ context instanceof sfContext || $ context instanceof sfProjectConfiguration ) { return $ context -> getEventDispatcher ( ) ; } elseif ( isset ( $ GLOBALS [ 'dispatcher' ] ) ) { return $ GLOBALS [ 'dispatcher' ] ; } $ refClass = new ReflectionClass ( get_class ( $ context ) ) ; if ( $ refClass -> hasProperty ( 'dispatcher' ) ) { return self :: retrieveByDispatcherProperty ( $ refClass , $ context ) ; } elseif ( $ refClass -> hasProperty ( 'configuration' ) ) { return self :: retrieveByConfigurationProperty ( $ refClass , $ context ) ; } } | Returns the sfEventDispatcher instance . |
25,520 | public static function initialize ( ) { switch ( $ _SERVER [ 'REQUEST_METHOD' ] ) { case "POST" : self :: $ _method = self :: POST ; break ; case "GET" : self :: $ _method = self :: GET ; break ; case "PUT" : self :: $ _method = self :: PUT ; break ; case "DELETE" : self :: $ _method = self :: DELETE ; break ; default : self :: $ _method = self :: HEAD ; } self :: $ _data = array ( ) ; self :: _parseData ( $ _GET ) ; self :: _parseData ( $ _POST ) ; if ( isset ( $ _SERVER [ 'HTTPS' ] ) && $ _SERVER [ 'HTTPS' ] !== null && $ _SERVER [ 'HTTPS' ] !== "off" ) { self :: $ _https = true ; } else { self :: $ _https = false ; } self :: $ _domain = ( string ) $ _SERVER [ 'HTTP_HOST' ] ; self :: $ _file = ( string ) $ _SERVER [ 'SCRIPT_FILENAME' ] ; if ( isset ( $ _SERVER [ 'PATH_INFO' ] ) ) { self :: $ _pathInfo = ( string ) $ _SERVER [ 'PATH_INFO' ] ; } else { self :: $ _pathInfo = "" ; } } | Initializes this class . This means the request and input data will be loaded and parsed . |
25,521 | private static function _parseData ( array $ data ) { foreach ( $ data as $ key => $ value ) { self :: $ _data [ \ mb_strtolower ( $ key ) ] = $ value ; } } | Adds the given array data to the input data . |
25,522 | public static function getValue ( string $ key ) { $ key = \ mb_strtolower ( $ key ) ; if ( isset ( self :: $ _data [ $ key ] ) ) { return self :: $ _data [ $ key ] ; } return null ; } | Returns the value with the given key from input data . |
25,523 | public static function issetValue ( string $ key ) : bool { $ key = \ mb_strtolower ( $ key ) ; return isset ( self :: $ _data [ $ key ] ) ; } | Checks whether a value t the given input key was set in the form . |
25,524 | public function backup ( $ databases ) { foreach ( $ databases as $ database ) { echo "\n" . 'dumping ' . $ database . ' database' . "\n" ; try { system ( $ this -> command ( $ database ) ) ; } catch ( \ Exception $ e ) { $ this -> event -> fire ( 'MonasheeBackupError' , $ e -> getMessage ( ) ) ; throw new \ Exception ( 'mysqldump error' ) ; } echo 'done.' . "\n\n" ; } $ this -> event -> fire ( 'MonasheeBackupInfo' , 'All databases done dumping.' ) ; return true ; } | Create backups and save to file |
25,525 | public function getPostEditUser ( ) { $ this -> di -> get ( "auth" ) -> isLoggedIn ( ) ; $ user = new User ( ) ; $ user -> setDb ( $ this -> di -> get ( "db" ) ) ; $ user -> find ( "email" , $ this -> di -> get ( "session" ) -> get ( "user" ) ) ; $ title = "Redigera profil" ; $ card = "Redigera" ; $ view = $ this -> di -> get ( "view" ) ; $ pageRender = $ this -> di -> get ( "pageRender" ) ; $ form = new EditUserForm ( $ this -> di , $ user -> email ) ; $ form -> check ( ) ; $ data = [ "form" => $ form -> getHTML ( ) , "card" => $ card , "title" => $ title , ] ; $ view -> add ( "user/edit" , $ data ) ; $ pageRender -> renderPage ( [ "title" => $ title ] ) ; } | Handler with form to update a user . |
25,526 | private function pickShortName ( $ syntax ) { $ name = null ; if ( preg_match ( '/,(\w+)=?/' , $ syntax , $ matches ) ) { $ name = $ matches [ 1 ] ; } return $ name ; } | pick short name |
25,527 | public static function prettySeconds ( $ seconds = 0.0 ) { $ _remain = $ seconds ; $ _hours = floor ( $ _remain / Enums \ DateTime :: SecondsPerHour ) ; $ _remain -= $ _hours * Enums \ DateTime :: SecondsPerHour ; $ _minutes = floor ( $ _remain / Enums \ DateTime :: SecondsPerMinute ) ; $ _remain -= $ _minutes * Enums \ DateTime :: SecondsPerMinute ; return $ _hours . 'h ' . $ _minutes . 'm ' . number_format ( $ _remain , 2 ) . 's' ; } | Coverts a number of seconds into a pretty string ( i . e . 0d 0h 0m 0 . 00s |
25,528 | public function getModel ( $ id ) { if ( ! is_array ( $ id ) ) { $ id = [ $ id ] ; } $ model = call_user_func ( $ this -> findModel , $ id ) ; if ( $ model === null ) { throw new NotFoundHttpException ( 'The requested page does not exist.' ) ; } return $ model ; } | If the data model is not found an exception is thrown HTTP 404 |
25,529 | public function redirect ( ActiveRecord $ model = null ) { $ route = $ this -> redirectTo ; $ controller = $ this -> controller ; $ request = Yii :: $ app -> getRequest ( ) ; if ( $ model && $ route instanceof \ Closure ) { $ route = call_user_func ( $ route , $ model ) ; } if ( $ route === null ) { return $ request -> getReferrer ( ) ? $ controller -> redirect ( $ request -> getReferrer ( ) ) : $ controller -> goHome ( ) ; } return $ controller -> redirect ( $ route ) ; } | Redirect to route passed as param |
25,530 | public function addSuccessFlash ( ) { if ( $ this -> successMessage ) { $ session = Instance :: of ( $ this -> session ) -> get ( ) ; $ session -> addFlash ( 'success' , $ this -> successMessage ) ; } } | Adds flash message about success completed operation . |
25,531 | public function addErrorFlash ( ) { if ( $ this -> errorMessage ) { $ session = Instance :: of ( $ this -> session ) -> get ( ) ; $ session -> addFlash ( 'error' , $ this -> errorMessage ) ; } } | Adds flash message if completed operation with error . |
25,532 | public function commit ( ) { try { if ( empty ( $ this -> _fields ) ) { $ field = 'COUNT(1)' ; } else { $ field = 'COUNT(' ; if ( $ this -> _fields [ static :: FIELD_DISTINCT ] ) { $ field .= 'DISTINCT(' ; } $ field .= '`' . $ this -> _fields [ static :: FIELD_NAME ] . '`' ; if ( $ this -> _fields [ static :: FIELD_DISTINCT ] ) { $ field .= ')' ; } $ field = ')' ; } $ query = " SELECT $field AS nb FROM `" . $ this -> getDbPrefix ( ) . $ this -> _dbContainer . "`" ; if ( $ this -> _conditions -> count ( ) ) { $ query .= " WHERE " . $ this -> _conditions -> getPreparedConditions ( $ this -> _dbContainer ) . "" ; } $ prepared = Agl :: app ( ) -> getDb ( ) -> getConnection ( ) -> prepare ( $ query ) ; if ( $ prepared -> execute ( $ this -> _conditions -> getPreparedValues ( ) ) ) { $ result = $ prepared -> fetchObject ( ) ; if ( ! $ result ) { throw new Exception ( "The count query failed (table '" . $ this -> getDbPrefix ( ) . $ this -> _dbContainer . "')" ) ; } } else { $ error = $ prepared -> errorInfo ( ) ; throw new Exception ( "The count query failed (table '" . $ this -> getDbPrefix ( ) . $ this -> _dbContainer . "') with message '" . $ error [ 2 ] . "'" ) ; } if ( Agl :: app ( ) -> isDebugMode ( ) ) { Agl :: app ( ) -> getDb ( ) -> incrementCounter ( ) ; } return ( int ) $ result -> { 'nb' } ; } catch ( Exception $ e ) { throw new Exception ( $ e ) ; } } | Commit the count query to the database and return the result . |
25,533 | public function newAction ( ) { $ entity = new Service ( ) ; $ form = $ this -> createCreateForm ( $ entity ) ; return array ( 'entity' => $ entity , 'form' => $ form -> createView ( ) , ) ; } | Displays a form to create a new Service entity . |
25,534 | public function get ( ) { do { $ response = $ this -> redis -> rpop ( "job_queue" ) ; usleep ( 500 ) ; } while ( $ response === null ) ; return unserialize ( $ response ) ; } | Get the next job on the job queue . |
25,535 | protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> before ( $ input , $ output ) ; $ this -> runTransient ( $ input , $ output ) ; $ this -> after ( $ input , $ output ) ; } | This is the command which executes the application |
25,536 | protected function loadEnvironments ( ) { $ this -> purge ( ) ; if ( false == file_exists ( $ this -> getFileName ( ) ) ) { touch ( $ this -> getFileName ( ) ) ; } $ tempEnvironments = file ( $ this -> getFileName ( ) ) ; foreach ( $ tempEnvironments as $ key => $ value ) { $ value = trim ( $ value ) ; if ( null != $ value && '' != $ value && false == is_array ( $ value ) ) { if ( true == $ this -> vagrentExists ( $ value ) ) { $ this -> _environments [ ] = $ value ; } } } return $ this -> _environments ; } | This method loads the _environments from disk into an array |
25,537 | public function save ( ) { if ( true == file_exists ( $ this -> getFileName ( ) ) ) { unlink ( $ this -> getFileName ( ) ) ; } touch ( $ this -> getFileName ( ) ) ; $ content = "" ; foreach ( $ this -> getEnvironments ( ) as $ environment ) { $ content .= "{$environment}\n" ; } file_put_contents ( $ this -> getFileName ( ) , $ content ) ; return $ content ; } | This method iterates over the _environments writing them to disk . |
25,538 | private function _getLogFileName ( ) { static $ logFileName = null ; if ( null == $ logFileName ) { $ logFileName = $ this -> getUserHome ( ) . self :: DEFAULT_LOG ; } return $ logFileName ; } | This method returns the path to the log file |
25,539 | public function createEnvironment ( $ name ) { if ( false == $ this -> vagrentExists ( $ name ) ) { $ msg = self :: VAGRANT_FILE_NAME . " not found in {$name}, skipping" ; $ this -> printLn ( $ msg , 'error' ) ; return ; } $ environments = $ this -> getEnvironments ( ) ; $ changed = false ; if ( false == $ this -> environmentExists ( $ name ) ) { $ environments [ ] = $ name ; $ changed = true ; $ this -> printLn ( "Environment {$name} created" ) ; } if ( true == $ changed ) { $ this -> setEnvironments ( $ environments ) ; $ environments = array_reverse ( $ environments ) ; $ this -> setEnvironments ( $ environments ) ; } else { $ message = "Environment {$name} already exists, skipping" ; $ this -> printLn ( $ message , 'notice' , false ) ; } return $ this ; } | This method adds the environment to storage if it is not already in storage . |
25,540 | public function removeEnvironment ( $ name ) { $ removed = false ; $ environments = $ this -> getEnvironments ( ) ; if ( true == in_array ( $ name , $ environments ) ) { if ( ( $ key = array_search ( $ name , $ environments ) ) !== false ) { $ this -> printLn ( "Removing environment {$name}" ) ; unset ( $ environments [ $ key ] ) ; $ removed = true ; } } if ( false == $ removed ) { $ this -> printLn ( "environment {$name} not found or removed" ) ; } $ this -> setEnvironments ( $ environments ) ; return $ this ; } | This method removed an environment from the system . The environment must match exactly to the path in storage . |
25,541 | protected function environmentsDown ( $ ignoreCurrentEnvironment = false ) { foreach ( $ this -> getEnvironments ( ) as $ environment ) { if ( true == $ ignoreCurrentEnvironment && $ environment == $ this -> getCurrentEnvironment ( ) ) { $ this -> printLn ( "Skipping current environment {$environment}" ) ; } else if ( true == file_exists ( $ environment ) ) { chdir ( $ environment ) ; $ this -> printLn ( "Attempting shutdown down vagrant in {$environment}" ) ; $ output = '' ; $ return = '' ; exec ( 'vagrant halt' , $ output , $ return ) ; if ( false == is_array ( $ output ) ) { $ output = array ( $ output ) ; } if ( 0 != $ return ) { $ this -> printLn ( "Error found, logged" , 'warning' ) ; $ this -> printLn ( implode ( ', ' , $ output ) , 'warning' , false ) ; } else { $ this -> printLn ( implode ( ', ' , $ output ) , 'notice' ) ; } } else { $ this -> printLn ( "Dir not found {$environment}" ) ; } } chdir ( $ this -> pwd ) ; return $ this ; } | This method halts every Vagrant environment . This is the only method which executes a command . |
25,542 | protected function printLn ( $ message , $ type = 'general' , $ out = true ) { if ( null == $ message ) { return ; } if ( null != $ this -> output ) { $ message = ( null == $ type ) ? $ message : "<{$type}>{$message}</{$type}>" ; if ( true == $ out ) { $ this -> output -> writeLn ( $ message ) ; } } $ this -> getLog ( ) -> addInfo ( $ message , array ( 'type' => $ type ) ) ; } | This method prints a line to the terminal . |
25,543 | protected function cleanEnvironments ( ) { $ environmentsWhichExist = array ( ) ; foreach ( $ this -> getEnvironments ( ) as $ key => $ environment ) { $ msg = "Cleaning environment from storage {$environment}" ; if ( true == $ this -> vagrentExists ( $ environment ) ) { $ environmentsWhichExist [ ] = $ environment ; $ msg = "Not cleaning from storage {$environment}" ; } $ this -> printLn ( $ msg ) ; } $ this -> setEnvironments ( $ environmentsWhichExist ) ; return $ this ; } | This method iterates over the _environments . If there is no VagrantFile within that environment then it is removed from the list of _environments . |
25,544 | protected function migrateEnvironments ( $ oldStore ) { $ currentStore = $ this -> getFileName ( ) ; if ( false == file_exists ( $ oldStore ) ) { $ this -> printLn ( "Old store not found at {$oldStore}" , 'error' ) ; } else { $ this -> printLn ( "Old store found {$oldStore}" ) ; } $ this -> setFileName ( $ oldStore ) ; $ this -> loadEnvironments ( ) ; $ this -> printLn ( "Old environments loaded" ) ; $ oldEnvironments = $ this -> getEnvironments ( ) ; $ this -> setFileName ( $ currentStore ) ; $ this -> loadEnvironments ( ) ; foreach ( $ oldEnvironments as $ oldEnvironment ) { $ this -> createEnvironment ( $ oldEnvironment ) ; } $ this -> save ( ) ; $ this -> printLn ( "Old environments appended onto current store" ) ; $ this -> getEnvironments ( ) ; } | This method migrates an old store to a new store . It does however validate that the environment is valid before adding it to the store . |
25,545 | public function getLog ( ) { if ( null == $ this -> log ) { $ handler = new StreamHandler ( $ this -> _getLogFileName ( ) , Logger :: INFO ) ; $ this -> log = new Logger ( 'VagrantTransient' ) ; $ this -> log -> pushHandler ( $ handler ) ; } return $ this -> log ; } | This method returns a singleton instance of the logger class . |
25,546 | public function loadTableRegistryMap ( Event $ event ) { foreach ( Bundles :: getLoaded ( ) as $ bundleName ) { $ mapDir = Bundles :: getPath ( $ bundleName ) . DS . 'Domain' . DS . 'map' ; if ( is_file ( $ mapDir . DS . 'table_registry_config.php' ) ) { require_once $ mapDir . DS . 'table_registry_config.php' ; } } } | Load table registry map |
25,547 | public function setUploadpath ( $ dir_name ) { if ( $ dir_name === null ) $ this -> upload_path = Registry :: getConfig ( ) [ 'upload_path' ] ; else $ this -> upload_path = $ dir_name ; return $ this ; } | This method sets the upload file path |
25,548 | public function setTargetdir ( ) { $ this -> target_dir = Path :: base ( ) . $ this -> upload_path ; if ( ! file_exists ( $ this -> target_dir ) ) mkdir ( $ this -> target_dir ) ; return $ this ; } | This method sets the upload target directory |
25,549 | public function setTargetfilename ( ) { $ this -> target_file_name = sprintf ( '%s.%s' , sha1_file ( $ _FILES [ $ this -> file_name ] [ 'tmp_name' ] ) , $ this -> file_type ) ; return $ this ; } | This method sets a unique target file name |
25,550 | public function setTargetfile ( ) { $ this -> upload_path_relative = $ this -> upload_path . $ this -> target_file_name ; $ this -> target_file = $ this -> target_dir . $ this -> target_file_name ; return $ this ; } | This method sets the target file name |
25,551 | public function initialize ( $ url , $ user = null , $ password = null ) { $ count = substr_count ( $ url , '#' ) ; if ( $ count === 1 ) { $ revision = null ; list ( $ repoUrl , $ module ) = explode ( '#' , $ url ) ; } elseif ( $ count === 2 ) { list ( $ repoUrl , $ module , $ revision ) = explode ( '#' , $ url ) ; } else { throw new \ UnexpectedValueException ( "No valid VCS url $url" ) ; } $ process = new \ Arbit \ VCSWrapper \ CvsCli \ Process ( ) ; $ process -> argument ( '-d' ) -> argument ( $ repoUrl ) -> argument ( 'checkout' ) -> argument ( '-P' ) -> argument ( '-r' ) -> argument ( $ revision ) -> argument ( '-d' ) -> argument ( $ this -> root ) -> argument ( $ module ) -> execute ( ) ; } | Initializes fresh checkout |
25,552 | public function transformValues ( array $ values ) { if ( ! empty ( $ values [ 'gridguyz-multisite' ] [ 'defaultDomain' ] ) ) { $ values [ 'gridguyz-multisite' ] [ 'defaultDomain' ] = trim ( $ values [ 'gridguyz-multisite' ] [ 'defaultDomain' ] , '.' ) ; } if ( ! empty ( $ values [ 'gridguyz-multisite' ] [ 'domainPostfix' ] ) ) { $ values [ 'gridguyz-multisite' ] [ 'domainPostfix' ] = '.' . trim ( $ values [ 'gridguyz-multisite' ] [ 'domainPostfix' ] , '.' ) ; } return $ values ; } | Transform form values |
25,553 | public function addFilenameSuffix ( $ suffix ) { $ path = $ this -> fi -> getPath ( ) ; $ ext = $ this -> fi -> getExtension ( ) ; $ nameWithoutExtension = preg_replace ( '/\.' . $ ext . '$/' , '' , $ this -> fi -> getFilename ( ) ) ; $ this -> fi = new \ SplFileInfo ( sprintf ( '%s/%s%s.%s' , $ path , $ nameWithoutExtension , $ suffix , $ ext ) ) ; return $ this ; } | Adds a suffix the the filename . |
25,554 | public function bindParameters ( ContainerBuilder $ container , $ name , $ config ) { if ( is_array ( $ config ) && empty ( $ config [ 0 ] ) ) { foreach ( $ config as $ key => $ value ) { $ this -> bindParameters ( $ container , $ name . '.' . $ key , $ value ) ; } } else { $ container -> setParameter ( $ name , $ config ) ; } } | Binds the params from config |
25,555 | function has ( $ label ) { $ r = $ this -> getIterator ( ) -> find ( array ( 'label' => strtolower ( $ label ) ) ) ; foreach ( $ r as $ v ) return true ; return false ; } | Has Header With Specific Label? |
25,556 | function del ( $ label ) { if ( ! $ this -> has ( $ label ) ) return $ this ; $ headers = $ this -> getIterator ( ) -> find ( array ( 'label' => strtolower ( $ label ) ) ) ; foreach ( $ headers as $ hash => $ header ) $ this -> getIterator ( ) -> del ( $ hash ) ; return $ this ; } | Delete a Header With Label Name |
25,557 | private function render ( ) { $ parsed_data = Parser :: parse ( $ this -> input_path ) ; if ( $ parsed_data [ 'frontmatter' ] !== false && ! $ this -> should_ignore ( ) ) { return Template :: render ( $ parsed_data [ 'content' ] , $ parsed_data [ 'frontmatter' ] ) ; } return $ parsed_data [ 'content' ] ; } | run this file through our templating engine |
25,558 | public function output ( ) { $ parts = explode ( '/' , $ this -> output_path ) ; array_pop ( $ parts ) ; $ path = implode ( '/' , $ parts ) ; if ( $ path && ! file_exists ( $ path ) ) { if ( ! mkdir ( $ path , 0777 , true ) ) { throw new \ Exception ( "could not make directory $path" ) ; } } if ( ! file_put_contents ( $ this -> output_path , $ this -> render ( ) ) ) { throw new \ Exception ( "could not write $filename" ) ; } } | this file now has it s contents and it parsed we just need to put it where it needs to go |
25,559 | private function should_ignore ( ) { $ parts = explode ( '.' , $ this -> relative_path ) ; $ ext = strtolower ( end ( $ parts ) ) ; return in_array ( $ ext , $ this -> should_ignore_extensions ) ; } | and it should be run through our template renderer |
25,560 | public function createView ( $ object ) { foreach ( $ this -> factories as $ factory ) { $ view = $ factory -> createView ( $ object ) ; if ( null !== $ view ) { return $ view ; } } } | Create a view for the object delegating to inner factories |
25,561 | protected function getExpression ( $ property , $ argn = 0 ) { $ type = $ this -> entity -> getProperty ( $ property ) -> getType ( ) ; return isset ( $ type ) ? ( '%{' . "$argn:$type" . '}' ) : ( '%{' . $ argn . '}' ) ; } | Returns the argument expression for the given property |
25,562 | public function readDataForType ( $ filename , Prototype $ prototype , array & $ metadata = [ ] ) { if ( $ prototype -> typeDescription ( ) -> nativeType ( ) !== NativeType :: COLLECTION ) throw new \ InvalidArgumentException ( 'The CsvReader can only handle collections' ) ; $ itemPrototype = $ prototype -> typeProperties ( ) [ 'item' ] -> typePrototype ( ) ; $ propertyNames = array_keys ( $ itemPrototype -> typeProperties ( ) ) ; $ reader = Reader :: createFromPath ( $ filename ) ; if ( array_key_exists ( 'delimiter' , $ metadata ) ) $ reader -> setDelimiter ( $ metadata [ 'delimiter' ] ) ; if ( array_key_exists ( 'enclosure' , $ metadata ) ) $ reader -> setEnclosure ( $ metadata [ 'enclosure' ] ) ; if ( array_key_exists ( 'escape' , $ metadata ) ) $ reader -> setEscape ( $ metadata [ 'escape' ] ) ; if ( array_key_exists ( 'file_encoding' , $ metadata ) ) $ reader -> setEncodingFrom ( $ metadata [ 'file_encoding' ] ) ; $ firstRow = $ reader -> fetchOne ( ) ; $ offset_or_keys = 0 ; $ iteratorFilters = [ ] ; if ( $ this -> isValidKeysRow ( $ firstRow , $ propertyNames ) ) { $ iteratorFilters [ ] = function ( $ row , $ rowIndex ) { return $ rowIndex != 0 ; } ; } else { $ offset_or_keys = $ propertyNames ; } $ iteratorFilters [ ] = function ( $ row ) { if ( ! is_array ( $ row ) ) return false ; if ( empty ( $ row ) ) return false ; if ( count ( $ row ) === 1 ) { $ value = current ( $ row ) ; return ! empty ( $ value ) ; } return true ; } ; foreach ( $ iteratorFilters as $ iteratorFilter ) $ reader -> addFilter ( $ iteratorFilter ) ; $ metadata [ 'total_items' ] = $ reader -> each ( function ( ) { return true ; } ) ; if ( array_key_exists ( 'offset' , $ metadata ) ) $ reader -> setOffset ( $ metadata [ 'offset' ] ) ; if ( array_key_exists ( 'limit' , $ metadata ) ) $ reader -> setLimit ( $ metadata [ 'limit' ] ) ; foreach ( $ iteratorFilters as $ iteratorFilter ) $ reader -> addFilter ( $ iteratorFilter ) ; return array_map ( function ( $ row ) use ( $ itemPrototype ) { return $ this -> convertToItemData ( $ row , $ itemPrototype ) ; } , $ reader -> fetchAssoc ( $ offset_or_keys ) ) ; } | Use League \ Csv \ Reader to fetch data from csv file |
25,563 | public function handleError ( \ Jivoo \ Http \ ActionRequest $ request , \ Psr \ Http \ Message \ ResponseInterface $ response ) { if ( isset ( $ this -> errorHandler ) ) { return call_user_func ( $ this -> errorHandler , $ request , $ response ) ; } return $ response -> withBody ( new \ Jivoo \ Http \ Message \ StringStream ( 'Asset not found' ) ) -> withStatus ( \ Jivoo \ Http \ Message \ Status :: NOT_FOUND ) ; } | Create the error response . |
25,564 | public function addPath ( $ namespace , $ path , $ priority = 5 ) { if ( $ path != '' ) { $ path = rtrim ( $ path , '/' ) . '/' ; } $ namespace = '/' . trim ( $ namespace , '/' ) ; if ( ! isset ( $ this -> paths [ $ namespace ] ) ) { $ this -> paths [ $ namespace ] = [ ] ; } $ this -> paths [ $ namespace ] [ ] = [ 'path' => $ path , 'priority' => $ priority ] ; usort ( $ this -> paths [ $ namespace ] , [ 'Jivoo\Utilities' , 'prioritySorter' ] ) ; } | Add an asset path . |
25,565 | public function find ( $ asset ) { $ asset = trim ( $ asset , '/' ) ; $ namespace = '/' ; while ( true ) { $ file = $ this -> findIn ( $ asset , $ namespace ) ; if ( isset ( $ file ) ) { return $ file ; } $ pos = strpos ( $ asset , '/' ) ; if ( $ pos === false ) { break ; } $ namespace = rtrim ( $ namespace , '/' ) . '/' . substr ( $ asset , 0 , $ pos ) ; $ asset = substr ( $ asset , $ pos + 1 ) ; } return null ; } | Find an asset . |
25,566 | public function findIn ( $ asset , $ namespace ) { if ( ! isset ( $ this -> paths [ $ namespace ] ) ) { return null ; } foreach ( $ this -> paths [ $ namespace ] as $ path ) { $ file = $ path [ 'path' ] . $ asset ; if ( is_file ( $ file ) ) { return $ file ; } } return null ; } | Find an asset in a namsepace . |
25,567 | private static function buildDependencies ( $ obj ) : void { $ name = get_class ( $ obj ) ; if ( ! array_key_exists ( $ name , self :: $ method_map ) ) { try { $ class = new ReflectionClass ( $ obj ) ; } catch ( ReflectionException $ e ) { throw new RuntimeException ( "This shouldn't be possible" , 0 , $ e ) ; } $ methods = $ class -> getMethods ( ReflectionMethod :: IS_PROTECTED ) ; $ properties = self :: filterProperties ( $ methods ) ; $ inflector = Inflector :: get ( ) ; $ method_map = self :: remapProperties ( [ $ inflector , 'underscore' ] , $ properties ) ; self :: $ method_map [ $ name ] = self :: extractProperties ( $ method_map ) ; } } | Builds and caches the properties for a given object if not already cached |
25,568 | private static function filterProperties ( array $ methods ) : array { return array_filter ( $ methods , function ( ReflectionMethod $ method ) { return ( strlen ( $ method -> name ) > 3 ) && ( ( strpos ( $ method -> name , 'get' ) === 0 ) || ( strpos ( $ method -> name , 'set' ) === 0 ) || ( strpos ( $ method -> name , 'itr' ) === 0 ) ) ; } ) ; } | Filters out all methods that don t match the property signatures |
25,569 | private static function remapProperties ( callable $ inflector , array $ properties ) : array { $ mapped = [ ] ; foreach ( $ properties as $ property ) { $ prop_name = $ inflector ( substr ( $ property -> name , 3 ) ) ; if ( ! isset ( $ mapped [ $ prop_name ] ) ) { $ mapped [ $ prop_name ] = [ 'get' => null , 'set' => null , 'itr' => null ] ; } $ mapped [ $ prop_name ] [ substr ( $ property -> name , 0 , 3 ) ] = $ property ; } return $ mapped ; } | Transforms property names and pairs them up where applicable |
25,570 | private function _propifier_getMethod ( string $ name , string $ prefix ) { if ( $ this -> _propifier_hasMethod ( $ name , $ prefix ) ) { return self :: $ method_map [ get_class ( $ this ) ] [ $ name ] [ $ prefix ] ; } throw new NoSuchPropertyException ( $ name ) ; } | Gets the accessor or mutator for a given property . This method will build the cache if necessary . |
25,571 | private function _propifier_hasMethod ( string $ name , string $ prefix ) : bool { self :: buildDependencies ( $ this ) ; return isset ( self :: $ method_map [ get_class ( $ this ) ] [ $ name ] [ $ prefix ] ) ; } | Checks if a given property exists . This method will build the cache if necessary . |
25,572 | protected function createAttachmentSchema ( array $ config ) { $ storage = $ this -> getStorage ( $ config [ 'storage' ] ) ; return new AttachmentSchema ( $ storage , $ config [ 'hash_callable' ] , $ config [ 'storage_depth' ] ) ; } | Create AttachmentSchema object holding information about how to handle specific model classes and field names . |
25,573 | public function storeAndAttachFile ( File $ file , AttachableObjectInterface $ object , $ fieldName = null , $ deleteAfterCopy = null , $ customFilename = null ) { $ this -> checkAttachableObject ( $ object ) ; if ( null === $ deleteAfterCopy ) { $ deleteAfterCopy = $ this -> guessDeleteAfterCopy ( $ file , $ object , $ fieldName ) ; } $ this -> checkFile ( $ file , $ deleteAfterCopy ) ; $ fileKey = $ this -> generateKey ( $ file , $ object , $ fieldName ) ; $ this -> copyToStorage ( $ file , $ fileKey ) ; $ attachment = $ this -> saveToDatabase ( $ file , $ object , $ fieldName , $ fileKey , $ customFilename ) ; if ( $ deleteAfterCopy ) { unlink ( $ file -> getRealPath ( ) ) ; } return $ attachment ; } | Store a new attachment file for the given object and optional object field name . There is no need for the field name to exist explicitly inside the object . |
25,574 | protected function checkFile ( File $ file , $ deleteAfterCopy ) { if ( ! $ file -> isReadable ( ) ) { throw new InputFileNotReadableException ( 'File ' . $ file -> getRealPath ( ) . ' is not readable' ) ; } if ( $ deleteAfterCopy && ! $ file -> isWritable ( ) ) { throw new InputFileNotWritableException ( 'File ' . $ file -> getRealPath ( ) . ' is not writable' ) ; } return true ; } | Perform some checks to see if the given file is valid and ready to use . |
25,575 | protected function generateKey ( File $ file , AttachableObjectInterface $ object , $ fieldName ) { $ schema = $ this -> getSchemaForObject ( $ object , $ fieldName ) ; if ( $ file instanceof UploadedFile ) { $ extension = $ file -> getClientOriginalExtension ( ) ; } else { $ extension = $ file -> getExtension ( ) ; } $ hash = $ this -> generateFileHash ( $ file , $ schema ) ; $ fileKey = new $ this -> fileKeyClass ( ) ; $ fileKey -> setHash ( $ hash ) -> setExtension ( $ extension ) -> setDepth ( $ schema -> getStorageDepth ( ) ) -> setClassName ( $ object -> getAttachableClassName ( ) ) -> setFieldName ( $ fieldName ) -> setStorageName ( $ schema -> getStorage ( ) -> getName ( ) ) ; $ fileKey -> getKey ( ) ; return $ fileKey ; } | Generate the file key for the given file path and config . |
25,576 | protected function generateFileHash ( File $ file , AttachmentSchema $ schema ) { return call_user_func ( $ schema -> getHashCallable ( ) , $ file -> getRealPath ( ) ) ; } | This generates the actual file hash by calling the hash callable passing the file path . |
25,577 | protected function getStorage ( $ name ) { if ( ! array_key_exists ( $ name , $ this -> storages ) ) { throw new StorageDoesNotExistException ( 'Invalid storage name: ' . $ name ) ; } return $ this -> storages [ $ name ] ; } | Get the storage with the given name |
25,578 | protected function copyToStorage ( File $ file , FileKey $ fileKey ) { $ storage = $ this -> getStorage ( $ fileKey -> getStorageName ( ) ) ; $ storagePath = $ this -> getStoragePath ( $ storage , $ fileKey ) ; $ filesystem = $ storage -> getFilesystem ( ) ; if ( ! $ filesystem -> has ( $ storagePath ) ) { $ size = $ file -> getSize ( ) ; $ writtenSize = $ filesystem -> write ( $ storagePath , file_get_contents ( $ file -> getRealPath ( ) ) ) ; if ( $ writtenSize != $ size ) { throw new CouldNotWriteToStorageException ( 'Error copying file ' . $ file -> getRealPath ( ) . ' to storage' ) ; } } } | Move the file to the storage as defined in the given file key . |
25,579 | protected function getStoragePath ( Storage $ storage , FileKey $ fileKey ) { return ltrim ( $ storage -> getPathPrefix ( ) . '/' . $ fileKey -> getFilePath ( ) , '/' ) ; } | Get the path inside the storage for the given Storage and FileKey . |
25,580 | protected function saveToDatabase ( File $ file , AttachableObjectInterface $ object , $ fieldName , FileKey $ fileKey , $ customFilename = null ) { $ attachment = $ this -> getOrCreateAttachment ( $ file , $ object , $ fieldName , $ fileKey ) ; $ link = $ this -> createAttachmentLink ( $ file , $ object , $ fieldName , $ attachment , $ customFilename ) ; if ( in_array ( $ fieldName , $ object -> getAttachableFieldNames ( ) ) ) { $ method = 'set' . $ fieldName . 'Attachment' ; if ( ! method_exists ( $ object , $ method ) ) { throw new InvalidAttachableFieldNameException ( 'Fieldname setter for ' . $ fieldName . ' does not exist in ' . get_class ( $ object ) ) ; } $ object -> $ method ( $ attachment ) ; $ link -> setIsCurrent ( true ) ; AttachmentLinkQuery :: create ( ) -> filterByAttachableObject ( $ object ) -> filterByModelField ( $ fieldName ) -> doUpdate ( array ( 'IsCurrent' => false ) , \ Propel :: getConnection ( ) ) ; } $ link -> save ( ) ; return $ attachment ; } | Perform filling and saving of attachment database object |
25,581 | protected function getOrCreateAttachment ( File $ file , AttachableObjectInterface $ object , $ fieldName , FileKey $ fileKey ) { $ attachment = $ this -> getAttachment ( $ fileKey -> getKey ( ) ) ; if ( null === $ attachment ) { $ schema = $ this -> getSchemaForObject ( $ object , $ fieldName ) ; $ attachment = new Attachment ( ) ; $ attachment -> setFileKey ( $ fileKey -> getKey ( ) ) -> setFileSize ( $ file -> getSize ( ) ) -> setFileType ( $ file -> getMimeType ( ) ) -> setStorageName ( $ schema -> getStorage ( ) -> getName ( ) ) -> setStorageDepth ( $ schema -> getStorageDepth ( ) ) -> setHashType ( $ schema -> getHashCallableAsString ( ) ) ; } return $ attachment ; } | Get a new Attachment object or an existing one if a file with the same key was already stored . |
25,582 | protected function createAttachmentLink ( File $ file , AttachableObjectInterface $ object , $ fieldName , Attachment $ attachment , $ customFilename = null ) { if ( $ file instanceof UploadedFile ) { $ extension = $ file -> getClientOriginalExtension ( ) ; $ filename = $ file -> getClientOriginalName ( ) ; $ basename = basename ( $ filename , '.' . $ extension ) ; } else { $ extension = $ file -> getExtension ( ) ; $ filename = $ file -> getFilename ( ) ; $ basename = $ file -> getBasename ( '.' . $ extension ) ; } if ( null !== $ customFilename ) { $ filename = $ customFilename ; $ basename = basename ( $ filename , '.' . $ extension ) ; } $ link = new AttachmentLink ( ) ; $ link -> setAttachment ( $ attachment ) -> setModelName ( $ object -> getAttachableClassName ( ) ) -> setModelId ( $ object -> getAttachableId ( ) ) -> setModelField ( $ fieldName ) -> setFileName ( $ filename ) -> setFileExtension ( $ extension ) -> setCustomName ( $ basename ) ; return $ link ; } | Create new AttachmentLink object for the given parameters . |
25,583 | protected function getFileKey ( $ key ) { $ key = ( string ) $ key ; if ( ! array_key_exists ( $ key , $ this -> fileKeys ) ) { $ this -> fileKeys [ $ key ] = new FileKey ( $ key ) ; } return $ this -> fileKeys [ $ key ] ; } | Convert an existing string key to a FileKey object for further usage . |
25,584 | protected function removeFile ( $ key ) { $ fileKey = $ this -> getFileKey ( $ key ) ; $ storage = $ this -> getStorage ( $ fileKey -> getStorageName ( ) ) ; return $ storage -> getFilesystem ( ) -> delete ( $ this -> getStoragePath ( $ storage , $ fileKey ) ) ; } | Remove the given file from the storage . |
25,585 | public function getFileUrl ( $ key ) { $ fileKey = $ this -> getFileKey ( $ key ) ; $ storage = $ this -> getStorage ( $ fileKey -> getStorageName ( ) ) ; if ( ! $ storage -> hasBaseUrl ( ) ) { throw new MissingStorageConfigException ( 'This storage does not have a configured base url!' ) ; } return $ storage -> getBaseUrl ( ) . '/' . $ this -> getStoragePath ( $ storage , $ fileKey ) ; } | Get the URL for the given file key . |
25,586 | public function fileExists ( $ key ) { $ fileKey = $ this -> getFileKey ( $ key ) ; $ storage = $ this -> getStorage ( $ fileKey -> getStorageName ( ) ) ; return $ storage -> getFilesystem ( ) -> has ( $ this -> getStoragePath ( $ storage , $ fileKey ) ) ; } | Check if the given file exists inside its storage . Actually you should never have to do this unless you are manipulating the storage by hand . |
25,587 | public function translate ( $ key , $ translation , $ locale = null , $ driver = null ) { $ driver = ! is_null ( $ driver ) ? $ this -> getDriver ( $ driver ) : $ this -> driver ( ) ; return $ driver -> translate ( $ key , $ translation , $ locale ) ; } | Translate a key . |
25,588 | protected function _finish ( ) { $ layoutPath = ! is_null ( $ this -> request -> route -> module ) ? $ this -> request -> route -> module -> path . '/Layouts' : LAYOUT_PATH ; if ( ! isset ( $ this -> _layout ) ) { if ( ! is_null ( static :: $ layout ) ) { $ this -> _layout = $ layoutPath . '/' . static :: $ layout ; } elseif ( ! is_null ( $ this -> request -> route -> module ) && ! is_null ( $ this -> request -> route -> module -> defaultLayout ) ) { $ this -> _layout = $ layoutPath . '/' . $ this -> request -> route -> module -> defaultLayout ; } else { $ this -> _layout = LAYOUT_PATH . '/' . Application :: getConfiguration ( ) -> defaultLayout ; } } if ( $ this -> _layout === false ) { if ( array_key_exists ( 'main' , $ this -> _renderedContent ) ) { echo $ this -> _renderedContent [ 'main' ] ; } } else { $ layoutFile = $ this -> _guessExtension ( $ this -> _layout ) ; if ( $ layoutFile === false ) { throw new \ Exception ( "Couldn't find layout for " . $ this -> _layout , 1 ) ; } $ this -> _layout = $ layoutFile ; $ layout = new Layout ( $ this -> _layout , $ this , $ this -> _renderedContent ) ; } } | When the action has completed the finish method will tie up loose ends |
25,589 | private function _guessExtension ( $ filename , $ suffix = '.php' ) { $ possibleExtensions = array ( ) ; $ allAccepted = false ; if ( ! is_null ( $ this -> contentType ) ) { $ possibleExtensions = $ this -> contentType -> getExtensions ( ) ; } else { foreach ( $ this -> request -> preferredContent as $ type ) { $ possibleExtensions = array_merge ( $ possibleExtensions , $ type -> getExtensions ( ) ) ; if ( $ type -> type == Mime :: ALL ) { $ allAccepted = true ; } } } foreach ( $ possibleExtensions as $ ext ) { $ tryFilename = $ filename . ".$ext$suffix" ; if ( file_exists ( $ tryFilename ) ) { return $ tryFilename ; } } if ( $ allAccepted ) { $ dir = dirname ( $ filename ) ; if ( ! file_exists ( $ dir ) || ! is_dir ( $ dir ) ) { return false ; } $ searchFor = substr ( $ filename , strlen ( $ dir ) + 1 ) ; $ dh = opendir ( $ dir ) ; while ( false !== ( $ file = readdir ( $ dh ) ) ) { if ( Str :: getContentExtension ( $ file ) ) if ( is_file ( $ dir . '/' . $ file ) && preg_match ( '/^' . preg_quote ( $ searchFor ) . '\.([a-z]+)' . preg_quote ( $ suffix ) . '$/' , $ file ) && Mime :: byExtension ( Str :: getContentExtension ( $ file ) ) !== false ) { return $ dir . '/' . $ file ; } } } return false ; } | Guess a file extension for the given extensionless filename based on the request headers or chosen content type . |
25,590 | private function _interpretOptionsWithinView ( & $ options ) { if ( is_null ( $ options ) ) { throw new \ Exception ( "Cannot execute an empty render inside a view." , 1 ) ; } if ( is_string ( $ options ) ) { $ options = array ( "partial" => $ options ) ; } if ( ! is_array ( $ options ) ) { $ options = array ( $ options ) ; } if ( count ( $ options ) == 0 ) { $ options = array ( "nothing" => true ) ; return ; } $ viewPath = ! is_null ( $ this -> request -> route -> module ) ? $ this -> request -> route -> module -> path . "/Views/" : VIEW_PATH . "/" ; if ( isset ( $ options [ 0 ] ) && is_object ( $ options [ 0 ] ) && is_subclass_of ( $ options [ 0 ] , "\\ChickenWire\\Model" ) ) { $ modelClass = $ options [ 0 ] -> getClass ( ) ; $ options = array ( "partial" => strtolower ( $ modelClass ) , "collection" => $ options ) ; } if ( array_key_exists ( "partial" , $ options ) ) { if ( array_key_exists ( "object" , $ options ) ) { $ options [ 'collection' ] = array ( $ options [ 'object' ] ) ; unset ( $ options [ 'object' ] ) ; } if ( array_key_exists ( "collection" , $ options ) && ! array_key_exists ( "as" , $ options ) ) { $ modelClass = $ options [ 'collection' ] [ 0 ] -> getClass ( ) ; $ options [ 'as' ] = strtolower ( $ modelClass ) ; } if ( strstr ( $ options [ 'partial' ] , '/' ) ) { } else { if ( is_null ( $ this -> request -> route -> models ) ) { throw new \ Exception ( "This route does not have a model linked to it, so you have to define a template, instead of an action." , 1 ) ; } $ model = $ this -> request -> route -> models [ count ( $ this -> request -> route -> models ) - 1 ] ; $ model = Str :: removeNamespace ( $ model ) ; $ options [ 'partial' ] = Str :: pluralize ( $ model ) . "/" . $ options [ 'partial' ] ; } if ( ! preg_match ( '/\/_[a-z]+$/' , $ options [ 'partial' ] ) ) { $ options [ 'partial' ] = substr ( $ options [ 'partial' ] , 0 , strrpos ( $ options [ 'partial' ] , "/" ) ) . '/_' . substr ( $ options [ 'partial' ] , strrpos ( $ options [ 'partial' ] , "/" ) + 1 ) ; } $ options [ 'partial' ] = $ viewPath . $ options [ 'partial' ] ; } } | Interpret the options given to a render call inside a view . |
25,591 | private function _checkAuth ( ) { if ( ! isset ( static :: $ requiresAuth ) || is_null ( static :: $ requiresAuth ) || empty ( static :: $ requiresAuth ) ) { return true ; } $ auth = static :: $ requiresAuth ; if ( is_array ( $ auth ) && array_key_exists ( "except" , $ auth ) ) { if ( in_array ( $ this -> route -> action , $ auth [ 'except' ] ) ) { return true ; } } if ( is_array ( $ auth ) && array_key_exists ( "only" , $ auth ) ) { if ( ! is_array ( $ auth [ 'only' ] ) ) { $ auth [ 'only' ] = array ( $ auth [ 'only' ] ) ; } if ( ! in_array ( $ this -> route -> action , $ auth [ 'only' ] ) ) { return true ; } } $ authName = is_array ( $ auth ) ? $ auth [ 0 ] : $ auth ; $ this -> auth = Auth :: get ( $ authName ) ; if ( $ this -> auth -> isAuthenticated ( ) !== true ) { $ this -> auth -> rememberPage ( $ this -> request -> uri ) ; if ( ! is_null ( $ this -> auth -> loginAction ) ) { $ this -> _invokeAuthLoginAction ( ) ; } else { $ this -> redirect ( $ this -> auth -> loginUri ) ; } return false ; } else { return true ; } } | Check if current action needs authentication and if it is validated |
25,592 | private function _invokeAuthLoginAction ( ) { $ login = new $ this -> auth -> loginController ( $ this -> request , false ) ; if ( method_exists ( $ login , $ this -> auth -> loginAction ) ) { $ reflection = new \ ReflectionMethod ( $ login , $ this -> auth -> loginAction ) ; if ( ! $ reflection -> isPublic ( ) ) { throw new \ Exception ( "The method '" . $ this -> auth -> loginAction . "' on " . get_class ( $ login ) . " is not public." , 1 ) ; } Http :: sendStatus ( 401 ) ; $ reflection -> invoke ( $ login ) ; } else { throw new \ Exception ( "There is no method '" . $ this -> auth -> loginAction . "' on " . get_class ( $ login ) , 1 ) ; } } | Invoke the Login action for the Controller s Auth object |
25,593 | protected function show404 ( ) { Http :: sendStatus ( 404 ) ; if ( class_exists ( "\\Application\\Controllers\\ErrorController" ) ) { $ controller = new \ Application \ Controllers \ ErrorController ( $ this -> request , false ) ; $ controller -> show ( 404 ) ; } else { echo ( "404 Page not found" ) ; } die ; } | Send a 404 error to the client |
25,594 | public function save ( ) { if ( $ this instanceof Immutable ) { throw new Exception \ Immutable ( $ this ) ; } $ errors = [ ] ; if ( method_exists ( $ this , 'notify' ) ) { $ notify = clone $ this ; } foreach ( $ this -> __adapters as $ model ) { if ( $ model -> isDirty ( ) ) { if ( $ model -> isNew ( ) && $ this instanceof Uncreateable ) { throw new Exception \ Uncreateable ( $ this ) ; } if ( ! $ model -> save ( ) ) { $ errors [ ] = true ; } } } $ annotations = $ this -> annotations ( ) [ 'properties' ] ; foreach ( $ annotations as $ prop => $ anns ) { if ( isset ( $ anns [ 'Private' ] ) || $ prop { 0 } == '_' ) { continue ; } $ value = $ this -> $ prop ; if ( is_object ( $ value ) ) { if ( $ value instanceof Collection && $ value -> isDirty ( ) ) { if ( $ error = $ value -> save ( ) ) { $ errors = array_merge ( $ errors , $ error ) ; } } elseif ( $ save = Helper :: modelSaveMethod ( $ value ) and ! method_exists ( $ value , 'isDirty' ) || $ value -> isDirty ( ) ) { if ( ! $ value -> $ save ( ) ) { $ errors [ ] = true ; } } } } if ( isset ( $ notify ) ) { $ notify -> notify ( ) ; } $ this -> markClean ( ) ; return $ errors ? $ errors : null ; } | Persists the model back to storage based on the specified adapters . If an adapter supports transactions you are encouraged to use them ; but you should do so in your own code . |
25,595 | public function delete ( ) { if ( method_exists ( $ this , 'notify' ) ) { $ notify = clone $ this ; } if ( $ this instanceof Undeleteable ) { throw new Exception \ Undeleteable ( $ this ) ; } $ errors = [ ] ; foreach ( $ this -> __adapters as $ adapter ) { if ( $ error = $ adapter -> delete ( $ this ) ) { $ errors [ ] = $ error ; } else { $ adapter -> markDeleted ( ) ; } } if ( isset ( $ notify ) ) { $ notify -> notify ( ) ; } $ this -> __state = 'deleted' ; return $ errors ? $ errors : null ; } | Deletes the current model from storage based on the specified adapters . If an adapter supports transactions you are encouraged to use them ; but you should do so in your own code . |
25,596 | public function markClean ( ) { foreach ( $ this -> __adapters as $ model ) { $ model -> markClean ( ) ; } $ annotations = $ this -> annotations ( ) [ 'properties' ] ; foreach ( $ annotations as $ prop => $ anns ) { if ( isset ( $ anns [ 'Private' ] ) || $ prop { 0 } == '_' ) { continue ; } $ value = $ this -> $ prop ; if ( is_object ( $ value ) and method_exists ( $ value , 'markClean' ) ) { $ value -> markClean ( ) ; } } $ this -> __state = 'clean' ; } | Mark the current model as clean i . e . not dirty . Useful if you manually set values after loading from storage that shouldn t count towards dirtiness . Called automatically after saving . |
25,597 | public function getUtils ( ) : Utils { if ( $ this -> _utils === null ) { $ this -> _utils = new Utils ( $ this -> getSystemService ( ) ) ; } return $ this -> _utils ; } | Returns the value of field _utils . |
25,598 | public function write ( array $ data , array $ options ) { if ( ! $ this -> getUtils ( ) -> isDotInstalled ( ) ) { throw ExportException :: create ( 'Can\'t export to a Graphviz image because "dot" binary is not available. Verify that the ' . '"graphviz" package is installed on your system.' ) ; } if ( ! isset ( $ data [ 'node' ] ) || ! ( $ data [ 'node' ] instanceof NodeInterface ) ) { throw ValidationException :: create ( 'Data attribute "node" must be an instance of IronEdge\Component\Graphs\Node\NodeInterface.' ) ; } if ( ! isset ( $ options [ 'path' ] ) || ! is_string ( $ options [ 'path' ] ) || $ options [ 'path' ] === '' ) { throw ValidationException :: create ( 'To be able to export this graph to a graphviz image, you must set option "path" with a string ' . 'with the path to the target file.' ) ; } $ graph = $ data [ 'node' ] ; $ file = $ options [ 'path' ] ; $ graphvizCode = 'digraph ' . $ graph -> getId ( ) . ' {' . PHP_EOL ; $ graphAttributes = $ graph -> getMetadataAttr ( 'graphviz.nodeAttributes' , [ ] ) ; if ( $ graphAttributes ) { foreach ( $ graphAttributes as $ k => $ v ) { $ graphvizCode .= ' ' . $ k . '=' . $ v . ';' . PHP_EOL ; } $ graphvizCode .= PHP_EOL ; } $ graphvizCode .= $ this -> generateNodeCode ( $ graph ) ; $ graphvizCode .= '}' ; $ this -> generateGraphvizOutputFile ( $ graphvizCode , $ file , [ 'targetType' => 'png' ] ) ; } | Writes the data into a graphviz image . |
25,599 | protected function generateGraphvizOutputFile ( string $ graphvizCode , string $ targetFile , array $ graphvizOptions = [ ] ) : GraphvizWriter { $ graphvizOptions = array_replace_recursive ( [ 'targetType' => 'png' ] , $ graphvizOptions ) ; $ tmpFile = $ targetFile . '.tmp' ; $ this -> removeFile ( $ targetFile ) -> removeFile ( $ tmpFile ) ; $ this -> writeFile ( $ graphvizCode , $ tmpFile ) ; exec ( 'dot -T' . $ graphvizOptions [ 'targetType' ] . ' ' . $ tmpFile . ' -o ' . $ targetFile , $ output , $ status ) ; if ( $ status ) { throw ExportException :: create ( 'Couldn\'t generate Graphviz image. Exit Code: ' . $ status . ' - Output: ' . print_r ( $ output , true ) ) ; } $ this -> removeFile ( $ tmpFile ) ; return $ this ; } | Exports a graphviz code to a file . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.