idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
18,400
protected function sendActivationMail ( $ user ) { $ token = $ this -> Token -> create ( $ user -> email , [ 'type' => 'signup' , 'user_id' => $ user -> id ] ) ; return $ this -> getMailer ( 'MeCms.User' ) -> set ( 'url' , Router :: url ( [ '_name' => 'activation' , $ user -> id , $ token ] , true ) ) -> send ( 'activation' , [ $ user ] ) ; }
Internal method to send the activation mail
18,401
public function getGridColumn ( $ columns = null ) { if ( $ columns !== null ) { foreach ( $ columns as $ val ) { $ this -> defaultColumns [ ] = $ val ; } } else { $ this -> defaultColumns [ ] = 'publish' ; $ this -> defaultColumns [ ] = 'parent_id' ; $ this -> defaultColumns [ ] = 'wall_id' ; $ this -> defaultColumns [ ] = 'user_id' ; $ this -> defaultColumns [ ] = 'comment' ; $ this -> defaultColumns [ ] = 'creation_date' ; $ this -> defaultColumns [ ] = 'modified_date' ; } return $ this -> defaultColumns ; }
Get column for CGrid View
18,402
public function go ( $ sEntryPoint , InputInterface $ oInputInterface = null , OutputInterface $ oOutputInterface = null , $ bAutoExit = true ) { if ( class_exists ( '\App\Console\Bootstrap' ) && is_callable ( '\App\Console\Bootstrap::preSystem' ) ) { \ App \ Console \ Bootstrap :: preSystem ( $ this ) ; } \ Nails \ Bootstrap :: run ( $ sEntryPoint ) ; set_time_limit ( 0 ) ; $ oUtf8 = new Utf8 ( ) ; $ oInput = Factory :: service ( 'Input' ) ; if ( ! $ oInput :: isCli ( ) ) { ErrorHandler :: halt ( 'This tool can only be used on the command line.' ) ; } $ oApp = new Application ( ) ; $ oApp -> setAutoExit ( $ bAutoExit ) ; $ aCommandLocations = [ [ NAILS_APP_PATH . 'vendor/nails/common/src/Common/Console/Command/' , 'Nails\Common\Console\Command' ] , [ NAILS_APP_PATH . 'src/Console/Command/' , 'App\Console\Command' ] , ] ; $ aModules = Components :: modules ( ) ; foreach ( $ aModules as $ oModule ) { $ aCommandLocations [ ] = [ $ oModule -> path . 'src/Console/Command' , $ oModule -> namespace . 'Console\Command' , ] ; } Factory :: helper ( 'directory' ) ; $ aCommands = [ ] ; function findCommands ( & $ aCommands , $ sPath , $ sNamespace ) { $ aDirMap = directory_map ( $ sPath ) ; if ( ! empty ( $ aDirMap ) ) { foreach ( $ aDirMap as $ sDir => $ sFile ) { if ( is_array ( $ sFile ) ) { findCommands ( $ aCommands , $ sPath . DIRECTORY_SEPARATOR . $ sDir , $ sNamespace . '\\' . trim ( $ sDir , '/' ) ) ; } else { $ aFileInfo = pathinfo ( $ sFile ) ; $ sFileName = basename ( $ sFile , '.' . $ aFileInfo [ 'extension' ] ) ; $ aCommands [ ] = $ sNamespace . '\\' . $ sFileName ; } } } } foreach ( $ aCommandLocations as $ aLocation ) { list ( $ sPath , $ sNamespace ) = $ aLocation ; findCommands ( $ aCommands , $ sPath , $ sNamespace ) ; } foreach ( $ aCommands as $ sCommandClass ) { $ oApp -> add ( new $ sCommandClass ( ) ) ; } if ( class_exists ( '\App\Console\Bootstrap' ) && is_callable ( '\App\Console\Bootstrap::preCommand' ) ) { \ App \ Console \ Bootstrap :: preCommand ( $ this ) ; } $ oApp -> run ( $ oInputInterface , $ oOutputInterface ) ; if ( class_exists ( '\App\Console\Bootstrap' ) && is_callable ( '\App\Console\Bootstrap::postCommand' ) ) { \ App \ Console \ Bootstrap :: postCommand ( $ this ) ; } \ Nails \ Bootstrap :: shutdown ( ) ; if ( class_exists ( '\App\Console\Bootstrap' ) && is_callable ( '\App\Console\Bootstrap::postSystem' ) ) { \ App \ Console \ Bootstrap :: postSystem ( $ this ) ; } }
Executes the console app
18,403
protected function obfuscate ( $ mail ) { return preg_replace_callback ( '/^([^@]+)(.*)$/' , function ( $ matches ) { $ lenght = floor ( strlen ( $ matches [ 1 ] ) / 2 ) ; $ name = substr ( $ matches [ 1 ] , 0 , $ lenght ) . str_repeat ( '*' , $ lenght ) ; return $ name . $ matches [ 2 ] ; } , $ mail ) ; }
Internal method to obfuscate an email address
18,404
public function link ( $ title , $ mail , array $ options = [ ] ) { $ title = filter_var ( $ title , FILTER_VALIDATE_EMAIL ) ? $ this -> obfuscate ( $ title ) : $ title ; $ mail = Security :: encryptMail ( $ mail ) ; $ url = Router :: url ( [ '_name' => 'mailhide' , '?' => compact ( 'mail' ) ] , true ) ; $ options [ 'escape' ] = false ; $ options [ 'onClick' ] = sprintf ( 'window.open(\'%s\',\'%s\',\'resizable,height=547,width=334\'); return false;' , $ url , $ title ) ; $ options += [ 'class' => 'recaptcha-mailhide' , 'title' => $ title ] ; return $ this -> Html -> link ( $ title , $ url , $ options ) ; }
Creates a link for the page where you enter the code and from which the clear email address will be displayed
18,405
private function beginBracket ( $ op ) { $ this -> currentWhere [ ] = [ $ op => [ ] ] ; $ this -> whereStack [ ] = & $ this -> currentWhere ; end ( $ this -> currentWhere ) ; $ this -> currentWhere = & $ this -> currentWhere [ key ( $ this -> currentWhere ) ] [ $ op ] ; return $ this ; }
Begin a bracket group in the WHERE clause .
18,406
public function end ( ) { unset ( $ this -> currentWhere ) ; if ( empty ( $ this -> whereStack ) ) { trigger_error ( "Call to Query->end() without a corresponding call to Query->begin*()." , E_USER_NOTICE ) ; $ this -> currentWhere = & $ this -> where ; } else { $ key = key ( end ( $ this -> whereStack ) ) ; $ this -> currentWhere = & $ this -> whereStack [ $ key ] ; unset ( $ this -> whereStack [ $ key ] ) ; } return $ this ; }
End a bracket group .
18,407
public function addLike ( $ column , $ value ) { $ r = $ this -> addWhere ( $ column , [ Db :: OP_LIKE => $ value ] ) ; return $ r ; }
Add a like statement to the current where clause .
18,408
public function addIn ( $ column , array $ values ) { $ r = $ this -> addWhere ( $ column , [ Db :: OP_IN , $ values ] ) ; return $ r ; }
Add an in statement to the current where clause .
18,409
public function addWheres ( array $ where ) { foreach ( $ where as $ column => $ value ) { $ this -> addWhere ( $ column , $ value ) ; } return $ this ; }
Add an array of where statements .
18,410
public function toArray ( ) { $ r = [ 'from' => $ this -> from , 'where' => $ this -> where , 'order' => $ this -> order , 'limit' => $ this -> limit , 'offset' => $ this -> offset ] ; return $ r ; }
Return an array representation of this query .
18,411
public function exec ( Db $ db ) { $ options = [ 'limit' => $ this -> limit , 'offset' => $ this -> offset ] ; $ r = $ db -> get ( $ this -> from , $ this -> where , $ options ) ; return $ r ; }
Execute this query against a database .
18,412
public function isOwnedBy ( $ recordId , $ userId = null ) { return ( bool ) $ this -> find ( ) -> where ( [ 'id' => $ recordId , 'user_id' => $ userId ] ) -> first ( ) ; }
Checks if a record is owned by an user .
18,413
public function posts ( ) { $ links [ ] = [ __d ( 'me_cms' , 'List posts' ) , [ 'controller' => 'Posts' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add post' ) , [ 'controller' => 'Posts' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; if ( $ this -> Auth -> isGroup ( [ 'admin' , 'manager' ] ) ) { $ links [ ] = [ __d ( 'me_cms' , 'List categories' ) , [ 'controller' => 'PostsCategories' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add category' ) , [ 'controller' => 'PostsCategories' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; } $ links [ ] = [ __d ( 'me_cms' , 'List tags' ) , [ 'controller' => 'PostsTags' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; return [ $ links , I18N_POSTS , [ 'icon' => 'far file-alt' ] ] ; }
Internal function to generate the menu for posts actions
18,414
public function pages ( ) { $ links [ ] = [ __d ( 'me_cms' , 'List pages' ) , [ 'controller' => 'Pages' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; if ( $ this -> Auth -> isGroup ( [ 'admin' , 'manager' ] ) ) { $ links [ ] = [ __d ( 'me_cms' , 'Add page' ) , [ 'controller' => 'Pages' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'List categories' ) , [ 'controller' => 'PagesCategories' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add category' ) , [ 'controller' => 'PagesCategories' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; } $ links [ ] = [ __d ( 'me_cms' , 'List static pages' ) , [ 'controller' => 'Pages' , 'action' => 'indexStatics' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; return [ $ links , I18N_PAGES , [ 'icon' => 'far copy' ] ] ; }
Internal function to generate the menu for pages actions
18,415
public function photos ( ) { $ links [ ] = [ __d ( 'me_cms' , 'List photos' ) , [ 'controller' => 'Photos' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Upload photos' ) , [ 'controller' => 'Photos' , 'action' => 'upload' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'List albums' ) , [ 'controller' => 'PhotosAlbums' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add album' ) , [ 'controller' => 'PhotosAlbums' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; return [ $ links , I18N_PHOTOS , [ 'icon' => 'camera-retro' ] ] ; }
Internal function to generate the menu for photos actions
18,416
public function banners ( ) { if ( ! $ this -> Auth -> isGroup ( [ 'admin' , 'manager' ] ) ) { return ; } $ links [ ] = [ __d ( 'me_cms' , 'List banners' ) , [ 'controller' => 'Banners' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Upload banners' ) , [ 'controller' => 'Banners' , 'action' => 'upload' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; if ( $ this -> Auth -> isGroup ( 'admin' ) ) { $ links [ ] = [ __d ( 'me_cms' , 'List positions' ) , [ 'controller' => 'BannersPositions' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add position' ) , [ 'controller' => 'BannersPositions' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; } return [ $ links , __d ( 'me_cms' , 'Banners' ) , [ 'icon' => 'shopping-cart' ] ] ; }
Internal function to generate the menu for banners actions
18,417
public function users ( ) { if ( ! $ this -> Auth -> isGroup ( [ 'admin' , 'manager' ] ) ) { return ; } $ links [ ] = [ __d ( 'me_cms' , 'List users' ) , [ 'controller' => 'Users' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add user' ) , [ 'controller' => 'Users' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; if ( $ this -> Auth -> isGroup ( 'admin' ) ) { $ links [ ] = [ __d ( 'me_cms' , 'List groups' ) , [ 'controller' => 'UsersGroups' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add group' ) , [ 'controller' => 'UsersGroups' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; } return [ $ links , I18N_USERS , [ 'icon' => 'users' ] ] ; }
Internal function to generate the menu for users actions
18,418
public function backups ( ) { if ( ! $ this -> Auth -> isGroup ( 'admin' ) ) { return ; } $ links [ ] = [ __d ( 'me_cms' , 'List backups' ) , [ 'controller' => 'Backups' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Add backup' ) , [ 'controller' => 'Backups' , 'action' => 'add' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; return [ $ links , __d ( 'me_cms' , 'Backups' ) , [ 'icon' => 'database' ] ] ; }
Internal function to generate the menu for backups actions
18,419
public function systems ( ) { if ( ! $ this -> Auth -> isGroup ( [ 'admin' , 'manager' ] ) ) { return ; } $ links [ ] = [ __d ( 'me_cms' , 'Temporary files' ) , [ 'controller' => 'Systems' , 'action' => 'tmpViewer' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; if ( $ this -> Auth -> isGroup ( 'admin' ) ) { $ links [ ] = [ __d ( 'me_cms' , 'Log management' ) , [ 'controller' => 'Logs' , 'action' => 'index' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; } $ links [ ] = [ __d ( 'me_cms' , 'System checkup' ) , [ 'controller' => 'Systems' , 'action' => 'checkup' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Media browser' ) , [ 'controller' => 'Systems' , 'action' => 'browser' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; $ links [ ] = [ __d ( 'me_cms' , 'Changelogs' ) , [ 'controller' => 'Systems' , 'action' => 'changelogs' , 'plugin' => 'MeCms' , 'prefix' => ADMIN_PREFIX , ] ] ; return [ $ links , __d ( 'me_cms' , 'System' ) , [ 'icon' => 'wrench' ] ] ; }
Internal function to generate the menu for systems actions
18,420
protected function dispatch ( $ request , $ response ) { $ this -> setRequest ( $ request ) ; $ this -> setResponse ( $ response ) ; if ( ! $ this -> responder ) { $ this -> responder = Respond :: getResponder ( ) ; } return $ this -> _execInternalMethods ( ) ; }
call this dispatch method to respond .
18,421
protected function sendEmails ( Swift_Transport $ transport , & $ failedRecipients , array $ emails ) { $ count = 0 ; $ time = time ( ) ; $ emails = $ this -> prepareEmails ( $ emails ) ; $ skip = false ; foreach ( $ emails as $ email ) { if ( $ skip ) { $ email -> setStatus ( SpoolEmailStatus :: STATUS_FAILED ) ; $ email -> setStatusMessage ( 'The time limit of execution is exceeded' ) ; continue ; } $ count += $ this -> sendEmail ( $ transport , $ email , $ failedRecipients ) ; $ this -> flushEmail ( $ email ) ; if ( $ this -> getTimeLimit ( ) && ( time ( ) - $ time ) >= $ this -> getTimeLimit ( ) ) { $ skip = true ; } } return $ count ; }
Send the emails message .
18,422
protected function prepareEmails ( array $ emails ) { foreach ( $ emails as $ email ) { $ email -> setStatus ( SpoolEmailStatus :: STATUS_SENDING ) ; $ email -> setSentAt ( null ) ; $ this -> om -> persist ( $ email ) ; } $ this -> om -> flush ( ) ; reset ( $ emails ) ; return $ emails ; }
Prepare the spool emails .
18,423
protected function sendEmail ( Swift_Transport $ transport , SpoolEmailInterface $ email , & $ failedRecipients ) { $ count = 0 ; try { if ( $ transport -> send ( $ email -> getMessage ( ) , $ failedRecipients ) ) { $ email -> setStatus ( SpoolEmailStatus :: STATUS_SUCCESS ) ; ++ $ count ; } else { $ email -> setStatus ( SpoolEmailStatus :: STATUS_FAILED ) ; } } catch ( \ Swift_TransportException $ e ) { $ email -> setStatus ( SpoolEmailStatus :: STATUS_FAILED ) ; $ email -> setStatusMessage ( $ e -> getMessage ( ) ) ; } return $ count ; }
Send the spool email .
18,424
protected function flushEmail ( SpoolEmailInterface $ email ) : void { $ email -> setSentAt ( new \ DateTime ( ) ) ; $ this -> om -> persist ( $ email ) ; $ this -> om -> flush ( ) ; if ( SpoolEmailStatus :: STATUS_SUCCESS === $ email -> getStatus ( ) ) { $ this -> om -> remove ( $ email ) ; $ this -> om -> flush ( ) ; } $ this -> om -> detach ( $ email ) ; }
Update and flush the spool email .
18,425
public function beforeSave ( Event $ event , EntityInterface $ entity , ArrayObject $ options ) { if ( empty ( $ entity -> created ) ) { $ entity -> created = new Time ; } elseif ( ! empty ( $ entity -> created ) && ! $ entity -> created instanceof Time ) { $ entity -> created = new Time ( $ entity -> created ) ; } }
Called before each entity is saved . Stopping this event will abort the save operation . When the event is stopped the result of the event will be returned
18,426
public function findRandom ( Query $ query , array $ options ) { $ query -> order ( 'rand()' ) ; if ( ! $ query -> clause ( 'limit' ) ) { $ query -> limit ( 1 ) ; } return $ query ; }
random find method
18,427
public function getCacheName ( $ associations = false ) { $ values = $ this -> cache ? : null ; if ( $ associations ) { $ values = [ $ values ] ; foreach ( $ this -> associations ( ) -> getIterator ( ) as $ association ) { if ( method_exists ( $ association -> getTarget ( ) , 'getCacheName' ) && $ association -> getTarget ( ) -> getCacheName ( ) ) { $ values [ ] = $ association -> getTarget ( ) -> getCacheName ( ) ; } } $ values = array_values ( array_unique ( array_filter ( $ values ) ) ) ; } return $ values ; }
Gets the cache configuration name used by this table
18,428
public function getList ( ) { return $ this -> find ( 'list' ) -> order ( [ $ this -> getDisplayField ( ) => 'ASC' ] ) -> cache ( sprintf ( '%s_list' , $ this -> getTable ( ) ) , $ this -> getCacheName ( ) ) ; }
Gets records as list
18,429
public function setPage ( int $ page ) { if ( $ page < 0 ) { throw new \ InvalidArgumentException ( "Invalid page '$page.'" , 500 ) ; } $ this -> setOffset ( ( $ page - 1 ) * $ this -> getLimit ( ) ) ; return $ this ; }
Set the current page .
18,430
public function setOffset ( $ offset ) { if ( ! is_numeric ( $ offset ) || $ offset < 0 ) { throw new \ InvalidArgumentException ( "Invalid offset '$offset.'" , 500 ) ; } $ this -> offset = ( int ) $ offset ; return $ this ; }
Set the offset .
18,431
protected function getResource ( string $ sFile , array $ aFields ) : string { if ( empty ( static :: RESOURCE_PATH ) ) { throw new NailsException ( 'RESOURCE_PATH is not defined' ) ; } $ sResource = require static :: RESOURCE_PATH . $ sFile ; foreach ( $ aFields as $ sField => $ sValue ) { $ sKey = '{{' . strtoupper ( $ sField ) . '}}' ; $ sResource = str_replace ( $ sKey , $ sValue , $ sResource ) ; } return $ sResource ; }
Get a resource and substitute fields into it
18,432
protected function createPath ( string $ sPath ) : BaseMaker { if ( ! is_dir ( $ sPath ) ) { if ( ! @ mkdir ( $ sPath , self :: FILE_PERMISSION , true ) ) { throw new DoesNotExistException ( 'Path "' . $ sPath . '" does not exist and could not be created' ) ; } } if ( ! is_writable ( $ sPath ) ) { throw new IsNotWritableException ( 'Path "' . $ sPath . '" exists, but is not writable' ) ; } return $ this ; }
Creates a new path
18,433
protected function getArguments ( ) : array { Factory :: helper ( 'string' ) ; $ aArguments = [ ] ; if ( ! empty ( $ this -> aArguments ) ) { foreach ( $ this -> aArguments as $ aArgument ) { $ aArguments [ ] = ( object ) [ 'name' => getFromArray ( 'name' , $ aArgument ) , 'value' => $ this -> oInput -> getArgument ( getFromArray ( 'name' , $ aArgument ) ) , 'required' => getFromArray ( 'required' , $ aArgument ) , ] ; } } else { $ aArgumentsRaw = array_slice ( $ this -> oInput -> getArguments ( ) , 1 ) ; foreach ( $ aArgumentsRaw as $ sField => $ sValue ) { $ sField = strtoupper ( camelcase_to_underscore ( $ sField ) ) ; $ aArguments [ ] = ( object ) [ 'name' => $ sField , 'value' => $ sValue , 'required' => true , ] ; } } unset ( $ sField ) ; unset ( $ sValue ) ; foreach ( $ aArguments as & $ oArgument ) { if ( empty ( $ oArgument -> value ) ) { $ sLabel = str_replace ( '_' , ' ' , $ oArgument -> name ) ; $ sLabel = ucwords ( strtolower ( $ sLabel ) ) ; $ sError = '' ; do { $ oArgument -> value = $ this -> ask ( $ sError . $ sLabel . ':' , '' ) ; $ sError = '<error>Please specify</error> ' ; if ( $ oArgument -> required && empty ( $ oArgument -> value ) ) { $ bAskAgain = true ; } else { $ bAskAgain = false ; } } while ( $ bAskAgain ) ; } } unset ( $ oArgument ) ; $ aOut = [ ] ; foreach ( $ aArguments as $ oArgument ) { $ aOut [ strtoupper ( $ oArgument -> name ) ] = $ oArgument -> value ; } return $ aOut ; }
Parses the arguments into an array ready for templates
18,434
protected function validateServiceFile ( string $ sToken = null ) : BaseMaker { if ( empty ( $ sToken ) && empty ( static :: SERVICE_TOKEN ) ) { throw new ConsoleException ( 'SERVICE_TOKEN is not set' ) ; } elseif ( empty ( $ sToken ) ) { $ sToken = static :: SERVICE_TOKEN ; } if ( ! file_exists ( static :: SERVICE_PATH ) ) { throw new ConsoleException ( 'Could not detect the app\'s services.php file: ' . static :: SERVICE_PATH ) ; } $ this -> fServicesHandle = fopen ( static :: SERVICE_PATH , 'r+' ) ; ; $ bFound = false ; if ( $ this -> fServicesHandle ) { $ iLocation = 0 ; while ( ( $ sLine = fgets ( $ this -> fServicesHandle ) ) !== false ) { if ( preg_match ( '#^(\s*)// GENERATOR\[' . $ sToken . '\]#' , $ sLine , $ aMatches ) ) { $ bFound = true ; $ this -> iServicesIndent = strlen ( $ aMatches [ 1 ] ) ; $ this -> iServicesTokenLocation = $ iLocation ; break ; } $ iLocation = ftell ( $ this -> fServicesHandle ) ; } if ( ! $ bFound ) { fclose ( $ this -> fServicesHandle ) ; throw new ConsoleException ( 'Services file does not contain the generator token (i.e // GENERATOR[' . $ sToken . ']) ' . 'This token is required so that the tool can safely insert new definitions' ) ; } } else { throw new ConsoleException ( 'Failed to open the services file for reading and writing: ' . static :: SERVICE_PATH ) ; } return $ this ; }
Validate the service file is valid
18,435
protected function writeServiceFile ( array $ aServiceDefinitions = [ ] ) : BaseMaker { $ fTempHandle = fopen ( static :: SERVICE_TEMP_PATH , 'w+' ) ; rewind ( $ this -> fServicesHandle ) ; $ iLocation = 0 ; while ( ( $ sLine = fgets ( $ this -> fServicesHandle ) ) !== false ) { if ( $ iLocation === $ this -> iServicesTokenLocation ) { fwrite ( $ fTempHandle , implode ( "\n" , $ aServiceDefinitions ) . "\n" ) ; } fwrite ( $ fTempHandle , $ sLine ) ; $ iLocation = ftell ( $ this -> fServicesHandle ) ; } unlink ( static :: SERVICE_PATH ) ; rename ( static :: SERVICE_TEMP_PATH , static :: SERVICE_PATH ) ; fclose ( $ fTempHandle ) ; fclose ( $ this -> fServicesHandle ) ; return $ this ; }
Write the definitions to the services file
18,436
protected function buildCoalescedStrings ( array $ prefixStrings , array $ suffix ) { $ strings = $ this -> runPass ( $ this -> buildPrefix ( $ prefixStrings ) ) ; if ( count ( $ strings ) === 1 && $ strings [ 0 ] [ 0 ] [ 0 ] === [ ] ) { $ strings [ 0 ] [ ] = $ suffix ; } else { array_unshift ( $ strings , [ ] ) ; $ strings = [ [ $ strings , $ suffix ] ] ; } return $ strings ; }
Build the final list of coalesced strings
18,437
protected function buildPrefix ( array $ strings ) { $ prefix = [ ] ; foreach ( $ strings as $ string ) { array_pop ( $ string ) ; $ prefix [ ] = $ string ; } return $ prefix ; }
Build the list of strings used as prefix
18,438
protected function buildSuffix ( array $ strings ) { $ suffix = [ [ ] ] ; foreach ( $ strings as $ string ) { if ( $ this -> isCharacterClassString ( $ string ) ) { foreach ( $ string [ 0 ] as $ element ) { $ suffix [ ] = $ element ; } } else { $ suffix [ ] = $ string ; } } return $ suffix ; }
Build a list of strings that matches any given strings or nothing
18,439
protected function getPrefixGroups ( array $ strings ) { $ groups = [ ] ; foreach ( $ strings as $ k => $ string ) { if ( $ this -> hasOptionalSuffix ( $ string ) ) { $ groups [ serialize ( end ( $ string ) ) ] [ $ k ] = $ string ; } } return $ groups ; }
Get the list of potential prefix strings grouped by identical suffix
18,440
public function match ( $ url ) { if ( ! $ this -> pattern ) { $ this -> pattern = self :: buildPatternFromScheme ( $ this ) ; } return ( bool ) preg_match ( $ this -> pattern , $ url ) ; }
Check whether the given URL match the scheme
18,441
static protected function buildPatternFromScheme ( URLScheme $ scheme ) { $ uniq = md5 ( mt_rand ( ) ) ; $ scheme = str_replace ( '://' . self :: WILDCARD_CHARACTER . '.' , '://' . $ uniq , $ scheme -> __tostring ( ) ) ; $ scheme = str_replace ( self :: WILDCARD_CHARACTER , $ uniq , $ scheme ) ; $ wrap = '|' ; $ pattern = preg_quote ( $ scheme , $ wrap ) ; $ pattern = str_replace ( $ uniq , '.*' , $ pattern ) ; return $ wrap . $ pattern . $ wrap . 'iu' ; }
Builds pattern from scheme
18,442
public function toLevel ( Experiences $ experiences ) : Level { $ woundsBonus = $ this -> toWoundsBonus ( $ experiences ) ; return new Level ( $ this -> bonusToLevelValue ( $ woundsBonus ) , $ this ) ; }
Gives highest level possible independently on any previous level .
18,443
public function toTotalLevel ( Experiences $ experiences ) : Level { $ currentExperiences = 0 ; $ usedExperiences = 0 ; $ maxLevelValue = 0 ; while ( $ usedExperiences + $ currentExperiences <= $ experiences -> getValue ( ) ) { $ level = $ this -> toLevel ( new Experiences ( $ currentExperiences , $ this ) ) ; if ( $ maxLevelValue < $ level -> getValue ( ) ) { $ usedExperiences += $ currentExperiences ; $ maxLevelValue = $ level -> getValue ( ) ; } $ currentExperiences ++ ; } return new Level ( $ maxLevelValue , $ this ) ; }
Leveling sequentially from very first level up to highest possible until all experiences are spent .
18,444
public function toTotalExperiences ( Level $ level ) : Experiences { $ experiencesSum = 0 ; for ( $ levelValueToCast = $ level -> getValue ( ) ; $ levelValueToCast > 0 ; $ levelValueToCast -- ) { if ( $ levelValueToCast > 1 ) { $ currentLevel = new Level ( $ levelValueToCast , $ this ) ; $ experiencesSum += $ currentLevel -> getExperiences ( ) -> getValue ( ) ; } } return new Experiences ( $ experiencesSum , $ this ) ; }
Casting level to experiences is mostly lossy conversion! Gives all experiences needed to achieve all levels sequentially up to given .
18,445
public static function driverClass ( $ driver ) { if ( $ driver instanceof PDO ) { $ name = $ driver -> getAttribute ( PDO :: ATTR_DRIVER_NAME ) ; } else { $ name = ( string ) $ driver ; } $ name = strtolower ( $ name ) ; return isset ( self :: $ drivers [ $ name ] ) ? self :: $ drivers [ $ name ] : null ; }
Get the name of the class that handles a database driver .
18,446
final public function dropTable ( string $ table , array $ options = [ ] ) { $ options += [ Db :: OPTION_IGNORE => false ] ; $ this -> dropTableDb ( $ table , $ options ) ; $ tableKey = strtolower ( $ table ) ; unset ( $ this -> tables [ $ tableKey ] , $ this -> tableNames [ $ tableKey ] ) ; }
Drop a table .
18,447
final public function fetchTableNames ( ) { if ( $ this -> tableNames !== null ) { return array_values ( $ this -> tableNames ) ; } $ names = $ this -> fetchTableNamesDb ( ) ; $ this -> tableNames = [ ] ; foreach ( $ names as $ name ) { $ name = $ this -> stripPrefix ( $ name ) ; $ this -> tableNames [ strtolower ( $ name ) ] = $ name ; } return array_values ( $ this -> tableNames ) ; }
Get the names of all the tables in the database .
18,448
final public function fetchTableDef ( string $ table ) { $ tableKey = strtolower ( $ table ) ; if ( isset ( $ this -> tables [ $ tableKey ] ) ) { $ tableDef = $ this -> tables [ $ tableKey ] ; if ( isset ( $ tableDef [ 'columns' ] , $ tableDef [ 'indexes' ] ) ) { return $ tableDef ; } } elseif ( $ this -> tableNames !== null && ! isset ( $ this -> tableNames [ $ tableKey ] ) ) { return null ; } $ tableDef = $ this -> fetchTableDefDb ( $ table ) ; if ( $ tableDef !== null ) { $ this -> fixIndexes ( $ tableDef [ 'name' ] , $ tableDef ) ; $ this -> tables [ $ tableKey ] = $ tableDef ; } return $ tableDef ; }
Get a table definition .
18,449
final public function fetchColumnDefs ( string $ table ) { $ tableKey = strtolower ( $ table ) ; if ( ! empty ( $ this -> tables [ $ tableKey ] [ 'columns' ] ) ) { $ this -> tables [ $ tableKey ] [ 'columns' ] ; } elseif ( $ this -> tableNames !== null && ! isset ( $ this -> tableNames [ $ tableKey ] ) ) { return null ; } $ columnDefs = $ this -> fetchColumnDefsDb ( $ table ) ; if ( $ columnDefs !== null ) { $ this -> tables [ $ tableKey ] [ 'columns' ] = $ columnDefs ; } return $ columnDefs ; }
Get the column definitions for a table .
18,450
public static function typeDef ( string $ type ) { $ unsigned = null ; if ( $ type [ 0 ] === 'u' ) { $ unsigned = true ; $ type = substr ( $ type , 1 ) ; } elseif ( preg_match ( '`(.+)\s+unsigned`i' , $ type , $ m ) ) { $ unsigned = true ; $ type = $ m [ 1 ] ; } $ brackets = null ; if ( preg_match ( '`^(.*)\((.*)\)$`' , $ type , $ m ) ) { $ brackets = $ m [ 2 ] ; $ type = $ m [ 1 ] ; } $ type = strtolower ( $ type ) ; if ( isset ( self :: $ types [ $ type ] ) ) { $ row = self :: $ types [ $ type ] ; $ dbtype = $ type ; if ( is_string ( $ row ) ) { $ dbtype = $ row ; $ row = self :: $ types [ $ row ] ; } } else { return null ; } $ schema = [ 'type' => $ row [ 'type' ] , 'dbtype' => $ dbtype ] ; if ( ! empty ( $ row [ 'schema' ] ) ) { $ schema += $ row [ 'schema' ] ; } if ( $ row [ 'type' ] === 'integer' && $ unsigned ) { $ schema [ 'unsigned' ] = true ; if ( ! empty ( $ schema [ 'maximum' ] ) ) { $ schema [ 'maximum' ] = $ schema [ 'maximum' ] * 2 + 1 ; $ schema [ 'minimum' ] = 0 ; } } if ( ! empty ( $ row [ 'length' ] ) ) { $ schema [ 'maxLength' ] = ( int ) $ brackets ? : 255 ; } if ( ! empty ( $ row [ 'precision' ] ) ) { $ parts = array_map ( 'trim' , explode ( ',' , $ brackets ) ) ; $ schema [ 'precision' ] = ( int ) $ parts [ 0 ] ; if ( isset ( $ parts [ 1 ] ) ) { $ schema [ 'scale' ] = ( int ) $ parts [ 1 ] ; } } if ( ! empty ( $ row [ 'enum' ] ) ) { $ enum = explode ( ',' , $ brackets ) ; $ schema [ 'enum' ] = array_map ( function ( $ str ) { return trim ( $ str , "'\" \t\n\r\0\x0B" ) ; } , $ enum ) ; } return $ schema ; }
Get the canonical type based on a type string .
18,451
protected static function dbType ( array $ typeDef ) { $ dbtype = $ typeDef [ 'dbtype' ] ; if ( ! empty ( $ typeDef [ 'maxLength' ] ) ) { $ dbtype .= "({$typeDef['maxLength']})" ; } elseif ( ! empty ( $ typeDef [ 'unsigned' ] ) ) { $ dbtype = 'u' . $ dbtype ; } elseif ( ! empty ( $ typeDef [ 'precision' ] ) ) { $ dbtype .= "({$typeDef['precision']}" ; if ( ! empty ( $ typeDef [ 'scale' ] ) ) { $ dbtype .= ",{$typeDef['scale']}" ; } $ dbtype .= ')' ; } elseif ( ! empty ( $ typeDef [ 'enum' ] ) ) { $ parts = array_map ( function ( $ str ) { return "'{$str}'" ; } , $ typeDef [ 'enum' ] ) ; $ dbtype .= '(' . implode ( ',' , $ parts ) . ')' ; } return $ dbtype ; }
Get the database type string from a type definition .
18,452
protected function findPrimaryKeyIndex ( array $ indexes ) { foreach ( $ indexes as $ index ) { if ( $ index [ 'type' ] === Db :: INDEX_PK ) { return $ index ; } } return null ; }
Find the primary key in an array of indexes .
18,453
private function fixIndexes ( string $ tableName , array & $ tableDef , $ curTableDef = null ) { $ tableDef += [ 'indexes' => [ ] ] ; $ primaryColumns = [ ] ; foreach ( $ tableDef [ 'columns' ] as $ cname => $ cdef ) { if ( ! empty ( $ cdef [ 'primary' ] ) ) { $ primaryColumns [ ] = $ cname ; } } $ primaryFound = false ; foreach ( $ tableDef [ 'indexes' ] as & $ indexDef ) { $ indexDef += [ 'name' => $ this -> buildIndexName ( $ tableName , $ indexDef ) , 'type' => null ] ; if ( $ indexDef [ 'type' ] === Db :: INDEX_PK ) { $ primaryFound = true ; if ( empty ( $ primaryColumns ) ) { foreach ( $ indexDef [ 'columns' ] as $ cname ) { $ tableDef [ 'columns' ] [ $ cname ] [ 'primary' ] = true ; } } elseif ( array_diff ( $ primaryColumns , $ indexDef [ 'columns' ] ) ) { throw new \ Exception ( "There is a mismatch in the primary key index and primary key columns." , 500 ) ; } } elseif ( isset ( $ curTableDef [ 'indexes' ] ) ) { foreach ( $ curTableDef [ 'indexes' ] as $ curIndexDef ) { if ( $ this -> indexCompare ( $ indexDef , $ curIndexDef ) === 0 ) { if ( ! empty ( $ curIndexDef [ 'name' ] ) ) { $ indexDef [ 'name' ] = $ curIndexDef [ 'name' ] ; } break ; } } } } if ( ! $ primaryFound && ! empty ( $ primaryColumns ) ) { $ tableDef [ 'indexes' ] [ ] = [ 'columns' => $ primaryColumns , 'type' => Db :: INDEX_PK ] ; } }
Move the primary key index into the correct place for database drivers .
18,454
private function indexCompare ( array $ a , array $ b ) : int { if ( $ a [ 'columns' ] > $ b [ 'columns' ] ) { return 1 ; } elseif ( $ a [ 'columns' ] < $ b [ 'columns' ] ) { return - 1 ; } return strcmp ( isset ( $ a [ 'type' ] ) ? $ a [ 'type' ] : '' , isset ( $ b [ 'type' ] ) ? $ b [ 'type' ] : '' ) ; }
Compare two index definitions to see if they have the same columns and same type .
18,455
final public function getOne ( $ table , array $ where , array $ options = [ ] ) { $ rows = $ this -> get ( $ table , $ where , $ options ) ; $ row = $ rows -> fetch ( ) ; return $ row === false ? null : $ row ; }
Get a single row from the database .
18,456
public function load ( string $ table , $ rows , array $ options = [ ] ) { foreach ( $ rows as $ row ) { $ this -> insert ( $ table , $ row , $ options ) ; } }
Load many rows into a table .
18,457
protected function buildIndexName ( string $ tableName , array $ indexDef ) : string { $ indexDef += [ 'type' => Db :: INDEX_IX , 'suffix' => '' ] ; $ type = $ indexDef [ 'type' ] ; if ( $ type === Db :: INDEX_PK ) { return 'primary' ; } $ px = self :: val ( $ type , [ Db :: INDEX_IX => 'ix_' , Db :: INDEX_UNIQUE => 'ux_' ] , 'ix_' ) ; $ sx = $ indexDef [ 'suffix' ] ; $ result = $ px . $ tableName . '_' . ( $ sx ? : implode ( '' , $ indexDef [ 'columns' ] ) ) ; return $ result ; }
Build a standardized index name from an index definition .
18,458
protected function query ( string $ sql , array $ params = [ ] , array $ options = [ ] ) : \ PDOStatement { $ options += [ Db :: OPTION_FETCH_MODE => $ this -> getFetchArgs ( ) ] ; $ stm = $ this -> getPDO ( ) -> prepare ( $ sql ) ; if ( $ options [ Db :: OPTION_FETCH_MODE ] ) { $ stm -> setFetchMode ( ... ( array ) $ options [ Db :: OPTION_FETCH_MODE ] ) ; } $ r = $ stm -> execute ( $ params ) ; if ( $ r === false ) { list ( $ state , $ code , $ msg ) = $ stm -> errorInfo ( ) ; throw new \ PDOException ( $ msg , $ code ) ; } return $ stm ; }
Execute a query that fetches data .
18,459
protected function queryModify ( string $ sql , array $ params = [ ] , array $ options = [ ] ) : int { $ options += [ Db :: OPTION_FETCH_MODE => 0 ] ; $ stm = $ this -> query ( $ sql , $ params , $ options ) ; return $ stm -> rowCount ( ) ; }
Query the database and return a row count .
18,460
protected function queryID ( string $ sql , array $ params = [ ] , array $ options = [ ] ) { $ options += [ Db :: OPTION_FETCH_MODE => 0 ] ; $ this -> query ( $ sql , $ params , $ options ) ; $ r = $ this -> getPDO ( ) -> lastInsertId ( ) ; return is_numeric ( $ r ) ? ( int ) $ r : $ r ; }
Query the database and return the ID of the record that was inserted .
18,461
protected function queryDefine ( string $ sql , array $ options = [ ] ) { $ options += [ Db :: OPTION_FETCH_MODE => 0 ] ; $ this -> query ( $ sql , [ ] , $ options ) ; }
Query the database for a database define .
18,462
public function escape ( $ identifier ) : string { if ( $ identifier instanceof Literal ) { return $ identifier -> getValue ( $ this ) ; } return '`' . str_replace ( '`' , '``' , $ identifier ) . '`' ; }
Escape an identifier .
18,463
protected function prefixTable ( $ table , bool $ escape = true ) : string { if ( $ table instanceof Identifier ) { return $ escape ? $ table -> escape ( $ this ) : ( string ) $ table ; } else { $ table = $ this -> px . $ table ; return $ escape ? $ this -> escape ( $ table ) : $ table ; } }
Prefix a table name .
18,464
protected function stripPrefix ( string $ table ) : string { $ len = strlen ( $ this -> px ) ; if ( strcasecmp ( substr ( $ table , 0 , $ len ) , $ this -> px ) === 0 ) { $ table = substr ( $ table , $ len ) ; } return $ table ; }
Strip the database prefix off a table name .
18,465
public function getThemesFromDir ( ) { $ themeList = array ( ) ; $ themePath = Yii :: getPathOfAlias ( 'webroot.themes' ) ; $ themes = scandir ( $ themePath ) ; foreach ( $ themes as $ theme ) { $ themeName = $ this -> urlTitle ( $ theme ) ; $ themeFile = $ themePath . '/' . $ theme . '/' . $ themeName . '.yaml' ; if ( file_exists ( $ themeFile ) ) { if ( ! in_array ( $ themeName , $ this -> getIgnoreTheme ( ) ) ) { $ themeList [ ] = $ theme ; } } } if ( count ( $ themeList ) > 0 ) return $ themeList ; else return false ; }
Mendapatkan daftar theme dari folder themes .
18,466
public function cacheThemeConfig ( $ return = false ) { $ themes = $ this -> getThemesFromDb ( ) ; $ arrayTheme = array ( ) ; foreach ( $ themes as $ theme ) { if ( ! in_array ( $ theme -> folder , $ arrayTheme ) ) $ arrayTheme [ ] = $ theme -> folder ; } if ( $ return == false ) { $ filePath = Yii :: getPathOfAlias ( 'application.config' ) ; $ fileHandle = fopen ( $ filePath . '/cache_theme.php' , 'w' ) ; fwrite ( $ fileHandle , implode ( "\n" , $ arrayTheme ) ) ; fclose ( $ fileHandle ) ; } else return $ arrayTheme ; }
Cache theme dari database ke bentuk file . Untuk mengurangi query pada saat install ke database .
18,467
public function getThemeConfig ( $ theme ) { Yii :: import ( 'mustangostang.spyc.Spyc' ) ; define ( 'DS' , DIRECTORY_SEPARATOR ) ; $ themeName = $ this -> urlTitle ( $ theme ) ; $ configPath = Yii :: getPathOfAlias ( 'webroot.themes.' . $ theme ) . DS . $ themeName . '.yaml' ; if ( file_exists ( $ configPath ) ) return Spyc :: YAMLLoad ( $ configPath ) ; else return null ; }
Get theme config from yaml file
18,468
public function deleteThemeDb ( $ theme ) { if ( $ theme != null ) { $ model = OmmuThemes :: model ( ) -> findByAttributes ( array ( 'folder' => $ theme ) ) ; if ( $ model != null ) $ model -> delete ( ) ; else return false ; } else return false ; }
Delete DB folder
18,469
public function setThemes ( ) { $ installedTheme = $ this -> getThemesFromDir ( ) ; $ cacheTheme = file ( Yii :: getPathOfAlias ( 'application.config' ) . '/cache_theme.php' ) ; $ toBeInstalled = array ( ) ; $ caches = array ( ) ; foreach ( $ cacheTheme as $ val ) { $ caches [ ] = $ val ; } if ( ! $ installedTheme ) $ installedTheme = array ( ) ; foreach ( $ caches as $ cache ) { $ cache = trim ( $ cache ) ; if ( ! in_array ( $ cache , array_map ( "trim" , $ installedTheme ) ) ) { $ this -> deleteTheme ( $ cache , true ) ; } } $ themeDb = $ this -> cacheThemeConfig ( true ) ; foreach ( $ installedTheme as $ theme ) { if ( ! in_array ( trim ( $ theme ) , array_map ( "trim" , $ themeDb ) ) ) { $ config = $ this -> getThemeConfig ( $ theme ) ; $ themeName = $ this -> urlTitle ( $ theme ) ; if ( $ config && $ themeName == $ config [ 'folder' ] ) { $ model = new OmmuThemes ; $ model -> group_page = $ config [ 'group_page' ] ; $ model -> folder = $ theme ; $ model -> layout = $ config [ 'layout' ] ; $ model -> name = $ config [ 'name' ] ; $ model -> thumbnail = $ config [ 'thumbnail' ] ; $ model -> save ( ) ; } } } }
Install theme ke database
18,470
public function afterSave ( Event $ event , Entity $ entity , ArrayObject $ options ) { ( new Folder ( $ entity -> path , true , 0777 ) ) ; parent :: afterSave ( $ event , $ entity , $ options ) ; }
Called after an entity is saved
18,471
public function execute ( Arguments $ args , ConsoleIo $ io ) { $ command = new AddUserCommand ; return $ command -> run ( [ '--group' , 1 ] + $ args -> getOptions ( ) , $ io ) ; }
Creates an admin user
18,472
public static function getReferrer ( ServerRequestInterface $ request ) { if ( $ referrer = $ request -> getAttribute ( self :: REFERRER ) ) { return $ referrer ; } if ( $ referrer = Respond :: session ( ) -> get ( self :: REFERRER ) ) { return $ referrer ; } $ info = $ request -> getServerParams ( ) ; return array_key_exists ( 'HTTP_REFERER' , $ info ) ? $ info [ 'HTTP_REFERER' ] : '' ; }
get the referrer uri set by withReferrer or the HTTP_REFERER if not set .
18,473
public static function withBasePath ( ServerRequestInterface $ request , $ basePath , $ pathInfo = null ) { $ path = $ request -> getUri ( ) -> getPath ( ) ; if ( strpos ( $ path , $ basePath ) !== 0 ) { throw new \ InvalidArgumentException ; } $ pathInfo = is_null ( $ pathInfo ) ? substr ( $ path , strlen ( $ basePath ) ) : $ pathInfo ; return $ request -> withAttribute ( self :: BASE_PATH , $ basePath ) -> withAttribute ( self :: PATH_INFO , $ pathInfo ) ; }
set a base - path and path - info for matching .
18,474
public static function getPathInfo ( ServerRequestInterface $ request ) { return $ request -> getAttribute ( self :: PATH_INFO , null ) ? : $ request -> getUri ( ) -> getPath ( ) ; }
get a path - info or uri s path if not set .
18,475
public function run ( $ eventname , $ count ) { $ queueEvents = $ this -> loadQueue ( $ eventname , $ count ) ; if ( $ queueEvents -> numRows ) { while ( $ queueEvents -> next ( ) ) { if ( $ this -> checkInterval ( $ queueEvents ) ) { $ this -> setStartTime ( $ queueEvents -> id ) ; $ jobEvent = $ this -> dispatch ( $ queueEvents ) ; $ this -> setEndTime ( $ queueEvents -> id , $ queueEvents -> intervaltorun ) ; $ this -> saveJobResult ( $ queueEvents -> id , $ jobEvent ) ; } } } else { $ this -> response ( $ eventname , 'noActiveJobs' , 'INFO' ) ; } }
Startet die Verarbeitung der Events eines Types der Queue .
18,476
protected function setError ( $ id ) { $ queueEvent = new QueueSetErrorEvent ( ) ; $ queueEvent -> setId ( $ id ) ; $ this -> dispatcher -> dispatch ( $ queueEvent :: NAME , $ queueEvent ) ; }
Setzt die Endzeit der Verarbeitung eines Eintrags in der Queue .
18,477
protected function saveJobResult ( $ id , $ jobEvent ) { if ( $ jobEvent ) { $ queueEvent = new QueueSaveJobResultEvent ( ) ; $ queueEvent -> setId ( $ id ) ; $ queueEvent -> setData ( $ jobEvent ) ; $ this -> dispatcher -> dispatch ( $ queueEvent :: NAME , $ queueEvent ) ; } }
Speichernt das verarbeitete Event in der Queue damit die Fehlermeldungen erhalten bleiben .
18,478
protected function dispatch ( $ queueEvent ) { $ event = urldecode ( $ queueEvent -> data ) ; $ event = unserialize ( $ event ) ; if ( $ event ) { $ this -> dispatcher -> dispatch ( $ event :: NAME , $ event ) ; if ( $ event -> getHasError ( ) ) { $ this -> setError ( $ queueEvent -> id ) ; $ this -> response ( $ event :: NAME , $ event -> getError ( ) , 'ERROR' , $ event -> getParam ( ) ) ; } else { $ this -> response ( $ event :: NAME , $ event -> getReturnMessages ( ) , 'NOTICE' , $ event -> getParam ( ) ) ; } return $ event ; } }
Ruft die Verarbeitung eines Events der Queue auf .
18,479
public function markAsRead ( int $ messageId ) { $ this -> sql = 'update message set is_read = \'Y\' where id = ?' ; $ this -> bindValues [ ] = $ messageId ; return $ this -> execute ( ) ; }
Mark As Read
18,480
public function markAsUnread ( int $ messageId ) { $ this -> sql = 'update message set is_read = \'N\' where id = ?' ; $ this -> bindValues [ ] = $ messageId ; return $ this -> execute ( ) ; }
Mark As Unread
18,481
public static function fromSpecification ( string $ specification ) : self { $ microseconds = 0 ; if ( false !== ( $ position = stripos ( $ specification , 'U' ) ) ) { $ microseconds = '' ; while ( $ position > 0 ) { $ char = $ specification [ -- $ position ] ; if ( ! is_numeric ( $ char ) ) { break ; } $ microseconds = $ char . $ microseconds ; } $ specification = substr ( $ specification , 0 , - 1 - strlen ( $ microseconds ) ) ; } if ( 'P' === $ specification || 'PT' === $ specification ) { $ specification = 'P0Y' ; } return new static ( new \ DateInterval ( $ specification ) , ( int ) $ microseconds ) ; }
Creates a new interval from a specification string .
18,482
public static function diff ( DateTime $ a , DateTime $ b , bool $ absolute = false ) : self { $ microseconds = $ b -> microsecond ( ) - $ a -> microsecond ( ) ; if ( $ absolute ) { $ microseconds = abs ( $ microseconds ) ; } $ diff = $ a -> toInternalDateTime ( ) -> diff ( $ b -> toInternalDateTime ( ) , $ absolute ) ; return new static ( $ diff , $ microseconds ) ; }
Returns an interval representing the difference between two dates .
18,483
public static function fromComponents ( int $ years = null , int $ months = null , int $ weeks = null , int $ days = null , int $ hours = null , int $ minutes = null , int $ seconds = null , int $ microseconds = null ) : self { if ( ! ( $ years || $ months || $ weeks || $ days || $ hours || $ minutes || $ seconds || $ microseconds ) ) { throw new \ InvalidArgumentException ( 'At least one component is required.' ) ; } $ years = $ years ? : 0 ; $ months = $ months ? : 0 ; $ weeks = $ weeks ? : 0 ; $ days = $ days ? : 0 ; $ hours = $ hours ? : 0 ; $ minutes = $ minutes ? : 0 ; $ seconds = $ seconds ? : 0 ; $ microseconds = $ microseconds ? : 0 ; $ specification = 'P' ; if ( $ years ) { $ specification .= $ years . 'Y' ; } if ( $ months ) { $ specification .= $ months . 'M' ; } if ( $ weeks ) { $ specification .= $ weeks . 'W' ; } if ( $ days ) { $ specification .= $ days . 'D' ; } if ( $ hours || $ minutes || $ seconds ) { $ specification .= 'T' ; if ( $ hours ) { $ specification .= $ hours . 'H' ; } if ( $ minutes ) { $ specification .= $ minutes . 'M' ; } if ( $ seconds ) { $ specification .= $ seconds . 'M' ; } } return new static ( new \ DateInterval ( $ specification ) , $ microseconds ) ; }
Note that if weeks and days are both specified only days will be used and weeks will be ignored .
18,484
public function format ( string $ format ) : string { $ format = preg_replace_callback ( '/((?:^|[^%])(?:%{2})*)(%u)/' , function ( array $ matches ) { return $ matches [ 1 ] . $ this -> microseconds ; } , $ format ) ; $ format = $ this -> wrapped -> format ( $ format ) ; return $ format ; }
In addition to the regular \ DateInterval formats this also supports %u for microseconds .
18,485
public function totalMicroseconds ( ) : int { if ( null === $ this -> totalMicroseconds ) { $ reference = DateTime :: now ( ) ; $ end = $ reference -> add ( $ this ) ; $ this -> totalMicroseconds = $ end -> timestampWithMicrosecond ( ) - $ reference -> timestampWithMicrosecond ( ) ; } return $ this -> totalMicroseconds ; }
The total number of microseconds represented by the interval .
18,486
private static function clone ( \ DateInterval $ interval ) { $ specification = $ interval -> format ( 'P%yY%mM%dDT%hH%iM%sS' ) ; $ clone = new \ DateInterval ( $ specification ) ; $ clone -> days = $ interval -> days ; $ clone -> invert = $ interval -> invert ; return $ clone ; }
Clone does not work for DateInterval object for some reason it leads to an error .
18,487
public function view ( $ slug = null ) { if ( $ this -> request -> getQuery ( 'q' ) ) { return $ this -> redirect ( [ $ this -> request -> getQuery ( 'q' ) ] ) ; } $ page = $ this -> request -> getQuery ( 'page' , 1 ) ; $ cache = sprintf ( 'category_%s_limit_%s_page_%s' , md5 ( $ slug ) , $ this -> paginate [ 'limit' ] , $ page ) ; list ( $ posts , $ paging ) = array_values ( Cache :: readMany ( [ $ cache , sprintf ( '%s_paging' , $ cache ) ] , $ this -> PostsCategories -> getCacheName ( ) ) ) ; if ( empty ( $ posts ) || empty ( $ paging ) ) { $ query = $ this -> PostsCategories -> Posts -> find ( 'active' ) -> find ( 'forIndex' ) -> where ( [ sprintf ( '%s.slug' , $ this -> PostsCategories -> getAlias ( ) ) => $ slug ] ) ; is_true_or_fail ( ! $ query -> isEmpty ( ) , I18N_NOT_FOUND , RecordNotFoundException :: class ) ; $ posts = $ this -> paginate ( $ query ) ; Cache :: writeMany ( [ $ cache => $ posts , sprintf ( '%s_paging' , $ cache ) => $ this -> request -> getParam ( 'paging' ) , ] , $ this -> PostsCategories -> getCacheName ( ) ) ; } else { $ this -> request = $ this -> request -> withParam ( 'paging' , $ paging ) ; } $ this -> set ( 'category' , $ posts -> extract ( 'category' ) -> first ( ) ) ; $ this -> set ( compact ( 'posts' ) ) ; }
Lists posts for a category
18,488
protected function getPath ( $ filename , $ serialized ) { if ( $ serialized ) { $ filename = pathinfo ( $ filename , PATHINFO_FILENAME ) . '_serialized.log' ; } return LOGS . $ filename ; }
Internal method to get the path for a log
18,489
protected function read ( $ filename , $ serialized ) { $ log = $ this -> getPath ( $ filename , $ serialized ) ; is_readable_or_fail ( $ log ) ; $ log = file_get_contents ( $ log ) ; return $ serialized ? @ unserialize ( $ log ) : trim ( $ log ) ; }
Internal method to read a log content
18,490
public function view ( $ filename ) { $ serialized = false ; if ( $ this -> request -> getQuery ( 'as' ) === 'serialized' ) { $ serialized = true ; $ this -> viewBuilder ( ) -> setTemplate ( 'view_as_serialized' ) ; } $ content = $ this -> read ( $ filename , $ serialized ) ; $ this -> set ( compact ( 'content' , 'filename' ) ) ; }
Views a log
18,491
public function download ( $ filename ) { return $ this -> response -> withFile ( $ this -> getPath ( $ filename , false ) , [ 'download' => true ] ) ; }
Downloads a log
18,492
public function delete ( $ filename ) { $ this -> request -> allowMethod ( [ 'post' , 'delete' ] ) ; $ success = ( new File ( $ this -> getPath ( $ filename , false ) ) ) -> delete ( ) ; $ serialized = $ this -> getPath ( $ filename , true ) ; if ( file_exists ( $ serialized ) ) { $ successSerialized = ( new File ( $ serialized ) ) -> delete ( ) ; } if ( $ success && $ successSerialized ) { $ this -> Flash -> success ( I18N_OPERATION_OK ) ; } else { $ this -> Flash -> error ( I18N_OPERATION_NOT_OK ) ; } return $ this -> redirect ( [ 'action' => 'index' ] ) ; }
Deletes a log . If there s even a serialized log copy it also deletes that .
18,493
public function view ( $ slug = null , $ id = null ) { if ( empty ( $ slug ) ) { $ slug = $ this -> Photos -> findById ( $ id ) -> contain ( [ $ this -> Photos -> Albums -> getAlias ( ) => [ 'fields' => [ 'slug' ] ] ] ) -> extract ( 'album.slug' ) -> first ( ) ; return $ this -> redirect ( compact ( 'id' , 'slug' ) , 301 ) ; } $ photo = $ this -> Photos -> findActiveById ( $ id ) -> select ( [ 'id' , 'album_id' , 'filename' , 'active' , 'modified' ] ) -> contain ( [ $ this -> Photos -> Albums -> getAlias ( ) => [ 'fields' => [ 'id' , 'title' , 'slug' ] ] ] ) -> cache ( sprintf ( 'view_%s' , md5 ( $ id ) ) , $ this -> Photos -> getCacheName ( ) ) -> firstOrFail ( ) ; $ this -> set ( compact ( 'photo' ) ) ; }
Views a photo
18,494
public function preview ( $ id = null ) { $ photo = $ this -> Photos -> findPendingById ( $ id ) -> select ( [ 'id' , 'album_id' , 'filename' ] ) -> contain ( [ $ this -> Photos -> Albums -> getAlias ( ) => [ 'fields' => [ 'id' , 'title' , 'slug' ] ] ] ) -> firstOrFail ( ) ; $ this -> set ( compact ( 'photo' ) ) ; $ this -> render ( 'view' ) ; }
Preview for photos . It uses the view template .
18,495
protected function checkCurrencies ( $ currencies ) { foreach ( ( array ) $ currencies as $ currency ) { if ( ! $ this -> hasCurrency ( $ currency ) ) { throw new InvalidCurrencyException ( sprintf ( '"%s" is an unknown currency code.' , $ currency ) ) ; } } }
Checks to see if the currencies supplied are known or unknown .
18,496
public function getRate ( $ fromCurrency , $ toCurrency = null ) { if ( null === $ toCurrency ) { $ toCurrency = $ this -> getBaseCurrency ( ) ; } $ this -> checkCurrencies ( array ( $ fromCurrency , $ toCurrency ) ) ; return $ this -> exchanger -> getRate ( $ fromCurrency , $ toCurrency ) ; }
Returns the current exchange rate between 2 currencies .
18,497
public function reduce ( MoneyInterface $ source , $ toCurrency = null ) { if ( null === $ toCurrency ) { $ toCurrency = $ this -> getBaseCurrency ( ) ; } $ this -> checkCurrencies ( $ toCurrency ) ; return $ source -> reduce ( $ this , $ toCurrency ) ; }
Reduces the supplied monetary object into a single Money object of the supplied currency .
18,498
public function createMoney ( $ amount , $ currency = null ) { if ( null === $ currency ) { $ currency = $ this -> getBaseCurrency ( ) ; } $ this -> checkCurrencies ( $ currency ) ; $ class = $ this -> moneyClass ; return new $ class ( $ amount , $ currency ) ; }
Creates a new money instance . If currency is not supplied the base currency for this bank is used .
18,499
public function verifyCredentials ( $ sIdentifier , $ sPassword ) { $ oUserModel = Factory :: model ( 'User' , 'nails/module-auth' ) ; $ oPasswordModel = Factory :: model ( 'UserPassword' , 'nails/module-auth' ) ; $ oUser = $ oUserModel -> getByIdentifier ( $ sIdentifier ) ; return ! empty ( $ oUser ) ? $ oPasswordModel -> isCorrect ( $ oUser -> id , $ sPassword ) : false ; }
Verifies a user s login credentials