idx int64 0 60.3k | question stringlengths 92 4.62k | target stringlengths 7 635 |
|---|---|---|
1,500 | public function addFields ( array $ pFields ) { $ fields = $ this -> _prefixFields ( $ pFields ) ; $ this -> _fields = array_merge ( $ fields , $ this -> _fields ) ; return $ this ; } | Add fields to the select query . |
1,501 | public function limit ( $ pNb ) { if ( is_array ( $ pNb ) and count ( $ pNb ) == 2 and isset ( $ pNb [ 0 ] ) and isset ( $ pNb [ 1 ] ) and is_int ( $ pNb [ 0 ] ) and is_int ( $ pNb [ 1 ] ) ) { $ nb = $ pNb [ 1 ] ; $ this -> skip ( $ pNb [ 0 ] ) ; } else if ( is_int ( $ pNb ) ) { $ nb = $ pNb ; } else { throw new Exception ( "Validation failed for type 'array' or 'int'" ) ; } $ this -> _limit = $ nb ; return $ this ; } | Add a limit to the select query . |
1,502 | public static function register ( $ metaTags ) { if ( $ metaTags instanceof \ mrstroz \ wavecms \ metatags \ models \ MetaTags ) { if ( $ metaTags -> meta_title ) { Yii :: $ app -> view -> title = $ metaTags -> meta_title ; } if ( $ metaTags -> meta_description ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'description' , 'content' => $ metaTags -> meta_description , ] ) ; } if ( $ metaTags -> meta_keywords ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'keywords' , 'content' => $ metaTags -> meta_keywords , ] ) ; } Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'og:url' , 'content' => Yii :: $ app -> request -> absoluteUrl , ] ) ; if ( $ metaTags -> og_type ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'og:type' , 'content' => $ metaTags -> og_type , ] ) ; } if ( $ metaTags -> og_title ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'og:title' , 'content' => $ metaTags -> og_title , ] ) ; } if ( $ metaTags -> og_description ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'og:description' , 'content' => $ metaTags -> og_description , ] ) ; } if ( $ metaTags -> og_image ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'og:image' , 'content' => Url :: base ( true ) . '/images/' . $ metaTags -> og_image ] ) ; list ( $ width , $ height ) = getimagesize ( 'images/' . $ metaTags -> og_image ) ; if ( $ width ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'og:image:width' , 'content' => $ width ] ) ; } if ( $ height ) { Yii :: $ app -> view -> registerMetaTag ( [ 'name' => 'og:image:height' , 'content' => $ height ] ) ; } } } } | Register meta tags |
1,503 | protected function saveInFile ( $ content ) { $ filename = $ this -> config -> get ( 'file_directory' ) . DIRECTORY_SEPARATOR . $ this -> config -> get ( 'file_name' ) ; $ fp = fopen ( $ filename , "a+b" ) ; fwrite ( $ fp , $ content . ";" ) ; fclose ( $ fp ) ; } | Save data in file . |
1,504 | protected function getDataInFile ( ) { $ filename = $ this -> config -> get ( 'file_directory' ) . DIRECTORY_SEPARATOR . $ this -> config -> get ( 'file_name' ) ; if ( ! file_exists ( $ filename ) ) { return array ( ) ; } $ fp = fopen ( $ filename , "rb" ) ; $ contenido = fread ( $ fp , filesize ( $ filename ) ) ; fclose ( $ fp ) ; $ data_ouput = array ( ) ; foreach ( explode ( ';' , $ contenido ) as $ key => $ value ) { $ data_tmp = explode ( '=' , $ value ) ; if ( count ( $ data_tmp ) > 1 ) { $ data_ouput [ $ data_tmp [ 0 ] ] = $ data_tmp [ 1 ] ; } } return $ data_ouput ; } | Get all data in file . |
1,505 | public function clearAllPersistentData ( ) { $ filename = $ this -> config -> get ( 'file_directory' ) . DIRECTORY_SEPARATOR . $ this -> config -> get ( 'file_name' ) ; unlink ( $ filename ) ; } | Clear all data from the persistent storage |
1,506 | public static function setForcedHost ( $ host = null ) { if ( ! is_string ( $ host ) && ! is_null ( $ host ) ) { throw new InvalidArgumentException ( sprintf ( 'Invalid host provided; must be an string or a null, "%s" received.' , is_object ( $ host ) ? get_class ( $ host ) : gettype ( $ host ) ) ) ; } static :: $ forcedHost = $ host ; } | Sets the host name for forced usage . |
1,507 | public static function retrieve ( array $ server = null ) { if ( empty ( $ server ) ) { $ server = $ _SERVER ; } if ( isset ( $ server [ 'SERVER_NAME' ] ) ) { return $ server [ 'SERVER_NAME' ] ; } $ address = '' ; if ( isset ( $ server [ 'SERVER_ADDR' ] ) ) { $ address = $ server [ 'SERVER_ADDR' ] ; } if ( isset ( $ server [ 'LOCAL_ADDR' ] ) ) { $ address = $ server [ 'LOCAL_ADDR' ] ; } if ( false !== strpos ( $ address , ':' ) ) { $ address = '[' . $ address . ']' ; } if ( $ address ) { return $ address ; } } | Retrieves the host name using incoming data ignores a forced host . If unable to retrive the host name try to retrieve server address . |
1,508 | private static function loadIntoCategory ( ) { $ { func_get_arg ( 0 ) -> getNameOfLanguageVariable ( ) } = array ( ) ; require_once func_get_arg ( 1 ) ; if ( ! empty ( $ { func_get_arg ( 0 ) -> getNameOfLanguageVariable ( ) } ) ) { func_get_arg ( 0 ) -> lang [ func_get_arg ( 2 ) ] [ func_get_arg ( 0 ) -> getCategory ( ) ] = $ { func_get_arg ( 0 ) -> getNameOfLanguageVariable ( ) } ; } } | Load the translations into the category from a file by the given path |
1,509 | public function offsetExists ( $ langcode ) { return ( isset ( $ this -> lang [ $ langcode ] [ $ this -> category ] ) or $ this -> isFileExistsInSubDir ( $ langcode ) or $ this -> isFileExistsWithSuffix ( $ langcode ) or $ this -> isFileExistsWithoutSuffix ( $ langcode ) ) ; } | Checking of existence of a language by language code |
1,510 | public function offsetGet ( $ langcode ) { $ noDefaultVersion = $ this -> getDefault ( ) !== $ langcode and ! isset ( $ this -> lang [ $ this -> getDefault ( ) ] [ $ this -> getCategory ( ) ] ) ; if ( ! isset ( $ this -> lang [ $ langcode ] [ $ this -> getCategory ( ) ] ) ) { if ( $ this -> isFileExistsInSubDir ( $ langcode ) ) { $ this -> loadFromFileInSubDir ( $ langcode ) ; } elseif ( $ this -> isFileExistsWithSuffix ( $ langcode ) ) { $ this -> loadFromFileWithSuffix ( $ langcode ) ; } elseif ( $ this -> isFileExistsWithoutSuffix ( $ langcode ) ) { $ this -> loadFromFileWithoutSuffix ( $ langcode ) ; } elseif ( $ noDefaultVersion and $ this -> isFileExistsInSubDir ( $ this -> getDefault ( ) ) ) { $ langcode = $ this -> getDefault ( ) ; $ this -> loadFromFileInSubDir ( $ langcode ) ; } elseif ( $ noDefaultVersion and $ this -> isFileExistsWithSuffix ( $ this -> getDefault ( ) ) ) { $ langcode = $ this -> getDefault ( ) ; $ this -> loadFromFileWithSuffix ( $ langcode ) ; } elseif ( $ noDefaultVersion and $ this -> isFileExistsWithoutSuffix ( $ this -> getDefault ( ) ) ) { $ langcode = $ this -> getDefault ( ) ; $ this -> loadFromFileWithoutSuffix ( $ langcode ) ; } } return $ this -> lang [ $ langcode ] [ $ this -> getCategory ( ) ] ; } | Get the array of texts by the given language code |
1,511 | public static function fromXml ( \ DOMElement $ xml ) { $ static = new static ( ) ; $ locationId = $ xml -> getElementsByTagName ( 'pickupLocation' ) ; $ static -> locationId = StringLiteral :: fromXml ( $ locationId ) ; $ text = $ xml -> getElementsByTagName ( 'pickupLocationText' ) ; $ static -> text = StringLiteral :: fromXml ( $ text ) ; return $ static ; } | Builds a PickupLocation object from XML . |
1,512 | public function add ( $ template , array $ data = [ ] , string $ region = "main" , int $ sort = 0 ) : object { $ this -> di -> get ( "view" ) -> add ( $ template , $ data , $ region , $ sort ) ; return $ this ; } | Utility method to add a view to the view collection for later rendering . |
1,513 | public function render ( array $ data = [ ] , int $ status = 200 ) { $ view = $ this -> di -> get ( "view" ) ; $ view -> add ( $ this -> layout , $ data , "layout" ) ; $ body = $ view -> renderBuffered ( "layout" ) ; $ response = $ this -> di -> get ( "response" ) ; $ response -> setBody ( $ body ) ; $ response -> setStatusCode ( $ status ) ; return $ response ; } | Add the layout view to the region layout and render all views within the region layout and create a response from it . |
1,514 | public static function assertLooselyInArray ( array $ array , $ value , Throwable $ exception ) : bool { static :: makeAssertion ( \ in_array ( $ value , $ array ) , $ exception ) ; return true ; } | Asserts that the given element exists in the given array with loose comparision . |
1,515 | public static function assertInArray ( array $ array , $ value , Throwable $ exception ) : bool { static :: makeAssertion ( \ in_array ( $ value , $ array , true ) , $ exception ) ; return true ; } | Asserts that the given element exists in the given array with strict comparison . |
1,516 | public function create ( $ name , CredentialsInterface $ credentials , StorageInterface $ storage , $ scopes = [ ] , $ baseApiUri = null , $ apiVersion = null ) { $ name = ucfirst ( $ name ) ; if ( is_null ( $ this -> client ) ) $ this -> client = new CurlClient ( ) ; $ class = '\\LibX\OAuth2\\Service\\' . $ name ; if ( ! class_exists ( $ class ) ) throw new \ Exception ( 'Service with name ' . $ name . ' not found' ) ; return new $ class ( $ credentials , $ this -> client , $ storage , $ scopes , $ baseApiUri ) ; } | Create an oauth2 service |
1,517 | public function generateUniqueFilename ( $ originalFilename ) { $ index = 0 ; $ filename = pathinfo ( $ originalFilename , PATHINFO_FILENAME ) ; $ extension = pathinfo ( $ originalFilename , PATHINFO_EXTENSION ) ; while ( $ this -> imageManager -> findByFilename ( $ originalFilename ) ) { $ index ++ ; $ originalFilename = $ filename . '-' . $ index . '.' . $ extension ; } return $ originalFilename ; } | Generate unique filename . |
1,518 | private function updateArgumentReferences ( array $ replacements , $ definitionId , array $ arguments ) { foreach ( $ arguments as $ k => $ argument ) { if ( is_array ( $ argument ) ) { $ arguments [ $ k ] = $ this -> updateArgumentReferences ( $ replacements , $ definitionId , $ argument ) ; continue ; } if ( ! $ argument instanceof Reference ) { continue ; } $ referenceId = ( string ) $ argument ; if ( ! isset ( $ replacements [ $ referenceId ] ) ) { continue ; } $ newId = $ replacements [ $ referenceId ] ; $ arguments [ $ k ] = new Reference ( $ newId , $ argument -> getInvalidBehavior ( ) ) ; $ this -> compiler -> addLogMessage ( $ this -> formatter -> formatUpdateReference ( $ this , $ definitionId , $ referenceId , $ newId ) ) ; } return $ arguments ; } | Recursively updates references in an array . |
1,519 | protected function addWatermarkFilterIfExists ( & $ set , $ width , $ height ) { if ( isset ( $ set [ 'watermark' ] ) ) { if ( ! empty ( $ set [ 'watermark' ] [ 1 ] ) ) { $ set [ 'filters' ] [ ] = [ 'target' , [ $ set [ 'watermark' ] [ 1 ] ] ] ; } if ( ! empty ( $ set [ 'watermark' ] [ 2 ] ) ) { $ set [ 'filters' ] [ ] = [ 'margin' , [ $ set [ 'watermark' ] [ 2 ] ] ] ; } $ set [ 'filters' ] [ ] = [ 'mix' , [ $ set [ 'watermark' ] [ 0 ] ] ] ; } } | Protected add watermark filter |
1,520 | protected function getThumbFileName ( $ x , $ y , $ width , $ height ) { return Filesystem :: removeExtension ( $ this -> file ) . $ this -> addPrefixToThumbFileName ( $ x , $ y , $ width , $ height ) . Filesystem :: getExtension ( $ this -> file , true ) ; } | Protected get thumb file name |
1,521 | protected function applyBackgroundTransparency ( $ file , $ width , $ height ) { imagealphablending ( $ file , false ) ; imagesavealpha ( $ file , true ) ; imagefilledrectangle ( $ file , 0 , 0 , $ width , $ height , $ this -> transparentBackground ( $ file ) ) ; } | Protected apply bacground transparency |
1,522 | protected function setThumbPaths ( $ file ) { $ this -> file = $ this -> getOnlyFileName ( $ file ) ; $ this -> thumbPath = $ this -> createThumbDirectory ( $ file ) ; } | Protected New Path |
1,523 | protected function fromFileType ( $ path ) { switch ( Filesystem :: getExtension ( $ path ) ) { case 'png' : return imagecreatefrompng ( $ path ) ; case 'gif' : return imagecreatefromgif ( $ path ) ; case 'jpg' : case 'jpeg' : default : return imagecreatefromjpeg ( $ path ) ; } } | Protected From File Type |
1,524 | protected function isImageFile ( $ file ) { if ( in_array ( MimeTypeFinder :: get ( $ file ) , $ this -> validMimes ) ) { return true ; } else { return false ; } } | Protected Is Image File |
1,525 | protected function extractSettingVariables ( $ file , $ settings ) { $ variables = [ ] ; list ( $ currentWidth , $ currentHeight ) = getimagesize ( $ file ) ; $ variables [ 'x' ] = $ settings [ 'x' ] ?? 0 ; $ variables [ 'y' ] = $ settings [ 'y' ] ?? 0 ; $ variables [ 'quality' ] = $ settings [ 'quality' ] ?? 0 ; $ variables [ 'prowidth' ] = $ settings [ 'prowidth' ] ?? NULL ; $ variables [ 'proheight' ] = $ settings [ 'proheight' ] ?? NULL ; $ rewidth = $ settings [ 'width' ] ?? $ currentWidth ; $ reheight = $ settings [ 'height' ] ?? $ currentHeight ; if ( ! empty ( $ settings [ 'reheight' ] ) ) { $ height = $ settings [ 'reheight' ] ; } elseif ( ! empty ( $ settings [ 'proheight' ] ) && $ settings [ 'proheight' ] < $ currentHeight ) { $ height = $ settings [ 'proheight' ] ; $ width = round ( ( $ currentWidth * $ height ) / $ currentHeight ) ; } if ( ! empty ( $ settings [ 'rewidth' ] ) ) { $ width = $ settings [ 'rewidth' ] ; } elseif ( ! empty ( $ settings [ 'prowidth' ] ) && $ settings [ 'prowidth' ] < $ currentWidth ) { $ width = $ settings [ 'prowidth' ] ; $ height = round ( ( $ currentHeight * $ width ) / $ currentWidth ) ; } $ variables [ 'width' ] = $ width ?? $ rewidth ; $ variables [ 'height' ] = $ height ?? $ reheight ; $ variables [ 'rWidth' ] = $ rewidth - $ variables [ 'x' ] ; $ variables [ 'rHeight' ] = $ reheight - $ variables [ 'y' ] ; return $ variables ; } | Protected extract setting variables |
1,526 | public function actionIndex ( ) { list ( $ theme , $ file ) = func_get_args ( ) ; if ( false !== strpos ( $ file , '..' ) ) { throw new Forbidden ; } $ file = realpath ( DOCROOT . '../themes/' . $ theme . '/assets/' . $ file ) ; if ( ! file_exists ( $ file ) ) { throw new NotFound ; } if ( ! is_readable ( $ file ) ) { throw new Forbidden ; } $ mime = Mimetypes :: fromFilename ( $ file ) ; $ content = file_get_contents ( $ file ) ; return \ Response :: forge ( 'content' , $ content , $ mime ) ; } | Catches all calls and handles theme asset requests |
1,527 | protected static function load ( ) { need ( root ( ) . 'app/http/Filter.php' ) ; $ filter = instance ( \ App \ Http \ Filter :: class ) ; self :: $ filters [ 'app' ] = $ filter :: $ middleware ; self :: $ filters [ 'route' ] = $ filter :: $ routeMiddleware ; return self :: $ filters ; } | Set the list of filters used by middleware . |
1,528 | public static function get ( $ name ) { if ( array_has ( self :: $ filters , 'app.' . $ name ) ) { return [ 'app' , array_get ( self :: $ filters , 'app.' . $ name ) ] ; } elseif ( array_has ( self :: $ filters , 'route.' . $ name ) ) { return [ 'route' , array_get ( self :: $ filters , 'route.' . $ name ) ] ; } exception ( MiddlewareNotFoundException :: class , $ name ) ; } | Get the Middleware by filter . |
1,529 | public function update ( $ table , $ data , $ filter = [ ] ) { $ fields_allowed = $ this -> getTableColumns ( $ table ) ; $ fields = $ this -> filterKeys ( $ fields_allowed , $ data ) ; if ( count ( $ fields ) === 0 ) { throw new PDOException ( 'empty request' ) ; } $ escapedFields = $ this -> quoteIdentifiers ( $ fields ) ; $ statement = $ this -> implodeBindFields ( $ escapedFields , ',' , 'u_' ) ; $ sets = ' SET ' . $ statement ; $ whereFields = $ this -> filterKeys ( $ fields_allowed , $ filter ) ; $ escapedWhereFields = $ this -> quoteIdentifiers ( $ whereFields ) ; $ statement = $ this -> implodeBindFields ( $ escapedWhereFields , ' AND ' , 'w_' ) ; $ whereStatement = $ statement !== false ? ' WHERE ' . $ statement : '' ; $ sql = 'UPDATE ' . self :: quoteIdentifiers ( $ table ) . $ sets . $ whereStatement ; $ bind = $ this -> bindValues ( $ fields , $ data , array ( ) , 'u_' ) ; $ bind = $ this -> bindValues ( $ whereFields , $ filter , $ bind , 'w_' ) ; return $ this -> run ( $ sql , $ bind ) ; } | Update one or more rows in the database table |
1,530 | public function delete ( $ table , $ filter = [ ] ) { $ whereFields = $ this -> filterKeysForTable ( $ table , $ filter ) ; $ escapedWhereFields = $ this -> quoteIdentifiers ( $ whereFields ) ; $ statement = $ this -> implodeBindFields ( $ escapedWhereFields , ' AND ' ) ; $ whereStatement = $ statement !== false ? ' WHERE ' . $ statement : '' ; $ sql = 'DELETE FROM ' . self :: quoteIdentifiers ( $ table ) . $ whereStatement ; $ bind = $ this -> bindValues ( $ whereFields , $ filter ) ; return $ this -> run ( $ sql , $ bind ) ; } | Delete rows on a database table |
1,531 | public function quoteIdentifiers ( $ names ) { if ( is_array ( $ names ) ) { foreach ( $ names as $ key => $ value ) { $ var = $ this -> quoteIdentifiers ( $ value ) ; $ names [ $ key ] = $ var ; } return $ names ; } $ result = $ this -> quote . preg_replace ( '#\\\*' . $ this -> quote . '#' , $ this -> quote . $ this -> quote , $ names ) . $ this -> quote ; $ result = preg_replace ( '#\.#' , $ this -> quote . '.' . $ this -> quote , $ result ) ; return $ result ; } | Quote one or an array of identifiers with backticks |
1,532 | public function filterKeys ( $ fields_allowed , $ params ) { if ( ! is_array ( $ params ) ) { return [ ] ; } $ params = array_keys ( $ params ) ; return $ this -> filter ( $ fields_allowed , $ params ) ; } | filter the keys of an associative array as column names for a specific table |
1,533 | public function implodeBindFields ( $ escapedFields , $ glue , $ keyPrefix = '' ) { if ( count ( $ escapedFields ) == 0 ) { return false ; } $ statement = '' ; $ first = true ; foreach ( $ escapedFields as $ key => $ value ) { if ( $ first ) { $ first = false ; } else { $ statement .= $ glue ; } $ statement .= $ value . ' = :' . $ keyPrefix . $ key ; } return $ statement ; } | insert bind placeholders for a sql statement |
1,534 | public function getTableColumns ( $ table ) { $ driver = $ this -> getDriverName ( ) ; $ bind = [ ] ; if ( $ driver == 'sqlite' ) { $ table = $ this -> quoteIdentifiers ( $ table ) ; $ sql = 'PRAGMA table_info(' . $ table . ');' ; $ key = 'name' ; } elseif ( $ driver == 'mysql' ) { $ table = $ this -> quoteIdentifiers ( $ table ) ; $ sql = 'DESCRIBE ' . $ table . ';' ; $ key = 'Field' ; } else { $ bind [ ] = $ table ; $ sql = 'SELECT column_name FROM information_schema.columns WHERE ' ; if ( $ driver == 'pgsql' ) { $ bind = explode ( '.' , $ table , 2 ) ; if ( count ( $ bind ) == 2 ) { $ sql .= 'table_schema = ? AND ' ; } } $ sql .= 'table_name = ? ;' ; $ key = 'column_name' ; } $ fields = [ ] ; if ( is_array ( $ list = $ this -> run ( $ sql , $ bind , false ) ) ) { foreach ( $ list as $ record ) { $ fields [ ] = $ record [ $ key ] ; } return $ fields ; } return $ fields ; } | Query the available columns for a database table |
1,535 | public function generateInsertPlaceholder ( $ fieldCount , $ rowCount ) { $ insertPlaceholder = '(' . implode ( ',' , array_fill ( 0 , $ fieldCount , '?' ) ) . ')' ; $ insertPlaceholder = implode ( ',' , array_fill ( 0 , $ rowCount , $ insertPlaceholder ) ) ; return $ insertPlaceholder ; } | generate insert placeholder for parameter binding based on field and row count |
1,536 | public function cache_init ( $ file_path ) { $ cache_key = md5 ( $ file_path ) ; $ cache_path = \ Config :: get ( 'parser.View_Jade.cache_dir' , null ) . substr ( $ cache_key , 0 , 2 ) . DS . substr ( $ cache_key , 2 , 2 ) ; if ( $ cache_path !== null AND ! is_dir ( $ cache_path ) ) { mkdir ( $ cache_path , 0777 , true ) ; } static :: $ _cache = $ cache_path ; } | compiled template . |
1,537 | public static function fromString ( $ string ) { \ Assert \ that ( $ string ) -> string ( 'Argument has to be a string' ) -> uuid ( 'String has to be an UUID' ) ; return new static ( Uuid :: fromString ( $ string ) ) ; } | Creates an identifier object from a string . |
1,538 | public function add ( $ title , string $ url = '' , array $ children = [ ] , array $ fields = [ ] ) : Builder { $ this -> menu [ ] = $ this -> parseMenuItems ( $ title , $ url , $ children , $ fields ) ; return $ this ; } | Add new menu item . |
1,539 | public function addChild ( string $ title , string $ url = '' , array $ children = [ ] , array $ fields = [ ] ) : Builder { $ index = count ( $ this -> menu ) - 1 ; if ( $ index < 0 ) { return $ this ; } $ this -> menu [ $ index ] -> appendChild ( $ this -> parseMenuItems ( $ title , $ url , $ children , $ fields ) ) ; return $ this ; } | Add child element to the root menu item . |
1,540 | public function cached ( $ lifetime = null , $ cache_key = null , $ cache_all = true ) { $ this -> _lifetime = $ lifetime ; $ this -> _cache_all = ( bool ) $ cache_all ; is_string ( $ cache_key ) and $ this -> _cache_key = $ cache_key ; return $ this ; } | Enables the query to be cached for a specified amount of time . |
1,541 | public function set_connection ( $ db ) { if ( ! $ db instanceof \ Database_Connection ) { $ db = \ Database_Connection :: instance ( $ db ) ; } $ this -> _connection = $ db ; return $ this ; } | Set a DB connection to use when compiling the SQL |
1,542 | public function compile ( $ db = null ) { if ( ! $ db instanceof \ Database_Connection ) { $ db = $ this -> _connection ? : \ Database_Connection :: instance ( $ db ) ; } $ sql = $ this -> _sql ; if ( ! empty ( $ this -> _parameters ) ) { $ values = array_map ( array ( $ db , 'quote' ) , $ this -> _parameters ) ; $ sql = \ Str :: tr ( $ sql , $ values ) ; } return trim ( $ sql ) ; } | Compile the SQL query and return it . Replaces any parameters with their given values . |
1,543 | public function execute ( $ db = null ) { if ( ! is_object ( $ db ) ) { $ db = \ Database_Connection :: instance ( $ db , null , ! $ this instanceof \ Database_Query_Builder_Select ) ; } $ sql = $ this -> compile ( $ db ) ; switch ( strtoupper ( substr ( ltrim ( $ sql , '(' ) , 0 , 6 ) ) ) { case 'SELECT' : $ this -> _type = \ DB :: SELECT ; break ; case 'INSERT' : case 'CREATE' : $ this -> _type = \ DB :: INSERT ; break ; } if ( $ db -> caching ( ) and ! empty ( $ this -> _lifetime ) and $ this -> _type === DB :: SELECT ) { $ cache_key = empty ( $ this -> _cache_key ) ? 'db.' . md5 ( 'Database_Connection::query("' . $ db . '", "' . $ sql . '")' ) : $ this -> _cache_key ; $ cache = \ Cache :: forge ( $ cache_key ) ; try { $ result = $ cache -> get ( ) ; return new Database_Result_Cached ( $ result , $ sql , $ this -> _as_object ) ; } catch ( CacheNotFoundException $ e ) { } } \ DB :: $ query_count ++ ; $ result = $ db -> query ( $ this -> _type , $ sql , $ this -> _as_object ) ; if ( isset ( $ cache ) and ( $ this -> _cache_all or $ result -> count ( ) ) ) { $ cache -> set_expiration ( $ this -> _lifetime ) -> set_contents ( $ result -> as_array ( ) ) -> set ( ) ; } return $ result ; } | Execute the current query on the given database . |
1,544 | public static function Ppsp ( array $ a , $ s , array $ b , array & $ apsb ) { $ sb = [ ] ; IAU :: Sxp ( $ s , $ b , $ sb ) ; IAU :: Ppp ( $ a , $ sb , $ apsb ) ; return ; } | - - - - - - - - i a u P p s p - - - - - - - - |
1,545 | public static function create ( ContainerInterface $ container = null , array $ configs = [ ] ) { if ( null === $ container ) { $ container = Factory :: create ( ) ; } return new Cache ( $ container , new SerializerManager ( ) , new CompressorManager ( ) , $ configs ) ; } | create a new cache instance |
1,546 | public function getQueryParams ( ) { if ( is_array ( $ this -> query ) ) { return $ this -> query ; } if ( $ this -> uri === null ) { return [ ] ; } parse_str ( $ this -> uri -> getQuery ( ) , $ this -> query ) ; return $ this -> query ; } | Retrieve query string arguments |
1,547 | public function getParsedBody ( ) { if ( $ this -> parsedBody || ! $ this -> body ) { return $ this -> parsedBody ; } $ type = $ this -> headers -> getContentType ( ) ; $ body = ( string ) $ this -> getBody ( ) ; switch ( $ type ) { case 'application/json' : $ this -> parsedBody = json_decode ( $ body , true ) ; break ; case 'application/x-www-form-urlencoded' : parse_str ( $ body , $ data ) ; $ this -> parsedBody = $ data ; break ; case 'text/xml' : $ disabled = libxml_disable_entity_loader ( true ) ; $ xml = simplexml_load_string ( $ body ) ; libxml_disable_entity_loader ( $ disabled ) ; $ this -> parsedBody = $ xml ; break ; default : break ; } return $ this -> parsedBody ; } | Retrieve any parameters provided in the request body |
1,548 | protected function addItem ( string $ key , array $ values ) : void { if ( ! array_key_exists ( 'source' , $ values ) || ! array_key_exists ( 'target' , $ values ) ) { throw new \ InvalidArgumentException ( 'Invalid translation array: ' . var_export ( $ values , true ) ) ; } $ this -> translationBuffer [ $ key ] = new MemoryTranslationValue ( $ key , $ values [ 'source' ] , $ values [ 'target' ] ) ; } | Add an element with the passed values . |
1,549 | public function writeFile ( ) { if ( ! empty ( $ this -> fileName ) ) { if ( ! file_exists ( $ this -> destinationPath ) ) { mkdir ( $ this -> destinationPath , 0777 ) ; } $ file = $ this -> file ( ) ; $ fileHandle = fopen ( $ file , 'w+' ) ; fwrite ( $ fileHandle , $ this -> body ) ; fclose ( $ fileHandle ) ; return $ file ; } else { return FALSE ; } } | Write the downloaded file |
1,550 | public function getAvailableTimezones ( ) { $ timezoneNames = DateTimeZone :: listIdentifiers ( DateTimeZone :: ALL ) ; $ timezones = array_map ( function ( $ timezoneName ) { $ timezone = new DateTimeZone ( $ timezoneName ) ; $ offset = $ timezone -> getOffset ( new DateTime ( "now" , $ timezone ) ) / 3600 ; if ( $ offset > 0 ) { $ offset = '+' . $ offset ; } return [ 'name' => $ timezoneName , 'offset' => $ offset ] ; } , $ timezoneNames ) ; usort ( $ timezones , function ( $ t1 , $ t2 ) { if ( $ t1 [ 'offset' ] < $ t2 [ 'offset' ] ) { return - 1 ; } elseif ( $ t1 [ 'offset' ] > $ t2 [ 'offset' ] ) { return 1 ; } else { return strcmp ( $ t1 [ 'name' ] , $ t2 [ 'name' ] ) ; } } ) ; return $ timezones ; } | Gets all timezones in the world |
1,551 | public static function normalize ( array $ context ) { $ diff = array_diff_key ( $ context , self :: $ defaults ) ; if ( ! empty ( $ diff ) ) { $ errorMessage = 'unknown index ' . implode ( ', ' , array_keys ( $ diff ) ) ; throw new InvalidContext ( $ errorMessage ) ; } if ( ! empty ( $ context [ 'namespace' ] ) ) { if ( preg_match ( '/^\\\\?(.*?)\\\\?$/s' , $ context [ 'namespace' ] , $ ns ) ) { $ context [ 'namespace' ] = $ ns [ 1 ] ? $ ns [ 1 ] . '\\' : null ; } } else { $ context [ 'namespace' ] = null ; } return array_replace ( self :: $ defaults , $ context ) ; } | Normalizes the context format |
1,552 | protected function connect ( ) { $ db = Config :: config ( ) [ 'user' ] [ 'database' ] ; if ( $ db [ 'enabled' ] ) { switch ( $ db [ 'driver' ] ) { case 'pdo' : $ options = [ Pdo :: ATTR_STATEMENT_CLASS => [ '\Gcs\Framework\Core\Pdo\PdoStatement' , [ ] ] ] ; switch ( $ db [ 'type' ] ) { case 'mysql' : try { $ this -> db = new Pdo ( 'mysql:host=' . $ db [ 'hostname' ] . ';dbname=' . $ db [ 'database' ] , $ db [ 'username' ] , $ db [ 'password' ] , $ options ) ; $ this -> db -> exec ( 'SET NAMES ' . strtoupper ( $ db [ 'charset' ] ) ) ; } catch ( \ PDOException $ e ) { throw new MissingDatabaseException ( $ e -> getMessage ( ) . ' / ' . $ e -> getCode ( ) . ' / ' . $ e -> getFile ( ) ) ; } break ; case 'pgsql' : try { $ this -> db = new Pdo ( 'mysql:host=' . $ db [ 'hostname' ] . ';dbname=' . $ db [ 'database' ] , $ db [ 'username' ] , $ db [ 'password' ] , $ options ) ; $ this -> db -> exec ( 'SET NAMES ' . strtoupper ( $ db [ 'charset' ] ) ) ; } catch ( \ PDOException $ e ) { throw new MissingDatabaseException ( $ e -> getMessage ( ) . ' / ' . $ e -> getCode ( ) ) ; } break ; default : throw new MissingDatabaseException ( "Can't connect to SQL Database because the driver is not supported" ) ; break ; } break ; default : throw new MissingDatabaseException ( "Can't connect to SQL Database because the API is unrecognized" ) ; break ; } return $ this -> db ; } else { return null ; } } | create the database connection |
1,553 | public static function generate ( string $ text = '' , ? int $ maxLength = null ) : string { $ text = StripTags :: strip ( $ text ) ; $ text = \ strtolower ( \ iconv ( 'UTF-8' , 'ASCII//TRANSLIT' , $ text ) ) ; $ text = \ preg_replace ( '/[^a-z0-9\-\ ]/' , '' , $ text ) ; $ text = \ preg_replace ( '/[\s\-]+/' , '-' , $ text ) ; if ( \ is_int ( $ maxLength ) ) { $ text = \ substr ( $ text , 0 , $ maxLength ) ; } $ text = \ rtrim ( $ text , '-' ) ; return '/' . $ text ; } | Generates web url |
1,554 | public function add_type ( $ type , $ path = null ) { isset ( $ this -> _asset_paths [ $ type ] ) or $ this -> _asset_paths [ $ type ] = array ( ) ; isset ( $ this -> _path_folders [ $ type ] ) or $ this -> _path_folders [ $ type ] = $ type . '/' ; if ( ! is_null ( $ path ) ) { $ path = $ this -> _unify_path ( $ path ) ; $ this -> _asset_paths [ $ type ] [ ] = $ path ; } return $ this ; } | Adds a new asset type to the list so we can load files of this type |
1,555 | public function add_path ( $ path , $ type = null ) { is_null ( $ type ) and $ type = $ this -> _path_folders ; empty ( $ path ) and $ path = DOCROOT ; if ( is_array ( $ type ) ) { foreach ( $ type as $ key => $ folder ) { is_numeric ( $ key ) and $ key = $ folder ; $ folder = $ this -> _unify_path ( $ path ) . ltrim ( $ this -> _unify_path ( $ folder ) , DS ) ; array_unshift ( $ this -> _asset_paths [ $ key ] , $ folder ) ; } } else { if ( ! isset ( $ this -> _asset_paths [ $ type ] ) ) { $ this -> _asset_paths [ $ type ] = array ( ) ; $ this -> _path_folders [ $ type ] = $ type . '/' ; } $ path = $ this -> _unify_path ( $ path ) ; array_unshift ( $ this -> _asset_paths [ $ type ] , $ path ) ; } return $ this ; } | Adds the given path to the front of the asset paths array . It adds paths in a way so that asset paths are used First in Last Out . |
1,556 | public function remove_path ( $ path , $ type = null ) { is_null ( $ type ) and $ type = $ this -> _path_folders ; if ( is_array ( $ type ) ) { foreach ( $ type as $ key => $ folder ) { is_numeric ( $ key ) and $ key = $ folder ; $ folder = $ this -> _unify_path ( $ path ) . ltrim ( $ this -> _unify_path ( $ folder ) , DS ) ; if ( ( $ found = array_search ( $ folder , $ this -> _asset_paths [ $ key ] ) ) !== false ) { unset ( $ this -> _asset_paths [ $ key ] [ $ found ] ) ; } } } else { $ path = $ this -> _unify_path ( $ path ) ; if ( ( $ key = array_search ( $ path , $ this -> _asset_paths [ $ type ] ) ) !== false ) { unset ( $ this -> _asset_paths [ $ type ] [ $ key ] ) ; } } return $ this ; } | Removes the given path from the asset paths array |
1,557 | protected function _unify_path ( $ path , $ ds = null , $ trailing = true ) { $ ds === null and $ ds = DS ; return rtrim ( str_replace ( array ( '\\' , '/' ) , $ ds , $ path ) , $ ds ) . ( $ trailing ? $ ds : '' ) ; } | Unify the path |
1,558 | protected function initialiseCommands ( ) { $ modules = $ this -> kernel -> getModules ( ) ; foreach ( $ modules as $ module ) { if ( ! $ module instanceof ConsoleModuleInterface ) { continue ; } $ module -> registerCommands ( $ this ) ; } } | Initialise commands from modules . |
1,559 | public function isTokenUnique ( $ token ) { $ record = List_Unsubscribe_Token :: where ( 'token' , $ token ) -> first ( ) ; if ( ! $ record ) { return true ; } return false ; } | Is a given token unique in the list_unsubscribe_token database table? |
1,560 | public function createTokenRecord ( $ emailID , $ listID , $ token ) { $ unsubscribe = new List_Unsubscribe_Token ; $ unsubscribe -> email_id = $ emailID ; $ unsubscribe -> list_id = $ listID ; $ unsubscribe -> token = $ token ; $ unsubscribe -> save ( ) ; } | INSERT a token record . |
1,561 | public function isTokenValid ( $ token ) { $ record = List_Unsubscribe_Token :: where ( 'token' , $ token ) -> first ( ) ; if ( ! $ record ) { return false ; } return true ; } | Does a given token exist in the database? |
1,562 | public function get ( $ alias ) { if ( false === $ this -> has ( $ alias ) ) { throw new DataSetContextNotFoundException ( $ alias ) ; } return $ this -> items [ $ alias ] ; } | Returns a dataset s context by its alias |
1,563 | public function getVisibleAttributes ( ) { $ result = $ this -> getAttributes ( ) ; $ hidden = $ this -> getHidden ( ) ; foreach ( $ hidden as $ forHide ) { unset ( $ result [ $ forHide ] ) ; } return $ result ; } | Get visible attributes |
1,564 | protected function _cleanName ( $ name ) { assert ( 'strpos($name, \':\') === false' ) ; if ( strpos ( $ name , ':' ) !== false ) { list ( $ name , ) = explode ( ':' , $ name ) ; } $ name = trim ( $ name ) ; if ( $ name == '' ) { throw new CacheException ( 'Cache-entry name cannot be empty' ) ; } return strtolower ( $ name ) ; } | Clean a name for use within the CacheStore . |
1,565 | public function set ( $ name , $ value , $ ttl = 0 ) { $ name = $ this -> _cleanName ( $ name ) ; if ( $ ttl == 0 && $ this -> _ttl !== null ) { $ ttl = $ this -> _ttl ; } return $ this -> _Cache -> set ( "{$this->_store}:$name" , $ value , $ ttl ) ; } | Add an entry to the CacheStore . |
1,566 | public function get ( $ name , & $ error = false ) { try { $ name = $ this -> _cleanName ( $ name ) ; } catch ( CacheException $ e ) { $ error = true ; return null ; } return $ this -> _Cache -> get ( "{$this->_store}:$name" , $ error ) ; } | Get an entry from the CacheStore . |
1,567 | public function delete ( $ name ) { try { $ name = $ this -> _cleanName ( $ name ) ; } catch ( CacheException $ e ) { return false ; } return $ this -> _Cache -> delete ( "{$this->_store}:$name" ) ; } | Delete an entry from the CacheStore . |
1,568 | public function errorMessages ( ) { $ messages = array ( ) ; foreach ( $ this -> errors as $ field => $ errors ) { $ messages [ $ field ] = array ( ) ; foreach ( $ errors as $ validation => $ error ) { $ vars = array_merge ( array ( 'field' => Language :: translate ( $ field ) ) , $ error ) ; unset ( $ vars [ 'message' ] ) ; $ messages [ $ field ] [ ] = Language :: translate ( $ error [ 'message' ] , $ vars ) ; } } return $ messages ; } | Returns the models errors with proper messages . |
1,569 | public function addError ( $ field , $ validation , $ data ) { if ( ! isset ( $ this -> errors [ $ field ] ) ) { $ this -> errors [ $ field ] = array ( ) ; } $ this -> errors [ $ field ] [ $ validation ] = $ data ; } | Adds an error for the specified field . |
1,570 | public function Connection ( ) { $ this -> _IsPersistent = GetValue ( PDO :: ATTR_PERSISTENT , $ this -> ConnectionOptions , FALSE ) ; if ( ! is_object ( $ this -> _Connection ) ) { try { $ this -> _Connection = new PDO ( strtolower ( $ this -> Engine ) . ':' . $ this -> Dsn , $ this -> User , $ this -> Password , $ this -> ConnectionOptions ) ; $ this -> _Connection -> setAttribute ( PDO :: ATTR_EMULATE_PREPARES , 0 ) ; if ( $ this -> ConnectionOptions [ 1002 ] ) $ this -> Query ( $ this -> ConnectionOptions [ 1002 ] ) ; $ this -> _Connection -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_SILENT ) ; } catch ( Exception $ ex ) { $ Timeout = FALSE ; if ( $ ex -> getCode ( ) == '2002' && preg_match ( '/Operation timed out/i' , $ ex -> getMessage ( ) ) ) $ Timeout = TRUE ; if ( $ ex -> getCode ( ) == '2003' && preg_match ( "/Can't connect to MySQL/i" , $ ex -> getMessage ( ) ) ) $ Timeout = TRUE ; if ( $ Timeout ) throw new Exception ( ErrorMessage ( 'Timeout while connecting to the database' , $ this -> ClassName , 'Connection' , $ ex -> getMessage ( ) ) , 504 ) ; trigger_error ( ErrorMessage ( 'An error occurred while attempting to connect to the database' , $ this -> ClassName , 'Connection' , $ ex -> getMessage ( ) ) , E_USER_ERROR ) ; } } return $ this -> _Connection ; } | Get the PDO connection to the database . |
1,571 | public function QuoteExpression ( $ Expr ) { if ( is_null ( $ Expr ) ) { return 'NULL' ; } elseif ( is_string ( $ Expr ) ) { return '\'' . str_replace ( '\'' , '\\\'' , $ Expr ) . '\'' ; } elseif ( is_object ( $ Expr ) ) { return '?OBJECT?' ; } else { return $ Expr ; } } | Properly quotes and escapes a expression for an sql string . |
1,572 | public function Init ( $ Config = NULL ) { if ( is_null ( $ Config ) ) $ Config = Gdn :: Config ( 'Database' ) ; elseif ( is_string ( $ Config ) ) $ Config = Gdn :: Config ( $ Config ) ; $ DefaultConfig = Gdn :: Config ( 'Database' ) ; if ( is_null ( $ Config ) ) $ Config = array ( ) ; if ( is_null ( $ DefaultConfig ) ) $ DefaultConfig = array ( ) ; $ this -> Engine = ArrayValue ( 'Engine' , $ Config , $ DefaultConfig [ 'Engine' ] ) ; $ this -> User = ArrayValue ( 'User' , $ Config , $ DefaultConfig [ 'User' ] ) ; $ this -> Password = ArrayValue ( 'Password' , $ Config , $ DefaultConfig [ 'Password' ] ) ; $ this -> ConnectionOptions = ArrayValue ( 'ConnectionOptions' , $ Config , $ DefaultConfig [ 'ConnectionOptions' ] ) ; $ this -> DatabasePrefix = ArrayValue ( 'DatabasePrefix' , $ Config , ArrayValue ( 'Prefix' , $ Config , $ DefaultConfig [ 'DatabasePrefix' ] ) ) ; $ this -> ExtendedProperties = ArrayValue ( 'ExtendedProperties' , $ Config , array ( ) ) ; if ( array_key_exists ( 'Dsn' , $ Config ) ) { $ Dsn = $ Config [ 'Dsn' ] ; } else { $ Host = ArrayValue ( 'Host' , $ Config , ArrayValue ( 'Host' , $ DefaultConfig , '' ) ) ; if ( array_key_exists ( 'Dbname' , $ Config ) ) $ Dbname = $ Config [ 'Dbname' ] ; elseif ( array_key_exists ( 'Name' , $ Config ) ) $ Dbname = $ Config [ 'Name' ] ; elseif ( array_key_exists ( 'Dbname' , $ DefaultConfig ) ) $ Dbname = $ DefaultConfig [ 'Dbname' ] ; elseif ( array_key_exists ( 'Name' , $ DefaultConfig ) ) $ Dbname = $ DefaultConfig [ 'Name' ] ; $ Port = ArrayValue ( 'Port' , $ Config , ArrayValue ( 'Port' , $ DefaultConfig , '' ) ) ; if ( ! isset ( $ Dbname ) ) { $ Dsn = $ DefaultConfig [ 'Dsn' ] ; } else { if ( empty ( $ Port ) ) { $ Host = explode ( ':' , $ Host ) ; $ Port = count ( $ Host ) == 2 ? $ Host [ 1 ] : '' ; $ Host = $ Host [ 0 ] ; } if ( empty ( $ Port ) ) { $ Dsn = sprintf ( 'host=%s;dbname=%s;' , $ Host , $ Dbname ) ; } else { $ Dsn = sprintf ( 'host=%s;port=%s;dbname=%s;' , $ Host , $ Port , $ Dbname ) ; } } } $ this -> Dsn = $ Dsn ; } | Initialize the properties of this object . |
1,573 | public function SQL ( ) { if ( is_null ( $ this -> _SQL ) ) { $ Name = $ this -> Engine . 'Driver' ; $ this -> _SQL = Gdn :: Factory ( $ Name ) ; $ this -> _SQL -> Database = $ this ; } return $ this -> _SQL ; } | Get the database driver class for the database . |
1,574 | public function Structure ( ) { if ( is_null ( $ this -> _Structure ) ) { $ Name = $ this -> Engine . 'Structure' ; $ this -> _Structure = Gdn :: Factory ( $ Name ) ; $ this -> _Structure -> Database = $ this ; } return $ this -> _Structure ; } | Get the database structure class for this database . |
1,575 | protected function _setSpec ( $ spec ) { if ( ! is_null ( $ spec ) ) { $ spec = $ this -> _normalizeIterable ( $ spec ) ; } $ this -> spec = $ spec ; } | Assigns a spec to this instance . |
1,576 | public static function dump ( $ var , $ format = null ) { if ( ! static :: isDebug ( ) ) return ; $ dumpers = [ static :: DUMP_HTML => '\\yolk\\debug\\HTMLDumper' , static :: DUMP_TERMINAL => '\\yolk\\debug\\TerminalDumper' , static :: DUMP_TEXT => '\\yolk\\debug\\TextDumper' , ] ; if ( ! isset ( $ dumpers [ $ format ] ) ) $ format = static :: isCLI ( ) ? static :: DUMP_TERMINAL : static :: DUMP_HTML ; $ dumpers [ $ format ] :: dump ( $ var ) ; } | Pretty - print a variable - if running in debug mode . |
1,577 | public static function addHelperMethod ( $ class , $ method ) { $ k = strtolower ( $ method ) ; if ( method_exists ( __CLASS__ , $ method ) ) throw new \ Exception ( sprintf ( "Helper methods cannot override pre-defined Yolk methods - '%s' is reserved" , $ method ) ) ; elseif ( isset ( static :: $ helpers [ $ k ] ) && static :: $ helpers [ $ k ] [ 0 ] != $ class ) throw new \ Exception ( sprintf ( "Helper method '%s' already defined in class '%s', duplicate in '%s'" , $ method , static :: $ helpers [ $ k ] [ 0 ] , $ class ) ) ; static :: $ helpers [ $ k ] = [ $ class , $ method ] ; } | Register a single static method as a helper . |
1,578 | public static function run ( Callable $ callable ) { try { register_shutdown_function ( [ '\\yolk\\exceptions\\Handler' , 'checkFatal' ] ) ; $ error_handler = set_error_handler ( static :: $ error_handler ) ; $ args = func_get_args ( ) ; array_shift ( $ args ) ; $ result = call_user_func_array ( $ callable , $ args ) ; set_error_handler ( $ error_handler ? : function ( ) { return false ; } ) ; return $ result ; } catch ( \ Exception $ e ) { static :: exception ( $ e ) ; } } | Executes the specified closure wrapping it in Yolk s error and exception handling . |
1,579 | public function method ( $ callable , bool $ testMethod = null ) : string { if ( is_string ( $ callable ) && false !== strstr ( $ callable , '::' ) ) { $ callable = explode ( '::' , $ callable ) ; } if ( ! is_array ( $ callable ) || empty ( $ callable [ 0 ] ) || empty ( $ callable [ 1 ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Provided callable is not a valid callable' ) ) ; } try { $ reflection = new ReflectionMethod ( $ callable [ 0 ] , $ callable [ 1 ] ) ; return $ reflection -> name ; } catch ( ReflectionException $ e ) { if ( ( null === $ testMethod && $ this -> allowNonExistingMethods ) || false === $ testMethod ) { return $ callable [ 1 ] ; } throw $ e ; } } | Method name helper . |
1,580 | public function onRegister ( ) { $ application = $ this -> application ; \ Route :: add ( "/" , "home" , function ( $ response , $ params = null ) use ( $ application ) { return $ response -> addContent ( "<pre>Welcome to Budkit.\nTo change this page add a new basepath route like so \n\n Route::add('/', function(\$route){\n ...\n });</pre>" ) ; } ) ; } | The package app . register event callback |
1,581 | public function add ( $ typeName , $ args ) { $ args = array_merge_recursive ( array ( 'public' => true , 'supports' => array ( 'title' , 'editor' , 'thumbnail' , 'revisions' , ) , 'has_archive' => true , ) , $ args ) ; $ this -> posttypes [ $ typeName ] = $ args ; return true ; } | Add new posttype |
1,582 | public static function getActivePersonSetingValue ( $ type ) { $ personId = Yii :: app ( ) -> getModule ( 'user' ) -> user ( ) -> profile -> person_id ; $ criteria = [ 'ppxs_pprs_id' => $ personId , 'ppxs_psty_id' => $ type ] ; $ model = PpxsPersonXSetting :: model ( ) -> findByAttributes ( $ criteria ) ; if ( ! $ model ) { return false ; } return $ model -> ppxs_value ; } | atgrie pirmo aktivas personas prasito settingu |
1,583 | public function match ( string $ message ) : bool { if ( $ this -> regexp ) { return ( bool ) preg_match ( $ this -> message , $ message ) ; } return mb_strtolower ( $ this -> message ) === mb_strtolower ( $ message ) ; } | Is message matches? |
1,584 | public function bundleCommand ( string $ packageKey , string $ serverScript = null , string $ clientScript = null ) { $ start = microtime ( true ) ; $ filePathResolver = new FilePathResolver ( ) ; $ package = $ this -> packageManager -> getPackage ( $ packageKey ) ; if ( $ serverScript !== null ) { $ serverScript = $ filePathResolver -> resolveFilePath ( $ serverScript ) ; } else { $ serverScript = str_replace ( '@packageResourcesPath' , rtrim ( $ package -> getResourcesPath ( ) , '/' ) , $ this -> reactServerFilePattern ) ; } if ( $ clientScript !== null ) { $ clientScript = $ filePathResolver -> resolveFilePath ( $ clientScript ) ; } else { $ clientScript = str_replace ( '@packageResourcesPath' , rtrim ( $ package -> getResourcesPath ( ) , '/' ) , $ this -> reactClientFilePattern ) ; } $ identifier = md5 ( $ serverScript ) ; $ request = new ActionRequest ( Request :: createFromEnvironment ( ) ) ; $ uriBuilder = new UriBuilder ( ) ; $ uriBuilder -> setRequest ( $ request ) ; $ controllerContext = new ControllerContext ( $ request , new Response ( ) , new Arguments ( ) , $ uriBuilder ) ; $ unit = new Unit ( $ controllerContext ) ; $ unit -> work ( function ( App $ app ) use ( $ clientScript , $ serverScript , $ identifier ) { $ this -> outputLine ( ) ; $ this -> output ( 'Transpiling... ' ) ; $ transpiler = new Transpiler ( $ app ) ; $ transpiler -> transpile ( $ identifier , $ serverScript , $ clientScript ) -> done ( function ( ) use ( $ app ) { $ this -> outputLine ( '<success>done</success>' ) ; $ app -> end ( ) ; } ) ; } ) ; $ bundler = new Bundler ( $ controllerContext ) ; $ this -> output ( 'Bundling module... ' ) ; $ bundler -> bundle ( $ identifier ) ; $ this -> outputLine ( '<success>done</success>' ) ; $ this -> outputLine ( ) ; $ elapsed = round ( microtime ( true ) - $ start , 2 ) ; $ this -> outputLine ( 'Bundled <success>%s</success> in <success>%s seconds</success>.' , [ $ package -> getPackageKey ( ) , $ elapsed ] ) ; $ this -> outputLine ( ) ; } | Prepares a react bundle for a specific package |
1,585 | public function stopProcessesCommand ( bool $ force = false ) { $ count = $ this -> processManager -> killAllProcesses ( $ force ) ; $ this -> outputLine ( ) ; if ( $ force === true ) { $ this -> outputFormatted ( '<comment>force stopped %s</comment>' , [ $ count === 1 ? '1 process' : $ count . ' processes' ] ) ; } else { $ this -> outputFormatted ( '<success>stopped %s</success>' , [ $ count === 1 ? '1 process' : $ count . ' processes' ] ) ; } $ this -> outputLine ( ) ; $ this -> outputFormatted ( 'The processes will automatically restart during the next request' ) ; $ this -> outputLine ( ) ; } | Stops all background processes |
1,586 | private static function getReflectionProperties ( $ object ) { $ class = get_class ( $ object ) ; if ( ! isset ( self :: $ reflectionProperties [ $ class ] ) ) { $ reflection = new \ ReflectionClass ( $ object ) ; $ reflectionProperties = array_filter ( $ reflection -> getProperties ( ) , function ( $ property ) { return ! $ property -> isStatic ( ) ; } ) ; self :: $ reflectionProperties [ $ class ] = [ ] ; foreach ( $ reflectionProperties as $ property ) { $ property -> setAccessible ( true ) ; self :: $ reflectionProperties [ $ class ] [ $ property -> getName ( ) ] = $ property ; } } return self :: $ reflectionProperties [ $ class ] ; } | Returns reflection properties from in - memory cache or load them |
1,587 | public function getRandom ( ) { $ em = $ this -> getEntityManager ( ) ; $ repository = $ em -> getRepository ( 'HarvestCloudCoreBundle:Location' ) ; $ query = $ em -> createQuery ( 'SELECT COUNT(l.id) FROM HarvestCloud\CoreBundle\Entity\Location l' ) ; $ count = $ query -> getSingleScalarResult ( ) ; return $ this -> find ( rand ( 1 , $ count - 1 ) ) ; } | Get a random Location from the Repository |
1,588 | private function InitForm ( ) { $ this -> AddCategoryField ( ) ; $ this -> AddTitleField ( ) ; $ this -> AddTeaserField ( ) ; $ this -> AddTextField ( ) ; $ this -> AddPublishField ( ) ; $ this -> AddPublishFromDateField ( ) ; $ this -> AddPublishFromHourField ( ) ; $ this -> AddPublishFromMinuteField ( ) ; $ this -> AddPublishToDateField ( ) ; $ this -> AddPublishToHourField ( ) ; $ this -> AddPublishToMinuteField ( ) ; $ this -> AddAuthorField ( ) ; $ this -> AddSubmit ( ) ; } | Adds all form fields |
1,589 | private function InitMembers ( ) { $ this -> archive = Archive :: Schema ( ) -> ByID ( Request :: GetData ( 'archive' ) ) ; if ( ! $ this -> archive ) { throw new \ Exception ( "Missing or invalid parameter 'archive'" ) ; } $ this -> article = new Article ( Request :: GetData ( 'article' ) ) ; $ this -> dateFormat = Trans ( 'Core.DateFormat' ) ; } | Initializes the class members |
1,590 | private function AddCategoryField ( ) { $ name = 'Category' ; $ value = '' ; if ( $ this -> article -> Exists ( ) ) { $ value = $ this -> article -> GetCategory ( ) -> GetID ( ) ; } $ field = new Select ( $ name , $ value ) ; $ field -> AddOption ( '' , Trans ( 'Core.PleaseSelect' ) ) ; $ catList = new CategoryListProvider ( $ this -> archive ) ; $ categories = $ catList -> ToArray ( ) ; foreach ( $ categories as $ category ) { $ field -> AddOption ( $ category -> GetID ( ) , $ category -> GetName ( ) ) ; } $ this -> AddField ( $ field ) ; $ this -> SetRequired ( $ name ) ; } | Adds the category select box |
1,591 | private function AddTitleField ( ) { $ name = 'Title' ; $ this -> AddField ( Input :: Text ( $ name , $ this -> article -> GetTitle ( ) ) ) ; $ this -> SetRequired ( $ name ) ; } | Adds the title field |
1,592 | private function AddTextField ( ) { $ name = 'Text' ; $ this -> AddRichTextField ( $ name , $ this -> article -> GetText ( ) ) ; $ this -> SetRequired ( $ name ) ; } | Adds the text field |
1,593 | private function AddPublishField ( ) { $ name = 'Publish' ; $ field = new Checkbox ( $ name , '1' , ( bool ) $ this -> article -> GetPublish ( ) ) ; $ this -> AddField ( $ field ) ; } | Adds the publish check box |
1,594 | private function AddPublishFromDateField ( ) { $ name = 'PublishFromDate' ; $ from = $ this -> article -> GetPublishFrom ( ) ; $ field = Input :: Text ( $ name , $ from ? $ from -> ToString ( $ this -> dateFormat ) : '' ) ; $ field -> SetHtmlAttribute ( 'data-type' , 'date' ) ; $ this -> AddField ( $ field ) ; } | Adds the publish from date field |
1,595 | private function AddPublishFromHourField ( ) { $ name = 'PublishFromHour' ; $ from = $ this -> article -> GetPublishFrom ( ) ; $ field = Input :: Text ( $ name , $ from ? $ from -> ToString ( 'H' ) : '' ) ; $ field -> SetHtmlAttribute ( 'data-type' , 'hour' ) ; $ this -> AddField ( $ field ) ; } | Adds the publish from hour field |
1,596 | private function AddPublishToDateField ( ) { $ name = 'PublishToDate' ; $ to = $ this -> article -> GetPublishTo ( ) ; $ field = Input :: Text ( $ name , $ to ? $ to -> ToString ( $ this -> dateFormat ) : '' ) ; $ field -> SetHtmlAttribute ( 'data-type' , 'date' ) ; $ this -> AddField ( $ field ) ; } | Adds the publish to date field |
1,597 | private function AddAuthorField ( ) { $ name = 'Author' ; if ( $ this -> article -> Exists ( ) ) { $ value = $ this -> article -> GetAuthor ( ) ? $ this -> article -> GetAuthor ( ) -> GetID ( ) : '' ; } else { $ value = self :: Guard ( ) -> GetUser ( ) -> GetID ( ) ; } $ field = new Select ( $ name , $ value ) ; $ field -> AddOption ( '' , Trans ( 'News.Article.Author.Anonymous' ) ) ; $ sql = Access :: SqlBuilder ( ) ; $ tblUser = User :: Schema ( ) -> Table ( ) ; $ users = User :: Schema ( ) -> Fetch ( false , null , $ sql -> OrderList ( $ sql -> OrderAsc ( $ tblUser -> Field ( 'Name' ) ) ) ) ; foreach ( $ users as $ user ) { $ userName = $ user -> GetName ( ) ; if ( $ user -> GetFirstName ( ) && $ user -> GetLastName ( ) ) { $ userName .= ' (' . $ user -> GetFirstName ( ) . ' ' . $ user -> GetLastName ( ) . ')' ; } $ field -> AddOption ( $ user -> GetID ( ) , $ userName ) ; } $ this -> AddField ( $ field ) ; if ( ! self :: Guard ( ) -> GetUser ( ) -> GetIsAdmin ( ) ) { $ field -> SetHtmlAttribute ( 'readonly' , 'readonly' ) ; } } | Adds the author field |
1,598 | protected function OnSuccess ( ) { $ this -> article -> SetPublish ( $ this -> Value ( 'Publish' ) ) ; $ this -> article -> SetPublishFrom ( $ this -> PublishDate ( 'PublishFrom' ) ) ; $ this -> article -> SetPublishTo ( $ this -> PublishDate ( 'PublishTo' ) ) ; $ this -> article -> SetCategory ( Category :: Schema ( ) -> ByID ( $ this -> Value ( 'Category' ) ) ) ; $ this -> article -> SetTitle ( $ this -> Value ( 'Title' ) ) ; $ this -> article -> SetTeaser ( $ this -> Value ( 'Teaser' ) ) ; $ this -> article -> SetText ( $ this -> Value ( 'Text' ) ) ; $ author = User :: Schema ( ) -> ByID ( $ this -> Value ( 'Author' ) ) ; $ this -> article -> SetAuthor ( $ author ) ; $ now = Date :: Now ( ) ; $ this -> article -> SetChanged ( $ now ) ; if ( ! $ this -> article -> Exists ( ) ) { $ this -> article -> SetCreated ( $ now ) ; } $ this -> article -> SetCleanTitle ( $ this -> CalcCleanTitle ( ) ) ; $ this -> article -> Save ( ) ; Response :: Redirect ( $ this -> BackLink ( ) ) ; } | Saves the article |
1,599 | public function plugin ( $ name , array $ options = [ ] ) { $ plugins = $ this -> getPluginManager ( ) ; return $ plugins -> get ( $ name , $ options ) ; } | Retrieve a filter plugin by name |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.