idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
59,500
protected function checkTransaction ( ) { if ( null !== $ this -> con && ! $ this -> con -> inTransaction ( ) ) { $ this -> con -> beginTransaction ( ) ; } if ( null !== $ this -> con && $ this -> con -> inTransaction ( ) ) { $ this -> items ++ ; } if ( $ this -> items >= Config :: getParam ( 'api.block.limit' , 1000 ) ) { $ this -> con -> commit ( ) ; $ this -> items = 0 ; } }
Checks if the connection has a transaction initialized
59,501
public function __toHtml ( $ submitted = false , $ blnSimpleLayout = false ) { if ( ! $ blnSimpleLayout ) { $ this -> setConditionalMeta ( ) ; $ strOutput = str_replace ( "[[metaString]]" , $ this -> __getMetaString ( ) , $ this -> __body ) ; } else { $ this -> setMeta ( "class" , "vf__multifielditem" ) ; $ strOutput = "<div " . $ this -> __getMetaString ( ) . "><span>{$this->__body}</span></div>\n" ; } return $ strOutput ; }
Render the string s HTML
59,502
public function toJS ( $ intDynamicPosition = 0 ) { $ strOutput = "" ; if ( $ this -> getMeta ( "id" ) ) { $ strId = $ this -> getMeta ( "id" ) ; $ strOutput = "objForm.addElement('{$strId}', '{$strId}');\n" ; $ strOutput .= $ this -> conditionsToJs ( $ intDynamicPosition ) ; } return $ strOutput ; }
Render the string s Javascript
59,503
public function generateConfFromDB ( DBUtils $ dbUtils , GuesserInterface $ guesser ) : array { $ this -> conn = $ dbUtils -> getConn ( ) ; $ tables = $ this -> getTablesList ( ) ; if ( empty ( $ tables ) ) { throw new NeuralyzerConfigurationException ( 'No tables to read in that database' ) ; } $ data = [ ] ; foreach ( $ tables as $ table ) { $ cols = $ this -> getColsList ( $ table ) ; if ( empty ( $ cols ) ) { continue ; } $ data [ $ table ] [ 'cols' ] = $ this -> guessColsAnonType ( $ table , $ cols , $ guesser ) ; } if ( empty ( $ data ) ) { throw new NeuralyzerConfigurationException ( 'All tables or fields have been ignored' ) ; } $ config = [ 'entities' => $ data ] ; $ processor = new Processor ( ) ; return $ processor -> processConfiguration ( new ConfigDefinition , [ $ config ] ) ; }
Generate the configuration by reading tables + cols
59,504
public function save ( array $ data , string $ filename ) { if ( ! is_writeable ( dirname ( $ filename ) ) ) { throw new NeuralyzerConfigurationException ( dirname ( $ filename ) . ' is not writable.' ) ; } file_put_contents ( $ filename , Yaml :: dump ( $ data , 4 ) ) ; }
Save the data to the file as YAML
59,505
protected function colIgnored ( string $ table , string $ col ) : bool { if ( $ this -> protectCols === false ) { return false ; } foreach ( $ this -> protectedCols as $ protectedCol ) { if ( preg_match ( "/^$protectedCol\$/" , $ table . '.' . $ col ) ) { return true ; } } return false ; }
Check if that col has to be ignored
59,506
protected function getColsList ( string $ table ) : array { $ schema = $ this -> conn -> getSchemaManager ( ) ; $ tableDetails = $ schema -> listTableDetails ( $ table ) ; if ( $ tableDetails -> hasPrimaryKey ( ) === false ) { throw new NeuralyzerConfigurationException ( "Can't work with $table, it has no primary key." ) ; } $ primaryKey = $ tableDetails -> getPrimaryKey ( ) -> getColumns ( ) [ 0 ] ; $ cols = $ schema -> listTableColumns ( $ table ) ; $ colsInfo = [ ] ; foreach ( $ cols as $ col ) { if ( $ primaryKey === $ col -> getName ( ) || $ this -> colIgnored ( $ table , $ col -> getName ( ) ) ) { continue ; } $ colsInfo [ ] = [ 'name' => $ col -> getName ( ) , 'type' => strtolower ( ( string ) $ col -> getType ( ) ) , 'len' => $ col -> getLength ( ) , ] ; } return $ colsInfo ; }
Get the cols lists from a connection + table
59,507
protected function getTablesList ( ) : array { $ schemaManager = $ this -> conn -> getSchemaManager ( ) ; $ tablesInDB = $ schemaManager -> listTables ( ) ; $ tables = [ ] ; foreach ( $ tablesInDB as $ table ) { if ( $ this -> tableIgnored ( $ table -> getName ( ) ) ) { continue ; } $ tables [ ] = $ this -> tablesInConf [ ] = $ table -> getName ( ) ; } return array_values ( $ tables ) ; }
Get the table lists from a connection
59,508
protected function guessColsAnonType ( string $ table , array $ cols , GuesserInterface $ guesser ) : array { $ mapping = [ ] ; foreach ( $ cols as $ props ) { $ mapping [ $ props [ 'name' ] ] = $ guesser -> mapCol ( $ table , $ props [ 'name' ] , $ props [ 'type' ] , $ props [ 'len' ] ) ; } return $ mapping ; }
Guess the cols with the guesser
59,509
protected function tableIgnored ( string $ table ) : bool { foreach ( $ this -> ignoredTables as $ ignoredTable ) { if ( preg_match ( "/^$ignoredTable\$/" , $ table ) ) { return true ; } } return false ; }
Check if that table has to be ignored
59,510
public function countResults ( string $ table ) : int { $ queryBuilder = $ this -> conn -> createQueryBuilder ( ) ; $ rows = $ queryBuilder -> select ( 'COUNT(1)' ) -> from ( $ table ) -> execute ( ) ; return ( int ) $ rows -> fetch ( \ Doctrine \ DBAL \ FetchMode :: NUMERIC ) [ 0 ] ; }
Do a simple count for a table
59,511
public function getPrimaryKey ( string $ table ) : string { $ schema = $ this -> conn -> getSchemaManager ( ) ; $ tableDetails = $ schema -> listTableDetails ( $ table ) ; if ( $ tableDetails -> hasPrimaryKey ( ) === false ) { throw new NeuralyzerException ( "Can't find a primary key for '{$table}'" ) ; } return $ tableDetails -> getPrimaryKey ( ) -> getColumns ( ) [ 0 ] ; }
Identify the primary key for a table
59,512
public function getTableCols ( string $ table ) : array { $ schema = $ this -> conn -> getSchemaManager ( ) ; $ tableCols = $ schema -> listTableColumns ( $ table ) ; $ cols = [ ] ; foreach ( $ tableCols as $ col ) { $ cols [ $ col -> getName ( ) ] = [ 'length' => $ col -> getLength ( ) , 'type' => $ col -> getType ( ) , 'unsigned' => $ col -> getUnsigned ( ) , ] ; } return $ cols ; }
Retrieve columns list for a table with type and length
59,513
public function assertTableExists ( string $ table ) : void { if ( $ this -> conn -> getSchemaManager ( ) -> tablesExist ( [ $ table ] ) === false ) { throw new NeuralyzerException ( "Table $table does not exist" ) ; } }
Make sure a table exists
59,514
public function getCondition ( string $ field , array $ fieldConf ) : string { $ type = strtolower ( $ fieldConf [ 'type' ] ) ; $ unsigned = $ fieldConf [ 'unsigned' ] ; $ integerCast = $ this -> getIntegerCast ( $ unsigned ) ; $ condition = "(CASE $field WHEN NULL THEN NULL ELSE :$field END)" ; $ typeToCast = [ 'date' => 'DATE' , 'datetime' => 'DATE' , 'time' => 'TIME' , 'smallint' => $ integerCast , 'integer' => $ integerCast , 'bigint' => $ integerCast , 'float' => 'DECIMAL' , 'decimal' => 'DECIMAL' , ] ; if ( ! array_key_exists ( $ type , $ typeToCast ) ) { return $ condition ; } return "CAST($condition AS {$typeToCast[$type]})" ; }
Build the condition by casting the value if needed
59,515
private function getIntegerCast ( bool $ unsigned ) : string { $ driver = $ this -> conn -> getDriver ( ) ; if ( strpos ( $ driver -> getName ( ) , 'mysql' ) ) { return $ unsigned === true ? 'UNSIGNED' : 'SIGNED' ; } return 'INTEGER' ; }
Get the right CAST for an INTEGER
59,516
public function first ( ) : ? Post { $ params = array_merge ( $ this -> getParameters ( ) , [ 'limit' => 1 , ] ) ; $ posts = Timber :: get_posts ( $ params , $ this -> postClass ) ; if ( ! is_array ( $ posts ) ) { return null ; } return collect ( $ posts ) -> first ( ) ; }
Get the first Post that matches the current query . If no Post matches then return null .
59,517
public function toHtml ( ) { $ this -> setMeta ( "class" , "vf__notes" ) ; $ this -> setConditionalMeta ( ) ; $ strOutput = "<div{$this->__getMetaString()}>\n" ; if ( ! empty ( $ this -> __header ) ) { $ strOutput .= "<h4{$this->__getLabelMetaString()}>$this->__header</h4>\n" ; } if ( ! empty ( $ this -> __body ) ) { if ( preg_match ( "/<p.*?>/" , $ this -> __body ) > 0 ) { $ strOutput .= "{$this->__body}\n" ; } else { $ strOutput .= "<p>{$this->__body}</p>\n" ; } } $ strOutput .= "</div>\n" ; return $ strOutput ; }
Render the Note
59,518
public function addComparison ( $ varComparison ) { $ objComparison = null ; if ( is_array ( $ varComparison ) ) { $ varArguments = array_keys ( $ varComparison ) ; if ( isset ( $ varComparison [ "subject" ] ) ) { $ varArguments = array_values ( $ varComparison ) ; } try { $ objReflection = new \ ReflectionClass ( "Comparison" ) ; $ objComparison = $ objReflection -> newInstanceArgs ( $ varArguments ) ; } catch ( \ Exception $ e ) { throw new \ Exception ( "Failed to add Comparison: " . $ e -> getMessage ( ) , 1 ) ; } if ( is_object ( $ objComparison ) ) { array_push ( $ this -> __comparisons , $ objComparison ) ; } else { throw new \ InvalidArgumentException ( "No valid comparison data supplied in addComparison() method." , 1 ) ; } } elseif ( is_object ( $ varComparison ) && get_class ( $ varComparison ) === "ValidFormBuilder\\Comparison" ) { array_push ( $ this -> __comparisons , $ varComparison ) ; } else { throw new \ InvalidArgumentException ( "No valid comparison data supplied in addComparison() method." , 1 ) ; } }
Add new comparison to Condition
59,519
public function isMet ( $ intDynamicPosition = 0 ) { $ blnResult = false ; switch ( $ this -> __comparisontype ) { default : case ValidForm :: VFORM_MATCH_ANY : foreach ( $ this -> __comparisons as $ objComparison ) { if ( $ objComparison -> check ( $ intDynamicPosition ) ) { $ blnResult = true ; break ; } } break ; case ValidForm :: VFORM_MATCH_ALL : $ blnFailed = false ; foreach ( $ this -> __comparisons as $ objComparison ) { if ( ! $ objComparison -> check ( $ intDynamicPosition ) ) { $ blnFailed = true ; break ; } } $ blnResult = ! $ blnFailed ; break ; } return $ blnResult ; }
Verify if the condition is met
59,520
public function jsonSerialize ( $ intDynamicPosition = null ) { if ( get_class ( $ this -> __subject ) == "ValidFormBuilder\\GroupField" || get_class ( $ this -> __subject ) == "ValidFormBuilder\\Area" ) { $ identifier = $ this -> __subject -> getId ( ) ; } elseif ( get_class ( $ this -> __subject ) == "ValidFormBuilder\\StaticText" ) { $ identifier = $ this -> __subject -> getMeta ( "id" ) ; } else { $ identifier = $ this -> __subject -> getName ( ) ; if ( $ intDynamicPosition > 0 ) { $ identifier = $ identifier . "_" . $ intDynamicPosition ; } } $ arrReturn = array ( "subject" => $ identifier , "property" => $ this -> __property , "value" => $ this -> __value , "comparisonType" => $ this -> __comparisontype , "comparisons" => array ( ) ) ; foreach ( $ this -> __comparisons as $ objComparison ) { array_push ( $ arrReturn [ "comparisons" ] , $ objComparison -> jsonSerialize ( ) ) ; } return $ arrReturn ; }
toJson method creates an array representation of the current condition object and all of it s comparions .
59,521
public function setLimit ( int $ limit ) { $ this -> limit = $ limit ; if ( $ this -> limit < $ this -> batchSize ) { $ this -> batchSize = $ this -> limit ; } return $ this ; }
Limit of fake generated records for updates and creates
59,522
protected function whatToDoWithEntity ( ) : int { $ this -> checkEntityIsInConfig ( ) ; $ entityConfig = $ this -> configEntities [ $ this -> entity ] ; $ actions = 0 ; if ( array_key_exists ( 'cols' , $ entityConfig ) ) { switch ( $ entityConfig [ 'action' ] ) { case 'update' : $ actions |= self :: UPDATE_TABLE ; break ; case 'insert' : $ actions |= self :: INSERT_TABLE ; break ; } } return $ actions ; }
Evaluate from the configuration if I have to update or Truncate the table
59,523
protected function generateFakeData ( ) : array { $ this -> checkEntityIsInConfig ( ) ; $ colsInConfig = $ this -> configEntities [ $ this -> entity ] [ 'cols' ] ; $ row = [ ] ; foreach ( $ colsInConfig as $ colName => $ colProps ) { $ this -> checkColIsInEntity ( $ colName ) ; $ data = \ call_user_func_array ( [ $ this -> getFakerObject ( $ this -> entity , $ colName , $ colProps ) , $ colProps [ 'method' ] ] , $ colProps [ 'params' ] ) ; if ( ! is_scalar ( $ data ) ) { $ msg = "You must use faker methods that generate strings: '{$colProps['method']}' forbidden" ; throw new NeuralyzerConfigurationException ( $ msg ) ; } $ row [ $ colName ] = trim ( $ data ) ; $ colLength = $ this -> entityCols [ $ colName ] [ 'length' ] ; if ( ! empty ( $ colLength ) && \ strlen ( $ row [ $ colName ] ) > $ colLength ) { $ row [ $ colName ] = substr ( $ row [ $ colName ] , 0 , $ colLength - 1 ) ; } } return $ row ; }
Generate fake data for an entity and return it as an Array
59,524
protected function checkEntityIsInConfig ( ) : void { if ( empty ( $ this -> configEntities ) ) { throw new NeuralyzerConfigurationException ( 'No entities found. Have you loaded a configuration file ?' ) ; } if ( ! array_key_exists ( $ this -> entity , $ this -> configEntities ) ) { throw new NeuralyzerConfigurationException ( "No configuration for that entity ({$this->entity})" ) ; } }
Make sure that entity is defined in the configuration
59,525
protected function initFaker ( ) : void { $ language = $ this -> configuration -> getConfigValues ( ) [ 'language' ] ; $ this -> faker = \ Faker \ Factory :: create ( $ language ) ; $ this -> faker -> addProvider ( new \ Edyan \ Neuralyzer \ Faker \ Provider \ Base ( $ this -> faker ) ) ; $ this -> faker -> addProvider ( new \ Edyan \ Neuralyzer \ Faker \ Provider \ UniqueWord ( $ this -> faker , $ language ) ) ; }
Init Faker and add additional methods
59,526
protected function getFakerObject ( string $ entityName , string $ colName , array $ colProps ) { if ( ! isset ( $ this -> fakers [ $ entityName ] [ $ colName ] ) ) { $ fakerClone = clone $ this -> faker ; $ this -> fakers [ $ entityName ] [ $ colName ] = isset ( $ colProps [ 'unique' ] ) && $ colProps [ 'unique' ] === true ? $ fakerClone -> unique ( ) : $ fakerClone ; } return $ this -> fakers [ $ entityName ] [ $ colName ] ; }
Get the faker object for a entity column
59,527
public function getId ( ) { return ( strpos ( $ this -> __id , "[]" ) !== false ) ? str_replace ( "[]" , "" , $ this -> __id ) : $ this -> __id ; }
Get element s ID
59,528
public function getName ( $ blnPlain = false ) { $ strReturn = "" ; if ( $ blnPlain ) { $ strReturn = $ this -> __name ; } else { switch ( $ this -> __type ) { case ValidForm :: VFORM_RADIO_LIST : $ strReturn = $ this -> __name ; break ; case ValidForm :: VFORM_CHECK_LIST : $ strReturn = ( strpos ( $ this -> __name , "[]" ) === false ) ? $ this -> __name . "[]" : $ this -> __name ; break ; } } return $ strReturn ; }
Get the element s name
59,529
public function addField ( $ label , $ value , $ checked = false , $ meta = array ( ) ) { $ name = $ this -> getName ( ) ; $ objField = new GroupField ( $ this -> getRandomId ( $ name ) , $ name , $ this -> __type , $ label , $ value , $ checked , $ meta ) ; $ objField -> setMeta ( "parent" , $ this , true ) ; $ this -> __fields -> addObject ( $ objField ) ; if ( $ checked ) { switch ( $ this -> __type ) { case ValidForm :: VFORM_CHECK_LIST : $ arrDefault = ( is_array ( $ this -> __default ) ) ? $ this -> __default : array ( $ this -> __default ) ; $ arrDefault [ ] = $ value ; $ this -> __default = $ arrDefault ; break ; default : $ this -> __default = $ value ; } } return $ objField ; }
Add either a radio button or checkbox to the group
59,530
public function init ( ) { $ this -> initSession ( ) ; $ this -> session = null === $ _SESSION ? array ( ) : $ _SESSION ; if ( NULL === $ this -> getSessionKey ( '__FLASH_CLEAR__' ) ) { $ this -> clearFlashes ( ) ; $ this -> setSessionKey ( '__FLASH_CLEAR__' , microtime ( TRUE ) ) ; } $ this -> user = array_key_exists ( self :: USER_ID_TOKEN , $ this -> session ) ? unserialize ( $ this -> session [ self :: USER_ID_TOKEN ] ) : NULL ; $ this -> admin = array_key_exists ( self :: ADMIN_ID_TOKEN , $ this -> session ) ? unserialize ( $ this -> session [ self :: ADMIN_ID_TOKEN ] ) : NULL ; if ( null === $ this -> admin ) { $ this -> checkAdmin ( ) ; } $ this -> setLoaded ( true ) ; }
Constructor por defecto
59,531
public function addButton ( $ label , $ meta = array ( ) ) { $ objButton = new Button ( $ label , $ meta ) ; $ objButton -> setMeta ( "parent" , $ this , true ) ; $ this -> __fields -> addObject ( $ objButton ) ; return $ objButton ; }
Add a button to the navigation object
59,532
public function addHtml ( $ html , $ meta = array ( ) ) { $ objString = new StaticText ( $ html , $ meta ) ; $ objString -> setMeta ( "parent" , $ this , true ) ; $ this -> __fields -> addObject ( $ objString ) ; return $ objString ; }
Inject HTML in the navigation element
59,533
public function toHtml ( $ submitted = false , $ blnSimpleLayout = false , $ blnLabel = true , $ blnDisplayError = true ) { $ this -> setConditionalMeta ( ) ; $ this -> setMeta ( "class" , "vf__navigation" ) ; $ strReturn = "<div{$this->__getMetaString()}>\n" ; foreach ( $ this -> __fields as $ field ) { $ strReturn .= $ field -> toHtml ( $ submitted , $ blnSimpleLayout , $ blnLabel , $ blnDisplayError ) ; } $ strReturn .= "</div>\n" ; return $ strReturn ; }
Render the Navigation and it s children
59,534
public static function getFlash ( $ key ) { $ var = Security :: getInstance ( ) -> getFlash ( $ key ) ; Security :: getInstance ( ) -> setFlash ( $ key , null ) ; return $ var ; }
Template function that get a flash session var
59,535
protected function getToken ( $ requestToken ) { $ prefix = $ this -> options [ 'token_prefix' ] ; if ( null === $ prefix ) { return $ requestToken ; } if ( null === $ requestToken ) { return $ requestToken ; } $ requestToken = trim ( str_replace ( $ prefix , "" , $ requestToken ) ) ; return $ requestToken ; }
Convert token with prefix to normal token
59,536
public function cacheSubscribers ( $ num = 1000 , $ page = 1 ) { if ( $ this -> cached != null ) { return $ this -> cached ; } $ this -> cached = $ this -> client -> call ( 'GET' , 'subscribers' , [ 'query' => [ 'per_page' => $ num , 'current_page' => $ page , ] , ] ) ; return $ this -> cached ; }
Cache Subscribers for performance improvement .
59,537
public function indexSubscribers ( $ num = 1000 , $ page = 1 ) { if ( $ this -> cache != false ) { return $ this -> cacheSubscribers ( $ num , $ page ) ; } return $ this -> client -> call ( 'GET' , 'subscribers' , [ 'query' => [ 'per_page' => $ num , 'current_page' => $ page , ] , ] ) ; }
Get a defined number of Subscribers .
59,538
public function searchSubscribers ( $ search , $ by , $ limit = 1 , $ num = 1000 , $ page = 1 ) { $ subscribers = $ this -> indexSubscribers ( $ num , $ page ) [ 'data' ] ; $ filtered = array_filter ( $ subscribers , function ( $ subscriber ) use ( $ search , $ by ) { if ( array_key_exists ( $ by , $ subscriber ) ) { if ( strpos ( $ subscriber [ $ by ] , $ search ) !== false ) { return $ subscriber ; } if ( $ subscriber [ $ by ] === $ search ) { return $ subscriber ; } } return false ; } ) ; if ( $ limit == 1 ) { return array_shift ( $ filtered ) ; } return array_slice ( $ filtered , 0 , $ limit ) ; }
Search if a defined number of Subscribers exists .
59,539
public function getDomain ( ) { $ model = explode ( "\\" , $ this -> getModelNamespace ( ) ) ; return strlen ( $ model [ 0 ] ) || 1 === count ( $ model ) ? $ model [ 0 ] : $ model [ 1 ] ; }
Method that extract the Domain name
59,540
protected function hydrateFromRequest ( ) { $ class = new \ ReflectionClass ( $ this -> getModelNamespace ( ) ) ; $ this -> model = $ class -> newInstance ( ) ; $ this -> hydrateModelFromRequest ( $ this -> model , $ this -> data ) ; }
Hydrate fields from request
59,541
protected function hydrateBulkRequest ( ) { $ class = new \ ReflectionClass ( $ this -> getModelNamespace ( ) ) ; $ this -> list = [ ] ; foreach ( $ this -> data as $ item ) { if ( is_array ( $ item ) ) { if ( count ( $ this -> list ) < Config :: getParam ( 'api.block.limit' , 1000 ) ) { $ model = $ class -> newInstance ( ) ; $ this -> hydrateModelFromRequest ( $ model , $ item ) ; $ this -> list [ ] = $ model ; } else { Logger :: log ( t ( 'Max items per bulk insert raised' ) , LOG_WARNING , count ( $ this -> data ) . t ( 'items' ) ) ; } } } }
Hydrate list elements for bulk insert
59,542
protected function saveBulk ( ) { $ tablemap = $ this -> getTableMap ( ) ; foreach ( $ this -> list as & $ model ) { $ con = Propel :: getWriteConnection ( $ tablemap :: DATABASE_NAME ) ; try { $ model -> save ( $ con ) ; $ con -> commit ( ) ; } catch ( \ Exception $ e ) { Logger :: log ( $ e -> getMessage ( ) , LOG_ERR , $ model -> toArray ( ) ) ; $ con -> rollBack ( ) ; } } }
Save the list of items
59,543
protected function hydrateModel ( $ primaryKey ) { try { $ query = $ this -> prepareQuery ( ) ; $ this -> model = $ this -> findPk ( $ query , $ primaryKey ) ; } catch ( \ Exception $ e ) { Logger :: log ( get_class ( $ this ) . ': ' . $ e -> getMessage ( ) , LOG_ERR ) ; } }
Hydrate model from pk
59,544
protected function _get ( $ primaryKey ) { $ this -> hydrateModel ( $ primaryKey ) ; return ( $ this -> getModel ( ) instanceof ActiveRecordInterface ) ? $ this -> getModel ( ) : NULL ; }
Extract specific entity
59,545
public function json ( $ response , $ status = 200 ) { $ this -> closeTransaction ( $ status ) ; return $ this -> _json ( $ response , $ status ) ; }
Wrapper for json parent method with close transactions and close connections tasks
59,546
protected function getModelNamespace ( ) { $ tableMap = $ this -> getModelTableMap ( ) ; return ( null !== $ tableMap ) ? $ tableMap :: getOMClass ( FALSE ) : null ; }
Extract model api namespace
59,547
protected function addDefaultListField ( ) { if ( ! in_array ( Api :: API_LIST_NAME_FIELD , array_values ( $ this -> extraColumns ) ) ) { $ tableMap = $ this -> getTableMap ( ) ; $ column = null ; if ( $ tableMap -> hasColumn ( 'NAME' ) ) { $ column = $ tableMap -> getColumn ( 'NAME' ) ; } elseif ( $ tableMap -> hasColumn ( 'TITLE' ) ) { $ column = $ tableMap -> getColumn ( 'TITLE' ) ; } elseif ( $ tableMap -> hasColumn ( 'LABEL' ) ) { $ column = $ tableMap -> getColumn ( 'LABEL' ) ; } if ( null !== $ column ) { $ this -> extraColumns [ $ column -> getFullyQualifiedName ( ) ] = Api :: API_LIST_NAME_FIELD ; } else { $ this -> addClassListName ( $ tableMap ) ; } } }
Method that add a new field with the Label of the row
59,548
public function getOnce ( $ key , $ default = null ) { $ read = $ this -> get ( $ key , $ default ) ; $ this -> delete ( $ key ) ; return $ read ; }
Read a value from the session and unset it this is a form of read once flash memory using the session .
59,549
public function addParagraph ( $ strBody , $ strHeader = "" , $ meta = array ( ) ) { $ objParagraph = new Paragraph ( $ strHeader , $ strBody , $ meta ) ; $ objParagraph -> setMeta ( "parent" , $ this , true ) ; $ this -> __fields -> addObject ( $ objParagraph ) ; return $ objParagraph ; }
Add paragraph to Area
59,550
public function addMultiField ( $ label = null , $ meta = array ( ) ) { if ( ! array_key_exists ( "dynamic" , $ meta ) ) { $ meta [ "dynamic" ] = $ this -> __dynamic ; } if ( $ this -> __dynamic ) { $ meta [ "dynamic" ] = $ this -> __dynamic ; $ meta [ "dynamicLabel" ] = "" ; } $ objField = new MultiField ( $ label , $ meta ) ; $ objField -> setRequiredStyle ( $ this -> __requiredstyle ) ; $ objField -> setMeta ( "parent" , $ this , true ) ; $ this -> __fields -> addObject ( $ objField ) ; return $ objField ; }
Add a multifield to the Area
59,551
public function hasContent ( $ intCount = 0 ) { $ blnReturn = false ; foreach ( $ this -> __fields as $ objField ) { if ( get_class ( $ objField ) !== "ValidFormBuilder\\Hidden" || get_class ( $ objField ) !== "ValidFormBuilder\\Paragraph" ) { if ( get_class ( $ objField ) == "ValidFormBuilder\\MultiField" ) { $ blnReturn = $ objField -> hasContent ( $ intCount ) ; if ( $ blnReturn ) { break ; } } else { if ( $ objField instanceof Element ) { $ varValue = $ objField -> getValidator ( ) -> getValue ( $ intCount ) ; if ( ! empty ( $ varValue ) ) { $ blnReturn = true ; break ; } } } } } return $ blnReturn ; }
Verify if any of the child fields in this area has submitted data
59,552
protected function getDynamicHtml ( $ intCount = 0 ) { $ strReturn = "" ; if ( $ this -> __dynamic && ! empty ( $ this -> __dynamicLabel ) ) { $ arrFields = array ( ) ; foreach ( $ this -> __fields as $ field ) { switch ( get_class ( $ field ) ) { case "ValidFormBuilder\\MultiField" : foreach ( $ field -> getFields ( ) as $ subField ) { if ( ( get_class ( $ subField ) == "ValidFormBuilder\\Hidden" ) && $ subField -> isDynamicCounter ( ) ) { continue ; } if ( ! empty ( $ field -> getName ( ) ) ) { $ arrFields [ $ subField -> getId ( ) ] = $ subField -> getName ( ) ; } } break ; default : if ( ( get_class ( $ field ) == "ValidFormBuilder\\Hidden" ) && $ field -> isDynamicCounter ( ) ) { continue ; } if ( ! empty ( $ field -> getName ( ) ) ) { $ arrFields [ $ field -> getId ( ) ] = $ field -> getName ( ) ; } break ; } } $ areaName = ( $ intCount == 0 ) ? $ this -> getName ( ) : $ this -> getName ( ) . "_" . $ intCount ; if ( $ this -> __active ) { $ arrFields [ $ areaName ] = $ areaName ; } $ strReturn .= "<div class=\"vf__dynamic\"{$this->getDynamicButtonMeta()}>" ; $ strReturn .= "<a href=\"#\" data-target-id=\"" . implode ( "|" , array_keys ( array_filter ( $ arrFields ) ) ) . "\" data-target-name=\"" . implode ( "|" , array_values ( array_filter ( $ arrFields ) ) ) . "\"{$this->__getDynamicLabelMetaString()}>{$this->__dynamicLabel}</a>" ; $ strReturn .= "</div>" ; } return $ strReturn ; }
Generate extra HTML output to facilitate the dynamic duplication logic
59,553
public function toJS ( $ intDynamicPosition = 0 ) { $ strReturn = "" ; foreach ( $ this -> __fields as $ field ) { $ strReturn .= $ field -> toJS ( $ this -> __dynamic ) ; } $ strReturn .= $ this -> conditionsToJs ( $ intDynamicPosition ) ; return $ strReturn ; }
Generate Javascript code .
59,554
public function isValid ( ) { $ blnReturn = true ; $ intDynamicCount = $ this -> getDynamicCount ( ) ; for ( $ intCount = 0 ; $ intCount <= $ intDynamicCount ; $ intCount ++ ) { $ blnReturn = $ this -> __validate ( $ intCount ) ; if ( ! $ blnReturn ) { break ; } } return $ blnReturn ; }
Verify if all submitted data of this area and it s children is valid .
59,555
public function getDynamicCount ( ) { $ intReturn = 0 ; if ( $ this -> __dynamic ) { $ objCounters = $ this -> getCountersRecursive ( $ this -> getFields ( ) ) ; foreach ( $ objCounters as $ objCounter ) { $ intCounterValue = $ objCounter -> getValidator ( ) -> getValue ( ) ; if ( $ intCounterValue > $ intReturn ) { $ intReturn = $ intCounterValue ; } } if ( $ intReturn > 0 ) { foreach ( $ objCounters as $ objCounter ) { $ objCounter -> setDefault ( $ intReturn ) ; } } } return $ intReturn ; }
Get the dynamic counter value if this is an dynamic area .
59,556
public function getValue ( $ intCount = null ) { $ strName = ( $ intCount > 0 ) ? $ this -> __name . "_" . $ intCount : $ this -> __name ; $ value = ValidForm :: get ( $ strName ) ; return ( ( $ this -> __active && ! empty ( $ value ) ) || ! $ this -> __active ) ? true : false ; }
If this is an active area this will return the value of the checkbox .
59,557
private function __validate ( $ intCount = null ) { $ blnReturn = true ; foreach ( $ this -> __fields as $ field ) { if ( ! $ field -> isValid ( $ intCount ) ) { $ blnReturn = false ; break ; } } if ( $ this -> __active && ! $ this -> hasContent ( $ intCount ) ) { $ blnReturn = true ; } return $ blnReturn ; }
Validate this Area and it s children s submitted values
59,558
public function regenerateTemplates ( ) { $ this -> generateTemplatesCache ( ) ; $ domains = Cache :: getInstance ( ) -> getDataFromFile ( CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json' , Cache :: JSON , true ) ; $ translations = [ ] ; if ( is_array ( $ domains ) ) { $ translations = $ this -> parsePathTranslations ( $ domains ) ; } $ translations [ ] = t ( 'Plantillas regeneradas correctamente' ) ; return $ translations ; }
Servicio que regenera todas las plantillas
59,559
private function loadDomains ( ) { $ domains = Cache :: getInstance ( ) -> getDataFromFile ( CONFIG_DIR . DIRECTORY_SEPARATOR . 'domains.json' , Cache :: JSON , true ) ; if ( null !== $ domains ) { foreach ( $ domains as $ domain => $ paths ) { $ this -> addPath ( $ paths [ 'template' ] , preg_replace ( '/(@|\/)/' , '' , $ domain ) ) ; } } }
Method that extract all domains for using them with the templates
59,560
private function generateTemplatesCache ( ) { $ loader = $ this -> tpl -> getLoader ( ) ; $ availablePaths = $ loader -> getPaths ( ) ; if ( ! empty ( $ availablePaths ) ) { foreach ( $ availablePaths as $ path ) { $ this -> generateTemplate ( $ path ) ; } } }
Method that generate all template caches
59,561
public function setLetterType ( $ letterType ) : PostageInfo { if ( ! in_array ( $ letterType , Envelope :: getLetterTypeOptions ( ) ) ) { throw new InvalidArgumentException ( sprintf ( 'Property %s is not supported for %s' , $ letterType , __FUNCTION__ ) ) ; } $ this -> letter [ 'type' ] = $ letterType ; return $ this ; }
Set the letter type
59,562
public static function generateTranslationsFile ( $ absoluteTranslationFileName ) { $ translations = array ( ) ; if ( file_exists ( $ absoluteTranslationFileName ) ) { @ include ( $ absoluteTranslationFileName ) ; } else { Cache :: getInstance ( ) -> storeData ( $ absoluteTranslationFileName , "<?php \$translations = array();\n" , Cache :: TEXT , TRUE ) ; } return $ translations ; }
Create translation file if not exists
59,563
public static function setLocale ( $ default = null ) { $ locale = self :: extractLocale ( $ default ) ; Logger :: log ( 'Set locale to project [' . $ locale . ']' ) ; putenv ( "LC_ALL=" . $ locale ) ; setlocale ( LC_ALL , $ locale ) ; $ locale_path = BASE_DIR . DIRECTORY_SEPARATOR . 'locale' ; Logger :: log ( 'Set locale dir ' . $ locale_path ) ; GeneratorHelper :: createDir ( $ locale_path ) ; bindtextdomain ( 'translations' , $ locale_path ) ; textdomain ( 'translations' ) ; bind_textdomain_codeset ( 'translations' , 'UTF-8' ) ; Security :: getInstance ( ) -> setSessionKey ( I18nHelper :: PSFS_SESSION_LANGUAGE_KEY , substr ( $ locale , 0 , 2 ) ) ; }
Method to set the locale
59,564
public function map ( array $ verbs , string $ uri , $ callback ) : Route { if ( $ this -> isControllerString ( $ callback ) ) { $ callback = $ this -> normaliseCallbackString ( $ callback ) ; } return parent :: map ( $ verbs , $ uri , $ callback ) ; }
Map a router action to a set of Http verbs and a URI
59,565
private function normaliseCallbackString ( string $ callback ) : string { @ list ( $ controller , $ method ) = explode ( '@' , $ callback ) ; if ( class_exists ( $ this -> defaultControllerNamespace . $ controller ) ) { return $ this -> defaultControllerNamespace . $ callback ; } return $ callback ; }
Add the default namespace to the Controller classname if required
59,566
public function mapCol ( string $ table , string $ name , string $ type , string $ len = null ) : array { $ colsName = $ this -> getColsNameMapping ( ) ; foreach ( $ colsName as $ colRegex => $ params ) { preg_match ( "/^$colRegex\$/i" , $ table . '.' . $ name , $ matches ) ; if ( ! empty ( $ matches ) ) { return $ params ; } } if ( $ type === 'enum' ) { return [ 'method' => 'randomElement' , 'params' => [ explode ( "','" , substr ( $ len , 1 , - 1 ) ) ] ] ; } $ colsType = $ this -> getColsTypeMapping ( $ len ) ; if ( ! array_key_exists ( $ type , $ colsType ) ) { $ msg = "Can't guess the type $type ({$table}.{$name})" ; throw new NeuralyzerGuesserException ( $ msg ) ; } return $ colsType [ $ type ] ; }
Will map cols first by looking for field name then by looking for field type if the first returned nothing
59,567
public function addField ( $ label , $ value , $ selected = false , $ meta = array ( ) ) { $ objOption = new SelectOption ( $ label , $ value , $ selected , $ meta ) ; $ objOption -> setMeta ( "parent" , $ this , true ) ; $ this -> __options -> addObject ( $ objOption ) ; return $ objOption ; }
Add option element
59,568
public function addGroup ( $ label ) { $ objGroup = new SelectGroup ( $ label ) ; $ objGroup -> setMeta ( "parent" , $ this , true ) ; $ this -> __options -> addObject ( $ objGroup ) ; return $ objGroup ; }
Add optgroup element
59,569
public static function compareSlashes ( $ routePattern , $ path ) { $ patternSeparator = count ( explode ( '/' , $ routePattern ) ) ; if ( preg_match ( '/\/$/' , $ routePattern ) ) { $ patternSeparator -- ; } $ routePattern = preg_replace ( '/\/\{.*\}$/' , '' , $ routePattern ) ; $ cleanPatternSeparator = count ( explode ( '/' , $ routePattern ) ) ; if ( preg_match ( '/\/$/' , $ routePattern ) ) { $ cleanPatternSeparator -- ; } $ path_sep = count ( explode ( '/' , $ path ) ) ; if ( preg_match ( '/\/$/' , $ path ) ) { $ path_sep -- ; } return abs ( $ patternSeparator - $ path_sep ) < 1 || abs ( $ cleanPatternSeparator - $ path_sep ) < 1 ; }
Function that checks if the long of the patterns match
59,570
public static function getDBHelper ( string $ driver ) : string { $ drivers = [ 'pdo_mysql' => MySQL :: class , 'mysql' => MySQL :: class , 'mysql2' => MySQL :: class , 'pdo_pgsql' => PostgreSQL :: class , 'pgsql' => PostgreSQL :: class , 'postgres' => PostgreSQL :: class , 'postgresql' => PostgreSQL :: class , 'pdo_sqlsrv' => SQLServer :: class , 'mssql' => SQLServer :: class , ] ; if ( ! array_key_exists ( $ driver , $ drivers ) ) { throw new \ InvalidArgumentException ( "$driver unknown" ) ; } return $ drivers [ $ driver ] ; }
Find the right local driver from a php extension
59,571
public function evaluateExpression ( string $ expression ) { $ expressionLanguage = new ExpressionLanguage ( ) ; return $ expressionLanguage -> evaluate ( $ expression , $ this -> services ) ; }
Evaluate an expression that would be in the most general case an action coming from an Anonymization config
59,572
public function evaluateExpressions ( array $ expressions ) : array { $ res = [ ] ; foreach ( $ expressions as $ expression ) { $ res [ ] = $ this -> evaluateExpression ( $ expression ) ; } return $ res ; }
Evaluate a list of expression
59,573
private function configure ( ) : void { $ services = array_keys ( $ this -> container -> findTaggedServiceIds ( 'app.service' ) ) ; foreach ( $ services as $ service ) { $ service = $ this -> container -> get ( $ service ) ; $ this -> services [ $ service -> getName ( ) ] = $ service ; } }
Configure that service by registering all services in an array
59,574
public function phar ( $ opts = [ 'neuralyzer-version' => 'dev' ] ) { if ( ( int ) ini_get ( 'phar.readonly' ) === 1 ) { throw new \ RuntimeException ( 'You must have phar.readonly = 1 or run' . PHP_EOL . 'php -d phar.readonly=0 vendor/bin/robo (phar|release)' ) ; } $ collection = $ this -> collectionBuilder ( ) ; $ workDir = $ collection -> tmpDir ( ) ; $ buildDir = "$workDir/neuralyzer" ; $ prepTasks = $ this -> collectionBuilder ( ) ; $ preparationResult = $ prepTasks -> taskFilesystemStack ( ) -> mkdir ( $ workDir ) -> taskCopyDir ( [ __DIR__ . '/src' => $ buildDir . '/src' ] ) -> taskFilesystemStack ( ) -> copy ( __DIR__ . '/bin/neuralyzer' , $ buildDir . '/bin/neuralyzer' ) -> copy ( __DIR__ . '/composer.json' , $ buildDir . '/composer.json' ) -> copy ( __DIR__ . '/composer.lock' , $ buildDir . '/composer.lock' ) -> copy ( __DIR__ . '/LICENSE' , $ buildDir . '/LICENSE' ) -> copy ( __DIR__ . '/README.md' , $ buildDir . '/README.md' ) -> taskComposerInstall ( ) -> dir ( $ buildDir ) -> noDev ( ) -> noScripts ( ) -> printOutput ( true ) -> optimizeAutoloader ( ) -> run ( ) ; if ( ! $ preparationResult -> wasSuccessful ( ) ) { return $ preparationResult ; } $ currentVersion = \ Edyan \ Neuralyzer \ Console \ Application :: VERSION ; $ this -> say ( "Setting version number to {$opts['neuralyzer-version']}" ) ; $ this -> taskReplaceInFile ( $ buildDir . '/src/Console/Application.php' ) -> from ( "const VERSION = '$currentVersion';" ) -> to ( "const VERSION = '{$opts['neuralyzer-version']}';" ) -> run ( ) ; $ this -> say ( "Force Robo to compress up to 1500 files in a phar" ) ; $ this -> taskReplaceInFile ( __DIR__ . '/vendor/consolidation/robo/src/Task/Development/PackPhar.php' ) -> from ( 'if (count($this->files) > 1000)' ) -> to ( 'if (count($this->files) > 1500)' ) -> run ( ) ; $ files = \ Symfony \ Component \ Finder \ Finder :: create ( ) -> ignoreVCS ( true ) -> files ( ) -> name ( '*.php' ) -> name ( '*.exe' ) -> path ( 'src' ) -> path ( 'vendor' ) -> notPath ( 'docs' ) -> notPath ( '/vendor\/.*\/[Tt]est/' ) -> in ( is_dir ( $ buildDir ) ? $ buildDir : __DIR__ ) ; $ fakerLang = \ Symfony \ Component \ Finder \ Finder :: create ( ) -> ignoreVCS ( true ) -> files ( ) -> name ( '*' ) -> path ( 'src/Faker/Dictionary' ) -> in ( is_dir ( $ buildDir ) ? $ buildDir : __DIR__ ) ; return $ collection -> taskPackPhar ( 'neuralyzer.phar' ) -> compress ( ) -> addFile ( 'bin/neuralyzer' , 'bin/neuralyzer' ) -> addFile ( 'config/services.yml' , 'config/services.yml' ) -> addFiles ( $ files ) -> addFiles ( $ fakerLang ) -> executable ( 'bin/neuralyzer' ) -> taskFilesystemStack ( ) -> chmod ( __DIR__ . '/neuralyzer.phar' , 0755 ) -> run ( ) ; }
Build an executable phar
59,575
private function anonymizeTable ( string $ table ) : bool { $ total = $ this -> getTotal ( $ table ) ; if ( $ total === 0 ) { $ this -> output -> writeln ( "<info>$table is empty</info>" ) ; return true ; } $ bar = new ProgressBar ( $ this -> output , $ total ) ; $ bar -> setRedrawFrequency ( $ total > 100 ? 100 : 0 ) ; $ this -> output -> writeln ( "<info>Anonymizing $table</info>" ) ; try { $ queries = $ this -> db -> setLimit ( $ total ) -> processEntity ( $ table , function ( ) use ( $ bar ) { $ bar -> advance ( ) ; } ) ; } catch ( \ Exception $ e ) { $ msg = "<error>Error anonymizing $table. Message was : " . $ e -> getMessage ( ) . "</error>" ; $ this -> output -> writeln ( PHP_EOL . $ msg . PHP_EOL ) ; return false ; } $ this -> output -> writeln ( PHP_EOL ) ; if ( $ this -> input -> getOption ( 'sql' ) ) { $ this -> output -> writeln ( '<comment>Queries:</comment>' ) ; $ this -> output -> writeln ( implode ( PHP_EOL , $ queries ) ) ; $ this -> output -> writeln ( PHP_EOL ) ; } return true ; }
Anonymize a specific table and display info about the job
59,576
private function getTotal ( string $ table ) : int { $ config = $ this -> reader -> getEntityConfig ( $ table ) ; $ limit = ( int ) $ config [ 'limit' ] ; if ( $ config [ 'action' ] === 'insert' ) { return empty ( $ limit ) ? 100 : $ limit ; } $ rows = $ this -> dbUtils -> countResults ( $ table ) ; if ( empty ( $ limit ) ) { return $ rows ; } if ( ! empty ( $ limit ) && $ limit > $ rows ) { return $ rows ; } return $ limit ; }
Define the total number of records to process for progress bar
59,577
protected function setClass ( $ type , & $ meta ) { switch ( $ type ) { case ValidForm :: VFORM_STRING : $ this -> setFieldMeta ( "class" , "vf__string" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_WORD : $ this -> setFieldMeta ( "class" , "vf__word" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_EMAIL : $ this -> setFieldMeta ( "class" , "vf__email" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_URL : case ValidForm :: VFORM_SIMPLEURL : $ this -> setFieldMeta ( "class" , "vf__url" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_CUSTOM : $ this -> setFieldMeta ( "class" , "vf__custom" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_CURRENCY : $ this -> setFieldMeta ( "class" , "vf__currency" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_DATE : $ this -> setFieldMeta ( "class" , "vf__date" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_NUMERIC : $ this -> setFieldMeta ( "class" , "vf__numeric" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_INTEGER : $ this -> setFieldMeta ( "class" , "vf__integer" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_PASSWORD : $ this -> setFieldMeta ( "class" , "vf__password" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_HTML : $ this -> setFieldMeta ( "class" , "vf__html" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_CUSTOM_TEXT : $ this -> setFieldMeta ( "class" , "vf__custom" ) ; $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_TEXT : $ this -> setFieldMeta ( "class" , "vf__text" ) ; break ; case ValidForm :: VFORM_FILE : $ this -> setFieldMeta ( "class" , "vf__file" ) ; break ; case ValidForm :: VFORM_BOOLEAN : $ this -> setFieldMeta ( "class" , "vf__checkbox" ) ; break ; case ValidForm :: VFORM_RADIO_LIST : case ValidForm :: VFORM_CHECK_LIST : $ this -> setFieldMeta ( "class" , "vf__list" ) ; break ; case ValidForm :: VFORM_SELECT_LIST : if ( ! isset ( $ meta [ "multiple" ] ) ) { $ this -> setFieldMeta ( "class" , "vf__one" ) ; } else { $ this -> setFieldMeta ( "class" , "vf__multiple" ) ; } $ this -> setFieldMeta ( "class" , "vf__select" ) ; break ; } }
Set type class
59,578
public function __toHtml ( $ submitted = false , $ blnSimpleLayout = false , $ blnLabel = true , $ blnDisplayErrors = true , $ intCount = 0 ) { return $ this -> toHtml ( $ submitted , $ blnSimpleLayout , $ blnLabel , $ blnDisplayErrors ) ; }
Generate HTML output for specific dynamic count
59,579
public function getRandomId ( $ name ) { if ( strpos ( $ name , "[]" ) !== false ) { $ strReturn = str_replace ( "[]" , "_" . rand ( 100000 , 900000 ) , $ name ) ; } else { $ strReturn = $ name . "_" . rand ( 100000 , 900000 ) ; } return $ strReturn ; }
Generate a random ID for a given field name to prevent having two fields with the same name
59,580
public function getDynamicCount ( $ blnParentIsDynamic = false ) { $ intReturn = 0 ; if ( ( $ this -> __dynamic || $ blnParentIsDynamic ) && is_object ( $ this -> __dynamiccounter ) ) { $ intReturn = $ this -> __dynamiccounter -> getValidator ( ) -> getValue ( ) ; } return ( int ) $ intReturn ; }
Get the number of dynamic fields from the dynamic counter field .
59,581
protected function getDynamicHtml ( ) { $ strReturn = "" ; if ( $ this -> __dynamic && ! empty ( $ this -> __dynamicLabel ) ) { $ strReturn = "<div class=\"vf__dynamic\"><a href=\"#\" data-target-id=\"{$this->__id}\" " . "data-target-name=\"{$this->__name}\"{$this->__getDynamicLabelMetaString()}>" . $ this -> __dynamicLabel . "</a></div>\n" ; } return $ strReturn ; }
Render html element needed for dynamic duplication client - side
59,582
protected function sanitize ( $ varValue , $ sanitizations ) { if ( is_array ( $ sanitizations ) ) { foreach ( $ sanitizations as $ value ) { try { if ( is_string ( $ value ) ) { switch ( $ value ) { case "trim" : $ varValue = trim ( $ varValue ) ; break ; case "clear" : $ varValue = "" ; break ; } } elseif ( is_callable ( $ value ) ) { $ varValue = $ value ( $ varValue ) ; } } catch ( \ Exception $ ex ) { } } } return $ varValue ; }
Sanitize a value according to the order of actions in a sanitize array .
59,583
public function setName ( $ strName ) { parent :: setName ( $ strName ) ; if ( is_object ( $ this -> __validator ) ) { $ this -> __validator -> setFieldName ( $ strName ) ; } }
Set a new name for this element
59,584
public function getEntityConfig ( string $ entity ) : array { if ( ! array_key_exists ( $ entity , $ this -> configValues [ 'entities' ] ) ) { throw new \ InvalidArgumentException ( "$entity is not set in config" ) ; } return $ this -> configValues [ 'entities' ] [ $ entity ] ; }
Get config values for an entity
59,585
private function createModulePath ( $ module , $ mod_path ) { GeneratorHelper :: createDir ( $ mod_path ) ; GeneratorHelper :: createDir ( $ mod_path . $ module ) ; }
Service that creates the root paths for the modules
59,586
private function createModulePathTree ( $ module , $ mod_path ) { $ this -> log -> addLog ( "Generamos la estructura" ) ; $ paths = [ "Api" , "Api/base" , "Config" , "Controller" , "Models" , "Public" , "Templates" , "Services" , "Test" , "Doc" , "Locale" , "Locale/" . Config :: getParam ( 'default.locale' , 'es_ES' ) , "Locale/" . Config :: getParam ( 'default.locale' , 'es_ES' ) . "/LC_MESSAGES" ] ; $ module_path = $ mod_path . $ module ; foreach ( $ paths as $ path ) { GeneratorHelper :: createDir ( $ module_path . DIRECTORY_SEPARATOR . $ path ) ; } $ htmlPaths = array ( "css" , "js" , "img" , "media" , "font" ) ; foreach ( $ htmlPaths as $ path ) { GeneratorHelper :: createDir ( $ module_path . DIRECTORY_SEPARATOR . "Public" . DIRECTORY_SEPARATOR . $ path ) ; } }
Servicio que genera la estructura base
59,587
public static function copyResources ( $ dest , $ force , $ filename_path , $ debug ) { if ( file_exists ( $ filename_path ) ) { $ destfolder = basename ( $ filename_path ) ; if ( ! file_exists ( WEB_DIR . $ dest . DIRECTORY_SEPARATOR . $ destfolder ) || $ debug || $ force ) { if ( is_dir ( $ filename_path ) ) { self :: copyr ( $ filename_path , WEB_DIR . $ dest . DIRECTORY_SEPARATOR . $ destfolder ) ; } else { if ( @ copy ( $ filename_path , WEB_DIR . $ dest . DIRECTORY_SEPARATOR . $ destfolder ) === FALSE ) { throw new ConfigException ( "Can't copy " . $ filename_path . " to " . WEB_DIR . $ dest . DIRECTORY_SEPARATOR . $ destfolder ) ; } } } } }
Method that copy resources recursively
59,588
public static function copyr ( $ src , $ dst ) { $ dir = opendir ( $ src ) ; GeneratorHelper :: createDir ( $ dst ) ; while ( false !== ( $ file = readdir ( $ dir ) ) ) { if ( ( $ file != '.' ) && ( $ file != '..' ) ) { if ( is_dir ( $ src . '/' . $ file ) ) { self :: copyr ( $ src . '/' . $ file , $ dst . '/' . $ file ) ; } elseif ( @ copy ( $ src . '/' . $ file , $ dst . '/' . $ file ) === false ) { throw new ConfigException ( "Can't copy " . $ src . " to " . $ dst ) ; } } } closedir ( $ dir ) ; }
Method that copy a resource
59,589
public function decode ( $ token ) { try { $ data = JWT :: decode ( $ token , $ this -> secretKey , $ this -> allowed_algs ) ; } catch ( \ UnexpectedValueException $ e ) { throw new \ UnexpectedValueException ( $ e -> getMessage ( ) ) ; } catch ( \ DomainException $ e ) { throw new \ UnexpectedValueException ( $ e -> getMessage ( ) ) ; } if ( $ data -> exp < time ( ) ) { throw new \ UnexpectedValueException ( 'token not allowed' ) ; } return $ data ; }
Token for decoding
59,590
public function removeOrder ( $ fieldToRemove ) { $ order = array ( ) ; if ( count ( $ order ) > 0 ) { foreach ( $ this -> fields as $ field => $ direction ) { if ( strtolower ( $ fieldToRemove ) === strtolower ( $ field ) ) { continue ; } $ order [ $ field ] = $ direction ; } } $ this -> fields = $ order ; }
Remove existing order
59,591
public static function checkAndLoad ( string $ filename ) : string { $ includePathFilename = \ stream_resolve_include_path ( $ filename ) ; $ localFile = __DIR__ . DIRECTORY_SEPARATOR . $ filename ; $ isReadable = @ \ fopen ( $ includePathFilename , 'r' ) !== false ; if ( ! $ includePathFilename || ! $ isReadable || $ includePathFilename === $ localFile ) { throw new \ Exception ( \ sprintf ( 'Cannot open file "%s".' . "\n" , $ filename ) ) ; } require_once $ includePathFilename ; return $ includePathFilename ; }
Checks if a PHP source file is readable and loads it .
59,592
public function addObject ( $ value , $ blnAddToBeginning = false ) { if ( $ blnAddToBeginning ) { array_unshift ( $ this -> collection , $ value ) ; } else { array_push ( $ this -> collection , $ value ) ; } }
Add object to the collection
59,593
public function addObjectAtPosition ( $ value , $ intPosition ) { $ arrTempCollection = array ( ) ; $ intCount = 0 ; if ( $ intPosition >= $ this -> count ( ) ) { $ this -> addObject ( $ value ) ; } else { foreach ( $ this -> collection as $ varObject ) { if ( $ intCount == $ intPosition ) { array_push ( $ arrTempCollection , $ value ) ; } array_push ( $ arrTempCollection , $ varObject ) ; $ intCount ++ ; } $ this -> collection = $ arrTempCollection ; } }
Add object to the collection at a specified position
59,594
public function addObjects ( $ arrObjects , $ blnAddToBeginning = false ) { foreach ( $ arrObjects as $ varObject ) { $ this -> addObject ( $ varObject , $ blnAddToBeginning ) ; } }
Add objects to the collection
59,595
public function seek ( $ intPosition ) { if ( is_numeric ( $ intPosition ) && $ intPosition < count ( $ this -> collection ) ) { reset ( $ this -> collection ) ; while ( $ intPosition < key ( $ this -> collection ) ) { next ( $ this -> collection ) ; } } $ this -> isSeek = true ; }
Advance internal pointer to a specific index
59,596
public function random ( ) { $ objReturn = null ; $ intIndex = rand ( 0 , ( count ( $ this -> collection ) - 1 ) ) ; if ( isset ( $ this -> collection [ $ intIndex ] ) ) { $ objReturn = $ this -> collection [ $ intIndex ] ; } return $ objReturn ; }
Pick a random child element
59,597
public function getFirst ( ) { $ varReturn = null ; if ( count ( $ this -> collection ) > 0 ) { $ varReturn = $ this -> collection [ 0 ] ; } return $ varReturn ; }
Get first element in collection
59,598
public function getLast ( $ strType = "" ) { $ varReturn = null ; if ( count ( $ this -> collection ) > 0 ) { if ( ! empty ( $ strType ) ) { $ arrTemp = array_reverse ( $ this -> collection ) ; foreach ( $ arrTemp as $ object ) { if ( get_class ( $ object ) == $ strType ) { $ varReturn = $ object ; break ; } } } else { $ varReturn = $ this -> collection [ $ this -> count ( ) - 1 ] ; } } return $ varReturn ; }
Get last element in collection
59,599
public function merge ( $ collection ) { if ( is_object ( $ collection ) && $ collection -> count ( ) > 0 ) { $ this -> collection = array_merge ( $ this -> collection , $ collection -> collection ) ; } }
Merge a collection with this collection .