idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
10,400
|
public function setToken ( $ key , $ value , $ duration = 60 ) { $ this -> cache -> put ( 'reactor.tokens.' . $ key , $ value , $ duration ) ; }
|
Setter for token
|
10,401
|
public function makeNewToken ( $ key , $ duration = 60 ) { $ token = str_random ( 32 ) ; $ this -> setToken ( $ key , $ token , $ duration ) ; return $ token ; }
|
Creates a new token and returns it
|
10,402
|
public function requestHasToken ( $ key ) { $ token = $ this -> request -> input ( $ key , null ) ; if ( $ token && $ token === $ this -> getToken ( $ key ) ) { return true ; } return false ; }
|
Checks if the request has the token
|
10,403
|
public function setOrderStatusDetail ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Trading \ Order \ OrderStatusDetail $ orderStatusDetail = null ) { $ this -> order_status_detail = $ orderStatusDetail ; return $ this ; }
|
Set orderStatusDetail .
|
10,404
|
public function setCustomer ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Trading \ Order \ Customer \ Customer $ customer = null ) { $ this -> customer = $ customer ; return $ this ; }
|
Set customer .
|
10,405
|
public function setTrading ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Trading \ Trading $ trading = null ) { $ this -> trading = $ trading ; return $ this ; }
|
Set trading .
|
10,406
|
public function addShipping ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Trading \ Order \ Shipping \ Shipping $ shipping ) { $ this -> shippings [ ] = $ shipping ; return $ this ; }
|
Add shipping .
|
10,407
|
public function removeShipping ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Trading \ Order \ Shipping \ Shipping $ shipping ) { return $ this -> shippings -> removeElement ( $ shipping ) ; }
|
Remove shipping .
|
10,408
|
public function removeFeedback ( \ Gpupo \ CommonSchema \ ORM \ Entity \ Trading \ Order \ Feedback \ Feedback $ feedback ) { return $ this -> feedbacks -> removeElement ( $ feedback ) ; }
|
Remove feedback .
|
10,409
|
private function addIndexerSection ( ArrayNodeDefinition $ node ) { $ node -> children ( ) -> arrayNode ( 'indexer' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> booleanNode ( 'sudo' ) -> defaultValue ( false ) -> end ( ) -> scalarNode ( 'bin' ) -> defaultValue ( '/usr/bin/indexer' ) -> end ( ) -> scalarNode ( 'config' ) -> defaultNull ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) ; }
|
Set indexer parameters
|
10,410
|
private function addIndexesSection ( ArrayNodeDefinition $ node ) { $ node -> children ( ) -> arrayNode ( 'indexes' ) -> isRequired ( ) -> requiresAtLeastOneElement ( ) -> useAttributeAsKey ( 'key' ) -> prototype ( 'scalar' ) -> end ( ) -> end ( ) -> end ( ) ; }
|
Set indexes parameters
|
10,411
|
private function addSearchdSection ( ArrayNodeDefinition $ node ) { $ node -> children ( ) -> arrayNode ( 'searchd' ) -> addDefaultsIfNotSet ( ) -> children ( ) -> scalarNode ( 'host' ) -> defaultValue ( 'localhost' ) -> end ( ) -> scalarNode ( 'port' ) -> defaultValue ( '9312' ) -> end ( ) -> scalarNode ( 'socket' ) -> defaultNull ( ) -> end ( ) -> end ( ) -> end ( ) -> end ( ) ; }
|
Set search daemon parameters
|
10,412
|
public function setOptions ( $ options ) { switch ( true ) { case ( $ options instanceof ezcCacheStorageMemcacheOptions ) : $ this -> properties [ 'options' ] = $ options ; break ; case ( $ options instanceof ezcCacheStorageOptions ) : $ this -> properties [ 'options' ] -> mergeStorageOptions ( $ options ) ; break ; case ( is_array ( $ options ) ) : $ this -> properties [ 'options' ] -> merge ( $ options ) ; break ; default : throw new ezcBaseValueException ( 'options' , $ options , 'instance of ezcCacheStorageMemcacheOptions' ) ; } }
|
Set new options .
|
10,413
|
function getResponsabilidadIva ( $ id = 0 ) { if ( $ id == 0 ) { $ id = $ this -> id ; } $ ret = $ this -> find ( 'first' , array ( 'conditions' => array ( 'Cliente.id' => $ id ) , 'contain' => array ( 'IvaResponsabilidad' ) ) ) ; return $ ret ; }
|
Me devuelve la responsabilidad del cliente frente el IVA
|
10,414
|
public function filerBySearch ( $ data ) { $ filter = $ data [ 'search' ] ; $ condition = array ( 'OR' => array ( $ this -> alias . '.nombre LIKE' => '%' . $ filter . '%' , $ this -> alias . '.nrodocumento LIKE' => '%' . $ filter . '%' , $ this -> alias . '.telefono LIKE' => '%' . $ filter . '%' , $ this -> alias . '.domicilio LIKE' => '%' . $ filter . '%' , $ this -> alias . '.codigo' => $ filter , ) ) ; return $ condition ; }
|
Or conditions with like
|
10,415
|
public function zip ( ) { if ( empty ( $ this -> filepath ) ) { throw ( new \ Exception ( "Must set \sb\Email\Attachment::file_path before zipping attachment" ) ) ; } if ( empty ( $ this -> name ) ) { $ this -> name = basename ( $ this -> filepath ) ; } $ zip = new \ ZipArchive ( ) ; $ zipfile_path = \ ROOT . "/private/cache/compression/" . md5 ( microtime ( true ) ) . '_' . $ this -> name . ".zip" ; $ zip_dir = dirname ( $ zipfile_path ) ; if ( ! is_dir ( $ zip_dir ) && ! @ mkdir ( $ zip_dir , 0755 , true ) ) { throw ( new \ Exception ( "Cannot create /private/cache/compression directory\n" ) ) ; } if ( $ zip -> open ( $ zipfile_path , \ ZIPARCHIVE :: CREATE ) !== true ) { throw ( new \ Exception ( "Cannot open <$zipfile_path>\n" ) ) ; } $ zip -> addFromString ( $ this -> name , \ file_get_contents ( $ this -> filepath ) ) ; $ zip -> close ( ) ; $ this -> name .= '.zip' ; $ this -> contents = \ file_get_contents ( $ zipfile_path ) ; \ unlink ( $ zipfile_path ) ; $ this -> mime_type = 'application/x-zip-compressed' ; }
|
Zips the attachment before sending and sets the proper mime type
|
10,416
|
public function addEpisodeJob ( Keychain $ keychain , $ uniqID , $ overwrite = false , $ worker_queue = false , $ first = false ) { $ this -> jobService -> addJob ( "Oktolab\MediaBundle\Model\ImportEpisodeMetadataJob" , [ 'keychain' => $ keychain -> getUniqID ( ) , 'uniqID' => $ uniqID , 'overwrite' => $ overwrite ] , $ worker_queue , $ first ) ; }
|
starts an import worker for an episode by uniqID from the given Keychain
|
10,417
|
public function addImportSeriesPosterframeJob ( $ uniqID , $ keychain , $ filekey ) { $ this -> jobService -> addJob ( "Oktolab\MediaBundle\Model\ImportSeriesPosterframeJob" , [ 'uniqID' => $ uniqID , 'keychain' => $ keychain -> getUniqID ( ) , 'key' => $ filekey ] ) ; }
|
please use addSeriesPosterframeJob in the future .
|
10,418
|
public function describeColumns ( $ conn , $ table , $ schema = null ) { $ dialect = $ this -> getDialect ( $ conn ) ; if ( method_exists ( $ dialect , 'showFullColumns' ) ) { $ sql = $ this -> getDialect ( $ conn ) -> showFullColumns ( $ table , $ schema ) ; $ comments = [ ] ; foreach ( $ conn -> fetchAll ( $ sql , Db :: FETCH_ASSOC ) as $ row ) { $ comments [ $ row [ 'Field' ] ] = $ row [ 'Comment' ] ; } $ columns = [ ] ; foreach ( $ conn -> describeColumns ( $ table , $ schema ) as $ col ) { $ column = Column :: copy ( $ col ) ; if ( ! empty ( $ comments [ $ col -> getName ( ) ] ) ) { $ column -> setComment ( $ comments [ $ col -> getName ( ) ] ) ; } $ columns [ ] = $ column ; } return $ columns ; } else { return $ conn -> describeColumns ( $ table , $ schema ) ; } }
|
Adds comment to column
|
10,419
|
public function describeIndexes ( $ conn , $ table , $ schema = null ) { $ dialect = $ conn -> getDialectType ( ) ; $ method = 'describeIndexes' . $ dialect ; if ( ! method_exists ( $ this , $ method ) ) { throw new Exception ( "Describe index for $dialect is not implemented yet" ) ; } return $ this -> $ method ( $ conn , $ table , $ schema ) ; }
|
Describes table indexes
|
10,420
|
public function createTable ( $ conn , $ table , $ schema , array $ definition ) { if ( empty ( $ definition [ 'columns' ] ) ) { throw new Exception ( "The table must contain at least one column" ) ; } $ conn -> execute ( $ this -> getDialect ( $ conn ) -> createTable ( $ table , $ schema , $ definition ) ) ; }
|
creates database table
|
10,421
|
public static function getConnection ( $ dsn ) { if ( ! is_array ( $ dsn ) ) { $ dsn = self :: parseDsn ( $ dsn ) ; } if ( ! isset ( $ dsn [ 'adapter' ] ) ) { throw new Exception ( "database adapter is missing for " . json_encode ( $ dsn ) ) ; } $ class = 'Phalcon\Db\Adapter\Pdo\\' . ucfirst ( $ dsn [ 'adapter' ] ) ; $ conn = new $ class ( $ dsn ) ; return Mixin :: create ( $ conn , new self ) ; }
|
creates database connect by dsn
|
10,422
|
public function setOptions ( array $ opt = array ( ) ) { if ( isset ( $ opt [ 'compileDir' ] ) || isset ( $ opt [ 'compile_dir' ] ) ) { trigger_error ( 'Dwoo ZF Adapter: the compile dir should be set in the $options[\'engine\'][\'compileDir\'] value the adapter settings' , E_USER_WARNING ) ; } if ( isset ( $ opt [ 'cacheDir' ] ) || isset ( $ opt [ 'cache_dir' ] ) ) { trigger_error ( 'Dwoo ZF Adapter: the cache dir should be set in the $options[\'engine\'][\'cacheDir\'] value the adapter settings' , E_USER_WARNING ) ; } $ classes = array ( 'engine' , 'dataProvider' , 'compiler' ) ; foreach ( $ opt as $ type => $ settings ) { if ( ! method_exists ( $ this , 'set' . $ type ) ) { throw new Dwoo_Exception ( "Unknown type $type" ) ; } if ( is_string ( $ settings ) || is_object ( $ settings ) ) { call_user_func ( array ( $ this , 'set' . $ type ) , $ settings ) ; } elseif ( is_array ( $ settings ) ) { if ( array_key_exists ( 'type' , $ settings ) ) { call_user_func ( array ( $ this , 'set' . $ type ) , $ settings [ 'type' ] ) ; } if ( in_array ( $ type , $ classes ) ) { $ rel = call_user_func ( array ( $ this , 'get' . $ type ) ) ; foreach ( $ settings as $ method => $ value ) { if ( method_exists ( $ rel , 'set' . $ method ) ) { call_user_func ( array ( $ rel , 'set' . $ method ) , $ value ) ; } } } elseif ( 'templateFile' == $ type ) { $ this -> _templateFileSettings = $ settings ; } } } }
|
Set object state from options array - engine = engine class name|engine object|array of options for engine - dataProvider = data provider class name|data provider object|array of options for data provider - compiler = compiler class name|compiler object|array of options for compiler - templateFile =
|
10,423
|
public function setEngine ( $ engine ) { if ( $ engine instanceof Dwoo ) { $ this -> _engine = $ engine ; } elseif ( is_subclass_of ( $ engine , 'Dwoo' ) || 'Dwoo' === $ engine ) { $ this -> _engine = new $ engine ( ) ; } else { throw new Dwoo_Exception ( "Custom engine must be a subclass of Dwoo" ) ; } }
|
Sets template engine
|
10,424
|
public function setDataProvider ( $ data ) { if ( $ data instanceof Dwoo_IDataProvider ) { $ this -> _dataProvider = $ data ; } elseif ( is_subclass_of ( $ data , 'Dwoo_Data' ) || 'Dwoo_Data' == $ data ) { $ this -> _dataProvider = new $ data ( ) ; } else { throw new Dwoo_Exception ( "Custom data provider must be a subclass of Dwoo_Data or instance of Dwoo_IDataProvider" ) ; } }
|
Sets Dwoo data object
|
10,425
|
public function setCompiler ( $ compiler ) { if ( $ compiler instanceof Dwoo_ICompiler ) { $ this -> _compiler = $ compiler ; } elseif ( is_subclass_of ( $ compiler , 'Dwoo_Compiler' ) || 'Dwoo_Compiler' == $ compiler ) { $ this -> _compiler = new $ compiler ; } else { throw new Dwoo_Exception ( "Custom compiler must be a subclass of Dwoo_Compiler or instance of Dwoo_ICompiler" ) ; } }
|
Sets Dwoo compiler
|
10,426
|
public function getCompiler ( ) { if ( null === $ this -> _compiler ) { $ this -> _compiler = Dwoo_Compiler :: compilerFactory ( ) ; } return $ this -> _compiler ; }
|
Return the Dwoo compiler object
|
10,427
|
public function getTemplateFile ( $ template ) { $ templateFileClass = $ this -> _templateFileClass ; $ dwooTemplateFile = new $ templateFileClass ( $ template ) ; if ( ! ( $ dwooTemplateFile instanceof Dwoo_ITemplate ) ) { throw new Dwoo_Exception ( "Custom templateFile class must be a subclass of Dwoo_ITemplate" ) ; } foreach ( $ this -> _templateFileSettings as $ method => $ value ) { if ( method_exists ( $ dwooTemplateFile , 'set' . $ method ) ) { call_user_func ( array ( $ dwooTemplateFile , 'set' . $ method ) , $ value ) ; } } return $ dwooTemplateFile ; }
|
Initializes Dwoo_ITemplate type of class and sets properties from _templateFileSettings
|
10,428
|
public function assign ( $ name , $ val = null ) { $ this -> getDataProvider ( ) -> assign ( $ name , $ val ) ; return $ this ; }
|
Passes data to Dwoo_Data object
|
10,429
|
public function _run ( ) { echo $ this -> _engine -> get ( $ this -> getTemplateFile ( func_get_arg ( 0 ) ) , $ this -> getDataProvider ( ) , $ this -> getCompiler ( ) ) ; }
|
Processes a view script and outputs it . Output is then passed through filters .
|
10,430
|
public function size ( $ remote_file ) { $ size = @ ftp_size ( $ this -> connection , $ remote_file ) ; if ( $ size && $ size != - 1 ) { return $ size ; } else { throw new \ Exception ( "Could not get remote file size: " . $ path ) ; } }
|
Gets the size of a remote file
|
10,431
|
public function chmod ( $ remote_file , $ mode ) { $ mode = octdec ( str_pad ( $ mode , 4 , '0' , STR_PAD_LEFT ) ) ; $ mode = ( int ) $ mode ; if ( ! @ ftp_chmod ( $ this -> connection , $ mode , $ remote_file ) !== false ) { throw new \ Exception ( "Could not change remote file to mode: " . $ mode ) ; } return true ; }
|
Change the file mode of a remote file
|
10,432
|
private function findWorkerTenderProcessesForTube ( $ tube ) { $ processes = array ( ) ; $ command = "ps ax " ; $ command .= "|grep php " ; $ command .= "|grep -v stop " ; $ command .= "|grep worker-tender " ; if ( $ tube !== '' ) { $ command .= "|grep " . escapeshellarg ( 'use-tube=' . $ tube ) ; } $ data = exec ( $ command ) ; $ lines = explode ( "\n" , $ data ) ; foreach ( $ lines as $ line ) { $ line = trim ( $ line ) ; $ parts = explode ( " " , $ line ) ; if ( $ parts [ 0 ] === '' ) { continue ; } $ processes [ ] = intval ( $ parts [ 0 ] ) ; } return $ processes ; }
|
Returns a list of processes that match the worker - tender
|
10,433
|
public function run ( $ method , $ action , $ data ) { $ method = strtoupper ( $ method ) ; if ( is_callable ( [ $ this , $ method ] ) ) { return $ this -> $ method ( $ action , $ data ) ; } return $ this -> httpError ( 405 , 'Method Not Allowed' ) ; }
|
Run the Nymph REST server process .
|
10,434
|
protected function httpError ( $ errorCode , $ message , $ exception = null ) { header ( "HTTP/1.1 $errorCode $message" , true , $ errorCode ) ; if ( $ exception ) { echo json_encode ( [ 'textStatus' => "$errorCode $message" , 'exception' => get_class ( $ exception ) , 'code' => $ exception -> getCode ( ) , 'message' => $ exception -> getMessage ( ) ] ) ; } else { echo json_encode ( [ 'textStatus' => "$errorCode $message" ] ) ; } return false ; }
|
Return the request with an HTTP error response .
|
10,435
|
public function listen ( $ request , $ response ) { $ this -> hits ++ ; $ path = '/' . ltrim ( $ request -> getPath ( ) , '/' ) ; $ endpoint = NULL ; if ( isset ( $ this -> routes [ $ path ] ) ) { $ endpoint = $ this -> routes [ $ path ] ; } else { $ endpointKey = NULL ; if ( isset ( $ this -> lookupCache [ $ path ] ) ) { $ endpointKey = $ this -> lookupCache [ $ path ] ; if ( $ this -> lookupCacheCount == 1000 ) { unset ( $ this -> lookupCache [ $ path ] ) ; $ this -> lookupCache [ $ path ] = $ endpointKey ; } $ endpoint = $ this -> searchRoutes [ $ endpointKey ] [ 1 ] ; } else { foreach ( $ this -> searchRoutes as $ key => $ route ) { if ( fnmatch ( $ route [ 0 ] , $ path ) ) { $ endpointKey = $ key ; break ; } } if ( $ endpointKey !== NULL ) { $ this -> lookupCache [ $ path ] = $ endpointKey ; $ this -> lookupCacheCount ++ ; while ( $ this -> lookupCacheCount -- > 1000 ) array_shift ( $ this -> lookupCache ) ; $ endpoint = $ this -> searchRoutes [ $ endpointKey ] [ 1 ] ; } } } if ( $ endpoint ) { return $ endpoint -> listen ( $ request , $ response ) ; } else { return $ this -> respondError ( 404 , $ request , $ response ) ; } }
|
Handle an incoming request map it to the correct endpoint using routes and call the listen method on the endpoint
|
10,436
|
protected function scanRoutes ( $ root , $ realRoot = NULL ) { if ( $ realRoot === NULL ) $ realRoot = $ root ; $ result = array ( ) ; $ all = glob ( $ root . '/*' ) ; foreach ( $ all as $ path ) { if ( ! is_dir ( $ path ) ) { $ res = $ this -> createRouteFromFile ( $ realRoot , $ path ) ; if ( $ res ) $ result [ ] = $ res ; } else { $ res = $ this -> scanRoutes ( $ path , $ realRoot ) ; foreach ( $ res as $ route ) $ result [ ] = $ route ; } } return $ result ; }
|
Recursively find all routes within path
|
10,437
|
public function s2o ( $ sql , $ params = null , $ class_name = '' , $ prepare_and_store = 1 ) { try { return parent :: s2o ( $ sql , $ params , $ class_name , $ prepare_and_store ) ; } catch ( \ Exception $ e ) { throw ( new \ sb \ PDO \ Exception ( 'CALLED: ' . __METHOD__ . "\nERROR RETURNED: " . print_r ( $ e , 1 ) ) ) ; } }
|
Additionally Logs the errors
|
10,438
|
public function setHeader ( $ keyName , $ value ) { $ normalizedKeyName = self :: normalizeHeaderKeyName ( $ keyName ) ; $ this -> headers [ $ normalizedKeyName ] = $ value ; }
|
Set a header . If it already exists the value is overwritten with the new one .
|
10,439
|
public function send ( ) { header ( sprintf ( 'HTTP/1.1 %s %s' , $ this -> statusCode , self :: codeToReason ( $ this -> statusCode ) ) ) ; foreach ( $ this -> headers as $ k => $ v ) { header ( sprintf ( '%s: %s' , $ k , $ v ) ) ; } echo $ this -> body ; }
|
Construct the response and send it out .
|
10,440
|
public function toArray ( ) { $ output = [ ] ; $ output [ ] = sprintf ( 'HTTP/1.1 %s %s' , $ this -> statusCode , self :: codeToReason ( $ this -> statusCode ) ) ; foreach ( $ this -> headers as $ k => $ v ) { $ output [ ] = sprintf ( '%s: %s' , $ k , $ v ) ; } $ output [ ] = '' ; $ output [ ] = $ this -> body ; return $ output ; }
|
Convert the full response to array for the purpose of unit testing .
|
10,441
|
public function render ( $ textOnly = false ) { if ( $ textOnly ) return $ this -> renderText ( ) ; $ str = $ this -> getStyle ( ) ; $ str .= "<table><tr><td valign='top'>" ; $ str .= $ this -> _render ( false ) ; $ str .= "</td></tr></table>" ; return $ str ; }
|
Returns the renderer s web page .
|
10,442
|
private function normalizeValue ( $ value ) { switch ( $ this -> type ) { case self :: TYPE_STRING : return trim ( ( string ) $ value ) ; case self :: TYPE_INT : return intval ( $ value ) ; case self :: TYPE_FLOAT : return floatval ( $ value ) ; } throw new FilterException ( "Invalid filter value type \"{$this->type}\"" ) ; }
|
Normalize input value
|
10,443
|
protected function getTagFromBranch ( $ branch ) { $ git = new GitRepository ( $ this -> input -> getArgument ( 'git-dir' ) ) ; $ tag = trim ( $ git -> describe ( ) -> tags ( ) -> always ( ) -> execute ( $ branch ) ) ; $ hash = trim ( $ git -> revParse ( ) -> short ( false ) -> execute ( $ branch ) ) ; return $ hash !== $ tag ? $ tag : null ; }
|
Retrieve the latest tag from a branch .
|
10,444
|
public function validate ( $ tag , $ alias ) { $ simpleAlias = preg_replace ( '~(\.x)?-dev~' , '' , $ alias ) ; $ versionLevel = count ( explode ( '.' , $ simpleAlias ) ) ; $ reducedTag = preg_replace ( '~-.*$~' , '' , $ tag ) ; $ reducedTag = implode ( '.' , array_slice ( explode ( '.' , $ reducedTag ) , 0 , $ versionLevel ) ) ; return version_compare ( $ reducedTag , $ simpleAlias , '<=' ) ; }
|
Validate the given branch .
|
10,445
|
protected function getConvertedParameters ( ) : array { $ parameters = $ this -> all ( ) ; $ parameters = $ this -> castBooleans ( $ parameters ) ; $ parameters = $ this -> convertToSnakeCase ( $ parameters ) ; if ( method_exists ( $ this , 'convertParameters' ) ) { $ parameters = $ this -> convertParameters ( $ parameters ) ; } return $ parameters ; }
|
Cast and convert parameters .
|
10,446
|
protected function castBooleans ( $ input ) : array { if ( $ this -> castToBooleanIsDisabled ( ) ) { return [ ] ; } $ casted = [ ] ; foreach ( $ input as $ key => $ value ) { $ casted [ $ key ] = $ this -> castValueToBoolean ( $ value ) ; } return $ casted ; }
|
Cast all string booleans to real boolean values .
|
10,447
|
protected function convertToSnakeCase ( $ input ) { if ( $ this -> convertToSnakeCaseIsDisabled ( ) ) { return ; } if ( is_null ( $ input ) ) { return null ; } elseif ( is_array ( $ input ) ) { return $ this -> convertArrayToSnakeCase ( $ input ) ; } return snake_case ( $ input ) ; }
|
Convert a string or array to snake case .
|
10,448
|
protected function convertArrayToSnakeCase ( array $ input ) : array { $ converted = [ ] ; foreach ( $ input as $ key => $ value ) { $ converted [ snake_case ( $ key ) ] = $ value ; } return $ converted ; }
|
Convert all keys of an array to snake case .
|
10,449
|
public function refreshLastUsed ( $ sessionId , $ lastUsed = null ) { if ( $ sessionInformation = $ this -> getSessionInformation ( $ sessionId ) ) { if ( $ sessionInformation -> getLastUsed ( ) !== $ lastUsed ) { $ sessionInformation -> refreshLastUsed ( $ lastUsed ) ; $ this -> saveSessionInformation ( $ sessionInformation ) ; } } }
|
Updates the given sessionId so its last request time is equal to the present date and time .
|
10,450
|
public function expireNow ( $ sessionId ) { if ( $ sessionInformation = $ this -> getSessionInformation ( $ sessionId ) ) { $ sessionInformation -> expireNow ( ) ; $ this -> saveSessionInformation ( $ sessionInformation ) ; } }
|
Expires the given sessionId .
|
10,451
|
public function registerNewSession ( $ sessionId , $ username , $ lastUsed = null ) { $ sessionInformation = new SessionInformation ( $ sessionId , $ username , $ lastUsed ? : time ( ) ) ; $ this -> saveSessionInformation ( $ sessionInformation ) ; }
|
Registers a new session for the given user .
|
10,452
|
public function collectGarbage ( $ maxLifetime = null ) { $ maxLifetime = $ maxLifetime ? : ini_get ( 'session.gc_maxlifetime' ) ; $ this -> sessionRegistryStorage -> collectGarbage ( $ maxLifetime ) ; }
|
Removes sessions information which last used timestamp is older than the given lifetime .
|
10,453
|
public function register ( ) { if ( ! $ this -> validate ( ) ) { return false ; } $ user = Yii :: createObject ( ModelMapHelper :: User ( ) ) ; $ user -> setAttributes ( $ this -> attributes ) ; $ result = $ user -> register ( ) ; if ( $ user -> hasErrors ( ) ) { foreach ( $ user -> errors as $ attribute => $ errors ) { foreach ( $ errors as $ error ) { $ this -> addError ( $ attribute , $ error ) ; } } } return $ result ; }
|
Performs registration of user . Returns User object on success or false on failure .
|
10,454
|
public function getCollections ( ) { return $ this -> getCachedProperty ( 'collections' , function ( ) { $ result = [ ] ; $ items = $ this -> query ( 'app:collection' ) ; foreach ( $ items as $ item ) { $ result [ ] = $ this -> getExtensions ( ) -> parseElement ( $ this , $ item ) ; } return $ result ; } ) ; }
|
Return collections .
|
10,455
|
public function addCollection ( $ title ) { $ collections = $ this -> getCollections ( ) ; $ collection = $ this -> getExtensions ( ) -> createElement ( $ this , 'app:collection' ) ; $ collection -> addTitle ( $ title ) ; $ collections [ ] = $ collection ; $ this -> setCachedProperty ( 'collections' , $ collections ) ; return $ collection ; }
|
Add new Collection
|
10,456
|
public function convertDateFields ( ) { $ grid_field = $ this -> getGridField ( ) ; $ config = $ grid_field -> getConfig ( ) ; $ db = Config :: inst ( ) -> get ( $ grid_field -> getModelClass ( ) , "db" ) ; $ dates = self :: config ( ) -> date_fields ; $ fields = $ this -> findDateFields ( ) ; foreach ( $ config -> getComponents ( ) as $ component ) { $ class = get_class ( $ component ) ; $ is_header = ( $ component instanceof GridFieldSortableHeader ) ; $ is_columns = ClassInfo :: classImplements ( $ class , GridField_ColumnProvider :: class ) ; if ( $ is_columns && method_exists ( $ component , "getDisplayFields" ) ) { $ display_fields = $ component -> getDisplayFields ( $ grid_field ) ; foreach ( $ fields as $ field ) { $ display_fields = $ this -> changeKeys ( $ field [ "Sort" ] , $ field [ "Column" ] , $ display_fields ) ; } $ component -> setDisplayFields ( $ display_fields ) ; } if ( $ is_header && count ( $ component -> getFieldSorting ( ) ) == 0 ) { $ sort_fields = [ ] ; foreach ( $ fields as $ field ) { $ sort_fields [ $ field [ "Column" ] ] = $ field [ "Sort" ] ; } $ component -> setFieldSorting ( $ sort_fields ) ; } } $ this -> setGridField ( $ grid_field ) ; return $ this ; }
|
Get any date fields from the passed list and convert to . Nice format .
|
10,457
|
public function open ( $ method , $ action = '' , $ attr = array ( ) ) { $ method = strtolower ( $ method ) ; if ( $ method === 'file' ) { $ method = 'post' ; $ attr [ 'enctype' ] = 'multipart/form-data' ; } if ( ! in_array ( $ method , array ( 'post' , 'get' ) ) ) { $ method = 'post' ; } $ attr [ 'method' ] = $ method ; $ attr [ 'action' ] = $ action ; return $ this -> Html -> tag ( 'form' , $ attr ) ; }
|
open a form
|
10,458
|
public function hidden ( $ name , $ attr = array ( ) ) { return $ this -> input ( $ name , false , array_merge ( $ attr , array ( 'type' => 'hidden' , 'wrapper' => false ) ) ) ; }
|
shortcut for hidden input field
|
10,459
|
public function password ( $ name , $ label , $ attr = array ( ) ) { return $ this -> input ( $ name , $ label , array_merge ( $ attr , array ( 'type' => 'password' ) ) ) ; }
|
shortcut for password field
|
10,460
|
public function textarea ( $ name , $ label , $ attr = array ( ) ) { return $ this -> input ( $ name , $ label , array_merge ( $ attr , array ( 'type' => 'textarea' ) ) ) ; }
|
shortcut for textarea field
|
10,461
|
public function file ( $ name , $ label , $ attr = array ( ) ) { return $ this -> input ( $ name , $ label , array_merge ( $ attr , array ( 'type' => 'file' ) ) ) ; }
|
shortcut for file field
|
10,462
|
public function checkbox ( $ name , $ label , $ attr = array ( ) ) { return $ this -> input ( $ name , $ label , array_merge ( $ attr , array ( 'type' => 'checkbox' ) ) ) ; }
|
shortcut for checkbox field
|
10,463
|
public function submit ( $ name , $ label , $ attr = array ( ) ) { return $ this -> input ( $ name , false , array_merge ( $ attr , array ( 'type' => 'submit' , 'value' => $ label ) ) ) ; }
|
generate a submit input
|
10,464
|
public function button ( $ name , $ label , $ attr = array ( ) ) { return $ this -> input ( $ name , false , array_merge ( $ attr , array ( 'type' => 'button' , 'value' => $ label ) ) ) ; }
|
generate a button input
|
10,465
|
public function radio ( $ name , $ label , $ options , $ attr = array ( ) ) { return $ this -> input ( $ name , $ label , array_merge ( $ attr , array ( 'type' => 'radio' , 'options' => $ options ) ) ) ; }
|
generate a group of radio buttons
|
10,466
|
public function input ( $ name , $ label , $ attr = array ( ) ) { if ( empty ( $ attr [ 'id' ] ) ) { $ attr [ 'id' ] = $ this -> transformNameForID ( $ name ) ; } if ( $ label !== false ) { $ labelAttr = [ ] ; if ( is_array ( $ label ) ) { $ labelAttr = $ label ; $ label = ( ! empty ( $ label [ 'value' ] ) ) ? $ label [ 'value' ] : $ name ; unset ( $ labelAttr [ 'value' ] ) ; } $ labelAttr [ 'for' ] = $ attr [ 'id' ] ; $ label = $ this -> label ( $ label , $ labelAttr ) ; } else { $ label = '' ; } $ wrapper = array ( ) ; if ( isset ( $ attr [ 'wrapper' ] ) ) { $ wrapper = $ attr [ 'wrapper' ] ; unset ( $ attr [ 'wrapper' ] ) ; } $ injects = $ this -> getInjects ( $ attr ) ; if ( empty ( $ attr [ 'type' ] ) ) { $ attr [ 'type' ] = 'text' ; } $ field = $ this -> generateField ( $ name , $ attr ) ; $ contents = $ this -> buildField ( $ attr [ 'type' ] , $ label , $ field , $ injects ) ; if ( isset ( $ wrapper ) && $ wrapper === false ) { return $ contents ; } $ wrapperInfo = $ this -> getWrapper ( $ wrapper , $ attr ) ; return $ this -> Html -> tag ( $ wrapperInfo [ 'tag' ] , $ wrapperInfo [ 'attr' ] , $ contents , true ) ; }
|
generate a complete input with wrapped div and label
|
10,467
|
public function generateField ( $ name , $ attr = array ( ) ) { $ tag = 'input' ; if ( in_array ( $ attr [ 'type' ] , $ this -> customGenerate ) ) { $ tag = $ attr [ 'type' ] ; } $ attr [ 'name' ] = $ this -> transformName ( $ name ) ; $ attr = $ this -> getData ( $ name , $ attr ) ; if ( $ tag !== 'input' ) { $ generate = 'generate' . ucfirst ( strtolower ( $ tag ) ) . 'Field' ; return $ this -> { $ generate } ( $ attr ) ; } else { return $ this -> Html -> tag ( 'input' , $ attr ) ; } }
|
generate a field
|
10,468
|
public function generateRadioField ( $ attr ) { if ( empty ( $ attr [ 'name' ] ) ) { return '' ; } $ out = '' ; $ options = array ( ) ; if ( ! empty ( $ attr [ 'options' ] ) ) { $ options = $ attr [ 'options' ] ; } if ( isset ( $ attr [ 'checked' ] ) ) { $ checkedItem = $ attr [ 'checked' ] ; } unset ( $ attr [ 'options' ] , $ attr [ 'checked' ] ) ; foreach ( $ options as $ value => $ label ) { $ id = $ attr [ 'id' ] . '_' . $ value ; $ optionsAttr = array ( 'id' => $ id , 'value' => $ value ) ; if ( isset ( $ checkedItem ) && $ checkedItem == $ value ) { $ optionsAttr [ ] = 'checked' ; } $ input = $ this -> Html -> tag ( 'input' , array_merge ( $ attr , $ optionsAttr ) ) ; $ label = $ this -> Html -> tag ( 'label' , array ( 'for' => $ id ) , $ label , true ) ; $ out .= $ this -> Html -> tag ( 'div' , array ( 'class' => 'radio-item' ) , $ input . $ label , true ) ; } return $ out ; }
|
generate a selection of radio buttons
|
10,469
|
public function generateCheckboxField ( $ attr ) { if ( empty ( $ attr [ 'name' ] ) ) { return '' ; } $ out = '' ; if ( ( isset ( $ attr [ 'hiddenCheckbox' ] ) && $ attr [ 'hiddenCheckbox' ] ) || ! isset ( $ attr [ 'hiddenCheckbox' ] ) ) { $ out .= $ this -> input ( $ attr [ 'name' ] , false , array ( 'type' => 'hidden' , 'wrapper' => false , 'id' => '_' . $ attr [ 'id' ] , 'value' => 0 ) ) ; } unset ( $ attr [ 'hiddenCheckbox' ] ) ; if ( ! isset ( $ attr [ 'value' ] ) ) { $ attr [ 'value' ] = 1 ; } $ out .= $ this -> Html -> tag ( 'input' , $ attr ) ; return $ out ; }
|
generate a checkbox
|
10,470
|
public function generateButtonField ( $ attr ) { $ value = 'Submit' ; if ( ! empty ( $ attr [ 'value' ] ) ) { $ value = $ attr [ 'value' ] ; } unset ( $ attr [ 'value' ] , $ attr [ 'type' ] ) ; return $ this -> Html -> tag ( 'button' , $ attr , $ value , true ) ; }
|
generate a button
|
10,471
|
public function generateSelectField ( $ attr ) { if ( empty ( $ attr [ 'name' ] ) ) { return '' ; } $ options = array ( ) ; if ( ! empty ( $ attr [ 'options' ] ) ) { $ options = $ attr [ 'options' ] ; } $ options = $ this -> generateSelectOptions ( $ options , $ attr ) ; unset ( $ attr [ 'options' ] , $ attr [ 'type' ] , $ attr [ 'selected' ] ) ; return $ this -> Html -> tag ( 'select' , $ attr , $ options , true ) ; }
|
generate a select field
|
10,472
|
public function generateSelectOptions ( $ options , $ attr ) { $ return = '' ; foreach ( $ options as $ key => $ value ) { if ( is_array ( $ value ) ) { $ subArray = $ this -> generateSelectOptions ( $ value , $ attr ) ; $ return .= $ this -> Html -> tag ( 'optgroup' , array ( 'label' => $ key ) , $ subArray , true ) ; } else { $ optionsAttr = array ( 'value' => $ key ) ; if ( isset ( $ attr [ 'selected' ] ) && $ attr [ 'selected' ] == $ key ) { $ optionsAttr [ ] = 'selected' ; } $ return .= $ this -> Html -> tag ( 'option' , $ optionsAttr , $ value , true ) ; } } return $ return ; }
|
generate the options for a select box
|
10,473
|
public function transformName ( $ name ) { if ( strpos ( $ name , '.' ) !== false ) { $ bits = explode ( '.' , $ name , 2 ) ; $ bits [ '1' ] = '[' . str_replace ( '.' , '][' , $ bits [ '1' ] ) . ']' ; return implode ( '' , $ bits ) ; } else { return $ name ; } }
|
transform the dot notation name into proper name
|
10,474
|
public function transformNameForID ( $ name ) { $ bits = explode ( '.' , $ name ) ; array_walk ( $ bits , function ( & $ value , $ key ) { $ value = ucfirst ( strtolower ( $ value ) ) ; } ) ; return implode ( '' , $ bits ) ; }
|
transform the dot notation name into a name for input ID if no ID was passed
|
10,475
|
public function getInjects ( & $ attr ) { $ inject = array ( 'before' => '' , 'between' => '' , 'after' => '' ) ; if ( ! empty ( $ attr [ 'before' ] ) ) { $ inject [ 'before' ] = $ attr [ 'before' ] ; unset ( $ attr [ 'before' ] ) ; } if ( ! empty ( $ attr [ 'between' ] ) ) { $ inject [ 'between' ] = $ attr [ 'between' ] ; unset ( $ attr [ 'between' ] ) ; } if ( ! empty ( $ attr [ 'after' ] ) ) { $ inject [ 'after' ] = $ attr [ 'after' ] ; unset ( $ attr [ 'after' ] ) ; } return $ inject ; }
|
get injections from the attributes allows data to be entered before between after
|
10,476
|
public function getWrapper ( $ wrapper , $ attr ) { $ type = '' ; if ( ! empty ( $ attr [ 'type' ] ) ) { $ type = ' ' . $ attr [ 'type' ] ; if ( ( isset ( $ attr [ 'type' ] ) && $ attr [ 'type' ] == 'select' ) && in_array ( 'multiple' , $ attr ) ) { $ type .= ' multiselect' ; } } $ defaults = array ( 'tag' => 'div' , 'class' => 'input' . $ type ) ; $ wrapperAttr = array_merge ( $ defaults , $ wrapper ) ; $ tag = $ wrapperAttr [ 'tag' ] ; unset ( $ wrapperAttr [ 'tag' ] ) ; return array ( 'tag' => $ tag , 'attr' => $ wrapperAttr ) ; }
|
given any user defined wrapper instructions build the wrapper data
|
10,477
|
public function getData ( $ name , $ attr ) { if ( empty ( $ name ) ) { return $ attr ; } $ value = $ this -> Data -> getValue ( $ name ) ; if ( $ value !== null ) { $ isCheckbox = ( isset ( $ attr [ 'type' ] ) && $ attr [ 'type' ] == 'checkbox' ) ; $ isRadio = ( isset ( $ attr [ 'type' ] ) && $ attr [ 'type' ] == 'radio' ) ; $ isSelect = ( isset ( $ attr [ 'type' ] ) && $ attr [ 'type' ] == 'select' ) ; if ( $ isCheckbox ) { $ attr [ ] = 'checked' ; } elseif ( $ isRadio ) { $ attr [ 'checked' ] = $ value ; } elseif ( $ isSelect ) { $ attr [ 'selected' ] = $ value ; } else { $ attr [ 'value' ] = $ value ; } } return $ attr ; }
|
use the Data interface and find any post data
|
10,478
|
public function setData ( $ Data ) { if ( ! is_object ( $ Data ) || ! $ Data instanceof Data ) { throw new \ InvalidArgumentException ( 'The Data Interface must be a valid Data Object' ) ; } $ this -> Data = $ Data ; return true ; }
|
check and set the form data interface
|
10,479
|
public function setHtml ( $ Html ) { if ( ! is_object ( $ Html ) || ! $ Html instanceof HtmlObject ) { throw new \ InvalidArgumentException ( 'The HTML Object must be a valid HTML Object' ) ; } $ this -> Html = $ Html ; return true ; }
|
check and set the HTML Object
|
10,480
|
protected function addExtensionsFromTemplateConfiguration ( Transformation $ transformation , ProjectDescriptor $ project , \ Twig_Environment $ twigEnvironment ) { $ isDebug = $ transformation -> getParameter ( 'twig-debug' ) ? $ transformation -> getParameter ( 'twig-debug' ) -> getValue ( ) : false ; if ( $ isDebug == 'true' ) { $ twigEnvironment -> enableDebug ( ) ; $ twigEnvironment -> enableAutoReload ( ) ; $ twigEnvironment -> addExtension ( new \ Twig_Extension_Debug ( ) ) ; } foreach ( $ transformation -> getParametersWithKey ( 'twig-extension' ) as $ extension ) { $ extensionValue = $ extension -> getValue ( ) ; if ( ! class_exists ( $ extensionValue ) ) { throw new \ InvalidArgumentException ( 'Unknown twig extension: ' . $ extensionValue ) ; } $ implementsInterface = in_array ( 'phpDocumentor\Plugin\Twig\ExtensionInterface' , class_implements ( $ extensionValue ) ) ; $ twigEnvironment -> addExtension ( $ implementsInterface ? new $ extensionValue ( $ project , $ transformation ) : new $ extensionValue ( ) ) ; } }
|
Tries to add any custom extensions that have been defined in the template or the transformation s configuration .
|
10,481
|
protected function getDestinationPath ( $ node , Transformation $ transformation ) { $ writer = $ this ; if ( ! $ node ) { throw new \ UnexpectedValueException ( 'The transformation node in the twig writer is not expected to be false or null' ) ; } if ( ! $ transformation -> getArtifact ( ) ) { $ rule = $ this -> routers -> match ( $ node ) ; if ( ! $ rule ) { throw new \ InvalidArgumentException ( 'No matching routing rule could be found for the given node, please provide an artifact location, ' . 'encountered: ' . ( $ node === null ? 'NULL' : get_class ( $ node ) ) ) ; } $ rule = new ForFileProxy ( $ rule ) ; $ url = $ rule -> generate ( $ node ) ; if ( $ url === false || $ url [ 0 ] !== DIRECTORY_SEPARATOR ) { return false ; } $ path = $ transformation -> getTransformer ( ) -> getTarget ( ) . str_replace ( '/' , DIRECTORY_SEPARATOR , $ url ) ; } else { $ path = $ transformation -> getTransformer ( ) -> getTarget ( ) . DIRECTORY_SEPARATOR . $ transformation -> getArtifact ( ) ; } $ finder = new Pathfinder ( ) ; $ destination = preg_replace_callback ( '/{{([^}]+)}}/' , function ( $ query ) use ( $ node , $ writer , $ finder ) { $ filepart = trim ( ( string ) current ( $ finder -> find ( $ node , $ query [ 1 ] ) ) , '\\/' ) ; if ( extension_loaded ( 'iconv' ) ) { $ filepart = iconv ( 'UTF-8' , 'ASCII//TRANSLIT' , $ filepart ) ; } $ filepart = strpos ( $ filepart , '/' ) !== false ? implode ( '/' , array_map ( 'urlencode' , explode ( '/' , $ filepart ) ) ) : implode ( '\\' , array_map ( 'urlencode' , explode ( '\\' , $ filepart ) ) ) ; return $ filepart ; } , $ path ) ; $ destination = str_replace ( array ( '/' , '\\' ) , DIRECTORY_SEPARATOR , $ destination ) ; if ( ! file_exists ( dirname ( $ destination ) ) ) { mkdir ( dirname ( $ destination ) , 0777 , true ) ; } return $ destination ; }
|
Uses the currently selected node and transformation to assemble the destination path for the file .
|
10,482
|
public function filter_sanitize ( $ v , $ p ) { $ option = Helper :: arrGet ( $ this -> sanitizes , $ p , $ p ) ; $ v -> setValue ( filter_var ( $ v -> getValue ( ) , $ option ) ) ; if ( $ p === 'int' ) { if ( ( int ) $ v -> getValue ( ) !== ( int ) ( float ) $ v -> getValue ( ) ) { $ v -> setValue ( '' ) ; } } }
|
sanitize the value using filter_var .
|
10,483
|
public function filter_datetime ( $ v , $ p ) { if ( is_bool ( $ p ) && $ p ) { $ p = 'Y-m-d H:i:s' ; } $ dt = \ date_create_from_format ( $ p , $ v -> getValue ( ) ) ; if ( ! $ dt ) { $ v -> setValue ( null ) ; $ v -> setError ( __METHOD__ , $ p ) ; return ; } $ v -> setValue ( $ dt -> format ( $ p ) ) ; }
|
check for valid date - time input string .
|
10,484
|
public function showMappingCommand ( string $ node ) { foreach ( $ this -> contentDimensionCombinator -> getAllAllowedCombinations ( ) as $ dimensions ) { $ context = $ this -> createContentContext ( 'live' , $ dimensions ) ; $ siteNode = $ context -> getNodeByIdentifier ( $ node ) ; $ taxonomyNodes = ( new FlowQuery ( [ $ siteNode ] ) ) -> find ( '[instanceof Ttree.Taxonomy:Document.Taxonomy]' ) -> get ( ) ; $ settings = [ ] ; foreach ( $ taxonomyNodes as $ taxonomyNode ) { $ this -> outputLine ( ) ; $ this -> outputLine ( 'Show mapping for <b>%s</b> (%s)' , [ $ taxonomyNode -> getLabel ( ) , $ taxonomyNode -> getContextPath ( ) ] ) ; $ settings = $ this -> managedVocabulary -> build ( $ taxonomyNode ) ; foreach ( Arrays :: getValueByPath ( $ settings , 'analysis.analyzer' ) as $ analyzerName => $ analyzerConfiguration ) { $ this -> outputLine ( ) ; $ this -> outputLine ( '+ Analyzer <info>%s</info>' , [ $ analyzerName ] ) ; $ this -> outputLine ( ' Tokenizer <info>%s</info>' , [ $ analyzerConfiguration [ 'tokenizer' ] ] ) ; $ this -> outputLine ( ' Filter <info>%s</info>' , [ \ implode ( ', ' , $ analyzerConfiguration [ 'filter' ] ) ] ) ; } foreach ( Arrays :: getValueByPath ( $ settings , 'analysis.filter' ) as $ filterName => $ filterConfiguration ) { $ this -> outputLine ( ) ; $ this -> outputLine ( '+ Filter <info>%s</info>' , [ $ analyzerName ] ) ; $ this -> outputLine ( ' Type <info>%s</info>' , [ $ filterConfiguration [ 'type' ] ] ) ; if ( $ filterConfiguration [ 'type' ] === 'synonym' ) { $ this -> outputLine ( ' Synonyms <info>%d</info>' , [ count ( $ filterConfiguration [ 'synonyms' ] ) ] ) ; } } } } }
|
Show ElasticSearch filters and analyzers
|
10,485
|
public function toArray ( ) { $ this -> data = $ this -> transformer -> transformBack ( $ this -> data ) ; return $ this -> data ; }
|
Return array representation of item
|
10,486
|
public function validate ( $ schemaFile ) { if ( ! $ this -> xmlString ) throw new XmlParserException ( "attempting to validate before parsing" ) ; if ( ! extension_loaded ( "DOM" ) ) { trigger_error ( "DOM extension not loaded, will not validate XML" , E_USER_NOTICE ) ; return $ this ; } libxml_use_internal_errors ( true ) ; $ document = new \ DOMDocument ( ) ; $ document -> loadXML ( $ this -> xmlString ) ; if ( ! $ document -> schemaValidate ( $ schemaFile ) ) { $ msg = "The following XML errors occurred while validating:" ; foreach ( libxml_get_errors ( ) as $ error ) $ msg .= "\n" . $ error -> message ; throw new XmlParserException ( $ msg ) ; } return $ this ; }
|
Validates XML using a schema .
|
10,487
|
public static function get ( $ node , $ tagName , $ count = 1 ) { $ node = $ node -> { $ tagName } ; if ( $ node -> count ( ) !== $ count ) throw new XmlParserException ( "xml does not have exactly $count $tagName's" ) ; return $ node [ 0 ] ; }
|
Returns a child node for a tag name from an XML node .
|
10,488
|
public static function connect ( $ mysqlConfig ) { $ dbConfig = array ( 'dsn' => 'mysql:dbname=' . $ mysqlConfig [ 'dbname' ] . ';host=' . $ mysqlConfig [ 'host' ] , 'user' => $ mysqlConfig [ 'user' ] , 'pass' => $ mysqlConfig [ 'pass' ] , 'options' => array ( PDO :: MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8" ) , ) ; return parent :: connect ( $ dbConfig ) ; }
|
Returns a PDO instance
|
10,489
|
private function writeField ( $ file , $ fieldName , $ field , $ isPrimary ) { fwrite ( $ file , "\n" ) ; if ( $ isPrimary ) { fwrite ( $ file , "\$def->idProperty = new ezcPersistentObjectIdProperty();\n" ) ; fwrite ( $ file , "\$def->idProperty->columnName = '$fieldName';\n" ) ; fwrite ( $ file , "\$def->idProperty->propertyName = '$fieldName';\n" ) ; if ( $ field -> autoIncrement ) { fwrite ( $ file , "\$def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentSequenceGenerator' );\n" ) ; } else { fwrite ( $ file , "\$def->idProperty->generator = new ezcPersistentGeneratorDefinition( 'ezcPersistentManualGenerator' );\n" ) ; fwrite ( $ file , "\$def->idProperty->propertyType = ezcPersistentObjectProperty::PHP_TYPE_STRING;\n" ) ; } } else { fwrite ( $ file , "\$def->properties['$fieldName'] = new ezcPersistentObjectProperty();\n" ) ; fwrite ( $ file , "\$def->properties['$fieldName']->columnName = '$fieldName';\n" ) ; fwrite ( $ file , "\$def->properties['$fieldName']->propertyName = '$fieldName';\n" ) ; fwrite ( $ file , "\$def->properties['$fieldName']->propertyType = {$this->translateType($field->type)};\n" ) ; } fwrite ( $ file , "\n" ) ; }
|
Write a field of the schema to the PersistentObject definition . This method writes a database field to the PersistentObject definition file .
|
10,490
|
private function writeTable ( $ dir , $ tableName , ezcDbSchemaTable $ table ) { $ file = $ this -> openFile ( $ dir , $ tableName ) ; fwrite ( $ file , "\$def = new ezcPersistentObjectDefinition();\n" ) ; fwrite ( $ file , "\$def->table = '$tableName';\n" ) ; fwrite ( $ file , "\$def->class = '{$this->prefix}$tableName';\n" ) ; $ primaries = $ this -> determinePrimaries ( $ table -> indexes ) ; foreach ( $ table -> fields as $ fieldName => $ field ) { $ this -> writeField ( $ file , $ fieldName , $ field , isset ( $ primaries [ $ fieldName ] ) ) ; } $ this -> closeFile ( $ file ) ; }
|
Writes the PersistentObject defintion for a table .
|
10,491
|
private function closeFile ( $ file ) { fwrite ( $ file , "return \$def;\n" ) ; fwrite ( $ file , "\n" ) ; fwrite ( $ file , "?>\n" ) ; fclose ( $ file ) ; }
|
Close a file where a PersistentObject definition has been written to . This method closes a file after writing a PersistentObject definition to it and writes the PHP closing tag to it .
|
10,492
|
private function determinePrimaries ( $ indexes ) { $ primaries = array ( ) ; foreach ( $ indexes as $ index ) { if ( $ index -> primary ) { foreach ( $ index -> indexFields as $ field => $ definiton ) { $ primaries [ $ field ] = true ; } } } return $ primaries ; }
|
Extract primary keys from an index definition . This method extracts the names of all primary keys from the index defintions of a table .
|
10,493
|
protected function generateTransformer ( ) { $ name = ( string ) $ this -> argument ( 'name' ) ; $ path = $ this -> laravel -> basePath ( ) . '/app/Transformers/' . $ name . '.php' ; if ( $ this -> files -> exists ( $ path ) ) { return $ this -> error ( $ name . ' already exists!' ) ; } $ this -> makeDirectory ( $ path ) ; $ stubPath = $ this -> option ( 'pivot' ) ? 'resources/stubs/transformer.pivot.stub' : 'resources/stubs/transformer.stub' ; $ stub = $ this -> files -> get ( __DIR__ . '/../../' . $ stubPath ) ; $ this -> files -> put ( $ path , $ this -> makeTransformer ( $ name , $ stub ) ) ; $ this -> info ( 'Transformer created successfully.' ) ; }
|
Generate the transformer class .
|
10,494
|
protected function makeTransformer ( string $ name , string $ stub ) : string { $ stub = $ this -> replaceNamespace ( $ stub ) ; $ stub = $ this -> replaceClass ( $ stub , $ name ) ; $ stub = $ this -> replaceModel ( $ stub , $ name ) ; return $ stub ; }
|
Build the transformer class using the given name and stub .
|
10,495
|
protected function getModelNamespace ( string $ name ) : string { if ( $ this -> option ( 'model' ) ) { return $ this -> option ( 'model' ) ; } return 'App\\' . str_replace ( 'Transformer' , '' , $ name ) ; }
|
Get the full class path for the model .
|
10,496
|
public function setAppLocale ( $ locale = null , $ session = true ) { $ locale = $ locale ? : $ this -> session -> get ( '_locale' , null ) ; if ( $ locale ) { $ this -> app -> setLocale ( $ locale ) ; if ( $ session ) { $ this -> session -> put ( '_locale' , $ locale ) ; } $ this -> setTimeLocale ( $ locale ) ; } }
|
Sets the app locale
|
10,497
|
public function setTimeLocale ( $ locale = null ) { $ locale = $ locale ? : $ this -> session -> get ( '_locale' , $ this -> app -> getLocale ( ) ) ; setlocale ( LC_TIME , $ this -> config -> get ( 'translatable.full_locales.' . $ locale , null ) ) ; Carbon :: setLocale ( $ locale ) ; }
|
Sets the time locale
|
10,498
|
public static function send ( $ file , $ display_file_name = '' , $ seekat = 0 ) { $ display_file_name = $ display_file_name ? $ display_file_name : basename ( $ file ) ; $ display_file_name = str_replace ( " " , "_" , $ display_file_name ) ; header ( "HTTP/1.1 200 OK" ) ; header ( "Status: 200 OK" ) ; header ( "Pragma: private" ) ; header ( "Expires: 0" ) ; header ( "Cache-Control: must-revalidate, post-check=0, pre-check=0" ) ; header ( "Content-Transfer-Encoding: Binary" ) ; header ( 'Content-Type: application/force-download' ) ; header ( 'Content-disposition: attachment; filename="' . $ display_file_name . '"' ) ; while ( ob_get_level ( ) > 0 ) { ob_end_flush ( ) ; } \ sb \ Files :: readChunked ( $ file , $ seekat ) ; }
|
Send headers and begins force - download
|
10,499
|
public static function fileToZip ( $ path ) { if ( is_file ( $ path ) || is_dir ( $ path ) ) { $ zip = new \ ZipArchive ; $ zip_file = ROOT . '/private/cache/zip/' . md5 ( microtime ( true ) ) ; if ( ! is_dir ( dirname ( $ zip_file ) ) ) { mkdir ( dirname ( $ zip_file ) , 0775 , true ) ; } if ( $ zip -> open ( $ zip_file , \ ZipArchive :: CREATE ) === true ) { if ( is_dir ( $ path ) ) { $ iterator = new \ DirectoryIterator ( $ path ) ; foreach ( $ iterator as $ file ) { if ( $ file -> isFile ( ) ) { $ bn = $ file -> getBasename ( ) ; $ zip -> addFile ( $ file -> getPath ( ) . '/' . $ bn , $ bn ) ; } } } else { $ zip -> addFile ( $ path , basename ( $ path ) ) ; } if ( $ zip -> close ( ) ) { self :: send ( $ zip_file , str_replace ( "/" , "_" , basename ( $ path ) ) . '.zip' ) ; unlink ( $ zip_file ) ; } } else { throw ( new \ Exception ( 'failed to create zip file' ) ) ; } } else { throw ( new \ Exception ( 'No data found!' ) ) ; } }
|
Converts a file or directory into a zip file for consumption by the browser
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.