idx
int64
0
60.3k
question
stringlengths
99
4.85k
target
stringlengths
5
718
46,400
protected function newItem ( string $ sKey ) : Item { $ oObj = ( object ) [ 'sKey' => $ sKey , 'sPath' => $ this -> prepKey ( $ sKey ) , ] ; if ( defined ( 'PHPUNIT_NAILS_COMMON_TEST_SUITE' ) ) { $ oItem = new Item ( $ oObj ) ; } else { $ oItem = Factory :: resource ( 'FileCacheItem' , null , $ oObj ) ; } return $ oIte...
Configures a new item object
46,401
public static function fileExistsCS ( $ sFilename ) { if ( array_key_exists ( $ sFilename , static :: $ aFileExistsCache ) ) { return static :: $ aFileExistsCache [ $ sFilename ] ; } $ sDirectory = dirname ( $ sFilename ) ; $ aFiles = array_map ( function ( $ sFile ) { return basename ( $ sFile ) ; } , glob ( $ sDirect...
A case - sensitive file_exists
46,402
public static function isDirCS ( $ sDir ) { if ( array_key_exists ( $ sDir , static :: $ aIsDirCache ) ) { return static :: $ aIsDirCache [ $ sDir ] ; } $ aDirBits = explode ( DIRECTORY_SEPARATOR , $ sDir ) ; $ bResult = true ; while ( count ( $ aDirBits ) > 1 ) { $ sDirectory = array_pop ( $ aDirBits ) ; $ sDirectoryP...
A case - sensitive is_dir
46,403
private function getObjectStates ( Options $ options ) : array { $ allObjectStates = [ ] ; $ groups = $ this -> objectStateService -> loadObjectStateGroups ( ) ; $ configuredGroups = $ options [ 'states' ] ; foreach ( $ groups as $ group ) { $ configuredGroups += [ $ group -> identifier => true ] ; if ( $ configuredGro...
Returns the allowed content states from eZ Platform .
46,404
protected function setCache ( $ sKey , $ mValue ) { if ( ! static :: $ CACHING_ENABLED ) { return false ; } elseif ( empty ( $ sKey ) ) { return false ; } if ( function_exists ( 'ini_get' ) ) { $ sMemoryLimit = ini_get ( 'memory_limit_cat' ) ; if ( $ sMemoryLimit !== false ) { $ sLastChar = strtoupper ( $ sMemoryLimit ...
Saves an item to the cache
46,405
protected function setCacheAlias ( $ sAliasKey , $ sOriginalKey ) { if ( ! static :: $ CACHING_ENABLED ) { return false ; } elseif ( empty ( $ sAliasKey ) || empty ( $ sOriginalKey ) ) { return false ; } $ sOriginalCacheKey = $ this -> getCache ( $ sOriginalKey , false ) ; if ( is_null ( $ sOriginalCacheKey ) ) { retur...
Adds an additional key to an existing cache item
46,406
protected function getCache ( $ sKey , $ bReturnValue = true ) { if ( ! static :: $ CACHING_ENABLED ) { return false ; } elseif ( empty ( $ sKey ) ) { return false ; } $ sCacheKey = $ this -> getCachePrefix ( ) . $ sKey ; foreach ( $ this -> aCache as $ iIndex => $ oCacheItem ) { if ( in_array ( $ sCacheKey , $ oCacheI...
Fetches an item from the cache
46,407
protected function unsetCachePrefix ( $ sPrefix ) { if ( ! static :: $ CACHING_ENABLED ) { return false ; } elseif ( empty ( $ sPrefix ) ) { return false ; } $ sPrefix = $ this -> getCachePrefix ( ) . $ sPrefix ; $ aKeysToUnset = [ ] ; foreach ( $ this -> aCache as $ sCacheKey => $ oCacheItem ) { foreach ( $ oCacheItem...
Deletes item from the cache which match a particular prefix
46,408
public function execute ( ) { $ oModel = Factory :: model ( static :: CONFIG_MODEL_NAME , static :: CONFIG_MODEL_PROVIDER ) ; $ oLocale = Factory :: service ( 'Locale' ) ; $ oDefaultLocale = $ oLocale -> getDefautLocale ( ) ; $ aFieldsDescribed = $ oModel -> describeFields ( ) ; $ aFields = [ ] ; foreach ( $ aFieldsDes...
Execute the seed
46,409
protected function generate ( $ aFields ) { $ aOut = [ ] ; foreach ( $ aFields as $ oField ) { switch ( $ oField -> type ) { case 'textarea' : $ mValue = $ this -> loremParagraph ( ) ; break ; case 'wysiwyg' : $ mValue = $ this -> loremHtml ( ) ; break ; case 'number' : $ mValue = $ this -> randomInteger ( ) ; break ; ...
Generate a new item
46,410
public function setFile ( $ sFile = '' ) { $ this -> oLog -> exists = false ; if ( ! empty ( $ sFile ) ) { $ this -> oLog -> file = $ sFile ; } else { $ oDate = Factory :: factory ( 'DateTime' ) ; $ this -> oLog -> file = 'log-' . $ oDate -> format ( 'Y-m-d' ) . '.php' ; } }
Set the filename which is being written to
46,411
public function setDir ( $ sDir = '' ) { $ this -> oLog -> exists = false ; if ( ! empty ( $ sDir ) && substr ( $ sDir , 0 , 1 ) === '/' ) { $ this -> oLog -> dir = $ sDir ; } elseif ( ! empty ( $ sDir ) ) { $ this -> oLog -> dir = DEPLOY_LOG_DIR . $ sDir ; } else { $ this -> oLog -> dir = DEPLOY_LOG_DIR ; } }
Set the log directory which is being written to
46,412
public function prepare ( $ sQuery ) { if ( empty ( $ this -> oDb ) ) { $ this -> connect ( ) ; } return $ this -> oDb -> prepare ( $ sQuery ) ; }
Prepares an SQL query
46,413
public function escape ( $ sString ) { if ( empty ( $ this -> oDb ) ) { $ this -> connect ( ) ; } return $ this -> oDb -> quote ( $ sString ) ; }
Escapes a string to make it query safe
46,414
public function transactionStart ( ) { if ( empty ( $ this -> oDb ) ) { $ this -> connect ( ) ; } try { $ this -> oDb -> beginTransaction ( ) ; $ this -> transactionRunning = true ; return true ; } catch ( \ Exception $ e ) { throw new TransactionException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
Starts a DB transaction
46,415
public function transactionCommit ( ) { if ( empty ( $ this -> oDb ) ) { $ this -> connect ( ) ; } try { $ this -> oDb -> commit ( ) ; $ this -> transactionRunning = false ; return true ; } catch ( \ Exception $ e ) { throw new TransactionException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
Commits a DB transaction
46,416
public function transactionRollback ( ) { if ( empty ( $ this -> oDb ) ) { $ this -> connect ( ) ; } try { $ this -> oDb -> rollback ( ) ; $ this -> transactionRunning = false ; return true ; } catch ( \ Exception $ e ) { throw new TransactionException ( $ e -> getMessage ( ) , $ e -> getCode ( ) ) ; } }
Rollsback a DB transaction
46,417
public static function replaceLastOccurrence ( $ sString , $ sReplace , $ sSubject ) { $ iPos = strrpos ( $ sSubject , $ sString ) ; if ( $ iPos !== false ) { $ sSubject = substr_replace ( $ sSubject , $ sReplace , $ iPos , strlen ( $ sString ) ) ; } return $ sSubject ; }
Replace the last occurrence of a string within a string with a string
46,418
public static function underscoreToCamelcase ( $ sString , $ bLowerFirst = true ) { $ sString = explode ( '_' , $ sString ) ; $ sString = array_map ( 'strtolower' , $ sString ) ; $ sString = array_map ( 'ucfirst' , $ sString ) ; $ sString = implode ( $ sString ) ; $ sString = $ bLowerFirst ? lcfirst ( $ sString ) : $ s...
Transforms a string with underscores into a camelcased string
46,419
public static function generateToken ( $ sMask = null , $ aChars = [ ] , $ aDigits = [ ] ) { $ sMask = empty ( $ sMask ) ? 'AAAA-AAAA-AAAA-AAAA-AAAA-AAAA' : $ sMask ; $ aChars = empty ( $ aChars ) ? str_split ( 'abcdefghijklmnopqrstuvwxyz' ) : $ aChars ; $ aDigits = empty ( $ aDigits ) ? str_split ( '0123456789' ) : $ ...
Generates a token string using a specific mask
46,420
public static function prosaicList ( array $ aArray , $ sSeparator = ', ' , $ sConjunctive = ' and ' , $ bOxfordComma = true ) { $ iCount = count ( $ aArray ) ; if ( $ iCount <= 1 ) { return implode ( '' , $ aArray ) ; } elseif ( $ iCount == 2 ) { return implode ( $ sConjunctive , $ aArray ) ; } else { $ aOut = [ ] ; f...
Takes an array of strings and returns as a comma separated string using a terminal conjunctive optionally using an Oxford Comma .
46,421
public function getInstance ( $ sSlug ) { if ( isset ( $ this -> aInstances [ $ sSlug ] ) ) { return $ this -> aInstances [ $ sSlug ] ; } else { foreach ( $ this -> aComponents as $ oDriverConfig ) { if ( $ sSlug == $ oDriverConfig -> slug ) { $ oDriver = $ oDriverConfig ; break ; } } if ( ! empty ( $ oDriver ) ) { $ t...
Return an instance of the driver .
46,422
public function getContentName ( $ contentId ) : string { try { $ versionInfo = $ this -> loadVersionInfo ( $ contentId ) ; return $ versionInfo -> getName ( ) ?? '' ; } catch ( Throwable $ t ) { return '' ; } }
Returns the content name .
46,423
public function getLocationPath ( $ locationId ) : array { try { $ location = $ this -> loadLocation ( $ locationId ) ; $ locationPath = $ location -> path ; array_shift ( $ locationPath ) ; $ translatedNames = [ ] ; foreach ( $ locationPath as $ locationPathId ) { $ locationInPath = $ this -> loadLocation ( $ location...
Returns the location path .
46,424
public function getContentTypeName ( string $ identifier ) : string { try { $ contentType = $ this -> loadContentType ( $ identifier ) ; return $ contentType -> getName ( ) ?? '' ; } catch ( Throwable $ t ) { return '' ; } }
Returns the content type name .
46,425
private function loadVersionInfo ( $ contentId ) : VersionInfo { return $ this -> repository -> sudo ( static function ( Repository $ repository ) use ( $ contentId ) : VersionInfo { return $ repository -> getContentService ( ) -> loadVersionInfoById ( $ contentId ) ; } ) ; }
Loads the version info for provided content ID .
46,426
private function loadContentType ( string $ identifier ) : ContentType { return $ this -> repository -> sudo ( static function ( Repository $ repository ) use ( $ identifier ) : ContentType { return $ repository -> getContentTypeService ( ) -> loadContentTypeByIdentifier ( $ identifier ) ; } ) ; }
Loads the content type for provided identifier .
46,427
public static function get ( ) { if ( empty ( static :: $ sEnvironment ) ) { if ( ! empty ( $ _ENV [ 'ENVIRONMENT' ] ) ) { static :: set ( $ _ENV [ 'ENVIRONMENT' ] ) ; } else { static :: set ( ENVIRONMENT ) ; } try { $ oInput = Factory :: service ( 'Input' ) ; if ( static :: not ( static :: ENV_PROD ) && $ oInput -> he...
Get the current environment
46,428
public static function is ( $ mEnvironment ) { if ( is_array ( $ mEnvironment ) ) { return array_search ( static :: get ( ) , array_map ( 'strtoupper' , $ mEnvironment ) ) !== false ; } else { return static :: get ( ) === strtoupper ( $ mEnvironment ) ; } }
Returns whether the environment is the supplied environment
46,429
public function filter_uri ( & $ str ) { try { parent :: filter_uri ( $ str ) ; } catch ( Exception $ e ) { $ sMessage = 'The URI you submitted has disallowed characters.' ; if ( Environment :: is ( Environment :: ENV_PROD ) && $ e -> getMessage ( ) === $ sMessage ) { ErrorHandler :: halt ( $ sMessage , '' , HttpCodes ...
Filters the URI and prevents illegal characters
46,430
public function query ( $ sQuery ) { $ sQuery = $ this -> replaceConstants ( $ sQuery ) ; $ this -> iQueryCount ++ ; $ this -> sLastQuery = $ sQuery ; return $ this -> oDb -> query ( $ sQuery ) ; }
Execute a DB query
46,431
public function prepare ( $ sQuery ) { $ sQuery = $ this -> replaceConstants ( $ sQuery ) ; $ this -> iQueryCount ++ ; $ this -> sLastQuery = $ sQuery ; return $ this -> oDb -> prepare ( $ sQuery ) ; }
Prepare a DB query
46,432
protected function parseUrl ( string $ sUrl ) : \ stdClass { preg_match ( $ this -> oLocaleService -> getUrlRegex ( ) , $ sUrl , $ aMatches ) ; $ sLanguage = ! empty ( $ aMatches [ 1 ] ) ? $ aMatches [ 1 ] : '' ; $ sRequestUrl = ! empty ( $ aMatches [ 3 ] ) ? $ aMatches [ 3 ] : '' ; $ aRequestUrl = parse_url ( $ sReque...
Parse the URL for supported languages
46,433
public function getData ( $ sKey = null ) { if ( is_null ( $ sKey ) ) { return $ this -> aData ; } elseif ( array_key_exists ( $ sKey , $ this -> aData ) ) { return $ this -> aData [ $ sKey ] ; } else { return null ; } }
Get an item from the view data array
46,434
public function setData ( $ mKey , $ mValue = null ) { if ( is_array ( $ mKey ) ) { foreach ( $ mKey as $ sKey => $ mSubValue ) { $ this -> setData ( $ sKey , $ mSubValue ) ; } } elseif ( is_string ( $ mKey ) || is_numeric ( $ mKey ) ) { $ this -> aData [ $ mKey ] = $ mValue ; } else { throw new NailsException ( 'Key m...
Add an item to the view data array or update an existing item
46,435
public function unsetData ( $ mKey ) { if ( is_array ( $ mKey ) ) { foreach ( $ mKey as $ sSubKey ) { $ this -> unsetData ( $ sSubKey ) ; } } else { unset ( $ this -> aData [ $ mKey ] ) ; } return $ this ; }
Unset an item from the view data array
46,436
protected function resolvePath ( $ sView ) { $ sCacheKey = 'path:' . $ sView ; $ sCached = $ this -> getCache ( $ sCacheKey ) ; if ( $ sCached !== null ) { return $ sCached ; } $ sView = preg_replace ( '/\.php$/' , '' , $ sView ) . '.php' ; $ sResolvedPath = '' ; $ oRouter = Factory :: service ( 'Router' ) ; if ( strpo...
Attempts to resolve the view path
46,437
public function isLoaded ( string $ sView ) : bool { try { return array_key_exists ( $ this -> resolvePath ( $ sView ) , $ this -> aLoadedViews ) ; } catch ( ViewNotFoundException $ e ) { return false ; } }
Determines if a view has previous been loaded or not
46,438
function defineAppVars ( ) { $ vars = [ ] ; $ vars [ ] = '// App Constants' ; $ vars [ ] = [ 'key' => 'APP_NAME' , 'label' => 'App Name' , 'value' => defined ( 'APP_NAME' ) ? APP_NAME : 'Untitled' , ] ; $ vars [ ] = [ 'key' => 'APP_DEFAULT_TIMEZONE' , 'label' => 'App Timezone' , 'value' => defined ( 'APP_DEFAULT_TIMEZO...
Defines all the App vars and their defaults
46,439
private function defineDeployVars ( ) { $ vars = [ ] ; $ vars [ ] = [ 'key' => 'ENVIRONMENT' , 'label' => 'Environment' , 'value' => Environment :: get ( ) ? : Environment :: ENV_DEV , 'options' => Environment :: available ( ) , 'callback' => function ( $ sInput ) { return trim ( strtoupper ( $ sInput ) ) ; } , ] ; $ v...
Defines all the Deploy vars and their defaults
46,440
private function getVarValue ( $ sKey , $ aVars ) { foreach ( $ aVars as $ aVar ) { if ( $ sKey == $ aVar [ 'key' ] ) { return $ aVar [ 'value' ] ; } } return null ; }
Returns the current value of a variable
46,441
private function getConstantsFromFile ( $ path , array $ vars = [ ] ) { $ out = [ ] ; if ( file_exists ( $ path ) ) { $ appFile = file_get_contents ( $ path ) ; $ pattern = '/define\([\'|"](.+?)[\'|"]\,(.*)\)/' ; preg_match_all ( $ pattern , $ appFile , $ matches ) ; if ( ! empty ( $ matches [ 0 ] ) ) { $ numMatches = ...
Finds all constants defined in a particular file
46,442
private function setVars ( & $ vars ) { foreach ( $ vars as & $ v ) { if ( is_array ( $ v ) ) { $ question = 'What should "' . $ v [ 'label' ] . '" be set to?' ; if ( ! empty ( $ v [ 'options' ] ) ) { $ question .= ' (' . implode ( '|' , $ v [ 'options' ] ) . ')' ; do { $ v [ 'value' ] = $ this -> ask ( $ question , $ ...
Requests the user to confirm all the variables
46,443
private function writeFile ( $ vars , $ file ) { $ fp = fopen ( $ file , 'w' ) ; fwrite ( $ fp , "<?php\n" ) ; foreach ( $ vars as $ v ) { if ( is_string ( $ v ) ) { fwrite ( $ fp , $ v . "\n" ) ; } else { if ( is_numeric ( $ v [ 'value' ] ) ) { $ sValue = $ v [ 'value' ] ; } else { $ sValue = "'" . str_replace ( "'" ,...
Writes the supplied variables to the config file
46,444
private function migrateDb ( $ sDbHost = null , $ sDbUser = null , $ sDbPass = null , $ sDbName = null ) { $ iExitCode = $ this -> callCommand ( 'db:migrate' , [ '--dbHost' => $ sDbHost , '--dbUser' => $ sDbUser , '--dbPass' => $ sDbPass , '--dbName' => $ sDbName , ] , false , true ) ; if ( $ iExitCode == static :: EXI...
Migrates the DB for a fresh install
46,445
private function buildSortParameters ( ParameterBuilderInterface $ builder , array $ groups = [ ] , array $ allowedSortTypes = [ ] ) : void { $ sortTypes = [ 'Published' => 'date_published' , 'Modified' => 'date_modified' , 'Alphabetical' => 'content_name' , 'Priority' => 'location_priority' , 'Defined by parent' => 'd...
Builds the parameters for sorting eZ content .
46,446
private function getSortClauses ( ParameterCollectionInterface $ parameterCollection , ? Location $ parentLocation = null ) : array { $ sortType = $ parameterCollection -> getParameter ( 'sort_type' ) -> getValue ( ) ?? 'default' ; $ sortDirection = $ parameterCollection -> getParameter ( 'sort_direction' ) -> getValue...
Returns the clauses for sorting eZ content .
46,447
public function view ( $ sSlug , $ sView , $ aData = array ( ) , $ bReturn = false ) { $ aSkins = $ this -> getAll ( ) ; $ oSkin = null ; foreach ( $ aSkins as $ oSkinConfig ) { if ( $ oSkinConfig -> slug == $ sSlug ) { $ oSkin = $ oSkinConfig ; break ; } } if ( empty ( $ oSkin ) ) { throw new NailsException ( '"' . $ ...
Load a view contained within a skin
46,448
public function getAllFlat ( ) { $ aOut = array ( ) ; $ aCountries = $ this -> getAll ( ) ; foreach ( $ aCountries as $ oCountry ) { $ aOut [ $ oCountry -> code ] = $ oCountry -> label ; } return $ aOut ; }
Get all defined countries as a flat array
46,449
public function getByCode ( $ sCode ) { $ aCountries = $ this -> getAll ( ) ; return ! empty ( $ aCountries [ $ sCode ] ) ? $ aCountries [ $ sCode ] : false ; }
Get a country by it s code
46,450
public function getContinentByCode ( $ sCode ) { $ aContinents = $ this -> getAll ( ) ; return ! empty ( $ aContinents [ $ sCode ] ) ? $ aContinents [ $ sCode ] : false ; }
Get a continent by it s code
46,451
public function getLogoUrl ( $ iWidth = null , $ iHeight = null ) { $ iLogoId = $ this -> getLogoId ( ) ; if ( ! empty ( $ iLogoId ) && ! empty ( $ iWidth ) && ! empty ( $ iHeight ) ) { return cdnScale ( $ iLogoId , $ iWidth , $ iHeight ) ; } elseif ( ! empty ( $ iLogoId ) ) { return cdnServe ( $ iLogoId ) ; } else { r...
Returns the URL of the driver s logo
46,452
public function getEnabledSlug ( ) { if ( $ this -> bEnableMultiple ) { $ aOut = [ ] ; foreach ( $ this -> mEnabled as $ oComponent ) { $ aOut [ ] = $ oComponent -> slug ; } return $ aOut ; } else { return ! empty ( $ this -> mEnabled -> slug ) ? $ this -> mEnabled -> slug : null ; } }
Fetches the slug of the enabled components or array of slugs if bEnableMultiple is true
46,453
public function getBySlug ( $ sSlug ) { foreach ( $ this -> aComponents as $ oComponent ) { if ( $ sSlug == $ oComponent -> slug ) { return $ oComponent ; } } return null ; }
Get a component by it s slug
46,454
public function saveEnabled ( $ mSlug ) { $ oAppSettingService = Factory :: service ( 'AppSetting' ) ; if ( $ this -> bEnableMultiple ) { $ mSlug = ( array ) $ mSlug ; $ mSlug = array_filter ( $ mSlug ) ; $ mSlug = array_unique ( $ mSlug ) ; } else { $ mSlug = trim ( $ mSlug ) ; } $ aSetting = [ $ this -> sEnabledSetti...
Save which components are enabled
46,455
protected function extractComponentSettings ( $ aSettings , $ sSlug ) { $ aOut = [ ] ; foreach ( $ aSettings as $ oSetting ) { if ( isset ( $ oSetting -> fields ) ) { $ aOut = array_merge ( $ aOut , $ this -> extractComponentSettings ( $ oSetting -> fields , $ sSlug ) ) ; } else { $ sValue = appSetting ( $ oSetting -> ...
Recursively gets all the settings from the settings array
46,456
protected function loremWord ( $ iNumWords = 5 ) { $ aWords = [ 'lorem' , 'ipsum' , 'dolor' , 'sit' , 'amet' , 'consectetur' , 'adipiscing' , 'elit' , 'mauris' , 'venenatis' , 'metus' , 'volutpat' , 'hendrerit' , 'interdum' , 'nisi' , 'odio' , 'finibus' , 'ex' , 'eu' , 'congue' , 'mauris' , 'nisi' , 'in' , 'magna' , 'u...
Generate some random Lorem Ipsum words
46,457
protected function loremSentence ( $ iNumSentences = 1 ) { $ aOut = [ ] ; $ aLengths = [ 5 , 6 , 8 , 10 , 12 ] ; for ( $ i = 0 ; $ i < $ iNumSentences ; $ i ++ ) { $ iLength = $ aLengths [ array_rand ( $ aLengths ) ] ; $ aOut [ ] = ucfirst ( $ this -> loremWord ( $ iLength ) ) ; } return implode ( '. ' , $ aOut ) . '.'...
Generate some random Lorem Ipsum sentences
46,458
protected function loremParagraph ( $ iNumParagraphs = 1 ) { $ aOut = [ ] ; $ aLengths = [ 5 , 6 , 8 , 10 , 12 ] ; for ( $ i = 0 ; $ i < $ iNumParagraphs ; $ i ++ ) { $ iLength = $ aLengths [ array_rand ( $ aLengths ) ] ; $ aOut [ ] = $ this -> loremSentence ( $ iLength ) ; } return implode ( "\n\n" , $ aOut ) ; }
Generate some random Lorem Ipsum paragraphs
46,459
protected function randomId ( $ sModel , $ sProvider , $ aData = [ ] ) { $ oModel = Factory :: model ( $ sModel , $ sProvider ) ; $ aResults = $ oModel -> getAll ( 0 , 1 , $ aData + [ 'sort' => [ [ 'id' , 'random' ] ] ] ) ; $ oRow = reset ( $ aResults ) ; return $ oRow ? $ oRow -> id : null ; }
Returns a random ID from a particular model
46,460
protected function randomPastDateTime ( $ sLow = null ) { $ oNow = Factory :: factory ( 'DateTime' ) ; return $ this -> randomDateTime ( $ sLow , $ oNow -> format ( 'Y-m-d H:i:s' ) ) ; }
Return a random datetime from the past optionally restricted to a lower bound
46,461
protected function randomDate ( $ sLow = null , $ sHigh = null , $ sFormat = 'Y-m-d' ) { $ iLow = $ sLow ? strtotime ( $ sLow ) : strtotime ( 'last year' ) ; $ iHigh = $ sHigh ? strtotime ( $ sHigh ) : strtotime ( 'next year' ) ; return date ( $ sFormat , rand ( $ iLow , $ iHigh ) ) ; }
Return a random date optionally restricted between bounds
46,462
protected function randomFutureDate ( $ sHigh = null ) { $ oNow = Factory :: factory ( 'DateTime' ) ; return $ this -> randomDateTime ( $ oNow -> format ( 'Y-m-d' ) , $ sHigh ) ; }
Return a random date from the future optionally restricted to a upper bound
46,463
private function prepareModelName ( $ sModelName ) : \ stdClass { $ sModelName = preg_replace ( '/[^a-zA-Z\/ ]/' , '' , $ sModelName ) ; $ sModelName = preg_replace ( '/\//' , ' \\ ' , $ sModelName ) ; $ sModelName = ucwords ( $ sModelName ) ; $ sTableName = preg_replace ( '/[^a-z ]/' , '' , strtolower ( $ sModelName )...
Prepare the model details and do some preliminary checks
46,464
private function tableExists ( \ stdClass $ oModel ) : bool { $ oDb = Factory :: service ( 'PDODatabase' ) ; $ oResult = $ oDb -> query ( 'SHOW TABLES LIKE "' . $ oModel -> table_with_prefix . '"' ) ; return $ oResult -> rowCount ( ) > 0 ; }
Detemine whether a particular table exists already
46,465
private function convertExistingModelToLocalised ( \ stdClass $ oModel , bool $ bSkipDb , bool $ bAdmin , bool $ bSkipSeeder ) : void { $ this -> addLocalisedUseStatement ( $ oModel ) -> convertTablesToLocalised ( $ oModel ) ; }
Orchestrates the conversion of a normal model to a localised model
46,466
private function createLocalisedModel ( \ stdClass $ oModel , bool $ bSkipDb , bool $ bAdmin , bool $ bSkipSeeder ) : array { $ this -> createModelFile ( $ oModel , 'model_localised' ) -> createResource ( $ oModel , 'resource' ) ; if ( ! $ bSkipDb ) { $ this -> createDatabaseTable ( $ oModel , 'model_table_localised' )...
Orchestrates the creation of a localised model
46,467
private function createModelFile ( \ stdClass $ oModel , string $ sTemplate ) : self { $ this -> oOutput -> write ( 'Creating model <comment>' . $ oModel -> class_path . '</comment>... ' ) ; $ this -> createPath ( $ oModel -> path ) ; $ this -> createFile ( $ oModel -> path . $ oModel -> filename , $ this -> getResourc...
Creates the model file
46,468
private function createResource ( \ stdClass $ oModel , string $ sTemplate ) : self { $ this -> oOutput -> write ( 'Creating resource <comment>' . $ oModel -> resource_class_path . '</comment>... ' ) ; $ this -> createPath ( $ oModel -> resource_path ) ; $ this -> createFile ( $ oModel -> resource_path . $ oModel -> re...
Creates the resource file
46,469
private function createDatabaseTable ( \ stdClass $ oModel , string $ sTemplate ) : self { $ this -> oOutput -> write ( 'Adding database table... ' ) ; $ oModel -> nails_db_prefix = NAILS_DB_PREFIX ; $ oDb = Factory :: service ( 'PDODatabase' ) ; $ oDb -> query ( $ this -> getResource ( 'template/' . $ sTemplate . '.ph...
Creates the database table
46,470
private function createAdminController ( \ stdClass $ oModel ) : self { $ this -> oOutput -> write ( 'Creating admin controller... ' ) ; $ iExitCode = $ this -> callCommand ( 'make:controller:admin' , [ 'modelName' => $ oModel -> service_name , '--skip-check' => true , ] , false , true ) ; if ( $ iExitCode === static :...
Creates an admin controller
46,471
private function generateServiceDefinitions ( \ stdClass $ oModel ) : array { return [ implode ( "\n" , [ str_repeat ( ' ' , $ this -> iServicesIndent ) . '\'' . $ oModel -> service_name . '\' => function () {' , str_repeat ( ' ' , $ this -> iServicesIndent ) . ' return new ' . $ oModel -> class_path . '();' , str_r...
Genenrates the service file definitions for a model
46,472
private function addLocalisedUseStatement ( \ stdClass $ oModel ) : self { $ sFile = file_get_contents ( $ oModel -> path . $ oModel -> filename ) ; $ aClasses = [ ] ; if ( preg_match_all ( '/^use (.+);$/m' , $ sFile , $ aMatches ) ) { if ( ! empty ( $ aMatches [ 1 ] ) ) { $ aClasses = $ aMatches [ 1 ] ; } } $ aClasses...
Adds a use Localised statement to a model
46,473
private function convertTablesToLocalised ( \ stdClass $ oModel ) : self { $ oDb = Factory :: service ( 'Database' ) ; $ oLocale = Factory :: service ( 'Locale' ) ; $ aQueries = [ 'SET FOREIGN_KEY_CHECKS = 0;' , 'RENAME TABLE `' . $ oModel -> table_with_prefix . '` TO `' . $ oModel -> table_with_prefix . '_localised`;'...
Converts existing non - localised model tables to a localised version
46,474
public static function siteUrl ( string $ sUrl = null , bool $ bForceSecure = false ) : string { $ oConfig = \ Nails \ Factory :: service ( 'Config' ) ; return $ oConfig :: siteUrl ( $ sUrl , $ bForceSecure ) ; }
Create a local URL based on your basepath . Segments can be passed via the first parameter either as a string or an array .
46,475
public function getUrl ( string $ sKey = null ) : string { $ sUrl = rtrim ( $ this -> sUrl , '/' ) ; $ sUrl .= $ sKey ? '/' . $ sKey : '' ; return $ sUrl ; }
Return the URL for the public cache
46,476
public static function arraySortMulti ( array & $ aArray , $ sField ) { uasort ( $ aArray , function ( $ a , $ b ) use ( $ sField ) { $ oA = ( object ) $ a ; $ oB = ( object ) $ b ; $ mA = property_exists ( $ oA , $ sField ) ? strtolower ( $ oA -> $ sField ) : null ; $ mB = property_exists ( $ oB , $ sField ) ? strtolo...
Sorts a multi dimensional array
46,477
public static function arraySearchMulti ( $ sValue , $ sKey , array $ aArray ) { foreach ( $ aArray as $ k => $ val ) { if ( is_array ( $ val ) ) { if ( $ val [ $ sKey ] == $ sValue ) { return $ k ; } } elseif ( is_object ( $ val ) ) { if ( $ val -> $ sKey == $ sValue ) { return $ k ; } } } return false ; }
Searches a multi - dimensional array
46,478
public static function inArrayMulti ( $ sValue , $ sKey , array $ aArray ) : bool { return static :: arraySearchMulti ( $ sValue , $ sKey , $ aArray ) !== false ; }
Reports whether a value exists in a multi dimensional array
46,479
public static function arrayExtractProperty ( array $ aInput , $ sProperty ) { $ aOutput = [ ] ; foreach ( $ aInput as $ mItem ) { $ aItem = ( array ) $ mItem ; if ( array_key_exists ( $ sProperty , $ aItem ) ) { $ aOutput [ ] = $ aItem [ $ sProperty ] ; } } return $ aOutput ; }
Extracts the value of properties from a multi - dimensional array into an array of those values
46,480
public function show_error ( $ sSubject , $ sMessage = '' , $ sTemplate = '500' , $ iStatusCode = 500 , $ bUseException = true ) { if ( is_array ( $ sMessage ) ) { $ sMessage = implode ( '<br>' , $ sMessage ) ; } if ( $ bUseException ) { throw new NailsException ( $ sMessage , $ iStatusCode ) ; } else { $ oErrorHandler...
Override the show_error method and pass to the Nails ErrorHandler
46,481
public function show_exception ( $ oException ) { $ oErrorHandler = Factory :: service ( 'ErrorHandler' ) ; $ sMessage = implode ( '; ' , [ 'Code: ' . $ oException -> getCode ( ) , 'File: ' . $ oException -> getFile ( ) , 'Line: ' . $ oException -> getLine ( ) , ] ) ; $ oErrorHandler -> showFatalErrorScreen ( $ oExcept...
Override the show_exception method and pass to the Nails ErrorHandler
46,482
public function show_php_error ( $ iSeverity , $ sMessage , $ sFilePath , $ iLine ) { $ oErrorHandler = Factory :: service ( 'ErrorHandler' ) ; return $ oErrorHandler -> triggerError ( $ iSeverity , $ sMessage , $ sFilePath , $ iLine ) ; }
Overrides the show_php_error method in order to track errors
46,483
public function trigger ( $ sEvent , $ sNamespace = 'nails/common' , $ aData = [ ] ) { $ this -> addHistory ( $ sEvent , $ sNamespace ) ; $ sEvent = strtoupper ( $ sEvent ) ; $ sNamespace = strtoupper ( $ sNamespace ) ; if ( ! empty ( $ this -> aSubscriptions [ $ sNamespace ] [ $ sEvent ] ) ) { foreach ( $ this -> aSub...
Trigger the event and execute all callbacks
46,484
protected function addHistory ( $ sEvent , $ sNamespace = 'nails/common' ) { $ sEvent = strtoupper ( $ sEvent ) ; $ sNamespace = strtoupper ( $ sNamespace ) ; if ( ! array_key_exists ( $ sNamespace , $ this -> aHistory ) ) { $ this -> aHistory [ $ sNamespace ] = [ ] ; } if ( ! array_key_exists ( $ sEvent , $ this -> aH...
Adds a history item to the history array
46,485
public function getHistory ( $ sNamespace = null , $ sEvent = null ) { $ sEvent = strtoupper ( $ sEvent ) ; $ sNamespace = strtoupper ( $ sNamespace ) ; if ( empty ( $ sNamespace ) && empty ( $ sEvent ) ) { return $ this -> aHistory ; } elseif ( empty ( $ sEvent ) && ! empty ( $ sNamespace ) && array_key_exists ( $ sNa...
Retrieve a history item
46,486
public function set ( $ sType , $ sMessage ) { $ sType = strtoupper ( trim ( $ sType ) ) ; $ sMessage = trim ( $ sMessage ) ; $ this -> aMessages [ $ sType ] = $ sMessage ; return $ this ; }
Set a feedback message
46,487
public function get ( $ sType ) { $ sType = strtoupper ( trim ( $ sType ) ) ; if ( ! empty ( $ this -> aMessages [ $ sType ] ) ) { return $ this -> aMessages [ $ sType ] ; } else { return '' ; } }
Return a feedack message
46,488
public function clear ( $ sType = '' ) { if ( empty ( $ sType ) ) { $ this -> aMessages [ $ sType ] = array ( ) ; } else { $ this -> aMessages [ $ sType ] = '' ; } }
Clear feedback messages
46,489
public function getAllDateFormat ( ) { $ aFormats = static :: FORMAT_DATE ; $ oNow = Factory :: factory ( 'DateTime' ) ; foreach ( $ aFormats as & $ aFormat ) { $ aFormat = ( object ) $ aFormat ; $ aFormat -> example = $ oNow -> format ( $ aFormat -> format ) ; } return $ aFormats ; }
Returns all the defined date format objects
46,490
public function getAllDateFormatFlat ( ) { $ aOut = [ ] ; $ aFormats = $ this -> getAllDateFormat ( ) ; foreach ( $ aFormats as $ oFormat ) { $ aOut [ $ oFormat -> slug ] = $ oFormat -> example ; } return $ aOut ; }
Returns all the date format objects as a flat array
46,491
public function getDateFormatBySlug ( $ sSlug ) { $ aFormats = $ this -> getAllDateFormat ( ) ; foreach ( $ aFormats as $ oFormat ) { if ( $ oFormat -> slug === $ sSlug ) { return $ oFormat ; } } return null ; }
Looks for a date format by it s slug
46,492
public function getAllTimeFormat ( ) { $ aFormats = static :: FORMAT_TIME ; foreach ( $ aFormats as & $ aFormat ) { $ aFormat = ( object ) $ aFormat ; $ oDateTimeObject = static :: convert ( time ( ) , $ this -> sTimezoneUser ) ; $ aFormat -> example = $ oDateTimeObject -> format ( $ aFormat -> format ) ; } return $ aF...
Returns all the defined time format objects
46,493
public function getAllTimeFormatFlat ( ) { $ aOut = [ ] ; $ aFormats = $ this -> getAllTimeFormat ( ) ; foreach ( $ aFormats as $ oFormat ) { $ aOut [ $ oFormat -> slug ] = $ oFormat -> label ; } return $ aOut ; }
Returns all the time format objects as a flat array
46,494
public function getTimeFormatBySlug ( $ sSlug ) { $ aFormats = $ this -> getAllTimeFormat ( ) ; foreach ( $ aFormats as $ oFormat ) { if ( $ oFormat -> slug === $ sSlug ) { return $ oFormat ; } } return null ; }
Looks for a time format by it s slug
46,495
public function setDateFormat ( $ sSlug ) { $ oDateFormat = $ this -> getDateFormatBySlug ( $ sSlug ) ; if ( empty ( $ oDateFormat ) ) { $ oDateFormat = $ this -> getDateFormatDefault ( ) ; } $ this -> sUserFormatDate = $ oDateFormat -> format ; }
Set the date format to use uses default if slug cannot be found
46,496
public function setTimeFormat ( $ sSlug = null ) { $ oTimeFormat = $ this -> getTimeFormatBySlug ( $ sSlug ) ; if ( empty ( $ oTimeFormat ) ) { $ oTimeFormat = $ this -> getTimeFormatDefault ( ) ; } $ this -> sUserFormatTime = $ oTimeFormat -> format ; }
Set the time format to use uses default if slug cannot be found
46,497
public function toUserDate ( $ mTimestamp = null , $ sFormat = null ) { $ oConverted = static :: convert ( $ mTimestamp , $ this -> sTimezoneUser , $ this -> sTimezoneNails ) ; if ( is_null ( $ oConverted ) ) { return null ; } if ( is_null ( $ sFormat ) ) { $ sFormat = $ this -> sUserFormatDate ; } return $ oConverted ...
Convert a date timestamp to the User s timezone from the Nails timezone
46,498
public function toNailsDate ( $ mTimestamp = null ) { $ oConverted = static :: convert ( $ mTimestamp , $ this -> sTimezoneNails , $ this -> sTimezoneUser ) ; if ( is_null ( $ oConverted ) ) { return null ; } return $ oConverted -> format ( 'Y-m-d' ) ; }
Convert a date timestamp to the Nails timezone from the User s timezone formatted as Y - m - d
46,499
public function toUserDatetime ( $ mTimestamp = null , $ sFormat = null ) { $ oConverted = static :: convert ( $ mTimestamp , $ this -> sTimezoneUser , $ this -> sTimezoneNails ) ; if ( is_null ( $ oConverted ) ) { return null ; } if ( is_null ( $ sFormat ) ) { $ sFormat = $ this -> sUserFormatDate . ' ' . $ this -> sU...
Convert a datetime timestamp to the user s timezone from the Nails timezone