idx
int64 0
60.3k
| question
stringlengths 64
4.24k
| target
stringlengths 5
618
|
|---|---|---|
9,500
|
public function where ( $ column , $ expression = null , $ value = null ) { return $ this -> doWhere ( self :: AND_WHERE , $ column , $ expression , $ value ) ; }
|
Add a where clause to the query .
|
9,501
|
public function andWhereIn ( $ column , array $ values ) { $ this -> where [ ] = [ self :: AND_WHERE_IN , $ column , $ values ] ; return $ this ; }
|
Add an and where in clause to the query .
|
9,502
|
public function orWhereIn ( $ column , array $ values ) { $ this -> where [ ] = [ self :: OR_WHERE_IN , $ column , $ values ] ; return $ this ; }
|
Add an or where in clause to the query .
|
9,503
|
public function on ( $ event_name , $ handler_callback ) { $ event = null ; if ( ! isset ( $ this -> event_queue [ $ event_name ] ) ) { $ event = new Event ( $ event_name ) ; $ this -> event_queue [ $ event_name ] = $ event ; } $ event = $ this -> event_queue [ $ event_name ] ; $ event -> setHandlerCallback ( $ handler_callback ) ; }
|
add a callback to the event one event one handler callback the handler callback is swappable so later handler callback can override previous handler callback
|
9,504
|
public function trigger ( $ event_name , $ default_handler_callback = "" , $ event_properties = array ( ) ) { $ event = null ; if ( isset ( $ this -> event_queue [ $ event_name ] ) ) { $ event = $ this -> event_queue [ $ event_name ] ; $ event -> setProperties ( $ event_properties ) ; $ handler_callback = $ event -> getHandlerCallback ( ) ; if ( is_callable ( $ handler_callback ) ) { $ result = call_user_func_array ( $ handler_callback , array ( $ event ) ) ; $ event -> setHandlerCallbackReturnValue ( $ result ) ; } } else { $ event = new Event ( $ event_name ) ; $ event -> setProperties ( $ event_properties ) ; if ( is_callable ( $ default_handler_callback ) ) { $ event -> setHandlerCallback ( $ default_handler_callback ) ; $ result = call_user_func_array ( $ default_handler_callback , array ( $ event ) ) ; $ event -> setHandlerCallbackReturnValue ( $ result ) ; $ this -> event_queue [ $ event_name ] = $ event ; } } $ result = $ event -> getHandlerCallbackReturnValue ( ) ; return $ result ; }
|
trigger an event with a default handler callback
|
9,505
|
public function usePlugin ( $ plugin_name , $ config = array ( ) ) { if ( ! isset ( $ this -> plugins [ $ plugin_name ] ) ) { $ plugin_name = str_replace ( "." , "\\" , $ plugin_name ) ; $ plugin_class_name = $ plugin_name . "\Main" ; $ this -> plugins [ $ plugin_name ] = new $ plugin_class_name ( ) ; $ this -> plugins [ $ plugin_name ] -> setAppInstance ( $ this ) ; $ this -> plugins [ $ plugin_name ] -> load ( $ config ) ; } return $ this -> plugins [ $ plugin_name ] ; }
|
tell the sytem to use a plugin
|
9,506
|
public function loadAllPlugins ( ) { if ( count ( $ this -> plugins ) > 0 ) { foreach ( $ this -> plugins as $ plugin_name => $ plugin ) { $ event_helpers = $ plugin -> getEventHelperCallbacks ( ) ; if ( count ( $ event_helpers ) > 0 ) { foreach ( $ event_helpers as $ event_name => $ callback ) { if ( ! isset ( $ this -> events_helpers [ $ event_name ] ) ) { $ this -> events_helpers [ $ event_name ] = array ( ) ; } $ this -> events_helpers [ $ event_name ] [ ] = $ plugin ; } } } if ( count ( $ this -> events_helpers ) > 0 ) { foreach ( $ this -> events_helpers as $ event_name => $ plugin_objs ) { if ( count ( $ plugin_objs ) > 0 ) { $ this -> plugin_loading = true ; $ this -> on ( $ event_name , function ( $ event ) use ( $ plugin_objs ) { return call_user_func_array ( array ( $ event , "register" ) , $ plugin_objs ) -> start ( ) ; } ) ; $ this -> plugin_loading = false ; } } } } }
|
load all plugins
|
9,507
|
public function findByLocale ( $ id , $ locale ) { return $ this -> model -> with ( [ 'type' , 'contents' => function ( $ query ) { $ query -> with ( 'lang' ) ; } ] ) -> where ( 'id' , $ id ) -> first ( ) ; }
|
find model by locale
|
9,508
|
public function store ( array $ data ) { DB :: transaction ( function ( ) use ( $ data ) { $ model = $ this -> storeNotificationInstance ( $ data ) ; foreach ( $ data [ 'title' ] as $ langId => $ content ) { $ model -> contents ( ) -> save ( $ model -> contents ( ) -> getModel ( ) -> newInstance ( [ 'notification_id' => $ model -> id , 'lang_id' => $ langId , 'title' => $ content , 'content' => $ data [ 'content' ] [ $ langId ] , 'subject' => $ data [ 'subject' ] [ $ langId ] ] ) ) ; } } ) ; }
|
stores new notification
|
9,509
|
protected function storeNotificationInstance ( array $ data ) { is_null ( $ typeId = array_get ( $ data , 'type_id' ) ) ? $ typeId = app ( NotificationTypes :: class ) -> where ( 'name' , array_get ( $ data , 'type' ) ) -> first ( ) -> id : null ; $ model = $ this -> model -> getModel ( ) -> newInstance ( [ 'category_id' => array_get ( $ data , 'category' ) , 'type_id' => $ typeId , 'active' => array_get ( $ data , 'active' , 1 ) , 'severity_id' => NotificationSeverity :: medium ( ) -> first ( ) -> id , 'event' => config ( 'antares/notifications::default.custom_event' ) ] ) ; $ model -> save ( ) ; return $ model ; }
|
Stores notification instance details
|
9,510
|
public function sync ( array $ data , array $ areas = [ ] ) { DB :: beginTransaction ( ) ; try { $ templates = array_get ( $ data , 'templates' , [ ] ) ; $ model = $ this -> storeNotificationInstance ( $ data ) ; $ langs = array_get ( $ data , 'languages' , [ ] ) ; foreach ( $ langs as $ lang ) { $ this -> processSingle ( $ data , $ lang , $ model ) ; } } catch ( Exception $ e ) { DB :: rollback ( ) ; throw $ e ; } DB :: commit ( ) ; return true ; }
|
Stores system notifications
|
9,511
|
protected function processSingle ( array $ data , $ lang , $ model ) { is_null ( $ view = array_get ( $ data , 'templates.' . $ lang -> code ) ) ? $ view = array_get ( $ data , 'templates.' . $ lang -> code ) : null ; $ content = '' ; if ( is_null ( $ view ) ) { $ content = app ( $ data [ 'classname' ] ) -> render ( ) ; } else { $ path = view ( $ view ) -> getPath ( ) ; if ( ! file_exists ( $ path ) ) { throw new Exception ( trans ( 'antares/notifications::messages.notification_view_not_exists' , [ 'path' => $ path ] ) ) ; } $ content = file_get_contents ( $ path ) ; } return $ model -> contents ( ) -> save ( $ model -> contents ( ) -> getModel ( ) -> newInstance ( [ 'notification_id' => $ model -> id , 'lang_id' => $ lang -> id , 'title' => array_get ( $ data , 'title' ) , 'subject' => array_get ( $ data , 'subject' ) , 'content' => $ content ] ) ) ; }
|
Process signle notification
|
9,512
|
public function getNotificationContents ( $ type = null ) { return NotificationContents :: select ( [ 'title' , 'id' ] ) -> whereHas ( 'lang' , function ( $ query ) { $ query -> where ( 'code' , locale ( ) ) ; } ) -> whereHas ( 'notification' , function ( $ query ) use ( $ type ) { if ( is_null ( $ type ) ) { $ query -> whereHas ( 'type' , function ( $ subquery ) { $ subquery -> whereIn ( 'name' , [ 'sms' , 'email' ] ) ; } ) ; } elseif ( is_numeric ( $ type ) ) { $ query -> where ( 'type_id' , $ type ) ; } elseif ( is_string ( $ type ) ) { $ query -> whereHas ( 'type' , function ( $ subquery ) use ( $ type ) { $ subquery -> where ( 'name' , $ type ) ; } ) ; } } ) -> get ( ) ; }
|
Gets notification contents
|
9,513
|
public function mapObjectsToRows ( $ objects , $ meta = null , $ context = null ) { if ( ! $ objects ) { return [ ] ; } if ( ! $ meta instanceof Meta ) { $ meta = $ this -> getMeta ( $ meta ? : get_class ( current ( $ objects ) ) ) ; } $ out = [ ] ; foreach ( $ objects as $ key => $ object ) { $ out [ $ key ] = $ this -> mapObjectToRow ( $ object , $ meta , $ context ) ; } return $ out ; }
|
Get row values from a list of objects
|
9,514
|
public function createObject ( $ meta , $ mapped , $ args = null ) { if ( ! $ meta instanceof Meta ) { $ meta = $ this -> getMeta ( $ meta ) ; } $ object = null ; $ args = $ args ? array_values ( $ args ) : [ ] ; $ argc = $ args ? count ( $ args ) : 0 ; if ( $ meta -> constructorArgs ) { $ actualArgs = [ ] ; foreach ( $ meta -> constructorArgs as $ argInfo ) { $ type = $ argInfo [ 0 ] ; $ id = isset ( $ argInfo [ 1 ] ) ? $ argInfo [ 1 ] : null ; switch ( $ type ) { case 'property' : $ actualArgs [ ] = isset ( $ mapped -> { $ id } ) ? $ mapped -> { $ id } : null ; unset ( $ mapped -> { $ id } ) ; break ; case 'arg' : if ( $ id >= $ argc ) { throw new Exception ( "Class {$meta->class} requires argument at index $id - please use Select->\$args" ) ; } $ actualArgs [ ] = $ args [ $ id ] ; break ; case 'all' : $ actualArgs [ ] = $ mapped ; break ; default : throw new Exception ( "Invalid constructor argument type {$type}" ) ; } } $ args = $ actualArgs ; } if ( $ meta -> constructor == '__construct' ) { if ( $ args ) { $ rc = new \ ReflectionClass ( $ meta -> class ) ; $ object = $ rc -> newInstanceArgs ( $ args ) ; } else { $ cname = $ meta -> class ; $ object = new $ cname ; } } else { $ rc = new \ ReflectionClass ( $ meta -> class ) ; $ method = $ rc -> getMethod ( $ meta -> constructor ) ; $ object = $ method -> invokeArgs ( null , $ args ? : [ ] ) ; } if ( ! $ object instanceof $ meta -> class ) { throw new Exception ( "Constructor {$meta->constructor} did not return instance of {$meta->class}" ) ; } return $ object ; }
|
The row is made available to this function but this is so it can be used to construct the object not to populate it . Feel free to ignore it it will be passed to populateObject as well .
|
9,515
|
public function populateObject ( $ object , \ stdClass $ mapped , $ meta = null ) { if ( ! $ meta instanceof Meta ) { $ meta = $ this -> getMeta ( $ meta ? : get_class ( $ object ) ) ; if ( ! $ meta ) { throw new \ InvalidArgumentException ( ) ; } } $ properties = $ meta -> getProperties ( ) ; foreach ( $ mapped as $ prop => $ value ) { if ( ! isset ( $ properties [ $ prop ] ) ) { throw new \ UnexpectedValueException ( "Property $prop does not exist on class {$meta->class}" ) ; } $ property = $ properties [ $ prop ] ; if ( ! isset ( $ property [ 'setter' ] ) ) { $ object -> { $ prop } = $ value ; } else { if ( $ property [ 'setter' ] !== false ) { call_user_func ( array ( $ object , $ property [ 'setter' ] ) , $ value ) ; } } } }
|
Populate an object with row values
|
9,516
|
public function addData ( array $ data ) : ErrorResponseBuilder { $ this -> data = array_merge ( $ this -> data , $ data ) ; return $ this ; }
|
Add additonal data appended to the error object .
|
9,517
|
public function setError ( $ errorCode = null , $ message = null ) : ErrorResponseBuilder { $ this -> errorCode = $ errorCode ; if ( is_array ( $ message ) ) { $ this -> parameters = $ message ; } else { $ this -> message = $ message ; } return $ this ; }
|
Set the error code and optionally an error message .
|
9,518
|
public function setStatus ( int $ statusCode ) : ResponseBuilder { if ( $ statusCode < 400 || $ statusCode >= 600 ) { throw new InvalidArgumentException ( "{$statusCode} is not a valid error HTTP status code." ) ; } return parent :: setStatus ( $ statusCode ) ; }
|
Set the HTTP status code for the response .
|
9,519
|
protected function buildErrorData ( ) { if ( is_null ( $ this -> errorCode ) ) { return null ; } $ data = [ 'code' => $ this -> errorCode , 'message' => $ this -> message ? : $ this -> resolveMessage ( ) ] ; return array_merge ( $ data , $ this -> data ) ; }
|
Build the error object of the serialized response data .
|
9,520
|
protected function resolveMessage ( ) { if ( ! $ this -> translator -> has ( $ code = "errors.$this->errorCode" ) ) { return null ; } return $ this -> translator -> trans ( $ code , $ this -> parameters ) ; }
|
Resolve an error message from the translator .
|
9,521
|
public function ensureIlluminateBase ( Container $ app = null ) { if ( ! $ app -> bound ( 'events' ) ) { $ app -> singleton ( 'events' , $ this -> illuminateClasses [ 'events' ] ) ; $ app [ 'events' ] -> fire ( 'booting' ) ; } if ( ! $ app -> bound ( 'files' ) ) { $ app -> bindIf ( 'files' , $ this -> illuminateClasses [ 'files' ] ) ; } }
|
Ensure the base event and file bindings are present . Required for binding anything else .
|
9,522
|
public function bindIlluminateCore ( Container $ app = null ) { if ( ! $ app ) { $ app = new Container ( ) ; } $ this -> ensureIlluminateBase ( $ app ) ; $ app -> bindIf ( 'url' , $ this -> illuminateClasses [ 'url' ] ) ; $ app -> bindIf ( 'session.manager' , function ( $ app ) { return new SessionManager ( $ app ) ; } ) ; $ app -> bindIf ( 'session' , function ( $ app ) { return $ app [ 'session.manager' ] -> driver ( 'array' ) ; } , true ) ; $ app -> bindIf ( 'request' , function ( $ app ) { $ request = Request :: createFromGlobals ( ) ; if ( method_exists ( $ request , 'setSessionStore' ) ) { $ request -> setSessionStore ( $ app [ 'session' ] ) ; } else { $ request -> setSession ( $ app [ 'session' ] ) ; } return $ request ; } , true ) ; $ app -> bindIf ( 'path.config' , function ( $ app ) { return $ this -> illuminateConfigPath ; } , true ) ; $ app -> bindIf ( 'config' , function ( $ app ) { $ config = new Repository ; $ this -> loadIlluminateConfig ( $ app , $ config ) ; return $ config ; } , true ) ; $ app -> bindIf ( 'translation.loader' , function ( $ app ) { return new FileLoader ( $ app [ 'files' ] , 'src/config' ) ; } ) ; $ app -> bindIf ( 'translator' , function ( $ app ) { $ loader = new FileLoader ( $ app [ 'files' ] , 'lang' ) ; return new Translator ( $ loader , 'en' ) ; } ) ; return $ app ; }
|
Bind the core classes to the Container
|
9,523
|
protected function loadIlluminateConfig ( Container $ app , Repository $ config ) { foreach ( $ this -> getIlluminateConfig ( $ app ) as $ key => $ path ) { $ config -> set ( $ key , require $ path ) ; } }
|
Load the configuration items from all config files .
|
9,524
|
protected function getIlluminateConfig ( Container $ app ) { $ files = array ( ) ; foreach ( Finder :: create ( ) -> files ( ) -> name ( '*.php' ) -> in ( $ app [ 'path.config' ] ) as $ file ) { $ files [ basename ( $ file -> getRealPath ( ) , '.php' ) ] = $ file -> getRealPath ( ) ; } return $ files ; }
|
Get all configuration files from the application .
|
9,525
|
public function findOne ( $ conditions , string $ orderBy = null ) : Result { $ query = $ this -> query ( ) -> where ( $ conditions ) -> limit ( 1 ) ; if ( $ orderBy ) { $ query -> orderBy ( $ orderBy ) ; } return $ query -> query ( ) ; }
|
Builds the query for the given conditions and executes it Will return an result with 1 or 0 rows
|
9,526
|
public function validateIdentifier ( $ id ) { $ printed = print_r ( $ id , true ) ; if ( count ( $ this -> keys ) > 1 && ! is_array ( $ id ) ) { throw new \ RuntimeException ( "Entity $this->name has a composed key, finding by id requires an array, given: $printed" ) ; } if ( count ( $ this -> keys ) !== count ( $ id ) ) { $ keys = print_r ( $ this -> keys , true ) ; throw new \ RuntimeException ( "Entity $this->name requires the following keys: $keys, given: $printed" ) ; } }
|
Validates the identifier to prevent unexpected behaviour
|
9,527
|
public function where ( $ id ) { $ this -> validateIdentifier ( $ id ) ; if ( ! is_array ( $ id ) ) { $ key = reset ( $ this -> keys ) ; return [ $ key => $ id ] ; } else { return $ id ; } }
|
Creates the where condition for the identifier
|
9,528
|
private function handleRunningProcess ( Process $ process , & $ runningCommand , & $ failed , & $ hasReceivedSignal , & $ exitCode , & $ exitCodeText ) { if ( $ process -> isRunning ( ) ) { if ( $ hasReceivedSignal ) { return ; } if ( $ this -> shutdownNow ) { $ this -> output -> write ( "[RECEIVED SIGNAL] Shutting down now!" ) ; $ process -> stop ( 0 ) ; $ hasReceivedSignal = true ; $ this -> keepWorking = false ; $ runningCommand = false ; } if ( ( ! $ this -> keepWorking || $ this -> shutdownGracefully ) ) { $ this -> output -> write ( "[RECEIVED SIGNAL] will shutdown after finishing task" ) ; $ hasReceivedSignal = true ; } } else { $ runningCommand = false ; $ exitCode = $ process -> getExitCode ( ) ; $ exitCodeText = $ process -> getExitCode ( ) ; if ( $ exitCode != 0 ) { $ failed = true ; } } }
|
Handles any running process waiting for signals ..
|
9,529
|
public function addFixture ( FixtureInterface $ fixture ) { $ this -> dropTables = array_merge ( $ this -> dropTables , ( array ) $ fixture -> getTables ( ) ) ; $ this -> fixtures [ ] = $ fixture ; }
|
Add a fixture to be loaded into the database .
|
9,530
|
public function run ( Connection $ connection , $ append = false ) { if ( ! $ append ) { foreach ( array_unique ( $ this -> dropTables ) as $ table ) { $ connection -> delete ( $ table , [ 1 => 1 ] , [ \ PDO :: PARAM_INT ] ) ; } } foreach ( $ this -> getSortedFixtures ( ) as $ fixture ) { $ this -> runFixture ( $ connection , $ fixture ) ; } }
|
Run all fixtures .
|
9,531
|
public function each ( callable $ closure ) { $ results = [ ] ; foreach ( $ this -> rows as $ row ) { $ results [ ] = $ closure ( ... array_values ( $ row ) ) ; } return $ results ; }
|
Call a closure for each row
|
9,532
|
public function row ( ) { if ( isset ( $ this -> rows [ $ this -> cursor ] ) ) { return $ this -> rows [ $ this -> cursor ++ ] ; } return false ; }
|
Get a single row as array
|
9,533
|
public function containsResourceIdentifier ( $ resourceIdentifier ) { $ items = $ this -> getItems ( 0 , false ) ; foreach ( $ items [ 0 ] as $ item ) { if ( $ item -> _id = $ resourceIdentifier ) { return true ; } } return false ; }
|
Test to see if the given resource identifier exists in the collection of resources .
|
9,534
|
protected function createCollectionResourceForItems ( $ items , $ from , $ to , $ count ) { $ resource = parent :: get ( ) ; $ resource -> items = $ items ; $ resource -> count = $ count ; $ resource -> range = new \ stdClass ( ) ; $ resource -> range -> from = $ from ; $ resource -> range -> to = $ to ; return $ resource ; }
|
Creates a valid collection response from a list of objects .
|
9,535
|
public function attr ( array $ attributes ) { $ result = '' ; foreach ( $ attributes as $ attribute => $ value ) { $ result .= ' ' . ( is_int ( $ attribute ) ? $ value : $ attribute . '="' . str_replace ( '"' , '"' , $ value ) . '"' ) ; } return $ result ; }
|
Render the attributes
|
9,536
|
public function mergeAttr ( ) { $ arrays = func_get_args ( ) ; $ result = array ( ) ; foreach ( $ arrays as $ array ) { $ result = $ this -> mergeRecursive ( $ result , $ array ) ; } return $ result ; }
|
It will merge multiple attributes arrays without erase values
|
9,537
|
public function insert ( $ substring , $ index ) { if ( $ index <= 0 ) { return $ this -> prepend ( $ substring ) ; } if ( $ index > $ this -> length ( ) ) { return $ this -> append ( $ substring ) ; } $ start = mb_substr ( $ this -> string , 0 , $ index , $ this -> encoding ) ; $ end = mb_substr ( $ this -> string , $ index , $ this -> length ( ) , $ this -> encoding ) ; return new Text ( $ start . $ substring . $ end ) ; }
|
Inserts a substring at the given index
|
9,538
|
public function compare ( $ compare , callable $ callback = null ) { if ( $ callback === null ) { $ callback = 'strcmp' ; } return $ callback ( $ this -> string , ( string ) $ compare ) ; }
|
Compares this string to another
|
9,539
|
public function slice ( $ offset , $ length = null ) { $ offset = $ this -> prepareOffset ( $ offset ) ; $ length = $ this -> prepareLength ( $ offset , $ length ) ; if ( $ length === 0 ) { return new Text ( '' , $ this -> encoding ) ; } return new Text ( mb_substr ( $ this -> string , $ offset , $ length , $ this -> encoding ) , $ this -> encoding ) ; }
|
Slices a piece of the string from a given offset with a specified length . If no length is given the String is sliced to its maximum length .
|
9,540
|
public function substring ( $ start , $ end = null ) { $ length = $ this -> length ( ) ; if ( $ end < 0 ) { $ end = $ length + $ end ; } $ end = $ end !== null ? min ( $ end , $ length ) : $ length ; $ start = min ( $ start , $ end ) ; $ end = max ( $ start , $ end ) ; $ end = $ end - $ start ; return new Text ( mb_substr ( $ this -> string , $ start , $ end , $ this -> encoding ) , $ this -> encoding ) ; }
|
Slices a piece of the string from a given start to an end . If no length is given the String is sliced to its maximum length .
|
9,541
|
public function countSubstring ( $ substring , $ caseSensitive = true ) { $ this -> verifyNotEmpty ( $ substring , '$substring' ) ; if ( $ caseSensitive ) { return mb_substr_count ( $ this -> string , $ substring , $ this -> encoding ) ; } $ str = mb_strtoupper ( $ this -> string , $ this -> encoding ) ; $ substring = mb_strtoupper ( $ substring , $ this -> encoding ) ; return mb_substr_count ( $ str , $ substring , $ this -> encoding ) ; }
|
Count the number of substring occurrences .
|
9,542
|
public function supplant ( array $ map ) { return new Text ( str_replace ( array_keys ( $ map ) , array_values ( $ map ) , $ this -> string ) , $ this -> encoding ) ; }
|
Replaces all occurences of given replacement map . Keys will be replaced with its values .
|
9,543
|
public function splice ( $ replacement , $ offset , $ length = null ) { $ offset = $ this -> prepareOffset ( $ offset ) ; $ length = $ this -> prepareLength ( $ offset , $ length ) ; $ start = $ this -> substring ( 0 , $ offset ) ; $ end = $ this -> substring ( $ offset + $ length ) ; return new Text ( $ start . $ replacement . $ end ) ; }
|
Replace text within a portion of a string .
|
9,544
|
public function chars ( ) { $ chars = new ArrayObject ( ) ; for ( $ i = 0 , $ l = $ this -> length ( ) ; $ i < $ l ; $ i ++ ) { $ chars -> push ( $ this -> at ( $ i ) ) ; } return $ chars ; }
|
Returns an ArrayObject consisting of the characters in the string .
|
9,545
|
public function indexOf ( $ string , $ offset = 0 ) { $ offset = $ this -> prepareOffset ( $ offset ) ; if ( $ string == '' ) { return $ offset ; } return mb_strpos ( $ this -> string , ( string ) $ string , $ offset , $ this -> encoding ) ; }
|
Returns the index of a given string starting at the optional zero - related offset
|
9,546
|
public function lastIndexOf ( $ string , $ offset = null ) { if ( null === $ offset ) { $ offset = $ this -> length ( ) ; } else { $ offset = $ this -> prepareOffset ( $ offset ) ; } if ( $ string === '' ) { return $ offset ; } return mb_strrpos ( $ this , ( string ) $ string , $ offset - $ this -> length ( ) , $ this -> encoding ) ; }
|
Returns the last index of a given string starting at the optional offset
|
9,547
|
public function startsWith ( $ substring ) { $ substringLength = mb_strlen ( $ substring , $ this -> encoding ) ; $ startOfStr = mb_substr ( $ this -> string , 0 , $ substringLength , $ this -> encoding ) ; return ( string ) $ substring === $ startOfStr ; }
|
Checks whether the string starts with the given string . Case sensitive!
|
9,548
|
public function startsWithIgnoreCase ( $ substring ) { $ substring = mb_strtolower ( $ substring , $ this -> encoding ) ; $ substringLength = mb_strlen ( $ substring , $ this -> encoding ) ; $ startOfStr = mb_strtolower ( mb_substr ( $ this -> string , 0 , $ substringLength , $ this -> encoding ) ) ; return ( string ) $ substring === $ startOfStr ; }
|
Checks whether the string starts with the given string . Ignores case .
|
9,549
|
public function endsWith ( $ substring ) { $ substringLength = mb_strlen ( $ substring , $ this -> encoding ) ; $ endOfStr = mb_substr ( $ this -> string , $ this -> length ( ) - $ substringLength , $ substringLength , $ this -> encoding ) ; return ( string ) $ substring === $ endOfStr ; }
|
Checks whether the string ends with the given string . Case sensitive!
|
9,550
|
public function endsWithIgnoreCase ( $ substring ) { $ substring = mb_strtolower ( $ substring , $ this -> encoding ) ; $ substringLength = mb_strlen ( $ substring , $ this -> encoding ) ; $ endOfStr = mb_strtolower ( mb_substr ( $ this -> string , $ this -> length ( ) - $ substringLength , $ substringLength , $ this -> encoding ) ) ; return ( string ) $ substring === $ endOfStr ; }
|
Checks whether the string ends with the given string . Ingores case .
|
9,551
|
public function pad ( $ length , $ padding = ' ' ) { $ len = $ length - $ this -> length ( ) ; return $ this -> applyPadding ( floor ( $ len / 2 ) , ceil ( $ len / 2 ) , $ padding ) ; }
|
Adds padding to the start and end
|
9,552
|
public function wrapWords ( $ width = 75 , $ break = "\n" , $ cut = false ) { return new Text ( wordwrap ( $ this -> string , $ width , $ break , $ cut ) , $ this -> encoding ) ; }
|
Returns a copy of the string wrapped at a given number of characters
|
9,553
|
public function truncate ( $ length , $ substring = '' ) { if ( $ this -> length ( ) <= $ length ) { return new Text ( $ this -> string , $ this -> encoding ) ; } $ substrLen = mb_strlen ( $ substring , $ this -> encoding ) ; if ( $ this -> length ( ) + $ substrLen > $ length ) { $ length -= $ substrLen ; } return $ this -> substring ( 0 , $ length ) -> append ( $ substring ) ; }
|
Truncates the string with a substring and ensures it doesn t exceed the given length
|
9,554
|
public function split ( $ delimiter , $ limit = PHP_INT_MAX ) { return new ArrayObject ( explode ( $ delimiter , $ this -> string , $ limit ) ) ; }
|
Splits the string by string
|
9,555
|
public static function join ( array $ pieces , $ glue = '' , $ encoding = null ) { return new Text ( implode ( $ pieces , $ glue ) , $ encoding ) ; }
|
Join array elements with a string
|
9,556
|
public function chunk ( $ splitLength = 1 ) { $ this -> verifyPositive ( $ splitLength , 'The chunk length' ) ; return new ArrayObject ( str_split ( $ this -> string , $ splitLength ) ) ; }
|
Convert the string to an array
|
9,557
|
public function toLowerCaseFirst ( ) { $ first = $ this -> substring ( 0 , 1 ) ; $ rest = $ this -> substring ( 1 ) ; return new Text ( mb_strtolower ( $ first , $ this -> encoding ) . $ rest , $ this -> encoding ) ; }
|
Transforms the string to first character lowercased
|
9,558
|
public function toUpperCaseFirst ( ) { $ first = $ this -> substring ( 0 , 1 ) ; $ rest = $ this -> substring ( 1 ) ; return new Text ( mb_strtoupper ( $ first , $ this -> encoding ) . $ rest , $ this -> encoding ) ; }
|
Transforms the string to first character uppercased
|
9,559
|
public function toCapitalCaseWords ( ) { $ encoding = $ this -> encoding ; return $ this -> split ( ' ' ) -> map ( function ( $ str ) use ( $ encoding ) { return Text :: create ( $ str , $ encoding ) -> toCapitalCase ( ) ; } ) -> join ( ' ' ) ; }
|
Transforms the string with the words capitalized .
|
9,560
|
public function toStudlyCase ( ) { $ input = $ this -> trim ( '-_' ) ; if ( $ input -> isEmpty ( ) ) { return $ input ; } $ encoding = $ this -> encoding ; return Text :: create ( preg_replace_callback ( '/([A-Z-_][a-z0-9]+)/' , function ( $ matches ) use ( $ encoding ) { return Text :: create ( $ matches [ 0 ] , $ encoding ) -> replace ( [ '-' , '_' ] , '' ) -> toUpperCaseFirst ( ) ; } , $ input ) , $ this -> encoding ) -> toUpperCaseFirst ( ) ; }
|
Converts this string into StudlyCase . Numbers are considered as part of its previous piece .
|
9,561
|
public function toKebabCase ( ) { if ( $ this -> contains ( '_' ) ) { return $ this -> replace ( '_' , '-' ) ; } return new Text ( mb_strtolower ( preg_replace ( '/([a-z0-9])([A-Z])/' , '$1-$2' , $ this -> string ) ) , $ this -> encoding ) ; }
|
Convert this string into kebab - case . Numbers are considered as part of its previous piece .
|
9,562
|
public function toPlural ( Pluralizer $ pluralizer = null ) { $ pluralizer = $ pluralizer ? : new EnglishPluralizer ( ) ; return new Text ( $ pluralizer -> getPluralForm ( $ this -> string ) , $ this -> encoding ) ; }
|
Get the plural form of the Text object .
|
9,563
|
public function toSingular ( Pluralizer $ pluralizer = null ) { $ pluralizer = $ pluralizer ? : new EnglishPluralizer ( ) ; return new Text ( $ pluralizer -> getSingularForm ( $ this -> string ) , $ this -> encoding ) ; }
|
Get the singular form of the Text object .
|
9,564
|
public static function isUsed ( $ password , $ user = null ) { if ( ! User :: isValid ( $ user ) ) { throw new InvalidParamException ( 'User Invalid.' ) ; } $ passwords = static :: find ( ) -> createdBy ( $ user ) -> all ( ) ; foreach ( $ passwords as $ p ) { if ( $ p -> validatePassword ( $ password ) ) { return $ p ; } } return false ; }
|
Check whether the password has been used .
|
9,565
|
public static function add ( $ password , $ user = null ) { if ( static :: isUsed ( $ password , $ user ) && ! $ user -> allowUsedPassword ) { throw new InvalidParamException ( 'Password existed.' ) ; } if ( static :: judgePasswordHash ( $ password ) ) { $ passwordHistory = $ user -> create ( static :: class ) ; $ passwordHistory -> { $ passwordHistory -> passwordHashAttribute } = $ password ; } else { $ passwordHistory = $ user -> create ( static :: class , [ 'password' => $ password ] ) ; } return $ passwordHistory -> save ( ) ; }
|
Add password to history .
|
9,566
|
public static function first ( $ user = null ) { if ( ! User :: isValid ( $ user ) ) { throw new InvalidParamException ( 'User Invalid.' ) ; } return static :: find ( ) -> createdBy ( $ user ) -> orderByCreatedAt ( ) -> one ( ) ; }
|
Get first password hash .
|
9,567
|
public static function last ( $ user = null ) { if ( ! User :: isValid ( $ user ) ) { throw new InvalidParamException ( 'User Invalid.' ) ; } return static :: find ( ) -> createdBy ( $ user ) -> orderByCreatedAt ( SORT_DESC ) -> one ( ) ; }
|
Get last password hash .
|
9,568
|
public function getScript ( ) { $ this -> useSingleQuotes ( ) ; foreach ( $ this -> aArguments as $ xArgument ) { if ( $ xArgument instanceof Element ) { $ this -> addParameter ( Jaxon :: JS_VALUE , $ xArgument -> getScript ( ) ) ; } else if ( $ xArgument instanceof Parameter ) { $ this -> addParameter ( $ xArgument -> getType ( ) , $ xArgument -> getValue ( ) ) ; } else if ( $ xArgument instanceof Request ) { $ this -> addParameter ( Jaxon :: JS_VALUE , 'function(){' . $ xArgument -> getScript ( ) . ';}' ) ; } else if ( is_numeric ( $ xArgument ) ) { $ this -> addParameter ( Jaxon :: NUMERIC_VALUE , $ xArgument ) ; } else if ( is_string ( $ xArgument ) ) { $ this -> addParameter ( Jaxon :: QUOTED_VALUE , $ xArgument ) ; } else if ( is_bool ( $ xArgument ) ) { $ this -> addParameter ( Jaxon :: BOOL_VALUE , $ xArgument ) ; } else if ( is_array ( $ xArgument ) || is_object ( $ xArgument ) ) { $ this -> addParameter ( Jaxon :: JS_VALUE , $ xArgument ) ; } } return $ this -> sMethod . '(' . implode ( ', ' , $ this -> aParameters ) . ')' ; }
|
Return a string representation of the call to this jQuery function
|
9,569
|
public function parseBody ( $ origLine ) { $ line = rtrim ( $ origLine , "\r\n" ) ; if ( $ this -> parserState == self :: PARSE_STATE_HEADERS && $ line == '' ) { $ this -> parserState = self :: PARSE_STATE_BODY ; $ headers = new ezcMailHeadersHolder ( ) ; $ headers [ 'Content-Type' ] = $ this -> headers [ 'Content-Type' ] ; if ( isset ( $ this -> headers [ 'Content-Transfer-Encoding' ] ) ) { $ headers [ 'Content-Transfer-Encoding' ] = $ this -> headers [ 'Content-Transfer-Encoding' ] ; } if ( isset ( $ this -> headers [ 'Content-Disposition' ] ) ) { $ headers [ 'Content-Disposition' ] = $ this -> headers [ 'Content-Disposition' ] ; } $ this -> bodyParser = self :: createPartParserForHeaders ( $ headers ) ; } else if ( $ this -> parserState == self :: PARSE_STATE_HEADERS ) { $ this -> parseHeader ( $ line , $ this -> headers ) ; } else { $ this -> bodyParser -> parseBody ( $ origLine ) ; } }
|
Parses the body of an rfc 2822 message .
|
9,570
|
public function saveHtml ( $ filename , $ base = null ) { $ this -> ensureWritableDirectory ( dirname ( $ filename ) ) ; $ html = new Html ( $ this -> getHtml ( ) ) ; if ( null !== $ base ) { $ html -> resolveLinks ( \ GuzzleHttp \ Psr7 \ uri_for ( $ base ) ) ; } file_put_contents ( $ filename , $ html -> get ( ) ) ; return $ this ; }
|
Save the HTML of the session into a file Optionally resolve all the links with a base uri
|
9,571
|
public static function parse ( $ filename , $ del = "." ) { if ( is_null ( self :: $ _instance ) ) { self :: $ _instance = new self ( $ filename , $ del ) ; } return self :: $ _instance -> getObj ( ) ; }
|
Singleton pattern constructor
|
9,572
|
private function _parseIni ( $ iniFile ) { $ aParsedIni = parse_ini_file ( $ iniFile , true , INI_SCANNER_RAW ) ; $ tmpArray = array ( ) ; foreach ( $ aParsedIni as $ key => $ value ) { if ( strpos ( $ key , ':' ) !== false ) { $ sections = explode ( ':' , $ key ) ; if ( count ( $ sections ) != 2 ) { throw new Exception ( 'Malformed section header!' ) ; } $ currentSection = trim ( $ sections [ 0 ] ) ; $ parentSection = trim ( $ sections [ 1 ] ) ; $ value = array_merge_recursive ( $ aParsedIni [ $ parentSection ] , $ aParsedIni [ $ key ] ) ; $ aParsedIni [ $ currentSection ] = $ value ; unset ( $ aParsedIni [ $ key ] ) ; $ key = $ currentSection ; } if ( is_array ( $ value ) ) { foreach ( $ value as $ vk => $ vv ) { $ newKey = $ key . "." . $ vk ; $ tmpArray [ $ newKey ] = $ vv ; if ( is_string ( $ vv ) && preg_match_all ( '/\${([a-zA-Z0-9\.]+)}/' , $ vv , $ match ) ) { if ( ! isset ( $ match [ 1 ] ) ) { continue ; } $ variableKey = $ match [ 1 ] ; foreach ( $ variableKey as & $ var ) { if ( strpos ( $ var , '.' ) === false ) { $ var = $ key . '.' . $ var ; } } $ this -> _varDeps [ $ newKey ] = $ variableKey ; } } } } if ( ! empty ( $ tmpArray ) ) { $ aParsedIni = $ tmpArray ; } foreach ( $ aParsedIni as $ key => $ value ) { if ( array_key_exists ( $ key , $ this -> _varDeps ) ) { $ deps = & $ this -> _varDeps ; $ value = preg_replace_callback ( '/\${([a-zA-Z0-9\.]+)}/' , function ( $ match ) use ( $ key , $ aParsedIni , & $ deps ) { return $ aParsedIni [ array_shift ( $ deps [ $ key ] ) ] ; } , $ value ) ; $ aParsedIni [ $ key ] = $ value ; } $ this -> _tmpValue = $ value ; $ aXKey = explode ( $ this -> _delimiter , $ key ) ; $ this -> _recursiveInit ( $ this -> _obj , $ aXKey ) ; } }
|
Parses ini file and extract its keys and prepare it for object creation
|
9,573
|
public function trim ( $ file , $ max_w , $ max_h , $ crop = false , $ suffix = null , $ dest_path = null , $ jpeg_quality = 90 ) { $ editor = wp_get_image_editor ( $ file ) ; if ( is_wp_error ( $ editor ) ) return $ editor ; $ editor -> set_quality ( $ jpeg_quality ) ; $ resized = $ editor -> resize ( $ max_w , $ max_h , $ crop ) ; if ( is_wp_error ( $ resized ) ) return $ resized ; $ dest_file = $ editor -> generate_filename ( $ suffix , $ dest_path ) ; $ saved = $ editor -> save ( $ dest_file ) ; if ( is_wp_error ( $ saved ) ) return $ saved ; return $ dest_file ; }
|
Clone of image resize
|
9,574
|
public function fit ( $ src , $ dest , $ width , $ height ) { $ size = getimagesize ( $ src ) ; $ ratio = max ( $ width / $ size [ 0 ] , $ height / $ size [ 1 ] ) ; $ old_width = $ size [ 0 ] ; $ old_height = $ size [ 1 ] ; $ new_width = intval ( $ old_width * $ ratio ) ; $ new_height = intval ( $ old_height * $ ratio ) ; @ ini_set ( 'memory_limit' , apply_filters ( 'image_memory_limit' , WP_MAX_MEMORY_LIMIT ) ) ; $ image = imagecreatefromstring ( file_get_contents ( $ src ) ) ; $ new_image = wp_imagecreatetruecolor ( $ new_width , $ new_height ) ; imagecopyresampled ( $ new_image , $ image , 0 , 0 , 0 , 0 , $ new_width , $ new_height , $ old_width , $ old_height ) ; if ( IMAGETYPE_PNG == $ size [ 2 ] && function_exists ( 'imageistruecolor' ) && ! imageistruecolor ( $ image ) ) { imagetruecolortopalette ( $ new_image , false , imagecolorstotal ( $ image ) ) ; } imagedestroy ( $ image ) ; switch ( $ size [ 2 ] ) { case IMAGETYPE_GIF : $ result = imagegif ( $ new_image , $ dest ) ; break ; case IMAGETYPE_PNG : $ result = imagepng ( $ new_image , $ dest ) ; break ; default : $ result = imagejpeg ( $ new_image , $ dest ) ; break ; } imagedestroy ( $ new_image ) ; return $ result ; }
|
Fit small image to specified bound
|
9,575
|
private function retrieveFormFieldDescription ( AdminInterface $ admin , $ field ) { $ admin -> getFormFieldDescriptions ( ) ; $ fieldDescription = $ admin -> getFormFieldDescription ( $ field ) ; if ( ! $ fieldDescription ) { throw new \ RuntimeException ( sprintf ( 'The field "%s" does not exist.' , $ field ) ) ; } if ( null === $ fieldDescription -> getTargetEntity ( ) ) { throw new \ RuntimeException ( sprintf ( 'No associated entity with field "%s".' , $ field ) ) ; } return $ fieldDescription ; }
|
Retrieve the form field description given by field name . Copied from Sonata \ AdminBundle \ Controller \ HelperController .
|
9,576
|
protected function execute ( InputInterface $ input , OutputInterface $ output ) { $ this -> initialiseWorker ( $ input , $ output ) ; $ totalTasks = $ input -> getOption ( 'total-tasks' ) ; for ( $ counter = 0 ; $ counter < $ totalTasks ; $ counter ++ ) { $ task = new ExampleTaskDescription ( ) ; $ task -> message = 'hello world' ; $ task -> wait = 1 ; $ this -> taskQueueService -> queueTask ( $ task , $ this -> tube ) ; } }
|
Adds an example task to the task queue using the ExampleTask . php
|
9,577
|
public function read ( $ path ) { $ config = $ this -> readByFilename ( $ path , Visithor :: CONFIG_FILE_NAME_DISTR ) ; if ( false === $ config ) { $ config = $ this -> readByFilename ( $ path , Visithor :: CONFIG_FILE_NAME ) ; } return $ config ; }
|
Read all the configuration given a path
|
9,578
|
public function readByFilename ( $ path , $ filename ) { $ config = false ; $ configFilePath = rtrim ( $ path , '/' ) . '/' . $ filename ; if ( is_file ( $ configFilePath ) ) { $ yamlParser = new YamlParser ( ) ; $ config = $ yamlParser -> parse ( file_get_contents ( $ configFilePath ) ) ; } return $ config ; }
|
Read all the configuration given a path and a filename
|
9,579
|
public function addClass ( $ class , $ extends = null , $ implements = [ ] ) { $ classId = $ this -> registerClass ( $ class ) ; if ( $ extends ) { $ parentClassId = $ this -> registerClass ( $ extends ) ; $ this -> extends [ $ classId ] = [ $ parentClassId ] ; } if ( ! empty ( $ implements ) ) { $ interfaceIds = [ ] ; foreach ( $ implements as $ interface ) { $ interfaceIds [ ] = $ this -> registerInterface ( $ interface ) ; } $ this -> implements [ $ classId ] = $ interfaceIds ; } }
|
add class to hierarchy tree
|
9,580
|
public function addInterface ( $ interface , $ extends = [ ] ) { $ interfaceId = $ this -> registerInterface ( $ interface ) ; if ( ! empty ( $ extends ) ) { $ interfaceIds = [ ] ; foreach ( $ extends as $ name ) { $ interfaceIds [ ] = $ this -> registerInterface ( $ name ) ; } $ this -> interfaceExtends [ $ interfaceId ] = $ interfaceIds ; } }
|
add interface to hierarchy tree
|
9,581
|
public function getParent ( $ class ) { $ classId = $ this -> getClassId ( $ class ) ; if ( ! isset ( $ classId ) ) { return false ; } $ parentClassId = $ this -> extends [ $ classId ] ; return isset ( $ parentClassId ) ? $ this -> classes [ $ parentClassId [ 0 ] ] : null ; }
|
gets parent class
|
9,582
|
public function getAncestors ( $ class ) { $ ancestors = [ ] ; while ( true ) { $ parent = $ this -> getParent ( $ class ) ; if ( $ parent ) { $ ancestors [ ] = $ parent ; $ class = $ parent ; } else { break ; } } return $ ancestors ; }
|
gets all parent classes
|
9,583
|
public function getImplements ( $ class ) { $ interfaces = [ ] ; $ classId = $ this -> getClassId ( $ class ) ; if ( isset ( $ classId ) ) { if ( isset ( $ this -> implements [ $ classId ] ) ) { foreach ( $ this -> implements [ $ classId ] as $ interfaceId ) { $ interfaces [ $ this -> interfaces [ $ interfaceId ] ] = 1 ; } } foreach ( $ this -> getAncestors ( $ class ) as $ parent ) { foreach ( $ this -> getImplements ( $ parent ) as $ interface ) { $ interfaces [ $ interface ] = 1 ; } } } return array_keys ( $ interfaces ) ; }
|
gets implemented interfaces
|
9,584
|
public function isA ( $ class , $ test_class ) { $ test_class = $ this -> normalize ( $ test_class ) ; if ( $ this -> classExists ( $ test_class ) ) { return in_array ( $ test_class , $ this -> getAncestors ( $ class ) ) ; } elseif ( $ this -> interfaceExists ( $ test_class ) ) { return in_array ( $ test_class , $ this -> getImplements ( $ class ) ) ; } else { throw new ClassNotExistException ( $ test_class ) ; } }
|
checks the class is subclass or implements the test class
|
9,585
|
public function getSubClasses ( $ class ) { $ class = $ this -> normalize ( $ class ) ; if ( $ this -> classExists ( $ class ) ) { return $ this -> getSubclassOfClass ( $ class ) ; } elseif ( $ this -> interfaceExists ( $ class ) ) { return $ this -> getSubclassOfInterface ( $ class ) ; } else { throw new ClassNotExistException ( $ class ) ; } }
|
gets all subclass of the class or interface
|
9,586
|
public function paginate ( ) { $ this -> count = $ this -> query -> get ( ) -> count ( ) ; $ this -> limit = $ this -> limit ? : $ this -> count ; $ this -> query -> skip ( $ this -> offset ) -> take ( $ this -> limit ) ; }
|
Will modify a query builder to get paginated data and will return an array with the meta data .
|
9,587
|
public function getNextPageParams ( ) { $ limit = $ this -> limit <= 0 ? $ this -> count : $ this -> limit ; $ next_url = $ this -> offset_key . $ this -> offset . $ this -> limit_key . $ limit ; if ( $ this -> count <= ( $ this -> offset + $ limit ) ) { return false ; } if ( $ this -> count >= $ limit ) { $ next_url = $ this -> offset_key . ( $ this -> offset + $ limit ) . $ this -> limit_key . $ limit ; } return $ next_url ; }
|
Generate the next page url parameters as string .
|
9,588
|
public function getPrevPageParams ( ) { $ limit = $ this -> limit <= 0 ? $ this -> count : $ this -> limit ; $ prev_url = $ this -> offset_key . $ this -> offset . $ this -> limit_key . $ limit ; if ( $ this -> count >= $ limit ) { $ prev_url = $ this -> offset_key . ( $ this -> offset - $ limit ) . $ this -> limit_key . $ limit ; } if ( $ this -> count <= ( $ this -> offset - $ limit ) ) { $ prev_url = $ this -> offset_key . $ this -> offset . $ this -> limit_key . $ limit ; } return $ prev_url ; }
|
Generate the prev page url parameters as string .
|
9,589
|
public function getLastPageParams ( ) { $ limit = $ this -> limit <= 0 ? $ this -> count : $ this -> limit ; $ last_page = intdiv ( intval ( $ this -> count ) , intval ( $ limit ) ) ; $ last_url = $ this -> offset_key . ( $ last_page * $ limit ) . $ this -> limit_key . $ limit ; return $ last_url ; }
|
Generate the last page url parameters as string .
|
9,590
|
public function getFirstPageParams ( ) { $ limit = $ this -> limit <= 0 ? $ this -> count : $ this -> limit ; $ first_url = $ this -> offset_key . '0' . $ this -> limit_key . $ limit ; return $ first_url ; }
|
Generate the first page url parameters as string .
|
9,591
|
public function getPaginationMetaData ( ) { $ pagination = [ 'count' => $ this -> count , 'offset' => $ this -> offset , 'limit' => $ this -> limit , 'next_page_params' => $ this -> getNextPageParams ( ) , ] ; return $ pagination ; }
|
Get a json encoded array with pagination metadata
|
9,592
|
public function recursiveReplace ( $ search , $ replace ) { $ json = json_encode ( $ this -> params ) ; $ json = str_replace ( $ search , $ replace , $ json ) ; $ this -> params = json_decode ( $ json , TRUE ) ; }
|
Search and replace function for multi level arrays
|
9,593
|
public function rollback ( ) { if ( $ this -> hasBackup ) { $ this -> params = $ this -> backup ; } else { throw new Exceptions \ NoValidBackup ( $ this -> params ) ; } }
|
Uses the backup array to revert the params array
|
9,594
|
public function activateSubscription ( $ hashString ) { $ subscription = ezcomSubscription :: fetchByHashString ( $ hashString ) ; if ( is_null ( $ subscription ) ) { $ this -> tpl -> setVariable ( 'error_message' , ezpI18n :: tr ( 'ezcomments/comment/activate' , 'There is no subscription with the hash string!' ) ) ; } else { if ( $ subscription -> attribute ( 'enabled' ) ) { ezDebugSetting :: writeNotice ( 'extension-ezcomments' , 'Subscription activated' , __METHOD__ ) ; } $ subscriber = ezcomSubscriber :: fetch ( $ subscription -> attribute ( 'subscriber_id' ) ) ; if ( $ subscriber -> attribute ( 'enabled' ) ) { $ subscription -> enable ( ) ; $ this -> tpl -> setVariable ( 'subscriber' , $ subscriber ) ; } else { $ this -> tpl -> setVariable ( 'error_message' , ezpI18n :: tr ( 'ezcomments/comment/activate' , 'The subscriber is disabled!' ) ) ; } } }
|
Activate subscription If there is error set error_message to the template If activation succeeds set subscriber to the template
|
9,595
|
public function addSubscription ( $ email , $ user , $ contentID , $ languageID , $ subscriptionType , $ currentTime , $ activate = true ) { $ ezcommentsINI = eZINI :: instance ( 'ezcomments.ini' ) ; $ subscriber = ezcomSubscriber :: fetchByEmail ( $ email ) ; if ( is_null ( $ subscriber ) ) { $ subscriber = ezcomSubscriber :: create ( ) ; $ subscriber -> setAttribute ( 'user_id' , $ user -> attribute ( 'contentobject_id' ) ) ; $ subscriber -> setAttribute ( 'email' , $ email ) ; if ( $ user -> isAnonymous ( ) ) { $ util = ezcomUtility :: instance ( ) ; $ hashString = $ util -> generateSusbcriberHashString ( $ subscriber ) ; $ subscriber -> setAttribute ( 'hash_string' , $ hashString ) ; } $ subscriber -> store ( ) ; eZDebugSetting :: writeNotice ( 'extension-ezcomments' , 'Subscriber does not exist, added one' , __METHOD__ ) ; $ subscriber = ezcomSubscriber :: fetchByEmail ( $ email ) ; } else { if ( $ subscriber -> attribute ( 'enabled' ) == false ) { throw new Exception ( 'Subscription can not be added because the subscriber is disabled.' , self :: ERROR_SUBSCRIBER_DISABLED ) ; } } $ hasSubscription = ezcomSubscription :: exists ( $ contentID , $ languageID , $ subscriptionType , $ email ) ; if ( $ hasSubscription === false ) { $ subscription = ezcomSubscription :: create ( ) ; $ subscription -> setAttribute ( 'user_id' , $ user -> attribute ( 'contentobject_id' ) ) ; $ subscription -> setAttribute ( 'subscriber_id' , $ subscriber -> attribute ( 'id' ) ) ; $ subscription -> setAttribute ( 'subscription_type' , $ subscriptionType ) ; $ subscription -> setAttribute ( 'content_id' , $ contentID ) ; $ subscription -> setAttribute ( 'language_id' , $ languageID ) ; $ subscription -> setAttribute ( 'subscription_time' , $ currentTime ) ; $ defaultActivated = $ ezcommentsINI -> variable ( 'CommentSettings' , 'SubscriptionActivated' ) ; if ( $ user -> isAnonymous ( ) && $ defaultActivated !== 'true' && $ activate === true ) { $ subscription -> setAttribute ( 'enabled' , 0 ) ; $ utility = ezcomUtility :: instance ( ) ; $ subscription -> setAttribute ( 'hash_string' , $ utility -> generateSubscriptionHashString ( $ subscription ) ) ; $ subscription -> store ( ) ; $ result = ezcomSubscriptionManager :: sendActivationEmail ( eZContentObject :: fetch ( $ contentID ) , $ subscriber , $ subscription ) ; if ( ! $ result ) { eZDebug :: writeError ( "Error sending mail to '$email'" , __METHOD__ ) ; } } else { $ subscription -> setAttribute ( 'enabled' , 1 ) ; $ subscription -> store ( ) ; } eZDebugSetting :: writeNotice ( 'extension-ezcomments' , 'No existing subscription for this content and user, added one' , __METHOD__ ) ; } }
|
Add an subscription . If the subscriber is disabled throw an exception If there is no subscriber add one . If there is no subscription for the content add one
|
9,596
|
public static function sendActivationEmail ( $ contentObject , $ subscriber , $ subscription ) { $ transport = eZNotificationTransport :: instance ( 'ezmail' ) ; $ email = $ subscriber -> attribute ( 'email' ) ; $ tpl = eZTemplate :: factory ( ) ; $ tpl -> setVariable ( 'contentobject' , $ contentObject ) ; $ tpl -> setVariable ( 'subscriber' , $ subscriber ) ; $ tpl -> setVariable ( 'subscription' , $ subscription ) ; $ mailSubject = $ tpl -> fetch ( 'design:comment/notification_activation_subject.tpl' ) ; $ mailBody = $ tpl -> fetch ( 'design:comment/notification_activation_body.tpl' ) ; $ parameters = array ( ) ; $ ezcommentsINI = eZINI :: instance ( 'ezcomments.ini' ) ; $ mailContentType = $ ezcommentsINI -> variable ( 'NotificationSettings' , 'ActivationMailContentType' ) ; $ parameters [ 'from' ] = $ ezcommentsINI -> variable ( 'NotificationSettings' , 'MailFrom' ) ; $ parameters [ 'content_type' ] = $ mailContentType ; $ result = $ transport -> send ( array ( $ email ) , $ mailSubject , $ mailBody , null , $ parameters ) ; return $ result ; }
|
send activation email to the user
|
9,597
|
public static function cleanupExpiredSubscription ( $ time ) { $ startTime = time ( ) - $ time ; $ db = eZDB :: instance ( ) ; $ selectSql = "SELECT id FROM ezcomment_subscription WHERE subscription_time < $startTime AND enabled = 0" ; $ result = $ db -> arrayQuery ( $ selectSql ) ; if ( is_array ( $ result ) && count ( $ result ) > 0 ) { $ deleteSql = "DELETE FROM ezcomment_subscription WHERE subscription_time < $startTime AND enabled = 0" ; $ db -> query ( $ deleteSql ) ; return $ result ; } else { return null ; } }
|
clean up the subscription if the subscription has not been activate for very long
|
9,598
|
public function deleteSubscription ( $ email , $ contentObjectID , $ languageID ) { $ subscriber = ezcomSubscriber :: fetchByEmail ( $ email ) ; $ cond = array ( ) ; $ cond [ 'subscriber_id' ] = $ subscriber -> attribute ( 'id' ) ; $ cond [ 'content_id' ] = $ contentObjectID ; $ cond [ 'language_id' ] = $ languageID ; $ cond [ 'subscription_type' ] = 'ezcomcomment' ; $ subscription = ezcomSubscription :: fetchByCond ( $ cond ) ; $ subscription -> remove ( ) ; }
|
delete the subscription given the subscriber s email
|
9,599
|
public static function instance ( $ tpl = null , $ module = null , $ params = null , $ className = null ) { $ object = null ; if ( is_null ( $ className ) ) { $ ini = eZINI :: instance ( 'ezcomments.ini' ) ; $ className = $ ini -> variable ( 'ManagerClasses' , 'SubscriptionManagerClass' ) ; } if ( ! is_null ( self :: $ instance ) ) { $ object = self :: $ instance ; } else { $ object = new $ className ( ) ; $ object -> tpl = $ tpl ; $ object -> module = $ module ; $ object -> params = $ params ; } return $ object ; }
|
method for creating object
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.