idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
16,300
|
public static function fill ( Grid $ grid , Distribution $ distribution , int $ maxRetries ) { Assert :: assertPositiveInteger ( $ maxRetries , 'maxRetries' ) ; if ( $ distribution -> getCells ( ) !== ( $ cells = $ grid -> rows * $ grid -> columns ) ) { throw new InvalidArgumentException ( "Cannot fill distribution {$distribution} ({$distribution->getCells()} cells)" . " in a {$grid->rows}x{$grid->columns} grid ({$cells} cells)" ) ; } if ( $ grid -> rows < 2 && $ distribution -> tall > 0 ) { throw new InvalidArgumentException ( "Cannot fill distribution {$distribution} in a {$grid->rows}x{$grid->columns} grid: not enough rows." ) ; } if ( $ grid -> columns < 2 && $ distribution -> wide > 0 ) { throw new InvalidArgumentException ( "Cannot fill distribution {$distribution} in a {$grid->rows}x{$grid->columns} grid: not enough columns." ) ; } for ( $ remainingTries = $ maxRetries ; $ remainingTries > 0 ; $ remainingTries -= 1 ) { try { return static :: tryToFill ( $ grid , $ distribution ) ; } catch ( InvalidArgumentException $ e ) { $ grid -> empty ( ) ; } } throw new RuntimeException ( "Could not fill distribution {$distribution} in a {$grid->rows}x{$grid->columns} grid" . " after {$maxRetries} tries." ) ; }
|
Try to fill a tiles distribution randomly within a grid .
|
16,301
|
public function addMenuItem ( MenuItem $ menuItem , $ position = - 1 ) { if ( ! is_int ( $ position ) ) { throw new InvalidArgumentException ( 'position should be of type int.' ) ; } if ( $ position < 0 ) { $ position = count ( $ this -> menuItems ) ; } $ menuItem -> setOrder ( $ position ) ; Utils :: array_insert ( $ this -> menuItems , $ menuItem , $ position ) ; return $ this ; }
|
Adds a MenuItem to this Menu .
|
16,302
|
public function connect ( Application $ app ) { $ ctrl = $ app [ 'controllers_factory' ] ; $ ctrl -> get ( '/' , function ( ) use ( $ app ) { $ root = str_replace ( 'index.php/' , '' , $ app [ 'url_generator' ] -> generate ( 'home' ) ) ; if ( $ app [ 'request' ] -> getRequestURI ( ) != $ root ) { return $ app -> redirect ( $ root , Response :: HTTP_MOVED_PERMANENTLY ) ; } return $ app [ 'twig' ] -> render ( 'front/partials/home.twig' ) ; } ) -> bind ( 'home' ) ; $ ctrl -> get ( '/admin' , function ( ) use ( $ app ) { return $ app -> redirect ( $ app [ 'url_generator' ] -> generate ( $ app [ 'config' ] [ 'admin' ] [ 'root' ] ) ) ; } ) ; $ ctrl -> get ( '/robots.txt' , function ( ) use ( $ app ) { $ response = new Response ( 'User-agent: *' . PHP_EOL . ( $ app [ 'debug' ] ? 'Disallow: /' : 'Sitemap: ' . $ app [ 'url_generator' ] -> generate ( 'home' ) . 'sitemap.xml' ) ) ; $ response -> headers -> set ( 'Content-Type' , 'text/plain' ) ; return $ response ; } ) ; return $ ctrl ; }
|
Silex method that exposes routes to the app
|
16,303
|
public function getText ( ) { $ args = $ this -> args ; $ msg = $ this -> getMessage ( ) ; return t ( $ msg , $ this -> domain , $ args ) ; }
|
Get the user s message
|
16,304
|
public static function from ( UserException $ e , $ field , $ value , $ type = null , $ args = array ( ) ) { return new static ( $ e -> getMessage ( ) , $ field , $ value , $ type , $ e -> getDomain ( ) , $ args ) ; }
|
Convert an UserException into an InvalidFieldException using other parameters
|
16,305
|
public function register ( PregDateLexerInterface $ lexer ) { $ this -> regexp .= $ lexer -> getExpression ( ) ; $ this -> lexers [ ] = $ lexer ; }
|
Registers a pattern in the collection .
|
16,306
|
protected function compileExpressions ( ) { if ( count ( $ this -> expressions ) === 0 ) { throw new BadMethodCallException ( 'Can\'t compile an empty expression' ) ; } if ( count ( $ this -> expressions ) === 1 ) { return reset ( $ this -> expressions ) ; } $ parts = [ ] ; foreach ( $ this -> expressions as $ expr ) { $ expr = '(?:' . $ expr . ')' ; $ parts [ ] = $ expr ; } return '(?:' . implode ( '|' , $ parts ) . ')' ; }
|
Compile expression list .
|
16,307
|
function getConnection ( ) { try { if ( is_null ( $ this -> conn ) ) { $ this -> conn = new PDO ( $ this -> getDbDsn ( ) , $ this -> getDbUser ( ) , $ this -> getDbPass ( ) ) ; } return $ this -> conn ; } catch ( PDOException $ e ) { print "Error!: " . $ e -> getMessage ( ) . "<br/>" ; die ( ) ; } }
|
Open a mysql connection .
|
16,308
|
public function sendMessage ( $ recipients , $ sender , $ subject , $ templateName , array $ context = array ( ) ) { $ this -> client -> sendMessage ( $ this -> createMessage ( $ recipients , $ sender , $ subject , $ this -> render ( $ templateName , $ context ) ) ) ; }
|
Send a transactional message using the given template .
|
16,309
|
public function getInputOptionsSynopsis ( definitions \ Options $ definitions , array $ options = null ) { if ( $ definitions -> isEmpty ( ) ) { return '' ; } if ( $ options [ 'short_synopsis' ] ?? false ) { return '[options]' ; } $ items = [ ] ; foreach ( $ definitions as $ option ) { $ items [ ] = $ this -> getInputOptionSynopsis ( $ option , $ options ) ; } return implode ( ' ' , $ items ) ; }
|
Provides a synopsis for the given Input Option Definitions .
|
16,310
|
public function getInputOptionSynopsis ( input \ Option $ definition , array $ options = null ) { $ shortcut = $ definition -> getShortcut ( ) ? sprintf ( '-%s|' , $ definition -> getShortcut ( ) ) : '' ; if ( $ value = $ definition -> getValue ( ) ) { $ format = $ value -> is ( input \ Value :: REQUIRED ) ? '%s--%s="..."' : '%s--%s[="..."]' ; } else { $ format = '%s--%s' ; } return sprintf ( '[' . $ format . ']' , $ shortcut , $ definition -> getName ( ) ) ; }
|
Provides a synopsis for the given Input Option .
|
16,311
|
public function getInputArgumentsSynopsis ( definitions \ Arguments $ definitions , array $ options = null ) { if ( $ definitions -> isEmpty ( ) ) { return '' ; } $ items = [ ] ; foreach ( $ definitions as $ argument ) { $ items [ ] = $ this -> getInputArgumentSynopsis ( $ argument , $ options ) ; } return implode ( ' ' , $ items ) ; }
|
Provides a synopsis for the given Input Argument Definitions .
|
16,312
|
public function getInputArgumentSynopsis ( input \ Argument $ definition , array $ options = null ) { $ output = '\<' . $ definition -> getName ( ) . '>' ; $ value = $ definition -> getValue ( ) ; if ( ! $ value -> is ( input \ Value :: REQUIRED ) ) { $ output = '[' . $ output . ']' ; } elseif ( $ value instanceof input \ values \ Multiple ) { $ output = $ output . ' (' . $ output . ')' ; } if ( $ value instanceof input \ values \ Multiple ) { $ output .= '...' ; } return $ output ; }
|
Provides a synopsis for the given Input Argument .
|
16,313
|
public static function getDisplayValue ( $ value ) { switch ( $ value ) { case self :: ACTIVE : return 'Active' ; case self :: ARCHIVED : return 'Archived' ; case self :: PENDING : return 'Pending' ; case self :: CORRUPT : return 'Corrupt' ; default : return $ value ; } }
|
Data is known to be corrupt
|
16,314
|
protected function getPWHashFunction ( AbstractData $ data , $ passwordField , $ saltField ) { $ that = $ this ; return function ( Entity $ entity ) use ( $ data , $ passwordField , $ saltField , $ that ) { $ password = $ entity -> get ( $ passwordField ) ; if ( ! $ password ) { return true ; } $ salt = $ entity -> get ( $ saltField ) ; $ newSalt = $ that -> possibleGenSalt ( $ salt , $ entity , $ saltField ) ; $ passwordHash = $ this -> encoder -> encodePassword ( $ password , $ salt ) ; $ doGenerateHash = $ that -> doGenerateHash ( $ data , $ entity , $ passwordField , $ password , $ newSalt ) ; if ( $ doGenerateHash ) { $ entity -> set ( $ passwordField , $ passwordHash ) ; } return true ; } ; }
|
Gets a closure for possibly generating a password hash in the entity .
|
16,315
|
public function possibleGenSalt ( & $ salt , Entity $ entity , $ saltField ) { if ( ! $ salt ) { $ salt = $ this -> getSalt ( 40 ) ; $ entity -> set ( $ saltField , $ salt ) ; return true ; } return false ; }
|
Generates a new salt if the given salt is null .
|
16,316
|
public function doGenerateHash ( AbstractData $ data , Entity $ entity , $ passwordField , $ password , $ newSalt ) { $ doGenerateHash = true ; $ id = $ entity -> get ( 'id' ) ; if ( $ id !== null ) { $ oldEntity = $ data -> get ( $ entity -> get ( 'id' ) ) ; $ doGenerateHash = $ oldEntity -> get ( $ passwordField ) !== $ password || $ newSalt ; } return $ doGenerateHash ; }
|
Determines whether the entity needs a new hash generated .
|
16,317
|
public function getSalt ( $ len ) { $ chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-=_+' ; $ l = strlen ( $ chars ) - 1 ; $ str = '' ; for ( $ i = 0 ; $ i < $ len ; ++ $ i ) { $ str .= $ chars [ mt_rand ( 0 , $ l ) ] ; } return $ str ; }
|
Generates a random salt of the given length .
|
16,318
|
public function addEvents ( AbstractData $ data , $ passwordField = 'password' , $ saltField = 'salt' ) { $ that = $ this ; $ saltGenFunction = function ( Entity $ entity ) use ( $ saltField , $ that ) { $ salt = $ that -> getSalt ( 40 ) ; $ entity -> set ( $ saltField , $ salt ) ; return true ; } ; $ data -> getEvents ( ) -> push ( 'before' , 'create' , $ saltGenFunction ) ; $ pwHashFunction = $ this -> getPWHashFunction ( $ data , $ passwordField , $ saltField ) ; $ data -> getEvents ( ) -> push ( 'before' , 'create' , $ pwHashFunction ) ; $ data -> getEvents ( ) -> push ( 'before' , 'update' , $ pwHashFunction ) ; }
|
Setups CRUDlex with some events so the passwords get salted and hashed properly .
|
16,319
|
public function append ( SemigroupInterface $ other ) { if ( $ other instanceof static ) { return new static ( array_merge ( $ this -> value , $ other -> value ) ) ; } $ this -> throwMismatchedDataTypeException ( $ other ) ; }
|
Append another semigroup and return the result .
|
16,320
|
protected function triggerOnStartup ( ) : AbstractApplication { foreach ( $ this -> getModules ( ) as $ module ) { if ( $ module instanceof StartupProviderInterface ) { $ module -> onStartup ( $ this -> getServiceLocator ( ) ) ; } } return $ this ; }
|
Trigger startup providers .
|
16,321
|
protected function triggerOnShutdown ( ) : AbstractApplication { foreach ( $ this -> getModules ( ) as $ module ) { if ( $ module instanceof ShutdownProviderInterface ) { $ module -> onShutdown ( $ this -> getServiceLocator ( ) ) ; } } return $ this ; }
|
Trigger shutdown providers .
|
16,322
|
public function pong ( EventInterface $ event , EventQueueInterface $ queue ) { $ params = $ event -> getParams ( ) ; $ queue -> ircPong ( $ params [ 'server1' ] ) ; }
|
Responds to server ping events .
|
16,323
|
public static function each ( string $ str , callable $ callable , string $ encoding = null , ... $ args ) : string { if ( $ str === '' ) { return $ str ; } $ result = '' ; $ encoding = $ encoding ? : utils \ Str :: encoding ( $ str ) ; $ length = mb_strlen ( $ str , $ encoding ) ; for ( $ idx = 0 ; $ idx < $ length ; $ idx ++ ) { $ result .= ( string ) call_user_func ( $ callable , mb_substr ( $ str , $ idx , 1 , $ encoding ) , $ idx , ... $ args ) ; } return $ result ; }
|
Runs the given callable over each character in the given string and returns the resulting string .
|
16,324
|
public static function toBinaryString ( string $ character ) : string { $ result = null ; $ length = strlen ( $ character ) ; for ( $ i = 0 ; $ i < $ length ; ++ $ i ) { $ result .= sprintf ( '%08b' , ord ( $ character [ $ i ] ) ) ; } return $ result ; }
|
Returns the binary string representation of the given character . Multi - byte safe .
|
16,325
|
public static function toDecimalCode ( string $ character ) : int { $ code = ord ( $ character [ 0 ] ) ; if ( ! ( $ code & 0x80 ) ) { return $ code ; } $ bytes = 1 ; if ( 0xc0 === ( $ code & 0xe0 ) ) { $ code = $ code & ~ 0xc0 ; $ bytes = 2 ; } elseif ( 0xe0 === ( $ code & 0xf0 ) ) { $ code = $ code & ~ 0xe0 ; $ bytes = 3 ; } elseif ( 0xf0 === ( $ code & 0xf8 ) ) { $ code = $ code & ~ 0xf0 ; $ bytes = 4 ; } for ( $ i = 2 ; $ i <= $ bytes ; $ i ++ ) { $ code = ( $ code << 6 ) + ( ord ( $ character [ $ i - 1 ] ) & ~ 0x80 ) ; } return $ code ; }
|
Returns the decimal code representation of the given character . Multi - byte safe .
|
16,326
|
public function addClass ( DocumentMetadata $ metadata ) : void { $ this -> graph -> addNode ( $ metadata -> name ) ; $ assocNames = $ metadata -> getAssociationNames ( ) ; foreach ( $ assocNames as $ assocName ) { $ targetClass = $ metadata -> getAssociationTargetClass ( $ assocName ) ; $ this -> graph -> addNode ( $ targetClass ) ; $ this -> graph -> connect ( $ metadata -> name , $ targetClass ) ; } }
|
Adds a document class to the dependency graph and evaluates its associations .
|
16,327
|
public function getOrder ( array $ classNames ) : array { $ elements = array_filter ( iterator_to_array ( $ this -> graph ) , function ( $ element ) use ( $ classNames ) : bool { list ( $ node ) = $ element ; return in_array ( $ node -> getClassName ( ) , $ classNames ) ; } ) ; return array_reverse ( $ elements , false ) ; }
|
Gets the commit order set .
|
16,328
|
public function setEntities ( array $ entities ) { foreach ( $ entities as $ entity ) { if ( ! $ entity instanceof AbstractEntity ) { $ message = sprintf ( 'Expected an array of entities. Array contains element of type %s.' , gettype ( $ entity ) ) ; throw new InvalidArgumentException ( $ message ) ; } } $ this -> entities = $ entities ; }
|
Set the entities wrapped by this class
|
16,329
|
public function getArrayCopy ( ) { $ results = array_map ( function ( $ entity ) { return $ entity -> getArrayCopy ( ) ; } , $ this -> entities ) ; if ( ! $ this -> paginationData ) { return $ results ; } else { $ data = $ this -> paginationData -> getArrayCopy ( ) ; $ data [ 'results' ] = $ results ; return $ data ; } }
|
Return an array representation of the object
|
16,330
|
private function setAccessControllers ( ) : void { $ this -> absolutePathToAccessControllers = [ ] ; $ route = $ this -> routingBasePath ; foreach ( $ this -> getRealArgs ( ) as $ arg ) { $ route .= $ arg . '/' ; $ path = $ route . 'access.php' ; if ( \ is_file ( $ path ) ) { array_unshift ( $ this -> absolutePathToAccessControllers , $ path ) ; break ; } } }
|
Set the access controller closures .
|
16,331
|
private function createRoute ( ) : void { $ this -> virtualArgs = [ ] ; $ this -> realArgs = \ explode ( '/' , $ this -> url ) ; do { if ( $ this -> setMainController ( $ this -> routingBasePath . implode ( '/' , $ this -> realArgs ) ) ) return ; array_unshift ( $ this -> virtualArgs , array_pop ( $ this -> realArgs ) ) ; } while ( count ( $ this -> realArgs ) > 0 ) ; throw new NoControllerFoundException ( ) ; }
|
Calculate the route and route parameters .
|
16,332
|
private function setMainController ( string $ route ) : bool { if ( ! \ is_dir ( $ route ) ) return false ; foreach ( $ this -> requestNames [ $ this -> requestType ] as $ requestName ) { $ path = $ route . '/' . $ requestName ; if ( \ is_file ( $ path ) ) { $ this -> absolutePathToMainController = $ path ; return true ; } } return false ; }
|
Set the main controller closure to the most fitting controller .
|
16,333
|
public function pop ( interfaces \ Style $ searched = null ) : interfaces \ Style { if ( empty ( $ this -> styles ) ) { return $ this -> default ; } if ( ! isset ( $ searched ) ) { return array_pop ( $ this -> styles ) ; } foreach ( array_reverse ( $ this -> styles , true ) as $ index => $ stackedStyle ) { if ( $ searched -> apply ( '' ) === $ stackedStyle -> apply ( '' ) ) { $ this -> styles = array_slice ( $ this -> styles , 0 , $ index ) ; return $ stackedStyle ; } } throw new \ InvalidArgumentException ( 'Encountered an incorrectly nested formatting style tag' ) ; }
|
Pops a style from the Stack .
|
16,334
|
public function current ( ) : interfaces \ Style { return ! empty ( $ this -> styles ) ? end ( $ this -> styles ) : $ this -> default ; }
|
Returns the current topmost Style in the stack or the default Style if none is stacked .
|
16,335
|
public function requestUrl ( ApiResourceInterface $ resource ) { $ resourcePath = $ this -> resourcePath ( ) . '/' . $ this -> getResourceId ( ) ; return $ resource -> apiUrl ( $ resourcePath ) ; }
|
HTTP request URL .
|
16,336
|
public static function postInstall ( Event $ event ) { $ vendor_dir = $ event -> getComposer ( ) -> getConfig ( ) -> get ( 'vendor-dir' ) ; $ base_dir = dirname ( $ vendor_dir ) ; $ config_file = $ base_dir . '/config/public_vendor.json' ; $ gitignore_file = $ base_dir . '/.gitignore' ; if ( file_exists ( $ config_file ) ) { $ config = json_decode ( file_get_contents ( $ config_file ) , true ) ; if ( $ config === null ) { throw new \ RuntimeException ( 'Error loading configuration file' ) ; } foreach ( $ config [ 'map' ] as $ map ) { if ( array_key_exists ( $ map [ 'vendor' ] , $ config [ 'vendors' ] ) ) { $ destiny = $ base_dir . '/' . $ config [ 'vendors' ] [ $ map [ 'vendor' ] ] . '/' . trim ( $ map [ 'destiny' ] , '/' ) ; $ source = $ vendor_dir . '/' . trim ( $ map [ 'source' ] , '/' ) ; if ( ! file_exists ( dirname ( $ destiny ) ) ) { mkdir ( dirname ( $ destiny ) , 0755 , true ) ; } if ( ! file_exists ( $ destiny ) ) { symlink ( $ source , $ destiny ) ; } } else { throw new \ RuntimeException ( 'Undefined vendor' ) ; } } $ gitignore = ( file_exists ( $ gitignore_file ) ) ? file ( $ gitignore_file , FILE_IGNORE_NEW_LINES ) : [ '/vendor/' ] ; foreach ( $ config [ 'vendors' ] as $ vendor_path ) { $ ignore_path = '/' . trim ( $ vendor_path , '/' ) . '/' ; if ( ! in_array ( $ ignore_path , $ gitignore ) ) { $ gitignore [ ] = $ ignore_path ; } } $ gitignore_handle = fopen ( $ gitignore_file , 'w' ) ; fwrite ( $ gitignore_handle , implode ( "\n" , $ gitignore ) . "\n" ) ; fclose ( $ gitignore_handle ) ; } else { throw new \ RuntimeException ( 'Configuration file not found' ) ; } }
|
Callback for Composer s post - install - cmd
|
16,337
|
public static function getSubPath ( $ pFileName , $ pDepth = 3 ) { if ( empty ( $ pFileName ) ) { return DS ; } $ levels = array ( ) ; for ( $ i = 0 ; $ i < $ pDepth ; $ i ++ ) { $ levels [ ] = substr ( $ pFileName , $ i , 1 ) ; } return implode ( DS , $ levels ) . DS ; }
|
Create a path to store files in multiple subdirectories based on first letters of filename .
|
16,338
|
public static function write ( $ pFile , $ pContent , $ pAppend = false ) { if ( ! is_writable ( $ pFile ) ) { self :: create ( $ pFile ) ; } if ( $ pAppend ) { return ( file_put_contents ( $ pFile , $ pContent , FILE_APPEND | LOCK_EX ) ) ; } return ( file_put_contents ( $ pFile , $ pContent , LOCK_EX ) ) ; }
|
Write content to a file .
|
16,339
|
public static function chmod ( $ pFile , $ pMode ) { if ( strpos ( $ pMode , '0' ) !== 0 ) { $ mode = octdec ( '0' . $ pMode ) ; } else { $ mode = octdec ( $ pMode ) ; } return chmod ( $ pFile , $ mode ) ; }
|
CHMOD a file .
|
16,340
|
public function withCallback ( callable $ theCallback ) { $ copy = clone $ this ; foreach ( $ this -> states as $ key => $ s ) { foreach ( $ s -> conditions as $ c ) { if ( $ c -> nextState === State :: MATCH_FOUND ) { $ copy -> callbacks [ $ key ] [ State :: MATCH_FOUND ] = $ theCallback ; } } } return $ copy ; }
|
Set the pattern s match callback
|
16,341
|
public static function getParent ( $ className ) { $ reflection = ClassType :: from ( $ className ) ; $ parent = $ reflection -> getParentClass ( ) ; return $ parent ? $ parent -> getName ( ) : $ parent ; }
|
Get parent class
|
16,342
|
public function getData ( ) { $ values = array_filter ( filter_input_array ( INPUT_POST ) ) ; foreach ( $ values as $ key => $ value ) { if ( is_array ( $ value ) ) { $ values [ $ key ] = array_filter ( $ value ) ; } } return $ values + $ _FILES ; }
|
Devuelve todos losd atos enviados de un formulario
|
16,343
|
public function is ( $ method ) { $ m = strtolower ( $ method ) ; if ( ( $ m == 'post' || $ m == 'ajax' ) && $ this -> _method == 'ajax-post' ) { return TRUE ; } return $ m == $ this -> _method ; }
|
Verifica el tipo de request dado
|
16,344
|
public function data ( $ name , $ filter = FILTER_DEFAULT , $ flag = NULL ) { $ data = $ flag ? filter_input ( INPUT_POST , $ name , $ filter , $ flag ) : filter_input ( INPUT_POST , $ name , $ filter ) ; return $ data ; }
|
Devuelve el dato enviado por POST
|
16,345
|
public function url ( $ name ) { if ( key_exists ( $ name , $ this -> _url ) ) { return $ this -> _url [ $ name ] ; } return htmlentities ( utf8_decode ( filter_input ( INPUT_GET , $ name , FILTER_SANITIZE_STRING ) ) ) ; }
|
Devuelve el dato enviado por GET
|
16,346
|
public function cookie ( $ name ) { if ( in_array ( $ name , $ this -> cookies ) ) { return filter_input ( INPUT_COOKIE , $ name , FILTER_SANITIZE_STRING ) ; } return NULL ; }
|
Devuelve el dato de una COOKIE
|
16,347
|
public function aliasSet ( $ value ) { $ columns = $ this -> getColumns ( ) ; $ this -> aliasGet ( $ oldValue ) ; foreach ( $ columns as & $ column ) { $ tableAlias = $ column [ 0 ] ; if ( $ tableAlias === $ oldValue ) { $ column [ 0 ] = $ value ; } } $ select = $ this -> getSelect ( ) ; $ from = $ select -> getPart ( Zend_Db_Select :: FROM ) ; $ select -> reset ( Zend_Db_Select :: FROM ) ; foreach ( $ from as $ tableAlias => $ descriptor ) { if ( $ tableAlias === $ oldValue ) { unset ( $ from [ $ oldValue ] ) ; $ from [ $ value ] = $ descriptor ; } } $ select -> from ( array ( $ value => $ this -> getTable ( ) ) , array ( ) ) ; return $ this -> setAlias ( $ value ) -> resetColumns ( $ columns ) ; }
|
Replaces current alias with different one .
|
16,348
|
public function deleteBy ( $ condition = null ) { if ( ! is_null ( $ condition ) ) { $ this -> filterBy ( $ condition ) ; } $ matched = $ this -> load ( ) ; array_each ( $ matched , function ( $ model ) { $ model -> delete ( ) ; } ) ; return ! empty ( $ matched ) ; }
|
Delete records by specified conditions .
|
16,349
|
public function beforePrepare ( Event $ event ) { $ command = $ event [ 'command' ] ; $ operation = $ command -> getOperation ( ) ; $ client = $ command -> getClient ( ) ; if ( $ command -> getName ( ) !== 'updateEntity' ) return ; if ( $ operation -> getParam ( 'collection' ) -> getDefault ( ) !== 'user' ) return ; $ statusValue = false ; if ( $ command -> offsetExists ( Model :: DELETED_AT ) ) { $ statusValue = $ command -> offsetGet ( Model :: DELETED_AT ) ; } elseif ( $ command -> offsetExists ( '_kmd' ) ) { $ _kmd = array_dot ( $ command -> offsetGet ( '_kmd' ) ) ; $ statusField = MODEL :: DELETED_AT ; $ statusField = str_replace ( '_kmd.' , '' , MODEL :: DELETED_AT ) ; if ( array_key_exists ( $ statusField , $ _kmd ) ) { $ statusValue = $ _kmd [ $ statusField ] ; } } if ( $ statusValue === false ) { return ; } elseif ( ! is_null ( $ statusValue ) ) { $ event -> stopPropagation ( ) ; $ suspendCommand = $ client -> getCommand ( 'deleteEntity' , array ( 'collection' => 'user' , '_id' => $ command -> offsetGet ( '_id' ) , ) ) ; $ suspendCommand -> execute ( ) ; } else { $ event -> stopPropagation ( ) ; $ restoreCommand = $ client -> getCommand ( 'restore' , array ( '_id' => $ command -> offsetGet ( '_id' ) , ) ) ; $ restoreCommand -> execute ( ) ; } }
|
Map Laravel s soft delete action to Kinvey s user suspend endpoint .
|
16,350
|
public function getProcess ( $ pid = null ) { if ( is_null ( $ pid ) ) { $ pid = $ this -> pid ; } if ( is_null ( $ pid ) ) { throw new ProcessFinderException ( 'Pid is required' ) ; } $ process = $ this -> api -> getProcessByPid ( $ pid ) ; return count ( $ process ) ? $ process [ 0 ] : false ; }
|
If the process exists will return the array else if not found will return false .
|
16,351
|
public function getRouteName ( $ resourceName = null , $ action ) { $ resourceName = $ resourceName ?? $ this -> resourceName ; return $ this -> alias . $ resourceName . '.' . $ action ; }
|
Get route name for the specified resource and action .
|
16,352
|
public function getViewsLocation ( $ resourceName = null ) { $ resourceName = $ resourceName ?? $ this -> resourceName ; return $ this -> module . $ this -> theme . $ resourceName ; }
|
Get views location for the specified resource .
|
16,353
|
public function getVendorViewsLocation ( $ resourceName = null ) { $ resourceName = $ resourceName ?? $ this -> resourceName ; if ( $ this -> package ) { $ package = str_finish ( $ this -> package , '.' ) ; } return 'vendor.' . $ package . $ this -> theme . $ resourceName ; }
|
Get vendor views location for the specified resource .
|
16,354
|
protected function loadModulePath ( $ path , $ locale , $ name , $ author ) { if ( $ this -> files -> exists ( $ full = "{$path}/{$author}/{$name}/translate/{$locale}.php" ) ) { return $ this -> files -> getRequire ( $ full ) ; } return [ ] ; }
|
load module file translated
|
16,355
|
public function loadModule ( $ locale , $ name , $ author ) { if ( isset ( $ this -> hints [ 'Modules' ] ) ) { return $ this -> loadModulePath ( $ this -> hints [ 'Modules' ] , $ locale , $ name , $ author ) ; } return [ ] ; }
|
get file from modules
|
16,356
|
public function run ( $ argv ) { $ args = $ this -> getArgs ( $ argv ) ; if ( array_key_exists ( $ args [ 1 ] , $ this -> commands ) ) { $ callback = $ this -> commands [ $ args [ 1 ] ] ; $ args = array_slice ( $ args , 2 ) ; if ( is_callable ( $ callback ) ) { return $ this -> injectionClosure ( $ callback , $ args ) ; } if ( is_string ( $ callback ) ) { if ( strpos ( $ callback , '>' ) !== false ) { list ( $ controller , $ method ) = explode ( '>' , $ callback ) ; return $ this -> injectionClass ( $ controller , $ method , $ args ) ; } return $ this -> injectionClass ( $ callback , '__invoke' , $ args ) ; } } throw new \ Exception ( 'command line callback not found.' ) ; }
|
Match and run a command line .
|
16,357
|
public function getLibSrc ( $ ver ) { if ( ! $ this -> isValidVersion ( $ ver ) ) { throw new \ Exception ( sprintf ( 'Invalid library version provided "%s"' , $ ver ) ) ; } $ options = $ this -> options ; $ cdnUrl = rtrim ( $ options [ 'cdn-base' ] , '/' ) . '/' . trim ( $ options [ 'cdn-subfolder' ] , '/' ) . '/' . $ ver . '/' . trim ( $ options [ 'cdn-file-path' ] , '/' ) ; return $ cdnUrl ; }
|
Get src to library for specific version
|
16,358
|
public function generateTableOptions ( Table $ table ) { $ code = [ ] ; $ options = $ table -> getOptions ( ) ; $ code = $ this -> valuetize ( $ options ) ; return $ code === '[]' ? '' : ', ' . $ code ; }
|
generate table options
|
16,359
|
public function generateColumnOptions ( Column $ column ) { $ options = [ ] ; $ keys = [ 'length' , 'default' , 'collation' , 'null' , 'precision' , 'scale' , 'after' , 'update' , 'comment' ] ; foreach ( $ keys as $ key ) { $ method = "get{$key}" ; if ( $ key === 'length' ) $ method = 'getLimit' ; $ value = $ column -> $ method ( ) ; if ( $ key === 'collation' ) { if ( $ value === null ) { $ key = 'charset' ; $ value = $ column -> getCharset ( ) ; } } if ( $ value === null ) continue ; if ( $ key === 'null' && $ value === false ) continue ; $ options [ $ key ] = $ value ; } $ code = $ this -> valuetize ( $ options ) ; return $ code === '[]' ? '' : ', ' . $ code ; }
|
generate column options
|
16,360
|
public function isSinglePrimaryKeyColumn ( Table $ table , Column $ column ) { $ options = $ table -> getOptions ( ) ; if ( ! $ options && $ column -> getName ( ) === 'id' ) return true ; if ( isset ( $ options [ 'id' ] ) && $ options [ 'id' ] == $ column -> getName ( ) ) return true ; return false ; }
|
is single primary key column ?
|
16,361
|
protected function createFactory ( ) { if ( ! class_exists ( $ this -> factoryClass ) ) { throw new RuntimeException ( sprintf ( 'Failed to create an instance of non-existing factory class "%s".' , $ this -> factoryClass ) ) ; } $ class = $ this -> factoryClass ; switch ( count ( $ this -> args ) ) { case 0 : $ factory = new $ class ( ) ; break ; case 1 : $ factory = new $ class ( $ this -> args [ 0 ] ) ; break ; case 2 : $ factory = new $ class ( $ this -> args [ 0 ] , $ this -> args [ 1 ] ) ; break ; case 3 : $ factory = new $ class ( $ this -> args [ 0 ] , $ this -> args [ 1 ] , $ this -> args [ 2 ] ) ; break ; case 4 : $ factory = new $ class ( $ this -> args [ 0 ] , $ this -> args [ 1 ] , $ this -> args [ 2 ] , $ this -> args [ 3 ] ) ; break ; default : $ reflection = new ClassReflection ( $ class ) ; $ factory = $ reflection -> newInstanceArgs ( $ this -> args ) ; break ; } if ( ! $ factory instanceof FactoryInterface ) { throw new LogicException ( sprintf ( 'Invalid service factory. Factory is expected to be an instance of %s, %s given.' , 'Zend\ServiceManager\FactoryInterface' , get_class ( $ factory ) ) ) ; } return $ factory ; }
|
Create the factory on demand
|
16,362
|
public static function stripAttributes ( $ routeString , & $ route , $ withParameters = true ) { $ route [ 'query' ] = [ ] ; $ route [ 'fragment' ] = '' ; $ route [ 'parameters' ] = [ ] ; $ regex = '/^(.*?)(?:\?([^?#]*))?(?:#([^#?]*))?$/' ; preg_match ( $ regex , $ routeString , $ matches ) ; if ( isset ( $ matches [ 2 ] ) ) { parse_str ( $ matches [ 2 ] , $ query ) ; $ route [ 'query' ] = $ query ; } if ( isset ( $ matches [ 3 ] ) ) { $ route [ 'fragment' ] = $ matches [ 3 ] ; } if ( $ withParameters ) { } return $ matches [ 1 ] ; }
|
Strip fragment query and optionally parameters from a route string .
|
16,363
|
protected function _assignDefinitionContainer ( callable $ definition , BaseContainerInterface $ container ) { return function ( BaseContainerInterface $ c ) use ( $ definition , $ container ) { $ args = func_get_args ( ) ; $ args [ 0 ] = $ container ; return $ this -> _invokeCallable ( $ definition , $ args ) ; } ; }
|
Wraps the given definition such that it will receive the given container .
|
16,364
|
public function perform ( ) { $ app = $ this -> application ( ) ; $ command = $ this -> getConsoleCommand ( $ app ) ; $ inputDefinition = $ this -> getInputDefinition ( $ this -> args ) ; $ input = new ArrayInput ( $ this -> args , $ inputDefinition ) ; $ output = new ConsoleOutput ; try { $ command -> run ( $ input , $ output ) ; } catch ( \ Exception $ e ) { $ output -> writeln ( 'Exception: ' . $ e -> getMessage ( ) ) ; $ output -> writeln ( 'Code: ' . $ e -> getCode ( ) ) ; $ output -> writeln ( 'Stack trace: ' . $ e -> getTraceAsString ( ) ) ; throw $ e ; } }
|
Manually load configure and run the console command
|
16,365
|
protected function application ( ) { $ applicationInitializer = new ApplicationInitializer ; $ app = $ applicationInitializer -> initialize ( ) ; $ defaultServices = new \ Synapse \ Application \ Services ; $ defaultServices -> register ( $ app ) ; $ appServices = new \ Application \ Services ; $ appServices -> register ( $ app ) ; return $ app ; }
|
Return the Silex application loaded with all routes and services
|
16,366
|
protected function getInputDefinition ( array $ args ) { $ definition = new InputDefinition ( ) ; foreach ( $ args as $ field => $ value ) { $ definition -> addArgument ( new InputArgument ( $ field ) ) ; } return $ definition ; }
|
Get an InputDefinition formed by the arguments provided
|
16,367
|
protected function initializeConfig ( array $ config = null ) { $ default = $ this -> defaultConfigurations ( ) ; $ this -> config = $ config ? array_replace_recursive ( $ default , $ config ) : $ default ; }
|
Overrides default configurations with user supplied values .
|
16,368
|
protected function getTotalOfRecordsString ( int $ totalOfRecords , array $ data ) { $ show = $ data [ 'show' ] ; $ page = $ data [ 'page' ] ; $ startRecord = 0 ; if ( intval ( $ totalOfRecords ) > 0 ) { $ startRecord = ( $ show * ( $ page - 1 ) ) + 1 ; } $ endRecord = $ show * $ page ; if ( $ endRecord > $ totalOfRecords ) { $ endRecord = $ totalOfRecords ; } return $ this -> trans ( 'totalOfRecordsString' , [ '%$startRecord%' => $ startRecord , '%$endRecord%' => $ endRecord , '%$totalOfRecords%' => $ totalOfRecords , ] , 'messages' ) ; }
|
Calculates the total of records string
|
16,369
|
public function setPath ( $ path ) { if ( ! is_readable ( $ path ) ) { throw new \ InvalidArgumentException ( 'The passed path is not readable: ' . $ path ) ; } $ this -> path = $ path ; $ this -> source = file_get_contents ( $ path ) ; return $ this ; }
|
Set the path to the source file .
|
16,370
|
public function getOutputFilename ( $ prefix = null ) { $ fileInfo = $ this -> getFileInformation ( ) ; $ filename = str_replace ( '/' , '_' , $ fileInfo -> getPathname ( ) ) ; if ( null !== $ prefix ) { $ filename = substr ( $ filename , strlen ( $ prefix ) ) ; } return strtr ( ltrim ( $ filename , '_' ) , array ( '.' . $ fileInfo -> getExtension ( ) => '.html' ) ) ; }
|
Get the name for this Pinocchio s output file .
|
16,371
|
protected static function parseResourceBundle ( $ p_rb , $ p_prefix = '' ) { $ p_prefix = rtrim ( $ p_prefix , '.' ) ; $ values = array ( ) ; if ( $ p_rb instanceof \ ResourceBundle ) { foreach ( $ p_rb as $ k => $ v ) { if ( is_object ( $ v ) ) { $ temp = self :: parseResourceBundle ( $ v , ( $ p_prefix == '' ? '' : $ p_prefix . '.' ) . print_r ( $ k , true ) . '.' ) ; $ values = array_merge ( $ values , $ temp ) ; } else { $ values [ $ p_prefix . '.' . $ k ] = $ v ; } } } return $ values ; }
|
Parse des ressources
|
16,372
|
public static function getAsArray ( $ p_name , $ p_path , $ p_prefix = '' ) { $ ressource = new \ ResourceBundle ( $ p_name , $ p_path ) ; $ arr = self :: parseResourceBundle ( $ ressource , $ p_prefix ) ; return $ arr ; }
|
Retourne les traductions sous forme de tableau
|
16,373
|
protected function getMethodNotAllowedResponse ( MethodNotAllowed $ exception ) : ResponseInterface { return ( new Response ( ) ) -> withStatusCode ( 405 ) -> withHeader ( 'Allow' , implode ( ', ' , $ exception -> getAllowedMethods ( ) ) ) -> withBody ( [ 'type' => '' , 'title' => 'Method not allowed.' , 'method' => $ exception -> getMethod ( ) , 'allowed_methods' => $ exception -> getAllowedMethods ( ) , ] ) ; }
|
Get response for MethodNotAllowed exception .
|
16,374
|
protected function getNotFoundResponse ( NotFound $ exception ) : ResponseInterface { return ( new Response ( ) ) -> withStatusCode ( 404 ) -> withBody ( [ 'type' => '' , 'title' => 'Not found.' , 'path' => $ exception -> getRequest ( ) -> getUri ( ) -> toRelative ( ) , ] ) ; }
|
Get response for NotFound exception .
|
16,375
|
protected function getInvalidQueryStringResponse ( InvalidQueryString $ exception ) : ResponseInterface { return ( new Response ( ) ) -> withStatusCode ( 400 ) -> withBody ( [ 'type' => '' , 'title' => 'Invalid query string.' , 'parameter' => $ exception -> getParameter ( ) , 'reason' => $ exception -> getResult ( ) , ] ) ; }
|
Get response for InvalidQueryString exception .
|
16,376
|
public function getText ( $ key ) { if ( isset ( $ this -> data [ $ key ] ) ) { return $ this -> data [ $ key ] ; } return $ key ; }
|
Returns a language string by looking for a matching key
|
16,377
|
public function save ( $ uri = null , $ className = null , $ extraHeaders = array ( ) ) { return $ this -> getService ( ) -> updateEntry ( $ this , $ uri , $ className , $ extraHeaders ) ; }
|
Uploads changes in this entry to the server using Zend_Gdata_App
|
16,378
|
public function reload ( $ uri = null , $ className = null , $ extraHeaders = array ( ) ) { $ editLink = $ this -> getEditLink ( ) ; if ( ( $ uri === null ) && $ editLink != null ) { $ uri = $ editLink -> getHref ( ) ; } if ( $ className === null ) { $ className = get_class ( $ this ) ; } if ( $ this -> _etag != null && ! array_key_exists ( 'If-Match' , $ extraHeaders ) && ! array_key_exists ( 'If-None-Match' , $ extraHeaders ) ) { $ extraHeaders [ 'If-None-Match' ] = $ this -> _etag ; } $ result = null ; try { $ result = $ this -> service -> importUrl ( $ uri , $ className , $ extraHeaders ) ; } catch ( Zend_Gdata_App_HttpException $ e ) { if ( $ e -> getResponse ( ) -> getStatus ( ) != '304' ) throw $ e ; } return $ result ; }
|
Reload the current entry . Returns a new copy of the entry as returned by the server or null if no changes exist . This does not modify the current entry instance .
|
16,379
|
protected static function cleanFields ( $ fields ) { $ new = [ ] ; $ fieldList = explode ( ',' , $ fields ) ; foreach ( $ fieldList as $ f ) { if ( static :: ID_FIELD !== trim ( strtolower ( $ f ) ) ) { $ new [ ] = $ f ; } } return implode ( ',' , $ new ) ; }
|
Excluding _id field from field list
|
16,380
|
protected function preCleanRecords ( $ records ) { $ new = [ ] ; foreach ( $ records as $ record ) { if ( property_exists ( $ record , $ this -> transactionTable ) ) { $ cleaned = ( array ) $ record -> { $ this -> transactionTable } ; unset ( $ cleaned [ static :: ID_FIELD ] ) ; if ( property_exists ( $ record , '_id' ) ) { $ cleaned = array_merge ( [ static :: ID_FIELD => $ record -> _id ] , $ cleaned ) ; } } else { $ cleaned = ( array ) $ record ; } $ new [ ] = $ cleaned ; } return $ new ; }
|
Cleaning Couchbase rows .
|
16,381
|
protected static function isExpression ( $ field ) { $ alias = explode ( ' as ' , $ field ) ; $ field = trim ( $ alias [ 0 ] ) ; if ( preg_match ( '/\S+\(\S*\)/' , $ field ) === 1 ) { if ( isset ( $ alias [ 1 ] ) ) { return trim ( $ alias [ 1 ] ) ; } return true ; } return false ; }
|
Checks to see if field is an expression
|
16,382
|
private function find ( $ id ) { if ( ! isset ( $ this -> registry [ $ id ] ) ) { throw new NotFoundException ( "Entry id '" . $ id . "' not found in container" ) ; } return $ this -> registry [ $ id ] ; }
|
Find the item in the registry
|
16,383
|
public function enabled ( $ name = null ) { if ( empty ( $ this -> _providers ) ) { $ this -> _providers = ( array ) Configure :: read ( 'Opauth.Strategy' ) ; } if ( empty ( $ this -> _providers ) ) { return false ; } if ( ! empty ( $ name ) ) { return isset ( $ this -> _providers [ $ name ] ) ; } return $ this -> _providers ; }
|
Check if a given provider s strategy is enabled .
|
16,384
|
public function isAuthenticated ( $ authData ) { if ( ! empty ( $ this -> _user ) ) { $ this -> updateData ( $ this -> mapData ( $ authData ) ) ; return $ this -> _user ; } $ Model = ClassRegistry :: init ( $ this -> _authenticateObject -> settings [ 'userModel' ] ) ; $ conditions = array ( $ Model -> alias . '.' . Inflector :: underscore ( $ authData [ 'provider' ] ) . '_id' => $ authData [ 'uid' ] ) ; if ( isset ( $ authData [ 'info' ] [ 'email' ] ) ) { $ conditions = array ( 'OR' => array_merge ( $ conditions , array ( $ Model -> alias . '.' . 'email' => $ authData [ 'info' ] [ 'email' ] ) ) ) ; } if ( ! empty ( $ this -> _authenticateObject -> settings [ 'scope' ] ) ) { $ conditions += $ this -> _authenticateObject -> settings [ 'scope' ] ; } $ result = $ Model -> find ( 'first' , array ( 'conditions' => $ conditions , 'contain' => $ this -> _authenticateObject -> settings [ 'contain' ] , 'recursive' => $ this -> _authenticateObject -> settings [ 'recursive' ] ) ) ; if ( empty ( $ result ) || empty ( $ result [ $ Model -> alias ] ) ) { return false ; } $ user = $ result [ $ Model -> alias ] ; if ( array_key_exists ( $ this -> _authenticateObject -> settings [ 'fields' ] [ 'password' ] , $ user ) ) { unset ( $ user [ $ this -> _authenticateObject -> settings [ 'fields' ] [ 'password' ] ] ) ; } unset ( $ result [ $ Model -> alias ] ) ; $ this -> _user = array_merge ( $ user , $ result ) ; $ this -> updateData ( $ this -> mapData ( $ authData ) ) ; return $ this -> _user ; }
|
Checks if OAuth2 user authenticates to local user base .
|
16,385
|
public function mapData ( $ authData ) { $ map = $ this -> mapKeysToFields ; list ( , $ model ) = pluginSplit ( $ this -> _authenticateObject -> settings [ 'userModel' ] ) ; $ provider = Inflector :: underscore ( $ authData [ 'provider' ] ) ; $ data = array ( $ model => array ( $ provider . '_credentials' => serialize ( $ authData [ 'credentials' ] ) ) ) ; foreach ( $ this -> mapKeysToFields as $ key => $ path ) { $ map [ $ key ] = String :: insert ( $ path , compact ( 'model' , 'provider' ) , array ( 'after' => ':' ) ) ; $ value = Hash :: get ( $ authData , $ key ) ; $ mappedKey = explode ( '.' , $ map [ $ key ] ) ; if ( ! empty ( $ this -> _user [ array_pop ( $ mappedKey ) ] ) || empty ( $ value ) ) { continue ; } $ data = Hash :: insert ( $ data , $ map [ $ key ] , Hash :: get ( $ authData , $ key ) ) ; } return $ data ; }
|
Maps Opauth s data for use in models .
|
16,386
|
public function patch ( Request $ request , Fractal $ fractal , InputGateContract $ inputGate ) { $ this -> beforeRequest ( $ request , func_get_args ( ) ) ; $ id = $ this -> parseObjectId ( $ request ) ; $ model = $ this -> loadAuthorizeObject ( $ id , 'update' ) ; $ input = $ request -> json ( ) -> all ( ) ; if ( ! is_array ( $ input ) || empty ( $ input ) ) { throw new UnprocessableEntityHttpException ( "Invalid request body" ) ; } $ attributes = $ originalAttributes = array_get ( $ input , 'data.attributes' , [ ] ) ; $ context = app ( 'context' ) ; foreach ( $ context as $ key => $ value ) { unset ( $ attributes [ $ key ] ) ; } $ relationships = array_get ( $ input , 'data.relationships' , [ ] ) ; $ attributes = $ inputGate -> process ( $ model , $ attributes , 'update' ) ; $ validatedRelationshipData = $ this -> validateRelationshipData ( $ model , $ relationships , 'update' ) ; if ( $ model -> update ( $ attributes ) && $ this -> saveRelationshipData ( $ validatedRelationshipData ) ) { return $ this -> respondWithUpdated ( $ fractal -> createData ( new FractalItem ( $ this -> loadAuthorizeObject ( $ id , 'update' ) , $ this -> getTransformer ( ) , $ this -> getResourceKey ( ) ) ) ) ; } throw new ServerErrorHttpException ( "Unable to save object. Try again later." ) ; }
|
Update the object
|
16,387
|
public function createAndSave ( $ create_vars = [ ] ) { $ new_model = $ this -> create ( $ create_vars ) ; $ model = $ this -> save ( $ new_model ) ; return $ model ; }
|
creates a new model
|
16,388
|
public function create ( $ create_vars = [ ] ) { $ new_model_doc_vars = array_merge ( $ this -> newModelDefaults ( ) , $ create_vars ) ; $ new_model_doc_vars = $ this -> onCreate_pre ( $ new_model_doc_vars ) ; return $ this -> newModel ( $ new_model_doc_vars ) ; }
|
creates a model without saving to the database
|
16,389
|
public function save ( BaseMysqlModel $ model ) { $ create_vars = $ this -> onSave_pre ( ( array ) $ model ) ; $ sql = $ this -> buildInsertStatement ( $ create_vars ) ; $ id = $ this -> connection_manager -> executeWithReconnect ( function ( $ mysql_dbh ) use ( $ sql , $ create_vars ) { $ sth = $ mysql_dbh -> prepare ( $ sql ) ; $ result = $ sth -> execute ( array_values ( $ create_vars ) ) ; return $ mysql_dbh -> lastInsertId ( ) ; } ) ; $ model [ 'id' ] = $ id ; return $ model ; }
|
saves a new model to the database
|
16,390
|
public function findByID ( $ model_or_id , $ options = null ) { $ id = $ this -> extractID ( $ model_or_id ) ; return $ this -> findOne ( [ 'id' => $ id ] , null , $ options ) ; }
|
finds a model by ID
|
16,391
|
public function findOne ( $ vars , $ order_by_keys = null , $ options = null ) { foreach ( $ this -> find ( $ vars , $ order_by_keys , 1 , $ options ) as $ model ) { return $ model ; } return null ; }
|
queries the database for a single object
|
16,392
|
public function update ( $ model_or_id , $ update_vars , $ mongo_options = [ ] ) { $ id = $ this -> extractID ( $ model_or_id ) ; $ update_vars = $ this -> onUpdate_pre ( $ update_vars , $ model_or_id ) ; $ sql = $ this -> buildUpdateStatement ( $ update_vars , [ 'id' ] ) ; $ sth = $ this -> connection_manager -> executeWithReconnect ( function ( $ mysql_dbh ) use ( $ sql , $ update_vars , $ id ) { $ sth = $ mysql_dbh -> prepare ( $ sql ) ; $ vars = $ this -> removeMysqlLiterals ( array_values ( $ update_vars ) ) ; $ vars [ ] = $ id ; $ result = $ sth -> execute ( $ vars ) ; return $ sth ; } ) ; return $ sth -> rowCount ( ) ; }
|
updates a model in the database
|
16,393
|
public static function createFromParts ( array $ parts , $ timezone = null ) { $ year = isset ( $ parts [ 0 ] ) ? $ parts [ 0 ] : date ( 'Y' ) ; $ month = isset ( $ parts [ 1 ] ) ? $ parts [ 1 ] : date ( 'm' ) ; $ day = isset ( $ parts [ 2 ] ) ? $ parts [ 2 ] : date ( 'd' ) ; $ hour = isset ( $ parts [ 3 ] ) ? $ parts [ 3 ] : 0 ; $ minute = isset ( $ parts [ 4 ] ) ? $ parts [ 4 ] : 0 ; $ second = isset ( $ parts [ 5 ] ) ? $ parts [ 5 ] : 0 ; $ micro = isset ( $ parts [ 6 ] ) ? $ parts [ 6 ] : 0 ; $ dateTimeString = sprintf ( '%04s-%02s-%02s %02s:%02s:%02s.%06s' , $ year , $ month , $ day , $ hour , $ minute , $ second , $ micro ) ; return new static ( $ dateTimeString , $ timezone ) ; }
|
Create a new DateTime instance from a specific parts of date and time .
|
16,394
|
private function next ( $ dayOfWeek ) { $ days = [ self :: SUNDAY => 'Sunday' , self :: MONDAY => 'Monday' , self :: TUESDAY => 'Tuesday' , self :: WEDNESDAY => 'Wednesday' , self :: THURSDAY => 'Thursday' , self :: FRIDAY => 'Friday' , self :: SATURDAY => 'Saturday' , ] ; $ dow = $ days [ $ dayOfWeek ] ; return $ this -> startOfDay ( ) -> modify ( "next $dow" ) ; }
|
Modify to the next occurrence of a given day of the week .
|
16,395
|
private static function localeFormat ( $ part = 'datetime' ) { if ( self :: $ localeFormat === null ) { $ locale = self :: getLocale ( ) ; $ file = resource_path ( 'lang/' . $ locale . '/datetime.php' ) ; if ( file_exists ( $ file ) ) { self :: $ localeFormat = include $ file ; } else { $ file = resource_path ( 'lang/' . config ( 'locale.fallback' ) . '/datetime.php' ) ; self :: $ localeFormat = file_exists ( $ file ) ? include $ file : [ 'datetime' => 'Y-m-d H:i' , 'date' => 'Y-m-d' , 'time' => 'H:i' ] ; } } return self :: $ localeFormat [ $ part ] ; }
|
Returns the locale date time format .
|
16,396
|
private function parseDiscriminatorField ( $ discriminatorField ) { if ( is_string ( $ discriminatorField ) ) { return $ discriminatorField ; } if ( ! is_array ( $ discriminatorField ) ) { throw new \ InvalidArgumentException ( 'Expected array or string for discriminatorField; found: ' . gettype ( $ discriminatorField ) ) ; } if ( isset ( $ discriminatorField [ 'name' ] ) ) { return ( string ) $ discriminatorField [ 'name' ] ; } if ( isset ( $ discriminatorField [ 'fieldName' ] ) ) { return ( string ) $ discriminatorField [ 'fieldName' ] ; } throw new \ InvalidArgumentException ( 'Expected "name" or "fieldName" key in discriminatorField array; found neither.' ) ; }
|
Parses the class or field - level discriminatorField option .
|
16,397
|
static function gaeutilJson ( $ project_directory , $ app_engine_project , $ gaeutil_defaults = [ ] ) { $ config_dir_location = Conf :: getConfFolderPath ( $ project_directory ) ; $ gaeutil_json_location = Conf :: getGaeUtilJsonPath ( $ project_directory ) ; Files :: ensureDirectory ( $ config_dir_location ) ; $ gaeutil_json_content = Files :: getJson ( $ gaeutil_json_location , [ ] ) ; foreach ( $ gaeutil_defaults as $ key => $ val ) { $ gaeutil_json_content [ $ key ] = $ val ; } $ project_key_name = $ gaeutil_json_content [ Secrets :: CONF_PROJECT_KEY_NAME ] ; $ project_key_parts = Secrets :: reverseKmsKey ( $ project_key_name ) ; list ( $ project , $ location , $ keyRing ) = array_values ( $ project_key_parts ) ; $ gaeutil_json_content [ Secrets :: CONF_PROJECT_KEY_NAME ] = Secrets :: getKeyName ( $ project , $ location , $ keyRing , $ app_engine_project ) ; if ( Files :: putJson ( $ gaeutil_json_location , $ gaeutil_json_content ) ) { Util :: cmdline ( "Updated gaeutil.json $project_directory" ) ; } }
|
Fixing gaeutil . json
|
16,398
|
static function packageJson ( $ project_directory , $ app_engine_project , $ app_engine_service , $ package_json_defaults = [ ] ) { $ package_json_location = $ project_directory . DIRECTORY_SEPARATOR . "package.json" ; $ package_json_content = Files :: getJson ( $ package_json_location , [ ] ) ; $ package_json_content = array_merge ( [ "name" => null , "project" => null , "private" => null , ] , $ package_json_content ) ; $ project_name = $ app_engine_project . '-' . $ app_engine_service ; $ package_json_defaults [ "private" ] = true ; $ package_json_content [ "name" ] = $ project_name ; $ package_json_content [ "project" ] = $ app_engine_project ; foreach ( $ package_json_defaults as $ key => $ val ) { $ package_json_content [ $ key ] = $ val ; } if ( $ app_engine_service == "default" ) { $ package_json_content [ "scripts" ] [ "deploy" ] = 'gcloud app deploy app.yaml queue.yaml --project $npm_package_project --promote --quiet' ; } else { $ package_json_content [ "scripts" ] [ "deploy" ] = 'gcloud app deploy app.yaml --project $npm_package_project --promote --quiet' ; } $ gaeutil_json = Files :: getJson ( Conf :: getGaeUtilJsonPath ( $ project_directory ) , [ ] ) ; $ project_key_name = $ gaeutil_json [ Secrets :: CONF_PROJECT_KEY_NAME ] ; $ project_key = Secrets :: reverseKmsKey ( $ project_key_name ) ; $ crypt_params = [ "ciphertext-file" => "config/secrets.cipher" , "plaintext-file" => "secrets.json" , "project" => $ project_key [ "project" ] , "location" => $ project_key [ "location" ] , "keyring" => $ project_key [ "keyRing" ] , "key" => $ project_key [ "cryptoKey" ] ] ; $ package_json_content [ "scripts" ] [ "encrypt" ] = self :: commandMaker ( "gcloud kms encrypt" , $ crypt_params ) ; $ package_json_content [ "scripts" ] [ "decrypt" ] = self :: commandMaker ( "gcloud kms decrypt" , $ crypt_params ) ; $ package_json_content [ "scripts" ] [ "devserve" ] = 'dev_appserver.py --port=5000 . -A $npm_package_project' ; if ( Files :: putJson ( $ package_json_location , $ package_json_content ) ) { Util :: cmdline ( "Updated package.json in $project_name" ) ; } }
|
Fixing package . json
|
16,399
|
private function info ( ) { $ response = [ 'class' => [ ] ] ; foreach ( $ this -> config [ "classes" ] as $ key => $ val ) { $ response [ "class" ] [ $ key ] [ "config" ] = ! empty ( $ val [ 1 ] ) ? $ val [ 1 ] : [ ] ; if ( ! file_exists ( $ val [ 0 ] ) ) { $ response [ "class" ] [ $ key ] [ "methods" ] = [ ] ; continue ; } require ( $ val [ 0 ] ) ; $ reflection = new \ ReflectionClass ( $ key ) ; foreach ( $ reflection -> getMethods ( ) as $ method ) { if ( ! in_array ( $ method -> getName ( ) , [ "__construct" ] ) ) { $ param = [ ] ; foreach ( $ method -> getParameters ( ) as $ parameter ) { $ param [ ] = $ parameter -> getName ( ) ; } $ response [ "class" ] [ $ key ] [ "methods" ] [ $ method -> getName ( ) ] = $ param ; } } } return $ response ; }
|
Return info about available classes
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.