idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
200
|
public function addInline ( $ content , $ type , $ group = 'head' , $ slot = 'inline' ) { if ( ! isset ( $ this -> assets [ $ group ] ) ) $ this -> assets [ $ group ] = array ( ) ; if ( ! isset ( $ this -> assets [ $ group ] [ $ type ] ) ) $ this -> assets [ $ group ] [ $ type ] = array ( ) ; $ this -> assets [ $ group ] [ $ type ] [ 3 ] [ ] = array ( 'data' => $ content , 'type' => $ type , 'origin' => 'inline' , 'slot' => $ slot , ) ; }
|
add inline script or styles
|
201
|
public function addNode ( $ node ) { $ src = false ; if ( array_key_exists ( 'src' , $ node ) ) $ src = $ node [ 'src' ] ; elseif ( array_key_exists ( 'href' , $ node ) ) $ src = $ node [ 'href' ] ; if ( $ src ) { if ( ! isset ( $ node [ 'type' ] ) ) { if ( preg_match ( '/.*\.(css|js)(?=[?#].*|$)/i' , $ src , $ match ) ) $ node [ 'type' ] = $ match [ 1 ] ; elseif ( array_key_exists ( 'src' , $ node ) ) $ node [ 'type' ] = 'js' ; elseif ( array_key_exists ( 'href' , $ node ) ) $ node [ 'type' ] = 'css' ; elseif ( empty ( $ type ) ) return "" ; } $ type = $ node [ 'type' ] ; if ( ! isset ( $ node [ 'group' ] ) ) $ node [ 'group' ] = ( $ node [ 'type' ] == 'js' ) ? 'footer' : 'head' ; if ( ! isset ( $ node [ 'priority' ] ) ) $ node [ 'priority' ] = 5 ; if ( ! isset ( $ node [ 'slot' ] ) ) $ node [ 'slot' ] = null ; $ group = $ node [ 'group' ] ; $ prio = $ node [ 'priority' ] ; $ slot = $ node [ 'slot' ] ; unset ( $ node [ 'priority' ] , $ node [ 'src' ] , $ node [ 'href' ] , $ node [ 'group' ] , $ node [ 'type' ] , $ node [ 'slot' ] ) ; $ this -> add ( $ src , $ type , $ group , $ prio , $ slot , $ node ) ; } }
|
push new asset during template execution
|
202
|
function parseNode ( $ node ) { $ src = false ; $ params = array ( ) ; if ( isset ( $ node [ '@attrib' ] ) ) { $ params = $ node [ '@attrib' ] ; unset ( $ node [ '@attrib' ] ) ; } if ( array_key_exists ( 'src' , $ params ) ) $ src = $ params [ 'src' ] ; elseif ( array_key_exists ( 'href' , $ params ) ) $ src = $ params [ 'href' ] ; if ( $ src ) { $ out = '<?php \Assets::instance()->addNode(array(' ; foreach ( $ params as $ key => $ val ) $ out .= var_export ( $ key , true ) . '=>' . ( preg_match ( '/{{(.+?)}}/s' , $ val ) ? $ this -> template -> token ( $ val ) : var_export ( $ val , true ) ) . ',' ; $ out .= ')); ?>' ; return $ out ; } if ( isset ( $ node [ 0 ] ) && isset ( $ params [ 'type' ] ) ) { if ( ! isset ( $ params [ 'group' ] ) ) $ params [ 'group' ] = ( $ params [ 'type' ] == 'js' ) ? 'footer' : 'head' ; if ( ! isset ( $ params [ 'slot' ] ) ) $ params [ 'slot' ] = 'inline' ; if ( $ this -> f3 -> get ( 'ASSETS.handle_inline' ) ) return '<?php \Assets::instance()->addInline(' . '$this->resolve(' . ( var_export ( $ node , true ) ) . ',get_defined_vars(),0,false,false),' . var_export ( $ params [ 'type' ] , true ) . ',' . var_export ( $ params [ 'group' ] , true ) . ',' . var_export ( $ params [ 'slot' ] , true ) . '); ?>' ; else return $ this -> f3 -> call ( $ this -> formatter [ $ params [ 'type' ] ] , array ( array ( 'data' => $ this -> template -> build ( $ node ) , 'origin' => 'inline' ) ) ) ; } }
|
parse node data on template compiling
|
203
|
function resolveAttr ( array $ attr ) { $ out = '' ; foreach ( $ attr as $ key => $ value ) { if ( preg_match ( '/{{(.+?)}}/s' , $ value ) ) $ value = $ this -> template -> build ( $ value ) ; if ( preg_match ( '/{{(.+?)}}/s' , $ key ) ) $ key = $ this -> template -> build ( $ key ) ; if ( is_numeric ( $ key ) ) $ out .= ' ' . $ value ; elseif ( $ value == NULL ) $ out .= ' ' . $ key ; else $ out .= ' ' . $ key . '="' . $ value . '"' ; } return $ out ; }
|
general bypass for unhandled tag attributes
|
204
|
public function actionCreate ( ) { $ stdout = '' ; foreach ( $ this -> db -> schema -> getTableSchemas ( ) as $ table ) { if ( $ table -> name === $ this -> migrationTable ) { continue ; } $ stdout .= static :: generateCreateTable ( $ table -> name ) . static :: generateColumns ( $ table -> columns , $ this -> db -> schema -> findUniqueIndexes ( $ table ) ) . static :: generatePrimaryKey ( $ table -> primaryKey , $ table -> columns ) . static :: generateTableOptions ( ) ; } foreach ( $ this -> db -> schema -> getTableSchemas ( ) as $ table ) { $ stdout .= $ this -> generateForeignKey ( $ table ) ; } $ this -> stdout ( $ stdout ) ; }
|
Generates the createTable code .
|
205
|
public function actionDrop ( ) { $ stdout = '' ; foreach ( $ this -> db -> schema -> getTableSchemas ( ) as $ table ) { if ( $ table -> name === $ this -> migrationTable ) { continue ; } $ stdout .= static :: generateDropTable ( $ table -> name ) ; if ( ! empty ( $ table -> foreignKeys ) ) { $ stdout .= ' // fk: ' ; foreach ( $ table -> foreignKeys as $ fk ) { foreach ( $ fk as $ k => $ v ) { if ( 0 === $ k ) { continue ; } $ stdout .= "$k, " ; } } $ stdout = rtrim ( $ stdout , ', ' ) ; } $ stdout .= "\n" ; } $ this -> stdout ( $ stdout ) ; }
|
Generates the dropTable code .
|
206
|
private static function generateColumns ( array $ columns , array $ unique ) { $ definition = '' ; foreach ( $ columns as $ column ) { $ tmp = sprintf ( " '%s' => \$this->%s%s,\n" , $ column -> name , static :: getSchemaType ( $ column ) , static :: other ( $ column , $ unique ) ) ; if ( null !== $ column -> enumValues ) { $ tmp = static :: replaceEnumColumn ( $ tmp ) ; } $ definition .= $ tmp ; } return $ definition ; }
|
Returns the columns definition .
|
207
|
private static function generatePrimaryKey ( array $ pk , array $ columns ) { if ( empty ( $ pk ) ) { return '' ; } if ( 2 <= count ( $ pk ) ) { $ compositePk = implode ( ', ' , $ pk ) ; return " 'PRIMARY KEY ($compositePk)',\n" ; } $ flag = false ; foreach ( $ columns as $ column ) { if ( $ column -> autoIncrement ) { $ flag = true ; } } if ( false === $ flag ) { return sprintf ( " 'PRIMARY KEY (%s)',\n" , $ pk [ 0 ] ) ; } return '' ; }
|
Returns the primary key definition .
|
208
|
private function generateForeignKey ( $ table ) { if ( empty ( $ table -> foreignKeys ) ) { return ; } $ definition = "// fk: $table->name\n" ; foreach ( $ table -> foreignKeys as $ fk ) { $ refTable = '' ; $ refColumns = '' ; $ columns = '' ; foreach ( $ fk as $ k => $ v ) { if ( 0 === $ k ) { $ refTable = $ v ; } else { $ columns = $ k ; $ refColumns = $ v ; } } $ definition .= sprintf ( "\$this->addForeignKey('%s', '{{%%%s}}', '%s', '{{%%%s}}', '%s');\n" , 'fk_' . $ table -> name . '_' . $ columns , $ table -> name , $ columns , $ refTable , $ refColumns ) ; } return "$definition\n" ; }
|
Returns the foreign key definition .
|
209
|
private static function getSchemaType ( $ column ) { if ( $ column -> isPrimaryKey && $ column -> autoIncrement ) { if ( 'bigint' === $ column -> type ) { return 'bigPrimaryKey()' ; } return 'primaryKey()' ; } if ( 'tinyint(1)' === $ column -> dbType ) { return 'boolean()' ; } if ( 'smallint' === $ column -> type ) { if ( null === $ column -> size ) { return 'smallInteger()' ; } return 'smallInteger' ; } if ( 'bigint' === $ column -> type ) { if ( null === $ column -> size ) { return 'bigInteger()' ; } return 'bigInteger' ; } if ( null !== $ column -> enumValues ) { $ enumValues = array_map ( 'addslashes' , $ column -> enumValues ) ; return "enum(['" . implode ( '\', \'' , $ enumValues ) . "'])" ; } if ( null === $ column -> size && 0 >= $ column -> scale ) { return $ column -> type . '()' ; } return $ column -> type ; }
|
Returns the schema type .
|
210
|
private static function other ( $ column , array $ unique ) { $ definition = '' ; if ( null !== $ column -> scale && 0 < $ column -> scale ) { $ definition .= "($column->precision,$column->scale)" ; } elseif ( null !== $ column -> size && ! $ column -> autoIncrement && 'tinyint(1)' !== $ column -> dbType ) { $ definition .= "($column->size)" ; } elseif ( null !== $ column -> size && ! $ column -> isPrimaryKey && $ column -> unsigned ) { $ definition .= "($column->size)" ; } if ( $ column -> unsigned ) { $ definition .= '->unsigned()' ; } if ( $ column -> allowNull ) { $ definition .= '->null()' ; } elseif ( ! $ column -> autoIncrement ) { $ definition .= '->notNull()' ; } if ( ! $ column -> isPrimaryKey && ! empty ( $ unique ) ) { foreach ( $ unique as $ name ) { if ( reset ( $ name ) === $ column -> name ) { $ definition .= '->unique()' ; } } } if ( $ column -> defaultValue instanceof Expression ) { $ definition .= "->defaultExpression('$column->defaultValue')" ; } elseif ( is_int ( $ column -> defaultValue ) ) { $ definition .= "->defaultValue($column->defaultValue)" ; } elseif ( is_bool ( $ column -> defaultValue ) ) { $ definition .= '->defaultValue(' . var_export ( $ column -> defaultValue , true ) . ')' ; } elseif ( is_string ( $ column -> defaultValue ) ) { $ definition .= "->defaultValue('" . addslashes ( $ column -> defaultValue ) . "')" ; } if ( null !== $ column -> comment && '' !== $ column -> comment ) { $ definition .= "->comment('" . addslashes ( $ column -> comment ) . "')" ; } return $ definition ; }
|
Returns the other definition .
|
211
|
private function byOption ( ) { $ option = new OptionForCli ( $ this -> interactor ) ; $ option -> setOption ( $ this -> option ) ; $ option -> execute ( ) ; }
|
Download by option .
|
212
|
public function add ( $ input_data ) { $ data [ 'inputs' ] = [ ] ; if ( is_array ( $ input_data ) ) { foreach ( $ input_data as $ image ) { $ data [ 'inputs' ] [ ] = $ this -> addNewImage ( $ image ) ; } } else { $ data [ 'inputs' ] [ ] = $ this -> addNewImage ( $ input_data ) ; } $ inputResult = $ this -> getRequest ( ) -> request ( 'POST' , $ this -> getRequestUrl ( 'inputs' ) , $ data ) ; return $ this -> getInputsFromResult ( $ inputResult ) ; }
|
Add Input Method
|
213
|
public function addNewImage ( Input $ image ) { $ data = [ ] ; $ data [ 'data' ] = [ 'image' => $ this -> generateImageAddress ( $ image -> getImage ( ) , $ image -> getImageMethod ( ) ) , ] ; if ( $ image -> getId ( ) ) { $ data = $ this -> addImageId ( $ data , $ image -> getId ( ) ) ; } if ( $ image -> getCrop ( ) ) { $ data [ 'data' ] [ 'image' ] = $ this -> addImageCrop ( $ data [ 'data' ] [ 'image' ] , $ image -> getCrop ( ) ) ; } if ( $ image -> getConcepts ( ) ) { $ data [ 'data' ] = $ this -> addImageConcepts ( $ data [ 'data' ] , $ image -> getConcepts ( ) ) ; } if ( $ image -> getMetaData ( ) ) { $ data [ 'data' ] = $ this -> addImageMetadata ( $ data [ 'data' ] , $ image -> getMetaData ( ) ) ; } return $ data ; }
|
Adds new Image to Custom Input
|
214
|
public function generateImageAddress ( string $ image , $ method = null ) { if ( $ method == Input :: IMG_BASE64 ) { return [ 'base64' => $ image ] ; } elseif ( $ method == Input :: IMG_PATH ) { if ( ! file_exists ( $ image ) ) { throw new FileNotFoundException ( $ image ) ; } return [ 'base64' => base64_encode ( file_get_contents ( $ image ) ) ] ; } else { return [ 'url' => $ image ] ; } }
|
Generate Image With Download Type
|
215
|
public function addImageConcepts ( array $ data , array $ concepts ) { $ data [ 'concepts' ] = [ ] ; foreach ( $ concepts as $ concept ) { $ data [ 'concepts' ] [ ] = [ 'id' => $ concept -> getId ( ) , 'value' => $ concept -> getValue ( ) , ] ; } return $ data ; }
|
Adds Image Concepts to Image Data
|
216
|
public function addImageMetadata ( array $ data , array $ metadata ) { $ data [ 'metadata' ] = [ ] ; foreach ( $ metadata as $ meta_name => $ meta_value ) { $ data [ 'metadata' ] [ $ meta_name ] = $ meta_value ; } return $ data ; }
|
Adds Image Metadaya to Image Data
|
217
|
public function get ( ) { $ inputResult = $ this -> getRequest ( ) -> request ( 'GET' , $ this -> getRequestUrl ( 'inputs' ) ) ; return $ this -> getInputsFromResult ( $ inputResult ) ; }
|
Gets All Inputs
|
218
|
public function getById ( $ id ) { $ inputResult = $ this -> getRequest ( ) -> request ( 'GET' , $ this -> getRequestUrl ( sprintf ( 'inputs/%s' , $ id ) ) ) ; if ( isset ( $ inputResult [ 'input' ] ) ) { $ input = new Input ( $ inputResult [ 'input' ] ) ; } else { throw new \ Exception ( 'Input Not Found' ) ; } return $ input ; }
|
Gets Input By Id
|
219
|
public function getStatus ( ) { $ statusResult = $ this -> getRequest ( ) -> request ( 'GET' , $ this -> getRequestUrl ( 'inputs/status' ) ) ; if ( isset ( $ statusResult [ 'counts' ] ) ) { $ status = $ statusResult [ 'counts' ] ; } else { throw new \ Exception ( 'Status Not Found' ) ; } return $ status ; }
|
Gets Status of your Inputs
|
220
|
public function deleteById ( $ id ) { $ deleteResult = $ this -> getRequest ( ) -> request ( 'DELETE' , $ this -> getRequestUrl ( sprintf ( 'inputs/%s' , $ id ) ) ) ; return $ deleteResult [ 'status' ] ; }
|
Deletes Input By Id
|
221
|
public function deleteByIdArray ( array $ ids ) { $ data [ 'ids' ] = $ ids ; $ deleteResult = $ this -> getRequest ( ) -> request ( 'DELETE' , $ this -> getRequestUrl ( 'inputs' ) , $ data ) ; return $ deleteResult [ 'status' ] ; }
|
Deletes Inputs By Id Array
|
222
|
public function updateInputConcepts ( array $ conceptsArray , $ action ) { $ data [ 'inputs' ] = [ ] ; foreach ( $ conceptsArray as $ inputId => $ inputConcepts ) { $ input = [ ] ; $ input [ 'id' ] = ( string ) $ inputId ; $ input [ 'data' ] = [ ] ; $ input [ 'data' ] = $ this -> addImageConcepts ( $ input [ 'data' ] , $ inputConcepts ) ; $ data [ 'inputs' ] [ ] = $ input ; } $ data [ 'action' ] = $ action ; $ updateResult = $ this -> getRequest ( ) -> request ( 'PATCH' , $ this -> getRequestUrl ( 'inputs' ) , $ data ) ; return $ this -> getInputsFromResult ( $ updateResult ) ; }
|
Common Input s Concepts Update Method
|
223
|
public function load ( ) { if ( empty ( $ this -> storage ) ) { throw new Exception ( 'Empty config storage' ) ; } $ storage = $ this -> getStorage ( ) ; $ storage -> load ( ) ; return $ this -> fromArray ( $ storage -> get ( ) ) ; }
|
Loads config from storage
|
224
|
protected function checkRequired ( ) { $ errors = new Exceptions ( ) ; foreach ( $ this -> getRequiredKeys ( ) as $ required ) { if ( ! isset ( $ this -> $ required ) ) { $ errors -> add ( new Exception ( 'Required property "' . $ required . '" is missing' ) ) ; } } if ( ! $ errors -> empty ( ) ) { throw $ errors ; } return true ; }
|
Checks if all required properties are set
|
225
|
public function createHelpMessage ( ) { $ m = 'Usage:' . PHP_EOL ; $ m .= ' -h,--help' . PHP_EOL ; $ m .= ' Display help message and exit.' . PHP_EOL ; $ m .= ' -p platform (required)' . PHP_EOL ; $ m .= ' Select platform [m]ac or [w]indows or [l]inux.' . PHP_EOL ; $ m .= ' Required except that "--help, -h" is specified.' . PHP_EOL ; $ m .= ' -d output_dir_path' . PHP_EOL ; $ m .= ' Enter the output directory path.' . PHP_EOL ; $ m .= ' If not specified, it is output to the path specified by .env.dafault|.env(DEFAULT_OUTPUT_DIR).' . PHP_EOL ; $ m .= ' If there is still no value, it is output to "selenium-downloader/xxx".' . PHP_EOL ; $ m .= ' -s selenium-standalone-server_ver' . PHP_EOL ; $ m .= ' Enter the version of selenium-standalone-server. (e.g 3.8.1, 3.7(3.7.0)' . PHP_EOL ; $ m .= ' (Recommend version 3.8.1)' . PHP_EOL ; $ m .= ' -c ChromeDriver_ver' . PHP_EOL ; $ m .= ' Enter the version of ChromeDriver. (e.g 2.43' . PHP_EOL ; $ m .= ' -g geckodriver_ver' . PHP_EOL ; $ m .= ' Enter the version of GeckoDriver. (e.g 0.23(0.23.0), 0.20.1' . PHP_EOL ; $ m .= ' -i IEDriverServer_ver' . PHP_EOL ; $ m .= ' Enter the version of IEDriverServer. (e.g 3.14(3.14.0)' . PHP_EOL ; $ m .= ' -b bit_of_os' . PHP_EOL ; $ m .= ' Enter the number of OS bits (32 or 64).' . PHP_EOL ; $ m .= ' Default is "32" (Because key input is earlier than 64bit version).' . PHP_EOL ; $ m .= ' Valid only when IEDriverServer is specified.' . PHP_EOL ; $ m .= PHP_EOL ; $ m .= 'e.g) 1 Basic.' . PHP_EOL ; $ m .= '$ php selenium_downloader.php -p m -s 3.8.1 -c 2.43 -g 0.23' . PHP_EOL ; $ m .= 'e.g) 2 When specifying the output directory.' . PHP_EOL ; $ m .= '$ php selenium_downloader.php -p m -d /your/path/to -s 3.8.1' . PHP_EOL ; $ m .= 'e.g) 3 When downloading the 64 bit version of the IEDriverServer.' . PHP_EOL ; $ m .= '$ php selenium_downloader.php -p w -i 3.14.0 -b 64' . PHP_EOL ; $ m .= 'e.g) 4 When downloading only geckodriver.' . PHP_EOL ; $ m .= '$ php selenium_downloader.php -p m -g 0.23' . PHP_EOL ; $ m .= 'or' . PHP_EOL ; $ m .= '$ php selenium_downloader.php -p m -s "" -c "" -g 0.23' . PHP_EOL ; return $ m ; }
|
Create help message .
|
226
|
private function _getopt ( ) { $ shortopts = OptionConfig :: HELP ; $ shortopts .= OptionConfig :: PLATFORM . ':' ; $ shortopts .= OptionConfig :: OUTPUT_DIR . ':' ; $ shortopts .= OptionConfig :: SELENIUM_VER . ':' ; $ shortopts .= OptionConfig :: CHROME_DRIVER_VER . ':' ; $ shortopts .= OptionConfig :: GECKO_DRIVER_VER . ':' ; $ shortopts .= OptionConfig :: IE_DRIVER_VER . ':' ; $ shortopts .= OptionConfig :: OS_BIT_VER . ':' ; $ longopts = array ( OptionConfig :: HELP_LONG . '::' , ) ; return getopt ( $ shortopts , $ longopts ) ; }
|
Acquire command line option .
|
227
|
public function getRegisteredParsers ( ) { if ( $ this -> parserInstances === null ) { $ result = [ ] ; foreach ( $ this -> parsers as $ parser ) { if ( $ parser instanceof ParserInterface ) { $ result [ ] = $ parser ; } else { $ instance = $ this -> app -> make ( $ parser ) ; if ( ! ( $ instance instanceof ParserInterface ) ) { throw new UserMessageException ( t ( '%1$s does not implement %2$s' , $ parser , ParserInterface :: class ) ) ; } $ result [ ] = $ instance ; } } $ this -> parserInstances = $ result ; } else { $ result = $ this -> parserInstances ; } return $ result ; }
|
Get the list of registered parsers .
|
228
|
public function showShareButtons ( Twig_Environment $ twigEnvironment , array $ options = array ( ) , array $ providers = array ( ) ) { $ this -> shareButtonsRenderer -> setTemplateEngine ( $ twigEnvironment ) ; if ( isset ( $ providers ) ) { $ options [ 'providers' ] = $ providers ; } if ( ! isset ( $ options [ 'template' ] ) ) { $ options [ 'template' ] = $ this -> configResolver -> getParameter ( 'template' , 'ez_share_buttons' ) ; } return $ twigEnvironment -> render ( sprintf ( 'EzSystemsShareButtonsBundle::%s.html.twig' , $ options [ 'template' ] ) , array ( 'shareButtons' => $ this -> shareButtonsRenderer -> render ( $ options ) , ) ) ; }
|
Renders share buttons bar template based on user settings .
|
229
|
public static function getFile ( $ tmp = true , $ name = null ) { return ( $ tmp ? realpath ( sys_get_temp_dir ( ) ) : '' ) . '/' . ( null === $ name ? uniqid ( ) : $ name ) ; }
|
Gets the file .
|
230
|
public function setAuthorizationFlow ( $ name , $ flow , $ authorizationUrl , $ tokenUrl , $ refreshUrl = null , array $ scopes = null ) { if ( ! isset ( $ this -> authFlows [ $ name ] ) ) { $ this -> authFlows [ $ name ] = [ ] ; } $ this -> authFlows [ $ name ] [ ] = [ $ flow , $ authorizationUrl , $ tokenUrl , $ refreshUrl , $ scopes ] ; }
|
Configuration details for a supported OAuth Flow
|
231
|
private static function decode ( $ data ) { if ( ( is_array ( $ data ) && isset ( $ data [ 0 ] ) ) || ( isset ( $ data [ 0 ] ) && ! is_string ( $ data [ 0 ] ) ) ) { return self :: parseArray ( $ data ) ; } else if ( is_null ( $ data ) || is_scalar ( $ data ) ) { return $ data ; } else { return self :: decodeNewObject ( $ data ) ; } }
|
Decode Array collection
|
232
|
protected function getVolatileDirectory ( ) { if ( $ this -> volatileDirectory === null ) { $ this -> volatileDirectory = $ this -> app -> make ( VolatileDirectory :: class ) ; } return $ this -> volatileDirectory ; }
|
Get the volatile instance that contains the decompressed contents of the package archive .
|
233
|
public function repack ( ) { $ this -> extract ( ) ; try { $ this -> app -> make ( 'helper/zip' ) -> zip ( $ this -> getVolatileDirectory ( ) -> getPath ( ) , $ this -> packageArchive , [ 'includeDotFiles' => true ] ) ; } catch ( \ Exception $ x ) { throw new UserMessageException ( $ x -> getMessage ( ) ) ; } }
|
Re - create the source archive with the contents of the extracted directory .
|
234
|
public function format ( $ user ) { $ id = null ; $ name = '' ; $ userInfo = null ; if ( isset ( $ user ) && $ user ) { if ( is_int ( $ user ) || ( is_string ( $ user ) && is_numeric ( $ user ) ) ) { $ user = \ User :: getByUserID ( $ user ) ; } try { if ( $ user instanceof ConcreteUser && $ user -> getUserID ( ) && $ user -> isRegistered ( ) ) { $ id = ( int ) $ user -> getUserID ( ) ; $ name = $ user -> getUserName ( ) ; } elseif ( $ user instanceof UserInfo && $ user -> getUserID ( ) ) { $ id = ( int ) $ user -> getUserID ( ) ; $ name = $ user -> getUserName ( ) ; $ userInfo = $ user ; } elseif ( $ user instanceof ConcreteUserEntity && $ user -> getUserID ( ) ) { $ id = ( int ) $ user -> getUserID ( ) ; $ name = $ user -> getUserName ( ) ; } } catch ( EntityNotFoundException $ x ) { $ id = null ; } } if ( $ id === null ) { $ result = '<i class="comtra-user comtra-user-removed">' . t ( 'removed user' ) . '</i>' ; } elseif ( $ id == USER_SUPER_ID ) { $ result = '<i class="comtra-user comtra-user-system">' . t ( 'system' ) . '</i>' ; } else { $ profileURL = null ; if ( $ userInfo === null ) { $ userInfo = $ this -> app -> make ( UserInfoRepository :: class ) -> getByID ( $ id ) ; } if ( $ userInfo !== null ) { $ profileURL = $ userInfo -> getUserPublicProfileUrl ( ) ; } if ( $ profileURL === null ) { $ result = '<span' ; } else { $ result = '<a href="' . h ( ( string ) $ profileURL ) . '"' ; } $ result .= ' class="comtra-user comtra-user-found">' . h ( $ name ) ; if ( $ profileURL === null ) { $ result .= '</span>' ; } else { $ result .= '</a>' ; } } return $ result ; }
|
Format a username .
|
235
|
public function getStickyRequest ( ) { if ( $ this -> stickyRequest === null ) { $ this -> stickyRequest = $ this -> app -> make ( StickyRequest :: class , [ 'community_translation.packages' ] ) ; } return $ this -> stickyRequest ; }
|
Get the instance of a class that holds the criteria of the last performed search .
|
236
|
public function getSearchList ( ) { if ( $ this -> searchList === null ) { $ this -> searchList = $ this -> app -> make ( SearchList :: class , [ $ this -> getStickyRequest ( ) ] ) ; } return $ this -> searchList ; }
|
Get the instance of a class that defines the search list .
|
237
|
public function getByHandle ( $ handle ) { return isset ( $ this -> converters [ $ handle ] ) ? $ this -> converters [ $ handle ] : null ; }
|
Get a converter given its handle .
|
238
|
public function getByFileExtension ( $ fileExtension ) { $ fileExtension = ltrim ( $ fileExtension ) ; $ result = [ ] ; foreach ( $ this -> converters as $ converter ) { if ( strcasecmp ( $ fileExtension , $ converter -> getFileExtension ( ) ) === 0 ) { $ result [ ] = $ converter ; } } return $ result ; }
|
Get the converter given a file extension .
|
239
|
public function getRegisteredConverters ( ) { $ result = $ this -> converters ; $ comparer = new Comparer ( ) ; usort ( $ result , function ( ConverterInterface $ a , ConverterInterface $ b ) use ( $ comparer ) { return $ comparer -> compare ( $ a -> getName ( ) , $ b -> getName ( ) ) ; } ) ; return $ result ; }
|
Get the list of registered converters .
|
240
|
public function filterByKeywords ( $ name ) { $ likeBuilder = $ this -> app -> make ( LikeBuilder :: class ) ; $ likes = $ likeBuilder -> splitKeywordsForLike ( $ name , '\W_' ) ; if ( ! empty ( $ likes ) ) { $ expr = $ this -> query -> expr ( ) ; $ orFields = $ expr -> orX ( ) ; foreach ( [ 'p.handle' , 'p.name' ] as $ fieldName ) { $ and = $ expr -> andX ( ) ; foreach ( $ likes as $ like ) { $ and -> add ( $ expr -> like ( $ fieldName , $ this -> query -> createNamedParameter ( $ like ) ) ) ; } $ orFields -> add ( $ and ) ; } $ this -> query -> andWhere ( $ orFields ) ; } }
|
Filter the results by keywords .
|
241
|
protected function doRender ( array $ options ) { if ( ! isset ( $ this -> templateEngine ) ) { throw new InvalidArgumentException ( 'Missing template engine' ) ; } if ( ! isset ( $ this -> label ) ) { throw new InvalidArgumentException ( 'Missing provider label' ) ; } if ( isset ( $ options [ $ this -> label ] ) ) { $ options = array_merge ( $ this -> options , $ options [ $ this -> label ] , $ options ) ; unset ( $ options [ $ this -> label ] ) ; } else { $ options = $ options + $ this -> options ; } $ template = sprintf ( 'EzSystemsShareButtonsBundle::%s/%s' , $ this -> templateName , $ options [ 'template' ] ) ; return $ this -> templateEngine -> render ( $ template , $ options ) ; }
|
Performs share button rendering .
|
242
|
public function addVisit ( $ type , $ count = 1 , DateTime $ dateTime = null , AddressInterface $ ipAddress = null ) { $ count = ( int ) $ count ; if ( $ count > 0 ) { if ( $ dateTime === null ) { $ dateTime = new DateTime ( ) ; } if ( $ ipAddress === null ) { $ ipAddress = $ this -> getIPAddress ( ) ; } $ this -> connection -> executeQuery ( 'insert into CommunityTranslationIPControl (type, ip, dateTime, count) values (?, ?, ?, ?) on duplicate key update count = count + ? ' , [ ( string ) $ type , ( string ) $ ipAddress , $ dateTime -> format ( $ this -> connection -> getDatabasePlatform ( ) -> getDateTimeFormatString ( ) ) , $ count , $ count , ] ) ; } }
|
Count a visit for a specified type .
|
243
|
public static function create ( $ domain , $ whois ) { $ tld = substr ( strrchr ( $ domain , '.' ) , 1 ) ; $ parserClass = 'Wisdom\\Whois\\Parser\\Tld\\' . ucfirst ( $ tld ) ; if ( ! class_exists ( $ parserClass ) ) { throw new WhoisParserNotFoundException ( sprintf ( 'Whois parser for .%s domains not found.' , $ tld ) ) ; } return new $ parserClass ( $ domain , $ whois ) ; }
|
Creates whois parser for given domain name .
|
244
|
public static function getCurrentArch ( ) : string { $ arch = php_uname ( 'm' ) ; if ( $ arch === "x86_64" ) { $ arch = "amd64" ; } elseif ( $ arch === "i386" ) { $ arch = "386" ; } else { printf ( 'ERROR: Unexpected, please contact the maintainer or provide a pull request :)%s' , PHP_EOL ) ; exit ( 1 ) ; } return $ arch ; }
|
Returns the architecture of the current machine
|
245
|
public static function getBinaryPath ( ) : string { $ binaryName = Utilities :: getReleaseName ( ) ; $ binaryPath = sprintf ( '%s/bin/%s' , Utilities :: getBasePath ( ) , $ binaryName ) ; return $ binaryPath ; }
|
returns the binary name
|
246
|
public static function downloadReleaseArchive ( string $ releaseName , string $ version ) : bool { $ archiveName = $ releaseName . '.tar.gz' ; $ archivePath = sprintf ( '%s/%s' , Utilities :: getBasePath ( ) , $ archiveName ) ; $ releaseUrl = sprintf ( 'https://github.com/editorconfig-checker/editorconfig-checker/releases/download/%s/%s' , $ version , $ archiveName ) ; $ result = file_put_contents ( $ archivePath , fopen ( $ releaseUrl , 'r' ) ) ; return $ result > 0 || $ result ; }
|
Downloads the release from the release page
|
247
|
public static function extractReleaseArchive ( string $ releaseName ) : bool { return Utilities :: decompress ( $ releaseName ) && Utilities :: unpack ( $ releaseName ) ; }
|
decompresses and extracts the release archive
|
248
|
public static function decompress ( string $ releaseName ) : bool { try { $ p = new \ PharData ( sprintf ( "%s/%s.tar.gz" , Utilities :: getBasePath ( ) , $ releaseName ) ) ; $ p -> decompress ( ) ; } catch ( Exception $ e ) { printf ( 'ERROR: Can not decompress the archive%s%s' , PHP_EOL , $ e ) ; return false ; } return true ; }
|
decompresses the release archive
|
249
|
public static function unpack ( string $ releaseName ) : bool { try { $ p = new \ PharData ( sprintf ( "%s/%s.tar" , Utilities :: getBasePath ( ) , $ releaseName ) ) ; $ p -> extractTo ( Utilities :: getBasePath ( ) ) ; if ( ! unlink ( sprintf ( "%s/%s.tar" , Utilities :: getBasePath ( ) , $ releaseName ) ) ) { printf ( 'ERROR: Can not remove the decompressed archive%s' , PHP_EOL ) ; return false ; } } catch ( \ PharException $ e ) { printf ( 'ERROR: Can not unpack the archive%s%s' , PHP_EOL , $ e ) ; return false ; } return true ; }
|
unpacks the release archive
|
250
|
public static function constructStringFromArguments ( array $ arguments ) : string { $ result = '' ; foreach ( $ arguments as $ argument ) { $ result .= ' ' . $ argument ; } return $ result ; }
|
Constructs the arguments the binary needs to be called by the arguments providedunline
|
251
|
public static function cleanup ( ) : void { $ releaseName = sprintf ( "%s/%s" , Utilities :: getBasePath ( ) , Utilities :: getReleaseName ( ) ) ; if ( is_file ( $ releaseName . '.tar.gz' ) ) { unlink ( $ releaseName . '.tar.gz' ) ; } if ( is_file ( $ releaseName . '.tar' ) ) { unlink ( $ releaseName . '.tar' ) ; } }
|
Removes all intermediate files
|
252
|
public function setTopic ( $ value ) { $ this -> assertValidString ( $ value , false ) ; if ( $ value === '' ) { throw new \ InvalidArgumentException ( 'The topic must not be empty.' ) ; } $ this -> topic = $ value ; }
|
Sets the topic .
|
253
|
public function processParameters ( ) { $ parameters = $ this -> getParameters ( ) ; $ factory = $ this -> buildFactory ( ) ; $ parametersType = $ this -> buildParametersType ( ) ; $ request = $ factory -> create ( $ parametersType ) ; if ( ! is_null ( $ parameters ) ) { $ processorFactory = new ParametersProcessorFactory ( ) ; $ processor = $ processorFactory -> create ( gettype ( $ parameters ) ) ; $ request = $ processor -> convertToObjectParameters ( $ request , $ parameters ) ; } return $ request ; }
|
Fonction de process pour les parametres
|
254
|
public function getAttributes ( ) { $ defaultPrefix = PhoneNumber :: config ( ) -> get ( 'default_country_code' ) ; $ attributes = [ 'class' => 'text' , 'placeholder' => _t ( __CLASS__ . '.Placeholder' , 'Phone number links will be prefixed with +{prefix}' , [ 'prefix' => $ defaultPrefix ] ) , ] ; return array_merge ( parent :: getAttributes ( ) , $ attributes ) ; }
|
Return field attributes
|
255
|
public function matches ( $ filter , $ topic ) { $ tokens = explode ( '/' , $ filter ) ; $ parts = [ ] ; for ( $ i = 0 , $ count = count ( $ tokens ) ; $ i < $ count ; ++ $ i ) { $ token = $ tokens [ $ i ] ; switch ( $ token ) { case '+' : $ parts [ ] = '[^/#\+]*' ; break ; case '#' : if ( $ i === 0 ) { $ parts [ ] = '[^\+\$]*' ; } else { $ parts [ ] = '[^\+]*' ; } break ; default : $ parts [ ] = str_replace ( '+' , '\+' , $ token ) ; break ; } } $ regex = implode ( '/' , $ parts ) ; $ regex = str_replace ( '$' , '\$' , $ regex ) ; $ regex = ';^' . $ regex . '$;' ; return preg_match ( $ regex , $ topic ) === 1 ; }
|
Check if the given topic matches the filter .
|
256
|
protected function log ( $ message , $ context ) { $ logger = $ this -> getLogger ( ) ; if ( $ logger !== null ) { $ logger -> error ( $ message , $ context ) ; } }
|
Curl operation error logging function
|
257
|
private function readRemainingLength ( PacketStream $ stream ) { $ this -> remainingPacketLength = 0 ; $ multiplier = 1 ; do { $ encodedByte = $ stream -> readByte ( ) ; $ this -> remainingPacketLength += ( $ encodedByte & 127 ) * $ multiplier ; $ multiplier *= 128 ; if ( $ multiplier > 128 * 128 * 128 * 128 ) { throw new MalformedPacketException ( 'Malformed remaining length.' ) ; } } while ( ( $ encodedByte & 128 ) !== 0 ) ; }
|
Reads the remaining length from the given stream .
|
258
|
private function writeRemainingLength ( PacketStream $ stream ) { $ x = $ this -> remainingPacketLength ; do { $ encodedByte = $ x % 128 ; $ x = ( int ) ( $ x / 128 ) ; if ( $ x > 0 ) { $ encodedByte |= 128 ; } $ stream -> writeByte ( $ encodedByte ) ; } while ( $ x > 0 ) ; }
|
Writes the remaining length to the given stream .
|
259
|
protected function assertPacketFlags ( $ value , $ fromPacket = true ) { if ( $ this -> packetFlags !== $ value ) { $ this -> throwException ( sprintf ( 'Expected flags %02x but got %02x.' , $ value , $ this -> packetFlags ) , $ fromPacket ) ; } }
|
Asserts that the packet flags have a specific value .
|
260
|
protected function assertRemainingPacketLength ( $ value = null , $ fromPacket = true ) { if ( $ value === null && $ this -> remainingPacketLength === 0 ) { $ this -> throwException ( 'Expected payload but remaining packet length is zero.' , $ fromPacket ) ; } if ( $ value !== null && $ this -> remainingPacketLength !== $ value ) { $ this -> throwException ( sprintf ( 'Expected remaining packet length of %d bytes but got %d.' , $ value , $ this -> remainingPacketLength ) , $ fromPacket ) ; } }
|
Asserts that the remaining length is greater than zero and has a specific value .
|
261
|
protected function assertValidQosLevel ( $ level , $ fromPacket = true ) { if ( $ level < 0 || $ level > 2 ) { $ this -> throwException ( sprintf ( 'Expected a quality of service level between 0 and 2 but got %d.' , $ level ) , $ fromPacket ) ; } }
|
Asserts that the given quality of service level is valid .
|
262
|
public static function run ( array $ arguments ) : int { $ releaseName = Utilities :: getReleaseName ( ) ; $ binaryPath = Utilities :: getBinaryPath ( ) ; if ( ! is_file ( $ binaryPath ) ) { Utilities :: cleanup ( ) ; if ( ! Utilities :: downloadReleaseArchive ( $ releaseName , CORE_VERSION ) ) { printf ( 'ERROR: Can not download the archive%s' , PHP_EOL ) ; return 1 ; } if ( ! Utilities :: extractReleaseArchive ( $ releaseName ) ) { printf ( 'ERROR: can not extract the archive%s' , PHP_EOL ) ; return 1 ; } Utilities :: cleanup ( ) ; } array_shift ( $ arguments ) ; $ args = Utilities :: constructStringFromArguments ( $ arguments ) ; system ( $ binaryPath . $ args , $ result ) ; return $ result ; }
|
Entry point of this class to invoke all needed steps
|
263
|
protected function applyCasts ( bool $ scalarOnly = false ) : void { if ( ! $ scalarOnly ) { foreach ( array_keys ( $ this -> casts ( ) ) as $ key ) { $ this -> applyCast ( $ key ) ; } return ; } foreach ( $ this -> casts ( ) as $ key => $ type ) { if ( ! in_array ( $ type , static :: SCALAR_CASTS ) ) { continue ; } $ this -> applyCast ( $ key ) ; } }
|
Applies casts to currently set attributes .
|
264
|
protected function applyCast ( string $ key ) : void { $ casts = $ this -> casts ( ) ; if ( ! count ( $ casts ) || ! array_key_exists ( $ key , $ casts ) ) { return ; } if ( ! isset ( $ this -> attributes [ $ key ] ) ) { $ value = null ; } else { $ value = $ this -> attributes [ $ key ] ; } if ( in_array ( $ casts [ $ key ] , static :: SCALAR_CASTS ) ) { $ this -> attributes [ $ key ] = call_user_func ( [ $ this , 'castValueAs' . ucfirst ( $ casts [ $ key ] ) ] , $ value ) ; return ; } $ dataObjectClass = $ casts [ $ key ] ; $ dataObjectArray = false ; if ( substr ( $ dataObjectClass , - 2 ) === '[]' ) { $ dataObjectClass = substr ( $ dataObjectClass , 0 , - 2 ) ; $ dataObjectArray = true ; } if ( null === $ value ) { if ( $ dataObjectArray ) { $ this -> attributes [ $ key ] = [ ] ; return ; } if ( $ this -> castUnsetObjects ) { $ this -> attributes [ $ key ] = $ this -> makeNestedDataObject ( $ dataObjectClass , [ ] , $ key ) ; } return ; } if ( $ dataObjectArray ) { if ( is_array ( $ this -> attributes [ $ key ] ) ) { foreach ( $ this -> attributes [ $ key ] as $ index => & $ item ) { if ( null === $ item && ! $ this -> castUnsetObjects ) { continue ; } if ( ! ( $ item instanceof $ dataObjectClass ) ) { $ item = $ this -> makeNestedDataObject ( $ dataObjectClass , $ item ? : [ ] , $ key . '.' . $ index ) ; } } } unset ( $ item ) ; return ; } if ( ! ( $ this -> attributes [ $ key ] instanceof $ dataObjectClass ) ) { $ this -> attributes [ $ key ] = $ this -> makeNestedDataObject ( $ dataObjectClass , $ this -> attributes [ $ key ] , $ key ) ; } }
|
Applies cast for a given attribute key .
|
265
|
protected function makeNestedDataObject ( string $ class , $ data , $ key ) : DataObjectInterface { $ data = ( $ data instanceof Arrayable ) ? $ data -> toArray ( ) : $ data ; if ( ! is_array ( $ data ) ) { throw new UnexpectedValueException ( "Cannot instantiate data object '{$class}' with non-array data for key '{$key}'" . ( is_scalar ( $ data ) || is_object ( $ data ) && method_exists ( $ data , '__toString' ) ? ' (data: ' . ( string ) $ data . ')' : null ) ) ; } return new $ class ( $ data ) ; }
|
Makes a new nested data object for a given class and data .
|
266
|
public function getNextValue ( string $ sequenceName ) : int { $ sequenceValue = $ this -> rawCollection ( ) -> findOneAndUpdate ( [ '_id' => $ sequenceName ] , [ '$inc' => [ 'seq' => 1 ] ] , [ 'upsert' => true ] ) ; if ( $ sequenceValue ) { $ _id = $ sequenceValue -> seq + 1 ; } return $ _id ?? 1 ; }
|
Get next value for the sequence .
|
267
|
public function reduce ( $ degree , $ lookAhead = null ) { if ( $ lookAhead ) { $ this -> lookAhead = ( int ) $ lookAhead ; } $ epsilon = deg2rad ( $ degree ) ; $ results = array ( ) ; for ( $ i = 0 ; $ i < $ this -> count ( ) ; $ i ++ ) { $ j = min ( $ i + $ this -> lookAhead , $ this -> lastKey ( ) ) ; $ basePoint = $ this -> points [ $ i ] ; $ results [ ] = $ basePoint ; $ boundPoint = $ this -> points [ $ j ] ; $ theta = $ this -> _theta ( $ basePoint , $ boundPoint ) ; $ a1 = $ theta - $ epsilon ; $ a2 = $ theta + $ epsilon ; while ( ++ $ i < $ j ) { $ testPoint = $ this -> points [ $ i ] ; $ delta = $ this -> _theta ( $ basePoint , $ testPoint ) ; if ( $ a1 < $ delta && $ delta < $ a2 ) { } else { break ; } } $ i -- ; } return $ this -> points = $ results ; }
|
Reduce points with modified version of Zhao - Saalfeld simplification .
|
268
|
private function _theta ( PointInterface $ a , PointInterface $ b ) { list ( $ x1 , $ y1 ) = $ a -> getCoordinates ( ) ; list ( $ x2 , $ y2 ) = $ b -> getCoordinates ( ) ; return atan2 ( $ y2 - $ y1 , $ x2 - $ x1 ) + 2 * M_PI ; }
|
Calculate the angle and add 2pi to protect against underflow .
|
269
|
public function read ( $ count ) { $ contentLength = strlen ( $ this -> data ) ; if ( $ this -> position > $ contentLength || $ count > $ contentLength - $ this -> position ) { throw new EndOfStreamException ( sprintf ( 'End of stream reached when trying to read %d bytes. content length=%d, position=%d' , $ count , $ contentLength , $ this -> position ) ) ; } $ chunk = substr ( $ this -> data , $ this -> position , $ count ) ; if ( $ chunk === false ) { $ chunk = '' ; } $ readBytes = strlen ( $ chunk ) ; $ this -> position += $ readBytes ; return $ chunk ; }
|
Returns the desired number of bytes .
|
270
|
public function writeWord ( $ value ) { $ this -> write ( chr ( ( $ value & 0xFFFF ) >> 8 ) ) ; $ this -> write ( chr ( $ value & 0xFF ) ) ; }
|
Appends a single word .
|
271
|
public function cut ( ) { $ this -> data = substr ( $ this -> data , $ this -> position ) ; if ( $ this -> data === false ) { $ this -> data = '' ; } $ this -> position = 0 ; }
|
Removes all bytes from the beginning to the current position .
|
272
|
public static function where ( array $ query = [ ] , array $ projection = [ ] , bool $ useCache = false ) { return self :: getDataMapperInstance ( ) -> where ( $ query , $ projection , $ useCache ) ; }
|
Gets a cursor of this kind of entities that matches the query from the database .
|
273
|
public static function first ( $ query = [ ] , array $ projection = [ ] , bool $ useCache = false ) { return self :: getDataMapperInstance ( ) -> first ( $ query , $ projection , $ useCache ) ; }
|
Gets the first entity of this kind that matches the query .
|
274
|
public static function firstOrFail ( $ query = [ ] , array $ projection = [ ] , bool $ useCache = false ) { return self :: getDataMapperInstance ( ) -> firstOrFail ( $ query , $ projection , $ useCache ) ; }
|
Gets the first entity of this kind that matches the query . If no document was found throws ModelNotFoundException .
|
275
|
public static function firstOrNew ( $ id ) { if ( $ entity = self :: getDataMapperInstance ( ) -> first ( $ id ) ) { return $ entity ; } $ entity = new static ( ) ; $ entity -> _id = $ id ; return $ entity ; }
|
Gets the first entity of this kind that matches the query . If no document was found a new entity will be returned with the _if field filled .
|
276
|
public function getDataMapper ( ) { $ dataMapper = Ioc :: make ( DataMapper :: class ) ; $ dataMapper -> setSchema ( $ this -> getSchema ( ) ) ; return $ dataMapper ; }
|
Returns a DataMapper configured with the Schema and collection described in this entity .
|
277
|
protected function execute ( string $ action ) { if ( ! $ this -> getCollectionName ( ) ) { return false ; } $ options = [ 'writeConcern' => new WriteConcern ( $ this -> getWriteConcern ( ) ) , ] ; if ( $ result = $ this -> getDataMapper ( ) -> $ action ( $ this , $ options ) ) { $ this -> syncOriginalAttributes ( ) ; } return $ result ; }
|
Performs the given action into database .
|
278
|
private static function getDataMapperInstance ( ) { $ instance = Ioc :: make ( get_called_class ( ) ) ; if ( ! $ instance -> getCollectionName ( ) ) { throw new NoCollectionNameException ( ) ; } return $ instance -> getDataMapper ( ) ; }
|
Returns the a valid instance from Ioc .
|
279
|
protected function succeed ( $ result = null ) { $ this -> isFinished = true ; $ this -> isSuccess = true ; $ this -> result = $ result ; }
|
Marks the flow as successful and sets the result .
|
280
|
protected function fail ( $ error = '' ) { $ this -> isFinished = true ; $ this -> isSuccess = false ; $ this -> error = $ error ; }
|
Marks the flow as failed and sets the error message .
|
281
|
public static function isObjectId ( $ value ) { if ( is_object ( $ value ) && method_exists ( $ value , '__toString' ) ) { $ value = ( string ) $ value ; } return is_string ( $ value ) && 24 == strlen ( $ value ) && ctype_xdigit ( $ value ) ; }
|
Checks if the given value can be a valid ObjectId .
|
282
|
protected function getScriptPath ( ) : string { $ class = new \ ReflectionClass ( $ this -> getClassName ( ) ) ; $ path = $ class -> getFileName ( ) ; $ path = preg_replace ( '/\.php$/' , '.phtml' , $ path , - 1 , $ count ) ; if ( $ count !== 1 ) { throw new \ RuntimeException ( 'The class filename does not end with .php' ) ; } return $ path ; }
|
Returns the view script path .
|
283
|
protected function getTableValuesSelect ( $ dbm = null ) { $ dbm = $ dbm ? $ dbm : new DBM ; $ table_raw = $ dbm -> getTableList ( ) ; return $ table_raw ? array_combine ( array_values ( $ table_raw ) , array_values ( $ table_raw ) ) : false ; }
|
Return value with table names for a select
|
284
|
protected function getDataTable ( ) { $ data = $ this -> getTableData ( ) ; $ header = $ this -> getTableHeader ( ) ; $ table = new Table ( ) ; $ table -> setConfig ( array ( "table-hover" => true , "table-condensed" => false , "table-responsive" => true , "table-striped" => true , ) ) ; $ table -> setHeader ( $ header ) ; foreach ( $ data as $ val ) { $ table -> addRows ( get_object_vars ( $ val ) ) ; } return $ table -> getHtml ( ) ; }
|
Return the table for the preview
|
285
|
protected function getTableData ( ) { $ data = array ( ) ; $ form_input = $ this -> getFormInput ( ) ; if ( $ form_input [ 'table_name' ] && $ form_input [ 'max_rows' ] ) { $ connection_name = Config :: get ( 'laravel-import-export::baseconf.connection_name' ) ; $ temp_data = DB :: connection ( $ connection_name ) -> table ( $ this -> form_input [ 'table_name' ] ) -> select ( "*" ) -> take ( $ this -> form_input [ 'max_rows' ] ) ; if ( $ temp_data -> exists ( ) ) { $ data = $ temp_data -> get ( ) ; } else { throw new NoDataException ; } } else { throw new \ BadMethodCallException ; } return $ data ; }
|
Get the data from the db for the preview
|
286
|
protected function getTableHeader ( $ dbm = null ) { $ dbm = $ dbm ? $ dbm : new DBM ; $ columns = array ( ) ; $ form_input = $ this -> getFormInput ( ) ; if ( $ form_input [ 'table_name' ] ) { $ dbal_columns = $ dbm -> getTableColumns ( $ this -> form_input [ 'table_name' ] ) ; foreach ( $ dbal_columns as $ column ) { $ array_columns = $ column -> toArray ( ) ; $ columns [ ] = $ array_columns [ "name" ] ; } } else { throw new \ BadMethodCallException ; } return $ columns ; }
|
Get the header for the preview
|
287
|
public function getTemporary ( ) { $ connection_name = Config :: get ( 'laravel-import-export::baseconf.connection_name' ) ; DB :: connection ( $ connection_name ) -> disableQueryLog ( ) ; $ temporary = TemporaryModel :: whereRaw ( "1" ) -> orderBy ( "id" , "DESC" ) -> first ( ) ; if ( $ temporary ) { $ this -> csv_file = $ temporary -> file_object ; return $ this -> csv_file ; } return false ; }
|
Get data from the temporary table
|
288
|
public function saveTemporary ( $ csv_file = null , $ temporary_model = null ) { $ csv_file = $ csv_file ? $ csv_file : $ this -> csv_file ; if ( $ csv_file ) { $ temporary_model = ( $ temporary_model ) ? $ temporary_model : new TemporaryModel ( ) ; $ temporary_model -> fill ( array ( "file_object" => $ csv_file ) ) ; $ connection_name = Config :: get ( 'laravel-import-export::baseconf.connection_name' ) ; DB :: connection ( $ connection_name ) -> disableQueryLog ( ) ; return $ temporary_model -> save ( ) ; } else { return false ; } }
|
Put data in the temporary table
|
289
|
public function updateHeaders ( CsvFile $ csv_file , array $ columns , $ table_name ) { $ this -> csv_file = $ csv_file ? $ csv_file : $ this -> csv_file ; foreach ( $ this -> csv_file as $ csv_line ) { $ this -> updateHeader ( $ csv_line , $ columns , $ table_name ) ; } }
|
Update headers of the csv_file
|
290
|
protected function updateHeader ( CsvLine $ csv_line , array $ columns , $ table_name ) { $ model_attributes = $ csv_line -> getAttributes ( ) ; $ new_attributes = array ( ) ; foreach ( $ columns as $ key_column => $ column ) { if ( isset ( $ model_attributes [ $ key_column ] ) ) { $ new_attributes = array_merge ( $ new_attributes , array ( $ column => $ model_attributes [ $ key_column ] ) ) ; unset ( $ model_attributes [ $ key_column ] ) ; } else { throw new UnalignedArrayException ; } } $ csv_line -> resetAttributes ( ) ; foreach ( $ new_attributes as $ key_attribute => $ attribute ) { $ csv_line -> forceSetAttribute ( $ key_attribute , $ attribute ) ; } $ table = array ( "table" => $ table_name ) ; $ csv_line -> setConfig ( $ table ) ; return true ; }
|
Update headers of the csv_line
|
291
|
public function openFromDb ( array $ config , DbFileBuilder $ builder = null ) { $ builder = $ builder ? $ builder : new DbFileBuilder ( ) ; $ builder -> setConfig ( $ config ) ; $ builder -> build ( ) ; $ this -> csv_file = $ builder -> getCsvFile ( ) ; return $ this -> getCsvFile ( ) ; }
|
Build the csvFile from Db
|
292
|
public function getMaxLength ( $ csv_file = null ) { $ csv_file = $ csv_file ? $ csv_file : $ this -> csv_file ; $ sizes = array ( 0 ) ; if ( ! $ csv_file ) { throw new NoDataException ( ) ; } foreach ( $ csv_file as $ line ) { $ sizes [ ] = count ( $ line -> getElements ( ) ) ; } return max ( $ sizes ) ; }
|
Get the max lenght of a csv_line
|
293
|
public function getCsvString ( $ separator , CsvFile $ csv_file = null ) { $ csv_file = $ csv_file ? $ csv_file : $ this -> csv_file ; $ csv = '' ; if ( ! isset ( $ csv_file ) ) { throw new NoDataException ; } else { foreach ( $ csv_file as $ key => $ csv_line ) { if ( $ key == 0 ) { $ csv .= $ csv_line -> getCsvHeader ( $ separator ) ; } $ csv .= $ csv_line -> getCsvString ( $ separator ) ; } } return $ csv ; }
|
Create the csv string rappresenting the CsvFile
|
294
|
protected function updateCsvHeader ( ) { if ( $ this -> config [ 'first_line_headers' ] ) { $ csv_line_array = $ this -> csv_parser -> parseCsvFile ( ) ; $ this -> csv_file -> setCsvHeader ( $ csv_line_array ) ; } }
|
Update the csv header with first row of the file if first_line_headers is enabled
|
295
|
protected function generateIdentifier ( ) { if ( $ this -> identifier === null ) { ++ self :: $ nextIdentifier ; self :: $ nextIdentifier &= 0xFFFF ; $ this -> identifier = self :: $ nextIdentifier ; } return $ this -> identifier ; }
|
Returns the identifier or generates a new one .
|
296
|
public function setIdentifier ( $ value ) { if ( $ value !== null && ( $ value < 0 || $ value > 0xFFFF ) ) { throw new \ InvalidArgumentException ( sprintf ( 'Expected an identifier between 0x0000 and 0xFFFF but got %x' , $ value ) ) ; } $ this -> identifier = $ value ; }
|
Sets the identifier .
|
297
|
public function approvedWithPending ( ) : ActiveQuery { return $ this -> andWhere ( [ $ this -> statusAttribute => [ Status :: APPROVED , Status :: PENDING ] ] ) ; }
|
Get a new active query object that includes approved and pending resources .
|
298
|
public function channel ( $ channel ) { if ( ! isset ( $ channel [ 'link' ] ) ) { $ channel [ 'link' ] = '/' ; } if ( ! isset ( $ channel [ 'title' ] ) ) { $ channel [ 'title' ] = '' ; } if ( ! isset ( $ channel [ 'description' ] ) ) { $ channel [ 'description' ] = '' ; } $ channel = $ this -> _prepareOutput ( $ channel ) ; return $ channel ; }
|
Prepares the channel and sets default values .
|
299
|
public function render ( $ view = null , $ layout = null ) { if ( isset ( $ this -> viewVars [ '_serialize' ] ) ) { return $ this -> _serialize ( $ this -> viewVars [ '_serialize' ] ) ; } if ( $ view !== false && $ this -> _getViewFileName ( $ view ) ) { return parent :: render ( $ view , false ) ; } }
|
Render a RSS view .
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.